From 10e29413bc92c2b4d17ab497353604a9015cd705 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 8 Nov 2024 19:44:55 -0500 Subject: [PATCH 001/161] Remove unncesssary `compile-flags` directive --- .../conf_disallowed_methods.rs | 2 -- .../conf_disallowed_methods.stderr | 28 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index 17fceae01780..0986290bb0e6 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -1,5 +1,3 @@ -//@compile-flags: --crate-name conf_disallowed_methods - #![allow(clippy::needless_raw_strings)] #![warn(clippy::disallowed_methods)] #![allow(clippy::useless_vec)] diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index e77b2b959497..edda35d647ab 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -1,5 +1,5 @@ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:35:14 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:33:14 | LL | let re = Regex::new(r"ab.*c").unwrap(); | ^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` error: use of a disallowed method `regex::Regex::is_match` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:36:8 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:34:8 | LL | re.is_match("abc"); | ^^^^^^^^ @@ -16,73 +16,73 @@ LL | re.is_match("abc"); = note: no matching allowed error: use of a disallowed method `std::iter::Iterator::sum` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:14 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:37:14 | LL | a.iter().sum::(); | ^^^ error: use of a disallowed method `slice::sort_unstable` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:41:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:7 | LL | a.sort_unstable(); | ^^^^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:44:20 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:42:20 | LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); | ^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:47:61 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:45:61 | LL | let indirect: fn(&str) -> Result = Regex::new; | ^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:28 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:48:28 | LL | let in_call = Box::new(f32::clamp); | ^^^^^^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:51:53 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:49:53 | LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new); | ^^^^^^^^^^ error: use of a disallowed method `futures::stream::select_all` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:31 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:52:31 | LL | let same_name_as_module = select_all(vec![empty::<()>()]); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_fn` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:5 | LL | local_fn(); | ^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_mod::f` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:55:5 | LL | local_mod::f(); | ^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Struct::method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:7 | LL | s.method(); | ^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:58:7 | LL | s.provided_method(); | ^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:61:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:7 | LL | s.implemented_method(); | ^^^^^^^^^^^^^^^^^^ From f159a3eb1dfc3b81088fce364a09e8a79968adda Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 8 Nov 2024 19:40:55 -0500 Subject: [PATCH 002/161] Support replacements in `disallowed_methods` --- clippy_config/src/types.rs | 38 +++++++++++++++++-- clippy_lints/src/await_holding_invalid.rs | 16 +++----- clippy_lints/src/disallowed_macros.rs | 13 ++----- clippy_lints/src/disallowed_methods.rs | 14 +++---- .../clippy.toml | 4 ++ .../replaceable_disallowed_methods.fixed | 8 ++++ .../replaceable_disallowed_methods.rs | 8 ++++ .../replaceable_disallowed_methods.stderr | 17 +++++++++ 8 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 tests/ui-toml/toml_replaceable_disallowed_methods/clippy.toml create mode 100644 tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed create mode 100644 tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs create mode 100644 tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index c949db9109de..70d9073b59ca 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -1,6 +1,8 @@ use clippy_utils::def_path_def_ids; +use rustc_errors::{Applicability, Diag}; use rustc_hir::def_id::DefIdMap; use rustc_middle::ty::TyCtxt; +use rustc_span::Span; use serde::de::{self, Deserializer, Visitor}; use serde::{Deserialize, Serialize, ser}; use std::collections::HashMap; @@ -16,7 +18,11 @@ pub struct Rename { #[serde(untagged)] pub enum DisallowedPath { Simple(String), - WithReason { path: String, reason: Option }, + WithReason { + path: String, + reason: Option, + replacement: Option, + }, } impl DisallowedPath { @@ -26,23 +32,47 @@ impl DisallowedPath { path } + pub fn diag_amendment(&self, span: Span) -> impl FnOnce(&mut Diag<'_, ()>) + use<'_> { + move |diag| { + if let Some(replacement) = self.replacement() { + diag.span_suggestion( + span, + self.reason().map_or_else(|| String::from("use"), ToOwned::to_owned), + replacement, + Applicability::MachineApplicable, + ); + } else if let Some(reason) = self.reason() { + diag.note(reason.to_owned()); + } + } + } + pub fn reason(&self) -> Option<&str> { match &self { Self::WithReason { reason, .. } => reason.as_deref(), Self::Simple(_) => None, } } + + fn replacement(&self) -> Option<&str> { + match &self { + Self::WithReason { replacement, .. } => replacement.as_deref(), + Self::Simple(_) => None, + } + } } /// Creates a map of disallowed items to the reason they were disallowed. pub fn create_disallowed_map( tcx: TyCtxt<'_>, disallowed: &'static [DisallowedPath], -) -> DefIdMap<(&'static str, Option<&'static str>)> { +) -> DefIdMap<(&'static str, &'static DisallowedPath)> { disallowed .iter() - .map(|x| (x.path(), x.path().split("::").collect::>(), x.reason())) - .flat_map(|(name, path, reason)| def_path_def_ids(tcx, &path).map(move |id| (id, (name, reason)))) + .map(|x| (x.path(), x.path().split("::").collect::>(), x)) + .flat_map(|(name, path, disallowed_path)| { + def_path_def_ids(tcx, &path).map(move |id| (id, (name, disallowed_path))) + }) .collect() } diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 2eb0566bf9a6..3ae7ab969150 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::create_disallowed_map; +use clippy_config::types::{DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_hir as hir; @@ -174,7 +174,7 @@ declare_clippy_lint! { impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]); pub struct AwaitHolding { - def_ids: DefIdMap<(&'static str, Option<&'static str>)>, + def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>, } impl AwaitHolding { @@ -247,25 +247,21 @@ impl AwaitHolding { ); }, ); - } else if let Some(&(path, reason)) = self.def_ids.get(&adt.did()) { - emit_invalid_type(cx, ty_cause.source_info.span, path, reason); + } else if let Some(&(path, disallowed_path)) = self.def_ids.get(&adt.did()) { + emit_invalid_type(cx, ty_cause.source_info.span, path, disallowed_path); } } } } } -fn emit_invalid_type(cx: &LateContext<'_>, span: Span, path: &'static str, reason: Option<&'static str>) { +fn emit_invalid_type(cx: &LateContext<'_>, span: Span, path: &'static str, disallowed_path: &'static DisallowedPath) { span_lint_and_then( cx, AWAIT_HOLDING_INVALID_TYPE, span, format!("holding a disallowed type across an await point `{path}`"), - |diag| { - if let Some(reason) = reason { - diag.note(reason); - } - }, + disallowed_path.diag_amendment(span), ); } diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs index a0cb36f88dc0..fe0870e8282f 100644 --- a/clippy_lints/src/disallowed_macros.rs +++ b/clippy_lints/src/disallowed_macros.rs @@ -1,9 +1,8 @@ use clippy_config::Conf; -use clippy_config::types::create_disallowed_map; +use clippy_config::types::{DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::macros::macro_backtrace; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::Diag; use rustc_hir::def_id::DefIdMap; use rustc_hir::{ Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty, @@ -60,7 +59,7 @@ declare_clippy_lint! { } pub struct DisallowedMacros { - disallowed: DefIdMap<(&'static str, Option<&'static str>)>, + disallowed: DefIdMap<(&'static str, &'static DisallowedPath)>, seen: FxHashSet, // Track the most recently seen node that can have a `derive` attribute. // Needed to use the correct lint level. @@ -91,13 +90,9 @@ impl DisallowedMacros { return; } - if let Some(&(path, reason)) = self.disallowed.get(&mac.def_id) { + if let Some(&(path, disallowed_path)) = self.disallowed.get(&mac.def_id) { let msg = format!("use of a disallowed macro `{path}`"); - let add_note = |diag: &mut Diag<'_, _>| { - if let Some(reason) = reason { - diag.note(reason); - } - }; + let add_note = disallowed_path.diag_amendment(mac.span); if matches!(mac.kind, MacroKind::Derive) && let Some(derive_src) = derive_src { diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index 1e660b1957a4..0cd9ea13f2e5 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::create_disallowed_map; +use clippy_config::types::{DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefIdMap; @@ -31,6 +31,8 @@ declare_clippy_lint! { /// # When using an inline table, can add a `reason` for why the method /// # is disallowed. /// { path = "std::vec::Vec::leak", reason = "no leaking memory" }, + /// # Can also add a `replacement` that will be offered as a suggestion. + /// { path = "std::sync::Mutex::new", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex::new" }, /// ] /// ``` /// @@ -58,7 +60,7 @@ declare_clippy_lint! { } pub struct DisallowedMethods { - disallowed: DefIdMap<(&'static str, Option<&'static str>)>, + disallowed: DefIdMap<(&'static str, &'static DisallowedPath)>, } impl DisallowedMethods { @@ -85,17 +87,13 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { }, _ => return, }; - if let Some(&(path, reason)) = self.disallowed.get(&id) { + if let Some(&(path, disallowed_path)) = self.disallowed.get(&id) { span_lint_and_then( cx, DISALLOWED_METHODS, span, format!("use of a disallowed method `{path}`"), - |diag| { - if let Some(reason) = reason { - diag.note(reason); - } - }, + disallowed_path.diag_amendment(span), ); } } diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/clippy.toml b/tests/ui-toml/toml_replaceable_disallowed_methods/clippy.toml new file mode 100644 index 000000000000..dc393f1355b5 --- /dev/null +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/clippy.toml @@ -0,0 +1,4 @@ +disallowed-methods = [ + { path = "replaceable_disallowed_methods::bad", replacement = "good" }, + { path = "replaceable_disallowed_methods::questionable", replacement = "good", reason = "a better function exists" }, +] diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed new file mode 100644 index 000000000000..dae7ce76ba28 --- /dev/null +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed @@ -0,0 +1,8 @@ +fn bad() {} +fn questionable() {} +fn good() {} + +fn main() { + good(); + good(); +} diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs new file mode 100644 index 000000000000..53678ffdf1c9 --- /dev/null +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs @@ -0,0 +1,8 @@ +fn bad() {} +fn questionable() {} +fn good() {} + +fn main() { + bad(); + questionable(); +} diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr new file mode 100644 index 000000000000..b85592029420 --- /dev/null +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr @@ -0,0 +1,17 @@ +error: use of a disallowed method `replaceable_disallowed_methods::bad` + --> tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs:6:5 + | +LL | bad(); + | ^^^ help: use: `good` + | + = note: `-D clippy::disallowed-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` + +error: use of a disallowed method `replaceable_disallowed_methods::questionable` + --> tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs:7:5 + | +LL | questionable(); + | ^^^^^^^^^^^^ help: a better function exists: `good` + +error: aborting due to 2 previous errors + From d0f35777205090e24d5822e668cc280cab78e4ec Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 13 Nov 2024 10:16:59 -0500 Subject: [PATCH 003/161] Properly handle `disallowed_types` --- clippy_config/src/types.rs | 2 +- clippy_lints/src/disallowed_types.rs | 25 ++++++++----------- .../replaceable_disallowed_types/clippy.toml | 3 +++ .../replaceable_disallowed_types.fixed | 16 ++++++++++++ .../replaceable_disallowed_types.rs | 16 ++++++++++++ .../replaceable_disallowed_types.stderr | 11 ++++++++ 6 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 tests/ui-toml/replaceable_disallowed_types/clippy.toml create mode 100644 tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed create mode 100644 tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs create mode 100644 tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index 70d9073b59ca..122fdca726d5 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -47,7 +47,7 @@ impl DisallowedPath { } } - pub fn reason(&self) -> Option<&str> { + fn reason(&self) -> Option<&str> { match &self { Self::WithReason { reason, .. } => reason.as_deref(), Self::Simple(_) => None, diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index 3265404f2b27..a34ec4616e51 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -1,4 +1,5 @@ use clippy_config::Conf; +use clippy_config::types::DisallowedPath; use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; @@ -31,7 +32,8 @@ declare_clippy_lint! { /// # When using an inline table, can add a `reason` for why the type /// # is disallowed. /// { path = "std::net::Ipv4Addr", reason = "no IPv4 allowed" }, - /// ] + /// # Can also add a `replacement` that will be offered as a suggestion. + /// { path = "std::sync::Mutex", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex" }, /// ] /// ``` /// /// ```rust,ignore @@ -51,24 +53,23 @@ declare_clippy_lint! { } pub struct DisallowedTypes { - def_ids: DefIdMap<(&'static str, Option<&'static str>)>, - prim_tys: FxHashMap)>, + def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>, + prim_tys: FxHashMap, } impl DisallowedTypes { pub fn new(tcx: TyCtxt<'_>, conf: &'static Conf) -> Self { let mut def_ids = DefIdMap::default(); let mut prim_tys = FxHashMap::default(); - for x in &conf.disallowed_types { - let path: Vec<_> = x.path().split("::").collect::>(); - let reason = x.reason(); + for disallowed_path in &conf.disallowed_types { + let path: Vec<_> = disallowed_path.path().split("::").collect::>(); for res in clippy_utils::def_path_res(tcx, &path) { match res { Res::Def(_, id) => { - def_ids.insert(id, (x.path(), reason)); + def_ids.insert(id, (disallowed_path.path(), disallowed_path)); }, Res::PrimTy(ty) => { - prim_tys.insert(ty, (x.path(), reason)); + prim_tys.insert(ty, (disallowed_path.path(), disallowed_path)); }, _ => {}, } @@ -78,7 +79,7 @@ impl DisallowedTypes { } fn check_res_emit(&self, cx: &LateContext<'_>, res: &Res, span: Span) { - let (path, reason) = match res { + let (path, disallowed_path) = match res { Res::Def(_, did) if let Some(&x) = self.def_ids.get(did) => x, Res::PrimTy(prim) if let Some(&x) = self.prim_tys.get(prim) => x, _ => return, @@ -88,11 +89,7 @@ impl DisallowedTypes { DISALLOWED_TYPES, span, format!("use of a disallowed type `{path}`"), - |diag| { - if let Some(reason) = reason { - diag.note(reason); - } - }, + disallowed_path.diag_amendment(span), ); } } diff --git a/tests/ui-toml/replaceable_disallowed_types/clippy.toml b/tests/ui-toml/replaceable_disallowed_types/clippy.toml new file mode 100644 index 000000000000..a08a2f00f506 --- /dev/null +++ b/tests/ui-toml/replaceable_disallowed_types/clippy.toml @@ -0,0 +1,3 @@ +disallowed-types = [ + { path = "std::string::String", replacement = "wrapper::String" }, +] diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed new file mode 100644 index 000000000000..6546981bd81c --- /dev/null +++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed @@ -0,0 +1,16 @@ +#![warn(clippy::disallowed_types)] + +#[allow(clippy::disallowed_types)] +mod wrapper { + pub struct String(std::string::String); + + impl From<&str> for String { + fn from(value: &str) -> Self { + Self(std::string::String::from(value)) + } + } +} + +fn main() { + let _ = wrapper::String::from("x"); +} diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs new file mode 100644 index 000000000000..d76f1af481de --- /dev/null +++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs @@ -0,0 +1,16 @@ +#![warn(clippy::disallowed_types)] + +#[allow(clippy::disallowed_types)] +mod wrapper { + pub struct String(std::string::String); + + impl From<&str> for String { + fn from(value: &str) -> Self { + Self(std::string::String::from(value)) + } + } +} + +fn main() { + let _ = String::from("x"); +} diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr new file mode 100644 index 000000000000..bb63e6970a16 --- /dev/null +++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr @@ -0,0 +1,11 @@ +error: use of a disallowed type `std::string::String` + --> tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs:15:13 + | +LL | let _ = String::from("x"); + | ^^^^^^ help: use: `wrapper::String` + | + = note: `-D clippy::disallowed-types` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]` + +error: aborting due to 1 previous error + From b97ad4eccdfa8b360df243ecf21eec1fd05cb92a Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 13 Nov 2024 18:34:08 -0500 Subject: [PATCH 004/161] Add const parameter `REPLACEMENT_ALLOWED` to `DisallowedPath` --- clippy_config/src/conf.rs | 2 +- clippy_config/src/types.rs | 73 +++++++++++++------ clippy_lints/src/await_holding_invalid.rs | 9 ++- .../await_holding_invalid_type.rs | 1 + .../await_holding_invalid_type.stderr | 11 +++ .../clippy.toml | 3 + 6 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs create mode 100644 tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.stderr create mode 100644 tests/ui-toml/await_holding_invalid_type_with_replacement/clippy.toml diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index c3b1fc83af0a..82ab08530e1a 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -445,7 +445,7 @@ define_Conf! { avoid_breaking_exported_api: bool = true, /// The list of types which may not be held across an await point. #[lints(await_holding_invalid_type)] - await_holding_invalid_types: Vec = Vec::new(), + await_holding_invalid_types: Vec> = Vec::new(), /// DEPRECATED LINT: BLACKLISTED_NAME. /// /// Use the Disallowed Names lint instead diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index 122fdca726d5..6a0f7aa75f25 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -14,9 +14,33 @@ pub struct Rename { pub rename: String, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Serialize)] +pub struct DisallowedPath { + path: String, + reason: Option, + replacement: Option, +} + +impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let enum_ = DisallowedPathEnum::deserialize(deserializer)?; + if !REPLACEMENT_ALLOWED && enum_.replacement().is_some() { + return Err(de::Error::custom("replacement not allowed for this configuration")); + } + Ok(Self { + path: enum_.path().to_owned(), + reason: enum_.reason().map(ToOwned::to_owned), + replacement: enum_.replacement().map(ToOwned::to_owned), + }) + } +} + +#[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] -pub enum DisallowedPath { +pub enum DisallowedPathEnum { Simple(String), WithReason { path: String, @@ -25,28 +49,34 @@ pub enum DisallowedPath { }, } -impl DisallowedPath { +impl DisallowedPath { + pub fn path(&self) -> &str { + &self.path + } + + pub fn diag_amendment(&self, span: Span) -> impl FnOnce(&mut Diag<'_, ()>) + use<'_, REPLACEMENT_ALLOWED> { + move |diag| { + if let Some(replacement) = &self.replacement { + diag.span_suggestion( + span, + self.reason.as_ref().map_or_else(|| String::from("use"), Clone::clone), + replacement, + Applicability::MachineApplicable, + ); + } else if let Some(reason) = &self.reason { + diag.note(reason.clone()); + } + } + } +} + +impl DisallowedPathEnum { pub fn path(&self) -> &str { let (Self::Simple(path) | Self::WithReason { path, .. }) = self; path } - pub fn diag_amendment(&self, span: Span) -> impl FnOnce(&mut Diag<'_, ()>) + use<'_> { - move |diag| { - if let Some(replacement) = self.replacement() { - diag.span_suggestion( - span, - self.reason().map_or_else(|| String::from("use"), ToOwned::to_owned), - replacement, - Applicability::MachineApplicable, - ); - } else if let Some(reason) = self.reason() { - diag.note(reason.to_owned()); - } - } - } - fn reason(&self) -> Option<&str> { match &self { Self::WithReason { reason, .. } => reason.as_deref(), @@ -63,10 +93,10 @@ impl DisallowedPath { } /// Creates a map of disallowed items to the reason they were disallowed. -pub fn create_disallowed_map( +pub fn create_disallowed_map( tcx: TyCtxt<'_>, - disallowed: &'static [DisallowedPath], -) -> DefIdMap<(&'static str, &'static DisallowedPath)> { + disallowed: &'static [DisallowedPath], +) -> DefIdMap<(&'static str, &'static DisallowedPath)> { disallowed .iter() .map(|x| (x.path(), x.path().split("::").collect::>(), x)) @@ -466,7 +496,6 @@ macro_rules! unimplemented_serialize { } unimplemented_serialize! { - DisallowedPath, Rename, MacroMatcher, } diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 3ae7ab969150..bf7f81f2f3e6 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -174,7 +174,7 @@ declare_clippy_lint! { impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]); pub struct AwaitHolding { - def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>, + def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>, } impl AwaitHolding { @@ -255,7 +255,12 @@ impl AwaitHolding { } } -fn emit_invalid_type(cx: &LateContext<'_>, span: Span, path: &'static str, disallowed_path: &'static DisallowedPath) { +fn emit_invalid_type( + cx: &LateContext<'_>, + span: Span, + path: &'static str, + disallowed_path: &'static DisallowedPath, +) { span_lint_and_then( cx, AWAIT_HOLDING_INVALID_TYPE, diff --git a/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs new file mode 100644 index 000000000000..f328e4d9d04c --- /dev/null +++ b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.stderr new file mode 100644 index 000000000000..86e30409af06 --- /dev/null +++ b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.stderr @@ -0,0 +1,11 @@ +error: error reading Clippy's configuration file: replacement not allowed for this configuration + --> $DIR/tests/ui-toml/await_holding_invalid_type_with_replacement/clippy.toml:1:31 + | +LL | await-holding-invalid-types = [ + | _______________________________^ +LL | | { path = "std::string::String", replacement = "std::net::Ipv4Addr" }, +LL | | ] + | |_^ + +error: aborting due to 1 previous error + diff --git a/tests/ui-toml/await_holding_invalid_type_with_replacement/clippy.toml b/tests/ui-toml/await_holding_invalid_type_with_replacement/clippy.toml new file mode 100644 index 000000000000..f6bc59672ed7 --- /dev/null +++ b/tests/ui-toml/await_holding_invalid_type_with_replacement/clippy.toml @@ -0,0 +1,3 @@ +await-holding-invalid-types = [ + { path = "std::string::String", replacement = "std::net::Ipv4Addr" }, +] From fef10d42a330a8d6f746e07f1307124520df3b92 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 18 Dec 2024 18:49:47 -0500 Subject: [PATCH 005/161] Use two structs rather than a const generic --- clippy_config/src/conf.rs | 8 +-- clippy_config/src/types.rs | 82 +++++++++++++++++------ clippy_lints/src/await_holding_invalid.rs | 8 +-- clippy_lints/src/disallowed_macros.rs | 9 +-- clippy_lints/src/disallowed_methods.rs | 4 +- clippy_lints/src/disallowed_types.rs | 4 +- 6 files changed, 78 insertions(+), 37 deletions(-) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 82ab08530e1a..7bfd32b32cd6 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -1,8 +1,8 @@ use crate::ClippyConfiguration; use crate::types::{ - DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering, - SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, - SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds, + DisallowedPath, DisallowedPathWithoutReplacement, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, + Rename, SourceItemOrdering, SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, + SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds, }; use clippy_utils::msrvs::Msrv; use rustc_errors::Applicability; @@ -445,7 +445,7 @@ define_Conf! { avoid_breaking_exported_api: bool = true, /// The list of types which may not be held across an await point. #[lints(await_holding_invalid_type)] - await_holding_invalid_types: Vec> = Vec::new(), + await_holding_invalid_types: Vec = Vec::new(), /// DEPRECATED LINT: BLACKLISTED_NAME. /// /// Use the Disallowed Names lint instead diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index 6a0f7aa75f25..ef3d46892a47 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -15,21 +15,40 @@ pub struct Rename { } #[derive(Debug, Serialize)] -pub struct DisallowedPath { +pub struct DisallowedPathWithoutReplacement { + path: String, + reason: Option, +} + +#[derive(Clone, Debug, Serialize)] +pub struct DisallowedPath { path: String, reason: Option, replacement: Option, } -impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath { +impl<'de> Deserialize<'de> for DisallowedPathWithoutReplacement { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let enum_ = DisallowedPathEnum::deserialize(deserializer)?; - if !REPLACEMENT_ALLOWED && enum_.replacement().is_some() { + if enum_.replacement().is_some() { return Err(de::Error::custom("replacement not allowed for this configuration")); } + Ok(Self { + path: enum_.path().to_owned(), + reason: enum_.reason().map(ToOwned::to_owned), + }) + } +} + +impl<'de> Deserialize<'de> for DisallowedPath { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let enum_ = DisallowedPathEnum::deserialize(deserializer)?; Ok(Self { path: enum_.path().to_owned(), reason: enum_.reason().map(ToOwned::to_owned), @@ -49,24 +68,45 @@ pub enum DisallowedPathEnum { }, } -impl DisallowedPath { - pub fn path(&self) -> &str { +pub trait AmendDiag { + fn path(&self) -> &str; + fn reason(&self) -> Option<&str>; + fn replacement(&self) -> Option<&str>; + fn amend_diag(&self, span: Span, diag: &mut Diag<'_, ()>) { + if let Some(replacement) = &self.replacement() { + diag.span_suggestion( + span, + self.reason().map_or_else(|| String::from("use"), ToOwned::to_owned), + replacement, + Applicability::MachineApplicable, + ); + } else if let Some(reason) = self.reason() { + diag.note(reason.to_owned()); + } + } +} + +impl AmendDiag for DisallowedPathWithoutReplacement { + fn path(&self) -> &str { &self.path } + fn reason(&self) -> Option<&str> { + self.reason.as_deref() + } + fn replacement(&self) -> Option<&str> { + None + } +} - pub fn diag_amendment(&self, span: Span) -> impl FnOnce(&mut Diag<'_, ()>) + use<'_, REPLACEMENT_ALLOWED> { - move |diag| { - if let Some(replacement) = &self.replacement { - diag.span_suggestion( - span, - self.reason.as_ref().map_or_else(|| String::from("use"), Clone::clone), - replacement, - Applicability::MachineApplicable, - ); - } else if let Some(reason) = &self.reason { - diag.note(reason.clone()); - } - } +impl AmendDiag for DisallowedPath { + fn path(&self) -> &str { + &self.path + } + fn reason(&self) -> Option<&str> { + self.reason.as_deref() + } + fn replacement(&self) -> Option<&str> { + self.replacement.as_deref() } } @@ -93,10 +133,10 @@ impl DisallowedPathEnum { } /// Creates a map of disallowed items to the reason they were disallowed. -pub fn create_disallowed_map( +pub fn create_disallowed_map( tcx: TyCtxt<'_>, - disallowed: &'static [DisallowedPath], -) -> DefIdMap<(&'static str, &'static DisallowedPath)> { + disallowed: &'static [T], +) -> DefIdMap<(&'static str, &'static T)> { disallowed .iter() .map(|x| (x.path(), x.path().split("::").collect::>(), x)) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index bf7f81f2f3e6..3eb87e05a236 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{DisallowedPath, create_disallowed_map}; +use clippy_config::types::{AmendDiag, DisallowedPathWithoutReplacement, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_hir as hir; @@ -174,7 +174,7 @@ declare_clippy_lint! { impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]); pub struct AwaitHolding { - def_ids: DefIdMap<(&'static str, &'static DisallowedPath)>, + def_ids: DefIdMap<(&'static str, &'static DisallowedPathWithoutReplacement)>, } impl AwaitHolding { @@ -259,14 +259,14 @@ fn emit_invalid_type( cx: &LateContext<'_>, span: Span, path: &'static str, - disallowed_path: &'static DisallowedPath, + disallowed_path: &'static DisallowedPathWithoutReplacement, ) { span_lint_and_then( cx, AWAIT_HOLDING_INVALID_TYPE, span, format!("holding a disallowed type across an await point `{path}`"), - disallowed_path.diag_amendment(span), + |diag| disallowed_path.amend_diag(span, diag), ); } diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs index fe0870e8282f..629bf416515c 100644 --- a/clippy_lints/src/disallowed_macros.rs +++ b/clippy_lints/src/disallowed_macros.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{DisallowedPath, create_disallowed_map}; +use clippy_config::types::{AmendDiag, DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::macros::macro_backtrace; use rustc_data_structures::fx::FxHashSet; @@ -92,7 +92,6 @@ impl DisallowedMacros { if let Some(&(path, disallowed_path)) = self.disallowed.get(&mac.def_id) { let msg = format!("use of a disallowed macro `{path}`"); - let add_note = disallowed_path.diag_amendment(mac.span); if matches!(mac.kind, MacroKind::Derive) && let Some(derive_src) = derive_src { @@ -102,10 +101,12 @@ impl DisallowedMacros { cx.tcx.local_def_id_to_hir_id(derive_src.def_id), mac.span, msg, - add_note, + |diag| disallowed_path.amend_diag(mac.span, diag), ); } else { - span_lint_and_then(cx, DISALLOWED_MACROS, mac.span, msg, add_note); + span_lint_and_then(cx, DISALLOWED_MACROS, mac.span, msg, |diag| { + disallowed_path.amend_diag(mac.span, diag); + }); } } } diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index 0cd9ea13f2e5..e6503b310537 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{DisallowedPath, create_disallowed_map}; +use clippy_config::types::{AmendDiag, DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefIdMap; @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { DISALLOWED_METHODS, span, format!("use of a disallowed method `{path}`"), - disallowed_path.diag_amendment(span), + |diag| disallowed_path.amend_diag(span, diag), ); } } diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index a34ec4616e51..15e5b8bb4c5a 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::DisallowedPath; +use clippy_config::types::{AmendDiag, DisallowedPath}; use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; @@ -89,7 +89,7 @@ impl DisallowedTypes { DISALLOWED_TYPES, span, format!("use of a disallowed type `{path}`"), - disallowed_path.diag_amendment(span), + |diag| disallowed_path.amend_diag(span, diag), ); } } From 17f9344a9689d57813d56ee35d95c97f05e6c5e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 6 Jan 2025 19:03:55 +0100 Subject: [PATCH 006/161] Fix `literal_string_with_formatting_args` lint emitted when it should not --- .../literal_string_with_formatting_args.rs | 2 +- .../ui/literal_string_with_formatting_arg.rs | 19 ++++++++++++ .../literal_string_with_formatting_arg.stderr | 30 +++++++++++-------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/literal_string_with_formatting_args.rs b/clippy_lints/src/literal_string_with_formatting_args.rs index 49353a1b76be..4c8063ee6e63 100644 --- a/clippy_lints/src/literal_string_with_formatting_args.rs +++ b/clippy_lints/src/literal_string_with_formatting_args.rs @@ -81,7 +81,7 @@ fn emit_lint(cx: &LateContext<'_>, expr: &Expr<'_>, spans: &[(Span, Option for LiteralStringWithFormattingArg { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if expr.span.from_expansion() { + if expr.span.from_expansion() || expr.span.is_dummy() { return; } if let ExprKind::Lit(lit) = expr.kind { diff --git a/tests/ui/literal_string_with_formatting_arg.rs b/tests/ui/literal_string_with_formatting_arg.rs index f257c66f59d3..c9731e592e59 100644 --- a/tests/ui/literal_string_with_formatting_arg.rs +++ b/tests/ui/literal_string_with_formatting_arg.rs @@ -1,6 +1,24 @@ #![warn(clippy::literal_string_with_formatting_args)] #![allow(clippy::unnecessary_literal_unwrap)] +// Regression test for . +// It's not supposed to emit the lint in this case (in `assert!` expansion). +fn compiler_macro() { + fn parse(_: &str) -> Result<(), i32> { + unimplemented!() + } + + assert!( + parse( + #[allow(clippy::literal_string_with_formatting_args)] + "foo {:}" + ) + .is_err() + ); + let value = 0; + assert!(format!("{value}").is_ascii()); +} + fn main() { let x: Option = None; let y = "hello"; @@ -13,6 +31,7 @@ fn main() { x.expect(r"{y:?} {y:?} "); //~ literal_string_with_formatting_args x.expect(r"{y:?} y:?}"); //~ literal_string_with_formatting_args x.expect(r##" {y:?} {y:?} "##); //~ literal_string_with_formatting_args + assert!("{y}".is_ascii()); //~ literal_string_with_formatting_args // Ensure that it doesn't try to go in the middle of a unicode character. x.expect("———{:?}"); //~ literal_string_with_formatting_args diff --git a/tests/ui/literal_string_with_formatting_arg.stderr b/tests/ui/literal_string_with_formatting_arg.stderr index 32a84f600da7..1898f4f57b82 100644 --- a/tests/ui/literal_string_with_formatting_arg.stderr +++ b/tests/ui/literal_string_with_formatting_arg.stderr @@ -1,5 +1,5 @@ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:7:15 + --> tests/ui/literal_string_with_formatting_arg.rs:25:15 | LL | x.expect("{y} {}"); | ^^^ @@ -8,64 +8,70 @@ LL | x.expect("{y} {}"); = help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_args)]` error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:8:16 + --> tests/ui/literal_string_with_formatting_arg.rs:26:16 | LL | x.expect(" {y} bla"); | ^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:9:15 + --> tests/ui/literal_string_with_formatting_arg.rs:27:15 | LL | x.expect("{:?}"); | ^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:10:15 + --> tests/ui/literal_string_with_formatting_arg.rs:28:15 | LL | x.expect("{y:?}"); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:11:16 + --> tests/ui/literal_string_with_formatting_arg.rs:29:16 | LL | x.expect(" {y:?} {y:?} "); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:12:23 + --> tests/ui/literal_string_with_formatting_arg.rs:30:23 | LL | x.expect(" {y:..} {y:?} "); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:13:16 + --> tests/ui/literal_string_with_formatting_arg.rs:31:16 | LL | x.expect(r"{y:?} {y:?} "); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:14:16 + --> tests/ui/literal_string_with_formatting_arg.rs:32:16 | LL | x.expect(r"{y:?} y:?}"); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:15:19 + --> tests/ui/literal_string_with_formatting_arg.rs:33:19 | LL | x.expect(r##" {y:?} {y:?} "##); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:17:18 + --> tests/ui/literal_string_with_formatting_arg.rs:34:14 + | +LL | assert!("{y}".is_ascii()); + | ^^^ + +error: this looks like a formatting argument but it is not part of a formatting macro + --> tests/ui/literal_string_with_formatting_arg.rs:36:18 | LL | x.expect("———{:?}"); | ^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:27:19 + --> tests/ui/literal_string_with_formatting_arg.rs:46:19 | LL | x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint | ^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors From a7fb37c1d832bea651f29b4676a816635dc11894 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 7 Jan 2025 15:55:41 +0100 Subject: [PATCH 007/161] Correctly handle expanded macros for `literal_string_with_formatting_args` lint --- .../src/literal_string_with_formatting_args.rs | 9 +++++++++ tests/ui/{literal_string_with_formatting_args}.rs | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/ui/{literal_string_with_formatting_args}.rs diff --git a/clippy_lints/src/literal_string_with_formatting_args.rs b/clippy_lints/src/literal_string_with_formatting_args.rs index 4c8063ee6e63..c0d016ce08b0 100644 --- a/clippy_lints/src/literal_string_with_formatting_args.rs +++ b/clippy_lints/src/literal_string_with_formatting_args.rs @@ -8,6 +8,7 @@ use rustc_span::{BytePos, Span}; use clippy_utils::diagnostics::span_lint; use clippy_utils::mir::enclosing_mir; +use clippy_utils::source::snippet_opt; declare_clippy_lint! { /// ### What it does @@ -95,7 +96,15 @@ impl LateLintPass<'_> for LiteralStringWithFormattingArg { }, _ => return, }; + let Some(snippet) = snippet_opt(cx, expr.span) else { + return; + }; let fmt_str = symbol.as_str(); + // If the literal has been generated by the macro, the snippet should not contain it, + // allowing us to skip it. + if !snippet.contains(fmt_str) { + return; + } let lo = expr.span.lo(); let mut current = fmt_str; let mut diff_len = 0; diff --git a/tests/ui/{literal_string_with_formatting_args}.rs b/tests/ui/{literal_string_with_formatting_args}.rs new file mode 100644 index 000000000000..8a06d0c7b360 --- /dev/null +++ b/tests/ui/{literal_string_with_formatting_args}.rs @@ -0,0 +1,14 @@ +// Regression test for . +// The `dbg` macro generates a literal with the name of the current file, so +// we need to ensure the lint is not emitted in this case. + +#![crate_name = "foo"] +#![allow(unused)] +#![warn(clippy::literal_string_with_formatting_args)] + +fn another_bad() { + let literal_string_with_formatting_args = 0; + dbg!("something"); +} + +fn main() {} From 00104a4167d2dd295e3639163dea393f7cd310d1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2025 16:42:56 +0100 Subject: [PATCH 008/161] Add more detailed explanations for #13885 regression test --- .../{literal_string_with_formatting_args}.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/ui/{literal_string_with_formatting_args}.rs b/tests/ui/{literal_string_with_formatting_args}.rs index 8a06d0c7b360..0f5b36e67503 100644 --- a/tests/ui/{literal_string_with_formatting_args}.rs +++ b/tests/ui/{literal_string_with_formatting_args}.rs @@ -2,6 +2,38 @@ // The `dbg` macro generates a literal with the name of the current file, so // we need to ensure the lint is not emitted in this case. +// Clippy sets `-Zflatten_format_args=no`, which changes the default behavior of how format args +// are lowered and only that one has this non-macro span. Adding the flag makes it repro on +// godbolt and shows a root context span for the file name string. +// +// So instead of having: +// +// ``` +// Lit( +// Spanned { +// node: Str( +// "[/app/example.rs:2:5] \"something\" = ", +// Cooked, +// ), +// span: /rustc/eb54a50837ad4bcc9842924f27e7287ca66e294c/library/std/src/macros.rs:365:35: 365:58 (#4), +// }, +// ), +// ``` +// +// We get: +// +// ``` +// Lit( +// Spanned { +// node: Str( +// "/app/example.rs", +// Cooked, +// ), +// span: /app/example.rs:2:5: 2:22 (#0), +// }, +// ) +// ``` + #![crate_name = "foo"] #![allow(unused)] #![warn(clippy::literal_string_with_formatting_args)] From e35330cabeaf312cefb4370560fd473d47eabe2d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2025 16:52:46 +0100 Subject: [PATCH 009/161] Use `is_from_proc_macro` instead of checking if the snippet contains the literal --- .../src/literal_string_with_formatting_args.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/literal_string_with_formatting_args.rs b/clippy_lints/src/literal_string_with_formatting_args.rs index c0d016ce08b0..21066a00eaf5 100644 --- a/clippy_lints/src/literal_string_with_formatting_args.rs +++ b/clippy_lints/src/literal_string_with_formatting_args.rs @@ -7,8 +7,8 @@ use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Span}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_from_proc_macro; use clippy_utils::mir::enclosing_mir; -use clippy_utils::source::snippet_opt; declare_clippy_lint! { /// ### What it does @@ -80,8 +80,8 @@ fn emit_lint(cx: &LateContext<'_>, expr: &Expr<'_>, spans: &[(Span, Option for LiteralStringWithFormattingArg { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for LiteralStringWithFormattingArg { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { if expr.span.from_expansion() || expr.span.is_dummy() { return; } @@ -96,15 +96,10 @@ impl LateLintPass<'_> for LiteralStringWithFormattingArg { }, _ => return, }; - let Some(snippet) = snippet_opt(cx, expr.span) else { - return; - }; - let fmt_str = symbol.as_str(); - // If the literal has been generated by the macro, the snippet should not contain it, - // allowing us to skip it. - if !snippet.contains(fmt_str) { + if is_from_proc_macro(cx, expr) { return; } + let fmt_str = symbol.as_str(); let lo = expr.span.lo(); let mut current = fmt_str; let mut diff_len = 0; From 3921ed67b20a4541b1fa378de95c1dbe3d5cc5ef Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 16 Jan 2025 18:12:36 +0100 Subject: [PATCH 010/161] [`path_buf_push_overwrite`]: mark suggestion as `MaybeIncorrect` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Proposing to replace ```rust let mut x = PathBuf::from("/foo"); x.push("/bar"); ``` by ```rust let mut x = PathBuf::from("/foo"); x.push("bar"); ``` changes the content of `x` (`/bar` ⇒ `/foo/bar`). --- clippy_lints/src/methods/path_buf_push_overwrite.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/path_buf_push_overwrite.rs b/clippy_lints/src/methods/path_buf_push_overwrite.rs index 2d3007e50b81..38d9c5f16778 100644 --- a/clippy_lints/src/methods/path_buf_push_overwrite.rs +++ b/clippy_lints/src/methods/path_buf_push_overwrite.rs @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t "calling `push` with '/' or '\\' (file system root) will overwrite the previous path definition", "try", format!("\"{}\"", pushed_path_lit.trim_start_matches(['/', '\\'])), - Applicability::MachineApplicable, + Applicability::MaybeIncorrect, ); } } From 76bc88c40fb467dc211ea38b79e1d37bb987e632 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 15 Dec 2024 23:21:47 +0100 Subject: [PATCH 011/161] More tests for `large_enum_variant` --- tests/ui/large_enum_variant.32bit.stderr | 18 +++++++++++++++++- tests/ui/large_enum_variant.64bit.stderr | 18 +++++++++++++++++- tests/ui/large_enum_variant.rs | 15 +++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index ff4f1a7f312c..7edff0df10f8 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -276,5 +276,21 @@ help: consider boxing the large fields to reduce the total size of the enum LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 16 previous errors +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:158:1 + | +LL | / enum WithRecursion { +LL | | Large([u64; 64]), + | | ---------------- the largest variant contains at least 512 bytes +LL | | Recursive(Box), + | | ----------------------------- the second-largest variant contains at least 0 bytes +LL | | } + | |_^ the entire enum is at least 0 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<[u64; 64]>), + | ~~~~~~~~~~~~~~ + +error: aborting due to 17 previous errors diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index 805cb406f834..a52967d962f7 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -276,5 +276,21 @@ help: consider boxing the large fields to reduce the total size of the enum LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 16 previous errors +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:158:1 + | +LL | / enum WithRecursion { +LL | | Large([u64; 64]), + | | ---------------- the largest variant contains at least 512 bytes +LL | | Recursive(Box), + | | ----------------------------- the second-largest variant contains at least 0 bytes +LL | | } + | |_^ the entire enum is at least 0 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<[u64; 64]>), + | ~~~~~~~~~~~~~~ + +error: aborting due to 17 previous errors diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 3625c011dbfa..fec4a1ee79f2 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -155,6 +155,21 @@ enum LargeEnumOfConst { Error(PossiblyLargeEnumWithConst<256>), } +enum WithRecursion { + Large([u64; 64]), + Recursive(Box), +} + +enum WithRecursionAndGenerics { + Large([T; 64]), + Recursive(Box>), +} + +enum LargeEnumWithGenericsAndRecursive { + Ok(), + Error(WithRecursionAndGenerics), +} + fn main() { external!( enum LargeEnumInMacro { From 19ddb6922c6bd270b092d8be1ea64ce3d7a5b485 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 15 Dec 2024 23:21:47 +0100 Subject: [PATCH 012/161] Handle more cases in `is_normalizable` By assuming that a recursive type is normalizable within the deeper calls to `is_normalizable_helper()`, more cases can be handled by this function. In order to fix stack overflows, a recursion limit has also been added for recursive generic type instantiations. --- clippy_utils/src/ty/mod.rs | 16 ++++-- tests/ui/crashes/ice-10508a.rs | 19 ++++++++ tests/ui/crashes/ice-10508b.rs | 24 +++++++++ tests/ui/crashes/ice-10508c.rs | 7 +++ tests/ui/large_enum_variant.32bit.stderr | 22 +++++++-- tests/ui/large_enum_variant.64bit.stderr | 54 +++++++++++++++++++-- tests/ui/large_enum_variant.rs | 62 ++++++++++++++++++++++++ 7 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 tests/ui/crashes/ice-10508a.rs create mode 100644 tests/ui/crashes/ice-10508b.rs create mode 100644 tests/ui/crashes/ice-10508c.rs diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index 260d1b801e3d..45dff91e8773 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -351,20 +351,26 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { /// Checks if `Ty` is normalizable. This function is useful /// to avoid crashes on `layout_of`. pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool { - is_normalizable_helper(cx, param_env, ty, &mut FxHashMap::default()) + is_normalizable_helper(cx, param_env, ty, 0, &mut FxHashMap::default()) } fn is_normalizable_helper<'tcx>( cx: &LateContext<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, + depth: usize, cache: &mut FxHashMap, bool>, ) -> bool { if let Some(&cached_result) = cache.get(&ty) { return cached_result; } - // prevent recursive loops, false-negative is better than endless loop leading to stack overflow - cache.insert(ty, false); + if !cx.tcx.recursion_limit().value_within_limit(depth) { + return false; + } + // Prevent recursive loops by answering `true` to recursive requests with the same + // type. This will be adjusted when the outermost call analyzes all the type + // components. + cache.insert(ty, true); let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode()); let cause = ObligationCause::dummy(); let result = if infcx.at(&cause, param_env).query_normalize(ty).is_ok() { @@ -373,11 +379,11 @@ fn is_normalizable_helper<'tcx>( variant .fields .iter() - .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), cache)) + .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), depth + 1, cache)) }), _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { - is_normalizable_helper(cx, param_env, inner_ty, cache) + is_normalizable_helper(cx, param_env, inner_ty, depth + 1, cache) }, _ => true, // if inner_ty == ty, we've already checked it }), diff --git a/tests/ui/crashes/ice-10508a.rs b/tests/ui/crashes/ice-10508a.rs new file mode 100644 index 000000000000..f45057217b43 --- /dev/null +++ b/tests/ui/crashes/ice-10508a.rs @@ -0,0 +1,19 @@ +// Used to overflow in `is_normalizable` + +use std::marker::PhantomData; + +struct Node { + m: PhantomData<&'static T>, +} + +struct Digit { + elem: T, +} + +enum FingerTree { + Single(T), + + Deep(Digit, Box>>), +} + +fn main() {} diff --git a/tests/ui/crashes/ice-10508b.rs b/tests/ui/crashes/ice-10508b.rs new file mode 100644 index 000000000000..41d4f0234b94 --- /dev/null +++ b/tests/ui/crashes/ice-10508b.rs @@ -0,0 +1,24 @@ +use std::marker::PhantomData; + +struct Digit { + elem: T, +} + +struct Node { + m: PhantomData<&'static T>, +} + +enum FingerTree { + Single(T), + + Deep(Digit, Node>>), +} + +enum Wrapper { + Simple, + Other(FingerTree), +} + +fn main() { + let w = Some(Wrapper::Simple::); +} diff --git a/tests/ui/crashes/ice-10508c.rs b/tests/ui/crashes/ice-10508c.rs new file mode 100644 index 000000000000..fb84d85fd675 --- /dev/null +++ b/tests/ui/crashes/ice-10508c.rs @@ -0,0 +1,7 @@ +#[derive(Debug)] +struct S { + t: T, + s: Box>, +} + +fn main() {} diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index 7edff0df10f8..36f3d930b535 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -283,14 +283,30 @@ LL | / enum WithRecursion { LL | | Large([u64; 64]), | | ---------------- the largest variant contains at least 512 bytes LL | | Recursive(Box), - | | ----------------------------- the second-largest variant contains at least 0 bytes + | | ----------------------------- the second-largest variant contains at least 4 bytes LL | | } - | |_^ the entire enum is at least 0 bytes + | |_^ the entire enum is at least 516 bytes | help: consider boxing the large fields to reduce the total size of the enum | LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ -error: aborting due to 17 previous errors +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:168:1 + | +LL | / enum LargeEnumWithGenericsAndRecursive { +LL | | Ok(), + | | ---- the second-largest variant carries no data at all +LL | | Error(WithRecursionAndGenerics), + | | ------------------------------------ the largest variant contains at least 516 bytes +LL | | } + | |_^ the entire enum is at least 516 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Error(Box>), + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 18 previous errors diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index a52967d962f7..31576a5863fc 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -283,14 +283,62 @@ LL | / enum WithRecursion { LL | | Large([u64; 64]), | | ---------------- the largest variant contains at least 512 bytes LL | | Recursive(Box), - | | ----------------------------- the second-largest variant contains at least 0 bytes + | | ----------------------------- the second-largest variant contains at least 8 bytes LL | | } - | |_^ the entire enum is at least 0 bytes + | |_^ the entire enum is at least 520 bytes | help: consider boxing the large fields to reduce the total size of the enum | LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ -error: aborting due to 17 previous errors +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:168:1 + | +LL | / enum LargeEnumWithGenericsAndRecursive { +LL | | Ok(), + | | ---- the second-largest variant carries no data at all +LL | | Error(WithRecursionAndGenerics), + | | ------------------------------------ the largest variant contains at least 520 bytes +LL | | } + | |_^ the entire enum is at least 520 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Error(Box>), + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:203:5 + | +LL | / enum NoWarnings { +LL | | BigBoi(PublishWithBytes), + | | ------------------------ the largest variant contains at least 296 bytes +LL | | _SmallBoi(u8), + | | ------------- the second-largest variant contains at least 1 bytes +LL | | } + | |_____^ the entire enum is at least 296 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | BigBoi(Box), + | ~~~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> tests/ui/large_enum_variant.rs:208:5 + | +LL | / enum MakesClippyAngry { +LL | | BigBoi(PublishWithVec), + | | ---------------------- the largest variant contains at least 224 bytes +LL | | _SmallBoi(u8), + | | ------------- the second-largest variant contains at least 1 bytes +LL | | } + | |_____^ the entire enum is at least 224 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | BigBoi(Box), + | ~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 20 previous errors diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index fec4a1ee79f2..57722f63b225 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -178,3 +178,65 @@ fn main() { } ); } + +mod issue11915 { + use std::sync::atomic::AtomicPtr; + + pub struct Bytes { + ptr: *const u8, + len: usize, + // inlined "trait object" + data: AtomicPtr<()>, + vtable: &'static Vtable, + } + pub(crate) struct Vtable { + /// fn(data, ptr, len) + pub clone: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> Bytes, + /// fn(data, ptr, len) + /// + /// takes `Bytes` to value + pub to_vec: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> Vec, + /// fn(data, ptr, len) + pub drop: unsafe fn(&mut AtomicPtr<()>, *const u8, usize), + } + + enum NoWarnings { + BigBoi(PublishWithBytes), + _SmallBoi(u8), + } + + enum MakesClippyAngry { + BigBoi(PublishWithVec), + _SmallBoi(u8), + } + + struct PublishWithBytes { + _dup: bool, + _retain: bool, + _topic: Bytes, + __topic: Bytes, + ___topic: Bytes, + ____topic: Bytes, + _pkid: u16, + _payload: Bytes, + __payload: Bytes, + ___payload: Bytes, + ____payload: Bytes, + _____payload: Bytes, + } + + struct PublishWithVec { + _dup: bool, + _retain: bool, + _topic: Vec, + __topic: Vec, + ___topic: Vec, + ____topic: Vec, + _pkid: u16, + _payload: Vec, + __payload: Vec, + ___payload: Vec, + ____payload: Vec, + _____payload: Vec, + } +} From 277bf089b36db59dbc2c2efa279fbe52a3fe1c4b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 18 Jan 2025 17:13:53 +0100 Subject: [PATCH 013/161] Fix regression #14007 --- .../literal_string_with_formatting_args.rs | 6 +++- .../ui/literal_string_with_formatting_arg.rs | 7 ++++ .../literal_string_with_formatting_arg.stderr | 36 +++++++++++-------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/literal_string_with_formatting_args.rs b/clippy_lints/src/literal_string_with_formatting_args.rs index 21066a00eaf5..7e3cc444a817 100644 --- a/clippy_lints/src/literal_string_with_formatting_args.rs +++ b/clippy_lints/src/literal_string_with_formatting_args.rs @@ -128,7 +128,11 @@ impl<'tcx> LateLintPass<'tcx> for LiteralStringWithFormattingArg { pos.start += diff_len; pos.end += diff_len; - let start = fmt_str[..pos.start].rfind('{').unwrap_or(pos.start); + let mut start = pos.start; + while start < fmt_str.len() && !fmt_str.is_char_boundary(start) { + start += 1; + } + let start = fmt_str[..start].rfind('{').unwrap_or(start); // If this is a unicode character escape, we don't want to lint. if start > 1 && fmt_str[..start].ends_with("\\u") { continue; diff --git a/tests/ui/literal_string_with_formatting_arg.rs b/tests/ui/literal_string_with_formatting_arg.rs index c9731e592e59..b9a6654d4276 100644 --- a/tests/ui/literal_string_with_formatting_arg.rs +++ b/tests/ui/literal_string_with_formatting_arg.rs @@ -19,6 +19,13 @@ fn compiler_macro() { assert!(format!("{value}").is_ascii()); } +// Regression test for . +fn regression_14007() { + let s = "{и}"; + let ш = 12; + let s = "{ш}"; //~ literal_string_with_formatting_args +} + fn main() { let x: Option = None; let y = "hello"; diff --git a/tests/ui/literal_string_with_formatting_arg.stderr b/tests/ui/literal_string_with_formatting_arg.stderr index 1898f4f57b82..021983056bf6 100644 --- a/tests/ui/literal_string_with_formatting_arg.stderr +++ b/tests/ui/literal_string_with_formatting_arg.stderr @@ -1,77 +1,83 @@ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:25:15 + --> tests/ui/literal_string_with_formatting_arg.rs:26:14 | -LL | x.expect("{y} {}"); - | ^^^ +LL | let s = "{ш}"; + | ^^^ | = note: `-D clippy::literal-string-with-formatting-args` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_args)]` error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:26:16 + --> tests/ui/literal_string_with_formatting_arg.rs:32:15 + | +LL | x.expect("{y} {}"); + | ^^^ + +error: this looks like a formatting argument but it is not part of a formatting macro + --> tests/ui/literal_string_with_formatting_arg.rs:33:16 | LL | x.expect(" {y} bla"); | ^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:27:15 + --> tests/ui/literal_string_with_formatting_arg.rs:34:15 | LL | x.expect("{:?}"); | ^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:28:15 + --> tests/ui/literal_string_with_formatting_arg.rs:35:15 | LL | x.expect("{y:?}"); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:29:16 + --> tests/ui/literal_string_with_formatting_arg.rs:36:16 | LL | x.expect(" {y:?} {y:?} "); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:30:23 + --> tests/ui/literal_string_with_formatting_arg.rs:37:23 | LL | x.expect(" {y:..} {y:?} "); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:31:16 + --> tests/ui/literal_string_with_formatting_arg.rs:38:16 | LL | x.expect(r"{y:?} {y:?} "); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:32:16 + --> tests/ui/literal_string_with_formatting_arg.rs:39:16 | LL | x.expect(r"{y:?} y:?}"); | ^^^^^ error: these look like formatting arguments but are not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:33:19 + --> tests/ui/literal_string_with_formatting_arg.rs:40:19 | LL | x.expect(r##" {y:?} {y:?} "##); | ^^^^^ ^^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:34:14 + --> tests/ui/literal_string_with_formatting_arg.rs:41:14 | LL | assert!("{y}".is_ascii()); | ^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:36:18 + --> tests/ui/literal_string_with_formatting_arg.rs:43:18 | LL | x.expect("———{:?}"); | ^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:46:19 + --> tests/ui/literal_string_with_formatting_arg.rs:53:19 | LL | x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint | ^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors From 06221e653ca57a51b94a794cd99c49c8cba68ff9 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 18 Jan 2025 17:14:33 +0100 Subject: [PATCH 014/161] Deprecate the `option_map_or_err_ok` lint --- clippy_lints/src/declared_lints.rs | 1 - clippy_lints/src/deprecated_lints.rs | 2 + clippy_lints/src/methods/mod.rs | 28 ------------- .../src/methods/option_map_or_err_ok.rs | 41 ------------------- tests/ui/deprecated.rs | 1 + tests/ui/deprecated.stderr | 8 +++- tests/ui/manual_ok_or.stderr | 11 +---- tests/ui/option_map_or_err_ok.fixed | 7 ---- tests/ui/option_map_or_err_ok.rs | 7 ---- tests/ui/option_map_or_err_ok.stderr | 11 ----- 10 files changed, 11 insertions(+), 106 deletions(-) delete mode 100644 clippy_lints/src/methods/option_map_or_err_ok.rs delete mode 100644 tests/ui/option_map_or_err_ok.fixed delete mode 100644 tests/ui/option_map_or_err_ok.rs delete mode 100644 tests/ui/option_map_or_err_ok.stderr diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 6d6b415f8cdd..01d0c919b216 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -449,7 +449,6 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::OPTION_AS_REF_CLONED_INFO, crate::methods::OPTION_AS_REF_DEREF_INFO, crate::methods::OPTION_FILTER_MAP_INFO, - crate::methods::OPTION_MAP_OR_ERR_OK_INFO, crate::methods::OPTION_MAP_OR_NONE_INFO, crate::methods::OR_FUN_CALL_INFO, crate::methods::OR_THEN_UNWRAP_INFO, diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 3ea792d8b835..9d0ad3a63987 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -40,6 +40,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[ ("clippy::pub_enum_variant_names", "`clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config"), #[clippy::version = "1.54.0"] ("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"), + #[clippy::version = "1.86.0"] + ("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"), // end deprecated lints. used by `cargo dev deprecate_lint` ]} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 9bfa59479905..5dad6c2e5dfd 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -82,7 +82,6 @@ mod ok_expect; mod open_options; mod option_as_ref_cloned; mod option_as_ref_deref; -mod option_map_or_err_ok; mod option_map_or_none; mod option_map_unwrap_or; mod or_fun_call; @@ -3782,31 +3781,6 @@ declare_clippy_lint! { "calls to `Path::join` which will overwrite the original path" } -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `_.map_or(Err(_), Ok)`. - /// - /// ### Why is this bad? - /// Readability, this can be written more concisely as - /// `_.ok_or(_)`. - /// - /// ### Example - /// ```no_run - /// # let opt = Some(1); - /// opt.map_or(Err("error"), Ok); - /// ``` - /// - /// Use instead: - /// ```no_run - /// # let opt = Some(1); - /// opt.ok_or("error"); - /// ``` - #[clippy::version = "1.76.0"] - pub OPTION_MAP_OR_ERR_OK, - style, - "using `Option.map_or(Err(_), Ok)`, which is more succinctly expressed as `Option.ok_or(_)`" -} - declare_clippy_lint! { /// ### What it does /// Checks for iterators of `Result`s using `.filter(Result::is_ok).map(Result::unwrap)` that may @@ -4510,7 +4484,6 @@ impl_lint_pass!(Methods => [ WAKER_CLONE_WAKE, UNNECESSARY_FALLIBLE_CONVERSIONS, JOIN_ABSOLUTE_PATHS, - OPTION_MAP_OR_ERR_OK, RESULT_FILTER_MAP, ITER_FILTER_IS_SOME, ITER_FILTER_IS_OK, @@ -5069,7 +5042,6 @@ impl Methods { ("map_or", [def, map]) => { option_map_or_none::check(cx, expr, recv, def, map); manual_ok_or::check(cx, expr, recv, def, map); - option_map_or_err_ok::check(cx, expr, recv, def, map); unnecessary_map_or::check(cx, expr, recv, def, map, span, &self.msrv); }, ("map_or_else", [def, map]) => { diff --git a/clippy_lints/src/methods/option_map_or_err_ok.rs b/clippy_lints/src/methods/option_map_or_err_ok.rs deleted file mode 100644 index 4e424d4c066a..000000000000 --- a/clippy_lints/src/methods/option_map_or_err_ok.rs +++ /dev/null @@ -1,41 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet; -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::{is_res_lang_ctor, path_res}; -use rustc_errors::Applicability; -use rustc_hir::LangItem::{ResultErr, ResultOk}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::LateContext; -use rustc_span::symbol::sym; - -use super::OPTION_MAP_OR_ERR_OK; - -pub(super) fn check<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx Expr<'tcx>, - recv: &'tcx Expr<'_>, - or_expr: &'tcx Expr<'_>, - map_expr: &'tcx Expr<'_>, -) { - // We check that it's called on an `Option` type. - if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) - // We check that first we pass an `Err`. - && let ExprKind::Call(call, &[arg]) = or_expr.kind - && is_res_lang_ctor(cx, path_res(cx, call), ResultErr) - // And finally we check that it is mapped as `Ok`. - && is_res_lang_ctor(cx, path_res(cx, map_expr), ResultOk) - { - let msg = "called `map_or(Err(_), Ok)` on an `Option` value"; - let self_snippet = snippet(cx, recv.span, ".."); - let err_snippet = snippet(cx, arg.span, ".."); - span_lint_and_sugg( - cx, - OPTION_MAP_OR_ERR_OK, - expr.span, - msg, - "consider using `ok_or`", - format!("{self_snippet}.ok_or({err_snippet})"), - Applicability::MachineApplicable, - ); - } -} diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 5617db90a470..35646e1c2391 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -15,5 +15,6 @@ #![warn(clippy::regex_macro)] //~ ERROR: lint `clippy::regex_macro` #![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names` #![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention` +#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok` fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index b3e1646c8045..d7be1e583b08 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -79,5 +79,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: `clippy::wrong LL | #![warn(clippy::wrong_pub_self_convention)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_or` covers this case + --> tests/ui/deprecated.rs:18:9 + | +LL | #![warn(clippy::option_map_or_err_ok)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 14 previous errors diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 2441a75b5c46..4722f53580f1 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -13,15 +13,6 @@ error: this pattern reimplements `Option::ok_or` LL | foo.map_or(Err("error"), Ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` -error: called `map_or(Err(_), Ok)` on an `Option` value - --> tests/ui/manual_ok_or.rs:14:5 - | -LL | foo.map_or(Err("error"), Ok); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `foo.ok_or("error")` - | - = note: `-D clippy::option-map-or-err-ok` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]` - error: this pattern reimplements `Option::ok_or` --> tests/ui/manual_ok_or.rs:17:5 | @@ -47,5 +38,5 @@ LL + "{}{}{}{}{}{}{}", LL ~ "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer")); | -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/option_map_or_err_ok.fixed b/tests/ui/option_map_or_err_ok.fixed deleted file mode 100644 index 131f4b2093e7..000000000000 --- a/tests/ui/option_map_or_err_ok.fixed +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::option_map_or_err_ok)] - -fn main() { - let x = Some("a"); - let _ = x.ok_or("a"); - //~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value -} diff --git a/tests/ui/option_map_or_err_ok.rs b/tests/ui/option_map_or_err_ok.rs deleted file mode 100644 index 0f07a592ae5f..000000000000 --- a/tests/ui/option_map_or_err_ok.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::option_map_or_err_ok)] - -fn main() { - let x = Some("a"); - let _ = x.map_or(Err("a"), Ok); - //~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value -} diff --git a/tests/ui/option_map_or_err_ok.stderr b/tests/ui/option_map_or_err_ok.stderr deleted file mode 100644 index 1971af80aa8d..000000000000 --- a/tests/ui/option_map_or_err_ok.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: called `map_or(Err(_), Ok)` on an `Option` value - --> tests/ui/option_map_or_err_ok.rs:5:13 - | -LL | let _ = x.map_or(Err("a"), Ok); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `x.ok_or("a")` - | - = note: `-D clippy::option-map-or-err-ok` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]` - -error: aborting due to 1 previous error - From a03242f8e0e7ac1d15b2e78568dcbb5e92e9f258 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 18 Jan 2025 17:17:41 +0100 Subject: [PATCH 015/161] Move `manual_ok_or` from pedantic to style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `manual_ok_or` covers the same case that were covered by `option_map_or_err_ok` which is not deprecated. The latter was in the "style" category. Also, the lint is machine applicable, and leads to shorter and more readable code, so "style" is appropriate. The only difference is that the η-expanded form of `Result::Ok()` was not covered by `option_map_or_err_ok` while it is by `manual_ok_or`, so the category change may expose some new occurrences. --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 5dad6c2e5dfd..7625057368e9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2639,7 +2639,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.49.0"] pub MANUAL_OK_OR, - pedantic, + style, "finds patterns that can be encoded more concisely with `Option::ok_or`" } From ac87b0cb73dc16df9413421119100001bf370d20 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 23 Jan 2025 12:40:12 +0900 Subject: [PATCH 016/161] fix ICE in `unnecessary_mut_passed` --- clippy_lints/src/mut_reference.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index c382fb8fce1b..2fd1049f42e1 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -54,8 +54,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { ); } }, - ExprKind::MethodCall(path, receiver, arguments, _) => { - let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); + ExprKind::MethodCall(path, receiver, arguments, _) + if let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) => + { let args = cx.typeck_results().node_args(e.hir_id); let method_type = cx.tcx.type_of(def_id).instantiate(cx.tcx, args); check_arguments( From 40c2c641c2ddf4eaf1e9e8c0991d4f8644c267ec Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sun, 26 Jan 2025 15:43:48 +0900 Subject: [PATCH 017/161] fix broken link of UI test in the book --- book/src/development/basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/development/basics.md b/book/src/development/basics.md index 166b6aab9fb3..931e5c3a2942 100644 --- a/book/src/development/basics.md +++ b/book/src/development/basics.md @@ -75,7 +75,7 @@ or if you modify a test file to add a test case. > _Note:_ This command may update more files than you intended. In that case > only commit the files you wanted to update. -[UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#guide-to-the-ui-tests +[UI test]: https://rustc-dev-guide.rust-lang.org/tests/adding.html#ui-test-walkthrough ## `cargo dev` From 665e78f20febeef66a05a6509154646c4eb09145 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Mon, 27 Jan 2025 23:10:42 +0900 Subject: [PATCH 018/161] add MSRV check for `manual_flatten` --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/loops/manual_flatten.rs | 3 +++ clippy_lints/src/loops/mod.rs | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 999df0efaac1..59530dbc4b20 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -743,6 +743,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_bits`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits) * [`manual_c_str_literals`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals) * [`manual_clamp`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp) +* [`manual_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten) * [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one) * [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) * [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 4b0fcbfc3bc6..9d8678848c8b 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -612,6 +612,7 @@ define_Conf! { manual_bits, manual_c_str_literals, manual_clamp, + manual_flatten, manual_hash_one, manual_is_ascii_check, manual_let_else, diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 366c310592f5..ffeb7e889c2e 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -1,6 +1,7 @@ use super::MANUAL_FLATTEN; use super::utils::make_iterator_snippet; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::visitors::is_local_used; use clippy_utils::{higher, path_to_local_id, peel_blocks_with_stmt}; use rustc_errors::Applicability; @@ -18,6 +19,7 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, span: Span, + msrv: &Msrv, ) { let inner_expr = peel_blocks_with_stmt(body); if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: None, .. }) @@ -34,6 +36,7 @@ pub(super) fn check<'tcx>( && (some_ctor || ok_ctor) // Ensure expr in `if let` is not used afterwards && !is_local_used(cx, if_then, pat_hir_id) + && msrv.meets(msrvs::ITER_FLATTEN) { let if_let_type = if some_ctor { "Some" } else { "Ok" }; // Prepare the error message diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index c5e75af2303c..80afb4f266d4 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -831,7 +831,7 @@ impl Loops { mut_range_bound::check(cx, arg, body); single_element_loop::check(cx, pat, arg, body, expr); same_item_push::check(cx, pat, arg, body, expr, &self.msrv); - manual_flatten::check(cx, pat, arg, body, span); + manual_flatten::check(cx, pat, arg, body, span, &self.msrv); manual_find::check(cx, pat, arg, body, span, expr); unused_enumerate_index::check(cx, pat, arg, body); } From 16e2196fc2d9aa87d261e6163e6a13bc9d761f60 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 28 Jan 2025 00:03:00 +0100 Subject: [PATCH 019/161] `useless_asref`: no lint if in a closure to change the ref depth Removing the `.as_ref()` or `.as_mut()` as the top-level expression in a closure may change the type of the result. In this case, it may be better not to lint rather than proposing a fix that would not work. --- clippy_lints/src/methods/useless_asref.rs | 19 +++++++++++++------ tests/ui/useless_asref.fixed | 5 +++++ tests/ui/useless_asref.rs | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 82313257e5c4..6d3da42775f4 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -55,12 +55,19 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty); let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty); if base_rcv_ty == base_res_ty && rcv_depth >= res_depth { - // allow the `as_ref` or `as_mut` if it is followed by another method call - if let Some(parent) = get_parent_expr(cx, expr) - && let hir::ExprKind::MethodCall(segment, ..) = parent.kind - && segment.ident.span != expr.span - { - return; + if let Some(parent) = get_parent_expr(cx, expr) { + // allow the `as_ref` or `as_mut` if it is followed by another method call + if let hir::ExprKind::MethodCall(segment, ..) = parent.kind + && segment.ident.span != expr.span + { + return; + } + + // allow the `as_ref` or `as_mut` if they belong to a closure that changes + // the number of references + if matches!(parent.kind, hir::ExprKind::Closure(..)) && rcv_depth != res_depth { + return; + } } let mut applicability = Applicability::MachineApplicable; diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index ddbb9255b466..2f179200bb37 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -198,6 +198,11 @@ fn issue_12528() { let _ = opt.as_ref().map(RcWeak::clone); } +fn issue_14088() { + let s = Some("foo"); + let _: Option<&str> = s.as_ref().map(|x| x.as_ref()); +} + fn main() { not_ok(); ok(); diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index b0405e930a25..9851a0caac4f 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -198,6 +198,11 @@ fn issue_12528() { let _ = opt.as_ref().map(RcWeak::clone); } +fn issue_14088() { + let s = Some("foo"); + let _: Option<&str> = s.as_ref().map(|x| x.as_ref()); +} + fn main() { not_ok(); ok(); From 736ac3d30f89d0c2709605d8f58094a833ebf934 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Tue, 28 Jan 2025 18:33:40 -0500 Subject: [PATCH 020/161] Undo most of last commit and add type alias --- clippy_config/src/types.rs | 88 +++++++---------------- clippy_lints/src/await_holding_invalid.rs | 4 +- clippy_lints/src/disallowed_macros.rs | 9 ++- clippy_lints/src/disallowed_methods.rs | 4 +- clippy_lints/src/disallowed_types.rs | 4 +- 5 files changed, 35 insertions(+), 74 deletions(-) diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index ef3d46892a47..b07188a2b0f6 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -14,41 +14,24 @@ pub struct Rename { pub rename: String, } -#[derive(Debug, Serialize)] -pub struct DisallowedPathWithoutReplacement { - path: String, - reason: Option, -} +pub type DisallowedPathWithoutReplacement = DisallowedPath; -#[derive(Clone, Debug, Serialize)] -pub struct DisallowedPath { +#[derive(Debug, Serialize)] +pub struct DisallowedPath { path: String, reason: Option, replacement: Option, } -impl<'de> Deserialize<'de> for DisallowedPathWithoutReplacement { +impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let enum_ = DisallowedPathEnum::deserialize(deserializer)?; - if enum_.replacement().is_some() { + if !REPLACEMENT_ALLOWED && enum_.replacement().is_some() { return Err(de::Error::custom("replacement not allowed for this configuration")); } - Ok(Self { - path: enum_.path().to_owned(), - reason: enum_.reason().map(ToOwned::to_owned), - }) - } -} - -impl<'de> Deserialize<'de> for DisallowedPath { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let enum_ = DisallowedPathEnum::deserialize(deserializer)?; Ok(Self { path: enum_.path().to_owned(), reason: enum_.reason().map(ToOwned::to_owned), @@ -68,48 +51,27 @@ pub enum DisallowedPathEnum { }, } -pub trait AmendDiag { - fn path(&self) -> &str; - fn reason(&self) -> Option<&str>; - fn replacement(&self) -> Option<&str>; - fn amend_diag(&self, span: Span, diag: &mut Diag<'_, ()>) { - if let Some(replacement) = &self.replacement() { - diag.span_suggestion( - span, - self.reason().map_or_else(|| String::from("use"), ToOwned::to_owned), - replacement, - Applicability::MachineApplicable, - ); - } else if let Some(reason) = self.reason() { - diag.note(reason.to_owned()); +impl DisallowedPath { + pub fn path(&self) -> &str { + &self.path + } + + pub fn diag_amendment(&self, span: Span) -> impl FnOnce(&mut Diag<'_, ()>) + use<'_, REPLACEMENT_ALLOWED> { + move |diag| { + if let Some(replacement) = &self.replacement { + diag.span_suggestion( + span, + self.reason.as_ref().map_or_else(|| String::from("use"), Clone::clone), + replacement, + Applicability::MachineApplicable, + ); + } else if let Some(reason) = &self.reason { + diag.note(reason.clone()); + } } } } -impl AmendDiag for DisallowedPathWithoutReplacement { - fn path(&self) -> &str { - &self.path - } - fn reason(&self) -> Option<&str> { - self.reason.as_deref() - } - fn replacement(&self) -> Option<&str> { - None - } -} - -impl AmendDiag for DisallowedPath { - fn path(&self) -> &str { - &self.path - } - fn reason(&self) -> Option<&str> { - self.reason.as_deref() - } - fn replacement(&self) -> Option<&str> { - self.replacement.as_deref() - } -} - impl DisallowedPathEnum { pub fn path(&self) -> &str { let (Self::Simple(path) | Self::WithReason { path, .. }) = self; @@ -133,10 +95,10 @@ impl DisallowedPathEnum { } /// Creates a map of disallowed items to the reason they were disallowed. -pub fn create_disallowed_map( +pub fn create_disallowed_map( tcx: TyCtxt<'_>, - disallowed: &'static [T], -) -> DefIdMap<(&'static str, &'static T)> { + disallowed: &'static [DisallowedPath], +) -> DefIdMap<(&'static str, &'static DisallowedPath)> { disallowed .iter() .map(|x| (x.path(), x.path().split("::").collect::>(), x)) diff --git a/clippy_lints/src/await_holding_invalid.rs b/clippy_lints/src/await_holding_invalid.rs index 3eb87e05a236..92a0c7f9acbc 100644 --- a/clippy_lints/src/await_holding_invalid.rs +++ b/clippy_lints/src/await_holding_invalid.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{AmendDiag, DisallowedPathWithoutReplacement, create_disallowed_map}; +use clippy_config::types::{DisallowedPathWithoutReplacement, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{match_def_path, paths}; use rustc_hir as hir; @@ -266,7 +266,7 @@ fn emit_invalid_type( AWAIT_HOLDING_INVALID_TYPE, span, format!("holding a disallowed type across an await point `{path}`"), - |diag| disallowed_path.amend_diag(span, diag), + disallowed_path.diag_amendment(span), ); } diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs index 629bf416515c..fe0870e8282f 100644 --- a/clippy_lints/src/disallowed_macros.rs +++ b/clippy_lints/src/disallowed_macros.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{AmendDiag, DisallowedPath, create_disallowed_map}; +use clippy_config::types::{DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::macros::macro_backtrace; use rustc_data_structures::fx::FxHashSet; @@ -92,6 +92,7 @@ impl DisallowedMacros { if let Some(&(path, disallowed_path)) = self.disallowed.get(&mac.def_id) { let msg = format!("use of a disallowed macro `{path}`"); + let add_note = disallowed_path.diag_amendment(mac.span); if matches!(mac.kind, MacroKind::Derive) && let Some(derive_src) = derive_src { @@ -101,12 +102,10 @@ impl DisallowedMacros { cx.tcx.local_def_id_to_hir_id(derive_src.def_id), mac.span, msg, - |diag| disallowed_path.amend_diag(mac.span, diag), + add_note, ); } else { - span_lint_and_then(cx, DISALLOWED_MACROS, mac.span, msg, |diag| { - disallowed_path.amend_diag(mac.span, diag); - }); + span_lint_and_then(cx, DISALLOWED_MACROS, mac.span, msg, add_note); } } } diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index e6503b310537..0cd9ea13f2e5 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{AmendDiag, DisallowedPath, create_disallowed_map}; +use clippy_config::types::{DisallowedPath, create_disallowed_map}; use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefIdMap; @@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { DISALLOWED_METHODS, span, format!("use of a disallowed method `{path}`"), - |diag| disallowed_path.amend_diag(span, diag), + disallowed_path.diag_amendment(span), ); } } diff --git a/clippy_lints/src/disallowed_types.rs b/clippy_lints/src/disallowed_types.rs index 15e5b8bb4c5a..a34ec4616e51 100644 --- a/clippy_lints/src/disallowed_types.rs +++ b/clippy_lints/src/disallowed_types.rs @@ -1,5 +1,5 @@ use clippy_config::Conf; -use clippy_config::types::{AmendDiag, DisallowedPath}; +use clippy_config::types::DisallowedPath; use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; @@ -89,7 +89,7 @@ impl DisallowedTypes { DISALLOWED_TYPES, span, format!("use of a disallowed type `{path}`"), - |diag| disallowed_path.amend_diag(span, diag), + disallowed_path.diag_amendment(span), ); } } From b8275293bab64910de43919d114e5ba8ff8619a5 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 29 Jan 2025 17:21:06 +0100 Subject: [PATCH 021/161] Don't use labeled block as top-level blocks Labeled blocks cannot be used as-is in the "then" or "else" part of an `if` expression. They must be enclosed in an anonymous block. --- clippy_utils/src/source.rs | 4 ++-- tests/ui/match_bool.fixed | 6 ++++++ tests/ui/match_bool.rs | 10 ++++++++++ tests/ui/match_bool.stderr | 21 ++++++++++++++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index eecbfb3936ac..8f9f27ff4048 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -293,7 +293,7 @@ impl SourceFileRange { } } -/// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`. +/// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block` with no label. pub fn expr_block( sess: &impl HasSession, expr: &Expr<'_>, @@ -304,7 +304,7 @@ pub fn expr_block( ) -> String { let (code, from_macro) = snippet_block_with_context(sess, expr.span, outer, default, indent_relative_to, app); if !from_macro - && let ExprKind::Block(block, _) = expr.kind + && let ExprKind::Block(block, None) = expr.kind && block.rules != BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) { format!("{code}") diff --git a/tests/ui/match_bool.fixed b/tests/ui/match_bool.fixed index 61a8e54fa10c..1dfb82db1206 100644 --- a/tests/ui/match_bool.fixed +++ b/tests/ui/match_bool.fixed @@ -55,4 +55,10 @@ fn match_bool() { if !(!test && option == 5) { println!("Hello") }; } +fn issue14099() { + if true { 'a: { + break 'a; + } } +} + fn main() {} diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index 9c81d2917869..e77f0304feda 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -103,4 +103,14 @@ fn match_bool() { }; } +fn issue14099() { + match true { + //~^ ERROR: `match` on a boolean expression + true => 'a: { + break 'a; + }, + _ => (), + } +} + fn main() {} diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index a4e504a0a82e..c05742e56339 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -164,5 +164,24 @@ LL | | _ => println!("Hello"), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !(!test && option == 5) { println!("Hello") }` -error: aborting due to 12 previous errors +error: `match` on a boolean expression + --> tests/ui/match_bool.rs:107:5 + | +LL | / match true { +LL | | +LL | | true => 'a: { +LL | | break 'a; +LL | | }, +LL | | _ => (), +LL | | } + | |_____^ + | +help: consider using an `if`/`else` expression + | +LL ~ if true { 'a: { +LL + break 'a; +LL + } } + | + +error: aborting due to 13 previous errors From d13897b829c57e7435bb58b310a5639e129075f5 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 30 Jan 2025 11:56:49 +0900 Subject: [PATCH 022/161] change the applicability of `if_then_some_else_none` to `MachineApplicable` --- clippy_lints/src/if_then_some_else_none.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 3fc0a6965224..869b425b2f0c 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { expr.span, format!("this could be simplified with `bool::{method_name}`"), |diag| { - let mut app = Applicability::Unspecified; + let mut app = Applicability::MachineApplicable; let cond_snip = Sugg::hir_with_context(cx, cond, expr.span.ctxt(), "[condition]", &mut app) .maybe_par() .to_string(); From 045e36d6a7b797e2eef8ee92bce11a499c319a5b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 30 Jan 2025 14:57:09 -0700 Subject: [PATCH 023/161] doc_link_code: add check for `text`[`adjacent`] style links This is the lint described at https://github.com/rust-lang/rust/pull/136308#issuecomment-2625485331 that recommends using HTML to nest links inside code. --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/doc/mod.rs | 62 +++++++++++++++ tests/ui/doc/link_adjacent.fixed | 52 ++++++++++++ tests/ui/doc/link_adjacent.rs | 52 ++++++++++++ tests/ui/doc/link_adjacent.stderr | 124 +++++++++++++++++++++++++++++ 6 files changed, 292 insertions(+) create mode 100644 tests/ui/doc/link_adjacent.fixed create mode 100644 tests/ui/doc/link_adjacent.rs create mode 100644 tests/ui/doc/link_adjacent.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index cb149ccfeead..4909f15ecaea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5530,6 +5530,7 @@ Released 2018-09-13 [`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression [`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg [`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation +[`doc_link_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_code [`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes [`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown [`doc_nested_refdefs`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_nested_refdefs diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1ce6f1256177..95dcd2c16482 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -139,6 +139,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::disallowed_types::DISALLOWED_TYPES_INFO, crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO, crate::doc::DOC_LAZY_CONTINUATION_INFO, + crate::doc::DOC_LINK_CODE_INFO, crate::doc::DOC_LINK_WITH_QUOTES_INFO, crate::doc::DOC_MARKDOWN_INFO, crate::doc::DOC_NESTED_REFDEFS_INFO, diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 15530c3dbc50..c0ee904002c9 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -84,6 +84,28 @@ declare_clippy_lint! { "presence of `_`, `::` or camel-case outside backticks in documentation" } +declare_clippy_lint! { + /// ### What it does + /// Checks for links with code directly adjacent to code text: + /// `` [`MyItem`]`<`[`u32`]`>` ``. + /// + /// ### Why is this bad? + /// It can be written more simply using HTML-style `` tags. + /// + /// ### Example + /// ```no_run + /// //! [`first`](x)`second` + /// ``` + /// Use instead: + /// ```no_run + /// //! [first](x)second + /// ``` + #[clippy::version = "1.86.0"] + pub DOC_LINK_CODE, + nursery, + "link with code back-to-back with other code" +} + declare_clippy_lint! { /// ### What it does /// Checks for the doc comments of publicly visible @@ -638,6 +660,7 @@ impl Documentation { } impl_lint_pass!(Documentation => [ + DOC_LINK_CODE, DOC_LINK_WITH_QUOTES, DOC_MARKDOWN, DOC_NESTED_REFDEFS, @@ -844,6 +867,14 @@ enum Container { List(usize), } +#[derive(Clone, Copy, Eq, PartialEq)] +enum CodeCluster { + // true means already in a link, so only needs to be followed by code + // false means we've hit code, and need to find a link + First(usize, bool), + Nth(usize, usize), +} + /// Checks parsed documentation. /// This walks the "events" (think sections of markdown) produced by `pulldown_cmark`, /// so lints here will generally access that information. @@ -875,9 +906,40 @@ fn check_doc<'a, Events: Iterator, Range { + Some(CodeCluster::First(range.start - 1, true)) + }, + (None, Code(_)) => Some(CodeCluster::First(range.start, false)), + (Some(CodeCluster::First(pos, _)), Start(Link { .. })) | (Some(CodeCluster::First(pos, true)), Code(_)) => { + Some(CodeCluster::Nth(pos, range.end)) + }, + (Some(CodeCluster::Nth(start, end)), Code(_) | Start(Link { .. })) => { + Some(CodeCluster::Nth(start, range.end.max(end))) + }, + (code_cluster @ Some(_), Code(_) | End(TagEnd::Link)) => code_cluster, + (Some(CodeCluster::First(_, _)) | None, _) => None, + (Some(CodeCluster::Nth(start, end)), _) => { + if let Some(span) = fragments.span(cx, start..end) { + span_lint_and_then(cx, DOC_LINK_CODE, span, "code link adjacent to code text", |diag| { + let sugg = format!("{}", doc[start..end].replace('`', "")); + diag.span_suggestion_verbose( + span, + "wrap the entire group in `` tags", + sugg, + Applicability::MaybeIncorrect, + ); + diag.help("separate code snippets will be shown with a gap"); + }); + } + None + }, + }; match event { Html(tag) | InlineHtml(tag) => { if tag.starts_with("[first](x)second +//~^ ERROR: adjacent +//! +//! So is this first[second](x) +//~^ ERROR: adjacent +//! +//! So is this [first](x)[second](x) +//~^ ERROR: adjacent +//! +//! So is this [first](x)[second](x)[third](x) +//~^ ERROR: adjacent +//! +//! So is this [first](x)second[third](x) +//~^ ERROR: adjacent + +/// Test case for code links that are adjacent to code text. +/// +/// This is not an example: `first``second` arst +/// +/// Neither is this: [`first`](x) arst +/// +/// Neither is this: [`first`](x) `second` arst +/// +/// Neither is this: [first](x)`second` arst +/// +/// This is: [first](x)second arst +//~^ ERROR: adjacent +/// +/// So is this first[second](x) arst +//~^ ERROR: adjacent +/// +/// So is this [first](x)[second](x) arst +//~^ ERROR: adjacent +/// +/// So is this [first](x)[second](x)[third](x) arst +//~^ ERROR: adjacent +/// +/// So is this [first](x)second[third](x) arst +//~^ ERROR: adjacent +pub struct WithTrailing; diff --git a/tests/ui/doc/link_adjacent.rs b/tests/ui/doc/link_adjacent.rs new file mode 100644 index 000000000000..af6755eeff61 --- /dev/null +++ b/tests/ui/doc/link_adjacent.rs @@ -0,0 +1,52 @@ +#![warn(clippy::doc_link_code)] + +//! Test case for code links that are adjacent to code text. +//! +//! This is not an example: `first``second` +//! +//! Neither is this: [`first`](x) +//! +//! Neither is this: [`first`](x) `second` +//! +//! Neither is this: [first](x)`second` +//! +//! This is: [`first`](x)`second` +//~^ ERROR: adjacent +//! +//! So is this `first`[`second`](x) +//~^ ERROR: adjacent +//! +//! So is this [`first`](x)[`second`](x) +//~^ ERROR: adjacent +//! +//! So is this [`first`](x)[`second`](x)[`third`](x) +//~^ ERROR: adjacent +//! +//! So is this [`first`](x)`second`[`third`](x) +//~^ ERROR: adjacent + +/// Test case for code links that are adjacent to code text. +/// +/// This is not an example: `first``second` arst +/// +/// Neither is this: [`first`](x) arst +/// +/// Neither is this: [`first`](x) `second` arst +/// +/// Neither is this: [first](x)`second` arst +/// +/// This is: [`first`](x)`second` arst +//~^ ERROR: adjacent +/// +/// So is this `first`[`second`](x) arst +//~^ ERROR: adjacent +/// +/// So is this [`first`](x)[`second`](x) arst +//~^ ERROR: adjacent +/// +/// So is this [`first`](x)[`second`](x)[`third`](x) arst +//~^ ERROR: adjacent +/// +/// So is this [`first`](x)`second`[`third`](x) arst +//~^ ERROR: adjacent +pub struct WithTrailing; diff --git a/tests/ui/doc/link_adjacent.stderr b/tests/ui/doc/link_adjacent.stderr new file mode 100644 index 000000000000..f09762fb6a0b --- /dev/null +++ b/tests/ui/doc/link_adjacent.stderr @@ -0,0 +1,124 @@ +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:13:14 + | +LL | //! This is: [`first`](x)`second` + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap + = note: `-D clippy::doc-link-code` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_link_code)]` +help: wrap the entire group in `` tags + | +LL | //! This is: [first](x)second + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:16:16 + | +LL | //! So is this `first`[`second`](x) + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | //! So is this first[second](x) + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:19:16 + | +LL | //! So is this [`first`](x)[`second`](x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | //! So is this [first](x)[second](x) + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:22:16 + | +LL | //! So is this [`first`](x)[`second`](x)[`third`](x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | //! So is this [first](x)[second](x)[third](x) + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:25:16 + | +LL | //! So is this [`first`](x)`second`[`third`](x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | //! So is this [first](x)second[third](x) + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:38:14 + | +LL | /// This is: [`first`](x)`second` arst + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | /// This is: [first](x)second arst + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:41:16 + | +LL | /// So is this `first`[`second`](x) arst + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | /// So is this first[second](x) arst + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:44:16 + | +LL | /// So is this [`first`](x)[`second`](x) arst + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | /// So is this [first](x)[second](x) arst + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:47:16 + | +LL | /// So is this [`first`](x)[`second`](x)[`third`](x) arst + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | /// So is this [first](x)[second](x)[third](x) arst + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: code link adjacent to code text + --> tests/ui/doc/link_adjacent.rs:50:16 + | +LL | /// So is this [`first`](x)`second`[`third`](x) arst + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: separate code snippets will be shown with a gap +help: wrap the entire group in `` tags + | +LL | /// So is this [first](x)second[third](x) arst + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 10 previous errors + From 58d483409705aa4063eec5edbe6bb020adcacb59 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sat, 1 Feb 2025 02:30:50 +0300 Subject: [PATCH 024/161] Resolve projections during internal mutability analysis --- clippy_lints/src/non_copy_const.rs | 6 +++ clippy_utils/src/ty/mod.rs | 4 ++ .../projections.rs | 42 ++++++++++++++++++ .../projections.stderr | 44 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 tests/ui/borrow_interior_mutable_const/projections.rs create mode 100644 tests/ui/borrow_interior_mutable_const/projections.stderr diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 147654675ec9..0d89b4e85350 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -215,6 +215,12 @@ impl<'tcx> NonCopyConst<'tcx> { .iter() .zip(tys) .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), + ty::Alias(ty::Projection, _) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { + Ok(normalized_ty) if ty != normalized_ty => { + Self::is_value_unfrozen_raw_inner(cx, ty::ValTree::Branch(val), normalized_ty) + }, + _ => false, + }, _ => false, } } diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index f2bbdda70585..5201036d84d3 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -1227,6 +1227,10 @@ impl<'tcx> InteriorMut<'tcx> { .find_map(|f| self.interior_mut_ty_chain(cx, f.ty(cx.tcx, args))) } }, + ty::Alias(ty::Projection, _) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { + Ok(normalized_ty) if ty != normalized_ty => self.interior_mut_ty_chain(cx, normalized_ty), + _ => None, + }, _ => None, }; diff --git a/tests/ui/borrow_interior_mutable_const/projections.rs b/tests/ui/borrow_interior_mutable_const/projections.rs new file mode 100644 index 000000000000..bbe5538fbe12 --- /dev/null +++ b/tests/ui/borrow_interior_mutable_const/projections.rs @@ -0,0 +1,42 @@ +#![deny(clippy::borrow_interior_mutable_const)] +#![deny(clippy::declare_interior_mutable_const)] + +// Inspired by https://github.com/rust-lang/rust/pull/130543#issuecomment-2364828139 + +use std::cell::UnsafeCell; + +trait Trait { + type Assoc; +} + +type Assoc = ::Assoc; + +impl Trait for u8 { + type Assoc = UnsafeCell; +} + +impl Trait for () { + type Assoc = (); +} + +enum MaybeMutable { + Mutable(Assoc), + Immutable(Assoc<()>), +} + +const CELL: Assoc = UnsafeCell::new(0); //~ ERROR: interior mutable +const UNIT: Assoc<()> = (); +const MUTABLE: MaybeMutable = MaybeMutable::Mutable(CELL); //~ ERROR: interior mutable +const IMMUTABLE: MaybeMutable = MaybeMutable::Immutable(UNIT); + +fn print_ref(t: &T) { + let p: *const T = t; + println!("{p:p}") +} + +fn main() { + print_ref(&CELL); //~ ERROR: interior mutability + print_ref(&UNIT); + print_ref(&MUTABLE); //~ ERROR: interior mutability + print_ref(&IMMUTABLE); +} diff --git a/tests/ui/borrow_interior_mutable_const/projections.stderr b/tests/ui/borrow_interior_mutable_const/projections.stderr new file mode 100644 index 000000000000..eabaf66560ad --- /dev/null +++ b/tests/ui/borrow_interior_mutable_const/projections.stderr @@ -0,0 +1,44 @@ +error: a `const` item should not be interior mutable + --> tests/ui/borrow_interior_mutable_const/projections.rs:27:1 + | +LL | const CELL: Assoc = UnsafeCell::new(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider making this `Sync` so that it can go in a static item or using a `thread_local` +note: the lint level is defined here + --> tests/ui/borrow_interior_mutable_const/projections.rs:2:9 + | +LL | #![deny(clippy::declare_interior_mutable_const)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a `const` item should not be interior mutable + --> tests/ui/borrow_interior_mutable_const/projections.rs:29:1 + | +LL | const MUTABLE: MaybeMutable = MaybeMutable::Mutable(CELL); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider making this `Sync` so that it can go in a static item or using a `thread_local` + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/projections.rs:38:16 + | +LL | print_ref(&CELL); + | ^^^^ + | + = help: assign this const to a local or static variable, and use the variable here +note: the lint level is defined here + --> tests/ui/borrow_interior_mutable_const/projections.rs:1:9 + | +LL | #![deny(clippy::borrow_interior_mutable_const)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/projections.rs:40:16 + | +LL | print_ref(&MUTABLE); + | ^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: aborting due to 4 previous errors + From 2a52fbe5daaa0f9e583b6f75067c0ef16bf1be9c Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sat, 1 Feb 2025 12:42:39 +0900 Subject: [PATCH 025/161] add MSRV check for `repeat_vec_with_capacity` --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/lib.rs | 2 +- clippy_lints/src/repeat_vec_with_capacity.rs | 24 +++++++++++++++++--- tests/ui/repeat_vec_with_capacity.fixed | 5 ++++ tests/ui/repeat_vec_with_capacity.rs | 5 ++++ 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index b8f9fff9c613..dfce429a8eeb 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -769,6 +769,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr) * [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names) * [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes) +* [`repeat_vec_with_capacity`](https://rust-lang.github.io/rust-clippy/master/index.html#repeat_vec_with_capacity) * [`same_item_push`](https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push) * [`seek_from_current`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current) * [`seek_rewind`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_rewind) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 552141476f3a..c2e97498f4df 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -638,6 +638,7 @@ define_Conf! { ptr_as_ptr, redundant_field_names, redundant_static_lifetimes, + repeat_vec_with_capacity, same_item_push, seek_from_current, seek_rewind, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 4b700673d0f8..7f7755015ffc 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -944,7 +944,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::>::default()); store.register_late_pass(|_| Box::new(iter_over_hash_type::IterOverHashType)); store.register_late_pass(|_| Box::new(impl_hash_with_borrow_str_and_bytes::ImplHashWithBorrowStrBytes)); - store.register_late_pass(|_| Box::new(repeat_vec_with_capacity::RepeatVecWithCapacity)); + store.register_late_pass(move |_| Box::new(repeat_vec_with_capacity::RepeatVecWithCapacity::new(conf))); store.register_late_pass(|_| Box::new(uninhabited_references::UninhabitedReferences)); store.register_late_pass(|_| Box::new(ineffective_open_options::IneffectiveOpenOptions)); store.register_late_pass(|_| Box::::default()); diff --git a/clippy_lints/src/repeat_vec_with_capacity.rs b/clippy_lints/src/repeat_vec_with_capacity.rs index 5dddf9263a35..40263afd28f1 100644 --- a/clippy_lints/src/repeat_vec_with_capacity.rs +++ b/clippy_lints/src/repeat_vec_with_capacity.rs @@ -1,15 +1,29 @@ +use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::VecArgs; use clippy_utils::macros::matching_root_macro_call; +use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet; use clippy_utils::{expr_or_init, fn_def_id, std_or_core}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; +use rustc_session::impl_lint_pass; use rustc_span::{Span, sym}; +pub struct RepeatVecWithCapacity { + msrv: Msrv, +} + +impl RepeatVecWithCapacity { + pub fn new(conf: &'static Conf) -> Self { + Self { + msrv: conf.msrv.clone(), + } + } +} + declare_clippy_lint! { /// ### What it does /// Looks for patterns such as `vec![Vec::with_capacity(x); n]` or `iter::repeat(Vec::with_capacity(x))`. @@ -48,7 +62,7 @@ declare_clippy_lint! { "repeating a `Vec::with_capacity` expression which does not retain capacity" } -declare_lint_pass!(RepeatVecWithCapacity => [REPEAT_VEC_WITH_CAPACITY]); +impl_lint_pass!(RepeatVecWithCapacity => [REPEAT_VEC_WITH_CAPACITY]); fn emit_lint(cx: &LateContext<'_>, span: Span, kind: &str, note: &'static str, sugg_msg: &'static str, sugg: String) { span_lint_and_then( @@ -112,6 +126,10 @@ fn check_repeat_fn(cx: &LateContext<'_>, expr: &Expr<'_>) { impl LateLintPass<'_> for RepeatVecWithCapacity { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { check_vec_macro(cx, expr); - check_repeat_fn(cx, expr); + if self.msrv.meets(msrvs::REPEAT_WITH) { + check_repeat_fn(cx, expr); + } } + + extract_msrv_attr!(LateContext); } diff --git a/tests/ui/repeat_vec_with_capacity.fixed b/tests/ui/repeat_vec_with_capacity.fixed index f72b61b5f6cd..34d9d7c3d71d 100644 --- a/tests/ui/repeat_vec_with_capacity.fixed +++ b/tests/ui/repeat_vec_with_capacity.fixed @@ -37,3 +37,8 @@ fn main() { from_macro!(Vec::<()>::with_capacity(42)); } } + +#[clippy::msrv = "1.27.0"] +fn msrv_check() { + std::iter::repeat(Vec::<()>::with_capacity(42)); +} diff --git a/tests/ui/repeat_vec_with_capacity.rs b/tests/ui/repeat_vec_with_capacity.rs index c0cc81f78436..6c7740b198aa 100644 --- a/tests/ui/repeat_vec_with_capacity.rs +++ b/tests/ui/repeat_vec_with_capacity.rs @@ -37,3 +37,8 @@ fn main() { from_macro!(Vec::<()>::with_capacity(42)); } } + +#[clippy::msrv = "1.27.0"] +fn msrv_check() { + std::iter::repeat(Vec::<()>::with_capacity(42)); +} From f9669e4caf219512b34546a13f39d80179511259 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sat, 1 Feb 2025 15:20:34 +0900 Subject: [PATCH 026/161] add MSRV check for `lines_filter_map_ok` --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/lib.rs | 2 +- clippy_lints/src/lines_filter_map_ok.rs | 24 +++++++++++++++++++++--- clippy_utils/src/msrvs.rs | 1 + tests/ui/lines_filter_map_ok.fixed | 7 +++++++ tests/ui/lines_filter_map_ok.rs | 7 +++++++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index b8f9fff9c613..998668fabf02 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -740,6 +740,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`index_refutable_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) * [`iter_kv_map`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map) * [`legacy_numeric_constants`](https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants) +* [`lines_filter_map_ok`](https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok) * [`manual_bits`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits) * [`manual_c_str_literals`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals) * [`manual_clamp`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 552141476f3a..cefcf81bcf06 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -609,6 +609,7 @@ define_Conf! { index_refutable_slice, iter_kv_map, legacy_numeric_constants, + lines_filter_map_ok, manual_bits, manual_c_str_literals, manual_clamp, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 4b700673d0f8..4da3160ee24e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -900,7 +900,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(manual_main_separator_str::ManualMainSeparatorStr::new(conf))); store.register_late_pass(|_| Box::new(unnecessary_struct_initialization::UnnecessaryStruct)); store.register_late_pass(move |_| Box::new(unnecessary_box_returns::UnnecessaryBoxReturns::new(conf))); - store.register_late_pass(|_| Box::new(lines_filter_map_ok::LinesFilterMapOk)); + store.register_late_pass(move |_| Box::new(lines_filter_map_ok::LinesFilterMapOk::new(conf))); store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule)); store.register_late_pass(|_| Box::new(manual_slice_size_calculation::ManualSliceSizeCalculation)); store.register_early_pass(move || Box::new(excessive_nesting::ExcessiveNesting::new(conf))); diff --git a/clippy_lints/src/lines_filter_map_ok.rs b/clippy_lints/src/lines_filter_map_ok.rs index 8206c75927b7..8c237191405a 100644 --- a/clippy_lints/src/lines_filter_map_ok.rs +++ b/clippy_lints/src/lines_filter_map_ok.rs @@ -1,12 +1,26 @@ +use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{is_diag_item_method, is_trait_method, path_to_local_id}; use rustc_errors::Applicability; use rustc_hir::{Body, Closure, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; +use rustc_session::impl_lint_pass; use rustc_span::sym; +pub struct LinesFilterMapOk { + msrv: Msrv, +} + +impl LinesFilterMapOk { + pub fn new(conf: &Conf) -> Self { + Self { + msrv: conf.msrv.clone(), + } + } +} + declare_clippy_lint! { /// ### What it does /// Checks for usage of `lines.filter_map(Result::ok)` or `lines.flat_map(Result::ok)` @@ -55,11 +69,13 @@ declare_clippy_lint! { suspicious, "filtering `std::io::Lines` with `filter_map()`, `flat_map()`, or `flatten()` might cause an infinite loop" } -declare_lint_pass!(LinesFilterMapOk => [LINES_FILTER_MAP_OK]); + +impl_lint_pass!(LinesFilterMapOk => [LINES_FILTER_MAP_OK]); impl LateLintPass<'_> for LinesFilterMapOk { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if let ExprKind::MethodCall(fm_method, fm_receiver, fm_args, fm_span) = expr.kind + if self.msrv.meets(msrvs::MAP_WHILE) + && let ExprKind::MethodCall(fm_method, fm_receiver, fm_args, fm_span) = expr.kind && is_trait_method(cx, expr, sym::Iterator) && let fm_method_str = fm_method.ident.as_str() && matches!(fm_method_str, "filter_map" | "flat_map" | "flatten") @@ -85,6 +101,8 @@ impl LateLintPass<'_> for LinesFilterMapOk { ); } } + + extract_msrv_attr!(LateContext); } fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> bool { diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index d73cb7e35611..34c575c66be5 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -34,6 +34,7 @@ msrv_aliases! { 1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE, CONST_EXTERN_C_FN } 1,59,0 { THREAD_LOCAL_CONST_INIT } 1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY, CONST_RAW_PTR_DEREF } + 1,57,0 { MAP_WHILE } 1,56,0 { CONST_FN_UNION } 1,55,0 { SEEK_REWIND } 1,54,0 { INTO_KEYS } diff --git a/tests/ui/lines_filter_map_ok.fixed b/tests/ui/lines_filter_map_ok.fixed index 621115cc1325..ae388ec39a15 100644 --- a/tests/ui/lines_filter_map_ok.fixed +++ b/tests/ui/lines_filter_map_ok.fixed @@ -31,3 +31,10 @@ fn main() -> io::Result<()> { io::stdin().lines().filter_map(|x| x.err()).for_each(|_| ()); Ok(()) } + +#[clippy::msrv = "1.56"] +fn msrv_check() { + let _lines = BufReader::new(std::fs::File::open("some-path").unwrap()) + .lines() + .filter_map(Result::ok); +} diff --git a/tests/ui/lines_filter_map_ok.rs b/tests/ui/lines_filter_map_ok.rs index a86efbd66862..4f486534e9b0 100644 --- a/tests/ui/lines_filter_map_ok.rs +++ b/tests/ui/lines_filter_map_ok.rs @@ -31,3 +31,10 @@ fn main() -> io::Result<()> { io::stdin().lines().filter_map(|x| x.err()).for_each(|_| ()); Ok(()) } + +#[clippy::msrv = "1.56"] +fn msrv_check() { + let _lines = BufReader::new(std::fs::File::open("some-path").unwrap()) + .lines() + .filter_map(Result::ok); +} From 2a7d1d4c0b1b6b06ffa6868cf10ace2a7b634129 Mon Sep 17 00:00:00 2001 From: alexey semenyuk Date: Sat, 1 Feb 2025 23:52:12 +0500 Subject: [PATCH 027/161] Remove `Known problems` section `invalid_upcast_comparisons` --- clippy_lints/src/invalid_upcast_comparisons.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/clippy_lints/src/invalid_upcast_comparisons.rs b/clippy_lints/src/invalid_upcast_comparisons.rs index 1929fbded3b5..b42664340d1c 100644 --- a/clippy_lints/src/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/invalid_upcast_comparisons.rs @@ -22,9 +22,6 @@ declare_clippy_lint! { /// will mistakenly imply that it is possible for `x` to be outside the range of /// `u8`. /// - /// ### Known problems - /// https://github.com/rust-lang/rust-clippy/issues/886 - /// /// ### Example /// ```no_run /// let x: u8 = 1; From a5329bd8d38983a57fd66098745099048fa90a2a Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sun, 2 Feb 2025 23:44:22 +0900 Subject: [PATCH 028/161] autofix for `range_zip_with_len` --- clippy_lints/src/methods/range_zip_with_len.rs | 13 +++++++------ tests/ui/range.fixed | 18 ++++++++++++++++++ tests/ui/range.rs | 3 +-- tests/ui/range.stderr | 4 ++-- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 tests/ui/range.fixed diff --git a/clippy_lints/src/methods/range_zip_with_len.rs b/clippy_lints/src/methods/range_zip_with_len.rs index f4d206c5307c..3a5e32172086 100644 --- a/clippy_lints/src/methods/range_zip_with_len.rs +++ b/clippy_lints/src/methods/range_zip_with_len.rs @@ -1,6 +1,7 @@ -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::{SpanlessEq, higher, is_integer_const, is_trait_method}; +use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; use rustc_span::sym; @@ -20,14 +21,14 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' && let ExprKind::Path(QPath::Resolved(_, len_path)) = len_recv.kind && SpanlessEq::new(cx).eq_path_segments(iter_path.segments, len_path.segments) { - span_lint( + span_lint_and_sugg( cx, RANGE_ZIP_WITH_LEN, expr.span, - format!( - "it is more idiomatic to use `{}.iter().enumerate()`", - snippet(cx, recv.span, "_") - ), + "using `.zip()` with a range and `.len()`", + "try", + format!("{}.iter().enumerate()", snippet(cx, recv.span, "_")), + Applicability::MachineApplicable, ); } } diff --git a/tests/ui/range.fixed b/tests/ui/range.fixed new file mode 100644 index 000000000000..82aa1b5f94fd --- /dev/null +++ b/tests/ui/range.fixed @@ -0,0 +1,18 @@ +#![allow(clippy::useless_vec)] +#[warn(clippy::range_zip_with_len)] +fn main() { + let v1 = vec![1, 2, 3]; + let v2 = vec![4, 5]; + let _x = v1.iter().enumerate(); + //~^ ERROR: using `.zip()` with a range and `.len()` + let _y = v1.iter().zip(0..v2.len()); // No error +} + +#[allow(unused)] +fn no_panic_with_fake_range_types() { + struct Range { + foo: i32, + } + + let _ = Range { foo: 0 }; +} diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 9541812b0691..a7d5cf38dfb5 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -4,8 +4,7 @@ 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` + //~^ ERROR: using `.zip()` with a range and `.len()` let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index 8c71a209700e..798ce1842d8b 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -1,8 +1,8 @@ -error: it is more idiomatic to use `v1.iter().enumerate()` +error: using `.zip()` with a range and `.len()` --> tests/ui/range.rs:6:14 | LL | let _x = v1.iter().zip(0..v1.len()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v1.iter().enumerate()` | = note: `-D clippy::range-zip-with-len` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::range_zip_with_len)]` From 5884fd0325325bcdfddb2dc431827c8b4656be1c Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Mon, 3 Feb 2025 06:44:41 +0300 Subject: [PATCH 029/161] tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` --- clippy_lints/src/attrs/mixed_attributes_style.rs | 6 +++--- clippy_lints/src/doc/needless_doctest_main.rs | 6 +++--- clippy_lints/src/undocumented_unsafe_blocks.rs | 10 +++++----- clippy_lints/src/utils/attr_collector.rs | 5 ++--- clippy_utils/src/consts.rs | 7 ++++--- clippy_utils/src/macros.rs | 6 ++++-- clippy_utils/src/source.rs | 7 ++++--- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index 3e4bcfbfc190..5a26ba8bf932 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -1,8 +1,8 @@ +use std::sync::Arc; use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; use rustc_ast::{AttrKind, AttrStyle, Attribute}; use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::sync::Lrc; use rustc_lint::{EarlyContext, LintContext}; use rustc_span::source_map::SourceMap; use rustc_span::{SourceFile, Span, Symbol}; @@ -79,7 +79,7 @@ fn lint_mixed_attrs(cx: &EarlyContext<'_>, attrs: &[Attribute]) { ); } -fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc, attr_span: Span) -> bool { +fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc, attr_span: Span) -> bool { let attr_src = source_map.lookup_source_file(attr_span.lo()); - Lrc::ptr_eq(item_src, &attr_src) + Arc::ptr_eq(item_src, &attr_src) } diff --git a/clippy_lints/src/doc/needless_doctest_main.rs b/clippy_lints/src/doc/needless_doctest_main.rs index 9ba2723157ad..ce5beab24bfa 100644 --- a/clippy_lints/src/doc/needless_doctest_main.rs +++ b/clippy_lints/src/doc/needless_doctest_main.rs @@ -1,10 +1,10 @@ use std::ops::Range; use std::{io, thread}; +use std::sync::Arc; use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST}; use clippy_utils::diagnostics::span_lint; use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind}; -use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::HumanEmitter; use rustc_errors::{Diag, DiagCtxt}; use rustc_lint::LateContext; @@ -46,8 +46,8 @@ pub fn check( rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle); let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings(); - #[expect(clippy::arc_with_non_send_sync)] // `Lrc` is expected by with_dcx - let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); + #[expect(clippy::arc_with_non_send_sync)] // `Arc` is expected by with_dcx + let sm = Arc::new(SourceMap::new(FilePathMapping::empty())); let psess = ParseSess::with_dcx(dcx, sm); let mut parser = match new_parser_from_source_str(&psess, filename, code) { diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 5e5d6a9e333b..b3d269080930 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use std::ops::ControlFlow; use clippy_config::Conf; @@ -6,7 +7,6 @@ use clippy_utils::is_lint_allowed; use clippy_utils::source::walk_span_to_context; use clippy_utils::visitors::{Descend, for_each_expr}; use hir::HirId; -use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource}; use rustc_lexer::{TokenKind, tokenize}; @@ -480,7 +480,7 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf if let Some(comment_start) = comment_start && let Ok(unsafe_line) = source_map.lookup_line(item.span.lo()) && let Ok(comment_start_line) = source_map.lookup_line(comment_start) - && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { return if comment_start_line.line >= unsafe_line.line { @@ -520,7 +520,7 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H if let Some(comment_start) = comment_start && let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Ok(comment_start_line) = source_map.lookup_line(comment_start) - && Lrc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &comment_start_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { return if comment_start_line.line >= unsafe_line.line { @@ -580,7 +580,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span // ^--------------------------------------------^ if let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo()) - && Lrc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, ¯o_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { if macro_line.line < unsafe_line.line { @@ -641,7 +641,7 @@ fn span_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool { if let Ok(unsafe_line) = source_map.lookup_line(span.lo()) && let Some(body_span) = walk_span_to_context(search_span, SyntaxContext::root()) && let Ok(body_line) = source_map.lookup_line(body_span.lo()) - && Lrc::ptr_eq(&unsafe_line.sf, &body_line.sf) + && Arc::ptr_eq(&unsafe_line.sf, &body_line.sf) && let Some(src) = unsafe_line.sf.src.as_deref() { // Get the text from the start of function body to the unsafe block. diff --git a/clippy_lints/src/utils/attr_collector.rs b/clippy_lints/src/utils/attr_collector.rs index 1522553bbf52..169429811d32 100644 --- a/clippy_lints/src/utils/attr_collector.rs +++ b/clippy_lints/src/utils/attr_collector.rs @@ -1,14 +1,13 @@ use std::mem; -use std::sync::OnceLock; +use std::sync::{Arc, OnceLock}; use rustc_ast::{Attribute, Crate}; -use rustc_data_structures::sync::Lrc; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; #[derive(Clone, Default)] -pub struct AttrStorage(pub Lrc>>); +pub struct AttrStorage(pub Arc>>); pub struct AttrCollector { storage: AttrStorage, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index a660623f4185..fab1db05d2e5 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -4,13 +4,14 @@ //! executable MIR bodies, so we have to do this instead. #![allow(clippy::float_cmp)] +use std::sync::Arc; + use crate::source::{SpanRangeExt, walk_span_to_context}; use crate::{clip, is_direct_expn_of, sext, unsext}; use rustc_apfloat::Float; use rustc_apfloat::ieee::{Half, Quad}; use rustc_ast::ast::{self, LitFloatType, LitKind}; -use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{ BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, PatExpr, PatExprKind, QPath, UnOp, @@ -37,7 +38,7 @@ pub enum Constant<'tcx> { /// A `String` (e.g., "abc"). Str(String), /// A binary string (e.g., `b"abc"`). - Binary(Lrc<[u8]>), + Binary(Arc<[u8]>), /// A single `char` (e.g., `'a'`). Char(char), /// An integer's bit representation. @@ -305,7 +306,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option>) -> Constan match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), - LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)), + LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Arc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index f4c730ef118b..30fd48fc0605 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -1,12 +1,14 @@ #![allow(clippy::similar_names)] // `expr` and `expn` +use std::sync::Arc; + use crate::get_unique_attr; use crate::visitors::{Descend, for_each_expr_without_closures}; use arrayvec::ArrayVec; use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::{Lrc, OnceLock}; +use rustc_data_structures::sync::OnceLock; use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath}; use rustc_lint::{LateContext, LintContext}; use rustc_span::def_id::DefId; @@ -393,7 +395,7 @@ fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) -> /// Stores AST [`FormatArgs`] nodes for use in late lint passes, as they are in a desugared form in /// the HIR #[derive(Default, Clone)] -pub struct FormatArgsStorage(Lrc>>); +pub struct FormatArgsStorage(Arc>>); impl FormatArgsStorage { /// Returns an AST [`FormatArgs`] node if a `format_args` expansion is found as a descendant of diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index eecbfb3936ac..2700ef139e6f 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -2,8 +2,9 @@ #![allow(clippy::module_name_repetitions)] +use std::sync::Arc; + use rustc_ast::{LitKind, StrStyle}; -use rustc_data_structures::sync::Lrc; use rustc_errors::Applicability; use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource}; use rustc_lint::{EarlyContext, LateContext}; @@ -204,7 +205,7 @@ impl fmt::Display for SourceText { fn get_source_range(sm: &SourceMap, sp: Range) -> Option { let start = sm.lookup_byte_offset(sp.start); let end = sm.lookup_byte_offset(sp.end); - if !Lrc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos { + if !Arc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos { return None; } sm.ensure_source_file_source_present(&start.sf); @@ -277,7 +278,7 @@ fn trim_start(sm: &SourceMap, sp: Range) -> Range { } pub struct SourceFileRange { - pub sf: Lrc, + pub sf: Arc, pub range: Range, } impl SourceFileRange { From 64dec0760e652878399155e4621063ecce88b12b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 29 Jan 2025 17:28:03 +0100 Subject: [PATCH 030/161] Simplify `reindent_multiline()` signature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `reindent_multiline()` always returns the result of `reindent_multiline_inner()` which returns a `String`. Make `reindent_multiline()` return a `String` as well, instead of a systematically owned `Cow<'_, str>`. - There is no reason for `reindent_multiline()` to force a caller to build a `Cow<'_, str>` instead of passing a `&str` directly, especially considering that a `String` will always be returned. Also, both the input parameter and return value (of type `Cow<'_, str>`) shared the same (elided) lifetime for no reason: this worked only because the result was always the `Cow::Owned` variant which is compatible with any lifetime. As a consequence, the signature changes from: ```rust fn reindent_multiline(s: Cow<'_, str>, …) -> Cow<'_, str> { … } ``` to ```rust fn reindent_multiline(s: &str, …) -> String { … } ``` --- clippy_lints/src/copies.rs | 11 ++-- clippy_lints/src/entry.rs | 4 +- clippy_lints/src/if_not_else.rs | 5 +- clippy_lints/src/matches/manual_unwrap_or.rs | 2 +- ...se_sensitive_file_extension_comparisons.rs | 5 +- clippy_lints/src/methods/filter_map.rs | 5 +- clippy_lints/src/methods/iter_filter.rs | 5 +- clippy_lints/src/methods/manual_ok_or.rs | 2 +- clippy_lints/src/methods/return_and_then.rs | 2 +- clippy_lints/src/needless_continue.rs | 2 +- clippy_lints/src/redundant_else.rs | 10 +--- clippy_lints/src/unit_types/unit_arg.rs | 5 +- clippy_utils/src/source.rs | 52 ++++++++----------- 13 files changed, 46 insertions(+), 64 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 89808d38b9f3..7c783df4f805 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -18,7 +18,6 @@ use rustc_session::impl_lint_pass; use rustc_span::hygiene::walk_chain; use rustc_span::source_map::SourceMap; use rustc_span::{Span, Symbol}; -use std::borrow::Cow; declare_clippy_lint! { /// ### What it does @@ -248,18 +247,18 @@ fn lint_branches_sharing_code<'tcx>( let first_line_span = first_line_of_span(cx, expr.span); let replace_span = first_line_span.with_hi(span.hi()); let cond_span = first_line_span.until(first_block.span); - let cond_snippet = reindent_multiline(snippet(cx, cond_span, "_"), false, None); + let cond_snippet = reindent_multiline(&snippet(cx, cond_span, "_"), false, None); let cond_indent = indent_of(cx, cond_span); - let moved_snippet = reindent_multiline(snippet(cx, span, "_"), true, None); + let moved_snippet = reindent_multiline(&snippet(cx, span, "_"), true, None); let suggestion = moved_snippet.to_string() + "\n" + &cond_snippet + "{"; - let suggestion = reindent_multiline(Cow::Borrowed(&suggestion), true, cond_indent); + let suggestion = reindent_multiline(&suggestion, true, cond_indent); (replace_span, suggestion.to_string()) }); let end_suggestion = res.end_span(last_block, sm).map(|span| { - let moved_snipped = reindent_multiline(snippet(cx, span, "_"), true, None); + let moved_snipped = reindent_multiline(&snippet(cx, span, "_"), true, None); let indent = indent_of(cx, expr.span.shrink_to_hi()); let suggestion = "}\n".to_string() + &moved_snipped; - let suggestion = reindent_multiline(Cow::Borrowed(&suggestion), true, indent); + let suggestion = reindent_multiline(&suggestion, true, indent); let span = span.with_hi(last_block.span.hi()); // Improve formatting if the inner block has indention (i.e. normal Rust formatting) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 2bec4f2f99e5..99d635aa5cc0 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -135,8 +135,8 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass { format!( "match {map_str}.entry({key_str}) {{\n{indent_str} {entry}::{then_entry} => {}\n\ {indent_str} {entry}::{else_entry} => {}\n{indent_str}}}", - reindent_multiline(then_str.into(), true, Some(4 + indent_str.len())), - reindent_multiline(else_str.into(), true, Some(4 + indent_str.len())), + reindent_multiline(&then_str, true, Some(4 + indent_str.len())), + reindent_multiline(&else_str, true, Some(4 + indent_str.len())), entry = map_ty.entry_path(), ) } diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index 2806d4d0e5d6..45f9aa0a53e4 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -7,7 +7,6 @@ use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::Span; -use std::borrow::Cow; declare_clippy_lint! { /// ### What it does @@ -107,7 +106,7 @@ fn make_sugg<'a>( els_span: Span, default: &'a str, indent_relative_to: Option, -) -> Cow<'a, str> { +) -> String { let cond_inner_snip = snippet(sess, cond_inner, default); let els_snip = snippet(sess, els_span, default); let indent = indent_relative_to.and_then(|s| indent_of(sess, s)); @@ -130,5 +129,5 @@ fn make_sugg<'a>( _ => String::new(), }; - reindent_multiline(suggestion.into(), true, indent) + reindent_multiline(&suggestion, true, indent) } diff --git a/clippy_lints/src/matches/manual_unwrap_or.rs b/clippy_lints/src/matches/manual_unwrap_or.rs index 59d375200117..c8c045d86d3d 100644 --- a/clippy_lints/src/matches/manual_unwrap_or.rs +++ b/clippy_lints/src/matches/manual_unwrap_or.rs @@ -113,7 +113,7 @@ fn lint<'tcx>( or_body_snippet: &str, indent: usize, ) { - let reindented_or_body = reindent_multiline(or_body_snippet.into(), true, Some(indent)); + let reindented_or_body = reindent_multiline(or_body_snippet, true, Some(indent)); let mut app = Applicability::MachineApplicable; let suggestion = sugg::Sugg::hir_with_context(cx, scrutinee, expr.span.ctxt(), "..", &mut app).maybe_par(); diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index 76bdbe55e2f3..18568e3661fe 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -57,14 +57,13 @@ pub(super) fn check<'tcx>( }; let suggestion_source = reindent_multiline( - format!( + &format!( "std::path::Path::new({}) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case(\"{}\"))", recv_source, ext_str.strip_prefix('.').unwrap() - ) - .into(), + ), true, Some(indent_of(cx, call_span).unwrap_or(0) + 4), ); diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index c1653b65e982..15a14c61d2bc 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -12,7 +12,6 @@ use rustc_lint::LateContext; use rustc_middle::ty::adjustment::Adjust; use rustc_span::Span; use rustc_span::symbol::{Ident, Symbol, sym}; -use std::borrow::Cow; use super::{MANUAL_FILTER_MAP, MANUAL_FIND_MAP, OPTION_FILTER_MAP, RESULT_FILTER_MAP}; @@ -302,7 +301,7 @@ pub(super) fn check( filter_span.with_hi(expr.span.hi()), "`filter` for `Some` followed by `unwrap`", "consider using `flatten` instead", - reindent_multiline(Cow::Borrowed("flatten()"), true, indent_of(cx, map_span)).into_owned(), + reindent_multiline("flatten()", true, indent_of(cx, map_span)), Applicability::MachineApplicable, ); @@ -316,7 +315,7 @@ pub(super) fn check( filter_span.with_hi(expr.span.hi()), "`filter` for `Ok` followed by `unwrap`", "consider using `flatten` instead", - reindent_multiline(Cow::Borrowed("flatten()"), true, indent_of(cx, map_span)).into_owned(), + reindent_multiline("flatten()", true, indent_of(cx, map_span)), Applicability::MachineApplicable, ); diff --git a/clippy_lints/src/methods/iter_filter.rs b/clippy_lints/src/methods/iter_filter.rs index 30387ba62a73..a6308dd9be0f 100644 --- a/clippy_lints/src/methods/iter_filter.rs +++ b/clippy_lints/src/methods/iter_filter.rs @@ -12,7 +12,6 @@ use rustc_hir as hir; use rustc_hir::QPath; use rustc_span::Span; use rustc_span::symbol::{Ident, Symbol, sym}; -use std::borrow::Cow; /// /// Returns true if the expression is a method call to `method_name` @@ -181,7 +180,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, filter_arg: &hir filter_span.with_hi(expr.span.hi()), "`filter` for `is_ok` on iterator over `Result`s", "consider using `flatten` instead", - reindent_multiline(Cow::Borrowed("flatten()"), true, indent_of(cx, filter_span)).into_owned(), + reindent_multiline("flatten()", true, indent_of(cx, filter_span)), Applicability::HasPlaceholders, ), Some(FilterType::IsSome) => span_lint_and_sugg( @@ -190,7 +189,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, filter_arg: &hir filter_span.with_hi(expr.span.hi()), "`filter` for `is_some` on iterator over `Option`", "consider using `flatten` instead", - reindent_multiline(Cow::Borrowed("flatten()"), true, indent_of(cx, filter_span)).into_owned(), + reindent_multiline("flatten()", true, indent_of(cx, filter_span)), Applicability::HasPlaceholders, ), } diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index 4321dd6b0e09..8da9c6b38094 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( && let Some(err_arg_snippet) = err_arg.span.get_source_text(cx) && let Some(indent) = indent_of(cx, expr.span) { - let reindented_err_arg_snippet = reindent_multiline(err_arg_snippet.as_str().into(), true, Some(indent + 4)); + let reindented_err_arg_snippet = reindent_multiline(err_arg_snippet.as_str(), true, Some(indent + 4)); span_lint_and_sugg( cx, MANUAL_OK_OR, diff --git a/clippy_lints/src/methods/return_and_then.rs b/clippy_lints/src/methods/return_and_then.rs index 7b1199ad1e2d..3c7b54dd8db9 100644 --- a/clippy_lints/src/methods/return_and_then.rs +++ b/clippy_lints/src/methods/return_and_then.rs @@ -60,7 +60,7 @@ pub(super) fn check<'tcx>( "let {} = {}?;\n{}", arg_snip, recv_snip, - reindent_multiline(inner.into(), false, indent_of(cx, expr.span)) + reindent_multiline(inner, false, indent_of(cx, expr.span)) ); span_lint_and_sugg(cx, RETURN_AND_THEN, expr.span, msg, "try", sugg, applicability); diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index 05b31fc84b9b..b8601f77e249 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -356,7 +356,7 @@ fn suggestion_snippet_for_continue_inside_else(cx: &EarlyContext<'_>, data: &Lin .iter() .map(|stmt| { let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span); - let snip = snippet_block(cx, span, "..", None).into_owned(); + let snip = snippet_block(cx, span, "..", None); snip.lines() .map(|line| format!("{}{line}", " ".repeat(indent))) .collect::>() diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 2995cd8d9f7a..2b5c33c5cbd1 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -7,7 +7,6 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::declare_lint_pass; use rustc_span::Span; -use std::borrow::Cow; declare_clippy_lint! { /// ### What it does @@ -164,14 +163,9 @@ fn extract_else_block(mut block: &str) -> String { block.trim_end().to_string() } -fn make_sugg<'a>( - cx: &EarlyContext<'_>, - els_span: Span, - default: &'a str, - indent_relative_to: Option, -) -> Cow<'a, str> { +fn make_sugg(cx: &EarlyContext<'_>, els_span: Span, default: &str, indent_relative_to: Option) -> String { let extracted = extract_else_block(&snippet(cx, els_span, default)); let indent = indent_relative_to.and_then(|s| indent_of(cx, s)); - reindent_multiline(extracted.into(), false, indent) + reindent_multiline(&extracted, false, indent) } diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index 47d6fe7db766..019ae16ca859 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -177,7 +177,7 @@ fn fmt_stmts_and_call( stmts_and_call.push(call_snippet_with_replacements); stmts_and_call = stmts_and_call .into_iter() - .map(|v| reindent_multiline(v.into(), true, Some(call_expr_indent)).into_owned()) + .map(|v| reindent_multiline(&v, true, Some(call_expr_indent))) .collect(); let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); @@ -185,8 +185,7 @@ fn fmt_stmts_and_call( let parent_node = cx.tcx.parent_hir_node(call_expr.hir_id); if !matches!(parent_node, Node::Block(_)) && !matches!(parent_node, Node::Stmt(_)) { let block_indent = call_expr_indent + 4; - stmts_and_call_snippet = - reindent_multiline(stmts_and_call_snippet.into(), true, Some(block_indent)).into_owned(); + stmts_and_call_snippet = reindent_multiline(&stmts_and_call_snippet, true, Some(block_indent)); stmts_and_call_snippet = format!( "{{\n{}{}\n{}}}", " ".repeat(block_indent), diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index eecbfb3936ac..096a2f8b9e0c 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -307,7 +307,7 @@ pub fn expr_block( && let ExprKind::Block(block, _) = expr.kind && block.rules != BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) { - format!("{code}") + code } else { // FIXME: add extra indent for the unsafe blocks: // original code: unsafe { ... } @@ -420,11 +420,10 @@ pub fn position_before_rarrow(s: &str) -> Option { } /// Reindent a multiline string with possibility of ignoring the first line. -#[expect(clippy::needless_pass_by_value)] -pub fn reindent_multiline(s: Cow<'_, str>, ignore_first: bool, indent: Option) -> Cow<'_, str> { - let s_space = reindent_multiline_inner(&s, ignore_first, indent, ' '); +pub fn reindent_multiline(s: &str, ignore_first: bool, indent: Option) -> String { + let s_space = reindent_multiline_inner(s, ignore_first, indent, ' '); let s_tab = reindent_multiline_inner(&s_space, ignore_first, indent, '\t'); - reindent_multiline_inner(&s_tab, ignore_first, indent, ' ').into() + reindent_multiline_inner(&s_tab, ignore_first, indent, ' ') } fn reindent_multiline_inner(s: &str, ignore_first: bool, indent: Option, ch: char) -> String { @@ -552,42 +551,37 @@ pub fn snippet_opt(sess: &impl HasSession, span: Span) -> Option { /// } // aligned with `if` /// ``` /// Note that the first line of the snippet always has 0 indentation. -pub fn snippet_block<'a>( - sess: &impl HasSession, - span: Span, - default: &'a str, - indent_relative_to: Option, -) -> Cow<'a, str> { +pub fn snippet_block(sess: &impl HasSession, span: Span, default: &str, indent_relative_to: Option) -> String { let snip = snippet(sess, span, default); let indent = indent_relative_to.and_then(|s| indent_of(sess, s)); - reindent_multiline(snip, true, indent) + reindent_multiline(&snip, true, indent) } /// Same as `snippet_block`, but adapts the applicability level by the rules of /// `snippet_with_applicability`. -pub fn snippet_block_with_applicability<'a>( +pub fn snippet_block_with_applicability( sess: &impl HasSession, span: Span, - default: &'a str, + default: &str, indent_relative_to: Option, applicability: &mut Applicability, -) -> Cow<'a, str> { +) -> String { let snip = snippet_with_applicability(sess, span, default, applicability); let indent = indent_relative_to.and_then(|s| indent_of(sess, s)); - reindent_multiline(snip, true, indent) + reindent_multiline(&snip, true, indent) } -pub fn snippet_block_with_context<'a>( +pub fn snippet_block_with_context( sess: &impl HasSession, span: Span, outer: SyntaxContext, - default: &'a str, + default: &str, indent_relative_to: Option, app: &mut Applicability, -) -> (Cow<'a, str>, bool) { +) -> (String, bool) { let (snip, from_macro) = snippet_with_context(sess, span, outer, default, app); let indent = indent_relative_to.and_then(|s| indent_of(sess, s)); - (reindent_multiline(snip, true, indent), from_macro) + (reindent_multiline(&snip, true, indent), from_macro) } /// Same as `snippet_with_applicability`, but first walks the span up to the given context. @@ -745,11 +739,11 @@ mod test { #[test] fn test_reindent_multiline_single_line() { - assert_eq!("", reindent_multiline("".into(), false, None)); - assert_eq!("...", reindent_multiline("...".into(), false, None)); - assert_eq!("...", reindent_multiline(" ...".into(), false, None)); - assert_eq!("...", reindent_multiline("\t...".into(), false, None)); - assert_eq!("...", reindent_multiline("\t\t...".into(), false, None)); + assert_eq!("", reindent_multiline("", false, None)); + assert_eq!("...", reindent_multiline("...", false, None)); + assert_eq!("...", reindent_multiline(" ...", false, None)); + assert_eq!("...", reindent_multiline("\t...", false, None)); + assert_eq!("...", reindent_multiline("\t\t...", false, None)); } #[test] @@ -764,7 +758,7 @@ mod test { y } else { z - }".into(), false, None)); + }", false, None)); assert_eq!("\ if x { \ty @@ -774,7 +768,7 @@ mod test { \ty } else { \tz - }".into(), false, None)); + }", false, None)); } #[test] @@ -791,7 +785,7 @@ mod test { } else { z - }".into(), false, None)); + }", false, None)); } #[test] @@ -807,6 +801,6 @@ mod test { y } else { z - }".into(), true, Some(8))); + }", true, Some(8))); } } From 4220dbd4b34f0c4cf1c9de1628c6d8b5d20bfd99 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Tue, 4 Feb 2025 12:19:04 +0900 Subject: [PATCH 031/161] allow `assign_op_pattern` in the test of `string_add` --- tests/ui/string_add.rs | 2 +- tests/ui/string_add.stderr | 17 +---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index c535f2ebbfcb..61c812f16c8c 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -4,7 +4,7 @@ extern crate proc_macros; use proc_macros::external; #[warn(clippy::string_add)] -#[allow(clippy::string_add_assign, unused)] +#[allow(clippy::assign_op_pattern, clippy::string_add_assign, unused)] fn main() { // ignores assignment distinction let mut x = String::new(); diff --git a/tests/ui/string_add.stderr b/tests/ui/string_add.stderr index fe6849b894b5..74ff7372e21a 100644 --- a/tests/ui/string_add.stderr +++ b/tests/ui/string_add.stderr @@ -1,12 +1,3 @@ -error: manual implementation of an assign operation - --> tests/ui/string_add.rs:13:9 - | -LL | x = x + "."; - | ^^^^^^^^^^^ help: replace it with: `x += "."` - | - = note: `-D clippy::assign-op-pattern` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` - error: you added something to a string. Consider using `String::push_str()` instead --> tests/ui/string_add.rs:13:13 | @@ -22,11 +13,5 @@ error: you added something to a string. Consider using `String::push_str()` inst LL | let z = y + "..."; | ^^^^^^^^^ -error: manual implementation of an assign operation - --> tests/ui/string_add.rs:22:5 - | -LL | x = x + 1; - | ^^^^^^^^^ help: replace it with: `x += 1` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors From a2f9861df8a817f3e3dd07a228b37d0569b67ece Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Tue, 2 Jul 2024 16:09:13 +0800 Subject: [PATCH 032/161] fix [`manual_map`] not catching type adjustment --- clippy_lints/src/matches/manual_utils.rs | 88 ++++++++++++++++++--- tests/ui/manual_map_option_2.fixed | 93 +++++++++++++++++++++- tests/ui/manual_map_option_2.rs | 99 +++++++++++++++++++++++- tests/ui/manual_map_option_2.stderr | 39 +++++++++- 4 files changed, 302 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index 0b57740064c1..c15e9a50a8e0 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -73,7 +73,7 @@ where } // `map` won't perform any adjustments. - if !cx.typeck_results().expr_adjustments(some_expr.expr).is_empty() { + if expr_has_type_coercion(cx, expr) { return None; } @@ -124,6 +124,12 @@ where }; let closure_expr_snip = some_expr.to_snippet_with_context(cx, expr_ctxt, &mut app); + let closure_body = if some_expr.needs_unsafe_block { + format!("unsafe {}", closure_expr_snip.blockify()) + } else { + closure_expr_snip.to_string() + }; + let body_str = if let PatKind::Binding(annotation, id, some_binding, None) = some_pat.kind { if !some_expr.needs_unsafe_block && let Some(func) = can_pass_as_func(cx, id, some_expr.expr) @@ -145,20 +151,12 @@ where "" }; - if some_expr.needs_unsafe_block { - format!("|{annotation}{some_binding}| unsafe {{ {closure_expr_snip} }}") - } else { - format!("|{annotation}{some_binding}| {closure_expr_snip}") - } + format!("|{annotation}{some_binding}| {closure_body}") } } else if !is_wild_none && explicit_ref.is_none() { // TODO: handle explicit reference annotations. let pat_snip = snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0; - if some_expr.needs_unsafe_block { - format!("|{pat_snip}| unsafe {{ {closure_expr_snip} }}") - } else { - format!("|{pat_snip}| {closure_expr_snip}") - } + format!("|{pat_snip}| {closure_body}") } else { // Refutable bindings and mixed reference annotations can't be handled by `map`. return None; @@ -274,3 +272,71 @@ pub(super) fn try_parse_pattern<'tcx>( fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { is_res_lang_ctor(cx, path_res(cx, peel_blocks(expr)), OptionNone) } + +fn expr_ty_adjusted(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + cx.typeck_results() + .expr_adjustments(expr) + .iter() + // We do not care about exprs with `NeverToAny` adjustments, such as `panic!` call. + .any(|adj| !matches!(adj.kind, Adjust::NeverToAny)) +} + +fn expr_has_type_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool { + if expr.span.from_expansion() { + return false; + } + if expr_ty_adjusted(cx, expr) { + return true; + } + + // Identify coercion sites and recursively check it those sites + // actually has type adjustments. + match expr.kind { + // Function/method calls, including enum initialization. + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) if let Some(def_id) = fn_def_id(cx, expr) => { + let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); + if !fn_sig.output().skip_binder().has_type_flags(TypeFlags::HAS_TY_PARAM) { + return false; + } + let mut args_with_ty_param = fn_sig + .inputs() + .skip_binder() + .iter() + .zip(args) + .filter_map(|(arg_ty, arg)| if arg_ty.has_type_flags(TypeFlags::HAS_TY_PARAM) { + Some(arg) + } else { + None + }); + args_with_ty_param.any(|arg| expr_has_type_coercion(cx, arg)) + }, + // Struct/union initialization. + ExprKind::Struct(_, fields, _) => { + fields.iter().map(|expr_field| expr_field.expr).any(|ex| expr_has_type_coercion(cx, ex)) + }, + // those two `ref` keywords cannot be removed + #[allow(clippy::needless_borrow)] + // Function results, including the final line of a block or a `return` expression. + ExprKind::Block(hir::Block { expr: Some(ref ret_expr), .. }, _) | + ExprKind::Ret(Some(ref ret_expr)) => expr_has_type_coercion(cx, ret_expr), + + // ===== Coercion-propagation expressions ===== + + // Array, where the type is `[U; n]`. + ExprKind::Array(elems) | + // Tuple, `(U_0, U_1, ..., U_n)`. + ExprKind::Tup(elems) => { + elems.iter().any(|elem| expr_has_type_coercion(cx, elem)) + }, + // Array but with repeating syntax. + ExprKind::Repeat(rep_elem, _) => expr_has_type_coercion(cx, rep_elem), + // Others that may contain coercion sites. + ExprKind::If(_, then, maybe_else) => { + expr_has_type_coercion(cx, then) || maybe_else.is_some_and(|e| expr_has_type_coercion(cx, e)) + } + ExprKind::Match(_, arms, _) => { + arms.iter().map(|arm| arm.body).any(|body| expr_has_type_coercion(cx, body)) + } + _ => false + } +} diff --git a/tests/ui/manual_map_option_2.fixed b/tests/ui/manual_map_option_2.fixed index f5bb4e0af1ba..49b9e77b441f 100644 --- a/tests/ui/manual_map_option_2.fixed +++ b/tests/ui/manual_map_option_2.fixed @@ -40,9 +40,14 @@ fn main() { None => None, }; - // Lint. `s` is captured by reference, so no lifetime issues. let s = Some(String::new()); + // Lint. `s` is captured by reference, so no lifetime issues. let _ = s.as_ref().map(|x| { if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }); + // Don't lint this, type of `s` is coercioned from `&String` to `&str` + let x: Option<(String, &str)> = match &s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + }; // Issue #7820 unsafe fn f(x: u32) -> u32 { @@ -54,3 +59,89 @@ fn main() { let _ = Some(0).map(|x| unsafe { f(x) }); let _ = Some(0).map(|x| unsafe { f(x) }); } + +// issue #12659 +mod with_type_coercion { + trait DummyTrait {} + + fn foo Result>(f: F) { + // Don't lint + let _: Option, ()>> = match Some(0) { + Some(_) => Some(match f() { + Ok(res) => Ok(Box::new(res)), + _ => Err(()), + }), + None => None, + }; + + let _: Option> = match Some(()) { + Some(_) => Some(Box::new(b"1234")), + None => None, + }; + + let x = String::new(); + let _: Option> = match Some(()) { + Some(_) => Some(Box::new(&x)), + None => None, + }; + + let _: Option<&str> = match Some(()) { + Some(_) => Some(&x), + None => None, + }; + + //~v ERROR: manual implementation of `Option::map` + let _ = Some(0).map(|_| match f() { + Ok(res) => Ok(Box::new(res)), + _ => Err(()), + }); + } + + #[allow(clippy::redundant_allocation)] + fn bar() { + fn f(_: Option>) {} + fn g(b: &[u8]) -> Box<&[u8]> { + Box::new(b) + } + + let x: &[u8; 4] = b"1234"; + f(match Some(()) { + Some(_) => Some(Box::new(x)), + None => None, + }); + + //~v ERROR: manual implementation of `Option::map` + let _: Option> = Some(0).map(|_| g(x)); + } + + fn with_fn_ret(s: &Option) -> Option<(String, &str)> { + // Don't lint, `map` doesn't work as the return type is adjusted. + match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + } + } + + fn with_fn_ret_2(s: &Option) -> Option<(String, &str)> { + if true { + // Don't lint, `map` doesn't work as the return type is adjusted. + return match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + }; + } + None + } + + #[allow(clippy::needless_late_init)] + fn with_fn_ret_3<'a>(s: &'a Option) -> Option<(String, &'a str)> { + let x: Option<(String, &'a str)>; + x = { + match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + } + }; + x + } +} diff --git a/tests/ui/manual_map_option_2.rs b/tests/ui/manual_map_option_2.rs index cbc2356e0a2d..962455daf7ba 100644 --- a/tests/ui/manual_map_option_2.rs +++ b/tests/ui/manual_map_option_2.rs @@ -43,12 +43,17 @@ fn main() { None => None, }; - // Lint. `s` is captured by reference, so no lifetime issues. let s = Some(String::new()); + // Lint. `s` is captured by reference, so no lifetime issues. let _ = match &s { Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), None => None, }; + // Don't lint this, type of `s` is coercioned from `&String` to `&str` + let x: Option<(String, &str)> = match &s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + }; // Issue #7820 unsafe fn f(x: u32) -> u32 { @@ -69,3 +74,95 @@ fn main() { None => None, }; } + +// issue #12659 +mod with_type_coercion { + trait DummyTrait {} + + fn foo Result>(f: F) { + // Don't lint + let _: Option, ()>> = match Some(0) { + Some(_) => Some(match f() { + Ok(res) => Ok(Box::new(res)), + _ => Err(()), + }), + None => None, + }; + + let _: Option> = match Some(()) { + Some(_) => Some(Box::new(b"1234")), + None => None, + }; + + let x = String::new(); + let _: Option> = match Some(()) { + Some(_) => Some(Box::new(&x)), + None => None, + }; + + let _: Option<&str> = match Some(()) { + Some(_) => Some(&x), + None => None, + }; + + //~v ERROR: manual implementation of `Option::map` + let _ = match Some(0) { + Some(_) => Some(match f() { + Ok(res) => Ok(Box::new(res)), + _ => Err(()), + }), + None => None, + }; + } + + #[allow(clippy::redundant_allocation)] + fn bar() { + fn f(_: Option>) {} + fn g(b: &[u8]) -> Box<&[u8]> { + Box::new(b) + } + + let x: &[u8; 4] = b"1234"; + f(match Some(()) { + Some(_) => Some(Box::new(x)), + None => None, + }); + + //~v ERROR: manual implementation of `Option::map` + let _: Option> = match Some(0) { + Some(_) => Some(g(x)), + None => None, + }; + } + + fn with_fn_ret(s: &Option) -> Option<(String, &str)> { + // Don't lint, `map` doesn't work as the return type is adjusted. + match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + } + } + + fn with_fn_ret_2(s: &Option) -> Option<(String, &str)> { + if true { + // Don't lint, `map` doesn't work as the return type is adjusted. + return match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + }; + } + None + } + + #[allow(clippy::needless_late_init)] + fn with_fn_ret_3<'a>(s: &'a Option) -> Option<(String, &'a str)> { + let x: Option<(String, &'a str)>; + x = { + match s { + Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), + None => None, + } + }; + x + } +} diff --git a/tests/ui/manual_map_option_2.stderr b/tests/ui/manual_map_option_2.stderr index 78e4677544bc..db048221db6a 100644 --- a/tests/ui/manual_map_option_2.stderr +++ b/tests/ui/manual_map_option_2.stderr @@ -32,7 +32,7 @@ LL | | }; | |_____^ help: try: `s.as_ref().map(|x| { if let Some(ref s) = s { (x.clone(), s) } else { panic!() } })` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:58:17 + --> tests/ui/manual_map_option_2.rs:63:17 | LL | let _ = match Some(0) { | _________________^ @@ -42,7 +42,7 @@ LL | | }; | |_________^ help: try: `Some(0).map(|x| f(x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:63:13 + --> tests/ui/manual_map_option_2.rs:68:13 | LL | let _ = match Some(0) { | _____________^ @@ -52,7 +52,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:67:13 + --> tests/ui/manual_map_option_2.rs:72:13 | LL | let _ = match Some(0) { | _____________^ @@ -61,5 +61,36 @@ LL | | None => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` -error: aborting due to 5 previous errors +error: manual implementation of `Option::map` + --> tests/ui/manual_map_option_2.rs:109:17 + | +LL | let _ = match Some(0) { + | _________________^ +LL | | Some(_) => Some(match f() { +LL | | Ok(res) => Ok(Box::new(res)), +LL | | _ => Err(()), +LL | | }), +LL | | None => None, +LL | | }; + | |_________^ + | +help: try + | +LL ~ let _ = Some(0).map(|_| match f() { +LL + Ok(res) => Ok(Box::new(res)), +LL + _ => Err(()), +LL ~ }); + | + +error: manual implementation of `Option::map` + --> tests/ui/manual_map_option_2.rs:132:37 + | +LL | let _: Option> = match Some(0) { + | _____________________________________^ +LL | | Some(_) => Some(g(x)), +LL | | None => None, +LL | | }; + | |_________^ help: try: `Some(0).map(|_| g(x))` + +error: aborting due to 7 previous errors From 2a4be5365abeb75ead816c8a2493af3f4d60aba4 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Sat, 14 Sep 2024 00:11:11 +0800 Subject: [PATCH 033/161] move `expr_requires_coercion` to clippy_utils & some other adjustments --- clippy_lints/src/matches/manual_utils.rs | 74 +------------------- clippy_utils/src/lib.rs | 89 +++++++++++++++++++++++- tests/ui/manual_map_option.fixed | 11 ++- tests/ui/manual_map_option.rs | 6 ++ tests/ui/manual_map_option.stderr | 17 ++--- 5 files changed, 111 insertions(+), 86 deletions(-) diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index c15e9a50a8e0..c5690e9588ca 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -4,8 +4,8 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_copy, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function}; use clippy_utils::{ - CaptureKind, can_move_expr_to_closure, is_else_clause, is_lint_allowed, is_res_lang_ctor, path_res, - path_to_local_id, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, + CaptureKind, can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, is_res_lang_ctor, + path_res, path_to_local_id, peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, }; use rustc_ast::util::parser::ExprPrecedence; use rustc_errors::Applicability; @@ -73,7 +73,7 @@ where } // `map` won't perform any adjustments. - if expr_has_type_coercion(cx, expr) { + if expr_requires_coercion(cx, expr) { return None; } @@ -272,71 +272,3 @@ pub(super) fn try_parse_pattern<'tcx>( fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { is_res_lang_ctor(cx, path_res(cx, peel_blocks(expr)), OptionNone) } - -fn expr_ty_adjusted(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - cx.typeck_results() - .expr_adjustments(expr) - .iter() - // We do not care about exprs with `NeverToAny` adjustments, such as `panic!` call. - .any(|adj| !matches!(adj.kind, Adjust::NeverToAny)) -} - -fn expr_has_type_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool { - if expr.span.from_expansion() { - return false; - } - if expr_ty_adjusted(cx, expr) { - return true; - } - - // Identify coercion sites and recursively check it those sites - // actually has type adjustments. - match expr.kind { - // Function/method calls, including enum initialization. - ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) if let Some(def_id) = fn_def_id(cx, expr) => { - let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); - if !fn_sig.output().skip_binder().has_type_flags(TypeFlags::HAS_TY_PARAM) { - return false; - } - let mut args_with_ty_param = fn_sig - .inputs() - .skip_binder() - .iter() - .zip(args) - .filter_map(|(arg_ty, arg)| if arg_ty.has_type_flags(TypeFlags::HAS_TY_PARAM) { - Some(arg) - } else { - None - }); - args_with_ty_param.any(|arg| expr_has_type_coercion(cx, arg)) - }, - // Struct/union initialization. - ExprKind::Struct(_, fields, _) => { - fields.iter().map(|expr_field| expr_field.expr).any(|ex| expr_has_type_coercion(cx, ex)) - }, - // those two `ref` keywords cannot be removed - #[allow(clippy::needless_borrow)] - // Function results, including the final line of a block or a `return` expression. - ExprKind::Block(hir::Block { expr: Some(ref ret_expr), .. }, _) | - ExprKind::Ret(Some(ref ret_expr)) => expr_has_type_coercion(cx, ret_expr), - - // ===== Coercion-propagation expressions ===== - - // Array, where the type is `[U; n]`. - ExprKind::Array(elems) | - // Tuple, `(U_0, U_1, ..., U_n)`. - ExprKind::Tup(elems) => { - elems.iter().any(|elem| expr_has_type_coercion(cx, elem)) - }, - // Array but with repeating syntax. - ExprKind::Repeat(rep_elem, _) => expr_has_type_coercion(cx, rep_elem), - // Others that may contain coercion sites. - ExprKind::If(_, then, maybe_else) => { - expr_has_type_coercion(cx, then) || maybe_else.is_some_and(|e| expr_has_type_coercion(cx, e)) - } - ExprKind::Match(_, arms, _) => { - arms.iter().map(|arm| arm.body).any(|body| expr_has_type_coercion(cx, body)) - } - _ => false - } -} diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 2f5639b686b8..3ed9313d82bc 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -117,7 +117,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, FloatTy, GenericArgKind, GenericArgsRef, IntTy, Ty, - TyCtxt, TypeVisitableExt, UintTy, UpvarCapture, + TyCtxt, TypeFlags, TypeVisitableExt, UintTy, UpvarCapture, }; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::SourceMap; @@ -3489,3 +3489,90 @@ pub fn leaks_droppable_temporary_with_limited_lifetime<'tcx>(cx: &LateContext<'t }) .is_break() } + +/// Returns true if the specified `expr` requires coercion, +/// meaning that it either has a coercion or propagates a coercion from one of its sub expressions. +/// +/// Similar to [`is_adjusted`], this not only checks if an expression's type was adjusted, +/// but also going through extra steps to see if it fits the description of [coercion sites]. +/// +/// You should used this when you want to avoid suggesting replacing an expression that is currently +/// a coercion site or coercion propagating expression with one that is not. +/// +/// [coercion sites]: https://doc.rust-lang.org/stable/reference/type-coercions.html#coercion-sites +pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool { + let expr_ty_is_adjusted = cx + .typeck_results() + .expr_adjustments(expr) + .iter() + // ignore `NeverToAny` adjustments, such as `panic!` call. + .any(|adj| !matches!(adj.kind, Adjust::NeverToAny)); + if expr_ty_is_adjusted { + return true; + } + + // Identify coercion sites and recursively check if those sites + // actually have type adjustments. + match expr.kind { + ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) if let Some(def_id) = fn_def_id(cx, expr) => { + let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); + + if !fn_sig.output().skip_binder().has_type_flags(TypeFlags::HAS_TY_PARAM) { + return false; + } + + let self_arg_count = usize::from(matches!(expr.kind, ExprKind::MethodCall(..))); + let mut args_with_ty_param = { + fn_sig + .inputs() + .skip_binder() + .iter() + .skip(self_arg_count) + .zip(args) + .filter_map(|(arg_ty, arg)| { + if arg_ty.has_type_flags(TypeFlags::HAS_TY_PARAM) { + Some(arg) + } else { + None + } + }) + }; + args_with_ty_param.any(|arg| expr_requires_coercion(cx, arg)) + }, + // Struct/union initialization. + ExprKind::Struct(qpath, _, _) => { + let res = cx.typeck_results().qpath_res(qpath, expr.hir_id); + if let Some((_, v_def)) = adt_and_variant_of_res(cx, res) { + let generic_args = cx.typeck_results().node_args(expr.hir_id); + v_def + .fields + .iter() + .any(|field| field.ty(cx.tcx, generic_args).has_type_flags(TypeFlags::HAS_TY_PARAM)) + } else { + false + } + }, + // Function results, including the final line of a block or a `return` expression. + ExprKind::Block( + &Block { + expr: Some(ret_expr), .. + }, + _, + ) + | ExprKind::Ret(Some(ret_expr)) => expr_requires_coercion(cx, ret_expr), + + // ===== Coercion-propagation expressions ===== + ExprKind::Array(elems) | ExprKind::Tup(elems) => elems.iter().any(|elem| expr_requires_coercion(cx, elem)), + // Array but with repeating syntax. + ExprKind::Repeat(rep_elem, _) => expr_requires_coercion(cx, rep_elem), + // Others that may contain coercion sites. + ExprKind::If(_, then, maybe_else) => { + expr_requires_coercion(cx, then) || maybe_else.is_some_and(|e| expr_requires_coercion(cx, e)) + }, + ExprKind::Match(_, arms, _) => arms + .iter() + .map(|arm| arm.body) + .any(|body| expr_requires_coercion(cx, body)), + _ => false, + } +} diff --git a/tests/ui/manual_map_option.fixed b/tests/ui/manual_map_option.fixed index 16cee3fd3823..3586979ab358 100644 --- a/tests/ui/manual_map_option.fixed +++ b/tests/ui/manual_map_option.fixed @@ -113,7 +113,16 @@ fn main() { } // #6811 - Some(0).map(|x| vec![x]); + match Some(0) { + Some(x) => Some(vec![x]), + None => None, + }; + + // Don't lint, coercion + let x: Option> = match Some(()) { + Some(_) => Some(vec![b"1234"]), + None => None, + }; option_env!("").map(String::from); diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index 4655acf1406c..2f21628977cf 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -170,6 +170,12 @@ fn main() { None => None, }; + // Don't lint, coercion + let x: Option> = match Some(()) { + Some(_) => Some(vec![b"1234"]), + None => None, + }; + match option_env!("") { Some(x) => Some(String::from(x)), None => None, diff --git a/tests/ui/manual_map_option.stderr b/tests/ui/manual_map_option.stderr index 47cc18303ba5..c496752e2f6d 100644 --- a/tests/ui/manual_map_option.stderr +++ b/tests/ui/manual_map_option.stderr @@ -156,16 +156,7 @@ LL | | }; | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:168:5 - | -LL | / match Some(0) { -LL | | Some(x) => Some(vec![x]), -LL | | None => None, -LL | | }; - | |_____^ help: try: `Some(0).map(|x| vec![x])` - -error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:173:5 + --> tests/ui/manual_map_option.rs:179:5 | LL | / match option_env!("") { LL | | Some(x) => Some(String::from(x)), @@ -174,7 +165,7 @@ LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:193:12 + --> tests/ui/manual_map_option.rs:199:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -185,7 +176,7 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:201:12 + --> tests/ui/manual_map_option.rs:207:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -195,5 +186,5 @@ LL | | None LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` -error: aborting due to 21 previous errors +error: aborting due to 20 previous errors From 60f94459002db4d8674008877fabd98782617104 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Tue, 4 Feb 2025 12:10:49 +0900 Subject: [PATCH 034/161] don't emit lint inside macro in `manual_async_fn` --- clippy_lints/src/manual_async_fn.rs | 1 + tests/ui/manual_async_fn.fixed | 26 ++++++++++++++++++++++++++ tests/ui/manual_async_fn.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 9f3b0957eab1..ba63f980316e 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -62,6 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn { && let Some(closure_body) = desugared_async_block(cx, block) && let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) = cx.tcx.hir_node_by_def_id(fn_def_id) + && !span.from_expansion() { let header_span = span.with_hi(ret_ty.span.hi()); diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index dc1cb8e11fca..ad0266d39e98 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -113,4 +113,30 @@ pub(crate) async fn issue_10450_2() -> i32 { 42 } pub(self) async fn issue_10450_3() -> i32 { 42 } +macro_rules! issue_12407 { + ( + $( + $(#[$m:meta])* + $v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? ( + $($arg_name:ident: $arg_typ:ty),* $(,)? + ) $(-> $ret_ty:ty)? = $e:expr; + )* + ) => { + $( + $(#[$m])* + $v $($($overrides)*)? fn $name$(<$($params)*>)?( + $($arg_name: $arg_typ),* + ) $(-> $ret_ty)? { + $e + } + )* + }; +} + +issue_12407! { + fn _hello() -> impl Future = async {}; + fn non_async() = println!("hello"); + fn foo() = non_async(); +} + fn main() {} diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index 9ca7654a3688..87973222c0bb 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -139,4 +139,30 @@ pub(self) fn issue_10450_3() -> impl Future { async { 42 } } +macro_rules! issue_12407 { + ( + $( + $(#[$m:meta])* + $v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? ( + $($arg_name:ident: $arg_typ:ty),* $(,)? + ) $(-> $ret_ty:ty)? = $e:expr; + )* + ) => { + $( + $(#[$m])* + $v $($($overrides)*)? fn $name$(<$($params)*>)?( + $($arg_name: $arg_typ),* + ) $(-> $ret_ty)? { + $e + } + )* + }; +} + +issue_12407! { + fn _hello() -> impl Future = async {}; + fn non_async() = println!("hello"); + fn foo() = non_async(); +} + fn main() {} From 44fda914d3c9f448765283a80d1e19793c4e7e1b Mon Sep 17 00:00:00 2001 From: Yutaro Ohno Date: Wed, 5 Feb 2025 19:16:50 +0900 Subject: [PATCH 035/161] Correct version of `doc_overindented_list_items` --- clippy_lints/src/doc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 15530c3dbc50..fce46537793d 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -455,7 +455,7 @@ declare_clippy_lint! { /// /// and this line is overindented. /// # fn foo() {} /// ``` - #[clippy::version = "1.80.0"] + #[clippy::version = "1.86.0"] pub DOC_OVERINDENTED_LIST_ITEMS, style, "ensure list items are not overindented" From f3e292da0bd1ca81f8ea8efb2f7ead5d23a4bbb0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 1 Feb 2025 10:06:35 +0000 Subject: [PATCH 036/161] Uniformly handle HIR literals in visitors and lints --- clippy_lints/src/approx_const.rs | 38 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 95c85f250e98..95f64b74044b 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -3,10 +3,10 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv}; use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; use rustc_attr_parsing::RustcVersion; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{HirId, Lit}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_span::symbol; +use rustc_span::{Span, symbol}; use std::f64::consts as f64; declare_clippy_lint! { @@ -73,22 +73,28 @@ impl ApproxConstant { msrv: conf.msrv.clone(), } } +} - fn check_lit(&self, cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) { - match *lit { +impl<'tcx> LateLintPass<'tcx> for ApproxConstant { + fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: &Lit, _negated: bool) { + match lit.node { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F16 => self.check_known_consts(cx, e, s, "f16"), - FloatTy::F32 => self.check_known_consts(cx, e, s, "f32"), - FloatTy::F64 => self.check_known_consts(cx, e, s, "f64"), - FloatTy::F128 => self.check_known_consts(cx, e, s, "f128"), + FloatTy::F16 => self.check_known_consts(cx, lit.span, s, "f16"), + FloatTy::F32 => self.check_known_consts(cx, lit.span, s, "f32"), + FloatTy::F64 => self.check_known_consts(cx, lit.span, s, "f64"), + FloatTy::F128 => self.check_known_consts(cx, lit.span, s, "f128"), }, // FIXME(f16_f128): add `f16` and `f128` when these types become stable. - LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, e, s, "f{32, 64}"), + LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, lit.span, s, "f{32, 64}"), _ => (), } } - fn check_known_consts(&self, cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) { + extract_msrv_attr!(LateContext); +} + +impl ApproxConstant { + fn check_known_consts(&self, cx: &LateContext<'_>, span: Span, s: symbol::Symbol, module: &str) { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { @@ -96,7 +102,7 @@ impl ApproxConstant { span_lint_and_help( cx, APPROX_CONSTANT, - e.span, + span, format!("approximate value of `{module}::consts::{name}` found"), None, "consider using the constant directly", @@ -110,16 +116,6 @@ impl ApproxConstant { impl_lint_pass!(ApproxConstant => [APPROX_CONSTANT]); -impl<'tcx> LateLintPass<'tcx> for ApproxConstant { - fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - if let ExprKind::Lit(lit) = &e.kind { - self.check_lit(cx, &lit.node, e); - } - } - - extract_msrv_attr!(LateContext); -} - /// Returns `false` if the number of significant figures in `value` are /// less than `min_digits`; otherwise, returns true if `value` is equal /// to `constant`, rounded to the number of digits present in `value`. From 5f6dd7a8eb8ea3cea3c53368c5e924bbf799483e Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 6 Feb 2025 12:47:47 +0900 Subject: [PATCH 037/161] remove an outdated line --- clippy_lints/src/transmute/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 1cb0f837227d..7c83a2187990 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -49,7 +49,6 @@ declare_clippy_lint! { "transmutes that are confusing at best, undefined behavior at worst and always useless" } -// FIXME: Move this to `complexity` again, after #5343 is fixed declare_clippy_lint! { /// ### What it does /// Checks for transmutes to the original type of the object From daab21ef9d161cc6b70f9e51f0a70cebd1628dc0 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Jul 2024 21:39:46 +0700 Subject: [PATCH 038/161] Pulicize `clippy_utils::ty::ty_from_hir_ty` And use it in the next commit to avoid ICE. --- clippy_lints/src/zero_sized_map_values.rs | 17 ++--------------- clippy_utils/src/lib.rs | 1 + clippy_utils/src/ty/mod.rs | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 1221abec1abf..3f64d18e1ad4 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -1,10 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item}; +use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, ty_from_hir_ty}; use rustc_hir::{self as hir, AmbigArg, HirId, ItemKind, Node}; -use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, TypeVisitableExt}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -82,15 +81,3 @@ fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { } false } - -fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - cx.maybe_typeck_results() - .and_then(|results| { - if results.hir_owner == hir_ty.hir_id.owner { - results.node_type_opt(hir_ty.hir_id) - } else { - None - } - }) - .unwrap_or_else(|| lower_ty(cx.tcx, hir_ty)) -} diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 2f5639b686b8..23bb44dc1f13 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -39,6 +39,7 @@ extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_hir; +extern crate rustc_hir_analysis; extern crate rustc_hir_typeck; extern crate rustc_index; extern crate rustc_infer; diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index f2bbdda70585..befca19f485e 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -10,6 +10,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, FnDecl, LangItem, TyKind}; +use rustc_hir_analysis::lower_ty; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::mir::ConstValue; @@ -36,6 +37,19 @@ use crate::{def_path_def_ids, match_def_path, path_res}; mod type_certainty; pub use type_certainty::expr_type_is_certain; +/// Lower a [`hir::Ty`] to a [`rustc_middle::Ty`]. +pub fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + cx.maybe_typeck_results() + .and_then(|results| { + if results.hir_owner == hir_ty.hir_id.owner { + results.node_type_opt(hir_ty.hir_id) + } else { + None + } + }) + .unwrap_or_else(|| lower_ty(cx.tcx, hir_ty)) +} + /// Checks if the given type implements copy. pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { cx.type_is_copy_modulo_regions(ty) From 83b97ae7139933bc17de6b5ccc8b01073e3d4949 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Jul 2024 21:42:54 +0700 Subject: [PATCH 039/161] Use `clippy_utils::ty::ty_from_hir_ty` to avoid ICE --- clippy_lints/src/use_self.rs | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 84b6430294f3..e0efc536e34b 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_from_proc_macro; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::ty::same_type_and_consts; +use clippy_utils::ty::{same_type_and_consts, ty_from_hir_ty}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -12,7 +12,6 @@ use rustc_hir::{ self as hir, AmbigArg, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, }; -use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty as MiddleTy; use rustc_session::impl_lint_pass; @@ -73,7 +72,6 @@ impl UseSelf { enum StackItem { Check { impl_id: LocalDefId, - in_body: u32, types_to_skip: FxHashSet, }, NoCheck, @@ -117,7 +115,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .collect(); StackItem::Check { impl_id: item.owner_id.def_id, - in_body: 0, types_to_skip, } } else { @@ -186,27 +183,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } - fn check_body(&mut self, _: &LateContext<'_>, _: &hir::Body<'_>) { - // `lower_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies - // we can use `cx.typeck_results.node_type(..)` to get the `ty::Ty` from a `hir::Ty`. - // However the `node_type()` method can *only* be called in bodies. - if let Some(&mut StackItem::Check { ref mut in_body, .. }) = self.stack.last_mut() { - *in_body = in_body.saturating_add(1); - } - } - - fn check_body_post(&mut self, _: &LateContext<'_>, _: &hir::Body<'_>) { - if let Some(&mut StackItem::Check { ref mut in_body, .. }) = self.stack.last_mut() { - *in_body = in_body.saturating_sub(1); - } - } fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &Ty<'tcx, AmbigArg>) { if !hir_ty.span.from_expansion() && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, - in_body, ref types_to_skip, }) = self.stack.last() && let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind @@ -215,12 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Def(DefKind::TyParam, _) ) && !types_to_skip.contains(&hir_ty.hir_id) - && let ty = if in_body > 0 { - cx.typeck_results().node_type(hir_ty.hir_id) - } else { - // We don't care about ignoring infer vars here - lower_ty(cx.tcx, hir_ty.as_unambig_ty()) - } + && let ty = ty_from_hir_ty(cx, hir_ty) && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() && same_type_and_consts(ty, impl_ty) // Ensure the type we encounter and the one from the impl have the same lifetime parameters. It may be that From 925718d8eb586d143de73e7eb3428cafb25077db Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 21 Jul 2024 00:24:35 +0700 Subject: [PATCH 040/161] Make the "expensive" comment belong to a branch --- clippy_lints/src/use_self.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index e0efc536e34b..994ca9b66906 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -94,8 +94,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { .as_ref() .is_none_or(|params| params.parenthesized == GenericArgsParentheses::No) && !item.span.from_expansion() + // expensive, should be last check && !is_from_proc_macro(cx, item) - // expensive, should be last check { // Self cannot be used inside const generic parameters let types_to_skip = generics From e3e6e6ea4131db92ff23a0e32eb40a353f50f8f6 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 25 Jul 2024 04:13:15 +0700 Subject: [PATCH 041/161] add bug 13092 --- tests/ui/use_self.fixed | 24 ++++++++++++++++++++++++ tests/ui/use_self.rs | 24 ++++++++++++++++++++++++ tests/ui/use_self.stderr | 22 +++++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index ffc5b74d7bd6..c6358a90f1e5 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -667,3 +667,27 @@ mod issue_10371 { } } } + +mod issue_13092 { + use std::cell::RefCell; + macro_rules! macro_inner_item { + ($ty:ty) => { + fn foo(_: $ty) { + fn inner(_: $ty) {} + } + }; + } + + #[derive(Default)] + struct MyStruct; + + impl MyStruct { + macro_inner_item!(Self); + } + + impl MyStruct { + thread_local! { + static SPECIAL: RefCell = RefCell::default(); + } + } +} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index eb9d96168bcd..c900341cadd8 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -667,3 +667,27 @@ mod issue_10371 { } } } + +mod issue_13092 { + use std::cell::RefCell; + macro_rules! macro_inner_item { + ($ty:ty) => { + fn foo(_: $ty) { + fn inner(_: $ty) {} + } + }; + } + + #[derive(Default)] + struct MyStruct; + + impl MyStruct { + macro_inner_item!(MyStruct); + } + + impl MyStruct { + thread_local! { + static SPECIAL: RefCell = RefCell::default(); + } + } +} diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index bd5b685b45d5..06260a598be2 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -259,5 +259,25 @@ error: unnecessary structure name repetition LL | E::A => {}, | ^ help: use the applicable keyword: `Self` -error: aborting due to 43 previous errors +error: unnecessary structure name repetition + --> tests/ui/use_self.rs:685:27 + | +LL | macro_inner_item!(MyStruct); + | ^^^^^^^^ help: use the applicable keyword: `Self` + +error: unnecessary structure name repetition + --> tests/ui/use_self.rs:690:37 + | +LL | static SPECIAL: RefCell = RefCell::default(); + | ^^^^^^^^ help: use the applicable keyword: `Self` + +error: unnecessary structure name repetition + --> tests/ui/use_self.rs:690:37 + | +LL | static SPECIAL: RefCell = RefCell::default(); + | ^^^^^^^^ help: use the applicable keyword: `Self` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 46 previous errors From bcfd0d1aba7b63dd2b571771885375f9e1f66d1f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 5 Sep 2024 00:58:33 +0700 Subject: [PATCH 042/161] Skip `use_self` inside macro expansion of `impl Self` items --- clippy_lints/src/use_self.rs | 14 +++++++++++++- tests/ui/use_self.fixed | 4 ++-- tests/ui/use_self.stderr | 22 +--------------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 994ca9b66906..0d56cf5c2b27 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -128,6 +128,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { + // Checking items of `impl Self` blocks in which macro expands into. + if impl_item.span.from_expansion() { + self.stack.push(StackItem::NoCheck); + return; + } // We want to skip types in trait `impl`s that aren't declared as `Self` in the trait // declaration. The collection of those types is all this method implementation does. if let ImplItemKind::Fn(FnSig { decl, .. }, ..) = impl_item.kind @@ -183,6 +188,13 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } + fn check_impl_item_post(&mut self, _: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { + if impl_item.span.from_expansion() + && let Some(StackItem::NoCheck) = self.stack.last() + { + self.stack.pop(); + } + } fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &Ty<'tcx, AmbigArg>) { if !hir_ty.span.from_expansion() @@ -197,7 +209,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Def(DefKind::TyParam, _) ) && !types_to_skip.contains(&hir_ty.hir_id) - && let ty = ty_from_hir_ty(cx, hir_ty) + && let ty = ty_from_hir_ty(cx, hir_ty.as_unambig_ty()) && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() && same_type_and_consts(ty, impl_ty) // Ensure the type we encounter and the one from the impl have the same lifetime parameters. It may be that diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index c6358a90f1e5..572e919fb2d2 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -682,12 +682,12 @@ mod issue_13092 { struct MyStruct; impl MyStruct { - macro_inner_item!(Self); + macro_inner_item!(MyStruct); } impl MyStruct { thread_local! { - static SPECIAL: RefCell = RefCell::default(); + static SPECIAL: RefCell = RefCell::default(); } } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 06260a598be2..bd5b685b45d5 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -259,25 +259,5 @@ error: unnecessary structure name repetition LL | E::A => {}, | ^ help: use the applicable keyword: `Self` -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:685:27 - | -LL | macro_inner_item!(MyStruct); - | ^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:690:37 - | -LL | static SPECIAL: RefCell = RefCell::default(); - | ^^^^^^^^ help: use the applicable keyword: `Self` - -error: unnecessary structure name repetition - --> tests/ui/use_self.rs:690:37 - | -LL | static SPECIAL: RefCell = RefCell::default(); - | ^^^^^^^^ help: use the applicable keyword: `Self` - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 46 previous errors +error: aborting due to 43 previous errors From 9ea2b6501e3bd3a6a3d030e1215593f00d8f9ed8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 7 Sep 2024 01:15:55 +0700 Subject: [PATCH 043/161] add test to check for popping wrong items co-authored-by: Alex Macleod --- tests/ui/use_self.fixed | 21 +++++++++++++++++++++ tests/ui/use_self.rs | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 572e919fb2d2..b44840d440b2 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -691,3 +691,24 @@ mod issue_13092 { } } } + +mod crash_check_13128 { + struct A; + + impl A { + fn a() { + struct B; + + // pushes a NoCheck + impl Iterator for &B { + // Pops the NoCheck + type Item = A; + + // Lints A -> Self + fn next(&mut self) -> Option { + Some(A) + } + } + } + } +} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index c900341cadd8..342c724c8e48 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -691,3 +691,24 @@ mod issue_13092 { } } } + +mod crash_check_13128 { + struct A; + + impl A { + fn a() { + struct B; + + // pushes a NoCheck + impl Iterator for &B { + // Pops the NoCheck + type Item = A; + + // Lints A -> Self + fn next(&mut self) -> Option { + Some(A) + } + } + } + } +} From 5aa9d7ae7f33a21842c532aa7dcbe98e1df91a15 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 6 Feb 2025 15:00:24 +0100 Subject: [PATCH 044/161] Merge commit '3e3715c31236bff56f1c63a1de2c7bbdfcfb0923' into clippy-subtree-update --- CHANGELOG.md | 4 + book/src/attribs.md | 2 +- book/src/lint_configuration.md | 1 + book/src/lints.md | 13 + clippy_config/src/conf.rs | 1 + clippy_dev/src/new_lint.rs | 28 ++- clippy_dev/src/update_lints.rs | 28 ++- clippy_lints/src/declared_lints.rs | 4 + clippy_lints/src/dereference.rs | 67 ++++-- clippy_lints/src/doc/empty_line_after.rs | 11 +- clippy_lints/src/endian_bytes.rs | 3 +- clippy_lints/src/eta_reduction.rs | 13 +- clippy_lints/src/excessive_nesting.rs | 4 +- clippy_lints/src/format_push_string.rs | 4 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/lib.rs | 2 + clippy_lints/src/loops/manual_slice_fill.rs | 111 +++++++++ clippy_lints/src/loops/mod.rs | 28 +++ clippy_lints/src/manual_div_ceil.rs | 15 +- clippy_lints/src/manual_option_as_slice.rs | 225 ++++++++++++++++++ clippy_lints/src/manual_unwrap_or_default.rs | 34 ++- clippy_lints/src/matches/match_as_ref.rs | 12 +- clippy_lints/src/methods/mod.rs | 68 +++++- .../src/methods/needless_option_take.rs | 18 +- clippy_lints/src/methods/return_and_then.rs | 67 ++++++ clippy_lints/src/methods/unnecessary_fold.rs | 68 ++++-- .../src/methods/unnecessary_lazy_eval.rs | 6 +- clippy_lints/src/misc.rs | 2 +- .../src/multiple_unsafe_ops_per_block.rs | 23 +- clippy_lints/src/mutex_atomic.rs | 30 ++- clippy_lints/src/needless_pass_by_value.rs | 11 +- clippy_lints/src/operators/mod.rs | 3 - clippy_lints/src/precedence.rs | 68 ++++-- clippy_lints/src/ptr.rs | 30 ++- clippy_lints/src/redundant_clone.rs | 12 +- clippy_lints/src/redundant_else.rs | 46 +++- clippy_lints/src/same_name_method.rs | 11 +- clippy_lints/src/size_of_in_element_count.rs | 10 +- clippy_lints/src/to_digit_is_some.rs | 12 +- clippy_lints/src/types/mod.rs | 64 +++-- clippy_lints/src/unconditional_recursion.rs | 11 +- clippy_lints/src/unnecessary_semicolon.rs | 38 ++- clippy_lints/src/unneeded_struct_pattern.rs | 2 +- clippy_lints/src/write.rs | 2 +- clippy_utils/README.md | 2 +- clippy_utils/src/ast_utils/mod.rs | 6 +- clippy_utils/src/lib.rs | 9 + clippy_utils/src/mir/mod.rs | 12 +- clippy_utils/src/msrvs.rs | 5 +- clippy_utils/src/qualify_min_const_fn.rs | 5 +- clippy_utils/src/source.rs | 15 +- clippy_utils/src/str_utils.rs | 10 +- lintcheck/src/config.rs | 9 + lintcheck/src/main.rs | 53 ++++- rust-toolchain | 2 +- tests/ui/cmp_null.fixed | 32 +++ tests/ui/cmp_null.rs | 12 + tests/ui/cmp_null.stderr | 26 +- tests/ui/eta.fixed | 5 + tests/ui/eta.rs | 5 + tests/ui/eta.stderr | 54 +++-- tests/ui/ignored_unit_patterns.fixed | 15 +- tests/ui/ignored_unit_patterns.rs | 15 +- tests/ui/ignored_unit_patterns.stderr | 18 +- .../ui/manual_memcpy/without_loop_counters.rs | 7 +- .../without_loop_counters.stderr | 36 +-- tests/ui/manual_option_as_slice.fixed | 62 +++++ tests/ui/manual_option_as_slice.rs | 71 ++++++ tests/ui/manual_option_as_slice.stderr | 58 +++++ tests/ui/manual_slice_fill.fixed | 101 ++++++++ tests/ui/manual_slice_fill.rs | 110 +++++++++ tests/ui/manual_slice_fill.stderr | 38 +++ .../ui/manual_unwrap_or_default_unfixable.rs | 15 ++ .../manual_unwrap_or_default_unfixable.stderr | 34 +++ tests/ui/needless_option_take.fixed | 58 +++++ tests/ui/needless_option_take.stderr | 36 ++- tests/ui/needless_range_loop.rs | 3 +- tests/ui/needless_range_loop.stderr | 28 +-- tests/ui/precedence.fixed | 8 +- tests/ui/precedence.stderr | 26 +- tests/ui/precedence_bits.fixed | 35 +++ tests/ui/precedence_bits.rs | 35 +++ tests/ui/precedence_bits.stderr | 29 +++ tests/ui/print_literal.fixed | 14 ++ tests/ui/print_literal.rs | 15 ++ tests/ui/print_literal.stderr | 38 ++- tests/ui/redundant_else.fixed | 154 ++++++++++++ tests/ui/redundant_else.stderr | 77 ++++-- tests/ui/return_and_then.fixed | 67 ++++++ tests/ui/return_and_then.rs | 63 +++++ tests/ui/return_and_then.stderr | 101 ++++++++ .../size_of_in_element_count/expressions.rs | 17 +- .../expressions.stderr | 12 +- .../ui/size_of_in_element_count/functions.rs | 45 ++-- .../size_of_in_element_count/functions.stderr | 110 ++++----- tests/ui/toplevel_ref_arg_non_rustfix.stderr | 4 +- .../unnecessary_semicolon.edition2021.fixed | 6 + .../unnecessary_semicolon.edition2024.fixed | 6 + tests/ui/unnecessary_semicolon.rs | 6 + tests/ui/write_literal.fixed | 16 ++ tests/ui/write_literal.rs | 17 ++ tests/ui/write_literal.stderr | 38 ++- util/gh-pages/index_template.html | 23 +- util/gh-pages/script.js | 87 ++++--- util/gh-pages/style.css | 8 +- util/gh-pages/theme.js | 9 + 106 files changed, 2681 insertions(+), 566 deletions(-) create mode 100644 clippy_lints/src/loops/manual_slice_fill.rs create mode 100644 clippy_lints/src/manual_option_as_slice.rs create mode 100644 clippy_lints/src/methods/return_and_then.rs create mode 100644 tests/ui/cmp_null.fixed create mode 100644 tests/ui/manual_option_as_slice.fixed create mode 100644 tests/ui/manual_option_as_slice.rs create mode 100644 tests/ui/manual_option_as_slice.stderr create mode 100644 tests/ui/manual_slice_fill.fixed create mode 100644 tests/ui/manual_slice_fill.rs create mode 100644 tests/ui/manual_slice_fill.stderr create mode 100644 tests/ui/manual_unwrap_or_default_unfixable.rs create mode 100644 tests/ui/manual_unwrap_or_default_unfixable.stderr create mode 100644 tests/ui/needless_option_take.fixed create mode 100644 tests/ui/precedence_bits.fixed create mode 100644 tests/ui/precedence_bits.rs create mode 100644 tests/ui/precedence_bits.stderr create mode 100644 tests/ui/redundant_else.fixed create mode 100644 tests/ui/return_and_then.fixed create mode 100644 tests/ui/return_and_then.rs create mode 100644 tests/ui/return_and_then.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index bc42c07224e1..fa03c953aa59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5765,6 +5765,7 @@ Released 2018-09-13 [`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive [`manual_ok_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err [`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or +[`manual_option_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice [`manual_pattern_char_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison [`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains [`manual_range_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns @@ -5773,6 +5774,7 @@ Released 2018-09-13 [`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain [`manual_rotate`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rotate [`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic +[`manual_slice_fill`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill [`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation [`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once [`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat @@ -5954,6 +5956,7 @@ Released 2018-09-13 [`positional_named_format_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#positional_named_format_parameters [`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma [`precedence`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence +[`precedence_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#precedence_bits [`print_in_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_in_format_impl [`print_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_literal [`print_stderr`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr @@ -6026,6 +6029,7 @@ Released 2018-09-13 [`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else [`result_unit_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err [`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used +[`return_and_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_and_then [`return_self_not_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use [`reverse_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#reverse_range_loop [`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges diff --git a/book/src/attribs.md b/book/src/attribs.md index cf99497bc0fc..9b7f59705041 100644 --- a/book/src/attribs.md +++ b/book/src/attribs.md @@ -5,7 +5,7 @@ To do this, Clippy provides attributes that can be applied to items in the 3rd p ## `#[clippy::format_args]` -_Available since Clippy v1.84_ +_Available since Clippy v1.85_ This attribute can be added to a macro that supports `format!`, `println!`, or similar syntax. It tells Clippy that the macro is a formatting macro, and that the arguments to the macro diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index b8f9fff9c613..dab2630a56fc 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -752,6 +752,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid) * [`manual_repeat_n`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n) * [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain) +* [`manual_slice_fill`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill) * [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once) * [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat) * [`manual_strip`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) diff --git a/book/src/lints.md b/book/src/lints.md index 442dc63914e9..1dd517976601 100644 --- a/book/src/lints.md +++ b/book/src/lints.md @@ -101,5 +101,18 @@ The `clippy::cargo` group gives you suggestions on how to improve your your crate and are not sure if you have all useful information in your `Cargo.toml`. +## Nursery + +The `clippy::nursery` group contains lints which are buggy or need more work. It is **not** +recommended to enable the whole group, but rather cherry-pick lints that are useful for your +code base and your use case. + +## Deprecated + +The `clippy::deprecated` is empty lints that exist to ensure that `#[allow(lintname)]` still +compiles after the lint was deprecated. Deprecation "removes" lints by removing their +functionality and marking them as deprecated, which may cause further warnings but cannot +cause a compiler error. + [Clippy lint documentation]: https://rust-lang.github.io/rust-clippy/ [Clippy 1.0 RFC]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 552141476f3a..a1591188bee7 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -621,6 +621,7 @@ define_Conf! { manual_rem_euclid, manual_repeat_n, manual_retain, + manual_slice_fill, manual_split_once, manual_str_repeat, manual_strip, diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index 35dd986ff614..cc4b26867a20 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { let name_camel = to_camel_case(lint.name); let name_upper = lint_name.to_uppercase(); - result.push_str(&if enable_msrv { - formatdoc!( + if enable_msrv { + let _: fmt::Result = writedoc!( + result, r" use clippy_utils::msrvs::{{self, Msrv}}; use clippy_config::Conf; @@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { use rustc_session::impl_lint_pass; " - ) + ); } else { - formatdoc!( + let _: fmt::Result = writedoc!( + result, r" {pass_import} use rustc_lint::{{{context_import}, {pass_type}}}; use rustc_session::declare_lint_pass; " - ) - }); + ); + } let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category)); - result.push_str(&if enable_msrv { - formatdoc!( + if enable_msrv { + let _: fmt::Result = writedoc!( + result, r" pub struct {name_camel} {{ msrv: Msrv, @@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { // TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed. // TODO: Update msrv config comment in `clippy_config/src/conf.rs` " - ) + ); } else { - formatdoc!( + let _: fmt::Result = writedoc!( + result, r" declare_lint_pass!({name_camel} => [{name_upper}]); impl {pass_type}{pass_lifetimes} for {name_camel} {{}} " - ) - }); + ); + } result } diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index fc0780f89a7f..b80ee5aac7e7 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -985,17 +985,23 @@ mod tests { Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()), ]; let mut expected: HashMap> = HashMap::new(); - expected.insert("group1".to_string(), vec![ - Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()), - Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()), - ]); - expected.insert("group2".to_string(), vec![Lint::new( - "should_assert_eq2", - "group2", - "\"abc\"", - "module_name", - Range::default(), - )]); + expected.insert( + "group1".to_string(), + vec![ + Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()), + Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()), + ], + ); + expected.insert( + "group2".to_string(), + vec![Lint::new( + "should_assert_eq2", + "group2", + "\"abc\"", + "module_name", + Range::default(), + )], + ); assert_eq!(expected, Lint::by_lint_group(lints.into_iter())); } } diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 86bcf8edd578..9fbeab5bf2e1 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -292,6 +292,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::loops::MANUAL_FIND_INFO, crate::loops::MANUAL_FLATTEN_INFO, crate::loops::MANUAL_MEMCPY_INFO, + crate::loops::MANUAL_SLICE_FILL_INFO, crate::loops::MANUAL_WHILE_LET_SOME_INFO, crate::loops::MISSING_SPIN_LOOP_INFO, crate::loops::MUT_RANGE_BOUND_INFO, @@ -321,6 +322,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::manual_let_else::MANUAL_LET_ELSE_INFO, crate::manual_main_separator_str::MANUAL_MAIN_SEPARATOR_STR_INFO, crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO, + crate::manual_option_as_slice::MANUAL_OPTION_AS_SLICE_INFO, crate::manual_range_patterns::MANUAL_RANGE_PATTERNS_INFO, crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO, crate::manual_retain::MANUAL_RETAIN_INFO, @@ -463,6 +465,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::REPEAT_ONCE_INFO, crate::methods::RESULT_FILTER_MAP_INFO, crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO, + crate::methods::RETURN_AND_THEN_INFO, crate::methods::SEARCH_IS_SOME_INFO, crate::methods::SEEK_FROM_CURRENT_INFO, crate::methods::SEEK_TO_START_INSTEAD_OF_REWIND_INFO, @@ -626,6 +629,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::permissions_set_readonly_false::PERMISSIONS_SET_READONLY_FALSE_INFO, crate::pointers_in_nomem_asm_block::POINTERS_IN_NOMEM_ASM_BLOCK_INFO, crate::precedence::PRECEDENCE_INFO, + crate::precedence::PRECEDENCE_BITS_INFO, crate::ptr::CMP_NULL_INFO, crate::ptr::INVALID_NULL_PTR_USAGE_INFO, crate::ptr::MUT_FROM_REF_INFO, diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 123e358d7c3d..233ebe00d8e7 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -291,10 +291,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { && let Some(ty) = use_node.defined_ty(cx) && TyCoercionStability::for_defined_ty(cx, ty, use_node.is_return()).is_deref_stable() { - self.state = Some((State::ExplicitDeref { mutability: None }, StateData { - first_expr: expr, - adjusted_ty, - })); + self.state = Some(( + State::ExplicitDeref { mutability: None }, + StateData { + first_expr: expr, + adjusted_ty, + }, + )); } }, RefOp::Method { mutbl, is_ufcs } @@ -456,10 +459,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { && next_adjust.is_none_or(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_))) && iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_))) { - self.state = Some((State::Borrow { mutability }, StateData { - first_expr: expr, - adjusted_ty, - })); + self.state = Some(( + State::Borrow { mutability }, + StateData { + first_expr: expr, + adjusted_ty, + }, + )); } }, _ => {}, @@ -503,10 +509,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { let stability = state.stability; report(cx, expr, State::DerefedBorrow(state), data, typeck); if stability.is_deref_stable() { - self.state = Some((State::Borrow { mutability }, StateData { - first_expr: expr, - adjusted_ty, - })); + self.state = Some(( + State::Borrow { mutability }, + StateData { + first_expr: expr, + adjusted_ty, + }, + )); } }, (Some((State::DerefedBorrow(state), data)), RefOp::Deref) => { @@ -531,10 +540,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { } else if stability.is_deref_stable() && let Some(parent) = get_parent_expr(cx, expr) { - self.state = Some((State::ExplicitDeref { mutability: None }, StateData { - first_expr: parent, - adjusted_ty, - })); + self.state = Some(( + State::ExplicitDeref { mutability: None }, + StateData { + first_expr: parent, + adjusted_ty, + }, + )); } }, @@ -1124,17 +1136,20 @@ impl<'tcx> Dereferencing<'tcx> { if let Some(outer_pat) = self.ref_locals.get_mut(&local) { if let Some(pat) = outer_pat { // Check for auto-deref - if !matches!(cx.typeck_results().expr_adjustments(e), [ - Adjustment { - kind: Adjust::Deref(_), + if !matches!( + cx.typeck_results().expr_adjustments(e), + [ + Adjustment { + kind: Adjust::Deref(_), + .. + }, + Adjustment { + kind: Adjust::Deref(_), + .. + }, .. - }, - Adjustment { - kind: Adjust::Deref(_), - .. - }, - .. - ]) { + ] + ) { match get_parent_expr(cx, e) { // Field accesses are the same no matter the number of references. Some(Expr { diff --git a/clippy_lints/src/doc/empty_line_after.rs b/clippy_lints/src/doc/empty_line_after.rs index 099194d4e746..6e85c6af642b 100644 --- a/clippy_lints/src/doc/empty_line_after.rs +++ b/clippy_lints/src/doc/empty_line_after.rs @@ -233,10 +233,13 @@ fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool { if let Some(owner) = cx.last_node_with_lint_attrs.as_owner() { let def_id = owner.to_def_id(); let def_descr = cx.tcx.def_descr(def_id); - diag.span_label(cx.tcx.def_span(def_id), match kind { - StopKind::Attr => format!("the attribute applies to this {def_descr}"), - StopKind::Doc(_) => format!("the comment documents this {def_descr}"), - }); + diag.span_label( + cx.tcx.def_span(def_id), + match kind { + StopKind::Attr => format!("the attribute applies to this {def_descr}"), + StopKind::Doc(_) => format!("the comment documents this {def_descr}"), + }, + ); } diag.multipart_suggestion_with_style( diff --git a/clippy_lints/src/endian_bytes.rs b/clippy_lints/src/endian_bytes.rs index 29deaaf3bc7a..a7670ffce887 100644 --- a/clippy_lints/src/endian_bytes.rs +++ b/clippy_lints/src/endian_bytes.rs @@ -6,6 +6,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::Ty; use rustc_session::declare_lint_pass; use rustc_span::Symbol; +use std::fmt::Write; declare_clippy_lint! { /// ### What it does @@ -183,7 +184,7 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix help_str.push_str("either of "); } - help_str.push_str(&format!("`{ty}::{}` ", lint.as_name(prefix))); + write!(help_str, "`{ty}::{}` ", lint.as_name(prefix)).unwrap(); if i != len && !only_one { help_str.push_str("or "); diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 52b699274bbb..f90bf9157aad 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::higher::VecArgs; -use clippy_utils::source::snippet_opt; +use clippy_utils::source::{snippet_opt, snippet_with_applicability}; use clippy_utils::ty::get_type_diagnostic_name; use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::{ get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id, }; use rustc_errors::Applicability; -use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Safety, TyKind}; +use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ @@ -239,6 +239,11 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx && !cx.tcx.has_attr(method_def_id, sym::track_caller) && check_sig(closure_sig, cx.tcx.fn_sig(method_def_id).skip_binder().skip_binder()) { + let mut app = Applicability::MachineApplicable; + let generic_args = match path.args.and_then(GenericArgs::span_ext) { + Some(span) => format!("::{}", snippet_with_applicability(cx, span, "<..>", &mut app)), + None => String::new(), + }; span_lint_and_then( cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, @@ -251,8 +256,8 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx diag.span_suggestion( expr.span, "replace the closure with the method itself", - format!("{}::{}", type_name, path.ident.name), - Applicability::MachineApplicable, + format!("{}::{}{}", type_name, path.ident.name, generic_args), + app, ); }, ); diff --git a/clippy_lints/src/excessive_nesting.rs b/clippy_lints/src/excessive_nesting.rs index 36567b3ded0b..1d3ae8949441 100644 --- a/clippy_lints/src/excessive_nesting.rs +++ b/clippy_lints/src/excessive_nesting.rs @@ -124,7 +124,9 @@ struct NestingVisitor<'conf, 'cx> { impl NestingVisitor<'_, '_> { fn check_indent(&mut self, span: Span, id: NodeId) -> bool { - if self.nest_level > self.conf.excessive_nesting_threshold && !span.in_external_macro(self.cx.sess().source_map()) { + if self.nest_level > self.conf.excessive_nesting_threshold + && !span.in_external_macro(self.cx.sess().source_map()) + { self.conf.nodes.insert(id); return true; diff --git a/clippy_lints/src/format_push_string.rs b/clippy_lints/src/format_push_string.rs index 8b1f86cbb913..68cc50f39391 100644 --- a/clippy_lints/src/format_push_string.rs +++ b/clippy_lints/src/format_push_string.rs @@ -11,7 +11,7 @@ declare_clippy_lint! { /// Detects cases where the result of a `format!` call is /// appended to an existing `String`. /// - /// ### Why restrict this? + /// ### Why is this bad? /// Introduces an extra, avoidable heap allocation. /// /// ### Known problems @@ -35,7 +35,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.62.0"] pub FORMAT_PUSH_STRING, - restriction, + pedantic, "`format!(..)` appended to existing `String`" } declare_lint_pass!(FormatPushString => [FORMAT_PUSH_STRING]); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 6f5c5d6b3ea3..c68499ce9f78 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -7,8 +7,8 @@ use clippy_utils::macros::macro_backtrace; use clippy_utils::source::snippet; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty; +use rustc_middle::ty::layout::LayoutOf; use rustc_session::impl_lint_pass; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 4b700673d0f8..8887ab7ec0d7 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -217,6 +217,7 @@ mod manual_is_power_of_two; mod manual_let_else; mod manual_main_separator_str; mod manual_non_exhaustive; +mod manual_option_as_slice; mod manual_range_patterns; mod manual_rem_euclid; mod manual_retain; @@ -976,5 +977,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(unneeded_struct_pattern::UnneededStructPattern)); store.register_late_pass(|_| Box::::default()); store.register_late_pass(move |_| Box::new(non_std_lazy_statics::NonStdLazyStatic::new(conf))); + store.register_late_pass(|_| Box::new(manual_option_as_slice::ManualOptionAsSlice::new(conf))); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs new file mode 100644 index 000000000000..7c6564235796 --- /dev/null +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -0,0 +1,111 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::eager_or_lazy::switch_to_eager_eval; +use clippy_utils::macros::span_is_local; +use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::source::{HasSession, snippet_with_applicability}; +use clippy_utils::ty::implements_trait; +use clippy_utils::{higher, peel_blocks_with_stmt, span_contains_comment}; +use rustc_ast::ast::LitKind; +use rustc_ast::{RangeLimits, UnOp}; +use rustc_data_structures::packed::Pu128; +use rustc_errors::Applicability; +use rustc_hir::QPath::Resolved; +use rustc_hir::def::Res; +use rustc_hir::{Expr, ExprKind, Pat}; +use rustc_lint::LateContext; +use rustc_span::source_map::Spanned; +use rustc_span::sym; + +use super::MANUAL_SLICE_FILL; + +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, + msrv: &Msrv, +) { + if !msrv.meets(msrvs::SLICE_FILL) { + return; + } + + // `for _ in 0..slice.len() { slice[_] = value; }` + if let Some(higher::Range { + start: Some(start), + end: Some(end), + limits: RangeLimits::HalfOpen, + }) = higher::Range::hir(arg) + && let ExprKind::Lit(Spanned { + node: LitKind::Int(Pu128(0), _), + .. + }) = start.kind + && let ExprKind::Block(..) = body.kind + // Check if the body is an assignment to a slice element. + && let ExprKind::Assign(assignee, assignval, _) = peel_blocks_with_stmt(body).kind + && let ExprKind::Index(slice, _, _) = assignee.kind + // Check if `len()` is used for the range end. + && let ExprKind::MethodCall(path, recv,..) = end.kind + && path.ident.name == sym::len + // Check if the slice which is being assigned to is the same as the one being iterated over. + && let ExprKind::Path(Resolved(_, recv_path)) = recv.kind + && let ExprKind::Path(Resolved(_, slice_path)) = slice.kind + && recv_path.res == slice_path.res + && !assignval.span.from_expansion() + // It is generally not equivalent to use the `fill` method if `assignval` can have side effects + && switch_to_eager_eval(cx, assignval) + && span_is_local(assignval.span) + // The `fill` method requires that the slice's element type implements the `Clone` trait. + && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() + && implements_trait(cx, cx.typeck_results().expr_ty(slice), clone_trait, &[]) + { + sugg(cx, body, expr, slice.span, assignval.span); + } + // `for _ in &mut slice { *_ = value; }` + else if let ExprKind::AddrOf(_, _, recv) = arg.kind + // Check if the body is an assignment to a slice element. + && let ExprKind::Assign(assignee, assignval, _) = peel_blocks_with_stmt(body).kind + && let ExprKind::Unary(UnOp::Deref, slice_iter) = assignee.kind + && let ExprKind::Path(Resolved(_, recv_path)) = recv.kind + // Check if the slice which is being assigned to is the same as the one being iterated over. + && let ExprKind::Path(Resolved(_, slice_path)) = slice_iter.kind + && let Res::Local(local) = slice_path.res + && local == pat.hir_id + && !assignval.span.from_expansion() + && switch_to_eager_eval(cx, assignval) + && span_is_local(assignval.span) + // The `fill` method cannot be used if the slice's element type does not implement the `Clone` trait. + && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() + && implements_trait(cx, cx.typeck_results().expr_ty(recv), clone_trait, &[]) + { + sugg(cx, body, expr, recv_path.span, assignval.span); + } +} + +fn sugg<'tcx>( + cx: &LateContext<'tcx>, + body: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, + slice_span: rustc_span::Span, + assignval_span: rustc_span::Span, +) { + let mut app = if span_contains_comment(cx.sess().source_map(), body.span) { + Applicability::MaybeIncorrect // Comments may be informational. + } else { + Applicability::MachineApplicable + }; + + span_lint_and_sugg( + cx, + MANUAL_SLICE_FILL, + expr.span, + "manually filling a slice", + "try", + format!( + "{}.fill({});", + snippet_with_applicability(cx, slice_span, "..", &mut app), + snippet_with_applicability(cx, assignval_span, "..", &mut app), + ), + app, + ); +} diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index c5e75af2303c..cdc8c18c3b74 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -8,6 +8,7 @@ mod iter_next_loop; mod manual_find; mod manual_flatten; mod manual_memcpy; +mod manual_slice_fill; mod manual_while_let_some; mod missing_spin_loop; mod mut_range_bound; @@ -714,6 +715,31 @@ declare_clippy_lint! { "possibly unintended infinite loop" } +declare_clippy_lint! { + /// ### What it does + /// Checks for manually filling a slice with a value. + /// + /// ### Why is this bad? + /// Using the `fill` method is more idiomatic and concise. + /// + /// ### Example + /// ```no_run + /// let mut some_slice = [1, 2, 3, 4, 5]; + /// for i in 0..some_slice.len() { + /// some_slice[i] = 0; + /// } + /// ``` + /// Use instead: + /// ```no_run + /// let mut some_slice = [1, 2, 3, 4, 5]; + /// some_slice.fill(0); + /// ``` + #[clippy::version = "1.86.0"] + pub MANUAL_SLICE_FILL, + style, + "manually filling a slice with a value" +} + pub struct Loops { msrv: Msrv, enforce_iter_loop_reborrow: bool, @@ -750,6 +776,7 @@ impl_lint_pass!(Loops => [ MANUAL_WHILE_LET_SOME, UNUSED_ENUMERATE_INDEX, INFINITE_LOOP, + MANUAL_SLICE_FILL, ]); impl<'tcx> LateLintPass<'tcx> for Loops { @@ -823,6 +850,7 @@ impl Loops { ) { let is_manual_memcpy_triggered = manual_memcpy::check(cx, pat, arg, body, expr); if !is_manual_memcpy_triggered { + manual_slice_fill::check(cx, pat, arg, body, expr, &self.msrv); needless_range_loop::check(cx, pat, arg, body, expr); explicit_counter_loop::check(cx, pat, arg, body, expr, label); } diff --git a/clippy_lints/src/manual_div_ceil.rs b/clippy_lints/src/manual_div_ceil.rs index 816ca17b3d2d..04357cdd8f66 100644 --- a/clippy_lints/src/manual_div_ceil.rs +++ b/clippy_lints/src/manual_div_ceil.rs @@ -181,13 +181,16 @@ fn build_suggestion( ExprKind::Lit(Spanned { node: LitKind::Int(_, LitIntType::Unsuffixed), .. - }) | ExprKind::Unary(UnOp::Neg, Expr { - kind: ExprKind::Lit(Spanned { - node: LitKind::Int(_, LitIntType::Unsuffixed), + }) | ExprKind::Unary( + UnOp::Neg, + Expr { + kind: ExprKind::Lit(Spanned { + node: LitKind::Int(_, LitIntType::Unsuffixed), + .. + }), .. - }), - .. - }) + } + ) ) { format!("_{}", cx.typeck_results().expr_ty(rhs)) } else { diff --git a/clippy_lints/src/manual_option_as_slice.rs b/clippy_lints/src/manual_option_as_slice.rs new file mode 100644 index 000000000000..5c40c945c690 --- /dev/null +++ b/clippy_lints/src/manual_option_as_slice.rs @@ -0,0 +1,225 @@ +use clippy_config::Conf; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::{is_none_arm, msrvs, peel_hir_expr_refs}; +use rustc_errors::Applicability; +use rustc_hir::def::{DefKind, Res}; +use rustc_hir::{Arm, Expr, ExprKind, LangItem, Pat, PatKind, QPath, is_range_literal}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; +use rustc_session::impl_lint_pass; +use rustc_span::{Span, Symbol, sym}; + +declare_clippy_lint! { + /// ### What it does + /// This detects various manual reimplementations of `Option::as_slice`. + /// + /// ### Why is this bad? + /// Those implementations are both more complex than calling `as_slice` + /// and unlike that incur a branch, pessimizing performance and leading + /// to more generated code. + /// + /// ### Example + /// ```no_run + ///# let opt = Some(1); + /// _ = opt.as_ref().map_or(&[][..], std::slice::from_ref); + /// _ = match opt.as_ref() { + /// Some(f) => std::slice::from_ref(f), + /// None => &[], + /// }; + /// ``` + /// Use instead: + /// ```no_run + ///# let opt = Some(1); + /// _ = opt.as_slice(); + /// _ = opt.as_slice(); + /// ``` + #[clippy::version = "1.85.0"] + pub MANUAL_OPTION_AS_SLICE, + complexity, + "manual `Option::as_slice`" +} + +pub struct ManualOptionAsSlice { + msrv: msrvs::Msrv, +} + +impl ManualOptionAsSlice { + pub fn new(conf: &Conf) -> Self { + Self { + msrv: conf.msrv.clone(), + } + } +} + +impl_lint_pass!(ManualOptionAsSlice => [MANUAL_OPTION_AS_SLICE]); + +impl LateLintPass<'_> for ManualOptionAsSlice { + extract_msrv_attr!(LateContext); + + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { + let span = expr.span; + if span.from_expansion() + || !self.msrv.meets(if clippy_utils::is_in_const_context(cx) { + msrvs::CONST_OPTION_AS_SLICE + } else { + msrvs::OPTION_AS_SLICE + }) + { + return; + } + match expr.kind { + ExprKind::Match(scrutinee, [arm1, arm2], _) => { + if is_none_arm(cx, arm2) && check_arms(cx, arm2, arm1) + || is_none_arm(cx, arm1) && check_arms(cx, arm1, arm2) + { + check_as_ref(cx, scrutinee, span); + } + }, + ExprKind::If(cond, then, Some(other)) => { + if let ExprKind::Let(let_expr) = cond.kind + && let Some(binding) = extract_ident_from_some_pat(cx, let_expr.pat) + && check_some_body(cx, binding, then) + && is_empty_slice(cx, other.peel_blocks()) + { + check_as_ref(cx, let_expr.init, span); + } + }, + ExprKind::MethodCall(seg, callee, [], _) => { + if seg.ident.name.as_str() == "unwrap_or_default" { + check_map(cx, callee, span); + } + }, + ExprKind::MethodCall(seg, callee, [or], _) => match seg.ident.name.as_str() { + "unwrap_or" => { + if is_empty_slice(cx, or) { + check_map(cx, callee, span); + } + }, + "unwrap_or_else" => { + if returns_empty_slice(cx, or) { + check_map(cx, callee, span); + } + }, + _ => {}, + }, + ExprKind::MethodCall(seg, callee, [or_else, map], _) => match seg.ident.name.as_str() { + "map_or" => { + if is_empty_slice(cx, or_else) && is_slice_from_ref(cx, map) { + check_as_ref(cx, callee, span); + } + }, + "map_or_else" => { + if returns_empty_slice(cx, or_else) && is_slice_from_ref(cx, map) { + check_as_ref(cx, callee, span); + } + }, + _ => {}, + }, + _ => {}, + } + } +} + +fn check_map(cx: &LateContext<'_>, map: &Expr<'_>, span: Span) { + if let ExprKind::MethodCall(seg, callee, [mapping], _) = map.kind + && seg.ident.name == sym::map + && is_slice_from_ref(cx, mapping) + { + check_as_ref(cx, callee, span); + } +} + +fn check_as_ref(cx: &LateContext<'_>, expr: &Expr<'_>, span: Span) { + if let ExprKind::MethodCall(seg, callee, [], _) = expr.kind + && seg.ident.name == sym::as_ref + && let ty::Adt(adtdef, ..) = cx.typeck_results().expr_ty(callee).kind() + && cx.tcx.is_diagnostic_item(sym::Option, adtdef.did()) + { + if let Some(snippet) = clippy_utils::source::snippet_opt(cx, callee.span) { + span_lint_and_sugg( + cx, + MANUAL_OPTION_AS_SLICE, + span, + "use `Option::as_slice`", + "use", + format!("{snippet}.as_slice()"), + Applicability::MachineApplicable, + ); + } else { + span_lint(cx, MANUAL_OPTION_AS_SLICE, span, "use `Option_as_slice`"); + } + } +} + +fn extract_ident_from_some_pat(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option { + if let PatKind::TupleStruct(QPath::Resolved(None, path), [binding], _) = pat.kind + && let Res::Def(DefKind::Ctor(..), def_id) = path.res + && let PatKind::Binding(_mode, _hir_id, ident, _inner_pat) = binding.kind + && clippy_utils::is_lang_item_or_ctor(cx, def_id, LangItem::OptionSome) + { + Some(ident.name) + } else { + None + } +} + +/// Returns true if `expr` is `std::slice::from_ref()`. Used in `if let`s. +fn check_some_body(cx: &LateContext<'_>, name: Symbol, expr: &Expr<'_>) -> bool { + if let ExprKind::Call(slice_from_ref, [arg]) = expr.peel_blocks().kind + && is_slice_from_ref(cx, slice_from_ref) + && let ExprKind::Path(QPath::Resolved(None, path)) = arg.kind + && let [seg] = path.segments + { + seg.ident.name == name + } else { + false + } +} + +fn check_arms(cx: &LateContext<'_>, none_arm: &Arm<'_>, some_arm: &Arm<'_>) -> bool { + if none_arm.guard.is_none() + && some_arm.guard.is_none() + && is_empty_slice(cx, none_arm.body) + && let Some(name) = extract_ident_from_some_pat(cx, some_arm.pat) + { + check_some_body(cx, name, some_arm.body) + } else { + false + } +} + +fn returns_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + match expr.kind { + ExprKind::Path(_) => clippy_utils::is_path_diagnostic_item(cx, expr, sym::default_fn), + ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir().body(cl.body).value), + _ => false, + } +} + +/// Returns if expr returns an empty slice. If: +/// - An indexing operation to an empty array with a built-in range. `[][..]` +/// - An indexing operation with a zero-ended range. `expr[..0]` +/// - A reference to an empty array. `&[]` +/// - Or a call to `Default::default`. +fn is_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + let expr = peel_hir_expr_refs(expr.peel_blocks()).0; + match expr.kind { + ExprKind::Index(arr, range, _) => match arr.kind { + ExprKind::Array([]) => is_range_literal(range), + ExprKind::Array(_) => { + let Some(range) = clippy_utils::higher::Range::hir(range) else { + return false; + }; + range.end.is_some_and(|e| clippy_utils::is_integer_const(cx, e, 0)) + }, + _ => false, + }, + ExprKind::Array([]) => true, + ExprKind::Call(def, []) => clippy_utils::is_path_diagnostic_item(cx, def, sym::default_fn), + _ => false, + } +} + +fn is_slice_from_ref(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + clippy_utils::is_expr_path_def_path(cx, expr, &["core", "slice", "raw", "from_ref"]) +} diff --git a/clippy_lints/src/manual_unwrap_or_default.rs b/clippy_lints/src/manual_unwrap_or_default.rs index 7b95399c907c..87d2faa225c5 100644 --- a/clippy_lints/src/manual_unwrap_or_default.rs +++ b/clippy_lints/src/manual_unwrap_or_default.rs @@ -9,8 +9,8 @@ use rustc_span::sym; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::IfLetOrMatch; use clippy_utils::sugg::Sugg; -use clippy_utils::ty::implements_trait; -use clippy_utils::{is_default_equivalent, is_in_const_context, peel_blocks, span_contains_comment}; +use clippy_utils::ty::{expr_type_is_certain, implements_trait}; +use clippy_utils::{is_default_equivalent, is_in_const_context, path_res, peel_blocks, span_contains_comment}; declare_clippy_lint! { /// ### What it does @@ -158,6 +158,36 @@ fn handle<'tcx>(cx: &LateContext<'tcx>, if_let_or_match: IfLetOrMatch<'tcx>, exp } else { Applicability::MachineApplicable }; + + // We now check if the condition is a None variant, in which case we need to specify the type + if path_res(cx, condition) + .opt_def_id() + .is_some_and(|id| Some(cx.tcx.parent(id)) == cx.tcx.lang_items().option_none_variant()) + { + return span_lint_and_sugg( + cx, + MANUAL_UNWRAP_OR_DEFAULT, + expr.span, + format!("{expr_name} can be simplified with `.unwrap_or_default()`"), + "replace it with", + format!("{receiver}::<{expr_type}>.unwrap_or_default()"), + applicability, + ); + } + + // We check if the expression type is still uncertain, in which case we ask the user to specify it + if !expr_type_is_certain(cx, condition) { + return span_lint_and_sugg( + cx, + MANUAL_UNWRAP_OR_DEFAULT, + expr.span, + format!("{expr_name} can be simplified with `.unwrap_or_default()`"), + format!("ascribe the type {expr_type} and replace your expression with"), + format!("{receiver}.unwrap_or_default()"), + Applicability::Unspecified, + ); + } + span_lint_and_sugg( cx, MANUAL_UNWRAP_OR_DEFAULT, diff --git a/clippy_lints/src/matches/match_as_ref.rs b/clippy_lints/src/matches/match_as_ref.rs index b1889d26c932..1cb4b512a30e 100644 --- a/clippy_lints/src/matches/match_as_ref.rs +++ b/clippy_lints/src/matches/match_as_ref.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks}; +use clippy_utils::{is_none_arm, is_res_lang_ctor, path_res, peel_blocks}; use rustc_errors::Applicability; -use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatExpr, PatExprKind, PatKind, QPath}; +use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; @@ -55,14 +55,6 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: } } -// Checks if arm has the form `None => None` -fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { - matches!( - arm.pat.kind, - PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), .. }) if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionNone) - ) -} - // Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`) fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option { if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 2f447775fa5b..f501cf060c2a 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -95,6 +95,7 @@ mod readonly_write_lock; mod redundant_as_str; mod repeat_once; mod result_map_or_else_none; +mod return_and_then; mod search_is_some; mod seek_from_current; mod seek_to_start_instead_of_rewind; @@ -3517,7 +3518,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.73.0"] pub FORMAT_COLLECT, - perf, + pedantic, "`format!`ing every element in a collection, then collecting the strings into a new `String`" } @@ -4365,7 +4366,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for string slices immediantly followed by `as_bytes`. + /// Checks for string slices immediately followed by `as_bytes`. /// /// ### Why is this bad? /// It involves doing an unnecessary UTF-8 alignment check which is less efficient, and can cause a panic. @@ -4391,6 +4392,46 @@ declare_clippy_lint! { "slicing a string and immediately calling as_bytes is less efficient and can lead to panics" } +declare_clippy_lint! { + /// ### What it does + /// + /// Detect functions that end with `Option::and_then` or `Result::and_then`, and suggest using a question mark (`?`) instead. + /// + /// ### Why is this bad? + /// + /// The `and_then` method is used to chain a computation that returns an `Option` or a `Result`. + /// This can be replaced with the `?` operator, which is more concise and idiomatic. + /// + /// ### Example + /// + /// ```no_run + /// fn test(opt: Option) -> Option { + /// opt.and_then(|n| { + /// if n > 1 { + /// Some(n + 1) + /// } else { + /// None + /// } + /// }) + /// } + /// ``` + /// Use instead: + /// ```no_run + /// fn test(opt: Option) -> Option { + /// let n = opt?; + /// if n > 1 { + /// Some(n + 1) + /// } else { + /// None + /// } + /// } + /// ``` + #[clippy::version = "1.86.0"] + pub RETURN_AND_THEN, + restriction, + "using `Option::and_then` or `Result::and_then` to chain a computation that returns an `Option` or a `Result`" +} + pub struct Methods { avoid_breaking_exported_api: bool, msrv: Msrv, @@ -4560,6 +4601,7 @@ impl_lint_pass!(Methods => [ USELESS_NONZERO_NEW_UNCHECKED, MANUAL_REPEAT_N, SLICED_STRING_AS_BYTES, + RETURN_AND_THEN, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4789,7 +4831,10 @@ impl Methods { let biom_option_linted = bind_instead_of_map::check_and_then_some(cx, expr, recv, arg); let biom_result_linted = bind_instead_of_map::check_and_then_ok(cx, expr, recv, arg); if !biom_option_linted && !biom_result_linted { - unnecessary_lazy_eval::check(cx, expr, recv, arg, "and"); + let ule_and_linted = unnecessary_lazy_eval::check(cx, expr, recv, arg, "and"); + if !ule_and_linted { + return_and_then::check(cx, expr, recv, arg); + } } }, ("any", [arg]) => { @@ -5003,7 +5048,9 @@ impl Methods { get_first::check(cx, expr, recv, arg); get_last_with_len::check(cx, expr, recv, arg); }, - ("get_or_insert_with", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "get_or_insert"), + ("get_or_insert_with", [arg]) => { + unnecessary_lazy_eval::check(cx, expr, recv, arg, "get_or_insert"); + }, ("hash", [arg]) => { unit_hash::check(cx, expr, recv, arg); }, @@ -5144,7 +5191,9 @@ impl Methods { }, _ => iter_nth_zero::check(cx, expr, recv, n_arg), }, - ("ok_or_else", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "ok_or"), + ("ok_or_else", [arg]) => { + unnecessary_lazy_eval::check(cx, expr, recv, arg, "ok_or"); + }, ("open", [_]) => { open_options::check(cx, expr, recv); }, @@ -5437,9 +5486,12 @@ impl ShouldImplTraitCase { fn lifetime_param_cond(&self, impl_item: &hir::ImplItem<'_>) -> bool { self.lint_explicit_lifetime || !impl_item.generics.params.iter().any(|p| { - matches!(p.kind, hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Explicit - }) + matches!( + p.kind, + hir::GenericParamKind::Lifetime { + kind: hir::LifetimeParamKind::Explicit + } + ) }) } } diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index c41ce2481d74..88b9c69f6f94 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -1,5 +1,6 @@ -use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::is_type_diagnostic_item; +use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; use rustc_span::sym; @@ -10,13 +11,22 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place if !recv.is_syntactic_place_expr() && is_expr_option(cx, recv) { if let Some(function_name) = source_of_temporary_value(recv) { - span_lint_and_note( + span_lint_and_then( cx, NEEDLESS_OPTION_TAKE, expr.span, "called `Option::take()` on a temporary value", - None, - format!("`{function_name}` creates a temporary value, so calling take() has no effect"), + |diag| { + diag.note(format!( + "`{function_name}` creates a temporary value, so calling take() has no effect" + )); + diag.span_suggestion( + expr.span.with_lo(recv.span.hi()), + "remove", + "", + Applicability::MachineApplicable, + ); + }, ); } } diff --git a/clippy_lints/src/methods/return_and_then.rs b/clippy_lints/src/methods/return_and_then.rs new file mode 100644 index 000000000000..7b1199ad1e2d --- /dev/null +++ b/clippy_lints/src/methods/return_and_then.rs @@ -0,0 +1,67 @@ +use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::LateContext; +use rustc_middle::ty::{self, GenericArg, Ty}; +use rustc_span::sym; +use std::ops::ControlFlow; + +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::{indent_of, reindent_multiline, snippet_with_applicability}; +use clippy_utils::ty::get_type_diagnostic_name; +use clippy_utils::visitors::for_each_unconsumed_temporary; +use clippy_utils::{is_expr_final_block_expr, peel_blocks}; + +use super::RETURN_AND_THEN; + +/// lint if `and_then` is the last expression in a block, and +/// there are no references or temporaries in the receiver +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + expr: &hir::Expr<'_>, + recv: &'tcx hir::Expr<'tcx>, + arg: &'tcx hir::Expr<'_>, +) { + if !is_expr_final_block_expr(cx.tcx, expr) { + return; + } + + let recv_type = cx.typeck_results().expr_ty(recv); + if !matches!(get_type_diagnostic_name(cx, recv_type), Some(sym::Option | sym::Result)) { + return; + } + + let has_ref_type = matches!(recv_type.kind(), ty::Adt(_, args) if args + .first() + .and_then(|arg0: &GenericArg<'tcx>| GenericArg::as_type(*arg0)) + .is_some_and(Ty::is_ref)); + let has_temporaries = for_each_unconsumed_temporary(cx, recv, |_| ControlFlow::Break(())).is_break(); + if has_ref_type && has_temporaries { + return; + } + + let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind else { + return; + }; + + let closure_arg = fn_decl.inputs[0]; + let closure_expr = peel_blocks(cx.tcx.hir().body(body).value); + + let mut applicability = Applicability::MachineApplicable; + let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability); + let recv_snip = snippet_with_applicability(cx, recv.span, "_", &mut applicability); + let body_snip = snippet_with_applicability(cx, closure_expr.span, "..", &mut applicability); + let inner = match body_snip.strip_prefix('{').and_then(|s| s.strip_suffix('}')) { + Some(s) => s.trim_start_matches('\n').trim_end(), + None => &body_snip, + }; + + let msg = "use the question mark operator instead of an `and_then` call"; + let sugg = format!( + "let {} = {}?;\n{}", + arg_snip, + recv_snip, + reindent_multiline(inner.into(), false, indent_of(cx, expr.span)) + ); + + span_lint_and_sugg(cx, RETURN_AND_THEN, expr.span, msg, "try", sugg, applicability); +} diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index c27d1fb4903b..e7adf3b43ba5 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -123,32 +123,60 @@ pub(super) fn check( if let hir::ExprKind::Lit(lit) = init.kind { match lit.node { ast::LitKind::Bool(false) => { - check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Or, Replacement { - method_name: "any", - has_args: true, - has_generic_return: false, - }); + check_fold_with_op( + cx, + expr, + acc, + fold_span, + hir::BinOpKind::Or, + Replacement { + method_name: "any", + has_args: true, + has_generic_return: false, + }, + ); }, ast::LitKind::Bool(true) => { - check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::And, Replacement { - method_name: "all", - has_args: true, - has_generic_return: false, - }); + check_fold_with_op( + cx, + expr, + acc, + fold_span, + hir::BinOpKind::And, + Replacement { + method_name: "all", + has_args: true, + has_generic_return: false, + }, + ); }, ast::LitKind::Int(Pu128(0), _) => { - check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Add, Replacement { - method_name: "sum", - has_args: false, - has_generic_return: needs_turbofish(cx, expr), - }); + check_fold_with_op( + cx, + expr, + acc, + fold_span, + hir::BinOpKind::Add, + Replacement { + method_name: "sum", + has_args: false, + has_generic_return: needs_turbofish(cx, expr), + }, + ); }, ast::LitKind::Int(Pu128(1), _) => { - check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Mul, Replacement { - method_name: "product", - has_args: false, - has_generic_return: needs_turbofish(cx, expr), - }); + check_fold_with_op( + cx, + expr, + acc, + fold_span, + hir::BinOpKind::Mul, + Replacement { + method_name: "product", + has_args: false, + has_generic_return: needs_turbofish(cx, expr), + }, + ); }, _ => (), } diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 1673a6f8b3a4..7af550fa7c68 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -18,7 +18,7 @@ pub(super) fn check<'tcx>( recv: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>, simplify_using: &str, -) { +) -> bool { let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); let is_bool = cx.typeck_results().expr_ty(recv).is_bool(); @@ -29,7 +29,7 @@ pub(super) fn check<'tcx>( let body_expr = &body.value; if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) { - return; + return false; } if eager_or_lazy::switch_to_eager_eval(cx, body_expr) { @@ -71,8 +71,10 @@ pub(super) fn check<'tcx>( applicability, ); }); + return true; } } } } + false } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index fa0eb9a94b73..fca416d9e64c 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -168,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass { TOPLEVEL_REF_ARG, arg.hir_id, arg.pat.span, - "`ref` directly on a function argument is ignored. \ + "`ref` directly on a function parameter does not prevent taking ownership of the passed argument. \ Consider using a reference type instead", ); } diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 302db2c914ca..9acede4f32d6 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -152,16 +152,19 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::AssignOp(_, lhs, rhs) | ExprKind::Assign(lhs, rhs, _) => { if matches!( lhs.kind, - ExprKind::Path(QPath::Resolved(_, hir::Path { - res: Res::Def( - DefKind::Static { - mutability: Mutability::Mut, - .. - }, - _ - ), - .. - })) + ExprKind::Path(QPath::Resolved( + _, + hir::Path { + res: Res::Def( + DefKind::Static { + mutability: Mutability::Mut, + .. + }, + _ + ), + .. + } + )) ) { unsafe_ops.push(("modification of a mutable static occurs here", expr.span)); collect_unsafe_exprs(cx, rhs, unsafe_ops); diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 86c084423b71..49fd29d1dd6d 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -18,11 +18,14 @@ declare_clippy_lint! { /// /// On the other hand, `Mutex`es are, in general, easier to /// verify correctness. An atomic does not behave the same as - /// an equivalent mutex. See [this issue](https://github.com/rust-lang/rust-clippy/issues/4295)'s commentary for more details. + /// an equivalent mutex. See [this issue](https://github.com/rust-lang/rust-clippy/issues/4295)'s + /// commentary for more details. /// /// ### Known problems - /// This lint cannot detect if the mutex is actually used - /// for waiting before a critical section. + /// * This lint cannot detect if the mutex is actually used + /// for waiting before a critical section. + /// * This lint has a false positive that warns without considering the case + /// where `Mutex` is used together with `Condvar`. /// /// ### Example /// ```no_run @@ -48,14 +51,23 @@ declare_clippy_lint! { /// Checks for usage of `Mutex` where `X` is an integral /// type. /// - /// ### Why is this bad? + /// ### Why restrict this? /// Using a mutex just to make access to a plain integer /// sequential is /// shooting flies with cannons. `std::sync::atomic::AtomicUsize` is leaner and faster. /// + /// On the other hand, `Mutex`es are, in general, easier to + /// verify correctness. An atomic does not behave the same as + /// an equivalent mutex. See [this issue](https://github.com/rust-lang/rust-clippy/issues/4295)'s + /// commentary for more details. + /// /// ### Known problems - /// This lint cannot detect if the mutex is actually used - /// for waiting before a critical section. + /// * This lint cannot detect if the mutex is actually used + /// for waiting before a critical section. + /// * This lint has a false positive that warns without considering the case + /// where `Mutex` is used together with `Condvar`. + /// * This lint suggest using `AtomicU64` instead of `Mutex`, but + /// `AtomicU64` is not available on some 32-bit platforms. /// /// ### Example /// ```no_run @@ -70,7 +82,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "pre 1.29.0"] pub MUTEX_INTEGER, - nursery, + restriction, "using a mutex for an integer type" } @@ -108,7 +120,7 @@ fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> { UintTy::U32 => Some("AtomicU32"), UintTy::U64 => Some("AtomicU64"), UintTy::Usize => Some("AtomicUsize"), - // There's no `AtomicU128`. + // `AtomicU128` is unstable and only available on a few platforms: https://github.com/rust-lang/rust/issues/99069 UintTy::U128 => None, } }, @@ -119,7 +131,7 @@ fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> { IntTy::I32 => Some("AtomicI32"), IntTy::I64 => Some("AtomicI64"), IntTy::Isize => Some("AtomicIsize"), - // There's no `AtomicI128`. + // `AtomicU128` is unstable and only available on a few platforms: https://github.com/rust-lang/rust/issues/99069 IntTy::I128 => None, } }, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 30846fb46ac1..2855703b9d56 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -181,9 +181,14 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { && !is_copy(cx, ty) && ty.is_sized(cx.tcx, cx.typing_env()) && !allowed_traits.iter().any(|&t| { - implements_trait_with_env_from_iter(cx.tcx, cx.typing_env(), ty, t, None, [None::< - ty::GenericArg<'tcx>, - >]) + implements_trait_with_env_from_iter( + cx.tcx, + cx.typing_env(), + ty, + t, + None, + [None::>], + ) }) && !implements_borrow_trait && !all_borrowable_trait diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index d9845bc3b0f7..9ad32c2bd396 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -265,9 +265,6 @@ declare_clippy_lint! { /// `x.trailing_zeros() >= 4` is much clearer than `x & 15 /// == 0` /// - /// ### Known problems - /// llvm generates better code for `x & 15 == 0` on x86 - /// /// ### Example /// ```no_run /// # let x = 1; diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 421b2b747555..ec6835db897e 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -3,17 +3,14 @@ use clippy_utils::source::snippet_with_applicability; use rustc_ast::ast::BinOpKind::{Add, BitAnd, BitOr, BitXor, Div, Mul, Rem, Shl, Shr, Sub}; use rustc_ast::ast::{BinOpKind, Expr, ExprKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; use rustc_session::declare_lint_pass; use rustc_span::source_map::Spanned; declare_clippy_lint! { /// ### What it does - /// Checks for operations where precedence may be unclear - /// and suggests to add parentheses. Currently it catches the following: - /// * mixed usage of arithmetic and bit shifting/combining operators without - /// parentheses - /// * mixed usage of bitmasking and bit shifting operators without parentheses + /// Checks for operations where precedence may be unclear and suggests to add parentheses. + /// It catches a mixed usage of arithmetic and bit shifting/combining operators without parentheses /// /// ### Why is this bad? /// Not everyone knows the precedence of those operators by @@ -21,15 +18,32 @@ declare_clippy_lint! { /// code. /// /// ### Example - /// * `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 - /// * `0x2345 & 0xF000 >> 12` equals 5, while `(0x2345 & 0xF000) >> 12` equals 2 + /// `1 << 2 + 3` equals 32, while `(1 << 2) + 3` equals 7 #[clippy::version = "pre 1.29.0"] pub PRECEDENCE, complexity, "operations where precedence may be unclear" } -declare_lint_pass!(Precedence => [PRECEDENCE]); +declare_clippy_lint! { + /// ### What it does + /// Checks for bit shifting operations combined with bit masking/combining operators + /// and suggest using parentheses. + /// + /// ### Why restrict this? + /// Not everyone knows the precedence of those operators by + /// heart, so expressions like these may trip others trying to reason about the + /// code. + /// + /// ### Example + /// `0x2345 & 0xF000 >> 12` equals 5, while `(0x2345 & 0xF000) >> 12` equals 2 + #[clippy::version = "1.86.0"] + pub PRECEDENCE_BITS, + restriction, + "operations mixing bit shifting with bit combining/masking" +} + +declare_lint_pass!(Precedence => [PRECEDENCE, PRECEDENCE_BITS]); impl EarlyLintPass for Precedence { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { @@ -38,10 +52,10 @@ impl EarlyLintPass for Precedence { } if let ExprKind::Binary(Spanned { node: op, .. }, ref left, ref right) = expr.kind { - let span_sugg = |expr: &Expr, sugg, appl| { + let span_sugg = |lint: &'static Lint, expr: &Expr, sugg, appl| { span_lint_and_sugg( cx, - PRECEDENCE, + lint, expr.span, "operator precedence might not be obvious", "consider parenthesizing your expression", @@ -57,37 +71,41 @@ impl EarlyLintPass for Precedence { match (op, get_bin_opt(left), get_bin_opt(right)) { ( BitAnd | BitOr | BitXor, - Some(Shl | Shr | Add | Div | Mul | Rem | Sub), - Some(Shl | Shr | Add | Div | Mul | Rem | Sub), + Some(left_op @ (Shl | Shr | Add | Div | Mul | Rem | Sub)), + Some(right_op @ (Shl | Shr | Add | Div | Mul | Rem | Sub)), ) - | (Shl | Shr, Some(Add | Div | Mul | Rem | Sub), Some(Add | Div | Mul | Rem | Sub)) => { + | ( + Shl | Shr, + Some(left_op @ (Add | Div | Mul | Rem | Sub)), + Some(right_op @ (Add | Div | Mul | Rem | Sub)), + ) => { let sugg = format!( "({}) {} ({})", snippet_with_applicability(cx, left.span, "..", &mut applicability), op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); - span_sugg(expr, sugg, applicability); + span_sugg(lint_for(&[op, left_op, right_op]), expr, sugg, applicability); }, - (BitAnd | BitOr | BitXor, Some(Shl | Shr | Add | Div | Mul | Rem | Sub), _) - | (Shl | Shr, Some(Add | Div | Mul | Rem | Sub), _) => { + (BitAnd | BitOr | BitXor, Some(side_op @ (Shl | Shr | Add | Div | Mul | Rem | Sub)), _) + | (Shl | Shr, Some(side_op @ (Add | Div | Mul | Rem | Sub)), _) => { let sugg = format!( "({}) {} {}", snippet_with_applicability(cx, left.span, "..", &mut applicability), op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); - span_sugg(expr, sugg, applicability); + span_sugg(lint_for(&[op, side_op]), expr, sugg, applicability); }, - (BitAnd | BitOr | BitXor, _, Some(Shl | Shr | Add | Div | Mul | Rem | Sub)) - | (Shl | Shr, _, Some(Add | Div | Mul | Rem | Sub)) => { + (BitAnd | BitOr | BitXor, _, Some(side_op @ (Shl | Shr | Add | Div | Mul | Rem | Sub))) + | (Shl | Shr, _, Some(side_op @ (Add | Div | Mul | Rem | Sub))) => { let sugg = format!( "{} {} ({})", snippet_with_applicability(cx, left.span, "..", &mut applicability), op.as_str(), snippet_with_applicability(cx, right.span, "..", &mut applicability) ); - span_sugg(expr, sugg, applicability); + span_sugg(lint_for(&[op, side_op]), expr, sugg, applicability); }, _ => (), } @@ -106,3 +124,11 @@ fn get_bin_opt(expr: &Expr) -> Option { fn is_bit_op(op: BinOpKind) -> bool { matches!(op, BitXor | BitAnd | BitOr | Shl | Shr) } + +fn lint_for(ops: &[BinOpKind]) -> &'static Lint { + if ops.iter().all(|op| is_bit_op(*op)) { + PRECEDENCE_BITS + } else { + PRECEDENCE + } +} diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 506adf0f2cc5..0b67594a9b19 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -1,5 +1,6 @@ -use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::source::SpanRangeExt; +use clippy_utils::sugg::Sugg; use clippy_utils::visitors::contains_unsafe_block; use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, std_or_core}; use hir::LifetimeName; @@ -250,15 +251,24 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Binary(ref op, l, r) = expr.kind { - if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(cx, l) || is_null_path(cx, r)) { - span_lint( - cx, - CMP_NULL, - expr.span, - "comparing with null is better expressed by the `.is_null()` method", - ); - } + if let ExprKind::Binary(op, l, r) = expr.kind + && (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) + { + let non_null_path_snippet = match (is_null_path(cx, l), is_null_path(cx, r)) { + (true, false) if let Some(sugg) = Sugg::hir_opt(cx, r) => sugg.maybe_par(), + (false, true) if let Some(sugg) = Sugg::hir_opt(cx, l) => sugg.maybe_par(), + _ => return, + }; + + span_lint_and_sugg( + cx, + CMP_NULL, + expr.span, + "comparing with null is better expressed by the `.is_null()` method", + "try", + format!("{non_null_path_snippet}.is_null()"), + Applicability::MachineApplicable, + ); } else { check_invalid_ptr_usage(cx, expr); } diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index b9e0106fc86b..fb1bc494bd94 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -349,10 +349,14 @@ fn visit_clone_usage(cloned: mir::Local, clone: mir::Local, mir: &mir::Body<'_>, local_use_locs: _, local_consume_or_mutate_locs: clone_consume_or_mutate_locs, }, - )) = visit_local_usage(&[cloned, clone], mir, mir::Location { - block: bb, - statement_index: mir.basic_blocks[bb].statements.len(), - }) + )) = visit_local_usage( + &[cloned, clone], + mir, + mir::Location { + block: bb, + statement_index: mir.basic_blocks[bb].statements.len(), + }, + ) .map(|mut vec| (vec.remove(0), vec.remove(0))) { CloneUsage { diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 3476f56cf338..a1b5a3aff323 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -1,8 +1,12 @@ -use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::{indent_of, reindent_multiline, snippet}; use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_ast::visit::{Visitor, walk_expr}; +use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::declare_lint_pass; +use rustc_span::Span; +use std::borrow::Cow; declare_clippy_lint! { /// ### What it does @@ -75,13 +79,27 @@ impl EarlyLintPass for RedundantElse { _ => break, } } - span_lint_and_help( + + let mut app = Applicability::MachineApplicable; + if let ExprKind::Block(block, _) = &els.kind { + for stmt in &block.stmts { + // If the `else` block contains a local binding or a macro invocation, Clippy shouldn't auto-fix it + if matches!(&stmt.kind, StmtKind::Let(_) | StmtKind::MacCall(_)) { + app = Applicability::Unspecified; + break; + } + } + } + + // FIXME: The indentation of the suggestion would be the same as the one of the macro invocation in this implementation, see https://github.com/rust-lang/rust-clippy/pull/13936#issuecomment-2569548202 + span_lint_and_sugg( cx, REDUNDANT_ELSE, - els.span, + els.span.with_lo(then.span.hi()), "redundant else block", - None, "remove the `else` block and move the contents out", + make_sugg(cx, els.span, "..", Some(expr.span)).to_string(), + app, ); } } @@ -136,3 +154,23 @@ impl BreakVisitor { self.check(stmt, Self::visit_stmt) } } + +// Extract the inner contents of an `else` block str +// e.g. `{ foo(); bar(); }` -> `foo(); bar();` +fn extract_else_block(mut block: &str) -> String { + block = block.strip_prefix("{").unwrap_or(block); + block = block.strip_suffix("}").unwrap_or(block); + block.trim_end().to_string() +} + +fn make_sugg<'a>( + cx: &EarlyContext<'_>, + els_span: Span, + default: &'a str, + indent_relative_to: Option, +) -> Cow<'a, str> { + let extracted = extract_else_block(&snippet(cx, els_span, default)); + let indent = indent_relative_to.and_then(|s| indent_of(cx, s)); + + reindent_multiline(extracted.into(), false, indent) +} diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 8d31641d4836..29914d4379fe 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -62,10 +62,13 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { && let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind { if !map.contains_key(res) { - map.insert(*res, ExistingName { - impl_methods: BTreeMap::new(), - trait_methods: BTreeMap::new(), - }); + map.insert( + *res, + ExistingName { + impl_methods: BTreeMap::new(), + trait_methods: BTreeMap::new(), + }, + ); } let existing_name = map.get_mut(res).unwrap(); diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index f72ff10dd43c..b22c638fc363 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -63,8 +63,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ) -> Option<(Ty<'tcx>, &'tcx Expr<'tcx>)> { - const METHODS: [&str; 11] = [ - "write_bytes", + const METHODS: [&str; 10] = [ "copy_to", "copy_from", "copy_to_nonoverlapping", @@ -79,7 +78,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( if let ExprKind::Call(func, [.., count]) = expr.kind // Find calls to ptr::{copy, copy_nonoverlapping} - // and ptr::{swap_nonoverlapping, write_bytes}, + // and ptr::swap_nonoverlapping, && let ExprKind::Path(ref func_qpath) = func.kind && let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id() && matches!(cx.tcx.get_diagnostic_name(def_id), Some( @@ -88,7 +87,6 @@ fn get_pointee_ty_and_count_expr<'tcx>( | sym::ptr_slice_from_raw_parts | sym::ptr_slice_from_raw_parts_mut | sym::ptr_swap_nonoverlapping - | sym::ptr_write_bytes | sym::slice_from_raw_parts | sym::slice_from_raw_parts_mut )) @@ -99,7 +97,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( return Some((pointee_ty, count)); } if let ExprKind::MethodCall(method_path, ptr_self, [.., count], _) = expr.kind - // Find calls to copy_{from,to}{,_nonoverlapping} and write_bytes methods + // Find calls to copy_{from,to}{,_nonoverlapping} && let method_ident = method_path.ident.as_str() && METHODS.iter().any(|m| *m == method_ident) @@ -121,6 +119,8 @@ impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount { instead of a count of elements of `T`"; if let Some((pointee_ty, count_expr)) = get_pointee_ty_and_count_expr(cx, expr) + // Using a number of bytes for a byte type isn't suspicious + && pointee_ty != cx.tcx.types.u8 // Find calls to functions with an element count parameter and get // the pointee type and count parameter expression diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 569812d81065..9993e6ae18b9 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -55,13 +55,11 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind && let to_digits_call_res = cx.qpath_res(to_digits_path, to_digits_call.hir_id) && let Some(to_digits_def_id) = to_digits_call_res.opt_def_id() - && match_def_path(cx, to_digits_def_id, &[ - "core", - "char", - "methods", - "", - "to_digit", - ]) + && match_def_path( + cx, + to_digits_def_id, + &["core", "char", "methods", "", "to_digit"], + ) { Some((false, char_arg, radix_arg)) } else { diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 391c36df492c..579cbf447a2b 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -386,22 +386,30 @@ impl<'tcx> LateLintPass<'tcx> for Types { let is_exported = cx.effective_visibilities.is_exported(def_id); - self.check_fn_decl(cx, decl, CheckTyContext { - is_in_trait_impl, - in_body: matches!(fn_kind, FnKind::Closure), - is_exported, - ..CheckTyContext::default() - }); + self.check_fn_decl( + cx, + decl, + CheckTyContext { + is_in_trait_impl, + in_body: matches!(fn_kind, FnKind::Closure), + is_exported, + ..CheckTyContext::default() + }, + ); } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); match item.kind { - ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _, _) => self.check_ty(cx, ty, CheckTyContext { - is_exported, - ..CheckTyContext::default() - }), + ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _, _) => self.check_ty( + cx, + ty, + CheckTyContext { + is_exported, + ..CheckTyContext::default() + }, + ), // functions, enums, structs, impls and traits are covered _ => (), } @@ -419,10 +427,14 @@ impl<'tcx> LateLintPass<'tcx> for Types { false }; - self.check_ty(cx, ty, CheckTyContext { - is_in_trait_impl, - ..CheckTyContext::default() - }); + self.check_ty( + cx, + ty, + CheckTyContext { + is_in_trait_impl, + ..CheckTyContext::default() + }, + ); }, // Methods are covered by check_fn. // Type aliases are ignored because oftentimes it's impossible to @@ -438,10 +450,14 @@ impl<'tcx> LateLintPass<'tcx> for Types { let is_exported = cx.effective_visibilities.is_exported(field.def_id); - self.check_ty(cx, field.ty, CheckTyContext { - is_exported, - ..CheckTyContext::default() - }); + self.check_ty( + cx, + field.ty, + CheckTyContext { + is_exported, + ..CheckTyContext::default() + }, + ); } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'tcx>) { @@ -469,10 +485,14 @@ impl<'tcx> LateLintPass<'tcx> for Types { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) { if let Some(ty) = local.ty { - self.check_ty(cx, ty, CheckTyContext { - in_body: true, - ..CheckTyContext::default() - }); + self.check_ty( + cx, + ty, + CheckTyContext { + in_body: true, + ..CheckTyContext::default() + }, + ); } } } diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 3fc08e8192d4..207f2ef4563a 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -257,10 +257,13 @@ fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>, } if matches!( ty.kind, - TyKind::Path(QPath::Resolved(_, hir::Path { - res: Res::SelfTyAlias { .. }, - .. - },)) + TyKind::Path(QPath::Resolved( + _, + hir::Path { + res: Res::SelfTyAlias { .. }, + .. + }, + )) ) { return true; } diff --git a/clippy_lints/src/unnecessary_semicolon.rs b/clippy_lints/src/unnecessary_semicolon.rs index efbc536dcb4d..e5267620c4fb 100644 --- a/clippy_lints/src/unnecessary_semicolon.rs +++ b/clippy_lints/src/unnecessary_semicolon.rs @@ -37,7 +37,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct UnnecessarySemicolon { - last_statements: Vec, + last_statements: Vec<(HirId, bool)>, } impl_lint_pass!(UnnecessarySemicolon => [UNNECESSARY_SEMICOLON]); @@ -45,27 +45,25 @@ impl_lint_pass!(UnnecessarySemicolon => [UNNECESSARY_SEMICOLON]); impl UnnecessarySemicolon { /// Enter or leave a block, remembering the last statement of the block. fn handle_block(&mut self, cx: &LateContext<'_>, block: &Block<'_>, enter: bool) { - // Up to edition 2021, removing the semicolon of the last statement of a block - // may result in the scrutinee temporary values to live longer than the block - // variables. To avoid this problem, we do not lint the last statement of an - // expressionless block. - if cx.tcx.sess.edition() <= Edition2021 - && block.expr.is_none() + // The last statement of an expressionless block deserves a special treatment. + if block.expr.is_none() && let Some(last_stmt) = block.stmts.last() { if enter { - self.last_statements.push(last_stmt.hir_id); + let block_ty = cx.typeck_results().node_type(block.hir_id); + self.last_statements.push((last_stmt.hir_id, block_ty.is_unit())); } else { self.last_statements.pop(); } } } - /// Checks if `stmt` is the last statement in an expressionless block for edition ≤ 2021. - fn is_last_in_block(&self, stmt: &Stmt<'_>) -> bool { + /// Checks if `stmt` is the last statement in an expressionless block. In this case, + /// return `Some` with a boolean which is `true` if the block type is `()`. + fn is_last_in_block(&self, stmt: &Stmt<'_>) -> Option { self.last_statements .last() - .is_some_and(|last_stmt_id| last_stmt_id == &stmt.hir_id) + .and_then(|&(stmt_id, is_unit)| (stmt_id == stmt.hir_id).then_some(is_unit)) } } @@ -90,8 +88,22 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessarySemicolon { ) && cx.typeck_results().expr_ty(expr) == cx.tcx.types.unit { - if self.is_last_in_block(stmt) && leaks_droppable_temporary_with_limited_lifetime(cx, expr) { - return; + if let Some(block_is_unit) = self.is_last_in_block(stmt) { + if cx.tcx.sess.edition() <= Edition2021 && leaks_droppable_temporary_with_limited_lifetime(cx, expr) { + // The expression contains temporaries with limited lifetimes in edition lower than 2024. Those may + // survive until after the end of the current scope instead of until the end of the statement, so do + // not lint this situation. + return; + } + + if !block_is_unit { + // Although the expression returns `()`, the block doesn't. This may happen if the expression + // returns early in all code paths, such as a `return value` in the condition of an `if` statement, + // in which case the block type would be `!`. Do not lint in this case, as the statement would + // become the block expression; the block type would become `()` and this may not type correctly + // if the expected type for the block is not `()`. + return; + } } let semi_span = expr.span.shrink_to_hi().to(stmt.span.shrink_to_hi()); diff --git a/clippy_lints/src/unneeded_struct_pattern.rs b/clippy_lints/src/unneeded_struct_pattern.rs index 40ba70d451db..a74eab8b6ae5 100644 --- a/clippy_lints/src/unneeded_struct_pattern.rs +++ b/clippy_lints/src/unneeded_struct_pattern.rs @@ -32,7 +32,7 @@ declare_clippy_lint! { /// None => 0, /// }; /// ``` - #[clippy::version = "1.83.0"] + #[clippy::version = "1.86.0"] pub UNNEEDED_STRUCT_PATTERN, style, "using struct pattern to match against unit variant" diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 31ae002e47d9..11c14c147776 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -522,7 +522,7 @@ fn check_literal(cx: &LateContext<'_>, format_args: &FormatArgs, name: &str) { let replacement = match (format_string_is_raw, replace_raw) { (false, false) => Some(replacement), - (false, true) => Some(replacement.replace('"', "\\\"").replace('\\', "\\\\")), + (false, true) => Some(replacement.replace('\\', "\\\\").replace('"', "\\\"")), (true, false) => match conservative_unescape(&replacement) { Ok(unescaped) => Some(unescaped), Err(UnescapeErr::Lint) => None, diff --git a/clippy_utils/README.md b/clippy_utils/README.md index 251e3dfe41be..41f3b1cbd507 100644 --- a/clippy_utils/README.md +++ b/clippy_utils/README.md @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain: ``` -nightly-2025-01-28 +nightly-2025-02-06 ``` diff --git a/clippy_utils/src/ast_utils/mod.rs b/clippy_utils/src/ast_utils/mod.rs index 798f4575c2e1..ab5f97199ce3 100644 --- a/clippy_utils/src/ast_utils/mod.rs +++ b/clippy_utils/src/ast_utils/mod.rs @@ -662,12 +662,12 @@ pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { && eq_ext(&l.ext, &r.ext) } +#[expect(clippy::ref_option, reason = "This is the type how it is stored in the AST")] pub fn eq_opt_fn_contract(l: &Option>, r: &Option>) -> bool { match (l, r) { (Some(l), Some(r)) => { - eq_expr_opt(l.requires.as_ref(), r.requires.as_ref()) - && eq_expr_opt(l.ensures.as_ref(), r.ensures.as_ref()) - } + eq_expr_opt(l.requires.as_ref(), r.requires.as_ref()) && eq_expr_opt(l.ensures.as_ref(), r.ensures.as_ref()) + }, (None, None) => true, (Some(_), None) | (None, Some(_)) => false, } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 5a5227af9074..337684b68f86 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -341,6 +341,15 @@ pub fn is_wild(pat: &Pat<'_>) -> bool { matches!(pat.kind, PatKind::Wild) } +// Checks if arm has the form `None => None` +pub fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool { + matches!( + arm.pat.kind, + PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), .. }) + if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone) + ) +} + /// Checks if the given `QPath` belongs to a type alias. pub fn is_ty_alias(qpath: &QPath<'_>) -> bool { match *qpath { diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index ccbbccd0dbff..85250f81dc47 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -112,10 +112,14 @@ pub fn block_in_cycle(body: &Body<'_>, block: BasicBlock) -> bool { /// Convenience wrapper around `visit_local_usage`. pub fn used_exactly_once(mir: &Body<'_>, local: Local) -> Option { - visit_local_usage(&[local], mir, Location { - block: START_BLOCK, - statement_index: 0, - }) + visit_local_usage( + &[local], + mir, + Location { + block: START_BLOCK, + statement_index: 0, + }, + ) .map(|mut vec| { let LocalUsage { local_use_locs, .. } = vec.remove(0); let mut locations = local_use_locs diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index d73cb7e35611..24f73b9df268 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -1,4 +1,5 @@ use rustc_ast::attr::AttributeExt; + use rustc_attr_parsing::{RustcVersion, parse_version}; use rustc_session::Session; use rustc_span::{Symbol, sym}; @@ -18,12 +19,14 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { + 1,84,0 { CONST_OPTION_AS_SLICE } 1,83,0 { CONST_EXTERN_FN, CONST_FLOAT_BITS_CONV, CONST_FLOAT_CLASSIFY, CONST_MUT_REFS, CONST_UNWRAP } 1,82,0 { IS_NONE_OR, REPEAT_N, RAW_REF_OP } 1,81,0 { LINT_REASONS_STABILIZATION, ERROR_IN_CORE, EXPLICIT_SELF_TYPE_ELISION } 1,80,0 { BOX_INTO_ITER, LAZY_CELL } 1,77,0 { C_STR_LITERALS } 1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT } + 1,75,0 { OPTION_AS_SLICE } 1,74,0 { REPR_RUST } 1,73,0 { MANUAL_DIV_CEIL } 1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE } @@ -40,7 +43,7 @@ msrv_aliases! { 1,53,0 { OR_PATTERNS, MANUAL_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN, ARRAY_INTO_ITERATOR } 1,52,0 { STR_SPLIT_ONCE, REM_EUCLID_CONST } 1,51,0 { BORROW_AS_PTR, SEEK_FROM_CURRENT, UNSIGNED_ABS } - 1,50,0 { BOOL_THEN, CLAMP } + 1,50,0 { BOOL_THEN, CLAMP, SLICE_FILL } 1,47,0 { TAU, IS_ASCII_DIGIT_CONST, ARRAY_IMPL_ANY_LEN, SATURATING_SUB_CONST } 1,46,0 { CONST_IF_MATCH } 1,45,0 { STR_STRIP_PREFIX } diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 5a3a3d0cedc4..c7890f33f27e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -179,7 +179,10 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _) + Rvalue::NullaryOp( + NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, + _, + ) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index eecbfb3936ac..b8b800b93cea 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -726,12 +726,15 @@ pub fn str_literal_to_char_literal( &snip[1..(snip.len() - 1)] }; - let hint = format!("'{}'", match ch { - "'" => "\\'", - r"\" => "\\\\", - "\\\"" => "\"", // no need to escape `"` in `'"'` - _ => ch, - }); + let hint = format!( + "'{}'", + match ch { + "'" => "\\'", + r"\" => "\\\\", + "\\\"" => "\"", // no need to escape `"` in `'"'` + _ => ch, + } + ); Some(hint) } else { diff --git a/clippy_utils/src/str_utils.rs b/clippy_utils/src/str_utils.rs index 1588ee452dae..421b25a77fe8 100644 --- a/clippy_utils/src/str_utils.rs +++ b/clippy_utils/src/str_utils.rs @@ -370,11 +370,9 @@ mod test { assert_eq!(camel_case_split("AbcDef"), vec!["Abc", "Def"]); assert_eq!(camel_case_split("Abc"), vec!["Abc"]); assert_eq!(camel_case_split("abcDef"), vec!["abc", "Def"]); - assert_eq!(camel_case_split("\u{f6}\u{f6}AabABcd"), vec![ - "\u{f6}\u{f6}", - "Aab", - "A", - "Bcd" - ]); + assert_eq!( + camel_case_split("\u{f6}\u{f6}AabABcd"), + vec!["\u{f6}\u{f6}", "Aab", "A", "Bcd"] + ); } } diff --git a/lintcheck/src/config.rs b/lintcheck/src/config.rs index af243f94274d..83c3d7aba021 100644 --- a/lintcheck/src/config.rs +++ b/lintcheck/src/config.rs @@ -2,6 +2,7 @@ use clap::{Parser, Subcommand, ValueEnum}; use std::num::NonZero; use std::path::PathBuf; +#[allow(clippy::struct_excessive_bools)] #[derive(Parser, Clone, Debug)] #[command(args_conflicts_with_subcommands = true)] pub(crate) struct LintcheckConfig { @@ -11,6 +12,9 @@ pub(crate) struct LintcheckConfig { short = 'j', value_name = "N", default_value_t = 0, + default_value_if("perf", "true", Some("1")), // Limit jobs to 1 when benchmarking + conflicts_with("perf"), + required = false, hide_default_value = true )] pub max_jobs: usize, @@ -46,6 +50,11 @@ pub(crate) struct LintcheckConfig { /// Run clippy on the dependencies of crates specified in crates-toml #[clap(long, conflicts_with("max_jobs"))] pub recursive: bool, + /// Also produce a `perf.data` file, implies --jobs=1, + /// the `perf.data` file can be found at + /// `target/lintcheck/sources/-/perf.data` + #[clap(long)] + pub perf: bool, #[command(subcommand)] pub subcommand: Option, } diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index e88d9f427bec..8d0d41ab9450 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -116,7 +116,25 @@ impl Crate { clippy_args.extend(lint_levels_args.iter().map(String::as_str)); - let mut cmd = Command::new("cargo"); + let mut cmd; + + if config.perf { + cmd = Command::new("perf"); + cmd.args(&[ + "record", + "-e", + "instructions", // Only count instructions + "-g", // Enable call-graph, useful for flamegraphs and produces richer reports + "--quiet", // Do not tamper with lintcheck's normal output + "-o", + "perf.data", + "--", + "cargo", + ]); + } else { + cmd = Command::new("cargo"); + } + cmd.arg(if config.fix { "fix" } else { "check" }) .arg("--quiet") .current_dir(&self.path) @@ -234,12 +252,22 @@ fn normalize_diag( } /// Builds clippy inside the repo to make sure we have a clippy executable we can use. -fn build_clippy() -> String { - let output = Command::new("cargo") - .args(["run", "--bin=clippy-driver", "--", "--version"]) - .stderr(Stdio::inherit()) - .output() - .unwrap(); +fn build_clippy(release_build: bool) -> String { + let mut build_cmd = Command::new("cargo"); + build_cmd.args([ + "run", + "--bin=clippy-driver", + if release_build { "-r" } else { "" }, + "--", + "--version", + ]); + + if release_build { + build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true"); + } + + let output = build_cmd.stderr(Stdio::inherit()).output().unwrap(); + if !output.status.success() { eprintln!("Error: Failed to compile Clippy!"); std::process::exit(1); @@ -270,13 +298,18 @@ fn main() { #[allow(clippy::too_many_lines)] fn lintcheck(config: LintcheckConfig) { - let clippy_ver = build_clippy(); - let clippy_driver_path = fs::canonicalize(format!("target/debug/clippy-driver{EXE_SUFFIX}")).unwrap(); + let clippy_ver = build_clippy(config.perf); + let clippy_driver_path = fs::canonicalize(format!( + "target/{}/clippy-driver{EXE_SUFFIX}", + if config.perf { "release" } else { "debug" } + )) + .unwrap(); // assert that clippy is found assert!( clippy_driver_path.is_file(), - "target/debug/clippy-driver binary not found! {}", + "target/{}/clippy-driver binary not found! {}", + if config.perf { "release" } else { "debug" }, clippy_driver_path.display() ); diff --git a/rust-toolchain b/rust-toolchain index c15d1fe6cd34..ab760287e83a 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,6 +1,6 @@ [toolchain] # begin autogenerated nightly -channel = "nightly-2025-01-28" +channel = "nightly-2025-02-06" # end autogenerated nightly components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal" diff --git a/tests/ui/cmp_null.fixed b/tests/ui/cmp_null.fixed new file mode 100644 index 000000000000..e5ab765bc861 --- /dev/null +++ b/tests/ui/cmp_null.fixed @@ -0,0 +1,32 @@ +#![warn(clippy::cmp_null)] +#![allow(unused_mut)] + +use std::ptr; + +fn main() { + let x = 0; + let p: *const usize = &x; + if p.is_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!"); + } + if p.is_null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + println!("This is surprising!"); + } + + let mut y = 0; + let mut m: *mut usize = &mut y; + if m.is_null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + println!("This is surprising, too!"); + } + if m.is_null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + println!("This is surprising, too!"); + } + + let _ = (x as *const ()).is_null(); + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method +} diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index ef1d93940aa6..257f7ba26627 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -11,10 +11,22 @@ fn main() { //~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` println!("This is surprising!"); } + if ptr::null() == p { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + 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!"); } + if ptr::null_mut() == m { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + println!("This is surprising, too!"); + } + + let _ = x as *const () == ptr::null(); + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method } diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index 8362904a5ba9..f3b35f3afba8 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -2,16 +2,34 @@ error: comparing with null is better expressed by the `.is_null()` method --> tests/ui/cmp_null.rs:9:8 | LL | if p == ptr::null() { - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ help: try: `p.is_null()` | = note: `-D clippy::cmp-null` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::cmp_null)]` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:16:8 + --> tests/ui/cmp_null.rs:14:8 + | +LL | if ptr::null() == p { + | ^^^^^^^^^^^^^^^^ help: try: `p.is_null()` + +error: comparing with null is better expressed by the `.is_null()` method + --> tests/ui/cmp_null.rs:21:8 | LL | if m == ptr::null_mut() { - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` -error: aborting due to 2 previous errors +error: comparing with null is better expressed by the `.is_null()` method + --> tests/ui/cmp_null.rs:25:8 + | +LL | if ptr::null_mut() == m { + | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` + +error: comparing with null is better expressed by the `.is_null()` method + --> tests/ui/cmp_null.rs:30:13 + | +LL | let _ = x as *const () == ptr::null(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(x as *const ()).is_null()` + +error: aborting due to 5 previous errors diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index f1baf28200e9..abccc30ef87d 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -116,6 +116,11 @@ fn test_redundant_closures_containing_method_calls() { t.iter().filter(|x| x.trait_foo_ref()); t.iter().map(|x| x.trait_foo_ref()); } + + fn issue14096() { + let x = Some("42"); + let _ = x.map(str::parse::); + } } struct Thunk(Box T>); diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index c52a51880bfc..9bcee4eba340 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -116,6 +116,11 @@ fn test_redundant_closures_containing_method_calls() { t.iter().filter(|x| x.trait_foo_ref()); t.iter().map(|x| x.trait_foo_ref()); } + + fn issue14096() { + let x = Some("42"); + let _ = x.map(|x| x.parse::()); + } } struct Thunk(Box T>); diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 1731a4377f53..ac58e87bc5ec 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -71,142 +71,148 @@ LL | let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_as | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase` error: redundant closure - --> tests/ui/eta.rs:169:22 + --> tests/ui/eta.rs:122:23 + | +LL | let _ = x.map(|x| x.parse::()); + | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `str::parse::` + +error: redundant closure + --> tests/ui/eta.rs:174:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> tests/ui/eta.rs:176:27 + --> tests/ui/eta.rs:181:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> tests/ui/eta.rs:181:27 + --> tests/ui/eta.rs:186:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> tests/ui/eta.rs:213:28 + --> tests/ui/eta.rs:218: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 - --> tests/ui/eta.rs:214:28 + --> tests/ui/eta.rs:219: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 - --> tests/ui/eta.rs:215:28 + --> tests/ui/eta.rs:220: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 - --> tests/ui/eta.rs:222:21 + --> tests/ui/eta.rs:227:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> tests/ui/eta.rs:226:21 + --> tests/ui/eta.rs:231:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> tests/ui/eta.rs:319:18 + --> tests/ui/eta.rs:324:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:322:19 + --> tests/ui/eta.rs:327:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:326:26 + --> tests/ui/eta.rs:331:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> tests/ui/eta.rs:338:19 + --> tests/ui/eta.rs:343:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> tests/ui/eta.rs:341:19 + --> tests/ui/eta.rs:346:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> tests/ui/eta.rs:344:17 + --> tests/ui/eta.rs:349:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> tests/ui/eta.rs:348:17 + --> tests/ui/eta.rs:353:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `::method_on_dyn` error: redundant closure - --> tests/ui/eta.rs:408:19 + --> tests/ui/eta.rs:413:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> tests/ui/eta.rs:436:22 + --> tests/ui/eta.rs:441:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> tests/ui/eta.rs:440:22 + --> tests/ui/eta.rs:445:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> tests/ui/eta.rs:453:18 + --> tests/ui/eta.rs:458:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> tests/ui/eta.rs:460:30 + --> tests/ui/eta.rs:465:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` error: redundant closure - --> tests/ui/eta.rs:479:38 + --> tests/ui/eta.rs:484:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `&f` error: redundant closure - --> tests/ui/eta.rs:483:38 + --> tests/ui/eta.rs:488:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` error: redundant closure - --> tests/ui/eta.rs:500:35 + --> tests/ui/eta.rs:505:35 | LL | let _field = bind.or_else(|| get_default()).unwrap(); | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default` -error: aborting due to 34 previous errors +error: aborting due to 35 previous errors diff --git a/tests/ui/ignored_unit_patterns.fixed b/tests/ui/ignored_unit_patterns.fixed index fde404373098..118f0b488952 100644 --- a/tests/ui/ignored_unit_patterns.fixed +++ b/tests/ui/ignored_unit_patterns.fixed @@ -21,12 +21,15 @@ fn main() { let _ = foo().map_err(|()| todo!()); //~^ ERROR: matching over `()` is more explicit - println!("{:?}", match foo() { - Ok(()) => {}, - //~^ ERROR: matching over `()` is more explicit - Err(()) => {}, - //~^ ERROR: matching over `()` is more explicit - }); + println!( + "{:?}", + match foo() { + Ok(()) => {}, + //~^ ERROR: matching over `()` is more explicit + Err(()) => {}, + //~^ ERROR: matching over `()` is more explicit + } + ); } // ignored_unit_patterns in derive macro should be ok diff --git a/tests/ui/ignored_unit_patterns.rs b/tests/ui/ignored_unit_patterns.rs index 528844d76e05..92feb9e6c281 100644 --- a/tests/ui/ignored_unit_patterns.rs +++ b/tests/ui/ignored_unit_patterns.rs @@ -21,12 +21,15 @@ fn main() { let _ = foo().map_err(|_| todo!()); //~^ ERROR: matching over `()` is more explicit - println!("{:?}", match foo() { - Ok(_) => {}, - //~^ ERROR: matching over `()` is more explicit - Err(_) => {}, - //~^ ERROR: matching over `()` is more explicit - }); + println!( + "{:?}", + match foo() { + Ok(_) => {}, + //~^ ERROR: matching over `()` is more explicit + Err(_) => {}, + //~^ ERROR: matching over `()` is more explicit + } + ); } // ignored_unit_patterns in derive macro should be ok diff --git a/tests/ui/ignored_unit_patterns.stderr b/tests/ui/ignored_unit_patterns.stderr index 54ff4454d6bd..00a254e39192 100644 --- a/tests/ui/ignored_unit_patterns.stderr +++ b/tests/ui/ignored_unit_patterns.stderr @@ -26,31 +26,31 @@ LL | let _ = foo().map_err(|_| todo!()); | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> tests/ui/ignored_unit_patterns.rs:25:12 + --> tests/ui/ignored_unit_patterns.rs:27:16 | -LL | Ok(_) => {}, - | ^ help: use `()` instead of `_`: `()` +LL | Ok(_) => {}, + | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> tests/ui/ignored_unit_patterns.rs:27:13 + --> tests/ui/ignored_unit_patterns.rs:29:17 | -LL | Err(_) => {}, - | ^ help: use `()` instead of `_`: `()` +LL | Err(_) => {}, + | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> tests/ui/ignored_unit_patterns.rs:38:9 + --> tests/ui/ignored_unit_patterns.rs:41:9 | LL | let _ = foo().unwrap(); | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> tests/ui/ignored_unit_patterns.rs:47:13 + --> tests/ui/ignored_unit_patterns.rs:50:13 | LL | (1, _) => unimplemented!(), | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> tests/ui/ignored_unit_patterns.rs:54:13 + --> tests/ui/ignored_unit_patterns.rs:57:13 | LL | for (x, _) in v { | ^ help: use `()` instead of `_`: `()` diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs index c917fa7f2d0b..2f8640cd3f50 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -1,5 +1,10 @@ #![warn(clippy::manual_memcpy)] -#![allow(clippy::assigning_clones, clippy::useless_vec, clippy::needless_range_loop)] +#![allow( + clippy::assigning_clones, + clippy::useless_vec, + clippy::needless_range_loop, + clippy::manual_slice_fill +)] //@no-rustfix const LOOP_OFFSET: usize = 5000; diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr index 803053b2db2e..c881e3fac769 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -1,5 +1,5 @@ error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:9:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:14:5 | LL | / for i in 0..src.len() { LL | | @@ -12,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:16:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { LL | | @@ -21,7 +21,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:22:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:27:5 | LL | / for i in 0..src.len() { LL | | @@ -30,7 +30,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:28:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:33:5 | LL | / for i in 11..src.len() { LL | | @@ -39,7 +39,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:34:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:39:5 | LL | / for i in 0..dst.len() { LL | | @@ -48,7 +48,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..dst.len()]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:48:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:53:5 | LL | / for i in 10..256 { LL | | @@ -64,7 +64,7 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:61:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:66:5 | LL | / for i in 10..LOOP_OFFSET { LL | | @@ -73,7 +73,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:75:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:80:5 | LL | / for i in 0..src_vec.len() { LL | | @@ -82,7 +82,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:105:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:110:5 | LL | / for i in from..from + src.len() { LL | | @@ -91,7 +91,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:110:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:115:5 | LL | / for i in from..from + 3 { LL | | @@ -100,7 +100,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:116:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:121:5 | LL | / for i in 0..5 { LL | | @@ -109,7 +109,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:122:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:127:5 | LL | / for i in 0..0 { LL | | @@ -118,7 +118,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:146:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:151:5 | LL | / for i in 0..4 { LL | | @@ -127,7 +127,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..4]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:152:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:157:5 | LL | / for i in 0..5 { LL | | @@ -136,7 +136,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:158:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:163:5 | LL | / for i in 0..5 { LL | | @@ -145,7 +145,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:205:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:210:5 | LL | / for i in 0..5 { LL | | @@ -154,7 +154,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:211:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:216:5 | LL | / for i in 0..5 { LL | | @@ -163,7 +163,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0][1]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:219:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:224:5 | LL | / for i in 0..src.len() { LL | | diff --git a/tests/ui/manual_option_as_slice.fixed b/tests/ui/manual_option_as_slice.fixed new file mode 100644 index 000000000000..48337d7654de --- /dev/null +++ b/tests/ui/manual_option_as_slice.fixed @@ -0,0 +1,62 @@ +#![warn(clippy::manual_option_as_slice)] +#![allow(clippy::redundant_closure, clippy::unwrap_or_default)] + +fn check(x: Option) { + _ = x.as_slice(); + + _ = x.as_slice(); + + _ = x.as_slice(); + //~^ manual_option_as_slice + + _ = x.as_slice(); + //~^ manual_option_as_slice + + _ = x.as_slice(); + //~^ manual_option_as_slice + + _ = x.as_slice(); + //~^ manual_option_as_slice + + { + use std::slice::from_ref; + _ = x.as_slice(); + //~^ manual_option_as_slice + } + + // possible false positives + let y = x.as_ref(); + _ = match y { + // as_ref outside + Some(f) => &[f][..], + None => &[][..], + }; + _ = match x.as_ref() { + Some(f) => std::slice::from_ref(f), + None => &[0], + }; + _ = match x.as_ref() { + Some(42) => &[23], + Some(f) => std::slice::from_ref(f), + None => &[], + }; + let b = &[42]; + _ = if let Some(_f) = x.as_ref() { + std::slice::from_ref(b) + } else { + &[] + }; + _ = x.as_ref().map_or(&[42][..], std::slice::from_ref); + _ = x.as_ref().map_or_else(|| &[42][..1], std::slice::from_ref); + _ = x.as_ref().map(|f| std::slice::from_ref(f)).unwrap_or_default(); +} + +#[clippy::msrv = "1.74"] +fn check_msrv(x: Option) { + _ = x.as_ref().map_or(&[][..], std::slice::from_ref); +} + +fn main() { + check(Some(1)); + check_msrv(Some(175)); +} diff --git a/tests/ui/manual_option_as_slice.rs b/tests/ui/manual_option_as_slice.rs new file mode 100644 index 000000000000..561a8b534014 --- /dev/null +++ b/tests/ui/manual_option_as_slice.rs @@ -0,0 +1,71 @@ +#![warn(clippy::manual_option_as_slice)] +#![allow(clippy::redundant_closure, clippy::unwrap_or_default)] + +fn check(x: Option) { + _ = match x.as_ref() { + //~^ manual_option_as_slice + Some(f) => std::slice::from_ref(f), + None => &[], + }; + + _ = if let Some(f) = x.as_ref() { + //~^ manual_option_as_slice + std::slice::from_ref(f) + } else { + &[] + }; + + _ = x.as_ref().map_or(&[][..], std::slice::from_ref); + //~^ manual_option_as_slice + + _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); + //~^ manual_option_as_slice + + _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); + //~^ manual_option_as_slice + + _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); + //~^ manual_option_as_slice + + { + use std::slice::from_ref; + _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); + //~^ manual_option_as_slice + } + + // possible false positives + let y = x.as_ref(); + _ = match y { + // as_ref outside + Some(f) => &[f][..], + None => &[][..], + }; + _ = match x.as_ref() { + Some(f) => std::slice::from_ref(f), + None => &[0], + }; + _ = match x.as_ref() { + Some(42) => &[23], + Some(f) => std::slice::from_ref(f), + None => &[], + }; + let b = &[42]; + _ = if let Some(_f) = x.as_ref() { + std::slice::from_ref(b) + } else { + &[] + }; + _ = x.as_ref().map_or(&[42][..], std::slice::from_ref); + _ = x.as_ref().map_or_else(|| &[42][..1], std::slice::from_ref); + _ = x.as_ref().map(|f| std::slice::from_ref(f)).unwrap_or_default(); +} + +#[clippy::msrv = "1.74"] +fn check_msrv(x: Option) { + _ = x.as_ref().map_or(&[][..], std::slice::from_ref); +} + +fn main() { + check(Some(1)); + check_msrv(Some(175)); +} diff --git a/tests/ui/manual_option_as_slice.stderr b/tests/ui/manual_option_as_slice.stderr new file mode 100644 index 000000000000..569269d3e2b7 --- /dev/null +++ b/tests/ui/manual_option_as_slice.stderr @@ -0,0 +1,58 @@ +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:5:9 + | +LL | _ = match x.as_ref() { + | _________^ +LL | | +LL | | Some(f) => std::slice::from_ref(f), +LL | | None => &[], +LL | | }; + | |_____^ help: use: `x.as_slice()` + | + = note: `-D clippy::manual-option-as-slice` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_option_as_slice)]` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:11:9 + | +LL | _ = if let Some(f) = x.as_ref() { + | _________^ +LL | | +LL | | std::slice::from_ref(f) +LL | | } else { +LL | | &[] +LL | | }; + | |_____^ help: use: `x.as_slice()` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:18:9 + | +LL | _ = x.as_ref().map_or(&[][..], std::slice::from_ref); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:21:9 + | +LL | _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:24:9 + | +LL | _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:27:9 + | +LL | _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` + +error: use `Option::as_slice` + --> tests/ui/manual_option_as_slice.rs:32:13 + | +LL | _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` + +error: aborting due to 7 previous errors + diff --git a/tests/ui/manual_slice_fill.fixed b/tests/ui/manual_slice_fill.fixed new file mode 100644 index 000000000000..397a156a2dc7 --- /dev/null +++ b/tests/ui/manual_slice_fill.fixed @@ -0,0 +1,101 @@ +#![warn(clippy::manual_slice_fill)] +#![allow(clippy::needless_range_loop)] + +macro_rules! assign_element { + ($slice:ident, $index:expr) => { + $slice[$index] = 0; + }; +} + +macro_rules! assign_element_2 { + ($i:expr) => { + $i = 0; + }; +} + +struct NoClone; + +fn num() -> usize { + 5 +} + +fn should_lint() { + let mut some_slice = [1, 2, 3, 4, 5]; + + some_slice.fill(0); + + let x = 5; + some_slice.fill(x); + + some_slice.fill(0); + + // This should trigger `manual_slice_fill`, but the applicability is `MaybeIncorrect` since comments + // within the loop might be purely informational. + some_slice.fill(0); +} + +fn should_not_lint() { + let mut some_slice = [1, 2, 3, 4, 5]; + + // Should not lint because we can't determine if the scope of the loop is intended to access all the + // elements of the slice. + for i in 0..5 { + some_slice[i] = 0; + } + + // Should not lint, as using a function to assign values to elements might be + // intentional. For example, the contents of `num()` could be temporary and subject to change + // later. + for i in 0..some_slice.len() { + some_slice[i] = num(); + } + + // Should not lint because this loop isn't equivalent to `fill`. + for i in 0..some_slice.len() { + some_slice[i] = 0; + println!("foo"); + } + + // Should not lint because it may be intentional to use a macro to perform an operation equivalent + // to `fill`. + for i in 0..some_slice.len() { + assign_element!(some_slice, i); + } + + let another_slice = [1, 2, 3]; + // Should not lint because the range is not for `some_slice`. + for i in 0..another_slice.len() { + some_slice[i] = 0; + } + + let mut vec: Vec> = Vec::with_capacity(5); + // Should not lint because `NoClone` does not have `Clone` trait. + for i in 0..vec.len() { + vec[i] = None; + } + + // Should not lint, as using a function to assign values to elements might be + // intentional. For example, the contents of `num()` could be temporary and subject to change + // later. + for i in &mut some_slice { + *i = num(); + } + + // Should not lint because this loop isn't equivalent to `fill`. + for i in &mut some_slice { + *i = 0; + println!("foo"); + } + + // Should not lint because it may be intentional to use a macro to perform an operation equivalent + // to `fill`. + for i in &mut some_slice { + assign_element_2!(*i); + } + + let mut vec: Vec> = Vec::with_capacity(5); + // Should not lint because `NoClone` does not have `Clone` trait. + for i in &mut vec { + *i = None; + } +} diff --git a/tests/ui/manual_slice_fill.rs b/tests/ui/manual_slice_fill.rs new file mode 100644 index 000000000000..c25127ca613a --- /dev/null +++ b/tests/ui/manual_slice_fill.rs @@ -0,0 +1,110 @@ +#![warn(clippy::manual_slice_fill)] +#![allow(clippy::needless_range_loop)] + +macro_rules! assign_element { + ($slice:ident, $index:expr) => { + $slice[$index] = 0; + }; +} + +macro_rules! assign_element_2 { + ($i:expr) => { + $i = 0; + }; +} + +struct NoClone; + +fn num() -> usize { + 5 +} + +fn should_lint() { + let mut some_slice = [1, 2, 3, 4, 5]; + + for i in 0..some_slice.len() { + some_slice[i] = 0; + } + + let x = 5; + for i in 0..some_slice.len() { + some_slice[i] = x; + } + + for i in &mut some_slice { + *i = 0; + } + + // This should trigger `manual_slice_fill`, but the applicability is `MaybeIncorrect` since comments + // within the loop might be purely informational. + for i in 0..some_slice.len() { + some_slice[i] = 0; + // foo + } +} + +fn should_not_lint() { + let mut some_slice = [1, 2, 3, 4, 5]; + + // Should not lint because we can't determine if the scope of the loop is intended to access all the + // elements of the slice. + for i in 0..5 { + some_slice[i] = 0; + } + + // Should not lint, as using a function to assign values to elements might be + // intentional. For example, the contents of `num()` could be temporary and subject to change + // later. + for i in 0..some_slice.len() { + some_slice[i] = num(); + } + + // Should not lint because this loop isn't equivalent to `fill`. + for i in 0..some_slice.len() { + some_slice[i] = 0; + println!("foo"); + } + + // Should not lint because it may be intentional to use a macro to perform an operation equivalent + // to `fill`. + for i in 0..some_slice.len() { + assign_element!(some_slice, i); + } + + let another_slice = [1, 2, 3]; + // Should not lint because the range is not for `some_slice`. + for i in 0..another_slice.len() { + some_slice[i] = 0; + } + + let mut vec: Vec> = Vec::with_capacity(5); + // Should not lint because `NoClone` does not have `Clone` trait. + for i in 0..vec.len() { + vec[i] = None; + } + + // Should not lint, as using a function to assign values to elements might be + // intentional. For example, the contents of `num()` could be temporary and subject to change + // later. + for i in &mut some_slice { + *i = num(); + } + + // Should not lint because this loop isn't equivalent to `fill`. + for i in &mut some_slice { + *i = 0; + println!("foo"); + } + + // Should not lint because it may be intentional to use a macro to perform an operation equivalent + // to `fill`. + for i in &mut some_slice { + assign_element_2!(*i); + } + + let mut vec: Vec> = Vec::with_capacity(5); + // Should not lint because `NoClone` does not have `Clone` trait. + for i in &mut vec { + *i = None; + } +} diff --git a/tests/ui/manual_slice_fill.stderr b/tests/ui/manual_slice_fill.stderr new file mode 100644 index 000000000000..3aa980f69191 --- /dev/null +++ b/tests/ui/manual_slice_fill.stderr @@ -0,0 +1,38 @@ +error: manually filling a slice + --> tests/ui/manual_slice_fill.rs:25:5 + | +LL | / for i in 0..some_slice.len() { +LL | | some_slice[i] = 0; +LL | | } + | |_____^ help: try: `some_slice.fill(0);` + | + = note: `-D clippy::manual-slice-fill` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_slice_fill)]` + +error: manually filling a slice + --> tests/ui/manual_slice_fill.rs:30:5 + | +LL | / for i in 0..some_slice.len() { +LL | | some_slice[i] = x; +LL | | } + | |_____^ help: try: `some_slice.fill(x);` + +error: manually filling a slice + --> tests/ui/manual_slice_fill.rs:34:5 + | +LL | / for i in &mut some_slice { +LL | | *i = 0; +LL | | } + | |_____^ help: try: `some_slice.fill(0);` + +error: manually filling a slice + --> tests/ui/manual_slice_fill.rs:40:5 + | +LL | / for i in 0..some_slice.len() { +LL | | some_slice[i] = 0; +LL | | // foo +LL | | } + | |_____^ help: try: `some_slice.fill(0);` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/manual_unwrap_or_default_unfixable.rs b/tests/ui/manual_unwrap_or_default_unfixable.rs new file mode 100644 index 000000000000..acc54b52816c --- /dev/null +++ b/tests/ui/manual_unwrap_or_default_unfixable.rs @@ -0,0 +1,15 @@ +//@no-rustfix +fn issue_12670() { + // no auto: type not found + #[allow(clippy::match_result_ok)] + let _ = if let Some(x) = "1".parse().ok() { + x + } else { + i32::default() + }; + let _ = if let Some(x) = None { x } else { i32::default() }; + // auto fix with unwrap_or_default + let a: Option = None; + let _ = if let Some(x) = a { x } else { i32::default() }; + let _ = if let Some(x) = Some(99) { x } else { i32::default() }; +} diff --git a/tests/ui/manual_unwrap_or_default_unfixable.stderr b/tests/ui/manual_unwrap_or_default_unfixable.stderr new file mode 100644 index 000000000000..3849d33cf254 --- /dev/null +++ b/tests/ui/manual_unwrap_or_default_unfixable.stderr @@ -0,0 +1,34 @@ +error: if let can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default_unfixable.rs:5:13 + | +LL | let _ = if let Some(x) = "1".parse().ok() { + | _____________^ +LL | | x +LL | | } else { +LL | | i32::default() +LL | | }; + | |_____^ help: ascribe the type i32 and replace your expression with: `"1".parse().ok().unwrap_or_default()` + | + = note: `-D clippy::manual-unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]` + +error: if let can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default_unfixable.rs:10:13 + | +LL | let _ = if let Some(x) = None { x } else { i32::default() }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `None::.unwrap_or_default()` + +error: if let can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default_unfixable.rs:13:13 + | +LL | let _ = if let Some(x) = a { x } else { i32::default() }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.unwrap_or_default()` + +error: if let can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default_unfixable.rs:14:13 + | +LL | let _ = if let Some(x) = Some(99) { x } else { i32::default() }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(99).unwrap_or_default()` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/needless_option_take.fixed b/tests/ui/needless_option_take.fixed new file mode 100644 index 000000000000..6514b67ef7a7 --- /dev/null +++ b/tests/ui/needless_option_take.fixed @@ -0,0 +1,58 @@ +struct MyStruct; + +impl MyStruct { + pub fn get_option() -> Option { + todo!() + } +} + +fn return_option() -> Option { + todo!() +} + +fn main() { + println!("Testing non erroneous option_take_on_temporary"); + let mut option = Some(1); + let _ = Box::new(move || option.take().unwrap()); + + println!("Testing non erroneous option_take_on_temporary"); + let x = Some(3); + x.as_ref(); + + let x = Some(3); + x.as_ref(); + //~^ ERROR: called `Option::take()` on a temporary value + + println!("Testing non erroneous option_take_on_temporary"); + let mut x = Some(3); + let y = x.as_mut(); + + let mut x = Some(3); + let y = x.as_mut(); + //~^ ERROR: called `Option::take()` on a temporary value + let y = x.replace(289); + //~^ ERROR: called `Option::take()` on a temporary value + + let y = Some(3).as_mut(); + //~^ ERROR: called `Option::take()` on a temporary value + + let y = Option::as_mut(&mut x); + //~^ ERROR: called `Option::take()` on a temporary value + + let x = return_option(); + let x = return_option(); + //~^ ERROR: called `Option::take()` on a temporary value + + let x = MyStruct::get_option(); + let x = MyStruct::get_option(); + //~^ ERROR: called `Option::take()` on a temporary value + + let mut my_vec = vec![1, 2, 3]; + my_vec.push(4); + let y = my_vec.first(); + let y = my_vec.first(); + //~^ ERROR: called `Option::take()` on a temporary value + + let y = my_vec.first(); + //~^ ERROR: called `Option::take()` on a temporary value +} diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index e036bd53170a..3fc339ed79e2 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -2,7 +2,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:23:5 | LL | x.as_ref().take(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^------- + | | + | help: remove | = note: `as_ref` creates a temporary value, so calling take() has no effect = note: `-D clippy::needless-option-take` implied by `-D warnings` @@ -12,7 +14,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:31:13 | LL | let y = x.as_mut().take(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^------- + | | + | help: remove | = note: `as_mut` creates a temporary value, so calling take() has no effect @@ -20,7 +24,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:33:13 | LL | let y = x.replace(289).take(); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `replace` creates a temporary value, so calling take() has no effect @@ -28,7 +34,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:36:13 | LL | let y = Some(3).as_mut().take(); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `as_mut` creates a temporary value, so calling take() has no effect @@ -36,7 +44,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:39:13 | LL | let y = Option::as_mut(&mut x).take(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `as_mut` creates a temporary value, so calling take() has no effect @@ -44,7 +54,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:43:13 | LL | let x = return_option().take(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `return_option` creates a temporary value, so calling take() has no effect @@ -52,7 +64,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:47:13 | LL | let x = MyStruct::get_option().take(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `get_option` creates a temporary value, so calling take() has no effect @@ -60,7 +74,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:53:13 | LL | let y = my_vec.first().take(); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `first` creates a temporary value, so calling take() has no effect @@ -68,7 +84,9 @@ error: called `Option::take()` on a temporary value --> tests/ui/needless_option_take.rs:56:13 | LL | let y = my_vec.first().take(); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^------- + | | + | help: remove | = note: `first` creates a temporary value, so calling take() has no effect diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index 3f2421953301..75f1896eded1 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -2,7 +2,8 @@ #![allow( clippy::uninlined_format_args, clippy::unnecessary_literal_unwrap, - clippy::useless_vec + clippy::useless_vec, + clippy::manual_slice_fill )] //@no-rustfix static STATIC: [usize; 4] = [0, 1, 8, 16]; diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index dc2cf437e02e..503d796e5e8d 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -1,5 +1,5 @@ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:15:14 + --> tests/ui/needless_range_loop.rs:16:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:26:14 + --> tests/ui/needless_range_loop.rs:27:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> tests/ui/needless_range_loop.rs:32:14 + --> tests/ui/needless_range_loop.rs:33:14 | LL | for j in 0..4 { | ^^^^ @@ -34,7 +34,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> tests/ui/needless_range_loop.rs:37:14 + --> tests/ui/needless_range_loop.rs:38:14 | LL | for j in 0..4 { | ^^^^ @@ -45,7 +45,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:42:14 + --> tests/ui/needless_range_loop.rs:43:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> tests/ui/needless_range_loop.rs:51:14 + --> tests/ui/needless_range_loop.rs:52:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:56:14 + --> tests/ui/needless_range_loop.rs:57:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:61:14 + --> tests/ui/needless_range_loop.rs:62:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:66:14 + --> tests/ui/needless_range_loop.rs:67:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:71:14 + --> tests/ui/needless_range_loop.rs:72:14 | LL | for i in 5..10 { | ^^^^^ @@ -111,7 +111,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:76:14 + --> tests/ui/needless_range_loop.rs:77:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -122,7 +122,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:81:14 + --> tests/ui/needless_range_loop.rs:82:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:86:14 + --> tests/ui/needless_range_loop.rs:87:14 | LL | for i in 5..10 { | ^^^^^ @@ -144,7 +144,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:92:14 + --> tests/ui/needless_range_loop.rs:93:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed index 9864dd2550b6..52144a18bac0 100644 --- a/tests/ui/precedence.fixed +++ b/tests/ui/precedence.fixed @@ -20,10 +20,10 @@ fn main() { 1 ^ (1 - 1); 3 | (2 - 1); 3 & (5 - 2); - 0x0F00 & (0x00F0 << 4); - 0x0F00 & (0xF000 >> 4); - (0x0F00 << 1) ^ 3; - (0x0F00 << 1) | 2; + 0x0F00 & 0x00F0 << 4; + 0x0F00 & 0xF000 >> 4; + 0x0F00 << 1 ^ 3; + 0x0F00 << 1 | 2; let b = 3; trip!(b * 8); diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index 329422cb8a69..68ad5cb4829a 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -43,29 +43,5 @@ error: operator precedence might not be obvious LL | 3 & 5 - 2; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` -error: operator precedence might not be obvious - --> tests/ui/precedence.rs:23:5 - | -LL | 0x0F00 & 0x00F0 << 4; - | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0x00F0 << 4)` - -error: operator precedence might not be obvious - --> tests/ui/precedence.rs:24:5 - | -LL | 0x0F00 & 0xF000 >> 4; - | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0xF000 >> 4)` - -error: operator precedence might not be obvious - --> tests/ui/precedence.rs:25:5 - | -LL | 0x0F00 << 1 ^ 3; - | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) ^ 3` - -error: operator precedence might not be obvious - --> tests/ui/precedence.rs:26:5 - | -LL | 0x0F00 << 1 | 2; - | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) | 2` - -error: aborting due to 11 previous errors +error: aborting due to 7 previous errors diff --git a/tests/ui/precedence_bits.fixed b/tests/ui/precedence_bits.fixed new file mode 100644 index 000000000000..82fea0d14e43 --- /dev/null +++ b/tests/ui/precedence_bits.fixed @@ -0,0 +1,35 @@ +#![warn(clippy::precedence_bits)] +#![allow( + unused_must_use, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::precedence +)] +#![allow(clippy::identity_op)] +#![allow(clippy::eq_op)] + +macro_rules! trip { + ($a:expr) => { + match $a & 0b1111_1111u8 { + 0 => println!("a is zero ({})", $a), + _ => println!("a is {}", $a), + } + }; +} + +fn main() { + 1 << 2 + 3; + 1 + 2 << 3; + 4 >> 1 + 1; + 1 + 3 >> 2; + 1 ^ 1 - 1; + 3 | 2 - 1; + 3 & 5 - 2; + 0x0F00 & (0x00F0 << 4); + 0x0F00 & (0xF000 >> 4); + (0x0F00 << 1) ^ 3; + (0x0F00 << 1) | 2; + + let b = 3; + trip!(b * 8); +} diff --git a/tests/ui/precedence_bits.rs b/tests/ui/precedence_bits.rs new file mode 100644 index 000000000000..9b353308b6ee --- /dev/null +++ b/tests/ui/precedence_bits.rs @@ -0,0 +1,35 @@ +#![warn(clippy::precedence_bits)] +#![allow( + unused_must_use, + clippy::no_effect, + clippy::unnecessary_operation, + clippy::precedence +)] +#![allow(clippy::identity_op)] +#![allow(clippy::eq_op)] + +macro_rules! trip { + ($a:expr) => { + match $a & 0b1111_1111u8 { + 0 => println!("a is zero ({})", $a), + _ => println!("a is {}", $a), + } + }; +} + +fn main() { + 1 << 2 + 3; + 1 + 2 << 3; + 4 >> 1 + 1; + 1 + 3 >> 2; + 1 ^ 1 - 1; + 3 | 2 - 1; + 3 & 5 - 2; + 0x0F00 & 0x00F0 << 4; + 0x0F00 & 0xF000 >> 4; + 0x0F00 << 1 ^ 3; + 0x0F00 << 1 | 2; + + let b = 3; + trip!(b * 8); +} diff --git a/tests/ui/precedence_bits.stderr b/tests/ui/precedence_bits.stderr new file mode 100644 index 000000000000..f468186b363c --- /dev/null +++ b/tests/ui/precedence_bits.stderr @@ -0,0 +1,29 @@ +error: operator precedence might not be obvious + --> tests/ui/precedence_bits.rs:28:5 + | +LL | 0x0F00 & 0x00F0 << 4; + | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0x00F0 << 4)` + | + = note: `-D clippy::precedence-bits` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::precedence_bits)]` + +error: operator precedence might not be obvious + --> tests/ui/precedence_bits.rs:29:5 + | +LL | 0x0F00 & 0xF000 >> 4; + | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0xF000 >> 4)` + +error: operator precedence might not be obvious + --> tests/ui/precedence_bits.rs:30:5 + | +LL | 0x0F00 << 1 ^ 3; + | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) ^ 3` + +error: operator precedence might not be obvious + --> tests/ui/precedence_bits.rs:31:5 + | +LL | 0x0F00 << 1 | 2; + | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) | 2` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index 1705a7ff01bb..328e9a9b999f 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -66,3 +66,17 @@ fn main() { println!("mixed: {{hello}} {world}"); } + +fn issue_13959() { + println!("\""); + println!( + " + foo + \\ + \\\\ + \" + \\\" + bar +" + ); +} diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index d10b26b5887c..3130d0b6998e 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -66,3 +66,18 @@ fn main() { println!("mixed: {} {world}", "{hello}"); } + +fn issue_13959() { + println!("{}", r#"""#); + println!( + "{}", + r#" + foo + \ + \\ + " + \" + bar +"# + ); +} diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index c4cbb8bed707..d967b7c24070 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -192,5 +192,41 @@ LL - println!("mixed: {} {world}", "{hello}"); LL + println!("mixed: {{hello}} {world}"); | -error: aborting due to 16 previous errors +error: literal with an empty format string + --> tests/ui/print_literal.rs:71:20 + | +LL | println!("{}", r#"""#); + | ^^^^^^ + | +help: try + | +LL - println!("{}", r#"""#); +LL + println!("\""); + | + +error: literal with an empty format string + --> tests/ui/print_literal.rs:74:9 + | +LL | / r#" +LL | | foo +LL | | \ +LL | | \\ +... | +LL | | bar +LL | | "# + | |__^ + | +help: try + | +LL ~ " +LL + foo +LL + \\ +LL + \\\\ +LL + \" +LL + \\\" +LL + bar +LL ~ " + | + +error: aborting due to 18 previous errors diff --git a/tests/ui/redundant_else.fixed b/tests/ui/redundant_else.fixed new file mode 100644 index 000000000000..47aa79302d2c --- /dev/null +++ b/tests/ui/redundant_else.fixed @@ -0,0 +1,154 @@ +#![warn(clippy::redundant_else)] +#![allow(clippy::needless_return, clippy::if_same_then_else, clippy::needless_late_init)] + +fn main() { + loop { + // break + if foo() { + println!("Love your neighbor;"); + break; + } + //~^ ERROR: redundant else block + println!("yet don't pull down your hedge."); + // continue + if foo() { + println!("He that lies down with Dogs,"); + continue; + } + //~^ ERROR: redundant else block + println!("shall rise up with fleas."); + // match block + if foo() { + match foo() { + 1 => break, + _ => return, + } + } + //~^ ERROR: redundant else block + println!("You may delay, but time will not."); + } + // else if + if foo() { + return; + } else if foo() { + return; + } + //~^ ERROR: redundant else block + println!("A fat kitchen makes a lean will."); + // let binding outside of block + let _ = { + if foo() { + return; + } + //~^ ERROR: redundant else block + 1 + }; + // else if with let binding outside of block + let _ = { + if foo() { + return; + } else if foo() { + return; + } + //~^ ERROR: redundant else block + 2 + }; + // inside if let + let _ = if let Some(1) = foo() { + let _ = 1; + if foo() { + return; + } + //~^ ERROR: redundant else block + 1 + } else { + 1 + }; + + // + // non-lint cases + // + + // sanity check + if foo() { + let _ = 1; + } else { + println!("Who is wise? He that learns from every one."); + } + // else if without else + if foo() { + return; + } else if foo() { + foo() + }; + // nested if return + if foo() { + if foo() { + return; + } + } else { + foo() + }; + // match with non-breaking branch + if foo() { + match foo() { + 1 => foo(), + _ => return, + } + } else { + println!("Three may keep a secret, if two of them are dead."); + } + // let binding + let _ = if foo() { + return; + } else { + 1 + }; + // assign + let mut a; + a = if foo() { + return; + } else { + 1 + }; + // assign-op + a += if foo() { + return; + } else { + 1 + }; + // if return else if else + if foo() { + return; + } else if foo() { + 1 + } else { + 2 + }; + // if else if return else + if foo() { + 1 + } else if foo() { + return; + } else { + 2 + }; + // else if with let binding + let _ = if foo() { + return; + } else if foo() { + return; + } else { + 2 + }; + // inside function call + Box::new(if foo() { + return; + } else { + 1 + }); +} + +fn foo() -> T { + unimplemented!("I'm not Santa Claus") +} diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index b649a210b5fa..ecc16f7cda5e 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -1,88 +1,123 @@ error: redundant else block - --> tests/ui/redundant_else.rs:10:16 + --> tests/ui/redundant_else.rs:10:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ | - = help: remove the `else` block and move the contents out = note: `-D clippy::redundant-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_else)]` +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + println!("yet don't pull down your hedge."); + | error: redundant else block - --> tests/ui/redundant_else.rs:18:16 + --> tests/ui/redundant_else.rs:18:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | println!("shall rise up with fleas."); LL | | } | |_________^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + println!("shall rise up with fleas."); + | error: redundant else block - --> tests/ui/redundant_else.rs:28:16 + --> tests/ui/redundant_else.rs:28:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | println!("You may delay, but time will not."); LL | | } | |_________^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + println!("You may delay, but time will not."); + | error: redundant else block - --> tests/ui/redundant_else.rs:38:12 + --> tests/ui/redundant_else.rs:38:6 | LL | } else { - | ____________^ + | ______^ LL | | LL | | println!("A fat kitchen makes a lean will."); LL | | } | |_____^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + println!("A fat kitchen makes a lean will."); + | error: redundant else block - --> tests/ui/redundant_else.rs:46:16 + --> tests/ui/redundant_else.rs:46:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | 1 LL | | } | |_________^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + 1 + | error: redundant else block - --> tests/ui/redundant_else.rs:57:16 + --> tests/ui/redundant_else.rs:57:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | 2 LL | | } | |_________^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + 2 + | error: redundant else block - --> tests/ui/redundant_else.rs:67:16 + --> tests/ui/redundant_else.rs:67:10 | LL | } else { - | ________________^ + | __________^ LL | | LL | | 1 LL | | } | |_________^ | - = help: remove the `else` block and move the contents out +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + 1 + | error: aborting due to 7 previous errors diff --git a/tests/ui/return_and_then.fixed b/tests/ui/return_and_then.fixed new file mode 100644 index 000000000000..9736a51ac868 --- /dev/null +++ b/tests/ui/return_and_then.fixed @@ -0,0 +1,67 @@ +#![warn(clippy::return_and_then)] + +fn main() { + fn test_opt_block(opt: Option) -> Option { + let n = opt?; + let mut ret = n + 1; + ret += n; + if n > 1 { Some(ret) } else { None } + } + + fn test_opt_func(opt: Option) -> Option { + let n = opt?; + test_opt_block(Some(n)) + } + + fn test_call_chain() -> Option { + let n = gen_option(1)?; + test_opt_block(Some(n)) + } + + fn test_res_block(opt: Result) -> Result { + let n = opt?; + if n > 1 { Ok(n + 1) } else { Err(n) } + } + + fn test_res_func(opt: Result) -> Result { + let n = opt?; + test_res_block(Ok(n)) + } + + fn test_ref_only() -> Option { + // ref: empty string + let x = Some("")?; + if x.len() > 2 { Some(3) } else { None } + } + + fn test_tmp_only() -> Option { + // unused temporary: vec![1, 2, 4] + let x = Some(match (vec![1, 2, 3], vec![1, 2, 4]) { + (a, _) if a.len() > 1 => a, + (_, b) => b, + })?; + if x.len() > 2 { Some(3) } else { None } + } + + // should not lint + fn test_tmp_ref() -> Option { + String::from("") + .strip_prefix("<") + .and_then(|s| s.strip_suffix(">").map(String::from)) + } + + // should not lint + fn test_unconsumed_tmp() -> Option { + [1, 2, 3] + .iter() + .map(|x| x + 1) + .collect::>() // temporary Vec created here + .as_slice() // creates temporary slice + .first() // creates temporary reference + .and_then(|x| test_opt_block(Some(*x))) + } +} + +fn gen_option(n: i32) -> Option { + Some(n) +} diff --git a/tests/ui/return_and_then.rs b/tests/ui/return_and_then.rs new file mode 100644 index 000000000000..8bcbdfc3a632 --- /dev/null +++ b/tests/ui/return_and_then.rs @@ -0,0 +1,63 @@ +#![warn(clippy::return_and_then)] + +fn main() { + fn test_opt_block(opt: Option) -> Option { + opt.and_then(|n| { + let mut ret = n + 1; + ret += n; + if n > 1 { Some(ret) } else { None } + }) + } + + fn test_opt_func(opt: Option) -> Option { + opt.and_then(|n| test_opt_block(Some(n))) + } + + fn test_call_chain() -> Option { + gen_option(1).and_then(|n| test_opt_block(Some(n))) + } + + fn test_res_block(opt: Result) -> Result { + opt.and_then(|n| if n > 1 { Ok(n + 1) } else { Err(n) }) + } + + fn test_res_func(opt: Result) -> Result { + opt.and_then(|n| test_res_block(Ok(n))) + } + + fn test_ref_only() -> Option { + // ref: empty string + Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None }) + } + + fn test_tmp_only() -> Option { + // unused temporary: vec![1, 2, 4] + Some(match (vec![1, 2, 3], vec![1, 2, 4]) { + (a, _) if a.len() > 1 => a, + (_, b) => b, + }) + .and_then(|x| if x.len() > 2 { Some(3) } else { None }) + } + + // should not lint + fn test_tmp_ref() -> Option { + String::from("") + .strip_prefix("<") + .and_then(|s| s.strip_suffix(">").map(String::from)) + } + + // should not lint + fn test_unconsumed_tmp() -> Option { + [1, 2, 3] + .iter() + .map(|x| x + 1) + .collect::>() // temporary Vec created here + .as_slice() // creates temporary slice + .first() // creates temporary reference + .and_then(|x| test_opt_block(Some(*x))) + } +} + +fn gen_option(n: i32) -> Option { + Some(n) +} diff --git a/tests/ui/return_and_then.stderr b/tests/ui/return_and_then.stderr new file mode 100644 index 000000000000..b2e8bf2ca45a --- /dev/null +++ b/tests/ui/return_and_then.stderr @@ -0,0 +1,101 @@ +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:5:9 + | +LL | / opt.and_then(|n| { +LL | | let mut ret = n + 1; +LL | | ret += n; +LL | | if n > 1 { Some(ret) } else { None } +LL | | }) + | |__________^ + | + = note: `-D clippy::return-and-then` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::return_and_then)]` +help: try + | +LL ~ let n = opt?; +LL + let mut ret = n + 1; +LL + ret += n; +LL + if n > 1 { Some(ret) } else { None } + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:13:9 + | +LL | opt.and_then(|n| test_opt_block(Some(n))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let n = opt?; +LL + test_opt_block(Some(n)) + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:17:9 + | +LL | gen_option(1).and_then(|n| test_opt_block(Some(n))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let n = gen_option(1)?; +LL + test_opt_block(Some(n)) + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:21:9 + | +LL | opt.and_then(|n| if n > 1 { Ok(n + 1) } else { Err(n) }) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let n = opt?; +LL + if n > 1 { Ok(n + 1) } else { Err(n) } + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:25:9 + | +LL | opt.and_then(|n| test_res_block(Ok(n))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let n = opt?; +LL + test_res_block(Ok(n)) + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:30:9 + | +LL | Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None }) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let x = Some("")?; +LL + if x.len() > 2 { Some(3) } else { None } + | + +error: use the question mark operator instead of an `and_then` call + --> tests/ui/return_and_then.rs:35:9 + | +LL | / Some(match (vec![1, 2, 3], vec![1, 2, 4]) { +LL | | (a, _) if a.len() > 1 => a, +LL | | (_, b) => b, +LL | | }) +LL | | .and_then(|x| if x.len() > 2 { Some(3) } else { None }) + | |_______________________________________________________________^ + | +help: try + | +LL ~ let x = Some(match (vec![1, 2, 3], vec![1, 2, 4]) { +LL + (a, _) if a.len() > 1 => a, +LL + (_, b) => b, +LL + })?; +LL + if x.len() > 2 { Some(3) } else { None } + | + +error: aborting due to 7 previous errors + diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index 91b7ea3922c5..f405ba200acd 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -8,11 +8,11 @@ fn main() { const SIZE: usize = 128; const HALF_SIZE: usize = SIZE / 2; const DOUBLE_SIZE: usize = SIZE * 2; - let mut x = [2u8; SIZE]; - let mut y = [2u8; SIZE]; + let mut x = [2u16; SIZE]; + let mut y = [2u16; SIZE]; // Count expression involving multiplication of size_of (Should trigger the lint) - unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; + 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) @@ -20,22 +20,19 @@ fn main() { //~^ 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) }; + 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::()) }; + unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / size_of::()) }; // Count expression involving divisions by multiple size_of (Should not trigger the lint) - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 * size_of::())) }; + unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 * size_of::())) }; // 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::())) }; + 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) }; - - // Different types for pointee and size_of (Should not trigger the lint) - unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() / 2 * SIZE) }; } diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 6396afd7f395..74be0d7773df 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -1,8 +1,8 @@ error: found a count of bytes instead of a count of elements of `T` --> tests/ui/size_of_in_element_count/expressions.rs:15:62 | -LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { copy_nonoverlapping(x.as_ptr(), 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 = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` @@ -19,16 +19,16 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si error: found a count of bytes instead of a count of elements of `T` --> tests/ui/size_of_in_element_count/expressions.rs:23:47 | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` --> tests/ui/size_of_in_element_count/expressions.rs:33:47 | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type diff --git a/tests/ui/size_of_in_element_count/functions.rs b/tests/ui/size_of_in_element_count/functions.rs index 3501cbdf81cf..af18136a1dbe 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -11,57 +11,52 @@ fn main() { const SIZE: usize = 128; const HALF_SIZE: usize = SIZE / 2; const DOUBLE_SIZE: usize = SIZE * 2; - let mut x = [2u8; SIZE]; - let mut y = [2u8; SIZE]; + let mut x = [2u16; SIZE]; + let mut y = [2u16; SIZE]; // Count is size_of (Should trigger the lint) - unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + 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::()) }; + 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::()) }; + 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::()) }; + 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::()) }; + 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::()) }; + 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) }; + 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` - unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; + 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` - slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); + 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` - slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); + 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 { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; + unsafe { y.as_mut_ptr().sub(size_of::()) }; //~^ ERROR: found a count of bytes instead of a count of elements of `T` - unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; + y.as_ptr().wrapping_sub(size_of::()); //~^ ERROR: found a count of bytes instead of a count of elements of `T` - - unsafe { y.as_mut_ptr().sub(size_of::()) }; + unsafe { y.as_ptr().add(size_of::()) }; //~^ ERROR: found a count of bytes instead of a count of elements of `T` - y.as_ptr().wrapping_sub(size_of::()); + 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().add(size_of::()) }; + 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_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); + 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 abde7dc7cd2d..de54789b2251 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -1,8 +1,8 @@ error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/functions.rs:18:68 + --> tests/ui/size_of_in_element_count/functions.rs:18:69 | -LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +LL | unsafe { copy_nonoverlapping::(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 = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` @@ -19,40 +19,40 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x error: found a count of bytes instead of a count of elements of `T` --> tests/ui/size_of_in_element_count/functions.rs:23:49 | -LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +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` --> tests/ui/size_of_in_element_count/functions.rs:25:64 | -LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +LL | unsafe { x.as_ptr().copy_to_nonoverlapping(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` --> tests/ui/size_of_in_element_count/functions.rs:27:51 | -LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +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` --> tests/ui/size_of_in_element_count/functions.rs:29:66 | -LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +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` --> tests/ui/size_of_in_element_count/functions.rs:32:47 | -LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; - | ^^^^^^^^^^^^^^^ +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 @@ -65,108 +65,92 @@ 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` - --> tests/ui/size_of_in_element_count/functions.rs:37:46 + --> tests/ui/size_of_in_element_count/functions.rs:37:66 | -LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.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` - --> tests/ui/size_of_in_element_count/functions.rs:39:47 + --> tests/ui/size_of_in_element_count/functions.rs:40:46 | -LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:42:66 + --> tests/ui/size_of_in_element_count/functions.rs:42:38 | -LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:45:46 + --> tests/ui/size_of_in_element_count/functions.rs:45:49 | -LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:47:38 + --> tests/ui/size_of_in_element_count/functions.rs:47:41 | -LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:50:49 + --> tests/ui/size_of_in_element_count/functions.rs:50:33 | -LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:52:41 + --> tests/ui/size_of_in_element_count/functions.rs:52:29 | -LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; - | ^^^^^^^^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:55:33 + --> tests/ui/size_of_in_element_count/functions.rs:54:29 | -LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; - | ^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:57:29 + --> tests/ui/size_of_in_element_count/functions.rs:56:33 | -LL | y.as_ptr().wrapping_sub(size_of::()); - | ^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:59:29 + --> tests/ui/size_of_in_element_count/functions.rs:58:32 | -LL | unsafe { y.as_ptr().add(size_of::()) }; - | ^^^^^^^^^^^^^^^ +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` - --> tests/ui/size_of_in_element_count/functions.rs:61:33 + --> tests/ui/size_of_in_element_count/functions.rs:60:36 | -LL | y.as_mut_ptr().wrapping_add(size_of::()); - | ^^^^^^^^^^^^^^^ +LL | y.as_mut_ptr().wrapping_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` - --> tests/ui/size_of_in_element_count/functions.rs:63:32 - | -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` - --> tests/ui/size_of_in_element_count/functions.rs:65:36 - | -LL | y.as_mut_ptr().wrapping_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: aborting due to 21 previous errors +error: aborting due to 19 previous errors diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index fb8fb1a00901..26166e2fc8da 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -1,4 +1,4 @@ -error: `ref` directly on a function argument is ignored. Consider using a reference type instead +error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead --> tests/ui/toplevel_ref_arg_non_rustfix.rs:9:15 | LL | fn the_answer(ref mut x: u8) { @@ -7,7 +7,7 @@ LL | fn the_answer(ref mut x: u8) { = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` -error: `ref` directly on a function argument is ignored. Consider using a reference type instead +error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead --> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24 | LL | fn fun_example(ref _x: usize) {} diff --git a/tests/ui/unnecessary_semicolon.edition2021.fixed b/tests/ui/unnecessary_semicolon.edition2021.fixed index 7a3b79553dea..343c88b98155 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.fixed +++ b/tests/ui/unnecessary_semicolon.edition2021.fixed @@ -55,3 +55,9 @@ fn no_borrow_issue(a: u32, b: u32) { None => {}, } } + +fn issue14100() -> bool { + // Removing the `;` would make the block type be `()` instead of `!`, and this could no longer be + // cast into the `bool` function return type. + if return true {}; +} diff --git a/tests/ui/unnecessary_semicolon.edition2024.fixed b/tests/ui/unnecessary_semicolon.edition2024.fixed index d186d5e7ebc4..1cba5760eb0a 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.fixed +++ b/tests/ui/unnecessary_semicolon.edition2024.fixed @@ -55,3 +55,9 @@ fn no_borrow_issue(a: u32, b: u32) { None => {}, } } + +fn issue14100() -> bool { + // Removing the `;` would make the block type be `()` instead of `!`, and this could no longer be + // cast into the `bool` function return type. + if return true {}; +} diff --git a/tests/ui/unnecessary_semicolon.rs b/tests/ui/unnecessary_semicolon.rs index 3028c5b27b34..6abbbd79aaf2 100644 --- a/tests/ui/unnecessary_semicolon.rs +++ b/tests/ui/unnecessary_semicolon.rs @@ -55,3 +55,9 @@ fn no_borrow_issue(a: u32, b: u32) { None => {}, }; } + +fn issue14100() -> bool { + // Removing the `;` would make the block type be `()` instead of `!`, and this could no longer be + // cast into the `bool` function return type. + if return true {}; +} diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed index 3d216b76cbf3..f1def776e1bc 100644 --- a/tests/ui/write_literal.fixed +++ b/tests/ui/write_literal.fixed @@ -62,3 +62,19 @@ fn main() { writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); //~^ ERROR: literal with an empty format string } + +fn issue_13959() { + let mut v = Vec::new(); + writeln!(v, "\""); + writeln!( + v, + " + foo + \\ + \\\\ + \" + \\\" + bar +" + ); +} diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index 79d6daa2e3b5..1b7df91b47e1 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -62,3 +62,20 @@ fn main() { writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); //~^ ERROR: literal with an empty format string } + +fn issue_13959() { + let mut v = Vec::new(); + writeln!(v, "{}", r#"""#); + writeln!( + v, + "{}", + r#" + foo + \ + \\ + " + \" + bar +"# + ); +} diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 9f4cdfd91e8a..35c93d567cd3 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -144,5 +144,41 @@ LL - writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); LL + writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); | -error: aborting due to 12 previous errors +error: literal with an empty format string + --> tests/ui/write_literal.rs:68:23 + | +LL | writeln!(v, "{}", r#"""#); + | ^^^^^^ + | +help: try + | +LL - writeln!(v, "{}", r#"""#); +LL + writeln!(v, "\""); + | + +error: literal with an empty format string + --> tests/ui/write_literal.rs:72:9 + | +LL | / r#" +LL | | foo +LL | | \ +LL | | \\ +... | +LL | | bar +LL | | "# + | |__^ + | +help: try + | +LL ~ " +LL + foo +LL + \\ +LL + \\\\ +LL + \" +LL + \\\" +LL + bar +LL ~ " + | + +error: aborting due to 14 previous errors diff --git a/util/gh-pages/index_template.html b/util/gh-pages/index_template.html index deb0ef0b4996..a9b646280030 100644 --- a/util/gh-pages/index_template.html +++ b/util/gh-pages/index_template.html @@ -24,14 +24,16 @@ Otherwise, have a great day =^.^= {# #} {# #} {# #} + {# #} + {# #} + {# #} {# #} {# #} - {# #}
{# #} {# #}
{# #}
Theme
{# #} - {# #} {# #} {# #} {# #} @@ -39,11 +41,12 @@ Otherwise, have a great day =^.^= {# #} {# #} {# #}
{# #}
{# #} + {# #}
{# #} {# #}
{# #}
{# #} - {# #} - {# #}
{# #} @@ -145,13 +148,13 @@ Otherwise, have a great day =^.^= {% for lint in lints %}
{# #} {# #} -
{# #}

{# #} {# #} @@ -227,9 +230,5 @@ Otherwise, have a great day =^.^= > {# #} {# #} {# #} - - {# #} - {# #} - {# #} {# #} {# #} diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js index 34d76ad642ec..c942a6a05a10 100644 --- a/util/gh-pages/script.js +++ b/util/gh-pages/script.js @@ -1,3 +1,5 @@ +"use strict"; + window.searchState = { timeout: null, inputElem: document.getElementById("search-input"), @@ -124,13 +126,6 @@ function toggleElements(filter, value) { } } -function changeSetting(elem) { - if (elem.id === "disable-shortcuts") { - disableShortcuts = elem.checked; - storeValue(elem.id, elem.checked); - } -} - function onEachLazy(lazyArray, func) { const arr = Array.prototype.slice.call(lazyArray); for (const el of arr) { @@ -138,17 +133,9 @@ function onEachLazy(lazyArray, func) { } } -function highlightIfNeeded(lintId) { - onEachLazy(document.querySelectorAll(`#${lintId} pre > code:not(.hljs)`), el => { - hljs.highlightElement(el.parentElement) - el.classList.add("highlighted"); - }); -} - function expandLint(lintId) { const elem = document.querySelector(`#${lintId} > input[type="checkbox"]`); elem.checked = true; - highlightIfNeeded(lintId); } function lintAnchor(event) { @@ -194,13 +181,9 @@ function handleBlur(event, elementId) { } function toggleExpansion(expand) { - onEachLazy( - document.querySelectorAll("article"), - expand ? el => { - el.classList.remove("collapsed"); - highlightIfNeeded(el); - } : el => el.classList.add("collapsed"), - ); + for (const checkbox of document.querySelectorAll("article input[type=checkbox]")) { + checkbox.checked = expand; + } } // Returns the current URL without any query parameter or hash. @@ -535,7 +518,7 @@ function parseURLFilters() { for (const [corres_key, corres_value] of Object.entries(URL_PARAMS_CORRESPONDENCE)) { if (corres_value === key) { if (key !== "versions") { - const settings = new Set(value.split(",")); + const settings = new Set(value.split(",")); onEachLazy(document.querySelectorAll(`#lint-${key} ul input`), elem => { elem.checked = settings.has(elem.getAttribute("data-value")); updateFilter(elem, corres_key, true); @@ -555,12 +538,60 @@ function parseURLFilters() { } } -document.getElementById(`theme-choice`).value = loadValue("theme"); -let disableShortcuts = loadValue('disable-shortcuts') === "true"; -document.getElementById("disable-shortcuts").checked = disableShortcuts; +function addListeners() { + disableShortcutsButton.addEventListener("change", () => { + disableShortcuts = disableShortcutsButton.checked; + storeValue("disable-shortcuts", disableShortcuts); + }); -document.addEventListener("keypress", handleShortcut); -document.addEventListener("keydown", handleShortcut); + document.getElementById("expand-all").addEventListener("click", () => toggleExpansion(true)); + document.getElementById("collapse-all").addEventListener("click", () => toggleExpansion(false)); + + // A delegated listener to avoid the upfront cost of >1000 listeners + document.addEventListener("click", event => { + if (!event.target instanceof HTMLAnchorElement) { + return; + } + + if (event.target.classList.contains("lint-anchor")) { + lintAnchor(event); + } else if (event.target.classList.contains("copy-to-clipboard")) { + copyToClipboard(event); + } + }); + + document.addEventListener("keypress", handleShortcut); + document.addEventListener("keydown", handleShortcut); +} + +// Highlight code blocks only when they approach the viewport so that clicking the "Expand All" +// button doesn't take a long time +function highlightLazily() { + if (!'IntersectionObserver' in window) { + return; + } + const observer = new IntersectionObserver((entries) => { + for (const entry of entries) { + if (entry.isIntersecting) { + observer.unobserve(entry.target); + for (const code of entry.target.querySelectorAll("pre code")) { + hljs.highlightElement(code); + } + } + } + }); + for (const docs of document.querySelectorAll(".lint-docs")) { + observer.observe(docs); + } +} + +let disableShortcuts = loadValue("disable-shortcuts") === "true"; + +const disableShortcutsButton = document.getElementById("disable-shortcuts"); +disableShortcutsButton.checked = disableShortcuts; + +addListeners(); +highlightLazily(); generateSettings(); generateSearch(); diff --git a/util/gh-pages/style.css b/util/gh-pages/style.css index 896f2fdac767..3cc7a919c23a 100644 --- a/util/gh-pages/style.css +++ b/util/gh-pages/style.css @@ -1,9 +1,5 @@ blockquote { font-size: 1em; } -[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { - display: none !important; -} - .dropdown-menu { color: var(--fg); background: var(--theme-popup-bg); @@ -188,8 +184,8 @@ details { padding: .5em .5em 0; } -code { - white-space: pre !important; +pre { + padding: 0; } summary { diff --git a/util/gh-pages/theme.js b/util/gh-pages/theme.js index 90f57d4469d1..a5dfeed9e8c8 100644 --- a/util/gh-pages/theme.js +++ b/util/gh-pages/theme.js @@ -1,3 +1,5 @@ +"use strict"; + function storeValue(settingName, value) { try { localStorage.setItem(`clippy-lint-list-${settingName}`, value); @@ -57,4 +59,11 @@ function setTheme(theme, store) { } else { setTheme(theme, false); } + + const themeChoice = document.getElementById("theme-choice"); + + themeChoice.value = loadValue("theme"); + document.getElementById("theme-choice").addEventListener("change", (e) => { + setTheme(themeChoice.value, true); + }); })(); From 8a9d55012d48d121e8552ccd72d86f1f5a420abf Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 5 Feb 2025 18:33:33 +0100 Subject: [PATCH 045/161] Use edition 2024 when running `cargo dev lint` --- clippy_dev/src/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_dev/src/lint.rs b/clippy_dev/src/lint.rs index 125195397e6c..beae7be7b304 100644 --- a/clippy_dev/src/lint.rs +++ b/clippy_dev/src/lint.rs @@ -17,7 +17,7 @@ pub fn run<'a>(path: &str, args: impl Iterator) { .args(["run", "--bin", "clippy-driver", "--"]) .args(["-L", "./target/debug"]) .args(["-Z", "no-codegen"]) - .args(["--edition", "2021"]) + .args(["--edition", "2024"]) .arg(path) .args(args) // Prevent rustc from creating `rustc-ice-*` files the console output is enough. From 0e42ba908c6b58674a979ff705bd517ad6cb03f0 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 5 Feb 2025 18:33:33 +0100 Subject: [PATCH 046/161] Permit specifying a non-default edition when linting file `cargo dev lint /tmp/file.rs -- --edition 2021` will select edition 2021. --- clippy_dev/src/lint.rs | 4 ++-- clippy_dev/src/main.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clippy_dev/src/lint.rs b/clippy_dev/src/lint.rs index beae7be7b304..e0e036757d56 100644 --- a/clippy_dev/src/lint.rs +++ b/clippy_dev/src/lint.rs @@ -2,7 +2,7 @@ use crate::utils::{cargo_clippy_path, exit_if_err}; use std::process::{self, Command}; use std::{env, fs}; -pub fn run<'a>(path: &str, args: impl Iterator) { +pub fn run<'a>(path: &str, edition: &str, args: impl Iterator) { let is_file = match fs::metadata(path) { Ok(metadata) => metadata.is_file(), Err(e) => { @@ -17,7 +17,7 @@ pub fn run<'a>(path: &str, args: impl Iterator) { .args(["run", "--bin", "clippy-driver", "--"]) .args(["-L", "./target/debug"]) .args(["-Z", "no-codegen"]) - .args(["--edition", "2024"]) + .args(["--edition", edition]) .arg(path) .args(args) // Prevent rustc from creating `rustc-ice-*` files the console output is enough. diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 56ed60256f16..93a74ba83871 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -68,7 +68,7 @@ fn main() { RemoveSubcommand::VscodeTasks => setup::vscode::remove_tasks(), }, DevCommand::Serve { port, lint } => serve::run(port, lint), - DevCommand::Lint { path, args } => lint::run(&path, args.iter()), + DevCommand::Lint { path, edition, args } => lint::run(&path, &edition, args.iter()), DevCommand::RenameLint { old_name, new_name, @@ -206,6 +206,9 @@ enum DevCommand { /// cargo dev lint file.rs -- -W clippy::pedantic {n} /// cargo dev lint ~/my-project -- -- -W clippy::pedantic Lint { + /// The Rust edition to use + #[arg(long, default_value = "2024")] + edition: String, /// The path to a file or package directory to lint path: String, /// Pass extra arguments to cargo/clippy-driver From 16781bf29d2da41fd1b67a5dfffbe40dfdf312eb Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Fri, 7 Feb 2025 20:57:11 +0900 Subject: [PATCH 047/161] add `manual_option_as_slice` to the lint documentation --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index dab2630a56fc..f662595d91e8 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -747,6 +747,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) * [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) * [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive) +* [`manual_option_as_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice) * [`manual_pattern_char_comparison`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison) * [`manual_range_contains`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains) * [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index a1591188bee7..c08cc53db0c2 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -616,6 +616,7 @@ define_Conf! { manual_is_ascii_check, manual_let_else, manual_non_exhaustive, + manual_option_as_slice, manual_pattern_char_comparison, manual_range_contains, manual_rem_euclid, From 7c94744afb8e9c1ad1b4f08ea7823596c720e125 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 7 Feb 2025 09:13:59 -0500 Subject: [PATCH 048/161] Address additional review comments --- clippy_config/src/types.rs | 4 +++- clippy_lints/src/disallowed_types.rs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index b07188a2b0f6..c72291e9799f 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -40,9 +40,11 @@ impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath Date: Thu, 6 Feb 2025 21:15:51 +0100 Subject: [PATCH 049/161] Convert `EMPTY_LINE_AFTER_OUTER_ATTR` and `EMPTY_LINE_AFTER_OUTER_ATTR` lint into early lints --- clippy_lints/src/declared_lints.rs | 4 +- clippy_lints/src/doc/empty_line_after.rs | 345 ----------------- clippy_lints/src/doc/mod.rs | 81 +--- clippy_lints/src/empty_line_after.rs | 453 +++++++++++++++++++++++ clippy_lints/src/lib.rs | 2 + 5 files changed, 458 insertions(+), 427 deletions(-) delete mode 100644 clippy_lints/src/doc/empty_line_after.rs create mode 100644 clippy_lints/src/empty_line_after.rs diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9fbeab5bf2e1..5c5978b55598 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -144,8 +144,6 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::doc::DOC_NESTED_REFDEFS_INFO, crate::doc::DOC_OVERINDENTED_LIST_ITEMS_INFO, crate::doc::EMPTY_DOCS_INFO, - crate::doc::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, - crate::doc::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::doc::MISSING_ERRORS_DOC_INFO, crate::doc::MISSING_PANICS_DOC_INFO, crate::doc::MISSING_SAFETY_DOC_INFO, @@ -162,6 +160,8 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, crate::empty_drop::EMPTY_DROP_INFO, crate::empty_enum::EMPTY_ENUM_INFO, + crate::empty_line_after::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, + crate::empty_line_after::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::empty_with_brackets::EMPTY_ENUM_VARIANTS_WITH_BRACKETS_INFO, crate::empty_with_brackets::EMPTY_STRUCTS_WITH_BRACKETS_INFO, crate::endian_bytes::BIG_ENDIAN_BYTES_INFO, diff --git a/clippy_lints/src/doc/empty_line_after.rs b/clippy_lints/src/doc/empty_line_after.rs deleted file mode 100644 index 6e85c6af642b..000000000000 --- a/clippy_lints/src/doc/empty_line_after.rs +++ /dev/null @@ -1,345 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanRangeExt, snippet_indent}; -use clippy_utils::tokenize_with_text; -use itertools::Itertools; -use rustc_ast::AttrStyle; -use rustc_ast::token::CommentKind; -use rustc_errors::{Applicability, Diag, SuggestionStyle}; -use rustc_hir::{AttrKind, Attribute, ItemKind, Node}; -use rustc_lexer::TokenKind; -use rustc_lint::LateContext; -use rustc_span::{BytePos, ExpnKind, InnerSpan, Span, SpanData}; - -use super::{EMPTY_LINE_AFTER_DOC_COMMENTS, EMPTY_LINE_AFTER_OUTER_ATTR}; - -#[derive(Debug, PartialEq, Clone, Copy)] -enum StopKind { - Attr, - Doc(CommentKind), -} - -impl StopKind { - fn is_doc(self) -> bool { - matches!(self, StopKind::Doc(_)) - } -} - -#[derive(Debug)] -struct Stop { - span: Span, - kind: StopKind, - first: usize, - last: usize, -} - -impl Stop { - fn convert_to_inner(&self) -> (Span, String) { - let inner = match self.kind { - // #|[...] - StopKind::Attr => InnerSpan::new(1, 1), - // /// or /** - // ^ ^ - StopKind::Doc(_) => InnerSpan::new(2, 3), - }; - (self.span.from_inner(inner), "!".into()) - } - - fn comment_out(&self, cx: &LateContext<'_>, suggestions: &mut Vec<(Span, String)>) { - match self.kind { - StopKind::Attr => { - if cx.tcx.sess.source_map().is_multiline(self.span) { - suggestions.extend([ - (self.span.shrink_to_lo(), "/* ".into()), - (self.span.shrink_to_hi(), " */".into()), - ]); - } else { - suggestions.push((self.span.shrink_to_lo(), "// ".into())); - } - }, - StopKind::Doc(CommentKind::Line) => suggestions.push((self.span.shrink_to_lo(), "// ".into())), - StopKind::Doc(CommentKind::Block) => { - // /** outer */ /*! inner */ - // ^ ^ - let asterisk = self.span.from_inner(InnerSpan::new(1, 2)); - suggestions.push((asterisk, String::new())); - }, - } - } - - fn from_attr(cx: &LateContext<'_>, attr: &Attribute) -> Option { - let SpanData { lo, hi, .. } = attr.span.data(); - let file = cx.tcx.sess.source_map().lookup_source_file(lo); - - Some(Self { - span: attr.span, - kind: match attr.kind { - AttrKind::Normal(_) => StopKind::Attr, - AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), - }, - first: file.lookup_line(file.relative_position(lo))?, - last: file.lookup_line(file.relative_position(hi))?, - }) - } -} - -/// Represents a set of attrs/doc comments separated by 1 or more empty lines -/// -/// ```ignore -/// /// chunk 1 docs -/// // not an empty line so also part of chunk 1 -/// #[chunk_1_attrs] // <-- prev_stop -/// -/// /* gap */ -/// -/// /// chunk 2 docs // <-- next_stop -/// #[chunk_2_attrs] -/// ``` -struct Gap<'a> { - /// The span of individual empty lines including the newline at the end of the line - empty_lines: Vec, - has_comment: bool, - next_stop: &'a Stop, - prev_stop: &'a Stop, - /// The chunk that includes [`prev_stop`](Self::prev_stop) - prev_chunk: &'a [Stop], -} - -impl<'a> Gap<'a> { - fn new(cx: &LateContext<'_>, prev_chunk: &'a [Stop], next_chunk: &'a [Stop]) -> Option { - let prev_stop = prev_chunk.last()?; - let next_stop = next_chunk.first()?; - let gap_span = prev_stop.span.between(next_stop.span); - let gap_snippet = gap_span.get_source_text(cx)?; - - let mut has_comment = false; - let mut empty_lines = Vec::new(); - - for (token, source, inner_span) in tokenize_with_text(&gap_snippet) { - match token { - TokenKind::BlockComment { - doc_style: None, - terminated: true, - } - | TokenKind::LineComment { doc_style: None } => has_comment = true, - TokenKind::Whitespace => { - let newlines = source.bytes().positions(|b| b == b'\n'); - empty_lines.extend( - newlines - .tuple_windows() - .map(|(a, b)| InnerSpan::new(inner_span.start + a + 1, inner_span.start + b)) - .map(|inner_span| gap_span.from_inner(inner_span)), - ); - }, - // Ignore cfg_attr'd out attributes as they may contain empty lines, could also be from macro - // shenanigans - _ => return None, - } - } - - (!empty_lines.is_empty()).then_some(Self { - empty_lines, - has_comment, - next_stop, - prev_stop, - prev_chunk, - }) - } - - fn contiguous_empty_lines(&self) -> impl Iterator + '_ { - self.empty_lines - // The `+ BytePos(1)` means "next line", because each empty line span is "N:1-N:1". - .chunk_by(|a, b| a.hi() + BytePos(1) == b.lo()) - .map(|chunk| { - let first = chunk.first().expect("at least one empty line"); - let last = chunk.last().expect("at least one empty line"); - // The BytePos subtraction here is safe, as before an empty line, there must be at least one - // attribute/comment. The span needs to start at the end of the previous line. - first.with_lo(first.lo() - BytePos(1)).with_hi(last.hi()) - }) - } -} - -/// If the node the attributes/docs apply to is the first in the module/crate suggest converting -/// them to inner attributes/docs -fn suggest_inner(cx: &LateContext<'_>, diag: &mut Diag<'_, ()>, kind: StopKind, gaps: &[Gap<'_>]) { - let Some(owner) = cx.last_node_with_lint_attrs.as_owner() else { - return; - }; - let parent_desc = match cx.tcx.parent_hir_node(owner.into()) { - Node::Item(item) - if let ItemKind::Mod(parent_mod) = item.kind - && let [first, ..] = parent_mod.item_ids - && first.owner_id == owner => - { - "parent module" - }, - Node::Crate(crate_mod) - if let Some(first) = crate_mod - .item_ids - .iter() - .map(|&id| cx.tcx.hir().item(id)) - // skip prelude imports - .find(|item| !matches!(item.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) - && first.owner_id == owner => - { - "crate" - }, - _ => return, - }; - - diag.multipart_suggestion_verbose( - match kind { - StopKind::Attr => format!("if the attribute should apply to the {parent_desc} use an inner attribute"), - StopKind::Doc(_) => format!("if the comment should document the {parent_desc} use an inner doc comment"), - }, - gaps.iter() - .flat_map(|gap| gap.prev_chunk) - .map(Stop::convert_to_inner) - .collect(), - Applicability::MaybeIncorrect, - ); -} - -fn check_gaps(cx: &LateContext<'_>, gaps: &[Gap<'_>]) -> bool { - let Some(first_gap) = gaps.first() else { - return false; - }; - let empty_lines = || gaps.iter().flat_map(|gap| gap.empty_lines.iter().copied()); - let contiguous_empty_lines = || gaps.iter().flat_map(Gap::contiguous_empty_lines); - let mut has_comment = false; - let mut has_attr = false; - for gap in gaps { - has_comment |= gap.has_comment; - if !has_attr { - has_attr = gap.prev_chunk.iter().any(|stop| stop.kind == StopKind::Attr); - } - } - let kind = first_gap.prev_stop.kind; - let (lint, kind_desc) = match kind { - StopKind::Attr => (EMPTY_LINE_AFTER_OUTER_ATTR, "outer attribute"), - StopKind::Doc(_) => (EMPTY_LINE_AFTER_DOC_COMMENTS, "doc comment"), - }; - let (lines, are, them) = if empty_lines().nth(1).is_some() { - ("lines", "are", "them") - } else { - ("line", "is", "it") - }; - span_lint_and_then( - cx, - lint, - first_gap.prev_stop.span.to(empty_lines().last().unwrap()), - format!("empty {lines} after {kind_desc}"), - |diag| { - if let Some(owner) = cx.last_node_with_lint_attrs.as_owner() { - let def_id = owner.to_def_id(); - let def_descr = cx.tcx.def_descr(def_id); - diag.span_label( - cx.tcx.def_span(def_id), - match kind { - StopKind::Attr => format!("the attribute applies to this {def_descr}"), - StopKind::Doc(_) => format!("the comment documents this {def_descr}"), - }, - ); - } - - diag.multipart_suggestion_with_style( - format!("if the empty {lines} {are} unintentional remove {them}"), - contiguous_empty_lines() - .map(|empty_lines| (empty_lines, String::new())) - .collect(), - Applicability::MaybeIncorrect, - SuggestionStyle::HideCodeAlways, - ); - - if has_comment && kind.is_doc() { - // Likely doc comments that applied to some now commented out code - // - // /// Old docs for Foo - // // struct Foo; - - let mut suggestions = Vec::new(); - for stop in gaps.iter().flat_map(|gap| gap.prev_chunk) { - stop.comment_out(cx, &mut suggestions); - } - let name = match cx.tcx.hir().opt_name(cx.last_node_with_lint_attrs) { - Some(name) => format!("`{name}`"), - None => "this".into(), - }; - diag.multipart_suggestion_verbose( - format!("if the doc comment should not document {name} comment it out"), - suggestions, - Applicability::MaybeIncorrect, - ); - } else { - suggest_inner(cx, diag, kind, gaps); - } - - if kind == StopKind::Doc(CommentKind::Line) - && gaps - .iter() - .all(|gap| !gap.has_comment && gap.next_stop.kind == StopKind::Doc(CommentKind::Line)) - { - // Commentless empty gaps between line doc comments, possibly intended to be part of the markdown - - let indent = snippet_indent(cx, first_gap.prev_stop.span).unwrap_or_default(); - diag.multipart_suggestion_verbose( - format!("if the documentation should include the empty {lines} include {them} in the comment"), - empty_lines() - .map(|empty_line| (empty_line, format!("{indent}///"))) - .collect(), - Applicability::MaybeIncorrect, - ); - } - }, - ); - kind.is_doc() -} - -/// Returns `true` if [`EMPTY_LINE_AFTER_DOC_COMMENTS`] triggered, used to skip other doc comment -/// lints where they would be confusing -/// -/// [`EMPTY_LINE_AFTER_OUTER_ATTR`] is also here to share an implementation but does not return -/// `true` if it triggers -pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) -> bool { - let mut outer = attrs - .iter() - .filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion()) - .map(|attr| Stop::from_attr(cx, attr)) - .collect::>>() - .unwrap_or_default(); - - if outer.is_empty() { - return false; - } - - // Push a fake attribute Stop for the item itself so we check for gaps between the last outer - // attr/doc comment and the item they apply to - let span = cx.tcx.hir().span(cx.last_node_with_lint_attrs); - if !span.from_expansion() - && let Ok(line) = cx.tcx.sess.source_map().lookup_line(span.lo()) - { - outer.push(Stop { - span, - kind: StopKind::Attr, - first: line.line, - // last doesn't need to be accurate here, we don't compare it with anything - last: line.line, - }); - } - - let mut gaps = Vec::new(); - let mut last = 0; - for pos in outer - .array_windows() - .positions(|[a, b]| b.first.saturating_sub(a.last) > 1) - { - // we want to be after the first stop in the window - let pos = pos + 1; - if let Some(gap) = Gap::new(cx, &outer[last..pos], &outer[pos..]) { - last = pos; - gaps.push(gap); - } - } - - check_gaps(cx, &gaps) -} diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 3d8ce7becdbd..42e1f7fd950d 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -33,7 +33,6 @@ use rustc_span::{Span, sym}; use std::ops::Range; use url::Url; -mod empty_line_after; mod include_in_doc_without_cfg; mod link_with_quotes; mod markdown; @@ -491,82 +490,6 @@ declare_clippy_lint! { "ensure the first documentation paragraph is short" } -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after outer attributes - /// - /// ### Why is this bad? - /// The attribute may have meant to be an inner attribute (`#![attr]`). If - /// it was meant to be an outer attribute (`#[attr]`) then the empty line - /// should be removed - /// - /// ### Example - /// ```no_run - /// #[allow(dead_code)] - /// - /// fn not_quite_good_code() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// // Good (as inner attribute) - /// #![allow(dead_code)] - /// - /// fn this_is_fine() {} - /// - /// // or - /// - /// // Good (as outer attribute) - /// #[allow(dead_code)] - /// fn this_is_fine_too() {} - /// ``` - #[clippy::version = "pre 1.29.0"] - pub EMPTY_LINE_AFTER_OUTER_ATTR, - suspicious, - "empty line after outer attribute" -} - -declare_clippy_lint! { - /// ### What it does - /// Checks for empty lines after doc comments. - /// - /// ### Why is this bad? - /// The doc comment may have meant to be an inner doc comment, regular - /// comment or applied to some old code that is now commented out. If it was - /// intended to be a doc comment, then the empty line should be removed. - /// - /// ### Example - /// ```no_run - /// /// Some doc comment with a blank line after it. - /// - /// fn f() {} - /// - /// /// Docs for `old_code` - /// // fn old_code() {} - /// - /// fn new_code() {} - /// ``` - /// - /// Use instead: - /// ```no_run - /// //! Convert it to an inner doc comment - /// - /// // Or a regular comment - /// - /// /// Or remove the empty line - /// fn f() {} - /// - /// // /// Docs for `old_code` - /// // fn old_code() {} - /// - /// fn new_code() {} - /// ``` - #[clippy::version = "1.70.0"] - pub EMPTY_LINE_AFTER_DOC_COMMENTS, - suspicious, - "empty line after doc comments" -} - declare_clippy_lint! { /// ### What it does /// Checks if included files in doc comments are included only for `cfg(doc)`. @@ -650,8 +573,6 @@ impl_lint_pass!(Documentation => [ EMPTY_DOCS, DOC_LAZY_CONTINUATION, DOC_OVERINDENTED_LIST_ITEMS, - EMPTY_LINE_AFTER_OUTER_ATTR, - EMPTY_LINE_AFTER_DOC_COMMENTS, TOO_LONG_FIRST_DOC_PARAGRAPH, DOC_INCLUDE_WITHOUT_CFG, ]); @@ -784,7 +705,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ } include_in_doc_without_cfg::check(cx, attrs); - if suspicious_doc_comments::check(cx, attrs) || empty_line_after::check(cx, attrs) || is_doc_hidden(attrs) { + if suspicious_doc_comments::check(cx, attrs) || is_doc_hidden(attrs) { return None; } diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs new file mode 100644 index 000000000000..7e0a2690d54e --- /dev/null +++ b/clippy_lints/src/empty_line_after.rs @@ -0,0 +1,453 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::{SpanRangeExt, snippet_indent}; +use clippy_utils::tokenize_with_text; +use itertools::Itertools; +use rustc_ast::token::CommentKind; +use rustc_ast::{AttrKind, AttrStyle, Attribute, Crate, Item, ItemKind, ModKind, NodeId}; +use rustc_errors::{Applicability, Diag, SuggestionStyle}; +use rustc_lexer::TokenKind; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_session::impl_lint_pass; +use rustc_span::symbol::kw; +use rustc_span::{BytePos, ExpnKind, InnerSpan, Span, SpanData, Symbol}; + +declare_clippy_lint! { + /// ### What it does + /// Checks for empty lines after outer attributes + /// + /// ### Why is this bad? + /// The attribute may have meant to be an inner attribute (`#![attr]`). If + /// it was meant to be an outer attribute (`#[attr]`) then the empty line + /// should be removed + /// + /// ### Example + /// ```no_run + /// #[allow(dead_code)] + /// + /// fn not_quite_good_code() {} + /// ``` + /// + /// Use instead: + /// ```no_run + /// // Good (as inner attribute) + /// #![allow(dead_code)] + /// + /// fn this_is_fine() {} + /// + /// // or + /// + /// // Good (as outer attribute) + /// #[allow(dead_code)] + /// fn this_is_fine_too() {} + /// ``` + #[clippy::version = "pre 1.29.0"] + pub EMPTY_LINE_AFTER_OUTER_ATTR, + suspicious, + "empty line after outer attribute" +} + +declare_clippy_lint! { + /// ### What it does + /// Checks for empty lines after doc comments. + /// + /// ### Why is this bad? + /// The doc comment may have meant to be an inner doc comment, regular + /// comment or applied to some old code that is now commented out. If it was + /// intended to be a doc comment, then the empty line should be removed. + /// + /// ### Example + /// ```no_run + /// /// Some doc comment with a blank line after it. + /// + /// fn f() {} + /// + /// /// Docs for `old_code` + /// // fn old_code() {} + /// + /// fn new_code() {} + /// ``` + /// + /// Use instead: + /// ```no_run + /// //! Convert it to an inner doc comment + /// + /// // Or a regular comment + /// + /// /// Or remove the empty line + /// fn f() {} + /// + /// // /// Docs for `old_code` + /// // fn old_code() {} + /// + /// fn new_code() {} + /// ``` + #[clippy::version = "1.70.0"] + pub EMPTY_LINE_AFTER_DOC_COMMENTS, + suspicious, + "empty line after doc comments" +} + +#[derive(Debug)] +struct ItemInfo { + kind: &'static str, + name: Symbol, + span: Span, + mod_items: Vec, +} + +pub struct EmptyLineAfter { + items: Vec, +} + +impl_lint_pass!(EmptyLineAfter => [ + EMPTY_LINE_AFTER_OUTER_ATTR, + EMPTY_LINE_AFTER_DOC_COMMENTS, +]); + +impl EmptyLineAfter { + pub fn new() -> Self { + Self { items: Vec::new() } + } +} + +#[derive(Debug, PartialEq, Clone, Copy)] +enum StopKind { + Attr, + Doc(CommentKind), +} + +impl StopKind { + fn is_doc(self) -> bool { + matches!(self, StopKind::Doc(_)) + } +} + +#[derive(Debug)] +struct Stop { + span: Span, + kind: StopKind, + first: usize, + last: usize, +} + +impl Stop { + fn convert_to_inner(&self) -> (Span, String) { + let inner = match self.kind { + // #|[...] + StopKind::Attr => InnerSpan::new(1, 1), + // /// or /** + // ^ ^ + StopKind::Doc(_) => InnerSpan::new(2, 3), + }; + (self.span.from_inner(inner), "!".into()) + } + + fn comment_out(&self, cx: &EarlyContext<'_>, suggestions: &mut Vec<(Span, String)>) { + match self.kind { + StopKind::Attr => { + if cx.sess().source_map().is_multiline(self.span) { + suggestions.extend([ + (self.span.shrink_to_lo(), "/* ".into()), + (self.span.shrink_to_hi(), " */".into()), + ]); + } else { + suggestions.push((self.span.shrink_to_lo(), "// ".into())); + } + }, + StopKind::Doc(CommentKind::Line) => suggestions.push((self.span.shrink_to_lo(), "// ".into())), + StopKind::Doc(CommentKind::Block) => { + // /** outer */ /*! inner */ + // ^ ^ + let asterisk = self.span.from_inner(InnerSpan::new(1, 2)); + suggestions.push((asterisk, String::new())); + }, + } + } + + fn from_attr(cx: &EarlyContext<'_>, attr: &Attribute) -> Option { + let SpanData { lo, hi, .. } = attr.span.data(); + let file = cx.sess().source_map().lookup_source_file(lo); + + Some(Self { + span: attr.span, + kind: match attr.kind { + AttrKind::Normal(_) => StopKind::Attr, + AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), + }, + first: file.lookup_line(file.relative_position(lo))?, + last: file.lookup_line(file.relative_position(hi))?, + }) + } +} + +/// Represents a set of attrs/doc comments separated by 1 or more empty lines +/// +/// ```ignore +/// /// chunk 1 docs +/// // not an empty line so also part of chunk 1 +/// #[chunk_1_attrs] // <-- prev_stop +/// +/// /* gap */ +/// +/// /// chunk 2 docs // <-- next_stop +/// #[chunk_2_attrs] +/// ``` +struct Gap<'a> { + /// The span of individual empty lines including the newline at the end of the line + empty_lines: Vec, + has_comment: bool, + next_stop: &'a Stop, + prev_stop: &'a Stop, + /// The chunk that includes [`prev_stop`](Self::prev_stop) + prev_chunk: &'a [Stop], +} + +impl<'a> Gap<'a> { + fn new(cx: &EarlyContext<'_>, prev_chunk: &'a [Stop], next_chunk: &'a [Stop]) -> Option { + let prev_stop = prev_chunk.last()?; + let next_stop = next_chunk.first()?; + let gap_span = prev_stop.span.between(next_stop.span); + let gap_snippet = gap_span.get_source_text(cx)?; + + let mut has_comment = false; + let mut empty_lines = Vec::new(); + + for (token, source, inner_span) in tokenize_with_text(&gap_snippet) { + match token { + TokenKind::BlockComment { + doc_style: None, + terminated: true, + } + | TokenKind::LineComment { doc_style: None } => has_comment = true, + TokenKind::Whitespace => { + let newlines = source.bytes().positions(|b| b == b'\n'); + empty_lines.extend( + newlines + .tuple_windows() + .map(|(a, b)| InnerSpan::new(inner_span.start + a + 1, inner_span.start + b)) + .map(|inner_span| gap_span.from_inner(inner_span)), + ); + }, + // Ignore cfg_attr'd out attributes as they may contain empty lines, could also be from macro + // shenanigans + _ => return None, + } + } + + (!empty_lines.is_empty()).then_some(Self { + empty_lines, + has_comment, + next_stop, + prev_stop, + prev_chunk, + }) + } + + fn contiguous_empty_lines(&self) -> impl Iterator + '_ { + self.empty_lines + // The `+ BytePos(1)` means "next line", because each empty line span is "N:1-N:1". + .chunk_by(|a, b| a.hi() + BytePos(1) == b.lo()) + .map(|chunk| { + let first = chunk.first().expect("at least one empty line"); + let last = chunk.last().expect("at least one empty line"); + // The BytePos subtraction here is safe, as before an empty line, there must be at least one + // attribute/comment. The span needs to start at the end of the previous line. + first.with_lo(first.lo() - BytePos(1)).with_hi(last.hi()) + }) + } +} + +impl EmptyLineAfter { + fn check_gaps(&self, cx: &EarlyContext<'_>, gaps: &[Gap<'_>], id: NodeId) { + let Some(first_gap) = gaps.first() else { + return; + }; + let empty_lines = || gaps.iter().flat_map(|gap| gap.empty_lines.iter().copied()); + let contiguous_empty_lines = || gaps.iter().flat_map(Gap::contiguous_empty_lines); + let mut has_comment = false; + let mut has_attr = false; + for gap in gaps { + has_comment |= gap.has_comment; + if !has_attr { + has_attr = gap.prev_chunk.iter().any(|stop| stop.kind == StopKind::Attr); + } + } + let kind = first_gap.prev_stop.kind; + let (lint, kind_desc) = match kind { + StopKind::Attr => (EMPTY_LINE_AFTER_OUTER_ATTR, "outer attribute"), + StopKind::Doc(_) => (EMPTY_LINE_AFTER_DOC_COMMENTS, "doc comment"), + }; + let (lines, are, them) = if empty_lines().nth(1).is_some() { + ("lines", "are", "them") + } else { + ("line", "is", "it") + }; + span_lint_and_then( + cx, + lint, + first_gap.prev_stop.span.to(empty_lines().last().unwrap()), + format!("empty {lines} after {kind_desc}"), + |diag| { + let info = self.items.last().unwrap(); + diag.span_label(info.span, match kind { + StopKind::Attr => format!("the attribute applies to this {}", info.kind), + StopKind::Doc(_) => format!("the comment documents this {}", info.kind), + }); + + diag.multipart_suggestion_with_style( + format!("if the empty {lines} {are} unintentional remove {them}"), + contiguous_empty_lines() + .map(|empty_lines| (empty_lines, String::new())) + .collect(), + Applicability::MaybeIncorrect, + SuggestionStyle::HideCodeAlways, + ); + + if has_comment && kind.is_doc() { + // Likely doc comments that applied to some now commented out code + // + // /// Old docs for Foo + // // struct Foo; + + let mut suggestions = Vec::new(); + for stop in gaps.iter().flat_map(|gap| gap.prev_chunk) { + stop.comment_out(cx, &mut suggestions); + } + diag.multipart_suggestion_verbose( + format!("if the doc comment should not document `{}` comment it out", info.name), + suggestions, + Applicability::MaybeIncorrect, + ); + } else { + self.suggest_inner(diag, kind, gaps, id); + } + + if kind == StopKind::Doc(CommentKind::Line) + && gaps + .iter() + .all(|gap| !gap.has_comment && gap.next_stop.kind == StopKind::Doc(CommentKind::Line)) + { + // Commentless empty gaps between line doc comments, possibly intended to be part of the markdown + + let indent = snippet_indent(cx, first_gap.prev_stop.span).unwrap_or_default(); + diag.multipart_suggestion_verbose( + format!("if the documentation should include the empty {lines} include {them} in the comment"), + empty_lines() + .map(|empty_line| (empty_line, format!("{indent}///"))) + .collect(), + Applicability::MaybeIncorrect, + ); + } + }, + ); + } + + /// If the node the attributes/docs apply to is the first in the module/crate suggest converting + /// them to inner attributes/docs + fn suggest_inner(&self, diag: &mut Diag<'_, ()>, kind: StopKind, gaps: &[Gap<'_>], id: NodeId) { + if let Some(parent) = self.items.iter().rev().nth(1) + && (parent.kind == "module" || parent.kind == "crate") + && parent.mod_items.first() == Some(&id) + { + let desc = if parent.kind == "module" { + "parent module" + } else { + parent.kind + }; + diag.multipart_suggestion_verbose( + match kind { + StopKind::Attr => format!("if the attribute should apply to the {desc} use an inner attribute"), + StopKind::Doc(_) => format!("if the comment should document the {desc} use an inner doc comment"), + }, + gaps.iter() + .flat_map(|gap| gap.prev_chunk) + .map(Stop::convert_to_inner) + .collect(), + Applicability::MaybeIncorrect, + ); + } + } +} + +impl EarlyLintPass for EmptyLineAfter { + fn check_crate(&mut self, _: &EarlyContext<'_>, krate: &Crate) { + self.items.push(ItemInfo { + kind: "crate", + name: kw::Crate, + span: krate.spans.inner_span.with_hi(krate.spans.inner_span.lo()), + mod_items: krate + .items + .iter() + .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) + .map(|i| i.id) + .collect::>(), + }); + } + + fn check_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.items.push(ItemInfo { + kind: item.kind.descr(), + name: item.ident.name, + span: if item.span.contains(item.ident.span) { + item.span.with_hi(item.ident.span.hi()) + } else { + item.span.with_hi(item.span.lo()) + }, + mod_items: match item.kind { + ItemKind::Mod(_, ModKind::Loaded(ref items, _, _, _)) => items + .iter() + .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) + .map(|i| i.id) + .collect::>(), + _ => Vec::new(), + }, + }); + + let mut outer = item + .attrs + .iter() + .filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion()) + .map(|attr| Stop::from_attr(cx, attr)) + .collect::>>() + .unwrap_or_default(); + + if outer.is_empty() { + return; + } + + // Push a fake attribute Stop for the item itself so we check for gaps between the last outer + // attr/doc comment and the item they apply to + let span = self.items.last().unwrap().span; + if !span.from_expansion() + && let Ok(line) = cx.sess().source_map().lookup_line(span.lo()) + { + outer.push(Stop { + span, + kind: StopKind::Attr, + first: line.line, + // last doesn't need to be accurate here, we don't compare it with anything + last: line.line, + }); + } + + let mut gaps = Vec::new(); + let mut last = 0; + for pos in outer + .array_windows() + .positions(|[a, b]| b.first.saturating_sub(a.last) > 1) + { + // we want to be after the first stop in the window + let pos = pos + 1; + if let Some(gap) = Gap::new(cx, &outer[last..pos], &outer[pos..]) { + last = pos; + gaps.push(gap); + } + } + + self.check_gaps(cx, &gaps, item.id); + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 8887ab7ec0d7..13218331a67b 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -126,6 +126,7 @@ mod duplicate_mod; mod else_if_without_else; mod empty_drop; mod empty_enum; +mod empty_line_after; mod empty_with_brackets; mod endian_bytes; mod entry; @@ -973,6 +974,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(unused_trait_names::UnusedTraitNames::new(conf))); store.register_late_pass(|_| Box::new(manual_ignore_case_cmp::ManualIgnoreCaseCmp)); store.register_late_pass(|_| Box::new(unnecessary_literal_bound::UnnecessaryLiteralBound)); + store.register_early_pass(|| Box::new(empty_line_after::EmptyLineAfter::new())); store.register_late_pass(move |_| Box::new(arbitrary_source_item_ordering::ArbitrarySourceItemOrdering::new(conf))); store.register_late_pass(|_| Box::new(unneeded_struct_pattern::UnneededStructPattern)); store.register_late_pass(|_| Box::::default()); From 42453bd73a39ef96727774159d300f0a27aec73d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Feb 2025 21:28:44 +0100 Subject: [PATCH 050/161] Update UI tests --- clippy_lints/src/empty_line_after.rs | 2 +- tests/ui/empty_line_after/doc_comments.stderr | 18 +++++++++--------- .../ui/empty_line_after/outer_attribute.stderr | 12 ++++++------ tests/ui/suspicious_doc_comments.fixed | 1 + tests/ui/suspicious_doc_comments.rs | 1 + tests/ui/suspicious_doc_comments.stderr | 18 +++++++++--------- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index 7e0a2690d54e..4f1c6186cfe8 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -133,7 +133,7 @@ struct Stop { impl Stop { fn convert_to_inner(&self) -> (Span, String) { let inner = match self.kind { - // #|[...] + // #![...] StopKind::Attr => InnerSpan::new(1, 1), // /// or /** // ^ ^ diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index c5d5f3d37594..d71c888e1966 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -5,7 +5,7 @@ LL | / /// for the crate LL | | | |_^ LL | fn first_in_crate() {} - | ------------------- the comment documents this function + | ----------------- the comment documents this function | = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` @@ -24,7 +24,7 @@ LL | / /// for the module LL | | | |_^ LL | fn first_in_module() {} - | -------------------- the comment documents this function + | ------------------ the comment documents this function | = help: if the empty line is unintentional remove it help: if the comment should document the parent module use an inner doc comment @@ -42,7 +42,7 @@ LL | | | |_^ LL | /// Blank line LL | fn indented() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | = help: if the empty line is unintentional remove it help: if the documentation should include the empty line include it in the comment @@ -57,7 +57,7 @@ LL | / /// This should produce a warning LL | | | |_^ LL | fn with_doc_and_newline() {} - | ------------------------- the comment documents this function + | ----------------------- the comment documents this function | = help: if the empty line is unintentional remove it @@ -72,7 +72,7 @@ LL | | | |_^ ... LL | fn three_attributes() {} - | --------------------- the comment documents this function + | ------------------- the comment documents this function | = help: if the empty lines are unintentional remove them @@ -84,7 +84,7 @@ LL | | // fn old_code() {} LL | | | |_^ LL | fn new_code() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | = help: if the empty line is unintentional remove it help: if the doc comment should not document `new_code` comment it out @@ -126,7 +126,7 @@ LL | | */ LL | | | |_^ LL | fn first_in_module() {} - | -------------------- the comment documents this function + | ------------------ the comment documents this function | = help: if the empty line is unintentional remove it help: if the comment should document the parent module use an inner doc comment @@ -145,7 +145,7 @@ LL | | | |_^ ... LL | fn new_code() {} - | ------------- the comment documents this function + | ----------- the comment documents this function | = help: if the empty line is unintentional remove it help: if the doc comment should not document `new_code` comment it out @@ -163,7 +163,7 @@ LL | | | |_^ LL | /// Docs for `new_code2` LL | fn new_code2() {} - | -------------- the comment documents this function + | ------------ the comment documents this function | = help: if the empty line is unintentional remove it help: if the doc comment should not document `new_code2` comment it out diff --git a/tests/ui/empty_line_after/outer_attribute.stderr b/tests/ui/empty_line_after/outer_attribute.stderr index a95306e2fa33..b4c49d0b3166 100644 --- a/tests/ui/empty_line_after/outer_attribute.stderr +++ b/tests/ui/empty_line_after/outer_attribute.stderr @@ -5,7 +5,7 @@ LL | / #[crate_type = "lib"] LL | | | |_^ LL | fn first_in_crate() {} - | ------------------- the attribute applies to this function + | ----------------- the attribute applies to this function | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` @@ -23,7 +23,7 @@ LL | | | |_^ LL | /// some comment LL | fn with_one_newline_and_comment() {} - | --------------------------------- the attribute applies to this function + | ------------------------------- the attribute applies to this function | = help: if the empty line is unintentional remove it @@ -34,7 +34,7 @@ LL | / #[inline] LL | | | |_^ LL | fn with_one_newline() {} - | --------------------- the attribute applies to this function + | ------------------- the attribute applies to this function | = help: if the empty line is unintentional remove it @@ -46,7 +46,7 @@ LL | | LL | | | |_^ LL | fn with_two_newlines() {} - | ---------------------- the attribute applies to this function + | -------------------- the attribute applies to this function | = help: if the empty lines are unintentional remove them help: if the attribute should apply to the parent module use an inner attribute @@ -95,7 +95,7 @@ LL | | // Still lint cases where the empty line does not immediately follow the LL | | | |_^ LL | fn comment_before_empty_line() {} - | ------------------------------ the attribute applies to this function + | ---------------------------- the attribute applies to this function | = help: if the empty line is unintentional remove it @@ -107,7 +107,7 @@ LL | / #[allow(unused)] LL | | | |_^ LL | pub fn isolated_comment() {} - | ------------------------- the attribute applies to this function + | ----------------------- the attribute applies to this function | = help: if the empty lines are unintentional remove them diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 614fc03571e5..d3df6a41cb12 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -1,5 +1,6 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] +#![allow(clippy::empty_line_after_doc_comments)] //! Real module documentation. //! Fake module documentation. diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index 7dcba0fefc98..04db2b199c09 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -1,5 +1,6 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] +#![allow(clippy::empty_line_after_doc_comments)] //! Real module documentation. ///! Fake module documentation. diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index f12053b1595a..c34e39cd0fcb 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -1,5 +1,5 @@ error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:5:1 + --> tests/ui/suspicious_doc_comments.rs:6:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:9:5 + --> tests/ui/suspicious_doc_comments.rs:10:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:21:5 + --> tests/ui/suspicious_doc_comments.rs:22:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -36,7 +36,7 @@ LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:35:5 + --> tests/ui/suspicious_doc_comments.rs:36:5 | LL | / ///! This module LL | | ///! contains @@ -51,7 +51,7 @@ LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:43:5 + --> tests/ui/suspicious_doc_comments.rs:44:5 | LL | / ///! a LL | | ///! b @@ -64,7 +64,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:51:5 + --> tests/ui/suspicious_doc_comments.rs:52:5 | LL | ///! a | ^^^^^^ @@ -75,7 +75,7 @@ LL | //! a | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:57:5 + --> tests/ui/suspicious_doc_comments.rs:58:5 | LL | / ///! a LL | | @@ -90,7 +90,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:69:5 + --> tests/ui/suspicious_doc_comments.rs:70:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL | //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:76:5 + --> tests/ui/suspicious_doc_comments.rs:77:5 | LL | ///! Huh. | ^^^^^^^^^ From 4044c1aa496e39e4fc1ec34d646d84ea639253ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20D=C3=B6nszelmann?= Date: Thu, 6 Feb 2025 21:44:00 +0100 Subject: [PATCH 051/161] fix empty after lint on impl/trait items Co-authored-by: Guillaume Gomez --- clippy_lints/src/empty_line_after.rs | 113 ++++++++++++------ .../ui/empty_line_after/doc_comments.1.fixed | 9 ++ .../ui/empty_line_after/doc_comments.2.fixed | 9 ++ tests/ui/empty_line_after/doc_comments.rs | 10 ++ tests/ui/empty_line_after/doc_comments.stderr | 13 +- 5 files changed, 116 insertions(+), 38 deletions(-) diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index 4f1c6186cfe8..89ddd885b6e4 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -3,13 +3,13 @@ use clippy_utils::source::{SpanRangeExt, snippet_indent}; use clippy_utils::tokenize_with_text; use itertools::Itertools; use rustc_ast::token::CommentKind; -use rustc_ast::{AttrKind, AttrStyle, Attribute, Crate, Item, ItemKind, ModKind, NodeId}; +use rustc_ast::{AssocItemKind, AttrKind, AttrStyle, Attribute, Crate, Item, ItemKind, ModKind, NodeId}; use rustc_errors::{Applicability, Diag, SuggestionStyle}; use rustc_lexer::TokenKind; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::impl_lint_pass; use rustc_span::symbol::kw; -use rustc_span::{BytePos, ExpnKind, InnerSpan, Span, SpanData, Symbol}; +use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol}; declare_clippy_lint! { /// ### What it does @@ -92,7 +92,7 @@ struct ItemInfo { kind: &'static str, name: Symbol, span: Span, - mod_items: Vec, + mod_items: Option, } pub struct EmptyLineAfter { @@ -347,7 +347,7 @@ impl EmptyLineAfter { fn suggest_inner(&self, diag: &mut Diag<'_, ()>, kind: StopKind, gaps: &[Gap<'_>], id: NodeId) { if let Some(parent) = self.items.iter().rev().nth(1) && (parent.kind == "module" || parent.kind == "crate") - && parent.mod_items.first() == Some(&id) + && parent.mod_items == Some(id) { let desc = if parent.kind == "module" { "parent module" @@ -367,48 +367,35 @@ impl EmptyLineAfter { ); } } -} -impl EarlyLintPass for EmptyLineAfter { - fn check_crate(&mut self, _: &EarlyContext<'_>, krate: &Crate) { + fn check_item_kind( + &mut self, + cx: &EarlyContext<'_>, + kind: &ItemKind, + ident: &Ident, + span: Span, + attrs: &[Attribute], + id: NodeId, + ) { self.items.push(ItemInfo { - kind: "crate", - name: kw::Crate, - span: krate.spans.inner_span.with_hi(krate.spans.inner_span.lo()), - mod_items: krate - .items - .iter() - .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) - .map(|i| i.id) - .collect::>(), - }); - } - - fn check_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { - self.items.pop(); - } - - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { - self.items.push(ItemInfo { - kind: item.kind.descr(), - name: item.ident.name, - span: if item.span.contains(item.ident.span) { - item.span.with_hi(item.ident.span.hi()) + kind: kind.descr(), + name: ident.name, + span: if span.contains(ident.span) { + span.with_hi(ident.span.hi()) } else { - item.span.with_hi(item.span.lo()) + span.with_hi(span.lo()) }, - mod_items: match item.kind { - ItemKind::Mod(_, ModKind::Loaded(ref items, _, _, _)) => items + mod_items: match kind { + ItemKind::Mod(_, ModKind::Loaded(items, _, _, _)) => items .iter() .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) .map(|i| i.id) - .collect::>(), - _ => Vec::new(), + .next(), + _ => None, }, }); - let mut outer = item - .attrs + let mut outer = attrs .iter() .filter(|attr| attr.style == AttrStyle::Outer && !attr.span.from_expansion()) .map(|attr| Stop::from_attr(cx, attr)) @@ -448,6 +435,58 @@ impl EarlyLintPass for EmptyLineAfter { } } - self.check_gaps(cx, &gaps, item.id); + self.check_gaps(cx, &gaps, id); + } +} + +impl EarlyLintPass for EmptyLineAfter { + fn check_crate(&mut self, _: &EarlyContext<'_>, krate: &Crate) { + self.items.push(ItemInfo { + kind: "crate", + name: kw::Crate, + span: krate.spans.inner_span.with_hi(krate.spans.inner_span.lo()), + mod_items: krate + .items + .iter() + .filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_))) + .map(|i| i.id) + .next(), + }); + } + + fn check_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + fn check_impl_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + fn check_trait_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) { + self.items.pop(); + } + + fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind( + cx, + &item.kind.clone().into(), + &item.ident, + item.span, + &item.attrs, + item.id, + ); + } + + fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind( + cx, + &item.kind.clone().into(), + &item.ident, + item.span, + &item.attrs, + item.id, + ); + } + + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + self.check_item_kind(cx, &item.kind, &item.ident, item.span, &item.attrs, item.id); } } diff --git a/tests/ui/empty_line_after/doc_comments.1.fixed b/tests/ui/empty_line_after/doc_comments.1.fixed index fd6a94b6a80c..3772b465fdb2 100644 --- a/tests/ui/empty_line_after/doc_comments.1.fixed +++ b/tests/ui/empty_line_after/doc_comments.1.fixed @@ -132,4 +132,13 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + /// comment on assoc item + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.2.fixed b/tests/ui/empty_line_after/doc_comments.2.fixed index 7a57dcd92332..3028d03b6699 100644 --- a/tests/ui/empty_line_after/doc_comments.2.fixed +++ b/tests/ui/empty_line_after/doc_comments.2.fixed @@ -141,4 +141,13 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + /// comment on assoc item + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.rs b/tests/ui/empty_line_after/doc_comments.rs index 1da761a5c3d5..ae4ebc271fa1 100644 --- a/tests/ui/empty_line_after/doc_comments.rs +++ b/tests/ui/empty_line_after/doc_comments.rs @@ -144,4 +144,14 @@ pub struct BlockComment; ))] fn empty_line_in_cfg_attr() {} +trait Foo { + fn bar(); +} + +impl Foo for LineComment { + /// comment on assoc item + + fn bar() {} +} + fn main() {} diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index d71c888e1966..10189665f014 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -171,5 +171,16 @@ help: if the doc comment should not document `new_code2` comment it out LL | // /// Docs for `old_code2` | ++ -error: aborting due to 10 previous errors +error: empty line after doc comment + --> tests/ui/empty_line_after/doc_comments.rs:152:5 + | +LL | / /// comment on assoc item +LL | | + | |_^ +LL | fn bar() {} + | ------ the comment documents this function + | + = help: if the empty line is unintentional remove it + +error: aborting due to 11 previous errors From 8ebc52e0321053a3e7e4693ab7ba05b293871dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Fri, 7 Feb 2025 16:00:27 +0100 Subject: [PATCH 052/161] fix typo --- clippy_lints/src/empty_line_after.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index 89ddd885b6e4..578ff6e38a6a 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -295,7 +295,7 @@ impl EmptyLineAfter { }); diag.multipart_suggestion_with_style( - format!("if the empty {lines} {are} unintentional remove {them}"), + format!("if the empty {lines} {are} unintentional, remove {them}"), contiguous_empty_lines() .map(|empty_lines| (empty_lines, String::new())) .collect(), From 477be9470a6555c467ca63ba445bcdb25d74db01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Fri, 7 Feb 2025 16:42:20 +0100 Subject: [PATCH 053/161] add tests for spurious failure and fix typo --- tests/ui/doc/unbalanced_ticks.rs | 16 ++++++++++++++ tests/ui/doc/unbalanced_ticks.stderr | 14 +++++++++++- tests/ui/empty_line_after/doc_comments.stderr | 22 +++++++++---------- .../empty_line_after/outer_attribute.stderr | 18 +++++++-------- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 04446787b6c2..a065654e319d 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -66,3 +66,19 @@ fn escape_3() {} /// Backslashes ` \` within code blocks don't count. fn escape_4() {} + +trait Foo { + fn bar(); +} + +struct Bar; +impl Foo for Bar { + // NOTE: false positive + /// Returns an `Option` from a i64, assuming a 1-index, January = 1. + /// + /// `Month::from_i64(n: i64)`: | `1` | `2` | ... | `12` + /// ---------------------------| -------------------- | --------------------- | ... | ----- + /// ``: | Some(Month::January) | Some(Month::February) | ... | + /// Some(Month::December) + fn bar() {} +} diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 50324010e97f..c9fd25eb1a1c 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -94,5 +94,17 @@ LL | /// Escaped \` ` backticks don't count, but unescaped backticks do. | = help: a backtick may be missing a pair -error: aborting due to 10 previous errors +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:79:9 + | +LL | /// `Month::from_i64(n: i64)`: | `1` | `2` | ... | `12` + | _________^ +LL | | /// ---------------------------| -------------------- | --------------------- | ... | ----- +LL | | /// ``: | Some(Month::January) | Some(Month::February) | ... | +LL | | /// Some(Month::December) + | |_____________________________^ + | + = help: a backtick may be missing a pair + +error: aborting due to 11 previous errors diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index 10189665f014..7b197ae67e00 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -9,7 +9,7 @@ LL | fn first_in_crate() {} | = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the crate use an inner doc comment | LL ~ //! Meant to be an @@ -26,7 +26,7 @@ LL | | LL | fn first_in_module() {} | ------------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the parent module use an inner doc comment | LL ~ //! Meant to be an @@ -44,7 +44,7 @@ LL | /// Blank line LL | fn indented() {} | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the documentation should include the empty line include it in the comment | LL | /// @@ -59,7 +59,7 @@ LL | | LL | fn with_doc_and_newline() {} | ----------------------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after doc comment --> tests/ui/empty_line_after/doc_comments.rs:44:1 @@ -74,7 +74,7 @@ LL | | LL | fn three_attributes() {} | ------------------- the comment documents this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:56:5 @@ -86,7 +86,7 @@ LL | | LL | fn new_code() {} | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code` comment it out | LL | // /// docs for `old_code` @@ -106,7 +106,7 @@ LL | | LL | struct Multiple; | --------------- the comment documents this struct | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them help: if the doc comment should not document `Multiple` comment it out | LL ~ // /// Docs @@ -128,7 +128,7 @@ LL | | LL | fn first_in_module() {} | ------------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the comment should document the parent module use an inner doc comment | LL | /*! @@ -147,7 +147,7 @@ LL | | LL | fn new_code() {} | ----------- the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code` comment it out | LL - /** @@ -165,7 +165,7 @@ LL | /// Docs for `new_code2` LL | fn new_code2() {} | ------------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the doc comment should not document `new_code2` comment it out | LL | // /// Docs for `old_code2` @@ -180,7 +180,7 @@ LL | | LL | fn bar() {} | ------ the comment documents this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: aborting due to 11 previous errors diff --git a/tests/ui/empty_line_after/outer_attribute.stderr b/tests/ui/empty_line_after/outer_attribute.stderr index b4c49d0b3166..519ba6e67615 100644 --- a/tests/ui/empty_line_after/outer_attribute.stderr +++ b/tests/ui/empty_line_after/outer_attribute.stderr @@ -9,7 +9,7 @@ LL | fn first_in_crate() {} | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it help: if the attribute should apply to the crate use an inner attribute | LL | #![crate_type = "lib"] @@ -25,7 +25,7 @@ LL | /// some comment LL | fn with_one_newline_and_comment() {} | ------------------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:23:1 @@ -36,7 +36,7 @@ LL | | LL | fn with_one_newline() {} | ------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:30:5 @@ -48,7 +48,7 @@ LL | | LL | fn with_two_newlines() {} | -------------------- the attribute applies to this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them help: if the attribute should apply to the parent module use an inner attribute | LL | #![crate_type = "lib"] @@ -63,7 +63,7 @@ LL | | LL | enum Baz { | -------- the attribute applies to this enum | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:45:1 @@ -74,7 +74,7 @@ LL | | LL | struct Foo { | ---------- the attribute applies to this struct | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:53:1 @@ -85,7 +85,7 @@ LL | | LL | mod foo {} | ------- the attribute applies to this module | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty line after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:58:1 @@ -97,7 +97,7 @@ LL | | LL | fn comment_before_empty_line() {} | ---------------------------- the attribute applies to this function | - = help: if the empty line is unintentional remove it + = help: if the empty line is unintentional, remove it error: empty lines after outer attribute --> tests/ui/empty_line_after/outer_attribute.rs:64:1 @@ -109,7 +109,7 @@ LL | | LL | pub fn isolated_comment() {} | ----------------------- the attribute applies to this function | - = help: if the empty lines are unintentional remove them + = help: if the empty lines are unintentional, remove them error: aborting due to 9 previous errors From b18bb0a48347e5d98c30027ebbdee010a8fee48c Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 4 Feb 2025 22:20:45 -0800 Subject: [PATCH 054/161] clippy: directly use rustc_abi instead of reexports --- clippy_lints/src/casts/cast_possible_truncation.rs | 2 +- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 4 ++-- clippy_lints/src/excessive_bools.rs | 6 +++--- clippy_lints/src/functions/too_many_arguments.rs | 8 ++++---- clippy_lints/src/inherent_to_string.rs | 4 ++-- clippy_lints/src/large_futures.rs | 2 +- clippy_lints/src/methods/mod.rs | 3 ++- clippy_lints/src/missing_const_for_fn.rs | 9 +++++---- clippy_lints/src/needless_pass_by_ref_mut.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/no_mangle_with_rust_abi.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 6 +++--- clippy_lints/src/types/type_complexity.rs | 4 ++-- clippy_utils/src/check_proc_macro.rs | 6 +++--- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/ty/mod.rs | 2 +- 20 files changed, 43 insertions(+), 41 deletions(-) diff --git a/clippy_lints/src/casts/cast_possible_truncation.rs b/clippy_lints/src/casts/cast_possible_truncation.rs index 48e9f1d690ee..ca973f4bb1aa 100644 --- a/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/clippy_lints/src/casts/cast_possible_truncation.rs @@ -4,13 +4,13 @@ use clippy_utils::expr_or_init; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; +use rustc_abi::IntegerType; use rustc_errors::{Applicability, Diag}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, FloatTy, Ty}; use rustc_span::Span; -use rustc_target::abi::IntegerType; use super::{CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION, utils}; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index a89f0d9c4327..c55d4387d696 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -10,7 +10,7 @@ use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; pub struct BoxedLocal { too_large_for_stack: u64, @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { fn_def_id: LocalDefId, ) { if let Some(header) = fn_kind.header() { - if header.abi != Abi::Rust { + if header.abi != ExternAbi::Rust { return; } } diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index f90bf9157aad..ae3acc1c4b19 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -15,7 +15,7 @@ use rustc_middle::ty::{ }; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _; declare_clippy_lint! { @@ -172,7 +172,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx && let output = typeck.expr_ty(body.value) && let ty::Tuple(tys) = *subs.type_at(1).kind() { - cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust) + cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, ExternAbi::Rust) } else { return; } diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 0011da03dda7..15afe3e8c145 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -145,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitItem<'tcx>) { // functions with a body are already checked by `check_fn` if let TraitItemKind::Fn(fn_sig, TraitFn::Required(_)) = &trait_item.kind - && fn_sig.header.abi == Abi::Rust + && fn_sig.header.abi == ExternAbi::Rust && fn_sig.decl.inputs.len() as u64 > self.max_fn_params_bools { check_fn_decl(cx, fn_sig.decl, fn_sig.span, self.max_fn_params_bools); @@ -162,7 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools { def_id: LocalDefId, ) { if let Some(fn_header) = fn_kind.header() - && fn_header.abi == Abi::Rust + && fn_header.abi == ExternAbi::Rust && fn_decl.inputs.len() as u64 > self.max_fn_params_bools && get_parent_as_impl(cx.tcx, cx.tcx.local_def_id_to_hir_id(def_id)) .is_none_or(|impl_item| impl_item.of_trait.is_none()) diff --git a/clippy_lints/src/functions/too_many_arguments.rs b/clippy_lints/src/functions/too_many_arguments.rs index e72a2ad49d82..f17f687719f2 100644 --- a/clippy_lints/src/functions/too_many_arguments.rs +++ b/clippy_lints/src/functions/too_many_arguments.rs @@ -1,7 +1,7 @@ use rustc_hir::{self as hir, intravisit}; use rustc_lint::LateContext; use rustc_span::Span; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; use clippy_utils::diagnostics::span_lint; use clippy_utils::is_trait_impl_item; @@ -23,11 +23,11 @@ pub(super) fn check_fn( intravisit::FnKind::Method( _, &hir::FnSig { - header: hir::FnHeader { abi: Abi::Rust, .. }, + header: hir::FnHeader { abi: ExternAbi::Rust, .. }, .. }, ) - | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }) => check_arg_number( + | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: ExternAbi::Rust, .. }) => check_arg_number( cx, decl, span.with_hi(decl.output.span().hi()), @@ -41,7 +41,7 @@ pub(super) fn check_fn( pub(super) fn check_trait_item(cx: &LateContext<'_>, item: &hir::TraitItem<'_>, too_many_arguments_threshold: u64) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { // don't lint extern functions decls, it's not their fault - if sig.header.abi == Abi::Rust { + if sig.header.abi == ExternAbi::Rust { check_arg_number( cx, sig.decl, diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index 415b47adac5a..c58e8773e3a2 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -5,7 +5,7 @@ use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::sym; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { // #11201 && let header = signature.header && header.is_safe() - && header.abi == Abi::Rust + && header.abi == ExternAbi::Rust && impl_item.ident.name == sym::to_string && let decl = signature.decl && decl.implicit_self.has_implicit_self() diff --git a/clippy_lints/src/large_futures.rs b/clippy_lints/src/large_futures.rs index 593704f206a1..fd7965d564d5 100644 --- a/clippy_lints/src/large_futures.rs +++ b/clippy_lints/src/large_futures.rs @@ -2,11 +2,11 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::implements_trait; +use rustc_abi::Size; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_target::abi::Size; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f501cf060c2a..0a8eafad0e84 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -149,6 +149,7 @@ use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::ty::{contains_ty_adt_constructor_opaque, implements_trait, is_copy, is_type_diagnostic_item}; use clippy_utils::{contains_return, is_bool, is_trait_method, iter_input_pats, peel_blocks, return_ty}; pub use path_ends_with_ext::DEFAULT_ALLOWED_DOTFILES; +use rustc_abi::ExternAbi; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::{Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind}; @@ -5447,7 +5448,7 @@ const FN_HEADER: hir::FnHeader = hir::FnHeader { safety: hir::HeaderSafety::Normal(hir::Safety::Safe), constness: hir::Constness::NotConst, asyncness: hir::IsAsync::NotAsync, - abi: rustc_target::spec::abi::Abi::Rust, + abi: ExternAbi::Rust, }; struct ShouldImplTraitCase { diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 962d85c6a9d3..ba4af134ccd0 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -1,3 +1,4 @@ + use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; @@ -12,7 +13,7 @@ use rustc_middle::ty; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -183,11 +184,11 @@ fn already_const(header: hir::FnHeader) -> bool { header.constness == Constness::Const } -fn could_be_const_with_abi(msrv: &Msrv, abi: Abi) -> bool { +fn could_be_const_with_abi(msrv: &Msrv, abi: ExternAbi) -> bool { match abi { - Abi::Rust => true, + ExternAbi::Rust => true, // `const extern "C"` was stabilized after 1.62.0 - Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), + ExternAbi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), // Rest ABIs are still unstable and need the `const_extern_fn` feature enabled. _ => msrv.meets(msrvs::CONST_EXTERN_FN), } diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index b7dc269061cf..996251fdf162 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -20,7 +20,7 @@ use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { return; } let attrs = cx.tcx.hir().attrs(hir_id); - if header.abi != Abi::Rust || requires_exact_signature(attrs) { + if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) { return; } header.is_async() diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 2855703b9d56..40c65d1ef9e8 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -19,7 +19,7 @@ use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; use rustc_trait_selection::traits; use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy; @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { match kind { FnKind::ItemFn(.., header) => { let attrs = cx.tcx.hir().attrs(hir_id); - if header.abi != Abi::Rust || requires_exact_signature(attrs) { + if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) { return; } }, diff --git a/clippy_lints/src/no_mangle_with_rust_abi.rs b/clippy_lints/src/no_mangle_with_rust_abi.rs index 2e2916c957da..b73b9083a991 100644 --- a/clippy_lints/src/no_mangle_with_rust_abi.rs +++ b/clippy_lints/src/no_mangle_with_rust_abi.rs @@ -5,7 +5,7 @@ use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Pos}; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi { for attr in attrs { if let Some(ident) = attr.ident() && ident.name == rustc_span::sym::no_mangle - && fn_sig.header.abi == Abi::Rust + && fn_sig.header.abi == ExternAbi::Rust && let Some((fn_attrs, _)) = fn_snippet.rsplit_once("fn") && !fn_attrs.contains("extern") { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 147654675ec9..405bbfc9c6fa 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -5,6 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_in_const_context; use clippy_utils::macros::macro_backtrace; use clippy_utils::ty::{InteriorMut, implements_trait}; +use rustc_abi::VariantIdx; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ @@ -16,7 +17,6 @@ use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::{DUMMY_SP, Span, sym}; -use rustc_target::abi::VariantIdx; // FIXME: this is a correctness problem but there's no suitable // warn-by-default category. diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index b2089487a9f4..a3e89671eecd 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, RegionKind, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; declare_clippy_lint! { /// ### What it does @@ -277,7 +277,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); match kind { FnKind::ItemFn(.., header) => { - if header.abi != Abi::Rust { + if header.abi != ExternAbi::Rust { return; } let attrs = cx.tcx.hir().attrs(hir_id); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 0b67594a9b19..7fba4b6a6c8b 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Binder, ClauseKind, ExistentialPredicate, List, Pre use rustc_session::declare_lint_pass; use rustc_span::symbol::Symbol; use rustc_span::{Span, sym}; -use rustc_target::spec::abi::Abi; +use rustc_abi::ExternAbi; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use std::{fmt, iter}; @@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, None); - if !matches!(sig.header.abi, Abi::Rust) { + if !matches!(sig.header.abi, ExternAbi::Rust) { // Ignore `extern` functions with non-Rust calling conventions return; } @@ -220,7 +220,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { check_mut_from_ref(cx, sig, Some(body)); - if !matches!(sig.header.abi, Abi::Rust) { + if !matches!(sig.header.abi, ExternAbi::Rust) { // Ignore `extern` functions with non-Rust calling conventions return; } diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index 7f51660293b5..0704653385f1 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint; +use rustc_abi::ExternAbi; use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; use rustc_hir::{self as hir, AmbigArg, GenericParamKind, TyKind}; use rustc_lint::LateContext; use rustc_span::Span; -use rustc_target::spec::abi::Abi; use super::TYPE_COMPLEXITY; @@ -50,7 +50,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1), // function types bring a lot of overhead - TyKind::BareFn(bare) if bare.abi == Abi::Rust => (50 * self.nest, 1), + TyKind::BareFn(bare) if bare.abi == ExternAbi::Rust => (50 * self.nest, 1), TyKind::TraitObject(param_bounds, _) => { let has_lifetime_parameters = param_bounds.iter().any(|bound| { diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 179d42a8b5dc..59aaaa3d9fb7 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -12,6 +12,7 @@ //! code was written, and check if the span contains that text. Note this will only work correctly //! if the span is not from a `macro_rules` based macro. +use rustc_abi::ExternAbi; use rustc_ast::AttrStyle; use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy}; use rustc_ast::token::CommentKind; @@ -26,7 +27,6 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::symbol::{Ident, kw}; use rustc_span::{Span, Symbol}; -use rustc_target::spec::abi::Abi; /// The search pattern to look for. Used by `span_matches_pat` #[derive(Clone)] @@ -233,7 +233,7 @@ fn fn_header_search_pat(header: FnHeader) -> Pat { Pat::Str("const") } else if header.is_unsafe() { Pat::Str("unsafe") - } else if header.abi != Abi::Rust { + } else if header.abi != ExternAbi::Rust { Pat::Str("extern") } else { Pat::MultiStr(&["fn", "extern"]) @@ -375,7 +375,7 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) { TyKind::BareFn(bare_fn) => ( if bare_fn.safety.is_unsafe() { Pat::Str("unsafe") - } else if bare_fn.abi != Abi::Rust { + } else if bare_fn.abi != ExternAbi::Rust { Pat::Str("extern") } else { Pat::MultiStr(&["fn", "extern"]) diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index fab1db05d2e5..db82c458f703 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use crate::source::{SpanRangeExt, walk_span_to_context}; use crate::{clip, is_direct_expn_of, sext, unsext}; +use rustc_abi::Size; use rustc_apfloat::Float; use rustc_apfloat::ieee::{Half, Quad}; use rustc_ast::ast::{self, LitFloatType, LitKind}; @@ -25,7 +26,6 @@ use rustc_middle::{bug, mir, span_bug}; use rustc_span::def_id::DefId; use rustc_span::symbol::Ident; use rustc_span::{SyntaxContext, sym}; -use rustc_target::abi::Size; use std::cell::Cell; use std::cmp::Ordering; use std::hash::{Hash, Hasher}; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 337684b68f86..79cc50665800 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -29,6 +29,7 @@ // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) +extern crate rustc_abi; extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr_parsing; @@ -48,7 +49,6 @@ extern crate rustc_middle; extern crate rustc_mir_dataflow; extern crate rustc_session; extern crate rustc_span; -extern crate rustc_target; extern crate rustc_trait_selection; extern crate smallvec; @@ -123,7 +123,7 @@ use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{Ident, Symbol, kw}; use rustc_span::{InnerSpan, Span, sym}; -use rustc_target::abi::Integer; +use rustc_abi::Integer; use visitors::{Visitable, for_each_unconsumed_temporary}; use crate::consts::{ConstEvalCtxt, Constant, mir_to_const}; diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index e9a05c45747d..a5374f6904e3 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -4,6 +4,7 @@ use core::ops::ControlFlow; use itertools::Itertools; +use rustc_abi::VariantIdx; use rustc_ast::ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; @@ -23,7 +24,6 @@ use rustc_middle::ty::{ }; use rustc_span::symbol::Ident; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; -use rustc_target::abi::VariantIdx; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Obligation, ObligationCause}; From 5e3b968da05a24d3e29a574b24eddf1181795b3c Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sun, 9 Feb 2025 06:49:38 +0900 Subject: [PATCH 055/161] remove "Known problems" section for `branches_sharing_code` --- clippy_lints/src/copies.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 7c783df4f805..03ed9c657b30 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -129,11 +129,6 @@ declare_clippy_lint! { /// ### Why is this bad? /// Duplicate code is less maintainable. /// - /// ### Known problems - /// * The lint doesn't check if the moved expressions modify values that are being used in - /// the if condition. The suggestion can in that case modify the behavior of the program. - /// See [rust-clippy#7452](https://github.com/rust-lang/rust-clippy/issues/7452) - /// /// ### Example /// ```ignore /// let foo = if … { From aad3686823ea20280dc461dfae935fdffdaf5162 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 9 Feb 2025 01:53:19 +0100 Subject: [PATCH 056/161] Add error markers for `obfuscated_if_else` lint --- tests/ui/obfuscated_if_else.fixed | 6 ++++++ tests/ui/obfuscated_if_else.rs | 6 ++++++ tests/ui/obfuscated_if_else.stderr | 10 +++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index bfe1c5e10cf8..4fe48c5ca543 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -3,16 +3,22 @@ fn main() { if true { "a" } else { "b" }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` if true { "a" } else { "b" }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` let a = 1; if a == 1 { "a" } else { "b" }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` if a == 1 { "a" } else { "b" }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint let mut a = 0; if true { a += 1 } else { () }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` if true { () } else { a += 2 }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` } diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index 0ded2a2ceedf..e1de6d0f4cff 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -3,16 +3,22 @@ fn main() { true.then_some("a").unwrap_or("b"); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` true.then(|| "a").unwrap_or("b"); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` let a = 1; (a == 1).then_some("a").unwrap_or("b"); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` (a == 1).then(|| "a").unwrap_or("b"); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint let mut a = 0; true.then_some(a += 1).unwrap_or(()); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` true.then_some(()).unwrap_or(a += 2); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` } diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 9ce1f475c480..175d57b49570 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -8,31 +8,31 @@ LL | true.then_some("a").unwrap_or("b"); = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:6:5 + --> tests/ui/obfuscated_if_else.rs:7:5 | LL | true.then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:9:5 + --> tests/ui/obfuscated_if_else.rs:11:5 | LL | (a == 1).then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:10:5 + --> tests/ui/obfuscated_if_else.rs:13:5 | LL | (a == 1).then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:16:5 + --> tests/ui/obfuscated_if_else.rs:20:5 | LL | true.then_some(a += 1).unwrap_or(()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:17:5 + --> tests/ui/obfuscated_if_else.rs:22:5 | LL | true.then_some(()).unwrap_or(a += 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` From ac0a11a8bc80befca52af0712e015b4c42ee3769 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 31 Jan 2025 23:25:26 +0100 Subject: [PATCH 057/161] Fix `obfuscated_if_else` suggestion on left side of a binary expr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An `if … { … } else { … }` used as the left operand of a binary expression requires parentheses to be parsed as an expression. --- .../src/methods/obfuscated_if_else.rs | 12 +++++ tests/ui/obfuscated_if_else.fixed | 26 ++++++++++ tests/ui/obfuscated_if_else.rs | 26 ++++++++++ tests/ui/obfuscated_if_else.stderr | 50 ++++++++++++++++++- 4 files changed, 113 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/obfuscated_if_else.rs b/clippy_lints/src/methods/obfuscated_if_else.rs index b71f79f84824..2272e03ef26e 100644 --- a/clippy_lints/src/methods/obfuscated_if_else.rs +++ b/clippy_lints/src/methods/obfuscated_if_else.rs @@ -1,6 +1,7 @@ use super::OBFUSCATED_IF_ELSE; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::eager_or_lazy::switch_to_eager_eval; +use clippy_utils::get_parent_expr; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; @@ -41,6 +42,17 @@ pub(super) fn check<'tcx>( snippet_with_applicability(cx, unwrap_arg.span, "..", &mut applicability) ); + // To be parsed as an expression, the `if { … } else { … }` as the left operand of a binary operator + // requires parentheses. + let sugg = if let Some(parent_expr) = get_parent_expr(cx, expr) + && let ExprKind::Binary(_, left, _) = parent_expr.kind + && left.hir_id == expr.hir_id + { + format!("({sugg})") + } else { + sugg + }; + span_lint_and_sugg( cx, OBFUSCATED_IF_ELSE, diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 4fe48c5ca543..2cdbee90d52d 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -22,3 +22,29 @@ fn main() { if true { () } else { a += 2 }; //~^ ERROR: this method chain can be written more clearly with `if .. else ..` } + +fn issue11141() { + // Parentheses are required around the left side of a binary expression + let _ = (if true { 40 } else { 17 }) | 2; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are required only for the leftmost expression + let _ = (if true { 30 } else { 17 }) | if true { 2 } else { 3 } | if true { 10 } else { 1 }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required around the right side of a binary expression + let _ = 2 | if true { 40 } else { 17 }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a cast + let _ = if true { 42 } else { 17 } as u8; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a deref + let _ = *if true { &42 } else { &17 }; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a deref followed by a cast + let _ = *if true { &42 } else { &17 } as u8; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` +} diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index e1de6d0f4cff..20c67e729926 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -22,3 +22,29 @@ fn main() { true.then_some(()).unwrap_or(a += 2); //~^ ERROR: this method chain can be written more clearly with `if .. else ..` } + +fn issue11141() { + // Parentheses are required around the left side of a binary expression + let _ = true.then_some(40).unwrap_or(17) | 2; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are required only for the leftmost expression + let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required around the right side of a binary expression + let _ = 2 | true.then_some(40).unwrap_or(17); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a cast + let _ = true.then_some(42).unwrap_or(17) as u8; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a deref + let _ = *true.then_some(&42).unwrap_or(&17); + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + + // Parentheses are not required for a deref followed by a cast + let _ = *true.then_some(&42).unwrap_or(&17) as u8; + //~^ ERROR: this method chain can be written more clearly with `if .. else ..` +} diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 175d57b49570..9b1aebb58940 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -37,5 +37,53 @@ error: this method chain can be written more clearly with `if .. else ..` LL | true.then_some(()).unwrap_or(a += 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` -error: aborting due to 6 previous errors +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:28:13 + | +LL | let _ = true.then_some(40).unwrap_or(17) | 2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 40 } else { 17 })` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:32:13 + | +LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 30 } else { 17 })` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:32:48 + | +LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 2 } else { 3 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:32:81 + | +LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 10 } else { 1 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:36:17 + | +LL | let _ = 2 | true.then_some(40).unwrap_or(17); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 40 } else { 17 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:40:13 + | +LL | let _ = true.then_some(42).unwrap_or(17) as u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 42 } else { 17 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:44:14 + | +LL | let _ = *true.then_some(&42).unwrap_or(&17); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:48:14 + | +LL | let _ = *true.then_some(&42).unwrap_or(&17) as u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` + +error: aborting due to 14 previous errors From 657dda7b5091001a22722b4eeacdeddfe62b3b54 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 9 Feb 2025 17:45:09 +0100 Subject: [PATCH 058/161] `let_and_return`: look for non-static references in expansion as well One cannot avoid descending into expansion results when looking for non-static references, or there is a risk of false negative which would then trigger the `let_and_return` lint. --- clippy_lints/src/returns.rs | 4 ++-- tests/ui/let_and_return.fixed | 10 ++++++++++ tests/ui/let_and_return.rs | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index a1cf16e6ce9f..3fcab6a766b8 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::source::{SpanRangeExt, snippet_with_context}; use clippy_utils::sugg::has_enclosing_paren; -use clippy_utils::visitors::{Descend, for_each_expr}; +use clippy_utils::visitors::for_each_expr; use clippy_utils::{ binary_expr_needs_parentheses, fn_def_id, is_from_proc_macro, is_inside_let_else, is_res_lang_ctor, leaks_droppable_temporary_with_limited_lifetime, path_res, path_to_local_id, span_contains_cfg, @@ -483,7 +483,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { ControlFlow::Break(()) } else { - ControlFlow::Continue(Descend::from(!e.span.from_expansion())) + ControlFlow::Continue(()) } }) .is_some() diff --git a/tests/ui/let_and_return.fixed b/tests/ui/let_and_return.fixed index b68b41cdca23..e22e66eb522e 100644 --- a/tests/ui/let_and_return.fixed +++ b/tests/ui/let_and_return.fixed @@ -244,4 +244,14 @@ fn issue12801() { } } +// Do not lint +fn issue14164() -> Result { + let v = std::cell::RefCell::new(Some(vec![1])); + let r = match &*v.borrow() { + Some(v) => Ok(Ok(v[0])), + None => Ok(Ok(0)), + }?; + r +} + fn main() {} diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 6b9035f94288..f9da55946c0b 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -244,4 +244,14 @@ fn issue12801() { } } +// Do not lint +fn issue14164() -> Result { + let v = std::cell::RefCell::new(Some(vec![1])); + let r = match &*v.borrow() { + Some(v) => Ok(Ok(v[0])), + None => Ok(Ok(0)), + }?; + r +} + fn main() {} From 5d2fe079ab8cbc8aaea26932d978d76b09b24f3f Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 9 Feb 2025 18:06:11 +0100 Subject: [PATCH 059/161] =?UTF-8?q?`let=5Fand=5Freturn`:=20lint=20more=20c?= =?UTF-8?q?ases=20in=20edition=20=E2=89=A5=202024?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../matches/significant_drop_in_scrutinee.rs | 6 +- clippy_lints/src/returns.rs | 3 +- tests/ui/let_and_return.edition2021.fixed | 265 ++++++++++++++++++ tests/ui/let_and_return.edition2021.stderr | 152 ++++++++++ tests/ui/let_and_return.edition2024.fixed | 265 ++++++++++++++++++ tests/ui/let_and_return.edition2024.stderr | 228 +++++++++++++++ tests/ui/let_and_return.rs | 10 +- 7 files changed, 923 insertions(+), 6 deletions(-) create mode 100644 tests/ui/let_and_return.edition2021.fixed create mode 100644 tests/ui/let_and_return.edition2021.stderr create mode 100644 tests/ui/let_and_return.edition2024.fixed create mode 100644 tests/ui/let_and_return.edition2024.stderr diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 35f2e780d2e2..37bac561a6e0 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -199,7 +199,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> { return false; } - let result = match ty.kind() { + match ty.kind() { rustc_middle::ty::Adt(adt, args) => { // if some field has significant drop, adt.all_fields() @@ -223,9 +223,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> { rustc_middle::ty::Tuple(tys) => tys.iter().any(|ty| self.has_sig_drop_attr_impl(ty)), rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr_impl(*ty), _ => false, - }; - - result + } } } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 3fcab6a766b8..0286c9843a94 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -21,6 +21,7 @@ use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; +use rustc_span::edition::Edition; use rustc_span::{BytePos, Pos, Span, sym}; use std::borrow::Cow; use std::fmt::Display; @@ -235,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { && let Some(initexpr) = &local.init && let PatKind::Binding(_, local_id, _, _) = local.pat.kind && path_to_local_id(retexpr, local_id) - && !last_statement_borrows(cx, initexpr) + && (cx.sess().edition() >= Edition::Edition2024 || !last_statement_borrows(cx, initexpr)) && !initexpr.span.in_external_macro(cx.sess().source_map()) && !retexpr.span.in_external_macro(cx.sess().source_map()) && !local.span.from_expansion() diff --git a/tests/ui/let_and_return.edition2021.fixed b/tests/ui/let_and_return.edition2021.fixed new file mode 100644 index 000000000000..c160d5df30fd --- /dev/null +++ b/tests/ui/let_and_return.edition2021.fixed @@ -0,0 +1,265 @@ +//@revisions: edition2021 edition2024 +//@[edition2021] edition:2021 +//@[edition2024] edition:2024 + +#![allow(unused)] +#![warn(clippy::let_and_return)] + +use std::cell::RefCell; + +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 + } +} + +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() + //~^ ERROR: returning the result of a `let` binding from a block +} + +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 + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + 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 + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + 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 + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + fn test2() -> i32 { + let x = Inner {}; + let value = Foo::new(&x).value(); + value + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + } +} + +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 _ + //~^ ERROR: returning the result of a `let` binding from a block + } + } +} + +mod issue_11335 { + pub enum E { + A(T), + B(T), + } + + impl E { + pub fn inner(&self) -> &T { + + + (match self { + E::A(x) => x, + E::B(x) => x, + }) as _ + //~^ ERROR: returning the result of a `let` binding from a block + } + } +} + +// 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 issue9150() -> usize { + let x = 1; + #[cfg(any())] + panic!("can't see me"); + x +} + +fn issue12801() { + fn left_is_if() -> String { + + (if true { "a".to_string() } else { "b".to_string() } + "c") + //~^ ERROR: returning the result of a `let` binding from a block + } + + fn no_par_needed() -> String { + + "c".to_string() + if true { "a" } else { "b" } + //~^ ERROR: returning the result of a `let` binding from a block + } + + fn conjunctive_blocks() -> String { + + ({ "a".to_string() } + "b" + { "c" } + "d") + //~^ ERROR: returning the result of a `let` binding from a block + } + + #[allow(clippy::overly_complex_bool_expr)] + fn other_ops() { + let _ = || { + + (if true { 2 } else { 3 } << 4) + //~^ ERROR: returning the result of a `let` binding from a block + }; + let _ = || { + + ({ true } || { false } && { 2 <= 3 }) + //~^ ERROR: returning the result of a `let` binding from a block + }; + } +} + +fn issue14164() -> Result { + let v = std::cell::RefCell::new(Some(vec![1])); + let r = match &*v.borrow() { + Some(v) => Ok(Ok(v[0])), + None => Ok(Ok(0)), + }?; + r + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block +} + +fn main() {} diff --git a/tests/ui/let_and_return.edition2021.stderr b/tests/ui/let_and_return.edition2021.stderr new file mode 100644 index 000000000000..105fa7a722d7 --- /dev/null +++ b/tests/ui/let_and_return.edition2021.stderr @@ -0,0 +1,152 @@ +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:13:5 + | +LL | let x = 5; + | ---------- unnecessary `let` binding +LL | x + | ^ + | + = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` +help: return the expression directly + | +LL ~ +LL ~ 5 + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:21:9 + | +LL | let x = 5; + | ---------- unnecessary `let` binding +LL | x + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ 5 + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:84:5 + | +LL | let line = stdin.lock().lines().next().unwrap().unwrap(); + | --------------------------------------------------------- unnecessary `let` binding +LL | line + | ^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ stdin.lock().lines().next().unwrap().unwrap() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:179:13 + | +LL | let clone = Arc::clone(&self.foo); + | ---------------------------------- unnecessary `let` binding +LL | clone + | ^^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ (Arc::clone(&self.foo)) as _ + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:198:13 + | +LL | / let result = match self { +LL | | E::A(x) => x, +LL | | E::B(x) => x, +LL | | }; + | |______________- unnecessary `let` binding +LL | +LL | result + | ^^^^^^ + | +help: return the expression directly + | +LL ~ +LL | +LL ~ (match self { +LL + E::A(x) => x, +LL + E::B(x) => x, +LL + }) as _ + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:224:9 + | +LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; + | ------------------------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:230:9 + | +LL | let s = "c".to_string() + if true { "a" } else { "b" }; + | ------------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ "c".to_string() + if true { "a" } else { "b" } + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:236:9 + | +LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; + | -------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:244:13 + | +LL | let s = if true { 2 } else { 3 } << 4; + | -------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ (if true { 2 } else { 3 } << 4) + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:249:13 + | +LL | let s = { true } || { false } && { 2 <= 3 }; + | -------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ ({ true } || { false } && { 2 <= 3 }) + | + +error: aborting due to 10 previous errors + diff --git a/tests/ui/let_and_return.edition2024.fixed b/tests/ui/let_and_return.edition2024.fixed new file mode 100644 index 000000000000..f958f70e1dcf --- /dev/null +++ b/tests/ui/let_and_return.edition2024.fixed @@ -0,0 +1,265 @@ +//@revisions: edition2021 edition2024 +//@[edition2021] edition:2021 +//@[edition2024] edition:2024 + +#![allow(unused)] +#![warn(clippy::let_and_return)] + +use std::cell::RefCell; + +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 + } +} + +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() + //~^ ERROR: returning the result of a `let` binding from a block +} + +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(); + + value.borrow().baz() + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + fn borrows_in_closure(value: Weak>) -> u32 { + fn f(mut x: impl FnMut() -> u32) -> impl FnMut() -> u32 { + x + } + + let value = value.upgrade().unwrap(); + + f(|| value.borrow().baz())() + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + 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 {}; + + some_foo(&x).value() + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + + fn test2() -> i32 { + let x = Inner {}; + + Foo::new(&x).value() + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + } + } +} + +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 _ + //~^ ERROR: returning the result of a `let` binding from a block + } + } +} + +mod issue_11335 { + pub enum E { + A(T), + B(T), + } + + impl E { + pub fn inner(&self) -> &T { + + + (match self { + E::A(x) => x, + E::B(x) => x, + }) as _ + //~^ ERROR: returning the result of a `let` binding from a block + } + } +} + +// 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 issue9150() -> usize { + let x = 1; + #[cfg(any())] + panic!("can't see me"); + x +} + +fn issue12801() { + fn left_is_if() -> String { + + (if true { "a".to_string() } else { "b".to_string() } + "c") + //~^ ERROR: returning the result of a `let` binding from a block + } + + fn no_par_needed() -> String { + + "c".to_string() + if true { "a" } else { "b" } + //~^ ERROR: returning the result of a `let` binding from a block + } + + fn conjunctive_blocks() -> String { + + ({ "a".to_string() } + "b" + { "c" } + "d") + //~^ ERROR: returning the result of a `let` binding from a block + } + + #[allow(clippy::overly_complex_bool_expr)] + fn other_ops() { + let _ = || { + + (if true { 2 } else { 3 } << 4) + //~^ ERROR: returning the result of a `let` binding from a block + }; + let _ = || { + + ({ true } || { false } && { 2 <= 3 }) + //~^ ERROR: returning the result of a `let` binding from a block + }; + } +} + +fn issue14164() -> Result { + let v = std::cell::RefCell::new(Some(vec![1])); + + match &*v.borrow() { + Some(v) => Ok(Ok(v[0])), + None => Ok(Ok(0)), + }? + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block +} + +fn main() {} diff --git a/tests/ui/let_and_return.edition2024.stderr b/tests/ui/let_and_return.edition2024.stderr new file mode 100644 index 000000000000..ec87e32b582d --- /dev/null +++ b/tests/ui/let_and_return.edition2024.stderr @@ -0,0 +1,228 @@ +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:13:5 + | +LL | let x = 5; + | ---------- unnecessary `let` binding +LL | x + | ^ + | + = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` +help: return the expression directly + | +LL ~ +LL ~ 5 + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:21:9 + | +LL | let x = 5; + | ---------- unnecessary `let` binding +LL | x + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ 5 + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:84:5 + | +LL | let line = stdin.lock().lines().next().unwrap().unwrap(); + | --------------------------------------------------------- unnecessary `let` binding +LL | line + | ^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ stdin.lock().lines().next().unwrap().unwrap() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:107:9 + | +LL | let ret = value.borrow().baz(); + | ------------------------------- unnecessary `let` binding +LL | ret + | ^^^ + | +help: return the expression directly + | +LL ~ +LL ~ value.borrow().baz() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:118:9 + | +LL | let ret = f(|| value.borrow().baz())(); + | --------------------------------------- unnecessary `let` binding +LL | ret + | ^^^ + | +help: return the expression directly + | +LL ~ +LL ~ f(|| value.borrow().baz())() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:150:13 + | +LL | let value = some_foo(&x).value(); + | --------------------------------- unnecessary `let` binding +LL | value + | ^^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ some_foo(&x).value() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:157:13 + | +LL | let value = Foo::new(&x).value(); + | --------------------------------- unnecessary `let` binding +LL | value + | ^^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ Foo::new(&x).value() + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:179:13 + | +LL | let clone = Arc::clone(&self.foo); + | ---------------------------------- unnecessary `let` binding +LL | clone + | ^^^^^ + | +help: return the expression directly + | +LL ~ +LL ~ (Arc::clone(&self.foo)) as _ + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:198:13 + | +LL | / let result = match self { +LL | | E::A(x) => x, +LL | | E::B(x) => x, +LL | | }; + | |______________- unnecessary `let` binding +LL | +LL | result + | ^^^^^^ + | +help: return the expression directly + | +LL ~ +LL | +LL ~ (match self { +LL + E::A(x) => x, +LL + E::B(x) => x, +LL + }) as _ + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:224:9 + | +LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; + | ------------------------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:230:9 + | +LL | let s = "c".to_string() + if true { "a" } else { "b" }; + | ------------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ "c".to_string() + if true { "a" } else { "b" } + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:236:9 + | +LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; + | -------------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:244:13 + | +LL | let s = if true { 2 } else { 3 } << 4; + | -------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ (if true { 2 } else { 3 } << 4) + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:249:13 + | +LL | let s = { true } || { false } && { 2 <= 3 }; + | -------------------------------------------- unnecessary `let` binding +LL | s + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ ({ true } || { false } && { 2 <= 3 }) + | + +error: returning the result of a `let` binding from a block + --> tests/ui/let_and_return.rs:261:5 + | +LL | / let r = match &*v.borrow() { +LL | | Some(v) => Ok(Ok(v[0])), +LL | | None => Ok(Ok(0)), +LL | | }?; + | |_______- unnecessary `let` binding +LL | r + | ^ + | +help: return the expression directly + | +LL ~ +LL ~ match &*v.borrow() { +LL + Some(v) => Ok(Ok(v[0])), +LL + None => Ok(Ok(0)), +LL + }? + | + +error: aborting due to 15 previous errors + diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index f9da55946c0b..0b7a1e26890f 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -1,3 +1,7 @@ +//@revisions: edition2021 edition2024 +//@[edition2021] edition:2021 +//@[edition2024] edition:2024 + #![allow(unused)] #![warn(clippy::let_and_return)] @@ -101,6 +105,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = value.borrow().baz(); ret + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block } fn borrows_in_closure(value: Weak>) -> u32 { @@ -111,6 +116,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = f(|| value.borrow().baz())(); ret + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block } mod free_function { @@ -142,12 +148,14 @@ mod no_lint_if_stmt_borrows { let x = Inner {}; let value = some_foo(&x).value(); value + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block } fn test2() -> i32 { let x = Inner {}; let value = Foo::new(&x).value(); value + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block } } } @@ -244,7 +252,6 @@ fn issue12801() { } } -// Do not lint fn issue14164() -> Result { let v = std::cell::RefCell::new(Some(vec![1])); let r = match &*v.borrow() { @@ -252,6 +259,7 @@ fn issue14164() -> Result { None => Ok(Ok(0)), }?; r + //~[edition2024]^ ERROR: returning the result of a `let` binding from a block } fn main() {} From 4d4ef0000c16fa89a51e39e022e5a2ebb891906d Mon Sep 17 00:00:00 2001 From: Yusuf Raji Date: Sun, 19 Jan 2025 16:30:58 +0100 Subject: [PATCH 060/161] Add single_option_map lint --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/lib.rs | 2 + clippy_lints/src/single_option_map.rs | 91 +++++++++++++++++++++++++++ tests/ui/single_option_map.rs | 69 ++++++++++++++++++++ tests/ui/single_option_map.stderr | 37 +++++++++++ 6 files changed, 201 insertions(+) create mode 100644 clippy_lints/src/single_option_map.rs create mode 100644 tests/ui/single_option_map.rs create mode 100644 tests/ui/single_option_map.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index fa03c953aa59..ea1119aca984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6067,6 +6067,7 @@ Released 2018-09-13 [`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop [`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match [`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else +[`single_option_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_option_map [`single_range_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_range_in_vec_init [`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count [`size_of_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_ref diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9fbeab5bf2e1..3d4ca4faecb4 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -684,6 +684,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::single_call_fn::SINGLE_CALL_FN_INFO, crate::single_char_lifetime_names::SINGLE_CHAR_LIFETIME_NAMES_INFO, crate::single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS_INFO, + crate::single_option_map::SINGLE_OPTION_MAP_INFO, crate::single_range_in_vec_init::SINGLE_RANGE_IN_VEC_INIT_INFO, crate::size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT_INFO, crate::size_of_ref::SIZE_OF_REF_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 8887ab7ec0d7..53a05a5a5586 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -339,6 +339,7 @@ mod significant_drop_tightening; mod single_call_fn; mod single_char_lifetime_names; mod single_component_path_imports; +mod single_option_map; mod single_range_in_vec_init; mod size_of_in_element_count; mod size_of_ref; @@ -978,5 +979,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::::default()); store.register_late_pass(move |_| Box::new(non_std_lazy_statics::NonStdLazyStatic::new(conf))); store.register_late_pass(|_| Box::new(manual_option_as_slice::ManualOptionAsSlice::new(conf))); + store.register_late_pass(|_| Box::new(single_option_map::SingleOptionMap)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/single_option_map.rs b/clippy_lints/src/single_option_map.rs new file mode 100644 index 000000000000..ad8463870a68 --- /dev/null +++ b/clippy_lints/src/single_option_map.rs @@ -0,0 +1,91 @@ +use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::{path_res, peel_blocks}; +use rustc_hir::def::Res; +use rustc_hir::def_id::LocalDefId; +use rustc_hir::intravisit::FnKind; +use rustc_hir::{Body, ExprKind, FnDecl, FnRetTy}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::declare_lint_pass; +use rustc_span::{Span, sym}; + +declare_clippy_lint! { + /// ### What it does + /// Checks for functions with method calls to `.map(_)` on an arg + /// of type `Option` as the outermost expression. + /// + /// ### Why is this bad? + /// Taking and returning an `Option` may require additional + /// `Some(_)` and `unwrap` if all you have is a `T`. + /// + /// ### Example + /// ```no_run + /// fn double(param: Option) -> Option { + /// param.map(|x| x * 2) + /// } + /// ``` + /// Use instead: + /// ```no_run + /// fn double(param: u32) -> u32 { + /// param * 2 + /// } + /// ``` + #[clippy::version = "1.86.0"] + pub SINGLE_OPTION_MAP, + nursery, + "Checks for functions with method calls to `.map(_)` on an arg of type `Option` as the outermost expression." +} + +declare_lint_pass!(SingleOptionMap => [SINGLE_OPTION_MAP]); + +impl<'tcx> LateLintPass<'tcx> for SingleOptionMap { + fn check_fn( + &mut self, + cx: &LateContext<'tcx>, + kind: FnKind<'tcx>, + decl: &'tcx FnDecl<'tcx>, + body: &'tcx Body<'tcx>, + span: Span, + _fn_def: LocalDefId, + ) { + if let FnRetTy::Return(_ret) = decl.output + && matches!(kind, FnKind::ItemFn(_, _, _) | FnKind::Method(_, _)) + { + let func_body = peel_blocks(body.value); + if let ExprKind::MethodCall(method_name, callee, args, _span) = func_body.kind + && method_name.ident.name == sym::map + && let callee_type = cx.typeck_results().expr_ty(callee) + && is_type_diagnostic_item(cx, callee_type, sym::Option) + && let ExprKind::Path(_path) = callee.kind + && let Res::Local(_id) = path_res(cx, callee) + && matches!(path_res(cx, callee), Res::Local(_id)) + && !matches!(args[0].kind, ExprKind::Path(_)) + { + if let ExprKind::Closure(closure) = args[0].kind { + let Body { params: [..], value } = cx.tcx.hir().body(closure.body); + if let ExprKind::Call(func, f_args) = value.kind + && matches!(func.kind, ExprKind::Path(_)) + && f_args.iter().all(|arg| matches!(arg.kind, ExprKind::Path(_))) + { + return; + } else if let ExprKind::MethodCall(_segment, receiver, method_args, _span) = value.kind + && matches!(receiver.kind, ExprKind::Path(_)) + && method_args.iter().all(|arg| matches!(arg.kind, ExprKind::Path(_))) + && method_args.iter().all(|arg| matches!(path_res(cx, arg), Res::Local(_))) + { + return; + } + } + + span_lint_and_help( + cx, + SINGLE_OPTION_MAP, + span, + "`fn` that only maps over argument", + None, + "move the `.map` to the caller or to an `_opt` function", + ); + } + } + } +} diff --git a/tests/ui/single_option_map.rs b/tests/ui/single_option_map.rs new file mode 100644 index 000000000000..571beec54799 --- /dev/null +++ b/tests/ui/single_option_map.rs @@ -0,0 +1,69 @@ +#![warn(clippy::single_option_map)] + +use std::sync::atomic::{AtomicUsize, Ordering}; + +static ATOM: AtomicUsize = AtomicUsize::new(42); +static MAYBE_ATOMIC: Option<&AtomicUsize> = Some(&ATOM); + +fn h(arg: Option) -> Option { + //~^ ERROR: `fn` that only maps over argument + arg.map(|x| x * 2) +} + +fn j(arg: Option) -> Option { + //~^ ERROR: `fn` that only maps over argument + arg.map(|x| x * 2) +} + +fn mul_args(a: String, b: u64) -> String { + a +} + +fn mul_args_opt(a: Option, b: u64) -> Option { + //~^ ERROR: `fn` that only maps over argument + a.map(|val| mul_args(val, b + 1)) +} + +// No lint: no `Option` argument argument +fn maps_static_option() -> Option { + MAYBE_ATOMIC.map(|a| a.load(Ordering::Relaxed)) +} + +// No lint: wrapped by another function +fn manipulate(i: i32) -> i32 { + i + 1 +} +// No lint: wraps another function to do the optional thing +fn manipulate_opt(opt_i: Option) -> Option { + opt_i.map(manipulate) +} + +// No lint: maps other than the receiver +fn map_not_arg(arg: Option) -> Option { + maps_static_option().map(|_| arg.unwrap()) +} + +// No lint: wrapper function with η-expanded form +#[allow(clippy::redundant_closure)] +fn manipulate_opt_explicit(opt_i: Option) -> Option { + opt_i.map(|x| manipulate(x)) +} + +// No lint +fn multi_args(a: String, b: bool, c: u64) -> String { + a +} + +// No lint: contains only map of a closure that binds other arguments +fn multi_args_opt(a: Option, b: bool, c: u64) -> Option { + a.map(|a| multi_args(a, b, c)) +} + +fn main() { + let answer = Some(42u32); + let h_result = h(answer); + + let answer = Some(42u64); + let j_result = j(answer); + maps_static_option(); +} diff --git a/tests/ui/single_option_map.stderr b/tests/ui/single_option_map.stderr new file mode 100644 index 000000000000..f7d48eba71e8 --- /dev/null +++ b/tests/ui/single_option_map.stderr @@ -0,0 +1,37 @@ +error: `fn` that only maps over argument + --> tests/ui/single_option_map.rs:8:1 + | +LL | / fn h(arg: Option) -> Option { +LL | | +LL | | arg.map(|x| x * 2) +LL | | } + | |_^ + | + = help: move the `.map` to the caller or to an `_opt` function + = note: `-D clippy::single-option-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_option_map)]` + +error: `fn` that only maps over argument + --> tests/ui/single_option_map.rs:13:1 + | +LL | / fn j(arg: Option) -> Option { +LL | | +LL | | arg.map(|x| x * 2) +LL | | } + | |_^ + | + = help: move the `.map` to the caller or to an `_opt` function + +error: `fn` that only maps over argument + --> tests/ui/single_option_map.rs:22:1 + | +LL | / fn mul_args_opt(a: Option, b: u64) -> Option { +LL | | +LL | | a.map(|val| mul_args(val, b + 1)) +LL | | } + | |_^ + | + = help: move the `.map` to the caller or to an `_opt` function + +error: aborting due to 3 previous errors + From 749eb371bf498224a03541980d4635db232c71b4 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Mon, 10 Feb 2025 20:13:21 +0900 Subject: [PATCH 061/161] correct "Affected lints" for `allow-one-hash-in-raw-strings` --- book/src/lint_configuration.md | 2 +- clippy_config/src/conf.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 6803a1db2bbd..f43c3a280727 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -108,7 +108,7 @@ Whether to allow `r#""#` when `r""` can be used --- **Affected lints:** -* [`unnecessary_raw_string_hashes`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_raw_string_hashes) +* [`needless_raw_string_hashes`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes) ## `allow-panic-in-tests` diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 10a17da15172..28e42c67d980 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -298,7 +298,7 @@ define_Conf! { #[lints(uninlined_format_args)] allow_mixed_uninlined_format_args: bool = true, /// Whether to allow `r#""#` when `r""` can be used - #[lints(unnecessary_raw_string_hashes)] + #[lints(needless_raw_string_hashes)] allow_one_hash_in_raw_strings: bool = false, /// Whether `panic` should be allowed in test functions or `#[cfg(test)]` #[lints(panic)] From b32ad4ce0a7f4aeb4dbb63032d8f42f67b773b14 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 10 Feb 2025 10:47:50 +0100 Subject: [PATCH 062/161] Use parentheses when needed in `nonminimal_bool` lint Since comparisons on types not implementing `Ord` (such as `f32`) are not inverted, they must be enclosed in parentheses when they are negated. --- clippy_lints/src/booleans.rs | 4 +++- tests/ui/nonminimal_bool.rs | 6 ++++++ tests/ui/nonminimal_bool.stderr | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index f8c30d1c881d..ee21f9379a52 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -3,6 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::eq_expr_value; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::SpanRangeExt; +use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use rustc_ast::ast::LitKind; use rustc_attr_parsing::RustcVersion; @@ -353,7 +354,8 @@ impl SuggestContext<'_, '_, '_> { self.output.push_str(&str); } else { self.output.push('!'); - self.output.push_str(&terminal.span.get_source_text(self.cx)?); + self.output + .push_str(&Sugg::hir_opt(self.cx, terminal)?.maybe_par().to_string()); } }, True | False | Not(_) => { diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 52b0155a762e..9d0a475064ed 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -183,3 +183,9 @@ fn issue_12371(x: usize) -> bool { fn many_ops(a: bool, b: bool, c: bool, d: bool, e: bool, f: bool) -> bool { (a && c && f) || (!a && b && !d) || (!b && !c && !e) || (d && e && !f) } + +fn issue14184(a: f32, b: bool) { + if !(a < 2.0 && !b) { + println!("Hi"); + } +} diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 578f918f0139..129dadf315e4 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -213,5 +213,11 @@ error: this boolean expression can be simplified LL | if !b != !c {} | ^^^^^^^^ help: try: `b != c` -error: aborting due to 29 previous errors +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool.rs:188:8 + | +LL | if !(a < 2.0 && !b) { + | ^^^^^^^^^^^^^^^^ help: try: `!(a < 2.0) || b` + +error: aborting due to 30 previous errors From 91ff190391b33cb686381f49d568d3270b0de475 Mon Sep 17 00:00:00 2001 From: Bastian Kersting Date: Fri, 24 Jan 2025 14:08:30 +0000 Subject: [PATCH 063/161] Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424. --- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- clippy_lints/src/dereference.rs | 2 +- clippy_lints/src/multiple_unsafe_ops_per_block.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 6 +++--- clippy_lints/src/ptr_offset_with_cast.rs | 2 +- clippy_utils/src/eager_or_lazy.rs | 2 +- clippy_utils/src/visitors.rs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index e4c0db5d9ef0..57a135abc2e2 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned") && let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id) && let Some(def_id) = cx.tcx.impl_of_method(def_id) - && cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr() + && cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr() { true } else { diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 233ebe00d8e7..849c60b89b97 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -682,7 +682,7 @@ fn try_parse_ref_op<'tcx>( }, [arg], ) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg), - ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_raw_ptr() => { return Some((RefOp::Deref, sub_expr)); }, ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)), diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 9acede4f32d6..2adc27c0b709 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -122,7 +122,7 @@ fn collect_unsafe_exprs<'tcx>( unsafe_ops.push(("access of a mutable static occurs here", expr.span)); }, - ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_raw_ptr() => { unsafe_ops.push(("raw pointer dereference occurs here", expr.span)); }, diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index a3e89671eecd..95403403217a 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -179,10 +179,10 @@ impl PassByRefOrValue { && let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind { if let Some(typeck) = cx.maybe_typeck_results() { - // Don't lint if an unsafe pointer is created. - // TODO: Limit the check only to unsafe pointers to the argument (or part of the argument) + // Don't lint if a raw pointer is created. + // TODO: Limit the check only to raw pointers to the argument (or part of the argument) // which escape the current function. - if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr()) + if typeck.node_types().items().any(|(_, &ty)| ty.is_raw_ptr()) || typeck .adjustments() .items() diff --git a/clippy_lints/src/ptr_offset_with_cast.rs b/clippy_lints/src/ptr_offset_with_cast.rs index 808a7e005c67..68ae575c9063 100644 --- a/clippy_lints/src/ptr_offset_with_cast.rs +++ b/clippy_lints/src/ptr_offset_with_cast.rs @@ -111,7 +111,7 @@ fn is_expr_ty_usize(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { // Is the type of the expression a raw pointer? fn is_expr_ty_raw_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - cx.typeck_results().expr_ty(expr).is_unsafe_ptr() + cx.typeck_results().expr_ty(expr).is_raw_ptr() } fn build_suggestion( diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index b5bb174e737a..aaea8d71efbe 100644 --- a/clippy_utils/src/eager_or_lazy.rs +++ b/clippy_utils/src/eager_or_lazy.rs @@ -217,7 +217,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS self.eagerness |= NoChange; }, // Dereferences should be cheap, but dereferencing a raw pointer earlier may not be safe. - ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => (), + ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_raw_ptr() => (), ExprKind::Unary(UnOp::Deref, _) => self.eagerness |= NoChange, ExprKind::Unary(_, e) if matches!( diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 99984c41714b..70910f5bf52d 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -417,7 +417,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { } fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result { match e.kind { - ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => { + ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_raw_ptr() => { ControlFlow::Break(()) }, ExprKind::MethodCall(..) From 15d08ef98e9b2d28f0534804239122537a5893c8 Mon Sep 17 00:00:00 2001 From: Bastian Kersting Date: Fri, 24 Jan 2025 15:13:37 +0000 Subject: [PATCH 064/161] Convert two missed places --- clippy_lints/src/operators/ptr_eq.rs | 2 +- clippy_lints/src/swap_ptr_to_ref.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/operators/ptr_eq.rs b/clippy_lints/src/operators/ptr_eq.rs index 861564d54569..8118ad59bb71 100644 --- a/clippy_lints/src/operators/ptr_eq.rs +++ b/clippy_lints/src/operators/ptr_eq.rs @@ -53,7 +53,7 @@ fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_> // If the given expression is a cast to a `*const` pointer, return the lhs of the cast // E.g., `foo as *const _` returns `foo`. fn expr_as_cast_to_raw_pointer<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { - if cx.typeck_results().expr_ty(cast_expr).is_unsafe_ptr() { + if cx.typeck_results().expr_ty(cast_expr).is_raw_ptr() { if let ExprKind::Cast(expr, _) = cast_expr.kind { return Some(expr); } diff --git a/clippy_lints/src/swap_ptr_to_ref.rs b/clippy_lints/src/swap_ptr_to_ref.rs index 8c5cf93ab6e8..ff196355a2e3 100644 --- a/clippy_lints/src/swap_ptr_to_ref.rs +++ b/clippy_lints/src/swap_ptr_to_ref.rs @@ -76,7 +76,7 @@ impl LateLintPass<'_> for SwapPtrToRef { fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bool, Option) { if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, borrowed_expr) = e.kind && let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind - && cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr() + && cx.typeck_results().expr_ty(derefed_expr).is_raw_ptr() { ( true, From 3a0b1ae59ddf210f6d9594035f74eb42bca8b27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 9 Jul 2024 22:30:26 +0000 Subject: [PATCH 065/161] Show diff suggestion format on verbose replacement ``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ``` --- tests/ui-toml/dbg_macro/dbg_macro.stderr | 31 +- .../doc_markdown.stderr | 5 +- .../doc_markdown.stderr | 15 +- .../enum_variant_size.stderr | 5 +- .../renamed_function_params.default.stderr | 5 +- .../renamed_function_params.extend.stderr | 5 +- tests/ui-toml/unwrap_used/unwrap_used.stderr | 75 +++-- tests/ui/assign_ops2.stderr | 90 +++-- tests/ui/bind_instead_of_map_multipart.stderr | 20 +- tests/ui/borrow_deref_ref_unfixable.stderr | 10 +- tests/ui/cast.stderr | 103 +++--- tests/ui/cast_lossless_bool.stderr | 75 +++-- tests/ui/cast_lossless_float.stderr | 65 ++-- tests/ui/cast_lossless_integer.stderr | 198 ++++++----- tests/ui/cast_size.64bit.stderr | 45 ++- tests/ui/create_dir.stderr | 10 +- tests/ui/dbg_macro/dbg_macro.stderr | 81 +++-- tests/ui/dbg_macro/dbg_macro_unfixable.stderr | 25 +- tests/ui/doc/doc-fixable.stderr | 161 +++++---- tests/ui/doc/doc_markdown-issue_13097.stderr | 5 +- tests/ui/doc/issue_10262.stderr | 5 +- tests/ui/doc/issue_12795.stderr | 20 +- tests/ui/doc/issue_9473.stderr | 5 +- tests/ui/doc/unbalanced_ticks.stderr | 15 +- tests/ui/eager_transmute.stderr | 85 +++-- tests/ui/empty_line_after/doc_comments.stderr | 5 +- tests/ui/excessive_precision.stderr | 80 +++-- tests/ui/fn_to_numeric_cast_any.stderr | 81 +++-- tests/ui/for_kv_map.stderr | 30 +- tests/ui/four_forward_slashes.stderr | 8 + .../ui/four_forward_slashes_first_line.stderr | 2 + tests/ui/get_unwrap.stderr | 85 +++-- tests/ui/implicit_hasher.stderr | 15 +- tests/ui/implicit_return.stderr | 67 ++-- tests/ui/iter_nth.stderr | 40 ++- tests/ui/join_absolute_paths.stderr | 40 ++- tests/ui/large_enum_variant.64bit.stderr | 65 ++-- tests/ui/legacy_numeric_constants.stderr | 80 +++-- tests/ui/literals.stderr | 35 +- tests/ui/lossy_float_literal.stderr | 55 +-- tests/ui/manual_assert.edition2018.stderr | 10 +- tests/ui/manual_assert.edition2021.stderr | 10 +- tests/ui/manual_async_fn.stderr | 60 ++-- tests/ui/manual_float_methods.stderr | 45 ++- tests/ui/manual_ignore_case_cmp.stderr | 245 ++++++++------ tests/ui/manual_is_ascii_check.stderr | 20 +- tests/ui/map_all_any_identity.stderr | 10 +- ...ap_with_unused_argument_over_ranges.stderr | 10 +- ...h_unused_argument_over_ranges_nostd.stderr | 5 +- tests/ui/match_result_ok.stderr | 15 +- tests/ui/match_str_case_mismatch.stderr | 35 +- tests/ui/needless_borrow_pat.stderr | 10 +- tests/ui/needless_for_each_unfixable.stderr | 5 +- tests/ui/needless_pass_by_value.stderr | 20 +- tests/ui/needless_range_loop.stderr | 70 ++-- tests/ui/needless_range_loop2.stderr | 40 ++- tests/ui/needless_return.stderr | 50 +-- tests/ui/never_loop.stderr | 10 +- .../ui/non_canonical_partial_ord_impl.stderr | 5 +- .../non_std_lazy_static_fixable.stderr | 15 +- .../non_std_lazy_static_unfixable.stderr | 15 +- tests/ui/nonminimal_bool.stderr | 50 +-- tests/ui/octal_escapes.stderr | 110 +++--- tests/ui/op_ref.stderr | 5 +- tests/ui/option_as_ref_cloned.stderr | 15 +- tests/ui/redundant_guards.stderr | 5 +- tests/ui/ref_binding_to_reference.stderr | 10 +- tests/ui/ref_option/ref_option.all.stderr | 10 +- tests/ui/ref_option/ref_option.private.stderr | 5 +- tests/ui/repeat_vec_with_capacity.stderr | 15 +- .../ui/repeat_vec_with_capacity_nostd.stderr | 5 +- tests/ui/reversed_empty_ranges_fixable.stderr | 20 +- ...reversed_empty_ranges_loops_fixable.stderr | 30 +- tests/ui/single_range_in_vec_init.stderr | 90 +++-- tests/ui/string_lit_chars_any.stderr | 25 +- tests/ui/suspicious_command_arg_space.stderr | 10 +- tests/ui/suspicious_doc_comments.stderr | 15 +- tests/ui/suspicious_to_owned.stderr | 40 ++- tests/ui/suspicious_xor_used_as_pow.stderr | 35 +- tests/ui/transmute_ptr_to_ptr.stderr | 55 +-- ...transmutes_expressible_as_ptr_casts.stderr | 10 +- tests/ui/unit_arg.stderr | 18 +- tests/ui/unknown_clippy_lints.stderr | 10 +- tests/ui/unnecessary_lazy_eval.stderr | 315 +++++++++++------- .../ui/unnecessary_lazy_eval_unfixable.stderr | 20 +- tests/ui/unnecessary_literal_unwrap.stderr | 50 +-- tests/ui/unnecessary_map_or.stderr | 48 ++- tests/ui/unnecessary_wraps.stderr | 44 ++- tests/ui/unnested_or_patterns.stderr | 85 +++-- tests/ui/unnested_or_patterns2.stderr | 40 ++- tests/ui/unused_enumerate_index.stderr | 10 +- tests/ui/unused_format_specs.stderr | 20 +- tests/ui/unused_result_ok.stderr | 20 +- 93 files changed, 2292 insertions(+), 1500 deletions(-) diff --git a/tests/ui-toml/dbg_macro/dbg_macro.stderr b/tests/ui-toml/dbg_macro/dbg_macro.stderr index 129fab5ff97a..f0d7104a57dd 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -8,8 +8,9 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | -LL | if let Some(n) = n.checked_sub(4) { n } else { n } - | ~~~~~~~~~~~~~~~~ +LL - if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } +LL + if let Some(n) = n.checked_sub(4) { n } else { n } + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:10:8 @@ -19,8 +20,9 @@ LL | if dbg!(n <= 1) { | help: remove the invocation before committing it to a version control system | -LL | if n <= 1 { - | ~~~~~~ +LL - if dbg!(n <= 1) { +LL + if n <= 1 { + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:11:9 @@ -30,7 +32,8 @@ LL | dbg!(1) | help: remove the invocation before committing it to a version control system | -LL | 1 +LL - dbg!(1) +LL + 1 | error: the `dbg!` macro is intended as a debugging tool @@ -41,7 +44,8 @@ LL | dbg!(n * factorial(n - 1)) | help: remove the invocation before committing it to a version control system | -LL | n * factorial(n - 1) +LL - dbg!(n * factorial(n - 1)) +LL + n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool @@ -52,8 +56,9 @@ LL | dbg!(42); | help: remove the invocation before committing it to a version control system | -LL | 42; - | ~~ +LL - dbg!(42); +LL + 42; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:19:14 @@ -63,8 +68,9 @@ LL | foo(3) + dbg!(factorial(4)); | help: remove the invocation before committing it to a version control system | -LL | foo(3) + factorial(4); - | ~~~~~~~~~~~~ +LL - foo(3) + dbg!(factorial(4)); +LL + foo(3) + factorial(4); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:20:5 @@ -74,8 +80,9 @@ LL | dbg!(1, 2, 3, 4, 5); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, 3, 4, 5); - | ~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, 3, 4, 5); +LL + (1, 2, 3, 4, 5); + | error: aborting due to 7 previous errors diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index a6e0ad0f804c..8ba237ee75cf 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -8,8 +8,9 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +LL + /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. + | error: aborting due to 1 previous error diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index d4d8a579798c..9f2d7cf54e0d 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -8,8 +8,9 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `OAuth` and LaTeX are inside Clippy's default list. - | ~~~~~~~ +LL - /// OAuth and LaTeX are inside Clippy's default list. +LL + /// `OAuth` and LaTeX are inside Clippy's default list. + | error: item in documentation is missing backticks --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:6:15 @@ -19,8 +20,9 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. | help: try | -LL | /// OAuth and `LaTeX` are inside Clippy's default list. - | ~~~~~~~ +LL - /// OAuth and LaTeX are inside Clippy's default list. +LL + /// OAuth and `LaTeX` are inside Clippy's default list. + | error: item in documentation is missing backticks --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:9:5 @@ -30,8 +32,9 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh | help: try | -LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +LL + /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. + | error: aborting due to 3 previous errors diff --git a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr index 8f7ebbd9546c..020b3cc78782 100644 --- a/tests/ui-toml/enum_variant_size/enum_variant_size.stderr +++ b/tests/ui-toml/enum_variant_size/enum_variant_size.stderr @@ -14,8 +14,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 501]>), - | ~~~~~~~~~~~~~~ +LL - B([u8; 501]), +LL + B(Box<[u8; 501]>), + | error: aborting due to 1 previous error diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr index 2d700f607592..de9f17520ff7 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr @@ -33,8 +33,9 @@ LL | fn hash_slice(date: &[Self], states: &mut H) { | help: consider using the default names | -LL | fn hash_slice(data: &[Self], state: &mut H) { - | ~~~~ ~~~~~ +LL - fn hash_slice(date: &[Self], states: &mut H) { +LL + fn hash_slice(data: &[Self], state: &mut H) { + | error: renamed function parameter of trait impl --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:80:18 diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr index e57554fa613a..bdc4eeaad80f 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr @@ -27,8 +27,9 @@ LL | fn hash_slice(date: &[Self], states: &mut H) { | help: consider using the default names | -LL | fn hash_slice(data: &[Self], state: &mut H) { - | ~~~~ ~~~~~ +LL - fn hash_slice(date: &[Self], states: &mut H) { +LL + fn hash_slice(data: &[Self], state: &mut H) { + | error: aborting due to 4 previous errors diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index b58ce9b8af3e..2aff276a4a12 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -8,8 +8,9 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::get_unwrap)]` help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:38:17 @@ -30,8 +31,9 @@ LL | let _ = some_slice.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_slice[0]; - | ~~~~~~~~~~~~~~ +LL - let _ = some_slice.get(0).unwrap(); +LL + let _ = &some_slice[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:39:17 @@ -50,8 +52,9 @@ LL | let _ = some_vec.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vec[0]; - | ~~~~~~~~~~~~ +LL - let _ = some_vec.get(0).unwrap(); +LL + let _ = &some_vec[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:40:17 @@ -70,8 +73,9 @@ LL | let _ = some_vecdeque.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vecdeque[0]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_vecdeque.get(0).unwrap(); +LL + let _ = &some_vecdeque[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 @@ -90,8 +94,9 @@ LL | let _ = some_hashmap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_hashmap[&1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_hashmap.get(&1).unwrap(); +LL + let _ = &some_hashmap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:42:17 @@ -110,8 +115,9 @@ LL | let _ = some_btreemap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_btreemap[&1]; - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = some_btreemap.get(&1).unwrap(); +LL + let _ = &some_btreemap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:43:17 @@ -130,8 +136,9 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _: u8 = boxed_slice[1]; - | ~~~~~~~~~~~~~~ +LL - let _: u8 = *boxed_slice.get(1).unwrap(); +LL + let _: u8 = boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:22 @@ -150,8 +157,9 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | boxed_slice[0] = 1; - | ~~~~~~~~~~~~~~ +LL - *boxed_slice.get_mut(0).unwrap() = 1; +LL + boxed_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:52:10 @@ -170,8 +178,9 @@ LL | *some_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_slice[0] = 1; - | ~~~~~~~~~~~~~ +LL - *some_slice.get_mut(0).unwrap() = 1; +LL + some_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:10 @@ -190,8 +199,9 @@ LL | *some_vec.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vec[0] = 1; - | ~~~~~~~~~~~ +LL - *some_vec.get_mut(0).unwrap() = 1; +LL + some_vec[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:54:10 @@ -210,8 +220,9 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vecdeque[0] = 1; - | ~~~~~~~~~~~~~~~~ +LL - *some_vecdeque.get_mut(0).unwrap() = 1; +LL + some_vecdeque[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:55:10 @@ -230,8 +241,9 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:67:17 @@ -250,8 +262,9 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get_mut(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui-toml/unwrap_used/unwrap_used.rs:68:17 @@ -270,8 +283,9 @@ LL | let _ = boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: called `.get().unwrap()` on a slice --> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17 @@ -281,8 +295,9 @@ LL | let _ = Box::new([0]).get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &Box::new([0])[1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = Box::new([0]).get(1).unwrap(); +LL + let _ = &Box::new([0])[1]; + | error: aborting due to 28 previous errors diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index ddeba2b2ff8f..09b101b216a5 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -8,12 +8,14 @@ LL | a += a + 1; = help: to override `-D warnings` add `#[allow(clippy::misrefactored_assign_op)]` help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | -LL | a += 1; - | ~~~~~~ +LL - a += a + 1; +LL + a += 1; + | help: or | -LL | a = a + a + 1; - | ~~~~~~~~~~~~~ +LL - a += a + 1; +LL + a = a + a + 1; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:11:5 @@ -23,12 +25,14 @@ LL | a += 1 + a; | help: did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with | -LL | a += 1; - | ~~~~~~ +LL - a += 1 + a; +LL + a += 1; + | help: or | -LL | a = a + 1 + a; - | ~~~~~~~~~~~~~ +LL - a += 1 + a; +LL + a = a + 1 + a; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:13:5 @@ -38,12 +42,14 @@ LL | a -= a - 1; | help: did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with | -LL | a -= 1; - | ~~~~~~ +LL - a -= a - 1; +LL + a -= 1; + | help: or | -LL | a = a - (a - 1); - | ~~~~~~~~~~~~~~~ +LL - a -= a - 1; +LL + a = a - (a - 1); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:15:5 @@ -53,12 +59,14 @@ LL | a *= a * 99; | help: did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with | -LL | a *= 99; - | ~~~~~~~ +LL - a *= a * 99; +LL + a *= 99; + | help: or | -LL | a = a * a * 99; - | ~~~~~~~~~~~~~~ +LL - a *= a * 99; +LL + a = a * a * 99; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:17:5 @@ -68,12 +76,14 @@ LL | a *= 42 * a; | help: did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with | -LL | a *= 42; - | ~~~~~~~ +LL - a *= 42 * a; +LL + a *= 42; + | help: or | -LL | a = a * 42 * a; - | ~~~~~~~~~~~~~~ +LL - a *= 42 * a; +LL + a = a * 42 * a; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:19:5 @@ -83,12 +93,14 @@ LL | a /= a / 2; | help: did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with | -LL | a /= 2; - | ~~~~~~ +LL - a /= a / 2; +LL + a /= 2; + | help: or | -LL | a = a / (a / 2); - | ~~~~~~~~~~~~~~~ +LL - a /= a / 2; +LL + a = a / (a / 2); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:21:5 @@ -98,12 +110,14 @@ LL | a %= a % 5; | help: did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with | -LL | a %= 5; - | ~~~~~~ +LL - a %= a % 5; +LL + a %= 5; + | help: or | -LL | a = a % (a % 5); - | ~~~~~~~~~~~~~~~ +LL - a %= a % 5; +LL + a = a % (a % 5); + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:23:5 @@ -113,12 +127,14 @@ LL | a &= a & 1; | help: did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with | -LL | a &= 1; - | ~~~~~~ +LL - a &= a & 1; +LL + a &= 1; + | help: or | -LL | a = a & a & 1; - | ~~~~~~~~~~~~~ +LL - a &= a & 1; +LL + a = a & a & 1; + | error: variable appears on both sides of an assignment operation --> tests/ui/assign_ops2.rs:25:5 @@ -128,12 +144,14 @@ LL | a *= a * a; | help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with | -LL | a *= a; - | ~~~~~~ +LL - a *= a * a; +LL + a *= a; + | help: or | -LL | a = a * a * a; - | ~~~~~~~~~~~~~ +LL - a *= a * a; +LL + a = a * a * a; + | error: manual implementation of an assign operation --> tests/ui/assign_ops2.rs:63:5 diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index d271381adea2..7c5882d4296e 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `map` instead | -LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ~~~ ~ ~~~~~~~ +LL - let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); +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)` --> tests/ui/bind_instead_of_map_multipart.rs:8:13 @@ -22,8 +23,9 @@ LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { | help: use `map` instead | -LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); - | ~~~ ~ ~~~~~~~ +LL - let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); +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)` --> tests/ui/bind_instead_of_map_multipart.rs:11:13 @@ -33,8 +35,9 @@ LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + | help: use `map_err` instead | -LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); - | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ +LL - let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); +LL + let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); + | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> tests/ui/bind_instead_of_map_multipart.rs:19:5 @@ -83,8 +86,9 @@ LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { So | help: use `map` instead | -LL | let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); - | ~~~ ~~~~ ~~~~~~~~ +LL - let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); +LL + let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); + | error: aborting due to 5 previous errors diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 7d3a5c84a820..71f43af46c24 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -8,12 +8,14 @@ LL | let x: &str = &*s; = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` help: if you would like to reborrow, try removing `&*` | -LL | let x: &str = s; - | ~ +LL - let x: &str = &*s; +LL + let x: &str = s; + | help: if you would like to deref, try using `&**` | -LL | let x: &str = &**s; - | ~~~~ +LL - let x: &str = &*s; +LL + let x: &str = &**s; + | error: aborting due to 1 previous error diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 452482fc88e2..901447c738ed 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -81,8 +81,9 @@ LL | 1i32 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(1i32); - | ~~~~~~~~~~~~~~~~~~ +LL - 1i32 as i8; +LL + i8::try_from(1i32); + | error: casting `i32` to `u8` may truncate the value --> tests/ui/cast.rs:52:5 @@ -93,8 +94,9 @@ LL | 1i32 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(1i32); - | ~~~~~~~~~~~~~~~~~~ +LL - 1i32 as u8; +LL + u8::try_from(1i32); + | error: casting `f64` to `isize` may truncate the value --> tests/ui/cast.rs:54:5 @@ -127,8 +129,9 @@ LL | 1f32 as u32 as u16; = 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 | u16::try_from(1f32 as u32); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 1f32 as u32 as u16; +LL + u16::try_from(1f32 as u32); + | error: casting `f32` to `u32` may truncate the value --> tests/ui/cast.rs:59:5 @@ -153,8 +156,9 @@ LL | let _x: i8 = 1i32 as _; = 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 | let _x: i8 = 1i32.try_into(); - | ~~~~~~~~~~~~~~~ +LL - let _x: i8 = 1i32 as _; +LL + let _x: i8 = 1i32.try_into(); + | error: casting `f32` to `i32` may truncate the value --> tests/ui/cast.rs:66:9 @@ -228,8 +232,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i8; +LL + i8::try_from(1usize); + | error: casting `usize` to `i16` may truncate the value --> tests/ui/cast.rs:90:5 @@ -240,8 +245,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i16; +LL + i16::try_from(1usize); + | error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers --> tests/ui/cast.rs:90:5 @@ -261,8 +267,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast.rs:95:5 @@ -300,8 +307,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast.rs:111:5 @@ -360,8 +368,9 @@ 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)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (-99999999999i64).min(1) as i8; +LL + i8::try_from((-99999999999i64).min(1)); + | error: casting `u64` to `u8` may truncate the value --> tests/ui/cast.rs:222:5 @@ -372,8 +381,9 @@ 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)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 999999u64.clamp(0, 256) as u8; +LL + u8::try_from(999999u64.clamp(0, 256)); + | error: casting `main::E2` to `u8` may truncate the value --> tests/ui/cast.rs:245:21 @@ -384,8 +394,9 @@ LL | let _ = self 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 | let _ = u8::try_from(self); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = self as u8; +LL + let _ = u8::try_from(self); + | error: casting `main::E2::B` to `u8` will truncate the value --> tests/ui/cast.rs:247:21 @@ -405,8 +416,9 @@ LL | let _ = self 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 | let _ = i8::try_from(self); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = self as i8; +LL + let _ = i8::try_from(self); + | error: casting `main::E5::A` to `i8` will truncate the value --> tests/ui/cast.rs:291:21 @@ -423,8 +435,9 @@ LL | let _ = self 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 | let _ = i16::try_from(self); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as i16; +LL + let _ = i16::try_from(self); + | error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast.rs:327:21 @@ -435,8 +448,9 @@ LL | let _ = self as usize; = 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 | let _ = usize::try_from(self); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as usize; +LL + let _ = usize::try_from(self); + | error: casting `main::E10` to `u16` may truncate the value --> tests/ui/cast.rs:374:21 @@ -447,8 +461,9 @@ LL | let _ = self as u16; = 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 | let _ = u16::try_from(self); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = self as u16; +LL + let _ = u16::try_from(self); + | error: casting `u32` to `u8` may truncate the value --> tests/ui/cast.rs:385:13 @@ -459,8 +474,9 @@ LL | let c = (q >> 16) 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 | let c = u8::try_from(q >> 16); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let c = (q >> 16) as u8; +LL + let c = u8::try_from(q >> 16); + | error: casting `u32` to `u8` may truncate the value --> tests/ui/cast.rs:389:13 @@ -471,8 +487,9 @@ LL | let c = (q / 1000) 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 | let c = u8::try_from(q / 1000); - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let c = (q / 1000) as u8; +LL + let c = u8::try_from(q / 1000); + | error: casting `i32` to `u32` may lose the sign of the value --> tests/ui/cast.rs:401:9 @@ -674,8 +691,9 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: ... or use `try_from` and handle the error accordingly | -LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = u32::MAX as u8; // cast_possible_truncation +LL + let _ = u8::try_from(u32::MAX); // cast_possible_truncation + | error: casting `f64` to `f32` may truncate the value --> tests/ui/cast.rs:474:21 @@ -698,7 +716,8 @@ LL | bar.unwrap().unwrap() as usize = 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 | usize::try_from(bar.unwrap().unwrap()) +LL - bar.unwrap().unwrap() as usize +LL + usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value @@ -716,8 +735,9 @@ LL | (256 & 999999u64) 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(256 & 999999u64); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (256 & 999999u64) as u8; +LL + u8::try_from(256 & 999999u64); + | error: casting `u64` to `u8` may truncate the value --> tests/ui/cast.rs:500:5 @@ -728,8 +748,9 @@ LL | (255 % 999999u64) 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(255 % 999999u64); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - (255 % 999999u64) as u8; +LL + u8::try_from(255 % 999999u64); + | error: aborting due to 92 previous errors diff --git a/tests/ui/cast_lossless_bool.stderr b/tests/ui/cast_lossless_bool.stderr index 82d6b2e4b8e6..689922717623 100644 --- a/tests/ui/cast_lossless_bool.stderr +++ b/tests/ui/cast_lossless_bool.stderr @@ -9,8 +9,9 @@ LL | let _ = true as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `u8::from` instead | -LL | let _ = u8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as u8; +LL + let _ = u8::from(true); + | error: casts from `bool` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:9:13 @@ -21,8 +22,9 @@ LL | let _ = true as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u16; +LL + let _ = u16::from(true); + | error: casts from `bool` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:10:13 @@ -33,8 +35,9 @@ LL | let _ = true as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | let _ = u32::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u32; +LL + let _ = u32::from(true); + | error: casts from `bool` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:11:13 @@ -45,8 +48,9 @@ LL | let _ = true as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | let _ = u64::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as u64; +LL + let _ = u64::from(true); + | error: casts from `bool` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:12:13 @@ -57,8 +61,9 @@ LL | let _ = true as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | let _ = u128::from(true); - | ~~~~~~~~~~~~~~~~ +LL - let _ = true as u128; +LL + let _ = u128::from(true); + | error: casts from `bool` to `usize` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:13:13 @@ -69,8 +74,9 @@ LL | let _ = true as usize; = help: an `as` cast can become silently lossy if the types change in the future help: use `usize::from` instead | -LL | let _ = usize::from(true); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = true as usize; +LL + let _ = usize::from(true); + | error: casts from `bool` to `i8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:15:13 @@ -81,8 +87,9 @@ LL | let _ = true as i8; = help: an `as` cast can become silently lossy if the types change in the future help: use `i8::from` instead | -LL | let _ = i8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as i8; +LL + let _ = i8::from(true); + | error: casts from `bool` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:16:13 @@ -93,8 +100,9 @@ LL | let _ = true as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | let _ = i16::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i16; +LL + let _ = i16::from(true); + | error: casts from `bool` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:17:13 @@ -105,8 +113,9 @@ LL | let _ = true as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i32; +LL + let _ = i32::from(true); + | error: casts from `bool` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:18:13 @@ -117,8 +126,9 @@ LL | let _ = true as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | let _ = i64::from(true); - | ~~~~~~~~~~~~~~~ +LL - let _ = true as i64; +LL + let _ = i64::from(true); + | error: casts from `bool` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:19:13 @@ -129,8 +139,9 @@ LL | let _ = true as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | let _ = i128::from(true); - | ~~~~~~~~~~~~~~~~ +LL - let _ = true as i128; +LL + let _ = i128::from(true); + | error: casts from `bool` to `isize` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:20:13 @@ -141,8 +152,9 @@ LL | let _ = true as isize; = help: an `as` cast can become silently lossy if the types change in the future help: use `isize::from` instead | -LL | let _ = isize::from(true); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = true as isize; +LL + let _ = isize::from(true); + | error: casts from `bool` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:23:13 @@ -153,8 +165,9 @@ LL | let _ = (true | false) as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(true | false); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (true | false) as u16; +LL + let _ = u16::from(true | false); + | error: casts from `bool` to `u8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:25:13 @@ -165,8 +178,9 @@ LL | let _ = true as U8; = help: an `as` cast can become silently lossy if the types change in the future help: use `U8::from` instead | -LL | let _ = U8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as U8; +LL + let _ = U8::from(true); + | error: casts from `bool` to `u8` can be expressed infallibly using `From` --> tests/ui/cast_lossless_bool.rs:53:13 @@ -177,8 +191,9 @@ LL | let _ = true as u8; = help: an `as` cast can become silently lossy if the types change in the future help: use `u8::from` instead | -LL | let _ = u8::from(true); - | ~~~~~~~~~~~~~~ +LL - let _ = true as u8; +LL + let _ = u8::from(true); + | error: aborting due to 15 previous errors diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index b36f8bcecf58..3f405e3f402f 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -9,8 +9,9 @@ LL | let _ = x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `f32::from` instead | -LL | let _ = f32::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as f32; +LL + let _ = f32::from(x0); + | error: casts from `i8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:13:13 @@ -21,8 +22,9 @@ LL | let _ = x0 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as f64; +LL + let _ = f64::from(x0); + | error: casts from `i8` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:14:13 @@ -33,8 +35,9 @@ LL | let _ = x0 as F32; = help: an `as` cast can become silently lossy if the types change in the future help: use `F32::from` instead | -LL | let _ = F32::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as F32; +LL + let _ = F32::from(x0); + | error: casts from `i8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:15:13 @@ -45,8 +48,9 @@ LL | let _ = x0 as F64; = help: an `as` cast can become silently lossy if the types change in the future help: use `F64::from` instead | -LL | let _ = F64::from(x0); - | ~~~~~~~~~~~~~ +LL - let _ = x0 as F64; +LL + let _ = F64::from(x0); + | error: casts from `u8` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:17:13 @@ -57,8 +61,9 @@ LL | let _ = x1 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x1); - | ~~~~~~~~~~~~~ +LL - let _ = x1 as f32; +LL + let _ = f32::from(x1); + | error: casts from `u8` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:18:13 @@ -69,8 +74,9 @@ LL | let _ = x1 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x1); - | ~~~~~~~~~~~~~ +LL - let _ = x1 as f64; +LL + let _ = f64::from(x1); + | error: casts from `i16` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:20:13 @@ -81,8 +87,9 @@ LL | let _ = x2 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x2); - | ~~~~~~~~~~~~~ +LL - let _ = x2 as f32; +LL + let _ = f32::from(x2); + | error: casts from `i16` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:21:13 @@ -93,8 +100,9 @@ LL | let _ = x2 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x2); - | ~~~~~~~~~~~~~ +LL - let _ = x2 as f64; +LL + let _ = f64::from(x2); + | error: casts from `u16` to `f32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:23:13 @@ -105,8 +113,9 @@ LL | let _ = x3 as f32; = help: an `as` cast can become silently lossy if the types change in the future help: use `f32::from` instead | -LL | let _ = f32::from(x3); - | ~~~~~~~~~~~~~ +LL - let _ = x3 as f32; +LL + let _ = f32::from(x3); + | error: casts from `u16` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:24:13 @@ -117,8 +126,9 @@ LL | let _ = x3 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x3); - | ~~~~~~~~~~~~~ +LL - let _ = x3 as f64; +LL + let _ = f64::from(x3); + | error: casts from `i32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:26:13 @@ -129,8 +139,9 @@ LL | let _ = x4 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x4); - | ~~~~~~~~~~~~~ +LL - let _ = x4 as f64; +LL + let _ = f64::from(x4); + | error: casts from `u32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:28:13 @@ -141,8 +152,9 @@ LL | let _ = x5 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(x5); - | ~~~~~~~~~~~~~ +LL - let _ = x5 as f64; +LL + let _ = f64::from(x5); + | error: casts from `f32` to `f64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_float.rs:31:13 @@ -153,8 +165,9 @@ LL | let _ = 1.0f32 as f64; = help: an `as` cast can become silently lossy if the types change in the future help: use `f64::from` instead | -LL | let _ = f64::from(1.0f32); - | ~~~~~~~~~~~~~~~~~ +LL - let _ = 1.0f32 as f64; +LL + let _ = f64::from(1.0f32); + | error: aborting due to 13 previous errors diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index c93ecb8fb561..d2580913bb54 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -9,8 +9,9 @@ LL | 0u8 as u16; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` help: use `u16::from` instead | -LL | u16::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u16; +LL + u16::from(0u8); + | error: casts from `u8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:10:5 @@ -21,8 +22,9 @@ LL | 0u8 as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | i16::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i16; +LL + i16::from(0u8); + | error: casts from `u8` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:12:5 @@ -33,8 +35,9 @@ LL | 0u8 as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | u32::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u32; +LL + u32::from(0u8); + | error: casts from `u8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:14:5 @@ -45,8 +48,9 @@ LL | 0u8 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i32; +LL + i32::from(0u8); + | error: casts from `u8` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:16:5 @@ -57,8 +61,9 @@ LL | 0u8 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as u64; +LL + u64::from(0u8); + | error: casts from `u8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:18:5 @@ -69,8 +74,9 @@ LL | 0u8 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u8); - | ~~~~~~~~~~~~~~ +LL - 0u8 as i64; +LL + i64::from(0u8); + | error: casts from `u8` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:20:5 @@ -81,8 +87,9 @@ LL | 0u8 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u8); - | ~~~~~~~~~~~~~~~ +LL - 0u8 as u128; +LL + u128::from(0u8); + | error: casts from `u8` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:22:5 @@ -93,8 +100,9 @@ LL | 0u8 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u8); - | ~~~~~~~~~~~~~~~ +LL - 0u8 as i128; +LL + i128::from(0u8); + | error: casts from `u16` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:25:5 @@ -105,8 +113,9 @@ LL | 0u16 as u32; = help: an `as` cast can become silently lossy if the types change in the future help: use `u32::from` instead | -LL | u32::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as u32; +LL + u32::from(0u16); + | error: casts from `u16` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:27:5 @@ -117,8 +126,9 @@ LL | 0u16 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as i32; +LL + i32::from(0u16); + | error: casts from `u16` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:29:5 @@ -129,8 +139,9 @@ LL | 0u16 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as u64; +LL + u64::from(0u16); + | error: casts from `u16` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:31:5 @@ -141,8 +152,9 @@ LL | 0u16 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u16); - | ~~~~~~~~~~~~~~~ +LL - 0u16 as i64; +LL + i64::from(0u16); + | error: casts from `u16` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:33:5 @@ -153,8 +165,9 @@ LL | 0u16 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u16); - | ~~~~~~~~~~~~~~~~ +LL - 0u16 as u128; +LL + u128::from(0u16); + | error: casts from `u16` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:35:5 @@ -165,8 +178,9 @@ LL | 0u16 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u16); - | ~~~~~~~~~~~~~~~~ +LL - 0u16 as i128; +LL + i128::from(0u16); + | error: casts from `u32` to `u64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:38:5 @@ -177,8 +191,9 @@ LL | 0u32 as u64; = help: an `as` cast can become silently lossy if the types change in the future help: use `u64::from` instead | -LL | u64::from(0u32); - | ~~~~~~~~~~~~~~~ +LL - 0u32 as u64; +LL + u64::from(0u32); + | error: casts from `u32` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:40:5 @@ -189,8 +204,9 @@ LL | 0u32 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0u32); - | ~~~~~~~~~~~~~~~ +LL - 0u32 as i64; +LL + i64::from(0u32); + | error: casts from `u32` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:42:5 @@ -201,8 +217,9 @@ LL | 0u32 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u32); - | ~~~~~~~~~~~~~~~~ +LL - 0u32 as u128; +LL + u128::from(0u32); + | error: casts from `u32` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:44:5 @@ -213,8 +230,9 @@ LL | 0u32 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u32); - | ~~~~~~~~~~~~~~~~ +LL - 0u32 as i128; +LL + i128::from(0u32); + | error: casts from `u64` to `u128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:47:5 @@ -225,8 +243,9 @@ LL | 0u64 as u128; = help: an `as` cast can become silently lossy if the types change in the future help: use `u128::from` instead | -LL | u128::from(0u64); - | ~~~~~~~~~~~~~~~~ +LL - 0u64 as u128; +LL + u128::from(0u64); + | error: casts from `u64` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:49:5 @@ -237,8 +256,9 @@ LL | 0u64 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0u64); - | ~~~~~~~~~~~~~~~~ +LL - 0u64 as i128; +LL + i128::from(0u64); + | error: casts from `i8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:52:5 @@ -249,8 +269,9 @@ LL | 0i8 as i16; = help: an `as` cast can become silently lossy if the types change in the future help: use `i16::from` instead | -LL | i16::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i16; +LL + i16::from(0i8); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:54:5 @@ -261,8 +282,9 @@ LL | 0i8 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i32; +LL + i32::from(0i8); + | error: casts from `i8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:56:5 @@ -273,8 +295,9 @@ LL | 0i8 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i8); - | ~~~~~~~~~~~~~~ +LL - 0i8 as i64; +LL + i64::from(0i8); + | error: casts from `i8` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:58:5 @@ -285,8 +308,9 @@ LL | 0i8 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i8); - | ~~~~~~~~~~~~~~~ +LL - 0i8 as i128; +LL + i128::from(0i8); + | error: casts from `i16` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:61:5 @@ -297,8 +321,9 @@ LL | 0i16 as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | i32::from(0i16); - | ~~~~~~~~~~~~~~~ +LL - 0i16 as i32; +LL + i32::from(0i16); + | error: casts from `i16` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:63:5 @@ -309,8 +334,9 @@ LL | 0i16 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i16); - | ~~~~~~~~~~~~~~~ +LL - 0i16 as i64; +LL + i64::from(0i16); + | error: casts from `i16` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:65:5 @@ -321,8 +347,9 @@ LL | 0i16 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i16); - | ~~~~~~~~~~~~~~~~ +LL - 0i16 as i128; +LL + i128::from(0i16); + | error: casts from `i32` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:68:5 @@ -333,8 +360,9 @@ LL | 0i32 as i64; = help: an `as` cast can become silently lossy if the types change in the future help: use `i64::from` instead | -LL | i64::from(0i32); - | ~~~~~~~~~~~~~~~ +LL - 0i32 as i64; +LL + i64::from(0i32); + | error: casts from `i32` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:70:5 @@ -345,8 +373,9 @@ LL | 0i32 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i32); - | ~~~~~~~~~~~~~~~~ +LL - 0i32 as i128; +LL + i128::from(0i32); + | error: casts from `i64` to `i128` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:73:5 @@ -357,8 +386,9 @@ LL | 0i64 as i128; = help: an `as` cast can become silently lossy if the types change in the future help: use `i128::from` instead | -LL | i128::from(0i64); - | ~~~~~~~~~~~~~~~~ +LL - 0i64 as i128; +LL + i128::from(0i64); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:77:13 @@ -369,8 +399,9 @@ LL | let _ = (1u8 + 1u8) as u16; = help: an `as` cast can become silently lossy if the types change in the future help: use `u16::from` instead | -LL | let _ = u16::from(1u8 + 1u8); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (1u8 + 1u8) as u16; +LL + let _ = u16::from(1u8 + 1u8); + | error: casts from `i8` to `i64` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:80:13 @@ -381,8 +412,9 @@ LL | let _ = 1i8 as I64Alias; = help: an `as` cast can become silently lossy if the types change in the future help: use `I64Alias::from` instead | -LL | let _ = I64Alias::from(1i8); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = 1i8 as I64Alias; +LL + let _ = I64Alias::from(1i8); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:83:18 @@ -393,8 +425,9 @@ LL | let _: u16 = 0u8 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u16 = 0u8.into(); - | ~~~~~~~~~~ +LL - let _: u16 = 0u8 as _; +LL + let _: u16 = 0u8.into(); + | error: casts from `i8` to `i16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:85:18 @@ -405,8 +438,9 @@ LL | let _: i16 = -1i8 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: i16 = (-1i8).into(); - | ~~~~~~~~~~~~~ +LL - let _: i16 = -1i8 as _; +LL + let _: i16 = (-1i8).into(); + | error: casts from `u8` to `u16` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:87:18 @@ -417,8 +451,9 @@ LL | let _: u16 = (1u8 + 2) as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u16 = (1u8 + 2).into(); - | ~~~~~~~~~~~~~~~~ +LL - let _: u16 = (1u8 + 2) as _; +LL + let _: u16 = (1u8 + 2).into(); + | error: casts from `u16` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:89:18 @@ -429,8 +464,9 @@ LL | let _: u32 = 1i8 as u16 as _; = help: an `as` cast can become silently lossy if the types change in the future help: use `Into::into` instead | -LL | let _: u32 = (1i8 as u16).into(); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _: u32 = 1i8 as u16 as _; +LL + let _: u32 = (1i8 as u16).into(); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:124:13 @@ -441,8 +477,9 @@ LL | let _ = sign_cast!(x, u8, i8) as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(sign_cast!(x, u8, i8)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = sign_cast!(x, u8, i8) as i32; +LL + let _ = i32::from(sign_cast!(x, u8, i8)); + | error: casts from `i8` to `i32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:126:13 @@ -453,8 +490,9 @@ LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; = help: an `as` cast can become silently lossy if the types change in the future help: use `i32::from` instead | -LL | let _ = i32::from(sign_cast!(x, u8, i8) + 1); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (sign_cast!(x, u8, i8) + 1) as i32; +LL + let _ = i32::from(sign_cast!(x, u8, i8) + 1); + | error: casts from `u8` to `u32` can be expressed infallibly using `From` --> tests/ui/cast_lossless_integer.rs:133:13 @@ -469,7 +507,8 @@ LL | let _ = in_macro!(); = note: this error originates in the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) help: use `u32::from` instead | -LL | u32::from(1u8) +LL - 1u8 as u32 +LL + u32::from(1u8) | error: casts from `u8` to `u32` can be expressed infallibly using `From` @@ -481,8 +520,9 @@ LL | let _ = 0u8 as ty!(); = help: an `as` cast can become silently lossy if the types change in the future help: use `::from` instead | -LL | let _ = ::from(0u8); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = 0u8 as ty!(); +LL + let _ = ::from(0u8); + | error: aborting due to 40 previous errors diff --git a/tests/ui/cast_size.64bit.stderr b/tests/ui/cast_size.64bit.stderr index bc37107d80e3..6b9919f8a105 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -9,8 +9,9 @@ LL | 1isize as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i8; +LL + i8::try_from(1isize); + | 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) --> tests/ui/cast_size.rs:21:5 @@ -48,8 +49,9 @@ LL | 1isize 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(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i32; +LL + i32::try_from(1isize); + | error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:29:5 @@ -60,8 +62,9 @@ LL | 1isize as u32; = 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 | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as u32; +LL + u32::try_from(1isize); + | error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:30:5 @@ -72,8 +75,9 @@ LL | 1usize as u32; = 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 | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as u32; +LL + u32::try_from(1usize); + | error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:31:5 @@ -84,8 +88,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:31:5 @@ -105,8 +110,9 @@ LL | 1i64 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(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as isize; +LL + isize::try_from(1i64); + | error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:33:5 @@ -117,8 +123,9 @@ LL | 1i64 as usize; = 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 | usize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as usize; +LL + usize::try_from(1i64); + | error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:34:5 @@ -129,8 +136,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:34:5 @@ -147,8 +155,9 @@ LL | 1u64 as usize; = 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 | usize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as usize; +LL + usize::try_from(1u64); + | error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:36:5 diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr index ab51705bb55a..9bb98a2606dd 100644 --- a/tests/ui/create_dir.stderr +++ b/tests/ui/create_dir.stderr @@ -8,8 +8,9 @@ LL | std::fs::create_dir("foo"); = help: to override `-D warnings` add `#[allow(clippy::create_dir)]` help: consider calling `std::fs::create_dir_all` instead | -LL | create_dir_all("foo"); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - std::fs::create_dir("foo"); +LL + create_dir_all("foo"); + | error: calling `std::fs::create_dir` where there may be a better way --> tests/ui/create_dir.rs:11:5 @@ -19,8 +20,9 @@ LL | std::fs::create_dir("bar").unwrap(); | help: consider calling `std::fs::create_dir_all` instead | -LL | create_dir_all("bar").unwrap(); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - std::fs::create_dir("bar").unwrap(); +LL + create_dir_all("bar").unwrap(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/dbg_macro/dbg_macro.stderr b/tests/ui/dbg_macro/dbg_macro.stderr index b3d74b9ff617..f218614fdd62 100644 --- a/tests/ui/dbg_macro/dbg_macro.stderr +++ b/tests/ui/dbg_macro/dbg_macro.stderr @@ -8,8 +8,9 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | -LL | if let Some(n) = n.checked_sub(4) { n } else { n } - | ~~~~~~~~~~~~~~~~ +LL - if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } +LL + if let Some(n) = n.checked_sub(4) { n } else { n } + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:11:8 @@ -19,8 +20,9 @@ LL | if dbg!(n <= 1) { | help: remove the invocation before committing it to a version control system | -LL | if n <= 1 { - | ~~~~~~ +LL - if dbg!(n <= 1) { +LL + if n <= 1 { + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:13:9 @@ -30,7 +32,8 @@ LL | dbg!(1) | help: remove the invocation before committing it to a version control system | -LL | 1 +LL - dbg!(1) +LL + 1 | error: the `dbg!` macro is intended as a debugging tool @@ -41,7 +44,8 @@ LL | dbg!(n * factorial(n - 1)) | help: remove the invocation before committing it to a version control system | -LL | n * factorial(n - 1) +LL - dbg!(n * factorial(n - 1)) +LL + n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool @@ -52,8 +56,9 @@ LL | dbg!(42); | help: remove the invocation before committing it to a version control system | -LL | 42; - | ~~ +LL - dbg!(42); +LL + 42; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:24:14 @@ -63,8 +68,9 @@ LL | foo(3) + dbg!(factorial(4)); | help: remove the invocation before committing it to a version control system | -LL | foo(3) + factorial(4); - | ~~~~~~~~~~~~ +LL - foo(3) + dbg!(factorial(4)); +LL + foo(3) + factorial(4); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:26:5 @@ -74,8 +80,9 @@ LL | dbg!(1, 2, 3, 4, 5); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, 3, 4, 5); - | ~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, 3, 4, 5); +LL + (1, 2, 3, 4, 5); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:48:5 @@ -96,8 +103,9 @@ LL | let _ = dbg!(); | help: remove the invocation before committing it to a version control system | -LL | let _ = (); - | ~~ +LL - let _ = dbg!(); +LL + let _ = (); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:53:9 @@ -107,8 +115,9 @@ LL | bar(dbg!()); | help: remove the invocation before committing it to a version control system | -LL | bar(()); - | ~~ +LL - bar(dbg!()); +LL + bar(()); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:55:10 @@ -118,8 +127,9 @@ LL | foo!(dbg!()); | help: remove the invocation before committing it to a version control system | -LL | foo!(()); - | ~~ +LL - foo!(dbg!()); +LL + foo!(()); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:57:16 @@ -129,8 +139,9 @@ LL | foo2!(foo!(dbg!())); | help: remove the invocation before committing it to a version control system | -LL | foo2!(foo!(())); - | ~~ +LL - foo2!(foo!(dbg!())); +LL + foo2!(foo!(())); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:43:13 @@ -155,8 +166,9 @@ LL | dbg!(2); | help: remove the invocation before committing it to a version control system | -LL | 2; - | ~ +LL - dbg!(2); +LL + 2; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:86:5 @@ -166,8 +178,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:92:5 @@ -177,8 +190,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:99:9 @@ -188,8 +202,9 @@ LL | dbg!(1); | help: remove the invocation before committing it to a version control system | -LL | 1; - | ~ +LL - dbg!(1); +LL + 1; + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:106:31 @@ -199,8 +214,9 @@ LL | println!("dbg: {:?}", dbg!(s)); | help: remove the invocation before committing it to a version control system | -LL | println!("dbg: {:?}", s); - | ~ +LL - println!("dbg: {:?}", dbg!(s)); +LL + println!("dbg: {:?}", s); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:108:22 @@ -210,8 +226,9 @@ LL | print!("{}", dbg!(s)); | help: remove the invocation before committing it to a version control system | -LL | print!("{}", s); - | ~ +LL - print!("{}", dbg!(s)); +LL + print!("{}", s); + | error: aborting due to 19 previous errors diff --git a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr index b8e91906b931..e8d5f9f2f46f 100644 --- a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr +++ b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr @@ -19,8 +19,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~~~~~~~~~~~~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:10 @@ -30,8 +31,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~~~~~~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:15 @@ -41,8 +43,9 @@ LL | dbg!(dbg!(dbg!(42))); | help: remove the invocation before committing it to a version control system | -LL | dbg!(dbg!(42)); - | ~~ +LL - dbg!(dbg!(dbg!(42))); +LL + dbg!(dbg!(42)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:5 @@ -52,8 +55,9 @@ LL | dbg!(1, 2, dbg!(3, 4)); | help: remove the invocation before committing it to a version control system | -LL | (1, 2, dbg!(3, 4)); - | ~~~~~~~~~~~~~~~~~~ +LL - dbg!(1, 2, dbg!(3, 4)); +LL + (1, 2, dbg!(3, 4)); + | error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:16 @@ -63,8 +67,9 @@ LL | dbg!(1, 2, dbg!(3, 4)); | help: remove the invocation before committing it to a version control system | -LL | dbg!(1, 2, (3, 4)); - | ~~~~~~ +LL - dbg!(1, 2, dbg!(3, 4)); +LL + dbg!(1, 2, (3, 4)); + | error: aborting due to 6 previous errors diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index 27a04e4b5583..54d735814855 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -8,8 +8,9 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) - | ~~~~~~~~~ +LL - /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +LL + /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:9:51 @@ -19,8 +20,9 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t | help: try | -LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot there) - | ~~~~~~~~~~ +LL - /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +LL + /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot there) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:10:83 @@ -30,8 +32,9 @@ LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. B | 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 +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 --> tests/ui/doc/doc-fixable.rs:12:13 @@ -41,8 +44,9 @@ LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a p | help: try | -LL | /// Here be `::a::global:path`, and _::another::global::path_. :: is not a path though. - | ~~~~~~~~~~~~~~~~~~ +LL - /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +LL + /// Here be `::a::global:path`, and _::another::global::path_. :: is not a path though. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:12:36 @@ -52,8 +56,9 @@ LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a p | help: try | -LL | /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a path though. - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +LL + /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a path though. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:13:25 @@ -63,8 +68,9 @@ LL | /// Import an item from ::awesome::global::blob:: (Intended postfix) | help: try | -LL | /// Import an item from `::awesome::global::blob::` (Intended postfix) - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// Import an item from ::awesome::global::blob:: (Intended postfix) +LL + /// Import an item from `::awesome::global::blob::` (Intended postfix) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:14:31 @@ -74,8 +80,9 @@ LL | /// These are the options for ::Cat: (Intended trailing single colon, shoul | help: try | -LL | /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) - | ~~~~~~~ +LL - /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) +LL + /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:15:22 @@ -85,8 +92,9 @@ LL | /// That's not code ~NotInCodeBlock~. | help: try | -LL | /// That's not code ~`NotInCodeBlock`~. - | ~~~~~~~~~~~~~~~~ +LL - /// That's not code ~NotInCodeBlock~. +LL + /// That's not code ~`NotInCodeBlock`~. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:16:5 @@ -96,8 +104,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:30:5 @@ -107,8 +116,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:37:5 @@ -118,8 +128,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:51:5 @@ -129,8 +140,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:79:5 @@ -140,8 +152,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:96:5 @@ -151,8 +164,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:104:8 @@ -162,8 +176,9 @@ LL | /// ## CamelCaseThing | help: try | -LL | /// ## `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// ## CamelCaseThing +LL + /// ## `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:107:7 @@ -173,8 +188,9 @@ LL | /// # CamelCaseThing | help: try | -LL | /// # `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// # CamelCaseThing +LL + /// # `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:109:22 @@ -184,8 +200,9 @@ LL | /// Not a title #897 CamelCaseThing | help: try | -LL | /// Not a title #897 `CamelCaseThing` - | ~~~~~~~~~~~~~~~~ +LL - /// Not a title #897 CamelCaseThing +LL + /// Not a title #897 `CamelCaseThing` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:110:5 @@ -195,8 +212,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:117:5 @@ -206,8 +224,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:130:5 @@ -217,8 +236,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:141:43 @@ -228,8 +248,9 @@ LL | /** E.g., serialization of an empty list: FooBar | help: try | -LL | /** E.g., serialization of an empty list: `FooBar` - | ~~~~~~~~ +LL - /** E.g., serialization of an empty list: FooBar +LL + /** E.g., serialization of an empty list: `FooBar` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:146:5 @@ -239,8 +260,9 @@ LL | And BarQuz too. | help: try | -LL | And `BarQuz` too. - | ~~~~~~~~ +LL - And BarQuz too. +LL + And `BarQuz` too. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:147:1 @@ -250,7 +272,8 @@ LL | be_sure_we_got_to_the_end_of_it | help: try | -LL | `be_sure_we_got_to_the_end_of_it` +LL - be_sure_we_got_to_the_end_of_it +LL + `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks @@ -261,8 +284,9 @@ LL | /** E.g., serialization of an empty list: FooBar | help: try | -LL | /** E.g., serialization of an empty list: `FooBar` - | ~~~~~~~~ +LL - /** E.g., serialization of an empty list: FooBar +LL + /** E.g., serialization of an empty list: `FooBar` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:157:5 @@ -272,8 +296,9 @@ LL | And BarQuz too. | help: try | -LL | And `BarQuz` too. - | ~~~~~~~~ +LL - And BarQuz too. +LL + And `BarQuz` too. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:158:1 @@ -283,7 +308,8 @@ LL | be_sure_we_got_to_the_end_of_it | help: try | -LL | `be_sure_we_got_to_the_end_of_it` +LL - be_sure_we_got_to_the_end_of_it +LL + `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks @@ -294,8 +320,9 @@ LL | /// be_sure_we_got_to_the_end_of_it | help: try | -LL | /// `be_sure_we_got_to_the_end_of_it` - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - /// be_sure_we_got_to_the_end_of_it +LL + /// `be_sure_we_got_to_the_end_of_it` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:188:22 @@ -305,8 +332,9 @@ LL | /// An iterator over mycrate::Collection's values. | help: try | -LL | /// An iterator over `mycrate::Collection`'s values. - | ~~~~~~~~~~~~~~~~~~~~~ +LL - /// An iterator over mycrate::Collection's values. +LL + /// An iterator over `mycrate::Collection`'s values. + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:212:34 @@ -316,8 +344,9 @@ LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint | help: try | -LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` - | ~~~~~~~~~~~~~~~~~ +LL - /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint +LL + /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:235:22 @@ -327,8 +356,9 @@ LL | /// There is no try (do() or do_not()). | help: try | -LL | /// There is no try (`do()` or do_not()). - | ~~~~~~ +LL - /// There is no try (do() or do_not()). +LL + /// There is no try (`do()` or do_not()). + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:235:30 @@ -338,8 +368,9 @@ LL | /// There is no try (do() or do_not()). | help: try | -LL | /// There is no try (do() or `do_not()`). - | ~~~~~~~~~~ +LL - /// There is no try (do() or do_not()). +LL + /// There is no try (do() or `do_not()`). + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:238:5 @@ -349,8 +380,9 @@ LL | /// ABes | help: try | -LL | /// `ABes` - | ~~~~~~ +LL - /// ABes +LL + /// `ABes` + | error: item in documentation is missing backticks --> tests/ui/doc/doc-fixable.rs:244:9 @@ -360,8 +392,9 @@ LL | /// foo() | help: try | -LL | /// `foo()` - | ~~~~~~~ +LL - /// foo() +LL + /// `foo()` + | error: you should put bare URLs between `<`/`>` or make a proper Markdown link --> tests/ui/doc/doc-fixable.rs:248:5 diff --git a/tests/ui/doc/doc_markdown-issue_13097.stderr b/tests/ui/doc/doc_markdown-issue_13097.stderr index ae68a767ec93..65b8f2ed80b6 100644 --- a/tests/ui/doc/doc_markdown-issue_13097.stderr +++ b/tests/ui/doc/doc_markdown-issue_13097.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::doc_markdown)] | ^^^^^^^^^^^^^^^^^^^^ help: try | -LL | /// `HumaNified` - | ~~~~~~~~~~~~ +LL - /// HumaNified +LL + /// `HumaNified` + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/issue_10262.stderr b/tests/ui/doc/issue_10262.stderr index f43d9551e94e..f9ecb3de219b 100644 --- a/tests/ui/doc/issue_10262.stderr +++ b/tests/ui/doc/issue_10262.stderr @@ -8,8 +8,9 @@ LL | /// AviSynth documentation: = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// `AviSynth` documentation: - | ~~~~~~~~~~ +LL - /// AviSynth documentation: +LL + /// `AviSynth` documentation: + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/issue_12795.stderr b/tests/ui/doc/issue_12795.stderr index 5700145ec8f7..047de915ed4c 100644 --- a/tests/ui/doc/issue_12795.stderr +++ b/tests/ui/doc/issue_12795.stderr @@ -8,8 +8,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | //! A comment with `a_b(x)` and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) - | ~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with `a_b(x)` and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:31 @@ -19,8 +20,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and `a_c` in it and (a_b((c)) ) too and (maybe a_b((c))) - | ~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and `a_c` in it and (a_b((c)) ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:46 @@ -30,8 +32,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and a_c in it and (`a_b((c))` ) too and (maybe a_b((c))) - | ~~~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and a_c in it and (`a_b((c))` ) too and (maybe a_b((c))) + | error: item in documentation is missing backticks --> tests/ui/doc/issue_12795.rs:3:72 @@ -41,8 +44,9 @@ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b( | help: try | -LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe `a_b((c))`) - | ~~~~~~~~~~ +LL - //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) +LL + //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe `a_b((c))`) + | error: aborting due to 4 previous errors diff --git a/tests/ui/doc/issue_9473.stderr b/tests/ui/doc/issue_9473.stderr index 35aa2884cc11..744c8dc8c838 100644 --- a/tests/ui/doc/issue_9473.stderr +++ b/tests/ui/doc/issue_9473.stderr @@ -8,8 +8,9 @@ LL | /// Blah blah blah [FooBar]<[FooBar]>[FooBar]. = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | -LL | /// Blah blah blah [FooBar]<[FooBar]>[`FooBar`]. - | ~~~~~~~~ +LL - /// Blah blah blah [FooBar]<[FooBar]>[FooBar]. +LL + /// Blah blah blah [FooBar]<[FooBar]>[`FooBar`]. + | error: aborting due to 1 previous error diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index c9fd25eb1a1c..4114a823822c 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -29,8 +29,9 @@ LL | /// This paragraph is fine and should_be linted normally. | help: try | -LL | /// This paragraph is fine and `should_be` linted normally. - | ~~~~~~~~~~~ +LL - /// This paragraph is fine and should_be linted normally. +LL + /// This paragraph is fine and `should_be` linted normally. + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:20:5 @@ -48,8 +49,9 @@ LL | /// ## not_fine | help: try | -LL | /// ## `not_fine` - | ~~~~~~~~~~ +LL - /// ## not_fine +LL + /// ## `not_fine` + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:37:5 @@ -75,8 +77,9 @@ LL | /// - This item needs backticks_here | help: try | -LL | /// - This item needs `backticks_here` - | ~~~~~~~~~~~~~~~~ +LL - /// - This item needs backticks_here +LL + /// - This item needs `backticks_here` + | error: backticks are unbalanced --> tests/ui/doc/unbalanced_ticks.rs:53:5 diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr index 5cf7bd49a929..68690c3730d8 100644 --- a/tests/ui/eager_transmute.stderr +++ b/tests/ui/eager_transmute.stderr @@ -8,8 +8,9 @@ LL | (op < 4).then_some(unsafe { std::mem::transmute(op) }) = help: to override `-D warnings` add `#[allow(clippy::eager_transmute)]` help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| unsafe { std::mem::transmute(op) }) - | ~~~~ ++ +LL - (op < 4).then_some(unsafe { std::mem::transmute(op) }) +LL + (op < 4).then(|| unsafe { std::mem::transmute(op) }) + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:27:33 @@ -19,8 +20,9 @@ LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:28:33 @@ -30,8 +32,9 @@ LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:29:34 @@ -41,8 +44,9 @@ LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); - | ~~~~ ++ +LL - (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); +LL + (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:31:68 @@ -52,8 +56,9 @@ LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:32:86 @@ -63,8 +68,9 @@ LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:35:84 @@ -74,8 +80,9 @@ LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(u | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); - | ~~~~ ++ +LL - let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); +LL + let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:47:70 @@ -85,8 +92,9 @@ LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::m | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:48:83 @@ -96,8 +104,9 @@ LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(un | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:49:69 @@ -107,8 +116,9 @@ LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::me | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:50:68 @@ -118,8 +128,9 @@ LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:51:68 @@ -129,8 +140,9 @@ LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:52:69 @@ -140,8 +152,9 @@ LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::me | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); - | ~~~~ ++ +LL - let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); +LL + let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:61:24 @@ -151,8 +164,9 @@ LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | help: consider using `bool::then` to only transmute if the condition holds | -LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); - | ~~~~ ++ +LL - (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); +LL + (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:90:62 @@ -162,8 +176,9 @@ LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::tran | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); - | ~~~~ ++ +LL - let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); +LL + let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:96:86 @@ -173,8 +188,9 @@ LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); - | ~~~~ ++ +LL - let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + | error: this transmute is always evaluated eagerly, even if the condition is false --> tests/ui/eager_transmute.rs:102:93 @@ -184,8 +200,9 @@ LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).th | help: consider using `bool::then` to only transmute if the condition holds | -LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); - | ~~~~ ++ +LL - let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); +LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + | error: aborting due to 17 previous errors diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index 7b197ae67e00..ca05a1b03eb1 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -131,8 +131,9 @@ LL | fn first_in_module() {} = help: if the empty line is unintentional, remove it help: if the comment should document the parent module use an inner doc comment | -LL | /*! - | ~ +LL - /** +LL + /*! + | error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:85:5 diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 81e4fb6765d0..b1f12eed4200 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -8,8 +8,9 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32; = help: to override `-D warnings` add `#[allow(clippy::excessive_precision)]` help: consider changing the type or truncating it to | -LL | const BAD32_1: f32 = 0.123_456_79_f32; - | ~~~~~~~~~~~~~~~~ +LL - const BAD32_1: f32 = 0.123_456_789_f32; +LL + const BAD32_1: f32 = 0.123_456_79_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:21:26 @@ -19,8 +20,9 @@ LL | const BAD32_2: f32 = 0.123_456_789; | help: consider changing the type or truncating it to | -LL | const BAD32_2: f32 = 0.123_456_79; - | ~~~~~~~~~~~~ +LL - const BAD32_2: f32 = 0.123_456_789; +LL + const BAD32_2: f32 = 0.123_456_79; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:22:26 @@ -30,8 +32,9 @@ LL | const BAD32_3: f32 = 0.100_000_000_000_1; | help: consider changing the type or truncating it to | -LL | const BAD32_3: f32 = 0.1; - | ~~~ +LL - const BAD32_3: f32 = 0.100_000_000_000_1; +LL + const BAD32_3: f32 = 0.1; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:23:29 @@ -41,8 +44,9 @@ LL | const BAD32_EDGE: f32 = 1.000_000_9; | help: consider changing the type or truncating it to | -LL | const BAD32_EDGE: f32 = 1.000_001; - | ~~~~~~~~~ +LL - const BAD32_EDGE: f32 = 1.000_000_9; +LL + const BAD32_EDGE: f32 = 1.000_001; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:27:26 @@ -52,8 +56,9 @@ LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; | help: consider changing the type or truncating it to | -LL | const BAD64_3: f64 = 0.1; - | ~~~ +LL - const BAD64_3: f64 = 0.100_000_000_000_000_000_1; +LL + const BAD64_3: f64 = 0.1; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:30:22 @@ -63,8 +68,9 @@ LL | println!("{:?}", 8.888_888_888_888_888_888_888); | help: consider changing the type or truncating it to | -LL | println!("{:?}", 8.888_888_888_888_89); - | ~~~~~~~~~~~~~~~~~~~~ +LL - println!("{:?}", 8.888_888_888_888_888_888_888); +LL + println!("{:?}", 8.888_888_888_888_89); + | error: float has excessive precision --> tests/ui/excessive_precision.rs:41:22 @@ -74,8 +80,9 @@ LL | let bad32: f32 = 1.123_456_789; | help: consider changing the type or truncating it to | -LL | let bad32: f32 = 1.123_456_8; - | ~~~~~~~~~~~ +LL - let bad32: f32 = 1.123_456_789; +LL + let bad32: f32 = 1.123_456_8; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:42:26 @@ -85,8 +92,9 @@ LL | let bad32_suf: f32 = 1.123_456_789_f32; | help: consider changing the type or truncating it to | -LL | let bad32_suf: f32 = 1.123_456_8_f32; - | ~~~~~~~~~~~~~~~ +LL - let bad32_suf: f32 = 1.123_456_789_f32; +LL + let bad32_suf: f32 = 1.123_456_8_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:43:21 @@ -96,8 +104,9 @@ LL | let bad32_inf = 1.123_456_789_f32; | help: consider changing the type or truncating it to | -LL | let bad32_inf = 1.123_456_8_f32; - | ~~~~~~~~~~~~~~~ +LL - let bad32_inf = 1.123_456_789_f32; +LL + let bad32_inf = 1.123_456_8_f32; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:53:36 @@ -107,8 +116,9 @@ LL | let bad_vec32: Vec = vec![0.123_456_789]; | help: consider changing the type or truncating it to | -LL | let bad_vec32: Vec = vec![0.123_456_79]; - | ~~~~~~~~~~~~ +LL - let bad_vec32: Vec = vec![0.123_456_789]; +LL + let bad_vec32: Vec = vec![0.123_456_79]; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:54:36 @@ -118,8 +128,9 @@ LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; | help: consider changing the type or truncating it to | -LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; +LL + let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:58:24 @@ -129,8 +140,9 @@ LL | let bad_e32: f32 = 1.123_456_788_888e-10; | help: consider changing the type or truncating it to | -LL | let bad_e32: f32 = 1.123_456_8e-10; - | ~~~~~~~~~~~~~~~ +LL - let bad_e32: f32 = 1.123_456_788_888e-10; +LL + let bad_e32: f32 = 1.123_456_8e-10; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:61:27 @@ -140,8 +152,9 @@ LL | let bad_bige32: f32 = 1.123_456_788_888E-10; | help: consider changing the type or truncating it to | -LL | let bad_bige32: f32 = 1.123_456_8E-10; - | ~~~~~~~~~~~~~~~ +LL - let bad_bige32: f32 = 1.123_456_788_888E-10; +LL + let bad_bige32: f32 = 1.123_456_8E-10; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:70:13 @@ -151,8 +164,9 @@ LL | let _ = 2.225_073_858_507_201_1e-308_f64; | help: consider changing the type or truncating it to | -LL | let _ = 2.225_073_858_507_201e-308_f64; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = 2.225_073_858_507_201_1e-308_f64; +LL + let _ = 2.225_073_858_507_201e-308_f64; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:73:13 @@ -162,8 +176,9 @@ LL | let _ = 1.000_000_000_000_001e-324_f64; | help: consider changing the type or truncating it to | -LL | let _ = 0_f64; - | ~~~~~ +LL - let _ = 1.000_000_000_000_001e-324_f64; +LL + let _ = 0_f64; + | error: float has excessive precision --> tests/ui/excessive_precision.rs:83:20 @@ -173,8 +188,9 @@ LL | const _: f64 = 3.0000000000000000e+00; | help: consider changing the type or truncating it to | -LL | const _: f64 = 3.0; - | ~~~ +LL - const _: f64 = 3.0000000000000000e+00; +LL + const _: f64 = 3.0; + | error: aborting due to 16 previous errors diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index a05b7138bc99..c069c9d1672d 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -8,8 +8,9 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` help: did you mean to invoke the function? | -LL | let _ = foo() as i8; - | ~~~~~~~~~~~ +LL - let _ = foo as i8; +LL + let _ = foo() as i8; + | error: casting function pointer `foo` to `i16` --> tests/ui/fn_to_numeric_cast_any.rs:26:13 @@ -19,8 +20,9 @@ LL | let _ = foo as i16; | help: did you mean to invoke the function? | -LL | let _ = foo() as i16; - | ~~~~~~~~~~~~ +LL - let _ = foo as i16; +LL + let _ = foo() as i16; + | error: casting function pointer `foo` to `i32` --> tests/ui/fn_to_numeric_cast_any.rs:28:13 @@ -30,8 +32,9 @@ LL | let _ = foo as i32; | help: did you mean to invoke the function? | -LL | let _ = foo() as i32; - | ~~~~~~~~~~~~ +LL - let _ = foo as i32; +LL + let _ = foo() as i32; + | error: casting function pointer `foo` to `i64` --> tests/ui/fn_to_numeric_cast_any.rs:30:13 @@ -41,8 +44,9 @@ LL | let _ = foo as i64; | help: did you mean to invoke the function? | -LL | let _ = foo() as i64; - | ~~~~~~~~~~~~ +LL - let _ = foo as i64; +LL + let _ = foo() as i64; + | error: casting function pointer `foo` to `i128` --> tests/ui/fn_to_numeric_cast_any.rs:32:13 @@ -52,8 +56,9 @@ LL | let _ = foo as i128; | help: did you mean to invoke the function? | -LL | let _ = foo() as i128; - | ~~~~~~~~~~~~~ +LL - let _ = foo as i128; +LL + let _ = foo() as i128; + | error: casting function pointer `foo` to `isize` --> tests/ui/fn_to_numeric_cast_any.rs:34:13 @@ -63,8 +68,9 @@ LL | let _ = foo as isize; | help: did you mean to invoke the function? | -LL | let _ = foo() as isize; - | ~~~~~~~~~~~~~~ +LL - let _ = foo as isize; +LL + let _ = foo() as isize; + | error: casting function pointer `foo` to `u8` --> tests/ui/fn_to_numeric_cast_any.rs:37:13 @@ -74,8 +80,9 @@ LL | let _ = foo as u8; | help: did you mean to invoke the function? | -LL | let _ = foo() as u8; - | ~~~~~~~~~~~ +LL - let _ = foo as u8; +LL + let _ = foo() as u8; + | error: casting function pointer `foo` to `u16` --> tests/ui/fn_to_numeric_cast_any.rs:39:13 @@ -85,8 +92,9 @@ LL | let _ = foo as u16; | help: did you mean to invoke the function? | -LL | let _ = foo() as u16; - | ~~~~~~~~~~~~ +LL - let _ = foo as u16; +LL + let _ = foo() as u16; + | error: casting function pointer `foo` to `u32` --> tests/ui/fn_to_numeric_cast_any.rs:41:13 @@ -96,8 +104,9 @@ LL | let _ = foo as u32; | help: did you mean to invoke the function? | -LL | let _ = foo() as u32; - | ~~~~~~~~~~~~ +LL - let _ = foo as u32; +LL + let _ = foo() as u32; + | error: casting function pointer `foo` to `u64` --> tests/ui/fn_to_numeric_cast_any.rs:43:13 @@ -107,8 +116,9 @@ LL | let _ = foo as u64; | help: did you mean to invoke the function? | -LL | let _ = foo() as u64; - | ~~~~~~~~~~~~ +LL - let _ = foo as u64; +LL + let _ = foo() as u64; + | error: casting function pointer `foo` to `u128` --> tests/ui/fn_to_numeric_cast_any.rs:45:13 @@ -118,8 +128,9 @@ LL | let _ = foo as u128; | help: did you mean to invoke the function? | -LL | let _ = foo() as u128; - | ~~~~~~~~~~~~~ +LL - let _ = foo as u128; +LL + let _ = foo() as u128; + | error: casting function pointer `foo` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:47:13 @@ -129,8 +140,9 @@ LL | let _ = foo as usize; | help: did you mean to invoke the function? | -LL | let _ = foo() as usize; - | ~~~~~~~~~~~~~~ +LL - let _ = foo as usize; +LL + let _ = foo() as usize; + | error: casting function pointer `Struct::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:52:13 @@ -140,8 +152,9 @@ LL | let _ = Struct::static_method as usize; | help: did you mean to invoke the function? | -LL | let _ = Struct::static_method() as usize; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Struct::static_method as usize; +LL + let _ = Struct::static_method() as usize; + | error: casting function pointer `f` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:57:5 @@ -151,7 +164,8 @@ LL | f as usize | help: did you mean to invoke the function? | -LL | f() as usize +LL - f as usize +LL + f() as usize | error: casting function pointer `T::static_method` to `usize` @@ -162,7 +176,8 @@ LL | T::static_method as usize | help: did you mean to invoke the function? | -LL | T::static_method() as usize +LL - T::static_method as usize +LL + T::static_method() as usize | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` @@ -173,8 +188,9 @@ LL | let _ = (clos as fn(u32) -> u32) as usize; | help: did you mean to invoke the function? | -LL | let _ = (clos as fn(u32) -> u32)() as usize; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = (clos as fn(u32) -> u32) as usize; +LL + let _ = (clos as fn(u32) -> u32)() as usize; + | error: casting function pointer `foo` to `*const ()` --> tests/ui/fn_to_numeric_cast_any.rs:74:13 @@ -184,8 +200,9 @@ LL | let _ = foo as *const (); | help: did you mean to invoke the function? | -LL | let _ = foo() as *const (); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = foo as *const (); +LL + let _ = foo() as *const (); + | error: aborting due to 17 previous errors diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index adcc3ab8fdb9..11b61c8cbc64 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -8,8 +8,9 @@ LL | for (_, v) in &m { = help: to override `-D warnings` add `#[allow(clippy::for_kv_map)]` help: use the corresponding method | -LL | for v in m.values() { - | ~ ~~~~~~~~~~ +LL - for (_, v) in &m { +LL + for v in m.values() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:16:19 @@ -19,8 +20,9 @@ LL | for (_, v) in &*m { | help: use the corresponding method | -LL | for v in (*m).values() { - | ~ ~~~~~~~~~~~~~ +LL - for (_, v) in &*m { +LL + for v in (*m).values() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:25:19 @@ -30,8 +32,9 @@ LL | for (_, v) in &mut m { | help: use the corresponding method | -LL | for v in m.values_mut() { - | ~ ~~~~~~~~~~~~~~ +LL - for (_, v) in &mut m { +LL + for v in m.values_mut() { + | error: you seem to want to iterate on a map's values --> tests/ui/for_kv_map.rs:31:19 @@ -41,8 +44,9 @@ LL | for (_, v) in &mut *m { | help: use the corresponding method | -LL | for v in (*m).values_mut() { - | ~ ~~~~~~~~~~~~~~~~~ +LL - for (_, v) in &mut *m { +LL + for v in (*m).values_mut() { + | error: you seem to want to iterate on a map's keys --> tests/ui/for_kv_map.rs:38:24 @@ -52,8 +56,9 @@ LL | for (k, _value) in rm { | help: use the corresponding method | -LL | for k in rm.keys() { - | ~ ~~~~~~~~~ +LL - for (k, _value) in rm { +LL + for k in rm.keys() { + | error: you seem to want to iterate on a map's keys --> tests/ui/for_kv_map.rs:45:32 @@ -63,8 +68,9 @@ LL | 'label: for (k, _value) in rm { | help: use the corresponding method | -LL | 'label: for k in rm.keys() { - | ~ ~~~~~~~~~ +LL - 'label: for (k, _value) in rm { +LL + 'label: for k in rm.keys() { + | error: aborting due to 6 previous errors diff --git a/tests/ui/four_forward_slashes.stderr b/tests/ui/four_forward_slashes.stderr index 3606a2227a00..d5bf71fadc7d 100644 --- a/tests/ui/four_forward_slashes.stderr +++ b/tests/ui/four_forward_slashes.stderr @@ -9,6 +9,8 @@ LL | | fn a() {} = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | +LL - //// whoops +LL - fn a() {} LL + /// whoops | @@ -22,6 +24,8 @@ LL | | fn b() {} | help: make this a doc comment by removing one `/` | +LL - //// whoops +LL - #[allow(dead_code)] LL + /// whoops | @@ -50,6 +54,8 @@ LL | | fn g() {} | help: make this a doc comment by removing one `/` | +LL - //// between attributes +LL - #[allow(dead_code)] LL + /// between attributes | @@ -62,6 +68,8 @@ LL | | fn h() {} | help: make this a doc comment by removing one `/` | +LL - //// not very start of contents +LL - fn h() {} LL + /// not very start of contents | diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index 81732346412a..83bfb60eb16f 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -9,6 +9,8 @@ LL | | fn a() {} = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | +LL - //// borked doc comment on the first line. doesn't combust! +LL - fn a() {} LL + /// borked doc comment on the first line. doesn't combust! | diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 8eacb249c60c..fc6c0b9299c4 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::get_unwrap)] | ^^^^^^^^^^^^^^^^^^ help: using `[]` is clearer and more concise | -LL | let _ = &boxed_slice[1]; - | ~~~~~~~~~~~~~~~ +LL - let _ = boxed_slice.get(1).unwrap(); +LL + let _ = &boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:37:17 @@ -33,8 +34,9 @@ LL | let _ = some_slice.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_slice[0]; - | ~~~~~~~~~~~~~~ +LL - let _ = some_slice.get(0).unwrap(); +LL + let _ = &some_slice[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:38:17 @@ -53,8 +55,9 @@ LL | let _ = some_vec.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vec[0]; - | ~~~~~~~~~~~~ +LL - let _ = some_vec.get(0).unwrap(); +LL + let _ = &some_vec[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:39:17 @@ -73,8 +76,9 @@ LL | let _ = some_vecdeque.get(0).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_vecdeque[0]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_vecdeque.get(0).unwrap(); +LL + let _ = &some_vecdeque[0]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:40:17 @@ -93,8 +97,9 @@ LL | let _ = some_hashmap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_hashmap[&1]; - | ~~~~~~~~~~~~~~~~~ +LL - let _ = some_hashmap.get(&1).unwrap(); +LL + let _ = &some_hashmap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:41:17 @@ -113,8 +118,9 @@ LL | let _ = some_btreemap.get(&1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _ = &some_btreemap[&1]; - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = some_btreemap.get(&1).unwrap(); +LL + let _ = &some_btreemap[&1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:42:17 @@ -133,8 +139,9 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _: u8 = boxed_slice[1]; - | ~~~~~~~~~~~~~~ +LL - let _: u8 = *boxed_slice.get(1).unwrap(); +LL + let _: u8 = boxed_slice[1]; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:46:22 @@ -153,8 +160,9 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | boxed_slice[0] = 1; - | ~~~~~~~~~~~~~~ +LL - *boxed_slice.get_mut(0).unwrap() = 1; +LL + boxed_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:51:10 @@ -173,8 +181,9 @@ LL | *some_slice.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_slice[0] = 1; - | ~~~~~~~~~~~~~ +LL - *some_slice.get_mut(0).unwrap() = 1; +LL + some_slice[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:52:10 @@ -193,8 +202,9 @@ LL | *some_vec.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vec[0] = 1; - | ~~~~~~~~~~~ +LL - *some_vec.get_mut(0).unwrap() = 1; +LL + some_vec[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:53:10 @@ -213,8 +223,9 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; | help: using `[]` is clearer and more concise | -LL | some_vecdeque[0] = 1; - | ~~~~~~~~~~~~~~~~ +LL - *some_vecdeque.get_mut(0).unwrap() = 1; +LL + some_vecdeque[0] = 1; + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:54:10 @@ -233,8 +244,9 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:66:17 @@ -253,8 +265,9 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | help: using `[]` is clearer and more concise | -LL | let _ = some_vec[0..1].to_vec(); - | ~~~~~~~~~~~~~~ +LL - let _ = some_vec.get_mut(0..1).unwrap().to_vec(); +LL + let _ = some_vec[0..1].to_vec(); + | error: used `unwrap()` on an `Option` value --> tests/ui/get_unwrap.rs:67:17 @@ -273,8 +286,9 @@ LL | let _x: &i32 = f.get(1 + 2).unwrap(); | help: using `[]` is clearer and more concise | -LL | let _x: &i32 = &f[1 + 2]; - | ~~~~~~~~~ +LL - let _x: &i32 = f.get(1 + 2).unwrap(); +LL + let _x: &i32 = &f[1 + 2]; + | error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:81:18 @@ -284,8 +298,9 @@ LL | let _x = f.get(1 + 2).unwrap().to_string(); | help: using `[]` is clearer and more concise | -LL | let _x = f[1 + 2].to_string(); - | ~~~~~~~~ +LL - let _x = f.get(1 + 2).unwrap().to_string(); +LL + let _x = f[1 + 2].to_string(); + | error: called `.get().unwrap()` on a slice --> tests/ui/get_unwrap.rs:84:18 @@ -295,8 +310,9 @@ LL | let _x = f.get(1 + 2).unwrap().abs(); | help: using `[]` is clearer and more concise | -LL | let _x = f[1 + 2].abs(); - | ~~~~~~~~ +LL - let _x = f.get(1 + 2).unwrap().abs(); +LL + let _x = f[1 + 2].abs(); + | error: called `.get_mut().unwrap()` on a slice --> tests/ui/get_unwrap.rs:101:33 @@ -306,8 +322,9 @@ LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - | help: using `[]` is clearer and more concise | -LL | let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); +LL + let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; + | error: aborting due to 30 previous errors diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 442f4789aacf..6e964c65a2e4 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -78,8 +78,9 @@ LL | pub fn map(map: &mut HashMap) {} | help: add a type parameter for `BuildHasher` | -LL | pub fn map(map: &mut HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ +LL - pub fn map(map: &mut HashMap) {} +LL + pub fn map(map: &mut HashMap) {} + | error: parameter of type `HashSet` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:70:22 @@ -89,8 +90,9 @@ LL | pub fn set(set: &mut HashSet) {} | help: add a type parameter for `BuildHasher` | -LL | pub fn set(set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ +LL - pub fn set(set: &mut HashSet) {} +LL + pub fn set(set: &mut HashSet) {} + | error: impl for `HashMap` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:76:43 @@ -114,8 +116,9 @@ LL | pub async fn election_vote(_data: HashMap) {} | help: add a type parameter for `BuildHasher` | -LL | pub async fn election_vote(_data: HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ +LL - pub async fn election_vote(_data: HashMap) {} +LL + pub async fn election_vote(_data: HashMap) {} + | error: aborting due to 9 previous errors diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 3b06f26f5a05..0d2faa5e067b 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -8,7 +8,8 @@ LL | true = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` help: add `return` as shown | -LL | return true +LL - true +LL + return true | error: missing `return` statement @@ -19,8 +20,9 @@ LL | if true { true } else { false } | help: add `return` as shown | -LL | if true { return true } else { false } - | ~~~~~~~~~~~ +LL - if true { true } else { false } +LL + if true { return true } else { false } + | error: missing `return` statement --> tests/ui/implicit_return.rs:19:29 @@ -30,8 +32,9 @@ LL | if true { true } else { false } | help: add `return` as shown | -LL | if true { true } else { return false } - | ~~~~~~~~~~~~ +LL - if true { true } else { false } +LL + if true { true } else { return false } + | error: missing `return` statement --> tests/ui/implicit_return.rs:25:17 @@ -41,8 +44,9 @@ LL | true => false, | help: add `return` as shown | -LL | true => return false, - | ~~~~~~~~~~~~ +LL - true => false, +LL + true => return false, + | error: missing `return` statement --> tests/ui/implicit_return.rs:26:20 @@ -52,8 +56,9 @@ LL | false => { true }, | help: add `return` as shown | -LL | false => { return true }, - | ~~~~~~~~~~~ +LL - false => { true }, +LL + false => { return true }, + | error: missing `return` statement --> tests/ui/implicit_return.rs:39:9 @@ -63,8 +68,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:46:13 @@ -74,8 +80,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:54:13 @@ -85,8 +92,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:72:18 @@ -96,8 +104,9 @@ LL | let _ = || { true }; | help: add `return` as shown | -LL | let _ = || { return true }; - | ~~~~~~~~~~~ +LL - let _ = || { true }; +LL + let _ = || { return true }; + | error: missing `return` statement --> tests/ui/implicit_return.rs:73:16 @@ -107,8 +116,9 @@ LL | let _ = || true; | help: add `return` as shown | -LL | let _ = || return true; - | ~~~~~~~~~~~ +LL - let _ = || true; +LL + let _ = || return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:81:5 @@ -118,7 +128,8 @@ LL | format!("test {}", "test") | help: add `return` as shown | -LL | return format!("test {}", "test") +LL - format!("test {}", "test") +LL + return format!("test {}", "test") | error: missing `return` statement @@ -129,7 +140,8 @@ LL | m!(true, false) | help: add `return` as shown | -LL | return m!(true, false) +LL - m!(true, false) +LL + return m!(true, false) | error: missing `return` statement @@ -140,8 +152,9 @@ LL | break true; | help: change `break` to `return` as shown | -LL | return true; - | ~~~~~~~~~~~ +LL - break true; +LL + return true; + | error: missing `return` statement --> tests/ui/implicit_return.rs:101:17 @@ -151,8 +164,9 @@ LL | break 'outer false; | help: change `break` to `return` as shown | -LL | return false; - | ~~~~~~~~~~~~ +LL - break 'outer false; +LL + return false; + | error: missing `return` statement --> tests/ui/implicit_return.rs:116:5 @@ -177,7 +191,8 @@ LL | true | help: add `return` as shown | -LL | return true +LL - true +LL + return true | error: aborting due to 16 previous errors diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index 178463f53475..1167a604ecdc 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -8,8 +8,9 @@ LL | let bad_vec = some_vec.iter().nth(3); = help: to override `-D warnings` add `#[allow(clippy::iter_nth)]` help: `get` is equivalent but more concise | -LL | let bad_vec = some_vec.get(3); - | ~~~ +LL - let bad_vec = some_vec.iter().nth(3); +LL + let bad_vec = some_vec.get(3); + | error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:35:26 @@ -19,8 +20,9 @@ LL | let bad_slice = &some_vec[..].iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_slice = &some_vec[..].get(3); - | ~~~ +LL - let bad_slice = &some_vec[..].iter().nth(3); +LL + let bad_slice = &some_vec[..].get(3); + | error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:36:31 @@ -30,8 +32,9 @@ LL | let bad_boxed_slice = boxed_slice.iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_boxed_slice = boxed_slice.get(3); - | ~~~ +LL - let bad_boxed_slice = boxed_slice.iter().nth(3); +LL + let bad_boxed_slice = boxed_slice.get(3); + | error: called `.iter().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:37:29 @@ -41,8 +44,9 @@ LL | let bad_vec_deque = some_vec_deque.iter().nth(3); | help: `get` is equivalent but more concise | -LL | let bad_vec_deque = some_vec_deque.get(3); - | ~~~ +LL - let bad_vec_deque = some_vec_deque.iter().nth(3); +LL + let bad_vec_deque = some_vec_deque.get(3); + | error: called `.iter_mut().nth()` on a `Vec` --> tests/ui/iter_nth.rs:42:23 @@ -52,8 +56,9 @@ LL | let bad_vec = some_vec.iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_vec = some_vec.get_mut(3); - | ~~~~~~~ +LL - let bad_vec = some_vec.iter_mut().nth(3); +LL + let bad_vec = some_vec.get_mut(3); + | error: called `.iter_mut().nth()` on a slice --> tests/ui/iter_nth.rs:45:26 @@ -63,8 +68,9 @@ LL | let bad_slice = &some_vec[..].iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_slice = &some_vec[..].get_mut(3); - | ~~~~~~~ +LL - let bad_slice = &some_vec[..].iter_mut().nth(3); +LL + let bad_slice = &some_vec[..].get_mut(3); + | error: called `.iter_mut().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:48:29 @@ -74,8 +80,9 @@ LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); | help: `get_mut` is equivalent but more concise | -LL | let bad_vec_deque = some_vec_deque.get_mut(3); - | ~~~~~~~ +LL - let bad_vec_deque = some_vec_deque.iter_mut().nth(3); +LL + let bad_vec_deque = some_vec_deque.get_mut(3); + | error: called `.iter().nth()` on a `Vec` --> tests/ui/iter_nth.rs:52:5 @@ -85,8 +92,9 @@ LL | vec_ref.iter().nth(3); | help: `get` is equivalent but more concise | -LL | vec_ref.get(3); - | ~~~ +LL - vec_ref.iter().nth(3); +LL + vec_ref.get(3); + | error: aborting due to 8 previous errors diff --git a/tests/ui/join_absolute_paths.stderr b/tests/ui/join_absolute_paths.stderr index e7fd5508823a..300946bf3b5f 100644 --- a/tests/ui/join_absolute_paths.stderr +++ b/tests/ui/join_absolute_paths.stderr @@ -9,12 +9,14 @@ LL | path.join("/sh"); = help: to override `-D warnings` add `#[allow(clippy::join_absolute_paths)]` help: if this is unintentional, try removing the starting separator | -LL | path.join("sh"); - | ~~~~ +LL - path.join("/sh"); +LL + path.join("sh"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("/sh"); - | ~~~~~~~~~~~~~~~~~~~~ +LL - path.join("/sh"); +LL + PathBuf::from("/sh"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:14:15 @@ -25,12 +27,14 @@ LL | path.join("\\user"); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join("\user"); - | ~~~~~~~ +LL - path.join("\\user"); +LL + path.join("\user"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("\\user"); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - path.join("\\user"); +LL + PathBuf::from("\\user"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:18:15 @@ -41,12 +45,14 @@ LL | path.join("/sh"); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join("sh"); - | ~~~~ +LL - path.join("/sh"); +LL + path.join("sh"); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from("/sh"); - | ~~~~~~~~~~~~~~~~~~~~ +LL - path.join("/sh"); +LL + PathBuf::from("/sh"); + | error: argument to `Path::join` starts with a path separator --> tests/ui/join_absolute_paths.rs:22:15 @@ -57,12 +63,14 @@ LL | path.join(r#"/sh"#); = note: joining a path starting with separator will replace the path instead help: if this is unintentional, try removing the starting separator | -LL | path.join(r#"sh"#); - | ~~~~~~~ +LL - path.join(r#"/sh"#); +LL + path.join(r#"sh"#); + | help: if this is intentional, consider using `Path::new` | -LL | PathBuf::from(r#"/sh"#); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - path.join(r#"/sh"#); +LL + PathBuf::from(r#"/sh"#); + | error: aborting due to 4 previous errors diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index 805cb406f834..60653b4abfb5 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -13,8 +13,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[i32; 8000]>), - | ~~~~~~~~~~~~~~~~ +LL - B([i32; 8000]), +LL + B(Box<[i32; 8000]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:35:1 @@ -29,8 +30,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingLargeEnum(Box), - | ~~~~~~~~~~~~~~ +LL - ContainingLargeEnum(LargeEnum), +LL + ContainingLargeEnum(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:40:1 @@ -46,8 +48,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), +LL + ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:46:1 @@ -62,8 +65,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge { x: [i32; 8000], y: i32 }, +LL + StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:51:1 @@ -78,8 +82,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge2 { x: [i32; 8000] }, +LL + StructLikeLarge2 { x: Box<[i32; 8000]> }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:67:1 @@ -95,8 +100,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 1255]>), - | ~~~~~~~~~~~~~~~ +LL - B([u8; 1255]), +LL + B(Box<[u8; 1255]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:73:1 @@ -111,8 +117,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), +LL + ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:78:1 @@ -127,8 +134,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:83:1 @@ -143,8 +151,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:88:1 @@ -159,8 +168,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:103:1 @@ -241,8 +251,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<(T, [u8; 512])>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large((T, [u8; 512])), +LL + Large(Box<(T, [u8; 512])>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:143:1 @@ -257,8 +268,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[Foo; 64]>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large([Foo; 64]), +LL + Large(Box<[Foo; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:153:1 @@ -273,8 +285,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(PossiblyLargeEnumWithConst<256>), +LL + Error(Box>), + | error: aborting due to 16 previous errors diff --git a/tests/ui/legacy_numeric_constants.stderr b/tests/ui/legacy_numeric_constants.stderr index 267b9ac8e4d1..74fe09e0f5c6 100644 --- a/tests/ui/legacy_numeric_constants.stderr +++ b/tests/ui/legacy_numeric_constants.stderr @@ -8,8 +8,9 @@ LL | std::f32::EPSILON; = help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]` help: use the associated constant instead | -LL | f32::EPSILON; - | ~~~~~~~~~~~~ +LL - std::f32::EPSILON; +LL + f32::EPSILON; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:34:5 @@ -19,8 +20,9 @@ LL | std::u8::MIN; | help: use the associated constant instead | -LL | u8::MIN; - | ~~~~~~~ +LL - std::u8::MIN; +LL + u8::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:37:5 @@ -30,8 +32,9 @@ LL | std::usize::MIN; | help: use the associated constant instead | -LL | usize::MIN; - | ~~~~~~~~~~ +LL - std::usize::MIN; +LL + usize::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:40:5 @@ -41,8 +44,9 @@ LL | std::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - std::u32::MAX; +LL + u32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:43:5 @@ -52,8 +56,9 @@ LL | core::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - core::u32::MAX; +LL + u32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:46:5 @@ -63,8 +68,9 @@ LL | MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - MAX; +LL + u32::MAX; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:49:10 @@ -74,8 +80,9 @@ LL | i32::max_value(); | help: use the associated constant instead | -LL | i32::MAX; - | ~~~ +LL - i32::max_value(); +LL + i32::MAX; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:52:9 @@ -85,8 +92,9 @@ LL | u8::max_value(); | help: use the associated constant instead | -LL | u8::MAX; - | ~~~ +LL - u8::max_value(); +LL + u8::MAX; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:55:9 @@ -96,8 +104,9 @@ LL | u8::min_value(); | help: use the associated constant instead | -LL | u8::MIN; - | ~~~ +LL - u8::min_value(); +LL + u8::MIN; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:58:5 @@ -107,8 +116,9 @@ LL | ::std::u8::MIN; | help: use the associated constant instead | -LL | u8::MIN; - | ~~~~~~~ +LL - ::std::u8::MIN; +LL + u8::MIN; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:61:27 @@ -118,8 +128,9 @@ LL | ::std::primitive::u8::min_value(); | help: use the associated constant instead | -LL | ::std::primitive::u8::MIN; - | ~~~ +LL - ::std::primitive::u8::min_value(); +LL + ::std::primitive::u8::MIN; + | error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:64:26 @@ -129,8 +140,9 @@ LL | std::primitive::i32::max_value(); | help: use the associated constant instead | -LL | std::primitive::i32::MAX; - | ~~~ +LL - std::primitive::i32::max_value(); +LL + std::primitive::i32::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:67:5 @@ -140,8 +152,9 @@ LL | self::a::u128::MAX; | help: use the associated constant instead | -LL | u128::MAX; - | ~~~~~~~~~ +LL - self::a::u128::MAX; +LL + u128::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:17:25 @@ -155,8 +168,9 @@ LL | b!(); = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) help: use the associated constant instead | -LL | let x = u64::MAX; - | ~~~~~~~~ +LL - let x = std::u64::MAX; +LL + let x = u64::MAX; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:81:14 @@ -166,8 +180,9 @@ LL | [(0, "", std::i128::MAX)]; | help: use the associated constant instead | -LL | [(0, "", i128::MAX)]; - | ~~~~~~~~~ +LL - [(0, "", std::i128::MAX)]; +LL + [(0, "", i128::MAX)]; + | error: usage of a legacy numeric constant --> tests/ui/legacy_numeric_constants.rs:115:5 @@ -177,8 +192,9 @@ LL | std::u32::MAX; | help: use the associated constant instead | -LL | u32::MAX; - | ~~~~~~~~ +LL - std::u32::MAX; +LL + u32::MAX; + | error: aborting due to 16 previous errors diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 564e0bc4f747..a9192825b354 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -71,12 +71,14 @@ LL | let fail_multi_zero = 000_123usize; = help: to override `-D warnings` add `#[allow(clippy::zero_prefixed_literal)]` help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let fail_multi_zero = 123usize; - | ~~~~~~~~ +LL - let fail_multi_zero = 000_123usize; +LL + let fail_multi_zero = 123usize; + | help: if you mean to use an octal constant, use `0o` | -LL | let fail_multi_zero = 0o123usize; - | ~~~~~~~~~~ +LL - let fail_multi_zero = 000_123usize; +LL + let fail_multi_zero = 0o123usize; + | error: integer type suffix should not be separated by an underscore --> tests/ui/literals.rs:36:16 @@ -92,12 +94,14 @@ LL | let fail8 = 0123; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let fail8 = 123; - | ~~~ +LL - let fail8 = 0123; +LL + let fail8 = 123; + | help: if you mean to use an octal constant, use `0o` | -LL | let fail8 = 0o123; - | ~~~~~ +LL - let fail8 = 0123; +LL + let fail8 = 0o123; + | error: integer type suffix should not be separated by an underscore --> tests/ui/literals.rs:48:16 @@ -143,8 +147,9 @@ LL | let _ = 08; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 8; - | ~ +LL - let _ = 08; +LL + let _ = 8; + | error: this is a decimal constant --> tests/ui/literals.rs:72:13 @@ -154,8 +159,9 @@ LL | let _ = 09; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 9; - | ~ +LL - let _ = 09; +LL + let _ = 9; + | error: this is a decimal constant --> tests/ui/literals.rs:74:13 @@ -165,8 +171,9 @@ LL | let _ = 089; | help: if you mean to use a decimal constant, remove the `0` to avoid confusion | -LL | let _ = 89; - | ~~ +LL - let _ = 089; +LL + let _ = 89; + | error: aborting due to 20 previous errors diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index 3026854e317a..118351a62d00 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -8,8 +8,9 @@ LL | let _: f32 = 16_777_217.0; = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_216.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_217.0; +LL + let _: f32 = 16_777_216.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:15:18 @@ -19,8 +20,9 @@ LL | let _: f32 = 16_777_219.0; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.0; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:16:18 @@ -30,8 +32,9 @@ LL | let _: f32 = 16_777_219.; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:17:18 @@ -41,8 +44,9 @@ LL | let _: f32 = 16_777_219.000; | help: consider changing the type or replacing it with | -LL | let _: f32 = 16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = 16_777_219.000; +LL + let _: f32 = 16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:18:13 @@ -52,8 +56,9 @@ LL | let _ = 16_777_219f32; | help: consider changing the type or replacing it with | -LL | let _ = 16_777_220_f32; - | ~~~~~~~~~~~~~~ +LL - let _ = 16_777_219f32; +LL + let _ = 16_777_220_f32; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:19:19 @@ -63,8 +68,9 @@ LL | let _: f32 = -16_777_219.0; | help: consider changing the type or replacing it with | -LL | let _: f32 = -16_777_220.0; - | ~~~~~~~~~~~~ +LL - let _: f32 = -16_777_219.0; +LL + let _: f32 = -16_777_220.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:21:18 @@ -74,8 +80,9 @@ LL | let _: f64 = 9_007_199_254_740_993.0; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.0; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:22:18 @@ -85,8 +92,9 @@ LL | let _: f64 = 9_007_199_254_740_993.; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:23:18 @@ -96,8 +104,9 @@ LL | let _: f64 = 9_007_199_254_740_993.00; | help: consider changing the type or replacing it with | -LL | let _: f64 = 9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = 9_007_199_254_740_993.00; +LL + let _: f64 = 9_007_199_254_740_992.0; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:24:13 @@ -107,8 +116,9 @@ LL | let _ = 9_007_199_254_740_993f64; | help: consider changing the type or replacing it with | -LL | let _ = 9_007_199_254_740_992_f64; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = 9_007_199_254_740_993f64; +LL + let _ = 9_007_199_254_740_992_f64; + | error: literal cannot be represented as the underlying type without loss of precision --> tests/ui/lossy_float_literal.rs:25:19 @@ -118,8 +128,9 @@ LL | let _: f64 = -9_007_199_254_740_993.0; | help: consider changing the type or replacing it with | -LL | let _: f64 = -9_007_199_254_740_992.0; - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: f64 = -9_007_199_254_740_993.0; +LL + let _: f64 = -9_007_199_254_740_992.0; + | error: aborting due to 11 previous errors diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 004463720e26..dfccf7e99396 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -79,7 +79,15 @@ LL | | } | help: try instead | -LL | assert!(!(a > 2), "panic with comment"); +LL - if a > 2 { +LL - // comment +LL - /* this is a +LL - multiline +LL - comment */ +LL - /// Doc comment +LL - panic!("panic with comment") // comment after `panic!` +LL - } +LL + assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 004463720e26..dfccf7e99396 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -79,7 +79,15 @@ LL | | } | help: try instead | -LL | assert!(!(a > 2), "panic with comment"); +LL - if a > 2 { +LL - // comment +LL - /* this is a +LL - multiline +LL - comment */ +LL - /// Doc comment +LL - panic!("panic with comment") // comment after `panic!` +LL - } +LL + assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index 68a97243436d..a7cfc30fb69c 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -8,8 +8,9 @@ LL | fn fut() -> impl Future { = help: to override `-D warnings` add `#[allow(clippy::manual_async_fn)]` help: make the function `async` and return the output of the future directly | -LL | async fn fut() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut() -> impl Future { +LL + async fn fut() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:11:1 @@ -19,8 +20,9 @@ LL | fn fut2() ->impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn fut2() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut2() ->impl Future { +LL + async fn fut2() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:16:1 @@ -30,8 +32,9 @@ LL | fn fut3()-> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn fut3() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn fut3()-> impl Future { +LL + async fn fut3() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:20:1 @@ -41,8 +44,9 @@ LL | fn empty_fut() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut() {} - | ~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut() -> impl Future { +LL + async fn empty_fut() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:25:1 @@ -52,8 +56,9 @@ LL | fn empty_fut2() ->impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut2() {} - | ~~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut2() ->impl Future { +LL + async fn empty_fut2() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:30:1 @@ -63,8 +68,9 @@ LL | fn empty_fut3()-> impl Future { | help: make the function `async` and return the output of the future directly | -LL | async fn empty_fut3() {} - | ~~~~~~~~~~~~~~~~~~~~~ ~~ +LL - fn empty_fut3()-> impl Future { +LL + async fn empty_fut3() {} + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:34:1 @@ -74,8 +80,9 @@ LL | fn core_fut() -> impl core::future::Future { | help: make the function `async` and return the output of the future directly | -LL | async fn core_fut() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn core_fut() -> impl core::future::Future { +LL + async fn core_fut() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:56:5 @@ -108,8 +115,9 @@ LL | fn elided(_: &i32) -> impl Future + '_ { | help: make the function `async` and return the output of the future directly | -LL | async fn elided(_: &i32) -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn elided(_: &i32) -> impl Future + '_ { +LL + async fn elided(_: &i32) -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:101:1 @@ -119,8 +127,9 @@ LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + | help: make the function `async` and return the output of the future directly | -LL | async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { +LL + async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:130:1 @@ -130,8 +139,9 @@ LL | pub fn issue_10450() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub async fn issue_10450() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub fn issue_10450() -> impl Future { +LL + pub async fn issue_10450() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:134:1 @@ -141,8 +151,9 @@ LL | pub(crate) fn issue_10450_2() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub(crate) async fn issue_10450_2() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub(crate) fn issue_10450_2() -> impl Future { +LL + pub(crate) async fn issue_10450_2() -> i32 { 42 } + | error: this function can be simplified using the `async fn` syntax --> tests/ui/manual_async_fn.rs:138:1 @@ -152,8 +163,9 @@ LL | pub(self) fn issue_10450_3() -> impl Future { | help: make the function `async` and return the output of the future directly | -LL | pub(self) async fn issue_10450_3() -> i32 { 42 } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ +LL - pub(self) fn issue_10450_3() -> impl Future { +LL + pub(self) async fn issue_10450_3() -> i32 { 42 } + | error: aborting due to 13 previous errors diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 676a4485ab4d..1352c5e73cab 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -17,16 +17,19 @@ LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_finite)]` help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != f32::INFINITY && x != f32::NEG_INFINITY {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:26:8 @@ -42,16 +45,19 @@ LL | if x != INFINITE && x != NEG_INFINITE {} | help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != INFINITE && x != NEG_INFINITE {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:29:8 @@ -67,16 +73,19 @@ LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | help: use the dedicated method instead | -LL | if x.is_finite() {} - | ~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if x.is_finite() {} + | help: this will alter how it handles NaN; if that is a problem, use instead | -LL | if x.is_finite() || x.is_nan() {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if x.is_finite() || x.is_nan() {} + | help: or, for conciseness | -LL | if !x.is_infinite() {} - | ~~~~~~~~~~~~~~~~ +LL - if x != f64::INFINITY && x != f64::NEG_INFINITY {} +LL + if !x.is_infinite() {} + | error: manually checking if a float is infinite --> tests/ui/manual_float_methods.rs:44:12 diff --git a/tests/ui/manual_ignore_case_cmp.stderr b/tests/ui/manual_ignore_case_cmp.stderr index 11e8b8aebb54..bc6393b66d5c 100644 --- a/tests/ui/manual_ignore_case_cmp.stderr +++ b/tests/ui/manual_ignore_case_cmp.stderr @@ -11,8 +11,9 @@ LL | #![deny(clippy::manual_ignore_case_cmp)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.eq_ignore_ascii_case()` instead | -LL | if a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_lowercase() == b.to_ascii_lowercase() { +LL + if a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:12:8 @@ -22,8 +23,9 @@ LL | if a.to_ascii_uppercase() == b.to_ascii_uppercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_uppercase() == b.to_ascii_uppercase() { +LL + if a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:15:13 @@ -33,8 +35,9 @@ LL | let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + let r = a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:16:18 @@ -44,8 +47,9 @@ LL | let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = r || a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); +LL + let r = r || a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:17:10 @@ -55,8 +59,9 @@ LL | r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | r && a.eq_ignore_ascii_case(&b.to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); +LL + r && a.eq_ignore_ascii_case(&b.to_uppercase()); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:19:8 @@ -66,8 +71,9 @@ LL | if a.to_ascii_lowercase() != b.to_ascii_lowercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if !a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_lowercase() != b.to_ascii_lowercase() { +LL + if !a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:22:8 @@ -77,8 +83,9 @@ LL | if a.to_ascii_uppercase() != b.to_ascii_uppercase() { | help: consider using `.eq_ignore_ascii_case()` instead | -LL | if !a.eq_ignore_ascii_case(b) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if a.to_ascii_uppercase() != b.to_ascii_uppercase() { +LL + if !a.eq_ignore_ascii_case(b) { + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:25:13 @@ -88,8 +95,9 @@ LL | let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = !a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); +LL + let r = !a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:26:18 @@ -99,8 +107,9 @@ LL | let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | let r = r || !a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); +LL + let r = r || !a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:27:10 @@ -110,8 +119,9 @@ LL | r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | r && !a.eq_ignore_ascii_case(&b.to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); +LL + r && !a.eq_ignore_ascii_case(&b.to_uppercase()); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:38:5 @@ -121,8 +131,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:41:5 @@ -132,8 +143,9 @@ LL | a.to_ascii_lowercase() == 'a'; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&'a'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == 'a'; +LL + a.eq_ignore_ascii_case(&'a'); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:42:5 @@ -143,8 +155,9 @@ LL | 'a' == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | 'a'.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - 'a' == b.to_ascii_lowercase(); +LL + 'a'.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:45:5 @@ -154,8 +167,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:46:5 @@ -165,8 +179,9 @@ LL | a.to_ascii_lowercase() == b'a'; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b'a'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b'a'; +LL + a.eq_ignore_ascii_case(&b'a'); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:47:5 @@ -176,8 +191,9 @@ LL | b'a' == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b'a'.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b'a' == b.to_ascii_lowercase(); +LL + b'a'.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:50:5 @@ -187,8 +203,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:51:5 @@ -198,8 +215,9 @@ LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.to_uppercase().eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:52:5 @@ -209,8 +227,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:53:5 @@ -220,8 +239,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:56:5 @@ -231,8 +251,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:57:5 @@ -242,8 +263,9 @@ LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.to_uppercase().eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:58:5 @@ -253,8 +275,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:59:5 @@ -264,8 +287,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:62:5 @@ -275,8 +299,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:63:5 @@ -286,8 +311,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:64:5 @@ -297,8 +323,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:67:5 @@ -308,8 +335,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:68:5 @@ -319,8 +347,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:71:5 @@ -330,8 +359,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:72:5 @@ -341,8 +371,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:73:5 @@ -352,8 +383,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:75:5 @@ -363,8 +395,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:76:5 @@ -374,8 +407,9 @@ LL | b.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == "a"; +LL + b.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:77:5 @@ -385,8 +419,9 @@ LL | "a" == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == a.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:80:5 @@ -396,8 +431,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:81:5 @@ -407,8 +443,9 @@ LL | a.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == "a"; +LL + a.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:82:5 @@ -418,8 +455,9 @@ LL | "a" == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == b.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:84:5 @@ -429,8 +467,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:85:5 @@ -440,8 +479,9 @@ LL | b.to_ascii_lowercase() == "a"; | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == "a"; +LL + b.eq_ignore_ascii_case("a"); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:86:5 @@ -451,8 +491,9 @@ LL | "a" == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "a" == a.to_ascii_lowercase(); +LL + "a".eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:89:5 @@ -462,8 +503,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:92:5 @@ -473,8 +515,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(&b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:95:5 @@ -484,8 +527,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:96:5 @@ -495,8 +539,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(&a); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:99:5 @@ -506,8 +551,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:102:5 @@ -517,8 +563,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:105:5 @@ -528,8 +575,9 @@ LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL + a.eq_ignore_ascii_case(b); + | error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:106:5 @@ -539,8 +587,9 @@ LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - b.to_ascii_lowercase() == a.to_ascii_lowercase(); +LL + b.eq_ignore_ascii_case(a); + | error: aborting due to 49 previous errors diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index 92d93208006a..7b3f0c938b0d 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -153,8 +153,9 @@ LL | take_while(|c| ('A'..='Z').contains(&c)); | help: try | -LL | take_while(|c: char| c.is_ascii_uppercase()); - | ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - take_while(|c| ('A'..='Z').contains(&c)); +LL + take_while(|c: char| c.is_ascii_uppercase()); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:82:20 @@ -164,8 +165,9 @@ LL | take_while(|c| (b'A'..=b'Z').contains(&c)); | help: try | -LL | take_while(|c: u8| c.is_ascii_uppercase()); - | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - take_while(|c| (b'A'..=b'Z').contains(&c)); +LL + take_while(|c: u8| c.is_ascii_uppercase()); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:83:26 @@ -181,8 +183,9 @@ LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').c | help: try | -LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ascii_digit()).collect(); - | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').contains(c)).collect(); +LL + let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ascii_digit()).collect(); + | error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:88:71 @@ -192,8 +195,9 @@ LL | let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'. | help: try | -LL | let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c: &&mut char| c.is_ascii_digit()).collect(); - | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'..='9').contains(c)).collect(); +LL + let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c: &&mut char| c.is_ascii_digit()).collect(); + | error: aborting due to 29 previous errors diff --git a/tests/ui/map_all_any_identity.stderr b/tests/ui/map_all_any_identity.stderr index 98fdcc2a9393..39df2a3d9616 100644 --- a/tests/ui/map_all_any_identity.stderr +++ b/tests/ui/map_all_any_identity.stderr @@ -8,8 +8,9 @@ LL | let _ = ["foo"].into_iter().map(|s| s == "foo").any(|a| a); = help: to override `-D warnings` add `#[allow(clippy::map_all_any_identity)]` help: use `.any(...)` instead | -LL | let _ = ["foo"].into_iter().any(|s| s == "foo"); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = ["foo"].into_iter().map(|s| s == "foo").any(|a| a); +LL + let _ = ["foo"].into_iter().any(|s| s == "foo"); + | error: usage of `.map(...).all(identity)` --> tests/ui/map_all_any_identity.rs:6:33 @@ -19,8 +20,9 @@ LL | let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::ident | help: use `.all(...)` instead | -LL | let _ = ["foo"].into_iter().all(|s| s == "foo"); - | ~~~~~~~~~~~~~~~~~~~ +LL - let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::identity); +LL + let _ = ["foo"].into_iter().all(|s| s == "foo"); + | error: aborting due to 2 previous errors diff --git a/tests/ui/map_with_unused_argument_over_ranges.stderr b/tests/ui/map_with_unused_argument_over_ranges.stderr index 0b56c6d95219..840515f95df4 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.stderr +++ b/tests/ui/map_with_unused_argument_over_ranges.stderr @@ -68,8 +68,9 @@ LL | (0..10).map(|_| 3); | help: remove the explicit range and use `repeat_n` | -LL | std::iter::repeat_n(3, 10); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~ +LL - (0..10).map(|_| 3); +LL + std::iter::repeat_n(3, 10); + | error: map of a closure that does not depend on its parameter over a range --> tests/ui/map_with_unused_argument_over_ranges.rs:31:5 @@ -216,8 +217,9 @@ LL | (0..10).map(|_| 3); | help: remove the explicit range and use `repeat` and `take` | -LL | std::iter::repeat(3).take(10); - | ~~~~~~~~~~~~~~~~~ ~ +++++++++ +LL - (0..10).map(|_| 3); +LL + std::iter::repeat(3).take(10); + | error: aborting due to 18 previous errors diff --git a/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr b/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr index d47f3d09175b..975ded83560f 100644 --- a/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr +++ b/tests/ui/map_with_unused_argument_over_ranges_nostd.stderr @@ -8,8 +8,9 @@ LL | let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_with_unused_argument_over_ranges)]` help: remove the explicit range and use `repeat_n` | -LL | let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); - | ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ +LL - let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); +LL + let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); + | error: aborting due to 1 previous error diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index b5b91cbe5534..18b23bd78454 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -8,8 +8,9 @@ LL | if let Some(y) = x.parse().ok() { y } else { 0 } = help: to override `-D warnings` add `#[allow(clippy::match_result_ok)]` help: consider matching on `Ok(y)` and removing the call to `ok` instead | -LL | if let Ok(y) = x.parse() { y } else { 0 } - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(y) = x.parse().ok() { y } else { 0 } +LL + if let Ok(y) = x.parse() { y } else { 0 } + | error: matching on `Some` with `ok()` is redundant --> tests/ui/match_result_ok.rs:23:9 @@ -19,8 +20,9 @@ LL | if let Some(y) = x . parse() . ok () { | help: consider matching on `Ok(y)` and removing the call to `ok` instead | -LL | if let Ok(y) = x . parse() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(y) = x . parse() . ok () { +LL + if let Ok(y) = x . parse() { + | error: matching on `Some` with `ok()` is redundant --> tests/ui/match_result_ok.rs:49:5 @@ -30,8 +32,9 @@ LL | while let Some(a) = wat.next().ok() { | help: consider matching on `Ok(a)` and removing the call to `ok` instead | -LL | while let Ok(a) = wat.next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - while let Some(a) = wat.next().ok() { +LL + while let Ok(a) = wat.next() { + | error: aborting due to 3 previous errors diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index 67e9ccaf6d2f..5b14fd13a53b 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -8,8 +8,9 @@ LL | "Bar" => {}, = help: to override `-D warnings` add `#[allow(clippy::match_str_case_mismatch)]` help: consider changing the case of this arm to respect `to_ascii_lowercase` | -LL | "bar" => {}, - | ~~~~~ +LL - "Bar" => {}, +LL + "bar" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:122:9 @@ -19,8 +20,9 @@ LL | "~!@#$%^&*()-_=+Foo" => {}, | help: consider changing the case of this arm to respect `to_ascii_lowercase` (notice the capitalization difference) | -LL | "~!@#$%^&*()-_=+foo" => {}, - | ~~~~~~~~~~~~~~~~~~~~ +LL - "~!@#$%^&*()-_=+Foo" => {}, +LL + "~!@#$%^&*()-_=+foo" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:134:9 @@ -30,8 +32,9 @@ LL | "Воды" => {}, | help: consider changing the case of this arm to respect `to_lowercase` | -LL | "воды" => {}, - | ~~~~~~ +LL - "Воды" => {}, +LL + "воды" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:145:9 @@ -41,8 +44,9 @@ LL | "barDz" => {}, | help: consider changing the case of this arm to respect `to_lowercase` | -LL | "bardz" => {}, - | ~~~~~~ +LL - "barDz" => {}, +LL + "bardz" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:155:9 @@ -52,8 +56,9 @@ LL | "bARʁ" => {}, | help: consider changing the case of this arm to respect `to_uppercase` | -LL | "BARʁ" => {}, - | ~~~~~~ +LL - "bARʁ" => {}, +LL + "BARʁ" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:165:9 @@ -63,8 +68,9 @@ LL | "Bar" => {}, | help: consider changing the case of this arm to respect `to_ascii_lowercase` | -LL | "bar" => {}, - | ~~~~~ +LL - "Bar" => {}, +LL + "bar" => {}, + | error: this `match` arm has a differing case than its expression --> tests/ui/match_str_case_mismatch.rs:180:9 @@ -74,8 +80,9 @@ LL | "bAR" => {}, | help: consider changing the case of this arm to respect `to_ascii_uppercase` | -LL | "BAR" => {}, - | ~~~~~ +LL - "bAR" => {}, +LL + "BAR" => {}, + | error: aborting due to 7 previous errors diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 2ad694490396..035376cabaf4 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -15,8 +15,9 @@ LL | Some(ref x) => *x, | help: try | -LL | Some(x) => x, - | ~ ~ +LL - Some(ref x) => *x, +LL + Some(x) => x, + | error: this pattern creates a reference to a reference --> tests/ui/needless_borrow_pat.rs:74:14 @@ -71,8 +72,9 @@ LL | E::A(ref x) | E::B(ref x) => *x, | help: try | -LL | E::A(x) | E::B(x) => x, - | ~ ~ ~ +LL - E::A(ref x) | E::B(ref x) => *x, +LL + E::A(x) | E::B(x) => x, + | error: this pattern creates a reference to a reference --> tests/ui/needless_borrow_pat.rs:126:21 diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 682140a1dfda..722016b12125 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -25,8 +25,9 @@ LL + } | help: ...and replace `return` with `continue` | -LL | continue; - | ~~~~~~~~ +LL - return; +LL + continue; + | error: aborting due to 1 previous error diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 2587d3f8c52f..2c90da51252a 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -63,12 +63,14 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | help: consider changing the type to | -LL | fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { - | ~~~~ +LL - fn issue_2114(s: String, t: String, u: Vec, v: Vec) { +LL + fn issue_2114(s: String, t: &str, u: Vec, v: Vec) { + | help: change `t.clone()` to | -LL | let _ = t.to_string(); - | ~~~~~~~~~~~~~ +LL - let _ = t.clone(); +LL + let _ = t.to_string(); + | error: this argument is passed by value, but not consumed in the function body --> tests/ui/needless_pass_by_value.rs:91:40 @@ -84,12 +86,14 @@ LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | help: consider changing the type to | -LL | fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { - | ~~~~~~ +LL - fn issue_2114(s: String, t: String, u: Vec, v: Vec) { +LL + fn issue_2114(s: String, t: String, u: Vec, v: &[i32]) { + | help: change `v.clone()` to | -LL | let _ = v.to_owned(); - | ~~~~~~~~~~~~ +LL - let _ = v.clone(); +LL + let _ = v.to_owned(); + | error: this argument is passed by value, but not consumed in the function body --> tests/ui/needless_pass_by_value.rs:108:12 diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 503d796e5e8d..831b8511e434 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -8,8 +8,9 @@ LL | for i in 0..vec.len() { = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | -LL | for in &vec { - | ~~~~~~ ~~~~ +LL - for i in 0..vec.len() { +LL + for in &vec { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:27:14 @@ -19,8 +20,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator | -LL | for in &vec { - | ~~~~~~ ~~~~ +LL - for i in 0..vec.len() { +LL + for in &vec { + | error: the loop variable `j` is only used to index `STATIC` --> tests/ui/needless_range_loop.rs:33:14 @@ -30,8 +32,9 @@ LL | for j in 0..4 { | help: consider using an iterator | -LL | for in &STATIC { - | ~~~~~~ ~~~~~~~ +LL - for j in 0..4 { +LL + for in &STATIC { + | error: the loop variable `j` is only used to index `CONST` --> tests/ui/needless_range_loop.rs:38:14 @@ -41,8 +44,9 @@ LL | for j in 0..4 { | help: consider using an iterator | -LL | for in &CONST { - | ~~~~~~ ~~~~~~ +LL - for j in 0..4 { +LL + for in &CONST { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:43:14 @@ -52,8 +56,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate() { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for (i, ) in vec.iter().enumerate() { + | error: the loop variable `i` is only used to index `vec2` --> tests/ui/needless_range_loop.rs:52:14 @@ -63,8 +68,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator | -LL | for in vec2.iter().take(vec.len()) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for in vec2.iter().take(vec.len()) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:57:14 @@ -74,8 +80,9 @@ LL | for i in 5..vec.len() { | help: consider using an iterator | -LL | for in vec.iter().skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 5..vec.len() { +LL + for in vec.iter().skip(5) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:62:14 @@ -85,8 +92,9 @@ LL | for i in 0..MAX_LEN { | help: consider using an iterator | -LL | for in vec.iter().take(MAX_LEN) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..MAX_LEN { +LL + for in vec.iter().take(MAX_LEN) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:67:14 @@ -96,8 +104,9 @@ LL | for i in 0..=MAX_LEN { | help: consider using an iterator | -LL | for in vec.iter().take(MAX_LEN + 1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..=MAX_LEN { +LL + for in vec.iter().take(MAX_LEN + 1) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:72:14 @@ -107,8 +116,9 @@ LL | for i in 5..10 { | help: consider using an iterator | -LL | for in vec.iter().take(10).skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..10 { +LL + for in vec.iter().take(10).skip(5) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop.rs:77:14 @@ -118,8 +128,9 @@ LL | for i in 5..=10 { | help: consider using an iterator | -LL | for in vec.iter().take(10 + 1).skip(5) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..=10 { +LL + for in vec.iter().take(10 + 1).skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:82:14 @@ -129,8 +140,9 @@ LL | for i in 5..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate().skip(5) { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..vec.len() { +LL + for (i, ) in vec.iter().enumerate().skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:87:14 @@ -140,8 +152,9 @@ LL | for i in 5..10 { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 5..10 { +LL + for (i, ) in vec.iter().enumerate().take(10).skip(5) { + | error: the loop variable `i` is used to index `vec` --> tests/ui/needless_range_loop.rs:93:14 @@ -151,8 +164,9 @@ LL | for i in 0..vec.len() { | help: consider using an iterator and enumerate() | -LL | for (i, ) in vec.iter_mut().enumerate() { - | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 0..vec.len() { +LL + for (i, ) in vec.iter_mut().enumerate() { + | error: aborting due to 14 previous errors diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 353f30b1b26d..f37e1f2872d0 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -8,8 +8,9 @@ LL | for i in 3..10 { = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | -LL | for in ns.iter().take(10).skip(3) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in 3..10 { +LL + for in ns.iter().take(10).skip(3) { + | error: the loop variable `i` is only used to index `ms` --> tests/ui/needless_range_loop2.rs:34:14 @@ -19,8 +20,9 @@ LL | for i in 0..ms.len() { | help: consider using an iterator | -LL | for in &mut ms { - | ~~~~~~ ~~~~~~~ +LL - for i in 0..ms.len() { +LL + for in &mut ms { + | error: the loop variable `i` is only used to index `ms` --> tests/ui/needless_range_loop2.rs:41:14 @@ -30,8 +32,9 @@ LL | for i in 0..ms.len() { | help: consider using an iterator | -LL | for in &mut ms { - | ~~~~~~ ~~~~~~~ +LL - for i in 0..ms.len() { +LL + for in &mut ms { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop2.rs:66:14 @@ -41,8 +44,9 @@ LL | for i in x..x + 4 { | help: consider using an iterator | -LL | for in vec.iter_mut().skip(x).take(4) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in x..x + 4 { +LL + for in vec.iter_mut().skip(x).take(4) { + | error: the loop variable `i` is only used to index `vec` --> tests/ui/needless_range_loop2.rs:74:14 @@ -52,8 +56,9 @@ LL | for i in x..=x + 4 { | help: consider using an iterator | -LL | for in vec.iter_mut().skip(x).take(4 + 1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in x..=x + 4 { +LL + for in vec.iter_mut().skip(x).take(4 + 1) { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:81:14 @@ -63,8 +68,9 @@ LL | for i in 0..3 { | help: consider using an iterator | -LL | for in &arr { - | ~~~~~~ ~~~~ +LL - for i in 0..3 { +LL + for in &arr { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:86:14 @@ -74,8 +80,9 @@ LL | for i in 0..2 { | help: consider using an iterator | -LL | for in arr.iter().take(2) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 0..2 { +LL + for in arr.iter().take(2) { + | error: the loop variable `i` is only used to index `arr` --> tests/ui/needless_range_loop2.rs:91:14 @@ -85,8 +92,9 @@ LL | for i in 1..3 { | help: consider using an iterator | -LL | for in arr.iter().skip(1) { - | ~~~~~~ ~~~~~~~~~~~~~~~~~~ +LL - for i in 1..3 { +LL + for in arr.iter().skip(1) { + | error: aborting due to 8 previous errors diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index d3c2a6badc0f..8d8b5b9e713d 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -80,8 +80,9 @@ LL | true => return false, | help: remove `return` | -LL | true => false, - | ~~~~~ +LL - true => return false, +LL + true => false, + | error: unneeded `return` statement --> tests/ui/needless_return.rs:58:13 @@ -115,8 +116,9 @@ LL | let _ = || return true; | help: remove `return` | -LL | let _ = || true; - | ~~~~ +LL - let _ = || return true; +LL + let _ = || true; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:71:5 @@ -183,8 +185,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:97:24 @@ -209,8 +212,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:113:9 @@ -244,8 +248,9 @@ LL | bar.unwrap_or_else(|_| return) | help: replace `return` with an empty block | -LL | bar.unwrap_or_else(|_| {}) - | ~~ +LL - bar.unwrap_or_else(|_| return) +LL + bar.unwrap_or_else(|_| {}) + | error: unneeded `return` statement --> tests/ui/needless_return.rs:141:21 @@ -270,8 +275,9 @@ LL | let _ = || return; | help: replace `return` with an empty block | -LL | let _ = || {}; - | ~~ +LL - let _ = || return; +LL + let _ = || {}; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:150:32 @@ -281,8 +287,9 @@ LL | res.unwrap_or_else(|_| return Foo) | help: remove `return` | -LL | res.unwrap_or_else(|_| Foo) - | ~~~ +LL - res.unwrap_or_else(|_| return Foo) +LL + res.unwrap_or_else(|_| Foo) + | error: unneeded `return` statement --> tests/ui/needless_return.rs:159:5 @@ -340,8 +347,9 @@ LL | true => return false, | help: remove `return` | -LL | true => false, - | ~~~~~ +LL - true => return false, +LL + true => false, + | error: unneeded `return` statement --> tests/ui/needless_return.rs:178:13 @@ -375,8 +383,9 @@ LL | let _ = || return true; | help: remove `return` | -LL | let _ = || true; - | ~~~~ +LL - let _ = || return true; +LL + let _ = || true; + | error: unneeded `return` statement --> tests/ui/needless_return.rs:191:5 @@ -443,8 +452,9 @@ LL | _ => return, | help: replace `return` with a unit value | -LL | _ => (), - | ~~ +LL - _ => return, +LL + _ => (), + | error: unneeded `return` statement --> tests/ui/needless_return.rs:222:9 diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index dab3488af106..203e33258225 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -77,8 +77,9 @@ LL | | } | help: if you need the first element of the iterator, try writing | -LL | if let Some(x) = (0..10).next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for x in 0..10 { +LL + if let Some(x) = (0..10).next() { + | error: this loop never actually loops --> tests/ui/never_loop.rs:167:5 @@ -145,8 +146,9 @@ LL | | } | help: if you need the first element of the iterator, try writing | -LL | if let Some(_) = (0..20).next() { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for _ in 0..20 { +LL + if let Some(_) = (0..20).next() { + | error: this loop never actually loops --> tests/ui/never_loop.rs:378:13 diff --git a/tests/ui/non_canonical_partial_ord_impl.stderr b/tests/ui/non_canonical_partial_ord_impl.stderr index a15379c5b1a5..9f0c2ec43015 100644 --- a/tests/ui/non_canonical_partial_ord_impl.stderr +++ b/tests/ui/non_canonical_partial_ord_impl.stderr @@ -25,8 +25,9 @@ LL | | } | help: change this to | -LL | fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } - | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - fn partial_cmp(&self, _: &Self) -> Option { +LL + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } + | error: aborting due to 2 previous errors diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr index f956f4b8d52a..333052ae1c11 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.stderr @@ -8,8 +8,9 @@ LL | static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); = help: to override `-D warnings` add `#[allow(clippy::non_std_lazy_statics)]` help: use `std::sync::LazyLock` instead | -LL | static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); +LL + static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:13:18 @@ -19,8 +20,9 @@ LL | static LAZY_BAR: Lazy = Lazy::new(|| { | help: use `std::sync::LazyLock` instead | -LL | static LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| { - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_BAR: Lazy = Lazy::new(|| { +LL + static LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| { + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:18:18 @@ -30,8 +32,9 @@ LL | static LAZY_BAZ: Lazy = { Lazy::new(|| "baz".to_uppercase()) }; | help: use `std::sync::LazyLock` instead | -LL | static LAZY_BAZ: std::sync::LazyLock = { std::sync::LazyLock::new(|| "baz".to_uppercase()) }; - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_BAZ: Lazy = { Lazy::new(|| "baz".to_uppercase()) }; +LL + static LAZY_BAZ: std::sync::LazyLock = { std::sync::LazyLock::new(|| "baz".to_uppercase()) }; + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs:20:18 diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr index 66dc435f9823..216190ae4ca3 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.stderr @@ -37,8 +37,9 @@ LL | static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static LAZY_FOO: Lazy = Lazy::new(|| "foo".to_uppercase()); +LL + static LAZY_FOO: std::sync::LazyLock = std::sync::LazyLock::new(|| "foo".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs:13:26 @@ -48,8 +49,9 @@ LL | static mut LAZY_BAR: Lazy = Lazy::new(|| "bar".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static mut LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| "bar".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static mut LAZY_BAR: Lazy = Lazy::new(|| "bar".to_uppercase()); +LL + static mut LAZY_BAR: std::sync::LazyLock = std::sync::LazyLock::new(|| "bar".to_uppercase()); + | error: this type has been superceded by `LazyLock` in the standard library --> tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs:15:26 @@ -59,8 +61,9 @@ LL | static mut LAZY_BAZ: Lazy = Lazy::new(|| "baz".to_uppercase()); | help: use `std::sync::LazyLock` instead | -LL | static mut LAZY_BAZ: std::sync::LazyLock = std::sync::LazyLock::new(|| "baz".to_uppercase()); - | ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - static mut LAZY_BAZ: Lazy = Lazy::new(|| "baz".to_uppercase()); +LL + static mut LAZY_BAZ: std::sync::LazyLock = std::sync::LazyLock::new(|| "baz".to_uppercase()); + | error: aborting due to 6 previous errors diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 578f918f0139..56d6eb10ac03 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -51,10 +51,12 @@ LL | let _ = a == b && c == 5 && a == b; | help: try | -LL | let _ = !(a != b || c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b && c == 5 && a == b; +LL + let _ = !(a != b || c != 5); + | +LL - let _ = a == b && c == 5 && a == b; +LL + let _ = a == b && c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:44:13 @@ -64,10 +66,12 @@ LL | let _ = a == b || c == 5 || a == b; | help: try | -LL | let _ = !(a != b && c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b || c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b || c == 5 || a == b; +LL + let _ = !(a != b && c != 5); + | +LL - let _ = a == b || c == 5 || a == b; +LL + let _ = a == b || c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:46:13 @@ -77,10 +81,12 @@ LL | let _ = a == b && c == 5 && b == a; | help: try | -LL | let _ = !(a != b || c != 5); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a == b && c == 5; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a == b && c == 5 && b == a; +LL + let _ = !(a != b || c != 5); + | +LL - let _ = a == b && c == 5 && b == a; +LL + let _ = a == b && c == 5; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:48:13 @@ -90,10 +96,12 @@ LL | let _ = a != b || !(a != b || c == d); | help: try | -LL | let _ = !(a == b && c == d); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a != b || c != d; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a != b || !(a != b || c == d); +LL + let _ = !(a == b && c == d); + | +LL - let _ = a != b || !(a != b || c == d); +LL + let _ = a != b || c != d; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:50:13 @@ -103,10 +111,12 @@ LL | let _ = a != b && !(a != b && c == d); | help: try | -LL | let _ = !(a == b || c == d); - | ~~~~~~~~~~~~~~~~~~~ -LL | let _ = a != b && c != d; - | ~~~~~~~~~~~~~~~~ +LL - let _ = a != b && !(a != b && c == d); +LL + let _ = !(a == b || c == d); + | +LL - let _ = a != b && !(a != b && c == d); +LL + let _ = a != b && c != d; + | error: this boolean expression can be simplified --> tests/ui/nonminimal_bool.rs:81:8 diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 9343ba64a30b..c8a89ac8bea4 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -9,12 +9,14 @@ LL | let _bad1 = "\033[0m"; = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape is intended, use a hex escape instead | -LL | let _bad1 = "\x1b[0m"; - | ~~~~ +LL - let _bad1 = "\033[0m"; +LL + let _bad1 = "\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad1 = "\x0033[0m"; - | ~~~~~~ +LL - let _bad1 = "\033[0m"; +LL + let _bad1 = "\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:6:19 @@ -24,12 +26,14 @@ LL | let _bad2 = b"\033[0m"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad2 = b"\x1b[0m"; - | ~~~~ +LL - let _bad2 = b"\033[0m"; +LL + let _bad2 = b"\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad2 = b"\x0033[0m"; - | ~~~~~~ +LL - let _bad2 = b"\033[0m"; +LL + let _bad2 = b"\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:7:20 @@ -39,12 +43,14 @@ LL | let _bad3 = "\\\033[0m"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad3 = "\\\x1b[0m"; - | ~~~~ +LL - let _bad3 = "\\\033[0m"; +LL + let _bad3 = "\\\x1b[0m"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad3 = "\\\x0033[0m"; - | ~~~~~~ +LL - let _bad3 = "\\\033[0m"; +LL + let _bad3 = "\\\x0033[0m"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:9:18 @@ -54,12 +60,14 @@ LL | let _bad4 = "\01234567"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad4 = "\x0a34567"; - | ~~~~ +LL - let _bad4 = "\01234567"; +LL + let _bad4 = "\x0a34567"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad4 = "\x001234567"; - | ~~~~~~ +LL - let _bad4 = "\01234567"; +LL + let _bad4 = "\x001234567"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:10:20 @@ -69,12 +77,14 @@ LL | let _bad5 = "\0\03"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad5 = "\0\x03"; - | ~~~~ +LL - let _bad5 = "\0\03"; +LL + let _bad5 = "\0\x03"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad5 = "\0\x0003"; - | ~~~~~~ +LL - let _bad5 = "\0\03"; +LL + let _bad5 = "\0\x0003"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:11:23 @@ -84,12 +94,14 @@ LL | let _bad6 = "Text-\055\077-MoreText"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad6 = "Text-\x2d\077-MoreText"; - | ~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\x2d\077-MoreText"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad6 = "Text-\x0055\077-MoreText"; - | ~~~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\x0055\077-MoreText"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:11:27 @@ -99,12 +111,14 @@ LL | let _bad6 = "Text-\055\077-MoreText"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad6 = "Text-\055\x3f-MoreText"; - | ~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\055\x3f-MoreText"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad6 = "Text-\055\x0077-MoreText"; - | ~~~~~~ +LL - let _bad6 = "Text-\055\077-MoreText"; +LL + let _bad6 = "Text-\055\x0077-MoreText"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:14:31 @@ -114,12 +128,14 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; - | ~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; - | ~~~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:14:34 @@ -129,12 +145,14 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; - | ~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; - | ~~~~~~ +LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; +LL + let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:17:19 @@ -144,12 +162,14 @@ LL | let _bad8 = "锈\01锈"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad8 = "锈\x01锈"; - | ~~~~ +LL - let _bad8 = "锈\01锈"; +LL + let _bad8 = "锈\x01锈"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad8 = "锈\x0001锈"; - | ~~~~~~ +LL - let _bad8 = "锈\01锈"; +LL + let _bad8 = "锈\x0001锈"; + | error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:18:19 @@ -159,12 +179,14 @@ LL | let _bad9 = "锈\011锈"; | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad9 = "锈\x09锈"; - | ~~~~ +LL - let _bad9 = "锈\011锈"; +LL + let _bad9 = "锈\x09锈"; + | help: if a null escape is intended, disambiguate using | -LL | let _bad9 = "锈\x0011锈"; - | ~~~~~~ +LL - let _bad9 = "锈\011锈"; +LL + let _bad9 = "锈\x0011锈"; + | error: aborting due to 11 previous errors diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index c5b68730a8f2..ad002437c0c6 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -8,8 +8,9 @@ LL | let foo = &5 - &6; = help: to override `-D warnings` add `#[allow(clippy::op_ref)]` help: use the values directly | -LL | let foo = 5 - 6; - | ~ ~ +LL - let foo = &5 - &6; +LL + let foo = 5 - 6; + | error: taken reference of right operand --> tests/ui/op_ref.rs:58:13 diff --git a/tests/ui/option_as_ref_cloned.stderr b/tests/ui/option_as_ref_cloned.stderr index 5892f2bdec56..0eda42b91b96 100644 --- a/tests/ui/option_as_ref_cloned.stderr +++ b/tests/ui/option_as_ref_cloned.stderr @@ -8,8 +8,9 @@ LL | let _: Option = x.as_ref().cloned(); = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_cloned)]` help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option = x.clone(); - | ~~~~~ +LL - let _: Option = x.as_ref().cloned(); +LL + let _: Option = x.clone(); + | error: cloning an `Option<_>` using `.as_mut().cloned()` --> tests/ui/option_as_ref_cloned.rs:8:31 @@ -19,8 +20,9 @@ LL | let _: Option = x.as_mut().cloned(); | help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option = x.clone(); - | ~~~~~ +LL - let _: Option = x.as_mut().cloned(); +LL + let _: Option = x.clone(); + | error: cloning an `Option<_>` using `.as_ref().cloned()` --> tests/ui/option_as_ref_cloned.rs:11:32 @@ -30,8 +32,9 @@ LL | let _: Option<&String> = y.as_ref().cloned(); | help: this can be written more concisely by cloning the `Option<_>` directly | -LL | let _: Option<&String> = y.clone(); - | ~~~~~ +LL - let _: Option<&String> = y.as_ref().cloned(); +LL + let _: Option<&String> = y.clone(); + | error: aborting due to 3 previous errors diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 7512546450b2..a10cd5c2f481 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -44,8 +44,9 @@ LL | Some(x) if matches!(x, Some(1) if true) => .., | help: try | -LL | Some(Some(1)) if true => .., - | ~~~~~~~ ~~~~~~~ +LL - Some(x) if matches!(x, Some(1) if true) => .., +LL + Some(Some(1)) if true => .., + | error: redundant guard --> tests/ui/redundant_guards.rs:50:20 diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 25ab98223827..233416351a0a 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -8,8 +8,9 @@ LL | Some(ref x) => x, = help: to override `-D warnings` add `#[allow(clippy::ref_binding_to_reference)]` help: try | -LL | Some(x) => &x, - | ~ ~~ +LL - Some(ref x) => x, +LL + Some(x) => &x, + | error: this pattern creates a reference to a reference --> tests/ui/ref_binding_to_reference.rs:38:14 @@ -34,8 +35,9 @@ LL | Some(ref x) => m2!(x), | help: try | -LL | Some(x) => m2!(&x), - | ~ ~~ +LL - Some(ref x) => m2!(x), +LL + Some(x) => m2!(&x), + | error: this pattern creates a reference to a reference --> tests/ui/ref_binding_to_reference.rs:55:15 diff --git a/tests/ui/ref_option/ref_option.all.stderr b/tests/ui/ref_option/ref_option.all.stderr index b4c69ac62962..fd30628bdd81 100644 --- a/tests/ui/ref_option/ref_option.all.stderr +++ b/tests/ui/ref_option/ref_option.all.stderr @@ -55,8 +55,9 @@ LL | fn mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - fn mult_string(a: &Option, b: &Option>) {} +LL + fn mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:18:1 @@ -85,8 +86,9 @@ LL | pub fn pub_mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - pub fn pub_mult_string(a: &Option, b: &Option>) {} +LL + pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:26:5 diff --git a/tests/ui/ref_option/ref_option.private.stderr b/tests/ui/ref_option/ref_option.private.stderr index 17c90536da34..d3428f1891f3 100644 --- a/tests/ui/ref_option/ref_option.private.stderr +++ b/tests/ui/ref_option/ref_option.private.stderr @@ -55,8 +55,9 @@ LL | fn mult_string(a: &Option, b: &Option>) {} | help: change this to | -LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} - | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - fn mult_string(a: &Option, b: &Option>) {} +LL + fn mult_string(a: Option<&String>, b: Option<&Vec>) {} + | error: it is more idiomatic to use `Option<&T>` instead of `&Option` --> tests/ui/ref_option/ref_option.rs:18:1 diff --git a/tests/ui/repeat_vec_with_capacity.stderr b/tests/ui/repeat_vec_with_capacity.stderr index 43027c9cb892..05513a8859a4 100644 --- a/tests/ui/repeat_vec_with_capacity.stderr +++ b/tests/ui/repeat_vec_with_capacity.stderr @@ -9,8 +9,9 @@ LL | vec![Vec::<()>::with_capacity(42); 123]; = help: to override `-D warnings` add `#[allow(clippy::repeat_vec_with_capacity)]` help: if you intended to initialize multiple `Vec`s with an initial capacity, try | -LL | (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![Vec::<()>::with_capacity(42); 123]; +LL + (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); + | error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity --> tests/ui/repeat_vec_with_capacity.rs:12:9 @@ -21,8 +22,9 @@ LL | vec![Vec::<()>::with_capacity(42); n]; = note: only the last `Vec` will have the capacity help: if you intended to initialize multiple `Vec`s with an initial capacity, try | -LL | (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![Vec::<()>::with_capacity(42); n]; +LL + (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); + | error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity --> tests/ui/repeat_vec_with_capacity.rs:27:9 @@ -33,8 +35,9 @@ LL | std::iter::repeat(Vec::<()>::with_capacity(42)); = note: none of the yielded `Vec`s will have the requested capacity help: if you intended to create an iterator that yields `Vec`s with an initial capacity, try | -LL | std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - std::iter::repeat(Vec::<()>::with_capacity(42)); +LL + std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); + | error: aborting due to 3 previous errors diff --git a/tests/ui/repeat_vec_with_capacity_nostd.stderr b/tests/ui/repeat_vec_with_capacity_nostd.stderr index 39364d09b961..092167485ced 100644 --- a/tests/ui/repeat_vec_with_capacity_nostd.stderr +++ b/tests/ui/repeat_vec_with_capacity_nostd.stderr @@ -9,8 +9,9 @@ LL | let _: Vec> = iter::repeat(Vec::with_capacity(42)).take(123).co = help: to override `-D warnings` add `#[allow(clippy::repeat_vec_with_capacity)]` help: if you intended to create an iterator that yields `Vec`s with an initial capacity, try | -LL | let _: Vec> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Vec> = iter::repeat(Vec::with_capacity(42)).take(123).collect(); +LL + let _: Vec> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); + | error: aborting due to 1 previous error diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index 3747eb9deebc..24cb959c96af 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -8,8 +8,9 @@ LL | (42..=21).for_each(|x| println!("{}", x)); = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | -LL | (21..=42).rev().for_each(|x| println!("{}", x)); - | ~~~~~~~~~~~~~~~ +LL - (42..=21).for_each(|x| println!("{}", x)); +LL + (21..=42).rev().for_each(|x| println!("{}", x)); + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:10:13 @@ -19,8 +20,9 @@ LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>( | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); +LL + let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:12:14 @@ -30,8 +32,9 @@ LL | for _ in -21..=-42 {} | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for _ in (-42..=-21).rev() {} - | ~~~~~~~~~~~~~~~~~ +LL - for _ in -21..=-42 {} +LL + for _ in (-42..=-21).rev() {} + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_fixable.rs:13:14 @@ -41,8 +44,9 @@ LL | for _ in 42u32..21u32 {} | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for _ in (21u32..42u32).rev() {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - for _ in 42u32..21u32 {} +LL + for _ in (21u32..42u32).rev() {} + | error: aborting due to 4 previous errors diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index d5df34c42f4f..3e9ccb653fe7 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -8,8 +8,9 @@ LL | for i in 10..0 { = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..10).rev() { - | ~~~~~~~~~~~~~ +LL - for i in 10..0 { +LL + for i in (0..10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:11:14 @@ -19,8 +20,9 @@ LL | for i in 10..=0 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..=10).rev() { - | ~~~~~~~~~~~~~~ +LL - for i in 10..=0 { +LL + for i in (0..=10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:15:14 @@ -30,8 +32,9 @@ LL | for i in MAX_LEN..0 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..MAX_LEN).rev() { - | ~~~~~~~~~~~~~~~~~~ +LL - for i in MAX_LEN..0 { +LL + for i in (0..MAX_LEN).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:34:14 @@ -41,8 +44,9 @@ LL | for i in (10..0).map(|x| x * 2) { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (0..10).rev().map(|x| x * 2) { - | ~~~~~~~~~~~~~ +LL - for i in (10..0).map(|x| x * 2) { +LL + for i in (0..10).rev().map(|x| x * 2) { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:39:14 @@ -52,8 +56,9 @@ LL | for i in 10..5 + 4 { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in (5 + 4..10).rev() { - | ~~~~~~~~~~~~~~~~~ +LL - for i in 10..5 + 4 { +LL + for i in (5 + 4..10).rev() { + | error: this range is empty so it will yield no values --> tests/ui/reversed_empty_ranges_loops_fixable.rs:43:14 @@ -63,8 +68,9 @@ LL | for i in (5 + 2)..(3 - 1) { | help: consider using the following if you are attempting to iterate over this range in reverse | -LL | for i in ((3 - 1)..(5 + 2)).rev() { - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - for i in (5 + 2)..(3 - 1) { +LL + for i in ((3 - 1)..(5 + 2)).rev() { + | error: aborting due to 6 previous errors diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.stderr index 9c125adb51a7..b3bc8dd4aca1 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.stderr @@ -8,12 +8,14 @@ LL | [0..200]; = help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]` help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200]; +LL + (0..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0; 200]; - | ~~~~~~ +LL - [0..200]; +LL + [0; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:27:5 @@ -23,12 +25,14 @@ LL | vec![0..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200]; +LL + (0..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0; 200]; - | ~~~~~~ +LL - vec![0..200]; +LL + vec![0; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:28:5 @@ -38,12 +42,14 @@ LL | [0u8..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0u8..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0u8..200]; +LL + (0u8..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0u8; 200]; - | ~~~~~~~~ +LL - [0u8..200]; +LL + [0u8; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:29:5 @@ -53,12 +59,14 @@ LL | [0usize..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0usize..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0usize..200]; +LL + (0usize..200).collect::>(); + | help: if you wanted an array of len 200, try | -LL | [0usize; 200]; - | ~~~~~~~~~~~ +LL - [0usize..200]; +LL + [0usize; 200]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:30:5 @@ -68,12 +76,14 @@ LL | [0..200usize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200usize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200usize]; +LL + (0..200usize).collect::>(); + | help: if you wanted an array of len 200usize, try | -LL | [0; 200usize]; - | ~~~~~~~~~~~ +LL - [0..200usize]; +LL + [0; 200usize]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:31:5 @@ -83,12 +93,14 @@ LL | vec![0u8..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0u8..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0u8..200]; +LL + (0u8..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0u8; 200]; - | ~~~~~~~~ +LL - vec![0u8..200]; +LL + vec![0u8; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:32:5 @@ -98,12 +110,14 @@ LL | vec![0usize..200]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0usize..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0usize..200]; +LL + (0usize..200).collect::>(); + | help: if you wanted a `Vec` of len 200, try | -LL | vec![0usize; 200]; - | ~~~~~~~~~~~ +LL - vec![0usize..200]; +LL + vec![0usize; 200]; + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:33:5 @@ -113,12 +127,14 @@ LL | vec![0..200usize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200usize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200usize]; +LL + (0..200usize).collect::>(); + | help: if you wanted a `Vec` of len 200usize, try | -LL | vec![0; 200usize]; - | ~~~~~~~~~~~ +LL - vec![0..200usize]; +LL + vec![0; 200usize]; + | error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:35:5 @@ -128,8 +144,9 @@ LL | [0..200isize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200isize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - [0..200isize]; +LL + (0..200isize).collect::>(); + | error: a `Vec` of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:36:5 @@ -139,8 +156,9 @@ LL | vec![0..200isize]; | help: if you wanted a `Vec` that contains the entire range, try | -LL | (0..200isize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - vec![0..200isize]; +LL + (0..200isize).collect::>(); + | error: aborting due to 10 previous errors diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index 4d3ca98e6237..1e28ae7b163e 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -8,8 +8,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); = help: to override `-D warnings` add `#[allow(clippy::string_lit_chars_any)]` help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:19:5 @@ -19,8 +20,9 @@ LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:20:5 @@ -30,8 +32,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:21:5 @@ -41,8 +44,9 @@ LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> tests/ui/string_lit_chars_any.rs:23:5 @@ -52,8 +56,9 @@ LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | help: use `matches!(...)` instead | -LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); +LL + matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + | error: aborting due to 5 previous errors diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 6fd07d07d7be..8952a3ffe4b8 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -8,8 +8,9 @@ LL | std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_command_arg_space)]` help: consider splitting the argument | -LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); - | ~~~~ ~~~~~~~~~~~~~~~ +LL - std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); +LL + std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + | error: single argument that looks like it should be multiple arguments --> tests/ui/suspicious_command_arg_space.rs:7:43 @@ -19,8 +20,9 @@ LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap() | help: consider splitting the argument | -LL | std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); - | ~~~~ ~~~~~~~~~~~~~~~~~~~~ +LL - std::process::Command::new("cat").arg("--number file").spawn().unwrap(); +LL + std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index c34e39cd0fcb..7e5933df2376 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -8,7 +8,8 @@ LL | ///! Fake module documentation. = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | -LL | //! Fake module documentation. +LL - ///! Fake module documentation. +LL + //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate @@ -19,7 +20,8 @@ LL | ///! This module contains useful functions. | help: use an inner doc comment to document the parent module or crate | -LL | //! This module contains useful functions. +LL - ///! This module contains useful functions. +LL + //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate @@ -71,7 +73,8 @@ LL | ///! a | help: use an inner doc comment to document the parent module or crate | -LL | //! a +LL - ///! a +LL + //! a | error: this is an outer doc comment and does not apply to the parent module or crate @@ -97,7 +100,8 @@ LL | ///! Very cool macro | help: use an inner doc comment to document the parent module or crate | -LL | //! Very cool macro +LL - ///! Very cool macro +LL + //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate @@ -108,7 +112,8 @@ LL | ///! Huh. | help: use an inner doc comment to document the parent module or crate | -LL | //! Huh. +LL - ///! Huh. +LL + //! Huh. | error: aborting due to 9 previous errors diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 255f211e6550..74bbcfcca51e 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -8,12 +8,14 @@ LL | let _ = cow.to_owned(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_to_owned)]` help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +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 --> tests/ui/suspicious_to_owned.rs:29:13 @@ -23,12 +25,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +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 --> tests/ui/suspicious_to_owned.rs:40:13 @@ -38,12 +42,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +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 --> tests/ui/suspicious_to_owned.rs:51:13 @@ -53,12 +59,14 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL | let _ = cow.into_owned(); - | ~~~~~~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.into_owned(); + | help: or clone the Cow itself | -LL | let _ = cow.clone(); - | ~~~~~~~~~~~ +LL - let _ = cow.to_owned(); +LL + let _ = cow.clone(); + | error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type --> tests/ui/suspicious_to_owned.rs:66:13 diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 43b03676b1db..2a153169bd34 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -8,8 +8,9 @@ LL | let _ = 2 ^ 5; = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` help: did you mean to write | -LL | let _ = 2.pow(5); - | ~~~~~~~~ +LL - let _ = 2 ^ 5; +LL + let _ = 2.pow(5); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:22:13 @@ -19,8 +20,9 @@ LL | let _ = 2i32 ^ 9i32; | help: did you mean to write | -LL | let _ = 2i32.pow(9i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 9i32; +LL + let _ = 2i32.pow(9i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 @@ -30,8 +32,9 @@ LL | let _ = 2i32 ^ 2i32; | help: did you mean to write | -LL | let _ = 2i32.pow(2i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 2i32; +LL + let _ = 2i32.pow(2i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 @@ -41,8 +44,9 @@ LL | let _ = 50i32 ^ 3i32; | help: did you mean to write | -LL | let _ = 50i32.pow(3i32); - | ~~~~~~~~~~~~~~~ +LL - let _ = 50i32 ^ 3i32; +LL + let _ = 50i32.pow(3i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:28:13 @@ -52,8 +56,9 @@ LL | let _ = 5i32 ^ 8i32; | help: did you mean to write | -LL | let _ = 5i32.pow(8i32); - | ~~~~~~~~~~~~~~ +LL - let _ = 5i32 ^ 8i32; +LL + let _ = 5i32.pow(8i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 @@ -63,8 +68,9 @@ LL | let _ = 2i32 ^ 32i32; | help: did you mean to write | -LL | let _ = 2i32.pow(32i32); - | ~~~~~~~~~~~~~~~ +LL - let _ = 2i32 ^ 32i32; +LL + let _ = 2i32.pow(32i32); + | error: `^` is not the exponentiation operator --> tests/ui/suspicious_xor_used_as_pow.rs:13:9 @@ -78,8 +84,9 @@ LL | macro_test_inside!(); = note: this error originates in the macro `macro_test_inside` (in Nightly builds, run with -Z macro-backtrace for more info) help: did you mean to write | -LL | 1.pow(2) // should warn even if inside macro - | ~~~~~~~~ +LL - 1 ^ 2 // should warn even if inside macro +LL + 1.pow(2) // should warn even if inside macro + | error: aborting due to 7 previous errors diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 8801eb943ce8..f4f83cd7ac6a 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -8,8 +8,9 @@ LL | let _: *const f32 = transmute(ptr); = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` help: use `pointer::cast` instead | -LL | let _: *const f32 = ptr.cast::(); - | ~~~~~~~~~~~~~~~~~ +LL - let _: *const f32 = transmute(ptr); +LL + let _: *const f32 = ptr.cast::(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:34:27 @@ -19,8 +20,9 @@ LL | let _: *mut f32 = transmute(mut_ptr); | help: use `pointer::cast` instead | -LL | let _: *mut f32 = mut_ptr.cast::(); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _: *mut f32 = transmute(mut_ptr); +LL + let _: *mut f32 = mut_ptr.cast::(); + | error: transmute from a reference to a reference --> tests/ui/transmute_ptr_to_ptr.rs:37:23 @@ -60,8 +62,9 @@ LL | let _: *const u32 = transmute(mut_ptr); | help: use `pointer::cast_const` instead | -LL | let _: *const u32 = mut_ptr.cast_const(); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u32 = transmute(mut_ptr); +LL + let _: *const u32 = mut_ptr.cast_const(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:52:27 @@ -71,8 +74,9 @@ LL | let _: *mut u32 = transmute(ptr); | help: use `pointer::cast_mut` instead | -LL | let _: *mut u32 = ptr.cast_mut(); - | ~~~~~~~~~~~~~~ +LL - let _: *mut u32 = transmute(ptr); +LL + let _: *mut u32 = ptr.cast_mut(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:64:14 @@ -82,8 +86,9 @@ LL | unsafe { transmute(v) } | help: use an `as` cast instead | -LL | unsafe { v as *const &() } - | ~~~~~~~~~~~~~~~ +LL - unsafe { transmute(v) } +LL + unsafe { v as *const &() } + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:79:28 @@ -93,8 +98,9 @@ LL | let _: *const i8 = transmute(ptr); | help: use an `as` cast instead | -LL | let _: *const i8 = ptr as *const i8; - | ~~~~~~~~~~~~~~~~ +LL - let _: *const i8 = transmute(ptr); +LL + let _: *const i8 = ptr as *const i8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:86:28 @@ -104,8 +110,9 @@ LL | let _: *const i8 = transmute(ptr); | help: use `pointer::cast` instead | -LL | let _: *const i8 = ptr.cast::(); - | ~~~~~~~~~~~~~~~~ +LL - let _: *const i8 = transmute(ptr); +LL + let _: *const i8 = ptr.cast::(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:93:26 @@ -115,8 +122,9 @@ LL | let _: *mut u8 = transmute(ptr); | help: use an `as` cast instead | -LL | let _: *mut u8 = ptr as *mut u8; - | ~~~~~~~~~~~~~~ +LL - let _: *mut u8 = transmute(ptr); +LL + let _: *mut u8 = ptr as *mut u8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:94:28 @@ -126,8 +134,9 @@ LL | let _: *const u8 = transmute(mut_ptr); | help: use an `as` cast instead | -LL | let _: *const u8 = mut_ptr as *const u8; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u8 = transmute(mut_ptr); +LL + let _: *const u8 = mut_ptr as *const u8; + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:101:26 @@ -137,8 +146,9 @@ LL | let _: *mut u8 = transmute(ptr); | help: use `pointer::cast_mut` instead | -LL | let _: *mut u8 = ptr.cast_mut(); - | ~~~~~~~~~~~~~~ +LL - let _: *mut u8 = transmute(ptr); +LL + let _: *mut u8 = ptr.cast_mut(); + | error: transmute from a pointer to a pointer --> tests/ui/transmute_ptr_to_ptr.rs:102:28 @@ -148,8 +158,9 @@ LL | let _: *const u8 = transmute(mut_ptr); | help: use `pointer::cast_const` instead | -LL | let _: *const u8 = mut_ptr.cast_const(); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _: *const u8 = transmute(mut_ptr); +LL + let _: *const u8 = mut_ptr.cast_const(); + | error: aborting due to 16 previous errors diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 2d74967ede56..21edd39e7ad6 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -17,8 +17,9 @@ LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` help: use `pointer::cast` instead | -LL | let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; +LL + let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; + | error: transmute from a pointer to a pointer --> tests/ui/transmutes_expressible_as_ptr_casts.rs:27:46 @@ -28,8 +29,9 @@ LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *con | help: use an `as` cast instead | -LL | let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; +LL + let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; + | error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead --> tests/ui/transmutes_expressible_as_ptr_casts.rs:33:50 diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 41ad1a2d3834..bf79e93e4440 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -10,7 +10,8 @@ LL | | }); = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` help: remove the semicolon from the last statement in the block | -LL | 1 +LL - 1; +LL + 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -43,7 +44,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | foo(2) +LL - foo(2); +LL + foo(2) | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -64,7 +66,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | 1 +LL - 1; +LL + 1 | help: or move the expression in front of the call and replace it with the unit literal `()` | @@ -98,7 +101,8 @@ LL | | }); | help: remove the semicolon from the last statement in the block | -LL | foo(2) +LL - foo(2); +LL + foo(2) | help: or move the expressions in front of the call and replace them with the unit literal `()` | @@ -124,11 +128,13 @@ LL | | ); | help: remove the semicolon from the last statement in the block | -LL | foo(1) +LL - foo(1); +LL + foo(1) | help: remove the semicolon from the last statement in the block | -LL | foo(3) +LL - foo(3); +LL + foo(3) | help: or move the expressions in front of the call and replace them with the unit literal `()` | diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index aa2c2f3c0e20..ea925cd3a9fc 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -39,8 +39,9 @@ LL | #[warn(clippy::dead_cod)] | help: a lint with a similar name exists in `rustc` lints | -LL | #[warn(dead_code)] - | ~~~~~~~~~ +LL - #[warn(clippy::dead_cod)] +LL + #[warn(dead_code)] + | error: unknown lint: `clippy::unused_colle` --> tests/ui/unknown_clippy_lints.rs:13:8 @@ -62,8 +63,9 @@ LL | #[warn(clippy::missing_docs)] | help: a lint with a similar name exists in `rustc` lints | -LL | #[warn(missing_docs)] - | ~~~~~~~~~~~~ +LL - #[warn(clippy::missing_docs)] +LL + #[warn(missing_docs)] + | error: aborting due to 9 previous errors diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 35a2144c389f..9bb1b71f0ed5 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -8,8 +8,9 @@ LL | let _ = opt.unwrap_or_else(|| 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| 2); +LL + let _ = opt.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:84:13 @@ -19,8 +20,9 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| astronomers_pi); +LL + let _ = opt.unwrap_or(astronomers_pi); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:85:13 @@ -30,8 +32,9 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | help: use `unwrap_or` instead | -LL | let _ = opt.unwrap_or(ext_str.some_field); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = opt.unwrap_or_else(|| ext_str.some_field); +LL + let _ = opt.unwrap_or(ext_str.some_field); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:87:13 @@ -41,8 +44,9 @@ LL | let _ = opt.and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = opt.and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = opt.and_then(|_| ext_opt); +LL + let _ = opt.and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:88:13 @@ -52,8 +56,9 @@ LL | let _ = opt.or_else(|| ext_opt); | help: use `or` instead | -LL | let _ = opt.or(ext_opt); - | ~~~~~~~~~~~ +LL - let _ = opt.or_else(|| ext_opt); +LL + let _ = opt.or(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:89:13 @@ -63,8 +68,9 @@ LL | let _ = opt.or_else(|| None); | help: use `or` instead | -LL | let _ = opt.or(None); - | ~~~~~~~~ +LL - let _ = opt.or_else(|| None); +LL + let _ = opt.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:90:13 @@ -74,8 +80,9 @@ LL | let _ = opt.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = opt.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = opt.get_or_insert_with(|| 2); +LL + let _ = opt.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:91:13 @@ -85,8 +92,9 @@ LL | let _ = opt.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _ = opt.ok_or(2); - | ~~~~~~~~ +LL - let _ = opt.ok_or_else(|| 2); +LL + let _ = opt.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:92:13 @@ -96,8 +104,9 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | help: use `unwrap_or` instead | -LL | let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); +LL + let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:93:13 @@ -107,8 +116,9 @@ LL | let _ = cond.then(|| astronomers_pi); | help: use `then_some` instead | -LL | let _ = cond.then_some(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = cond.then(|| astronomers_pi); +LL + let _ = cond.then_some(astronomers_pi); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:94:13 @@ -118,8 +128,9 @@ LL | let _ = true.then(|| -> _ {}); | help: use `then_some` instead | -LL | let _ = true.then_some({}); - | ~~~~~~~~~~~~~ +LL - let _ = true.then(|| -> _ {}); +LL + let _ = true.then_some({}); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:95:13 @@ -129,8 +140,9 @@ LL | let _ = true.then(|| {}); | help: use `then_some` instead | -LL | let _ = true.then_some({}); - | ~~~~~~~~~~~~~ +LL - let _ = true.then(|| {}); +LL + let _ = true.then_some({}); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:99:13 @@ -140,8 +152,9 @@ LL | let _ = Some(1).unwrap_or_else(|| *r); | help: use `unwrap_or` instead | -LL | let _ = Some(1).unwrap_or(*r); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).unwrap_or_else(|| *r); +LL + let _ = Some(1).unwrap_or(*r); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:101:13 @@ -151,8 +164,9 @@ LL | let _ = Some(1).unwrap_or_else(|| *b); | help: use `unwrap_or` instead | -LL | let _ = Some(1).unwrap_or(*b); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).unwrap_or_else(|| *b); +LL + let _ = Some(1).unwrap_or(*b); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:103:13 @@ -162,8 +176,9 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | help: use `unwrap_or` instead | -LL | let _ = Some(1).as_ref().unwrap_or(&r); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).as_ref().unwrap_or_else(|| &r); +LL + let _ = Some(1).as_ref().unwrap_or(&r); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:104:13 @@ -173,8 +188,9 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | help: use `unwrap_or` instead | -LL | let _ = Some(1).as_ref().unwrap_or(&b); - | ~~~~~~~~~~~~~ +LL - let _ = Some(1).as_ref().unwrap_or_else(|| &b); +LL + let _ = Some(1).as_ref().unwrap_or(&b); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:107:13 @@ -184,8 +200,9 @@ LL | let _ = Some(10).unwrap_or_else(|| 2); | help: use `unwrap_or` instead | -LL | let _ = Some(10).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Some(10).unwrap_or_else(|| 2); +LL + let _ = Some(10).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:108:13 @@ -195,8 +212,9 @@ LL | let _ = Some(10).and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = Some(10).and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = Some(10).and_then(|_| ext_opt); +LL + let _ = Some(10).and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:109:28 @@ -206,8 +224,9 @@ LL | let _: Option = None.or_else(|| ext_opt); | help: use `or` instead | -LL | let _: Option = None.or(ext_opt); - | ~~~~~~~~~~~ +LL - let _: Option = None.or_else(|| ext_opt); +LL + let _: Option = None.or(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:110:13 @@ -217,8 +236,9 @@ LL | let _ = None.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = None.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = None.get_or_insert_with(|| 2); +LL + let _ = None.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:111:35 @@ -228,8 +248,9 @@ LL | let _: Result = None.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _: Result = None.ok_or(2); - | ~~~~~~~~ +LL - let _: Result = None.ok_or_else(|| 2); +LL + let _: Result = None.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:112:28 @@ -239,8 +260,9 @@ LL | let _: Option = None.or_else(|| None); | help: use `or` instead | -LL | let _: Option = None.or(None); - | ~~~~~~~~ +LL - let _: Option = None.or_else(|| None); +LL + let _: Option = None.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:115:13 @@ -250,8 +272,9 @@ LL | let _ = deep.0.unwrap_or_else(|| 2); | help: use `unwrap_or` instead | -LL | let _ = deep.0.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = deep.0.unwrap_or_else(|| 2); +LL + let _ = deep.0.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:116:13 @@ -261,8 +284,9 @@ LL | let _ = deep.0.and_then(|_| ext_opt); | help: use `and` instead | -LL | let _ = deep.0.and(ext_opt); - | ~~~~~~~~~~~~ +LL - let _ = deep.0.and_then(|_| ext_opt); +LL + let _ = deep.0.and(ext_opt); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:117:13 @@ -272,8 +296,9 @@ LL | let _ = deep.0.or_else(|| None); | help: use `or` instead | -LL | let _ = deep.0.or(None); - | ~~~~~~~~ +LL - let _ = deep.0.or_else(|| None); +LL + let _ = deep.0.or(None); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:118:13 @@ -283,8 +308,9 @@ LL | let _ = deep.0.get_or_insert_with(|| 2); | help: use `get_or_insert` instead | -LL | let _ = deep.0.get_or_insert(2); - | ~~~~~~~~~~~~~~~~ +LL - let _ = deep.0.get_or_insert_with(|| 2); +LL + let _ = deep.0.get_or_insert(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:119:13 @@ -294,8 +320,9 @@ LL | let _ = deep.0.ok_or_else(|| 2); | help: use `ok_or` instead | -LL | let _ = deep.0.ok_or(2); - | ~~~~~~~~ +LL - let _ = deep.0.ok_or_else(|| 2); +LL + let _ = deep.0.ok_or(2); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:150:28 @@ -305,8 +332,9 @@ LL | let _: Option = None.or_else(|| Some(3)); | help: use `or` instead | -LL | let _: Option = None.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _: Option = None.or_else(|| Some(3)); +LL + let _: Option = None.or(Some(3)); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:151:13 @@ -316,8 +344,9 @@ LL | let _ = deep.0.or_else(|| Some(3)); | help: use `or` instead | -LL | let _ = deep.0.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _ = deep.0.or_else(|| Some(3)); +LL + let _ = deep.0.or(Some(3)); + | error: unnecessary closure used to substitute value for `Option::None` --> tests/ui/unnecessary_lazy_eval.rs:152:13 @@ -327,8 +356,9 @@ LL | let _ = opt.or_else(|| Some(3)); | help: use `or` instead | -LL | let _ = opt.or(Some(3)); - | ~~~~~~~~~~~ +LL - let _ = opt.or_else(|| Some(3)); +LL + let _ = opt.or(Some(3)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:158:13 @@ -338,8 +368,9 @@ LL | let _ = res2.unwrap_or_else(|_| 2); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| 2); +LL + let _ = res2.unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:159:13 @@ -349,8 +380,9 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(astronomers_pi); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| astronomers_pi); +LL + let _ = res2.unwrap_or(astronomers_pi); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:160:13 @@ -360,8 +392,9 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | help: use `unwrap_or` instead | -LL | let _ = res2.unwrap_or(ext_str.some_field); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = res2.unwrap_or_else(|_| ext_str.some_field); +LL + let _ = res2.unwrap_or(ext_str.some_field); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:182:35 @@ -371,8 +404,9 @@ LL | let _: Result = res.and_then(|_| Err(2)); | help: use `and` instead | -LL | let _: Result = res.and(Err(2)); - | ~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(2)); +LL + let _: Result = res.and(Err(2)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:183:35 @@ -382,8 +416,9 @@ LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | help: use `and` instead | -LL | let _: Result = res.and(Err(astronomers_pi)); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(astronomers_pi)); +LL + let _: Result = res.and(Err(astronomers_pi)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:184:35 @@ -393,8 +428,9 @@ LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)) | help: use `and` instead | -LL | let _: Result = res.and(Err(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.and_then(|_| Err(ext_str.some_field)); +LL + let _: Result = res.and(Err(ext_str.some_field)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:186:35 @@ -404,8 +440,9 @@ LL | let _: Result = res.or_else(|_| Ok(2)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(2)); - | ~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(2)); +LL + let _: Result = res.or(Ok(2)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:187:35 @@ -415,8 +452,9 @@ LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(astronomers_pi)); - | ~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(astronomers_pi)); +LL + let _: Result = res.or(Ok(astronomers_pi)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:188:35 @@ -426,8 +464,9 @@ LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | help: use `or` instead | -LL | let _: Result = res.or(Ok(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _: Result = res.or_else(|_| Ok(ext_str.some_field)); +LL + let _: Result = res.or(Ok(ext_str.some_field)); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval.rs:189:35 @@ -440,8 +479,9 @@ LL | | or_else(|_| Ok(ext_str.some_field)); | help: use `or` instead | -LL | or(Ok(ext_str.some_field)); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - or_else(|_| Ok(ext_str.some_field)); +LL + or(Ok(ext_str.some_field)); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:219:14 @@ -451,8 +491,9 @@ LL | let _x = false.then(|| i32::MAX + 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX + 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX + 1); +LL + let _x = false.then_some(i32::MAX + 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:221:14 @@ -462,8 +503,9 @@ LL | let _x = false.then(|| i32::MAX * 2); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX * 2); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX * 2); +LL + let _x = false.then_some(i32::MAX * 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:223:14 @@ -473,8 +515,9 @@ LL | let _x = false.then(|| i32::MAX - 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX - 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX - 1); +LL + let _x = false.then_some(i32::MAX - 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:225:14 @@ -484,8 +527,9 @@ LL | let _x = false.then(|| i32::MIN - 1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN - 1); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN - 1); +LL + let _x = false.then_some(i32::MIN - 1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:227:14 @@ -495,8 +539,9 @@ LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | help: use `then_some` instead | -LL | let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); +LL + let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:229:14 @@ -506,8 +551,9 @@ LL | let _x = false.then(|| 255u8 << 7); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 << 7); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 << 7); +LL + let _x = false.then_some(255u8 << 7); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:231:14 @@ -517,8 +563,9 @@ LL | let _x = false.then(|| 255u8 << 8); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 << 8); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 << 8); +LL + let _x = false.then_some(255u8 << 8); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:233:14 @@ -528,8 +575,9 @@ LL | let _x = false.then(|| 255u8 >> 8); | help: use `then_some` instead | -LL | let _x = false.then_some(255u8 >> 8); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255u8 >> 8); +LL + let _x = false.then_some(255u8 >> 8); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:236:14 @@ -539,8 +587,9 @@ LL | let _x = false.then(|| i32::MAX + -1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MAX + -1); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MAX + -1); +LL + let _x = false.then_some(i32::MAX + -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:238:14 @@ -550,8 +599,9 @@ LL | let _x = false.then(|| -i32::MAX); | help: use `then_some` instead | -LL | let _x = false.then_some(-i32::MAX); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| -i32::MAX); +LL + let _x = false.then_some(-i32::MAX); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:240:14 @@ -561,8 +611,9 @@ LL | let _x = false.then(|| -i32::MIN); | help: use `then_some` instead | -LL | let _x = false.then_some(-i32::MIN); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| -i32::MIN); +LL + let _x = false.then_some(-i32::MIN); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:243:14 @@ -572,8 +623,9 @@ LL | let _x = false.then(|| 255 >> -7); | help: use `then_some` instead | -LL | let _x = false.then_some(255 >> -7); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255 >> -7); +LL + let _x = false.then_some(255 >> -7); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:245:14 @@ -583,8 +635,9 @@ LL | let _x = false.then(|| 255 << -1); | help: use `then_some` instead | -LL | let _x = false.then_some(255 << -1); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 255 << -1); +LL + let _x = false.then_some(255 << -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:247:14 @@ -594,8 +647,9 @@ LL | let _x = false.then(|| 1 / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(1 / 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 1 / 0); +LL + let _x = false.then_some(1 / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:249:14 @@ -605,8 +659,9 @@ LL | let _x = false.then(|| x << -1); | help: use `then_some` instead | -LL | let _x = false.then_some(x << -1); - | ~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x << -1); +LL + let _x = false.then_some(x << -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:251:14 @@ -616,8 +671,9 @@ LL | let _x = false.then(|| x << 2); | help: use `then_some` instead | -LL | let _x = false.then_some(x << 2); - | ~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x << 2); +LL + let _x = false.then_some(x << 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:261:14 @@ -627,8 +683,9 @@ LL | let _x = false.then(|| x / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(x / 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x / 0); +LL + let _x = false.then_some(x / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:263:14 @@ -638,8 +695,9 @@ LL | let _x = false.then(|| x % 0); | help: use `then_some` instead | -LL | let _x = false.then_some(x % 0); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| x % 0); +LL + let _x = false.then_some(x % 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:266:14 @@ -649,8 +707,9 @@ LL | let _x = false.then(|| 1 / -1); | help: use `then_some` instead | -LL | let _x = false.then_some(1 / -1); - | ~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 1 / -1); +LL + let _x = false.then_some(1 / -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:268:14 @@ -660,8 +719,9 @@ LL | let _x = false.then(|| i32::MIN / -1); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN / -1); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN / -1); +LL + let _x = false.then_some(i32::MIN / -1); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:271:14 @@ -671,8 +731,9 @@ LL | let _x = false.then(|| i32::MIN / 0); | help: use `then_some` instead | -LL | let _x = false.then_some(i32::MIN / 0); - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| i32::MIN / 0); +LL + let _x = false.then_some(i32::MIN / 0); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:273:14 @@ -682,8 +743,9 @@ LL | let _x = false.then(|| 4 / 2); | help: use `then_some` instead | -LL | let _x = false.then_some(4 / 2); - | ~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| 4 / 2); +LL + let _x = false.then_some(4 / 2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval.rs:281:14 @@ -693,8 +755,9 @@ LL | let _x = false.then(|| f1 + f2); | help: use `then_some` instead | -LL | let _x = false.then_some(f1 + f2); - | ~~~~~~~~~~~~~~~~~~ +LL - let _x = false.then(|| f1 + f2); +LL + let _x = false.then_some(f1 + f2); + | error: aborting due to 63 previous errors diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 390235b21247..9688c44c9145 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -8,8 +8,9 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|()| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:19:13 @@ -19,8 +20,9 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|e::E| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used to substitute value for `Result::Err` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:21:13 @@ -30,8 +32,9 @@ LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | help: use `unwrap_or` instead | -LL | let _ = Ok(1).unwrap_or(2); - | ~~~~~~~~~~~~ +LL - let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); +LL + let _ = Ok(1).unwrap_or(2); + | error: unnecessary closure used with `bool::then` --> tests/ui/unnecessary_lazy_eval_unfixable.rs:31:13 @@ -41,8 +44,9 @@ LL | let _ = true.then(|| -> &[u8] { &[] }); | help: use `then_some` instead | -LL | let _ = true.then_some({ &[] }); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = true.then(|| -> &[u8] { &[] }); +LL + let _ = true.then_some({ &[] }); + | error: aborting due to 4 previous errors diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 37ee9195fce6..631bf0837266 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -62,8 +62,9 @@ LL | let _val = None::<()>.expect("this always happens"); | help: remove the `None` and `expect()` | -LL | let _val = panic!("this always happens"); - | ~~~~~~~ +LL - let _val = None::<()>.expect("this always happens"); +LL + let _val = panic!("this always happens"); + | error: used `unwrap_or_default()` on `None` value --> tests/ui/unnecessary_literal_unwrap.rs:22:24 @@ -133,8 +134,9 @@ LL | None::<()>.expect("this always happens"); | help: remove the `None` and `expect()` | -LL | panic!("this always happens"); - | ~~~~~~~ +LL - None::<()>.expect("this always happens"); +LL + panic!("this always happens"); + | error: used `unwrap_or_default()` on `None` value --> tests/ui/unnecessary_literal_unwrap.rs:30:5 @@ -222,8 +224,9 @@ LL | let _val = Ok::<_, ()>(1).unwrap_err(); | help: remove the `Ok` and `unwrap_err()` | -LL | let _val = panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - let _val = Ok::<_, ()>(1).unwrap_err(); +LL + let _val = panic!("{:?}", 1); + | error: used `expect_err()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:41:16 @@ -233,8 +236,9 @@ LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | help: remove the `Ok` and `expect_err()` | -LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - let _val = Ok::<_, ()>(1).expect_err("this always happens"); +LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:43:5 @@ -268,8 +272,9 @@ LL | Ok::<_, ()>(1).unwrap_err(); | help: remove the `Ok` and `unwrap_err()` | -LL | panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - Ok::<_, ()>(1).unwrap_err(); +LL + panic!("{:?}", 1); + | error: used `expect_err()` on `Ok` value --> tests/ui/unnecessary_literal_unwrap.rs:46:5 @@ -279,8 +284,9 @@ LL | Ok::<_, ()>(1).expect_err("this always happens"); | help: remove the `Ok` and `expect_err()` | -LL | panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - Ok::<_, ()>(1).expect_err("this always happens"); +LL + panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_err()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:50:16 @@ -314,8 +320,9 @@ LL | let _val = Err::<(), _>(1).unwrap(); | help: remove the `Err` and `unwrap()` | -LL | let _val = panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - let _val = Err::<(), _>(1).unwrap(); +LL + let _val = panic!("{:?}", 1); + | error: used `expect()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:53:16 @@ -325,8 +332,9 @@ LL | let _val = Err::<(), _>(1).expect("this always happens"); | help: remove the `Err` and `expect()` | -LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - let _val = Err::<(), _>(1).expect("this always happens"); +LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_err()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:55:5 @@ -360,8 +368,9 @@ LL | Err::<(), _>(1).unwrap(); | help: remove the `Err` and `unwrap()` | -LL | panic!("{:?}", 1); - | ~~~~~~~~~~~~~~ ~ +LL - Err::<(), _>(1).unwrap(); +LL + panic!("{:?}", 1); + | error: used `expect()` on `Err` value --> tests/ui/unnecessary_literal_unwrap.rs:58:5 @@ -371,8 +380,9 @@ LL | Err::<(), _>(1).expect("this always happens"); | help: remove the `Err` and `expect()` | -LL | panic!("{1}: {:?}", 1, "this always happens"); - | ~~~~~~~~~~~~~~~~~~~ ~ +LL - Err::<(), _>(1).expect("this always happens"); +LL + panic!("{1}: {:?}", 1, "this always happens"); + | error: used `unwrap_or()` on `Some` value --> tests/ui/unnecessary_literal_unwrap.rs:62:16 diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index 2ae327f0bf88..9f38b8c8d93a 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -8,8 +8,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_or)]` help: use a standard comparison instead | -LL | let _ = Some(5) == Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5); +LL + let _ = Some(5) == Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:14:13 @@ -19,8 +20,9 @@ LL | let _ = Some(5).map_or(true, |n| n != 5); | help: use a standard comparison instead | -LL | let _ = Some(5) != Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(true, |n| n != 5); +LL + let _ = Some(5) != Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:15:13 @@ -34,8 +36,12 @@ LL | | }); | help: use a standard comparison instead | -LL | let _ = Some(5) == Some(5); - | ~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| { +LL - let _ = 1; +LL - n == 5 +LL - }); +LL + let _ = Some(5) == Some(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:19:13 @@ -121,8 +127,9 @@ LL | let _ = Ok::(5).map_or(false, |n| n == 5); | help: use a standard comparison instead | -LL | let _ = Ok::(5) == Ok(5); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Ok::(5).map_or(false, |n| n == 5); +LL + let _ = Ok::(5) == Ok(5); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:29:13 @@ -132,8 +139,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)).then(|| 1); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); +LL + let _ = (Some(5) == Some(5)).then(|| 1); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:30:13 @@ -167,8 +175,9 @@ LL | let _ = !Some(5).map_or(false, |n| n == 5); | help: use a standard comparison instead | -LL | let _ = !(Some(5) == Some(5)); - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = !Some(5).map_or(false, |n| n == 5); +LL + let _ = !(Some(5) == Some(5)); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:33:13 @@ -178,8 +187,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5) || false; | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)) || false; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5) || false; +LL + let _ = (Some(5) == Some(5)) || false; + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:34:13 @@ -189,8 +199,9 @@ LL | let _ = Some(5).map_or(false, |n| n == 5) as usize; | help: use a standard comparison instead | -LL | let _ = (Some(5) == Some(5)) as usize; - | ~~~~~~~~~~~~~~~~~~~~ +LL - let _ = Some(5).map_or(false, |n| n == 5) as usize; +LL + let _ = (Some(5) == Some(5)) as usize; + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:58:13 @@ -248,8 +259,9 @@ LL | let _ = r.map_or(false, |x| x == 8); | help: use a standard comparison instead | -LL | let _ = r == Ok(8); - | ~~~~~~~~~~ +LL - let _ = r.map_or(false, |x| x == 8); +LL + let _ = r == Ok(8); + | error: this `map_or` can be simplified --> tests/ui/unnecessary_map_or.rs:90:5 diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index b304d4dce6ea..b06ab91dc8de 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -13,8 +13,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::unnecessary_wraps)]` help: remove `Option` from the return type... | -LL | fn func1(a: bool, b: bool) -> i32 { - | ~~~ +LL - fn func1(a: bool, b: bool) -> Option { +LL + fn func1(a: bool, b: bool) -> i32 { + | help: ...and then change returning expressions | LL ~ return 42; @@ -40,8 +41,9 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func2(a: bool, b: bool) -> i32 { - | ~~~ +LL - fn func2(a: bool, b: bool) -> Option { +LL + fn func2(a: bool, b: bool) -> i32 { + | help: ...and then change returning expressions | LL ~ return 10; @@ -60,11 +62,13 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func5() -> i32 { - | ~~~ +LL - fn func5() -> Option { +LL + fn func5() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Some(1) +LL + 1 | error: this function's return value is unnecessarily wrapped by `Result` @@ -78,11 +82,13 @@ LL | | } | help: remove `Result` from the return type... | -LL | fn func7() -> i32 { - | ~~~ +LL - fn func7() -> Result { +LL + fn func7() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Ok(1) +LL + 1 | error: this function's return value is unnecessarily wrapped by `Option` @@ -96,11 +102,13 @@ LL | | } | help: remove `Option` from the return type... | -LL | fn func12() -> i32 { - | ~~~ +LL - fn func12() -> Option { +LL + fn func12() -> i32 { + | help: ...and then change returning expressions | -LL | 1 +LL - Some(1) +LL + 1 | error: this function's return value is unnecessary @@ -116,8 +124,9 @@ LL | | } | help: remove the return type... | -LL | fn issue_6640_1(a: bool, b: bool) -> () { - | ~~ +LL - fn issue_6640_1(a: bool, b: bool) -> Option<()> { +LL + fn issue_6640_1(a: bool, b: bool) -> () { + | help: ...and then remove returned values | LL ~ return ; @@ -142,8 +151,9 @@ LL | | } | help: remove the return type... | -LL | fn issue_6640_2(a: bool, b: bool) -> () { - | ~~ +LL - fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { +LL + fn issue_6640_2(a: bool, b: bool) -> () { + | help: ...and then remove returned values | LL ~ return ; diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index bd15ef62368e..4325df143042 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -8,8 +8,9 @@ LL | if let box 0 | box 2 = Box::new(0) {} = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | -LL | if let box (0 | 2) = Box::new(0) {} - | ~~~~~~~~~~~ +LL - if let box 0 | box 2 = Box::new(0) {} +LL + if let box (0 | 2) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:17:12 @@ -19,8 +20,9 @@ LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | help: nest the patterns | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} +LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:19:12 @@ -30,8 +32,9 @@ LL | if let Some(1) | C0 | Some(2) = None {} | help: nest the patterns | -LL | if let Some(1 | 2) | C0 = None {} - | ~~~~~~~~~~~~~~~~ +LL - if let Some(1) | C0 | Some(2) = None {} +LL + if let Some(1 | 2) | C0 = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:20:12 @@ -41,8 +44,9 @@ LL | if let &mut 0 | &mut 2 = &mut 0 {} | help: nest the patterns | -LL | if let &mut (0 | 2) = &mut 0 {} - | ~~~~~~~~~~~~ +LL - if let &mut 0 | &mut 2 = &mut 0 {} +LL + if let &mut (0 | 2) = &mut 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:21:12 @@ -52,8 +56,9 @@ LL | if let x @ 0 | x @ 2 = 0 {} | help: nest the patterns | -LL | if let x @ (0 | 2) = 0 {} - | ~~~~~~~~~~~ +LL - if let x @ 0 | x @ 2 = 0 {} +LL + if let x @ (0 | 2) = 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:22:12 @@ -63,8 +68,9 @@ LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | help: nest the patterns | -LL | if let (0, 1 | 2 | 3) = (0, 0) {} - | ~~~~~~~~~~~~~~ +LL - if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} +LL + if let (0, 1 | 2 | 3) = (0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:23:12 @@ -74,8 +80,9 @@ LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | help: nest the patterns | -LL | if let (1 | 2 | 3, 0) = (0, 0) {} - | ~~~~~~~~~~~~~~ +LL - if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} +LL + if let (1 | 2 | 3, 0) = (0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:24:12 @@ -85,8 +92,9 @@ LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | help: nest the patterns | -LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} +LL + if let (x, ..) | (x, 1 | 2) = (0, 1) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:25:12 @@ -96,8 +104,9 @@ LL | if let [0] | [1] = [0] {} | help: nest the patterns | -LL | if let [0 | 1] = [0] {} - | ~~~~~~~ +LL - if let [0] | [1] = [0] {} +LL + if let [0 | 1] = [0] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:26:12 @@ -107,8 +116,9 @@ LL | if let [x, 0] | [x, 1] = [0, 1] {} | help: nest the patterns | -LL | if let [x, 0 | 1] = [0, 1] {} - | ~~~~~~~~~~ +LL - if let [x, 0] | [x, 1] = [0, 1] {} +LL + if let [x, 0 | 1] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:27:12 @@ -118,8 +128,9 @@ LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | help: nest the patterns | -LL | if let [x, 0 | 1 | 2] = [0, 1] {} - | ~~~~~~~~~~~~~~ +LL - if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} +LL + if let [x, 0 | 1 | 2] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:28:12 @@ -129,8 +140,9 @@ LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | help: nest the patterns | -LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} - | ~~~~~~~~~~~~~~~~~~~~ +LL - if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} +LL + if let [x, ..] | [x, 1 | 2] = [0, 1] {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:30:12 @@ -140,8 +152,9 @@ LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(0 | 1, x) = TS(0, 0) {} - | ~~~~~~~~~~~~ +LL - if let TS(0, x) | TS(1, x) = TS(0, 0) {} +LL + if let TS(0 | 1, x) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:31:12 @@ -151,8 +164,9 @@ LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} - | ~~~~~~~~~~~~~~~~ +LL - if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} +LL + if let TS(1 | 2 | 3, 0) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:32:12 @@ -162,8 +176,9 @@ LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | help: nest the patterns | -LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} +LL + if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:37:12 @@ -173,8 +188,9 @@ LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | help: nest the patterns | -LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} - | ~~~~~~~~~~~~~~~~~ +LL - if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} +LL + if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns.rs:48:12 @@ -184,8 +200,9 @@ LL | if let [1] | [53] = [0] {} | help: nest the patterns | -LL | if let [1 | 53] = [0] {} - | ~~~~~~~~ +LL - if let [1] | [53] = [0] {} +LL + if let [1 | 53] = [0] {} + | error: aborting due to 17 previous errors diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 54f03937508a..3d8968551b96 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -8,8 +8,9 @@ LL | if let Some(Some(0)) | Some(Some(1)) = None {} = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | -LL | if let Some(Some(0 | 1)) = None {} - | ~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0)) | Some(Some(1)) = None {} +LL + if let Some(Some(0 | 1)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:13:12 @@ -19,8 +20,9 @@ LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} +LL + if let Some(Some(0 | 1 | 2)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:14:12 @@ -30,8 +32,9 @@ LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} +LL + if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:15:12 @@ -41,8 +44,9 @@ LL | if let Some(Some(0) | Some(1 | 2)) = None {} | help: nest the patterns | -LL | if let Some(Some(0 | 1 | 2)) = None {} - | ~~~~~~~~~~~~~~~~~~~~~ +LL - if let Some(Some(0) | Some(1 | 2)) = None {} +LL + if let Some(Some(0 | 1 | 2)) = None {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:16:12 @@ -52,8 +56,9 @@ LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | help: nest the patterns | -LL | if let ((0 | 1 | 2,),) = ((0,),) {} - | ~~~~~~~~~~~~~~~ +LL - if let ((0,),) | ((1,) | (2,),) = ((0,),) {} +LL + if let ((0 | 1 | 2,),) = ((0,),) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:17:12 @@ -63,8 +68,9 @@ LL | if let 0 | (1 | 2) = 0 {} | help: nest the patterns | -LL | if let 0 | 1 | 2 = 0 {} - | ~~~~~~~~~ +LL - if let 0 | (1 | 2) = 0 {} +LL + if let 0 | 1 | 2 = 0 {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:18:12 @@ -74,8 +80,9 @@ LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | help: nest the patterns | -LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} - | ~~~~~~~~~~~~~~~~~~~~~~~ +LL - if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} +LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + | error: unnested or-patterns --> tests/ui/unnested_or_patterns2.rs:19:12 @@ -85,8 +92,9 @@ LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | help: nest the patterns | -LL | if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} - | ~~~~~~~~~~~~~~~~~~~ +LL - if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} +LL + if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} + | error: aborting due to 8 previous errors diff --git a/tests/ui/unused_enumerate_index.stderr b/tests/ui/unused_enumerate_index.stderr index 6ec07dcbff0a..02d65f064308 100644 --- a/tests/ui/unused_enumerate_index.stderr +++ b/tests/ui/unused_enumerate_index.stderr @@ -8,8 +8,9 @@ LL | for (_, x) in v.iter().enumerate() { = help: to override `-D warnings` add `#[allow(clippy::unused_enumerate_index)]` help: remove the `.enumerate()` call | -LL | for x in v.iter() { - | ~ ~~~~~~~~ +LL - for (_, x) in v.iter().enumerate() { +LL + for x in v.iter() { + | error: you seem to use `.enumerate()` and immediately discard the index --> tests/ui/unused_enumerate_index.rs:59:19 @@ -19,8 +20,9 @@ LL | for (_, x) in dummy.enumerate() { | help: remove the `.enumerate()` call | -LL | for x in dummy { - | ~ ~~~~~ +LL - for (_, x) in dummy.enumerate() { +LL + for x in dummy { + | error: you seem to use `.enumerate()` and immediately discard the index --> tests/ui/unused_enumerate_index.rs:63:39 diff --git a/tests/ui/unused_format_specs.stderr b/tests/ui/unused_format_specs.stderr index df61d59130ef..d3c0530ced46 100644 --- a/tests/ui/unused_format_specs.stderr +++ b/tests/ui/unused_format_specs.stderr @@ -8,8 +8,9 @@ LL | println!("{:5}.", format_args!("")); = help: to override `-D warnings` add `#[allow(clippy::unused_format_specs)]` help: for the width to apply consider using `format!()` | -LL | println!("{:5}.", format!("")); - | ~~~~~~ +LL - println!("{:5}.", format_args!("")); +LL + println!("{:5}.", format!("")); + | help: if the current behavior is intentional, remove the format specifiers | LL - println!("{:5}.", format_args!("")); @@ -24,8 +25,9 @@ LL | println!("{:.3}", format_args!("abcde")); | help: for the precision to apply consider using `format!()` | -LL | println!("{:.3}", format!("abcde")); - | ~~~~~~ +LL - println!("{:.3}", format_args!("abcde")); +LL + println!("{:.3}", format!("abcde")); + | help: if the current behavior is intentional, remove the format specifiers | LL - println!("{:.3}", format_args!("abcde")); @@ -66,8 +68,9 @@ LL | usr_println!(true, "{:5}.", format_args!("")); | help: for the width to apply consider using `format!()` | -LL | usr_println!(true, "{:5}.", format!("")); - | ~~~~~~ +LL - usr_println!(true, "{:5}.", format_args!("")); +LL + usr_println!(true, "{:5}.", format!("")); + | help: if the current behavior is intentional, remove the format specifiers | LL - usr_println!(true, "{:5}.", format_args!("")); @@ -82,8 +85,9 @@ LL | usr_println!(true, "{:.3}", format_args!("abcde")); | help: for the precision to apply consider using `format!()` | -LL | usr_println!(true, "{:.3}", format!("abcde")); - | ~~~~~~ +LL - usr_println!(true, "{:.3}", format_args!("abcde")); +LL + usr_println!(true, "{:.3}", format!("abcde")); + | help: if the current behavior is intentional, remove the format specifiers | LL - usr_println!(true, "{:.3}", format_args!("abcde")); diff --git a/tests/ui/unused_result_ok.stderr b/tests/ui/unused_result_ok.stderr index 241e0c71261e..024aafa6bbb8 100644 --- a/tests/ui/unused_result_ok.stderr +++ b/tests/ui/unused_result_ok.stderr @@ -8,8 +8,9 @@ LL | x.parse::().ok(); = help: to override `-D warnings` add `#[allow(clippy::unused_result_ok)]` help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = x.parse::(); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - x.parse::().ok(); +LL + let _ = x.parse::(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:18:5 @@ -19,8 +20,9 @@ LL | x . parse::() . ok (); | help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = x . parse::(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - x . parse::() . ok (); +LL + let _ = x . parse::(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:34:5 @@ -30,8 +32,9 @@ LL | v!().ok(); | help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = v!(); - | ~~~~~~~~~~~~ +LL - v!().ok(); +LL + let _ = v!(); + | error: ignoring a result with `.ok()` is misleading --> tests/ui/unused_result_ok.rs:29:9 @@ -45,8 +48,9 @@ LL | w!(); = note: this error originates in the macro `w` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider using `let _ =` and removing the call to `.ok()` instead | -LL | let _ = Ok::<(), ()>(()); - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Ok::<(), ()>(()).ok(); +LL + let _ = Ok::<(), ()>(()); + | error: aborting due to 4 previous errors From aff497f17f4264fcaaa36d4db83968bbe2b8ef19 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 10 Feb 2025 14:32:36 -0700 Subject: [PATCH 066/161] Use a separate loop to drive the check for code clusters By using a separate loop, I can just skip nodes that I don't want to process twice, instead of having to hand-build a state machine with an enum. --- clippy_lints/src/doc/mod.rs | 110 ++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index c0ee904002c9..fc6d6c4282cd 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -844,6 +844,21 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ let mut cb = fake_broken_link_callback; + check_for_code_clusters( + cx, + pulldown_cmark::Parser::new_with_broken_link_callback( + &doc, + main_body_opts() - Options::ENABLE_SMART_PUNCTUATION, + Some(&mut cb), + ) + .into_offset_iter(), + &doc, + Fragments { + doc: &doc, + fragments: &fragments, + }, + ); + // disable smart punctuation to pick up ['link'] more easily let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION; let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb)); @@ -867,12 +882,64 @@ enum Container { List(usize), } -#[derive(Clone, Copy, Eq, PartialEq)] -enum CodeCluster { - // true means already in a link, so only needs to be followed by code - // false means we've hit code, and need to find a link - First(usize, bool), - Nth(usize, usize), +/// Scan the documentation for code links that are back-to-back with code spans. +/// +/// This is done separately from the rest of the docs, because that makes it easier to produce +/// the correct messages. +fn check_for_code_clusters<'a, Events: Iterator, Range)>>( + cx: &LateContext<'_>, + events: Events, + doc: &str, + fragments: Fragments<'_>, +) { + let mut events = events.peekable(); + let mut code_starts_at = None; + let mut code_ends_at = None; + let mut code_includes_link = false; + while let Some((event, range)) = events.next() { + match event { + Start(Link { .. }) if matches!(events.peek(), Some((Code(_), _range))) => { + if code_starts_at.is_some() { + code_ends_at = Some(range.end); + } else { + code_starts_at = Some(range.start); + } + code_includes_link = true; + // skip the nested "code", because we're already handling it here + let _ = events.next(); + }, + Code(_) => { + if code_starts_at.is_some() { + code_ends_at = Some(range.end); + } else { + code_starts_at = Some(range.start); + } + }, + End(TagEnd::Link) => {}, + _ => { + if let Some(start) = code_starts_at + && let Some(end) = code_ends_at + && code_includes_link + { + if let Some(span) = fragments.span(cx, start..end) { + span_lint_and_then(cx, DOC_LINK_CODE, span, "code link adjacent to code text", |diag| { + let sugg = format!("{}", doc[start..end].replace('`', "")); + diag.span_suggestion_verbose( + span, + "wrap the entire group in `` tags", + sugg, + Applicability::MaybeIncorrect, + ); + diag.help("separate code snippets will be shown with a gap"); + }); + } + } + code_includes_link = false; + code_starts_at = None; + code_ends_at = None; + }, + } + } } /// Checks parsed documentation. @@ -906,40 +973,9 @@ fn check_doc<'a, Events: Iterator, Range { - Some(CodeCluster::First(range.start - 1, true)) - }, - (None, Code(_)) => Some(CodeCluster::First(range.start, false)), - (Some(CodeCluster::First(pos, _)), Start(Link { .. })) | (Some(CodeCluster::First(pos, true)), Code(_)) => { - Some(CodeCluster::Nth(pos, range.end)) - }, - (Some(CodeCluster::Nth(start, end)), Code(_) | Start(Link { .. })) => { - Some(CodeCluster::Nth(start, range.end.max(end))) - }, - (code_cluster @ Some(_), Code(_) | End(TagEnd::Link)) => code_cluster, - (Some(CodeCluster::First(_, _)) | None, _) => None, - (Some(CodeCluster::Nth(start, end)), _) => { - if let Some(span) = fragments.span(cx, start..end) { - span_lint_and_then(cx, DOC_LINK_CODE, span, "code link adjacent to code text", |diag| { - let sugg = format!("{}", doc[start..end].replace('`', "")); - diag.span_suggestion_verbose( - span, - "wrap the entire group in `` tags", - sugg, - Applicability::MaybeIncorrect, - ); - diag.help("separate code snippets will be shown with a gap"); - }); - } - None - }, - }; match event { Html(tag) | InlineHtml(tag) => { if tag.starts_with(" Date: Sun, 12 Jan 2025 00:01:53 +0000 Subject: [PATCH 067/161] Use MIR body to identify more "default equivalent" calls When looking for `Default` impls that could be derived, we look at the body of their `fn default()` and if it is an fn call or literal we check if they are equivalent to what `#[derive(Default)]` would have used. Now, when checking those fn calls in the `fn default()` body, we also compare against the corresponding type's `Default::default` body to see if our call is equivalent to that one. For example, given ```rust struct S; impl S { fn new() -> S { S } } impl Default for S { fn default() -> S { S::new() } } ``` `::default()` and `S::new()` are considered equivalent. Given that, if the user also writes ```rust struct R { s: S, } impl Default for R { fn default() -> R { R { s: S::new() } } } ``` the `derivable_impls` lint will now trigger. --- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_utils/src/lib.rs | 96 ++++++++++++++++++++++--- tests/ui/derivable_impls.fixed | 34 +++++++++ tests/ui/derivable_impls.rs | 49 +++++++++++++ tests/ui/derivable_impls.stderr | 57 ++++++++++++++- tests/ui/mem_replace.fixed | 2 + tests/ui/mem_replace.rs | 2 + tests/ui/mem_replace.stderr | 56 +++++++++------ 8 files changed, 264 insertions(+), 34 deletions(-) diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 6b39b753885e..f00e4b87a7df 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -104,7 +104,7 @@ pub(super) fn check<'tcx>( if (is_new(fun) && output_type_implements_default(fun)) || match call_expr { Some(call_expr) => is_default_equivalent(cx, call_expr), - None => is_default_equivalent_call(cx, fun) || closure_body_returns_empty_to_string(cx, fun), + None => is_default_equivalent_call(cx, fun, None) || closure_body_returns_empty_to_string(cx, fun), } { span_lint_and_sugg( diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 80d52a26e223..0d9502c50db6 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -113,6 +113,7 @@ use rustc_hir::{ use rustc_lexer::{TokenKind, tokenize}; use rustc_lint::{LateContext, Level, Lint, LintContext}; use rustc_middle::hir::place::PlaceBase; +use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementKind, TerminatorKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::layout::IntegerExt; @@ -919,22 +920,101 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath< } /// Returns true if the expr is equal to `Default::default` when evaluated. -pub fn is_default_equivalent_call(cx: &LateContext<'_>, repl_func: &Expr<'_>) -> bool { +pub fn is_default_equivalent_call( + cx: &LateContext<'_>, + repl_func: &Expr<'_>, + whole_call_expr: Option<&Expr<'_>>, +) -> bool { if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind && let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id() && (is_diag_trait_item(cx, repl_def_id, sym::Default) || is_default_equivalent_ctor(cx, repl_def_id, repl_func_qpath)) { - true - } else { - false + return true; } + + // Get the type of the whole method call expression, find the exact method definition, look at + // its body and check if it is similar to the corresponding `Default::default()` body. + let Some(e) = whole_call_expr else { return false }; + let Some(default_fn_def_id) = cx.tcx.get_diagnostic_item(sym::default_fn) else { + return false; + }; + let Some(ty) = cx.tcx.typeck(e.hir_id.owner.def_id).expr_ty_adjusted_opt(e) else { + return false; + }; + let args = rustc_ty::GenericArgs::for_item(cx.tcx, default_fn_def_id, |param, _| { + if let rustc_ty::GenericParamDefKind::Lifetime = param.kind { + cx.tcx.lifetimes.re_erased.into() + } else if param.index == 0 && param.name == kw::SelfUpper { + ty.into() + } else { + param.to_error(cx.tcx) + } + }); + let instance = rustc_ty::Instance::try_resolve(cx.tcx, cx.typing_env(), default_fn_def_id, args); + + let Ok(Some(instance)) = instance else { return false }; + if let rustc_ty::InstanceKind::Item(def) = instance.def + && !cx.tcx.is_mir_available(def) + { + return false; + } + let ExprKind::Path(ref repl_func_qpath) = repl_func.kind else { + return false; + }; + let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id() else { + return false; + }; + + // Get the MIR Body for the `::default()` function. + // If it is a value or call (either fn or ctor), we compare its `DefId` against the one for the + // resolution of the expression we had in the path. This lets us identify, for example, that + // the body of ` as Default>::default()` is a `Vec::new()`, and the field was being + // initialized to `Vec::new()` as well. + let body = cx.tcx.instance_mir(instance.def); + for block_data in body.basic_blocks.iter() { + if block_data.statements.len() == 1 + && let StatementKind::Assign(assign) = &block_data.statements[0].kind + && assign.0.local == RETURN_PLACE + && let Rvalue::Aggregate(kind, _places) = &assign.1 + && let AggregateKind::Adt(did, variant_index, _, _, _) = &**kind + && let def = cx.tcx.adt_def(did) + && let variant = &def.variant(*variant_index) + && variant.fields.is_empty() + && let Some((_, did)) = variant.ctor + && did == repl_def_id + { + return true; + } else if block_data.statements.is_empty() + && let Some(term) = &block_data.terminator + { + match &term.kind { + TerminatorKind::Call { + func: Operand::Constant(c), + .. + } if let rustc_ty::FnDef(did, _args) = c.ty().kind() + && *did == repl_def_id => + { + return true; + }, + TerminatorKind::TailCall { + func: Operand::Constant(c), + .. + } if let rustc_ty::FnDef(did, _args) = c.ty().kind() + && *did == repl_def_id => + { + return true; + }, + _ => {}, + } + } + } + false } -/// Returns true if the expr is equal to `Default::default()` of it's type when evaluated. +/// Returns true if the expr is equal to `Default::default()` of its type when evaluated. /// -/// It doesn't cover all cases, for example indirect function calls (some of std -/// functions are supported) but it is the best we have. +/// It doesn't cover all cases, like struct literals, but it is a close approximation. pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { match &e.kind { ExprKind::Lit(lit) => match lit.node { @@ -955,7 +1035,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { false } }, - ExprKind::Call(repl_func, []) => is_default_equivalent_call(cx, repl_func), + ExprKind::Call(repl_func, []) => is_default_equivalent_call(cx, repl_func, Some(e)), ExprKind::Call(from_func, [arg]) => is_default_equivalent_from(cx, from_func, arg), ExprKind::Path(qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, e.hir_id), OptionNone), ExprKind::AddrOf(rustc_hir::BorrowKind::Ref, _, expr) => matches!(expr.kind, ExprKind::Array([])), diff --git a/tests/ui/derivable_impls.fixed b/tests/ui/derivable_impls.fixed index c85f384fd6eb..65bfded38835 100644 --- a/tests/ui/derivable_impls.fixed +++ b/tests/ui/derivable_impls.fixed @@ -144,6 +144,40 @@ impl Default for SpecializedImpl2 { } } +#[derive(Default)] +pub struct DirectDefaultDefaultCall { + v: Vec, +} + + +#[derive(Default)] +pub struct EquivalentToDefaultDefaultCallVec { + v: Vec, +} + + +pub struct S { + x: i32, +} + +impl S { + fn new() -> S { + S { x: 42 } + } +} + +impl Default for S { + fn default() -> Self { + Self::new() + } +} + +#[derive(Default)] +pub struct EquivalentToDefaultDefaultCallLocal { + v: S, +} + + // https://github.com/rust-lang/rust-clippy/issues/7654 pub struct Color { diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index 21d73ba8b777..eb9a007bf10f 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -181,6 +181,55 @@ impl Default for SpecializedImpl2 { } } +pub struct DirectDefaultDefaultCall { + v: Vec, +} + +impl Default for DirectDefaultDefaultCall { + fn default() -> Self { + // When calling `Default::default()` in all fields, we know it is the same as deriving. + Self { v: Default::default() } + } +} + +pub struct EquivalentToDefaultDefaultCallVec { + v: Vec, +} + +impl Default for EquivalentToDefaultDefaultCallVec { + fn default() -> Self { + // The body of `::default()` is `Vec::new()`, so they are equivalent. + Self { v: Vec::new() } + } +} + +pub struct S { + x: i32, +} + +impl S { + fn new() -> S { + S { x: 42 } + } +} + +impl Default for S { + fn default() -> Self { + Self::new() + } +} + +pub struct EquivalentToDefaultDefaultCallLocal { + v: S, +} + +impl Default for EquivalentToDefaultDefaultCallLocal { + fn default() -> Self { + // The body of `::default()` is `S::new()`, so they are equivalent. + Self { v: S::new() } + } +} + // https://github.com/rust-lang/rust-clippy/issues/7654 pub struct Color { diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index 0caea892358a..a14c0b28c4ea 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -98,7 +98,58 @@ LL ~ struct WithoutSelfParan(bool); | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:216:1 + --> tests/ui/derivable_impls.rs:188:1 + | +LL | / impl Default for DirectDefaultDefaultCall { +LL | | fn default() -> Self { +LL | | // When calling `Default::default()` in all fields, we know it is the same as deriving. +LL | | Self { v: Default::default() } +LL | | } +LL | | } + | |_^ + | +help: replace the manual implementation with a derive attribute + | +LL + #[derive(Default)] +LL ~ pub struct DirectDefaultDefaultCall { + | + +error: this `impl` can be derived + --> tests/ui/derivable_impls.rs:199:1 + | +LL | / impl Default for EquivalentToDefaultDefaultCallVec { +LL | | fn default() -> Self { +LL | | // The body of `::default()` is `Vec::new()`, so they are equivalent. +LL | | Self { v: Vec::new() } +LL | | } +LL | | } + | |_^ + | +help: replace the manual implementation with a derive attribute + | +LL + #[derive(Default)] +LL ~ pub struct EquivalentToDefaultDefaultCallVec { + | + +error: this `impl` can be derived + --> tests/ui/derivable_impls.rs:226:1 + | +LL | / impl Default for EquivalentToDefaultDefaultCallLocal { +LL | | fn default() -> Self { +LL | | // The body of `::default()` is `S::new()`, so they are equivalent. +LL | | Self { v: S::new() } +LL | | } +LL | | } + | |_^ + | +help: replace the manual implementation with a derive attribute + | +LL + #[derive(Default)] +LL ~ pub struct EquivalentToDefaultDefaultCallLocal { + | + +error: this `impl` can be derived + --> tests/ui/derivable_impls.rs:265:1 | LL | / impl Default for RepeatDefault1 { LL | | fn default() -> Self { @@ -114,7 +165,7 @@ LL ~ pub struct RepeatDefault1 { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:250:1 + --> tests/ui/derivable_impls.rs:299:1 | LL | / impl Default for SimpleEnum { LL | | fn default() -> Self { @@ -132,5 +183,5 @@ LL ~ #[default] LL ~ Bar, | -error: aborting due to 8 previous errors +error: aborting due to 11 previous errors diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 4210dbbe82d3..248ecd5d85f4 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -18,10 +18,12 @@ fn replace_option_with_none() { fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::take(&mut s); + let _ = std::mem::take(&mut s); let s = &mut String::from("foo"); let _ = std::mem::take(s); let _ = std::mem::take(s); + let _ = std::mem::take(s); let mut v = vec![123]; let _ = std::mem::take(&mut v); diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index bd7ad78b2af2..486d2ba1b6a5 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -18,9 +18,11 @@ fn replace_option_with_none() { fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::replace(&mut s, String::default()); + let _ = std::mem::replace(&mut s, String::new()); let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); + let _ = std::mem::replace(s, String::new()); let _ = std::mem::replace(s, Default::default()); let mut v = vec![123]; diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index c33f80b01b85..a60f2253d13e 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -23,130 +23,142 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:23:13 + --> tests/ui/mem_replace.rs:21:13 + | +LL | let _ = std::mem::replace(&mut s, String::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` + +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> tests/ui/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` - --> tests/ui/mem_replace.rs:24:13 + --> tests/ui/mem_replace.rs:25:13 + | +LL | let _ = std::mem::replace(s, String::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` + +error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` + --> tests/ui/mem_replace.rs:26: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` - --> tests/ui/mem_replace.rs:27:13 + --> tests/ui/mem_replace.rs:29: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` - --> tests/ui/mem_replace.rs:28:13 + --> tests/ui/mem_replace.rs:30: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` - --> tests/ui/mem_replace.rs:29:13 + --> tests/ui/mem_replace.rs:31: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` - --> tests/ui/mem_replace.rs:30:13 + --> tests/ui/mem_replace.rs:32:13 | LL | let _ = std::mem::replace(&mut v, vec![]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:33:13 + --> tests/ui/mem_replace.rs:35: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` - --> tests/ui/mem_replace.rs:36:13 + --> tests/ui/mem_replace.rs:38: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` - --> tests/ui/mem_replace.rs:39:13 + --> tests/ui/mem_replace.rs:41: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` - --> tests/ui/mem_replace.rs:42:13 + --> tests/ui/mem_replace.rs:44: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` - --> tests/ui/mem_replace.rs:45:13 + --> tests/ui/mem_replace.rs:47: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` - --> tests/ui/mem_replace.rs:48:13 + --> tests/ui/mem_replace.rs:50: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` - --> tests/ui/mem_replace.rs:51:13 + --> tests/ui/mem_replace.rs:53: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` - --> tests/ui/mem_replace.rs:54:13 + --> tests/ui/mem_replace.rs:56:13 | LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:57:13 + --> tests/ui/mem_replace.rs:59: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` - --> tests/ui/mem_replace.rs:60:13 + --> tests/ui/mem_replace.rs:62: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` - --> tests/ui/mem_replace.rs:96:13 + --> tests/ui/mem_replace.rs:98:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:126:13 + --> tests/ui/mem_replace.rs:128:13 | LL | let _ = std::mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:127:13 + --> tests/ui/mem_replace.rs:129:13 | LL | let _ = std::mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:128:13 + --> tests/ui/mem_replace.rs:130: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` - --> tests/ui/mem_replace.rs:130:13 + --> tests/ui/mem_replace.rs:132:13 | LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` -error: aborting due to 24 previous errors +error: aborting due to 26 previous errors From 7139436f98045b515db7f15a65cafe5afc5b7527 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Tue, 11 Feb 2025 03:13:16 +0900 Subject: [PATCH 068/161] add index checks for the slice in `manual_slice_fill` --- clippy_lints/src/loops/manual_slice_fill.rs | 7 ++++++- tests/ui/manual_slice_fill.fixed | 18 +++++++++++++++++- tests/ui/manual_slice_fill.rs | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs index 7c6564235796..bece83eaf3d8 100644 --- a/clippy_lints/src/loops/manual_slice_fill.rs +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -4,6 +4,7 @@ use clippy_utils::macros::span_is_local; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::{HasSession, snippet_with_applicability}; use clippy_utils::ty::implements_trait; +use clippy_utils::visitors::is_local_used; use clippy_utils::{higher, peel_blocks_with_stmt, span_contains_comment}; use rustc_ast::ast::LitKind; use rustc_ast::{RangeLimits, UnOp}; @@ -43,7 +44,7 @@ pub(super) fn check<'tcx>( && let ExprKind::Block(..) = body.kind // Check if the body is an assignment to a slice element. && let ExprKind::Assign(assignee, assignval, _) = peel_blocks_with_stmt(body).kind - && let ExprKind::Index(slice, _, _) = assignee.kind + && let ExprKind::Index(slice, idx, _) = assignee.kind // Check if `len()` is used for the range end. && let ExprKind::MethodCall(path, recv,..) = end.kind && path.ident.name == sym::len @@ -58,6 +59,10 @@ pub(super) fn check<'tcx>( // The `fill` method requires that the slice's element type implements the `Clone` trait. && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() && implements_trait(cx, cx.typeck_results().expr_ty(slice), clone_trait, &[]) + // https://github.com/rust-lang/rust-clippy/issues/14192 + && let ExprKind::Path(Resolved(_, idx_path)) = idx.kind + && let Res::Local(idx_hir) = idx_path.res + && !is_local_used(cx, assignval, idx_hir) { sugg(cx, body, expr, slice.span, assignval.span); } diff --git a/tests/ui/manual_slice_fill.fixed b/tests/ui/manual_slice_fill.fixed index 397a156a2dc7..80e271117fc1 100644 --- a/tests/ui/manual_slice_fill.fixed +++ b/tests/ui/manual_slice_fill.fixed @@ -1,5 +1,5 @@ #![warn(clippy::manual_slice_fill)] -#![allow(clippy::needless_range_loop)] +#![allow(clippy::needless_range_loop, clippy::useless_vec)] macro_rules! assign_element { ($slice:ident, $index:expr) => { @@ -99,3 +99,19 @@ fn should_not_lint() { *i = None; } } + +fn issue_14192() { + let mut tmp = vec![0; 3]; + + for i in 0..tmp.len() { + tmp[i] = i; + } + + for i in 0..tmp.len() { + tmp[i] = 2 + i; + } + + for i in 0..tmp.len() { + tmp[0] = i; + } +} diff --git a/tests/ui/manual_slice_fill.rs b/tests/ui/manual_slice_fill.rs index c25127ca613a..75a391f4243c 100644 --- a/tests/ui/manual_slice_fill.rs +++ b/tests/ui/manual_slice_fill.rs @@ -1,5 +1,5 @@ #![warn(clippy::manual_slice_fill)] -#![allow(clippy::needless_range_loop)] +#![allow(clippy::needless_range_loop, clippy::useless_vec)] macro_rules! assign_element { ($slice:ident, $index:expr) => { @@ -108,3 +108,19 @@ fn should_not_lint() { *i = None; } } + +fn issue_14192() { + let mut tmp = vec![0; 3]; + + for i in 0..tmp.len() { + tmp[i] = i; + } + + for i in 0..tmp.len() { + tmp[i] = 2 + i; + } + + for i in 0..tmp.len() { + tmp[0] = i; + } +} From ac15a10b55580065320e48b29b6ff0ea36d8093a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 6 Feb 2025 15:38:28 -0700 Subject: [PATCH 069/161] just_underscores_and_digits: ignore empty ident Empty idents come from error recovery, and should imply that a better error has already been emitted. --- clippy_dev/src/fmt.rs | 9 +++++++-- clippy_lints/src/non_expressive_names.rs | 3 ++- .../non_expressive_names_error_recovery.fixed | 8 ++++++++ .../non_expressive_names_error_recovery.rs | 8 ++++++++ .../non_expressive_names_error_recovery.stderr | 13 +++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed create mode 100644 tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs create mode 100644 tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.stderr diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index 790dafa811f9..bdddf46a2cb1 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -290,8 +290,13 @@ fn run_rustfmt(context: &FmtContext) -> Result<(), Error> { .filter_map(|entry| { let entry = entry.expect("failed to find tests"); let path = entry.path(); - - if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" { + if path.extension() != Some("rs".as_ref()) + || path + .components() + .nth_back(1) + .is_some_and(|c| c.as_os_str() == "syntax-error-recovery") + || entry.file_name() == "ice-3891.rs" + { None } else { Some(entry.into_path().into_os_string()) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 1a3b43cbb10a..c5873589b26f 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -208,7 +208,8 @@ impl SimilarNamesNameVisitor<'_, '_, '_> { fn check_ident(&mut self, ident: Ident) { let interned_name = ident.name.as_str(); - if interned_name.chars().any(char::is_uppercase) { + // name can be empty if it comes from recovery + if interned_name.chars().any(char::is_uppercase) || interned_name.is_empty() { return; } if interned_name.chars().all(|c| c.is_ascii_digit() || c == '_') { diff --git a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed new file mode 100644 index 000000000000..5e5821a140de --- /dev/null +++ b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed @@ -0,0 +1,8 @@ +// https://github.com/rust-lang/rust-clippy/issues/12302 +use std::marker::PhantomData; + +pub struct Aa(PhantomData); + +fn aa(a: Aa) { + +} diff --git a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs new file mode 100644 index 000000000000..d6e1da0e0898 --- /dev/null +++ b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs @@ -0,0 +1,8 @@ +// https://github.com/rust-lang/rust-clippy/issues/12302 +use std::marker::PhantomData; + +pub struct Aa(PhantomData); + +fn aa(a: Aa`, found `)` + --> tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs:6:19 + | +LL | fn aa(a: Aa) { + | + + +error: aborting due to 1 previous error + From da6a05977dd0a9a8fd973b3d08937e9b81d7e2ab Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 11 Feb 2025 18:32:10 +0100 Subject: [PATCH 070/161] `{expect,unwrap}_used`: add options to lint at compilation time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, do not lint `.unwrap()` and `.expect(…)` in always const contexts, as a failure would be detected at compile time anyway. New options `allow_expect_in_consts` and `allow_unwrap_in_consts`, defaulting to `true`, can be turned unset to still lint in always const contexts. --- CHANGELOG.md | 2 ++ book/src/lint_configuration.md | 20 +++++++++++++++++ clippy_config/src/conf.rs | 6 +++++ clippy_lints/src/methods/mod.rs | 9 ++++++++ .../src/methods/unwrap_expect_used.rs | 7 +++++- tests/ui-toml/expect_used/clippy.toml | 1 + tests/ui-toml/expect_used/expect_used.rs | 9 ++++++++ tests/ui-toml/expect_used/expect_used.stderr | 22 ++++++++++++++++--- .../toml_unknown_key/conf_unknown_key.stderr | 6 +++++ tests/ui-toml/unwrap_used/clippy.toml | 1 + .../ui-toml/unwrap_used/unwrap_used_const.rs | 11 ++++++++++ .../unwrap_used/unwrap_used_const.stderr | 22 +++++++++++++++++++ tests/ui/unwrap_expect_used.rs | 11 ++++++++++ 13 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 tests/ui-toml/unwrap_used/unwrap_used_const.rs create mode 100644 tests/ui-toml/unwrap_used/unwrap_used_const.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1119aca984..14f61fb1cd91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6268,6 +6268,7 @@ Released 2018-09-13 [`accept-comment-above-statement`]: https://doc.rust-lang.org/clippy/lint_configuration.html#accept-comment-above-statement [`allow-comparison-to-zero`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-comparison-to-zero [`allow-dbg-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-dbg-in-tests +[`allow-expect-in-consts`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-expect-in-consts [`allow-expect-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-expect-in-tests [`allow-indexing-slicing-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-indexing-slicing-in-tests [`allow-mixed-uninlined-format-args`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-mixed-uninlined-format-args @@ -6276,6 +6277,7 @@ Released 2018-09-13 [`allow-print-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-print-in-tests [`allow-private-module-inception`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-private-module-inception [`allow-renamed-params-for`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-renamed-params-for +[`allow-unwrap-in-consts`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-unwrap-in-consts [`allow-unwrap-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-unwrap-in-tests [`allow-useless-vec-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-useless-vec-in-tests [`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index f43c3a280727..978fb4f3b34d 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -71,6 +71,16 @@ Whether `dbg!` should be allowed in test functions or `#[cfg(test)]` * [`dbg_macro`](https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro) +## `allow-expect-in-consts` +Whether `expect` should be allowed in code always evaluated at compile time + +**Default Value:** `true` + +--- +**Affected lints:** +* [`expect_used`](https://rust-lang.github.io/rust-clippy/master/index.html#expect_used) + + ## `allow-expect-in-tests` Whether `expect` should be allowed in test functions or `#[cfg(test)]` @@ -164,6 +174,16 @@ default configuration of Clippy. By default, any configuration will replace the * [`renamed_function_params`](https://rust-lang.github.io/rust-clippy/master/index.html#renamed_function_params) +## `allow-unwrap-in-consts` +Whether `unwrap` should be allowed in code always evaluated at compile time + +**Default Value:** `true` + +--- +**Affected lints:** +* [`unwrap_used`](https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used) + + ## `allow-unwrap-in-tests` Whether `unwrap` should be allowed in test functions or `#[cfg(test)]` diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 28e42c67d980..e2f5574d5669 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -288,6 +288,9 @@ define_Conf! { /// Whether `dbg!` should be allowed in test functions or `#[cfg(test)]` #[lints(dbg_macro)] allow_dbg_in_tests: bool = false, + /// Whether `expect` should be allowed in code always evaluated at compile time + #[lints(expect_used)] + allow_expect_in_consts: bool = true, /// Whether `expect` should be allowed in test functions or `#[cfg(test)]` #[lints(expect_used)] allow_expect_in_tests: bool = false, @@ -325,6 +328,9 @@ define_Conf! { #[lints(renamed_function_params)] allow_renamed_params_for: Vec = DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS.iter().map(ToString::to_string).collect(), + /// Whether `unwrap` should be allowed in code always evaluated at compile time + #[lints(unwrap_used)] + allow_unwrap_in_consts: bool = true, /// Whether `unwrap` should be allowed in test functions or `#[cfg(test)]` #[lints(unwrap_used)] allow_unwrap_in_tests: bool = false, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f151dedc2448..7d33f3de57d6 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4406,11 +4406,14 @@ declare_clippy_lint! { "using `Option::and_then` or `Result::and_then` to chain a computation that returns an `Option` or a `Result`" } +#[expect(clippy::struct_excessive_bools)] pub struct Methods { avoid_breaking_exported_api: bool, msrv: Msrv, allow_expect_in_tests: bool, allow_unwrap_in_tests: bool, + allow_expect_in_consts: bool, + allow_unwrap_in_consts: bool, allowed_dotfiles: FxHashSet<&'static str>, format_args: FormatArgsStorage, } @@ -4425,6 +4428,8 @@ impl Methods { msrv: conf.msrv.clone(), allow_expect_in_tests: conf.allow_expect_in_tests, allow_unwrap_in_tests: conf.allow_unwrap_in_tests, + allow_expect_in_consts: conf.allow_expect_in_consts, + allow_unwrap_in_consts: conf.allow_unwrap_in_consts, allowed_dotfiles, format_args, } @@ -4918,6 +4923,7 @@ impl Methods { expr, recv, false, + self.allow_expect_in_consts, self.allow_expect_in_tests, unwrap_expect_used::Variant::Expect, ), @@ -4931,6 +4937,7 @@ impl Methods { expr, recv, true, + self.allow_expect_in_consts, self.allow_expect_in_tests, unwrap_expect_used::Variant::Expect, ); @@ -5304,6 +5311,7 @@ impl Methods { expr, recv, false, + self.allow_unwrap_in_consts, self.allow_unwrap_in_tests, unwrap_expect_used::Variant::Unwrap, ); @@ -5315,6 +5323,7 @@ impl Methods { expr, recv, true, + self.allow_unwrap_in_consts, self.allow_unwrap_in_tests, unwrap_expect_used::Variant::Unwrap, ); diff --git a/clippy_lints/src/methods/unwrap_expect_used.rs b/clippy_lints/src/methods/unwrap_expect_used.rs index 5b0bd0f716ab..027215e3b4d7 100644 --- a/clippy_lints/src/methods/unwrap_expect_used.rs +++ b/clippy_lints/src/methods/unwrap_expect_used.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::{is_never_like, is_type_diagnostic_item}; -use clippy_utils::{is_in_test, is_lint_allowed}; +use clippy_utils::{is_in_test, is_inside_always_const_context, is_lint_allowed}; use rustc_hir::Expr; use rustc_lint::{LateContext, Lint}; use rustc_middle::ty; @@ -39,6 +39,7 @@ pub(super) fn check( expr: &Expr<'_>, recv: &Expr<'_>, is_err: bool, + allow_unwrap_in_consts: bool, allow_unwrap_in_tests: bool, variant: Variant, ) { @@ -65,6 +66,10 @@ pub(super) fn check( return; } + if allow_unwrap_in_consts && is_inside_always_const_context(cx.tcx, expr.hir_id) { + return; + } + span_lint_and_then( cx, variant.lint(), diff --git a/tests/ui-toml/expect_used/clippy.toml b/tests/ui-toml/expect_used/clippy.toml index 6933b8164195..895de8357cf7 100644 --- a/tests/ui-toml/expect_used/clippy.toml +++ b/tests/ui-toml/expect_used/clippy.toml @@ -1 +1,2 @@ +allow-expect-in-consts = false allow-expect-in-tests = true diff --git a/tests/ui-toml/expect_used/expect_used.rs b/tests/ui-toml/expect_used/expect_used.rs index 206788e19f02..f0b92329f97a 100644 --- a/tests/ui-toml/expect_used/expect_used.rs +++ b/tests/ui-toml/expect_used/expect_used.rs @@ -1,4 +1,5 @@ //@compile-flags: --test +//@no-rustfix #![warn(clippy::expect_used)] #![allow(clippy::unnecessary_literal_unwrap)] @@ -15,6 +16,14 @@ fn expect_result() { fn main() { expect_option(); expect_result(); + + const SOME: Option = Some(3); + const UNWRAPPED: i32 = SOME.expect("Not three?"); + //~^ ERROR: used `expect()` on an `Option` value + const { + SOME.expect("Still not three?"); + //~^ ERROR: used `expect()` on an `Option` value + } } #[test] diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr index 81691f8ac6c0..b28bb7b7e0d1 100644 --- a/tests/ui-toml/expect_used/expect_used.stderr +++ b/tests/ui-toml/expect_used/expect_used.stderr @@ -1,5 +1,5 @@ error: used `expect()` on an `Option` value - --> tests/ui-toml/expect_used/expect_used.rs:7:13 + --> tests/ui-toml/expect_used/expect_used.rs:8:13 | LL | let _ = opt.expect(""); | ^^^^^^^^^^^^^^ @@ -9,12 +9,28 @@ LL | let _ = opt.expect(""); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value - --> tests/ui-toml/expect_used/expect_used.rs:12:13 + --> tests/ui-toml/expect_used/expect_used.rs:13:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ | = note: if this value is an `Err`, it will panic -error: aborting due to 2 previous errors +error: used `expect()` on an `Option` value + --> tests/ui-toml/expect_used/expect_used.rs:21:28 + | +LL | const UNWRAPPED: i32 = SOME.expect("Not three?"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: if this value is `None`, it will panic + +error: used `expect()` on an `Option` value + --> tests/ui-toml/expect_used/expect_used.rs:24:9 + | +LL | SOME.expect("Still not three?"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: if this value is `None`, it will panic + +error: aborting due to 4 previous errors diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 01e9f5c26a37..842059df1e92 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -5,6 +5,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect accept-comment-above-statement allow-comparison-to-zero allow-dbg-in-tests + allow-expect-in-consts allow-expect-in-tests allow-indexing-slicing-in-tests allow-mixed-uninlined-format-args @@ -13,6 +14,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect allow-print-in-tests allow-private-module-inception allow-renamed-params-for + allow-unwrap-in-consts allow-unwrap-in-tests allow-useless-vec-in-tests allowed-dotfiles @@ -94,6 +96,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect accept-comment-above-statement allow-comparison-to-zero allow-dbg-in-tests + allow-expect-in-consts allow-expect-in-tests allow-indexing-slicing-in-tests allow-mixed-uninlined-format-args @@ -102,6 +105,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect allow-print-in-tests allow-private-module-inception allow-renamed-params-for + allow-unwrap-in-consts allow-unwrap-in-tests allow-useless-vec-in-tests allowed-dotfiles @@ -183,6 +187,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni accept-comment-above-statement allow-comparison-to-zero allow-dbg-in-tests + allow-expect-in-consts allow-expect-in-tests allow-indexing-slicing-in-tests allow-mixed-uninlined-format-args @@ -191,6 +196,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni allow-print-in-tests allow-private-module-inception allow-renamed-params-for + allow-unwrap-in-consts allow-unwrap-in-tests allow-useless-vec-in-tests allowed-dotfiles diff --git a/tests/ui-toml/unwrap_used/clippy.toml b/tests/ui-toml/unwrap_used/clippy.toml index 154626ef4e81..6fd1eb6f8d0d 100644 --- a/tests/ui-toml/unwrap_used/clippy.toml +++ b/tests/ui-toml/unwrap_used/clippy.toml @@ -1 +1,2 @@ +allow-unwrap-in-consts = false allow-unwrap-in-tests = true diff --git a/tests/ui-toml/unwrap_used/unwrap_used_const.rs b/tests/ui-toml/unwrap_used/unwrap_used_const.rs new file mode 100644 index 000000000000..c7d8e8c1ffb5 --- /dev/null +++ b/tests/ui-toml/unwrap_used/unwrap_used_const.rs @@ -0,0 +1,11 @@ +#![warn(clippy::unwrap_used)] + +fn main() { + const SOME: Option = Some(3); + const UNWRAPPED: i32 = SOME.unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value + const { + SOME.unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value + } +} diff --git a/tests/ui-toml/unwrap_used/unwrap_used_const.stderr b/tests/ui-toml/unwrap_used/unwrap_used_const.stderr new file mode 100644 index 000000000000..362b41bc1bff --- /dev/null +++ b/tests/ui-toml/unwrap_used/unwrap_used_const.stderr @@ -0,0 +1,22 @@ +error: used `unwrap()` on an `Option` value + --> tests/ui-toml/unwrap_used/unwrap_used_const.rs:5:28 + | +LL | const UNWRAPPED: i32 = SOME.unwrap(); + | ^^^^^^^^^^^^^ + | + = 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` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` + +error: used `unwrap()` on an `Option` value + --> tests/ui-toml/unwrap_used/unwrap_used_const.rs:8:9 + | +LL | SOME.unwrap(); + | ^^^^^^^^^^^^^ + | + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message + +error: aborting due to 2 previous errors + diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index a56bd0a8d079..bab99f2ffbdd 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -50,4 +50,15 @@ fn main() { //~^ ERROR: used `unwrap_err()` on a `Result` value a.expect_err("Hello error!"); //~^ ERROR: used `expect_err()` on a `Result` value + + // Don't trigger in compile time contexts by default + const SOME: Option = Some(3); + const UNWRAPPED: i32 = SOME.unwrap(); + const EXPECTED: i32 = SOME.expect("Not three?"); + const { + SOME.unwrap(); + } + const { + SOME.expect("Still not three?"); + } } From 8b6de49ef74de5bc5485ccb507178fa72dff9c87 Mon Sep 17 00:00:00 2001 From: jonathan Date: Mon, 27 Jan 2025 21:50:22 +0100 Subject: [PATCH 071/161] New lint: `unbuffered_bytes` --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/methods/mod.rs | 30 ++++++++++++++++ clippy_lints/src/methods/unbuffered_bytes.rs | 31 ++++++++++++++++ clippy_utils/src/paths.rs | 1 + tests/ui/bytes_count_to_len.fixed | 6 ++-- tests/ui/bytes_count_to_len.rs | 6 ++-- tests/ui/unbuffered_bytes.rs | 37 ++++++++++++++++++++ tests/ui/unbuffered_bytes.stderr | 36 +++++++++++++++++++ 9 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 clippy_lints/src/methods/unbuffered_bytes.rs create mode 100644 tests/ui/unbuffered_bytes.rs create mode 100644 tests/ui/unbuffered_bytes.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f61fb1cd91..2d37e0da37f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6144,6 +6144,7 @@ Released 2018-09-13 [`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity [`type_id_on_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_id_on_box [`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds +[`unbuffered_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#unbuffered_bytes [`unchecked_duration_subtraction`]: https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction [`unconditional_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion [`undocumented_unsafe_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index d5a8f875e472..ac3e4bd90dc1 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -482,6 +482,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::SUSPICIOUS_SPLITN_INFO, crate::methods::SUSPICIOUS_TO_OWNED_INFO, crate::methods::TYPE_ID_ON_BOX_INFO, + crate::methods::UNBUFFERED_BYTES_INFO, crate::methods::UNINIT_ASSUMED_INIT_INFO, crate::methods::UNIT_HASH_INFO, crate::methods::UNNECESSARY_FALLIBLE_CONVERSIONS_INFO, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7d33f3de57d6..7e9db66ff864 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -113,6 +113,7 @@ mod suspicious_map; mod suspicious_splitn; mod suspicious_to_owned; mod type_id_on_box; +mod unbuffered_bytes; mod uninit_assumed_init; mod unit_hash; mod unnecessary_fallible_conversions; @@ -4406,6 +4407,33 @@ declare_clippy_lint! { "using `Option::and_then` or `Result::and_then` to chain a computation that returns an `Option` or a `Result`" } +declare_clippy_lint! { + /// ### What it does + /// Checks for calls to `Read::bytes` on types which don't implement `BufRead`. + /// + /// ### Why is this bad? + /// The default implementation calls `read` for each byte, which can be very inefficient for data that’s not in memory, such as `File`. + /// + /// ### Example + /// ```no_run + /// use std::io::Read; + /// use std::fs::File; + /// let file = File::open("./bytes.txt").unwrap(); + /// file.bytes(); + /// ``` + /// Use instead: + /// ```no_run + /// use std::io::{BufReader, Read}; + /// use std::fs::File; + /// let file = BufReader::new(std::fs::File::open("./bytes.txt").unwrap()); + /// file.bytes(); + /// ``` + #[clippy::version = "1.86.0"] + pub UNBUFFERED_BYTES, + perf, + "calling .bytes() is very inefficient when data is not in memory" +} + #[expect(clippy::struct_excessive_bools)] pub struct Methods { avoid_breaking_exported_api: bool, @@ -4580,6 +4608,7 @@ impl_lint_pass!(Methods => [ MANUAL_REPEAT_N, SLICED_STRING_AS_BYTES, RETURN_AND_THEN, + UNBUFFERED_BYTES, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4856,6 +4885,7 @@ impl Methods { ("as_ptr", []) => manual_c_str_literals::check_as_ptr(cx, expr, recv, &self.msrv), ("as_ref", []) => useless_asref::check(cx, expr, "as_ref", recv), ("assume_init", []) => uninit_assumed_init::check(cx, expr, recv), + ("bytes", []) => unbuffered_bytes::check(cx, expr, recv), ("cloned", []) => { cloned_instead_of_copied::check(cx, expr, recv, span, &self.msrv); option_as_ref_cloned::check(cx, recv, span); diff --git a/clippy_lints/src/methods/unbuffered_bytes.rs b/clippy_lints/src/methods/unbuffered_bytes.rs new file mode 100644 index 000000000000..71c23d256ac6 --- /dev/null +++ b/clippy_lints/src/methods/unbuffered_bytes.rs @@ -0,0 +1,31 @@ +use super::UNBUFFERED_BYTES; +use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::ty::implements_trait; +use clippy_utils::{get_trait_def_id, is_trait_method, paths}; +use rustc_hir as hir; +use rustc_lint::LateContext; +use rustc_span::sym; + +pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { + let ty = cx.typeck_results().expr_ty_adjusted(recv); + + // If the .bytes() call is a call from the Read trait + if is_trait_method(cx, expr, sym::IoRead) { + // Retrieve the DefId of the BufRead trait + // FIXME: add a diagnostic item for `BufRead` + let Some(buf_read) = get_trait_def_id(cx.tcx, &paths::BUF_READ) else { + return; + }; + // And the implementor of the trait is not buffered + if !implements_trait(cx, ty, buf_read, &[]) { + span_lint_and_help( + cx, + UNBUFFERED_BYTES, + expr.span, + "calling .bytes() is very inefficient when data is not in memory", + None, + "consider using `BufReader`", + ); + } + } +} diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index f15fffc09e8d..74a392354894 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -29,6 +29,7 @@ pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"] // Paths in `core`/`alloc`/`std`. This should be avoided and cleaned up by adding diagnostic items. pub const ABORT: [&str; 3] = ["std", "process", "abort"]; +pub const BUF_READ: [&str; 3] = ["std", "io", "BufRead"]; pub const CHILD: [&str; 3] = ["std", "process", "Child"]; pub const CHILD_ID: [&str; 4] = ["std", "process", "Child", "id"]; pub const CHILD_KILL: [&str; 4] = ["std", "process", "Child", "kill"]; diff --git a/tests/ui/bytes_count_to_len.fixed b/tests/ui/bytes_count_to_len.fixed index d20af22535a0..fb31ceaad7c4 100644 --- a/tests/ui/bytes_count_to_len.fixed +++ b/tests/ui/bytes_count_to_len.fixed @@ -1,6 +1,6 @@ #![warn(clippy::bytes_count_to_len)] use std::fs::File; -use std::io::Read; +use std::io::{BufReader, Read}; fn main() { // should fix, because type is String @@ -26,8 +26,8 @@ fn main() { bytes.bytes().count(); // The type is File, so should not fix - let _ = File::open("foobar").unwrap().bytes().count(); + let _ = BufReader::new(File::open("foobar").unwrap()).bytes().count(); - let f = File::open("foobar").unwrap(); + let f = BufReader::new(File::open("foobar").unwrap()); let _ = f.bytes().count(); } diff --git a/tests/ui/bytes_count_to_len.rs b/tests/ui/bytes_count_to_len.rs index 340e6b412556..0250059afeb2 100644 --- a/tests/ui/bytes_count_to_len.rs +++ b/tests/ui/bytes_count_to_len.rs @@ -1,6 +1,6 @@ #![warn(clippy::bytes_count_to_len)] use std::fs::File; -use std::io::Read; +use std::io::{BufReader, Read}; fn main() { // should fix, because type is String @@ -26,8 +26,8 @@ fn main() { bytes.bytes().count(); // The type is File, so should not fix - let _ = File::open("foobar").unwrap().bytes().count(); + let _ = BufReader::new(File::open("foobar").unwrap()).bytes().count(); - let f = File::open("foobar").unwrap(); + let f = BufReader::new(File::open("foobar").unwrap()); let _ = f.bytes().count(); } diff --git a/tests/ui/unbuffered_bytes.rs b/tests/ui/unbuffered_bytes.rs new file mode 100644 index 000000000000..82c8839e8391 --- /dev/null +++ b/tests/ui/unbuffered_bytes.rs @@ -0,0 +1,37 @@ +#![warn(clippy::unbuffered_bytes)] + +use std::fs::File; +use std::io::{BufReader, Cursor, Read, Stdin, stdin}; +use std::net::TcpStream; + +fn main() { + // File is not buffered, should complain + let file = File::open("./bytes.txt").unwrap(); + file.bytes(); + + // TcpStream is not buffered, should complain + let tcp_stream: TcpStream = TcpStream::connect("127.0.0.1:80").unwrap(); + tcp_stream.bytes(); + + // BufReader is buffered, should not complain + let file = BufReader::new(File::open("./bytes.txt").unwrap()); + file.bytes(); + + // Cursor is buffered, should not complain + let cursor = Cursor::new(Vec::new()); + cursor.bytes(); + + // Stdio would acquire the lock for every byte, should complain + let s: Stdin = stdin(); + s.bytes(); + + // But when locking stdin, this is fine so should not complain + let s: Stdin = stdin(); + let s = s.lock(); + s.bytes(); +} + +fn use_read(r: R) { + // Callers of `use_read` may choose a `R` that is not buffered + r.bytes(); +} diff --git a/tests/ui/unbuffered_bytes.stderr b/tests/ui/unbuffered_bytes.stderr new file mode 100644 index 000000000000..3303d579fedc --- /dev/null +++ b/tests/ui/unbuffered_bytes.stderr @@ -0,0 +1,36 @@ +error: calling .bytes() is very inefficient when data is not in memory + --> tests/ui/unbuffered_bytes.rs:10:5 + | +LL | file.bytes(); + | ^^^^^^^^^^^^ + | + = help: consider using `BufReader` + = note: `-D clippy::unbuffered-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unbuffered_bytes)]` + +error: calling .bytes() is very inefficient when data is not in memory + --> tests/ui/unbuffered_bytes.rs:14:5 + | +LL | tcp_stream.bytes(); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider using `BufReader` + +error: calling .bytes() is very inefficient when data is not in memory + --> tests/ui/unbuffered_bytes.rs:26:5 + | +LL | s.bytes(); + | ^^^^^^^^^ + | + = help: consider using `BufReader` + +error: calling .bytes() is very inefficient when data is not in memory + --> tests/ui/unbuffered_bytes.rs:36:5 + | +LL | r.bytes(); + | ^^^^^^^^^ + | + = help: consider using `BufReader` + +error: aborting due to 4 previous errors + From 8573725a030a8e17b1f687061f46822234e21cb1 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 12 Feb 2025 15:22:32 +0100 Subject: [PATCH 072/161] Remove ignored `#[must_use]` attributes from Clippy The `#[must_use]` attribute has no effect when applied to methods in trait implementations. --- clippy_lints/src/infinite_iter.rs | 1 - clippy_utils/src/consts.rs | 3 --- 2 files changed, 4 deletions(-) diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index d3aade31f14f..7210f4b438db 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -94,7 +94,6 @@ impl Finiteness { } impl From for Finiteness { - #[must_use] fn from(b: bool) -> Self { if b { Infinite } else { Finite } } diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index db82c458f703..21909896c33e 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -351,21 +351,18 @@ pub enum FullInt { } impl PartialEq for FullInt { - #[must_use] fn eq(&self, other: &Self) -> bool { self.cmp(other) == Ordering::Equal } } impl PartialOrd for FullInt { - #[must_use] fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for FullInt { - #[must_use] fn cmp(&self, other: &Self) -> Ordering { use FullInt::{S, U}; From 39bde6d46a5c7dbebdc66afb8ac166a4e9087231 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 12 Feb 2025 17:15:27 +0100 Subject: [PATCH 073/161] Reorganize code in `mem_replace.rs` Make each lint be more self-contained, and trigger only the next lint when the previous one didn't already rewrite the expression. --- clippy_lints/src/mem_replace.rs | 86 +++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 41528c5dee3a..4f3279d292d1 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -103,26 +103,31 @@ declare_clippy_lint! { impl_lint_pass!(MemReplace => [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); -fn check_replace_option_with_none(cx: &LateContext<'_>, dest: &Expr<'_>, expr_span: Span) { - // Since this is a late pass (already type-checked), - // and we already know that the second argument is an - // `Option`, we do not need to check the first - // argument's type. All that's left is to get - // the replacee's expr after peeling off the `&mut` - let sugg_expr = peel_ref_operators(cx, dest); - let mut applicability = Applicability::MachineApplicable; - span_lint_and_sugg( - cx, - MEM_REPLACE_OPTION_WITH_NONE, - expr_span, - "replacing an `Option` with `None`", - "consider `Option::take()` instead", - format!( - "{}.take()", - Sugg::hir_with_context(cx, sugg_expr, expr_span.ctxt(), "", &mut applicability).maybe_par() - ), - applicability, - ); +fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) -> bool { + if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) { + // Since this is a late pass (already type-checked), + // and we already know that the second argument is an + // `Option`, we do not need to check the first + // argument's type. All that's left is to get + // the replacee's expr after peeling off the `&mut` + let sugg_expr = peel_ref_operators(cx, dest); + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + MEM_REPLACE_OPTION_WITH_NONE, + expr_span, + "replacing an `Option` with `None`", + "consider `Option::take()` instead", + format!( + "{}.take()", + Sugg::hir_with_context(cx, sugg_expr, expr_span.ctxt(), "", &mut applicability).maybe_par() + ), + applicability, + ); + true + } else { + false + } } fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { @@ -181,27 +186,34 @@ fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<' } } -fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { - // disable lint for primitives - let expr_type = cx.typeck_results().expr_ty_adjusted(src); - if is_non_aggregate_primitive_type(expr_type) { - return; - } - if is_default_equivalent(cx, src) && !expr_span.in_external_macro(cx.tcx.sess.source_map()) { - let Some(top_crate) = std_or_core(cx) else { return }; +fn check_replace_with_default( + cx: &LateContext<'_>, + src: &Expr<'_>, + dest: &Expr<'_>, + expr: &Expr<'_>, + msrv: &Msrv, +) -> bool { + if msrv.meets(msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) + // disable lint for primitives + && let expr_type = cx.typeck_results().expr_ty_adjusted(src) + && !is_non_aggregate_primitive_type(expr_type) + && is_default_equivalent(cx, src) + && !expr.span.in_external_macro(cx.tcx.sess.source_map()) + && let Some(top_crate) = std_or_core(cx) + { span_lint_and_then( cx, MEM_REPLACE_WITH_DEFAULT, - expr_span, + expr.span, format!( "replacing a value of type `T` with `T::default()` is better expressed using `{top_crate}::mem::take`" ), |diag| { - if !expr_span.from_expansion() { + if !expr.span.from_expansion() { let suggestion = format!("{top_crate}::mem::take({})", snippet(cx, dest.span, "")); diag.span_suggestion( - expr_span, + expr.span, "consider using", suggestion, Applicability::MachineApplicable, @@ -209,6 +221,9 @@ fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr< } }, ); + true + } else { + false } } @@ -233,12 +248,11 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace { && cx.tcx.is_diagnostic_item(sym::mem_replace, def_id) { // Check that second argument is `Option::None` - if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) { - check_replace_option_with_none(cx, dest, expr.span); - } else if self.msrv.meets(msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) { - check_replace_with_default(cx, src, dest, expr.span); + if !check_replace_option_with_none(cx, src, dest, expr.span) + && !check_replace_with_default(cx, src, dest, expr, &self.msrv) + { + check_replace_with_uninit(cx, src, dest, expr.span); } - check_replace_with_uninit(cx, src, dest, expr.span); } } extract_msrv_attr!(LateContext); From b167895a19dd8c634c66b5c672a83cdb610ab8a9 Mon Sep 17 00:00:00 2001 From: WeiTheShinobi Date: Thu, 13 Feb 2025 01:06:32 +0800 Subject: [PATCH 074/161] Fix `used_underscore_items` lint uses of foreign functions --- clippy_lints/src/misc.rs | 4 ++-- tests/ui/used_underscore_items.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 8dbc41085532..646145997bc3 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -7,7 +7,6 @@ use clippy_utils::{ }; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::intravisit::FnKind; use rustc_hir::{ BinOpKind, BindingMode, Body, ByRef, Expr, ExprKind, FnDecl, Mutability, PatKind, QPath, Stmt, StmtKind, @@ -287,7 +286,8 @@ fn used_underscore_items<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if name.starts_with('_') && !name.starts_with("__") && !definition_span.from_expansion() - && def_id.krate == LOCAL_CRATE + && def_id.is_local() + && !cx.tcx.is_foreign_item(def_id) { span_lint_and_then( cx, diff --git a/tests/ui/used_underscore_items.rs b/tests/ui/used_underscore_items.rs index 223016a5c966..ed76f4e68dc9 100644 --- a/tests/ui/used_underscore_items.rs +++ b/tests/ui/used_underscore_items.rs @@ -61,3 +61,13 @@ fn external_item_call() { external_item::_exernal_foo(); } + +// should not lint foreign functions. +// issue #14156 +extern "C" { + pub fn _exit(code: i32) -> !; +} + +fn _f() { + unsafe { _exit(1) } +} From 342ac8ee289abbc28da41daa6cbb3e60586fe42b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 11 Feb 2025 13:46:55 +0100 Subject: [PATCH 075/161] New lint: `mem_replace_option_with_some` `mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`. --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/mem_replace.rs | 64 +++++++++++++++++++++++++++++- clippy_utils/src/msrvs.rs | 1 + tests/ui/mem_replace.fixed | 22 ++++++++++ tests/ui/mem_replace.rs | 22 ++++++++++ tests/ui/mem_replace.stderr | 23 ++++++++++- 9 files changed, 133 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea1119aca984..232e1e6c3761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5812,6 +5812,7 @@ Released 2018-09-13 [`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum [`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget [`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none +[`mem_replace_option_with_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_some [`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default [`mem_replace_with_uninit`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_uninit [`min_ident_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index f43c3a280727..6168a3313ce3 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -764,6 +764,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or) * [`map_with_unused_argument_over_ranges`](https://rust-lang.github.io/rust-clippy/master/index.html#map_with_unused_argument_over_ranges) * [`match_like_matches_macro`](https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro) +* [`mem_replace_option_with_some`](https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_some) * [`mem_replace_with_default`](https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default) * [`missing_const_for_fn`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn) * [`needless_borrow`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 28e42c67d980..e7f27250da04 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -633,6 +633,7 @@ define_Conf! { map_unwrap_or, map_with_unused_argument_over_ranges, match_like_matches_macro, + mem_replace_option_with_some, mem_replace_with_default, missing_const_for_fn, needless_borrow, diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index d5a8f875e472..f733809b90de 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -362,6 +362,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::matches::WILDCARD_ENUM_MATCH_ARM_INFO, crate::matches::WILDCARD_IN_OR_PATTERNS_INFO, crate::mem_replace::MEM_REPLACE_OPTION_WITH_NONE_INFO, + crate::mem_replace::MEM_REPLACE_OPTION_WITH_SOME_INFO, crate::mem_replace::MEM_REPLACE_WITH_DEFAULT_INFO, crate::mem_replace::MEM_REPLACE_WITH_UNINIT_INFO, crate::methods::BIND_INSTEAD_OF_MAP_INFO, diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 4f3279d292d1..2fe5f6a3a37a 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -8,7 +8,7 @@ use clippy_utils::{ is_default_equivalent, is_expr_used_or_unified, is_res_lang_ctor, path_res, peel_ref_operators, std_or_core, }; use rustc_errors::Applicability; -use rustc_hir::LangItem::OptionNone; +use rustc_hir::LangItem::{OptionNone, OptionSome}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; @@ -43,6 +43,31 @@ declare_clippy_lint! { "replacing an `Option` with `None` instead of `take()`" } +declare_clippy_lint! { + /// ### What it does + /// Checks for `mem::replace()` on an `Option` with `Some(…)`. + /// + /// ### Why is this bad? + /// `Option` already has the method `replace()` for + /// taking its current value (Some(…) or None) and replacing it with + /// `Some(…)`. + /// + /// ### Example + /// ```no_run + /// let mut an_option = Some(0); + /// let replaced = std::mem::replace(&mut an_option, Some(1)); + /// ``` + /// Is better expressed with: + /// ```no_run + /// let mut an_option = Some(0); + /// let taken = an_option.replace(1); + /// ``` + #[clippy::version = "1.86.0"] + pub MEM_REPLACE_OPTION_WITH_SOME, + style, + "replacing an `Option` with `Some` instead of `replace()`" +} + declare_clippy_lint! { /// ### What it does /// Checks for `mem::replace(&mut _, mem::uninitialized())` @@ -101,7 +126,7 @@ declare_clippy_lint! { } impl_lint_pass!(MemReplace => - [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); + [MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_OPTION_WITH_SOME, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]); fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) -> bool { if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) { @@ -130,6 +155,40 @@ fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &E } } +fn check_replace_option_with_some( + cx: &LateContext<'_>, + src: &Expr<'_>, + dest: &Expr<'_>, + expr_span: Span, + msrv: &Msrv, +) -> bool { + if msrv.meets(msrvs::OPTION_REPLACE) + && let ExprKind::Call(src_func, [src_arg]) = src.kind + && is_res_lang_ctor(cx, path_res(cx, src_func), OptionSome) + { + // We do not have to check for a `const` context here, because `core::mem::replace()` and + // `Option::replace()` have been const-stabilized simultaneously in version 1.83.0. + let sugg_expr = peel_ref_operators(cx, dest); + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + MEM_REPLACE_OPTION_WITH_SOME, + expr_span, + "replacing an `Option` with `Some(..)`", + "consider `Option::replace()` instead", + format!( + "{}.replace({})", + Sugg::hir_with_context(cx, sugg_expr, expr_span.ctxt(), "_", &mut applicability).maybe_par(), + snippet_with_applicability(cx, src_arg.span, "_", &mut applicability) + ), + applicability, + ); + true + } else { + false + } +} + fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(src.hir_id) // check if replacement is mem::MaybeUninit::uninit().assume_init() @@ -249,6 +308,7 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace { { // Check that second argument is `Option::None` if !check_replace_option_with_none(cx, src, dest, expr.span) + && !check_replace_option_with_some(cx, src, dest, expr.span, &self.msrv) && !check_replace_with_default(cx, src, dest, expr, &self.msrv) { check_replace_with_uninit(cx, src, dest, expr.span); diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 87c8165eae25..2e8bcfaa7af0 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -58,6 +58,7 @@ msrv_aliases! { 1,35,0 { OPTION_COPIED, RANGE_CONTAINS } 1,34,0 { TRY_FROM } 1,33,0 { UNDERSCORE_IMPORTS } + 1,31,0 { OPTION_REPLACE } 1,30,0 { ITERATOR_FIND_MAP, TOOL_ATTRIBUTES } 1,29,0 { ITER_FLATTEN } 1,28,0 { FROM_BOOL, REPEAT_WITH } diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 248ecd5d85f4..02b0d9c7045f 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -131,3 +131,25 @@ fn issue9824() { // replace with default let _ = std::mem::take(&mut b.val); } + +#[clippy::msrv = "1.31"] +fn mem_replace_option_with_some() { + let mut an_option = Some(0); + let replaced = an_option.replace(1); + //~^ ERROR: replacing an `Option` with `Some(..)` + + let mut an_option = &mut Some(0); + let replaced = an_option.replace(1); + //~^ ERROR: replacing an `Option` with `Some(..)` + + let (mut opt1, mut opt2) = (Some(0), Some(0)); + let b = true; + let replaced = (if b { &mut opt1 } else { &mut opt2 }).replace(1); + //~^ ERROR: replacing an `Option` with `Some(..)` +} + +#[clippy::msrv = "1.30"] +fn mem_replace_option_with_some_bad_msrv() { + let mut an_option = Some(0); + let replaced = mem::replace(&mut an_option, Some(1)); +} diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 486d2ba1b6a5..1bb72b5de239 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -131,3 +131,25 @@ fn issue9824() { // replace with default let _ = std::mem::replace(&mut b.val, String::default()); } + +#[clippy::msrv = "1.31"] +fn mem_replace_option_with_some() { + let mut an_option = Some(0); + let replaced = mem::replace(&mut an_option, Some(1)); + //~^ ERROR: replacing an `Option` with `Some(..)` + + let mut an_option = &mut Some(0); + let replaced = mem::replace(an_option, Some(1)); + //~^ ERROR: replacing an `Option` with `Some(..)` + + let (mut opt1, mut opt2) = (Some(0), Some(0)); + let b = true; + let replaced = mem::replace(if b { &mut opt1 } else { &mut opt2 }, Some(1)); + //~^ ERROR: replacing an `Option` with `Some(..)` +} + +#[clippy::msrv = "1.30"] +fn mem_replace_option_with_some_bad_msrv() { + let mut an_option = Some(0); + let replaced = mem::replace(&mut an_option, Some(1)); +} diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index a60f2253d13e..42ab546a5d77 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -160,5 +160,26 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` -error: aborting due to 26 previous errors +error: replacing an `Option` with `Some(..)` + --> tests/ui/mem_replace.rs:138:20 + | +LL | let replaced = mem::replace(&mut an_option, Some(1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `an_option.replace(1)` + | + = note: `-D clippy::mem-replace-option-with-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_some)]` + +error: replacing an `Option` with `Some(..)` + --> tests/ui/mem_replace.rs:142:20 + | +LL | let replaced = mem::replace(an_option, Some(1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `an_option.replace(1)` + +error: replacing an `Option` with `Some(..)` + --> tests/ui/mem_replace.rs:147:20 + | +LL | let replaced = mem::replace(if b { &mut opt1 } else { &mut opt2 }, Some(1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `(if b { &mut opt1 } else { &mut opt2 }).replace(1)` + +error: aborting due to 29 previous errors From a75cc61f99c029c22fd100af524de7e2ba600d5e Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Feb 2025 19:33:58 +0100 Subject: [PATCH 076/161] intern valtrees --- clippy_lints/src/non_copy_const.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 405bbfc9c6fa..f965ab90da23 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -179,8 +179,8 @@ impl<'tcx> NonCopyConst<'tcx> { } fn is_value_unfrozen_raw_inner(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> bool { - // No branch that we check (yet) should continue if val isn't a ValTree::Branch - let ty::ValTree::Branch(val) = val else { return false }; + // No branch that we check (yet) should continue if val isn't a branch + let Some(val) = val.try_to_branch() else { return false }; match *ty.kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. @@ -192,9 +192,10 @@ impl<'tcx> NonCopyConst<'tcx> { .iter() .any(|field| Self::is_value_unfrozen_raw_inner(cx, *field, ty)), ty::Adt(def, args) if def.is_enum() => { - let Some((&ty::ValTree::Leaf(variant_index), fields)) = val.split_first() else { + let Some((&variant_valtree, fields)) = val.split_first() else { return false; }; + let variant_index = variant_valtree.unwrap_leaf(); let variant_index = VariantIdx::from_u32(variant_index.to_u32()); fields .iter() From c47746ca67d53d5d8fc3ae9fd7ad144463a69e7d Mon Sep 17 00:00:00 2001 From: yanglsh Date: Thu, 13 Feb 2025 15:26:11 +0800 Subject: [PATCH 077/161] fix: `needless_option_as_deref` FP in trait --- clippy_utils/src/lib.rs | 6 +++++- tests/ui/needless_option_as_deref.fixed | 13 +++++++++++++ tests/ui/needless_option_as_deref.rs | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0d9502c50db6..d1b3d5508b09 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -107,7 +107,7 @@ use rustc_hir::{ self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode, Param, Pat, - PatExpr, PatExprKind, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, + PatExpr, PatExprKind, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitFn, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, def, }; use rustc_lexer::{TokenKind, tokenize}; @@ -1505,6 +1505,10 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio | Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(_, eid), .. + }) + | Node::TraitItem(&TraitItem { + kind: TraitItemKind::Fn(_, TraitFn::Provided(eid)), + .. }) => match cx.tcx.hir().body(eid).value.kind { ExprKind::Block(block, _) => Some(block), _ => None, diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index 84eaf12fc139..577deb2793c1 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -70,3 +70,16 @@ mod issue_non_copy_13077 { pub field: (), } } + +mod issue14148 { + pub trait SomeTrait { + fn something(&self, mut maybe_side_effect: Option<&mut String>) { + other(maybe_side_effect.as_deref_mut()); + other(maybe_side_effect); + } + } + + fn other(_maybe_side_effect: Option<&mut String>) { + unimplemented!() + } +} diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index fff1e45d846f..47f1f90b21b3 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -70,3 +70,16 @@ mod issue_non_copy_13077 { pub field: (), } } + +mod issue14148 { + pub trait SomeTrait { + fn something(&self, mut maybe_side_effect: Option<&mut String>) { + other(maybe_side_effect.as_deref_mut()); + other(maybe_side_effect); + } + } + + fn other(_maybe_side_effect: Option<&mut String>) { + unimplemented!() + } +} From 8cac5b03f3fdc6906a037ccdd656161e4263e898 Mon Sep 17 00:00:00 2001 From: Sebastian Jeltsch Date: Fri, 31 Jan 2025 15:17:45 +0100 Subject: [PATCH 078/161] rustc_tools_util: Change release channel default to stable Fixes the exposed release channel Bump version to 0.4.1 --- Cargo.toml | 4 +-- rustc_tools_util/Cargo.toml | 2 +- rustc_tools_util/README.md | 4 +-- rustc_tools_util/src/lib.rs | 55 ++++++++++++++++++++++--------------- tests/versioncheck.rs | 6 ++++ 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b615bb9e6f6b..263f2a4aab70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ path = "src/driver.rs" [dependencies] clippy_config = { path = "clippy_config" } clippy_lints = { path = "clippy_lints" } -rustc_tools_util = "0.4.0" +rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" } tempfile = { version = "3.3", optional = true } termize = "0.1" color-print = "0.3.4" @@ -54,7 +54,7 @@ parking_lot = "0.12" tokio = { version = "1", features = ["io-util"] } [build-dependencies] -rustc_tools_util = "0.4.0" +rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" } [features] integration = ["tempfile"] diff --git a/rustc_tools_util/Cargo.toml b/rustc_tools_util/Cargo.toml index cba025639482..189f34dd2a65 100644 --- a/rustc_tools_util/Cargo.toml +++ b/rustc_tools_util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_tools_util" -version = "0.4.0" +version = "0.4.1" description = "small helper to generate version information for git packages" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/rustc_tools_util/README.md b/rustc_tools_util/README.md index 1b11dfe06191..455654c10900 100644 --- a/rustc_tools_util/README.md +++ b/rustc_tools_util/README.md @@ -13,10 +13,10 @@ build = "build.rs" List rustc_tools_util as regular AND build dependency. ````toml [dependencies] -rustc_tools_util = "0.4.0" +rustc_tools_util = "0.4.1" [build-dependencies] -rustc_tools_util = "0.4.0" +rustc_tools_util = "0.4.1" ```` In `build.rs`, generate the data in your `main()` diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index 16be02f4a40f..cabd9dfa0c7c 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -28,9 +28,8 @@ macro_rules! get_version_info { }}; } -/// This macro can be used in `build.rs` to automatically set the needed -/// environment values, namely `GIT_HASH`, `COMMIT_DATE` and -/// `RUSTC_RELEASE_CHANNEL` +/// This macro can be used in `build.rs` to automatically set the needed environment values, namely +/// `GIT_HASH`, `COMMIT_DATE` and `RUSTC_RELEASE_CHANNEL` #[macro_export] macro_rules! setup_version_info { () => {{ @@ -43,7 +42,11 @@ macro_rules! setup_version_info { "cargo:rustc-env=COMMIT_DATE={}", $crate::get_commit_date().unwrap_or_default() ); - println!("cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", $crate::get_channel()); + let compiler_version = $crate::get_compiler_version(); + println!( + "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", + $crate::get_channel(compiler_version) + ); }}; } @@ -87,16 +90,17 @@ impl std::fmt::Debug for VersionInfo { "VersionInfo {{ crate_name: \"{}\", major: {}, minor: {}, patch: {}", self.crate_name, self.major, self.minor, self.patch, )?; - if self.commit_hash.is_some() { - write!( - f, - ", commit_hash: \"{}\", commit_date: \"{}\" }}", - self.commit_hash.clone().unwrap_or_default().trim(), - self.commit_date.clone().unwrap_or_default().trim() - )?; - } else { - write!(f, " }}")?; + if let Some(ref commit_hash) = self.commit_hash { + write!(f, ", commit_hash: \"{}\"", commit_hash.trim(),)?; } + if let Some(ref commit_date) = self.commit_date { + write!(f, ", commit_date: \"{}\"", commit_date.trim())?; + } + if let Some(ref host_compiler) = self.host_compiler { + write!(f, ", host_compiler: \"{}\"", host_compiler.trim())?; + } + + write!(f, " }}")?; Ok(()) } @@ -152,22 +156,27 @@ pub fn get_commit_date() -> Option { } #[must_use] -pub fn get_channel() -> String { +pub fn get_compiler_version() -> Option { + get_output("rustc", &["-V"]) +} + +#[must_use] +pub fn get_channel(compiler_version: Option) -> String { if let Ok(channel) = std::env::var("CFG_RELEASE_CHANNEL") { return channel; } // if that failed, try to ask rustc -V, do some parsing and find out - if let Some(rustc_output) = get_output("rustc", &["-V"]) { + if let Some(rustc_output) = compiler_version { if rustc_output.contains("beta") { return String::from("beta"); - } else if rustc_output.contains("stable") { - return String::from("stable"); + } else if rustc_output.contains("nightly") { + return String::from("nightly"); } } - // default to nightly - String::from("nightly") + // default to stable + String::from("stable") } #[cfg(test)] @@ -179,17 +188,19 @@ mod test { let vi = get_version_info!(); assert_eq!(vi.major, 0); assert_eq!(vi.minor, 4); - assert_eq!(vi.patch, 0); + assert_eq!(vi.patch, 1); assert_eq!(vi.crate_name, "rustc_tools_util"); // hard to make positive tests for these since they will always change assert!(vi.commit_hash.is_none()); assert!(vi.commit_date.is_none()); + + assert!(vi.host_compiler.is_none()); } #[test] fn test_display_local() { let vi = get_version_info!(); - assert_eq!(vi.to_string(), "rustc_tools_util 0.4.0"); + assert_eq!(vi.to_string(), "rustc_tools_util 0.4.1"); } #[test] @@ -198,7 +209,7 @@ mod test { let s = format!("{vi:?}"); assert_eq!( s, - "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 0 }" + "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 1 }" ); } } diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index ed357137095b..ea540d48a2b9 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -90,3 +90,9 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() { }, } } + +#[test] +fn check_host_compiler() { + let version = rustc_tools_util::get_version_info!(); + assert_eq!(version.host_compiler, Some("nightly".to_string())); +} From f826193aec2d58f64c4592818dd2d855a5bbc597 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 12 Feb 2025 20:44:22 +0100 Subject: [PATCH 079/161] `unnecessary_map_or`: do not consume the non-`Copy` comparison value --- .../src/methods/unnecessary_map_or.rs | 6 +++-- tests/ui/unnecessary_map_or.fixed | 6 +++++ tests/ui/unnecessary_map_or.rs | 6 +++++ tests/ui/unnecessary_map_or.stderr | 26 ++++++++++++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index 6dea1506d0e3..c307e8c951d0 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::eager_or_lazy::switch_to_eager_eval; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::sugg::{Sugg, make_binop}; -use clippy_utils::ty::{get_type_diagnostic_name, implements_trait}; +use clippy_utils::ty::{get_type_diagnostic_name, implements_trait, is_copy}; use clippy_utils::visitors::is_local_used; use clippy_utils::{get_parent_expr, is_from_proc_macro, path_to_local_id}; use rustc_ast::LitKind::Bool; @@ -81,9 +81,11 @@ pub(super) fn check<'a>( && (path_to_local_id(l, hir_id) ^ path_to_local_id(r, hir_id)) && !is_local_used(cx, non_binding_location, hir_id) && let typeck_results = cx.typeck_results() - && typeck_results.expr_ty(l) == typeck_results.expr_ty(r) + && let l_ty = typeck_results.expr_ty(l) + && l_ty == typeck_results.expr_ty(r) && let Some(partial_eq) = cx.tcx.get_diagnostic_item(sym::PartialEq) && implements_trait(cx, recv_ty, partial_eq, &[recv_ty.into()]) + && is_copy(cx, l_ty) { let wrap = variant.variant_name(); diff --git a/tests/ui/unnecessary_map_or.fixed b/tests/ui/unnecessary_map_or.fixed index 5a6e77a06b8f..27532373a7b9 100644 --- a/tests/ui/unnecessary_map_or.fixed +++ b/tests/ui/unnecessary_map_or.fixed @@ -99,3 +99,9 @@ impl std::ops::Deref for S { fn with_deref(o: &S) -> bool { o.is_none_or(|n| n > 5) } + +fn issue14201(a: Option, b: Option, s: &String) -> bool { + let x = a.is_some_and(|a| a == *s); + let y = b.is_none_or(|b| b == *s); + x && y +} diff --git a/tests/ui/unnecessary_map_or.rs b/tests/ui/unnecessary_map_or.rs index 5ba63121659f..6496defe1300 100644 --- a/tests/ui/unnecessary_map_or.rs +++ b/tests/ui/unnecessary_map_or.rs @@ -102,3 +102,9 @@ impl std::ops::Deref for S { fn with_deref(o: &S) -> bool { o.map_or(true, |n| n > 5) } + +fn issue14201(a: Option, b: Option, s: &String) -> bool { + let x = a.map_or(false, |a| a == *s); + let y = b.map_or(true, |b| b == *s); + x && y +} diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index 2ae327f0bf88..f672f55dd04d 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -287,5 +287,29 @@ LL - o.map_or(true, |n| n > 5) LL + o.is_none_or(|n| n > 5) | -error: aborting due to 24 previous errors +error: this `map_or` can be simplified + --> tests/ui/unnecessary_map_or.rs:107:13 + | +LL | let x = a.map_or(false, |a| a == *s); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use is_some_and instead + | +LL - let x = a.map_or(false, |a| a == *s); +LL + let x = a.is_some_and(|a| a == *s); + | + +error: this `map_or` can be simplified + --> tests/ui/unnecessary_map_or.rs:108:13 + | +LL | let y = b.map_or(true, |b| b == *s); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use is_none_or instead + | +LL - let y = b.map_or(true, |b| b == *s); +LL + let y = b.is_none_or(|b| b == *s); + | + +error: aborting due to 26 previous errors From fc532c5b322106e8ddc6485451cd5f14c4e995bd Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 13 Feb 2025 03:21:25 +0000 Subject: [PATCH 080/161] Trim suggestion parts to the subset that is purely additive --- tests/ui/implicit_return.stderr | 42 +++++++++--------------- tests/ui/legacy_numeric_constants.stderr | 5 ++- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 0d2faa5e067b..7ea72307450c 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -8,8 +8,7 @@ LL | true = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` help: add `return` as shown | -LL - true -LL + return true +LL | return true | error: missing `return` statement @@ -20,9 +19,8 @@ LL | if true { true } else { false } | help: add `return` as shown | -LL - if true { true } else { false } -LL + if true { return true } else { false } - | +LL | if true { return true } else { false } + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:19:29 @@ -32,9 +30,8 @@ LL | if true { true } else { false } | help: add `return` as shown | -LL - if true { true } else { false } -LL + if true { true } else { return false } - | +LL | if true { true } else { return false } + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:25:17 @@ -44,9 +41,8 @@ LL | true => false, | help: add `return` as shown | -LL - true => false, -LL + true => return false, - | +LL | true => return false, + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:26:20 @@ -56,9 +52,8 @@ LL | false => { true }, | help: add `return` as shown | -LL - false => { true }, -LL + false => { return true }, - | +LL | false => { return true }, + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:39:9 @@ -104,9 +99,8 @@ LL | let _ = || { true }; | help: add `return` as shown | -LL - let _ = || { true }; -LL + let _ = || { return true }; - | +LL | let _ = || { return true }; + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:73:16 @@ -116,9 +110,8 @@ LL | let _ = || true; | help: add `return` as shown | -LL - let _ = || true; -LL + let _ = || return true; - | +LL | let _ = || return true; + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:81:5 @@ -128,8 +121,7 @@ LL | format!("test {}", "test") | help: add `return` as shown | -LL - format!("test {}", "test") -LL + return format!("test {}", "test") +LL | return format!("test {}", "test") | error: missing `return` statement @@ -140,8 +132,7 @@ LL | m!(true, false) | help: add `return` as shown | -LL - m!(true, false) -LL + return m!(true, false) +LL | return m!(true, false) | error: missing `return` statement @@ -191,8 +182,7 @@ LL | true | help: add `return` as shown | -LL - true -LL + return true +LL | return true | error: aborting due to 16 previous errors diff --git a/tests/ui/legacy_numeric_constants.stderr b/tests/ui/legacy_numeric_constants.stderr index 74fe09e0f5c6..91dfe79d55ba 100644 --- a/tests/ui/legacy_numeric_constants.stderr +++ b/tests/ui/legacy_numeric_constants.stderr @@ -68,9 +68,8 @@ LL | MAX; | help: use the associated constant instead | -LL - MAX; -LL + u32::MAX; - | +LL | u32::MAX; + | +++++ error: usage of a legacy numeric method --> tests/ui/legacy_numeric_constants.rs:49:10 From f7f78880414aec9ba22d03d894f8ca026b63dd84 Mon Sep 17 00:00:00 2001 From: Sebastian Jeltsch Date: Thu, 13 Feb 2025 14:51:04 +0100 Subject: [PATCH 081/161] Make rust_tools_util package compatible with current stable by lowering rust edition to 2021. --- Cargo.toml | 4 ++-- rustc_tools_util/Cargo.toml | 4 ++-- rustc_tools_util/README.md | 4 ++-- rustc_tools_util/src/lib.rs | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 263f2a4aab70..6c19e7af5f8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ path = "src/driver.rs" [dependencies] clippy_config = { path = "clippy_config" } clippy_lints = { path = "clippy_lints" } -rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" } +rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" } tempfile = { version = "3.3", optional = true } termize = "0.1" color-print = "0.3.4" @@ -54,7 +54,7 @@ parking_lot = "0.12" tokio = { version = "1", features = ["io-util"] } [build-dependencies] -rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" } +rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" } [features] integration = ["tempfile"] diff --git a/rustc_tools_util/Cargo.toml b/rustc_tools_util/Cargo.toml index 189f34dd2a65..716b1ed61443 100644 --- a/rustc_tools_util/Cargo.toml +++ b/rustc_tools_util/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "rustc_tools_util" -version = "0.4.1" +version = "0.4.2" description = "small helper to generate version information for git packages" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" license = "MIT OR Apache-2.0" keywords = ["rustc", "tool", "git", "version", "hash"] categories = ["development-tools"] -edition = "2024" +edition = "2021" # Keep this, for this crate's MSRV to stay low [dependencies] diff --git a/rustc_tools_util/README.md b/rustc_tools_util/README.md index 455654c10900..ff4ca6f830e6 100644 --- a/rustc_tools_util/README.md +++ b/rustc_tools_util/README.md @@ -13,10 +13,10 @@ build = "build.rs" List rustc_tools_util as regular AND build dependency. ````toml [dependencies] -rustc_tools_util = "0.4.1" +rustc_tools_util = "0.4.2" [build-dependencies] -rustc_tools_util = "0.4.1" +rustc_tools_util = "0.4.2" ```` In `build.rs`, generate the data in your `main()` diff --git a/rustc_tools_util/src/lib.rs b/rustc_tools_util/src/lib.rs index cabd9dfa0c7c..423154a69fa0 100644 --- a/rustc_tools_util/src/lib.rs +++ b/rustc_tools_util/src/lib.rs @@ -188,7 +188,7 @@ mod test { let vi = get_version_info!(); assert_eq!(vi.major, 0); assert_eq!(vi.minor, 4); - assert_eq!(vi.patch, 1); + assert_eq!(vi.patch, 2); assert_eq!(vi.crate_name, "rustc_tools_util"); // hard to make positive tests for these since they will always change assert!(vi.commit_hash.is_none()); @@ -200,7 +200,7 @@ mod test { #[test] fn test_display_local() { let vi = get_version_info!(); - assert_eq!(vi.to_string(), "rustc_tools_util 0.4.1"); + assert_eq!(vi.to_string(), "rustc_tools_util 0.4.2"); } #[test] @@ -209,7 +209,7 @@ mod test { let s = format!("{vi:?}"); assert_eq!( s, - "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 1 }" + "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 2 }" ); } } From 133882920bdea4fb8c6d598f85e2a2296cce242e Mon Sep 17 00:00:00 2001 From: alexey semenyuk Date: Sat, 15 Feb 2025 14:47:18 +0500 Subject: [PATCH 082/161] Add example for macro_use --- clippy_lints/src/macro_use.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 374128665392..bb6e22d9e5c7 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -21,7 +21,21 @@ declare_clippy_lint! { /// ### Example /// ```rust,ignore /// #[macro_use] - /// use some_macro; + /// extern crate some_crate; + /// + /// fn main() { + /// some_macro!(); + /// } + /// ``` + /// + /// Use instead: + /// + /// ```rust,ignore + /// use some_crate::some_macro; + /// + /// fn main() { + /// some_macro!(); + /// } /// ``` #[clippy::version = "1.44.0"] pub MACRO_USE_IMPORTS, From 95c6866dd4ab3de3b21aa02ca93741c0010836f8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Feb 2025 15:56:15 +0100 Subject: [PATCH 083/161] Make UI tests annotations mandatory --- tests/compile-test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index d1b1a1d23232..838ca2919a26 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -153,7 +153,7 @@ impl TestContext { }; let defaults = config.comment_defaults.base(); defaults.exit_status = None.into(); - defaults.require_annotations = None.into(); + defaults.require_annotations = Some(Spanned::dummy(true)).into(); defaults.diagnostic_code_prefix = Some(Spanned::dummy("clippy::".into())).into(); defaults.set_custom("rustfix", RustfixMode::Everything); if let Some(collector) = self.diagnostic_collector.clone() { From f666fd6417a87fcb69f7e62ac0c41712099046a4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Feb 2025 17:57:08 +0100 Subject: [PATCH 084/161] Update UI tests --- tests/ui/absurd-extreme-comparisons.rs | 56 +- tests/ui/absurd-extreme-comparisons.stderr | 34 +- tests/ui/allow_attributes.fixed | 3 + tests/ui/allow_attributes.rs | 3 + tests/ui/allow_attributes.stderr | 4 +- tests/ui/allow_attributes_without_reason.rs | 5 + .../ui/allow_attributes_without_reason.stderr | 8 +- tests/ui/almost_complete_range.fixed | 27 + tests/ui/almost_complete_range.rs | 27 + tests/ui/almost_complete_range.stderr | 52 +- tests/ui/approx_const.rs | 69 ++- tests/ui/approx_const.stderr | 44 +- tests/ui/arc_with_non_send_sync.rs | 3 + tests/ui/arc_with_non_send_sync.stderr | 4 +- tests/ui/arithmetic_side_effects.rs | 128 +++++ tests/ui/arithmetic_side_effects.stderr | 254 ++++----- tests/ui/as_conversions.rs | 4 +- tests/ui/as_pointer_underscore.fixed | 6 +- tests/ui/as_pointer_underscore.rs | 6 +- tests/ui/as_pointer_underscore.stderr | 2 +- tests/ui/as_ptr_cast_mut.rs | 8 +- tests/ui/as_ptr_cast_mut.stderr | 2 +- tests/ui/as_underscore.fixed | 2 + tests/ui/as_underscore.rs | 2 + tests/ui/as_underscore.stderr | 2 +- tests/ui/asm_syntax_not_x86.rs | 5 + tests/ui/asm_syntax_x86.rs | 24 +- tests/ui/asm_syntax_x86.stderr | 14 +- tests/ui/assertions_on_constants.rs | 36 +- tests/ui/assertions_on_constants.stderr | 22 +- tests/ui/assertions_on_result_states.fixed | 7 + tests/ui/assertions_on_result_states.rs | 7 + tests/ui/assertions_on_result_states.stderr | 12 +- tests/ui/assign_ops.fixed | 11 + tests/ui/assign_ops.rs | 11 + tests/ui/assign_ops.stderr | 20 +- tests/ui/assign_ops2.rs | 34 +- tests/ui/assign_ops2.stderr | 18 +- tests/ui/assigning_clones.fixed | 30 ++ tests/ui/assigning_clones.rs | 30 ++ tests/ui/assigning_clones.stderr | 58 +- tests/ui/async_yields_async.fixed | 6 + tests/ui/async_yields_async.rs | 6 + tests/ui/async_yields_async.stderr | 10 +- tests/ui/attrs.rs | 13 +- tests/ui/attrs.stderr | 48 +- tests/ui/author.rs | 2 + tests/ui/author/blocks.rs | 1 + tests/ui/author/call.rs | 2 + tests/ui/author/if.rs | 2 + tests/ui/author/issue_3849.rs | 2 + tests/ui/author/loop.rs | 2 + tests/ui/author/macro_in_closure.rs | 2 + tests/ui/author/macro_in_loop.rs | 2 + tests/ui/author/matches.rs | 2 + tests/ui/author/repeat.rs | 2 + tests/ui/author/struct.rs | 2 + tests/ui/await_holding_refcell_ref.rs | 18 +- tests/ui/await_holding_refcell_ref.stderr | 22 +- tests/ui/bind_instead_of_map.fixed | 3 + tests/ui/bind_instead_of_map.rs | 3 + tests/ui/bind_instead_of_map.stderr | 4 +- tests/ui/bind_instead_of_map_multipart.fixed | 5 + tests/ui/bind_instead_of_map_multipart.rs | 5 + tests/ui/bind_instead_of_map_multipart.stderr | 11 +- tests/ui/bit_masks.rs | 57 +- tests/ui/bit_masks.stderr | 30 +- tests/ui/blanket_clippy_restriction_lints.rs | 10 +- .../blanket_clippy_restriction_lints.stderr | 6 +- tests/ui/blocks_in_conditions.fixed | 1 + tests/ui/blocks_in_conditions.rs | 1 + tests/ui/blocks_in_conditions.stderr | 2 +- tests/ui/bool_assert_comparison.fixed | 33 ++ tests/ui/bool_assert_comparison.rs | 33 ++ tests/ui/bool_assert_comparison.stderr | 64 +-- tests/ui/bool_comparison.fixed | 25 + tests/ui/bool_comparison.rs | 25 + tests/ui/bool_comparison.stderr | 48 +- tests/ui/bool_to_int_with_if.fixed | 1 + tests/ui/bool_to_int_with_if.rs | 9 + tests/ui/bool_to_int_with_if.stderr | 24 +- tests/ui/borrow_and_ref_as_ptr.fixed | 2 + tests/ui/borrow_and_ref_as_ptr.rs | 2 + tests/ui/borrow_and_ref_as_ptr.stderr | 2 +- tests/ui/borrow_as_ptr.fixed | 4 + tests/ui/borrow_as_ptr.rs | 4 + tests/ui/borrow_as_ptr.stderr | 6 +- tests/ui/borrow_as_ptr_no_std.fixed | 2 + tests/ui/borrow_as_ptr_no_std.rs | 2 + tests/ui/borrow_as_ptr_no_std.stderr | 2 +- tests/ui/borrow_as_ptr_raw_ref.fixed | 2 + tests/ui/borrow_as_ptr_raw_ref.rs | 2 + tests/ui/borrow_as_ptr_raw_ref.stderr | 2 +- tests/ui/borrow_box.fixed | 30 +- tests/ui/borrow_box.rs | 30 +- tests/ui/borrow_box.stderr | 18 +- tests/ui/borrow_deref_ref.fixed | 3 + tests/ui/borrow_deref_ref.rs | 3 + tests/ui/borrow_deref_ref.stderr | 4 +- tests/ui/borrow_deref_ref_unfixable.rs | 5 +- .../borrow_interior_mutable_const/others.rs | 42 +- .../others.stderr | 112 ++-- .../borrow_interior_mutable_const/traits.rs | 51 +- .../traits.stderr | 102 ++-- tests/ui/box_collection.rs | 27 +- tests/ui/box_collection.stderr | 16 +- tests/ui/box_default.fixed | 10 + tests/ui/box_default.rs | 10 + tests/ui/box_default.stderr | 18 +- tests/ui/box_default_no_std.rs | 2 + tests/ui/boxed_local.rs | 14 +- tests/ui/boxed_local.stderr | 6 +- .../branches_sharing_code/false_positives.rs | 2 + .../branches_sharing_code/shared_at_bottom.rs | 33 +- .../shared_at_bottom.stderr | 33 +- .../ui/branches_sharing_code/shared_at_top.rs | 21 +- .../shared_at_top.stderr | 21 +- .../shared_at_top_and_bottom.rs | 15 +- .../shared_at_top_and_bottom.stderr | 25 +- .../branches_sharing_code/valid_if_blocks.rs | 15 +- .../valid_if_blocks.stderr | 16 +- tests/ui/builtin_type_shadow.rs | 3 +- tests/ui/builtin_type_shadow.stderr | 3 +- tests/ui/byte_char_slices.fixed | 5 + tests/ui/byte_char_slices.rs | 5 + tests/ui/byte_char_slices.stderr | 8 +- tests/ui/bytecount.rs | 9 +- tests/ui/bytecount.stderr | 4 +- tests/ui/bytes_count_to_len.fixed | 4 + tests/ui/bytes_count_to_len.rs | 4 + tests/ui/bytes_count_to_len.stderr | 6 +- tests/ui/bytes_nth.fixed | 3 + tests/ui/bytes_nth.rs | 3 + tests/ui/bytes_nth.stderr | 4 +- ...sensitive_file_extension_comparisons.fixed | 6 + ...se_sensitive_file_extension_comparisons.rs | 6 + ...ensitive_file_extension_comparisons.stderr | 10 +- tests/ui/cast.rs | 250 ++++++--- tests/ui/cast.stderr | 182 +++---- tests/ui/cast_abs_to_unsigned.fixed | 18 + tests/ui/cast_abs_to_unsigned.rs | 18 + tests/ui/cast_abs_to_unsigned.stderr | 42 +- tests/ui/cast_alignment.rs | 14 +- tests/ui/cast_alignment.stderr | 6 +- tests/ui/cast_enum_constructor.rs | 8 +- tests/ui/cast_enum_constructor.stderr | 2 +- tests/ui/cast_lossless_bool.fixed | 15 + tests/ui/cast_lossless_bool.rs | 15 + tests/ui/cast_lossless_bool.stderr | 28 +- tests/ui/cast_lossless_float.fixed | 13 + tests/ui/cast_lossless_float.rs | 13 + tests/ui/cast_lossless_float.stderr | 24 +- tests/ui/cast_lossless_integer.fixed | 40 ++ tests/ui/cast_lossless_integer.rs | 40 ++ tests/ui/cast_lossless_integer.stderr | 78 +-- tests/ui/cast_nan_to_int.rs | 30 +- tests/ui/cast_nan_to_int.stderr | 10 +- tests/ui/cast_raw_slice_pointer_cast.fixed | 7 + tests/ui/cast_raw_slice_pointer_cast.rs | 7 + tests/ui/cast_raw_slice_pointer_cast.stderr | 12 +- tests/ui/cast_size.64bit.stderr | 34 +- tests/ui/cast_size.rs | 18 + tests/ui/cast_slice_different_sizes.rs | 44 +- tests/ui/cast_slice_different_sizes.stderr | 37 +- tests/ui/cfg_attr_cargo_clippy.fixed | 21 +- tests/ui/cfg_attr_cargo_clippy.rs | 21 +- tests/ui/cfg_attr_cargo_clippy.stderr | 12 +- tests/ui/cfg_attr_rustfmt.fixed | 3 + tests/ui/cfg_attr_rustfmt.rs | 3 + tests/ui/cfg_attr_rustfmt.stderr | 4 +- tests/ui/cfg_not_test.rs | 5 + tests/ui/cfg_not_test.stderr | 8 +- tests/ui/char_lit_as_u8.rs | 5 +- tests/ui/char_lit_as_u8_suggestions.fixed | 4 + tests/ui/char_lit_as_u8_suggestions.rs | 4 + tests/ui/char_lit_as_u8_suggestions.stderr | 6 +- tests/ui/checked_conversions.fixed | 17 + tests/ui/checked_conversions.rs | 17 + tests/ui/checked_conversions.stderr | 32 +- .../ui/checked_unwrap/complex_conditionals.rs | 60 ++- .../complex_conditionals.stderr | 38 +- .../complex_conditionals_nested.rs | 4 +- .../ui/checked_unwrap/simple_conditionals.rs | 74 ++- .../checked_unwrap/simple_conditionals.stderr | 50 +- tests/ui/clear_with_drain.fixed | 21 + tests/ui/clear_with_drain.rs | 21 + tests/ui/clear_with_drain.stderr | 40 +- tests/ui/clone_on_copy.fixed | 9 + tests/ui/clone_on_copy.rs | 9 + tests/ui/clone_on_copy.stderr | 16 +- tests/ui/clone_on_copy_impl.rs | 2 + tests/ui/cloned_instead_of_copied.fixed | 8 + tests/ui/cloned_instead_of_copied.rs | 8 + tests/ui/cloned_instead_of_copied.stderr | 14 +- tests/ui/cmp_null.fixed | 17 +- tests/ui/cmp_null.rs | 17 +- tests/ui/cmp_null.stderr | 8 +- .../ui/cmp_owned/asymmetric_partial_eq.fixed | 6 + tests/ui/cmp_owned/asymmetric_partial_eq.rs | 6 + .../ui/cmp_owned/asymmetric_partial_eq.stderr | 10 +- tests/ui/cmp_owned/comparison_flip.fixed | 2 + tests/ui/cmp_owned/comparison_flip.rs | 2 + tests/ui/cmp_owned/comparison_flip.stderr | 2 +- tests/ui/cmp_owned/with_suggestion.fixed | 6 + tests/ui/cmp_owned/with_suggestion.rs | 6 + tests/ui/cmp_owned/with_suggestion.stderr | 10 +- tests/ui/cmp_owned/without_suggestion.rs | 11 +- tests/ui/cmp_owned/without_suggestion.stderr | 4 +- tests/ui/cognitive_complexity.rs | 60 ++- tests/ui/cognitive_complexity.stderr | 38 +- tests/ui/cognitive_complexity_attr_used.rs | 3 +- tests/ui/collapsible_else_if.fixed | 8 + tests/ui/collapsible_else_if.rs | 8 + tests/ui/collapsible_else_if.stderr | 154 ------ tests/ui/collapsible_if.fixed | 9 + tests/ui/collapsible_if.rs | 9 + tests/ui/collapsible_if.stderr | 139 ----- tests/ui/collapsible_match.rs | 37 +- tests/ui/collapsible_match.stderr | 70 ++- tests/ui/collapsible_match2.rs | 13 +- tests/ui/collapsible_match2.stderr | 61 ++- tests/ui/collapsible_str_replace.fixed | 13 + tests/ui/collapsible_str_replace.rs | 14 + tests/ui/collapsible_str_replace.stderr | 27 +- tests/ui/collection_is_never_read.rs | 62 ++- tests/ui/collection_is_never_read.stderr | 38 +- tests/ui/comparison_chain.rs | 24 +- tests/ui/comparison_chain.stderr | 28 +- tests/ui/comparison_to_empty.fixed | 13 + tests/ui/comparison_to_empty.rs | 13 + tests/ui/comparison_to_empty.stderr | 24 +- tests/ui/const_comparisons.rs | 113 ++-- tests/ui/const_comparisons.stderr | 60 +-- tests/ui/const_is_empty.rs | 79 ++- tests/ui/const_is_empty.stderr | 52 +- tests/ui/copy_iterator.rs | 5 +- tests/ui/copy_iterator.stderr | 3 - tests/ui/crashes/associated-constant-ice.rs | 1 + tests/ui/crashes/cc_seme.rs | 1 + tests/ui/crashes/enum-glob-import-crate.rs | 2 + tests/ui/crashes/ice-10148.rs | 1 + tests/ui/crashes/ice-10508a.rs | 1 + tests/ui/crashes/ice-10508b.rs | 2 + tests/ui/crashes/ice-10508c.rs | 2 + tests/ui/crashes/ice-10972-tait.rs | 1 + tests/ui/crashes/ice-11065.rs | 2 + tests/ui/crashes/ice-11230.fixed | 2 + tests/ui/crashes/ice-11230.rs | 2 + tests/ui/crashes/ice-11230.stderr | 2 +- tests/ui/crashes/ice-11337.rs | 2 + tests/ui/crashes/ice-11422.fixed | 1 + tests/ui/crashes/ice-11422.rs | 1 + tests/ui/crashes/ice-11755.rs | 2 + tests/ui/crashes/ice-11803.rs | 2 + tests/ui/crashes/ice-11939.rs | 2 + tests/ui/crashes/ice-12253.rs | 2 + tests/ui/crashes/ice-12491.fixed | 1 + tests/ui/crashes/ice-12491.rs | 1 + tests/ui/crashes/ice-12585.rs | 2 + tests/ui/crashes/ice-12616.fixed | 1 + tests/ui/crashes/ice-12616.rs | 1 + tests/ui/crashes/ice-13862.rs | 2 + tests/ui/crashes/ice-1588.rs | 2 + tests/ui/crashes/ice-1782.rs | 2 + tests/ui/crashes/ice-1969.rs | 2 + tests/ui/crashes/ice-2499.rs | 2 + tests/ui/crashes/ice-2594.rs | 2 + tests/ui/crashes/ice-2727.rs | 1 + tests/ui/crashes/ice-2760.rs | 2 + tests/ui/crashes/ice-2774.fixed | 5 +- tests/ui/crashes/ice-2774.rs | 5 +- tests/ui/crashes/ice-2862.rs | 1 + tests/ui/crashes/ice-2865.rs | 2 + tests/ui/crashes/ice-3151.rs | 1 + tests/ui/crashes/ice-3462.rs | 2 + tests/ui/crashes/ice-360.rs | 11 +- tests/ui/crashes/ice-360.stderr | 2 +- tests/ui/crashes/ice-3717.fixed | 3 +- tests/ui/crashes/ice-3717.rs | 3 +- tests/ui/crashes/ice-3717.stderr | 1 + tests/ui/crashes/ice-3741.rs | 1 + tests/ui/crashes/ice-3747.rs | 1 + tests/ui/crashes/ice-3969.rs | 11 +- tests/ui/crashes/ice-3969.stderr | 8 +- tests/ui/crashes/ice-4121.rs | 2 + tests/ui/crashes/ice-4545.rs | 2 + tests/ui/crashes/ice-4579.rs | 2 + tests/ui/crashes/ice-4671.rs | 2 + tests/ui/crashes/ice-4727.rs | 2 + tests/ui/crashes/ice-4760.rs | 2 + tests/ui/crashes/ice-4775.rs | 2 + tests/ui/crashes/ice-4968.rs | 1 + tests/ui/crashes/ice-5207.rs | 1 + tests/ui/crashes/ice-5223.rs | 1 + tests/ui/crashes/ice-5238.rs | 1 + tests/ui/crashes/ice-5389.rs | 2 + tests/ui/crashes/ice-5579.rs | 2 + tests/ui/crashes/ice-5835.fixed | 11 - tests/ui/crashes/ice-5835.rs | 6 +- tests/ui/crashes/ice-5835.stderr | 18 +- tests/ui/crashes/ice-5872.fixed | 5 +- tests/ui/crashes/ice-5872.rs | 5 +- tests/ui/crashes/ice-5944.rs | 2 + tests/ui/crashes/ice-6139.rs | 2 + tests/ui/crashes/ice-6153.rs | 2 + tests/ui/crashes/ice-6179.rs | 1 + tests/ui/crashes/ice-6250.rs | 2 + tests/ui/crashes/ice-6251.rs | 3 + tests/ui/crashes/ice-6252.rs | 3 + tests/ui/crashes/ice-6252.stderr | 4 +- tests/ui/crashes/ice-6254.rs | 1 + tests/ui/crashes/ice-6332.rs | 2 + tests/ui/crashes/ice-6539.rs | 1 + tests/ui/crashes/ice-6792.rs | 1 + tests/ui/crashes/ice-6793.rs | 1 + tests/ui/crashes/ice-6840.rs | 1 + tests/ui/crashes/ice-700.rs | 2 + tests/ui/crashes/ice-7012.rs | 2 + tests/ui/crashes/ice-7126.rs | 1 + tests/ui/crashes/ice-7169.fixed | 5 +- tests/ui/crashes/ice-7169.rs | 5 +- tests/ui/crashes/ice-7231.rs | 2 + tests/ui/crashes/ice-7272.rs | 1 + tests/ui/crashes/ice-7340.rs | 2 + tests/ui/crashes/ice-7410.rs | 1 + tests/ui/crashes/ice-7423.rs | 2 + tests/ui/crashes/ice-7868.rs | 1 + tests/ui/crashes/ice-7869.rs | 3 +- tests/ui/crashes/ice-7869.stderr | 1 + tests/ui/crashes/ice-7934.rs | 2 + tests/ui/crashes/ice-8250.fixed | 5 +- tests/ui/crashes/ice-8250.rs | 5 +- tests/ui/crashes/ice-8386.rs | 2 + tests/ui/crashes/ice-8681.rs | 1 + tests/ui/crashes/ice-8821.rs | 2 + tests/ui/crashes/ice-8850.fixed | 7 +- tests/ui/crashes/ice-8850.rs | 7 +- tests/ui/crashes/ice-8850.stderr | 4 +- tests/ui/crashes/ice-9041.rs | 5 +- tests/ui/crashes/ice-9238.rs | 2 + tests/ui/crashes/ice-9242.rs | 2 + tests/ui/crashes/ice-9405.rs | 2 + tests/ui/crashes/ice-9405.stderr | 2 +- tests/ui/crashes/ice-9414.rs | 2 + tests/ui/crashes/ice-9445.rs | 1 + tests/ui/crashes/ice-9459.rs | 2 + tests/ui/crashes/ice-9463.rs | 3 +- tests/ui/crashes/ice-9625.rs | 2 + tests/ui/crashes/ice-9746.rs | 1 + tests/ui/crashes/ice-rust-107877.rs | 2 + tests/ui/crashes/ice_exact_size.rs | 2 + tests/ui/crashes/if_same_then_else.rs | 2 + tests/ui/crashes/implements-trait.rs | 2 + tests/ui/crashes/inherent_impl.rs | 2 + tests/ui/crashes/issue-825.rs | 2 + tests/ui/crashes/issues_loop_mut_cond.rs | 2 + tests/ui/crashes/match_same_arms_const.rs | 2 + tests/ui/crashes/needless_borrow_fp.rs | 2 + .../needless_lifetimes_impl_trait.fixed | 4 +- .../crashes/needless_lifetimes_impl_trait.rs | 4 +- .../needless_lifetimes_impl_trait.stderr | 2 +- .../needless_pass_by_value-w-late-bound.fixed | 3 +- .../needless_pass_by_value-w-late-bound.rs | 3 +- tests/ui/crashes/regressions.rs | 2 + tests/ui/crashes/returns.rs | 1 + tests/ui/crashes/shadow.rs | 2 + tests/ui/crashes/single-match-else.rs | 2 + .../crashes/third-party/conf_allowlisted.rs | 2 + tests/ui/crashes/trivial_bounds.rs | 2 + .../ui/crashes/unreachable-array-or-slice.rs | 1 + .../crashes/used_underscore_binding_macro.rs | 2 + tests/ui/crate_in_macro_def.fixed | 1 + tests/ui/crate_in_macro_def.rs | 1 + .../entrypoint_recursion.rs | 1 + tests/ui/crate_level_checks/no_std_swap.rs | 5 +- .../crate_level_checks/std_main_recursion.rs | 3 +- tests/ui/create_dir.fixed | 2 + tests/ui/create_dir.rs | 2 + tests/ui/create_dir.stderr | 2 +- tests/ui/dbg_macro/dbg_macro.fixed | 57 +- tests/ui/dbg_macro/dbg_macro.rs | 57 +- tests/ui/dbg_macro/dbg_macro.stderr | 36 +- tests/ui/dbg_macro/dbg_macro_unfixable.rs | 10 +- tests/ui/dbg_macro/dbg_macro_unfixable.stderr | 10 +- tests/ui/debug_assert_with_mut_call.rs | 86 ++- tests/ui/debug_assert_with_mut_call.stderr | 54 +- tests/ui/decimal_literal_representation.fixed | 7 + tests/ui/decimal_literal_representation.rs | 7 + .../ui/decimal_literal_representation.stderr | 12 +- .../declare_interior_mutable_const/enums.rs | 36 +- .../enums.stderr | 58 +- .../declare_interior_mutable_const/others.rs | 13 +- .../others.stderr | 8 +- .../declare_interior_mutable_const/traits.rs | 39 +- .../traits.stderr | 72 +-- .../ui/default_constructed_unit_structs.fixed | 6 + tests/ui/default_constructed_unit_structs.rs | 6 + .../default_constructed_unit_structs.stderr | 10 +- tests/ui/default_instead_of_iter_empty.fixed | 3 + tests/ui/default_instead_of_iter_empty.rs | 3 + tests/ui/default_instead_of_iter_empty.stderr | 4 +- ...default_instead_of_iter_empty_no_std.fixed | 2 + .../default_instead_of_iter_empty_no_std.rs | 2 + ...efault_instead_of_iter_empty_no_std.stderr | 2 +- tests/ui/default_numeric_fallback_f64.fixed | 23 + tests/ui/default_numeric_fallback_f64.rs | 23 + tests/ui/default_numeric_fallback_f64.stderr | 44 +- tests/ui/default_numeric_fallback_i32.fixed | 28 + tests/ui/default_numeric_fallback_i32.rs | 28 + tests/ui/default_numeric_fallback_i32.stderr | 54 +- tests/ui/default_trait_access.fixed | 8 + tests/ui/default_trait_access.rs | 8 + tests/ui/default_trait_access.stderr | 14 +- tests/ui/default_union_representation.rs | 12 +- tests/ui/default_union_representation.stderr | 10 +- tests/ui/deref_addrof.fixed | 11 + tests/ui/deref_addrof.rs | 11 + tests/ui/deref_addrof.stderr | 20 +- tests/ui/deref_addrof_double_trigger.rs | 11 +- tests/ui/deref_addrof_double_trigger.stderr | 4 +- tests/ui/deref_addrof_macro.rs | 1 + tests/ui/deref_by_slicing.fixed | 10 + tests/ui/deref_by_slicing.rs | 10 + tests/ui/deref_by_slicing.stderr | 18 +- tests/ui/derivable_impls.rs | 11 + tests/ui/derivable_impls.stderr | 44 +- tests/ui/derive.rs | 15 +- tests/ui/derive.stderr | 56 +- tests/ui/derive_ord_xor_partial_ord.rs | 12 +- tests/ui/derive_ord_xor_partial_ord.stderr | 22 +- tests/ui/derive_partial_eq_without_eq.fixed | 17 +- tests/ui/derive_partial_eq_without_eq.rs | 17 +- tests/ui/derive_partial_eq_without_eq.stderr | 32 +- tests/ui/derived_hash_with_manual_eq.rs | 6 +- tests/ui/derived_hash_with_manual_eq.stderr | 6 +- tests/ui/disallowed_names.rs | 44 +- tests/ui/disallowed_names.stderr | 26 +- tests/ui/disallowed_script_idents.rs | 6 +- tests/ui/disallowed_script_idents.stderr | 2 +- tests/ui/diverging_sub_expression.rs | 35 +- tests/ui/diverging_sub_expression.stderr | 20 +- tests/ui/doc/doc-fixable.fixed | 34 ++ tests/ui/doc/doc-fixable.rs | 34 ++ tests/ui/doc/doc-fixable.stderr | 64 +-- tests/ui/doc/doc_include_without_cfg.fixed | 6 +- tests/ui/doc/doc_include_without_cfg.rs | 6 +- tests/ui/doc/doc_include_without_cfg.stderr | 2 +- tests/ui/doc/footnote_issue_13183.rs | 1 + tests/ui/doc/issue_12795.fixed | 12 +- tests/ui/doc/issue_12795.rs | 12 +- tests/ui/doc/issue_1832.rs | 1 + tests/ui/doc/issue_902.rs | 1 + tests/ui/doc/issue_9473.fixed | 1 + tests/ui/doc/issue_9473.rs | 1 + tests/ui/doc/needless_doctest_main.rs | 2 + tests/ui/doc/unbalanced_ticks.rs | 25 +- tests/ui/doc/unbalanced_ticks.stderr | 172 +++--- tests/ui/doc_errors.rs | 23 +- tests/ui/doc_errors.stderr | 12 +- tests/ui/doc_link_with_quotes.rs | 6 +- tests/ui/doc_link_with_quotes.stderr | 2 +- tests/ui/doc_unsafe.rs | 6 + tests/ui/doc_unsafe.stderr | 10 +- tests/ui/double_comparison.fixed | 8 + tests/ui/double_comparison.rs | 8 + tests/ui/double_comparison.stderr | 14 +- tests/ui/double_ended_iterator_last.fixed | 2 + tests/ui/double_ended_iterator_last.rs | 2 + tests/ui/double_ended_iterator_last.stderr | 2 +- tests/ui/double_must_use.rs | 12 +- tests/ui/double_must_use.stderr | 6 +- tests/ui/double_parens.rs | 20 +- tests/ui/double_parens.stderr | 10 +- tests/ui/drain_collect.fixed | 10 + tests/ui/drain_collect.rs | 10 + tests/ui/drain_collect.stderr | 26 +- tests/ui/drain_collect_nostd.fixed | 1 + tests/ui/drain_collect_nostd.rs | 1 + tests/ui/drop_non_drop.rs | 6 +- tests/ui/drop_non_drop.stderr | 4 +- tests/ui/duplicate_underscore_argument.rs | 5 +- tests/ui/duration_subsec.fixed | 5 + tests/ui/duration_subsec.rs | 5 + tests/ui/duration_subsec.stderr | 8 +- tests/ui/eager_transmute.fixed | 17 + tests/ui/eager_transmute.rs | 17 + tests/ui/eager_transmute.stderr | 32 +- tests/ui/else_if_without_else.rs | 12 +- tests/ui/else_if_without_else.stderr | 10 +- tests/ui/empty_docs.rs | 9 + tests/ui/empty_docs.stderr | 16 +- tests/ui/empty_drop.rs | 2 + tests/ui/empty_drop.stderr | 4 +- tests/ui/empty_enum.rs | 3 +- .../empty_enum_variants_with_brackets.fixed | 12 +- tests/ui/empty_enum_variants_with_brackets.rs | 12 +- .../empty_enum_variants_with_brackets.stderr | 24 +- tests/ui/empty_enum_without_never_type.rs | 2 + .../ui/empty_line_after/doc_comments.1.fixed | 30 +- .../ui/empty_line_after/doc_comments.2.fixed | 55 +- tests/ui/empty_line_after/doc_comments.rs | 30 +- tests/ui/empty_line_after/doc_comments.stderr | 65 ++- tests/ui/empty_loop.rs | 3 + tests/ui/empty_loop.stderr | 4 +- tests/ui/empty_loop_no_std.rs | 3 +- tests/ui/empty_structs_with_brackets.fixed | 2 + tests/ui/empty_structs_with_brackets.rs | 2 + tests/ui/empty_structs_with_brackets.stderr | 2 +- tests/ui/endian_bytes.rs | 86 +++ tests/ui/endian_bytes.stderr | 170 +++--- tests/ui/entry.fixed | 9 + tests/ui/entry.rs | 11 + tests/ui/entry.stderr | 48 +- tests/ui/entry_btree.fixed | 1 + tests/ui/entry_btree.rs | 1 + tests/ui/entry_btree.stderr | 2 + tests/ui/entry_with_else.fixed | 7 + tests/ui/entry_with_else.rs | 7 + tests/ui/entry_with_else.stderr | 26 +- tests/ui/enum_clike_unportable_variant.rs | 29 +- tests/ui/enum_clike_unportable_variant.stderr | 16 +- tests/ui/enum_glob_use.fixed | 3 + tests/ui/enum_glob_use.rs | 3 + tests/ui/enum_glob_use.stderr | 4 +- tests/ui/enum_variants.rs | 34 +- tests/ui/enum_variants.stderr | 11 +- tests/ui/eprint_with_newline.fixed | 29 +- tests/ui/eprint_with_newline.rs | 29 +- tests/ui/eprint_with_newline.stderr | 20 +- tests/ui/eq_op.rs | 91 ++-- tests/ui/eq_op.stderr | 56 +- tests/ui/eq_op_macros.rs | 28 +- tests/ui/eq_op_macros.stderr | 22 +- tests/ui/equatable_if_let.fixed | 14 + tests/ui/equatable_if_let.rs | 14 + tests/ui/equatable_if_let.stderr | 26 +- tests/ui/erasing_op.rs | 17 +- tests/ui/erasing_op.stderr | 8 +- tests/ui/err_expect.fixed | 2 + tests/ui/err_expect.rs | 2 + tests/ui/err_expect.stderr | 2 +- tests/ui/error_impl_error.rs | 12 +- tests/ui/error_impl_error.stderr | 12 +- tests/ui/eta.fixed | 35 ++ tests/ui/eta.rs | 35 ++ tests/ui/eta.stderr | 68 +-- tests/ui/eta_nostd.fixed | 1 + tests/ui/eta_nostd.rs | 1 + tests/ui/excessive_precision.fixed | 16 + tests/ui/excessive_precision.rs | 16 + tests/ui/excessive_precision.stderr | 30 +- tests/ui/exhaustive_items.fixed | 3 + tests/ui/exhaustive_items.rs | 3 + tests/ui/exhaustive_items.stderr | 7 +- tests/ui/exit1.rs | 5 +- tests/ui/exit2.rs | 5 +- tests/ui/exit3.rs | 2 + tests/ui/expect.rs | 9 +- tests/ui/expect.stderr | 4 +- tests/ui/expect_fun_call.fixed | 15 + tests/ui/expect_fun_call.rs | 15 + tests/ui/expect_fun_call.stderr | 28 +- tests/ui/explicit_auto_deref.fixed | 46 ++ tests/ui/explicit_auto_deref.rs | 46 ++ tests/ui/explicit_auto_deref.stderr | 90 ++-- tests/ui/explicit_counter_loop.rs | 32 +- tests/ui/explicit_counter_loop.stderr | 18 +- tests/ui/explicit_deref_methods.fixed | 12 + tests/ui/explicit_deref_methods.rs | 12 + tests/ui/explicit_deref_methods.stderr | 22 +- tests/ui/explicit_into_iter_loop.fixed | 6 + tests/ui/explicit_into_iter_loop.rs | 6 + tests/ui/explicit_into_iter_loop.stderr | 10 +- tests/ui/explicit_iter_loop.fixed | 18 + tests/ui/explicit_iter_loop.rs | 18 + tests/ui/explicit_iter_loop.stderr | 34 +- tests/ui/explicit_write.fixed | 13 + tests/ui/explicit_write.rs | 13 + tests/ui/explicit_write.stderr | 24 +- tests/ui/extend_with_drain.fixed | 4 + tests/ui/extend_with_drain.rs | 4 + tests/ui/extend_with_drain.stderr | 6 +- tests/ui/extra_unused_lifetimes.rs | 7 + tests/ui/extra_unused_lifetimes.stderr | 12 +- tests/ui/extra_unused_type_parameters.fixed | 8 + tests/ui/extra_unused_type_parameters.rs | 8 + tests/ui/extra_unused_type_parameters.stderr | 14 +- .../extra_unused_type_parameters_unfixable.rs | 9 +- ...ra_unused_type_parameters_unfixable.stderr | 4 +- tests/ui/fallible_impl_from.rs | 12 +- tests/ui/fallible_impl_from.stderr | 24 +- tests/ui/field_reassign_with_default.rs | 11 + tests/ui/field_reassign_with_default.stderr | 58 +- tests/ui/field_scoped_visibility_modifiers.rs | 3 + .../field_scoped_visibility_modifiers.stderr | 4 +- tests/ui/filetype_is_file.rs | 9 +- tests/ui/filetype_is_file.stderr | 4 +- tests/ui/filter_map_bool_then.fixed | 10 + tests/ui/filter_map_bool_then.rs | 10 + tests/ui/filter_map_bool_then.stderr | 18 +- tests/ui/filter_map_identity.fixed | 68 ++- tests/ui/filter_map_identity.rs | 66 ++- tests/ui/filter_map_identity.stderr | 112 ++-- tests/ui/filter_map_next.rs | 5 +- tests/ui/filter_map_next.stderr | 3 - tests/ui/filter_map_next_fixable.fixed | 2 + tests/ui/filter_map_next_fixable.rs | 2 + tests/ui/filter_map_next_fixable.stderr | 2 +- tests/ui/find_map.rs | 2 + tests/ui/flat_map_identity.fixed | 3 + tests/ui/flat_map_identity.rs | 3 + tests/ui/flat_map_identity.stderr | 4 +- tests/ui/flat_map_option.fixed | 2 + tests/ui/flat_map_option.rs | 2 + tests/ui/flat_map_option.stderr | 2 +- tests/ui/float_arithmetic.rs | 53 +- tests/ui/float_arithmetic.stderr | 32 +- tests/ui/float_cmp.rs | 18 +- tests/ui/float_cmp.stderr | 10 +- tests/ui/float_cmp_const.rs | 24 +- tests/ui/float_cmp_const.stderr | 14 +- tests/ui/float_equality_without_abs.rs | 35 +- tests/ui/float_equality_without_abs.stderr | 20 +- tests/ui/floating_point_abs.fixed | 8 + tests/ui/floating_point_abs.rs | 8 + tests/ui/floating_point_abs.stderr | 14 +- tests/ui/floating_point_arithmetic_nostd.rs | 2 + tests/ui/floating_point_exp.fixed | 5 + tests/ui/floating_point_exp.rs | 5 + tests/ui/floating_point_exp.stderr | 8 +- tests/ui/floating_point_hypot.fixed | 3 + tests/ui/floating_point_hypot.rs | 3 + tests/ui/floating_point_hypot.stderr | 4 +- tests/ui/floating_point_log.fixed | 29 + tests/ui/floating_point_log.rs | 29 + tests/ui/floating_point_log.stderr | 144 ++--- tests/ui/floating_point_logbase.fixed | 5 + tests/ui/floating_point_logbase.rs | 5 + tests/ui/floating_point_logbase.stderr | 8 +- tests/ui/floating_point_mul_add.fixed | 13 + tests/ui/floating_point_mul_add.rs | 13 + tests/ui/floating_point_mul_add.stderr | 24 +- tests/ui/floating_point_powf.fixed | 32 ++ tests/ui/floating_point_powf.rs | 32 ++ tests/ui/floating_point_powf.stderr | 62 +-- tests/ui/floating_point_powi.fixed | 14 + tests/ui/floating_point_powi.rs | 14 + tests/ui/floating_point_powi.stderr | 26 +- tests/ui/floating_point_rad.fixed | 8 + tests/ui/floating_point_rad.rs | 8 + tests/ui/floating_point_rad.stderr | 14 +- tests/ui/fn_to_numeric_cast.64bit.stderr | 44 +- tests/ui/fn_to_numeric_cast.rs | 23 + tests/ui/fn_to_numeric_cast_any.rs | 53 +- tests/ui/fn_to_numeric_cast_any.stderr | 32 +- tests/ui/for_kv_map.fixed | 20 +- tests/ui/for_kv_map.rs | 20 +- tests/ui/for_kv_map.stderr | 10 +- tests/ui/forget_non_drop.rs | 6 +- tests/ui/forget_non_drop.stderr | 4 +- tests/ui/format.fixed | 14 + tests/ui/format.rs | 15 + tests/ui/format.stderr | 29 +- tests/ui/format_args.fixed | 26 + tests/ui/format_args.rs | 26 + tests/ui/format_args.stderr | 50 +- tests/ui/format_args_unfixable.rs | 75 ++- tests/ui/format_args_unfixable.stderr | 50 +- tests/ui/format_collect.rs | 9 +- tests/ui/format_collect.stderr | 16 +- tests/ui/format_push_string.rs | 15 +- tests/ui/format_push_string.stderr | 11 +- tests/ui/formatting.rs | 30 +- tests/ui/formatting.stderr | 10 +- tests/ui/four_forward_slashes.fixed | 6 +- tests/ui/four_forward_slashes.rs | 6 +- tests/ui/four_forward_slashes.stderr | 13 +- .../ui/four_forward_slashes_first_line.fixed | 1 + tests/ui/four_forward_slashes_first_line.rs | 1 + .../ui/four_forward_slashes_first_line.stderr | 1 + tests/ui/from_iter_instead_of_collect.fixed | 15 + tests/ui/from_iter_instead_of_collect.rs | 15 + tests/ui/from_iter_instead_of_collect.stderr | 28 +- tests/ui/from_over_into.fixed | 7 + tests/ui/from_over_into.rs | 7 + tests/ui/from_over_into.stderr | 19 +- tests/ui/from_over_into_unfixable.rs | 12 +- tests/ui/from_over_into_unfixable.stderr | 6 +- tests/ui/from_raw_with_void_ptr.rs | 15 +- tests/ui/from_raw_with_void_ptr.stderr | 16 +- tests/ui/from_str_radix_10.fixed | 26 +- tests/ui/from_str_radix_10.rs | 26 +- tests/ui/from_str_radix_10.stderr | 14 +- tests/ui/functions.rs | 52 +- tests/ui/functions.stderr | 32 +- tests/ui/functions_maxlines.rs | 5 +- tests/ui/functions_maxlines.stderr | 3 - tests/ui/future_not_send.rs | 24 +- tests/ui/future_not_send.stderr | 41 +- tests/ui/get_first.fixed | 15 +- tests/ui/get_first.rs | 15 +- tests/ui/get_first.stderr | 8 +- tests/ui/get_last_with_len.fixed | 6 + tests/ui/get_last_with_len.rs | 6 + tests/ui/get_last_with_len.stderr | 10 +- tests/ui/get_unwrap.fixed | 30 ++ tests/ui/get_unwrap.rs | 30 ++ tests/ui/get_unwrap.stderr | 56 +- tests/ui/identity_op.fixed | 187 ++++--- tests/ui/identity_op.rs | 187 ++++--- tests/ui/identity_op.stderr | 124 ++--- tests/ui/if_let_mutex.rs | 4 + tests/ui/if_not_else.fixed | 10 +- tests/ui/if_not_else.rs | 10 +- tests/ui/if_not_else.stderr | 23 +- tests/ui/if_not_else_bittest.rs | 2 + tests/ui/if_same_then_else.rs | 16 +- tests/ui/if_same_then_else.stderr | 20 +- tests/ui/if_same_then_else2.rs | 18 +- tests/ui/if_same_then_else2.stderr | 20 +- tests/ui/if_then_some_else_none.fixed | 7 +- tests/ui/if_then_some_else_none.rs | 16 +- tests/ui/if_then_some_else_none.stderr | 22 +- tests/ui/ifs_same_cond.rs | 12 +- tests/ui/ifs_same_cond.stderr | 12 +- tests/ui/impl.rs | 12 +- tests/ui/impl.stderr | 13 +- tests/ui/impl_trait_in_params.rs | 12 +- tests/ui/impl_trait_in_params.stderr | 22 +- tests/ui/implicit_clone.fixed | 11 + tests/ui/implicit_clone.rs | 11 + tests/ui/implicit_clone.stderr | 20 +- tests/ui/implicit_hasher.fixed | 9 + tests/ui/implicit_hasher.rs | 9 + tests/ui/implicit_hasher.stderr | 23 +- tests/ui/implicit_return.fixed | 16 + tests/ui/implicit_return.rs | 16 + tests/ui/implicit_return.stderr | 30 +- tests/ui/implicit_saturating_add.rs | 24 + tests/ui/implicit_saturating_add.stderr | 204 ++++---- tests/ui/implicit_saturating_sub.rs | 24 + tests/ui/implicit_saturating_sub.stderr | 110 ++-- tests/ui/implied_bounds_in_impls.fixed | 23 + tests/ui/implied_bounds_in_impls.rs | 23 + tests/ui/implied_bounds_in_impls.stderr | 44 +- tests/ui/incompatible_msrv.rs | 9 +- tests/ui/incompatible_msrv.stderr | 4 +- tests/ui/inconsistent_digit_grouping.fixed | 10 + tests/ui/inconsistent_digit_grouping.rs | 10 + tests/ui/inconsistent_digit_grouping.stderr | 10 +- .../ui/inconsistent_struct_constructor.fixed | 2 + tests/ui/inconsistent_struct_constructor.rs | 2 + .../ui/inconsistent_struct_constructor.stderr | 2 +- .../if_let_slice_binding.fixed | 30 +- .../if_let_slice_binding.rs | 30 +- .../if_let_slice_binding.stderr | 52 +- tests/ui/indexing_slicing_index.rs | 6 + tests/ui/indexing_slicing_index.stderr | 26 +- tests/ui/indexing_slicing_slice.rs | 36 +- tests/ui/indexing_slicing_slice.stderr | 22 +- tests/ui/ineffective_open_options.fixed | 4 +- tests/ui/ineffective_open_options.rs | 6 +- tests/ui/ineffective_open_options.stderr | 12 +- tests/ui/inefficient_to_string.fixed | 6 + tests/ui/inefficient_to_string.rs | 6 + tests/ui/inefficient_to_string.stderr | 10 +- tests/ui/infallible_destructuring_match.rs | 4 + .../ui/infallible_destructuring_match.stderr | 10 +- tests/ui/infinite_iter.rs | 44 +- tests/ui/infinite_iter.stderr | 33 +- tests/ui/infinite_loop.rs | 55 +- tests/ui/infinite_loop.stderr | 36 +- tests/ui/infinite_loops.rs | 39 +- tests/ui/infinite_loops.stderr | 37 +- tests/ui/inherent_to_string.rs | 6 +- tests/ui/inherent_to_string.stderr | 4 +- tests/ui/init_numbered_fields.fixed | 1 + tests/ui/init_numbered_fields.rs | 3 + tests/ui/init_numbered_fields.stderr | 6 +- tests/ui/inline_fn_without_body.fixed | 3 + tests/ui/inline_fn_without_body.rs | 3 + tests/ui/inline_fn_without_body.stderr | 10 +- tests/ui/inspect_for_each.rs | 3 +- tests/ui/inspect_for_each.stderr | 1 + tests/ui/int_plus_one.fixed | 4 + tests/ui/int_plus_one.rs | 4 + tests/ui/int_plus_one.stderr | 6 +- tests/ui/integer_division.rs | 9 +- tests/ui/integer_division.stderr | 4 +- tests/ui/integer_division_remainder_used.rs | 9 + .../ui/integer_division_remainder_used.stderr | 16 +- tests/ui/into_iter_on_ref.fixed | 78 ++- tests/ui/into_iter_on_ref.rs | 78 ++- tests/ui/into_iter_on_ref.stderr | 172 +++--- tests/ui/into_iter_without_iter.rs | 11 +- tests/ui/into_iter_without_iter.stderr | 2 +- tests/ui/invalid_null_ptr_usage.fixed | 22 + tests/ui/invalid_null_ptr_usage.rs | 22 + tests/ui/invalid_null_ptr_usage.stderr | 42 +- tests/ui/invalid_null_ptr_usage_no_std.fixed | 22 + tests/ui/invalid_null_ptr_usage_no_std.rs | 22 + tests/ui/invalid_null_ptr_usage_no_std.stderr | 42 +- tests/ui/invalid_upcast_comparisons.rs | 83 ++- tests/ui/invalid_upcast_comparisons.stderr | 52 +- tests/ui/is_digit_ascii_radix.fixed | 3 + tests/ui/is_digit_ascii_radix.rs | 3 + tests/ui/is_digit_ascii_radix.stderr | 4 +- tests/ui/issue-111399.rs | 2 + tests/ui/issue-7447.rs | 8 +- tests/ui/issue-7447.stderr | 2 +- tests/ui/issue_2356.fixed | 1 + tests/ui/issue_2356.rs | 1 + tests/ui/issue_4266.rs | 11 +- tests/ui/issue_4266.stderr | 4 +- tests/ui/items_after_statement.rs | 9 +- tests/ui/items_after_statement.stderr | 10 +- .../after_proc_macros.rs | 1 + .../imported_module.rs | 1 + .../items_after_test_module/in_submodule.rs | 1 + .../multiple_modules.rs | 2 + .../items_after_test_module/root_module.fixed | 1 + .../ui/items_after_test_module/root_module.rs | 1 + tests/ui/iter_cloned_collect.fixed | 4 + tests/ui/iter_cloned_collect.rs | 5 + tests/ui/iter_cloned_collect.stderr | 9 +- tests/ui/iter_count.fixed | 25 + tests/ui/iter_count.rs | 25 + tests/ui/iter_count.stderr | 48 +- tests/ui/iter_filter_is_ok.fixed | 36 +- tests/ui/iter_filter_is_ok.rs | 36 +- tests/ui/iter_filter_is_ok.stderr | 30 +- tests/ui/iter_filter_is_some.fixed | 30 +- tests/ui/iter_filter_is_some.rs | 30 +- tests/ui/iter_filter_is_some.stderr | 18 +- tests/ui/iter_kv_map.fixed | 58 +- tests/ui/iter_kv_map.rs | 58 +- tests/ui/iter_kv_map.stderr | 142 ++--- tests/ui/iter_next_loop.rs | 1 + tests/ui/iter_next_slice.fixed | 4 + tests/ui/iter_next_slice.rs | 4 + tests/ui/iter_next_slice.stderr | 6 +- tests/ui/iter_not_returning_iterator.rs | 11 +- tests/ui/iter_not_returning_iterator.stderr | 4 +- tests/ui/iter_nth.fixed | 8 + tests/ui/iter_nth.rs | 8 + tests/ui/iter_nth.stderr | 14 +- tests/ui/iter_nth_zero.fixed | 3 + tests/ui/iter_nth_zero.rs | 3 + tests/ui/iter_nth_zero.stderr | 4 +- tests/ui/iter_on_empty_collections.fixed | 7 + tests/ui/iter_on_empty_collections.rs | 7 + tests/ui/iter_on_empty_collections.stderr | 12 +- tests/ui/iter_on_single_items.fixed | 6 + tests/ui/iter_on_single_items.rs | 6 + tests/ui/iter_on_single_items.stderr | 10 +- tests/ui/iter_out_of_bounds.rs | 42 +- tests/ui/iter_out_of_bounds.stderr | 26 +- tests/ui/iter_over_hash_type.rs | 13 + tests/ui/iter_over_hash_type.stderr | 65 ++- tests/ui/iter_overeager_cloned.fixed | 19 + tests/ui/iter_overeager_cloned.rs | 19 + tests/ui/iter_overeager_cloned.stderr | 37 +- tests/ui/iter_skip_next.fixed | 7 + tests/ui/iter_skip_next.rs | 7 + tests/ui/iter_skip_next.stderr | 12 +- tests/ui/iter_skip_next_unfixable.rs | 9 +- tests/ui/iter_skip_next_unfixable.stderr | 8 +- tests/ui/iter_skip_zero.fixed | 5 + tests/ui/iter_skip_zero.rs | 5 + tests/ui/iter_skip_zero.stderr | 8 +- tests/ui/iter_with_drain.fixed | 6 + tests/ui/iter_with_drain.rs | 6 + tests/ui/iter_with_drain.stderr | 10 +- tests/ui/iter_without_into_iter.rs | 14 +- tests/ui/iter_without_into_iter.stderr | 8 +- tests/ui/iterator_step_by_zero.rs | 23 +- tests/ui/iterator_step_by_zero.stderr | 12 +- tests/ui/join_absolute_paths.rs | 12 +- tests/ui/join_absolute_paths.stderr | 6 +- tests/ui/large_const_arrays.fixed | 10 + tests/ui/large_const_arrays.rs | 10 + tests/ui/large_const_arrays.stderr | 18 +- tests/ui/large_digit_groups.fixed | 5 + tests/ui/large_digit_groups.rs | 5 + tests/ui/large_digit_groups.stderr | 8 +- tests/ui/large_enum_variant.64bit.stderr | 70 ++- tests/ui/large_enum_variant.rs | 20 + tests/ui/large_futures.fixed | 24 +- tests/ui/large_futures.rs | 24 +- tests/ui/large_futures.stderr | 18 +- tests/ui/large_stack_frames.rs | 12 +- tests/ui/large_stack_frames.stderr | 6 +- tests/ui/large_types_passed_by_value.rs | 8 + tests/ui/large_types_passed_by_value.stderr | 14 +- tests/ui/legacy_numeric_constants.fixed | 1 + tests/ui/legacy_numeric_constants.rs | 1 + tests/ui/legacy_numeric_constants.stderr | 32 +- .../ui/legacy_numeric_constants_unfixable.rs | 1 + .../legacy_numeric_constants_unfixable.stderr | 18 +- tests/ui/len_without_is_empty.rs | 50 +- tests/ui/len_without_is_empty.stderr | 42 +- tests/ui/len_zero.fixed | 27 + tests/ui/len_zero.rs | 27 + tests/ui/len_zero.stderr | 52 +- tests/ui/len_zero_ranges.fixed | 2 + tests/ui/len_zero_ranges.rs | 2 + tests/ui/len_zero_ranges.stderr | 2 +- tests/ui/let_and_return.edition2021.fixed | 42 +- tests/ui/let_and_return.edition2021.stderr | 18 +- tests/ui/let_and_return.edition2024.fixed | 42 +- tests/ui/let_and_return.edition2024.stderr | 28 +- tests/ui/let_and_return.rs | 42 +- tests/ui/let_if_seq.rs | 18 +- tests/ui/let_if_seq.stderr | 21 +- tests/ui/let_underscore_future.rs | 9 +- tests/ui/let_underscore_future.stderr | 4 +- tests/ui/let_underscore_must_use.rs | 36 +- tests/ui/let_underscore_must_use.stderr | 22 +- tests/ui/let_underscore_untyped.rs | 5 + tests/ui/let_underscore_untyped.stderr | 16 +- tests/ui/let_unit.fixed | 4 + tests/ui/let_unit.rs | 4 + tests/ui/let_unit.stderr | 14 +- tests/ui/let_with_type_underscore.rs | 5 + tests/ui/let_with_type_underscore.stderr | 16 +- tests/ui/lines_filter_map_ok.fixed | 6 + tests/ui/lines_filter_map_ok.rs | 6 + tests/ui/lines_filter_map_ok.stderr | 20 +- tests/ui/linkedlist.rs | 27 +- tests/ui/linkedlist.stderr | 16 +- .../ui/literal_string_with_formatting_arg.rs | 4 +- .../literal_string_with_formatting_arg.stderr | 2 +- tests/ui/literals.rs | 72 ++- tests/ui/literals.stderr | 38 +- tests/ui/lossy_float_literal.fixed | 11 + tests/ui/lossy_float_literal.rs | 11 + tests/ui/lossy_float_literal.stderr | 20 +- tests/ui/macro_use_imports.fixed | 4 + tests/ui/macro_use_imports.rs | 4 + tests/ui/macro_use_imports.stderr | 6 +- tests/ui/macro_use_imports_expect.rs | 1 + tests/ui/manual_arithmetic_check-2.rs | 18 +- tests/ui/manual_arithmetic_check-2.stderr | 20 +- tests/ui/manual_arithmetic_check.fixed | 14 +- tests/ui/manual_arithmetic_check.rs | 12 +- tests/ui/manual_arithmetic_check.stderr | 6 +- tests/ui/manual_assert.edition2018.stderr | 99 +++- tests/ui/manual_assert.edition2021.stderr | 99 +++- tests/ui/manual_assert.rs | 10 + tests/ui/manual_async_fn.rs | 13 + tests/ui/manual_async_fn.stderr | 24 +- tests/ui/manual_bits.fixed | 29 + tests/ui/manual_bits.rs | 29 + tests/ui/manual_bits.stderr | 56 +- .../manual_c_str_literals.edition2021.fixed | 14 + .../manual_c_str_literals.edition2021.stderr | 26 +- tests/ui/manual_c_str_literals.rs | 14 + tests/ui/manual_clamp.fixed | 90 ++-- tests/ui/manual_clamp.rs | 175 ++++--- tests/ui/manual_clamp.stderr | 129 ++--- tests/ui/manual_div_ceil.fixed | 26 +- tests/ui/manual_div_ceil.rs | 26 +- tests/ui/manual_div_ceil.stderr | 52 +- tests/ui/manual_div_ceil_with_feature.fixed | 23 + tests/ui/manual_div_ceil_with_feature.rs | 23 + tests/ui/manual_div_ceil_with_feature.stderr | 44 +- tests/ui/manual_filter.rs | 15 + tests/ui/manual_filter.stderr | 55 +- tests/ui/manual_filter_map.fixed | 14 + tests/ui/manual_filter_map.rs | 29 + tests/ui/manual_filter_map.stderr | 87 +-- tests/ui/manual_find.rs | 10 +- tests/ui/manual_find.stderr | 8 +- tests/ui/manual_find_fixable.rs | 12 + tests/ui/manual_find_fixable.stderr | 34 +- tests/ui/manual_find_map.fixed | 17 + tests/ui/manual_find_map.rs | 30 ++ tests/ui/manual_find_map.stderr | 87 +-- tests/ui/manual_flatten.rs | 27 +- tests/ui/manual_flatten.stderr | 66 +-- tests/ui/manual_float_methods.rs | 7 + tests/ui/manual_float_methods.stderr | 12 +- tests/ui/manual_hash_one.fixed | 4 + tests/ui/manual_hash_one.rs | 4 + tests/ui/manual_hash_one.stderr | 6 +- tests/ui/manual_ignore_case_cmp.fixed | 49 ++ tests/ui/manual_ignore_case_cmp.rs | 49 ++ tests/ui/manual_ignore_case_cmp.stderr | 494 +++++++++--------- tests/ui/manual_inspect.fixed | 13 + tests/ui/manual_inspect.rs | 13 + tests/ui/manual_inspect.stderr | 47 +- tests/ui/manual_instant_elapsed.fixed | 2 + tests/ui/manual_instant_elapsed.rs | 2 + tests/ui/manual_instant_elapsed.stderr | 2 +- tests/ui/manual_is_ascii_check.fixed | 29 + tests/ui/manual_is_ascii_check.rs | 29 + tests/ui/manual_is_ascii_check.stderr | 56 +- tests/ui/manual_is_power_of_two.fixed | 6 + tests/ui/manual_is_power_of_two.rs | 6 + tests/ui/manual_is_power_of_two.stderr | 10 +- tests/ui/manual_is_variant_and.fixed | 5 + tests/ui/manual_is_variant_and.rs | 8 + tests/ui/manual_is_variant_and.stderr | 22 +- tests/ui/manual_let_else.rs | 89 +++- tests/ui/manual_let_else.stderr | 96 ++-- tests/ui/manual_let_else_match.rs | 32 +- tests/ui/manual_let_else_match.stderr | 31 +- tests/ui/manual_let_else_question_mark.fixed | 5 + tests/ui/manual_let_else_question_mark.rs | 7 + tests/ui/manual_let_else_question_mark.stderr | 14 +- tests/ui/manual_main_separator_str.fixed | 4 + tests/ui/manual_main_separator_str.rs | 4 + tests/ui/manual_main_separator_str.stderr | 6 +- tests/ui/manual_map_option.rs | 20 + tests/ui/manual_map_option.stderr | 58 +- tests/ui/manual_map_option_2.fixed | 2 - tests/ui/manual_map_option_2.rs | 9 +- tests/ui/manual_map_option_2.stderr | 25 +- tests/ui/manual_memcpy/with_loop_counters.rs | 35 +- .../manual_memcpy/with_loop_counters.stderr | 37 +- .../ui/manual_memcpy/without_loop_counters.rs | 56 +- .../without_loop_counters.stderr | 55 +- tests/ui/manual_next_back.fixed | 2 + tests/ui/manual_next_back.rs | 2 + tests/ui/manual_next_back.stderr | 2 +- tests/ui/manual_non_exhaustive_enum.rs | 3 +- tests/ui/manual_non_exhaustive_enum.stderr | 3 +- tests/ui/manual_ok_err.rs | 24 +- tests/ui/manual_ok_err.stderr | 22 +- tests/ui/manual_ok_or.fixed | 3 + tests/ui/manual_ok_or.rs | 4 + tests/ui/manual_ok_or.stderr | 10 +- tests/ui/manual_option_as_slice.fixed | 9 +- tests/ui/manual_option_as_slice.rs | 11 +- tests/ui/manual_option_as_slice.stderr | 14 +- tests/ui/manual_pattern_char_comparison.fixed | 10 + tests/ui/manual_pattern_char_comparison.rs | 10 + .../ui/manual_pattern_char_comparison.stderr | 18 +- tests/ui/manual_range_patterns.fixed | 19 + tests/ui/manual_range_patterns.rs | 19 + tests/ui/manual_range_patterns.stderr | 36 +- tests/ui/manual_rem_euclid.fixed | 10 + tests/ui/manual_rem_euclid.rs | 10 + tests/ui/manual_rem_euclid.stderr | 18 +- tests/ui/manual_repeat_n.fixed | 5 + tests/ui/manual_repeat_n.rs | 5 + tests/ui/manual_repeat_n.stderr | 8 +- tests/ui/manual_retain.fixed | 36 ++ tests/ui/manual_retain.rs | 38 ++ tests/ui/manual_retain.stderr | 76 +-- tests/ui/manual_rotate.fixed | 11 + tests/ui/manual_rotate.rs | 11 + tests/ui/manual_rotate.stderr | 20 +- tests/ui/manual_saturating_arithmetic.fixed | 19 + tests/ui/manual_saturating_arithmetic.rs | 24 + tests/ui/manual_saturating_arithmetic.stderr | 51 +- tests/ui/manual_slice_fill.rs | 4 + tests/ui/manual_slice_fill.stderr | 10 +- tests/ui/manual_slice_size_calculation.fixed | 9 + tests/ui/manual_slice_size_calculation.rs | 9 + tests/ui/manual_slice_size_calculation.stderr | 16 +- tests/ui/manual_split_once.fixed | 19 + tests/ui/manual_split_once.rs | 19 + tests/ui/manual_split_once.stderr | 54 +- tests/ui/manual_str_repeat.fixed | 10 + tests/ui/manual_str_repeat.rs | 10 + tests/ui/manual_str_repeat.stderr | 18 +- tests/ui/manual_string_new.fixed | 9 + tests/ui/manual_string_new.rs | 9 + tests/ui/manual_string_new.stderr | 16 +- tests/ui/manual_strip.rs | 24 +- tests/ui/manual_strip.stderr | 32 +- tests/ui/manual_swap_auto_fix.rs | 12 +- tests/ui/manual_swap_auto_fix.stderr | 22 +- tests/ui/manual_try_fold.rs | 4 + tests/ui/manual_try_fold.stderr | 6 +- tests/ui/manual_unwrap_or.rs | 16 + tests/ui/manual_unwrap_or.stderr | 48 +- tests/ui/manual_unwrap_or_default.rs | 22 +- tests/ui/manual_unwrap_or_default.stderr | 22 +- .../ui/manual_unwrap_or_default_unfixable.rs | 4 + .../manual_unwrap_or_default_unfixable.stderr | 7 +- tests/ui/manual_while_let_some.fixed | 7 + tests/ui/manual_while_let_some.rs | 7 + tests/ui/manual_while_let_some.stderr | 12 +- tests/ui/many_single_char_names.rs | 17 +- tests/ui/many_single_char_names.stderr | 4 +- tests/ui/map_all_any_identity.fixed | 2 + tests/ui/map_all_any_identity.rs | 2 + tests/ui/map_all_any_identity.stderr | 2 +- tests/ui/map_clone.fixed | 49 +- tests/ui/map_clone.rs | 49 +- tests/ui/map_clone.stderr | 28 +- tests/ui/map_collect_result_unit.fixed | 2 + tests/ui/map_collect_result_unit.rs | 2 + tests/ui/map_collect_result_unit.stderr | 2 +- tests/ui/map_err.rs | 3 +- tests/ui/map_flatten.rs | 17 +- tests/ui/map_flatten.stderr | 23 +- tests/ui/map_flatten_fixable.fixed | 9 + tests/ui/map_flatten_fixable.rs | 9 + tests/ui/map_flatten_fixable.stderr | 20 +- tests/ui/map_identity.fixed | 11 + tests/ui/map_identity.rs | 13 + tests/ui/map_identity.stderr | 26 +- tests/ui/map_unit_fn.rs | 2 + tests/ui/map_unwrap_or.rs | 15 + tests/ui/map_unwrap_or.stderr | 40 +- tests/ui/map_unwrap_or_fixable.rs | 2 + tests/ui/map_unwrap_or_fixable.stderr | 6 +- ...map_with_unused_argument_over_ranges.fixed | 18 + .../map_with_unused_argument_over_ranges.rs | 18 + ...ap_with_unused_argument_over_ranges.stderr | 36 +- ...th_unused_argument_over_ranges_nostd.fixed | 1 + ..._with_unused_argument_over_ranges_nostd.rs | 1 + tests/ui/match_as_ref.rs | 3 + tests/ui/match_as_ref.stderr | 7 +- tests/ui/match_bool.rs | 39 +- tests/ui/match_bool.stderr | 50 +- tests/ui/match_expr_like_matches_macro.fixed | 14 + tests/ui/match_expr_like_matches_macro.rs | 14 + tests/ui/match_expr_like_matches_macro.stderr | 26 +- tests/ui/match_on_vec_items.rs | 26 +- tests/ui/match_on_vec_items.stderr | 14 +- tests/ui/match_overlapping_arm.rs | 24 +- tests/ui/match_overlapping_arm.stderr | 30 +- tests/ui/match_ref_pats.fixed | 5 + tests/ui/match_ref_pats.rs | 5 + tests/ui/match_ref_pats.stderr | 14 +- tests/ui/match_result_ok.fixed | 3 + tests/ui/match_result_ok.rs | 3 + tests/ui/match_result_ok.stderr | 4 +- tests/ui/match_same_arms.rs | 24 +- tests/ui/match_same_arms.stderr | 65 +-- tests/ui/match_same_arms2.fixed | 40 +- tests/ui/match_same_arms2.rs | 40 +- tests/ui/match_same_arms2.stderr | 93 ++-- tests/ui/match_same_arms_non_exhaustive.fixed | 6 +- tests/ui/match_same_arms_non_exhaustive.rs | 6 +- .../ui/match_same_arms_non_exhaustive.stderr | 6 +- tests/ui/match_single_binding.rs | 24 + tests/ui/match_single_binding.stderr | 72 ++- tests/ui/match_single_binding2.fixed | 1 + tests/ui/match_single_binding2.rs | 4 + tests/ui/match_single_binding2.stderr | 11 +- tests/ui/match_str_case_mismatch.fixed | 7 + tests/ui/match_str_case_mismatch.rs | 7 + tests/ui/match_str_case_mismatch.stderr | 12 +- tests/ui/match_wild_err_arm.rs | 20 +- tests/ui/match_wild_err_arm.stderr | 6 +- .../match_wildcard_for_single_variants.fixed | 10 + .../ui/match_wildcard_for_single_variants.rs | 10 + .../match_wildcard_for_single_variants.stderr | 18 +- tests/ui/mem_forget.rs | 20 +- tests/ui/mem_forget.stderr | 6 +- tests/ui/mem_replace.fixed | 26 + tests/ui/mem_replace.rs | 26 + tests/ui/mem_replace.stderr | 50 +- tests/ui/mem_replace_macro.rs | 1 + tests/ui/mem_replace_no_std.fixed | 7 + tests/ui/mem_replace_no_std.rs | 7 + tests/ui/mem_replace_no_std.stderr | 12 +- tests/ui/methods.rs | 2 + tests/ui/methods.stderr | 4 +- tests/ui/methods_fixable.fixed | 1 + tests/ui/methods_fixable.rs | 1 + tests/ui/methods_unfixable.rs | 3 +- tests/ui/min_ident_chars.rs | 32 ++ tests/ui/min_ident_chars.stderr | 62 +-- tests/ui/min_max.rs | 41 +- tests/ui/min_max.stderr | 24 +- tests/ui/min_rust_version_attr.rs | 18 +- tests/ui/min_rust_version_attr.stderr | 10 +- tests/ui/mismatching_type_param_order.rs | 30 +- tests/ui/mismatching_type_param_order.stderr | 16 +- tests/ui/misnamed_getters.fixed | 56 +- tests/ui/misnamed_getters.rs | 56 +- tests/ui/misnamed_getters.stderr | 54 +- tests/ui/missing_asserts_for_indexing.fixed | 33 +- tests/ui/missing_asserts_for_indexing.rs | 33 +- tests/ui/missing_asserts_for_indexing.stderr | 86 +-- .../missing_asserts_for_indexing_unfixable.rs | 18 +- ...sing_asserts_for_indexing_unfixable.stderr | 47 +- .../ui/missing_const_for_fn/cant_be_const.rs | 1 + .../missing_const_for_fn/could_be_const.fixed | 47 +- .../ui/missing_const_for_fn/could_be_const.rs | 47 +- .../could_be_const.stderr | 50 +- tests/ui/missing_const_for_thread_local.fixed | 18 +- tests/ui/missing_const_for_thread_local.rs | 18 +- .../ui/missing_const_for_thread_local.stderr | 10 +- tests/ui/missing_doc.rs | 14 + tests/ui/missing_doc.stderr | 32 +- tests/ui/missing_doc_crate.rs | 2 + tests/ui/missing_doc_crate_missing.rs | 5 +- tests/ui/missing_doc_impl.rs | 7 + tests/ui/missing_doc_impl.stderr | 17 +- tests/ui/missing_fields_in_debug.rs | 9 +- tests/ui/missing_fields_in_debug.stderr | 20 +- tests/ui/missing_inline.rs | 20 +- tests/ui/missing_inline.stderr | 10 +- tests/ui/missing_inline_executable.rs | 2 + tests/ui/missing_inline_proc_macro.rs | 2 + tests/ui/missing_panics_doc.rs | 12 + tests/ui/missing_panics_doc.stderr | 46 +- tests/ui/missing_spin_loop.fixed | 6 + tests/ui/missing_spin_loop.rs | 6 + tests/ui/missing_spin_loop.stderr | 10 +- tests/ui/missing_spin_loop_no_std.fixed | 1 + tests/ui/missing_spin_loop_no_std.rs | 1 + tests/ui/missing_trait_methods.rs | 9 +- tests/ui/missing_trait_methods.stderr | 52 +- tests/ui/mistyped_literal_suffix.fixed | 16 + tests/ui/mistyped_literal_suffix.rs | 16 + tests/ui/mistyped_literal_suffix.stderr | 30 +- .../auxiliary/submodule.rs | 3 +- .../ui/mixed_attributes_style/global_allow.rs | 2 + .../mixed_attributes_style/mod_declaration.rs | 3 + .../mod_declaration.stderr | 21 +- tests/ui/mixed_read_write_in_expression.rs | 12 +- .../ui/mixed_read_write_in_expression.stderr | 12 +- tests/ui/module_inception.rs | 14 +- tests/ui/module_inception.stderr | 13 +- tests/ui/module_name_repetitions.rs | 20 +- tests/ui/module_name_repetitions.stderr | 10 +- tests/ui/modulo_arithmetic_float.rs | 80 +-- tests/ui/modulo_arithmetic_float.stderr | 30 +- tests/ui/modulo_arithmetic_integral.rs | 85 +-- tests/ui/modulo_arithmetic_integral.stderr | 32 +- tests/ui/modulo_arithmetic_integral_const.rs | 85 +-- .../modulo_arithmetic_integral_const.stderr | 32 +- tests/ui/modulo_one.rs | 23 +- tests/ui/modulo_one.stderr | 28 +- tests/ui/multi_assignments.rs | 20 +- tests/ui/multi_assignments.stderr | 10 +- tests/ui/multiple_bound_locations.rs | 18 +- tests/ui/multiple_bound_locations.stderr | 10 +- tests/ui/multiple_unsafe_ops_per_block.rs | 8 + tests/ui/multiple_unsafe_ops_per_block.stderr | 64 ++- tests/ui/must_use_candidates.fixed | 5 + tests/ui/must_use_candidates.rs | 5 + tests/ui/must_use_candidates.stderr | 8 +- tests/ui/must_use_unit.fixed | 5 + tests/ui/must_use_unit.rs | 5 + tests/ui/must_use_unit.stderr | 8 +- tests/ui/mut_from_ref.rs | 18 +- tests/ui/mut_from_ref.stderr | 20 +- tests/ui/mut_key.rs | 47 +- tests/ui/mut_key.stderr | 26 +- tests/ui/mut_mut.rs | 9 + tests/ui/mut_mut.stderr | 16 +- tests/ui/mut_mutex_lock.fixed | 2 + tests/ui/mut_mutex_lock.rs | 2 + tests/ui/mut_mutex_lock.stderr | 2 +- tests/ui/mut_range_bound.rs | 35 +- tests/ui/mut_range_bound.stderr | 12 +- tests/ui/mut_reference.rs | 11 +- tests/ui/mut_reference.stderr | 4 +- tests/ui/mutex_atomic.rs | 37 +- tests/ui/mutex_atomic.stderr | 20 +- tests/ui/needless_arbitrary_self_type.fixed | 8 + tests/ui/needless_arbitrary_self_type.rs | 8 + tests/ui/needless_arbitrary_self_type.stderr | 14 +- ...edless_arbitrary_self_type_unfixable.fixed | 1 + .../needless_arbitrary_self_type_unfixable.rs | 1 + tests/ui/needless_as_bytes.fixed | 16 +- tests/ui/needless_as_bytes.rs | 16 +- tests/ui/needless_as_bytes.stderr | 14 +- tests/ui/needless_bitwise_bool.fixed | 1 + tests/ui/needless_bitwise_bool.rs | 1 + tests/ui/needless_bool/fixable.fixed | 24 + tests/ui/needless_bool/fixable.rs | 24 + tests/ui/needless_bool/fixable.stderr | 46 +- tests/ui/needless_bool/simple.rs | 4 + tests/ui/needless_bool/simple.stderr | 45 -- tests/ui/needless_bool_assign.fixed | 4 + tests/ui/needless_bool_assign.rs | 4 + tests/ui/needless_bool_assign.stderr | 55 -- tests/ui/needless_borrow.fixed | 30 +- tests/ui/needless_borrow.rs | 30 +- tests/ui/needless_borrow.stderr | 54 +- tests/ui/needless_borrow_pat.fixed | 38 +- tests/ui/needless_borrow_pat.rs | 38 +- tests/ui/needless_borrow_pat.stderr | 26 +- tests/ui/needless_borrowed_ref.fixed | 17 + tests/ui/needless_borrowed_ref.rs | 17 + tests/ui/needless_borrowed_ref.stderr | 34 +- .../needless_borrows_for_generic_args.fixed | 11 + tests/ui/needless_borrows_for_generic_args.rs | 11 + .../needless_borrows_for_generic_args.stderr | 20 +- tests/ui/needless_character_iteration.fixed | 21 +- tests/ui/needless_character_iteration.rs | 27 +- tests/ui/needless_character_iteration.stderr | 18 +- tests/ui/needless_collect.fixed | 19 + tests/ui/needless_collect.rs | 19 + tests/ui/needless_collect.stderr | 36 +- tests/ui/needless_collect_indirect.rs | 49 +- tests/ui/needless_collect_indirect.stderr | 87 +-- tests/ui/needless_continue.rs | 35 +- tests/ui/needless_continue.stderr | 42 +- tests/ui/needless_doc_main.rs | 1 - tests/ui/needless_doc_main.stderr | 7 +- tests/ui/needless_else.fixed | 1 + tests/ui/needless_else.rs | 1 + tests/ui/needless_else.stderr | 13 - tests/ui/needless_for_each_fixable.fixed | 8 + tests/ui/needless_for_each_fixable.rs | 8 + tests/ui/needless_for_each_fixable.stderr | 30 +- tests/ui/needless_for_each_unfixable.rs | 5 +- tests/ui/needless_for_each_unfixable.stderr | 6 +- tests/ui/needless_if.fixed | 7 + tests/ui/needless_if.rs | 7 + tests/ui/needless_if.stderr | 16 +- tests/ui/needless_late_init.fixed | 16 + tests/ui/needless_late_init.rs | 16 + tests/ui/needless_late_init.stderr | 87 +-- tests/ui/needless_lifetimes.fixed | 58 +- tests/ui/needless_lifetimes.rs | 58 +- tests/ui/needless_lifetimes.stderr | 131 +++-- tests/ui/needless_match.fixed | 3 + tests/ui/needless_match.rs | 14 + tests/ui/needless_match.stderr | 42 +- tests/ui/needless_maybe_sized.fixed | 20 + tests/ui/needless_maybe_sized.rs | 20 + tests/ui/needless_maybe_sized.stderr | 76 +-- tests/ui/needless_option_as_deref.fixed | 3 + tests/ui/needless_option_as_deref.rs | 3 + tests/ui/needless_option_as_deref.stderr | 4 +- tests/ui/needless_option_take.fixed | 27 +- tests/ui/needless_option_take.rs | 27 +- tests/ui/needless_option_take.stderr | 16 +- .../needless_parens_on_range_literals.fixed | 6 + tests/ui/needless_parens_on_range_literals.rs | 6 + .../needless_parens_on_range_literals.stderr | 8 +- tests/ui/needless_pass_by_ref_mut.rs | 82 ++- tests/ui/needless_pass_by_ref_mut.stderr | 66 +-- tests/ui/needless_pass_by_ref_mut2.fixed | 6 +- tests/ui/needless_pass_by_ref_mut2.rs | 6 +- tests/ui/needless_pass_by_ref_mut2.stderr | 2 +- tests/ui/needless_pass_by_value.rs | 68 ++- tests/ui/needless_pass_by_value.stderr | 50 +- tests/ui/needless_pass_by_value_proc_macro.rs | 2 + tests/ui/needless_pub_self.fixed | 3 + tests/ui/needless_pub_self.rs | 3 + tests/ui/needless_pub_self.stderr | 4 +- tests/ui/needless_question_mark.fixed | 15 + tests/ui/needless_question_mark.rs | 15 + tests/ui/needless_question_mark.stderr | 28 +- tests/ui/needless_range_loop.rs | 44 +- tests/ui/needless_range_loop.stderr | 26 +- tests/ui/needless_range_loop2.rs | 26 +- tests/ui/needless_range_loop2.stderr | 14 +- tests/ui/needless_raw_string.fixed | 10 + tests/ui/needless_raw_string.rs | 10 + tests/ui/needless_raw_string.stderr | 23 +- tests/ui/needless_raw_string_hashes.fixed | 18 + tests/ui/needless_raw_string_hashes.rs | 18 + tests/ui/needless_raw_string_hashes.stderr | 39 +- tests/ui/needless_return.fixed | 54 ++ tests/ui/needless_return.rs | 55 +- tests/ui/needless_return.stderr | 124 ++--- .../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 | 13 + tests/ui/needless_splitn.rs | 13 + tests/ui/needless_splitn.stderr | 24 +- tests/ui/needless_update.rs | 5 +- tests/ui/neg_cmp_op_on_partial_ord.rs | 14 +- tests/ui/neg_cmp_op_on_partial_ord.stderr | 6 +- tests/ui/neg_multiply.fixed | 8 + tests/ui/neg_multiply.rs | 8 + tests/ui/neg_multiply.stderr | 14 +- tests/ui/never_loop.rs | 52 +- tests/ui/never_loop.stderr | 63 +-- tests/ui/new_ret_no_self.rs | 38 +- tests/ui/new_ret_no_self.stderr | 64 ++- tests/ui/new_ret_no_self_overflow.rs | 1 + tests/ui/new_without_default.fixed | 25 +- tests/ui/new_without_default.rs | 25 +- tests/ui/new_without_default.stderr | 28 +- tests/ui/no_effect.rs | 83 ++- tests/ui/no_effect.stderr | 52 +- tests/ui/no_effect_async_fn.rs | 12 +- tests/ui/no_effect_async_fn.stderr | 6 +- tests/ui/no_effect_replace.rs | 26 +- tests/ui/no_effect_replace.stderr | 14 +- tests/ui/no_effect_return.rs | 29 +- tests/ui/no_effect_return.stderr | 16 +- tests/ui/no_mangle_with_rust_abi.rs | 12 +- tests/ui/no_mangle_with_rust_abi.stderr | 10 +- tests/ui/no_mangle_with_rust_abi_2021.rs | 11 +- tests/ui/no_mangle_with_rust_abi_2021.stderr | 8 +- tests/ui/non_canonical_clone_impl.rs | 4 + tests/ui/non_canonical_clone_impl.stderr | 10 +- tests/ui/non_canonical_partial_ord_impl.fixed | 2 + tests/ui/non_canonical_partial_ord_impl.rs | 2 + .../ui/non_canonical_partial_ord_impl.stderr | 4 +- ...n_canonical_partial_ord_impl_fully_qual.rs | 2 + ...nonical_partial_ord_impl_fully_qual.stderr | 4 +- tests/ui/non_expressive_names.rs | 18 +- tests/ui/non_expressive_names.stderr | 36 +- tests/ui/non_minimal_cfg.fixed | 4 + tests/ui/non_minimal_cfg.rs | 4 + tests/ui/non_minimal_cfg.stderr | 6 +- tests/ui/non_minimal_cfg2.rs | 1 + tests/ui/non_minimal_cfg2.stderr | 2 +- tests/ui/non_octal_unix_permissions.fixed | 4 + tests/ui/non_octal_unix_permissions.rs | 4 + tests/ui/non_octal_unix_permissions.stderr | 6 +- .../non_std_lazy_static_no_std.rs | 1 + .../non_std_lazy_static_other_once_cell.rs | 1 + tests/ui/non_zero_suggestions.fixed | 18 +- tests/ui/non_zero_suggestions.rs | 18 +- tests/ui/non_zero_suggestions.stderr | 10 +- tests/ui/non_zero_suggestions_unfixable.rs | 9 +- .../ui/non_zero_suggestions_unfixable.stderr | 4 +- tests/ui/nonminimal_bool.rs | 78 ++- tests/ui/nonminimal_bool.stderr | 122 ++--- tests/ui/nonminimal_bool_methods.fixed | 93 +++- tests/ui/nonminimal_bool_methods.rs | 93 +++- tests/ui/nonminimal_bool_methods.stderr | 192 +++---- tests/ui/nonminimal_bool_methods_unfixable.rs | 4 +- .../nonminimal_bool_methods_unfixable.stderr | 12 +- tests/ui/obfuscated_if_else.fixed | 38 +- tests/ui/obfuscated_if_else.rs | 38 +- tests/ui/obfuscated_if_else.stderr | 26 +- tests/ui/octal_escapes.rs | 25 +- tests/ui/octal_escapes.stderr | 106 ++-- tests/ui/ok_expect.rs | 15 +- tests/ui/ok_expect.stderr | 8 +- tests/ui/only_used_in_recursion.rs | 48 +- tests/ui/only_used_in_recursion.stderr | 62 +-- tests/ui/only_used_in_recursion2.rs | 15 +- tests/ui/only_used_in_recursion2.stderr | 18 +- tests/ui/op_ref.fixed | 14 +- tests/ui/op_ref.rs | 14 +- tests/ui/op_ref.stderr | 6 +- tests/ui/open_options.rs | 26 +- tests/ui/open_options.stderr | 14 +- tests/ui/open_options_fixable.fixed | 3 +- tests/ui/open_options_fixable.rs | 3 +- tests/ui/option_as_ref_cloned.fixed | 3 + tests/ui/option_as_ref_cloned.rs | 3 + tests/ui/option_as_ref_cloned.stderr | 4 +- tests/ui/option_as_ref_deref.fixed | 17 + tests/ui/option_as_ref_deref.rs | 18 + tests/ui/option_as_ref_deref.stderr | 35 +- tests/ui/option_env_unwrap.rs | 7 + tests/ui/option_env_unwrap.stderr | 12 +- tests/ui/option_filter_map.fixed | 18 +- tests/ui/option_filter_map.rs | 24 +- tests/ui/option_filter_map.stderr | 18 +- tests/ui/option_if_let_else.fixed | 13 + tests/ui/option_if_let_else.rs | 25 + tests/ui/option_if_let_else.stderr | 80 ++- tests/ui/option_map_or_none.fixed | 4 + tests/ui/option_map_or_none.rs | 5 + tests/ui/option_map_or_none.stderr | 11 +- tests/ui/option_map_unit_fn_fixable.fixed | 19 + tests/ui/option_map_unit_fn_fixable.rs | 19 + tests/ui/option_map_unit_fn_fixable.stderr | 36 +- tests/ui/option_map_unit_fn_unfixable.rs | 4 + tests/ui/option_map_unit_fn_unfixable.stderr | 6 +- tests/ui/or_fun_call.fixed | 50 +- tests/ui/or_fun_call.rs | 50 +- tests/ui/or_fun_call.stderr | 76 +-- tests/ui/or_then_unwrap.fixed | 3 + tests/ui/or_then_unwrap.rs | 3 + tests/ui/or_then_unwrap.stderr | 4 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 8 +- .../out_of_bounds_indexing/issue-3102.stderr | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 20 +- tests/ui/out_of_bounds_indexing/simple.stderr | 10 +- tests/ui/overly_complex_bool_expr.fixed | 15 +- tests/ui/overly_complex_bool_expr.rs | 15 +- tests/ui/overly_complex_bool_expr.stderr | 16 +- tests/ui/panic_in_result_fn.rs | 7 +- tests/ui/panic_in_result_fn.stderr | 19 +- tests/ui/panic_in_result_fn_assertions.rs | 9 +- tests/ui/panic_in_result_fn_assertions.stderr | 22 +- .../ui/panic_in_result_fn_debug_assertions.rs | 2 + tests/ui/panicking_macros.rs | 56 +- tests/ui/panicking_macros.stderr | 30 +- tests/ui/panicking_overflow_checks.rs | 18 +- tests/ui/panicking_overflow_checks.stderr | 36 +- tests/ui/partial_pub_fields.rs | 12 +- tests/ui/partial_pub_fields.stderr | 6 +- tests/ui/partialeq_ne_impl.rs | 5 +- tests/ui/partialeq_ne_impl.stderr | 4 +- tests/ui/partialeq_to_none.fixed | 15 + tests/ui/partialeq_to_none.rs | 15 + 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_ends_with_ext.fixed | 6 +- tests/ui/path_ends_with_ext.rs | 6 +- tests/ui/path_ends_with_ext.stderr | 2 +- tests/ui/pathbuf_init_then_push.fixed | 8 +- tests/ui/pathbuf_init_then_push.rs | 12 +- tests/ui/pathbuf_init_then_push.stderr | 20 +- tests/ui/pattern_type_mismatch/mutability.rs | 6 +- .../pattern_type_mismatch/mutability.stderr | 2 +- .../pattern_alternatives.rs | 9 +- .../pattern_alternatives.stderr | 4 +- .../pattern_type_mismatch/pattern_structs.rs | 24 +- .../pattern_structs.stderr | 14 +- .../pattern_type_mismatch/pattern_tuples.rs | 30 +- .../pattern_tuples.stderr | 18 +- tests/ui/pattern_type_mismatch/syntax.rs | 25 +- tests/ui/pattern_type_mismatch/syntax.stderr | 16 +- tests/ui/patterns.fixed | 3 + tests/ui/patterns.rs | 3 + tests/ui/patterns.stderr | 4 +- tests/ui/permissions_set_readonly_false.rs | 5 +- tests/ui/pointers_in_nomem_asm_block.rs | 9 +- tests/ui/pointers_in_nomem_asm_block.stderr | 4 +- tests/ui/precedence.fixed | 7 + tests/ui/precedence.rs | 7 + tests/ui/precedence.stderr | 12 +- tests/ui/precedence_bits.fixed | 4 + tests/ui/precedence_bits.rs | 4 + tests/ui/precedence_bits.stderr | 6 +- tests/ui/print.rs | 28 +- tests/ui/print.stderr | 14 +- tests/ui/print_in_format_impl.rs | 23 +- tests/ui/print_in_format_impl.stderr | 12 +- tests/ui/print_literal.fixed | 36 +- tests/ui/print_literal.rs | 36 +- tests/ui/print_literal.stderr | 37 +- tests/ui/print_stderr.rs | 8 +- tests/ui/print_stderr.stderr | 2 +- tests/ui/print_stdout_build_script.rs | 1 + tests/ui/print_with_newline.fixed | 29 +- tests/ui/print_with_newline.rs | 29 +- tests/ui/print_with_newline.stderr | 20 +- tests/ui/println_empty_string.fixed | 4 + tests/ui/println_empty_string.rs | 4 + tests/ui/println_empty_string.stderr | 6 +- tests/ui/ptr_arg.rs | 78 ++- tests/ui/ptr_arg.stderr | 59 ++- tests/ui/ptr_as_ptr.fixed | 33 ++ tests/ui/ptr_as_ptr.rs | 33 ++ tests/ui/ptr_as_ptr.stderr | 82 +-- tests/ui/ptr_cast_constness.fixed | 13 + tests/ui/ptr_cast_constness.rs | 13 + tests/ui/ptr_cast_constness.stderr | 24 +- tests/ui/ptr_eq.fixed | 2 + tests/ui/ptr_eq.rs | 2 + tests/ui/ptr_eq.stderr | 2 +- tests/ui/ptr_eq_no_std.fixed | 2 + tests/ui/ptr_eq_no_std.rs | 2 + tests/ui/ptr_eq_no_std.stderr | 2 +- tests/ui/ptr_offset_with_cast.fixed | 2 + tests/ui/ptr_offset_with_cast.rs | 2 + tests/ui/ptr_offset_with_cast.stderr | 2 +- tests/ui/pub_use.rs | 3 +- tests/ui/pub_with_shorthand.fixed | 4 + tests/ui/pub_with_shorthand.rs | 4 + tests/ui/pub_with_shorthand.stderr | 6 +- tests/ui/pub_without_shorthand.fixed | 3 + tests/ui/pub_without_shorthand.rs | 3 + tests/ui/pub_without_shorthand.stderr | 4 +- tests/ui/question_mark.fixed | 2 + tests/ui/question_mark.rs | 22 + tests/ui/question_mark.stderr | 62 ++- tests/ui/question_mark_used.rs | 3 +- tests/ui/range.fixed | 3 +- tests/ui/range.rs | 3 +- tests/ui/range_contains.fixed | 21 + tests/ui/range_contains.rs | 21 + tests/ui/range_contains.stderr | 40 +- tests/ui/range_plus_minus_one.fixed | 9 + tests/ui/range_plus_minus_one.rs | 9 + tests/ui/range_plus_minus_one.stderr | 16 +- tests/ui/rc_buffer.fixed | 8 + tests/ui/rc_buffer.rs | 8 + tests/ui/rc_buffer.stderr | 14 +- tests/ui/rc_buffer_arc.fixed | 8 + tests/ui/rc_buffer_arc.rs | 8 + tests/ui/rc_buffer_arc.stderr | 14 +- tests/ui/rc_buffer_redefined_string.rs | 2 + tests/ui/rc_clone_in_vec_init/arc.rs | 20 +- tests/ui/rc_clone_in_vec_init/arc.stderr | 12 +- tests/ui/rc_clone_in_vec_init/rc.rs | 20 +- tests/ui/rc_clone_in_vec_init/rc.stderr | 12 +- tests/ui/rc_clone_in_vec_init/weak.rs | 40 +- tests/ui/rc_clone_in_vec_init/weak.stderr | 20 +- tests/ui/rc_mutex.rs | 11 +- tests/ui/rc_mutex.stderr | 4 +- tests/ui/read_line_without_trim.fixed | 7 + tests/ui/read_line_without_trim.rs | 7 + tests/ui/read_line_without_trim.stderr | 24 +- tests/ui/read_zero_byte_vec.rs | 1 + tests/ui/read_zero_byte_vec.stderr | 22 +- tests/ui/readonly_write_lock.fixed | 8 +- tests/ui/readonly_write_lock.rs | 8 +- tests/ui/readonly_write_lock.stderr | 2 +- tests/ui/recursive_format_impl.rs | 32 +- tests/ui/recursive_format_impl.stderr | 18 +- tests/ui/redundant_allocation.rs | 100 ++-- tests/ui/redundant_allocation.stderr | 38 +- tests/ui/redundant_allocation_fixable.fixed | 12 + tests/ui/redundant_allocation_fixable.rs | 12 + tests/ui/redundant_allocation_fixable.stderr | 22 +- tests/ui/redundant_as_str.fixed | 2 + tests/ui/redundant_as_str.rs | 2 + tests/ui/redundant_as_str.stderr | 2 +- tests/ui/redundant_async_block.fixed | 10 + tests/ui/redundant_async_block.rs | 10 + tests/ui/redundant_async_block.stderr | 26 +- tests/ui/redundant_at_rest_pattern.fixed | 6 + tests/ui/redundant_at_rest_pattern.rs | 6 + tests/ui/redundant_at_rest_pattern.stderr | 10 +- tests/ui/redundant_clone.fixed | 15 + tests/ui/redundant_clone.rs | 15 + tests/ui/redundant_clone.stderr | 56 +- tests/ui/redundant_closure_call_early.rs | 8 +- tests/ui/redundant_closure_call_early.stderr | 2 +- tests/ui/redundant_closure_call_fixable.fixed | 17 + tests/ui/redundant_closure_call_fixable.rs | 17 + .../ui/redundant_closure_call_fixable.stderr | 36 +- tests/ui/redundant_closure_call_late.rs | 11 +- tests/ui/redundant_closure_call_late.stderr | 4 +- tests/ui/redundant_else.fixed | 35 +- tests/ui/redundant_else.rs | 21 +- tests/ui/redundant_else.stderr | 40 +- tests/ui/redundant_field_names.fixed | 9 + tests/ui/redundant_field_names.rs | 9 + tests/ui/redundant_field_names.stderr | 16 +- tests/ui/redundant_guards.fixed | 28 + tests/ui/redundant_guards.rs | 28 + tests/ui/redundant_guards.stderr | 58 +- tests/ui/redundant_locals.rs | 14 + tests/ui/redundant_locals.stderr | 108 ++-- ...edundant_pattern_matching_drop_order.fixed | 22 + .../redundant_pattern_matching_drop_order.rs | 22 + ...dundant_pattern_matching_drop_order.stderr | 42 +- ...dundant_pattern_matching_if_let_true.fixed | 7 + .../redundant_pattern_matching_if_let_true.rs | 7 + ...undant_pattern_matching_if_let_true.stderr | 12 +- .../redundant_pattern_matching_ipaddr.fixed | 14 + tests/ui/redundant_pattern_matching_ipaddr.rs | 20 + .../redundant_pattern_matching_ipaddr.stderr | 44 +- .../redundant_pattern_matching_option.fixed | 22 + tests/ui/redundant_pattern_matching_option.rs | 31 ++ .../redundant_pattern_matching_option.stderr | 69 +-- .../ui/redundant_pattern_matching_poll.fixed | 15 + tests/ui/redundant_pattern_matching_poll.rs | 20 + .../ui/redundant_pattern_matching_poll.stderr | 43 +- .../redundant_pattern_matching_result.fixed | 18 + tests/ui/redundant_pattern_matching_result.rs | 28 + .../redundant_pattern_matching_result.stderr | 64 ++- tests/ui/redundant_pub_crate.fixed | 16 + tests/ui/redundant_pub_crate.rs | 16 + tests/ui/redundant_pub_crate.stderr | 30 +- tests/ui/redundant_slicing.fixed | 3 + tests/ui/redundant_slicing.rs | 3 + tests/ui/redundant_slicing.stderr | 4 +- tests/ui/redundant_static_lifetimes.fixed | 18 + tests/ui/redundant_static_lifetimes.rs | 18 + tests/ui/redundant_static_lifetimes.stderr | 34 +- .../ui/redundant_static_lifetimes_multiple.rs | 32 +- ...redundant_static_lifetimes_multiple.stderr | 16 +- tests/ui/redundant_type_annotations.rs | 53 +- tests/ui/redundant_type_annotations.stderr | 32 +- tests/ui/ref_as_ptr.fixed | 44 ++ tests/ui/ref_as_ptr.rs | 44 ++ tests/ui/ref_as_ptr.stderr | 86 +-- tests/ui/ref_binding_to_reference.rs | 23 +- tests/ui/ref_binding_to_reference.stderr | 17 +- tests/ui/ref_option/ref_option.all.fixed | 17 + tests/ui/ref_option/ref_option.all.stderr | 37 +- tests/ui/ref_option/ref_option.private.fixed | 17 + tests/ui/ref_option/ref_option.private.stderr | 24 +- tests/ui/ref_option/ref_option.rs | 17 + .../ref_option/ref_option_traits.all.stderr | 6 +- .../ref_option_traits.private.stderr | 4 +- tests/ui/ref_option/ref_option_traits.rs | 4 + tests/ui/ref_option_ref.rs | 35 +- tests/ui/ref_option_ref.stderr | 20 +- tests/ui/ref_patterns.rs | 9 +- tests/ui/ref_patterns.stderr | 4 +- tests/ui/regex.rs | 7 + tests/ui/regex.stderr | 64 +-- tests/ui/renamed_builtin_attr.fixed | 1 + tests/ui/renamed_builtin_attr.rs | 1 + tests/ui/repeat_once.fixed | 6 + tests/ui/repeat_once.rs | 6 + tests/ui/repeat_once.stderr | 10 +- tests/ui/repeat_vec_with_capacity.fixed | 9 +- tests/ui/repeat_vec_with_capacity.rs | 9 +- tests/ui/repeat_vec_with_capacity.stderr | 4 +- tests/ui/repeat_vec_with_capacity_nostd.fixed | 1 + tests/ui/repeat_vec_with_capacity_nostd.rs | 1 + tests/ui/repl_uninit.rs | 14 +- tests/ui/repl_uninit.stderr | 6 +- tests/ui/repr_packed_without_abi.rs | 2 + tests/ui/repr_packed_without_abi.stderr | 4 +- tests/ui/reserve_after_initialization.rs | 3 + tests/ui/reserve_after_initialization.stderr | 7 +- tests/ui/rest_pat_in_fully_bound_structs.rs | 9 +- .../ui/rest_pat_in_fully_bound_structs.stderr | 4 +- tests/ui/result_filter_map.rs | 12 +- tests/ui/result_filter_map.stderr | 14 +- tests/ui/result_large_err.rs | 36 +- tests/ui/result_large_err.stderr | 22 +- tests/ui/result_map_or_into_option.fixed | 9 +- tests/ui/result_map_or_into_option.rs | 9 +- tests/ui/result_map_or_into_option.stderr | 4 +- tests/ui/result_map_unit_fn_fixable.fixed | 18 + tests/ui/result_map_unit_fn_fixable.rs | 18 + tests/ui/result_map_unit_fn_fixable.stderr | 34 +- tests/ui/result_map_unit_fn_unfixable.rs | 20 +- tests/ui/result_map_unit_fn_unfixable.stderr | 11 +- tests/ui/result_unit_error.rs | 15 +- tests/ui/result_unit_error.stderr | 8 +- tests/ui/result_unit_error_no_std.rs | 1 + tests/ui/return_and_then.fixed | 13 +- tests/ui/return_and_then.rs | 7 + tests/ui/return_and_then.stderr | 22 +- tests/ui/return_self_not_must_use.rs | 9 +- tests/ui/return_self_not_must_use.stderr | 6 +- tests/ui/reversed_empty_ranges_fixable.fixed | 4 + tests/ui/reversed_empty_ranges_fixable.rs | 4 + tests/ui/reversed_empty_ranges_fixable.stderr | 6 +- .../reversed_empty_ranges_loops_fixable.fixed | 6 + .../ui/reversed_empty_ranges_loops_fixable.rs | 6 + ...reversed_empty_ranges_loops_fixable.stderr | 10 +- .../reversed_empty_ranges_loops_unfixable.rs | 8 +- ...versed_empty_ranges_loops_unfixable.stderr | 2 +- tests/ui/reversed_empty_ranges_unfixable.rs | 11 +- .../ui/reversed_empty_ranges_unfixable.stderr | 4 +- tests/ui/same_functions_in_if_condition.rs | 18 +- .../ui/same_functions_in_if_condition.stderr | 20 +- tests/ui/same_item_push.rs | 18 +- tests/ui/same_item_push.stderr | 10 +- tests/ui/same_name_method.rs | 18 +- tests/ui/same_name_method.stderr | 22 +- tests/ui/search_is_some.rs | 8 + tests/ui/search_is_some.stderr | 20 +- tests/ui/search_is_some_fixable_none.fixed | 54 ++ tests/ui/search_is_some_fixable_none.rs | 55 ++ tests/ui/search_is_some_fixable_none.stderr | 113 ++-- tests/ui/search_is_some_fixable_some.fixed | 44 ++ tests/ui/search_is_some_fixable_some.rs | 47 ++ tests/ui/search_is_some_fixable_some.stderr | 95 ++-- tests/ui/seek_from_current.fixed | 1 + tests/ui/seek_from_current.rs | 1 + .../ui/seek_to_start_instead_of_rewind.fixed | 3 + tests/ui/seek_to_start_instead_of_rewind.rs | 3 + .../ui/seek_to_start_instead_of_rewind.stderr | 4 +- tests/ui/self_assignment.rs | 35 +- tests/ui/self_assignment.stderr | 20 +- tests/ui/self_named_constructors.rs | 5 +- tests/ui/self_named_constructors.stderr | 4 +- tests/ui/semicolon_if_nothing_returned.fixed | 5 + tests/ui/semicolon_if_nothing_returned.rs | 5 + tests/ui/semicolon_if_nothing_returned.stderr | 8 +- tests/ui/semicolon_inside_block.fixed | 4 + tests/ui/semicolon_inside_block.rs | 4 + tests/ui/semicolon_inside_block.stderr | 7 +- tests/ui/semicolon_outside_block.fixed | 6 + tests/ui/semicolon_outside_block.rs | 6 + tests/ui/semicolon_outside_block.stderr | 13 +- tests/ui/serde.rs | 3 +- tests/ui/serde.stderr | 4 +- tests/ui/set_contains_or_insert.rs | 14 + tests/ui/set_contains_or_insert.stderr | 40 +- tests/ui/shadow.rs | 26 + tests/ui/shadow.stderr | 216 ++++---- tests/ui/short_circuit_statement.fixed | 21 +- tests/ui/short_circuit_statement.rs | 21 +- tests/ui/short_circuit_statement.stderr | 12 +- tests/ui/should_impl_trait/corner_cases.rs | 2 + tests/ui/should_impl_trait/method_list_1.rs | 45 +- .../ui/should_impl_trait/method_list_1.stderr | 43 +- tests/ui/should_impl_trait/method_list_2.rs | 45 +- .../ui/should_impl_trait/method_list_2.stderr | 43 +- tests/ui/should_panic_without_expect.rs | 1 + tests/ui/significant_drop_in_scrutinee.rs | 87 ++- tests/ui/significant_drop_in_scrutinee.stderr | 68 ++- tests/ui/significant_drop_tightening.fixed | 4 + tests/ui/significant_drop_tightening.rs | 4 + tests/ui/significant_drop_tightening.stderr | 15 +- tests/ui/similar_names.rs | 15 +- tests/ui/similar_names.stderr | 16 +- tests/ui/single_call_fn.rs | 6 + tests/ui/single_call_fn.stderr | 23 +- tests/ui/single_char_add_str.fixed | 21 + tests/ui/single_char_add_str.rs | 21 + tests/ui/single_char_add_str.stderr | 40 +- tests/ui/single_char_lifetime_names.rs | 15 +- tests/ui/single_char_lifetime_names.stderr | 6 +- tests/ui/single_char_pattern.fixed | 35 ++ tests/ui/single_char_pattern.rs | 35 ++ tests/ui/single_char_pattern.stderr | 68 +-- tests/ui/single_component_path_imports.fixed | 2 + tests/ui/single_component_path_imports.rs | 2 + tests/ui/single_component_path_imports.stderr | 2 +- .../ui/single_component_path_imports_macro.rs | 2 + ...gle_component_path_imports_nested_first.rs | 11 +- ...component_path_imports_nested_first.stderr | 4 +- ...ingle_component_path_imports_self_after.rs | 2 + ...ngle_component_path_imports_self_before.rs | 2 + tests/ui/single_element_loop.fixed | 8 + tests/ui/single_element_loop.rs | 8 + tests/ui/single_element_loop.stderr | 23 +- tests/ui/single_match.fixed | 26 + tests/ui/single_match.rs | 26 + tests/ui/single_match.stderr | 282 ---------- tests/ui/single_match_else.fixed | 10 + tests/ui/single_match_else.rs | 10 + tests/ui/single_match_else.stderr | 211 -------- tests/ui/single_option_map.rs | 9 +- tests/ui/single_option_map.stderr | 7 +- tests/ui/single_range_in_vec_init.rs | 10 + tests/ui/single_range_in_vec_init.stderr | 18 +- .../size_of_in_element_count/expressions.rs | 12 +- .../expressions.stderr | 6 +- .../ui/size_of_in_element_count/functions.rs | 57 +- .../size_of_in_element_count/functions.stderr | 36 +- tests/ui/size_of_ref.rs | 9 +- tests/ui/size_of_ref.stderr | 4 +- tests/ui/skip_while_next.rs | 2 + tests/ui/skip_while_next.stderr | 3 +- tests/ui/sliced_string_as_bytes.fixed | 3 + tests/ui/sliced_string_as_bytes.rs | 3 + tests/ui/sliced_string_as_bytes.stderr | 4 +- tests/ui/slow_vector_initialization.rs | 41 +- tests/ui/slow_vector_initialization.stderr | 48 +- tests/ui/stable_sort_primitive.fixed | 7 + tests/ui/stable_sort_primitive.rs | 7 + tests/ui/stable_sort_primitive.stderr | 24 +- tests/ui/starts_ends_with.fixed | 16 + tests/ui/starts_ends_with.rs | 16 + tests/ui/starts_ends_with.stderr | 30 +- tests/ui/std_instead_of_core.fixed | 1 + tests/ui/std_instead_of_core.rs | 1 + tests/ui/str_split.fixed | 10 + tests/ui/str_split.rs | 10 + tests/ui/str_split.stderr | 18 +- tests/ui/str_to_string.fixed | 6 +- tests/ui/str_to_string.rs | 6 +- tests/ui/str_to_string.stderr | 2 +- tests/ui/string_add.rs | 2 + tests/ui/string_add.stderr | 2 +- tests/ui/string_add_assign.fixed | 3 + tests/ui/string_add_assign.rs | 3 + tests/ui/string_add_assign.stderr | 2 +- tests/ui/string_extend.fixed | 4 + tests/ui/string_extend.rs | 4 + tests/ui/string_extend.stderr | 6 +- tests/ui/string_from_utf8_as_bytes.fixed | 1 + tests/ui/string_from_utf8_as_bytes.rs | 1 + tests/ui/string_lit_as_bytes.fixed | 7 + tests/ui/string_lit_as_bytes.rs | 7 + tests/ui/string_lit_as_bytes.stderr | 12 +- tests/ui/string_lit_chars_any.fixed | 5 + tests/ui/string_lit_chars_any.rs | 5 + tests/ui/string_lit_chars_any.stderr | 8 +- tests/ui/string_slice.rs | 14 +- tests/ui/string_slice.stderr | 6 +- tests/ui/string_to_string.rs | 3 +- tests/ui/strlen_on_c_strings.fixed | 7 + tests/ui/strlen_on_c_strings.rs | 7 + tests/ui/strlen_on_c_strings.stderr | 12 +- tests/ui/struct_excessive_bools.rs | 6 +- tests/ui/struct_excessive_bools.stderr | 10 +- tests/ui/struct_fields.rs | 2 + tests/ui/struct_fields.stderr | 2 +- tests/ui/suspicious_arithmetic_impl.rs | 31 +- tests/ui/suspicious_arithmetic_impl.stderr | 16 +- tests/ui/suspicious_command_arg_space.fixed | 8 +- tests/ui/suspicious_command_arg_space.rs | 8 +- tests/ui/suspicious_command_arg_space.stderr | 2 +- tests/ui/suspicious_doc_comments.fixed | 9 + tests/ui/suspicious_doc_comments.rs | 9 + tests/ui/suspicious_doc_comments.stderr | 67 +-- tests/ui/suspicious_doc_comments_unfixable.rs | 8 +- .../suspicious_doc_comments_unfixable.stderr | 9 +- tests/ui/suspicious_else_formatting.rs | 9 +- tests/ui/suspicious_else_formatting.stderr | 44 +- tests/ui/suspicious_map.rs | 6 +- tests/ui/suspicious_map.stderr | 2 +- tests/ui/suspicious_operation_groupings.fixed | 26 + tests/ui/suspicious_operation_groupings.rs | 26 + .../ui/suspicious_operation_groupings.stderr | 58 +- tests/ui/suspicious_splitn.rs | 45 +- tests/ui/suspicious_splitn.stderr | 16 +- tests/ui/suspicious_to_owned.rs | 22 +- tests/ui/suspicious_to_owned.stderr | 10 +- tests/ui/suspicious_unary_op_formatting.rs | 12 +- .../ui/suspicious_unary_op_formatting.stderr | 6 +- tests/ui/suspicious_xor_used_as_pow.rs | 21 +- tests/ui/suspicious_xor_used_as_pow.stderr | 12 +- tests/ui/swap.rs | 17 + tests/ui/swap.stderr | 49 +- tests/ui/swap_ptr_to_ref.fixed | 4 + tests/ui/swap_ptr_to_ref.rs | 4 + tests/ui/swap_ptr_to_ref.stderr | 6 +- tests/ui/swap_ptr_to_ref_unfixable.rs | 11 +- tests/ui/swap_ptr_to_ref_unfixable.stderr | 4 +- tests/ui/tabs_in_doc_comments.fixed | 8 + tests/ui/tabs_in_doc_comments.rs | 8 + tests/ui/tabs_in_doc_comments.stderr | 12 +- tests/ui/temporary_assignment.rs | 14 +- tests/ui/temporary_assignment.stderr | 10 +- tests/ui/test_attr_in_doctest.rs | 3 + tests/ui/test_attr_in_doctest.stderr | 7 +- tests/ui/tests_outside_test_module.rs | 1 + tests/ui/tests_outside_test_module.stderr | 2 +- tests/ui/to_digit_is_some.fixed | 2 + tests/ui/to_digit_is_some.rs | 2 + tests/ui/to_digit_is_some.stderr | 2 +- ...to_string_in_format_args_incremental.fixed | 1 + .../to_string_in_format_args_incremental.rs | 1 + tests/ui/to_string_trait_impl.rs | 1 + tests/ui/to_string_trait_impl.stderr | 1 + .../ui/too_long_first_doc_paragraph-fix.fixed | 2 + tests/ui/too_long_first_doc_paragraph-fix.rs | 1 + .../too_long_first_doc_paragraph-fix.stderr | 3 + tests/ui/too_long_first_doc_paragraph.rs | 3 + tests/ui/too_long_first_doc_paragraph.stderr | 9 +- tests/ui/toplevel_ref_arg.fixed | 6 + tests/ui/toplevel_ref_arg.rs | 6 + tests/ui/toplevel_ref_arg.stderr | 10 +- tests/ui/toplevel_ref_arg_non_rustfix.rs | 2 + tests/ui/toplevel_ref_arg_non_rustfix.stderr | 2 +- tests/ui/track-diagnostics.rs | 1 + tests/ui/trailing_empty_array.rs | 33 +- tests/ui/trailing_empty_array.stderr | 30 +- tests/ui/trailing_zeros.fixed | 8 +- tests/ui/trailing_zeros.rs | 8 +- tests/ui/trailing_zeros.stderr | 2 +- tests/ui/trait_duplication_in_bounds.fixed | 12 + tests/ui/trait_duplication_in_bounds.rs | 12 + tests/ui/trait_duplication_in_bounds.stderr | 22 +- .../trait_duplication_in_bounds_unfixable.rs | 24 +- ...ait_duplication_in_bounds_unfixable.stderr | 12 +- tests/ui/transmute.rs | 174 +++--- tests/ui/transmute.stderr | 114 ++-- tests/ui/transmute_64bit.rs | 8 +- tests/ui/transmute_64bit.stderr | 2 +- tests/ui/transmute_collection.rs | 56 +- tests/ui/transmute_collection.stderr | 34 +- tests/ui/transmute_float_to_int.fixed | 44 +- tests/ui/transmute_float_to_int.rs | 44 +- tests/ui/transmute_float_to_int.stderr | 26 +- tests/ui/transmute_int_to_char.fixed | 8 +- tests/ui/transmute_int_to_char.rs | 8 +- tests/ui/transmute_int_to_char.stderr | 2 +- tests/ui/transmute_int_to_char_no_std.fixed | 8 +- tests/ui/transmute_int_to_char_no_std.rs | 8 +- tests/ui/transmute_int_to_char_no_std.stderr | 2 +- tests/ui/transmute_int_to_non_zero.fixed | 32 +- tests/ui/transmute_int_to_non_zero.rs | 32 +- tests/ui/transmute_int_to_non_zero.stderr | 18 +- tests/ui/transmute_null_to_fn.rs | 18 +- tests/ui/transmute_null_to_fn.stderr | 10 +- tests/ui/transmute_ptr_to_ptr.fixed | 16 + tests/ui/transmute_ptr_to_ptr.rs | 16 + tests/ui/transmute_ptr_to_ptr.stderr | 30 +- tests/ui/transmute_ptr_to_ref.fixed | 22 + tests/ui/transmute_ptr_to_ref.rs | 22 + tests/ui/transmute_ptr_to_ref.stderr | 42 +- tests/ui/transmute_ref_to_ref.rs | 9 +- tests/ui/transmute_ref_to_ref.stderr | 4 +- tests/ui/transmute_ref_to_ref_no_std.rs | 9 +- tests/ui/transmute_ref_to_ref_no_std.stderr | 4 +- tests/ui/transmute_undefined_repr.rs | 58 +- tests/ui/transmute_undefined_repr.stderr | 22 +- .../transmutes_expressible_as_ptr_casts.fixed | 10 + .../ui/transmutes_expressible_as_ptr_casts.rs | 10 + ...transmutes_expressible_as_ptr_casts.stderr | 18 +- tests/ui/transmuting_null.rs | 11 +- tests/ui/transmuting_null.stderr | 4 +- tests/ui/trim_split_whitespace.fixed | 8 + tests/ui/trim_split_whitespace.rs | 8 + tests/ui/trim_split_whitespace.stderr | 14 +- tests/ui/trivially_copy_pass_by_ref.rs | 1 + tests/ui/trivially_copy_pass_by_ref.stderr | 30 +- tests/ui/try_err.fixed | 11 + tests/ui/try_err.rs | 11 + tests/ui/try_err.stderr | 20 +- tests/ui/tuple_array_conversions.rs | 10 + tests/ui/tuple_array_conversions.stderr | 18 +- tests/ui/ty_fn_sig.rs | 1 + tests/ui/type_complexity.rs | 47 +- tests/ui/type_complexity.stderr | 28 +- tests/ui/type_id_on_box.fixed | 12 +- tests/ui/type_id_on_box.rs | 12 +- tests/ui/type_id_on_box.stderr | 6 +- tests/ui/type_id_on_box_unfixable.rs | 6 +- tests/ui/type_id_on_box_unfixable.stderr | 2 +- tests/ui/unchecked_duration_subtraction.fixed | 4 + tests/ui/unchecked_duration_subtraction.rs | 4 + .../ui/unchecked_duration_subtraction.stderr | 6 +- tests/ui/unconditional_recursion.rs | 51 +- tests/ui/unconditional_recursion.stderr | 138 ++--- tests/ui/unicode.fixed | 8 + tests/ui/unicode.rs | 8 + tests/ui/unicode.stderr | 18 +- tests/ui/uninhabited_references.rs | 4 + tests/ui/uninhabited_references.stderr | 6 +- tests/ui/uninit.rs | 11 +- tests/ui/uninit.stderr | 4 +- tests/ui/uninit_vec.rs | 36 +- tests/ui/uninit_vec.stderr | 31 +- tests/ui/uninlined_format_args.fixed | 75 +++ tests/ui/uninlined_format_args.rs | 75 +++ tests/ui/uninlined_format_args.stderr | 154 +++--- ...nlined_format_args_panic.edition2018.fixed | 6 + ...nlined_format_args_panic.edition2021.fixed | 6 + ...lined_format_args_panic.edition2021.stderr | 10 +- tests/ui/uninlined_format_args_panic.rs | 6 + tests/ui/unit_arg.rs | 10 + tests/ui/unit_arg.stderr | 29 +- tests/ui/unit_arg_empty_blocks.fixed | 4 + tests/ui/unit_arg_empty_blocks.rs | 4 + tests/ui/unit_arg_empty_blocks.stderr | 6 +- tests/ui/unit_cmp.rs | 20 +- tests/ui/unit_cmp.stderr | 28 +- tests/ui/unit_hash.fixed | 15 +- tests/ui/unit_hash.rs | 15 +- tests/ui/unit_hash.stderr | 4 +- tests/ui/unit_return_expecting_ord.rs | 12 +- tests/ui/unit_return_expecting_ord.stderr | 10 +- tests/ui/unknown_clippy_lints.fixed | 9 + tests/ui/unknown_clippy_lints.rs | 9 + tests/ui/unknown_clippy_lints.stderr | 16 +- tests/ui/unnecessary_box_returns.rs | 12 +- tests/ui/unnecessary_box_returns.stderr | 6 +- tests/ui/unnecessary_cast.fixed | 41 ++ tests/ui/unnecessary_cast.rs | 41 ++ tests/ui/unnecessary_cast.stderr | 80 +-- tests/ui/unnecessary_cast_unfixable.rs | 8 +- tests/ui/unnecessary_cast_unfixable.stderr | 2 +- tests/ui/unnecessary_clippy_cfg.rs | 26 +- tests/ui/unnecessary_clippy_cfg.stderr | 26 +- tests/ui/unnecessary_clone.rs | 31 +- tests/ui/unnecessary_clone.stderr | 16 +- .../ui/unnecessary_fallible_conversions.fixed | 30 +- tests/ui/unnecessary_fallible_conversions.rs | 30 +- .../unnecessary_fallible_conversions.stderr | 18 +- tests/ui/unnecessary_filter_map.rs | 18 +- tests/ui/unnecessary_filter_map.stderr | 19 +- tests/ui/unnecessary_find_map.rs | 15 +- tests/ui/unnecessary_find_map.stderr | 13 +- tests/ui/unnecessary_first_then_check.fixed | 7 + tests/ui/unnecessary_first_then_check.rs | 7 + tests/ui/unnecessary_first_then_check.stderr | 12 +- tests/ui/unnecessary_fold.fixed | 16 + tests/ui/unnecessary_fold.rs | 16 + tests/ui/unnecessary_fold.stderr | 30 +- tests/ui/unnecessary_get_then_check.fixed | 30 +- tests/ui/unnecessary_get_then_check.rs | 30 +- tests/ui/unnecessary_get_then_check.stderr | 80 +-- tests/ui/unnecessary_iter_cloned.fixed | 15 +- tests/ui/unnecessary_iter_cloned.rs | 15 +- tests/ui/unnecessary_iter_cloned.stderr | 16 +- tests/ui/unnecessary_join.rs | 2 + tests/ui/unnecessary_join.stderr | 4 +- tests/ui/unnecessary_lazy_eval.fixed | 86 ++- tests/ui/unnecessary_lazy_eval.rs | 86 ++- tests/ui/unnecessary_lazy_eval.stderr | 124 ++--- tests/ui/unnecessary_lazy_eval_unfixable.rs | 12 +- .../ui/unnecessary_lazy_eval_unfixable.stderr | 6 +- tests/ui/unnecessary_literal_bound.fixed | 3 + tests/ui/unnecessary_literal_bound.rs | 3 + tests/ui/unnecessary_literal_bound.stderr | 4 +- tests/ui/unnecessary_literal_unwrap.fixed | 53 ++ tests/ui/unnecessary_literal_unwrap.rs | 53 ++ tests/ui/unnecessary_literal_unwrap.stderr | 104 ++-- .../unnecessary_literal_unwrap_unfixable.rs | 156 ++++-- ...nnecessary_literal_unwrap_unfixable.stderr | 198 +++---- tests/ui/unnecessary_map_on_constructor.fixed | 8 + tests/ui/unnecessary_map_on_constructor.rs | 8 + .../ui/unnecessary_map_on_constructor.stderr | 14 +- tests/ui/unnecessary_map_or.fixed | 23 + tests/ui/unnecessary_map_or.rs | 24 + tests/ui/unnecessary_map_or.stderr | 48 +- tests/ui/unnecessary_min_or_max.fixed | 17 + tests/ui/unnecessary_min_or_max.rs | 17 + tests/ui/unnecessary_min_or_max.stderr | 32 +- tests/ui/unnecessary_operation.fixed | 20 +- tests/ui/unnecessary_operation.rs | 22 +- tests/ui/unnecessary_operation.stderr | 40 +- .../ui/unnecessary_owned_empty_strings.fixed | 2 + tests/ui/unnecessary_owned_empty_strings.rs | 2 + .../ui/unnecessary_owned_empty_strings.stderr | 2 +- tests/ui/unnecessary_result_map_or_else.fixed | 9 +- tests/ui/unnecessary_result_map_or_else.rs | 12 +- .../ui/unnecessary_result_map_or_else.stderr | 22 +- tests/ui/unnecessary_safety_comment.rs | 25 +- tests/ui/unnecessary_safety_comment.stderr | 50 +- tests/ui/unnecessary_self_imports.fixed | 2 + tests/ui/unnecessary_self_imports.rs | 2 + tests/ui/unnecessary_self_imports.stderr | 2 +- .../unnecessary_semicolon.edition2021.fixed | 8 +- .../unnecessary_semicolon.edition2021.stderr | 4 +- .../unnecessary_semicolon.edition2024.fixed | 8 +- .../unnecessary_semicolon.edition2024.stderr | 6 +- tests/ui/unnecessary_semicolon.rs | 8 +- tests/ui/unnecessary_sort_by.fixed | 12 + tests/ui/unnecessary_sort_by.rs | 12 + tests/ui/unnecessary_sort_by.stderr | 22 +- tests/ui/unnecessary_sort_by_no_std.fixed | 2 + tests/ui/unnecessary_sort_by_no_std.rs | 2 + tests/ui/unnecessary_sort_by_no_std.stderr | 2 +- .../unnecessary_struct_initialization.fixed | 9 + tests/ui/unnecessary_struct_initialization.rs | 11 + .../unnecessary_struct_initialization.stderr | 22 +- tests/ui/unnecessary_to_owned.fixed | 98 +++- tests/ui/unnecessary_to_owned.rs | 98 +++- tests/ui/unnecessary_to_owned.stderr | 205 ++++---- tests/ui/unnecessary_to_owned_on_split.fixed | 27 +- tests/ui/unnecessary_to_owned_on_split.rs | 27 +- tests/ui/unnecessary_to_owned_on_split.stderr | 16 +- tests/ui/unnecessary_unsafety_doc.rs | 7 + tests/ui/unnecessary_unsafety_doc.stderr | 12 +- tests/ui/unnecessary_wraps.rs | 23 +- tests/ui/unnecessary_wraps.stderr | 26 +- tests/ui/unneeded_field_pattern.rs | 2 + tests/ui/unneeded_field_pattern.stderr | 2 +- tests/ui/unneeded_struct_pattern.fixed | 62 +-- tests/ui/unneeded_struct_pattern.rs | 47 +- tests/ui/unneeded_struct_pattern.stderr | 152 ++---- tests/ui/unneeded_wildcard_pattern.fixed | 14 + tests/ui/unneeded_wildcard_pattern.rs | 14 + tests/ui/unneeded_wildcard_pattern.stderr | 26 +- tests/ui/unnested_or_patterns.fixed | 17 + tests/ui/unnested_or_patterns.rs | 17 + tests/ui/unnested_or_patterns.stderr | 32 +- tests/ui/unnested_or_patterns2.fixed | 8 + tests/ui/unnested_or_patterns2.rs | 8 + tests/ui/unnested_or_patterns2.stderr | 14 +- tests/ui/unreadable_literal.fixed | 10 + tests/ui/unreadable_literal.rs | 10 + tests/ui/unreadable_literal.stderr | 12 +- tests/ui/unsafe_removed_from_name.rs | 17 +- tests/ui/unsafe_removed_from_name.stderr | 8 +- tests/ui/unseparated_prefix_literals.fixed | 9 + tests/ui/unseparated_prefix_literals.rs | 9 + tests/ui/unseparated_prefix_literals.stderr | 16 +- tests/ui/unused_async.rs | 12 +- tests/ui/unused_async.stderr | 11 +- tests/ui/unused_enumerate_index.fixed | 8 + tests/ui/unused_enumerate_index.rs | 8 + tests/ui/unused_enumerate_index.stderr | 38 +- tests/ui/unused_format_specs.1.fixed | 26 +- tests/ui/unused_format_specs.2.fixed | 26 +- tests/ui/unused_format_specs.rs | 26 +- tests/ui/unused_format_specs.stderr | 14 +- tests/ui/unused_io_amount.rs | 59 +-- tests/ui/unused_io_amount.stderr | 32 +- tests/ui/unused_peekable.rs | 24 +- tests/ui/unused_peekable.stderr | 14 +- tests/ui/unused_result_ok.fixed | 4 + tests/ui/unused_result_ok.rs | 4 + tests/ui/unused_result_ok.stderr | 6 +- tests/ui/unused_rounding.fixed | 5 + tests/ui/unused_rounding.rs | 5 + tests/ui/unused_rounding.stderr | 8 +- tests/ui/unused_self.rs | 27 +- tests/ui/unused_self.stderr | 16 +- tests/ui/unused_trait_names.fixed | 10 + tests/ui/unused_trait_names.rs | 10 + tests/ui/unused_trait_names.stderr | 18 +- tests/ui/unused_unit.fixed | 19 + tests/ui/unused_unit.rs | 19 + tests/ui/unused_unit.stderr | 62 +-- tests/ui/unwrap.rs | 9 +- tests/ui/unwrap.stderr | 4 +- tests/ui/unwrap_expect_used.rs | 17 +- tests/ui/unwrap_expect_used.stderr | 10 +- tests/ui/unwrap_in_result.rs | 7 +- tests/ui/unwrap_in_result.stderr | 16 +- tests/ui/unwrap_or.fixed | 8 +- tests/ui/unwrap_or.rs | 8 +- tests/ui/unwrap_or.stderr | 2 +- tests/ui/unwrap_or_else_default.fixed | 16 + tests/ui/unwrap_or_else_default.rs | 16 + tests/ui/unwrap_or_else_default.stderr | 56 +- tests/ui/upper_case_acronyms.fixed | 38 +- tests/ui/upper_case_acronyms.rs | 38 +- tests/ui/upper_case_acronyms.stderr | 22 +- tests/ui/use_self.fixed | 43 ++ tests/ui/use_self.rs | 43 ++ tests/ui/use_self.stderr | 84 +-- tests/ui/use_self_trait.fixed | 16 + tests/ui/use_self_trait.rs | 16 + tests/ui/use_self_trait.stderr | 28 +- tests/ui/used_underscore_binding.rs | 6 + tests/ui/used_underscore_binding.stderr | 20 +- tests/ui/used_underscore_items.rs | 9 + tests/ui/used_underscore_items.stderr | 16 +- tests/ui/useful_asref.rs | 2 + tests/ui/useless_asref.fixed | 32 +- tests/ui/useless_asref.rs | 32 +- tests/ui/useless_asref.stderr | 34 +- tests/ui/useless_attribute.fixed | 3 + tests/ui/useless_attribute.rs | 3 + tests/ui/useless_attribute.stderr | 4 +- tests/ui/useless_conversion.fixed | 47 +- tests/ui/useless_conversion.rs | 41 ++ tests/ui/useless_conversion.stderr | 108 ++-- tests/ui/useless_conversion_try.rs | 27 +- tests/ui/useless_conversion_try.stderr | 16 +- tests/ui/useless_nonzero_new_unchecked.fixed | 15 +- tests/ui/useless_nonzero_new_unchecked.rs | 15 +- tests/ui/useless_nonzero_new_unchecked.stderr | 8 +- tests/ui/useless_vec.rs | 3 +- tests/ui/useless_vec.stderr | 1 + tests/ui/vec.fixed | 23 +- tests/ui/vec.rs | 23 +- tests/ui/vec.stderr | 64 +-- tests/ui/vec_box_sized.rs | 9 + tests/ui/vec_box_sized.stderr | 16 +- tests/ui/vec_init_then_push.rs | 26 +- tests/ui/vec_init_then_push.stderr | 26 +- tests/ui/vec_resize_to_zero.fixed | 3 +- tests/ui/vec_resize_to_zero.rs | 3 +- tests/ui/verbose_file_reads.rs | 6 +- tests/ui/verbose_file_reads.stderr | 2 +- tests/ui/waker_clone_wake.fixed | 2 + tests/ui/waker_clone_wake.rs | 2 + tests/ui/waker_clone_wake.stderr | 2 +- tests/ui/while_float.rs | 2 + tests/ui/while_float.stderr | 2 +- tests/ui/while_let_loop.rs | 17 +- tests/ui/while_let_loop.stderr | 21 +- tests/ui/while_let_on_iterator.fixed | 28 + tests/ui/while_let_on_iterator.rs | 28 + tests/ui/while_let_on_iterator.stderr | 62 +-- tests/ui/wild_in_or_pats.rs | 14 +- tests/ui/wild_in_or_pats.stderr | 10 +- tests/ui/wildcard_enum_match_arm.fixed | 6 + tests/ui/wildcard_enum_match_arm.rs | 6 + tests/ui/wildcard_enum_match_arm.stderr | 10 +- tests/ui/wildcard_imports.fixed | 21 + tests/ui/wildcard_imports.rs | 22 + tests/ui/wildcard_imports.stderr | 43 +- .../wildcard_imports_2021.edition2018.fixed | 21 + .../wildcard_imports_2021.edition2018.stderr | 43 +- .../wildcard_imports_2021.edition2021.fixed | 21 + .../wildcard_imports_2021.edition2021.stderr | 43 +- tests/ui/wildcard_imports_2021.rs | 22 + tests/ui/wildcard_imports_cfgtest.rs | 1 + tests/ui/write_literal.fixed | 40 +- tests/ui/write_literal.rs | 40 +- tests/ui/write_literal.stderr | 29 +- tests/ui/write_literal_2.rs | 42 +- tests/ui/write_literal_2.stderr | 28 +- tests/ui/write_with_newline.fixed | 29 +- tests/ui/write_with_newline.rs | 29 +- tests/ui/write_with_newline.stderr | 20 +- tests/ui/writeln_empty_string.fixed | 2 + tests/ui/writeln_empty_string.rs | 2 + tests/ui/writeln_empty_string.stderr | 2 +- tests/ui/wrong_self_convention.rs | 72 ++- tests/ui/wrong_self_convention.stderr | 46 +- tests/ui/wrong_self_convention2.rs | 6 +- tests/ui/wrong_self_convention2.stderr | 2 +- tests/ui/wrong_self_conventions_mut.rs | 6 +- tests/ui/wrong_self_conventions_mut.stderr | 2 +- tests/ui/zero_div_zero.rs | 12 +- tests/ui/zero_div_zero.stderr | 6 +- tests/ui/zero_offset.rs | 26 +- tests/ui/zero_offset.stderr | 14 +- tests/ui/zero_ptr.fixed | 5 + tests/ui/zero_ptr.rs | 5 + tests/ui/zero_ptr.stderr | 8 +- tests/ui/zero_ptr_no_std.fixed | 3 + tests/ui/zero_ptr_no_std.rs | 3 + tests/ui/zero_ptr_no_std.stderr | 4 +- tests/ui/zero_repeat_side_effects.fixed | 9 + tests/ui/zero_repeat_side_effects.rs | 9 + tests/ui/zero_repeat_side_effects.stderr | 16 +- tests/ui/zero_sized_btreemap_values.rs | 39 +- tests/ui/zero_sized_btreemap_values.stderr | 24 +- tests/ui/zero_sized_hashmap_values.rs | 39 +- tests/ui/zero_sized_hashmap_values.stderr | 24 +- tests/ui/zombie_processes.rs | 8 + tests/ui/zombie_processes.stderr | 30 +- tests/ui/zombie_processes_fixable.fixed | 10 +- tests/ui/zombie_processes_fixable.rs | 10 +- tests/ui/zombie_processes_fixable.stderr | 6 +- 2287 files changed, 29493 insertions(+), 15906 deletions(-) delete mode 100644 tests/ui/collapsible_else_if.stderr delete mode 100644 tests/ui/collapsible_if.stderr delete mode 100644 tests/ui/crashes/ice-5835.fixed delete mode 100644 tests/ui/needless_bool/simple.stderr delete mode 100644 tests/ui/needless_bool_assign.stderr delete mode 100644 tests/ui/needless_else.stderr delete mode 100644 tests/ui/single_match.stderr delete mode 100644 tests/ui/single_match_else.stderr diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index 60f2ba4abcff..793961d30f0d 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -12,46 +12,64 @@ 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 + //~^ absurd_extreme_comparisons + u <= Z; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u < Z; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + Z >= u; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + Z > u; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u > u32::MAX; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u >= u32::MAX; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u32::MAX < u; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u32::MAX <= u; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + 1-1 > u; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u >= !0; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + u <= 12 - 2*6; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + let i: i8 = 0; i < -127 - 1; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + i8::MAX >= i; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + 3-7 < i32::MIN; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + let b = false; b >= true; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + false > b; - //~^ ERROR: this comparison involving the minimum or maximum element for this type con + //~^ absurd_extreme_comparisons + 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 + //~^ unit_cmp + + } use std::cmp::{Ordering, PartialEq, PartialOrd}; diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index f98114c0000a..6df50c15e8cd 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -9,7 +9,7 @@ LL | u <= 0; = help: to override `-D warnings` add `#[allow(clippy::absurd_extreme_comparisons)]` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:16:5 + --> tests/ui/absurd-extreme-comparisons.rs:17:5 | LL | u <= Z; | ^^^^^^ @@ -17,7 +17,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 - --> tests/ui/absurd-extreme-comparisons.rs:18:5 + --> tests/ui/absurd-extreme-comparisons.rs:20:5 | LL | u < Z; | ^^^^^ @@ -25,7 +25,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 - --> tests/ui/absurd-extreme-comparisons.rs:20:5 + --> tests/ui/absurd-extreme-comparisons.rs:23:5 | LL | Z >= u; | ^^^^^^ @@ -33,7 +33,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 - --> tests/ui/absurd-extreme-comparisons.rs:22:5 + --> tests/ui/absurd-extreme-comparisons.rs:26:5 | LL | Z > u; | ^^^^^ @@ -41,7 +41,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 - --> tests/ui/absurd-extreme-comparisons.rs:24:5 + --> tests/ui/absurd-extreme-comparisons.rs:29:5 | LL | u > u32::MAX; | ^^^^^^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/absurd-extreme-comparisons.rs:26:5 + --> tests/ui/absurd-extreme-comparisons.rs:32:5 | LL | u >= u32::MAX; | ^^^^^^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/absurd-extreme-comparisons.rs:28:5 + --> tests/ui/absurd-extreme-comparisons.rs:35:5 | LL | u32::MAX < u; | ^^^^^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/absurd-extreme-comparisons.rs:30:5 + --> tests/ui/absurd-extreme-comparisons.rs:38:5 | LL | u32::MAX <= u; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/absurd-extreme-comparisons.rs:32:5 + --> tests/ui/absurd-extreme-comparisons.rs:41:5 | LL | 1-1 > u; | ^^^^^^^ @@ -81,7 +81,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 - --> tests/ui/absurd-extreme-comparisons.rs:34:5 + --> tests/ui/absurd-extreme-comparisons.rs:44:5 | LL | u >= !0; | ^^^^^^^ @@ -89,7 +89,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 - --> tests/ui/absurd-extreme-comparisons.rs:36:5 + --> tests/ui/absurd-extreme-comparisons.rs:47:5 | LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ @@ -97,7 +97,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 - --> tests/ui/absurd-extreme-comparisons.rs:39:5 + --> tests/ui/absurd-extreme-comparisons.rs:51:5 | LL | i < -127 - 1; | ^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/absurd-extreme-comparisons.rs:41:5 + --> tests/ui/absurd-extreme-comparisons.rs:54:5 | LL | i8::MAX >= i; | ^^^^^^^^^^^^ @@ -113,7 +113,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 - --> tests/ui/absurd-extreme-comparisons.rs:43:5 + --> tests/ui/absurd-extreme-comparisons.rs:57:5 | LL | 3-7 < i32::MIN; | ^^^^^^^^^^^^^^ @@ -121,7 +121,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 - --> tests/ui/absurd-extreme-comparisons.rs:46:5 + --> tests/ui/absurd-extreme-comparisons.rs:61:5 | LL | b >= true; | ^^^^^^^^^ @@ -129,7 +129,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 - --> tests/ui/absurd-extreme-comparisons.rs:48:5 + --> tests/ui/absurd-extreme-comparisons.rs:64:5 | LL | false > b; | ^^^^^^^^^ @@ -137,7 +137,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 - --> tests/ui/absurd-extreme-comparisons.rs:52:5 + --> tests/ui/absurd-extreme-comparisons.rs:69:5 | LL | () < {}; | ^^^^^^^ diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index 8f6c962e2f5b..56a98cca3404 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -11,6 +11,7 @@ use proc_macros::{external, with_span}; // Should lint #[expect(dead_code)] +//~^ allow_attributes struct T1; struct T2; // Should not lint @@ -20,6 +21,7 @@ struct T3; struct T4; // `panic = "unwind"` should always be true #[cfg_attr(panic = "unwind", expect(dead_code))] +//~^ allow_attributes struct CfgT; #[allow(clippy::allow_attributes, unused)] @@ -51,6 +53,7 @@ fn ignore_inner_attr() { #[clippy::msrv = "1.81"] fn msrv_1_81() { #[expect(unused)] + //~^ allow_attributes let x = 1; } diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index cb6c4dcf7158..65a0a6b5a108 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -11,6 +11,7 @@ use proc_macros::{external, with_span}; // Should lint #[allow(dead_code)] +//~^ allow_attributes struct T1; struct T2; // Should not lint @@ -20,6 +21,7 @@ struct T3; struct T4; // `panic = "unwind"` should always be true #[cfg_attr(panic = "unwind", allow(dead_code))] +//~^ allow_attributes struct CfgT; #[allow(clippy::allow_attributes, unused)] @@ -51,6 +53,7 @@ fn ignore_inner_attr() { #[clippy::msrv = "1.81"] fn msrv_1_81() { #[allow(unused)] + //~^ allow_attributes let x = 1; } diff --git a/tests/ui/allow_attributes.stderr b/tests/ui/allow_attributes.stderr index 5a4ff287acd2..dd5fb21ffeaf 100644 --- a/tests/ui/allow_attributes.stderr +++ b/tests/ui/allow_attributes.stderr @@ -8,13 +8,13 @@ LL | #[allow(dead_code)] = help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]` error: #[allow] attribute found - --> tests/ui/allow_attributes.rs:22:30 + --> tests/ui/allow_attributes.rs:23:30 | LL | #[cfg_attr(panic = "unwind", allow(dead_code))] | ^^^^^ help: replace it with: `expect` error: #[allow] attribute found - --> tests/ui/allow_attributes.rs:53:7 + --> tests/ui/allow_attributes.rs:55:7 | LL | #[allow(unused)] | ^^^^^ help: replace it with: `expect` diff --git a/tests/ui/allow_attributes_without_reason.rs b/tests/ui/allow_attributes_without_reason.rs index 334e7ddd9d23..ea89511ebb46 100644 --- a/tests/ui/allow_attributes_without_reason.rs +++ b/tests/ui/allow_attributes_without_reason.rs @@ -1,14 +1,18 @@ //@aux-build:proc_macros.rs #![deny(clippy::allow_attributes_without_reason)] #![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)] +//~^ allow_attributes_without_reason extern crate proc_macros; use proc_macros::{external, with_span}; // These should trigger the lint #[allow(dead_code)] +//~^ allow_attributes_without_reason #[allow(dead_code, deprecated)] +//~^ allow_attributes_without_reason #[expect(dead_code)] +//~^ allow_attributes_without_reason // These should be fine #[allow(dead_code, reason = "This should be allowed")] #[warn(dyn_drop, reason = "Warnings can also have reasons")] @@ -44,6 +48,7 @@ pub fn trigger_fp_result() -> Result<(), &'static str> { #[clippy::msrv = "1.81"] fn msrv_1_81() { #[allow(unused)] + //~^ allow_attributes_without_reason let _ = 1; } diff --git a/tests/ui/allow_attributes_without_reason.stderr b/tests/ui/allow_attributes_without_reason.stderr index 9c1ac5af91b0..07e74839b769 100644 --- a/tests/ui/allow_attributes_without_reason.stderr +++ b/tests/ui/allow_attributes_without_reason.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::allow_attributes_without_reason)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:9:1 + --> tests/ui/allow_attributes_without_reason.rs:10:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | #[allow(dead_code)] = help: try adding a reason at the end with `, reason = ".."` error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:10:1 + --> tests/ui/allow_attributes_without_reason.rs:12:1 | LL | #[allow(dead_code, deprecated)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | #[allow(dead_code, deprecated)] = help: try adding a reason at the end with `, reason = ".."` error: `expect` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:11:1 + --> tests/ui/allow_attributes_without_reason.rs:14:1 | LL | #[expect(dead_code)] | ^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | #[expect(dead_code)] = help: try adding a reason at the end with `, reason = ".."` error: `allow` attribute without specifying a reason - --> tests/ui/allow_attributes_without_reason.rs:46:5 + --> tests/ui/allow_attributes_without_reason.rs:50:5 | LL | #[allow(unused)] | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/almost_complete_range.fixed b/tests/ui/almost_complete_range.fixed index 6c2b2f117437..7591508b8350 100644 --- a/tests/ui/almost_complete_range.fixed +++ b/tests/ui/almost_complete_range.fixed @@ -15,8 +15,11 @@ fn main() { #[rustfmt::skip] { let _ = ('a') ..='z'; + //~^ almost_complete_range let _ = 'A' ..= ('Z'); + //~^ almost_complete_range let _ = ((('0'))) ..= ('9'); + //~^ almost_complete_range } let _ = 'b'..'z'; @@ -24,21 +27,30 @@ fn main() { let _ = '1'..'9'; let _ = (b'a')..=(b'z'); + //~^ almost_complete_range let _ = b'A'..=b'Z'; + //~^ almost_complete_range let _ = b'0'..=b'9'; + //~^ almost_complete_range let _ = b'b'..b'z'; let _ = b'B'..b'Z'; let _ = b'1'..b'9'; let _ = inline!('a')..='z'; + //~^ almost_complete_range let _ = inline!('A')..='Z'; + //~^ almost_complete_range let _ = inline!('0')..='9'; + //~^ almost_complete_range let _ = match 0u8 { b'a'..=b'z' if true => 1, + //~^ almost_complete_range b'A'..=b'Z' if true => 2, + //~^ almost_complete_range b'0'..=b'9' if true => 3, + //~^ almost_complete_range b'b'..b'z' => 4, b'B'..b'Z' => 5, b'1'..b'9' => 6, @@ -47,8 +59,11 @@ fn main() { let _ = match 'x' { 'a'..='z' if true => 1, + //~^ almost_complete_range 'A'..='Z' if true => 2, + //~^ almost_complete_range '0'..='9' if true => 3, + //~^ almost_complete_range 'b'..'z' => 4, 'B'..'Z' => 5, '1'..'9' => 6, @@ -62,8 +77,11 @@ fn main() { ); inline!( let _ = 'a'..='z'; + //~^ almost_complete_range let _ = 'A'..='Z'; + //~^ almost_complete_range let _ = '0'..='9'; + //~^ almost_complete_range ); } @@ -71,8 +89,11 @@ fn main() { fn _under_msrv() { let _ = match 'a' { 'a'...'z' => 1, + //~^ almost_complete_range 'A'...'Z' => 2, + //~^ almost_complete_range '0'...'9' => 3, + //~^ almost_complete_range _ => 4, }; } @@ -80,12 +101,18 @@ fn _under_msrv() { #[clippy::msrv = "1.26"] fn _meets_msrv() { let _ = 'a'..='z'; + //~^ almost_complete_range let _ = 'A'..='Z'; + //~^ almost_complete_range let _ = '0'..='9'; + //~^ almost_complete_range let _ = match 'a' { 'a'..='z' => 1, + //~^ almost_complete_range 'A'..='Z' => 1, + //~^ almost_complete_range '0'..='9' => 3, + //~^ almost_complete_range _ => 4, }; } diff --git a/tests/ui/almost_complete_range.rs b/tests/ui/almost_complete_range.rs index 813668a53096..907f70bd8156 100644 --- a/tests/ui/almost_complete_range.rs +++ b/tests/ui/almost_complete_range.rs @@ -15,8 +15,11 @@ fn main() { #[rustfmt::skip] { let _ = ('a') ..'z'; + //~^ almost_complete_range let _ = 'A' .. ('Z'); + //~^ almost_complete_range let _ = ((('0'))) .. ('9'); + //~^ almost_complete_range } let _ = 'b'..'z'; @@ -24,21 +27,30 @@ fn main() { let _ = '1'..'9'; let _ = (b'a')..(b'z'); + //~^ almost_complete_range let _ = b'A'..b'Z'; + //~^ almost_complete_range let _ = b'0'..b'9'; + //~^ almost_complete_range let _ = b'b'..b'z'; let _ = b'B'..b'Z'; let _ = b'1'..b'9'; let _ = inline!('a')..'z'; + //~^ almost_complete_range let _ = inline!('A')..'Z'; + //~^ almost_complete_range let _ = inline!('0')..'9'; + //~^ almost_complete_range let _ = match 0u8 { b'a'..b'z' if true => 1, + //~^ almost_complete_range b'A'..b'Z' if true => 2, + //~^ almost_complete_range b'0'..b'9' if true => 3, + //~^ almost_complete_range b'b'..b'z' => 4, b'B'..b'Z' => 5, b'1'..b'9' => 6, @@ -47,8 +59,11 @@ fn main() { let _ = match 'x' { 'a'..'z' if true => 1, + //~^ almost_complete_range 'A'..'Z' if true => 2, + //~^ almost_complete_range '0'..'9' if true => 3, + //~^ almost_complete_range 'b'..'z' => 4, 'B'..'Z' => 5, '1'..'9' => 6, @@ -62,8 +77,11 @@ fn main() { ); inline!( let _ = 'a'..'z'; + //~^ almost_complete_range let _ = 'A'..'Z'; + //~^ almost_complete_range let _ = '0'..'9'; + //~^ almost_complete_range ); } @@ -71,8 +89,11 @@ fn main() { fn _under_msrv() { let _ = match 'a' { 'a'..'z' => 1, + //~^ almost_complete_range 'A'..'Z' => 2, + //~^ almost_complete_range '0'..'9' => 3, + //~^ almost_complete_range _ => 4, }; } @@ -80,12 +101,18 @@ fn _under_msrv() { #[clippy::msrv = "1.26"] fn _meets_msrv() { let _ = 'a'..'z'; + //~^ almost_complete_range let _ = 'A'..'Z'; + //~^ almost_complete_range let _ = '0'..'9'; + //~^ almost_complete_range let _ = match 'a' { 'a'..'z' => 1, + //~^ almost_complete_range 'A'..'Z' => 1, + //~^ almost_complete_range '0'..'9' => 3, + //~^ almost_complete_range _ => 4, }; } diff --git a/tests/ui/almost_complete_range.stderr b/tests/ui/almost_complete_range.stderr index bfc2beb07d85..217df7f4883f 100644 --- a/tests/ui/almost_complete_range.stderr +++ b/tests/ui/almost_complete_range.stderr @@ -10,7 +10,7 @@ LL | let _ = ('a') ..'z'; = help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:18:17 + --> tests/ui/almost_complete_range.rs:19:17 | LL | let _ = 'A' .. ('Z'); | ^^^^--^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = 'A' .. ('Z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:19:17 + --> tests/ui/almost_complete_range.rs:21:17 | LL | let _ = ((('0'))) .. ('9'); | ^^^^^^^^^^--^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = ((('0'))) .. ('9'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:26:13 + --> tests/ui/almost_complete_range.rs:29:13 | LL | let _ = (b'a')..(b'z'); | ^^^^^^--^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = (b'a')..(b'z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:27:13 + --> tests/ui/almost_complete_range.rs:31:13 | LL | let _ = b'A'..b'Z'; | ^^^^--^^^^ @@ -42,7 +42,7 @@ LL | let _ = b'A'..b'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:28:13 + --> tests/ui/almost_complete_range.rs:33:13 | LL | let _ = b'0'..b'9'; | ^^^^--^^^^ @@ -50,7 +50,7 @@ LL | let _ = b'0'..b'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:34:13 + --> tests/ui/almost_complete_range.rs:40:13 | LL | let _ = inline!('a')..'z'; | ^^^^^^^^^^^^--^^^ @@ -58,7 +58,7 @@ LL | let _ = inline!('a')..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:35:13 + --> tests/ui/almost_complete_range.rs:42:13 | LL | let _ = inline!('A')..'Z'; | ^^^^^^^^^^^^--^^^ @@ -66,7 +66,7 @@ LL | let _ = inline!('A')..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:36:13 + --> tests/ui/almost_complete_range.rs:44:13 | LL | let _ = inline!('0')..'9'; | ^^^^^^^^^^^^--^^^ @@ -74,7 +74,7 @@ LL | let _ = inline!('0')..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:39:9 + --> tests/ui/almost_complete_range.rs:48:9 | LL | b'a'..b'z' if true => 1, | ^^^^--^^^^ @@ -82,7 +82,7 @@ LL | b'a'..b'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:40:9 + --> tests/ui/almost_complete_range.rs:50:9 | LL | b'A'..b'Z' if true => 2, | ^^^^--^^^^ @@ -90,7 +90,7 @@ LL | b'A'..b'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:41:9 + --> tests/ui/almost_complete_range.rs:52:9 | LL | b'0'..b'9' if true => 3, | ^^^^--^^^^ @@ -98,7 +98,7 @@ LL | b'0'..b'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:49:9 + --> tests/ui/almost_complete_range.rs:61:9 | LL | 'a'..'z' if true => 1, | ^^^--^^^ @@ -106,7 +106,7 @@ LL | 'a'..'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:50:9 + --> tests/ui/almost_complete_range.rs:63:9 | LL | 'A'..'Z' if true => 2, | ^^^--^^^ @@ -114,7 +114,7 @@ LL | 'A'..'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:51:9 + --> tests/ui/almost_complete_range.rs:65:9 | LL | '0'..'9' if true => 3, | ^^^--^^^ @@ -122,7 +122,7 @@ LL | '0'..'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:64:17 + --> tests/ui/almost_complete_range.rs:79:17 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -132,7 +132,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 - --> tests/ui/almost_complete_range.rs:65:17 + --> tests/ui/almost_complete_range.rs:81:17 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -142,7 +142,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 - --> tests/ui/almost_complete_range.rs:66:17 + --> tests/ui/almost_complete_range.rs:83:17 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -152,7 +152,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 - --> tests/ui/almost_complete_range.rs:73:9 + --> tests/ui/almost_complete_range.rs:91:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -160,7 +160,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:74:9 + --> tests/ui/almost_complete_range.rs:93:9 | LL | 'A'..'Z' => 2, | ^^^--^^^ @@ -168,7 +168,7 @@ LL | 'A'..'Z' => 2, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:75:9 + --> tests/ui/almost_complete_range.rs:95:9 | LL | '0'..'9' => 3, | ^^^--^^^ @@ -176,7 +176,7 @@ LL | '0'..'9' => 3, | help: use an inclusive range: `...` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:82:13 + --> tests/ui/almost_complete_range.rs:103:13 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -184,7 +184,7 @@ LL | let _ = 'a'..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:83:13 + --> tests/ui/almost_complete_range.rs:105:13 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -192,7 +192,7 @@ LL | let _ = 'A'..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:84:13 + --> tests/ui/almost_complete_range.rs:107:13 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -200,7 +200,7 @@ LL | let _ = '0'..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:86:9 + --> tests/ui/almost_complete_range.rs:110:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -208,7 +208,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:87:9 + --> tests/ui/almost_complete_range.rs:112:9 | LL | 'A'..'Z' => 1, | ^^^--^^^ @@ -216,7 +216,7 @@ LL | 'A'..'Z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> tests/ui/almost_complete_range.rs:88:9 + --> tests/ui/almost_complete_range.rs:114:9 | LL | '0'..'9' => 3, | ^^^--^^^ diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs index 3c4ed0367894..6461666be8f5 100644 --- a/tests/ui/approx_const.rs +++ b/tests/ui/approx_const.rs @@ -1,86 +1,109 @@ #[warn(clippy::approx_constant)] fn main() { let my_e = 2.7182; - //~^ ERROR: approximate value of `f{32, 64}::consts::E` found + //~^ approx_constant + let almost_e = 2.718; - //~^ ERROR: approximate value of `f{32, 64}::consts::E` found + //~^ approx_constant + let no_e = 2.71; let my_1_frac_pi = 0.3183; - //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_PI` found + //~^ approx_constant + 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 + //~^ approx_constant + let almost_frac_1_sqrt_2 = 0.70711; - //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + 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 + //~^ approx_constant + let no_frac_pi_8 = 0.392; let my_ln_10 = 2.302585092994046; - //~^ ERROR: approximate value of `f{32, 64}::consts::LN_10` found + //~^ approx_constant + let no_ln_10 = 2.303; let my_ln_2 = 0.6931471805599453; - //~^ ERROR: approximate value of `f{32, 64}::consts::LN_2` found + //~^ approx_constant + let no_ln_2 = 0.693; let my_log10_e = 0.4342944819032518; - //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_E` found + //~^ approx_constant + let no_log10_e = 0.434; let my_log2_e = 1.4426950408889634; - //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_E` found + //~^ approx_constant + let no_log2_e = 1.442; let log2_10 = 3.321928094887362; - //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found + //~^ approx_constant + let no_log2_10 = 3.321; let log10_2 = 0.301029995663981; - //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_2` found + //~^ approx_constant + let no_log10_2 = 0.301; let my_pi = 3.1415; - //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found + //~^ approx_constant + let almost_pi = 3.14; - //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found + //~^ approx_constant + let no_pi = 3.15; let my_sq2 = 1.4142; - //~^ ERROR: approximate value of `f{32, 64}::consts::SQRT_2` found + //~^ approx_constant + let no_sq2 = 1.414; let my_tau = 6.2832; - //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found + //~^ approx_constant + let almost_tau = 6.28; - //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found + //~^ approx_constant + let no_tau = 6.3; } diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index 5e82d51edf20..f7bda0468cbd 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -9,7 +9,7 @@ LL | let my_e = 2.7182; = help: to override `-D warnings` add `#[allow(clippy::approx_constant)]` error: approximate value of `f{32, 64}::consts::E` found - --> tests/ui/approx_const.rs:5:20 + --> tests/ui/approx_const.rs:6:20 | LL | let almost_e = 2.718; | ^^^^^ @@ -17,7 +17,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 - --> tests/ui/approx_const.rs:9:24 + --> tests/ui/approx_const.rs:11:24 | LL | let my_1_frac_pi = 0.3183; | ^^^^^^ @@ -25,7 +25,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 - --> tests/ui/approx_const.rs:13:28 + --> tests/ui/approx_const.rs:16:28 | LL | let my_frac_1_sqrt_2 = 0.70710678; | ^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/approx_const.rs:15:32 + --> tests/ui/approx_const.rs:19:32 | LL | let almost_frac_1_sqrt_2 = 0.70711; | ^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/approx_const.rs:19:24 + --> tests/ui/approx_const.rs:24:24 | LL | let my_frac_2_pi = 0.63661977; | ^^^^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/approx_const.rs:23:27 + --> tests/ui/approx_const.rs:29:27 | LL | let my_frac_2_sq_pi = 1.128379; | ^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/approx_const.rs:27:24 + --> tests/ui/approx_const.rs:34:24 | LL | let my_frac_pi_2 = 1.57079632679; | ^^^^^^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/approx_const.rs:31:24 + --> tests/ui/approx_const.rs:39:24 | LL | let my_frac_pi_3 = 1.04719755119; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/approx_const.rs:35:24 + --> tests/ui/approx_const.rs:44:24 | LL | let my_frac_pi_4 = 0.785398163397; | ^^^^^^^^^^^^^^ @@ -81,7 +81,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 - --> tests/ui/approx_const.rs:39:24 + --> tests/ui/approx_const.rs:49:24 | LL | let my_frac_pi_6 = 0.523598775598; | ^^^^^^^^^^^^^^ @@ -89,7 +89,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 - --> tests/ui/approx_const.rs:43:24 + --> tests/ui/approx_const.rs:54:24 | LL | let my_frac_pi_8 = 0.3926990816987; | ^^^^^^^^^^^^^^^ @@ -97,7 +97,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 - --> tests/ui/approx_const.rs:47:20 + --> tests/ui/approx_const.rs:59:20 | LL | let my_ln_10 = 2.302585092994046; | ^^^^^^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/approx_const.rs:51:19 + --> tests/ui/approx_const.rs:64:19 | LL | let my_ln_2 = 0.6931471805599453; | ^^^^^^^^^^^^^^^^^^ @@ -113,7 +113,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 - --> tests/ui/approx_const.rs:55:22 + --> tests/ui/approx_const.rs:69:22 | LL | let my_log10_e = 0.4342944819032518; | ^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,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 - --> tests/ui/approx_const.rs:59:21 + --> tests/ui/approx_const.rs:74:21 | LL | let my_log2_e = 1.4426950408889634; | ^^^^^^^^^^^^^^^^^^ @@ -129,7 +129,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 - --> tests/ui/approx_const.rs:63:19 + --> tests/ui/approx_const.rs:79:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_2` found - --> tests/ui/approx_const.rs:67:19 + --> tests/ui/approx_const.rs:84:19 | LL | let log10_2 = 0.301029995663981; | ^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let log10_2 = 0.301029995663981; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> tests/ui/approx_const.rs:71:17 + --> tests/ui/approx_const.rs:89:17 | LL | let my_pi = 3.1415; | ^^^^^^ @@ -153,7 +153,7 @@ LL | let my_pi = 3.1415; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> tests/ui/approx_const.rs:73:21 + --> tests/ui/approx_const.rs:92:21 | LL | let almost_pi = 3.14; | ^^^^ @@ -161,7 +161,7 @@ LL | let almost_pi = 3.14; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::SQRT_2` found - --> tests/ui/approx_const.rs:77:18 + --> tests/ui/approx_const.rs:97:18 | LL | let my_sq2 = 1.4142; | ^^^^^^ @@ -169,7 +169,7 @@ LL | let my_sq2 = 1.4142; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> tests/ui/approx_const.rs:81:18 + --> tests/ui/approx_const.rs:102:18 | LL | let my_tau = 6.2832; | ^^^^^^ @@ -177,7 +177,7 @@ LL | let my_tau = 6.2832; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> tests/ui/approx_const.rs:83:22 + --> tests/ui/approx_const.rs:105:22 | LL | let almost_tau = 6.28; | ^^^^ diff --git a/tests/ui/arc_with_non_send_sync.rs b/tests/ui/arc_with_non_send_sync.rs index c287480bb1fd..07025ccc42fd 100644 --- a/tests/ui/arc_with_non_send_sync.rs +++ b/tests/ui/arc_with_non_send_sync.rs @@ -33,9 +33,12 @@ fn main() { let _ = Arc::new(42); let _ = Arc::new(RefCell::new(42)); + //~^ arc_with_non_send_sync let mutex = Mutex::new(1); let _ = Arc::new(mutex.lock().unwrap()); + //~^ arc_with_non_send_sync let _ = Arc::new(&42 as *const i32); + //~^ arc_with_non_send_sync } diff --git a/tests/ui/arc_with_non_send_sync.stderr b/tests/ui/arc_with_non_send_sync.stderr index da363a3ebdd9..5556b0df88c9 100644 --- a/tests/ui/arc_with_non_send_sync.stderr +++ b/tests/ui/arc_with_non_send_sync.stderr @@ -11,7 +11,7 @@ LL | let _ = Arc::new(RefCell::new(42)); = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]` error: usage of an `Arc` that is not `Send` and `Sync` - --> tests/ui/arc_with_non_send_sync.rs:38:13 + --> tests/ui/arc_with_non_send_sync.rs:39:13 | LL | let _ = Arc::new(mutex.lock().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let _ = Arc::new(mutex.lock().unwrap()); = help: otherwise make `MutexGuard<'_, i32>` `Send` and `Sync` or consider a wrapper type such as `Mutex` error: usage of an `Arc` that is not `Send` and `Sync` - --> tests/ui/arc_with_non_send_sync.rs:40:13 + --> tests/ui/arc_with_non_send_sync.rs:42:13 | LL | let _ = Arc::new(&42 as *const i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index f09106773c7e..21be2af201f0 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -164,13 +164,16 @@ pub fn association_with_structures_should_not_trigger_the_lint() { pub fn hard_coded_allowed() { let _ = 1f16 + 1f16; + //~^ arithmetic_side_effects let _ = 1f32 + 1f32; let _ = 1f64 + 1f64; let _ = 1f128 + 1f128; + //~^ arithmetic_side_effects let _ = Saturating(0u32) + Saturating(0u32); let _ = String::new() + ""; let _ = String::new() + &String::new(); + //~^ arithmetic_side_effects let _ = Wrapping(0u32) + Wrapping(0u32); let saturating: Saturating = Saturating(0u32); @@ -306,117 +309,221 @@ pub fn unknown_ops_or_runtime_ops_that_can_overflow() { // Assign _n += 1; + //~^ arithmetic_side_effects _n += &1; + //~^ arithmetic_side_effects _n -= 1; + //~^ arithmetic_side_effects _n -= &1; + //~^ arithmetic_side_effects _n /= 0; + //~^ arithmetic_side_effects _n /= &0; + //~^ arithmetic_side_effects _n %= 0; + //~^ arithmetic_side_effects _n %= &0; + //~^ arithmetic_side_effects _n *= 2; + //~^ arithmetic_side_effects _n *= &2; + //~^ arithmetic_side_effects _n += -1; + //~^ arithmetic_side_effects _n += &-1; + //~^ arithmetic_side_effects _n -= -1; + //~^ arithmetic_side_effects _n -= &-1; + //~^ arithmetic_side_effects _n /= -0; + //~^ arithmetic_side_effects _n /= &-0; + //~^ arithmetic_side_effects _n %= -0; + //~^ arithmetic_side_effects _n %= &-0; + //~^ arithmetic_side_effects _n *= -2; + //~^ arithmetic_side_effects _n *= &-2; + //~^ arithmetic_side_effects _custom += Custom; + //~^ arithmetic_side_effects _custom += &Custom; + //~^ arithmetic_side_effects _custom -= Custom; + //~^ arithmetic_side_effects _custom -= &Custom; + //~^ arithmetic_side_effects _custom /= Custom; + //~^ arithmetic_side_effects _custom /= &Custom; + //~^ arithmetic_side_effects _custom %= Custom; + //~^ arithmetic_side_effects _custom %= &Custom; + //~^ arithmetic_side_effects _custom *= Custom; + //~^ arithmetic_side_effects _custom *= &Custom; + //~^ arithmetic_side_effects _custom >>= Custom; + //~^ arithmetic_side_effects _custom >>= &Custom; + //~^ arithmetic_side_effects _custom <<= Custom; + //~^ arithmetic_side_effects _custom <<= &Custom; + //~^ arithmetic_side_effects _custom += -Custom; + //~^ arithmetic_side_effects _custom += &-Custom; + //~^ arithmetic_side_effects _custom -= -Custom; + //~^ arithmetic_side_effects _custom -= &-Custom; + //~^ arithmetic_side_effects _custom /= -Custom; + //~^ arithmetic_side_effects _custom /= &-Custom; + //~^ arithmetic_side_effects _custom %= -Custom; + //~^ arithmetic_side_effects _custom %= &-Custom; + //~^ arithmetic_side_effects _custom *= -Custom; + //~^ arithmetic_side_effects _custom *= &-Custom; + //~^ arithmetic_side_effects _custom >>= -Custom; + //~^ arithmetic_side_effects _custom >>= &-Custom; + //~^ arithmetic_side_effects _custom <<= -Custom; + //~^ arithmetic_side_effects _custom <<= &-Custom; + //~^ arithmetic_side_effects // Binary _n = _n + 1; + //~^ arithmetic_side_effects _n = _n + &1; + //~^ arithmetic_side_effects _n = 1 + _n; + //~^ arithmetic_side_effects _n = &1 + _n; + //~^ arithmetic_side_effects _n = _n - 1; + //~^ arithmetic_side_effects _n = _n - &1; + //~^ arithmetic_side_effects _n = 1 - _n; + //~^ arithmetic_side_effects _n = &1 - _n; + //~^ arithmetic_side_effects _n = _n / 0; + //~^ arithmetic_side_effects _n = _n / &0; + //~^ arithmetic_side_effects _n = _n % 0; + //~^ arithmetic_side_effects _n = _n % &0; + //~^ arithmetic_side_effects _n = _n * 2; + //~^ arithmetic_side_effects _n = _n * &2; + //~^ arithmetic_side_effects _n = 2 * _n; + //~^ arithmetic_side_effects _n = &2 * _n; + //~^ arithmetic_side_effects _n = 23 + &85; + //~^ arithmetic_side_effects _n = &23 + 85; + //~^ arithmetic_side_effects _n = &23 + &85; + //~^ arithmetic_side_effects _custom = _custom + _custom; + //~^ arithmetic_side_effects _custom = _custom + &_custom; + //~^ arithmetic_side_effects _custom = Custom + _custom; + //~^ arithmetic_side_effects _custom = &Custom + _custom; + //~^ arithmetic_side_effects _custom = _custom - Custom; + //~^ arithmetic_side_effects _custom = _custom - &Custom; + //~^ arithmetic_side_effects _custom = Custom - _custom; + //~^ arithmetic_side_effects _custom = &Custom - _custom; + //~^ arithmetic_side_effects _custom = _custom / Custom; + //~^ arithmetic_side_effects _custom = _custom / &Custom; + //~^ arithmetic_side_effects _custom = _custom % Custom; + //~^ arithmetic_side_effects _custom = _custom % &Custom; + //~^ arithmetic_side_effects _custom = _custom * Custom; + //~^ arithmetic_side_effects _custom = _custom * &Custom; + //~^ arithmetic_side_effects _custom = Custom * _custom; + //~^ arithmetic_side_effects _custom = &Custom * _custom; + //~^ arithmetic_side_effects _custom = Custom + &Custom; + //~^ arithmetic_side_effects _custom = &Custom + Custom; + //~^ arithmetic_side_effects _custom = &Custom + &Custom; + //~^ arithmetic_side_effects _custom = _custom >> _custom; + //~^ arithmetic_side_effects _custom = _custom >> &_custom; + //~^ arithmetic_side_effects _custom = Custom << _custom; + //~^ arithmetic_side_effects _custom = &Custom << _custom; + //~^ arithmetic_side_effects // Method _n.saturating_div(0); + //~^ arithmetic_side_effects _n.wrapping_div(0); + //~^ arithmetic_side_effects _n.wrapping_rem(0); + //~^ arithmetic_side_effects _n.wrapping_rem_euclid(0); + //~^ arithmetic_side_effects _n.saturating_div(_n); + //~^ arithmetic_side_effects _n.wrapping_div(_n); + //~^ arithmetic_side_effects _n.wrapping_rem(_n); + //~^ arithmetic_side_effects _n.wrapping_rem_euclid(_n); + //~^ arithmetic_side_effects _n.saturating_div(*Box::new(_n)); + //~^ arithmetic_side_effects // Unary _n = -_n; + //~^ arithmetic_side_effects _n = -&_n; + //~^ arithmetic_side_effects _custom = -_custom; + //~^ arithmetic_side_effects _custom = -&_custom; + //~^ arithmetic_side_effects _ = -*Box::new(_n); + //~^ arithmetic_side_effects } // Copied and pasted from the `integer_arithmetic` lint for comparison. @@ -426,10 +533,15 @@ pub fn integer_arithmetic() { let mut var2 = -1i32; 1 + i; + //~^ arithmetic_side_effects i * 2; + //~^ arithmetic_side_effects 1 % i / 2; + //~^ arithmetic_side_effects i - 2 + 2 - i; + //~^ arithmetic_side_effects -i; + //~^ arithmetic_side_effects i >> 1; i << 1; @@ -441,18 +553,27 @@ pub fn integer_arithmetic() { i ^ 1; i += 1; + //~^ arithmetic_side_effects i -= 1; + //~^ arithmetic_side_effects i *= 2; + //~^ arithmetic_side_effects i /= 2; i /= 0; + //~^ arithmetic_side_effects i /= -1; i /= var1; + //~^ arithmetic_side_effects i /= var2; + //~^ arithmetic_side_effects i %= 2; i %= 0; + //~^ arithmetic_side_effects i %= -1; i %= var1; + //~^ arithmetic_side_effects i %= var2; + //~^ arithmetic_side_effects i <<= 3; i >>= 2; @@ -463,6 +584,7 @@ pub fn integer_arithmetic() { pub fn issue_10583(a: u16) -> u16 { 10 / a + //~^ arithmetic_side_effects } pub fn issue_10767() { @@ -517,10 +639,12 @@ pub fn issue_11392() { pub fn issue_11393() { fn example_div(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { x / maybe_zero + //~^ arithmetic_side_effects } fn example_rem(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { x % maybe_zero + //~^ arithmetic_side_effects } let [x, maybe_zero] = [1, 0].map(Wrapping); @@ -532,17 +656,21 @@ pub fn issue_12318() { use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; let mut one: i32 = 1; one.add_assign(1); + //~^ arithmetic_side_effects one.div_assign(1); one.mul_assign(1); one.rem_assign(1); one.sub_assign(1); + //~^ arithmetic_side_effects } pub fn explicit_methods() { use core::ops::Add; let one: i32 = 1; one.add(&one); + //~^ arithmetic_side_effects Box::new(one).add(one); + //~^ arithmetic_side_effects } fn main() {} diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 9b4cfb83fbb2..e15fb612be5e 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -8,763 +8,763 @@ LL | let _ = 1f16 + 1f16; = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:169:13 + --> tests/ui/arithmetic_side_effects.rs:170:13 | LL | let _ = 1f128 + 1f128; | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:173:13 + --> tests/ui/arithmetic_side_effects.rs:175:13 | LL | let _ = String::new() + &String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:308:5 + --> tests/ui/arithmetic_side_effects.rs:311:5 | LL | _n += 1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:309:5 + --> tests/ui/arithmetic_side_effects.rs:313:5 | LL | _n += &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:310:5 + --> tests/ui/arithmetic_side_effects.rs:315:5 | LL | _n -= 1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:311:5 + --> tests/ui/arithmetic_side_effects.rs:317:5 | LL | _n -= &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:312:5 + --> tests/ui/arithmetic_side_effects.rs:319:5 | LL | _n /= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:313:5 + --> tests/ui/arithmetic_side_effects.rs:321:5 | LL | _n /= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:314:5 + --> tests/ui/arithmetic_side_effects.rs:323:5 | LL | _n %= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:315:5 + --> tests/ui/arithmetic_side_effects.rs:325:5 | LL | _n %= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:316:5 + --> tests/ui/arithmetic_side_effects.rs:327:5 | LL | _n *= 2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:317:5 + --> tests/ui/arithmetic_side_effects.rs:329:5 | LL | _n *= &2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:318:5 + --> tests/ui/arithmetic_side_effects.rs:331:5 | LL | _n += -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:319:5 + --> tests/ui/arithmetic_side_effects.rs:333:5 | LL | _n += &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:320:5 + --> tests/ui/arithmetic_side_effects.rs:335:5 | LL | _n -= -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:321:5 + --> tests/ui/arithmetic_side_effects.rs:337:5 | LL | _n -= &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:322:5 + --> tests/ui/arithmetic_side_effects.rs:339:5 | LL | _n /= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:323:5 + --> tests/ui/arithmetic_side_effects.rs:341:5 | LL | _n /= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:324:5 + --> tests/ui/arithmetic_side_effects.rs:343:5 | LL | _n %= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:325:5 + --> tests/ui/arithmetic_side_effects.rs:345:5 | LL | _n %= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:326:5 + --> tests/ui/arithmetic_side_effects.rs:347:5 | LL | _n *= -2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:327:5 + --> tests/ui/arithmetic_side_effects.rs:349:5 | LL | _n *= &-2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:328:5 + --> tests/ui/arithmetic_side_effects.rs:351:5 | LL | _custom += Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:329:5 + --> tests/ui/arithmetic_side_effects.rs:353:5 | LL | _custom += &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:330:5 + --> tests/ui/arithmetic_side_effects.rs:355:5 | LL | _custom -= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:331:5 + --> tests/ui/arithmetic_side_effects.rs:357:5 | LL | _custom -= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:332:5 + --> tests/ui/arithmetic_side_effects.rs:359:5 | LL | _custom /= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:333:5 + --> tests/ui/arithmetic_side_effects.rs:361:5 | LL | _custom /= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:334:5 + --> tests/ui/arithmetic_side_effects.rs:363:5 | LL | _custom %= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:335:5 + --> tests/ui/arithmetic_side_effects.rs:365:5 | LL | _custom %= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:336:5 + --> tests/ui/arithmetic_side_effects.rs:367:5 | LL | _custom *= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:337:5 + --> tests/ui/arithmetic_side_effects.rs:369:5 | LL | _custom *= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:338:5 + --> tests/ui/arithmetic_side_effects.rs:371:5 | LL | _custom >>= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:339:5 + --> tests/ui/arithmetic_side_effects.rs:373:5 | LL | _custom >>= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:340:5 + --> tests/ui/arithmetic_side_effects.rs:375:5 | LL | _custom <<= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:341:5 + --> tests/ui/arithmetic_side_effects.rs:377:5 | LL | _custom <<= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:342:5 + --> tests/ui/arithmetic_side_effects.rs:379:5 | LL | _custom += -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:343:5 + --> tests/ui/arithmetic_side_effects.rs:381:5 | LL | _custom += &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:344:5 + --> tests/ui/arithmetic_side_effects.rs:383:5 | LL | _custom -= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:345:5 + --> tests/ui/arithmetic_side_effects.rs:385:5 | LL | _custom -= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:346:5 + --> tests/ui/arithmetic_side_effects.rs:387:5 | LL | _custom /= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:347:5 + --> tests/ui/arithmetic_side_effects.rs:389:5 | LL | _custom /= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:348:5 + --> tests/ui/arithmetic_side_effects.rs:391:5 | LL | _custom %= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:349:5 + --> tests/ui/arithmetic_side_effects.rs:393:5 | LL | _custom %= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:350:5 + --> tests/ui/arithmetic_side_effects.rs:395:5 | LL | _custom *= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:351:5 + --> tests/ui/arithmetic_side_effects.rs:397:5 | LL | _custom *= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:352:5 + --> tests/ui/arithmetic_side_effects.rs:399:5 | LL | _custom >>= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:353:5 + --> tests/ui/arithmetic_side_effects.rs:401:5 | LL | _custom >>= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:354:5 + --> tests/ui/arithmetic_side_effects.rs:403:5 | LL | _custom <<= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:355:5 + --> tests/ui/arithmetic_side_effects.rs:405:5 | LL | _custom <<= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:358:10 + --> tests/ui/arithmetic_side_effects.rs:409:10 | LL | _n = _n + 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:359:10 + --> tests/ui/arithmetic_side_effects.rs:411:10 | LL | _n = _n + &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:360:10 + --> tests/ui/arithmetic_side_effects.rs:413:10 | LL | _n = 1 + _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:361:10 + --> tests/ui/arithmetic_side_effects.rs:415:10 | LL | _n = &1 + _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:362:10 + --> tests/ui/arithmetic_side_effects.rs:417:10 | LL | _n = _n - 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:363:10 + --> tests/ui/arithmetic_side_effects.rs:419:10 | LL | _n = _n - &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:364:10 + --> tests/ui/arithmetic_side_effects.rs:421:10 | LL | _n = 1 - _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:365:10 + --> tests/ui/arithmetic_side_effects.rs:423:10 | LL | _n = &1 - _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:366:10 + --> tests/ui/arithmetic_side_effects.rs:425:10 | LL | _n = _n / 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:367:10 + --> tests/ui/arithmetic_side_effects.rs:427:10 | LL | _n = _n / &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:368:10 + --> tests/ui/arithmetic_side_effects.rs:429:10 | LL | _n = _n % 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:369:10 + --> tests/ui/arithmetic_side_effects.rs:431:10 | LL | _n = _n % &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:370:10 + --> tests/ui/arithmetic_side_effects.rs:433:10 | LL | _n = _n * 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:371:10 + --> tests/ui/arithmetic_side_effects.rs:435:10 | LL | _n = _n * &2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:372:10 + --> tests/ui/arithmetic_side_effects.rs:437:10 | LL | _n = 2 * _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:373:10 + --> tests/ui/arithmetic_side_effects.rs:439:10 | LL | _n = &2 * _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:374:10 + --> tests/ui/arithmetic_side_effects.rs:441:10 | LL | _n = 23 + &85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:375:10 + --> tests/ui/arithmetic_side_effects.rs:443:10 | LL | _n = &23 + 85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:376:10 + --> tests/ui/arithmetic_side_effects.rs:445:10 | LL | _n = &23 + &85; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:377:15 + --> tests/ui/arithmetic_side_effects.rs:447:15 | LL | _custom = _custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:378:15 + --> tests/ui/arithmetic_side_effects.rs:449:15 | LL | _custom = _custom + &_custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:379:15 + --> tests/ui/arithmetic_side_effects.rs:451:15 | LL | _custom = Custom + _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:380:15 + --> tests/ui/arithmetic_side_effects.rs:453:15 | LL | _custom = &Custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:381:15 + --> tests/ui/arithmetic_side_effects.rs:455:15 | LL | _custom = _custom - Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:382:15 + --> tests/ui/arithmetic_side_effects.rs:457:15 | LL | _custom = _custom - &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:383:15 + --> tests/ui/arithmetic_side_effects.rs:459:15 | LL | _custom = Custom - _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:384:15 + --> tests/ui/arithmetic_side_effects.rs:461:15 | LL | _custom = &Custom - _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:385:15 + --> tests/ui/arithmetic_side_effects.rs:463:15 | LL | _custom = _custom / Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:386:15 + --> tests/ui/arithmetic_side_effects.rs:465:15 | LL | _custom = _custom / &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:387:15 + --> tests/ui/arithmetic_side_effects.rs:467:15 | LL | _custom = _custom % Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:388:15 + --> tests/ui/arithmetic_side_effects.rs:469:15 | LL | _custom = _custom % &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:389:15 + --> tests/ui/arithmetic_side_effects.rs:471:15 | LL | _custom = _custom * Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:390:15 + --> tests/ui/arithmetic_side_effects.rs:473:15 | LL | _custom = _custom * &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:391:15 + --> tests/ui/arithmetic_side_effects.rs:475:15 | LL | _custom = Custom * _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:392:15 + --> tests/ui/arithmetic_side_effects.rs:477:15 | LL | _custom = &Custom * _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:393:15 + --> tests/ui/arithmetic_side_effects.rs:479:15 | LL | _custom = Custom + &Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:394:15 + --> tests/ui/arithmetic_side_effects.rs:481:15 | LL | _custom = &Custom + Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:395:15 + --> tests/ui/arithmetic_side_effects.rs:483:15 | LL | _custom = &Custom + &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:396:15 + --> tests/ui/arithmetic_side_effects.rs:485:15 | LL | _custom = _custom >> _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:397:15 + --> tests/ui/arithmetic_side_effects.rs:487:15 | LL | _custom = _custom >> &_custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:398:15 + --> tests/ui/arithmetic_side_effects.rs:489:15 | LL | _custom = Custom << _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:399:15 + --> tests/ui/arithmetic_side_effects.rs:491:15 | LL | _custom = &Custom << _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:402:23 + --> tests/ui/arithmetic_side_effects.rs:495:23 | LL | _n.saturating_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:403:21 + --> tests/ui/arithmetic_side_effects.rs:497:21 | LL | _n.wrapping_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:404:21 + --> tests/ui/arithmetic_side_effects.rs:499:21 | LL | _n.wrapping_rem(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:405:28 + --> tests/ui/arithmetic_side_effects.rs:501:28 | LL | _n.wrapping_rem_euclid(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:407:23 + --> tests/ui/arithmetic_side_effects.rs:504:23 | LL | _n.saturating_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:408:21 + --> tests/ui/arithmetic_side_effects.rs:506:21 | LL | _n.wrapping_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:409:21 + --> tests/ui/arithmetic_side_effects.rs:508:21 | LL | _n.wrapping_rem(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:410:28 + --> tests/ui/arithmetic_side_effects.rs:510:28 | LL | _n.wrapping_rem_euclid(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:412:23 + --> tests/ui/arithmetic_side_effects.rs:513:23 | LL | _n.saturating_div(*Box::new(_n)); | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:415:10 + --> tests/ui/arithmetic_side_effects.rs:517:10 | LL | _n = -_n; | ^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:416:10 + --> tests/ui/arithmetic_side_effects.rs:519:10 | LL | _n = -&_n; | ^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:417:15 + --> tests/ui/arithmetic_side_effects.rs:521:15 | LL | _custom = -_custom; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:418:15 + --> tests/ui/arithmetic_side_effects.rs:523:15 | LL | _custom = -&_custom; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:419:9 + --> tests/ui/arithmetic_side_effects.rs:525:9 | LL | _ = -*Box::new(_n); | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:428:5 + --> tests/ui/arithmetic_side_effects.rs:535:5 | LL | 1 + i; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:429:5 + --> tests/ui/arithmetic_side_effects.rs:537:5 | LL | i * 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:430:5 + --> tests/ui/arithmetic_side_effects.rs:539:5 | LL | 1 % i / 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:431:5 + --> tests/ui/arithmetic_side_effects.rs:541:5 | LL | i - 2 + 2 - i; | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:432:5 + --> tests/ui/arithmetic_side_effects.rs:543:5 | LL | -i; | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:443:5 + --> tests/ui/arithmetic_side_effects.rs:555:5 | LL | i += 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:444:5 + --> tests/ui/arithmetic_side_effects.rs:557:5 | LL | i -= 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:445:5 + --> tests/ui/arithmetic_side_effects.rs:559:5 | LL | i *= 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:447:5 + --> tests/ui/arithmetic_side_effects.rs:562:5 | LL | i /= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:449:5 + --> tests/ui/arithmetic_side_effects.rs:565:5 | LL | i /= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:450:5 + --> tests/ui/arithmetic_side_effects.rs:567:5 | LL | i /= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:452:5 + --> tests/ui/arithmetic_side_effects.rs:570:5 | LL | i %= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:454:5 + --> tests/ui/arithmetic_side_effects.rs:573:5 | LL | i %= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:455:5 + --> tests/ui/arithmetic_side_effects.rs:575:5 | LL | i %= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:465:5 + --> tests/ui/arithmetic_side_effects.rs:586:5 | LL | 10 / a | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:519:9 + --> tests/ui/arithmetic_side_effects.rs:641:9 | LL | x / maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:523:9 + --> tests/ui/arithmetic_side_effects.rs:646:9 | LL | x % maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:534:5 + --> tests/ui/arithmetic_side_effects.rs:658:5 | LL | one.add_assign(1); | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:538:5 + --> tests/ui/arithmetic_side_effects.rs:663:5 | LL | one.sub_assign(1); | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:544:5 + --> tests/ui/arithmetic_side_effects.rs:670:5 | LL | one.add(&one); | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:545:5 + --> tests/ui/arithmetic_side_effects.rs:672:5 | LL | Box::new(one).add(one); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/as_conversions.rs b/tests/ui/as_conversions.rs index 8499c0ac5a0f..fba8913a2097 100644 --- a/tests/ui/as_conversions.rs +++ b/tests/ui/as_conversions.rs @@ -7,9 +7,11 @@ extern crate proc_macros; use proc_macros::{external, with_span}; fn main() { - let i = 0u32 as u64; + let i = 0u32 as u64; //~ as_conversions let j = &i as *const u64 as *mut u64; + //~^ as_conversions + //~| as_conversions external!(0u32 as u64); } diff --git a/tests/ui/as_pointer_underscore.fixed b/tests/ui/as_pointer_underscore.fixed index db06486ecb04..374c8a7f611a 100644 --- a/tests/ui/as_pointer_underscore.fixed +++ b/tests/ui/as_pointer_underscore.fixed @@ -6,10 +6,12 @@ struct S; fn f(s: &S) -> usize { &s as *const &S as usize - //~^ ERROR: using inferred pointer cast + //~^ as_pointer_underscore + } fn g(s: &mut S) -> usize { s as *mut S as usize - //~^ ERROR: using inferred pointer cast + //~^ as_pointer_underscore + } diff --git a/tests/ui/as_pointer_underscore.rs b/tests/ui/as_pointer_underscore.rs index 955c702ccc99..b194b3f473e2 100644 --- a/tests/ui/as_pointer_underscore.rs +++ b/tests/ui/as_pointer_underscore.rs @@ -6,10 +6,12 @@ struct S; fn f(s: &S) -> usize { &s as *const _ as usize - //~^ ERROR: using inferred pointer cast + //~^ as_pointer_underscore + } fn g(s: &mut S) -> usize { s as *mut _ as usize - //~^ ERROR: using inferred pointer cast + //~^ as_pointer_underscore + } diff --git a/tests/ui/as_pointer_underscore.stderr b/tests/ui/as_pointer_underscore.stderr index 270056f36454..fd9f061322b5 100644 --- a/tests/ui/as_pointer_underscore.stderr +++ b/tests/ui/as_pointer_underscore.stderr @@ -8,7 +8,7 @@ LL | &s as *const _ as usize = help: to override `-D warnings` add `#[allow(clippy::as_pointer_underscore)]` error: using inferred pointer cast - --> tests/ui/as_pointer_underscore.rs:13:10 + --> tests/ui/as_pointer_underscore.rs:14:10 | LL | s as *mut _ as usize | ^^^^^^ help: use explicit type: `*mut S` diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 9e862320f4ef..751e4a70b0fa 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -20,10 +20,12 @@ 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` + //~^ as_ptr_cast_mut + + let _: *mut i8 = string.as_ptr() as *mut _; - //~^ ERROR: casting the result of `as_ptr` to *mut i8 + //~^ as_ptr_cast_mut + 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 b3fc223ccdba..67dd7ddb8291 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -8,7 +8,7 @@ LL | let _ = string.as_ptr() as *mut u8; = help: to override `-D warnings` add `#[allow(clippy::as_ptr_cast_mut)]` error: casting the result of `as_ptr` to *mut i8 - --> tests/ui/as_ptr_cast_mut.rs:25:22 + --> tests/ui/as_ptr_cast_mut.rs:26: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 c7f26e64cce7..ca2a7f043286 100644 --- a/tests/ui/as_underscore.fixed +++ b/tests/ui/as_underscore.fixed @@ -5,7 +5,9 @@ fn foo(_n: usize) {} fn main() { let n: u16 = 256; foo(n as usize); + //~^ as_underscore let n = 0_u128; let _n: u8 = n as u8; + //~^ as_underscore } diff --git a/tests/ui/as_underscore.rs b/tests/ui/as_underscore.rs index 70f3b386631c..df500c4c4df1 100644 --- a/tests/ui/as_underscore.rs +++ b/tests/ui/as_underscore.rs @@ -5,7 +5,9 @@ fn foo(_n: usize) {} fn main() { let n: u16 = 256; foo(n as _); + //~^ as_underscore let n = 0_u128; let _n: u8 = n as _; + //~^ as_underscore } diff --git a/tests/ui/as_underscore.stderr b/tests/ui/as_underscore.stderr index dba56a2a8af3..02c10feb78eb 100644 --- a/tests/ui/as_underscore.stderr +++ b/tests/ui/as_underscore.stderr @@ -10,7 +10,7 @@ LL | foo(n as _); = help: to override `-D warnings` add `#[allow(clippy::as_underscore)]` error: using `as _` conversion - --> tests/ui/as_underscore.rs:10:18 + --> tests/ui/as_underscore.rs:11:18 | LL | let _n: u8 = n as _; | ^^^^^- diff --git a/tests/ui/asm_syntax_not_x86.rs b/tests/ui/asm_syntax_not_x86.rs index a7d29cc239e5..91fde12680cc 100644 --- a/tests/ui/asm_syntax_not_x86.rs +++ b/tests/ui/asm_syntax_not_x86.rs @@ -8,12 +8,17 @@ mod dont_warn { pub(super) unsafe fn use_asm() { asm!(""); + //~^ inline_asm_x86_intel_syntax asm!("", options()); + //~^ inline_asm_x86_intel_syntax asm!("", options(nostack)); + //~^ inline_asm_x86_intel_syntax } global_asm!(""); + //~^ inline_asm_x86_intel_syntax global_asm!("", options()); + //~^ inline_asm_x86_intel_syntax } fn main() { diff --git a/tests/ui/asm_syntax_x86.rs b/tests/ui/asm_syntax_x86.rs index 5ceaceb7527b..0d30b95dcf5e 100644 --- a/tests/ui/asm_syntax_x86.rs +++ b/tests/ui/asm_syntax_x86.rs @@ -6,19 +6,24 @@ mod warn_intel { pub(super) unsafe fn use_asm() { asm!(""); - //~^ ERROR: Intel x86 assembly syntax used + //~^ inline_asm_x86_intel_syntax + asm!("", options()); - //~^ ERROR: Intel x86 assembly syntax used + //~^ inline_asm_x86_intel_syntax + asm!("", options(nostack)); - //~^ ERROR: Intel x86 assembly syntax used + //~^ inline_asm_x86_intel_syntax + asm!("", options(att_syntax)); asm!("", options(nostack, att_syntax)); } global_asm!(""); - //~^ ERROR: Intel x86 assembly syntax used + //~^ inline_asm_x86_intel_syntax + global_asm!("", options()); - //~^ ERROR: Intel x86 assembly syntax used + //~^ inline_asm_x86_intel_syntax + global_asm!("", options(att_syntax)); } @@ -31,15 +36,18 @@ mod warn_att { asm!("", options()); asm!("", options(nostack)); asm!("", options(att_syntax)); - //~^ ERROR: AT&T x86 assembly syntax used + //~^ inline_asm_x86_att_syntax + asm!("", options(nostack, att_syntax)); - //~^ ERROR: AT&T x86 assembly syntax used + //~^ inline_asm_x86_att_syntax + } global_asm!(""); global_asm!("", options()); global_asm!("", options(att_syntax)); - //~^ ERROR: AT&T x86 assembly syntax used + //~^ inline_asm_x86_att_syntax + } fn main() { diff --git a/tests/ui/asm_syntax_x86.stderr b/tests/ui/asm_syntax_x86.stderr index 1911ef66e239..8e1992b66bca 100644 --- a/tests/ui/asm_syntax_x86.stderr +++ b/tests/ui/asm_syntax_x86.stderr @@ -9,7 +9,7 @@ LL | asm!(""); = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_intel_syntax)]` error: Intel x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:10:9 + --> tests/ui/asm_syntax_x86.rs:11:9 | LL | asm!("", options()); | ^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | asm!("", options()); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:12:9 + --> tests/ui/asm_syntax_x86.rs:14:9 | LL | asm!("", options(nostack)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | asm!("", options(nostack)); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:18:5 + --> tests/ui/asm_syntax_x86.rs:21:5 | LL | global_asm!(""); | ^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | global_asm!(""); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:20:5 + --> tests/ui/asm_syntax_x86.rs:24:5 | LL | global_asm!("", options()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | global_asm!("", options()); = help: use AT&T x86 assembly syntax error: AT&T x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:33:9 + --> tests/ui/asm_syntax_x86.rs:38:9 | LL | asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL | asm!("", options(att_syntax)); = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_att_syntax)]` error: AT&T x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:35:9 + --> tests/ui/asm_syntax_x86.rs:41:9 | LL | asm!("", options(nostack, att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,7 +59,7 @@ LL | asm!("", options(nostack, att_syntax)); = help: use Intel x86 assembly syntax error: AT&T x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:41:5 + --> tests/ui/asm_syntax_x86.rs:48:5 | LL | global_asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 957154e60dec..96b9c16d4303 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -8,30 +8,39 @@ macro_rules! assert_const { } fn main() { assert!(true); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + assert!(false); - //~^ ERROR: `assert!(false)` should probably be replaced + //~^ assertions_on_constants + assert!(true, "true message"); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + assert!(false, "false message"); - //~^ ERROR: `assert!(false, ..)` should probably be replaced + //~^ assertions_on_constants + let msg = "panic message"; assert!(false, "{}", msg.to_uppercase()); - //~^ ERROR: `assert!(false, ..)` should probably be replaced + //~^ assertions_on_constants + const B: bool = true; assert!(B); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + const C: bool = false; assert!(C); - //~^ ERROR: `assert!(false)` should probably be replaced + //~^ assertions_on_constants + assert!(C, "C message"); - //~^ ERROR: `assert!(false, ..)` should probably be replaced + //~^ assertions_on_constants + debug_assert!(true); - //~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + // Don't lint this, since there is no better way for expressing "Only panic in debug mode". debug_assert!(false); // #3948 assert_const!(3); @@ -47,10 +56,12 @@ fn main() { assert!(!CFG_FLAG); const _: () = assert!(true); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + assert!(8 == (7 + 1)); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + // Don't lint if the value is dependent on a defined constant: const N: usize = 1024; @@ -59,6 +70,7 @@ fn main() { const _: () = { assert!(true); - //~^ ERROR: `assert!(true)` will be optimized out by the compiler + //~^ assertions_on_constants + assert!(8 == (7 + 1)); }; diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index e164a999c43e..b0e6496982f9 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -9,7 +9,7 @@ LL | assert!(true); = help: to override `-D warnings` add `#[allow(clippy::assertions_on_constants)]` error: `assert!(false)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:12:5 + --> tests/ui/assertions_on_constants.rs:13:5 | LL | assert!(false); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | assert!(false); = help: use `panic!()` or `unreachable!()` error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:14:5 + --> tests/ui/assertions_on_constants.rs:16:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | assert!(true, "true message"); = help: remove it error: `assert!(false, ..)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:16:5 + --> tests/ui/assertions_on_constants.rs:19:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | assert!(false, "false message"); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(false, ..)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:20:5 + --> tests/ui/assertions_on_constants.rs:24:5 | LL | assert!(false, "{}", msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | assert!(false, "{}", msg.to_uppercase()); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:24:5 + --> tests/ui/assertions_on_constants.rs:29:5 | LL | assert!(B); | ^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | assert!(B); = help: remove it error: `assert!(false)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:28:5 + --> tests/ui/assertions_on_constants.rs:34:5 | LL | assert!(C); | ^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | assert!(C); = help: use `panic!()` or `unreachable!()` error: `assert!(false, ..)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:30:5 + --> tests/ui/assertions_on_constants.rs:37:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | assert!(C, "C message"); = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:33:5 + --> tests/ui/assertions_on_constants.rs:41:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | debug_assert!(true); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:49:19 + --> tests/ui/assertions_on_constants.rs:58:19 | LL | const _: () = assert!(true); | ^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | const _: () = assert!(true); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:52:5 + --> tests/ui/assertions_on_constants.rs:62:5 | LL | assert!(8 == (7 + 1)); | ^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | assert!(8 == (7 + 1)); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:61:5 + --> tests/ui/assertions_on_constants.rs:72:5 | LL | assert!(true); | ^^^^^^^^^^^^^ diff --git a/tests/ui/assertions_on_result_states.fixed b/tests/ui/assertions_on_result_states.fixed index 14d9b8b99d5e..09c1a8d0ed1d 100644 --- a/tests/ui/assertions_on_result_states.fixed +++ b/tests/ui/assertions_on_result_states.fixed @@ -22,6 +22,7 @@ fn main() { let r: Result = Ok(Foo); debug_assert!(r.is_ok()); r.unwrap(); + //~^ assertions_on_result_states // test ok with non-debug error type let r: Result = Ok(Foo); @@ -40,9 +41,11 @@ fn main() { Ok(Foo) } get_ok().unwrap(); + //~^ assertions_on_result_states // test macro ok get_ok_macro!().unwrap(); + //~^ assertions_on_result_states // test ok that shouldn't be moved let r: Result = Ok(CopyFoo); @@ -56,12 +59,14 @@ fn main() { // test ok that is copied let r: Result = Ok(CopyFoo); r.unwrap(); + //~^ assertions_on_result_states r.unwrap(); // test reference to ok let r: Result = Ok(CopyFoo); fn test_ref_copy_ok(r: &Result) { r.unwrap(); + //~^ assertions_on_result_states } test_ref_copy_ok(&r); r.unwrap(); @@ -70,6 +75,7 @@ fn main() { let r: Result = Err(Foo); debug_assert!(r.is_err()); r.unwrap_err(); + //~^ assertions_on_result_states // test err with non-debug value type let r: Result = Err(Foo); @@ -80,4 +86,5 @@ fn main() { fn issue9450() { let res: Result = Ok(1); res.unwrap_err(); + //~^ assertions_on_result_states } diff --git a/tests/ui/assertions_on_result_states.rs b/tests/ui/assertions_on_result_states.rs index ac1911d87c93..c63c2502b537 100644 --- a/tests/ui/assertions_on_result_states.rs +++ b/tests/ui/assertions_on_result_states.rs @@ -22,6 +22,7 @@ fn main() { let r: Result = Ok(Foo); debug_assert!(r.is_ok()); assert!(r.is_ok()); + //~^ assertions_on_result_states // test ok with non-debug error type let r: Result = Ok(Foo); @@ -40,9 +41,11 @@ fn main() { Ok(Foo) } assert!(get_ok().is_ok()); + //~^ assertions_on_result_states // test macro ok assert!(get_ok_macro!().is_ok()); + //~^ assertions_on_result_states // test ok that shouldn't be moved let r: Result = Ok(CopyFoo); @@ -56,12 +59,14 @@ fn main() { // test ok that is copied let r: Result = Ok(CopyFoo); assert!(r.is_ok()); + //~^ assertions_on_result_states r.unwrap(); // test reference to ok let r: Result = Ok(CopyFoo); fn test_ref_copy_ok(r: &Result) { assert!(r.is_ok()); + //~^ assertions_on_result_states } test_ref_copy_ok(&r); r.unwrap(); @@ -70,6 +75,7 @@ fn main() { let r: Result = Err(Foo); debug_assert!(r.is_err()); assert!(r.is_err()); + //~^ assertions_on_result_states // test err with non-debug value type let r: Result = Err(Foo); @@ -80,4 +86,5 @@ fn main() { fn issue9450() { let res: Result = Ok(1); assert!(res.is_err()) + //~^ assertions_on_result_states } diff --git a/tests/ui/assertions_on_result_states.stderr b/tests/ui/assertions_on_result_states.stderr index a2bddc7025a9..3bf811588c69 100644 --- a/tests/ui/assertions_on_result_states.stderr +++ b/tests/ui/assertions_on_result_states.stderr @@ -8,37 +8,37 @@ LL | assert!(r.is_ok()); = help: to override `-D warnings` add `#[allow(clippy::assertions_on_result_states)]` error: called `assert!` with `Result::is_ok` - --> tests/ui/assertions_on_result_states.rs:42:5 + --> tests/ui/assertions_on_result_states.rs:43:5 | LL | assert!(get_ok().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok().unwrap()` error: called `assert!` with `Result::is_ok` - --> tests/ui/assertions_on_result_states.rs:45:5 + --> tests/ui/assertions_on_result_states.rs:47:5 | LL | assert!(get_ok_macro!().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok_macro!().unwrap()` error: called `assert!` with `Result::is_ok` - --> tests/ui/assertions_on_result_states.rs:58:5 + --> tests/ui/assertions_on_result_states.rs:61:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_ok` - --> tests/ui/assertions_on_result_states.rs:64:9 + --> tests/ui/assertions_on_result_states.rs:68:9 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_err` - --> tests/ui/assertions_on_result_states.rs:72:5 + --> tests/ui/assertions_on_result_states.rs:77:5 | LL | assert!(r.is_err()); | ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()` error: called `assert!` with `Result::is_err` - --> tests/ui/assertions_on_result_states.rs:82:5 + --> tests/ui/assertions_on_result_states.rs:88: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 2bd0807f4262..18f0e04a8807 100644 --- a/tests/ui/assign_ops.fixed +++ b/tests/ui/assign_ops.fixed @@ -5,25 +5,36 @@ use core::num::Wrapping; fn main() { let mut a = 5; a += 1; + //~^ assign_op_pattern a += 1; + //~^ assign_op_pattern a -= 1; + //~^ assign_op_pattern a *= 99; + //~^ assign_op_pattern a *= 42; + //~^ assign_op_pattern a /= 2; + //~^ assign_op_pattern a %= 5; + //~^ assign_op_pattern a &= 1; + //~^ assign_op_pattern a = 1 - a; a = 5 / a; a = 42 % a; a = 6 << a; let mut s = String::new(); s += "bla"; + //~^ assign_op_pattern // Issue #9180 let mut a = Wrapping(0u32); a += Wrapping(1u32); + //~^ assign_op_pattern let mut v = vec![0u32, 1u32]; v[0] += v[1]; + //~^ assign_op_pattern let mut v = vec![Wrapping(0u32), Wrapping(1u32)]; v[0] = v[0] + v[1]; let _ = || v[0] = v[0] + v[1]; diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index be3491a44c7e..8b05c74d8604 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -5,25 +5,36 @@ use core::num::Wrapping; fn main() { let mut a = 5; a = a + 1; + //~^ assign_op_pattern a = 1 + a; + //~^ assign_op_pattern a = a - 1; + //~^ assign_op_pattern a = a * 99; + //~^ assign_op_pattern a = 42 * a; + //~^ assign_op_pattern a = a / 2; + //~^ assign_op_pattern a = a % 5; + //~^ assign_op_pattern a = a & 1; + //~^ assign_op_pattern a = 1 - a; a = 5 / a; a = 42 % a; a = 6 << a; let mut s = String::new(); s = s + "bla"; + //~^ assign_op_pattern // Issue #9180 let mut a = Wrapping(0u32); a = a + Wrapping(1u32); + //~^ assign_op_pattern let mut v = vec![0u32, 1u32]; v[0] = v[0] + v[1]; + //~^ assign_op_pattern let mut v = vec![Wrapping(0u32), Wrapping(1u32)]; v[0] = v[0] + v[1]; let _ = || v[0] = v[0] + v[1]; diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr index 4975ac5911fd..17f216ee4a07 100644 --- a/tests/ui/assign_ops.stderr +++ b/tests/ui/assign_ops.stderr @@ -8,61 +8,61 @@ LL | a = a + 1; = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:8:5 + --> tests/ui/assign_ops.rs:9:5 | LL | a = 1 + a; | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:9:5 + --> tests/ui/assign_ops.rs:11:5 | LL | a = a - 1; | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:10:5 + --> tests/ui/assign_ops.rs:13:5 | LL | a = a * 99; | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:11:5 + --> tests/ui/assign_ops.rs:15:5 | LL | a = 42 * a; | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:12:5 + --> tests/ui/assign_ops.rs:17:5 | LL | a = a / 2; | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:13:5 + --> tests/ui/assign_ops.rs:19:5 | LL | a = a % 5; | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:14:5 + --> tests/ui/assign_ops.rs:21:5 | LL | a = a & 1; | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:20:5 + --> tests/ui/assign_ops.rs:28:5 | LL | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:24:5 + --> tests/ui/assign_ops.rs:33:5 | LL | a = a + Wrapping(1u32); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:26:5 + --> tests/ui/assign_ops.rs:36: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 a53556425849..7cac9f51ea4e 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -6,24 +6,33 @@ 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` + //~^ misrefactored_assign_op + + a += 1 + a; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a -= a - 1; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a *= a * 99; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a *= 42 * a; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a /= a / 2; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a %= a % 5; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a &= a & 1; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a *= a * a; - //~^ ERROR: variable appears on both sides of an assignment operation + //~^ misrefactored_assign_op + a = a * a * a; a = a * 42 * a; a = a * 2 + a; @@ -61,8 +70,9 @@ 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` + //~^ assign_op_pattern + + // 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 ddeba2b2ff8f..56b5219dd646 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -16,7 +16,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:11:5 + --> tests/ui/assign_ops2.rs:12:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:13:5 + --> tests/ui/assign_ops2.rs:15:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:15:5 + --> tests/ui/assign_ops2.rs:18:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:17:5 + --> tests/ui/assign_ops2.rs:21:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:19:5 + --> tests/ui/assign_ops2.rs:24:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:21:5 + --> tests/ui/assign_ops2.rs:27:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:23:5 + --> tests/ui/assign_ops2.rs:30:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:25:5 + --> tests/ui/assign_ops2.rs:33:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> tests/ui/assign_ops2.rs:63:5 + --> tests/ui/assign_ops2.rs:72:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` diff --git a/tests/ui/assigning_clones.fixed b/tests/ui/assigning_clones.fixed index 09732d1a50ce..9e44008e6fab 100644 --- a/tests/ui/assigning_clones.fixed +++ b/tests/ui/assigning_clones.fixed @@ -23,60 +23,73 @@ impl Clone for HasCloneFrom { fn clone_method_rhs_val(mut_thing: &mut HasCloneFrom, value_thing: HasCloneFrom) { mut_thing.clone_from(&value_thing); + //~^ assigning_clones } fn clone_method_rhs_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { mut_thing.clone_from(ref_thing); + //~^ assigning_clones } fn clone_method_lhs_val(mut mut_thing: HasCloneFrom, ref_thing: &HasCloneFrom) { mut_thing.clone_from(ref_thing); + //~^ assigning_clones } fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { Clone::clone_from(mut_thing, ref_thing); + //~^ assigning_clones } fn clone_function_lhs_val(mut mut_thing: HasCloneFrom, ref_thing: &HasCloneFrom) { Clone::clone_from(&mut mut_thing, ref_thing); + //~^ assigning_clones } fn clone_function_through_trait(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { Clone::clone_from(mut_thing, ref_thing); + //~^ assigning_clones } fn clone_function_through_type(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { Clone::clone_from(mut_thing, ref_thing); + //~^ assigning_clones } fn clone_function_fully_qualified(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { Clone::clone_from(mut_thing, ref_thing); + //~^ assigning_clones } fn clone_method_lhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { // These parens should be kept as necessary for a receiver (mut_thing + &mut HasCloneFrom).clone_from(ref_thing); + //~^ assigning_clones } fn clone_method_rhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { // These parens should be removed since they are not needed in a function argument mut_thing.clone_from(ref_thing + ref_thing); + //~^ assigning_clones } fn clone_method_macro() { let mut s = String::from(""); s.clone_from(&format!("{} {}", "hello", "world")); + //~^ assigning_clones } fn clone_function_macro() { let mut s = String::from(""); Clone::clone_from(&mut s, &format!("{} {}", "hello", "world")); + //~^ assigning_clones } fn assign_to_init_mut_var(b: HasCloneFrom) -> HasCloneFrom { let mut a = HasCloneFrom; for _ in 1..10 { a.clone_from(&b); + //~^ assigning_clones } a } @@ -148,6 +161,7 @@ fn ignore_generic_clone(a: &mut T, b: &T) { #[clippy::msrv = "1.62"] fn msrv_1_62(mut a: String, b: String, c: &str) { a.clone_from(&b); + //~^ assigning_clones // Should not be linted, as clone_into wasn't stabilized until 1.63 a = c.to_owned(); } @@ -155,7 +169,9 @@ fn msrv_1_62(mut a: String, b: String, c: &str) { #[clippy::msrv = "1.63"] fn msrv_1_63(mut a: String, b: String, c: &str) { a.clone_from(&b); + //~^ assigning_clones c.clone_into(&mut a); + //~^ assigning_clones } macro_rules! clone_inside { @@ -186,35 +202,43 @@ impl Clone for AvoidRecursiveCloneFrom { // Deref handling fn clone_into_deref_method(mut a: DerefWrapper, b: HasCloneFrom) { (*a).clone_from(&b); + //~^ assigning_clones } fn clone_into_deref_with_clone_method(mut a: DerefWrapperWithClone, b: HasCloneFrom) { (*a).clone_from(&b); + //~^ assigning_clones } fn clone_into_box_method(mut a: Box, b: HasCloneFrom) { (*a).clone_from(&b); + //~^ assigning_clones } fn clone_into_self_deref_method(a: &mut DerefWrapperWithClone, b: DerefWrapperWithClone) { a.clone_from(&b); + //~^ assigning_clones } fn clone_into_deref_function(mut a: DerefWrapper, b: HasCloneFrom) { Clone::clone_from(&mut *a, &b); + //~^ assigning_clones } fn clone_into_box_function(mut a: Box, b: HasCloneFrom) { Clone::clone_from(&mut *a, &b); + //~^ assigning_clones } // ToOwned fn owned_method_mut_ref(mut_string: &mut String, ref_str: &str) { ref_str.clone_into(mut_string); + //~^ assigning_clones } fn owned_method_val(mut mut_string: String, ref_str: &str) { ref_str.clone_into(&mut mut_string); + //~^ assigning_clones } struct HasDeref { @@ -236,28 +260,34 @@ impl DerefMut for HasDeref { fn owned_method_box(mut_box_string: &mut Box, ref_str: &str) { ref_str.clone_into(&mut (*mut_box_string)); + //~^ assigning_clones } fn owned_method_deref(mut_box_string: &mut HasDeref, ref_str: &str) { ref_str.clone_into(&mut (*mut_box_string)); + //~^ assigning_clones } fn owned_function_mut_ref(mut_thing: &mut String, ref_str: &str) { ToOwned::clone_into(ref_str, mut_thing); + //~^ assigning_clones } fn owned_function_val(mut mut_thing: String, ref_str: &str) { ToOwned::clone_into(ref_str, &mut mut_thing); + //~^ assigning_clones } fn owned_method_macro() { let mut s = String::from(""); format!("{} {}", "hello", "world").clone_into(&mut s); + //~^ assigning_clones } fn owned_function_macro() { let mut s = String::from(""); ToOwned::clone_into(&format!("{} {}", "hello", "world"), &mut s); + //~^ assigning_clones } struct FakeToOwned; diff --git a/tests/ui/assigning_clones.rs b/tests/ui/assigning_clones.rs index 6be25ae17a55..8ae8abfed367 100644 --- a/tests/ui/assigning_clones.rs +++ b/tests/ui/assigning_clones.rs @@ -23,60 +23,73 @@ impl Clone for HasCloneFrom { fn clone_method_rhs_val(mut_thing: &mut HasCloneFrom, value_thing: HasCloneFrom) { *mut_thing = value_thing.clone(); + //~^ assigning_clones } fn clone_method_rhs_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { *mut_thing = ref_thing.clone(); + //~^ assigning_clones } fn clone_method_lhs_val(mut mut_thing: HasCloneFrom, ref_thing: &HasCloneFrom) { mut_thing = ref_thing.clone(); + //~^ assigning_clones } fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { *mut_thing = Clone::clone(ref_thing); + //~^ assigning_clones } fn clone_function_lhs_val(mut mut_thing: HasCloneFrom, ref_thing: &HasCloneFrom) { mut_thing = Clone::clone(ref_thing); + //~^ assigning_clones } fn clone_function_through_trait(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { *mut_thing = Clone::clone(ref_thing); + //~^ assigning_clones } fn clone_function_through_type(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { *mut_thing = HasCloneFrom::clone(ref_thing); + //~^ assigning_clones } fn clone_function_fully_qualified(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { *mut_thing = ::clone(ref_thing); + //~^ assigning_clones } fn clone_method_lhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { // These parens should be kept as necessary for a receiver *(mut_thing + &mut HasCloneFrom) = ref_thing.clone(); + //~^ assigning_clones } fn clone_method_rhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) { // These parens should be removed since they are not needed in a function argument *mut_thing = (ref_thing + ref_thing).clone(); + //~^ assigning_clones } fn clone_method_macro() { let mut s = String::from(""); s = format!("{} {}", "hello", "world").clone(); + //~^ assigning_clones } fn clone_function_macro() { let mut s = String::from(""); s = Clone::clone(&format!("{} {}", "hello", "world")); + //~^ assigning_clones } fn assign_to_init_mut_var(b: HasCloneFrom) -> HasCloneFrom { let mut a = HasCloneFrom; for _ in 1..10 { a = b.clone(); + //~^ assigning_clones } a } @@ -148,6 +161,7 @@ fn ignore_generic_clone(a: &mut T, b: &T) { #[clippy::msrv = "1.62"] fn msrv_1_62(mut a: String, b: String, c: &str) { a = b.clone(); + //~^ assigning_clones // Should not be linted, as clone_into wasn't stabilized until 1.63 a = c.to_owned(); } @@ -155,7 +169,9 @@ fn msrv_1_62(mut a: String, b: String, c: &str) { #[clippy::msrv = "1.63"] fn msrv_1_63(mut a: String, b: String, c: &str) { a = b.clone(); + //~^ assigning_clones a = c.to_owned(); + //~^ assigning_clones } macro_rules! clone_inside { @@ -186,35 +202,43 @@ impl Clone for AvoidRecursiveCloneFrom { // Deref handling fn clone_into_deref_method(mut a: DerefWrapper, b: HasCloneFrom) { *a = b.clone(); + //~^ assigning_clones } fn clone_into_deref_with_clone_method(mut a: DerefWrapperWithClone, b: HasCloneFrom) { *a = b.clone(); + //~^ assigning_clones } fn clone_into_box_method(mut a: Box, b: HasCloneFrom) { *a = b.clone(); + //~^ assigning_clones } fn clone_into_self_deref_method(a: &mut DerefWrapperWithClone, b: DerefWrapperWithClone) { *a = b.clone(); + //~^ assigning_clones } fn clone_into_deref_function(mut a: DerefWrapper, b: HasCloneFrom) { *a = Clone::clone(&b); + //~^ assigning_clones } fn clone_into_box_function(mut a: Box, b: HasCloneFrom) { *a = Clone::clone(&b); + //~^ assigning_clones } // ToOwned fn owned_method_mut_ref(mut_string: &mut String, ref_str: &str) { *mut_string = ref_str.to_owned(); + //~^ assigning_clones } fn owned_method_val(mut mut_string: String, ref_str: &str) { mut_string = ref_str.to_owned(); + //~^ assigning_clones } struct HasDeref { @@ -236,28 +260,34 @@ impl DerefMut for HasDeref { fn owned_method_box(mut_box_string: &mut Box, ref_str: &str) { **mut_box_string = ref_str.to_owned(); + //~^ assigning_clones } fn owned_method_deref(mut_box_string: &mut HasDeref, ref_str: &str) { **mut_box_string = ref_str.to_owned(); + //~^ assigning_clones } fn owned_function_mut_ref(mut_thing: &mut String, ref_str: &str) { *mut_thing = ToOwned::to_owned(ref_str); + //~^ assigning_clones } fn owned_function_val(mut mut_thing: String, ref_str: &str) { mut_thing = ToOwned::to_owned(ref_str); + //~^ assigning_clones } fn owned_method_macro() { let mut s = String::from(""); s = format!("{} {}", "hello", "world").to_owned(); + //~^ assigning_clones } fn owned_function_macro() { let mut s = String::from(""); s = ToOwned::to_owned(&format!("{} {}", "hello", "world")); + //~^ assigning_clones } struct FakeToOwned; diff --git a/tests/ui/assigning_clones.stderr b/tests/ui/assigning_clones.stderr index 19724a6d4ec2..2714d599b28a 100644 --- a/tests/ui/assigning_clones.stderr +++ b/tests/ui/assigning_clones.stderr @@ -8,175 +8,175 @@ LL | *mut_thing = value_thing.clone(); = help: to override `-D warnings` add `#[allow(clippy::assigning_clones)]` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:29:5 + --> tests/ui/assigning_clones.rs:30:5 | LL | *mut_thing = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:33:5 + --> tests/ui/assigning_clones.rs:35:5 | LL | mut_thing = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:37:5 + --> tests/ui/assigning_clones.rs:40:5 | LL | *mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:41:5 + --> tests/ui/assigning_clones.rs:45:5 | LL | mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:45:5 + --> tests/ui/assigning_clones.rs:50:5 | LL | *mut_thing = Clone::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:49:5 + --> tests/ui/assigning_clones.rs:55:5 | LL | *mut_thing = HasCloneFrom::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:53:5 + --> tests/ui/assigning_clones.rs:60:5 | LL | *mut_thing = ::clone(ref_thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(mut_thing, ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:58:5 + --> tests/ui/assigning_clones.rs:66:5 | LL | *(mut_thing + &mut HasCloneFrom) = ref_thing.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `(mut_thing + &mut HasCloneFrom).clone_from(ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:63:5 + --> tests/ui/assigning_clones.rs:72:5 | LL | *mut_thing = (ref_thing + ref_thing).clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing + ref_thing)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:68:5 + --> tests/ui/assigning_clones.rs:78:5 | LL | s = format!("{} {}", "hello", "world").clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `s.clone_from(&format!("{} {}", "hello", "world"))` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:73:5 + --> tests/ui/assigning_clones.rs:84:5 | LL | s = Clone::clone(&format!("{} {}", "hello", "world")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut s, &format!("{} {}", "hello", "world"))` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:79:9 + --> tests/ui/assigning_clones.rs:91:9 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:150:5 + --> tests/ui/assigning_clones.rs:163:5 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:157:5 + --> tests/ui/assigning_clones.rs:171:5 | LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:158:5 + --> tests/ui/assigning_clones.rs:173:5 | LL | a = c.to_owned(); | ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `c.clone_into(&mut a)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:188:5 + --> tests/ui/assigning_clones.rs:204:5 | LL | *a = b.clone(); | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:192:5 + --> tests/ui/assigning_clones.rs:209:5 | LL | *a = b.clone(); | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:196:5 + --> tests/ui/assigning_clones.rs:214:5 | LL | *a = b.clone(); | ^^^^^^^^^^^^^^ help: use `clone_from()`: `(*a).clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:200:5 + --> tests/ui/assigning_clones.rs:219:5 | LL | *a = b.clone(); | ^^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:204:5 + --> tests/ui/assigning_clones.rs:224:5 | LL | *a = Clone::clone(&b); | ^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut *a, &b)` error: assigning the result of `Clone::clone()` may be inefficient - --> tests/ui/assigning_clones.rs:208:5 + --> tests/ui/assigning_clones.rs:229:5 | LL | *a = Clone::clone(&b); | ^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut *a, &b)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:213:5 + --> tests/ui/assigning_clones.rs:235:5 | LL | *mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:217:5 + --> tests/ui/assigning_clones.rs:240:5 | LL | mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:238:5 + --> tests/ui/assigning_clones.rs:262:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:242:5 + --> tests/ui/assigning_clones.rs:267:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:246:5 + --> tests/ui/assigning_clones.rs:272:5 | LL | *mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:250:5 + --> tests/ui/assigning_clones.rs:277:5 | LL | mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:255:5 + --> tests/ui/assigning_clones.rs:283:5 | LL | s = format!("{} {}", "hello", "world").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `format!("{} {}", "hello", "world").clone_into(&mut s)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:260:5 + --> tests/ui/assigning_clones.rs:289:5 | LL | s = ToOwned::to_owned(&format!("{} {}", "hello", "world")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(&format!("{} {}", "hello", "world"), &mut s)` diff --git a/tests/ui/async_yields_async.fixed b/tests/ui/async_yields_async.fixed index 48402164a827..93c573d30863 100644 --- a/tests/ui/async_yields_async.fixed +++ b/tests/ui/async_yields_async.fixed @@ -38,9 +38,11 @@ fn main() { 3 }.await }; + //~^^^^ async_yields_async let _i = async { CustomFutureType.await }; + //~^^ async_yields_async let _i = async || { 3 }; @@ -49,10 +51,13 @@ fn main() { 3 }.await }; + //~^^^^ async_yields_async let _k = async || { CustomFutureType.await }; + //~^^ async_yields_async let _l = async || CustomFutureType.await; + //~^ async_yields_async let _m = async || { println!("I'm bored"); // Some more stuff @@ -60,6 +65,7 @@ fn main() { // Finally something to await CustomFutureType.await }; + //~^^ async_yields_async let _n = async || custom_future_type_ctor(); let _o = async || f(); } diff --git a/tests/ui/async_yields_async.rs b/tests/ui/async_yields_async.rs index 8ad016b6bb4e..166d522e1c04 100644 --- a/tests/ui/async_yields_async.rs +++ b/tests/ui/async_yields_async.rs @@ -38,9 +38,11 @@ fn main() { 3 } }; + //~^^^^ async_yields_async let _i = async { CustomFutureType }; + //~^^ async_yields_async let _i = async || { 3 }; @@ -49,10 +51,13 @@ fn main() { 3 } }; + //~^^^^ async_yields_async let _k = async || { CustomFutureType }; + //~^^ async_yields_async let _l = async || CustomFutureType; + //~^ async_yields_async let _m = async || { println!("I'm bored"); // Some more stuff @@ -60,6 +65,7 @@ fn main() { // Finally something to await CustomFutureType }; + //~^^ async_yields_async let _n = async || custom_future_type_ctor(); let _o = async || f(); } diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 474914299d06..01533268a515 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -20,7 +20,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:42:9 + --> tests/ui/async_yields_async.rs:43:9 | LL | let _i = async { | ____________________- @@ -33,7 +33,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:48:9 + --> tests/ui/async_yields_async.rs:50:9 | LL | let _j = async || { | ________________________- @@ -52,7 +52,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:53:9 + --> tests/ui/async_yields_async.rs:56:9 | LL | let _k = async || { | _______________________- @@ -65,7 +65,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:55:23 + --> tests/ui/async_yields_async.rs:59:23 | LL | let _l = async || CustomFutureType; | ^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | let _l = async || CustomFutureType; | help: consider awaiting this value: `CustomFutureType.await` error: an async construct yields a type which is itself awaitable - --> tests/ui/async_yields_async.rs:61:9 + --> tests/ui/async_yields_async.rs:66:9 | LL | let _m = async || { | _______________________- diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index da96eabede17..6f08bb304260 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -3,8 +3,9 @@ #![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` +//~^ inline_always + + fn test_attr_lint() { assert!(true) } @@ -25,12 +26,14 @@ 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` +//~^ deprecated_semver + + pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] -//~^ ERROR: the since field must contain a semver-compliant version +//~^ deprecated_semver + pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index a7fdceaba6f3..74d4068f6331 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -1,5 +1,5 @@ error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:27:14 + --> tests/ui/attrs.rs:28:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -8,11 +8,29 @@ LL | #[deprecated(since = "forever")] = help: to override `-D warnings` add `#[allow(clippy::deprecated_semver)]` error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:32:14 + --> tests/ui/attrs.rs:34:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ +error: empty lines after outer attribute + --> tests/ui/attrs.rs:5:1 + | +LL | / #[inline(always)] +... | +LL | | + | |_^ +LL | fn test_attr_lint() { + | ------------------- the attribute applies to this function + | + = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` + = help: if the empty lines are unintentional remove them +help: if the attribute should apply to the crate use an inner attribute + | +LL | #![inline(always)] + | + + error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea --> tests/ui/attrs.rs:5:1 | @@ -22,5 +40,29 @@ LL | #[inline(always)] = note: `-D clippy::inline-always` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::inline_always)]` -error: aborting due to 3 previous errors +error: empty lines after outer attribute + --> tests/ui/attrs.rs:28:1 + | +LL | / #[deprecated(since = "forever")] +... | +LL | | + | |_^ +LL | pub const SOME_CONST: u8 = 42; + | ------------------------ the attribute applies to this constant + | + = help: if the empty lines are unintentional remove them + +error: empty line after outer attribute + --> tests/ui/attrs.rs:34:1 + | +LL | / #[deprecated(since = "1")] +LL | | +LL | | + | |_^ +LL | pub const ANOTHER_CONST: u8 = 23; + | --------------------------- the attribute applies to this constant + | + = help: if the empty line is unintentional remove it + +error: aborting due to 6 previous errors diff --git a/tests/ui/author.rs b/tests/ui/author.rs index 0a1be3568967..faab114852fb 100644 --- a/tests/ui/author.rs +++ b/tests/ui/author.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn main() { #[clippy::author] let x: char = 0x45 as char; diff --git a/tests/ui/author/blocks.rs b/tests/ui/author/blocks.rs index e9db611a2aa9..73e921e4c75d 100644 --- a/tests/ui/author/blocks.rs +++ b/tests/ui/author/blocks.rs @@ -1,3 +1,4 @@ +//@ check-pass //@edition:2018 #![allow(redundant_semicolons, clippy::no_effect)] diff --git a/tests/ui/author/call.rs b/tests/ui/author/call.rs index e99c3c41dc4e..8d48eb7bd3e3 100644 --- a/tests/ui/author/call.rs +++ b/tests/ui/author/call.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn main() { #[clippy::author] let _ = ::std::cmp::min(3, 4); diff --git a/tests/ui/author/if.rs b/tests/ui/author/if.rs index 946088ab3461..59bc9f5bfa5c 100644 --- a/tests/ui/author/if.rs +++ b/tests/ui/author/if.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[allow(clippy::all)] fn main() { diff --git a/tests/ui/author/issue_3849.rs b/tests/ui/author/issue_3849.rs index 5f65746d71f2..dbd63b21af29 100644 --- a/tests/ui/author/issue_3849.rs +++ b/tests/ui/author/issue_3849.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code)] #![allow(clippy::zero_ptr)] #![allow(clippy::transmute_ptr_to_ref)] diff --git a/tests/ui/author/loop.rs b/tests/ui/author/loop.rs index ff5b61001179..dcf6fbd72027 100644 --- a/tests/ui/author/loop.rs +++ b/tests/ui/author/loop.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(stmt_expr_attributes)] #![allow( clippy::never_loop, diff --git a/tests/ui/author/macro_in_closure.rs b/tests/ui/author/macro_in_closure.rs index 444e6a12165d..8a02f38fad87 100644 --- a/tests/ui/author/macro_in_closure.rs +++ b/tests/ui/author/macro_in_closure.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn main() { #[clippy::author] let print_text = |x| println!("{}", x); diff --git a/tests/ui/author/macro_in_loop.rs b/tests/ui/author/macro_in_loop.rs index 8a520501f8dd..84ffe416e839 100644 --- a/tests/ui/author/macro_in_loop.rs +++ b/tests/ui/author/macro_in_loop.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(stmt_expr_attributes)] fn main() { diff --git a/tests/ui/author/matches.rs b/tests/ui/author/matches.rs index 674e07ec2d3d..e80d9c51023a 100644 --- a/tests/ui/author/matches.rs +++ b/tests/ui/author/matches.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::let_and_return)] fn main() { diff --git a/tests/ui/author/repeat.rs b/tests/ui/author/repeat.rs index d8e9d589e689..872f99844a01 100644 --- a/tests/ui/author/repeat.rs +++ b/tests/ui/author/repeat.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[allow(clippy::no_effect)] fn main() { #[clippy::author] diff --git a/tests/ui/author/struct.rs b/tests/ui/author/struct.rs index a99bdfc13137..73db44b73319 100644 --- a/tests/ui/author/struct.rs +++ b/tests/ui/author/struct.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow( clippy::unnecessary_operation, clippy::single_match, diff --git a/tests/ui/await_holding_refcell_ref.rs b/tests/ui/await_holding_refcell_ref.rs index b0c92d8c1f6e..258e16c07e04 100644 --- a/tests/ui/await_holding_refcell_ref.rs +++ b/tests/ui/await_holding_refcell_ref.rs @@ -4,13 +4,15 @@ use std::cell::RefCell; async fn bad(x: &RefCell) -> u32 { let b = x.borrow(); - //~^ ERROR: this `RefCell` reference is held across an await point + //~^ await_holding_refcell_ref + baz().await } async fn bad_mut(x: &RefCell) -> u32 { let b = x.borrow_mut(); - //~^ ERROR: this `RefCell` reference is held across an await point + //~^ await_holding_refcell_ref + baz().await } @@ -32,7 +34,8 @@ 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 + //~^ await_holding_refcell_ref + let second = baz().await; @@ -45,7 +48,8 @@ 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 + //~^ await_holding_refcell_ref + let second = baz().await; @@ -61,7 +65,8 @@ async fn not_good(x: &RefCell) -> u32 { let second = { let b = x.borrow_mut(); - //~^ ERROR: this `RefCell` reference is held across an await point + //~^ await_holding_refcell_ref + baz().await }; @@ -74,7 +79,8 @@ 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 + //~^ await_holding_refcell_ref + baz().await } } diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 6c7209c9ff9e..ce7c71ae8fec 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -6,7 +6,7 @@ LL | let b = x.borrow(); | = help: ensure the reference is dropped before calling `await` note: these are all the await points this reference is held through - --> tests/ui/await_holding_refcell_ref.rs:8:11 + --> tests/ui/await_holding_refcell_ref.rs:9:11 | LL | baz().await | ^^^^^ @@ -14,27 +14,27 @@ LL | baz().await = help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]` error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:12:9 + --> tests/ui/await_holding_refcell_ref.rs:13: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 - --> tests/ui/await_holding_refcell_ref.rs:14:11 + --> tests/ui/await_holding_refcell_ref.rs:16:11 | LL | baz().await | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:34:9 + --> tests/ui/await_holding_refcell_ref.rs:36: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 - --> tests/ui/await_holding_refcell_ref.rs:37:24 + --> tests/ui/await_holding_refcell_ref.rs:40:24 | LL | let second = baz().await; | ^^^^^ @@ -43,40 +43,40 @@ LL | let third = baz().await; | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:47:9 + --> tests/ui/await_holding_refcell_ref.rs:50: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 - --> tests/ui/await_holding_refcell_ref.rs:50:24 + --> tests/ui/await_holding_refcell_ref.rs:54:24 | LL | let second = baz().await; | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:63:13 + --> tests/ui/await_holding_refcell_ref.rs:67: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 - --> tests/ui/await_holding_refcell_ref.rs:65:15 + --> tests/ui/await_holding_refcell_ref.rs:70:15 | LL | baz().await | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:76:13 + --> tests/ui/await_holding_refcell_ref.rs:81: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 - --> tests/ui/await_holding_refcell_ref.rs:78:15 + --> tests/ui/await_holding_refcell_ref.rs:84:15 | LL | baz().await | ^^^^^ diff --git a/tests/ui/bind_instead_of_map.fixed b/tests/ui/bind_instead_of_map.fixed index 910cec2f203d..80e010e2dfd7 100644 --- a/tests/ui/bind_instead_of_map.fixed +++ b/tests/ui/bind_instead_of_map.fixed @@ -6,13 +6,16 @@ pub fn main() { let x = Some(5); // the easiest cases let _ = x; + //~^ bind_instead_of_map let _ = x.map(|o| o + 1); + //~^ bind_instead_of_map // and an easy counter-example let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); // Different type let x: Result = Ok(1); let _ = x; + //~^ bind_instead_of_map } pub fn foo() -> Option { diff --git a/tests/ui/bind_instead_of_map.rs b/tests/ui/bind_instead_of_map.rs index 6d66f659ba78..09aa8480cbd9 100644 --- a/tests/ui/bind_instead_of_map.rs +++ b/tests/ui/bind_instead_of_map.rs @@ -6,13 +6,16 @@ pub fn main() { let x = Some(5); // the easiest cases let _ = x.and_then(Some); + //~^ bind_instead_of_map let _ = x.and_then(|o| Some(o + 1)); + //~^ bind_instead_of_map // and an easy counter-example let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); // Different type let x: Result = Ok(1); let _ = x.and_then(Ok); + //~^ bind_instead_of_map } pub fn foo() -> Option { diff --git a/tests/ui/bind_instead_of_map.stderr b/tests/ui/bind_instead_of_map.stderr index 57e0e4fb8475..08f85fb58549 100644 --- a/tests/ui/bind_instead_of_map.stderr +++ b/tests/ui/bind_instead_of_map.stderr @@ -11,13 +11,13 @@ LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> tests/ui/bind_instead_of_map.rs:9:13 + --> tests/ui/bind_instead_of_map.rs:10: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 - --> tests/ui/bind_instead_of_map.rs:15:13 + --> tests/ui/bind_instead_of_map.rs:17: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 8c77039b3c01..a1da2cfc9fc6 100644 --- a/tests/ui/bind_instead_of_map_multipart.fixed +++ b/tests/ui/bind_instead_of_map_multipart.fixed @@ -3,12 +3,15 @@ pub fn main() { let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + //~^ bind_instead_of_map let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) }); let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); + //~^ bind_instead_of_map let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) }); let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); + //~^ bind_instead_of_map let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) }); hard_example(); @@ -17,6 +20,7 @@ pub fn main() { fn hard_example() { Some("42").map(|s| { + //~^ bind_instead_of_map if { if s == "43" { return 43; @@ -58,4 +62,5 @@ macro_rules! m { fn macro_example() { let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) }); let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); + //~^ bind_instead_of_map } diff --git a/tests/ui/bind_instead_of_map_multipart.rs b/tests/ui/bind_instead_of_map_multipart.rs index 44257f3a4698..5710254ddf6e 100644 --- a/tests/ui/bind_instead_of_map_multipart.rs +++ b/tests/ui/bind_instead_of_map_multipart.rs @@ -3,12 +3,15 @@ pub fn main() { let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); + //~^ bind_instead_of_map let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) }); let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); + //~^ bind_instead_of_map let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) }); let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); + //~^ bind_instead_of_map let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) }); hard_example(); @@ -17,6 +20,7 @@ pub fn main() { fn hard_example() { Some("42").and_then(|s| { + //~^ bind_instead_of_map if { if s == "43" { return Some(43); @@ -58,4 +62,5 @@ macro_rules! m { fn macro_example() { let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) }); let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); + //~^ bind_instead_of_map } diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index d271381adea2..336b19433a68 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -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)` - --> tests/ui/bind_instead_of_map_multipart.rs:8:13 + --> tests/ui/bind_instead_of_map_multipart.rs:9: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)` - --> tests/ui/bind_instead_of_map_multipart.rs:11:13 + --> tests/ui/bind_instead_of_map_multipart.rs:13:13 | LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,12 +37,12 @@ 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)` - --> tests/ui/bind_instead_of_map_multipart.rs:19:5 + --> tests/ui/bind_instead_of_map_multipart.rs:22:5 | LL | / Some("42").and_then(|s| { +LL | | LL | | if { LL | | if s == "43" { -LL | | return Some(43); ... | LL | | }); | |______^ @@ -50,6 +50,7 @@ LL | | }); help: use `map` instead | LL ~ Some("42").map(|s| { +LL | LL | if { LL | if s == "43" { LL ~ return 43; @@ -76,7 +77,7 @@ LL ~ _ => 1, | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> tests/ui/bind_instead_of_map_multipart.rs:60:13 + --> tests/ui/bind_instead_of_map_multipart.rs:64:13 | LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index 8e1d066c25e4..b38523a03960 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -12,27 +12,33 @@ 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 + //~^ bad_bit_mask + //~| erasing_op + + + + 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` + //~^ bad_bit_mask + x | 0 == 0; //ok, equals x == 0 (maybe warn?) x | 1 == 3; //ok, equals x == 2 || x == 3 x | 3 == 3; //ok, equals x <= 3 x | 3 == 2; - //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` + //~^ bad_bit_mask + x & 1 > 1; - //~^ ERROR: incompatible bit mask: `_ & 1` will never be higher than `1` + //~^ bad_bit_mask + x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x | 1 > 1; // ok (if a bit silly), equals x > 1 x | 2 > 1; - //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` + //~^ bad_bit_mask + x | 2 <= 2; // ok (if a bit silly), equals x <= 2 x & 192 == 128; // ok, tests for bit 7 and not bit 6 @@ -40,22 +46,29 @@ fn main() { // this also now works with constants x & THREE_BITS == 8; - //~^ ERROR: incompatible bit mask: `_ & 7` can never be equal to `8` + //~^ bad_bit_mask + x | EVEN_MORE_REDIRECTION < 7; - //~^ ERROR: incompatible bit mask: `_ | 7` will never be lower than `7` + //~^ bad_bit_mask + 0 & x == 0; - //~^ ERROR: &-masking with zero - //~| ERROR: this operation will always return zero. This is likely not the intended ou + //~^ bad_bit_mask + //~| erasing_op + + 1 | x > 1; // and should now also match uncommon usage 1 < 2 | x; - //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` + //~^ bad_bit_mask + 2 == 3 | x; - //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` + //~^ bad_bit_mask + 1 == x & 2; - //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` + //~^ bad_bit_mask + x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); @@ -67,14 +80,18 @@ 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` + //~^ ineffective_bit_mask + + x | 1 < 4; - //~^ ERROR: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared d + //~^ ineffective_bit_mask + x | 1 <= 3; - //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d + //~^ ineffective_bit_mask + x | 1 >= 8; - //~^ ERROR: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared d + //~^ ineffective_bit_mask + x | 1 > 2; // not an error (yet), better written as x >= 2 x | 1 >= 7; // not an error (yet), better written as x >= 6 diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index 004f6ad94841..300c93df9250 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -16,73 +16,73 @@ LL | x & 0 == 0; = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:21:5 + --> tests/ui/bit_masks.rs:23:5 | LL | x & 2 == 1; | ^^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:26:5 + --> tests/ui/bit_masks.rs:29:5 | LL | x | 3 == 2; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> tests/ui/bit_masks.rs:29:5 + --> tests/ui/bit_masks.rs:33:5 | LL | x & 1 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:34:5 + --> tests/ui/bit_masks.rs:39:5 | LL | x | 2 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> tests/ui/bit_masks.rs:42:5 + --> tests/ui/bit_masks.rs:48:5 | LL | x & THREE_BITS == 8; | ^^^^^^^^^^^^^^^^^^^ error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> tests/ui/bit_masks.rs:44:5 + --> tests/ui/bit_masks.rs:51:5 | LL | x | EVEN_MORE_REDIRECTION < 7; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: &-masking with zero - --> tests/ui/bit_masks.rs:47:5 + --> tests/ui/bit_masks.rs:55:5 | LL | 0 & x == 0; | ^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/bit_masks.rs:47:5 + --> tests/ui/bit_masks.rs:55:5 | LL | 0 & x == 0; | ^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:53:5 + --> tests/ui/bit_masks.rs:63:5 | LL | 1 < 2 | x; | ^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:55:5 + --> tests/ui/bit_masks.rs:66:5 | LL | 2 == 3 | x; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:57:5 + --> tests/ui/bit_masks.rs:69:5 | LL | 1 == x & 2; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:69:5 + --> tests/ui/bit_masks.rs:82:5 | LL | x | 1 > 3; | ^^^^^^^^^ @@ -91,19 +91,19 @@ LL | x | 1 > 3; = help: to override `-D warnings` add `#[allow(clippy::ineffective_bit_mask)]` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> tests/ui/bit_masks.rs:72:5 + --> tests/ui/bit_masks.rs:86:5 | LL | x | 1 < 4; | ^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:74:5 + --> tests/ui/bit_masks.rs:89:5 | LL | x | 1 <= 3; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> tests/ui/bit_masks.rs:76:5 + --> tests/ui/bit_masks.rs:92:5 | LL | x | 1 >= 8; | ^^^^^^^^^^ diff --git a/tests/ui/blanket_clippy_restriction_lints.rs b/tests/ui/blanket_clippy_restriction_lints.rs index 2bfaadf8df94..16e2e62c523d 100644 --- a/tests/ui/blanket_clippy_restriction_lints.rs +++ b/tests/ui/blanket_clippy_restriction_lints.rs @@ -1,13 +1,17 @@ //@compile-flags: -W clippy::restriction +//@error-in-other-file: restriction #![warn(clippy::blanket_clippy_restriction_lints)] //! Test that the whole restriction group is not enabled #![warn(clippy::restriction)] -//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group +//~^ blanket_clippy_restriction_lints + #![deny(clippy::restriction)] -//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group +//~^ blanket_clippy_restriction_lints + #![forbid(clippy::restriction)] -//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group +//~^ blanket_clippy_restriction_lints + fn main() {} diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 1bad259b09a3..5bfd7d208307 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -6,7 +6,7 @@ error: `clippy::restriction` is not meant to be enabled as a group = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` error: `clippy::restriction` is not meant to be enabled as a group - --> tests/ui/blanket_clippy_restriction_lints.rs:6:9 + --> tests/ui/blanket_clippy_restriction_lints.rs:7:9 | LL | #![warn(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,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 - --> tests/ui/blanket_clippy_restriction_lints.rs:8:9 + --> tests/ui/blanket_clippy_restriction_lints.rs:10:9 | LL | #![deny(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,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 - --> tests/ui/blanket_clippy_restriction_lints.rs:10:11 + --> tests/ui/blanket_clippy_restriction_lints.rs:13:11 | LL | #![forbid(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/blocks_in_conditions.fixed b/tests/ui/blocks_in_conditions.fixed index af8e65270d09..df375e370573 100644 --- a/tests/ui/blocks_in_conditions.fixed +++ b/tests/ui/blocks_in_conditions.fixed @@ -46,6 +46,7 @@ fn condition_has_block_with_single_expression() -> i32 { fn condition_is_normal() -> i32 { let x = 3; if x == 3 { 6 } else { 10 } + //~^ nonminimal_bool } fn condition_is_unsafe_block() { diff --git a/tests/ui/blocks_in_conditions.rs b/tests/ui/blocks_in_conditions.rs index 6adae951a290..1d9c9dd42460 100644 --- a/tests/ui/blocks_in_conditions.rs +++ b/tests/ui/blocks_in_conditions.rs @@ -46,6 +46,7 @@ fn condition_has_block_with_single_expression() -> i32 { fn condition_is_normal() -> i32 { let x = 3; if true && x == 3 { 6 } else { 10 } + //~^ nonminimal_bool } fn condition_is_unsafe_block() { diff --git a/tests/ui/blocks_in_conditions.stderr b/tests/ui/blocks_in_conditions.stderr index a55e1efb575e..da21344a8428 100644 --- a/tests/ui/blocks_in_conditions.stderr +++ b/tests/ui/blocks_in_conditions.stderr @@ -35,7 +35,7 @@ LL | if true && x == 3 { 6 } else { 10 } = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> tests/ui/blocks_in_conditions.rs:75:5 + --> tests/ui/blocks_in_conditions.rs:76:5 | LL | / match { LL | | diff --git a/tests/ui/bool_assert_comparison.fixed b/tests/ui/bool_assert_comparison.fixed index b05166a055ee..721d8b2c2dcd 100644 --- a/tests/ui/bool_assert_comparison.fixed +++ b/tests/ui/bool_assert_comparison.fixed @@ -85,65 +85,90 @@ fn main() { assert_eq!("a".len(), 1); assert!(!"a".is_empty()); + //~^ bool_assert_comparison assert!("".is_empty()); + //~^ bool_assert_comparison assert!("".is_empty()); + //~^ bool_assert_comparison assert_eq!(a!(), b!()); assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); assert!(b); + //~^ bool_assert_comparison assert_ne!("a".len(), 1); assert!("a".is_empty()); + //~^ bool_assert_comparison assert!(!"".is_empty()); + //~^ bool_assert_comparison assert!(!"".is_empty()); + //~^ bool_assert_comparison assert_ne!(a!(), b!()); assert_ne!(a!(), "".is_empty()); assert_ne!("".is_empty(), b!()); assert_ne!(a, true); assert!(!b); + //~^ bool_assert_comparison debug_assert_eq!("a".len(), 1); debug_assert!(!"a".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert_eq!(a!(), b!()); debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); debug_assert!(b); + //~^ bool_assert_comparison debug_assert_ne!("a".len(), 1); debug_assert!("a".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"".is_empty()); + //~^ bool_assert_comparison debug_assert_ne!(a!(), b!()); debug_assert_ne!(a!(), "".is_empty()); debug_assert_ne!("".is_empty(), b!()); debug_assert_ne!(a, true); debug_assert!(!b); + //~^ bool_assert_comparison // assert with error messages assert_eq!("a".len(), 1, "tadam {}", 1); assert_eq!("a".len(), 1, "tadam {}", true); assert!(!"a".is_empty(), "tadam {}", 1); + //~^ bool_assert_comparison assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(a, true, "tadam {}", false); debug_assert_eq!("a".len(), 1, "tadam {}", 1); debug_assert_eq!("a".len(), 1, "tadam {}", true); debug_assert!(!"a".is_empty(), "tadam {}", 1); + //~^ bool_assert_comparison debug_assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert!(!"a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(a, true, "tadam {}", false); assert!(a!()); + //~^ bool_assert_comparison assert!(b!()); + //~^ bool_assert_comparison use debug_assert_eq as renamed; renamed!(a, true); debug_assert!(b); + //~^ bool_assert_comparison let non_copy = NonCopy; assert_eq!(non_copy, true); @@ -158,12 +183,20 @@ fn main() { in_macro!(a); assert!("".is_empty()); + //~^ bool_assert_comparison assert!("".is_empty()); + //~^ bool_assert_comparison assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!("".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison debug_assert!(!"requires negation".is_empty()); + //~^ bool_assert_comparison } diff --git a/tests/ui/bool_assert_comparison.rs b/tests/ui/bool_assert_comparison.rs index dc51fcf1d36b..5ab4f475b063 100644 --- a/tests/ui/bool_assert_comparison.rs +++ b/tests/ui/bool_assert_comparison.rs @@ -85,65 +85,90 @@ fn main() { assert_eq!("a".len(), 1); assert_eq!("a".is_empty(), false); + //~^ bool_assert_comparison assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison assert_eq!(true, "".is_empty()); + //~^ bool_assert_comparison assert_eq!(a!(), b!()); assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); assert_eq!(b, true); + //~^ bool_assert_comparison assert_ne!("a".len(), 1); assert_ne!("a".is_empty(), false); + //~^ bool_assert_comparison assert_ne!("".is_empty(), true); + //~^ bool_assert_comparison assert_ne!(true, "".is_empty()); + //~^ bool_assert_comparison assert_ne!(a!(), b!()); assert_ne!(a!(), "".is_empty()); assert_ne!("".is_empty(), b!()); assert_ne!(a, true); assert_ne!(b, true); + //~^ bool_assert_comparison debug_assert_eq!("a".len(), 1); debug_assert_eq!("a".is_empty(), false); + //~^ bool_assert_comparison debug_assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_eq!(true, "".is_empty()); + //~^ bool_assert_comparison debug_assert_eq!(a!(), b!()); debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); debug_assert_eq!(b, true); + //~^ bool_assert_comparison debug_assert_ne!("a".len(), 1); debug_assert_ne!("a".is_empty(), false); + //~^ bool_assert_comparison debug_assert_ne!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_ne!(true, "".is_empty()); + //~^ bool_assert_comparison debug_assert_ne!(a!(), b!()); debug_assert_ne!(a!(), "".is_empty()); debug_assert_ne!("".is_empty(), b!()); debug_assert_ne!(a, true); debug_assert_ne!(b, true); + //~^ bool_assert_comparison // assert with error messages assert_eq!("a".len(), 1, "tadam {}", 1); assert_eq!("a".len(), 1, "tadam {}", true); assert_eq!("a".is_empty(), false, "tadam {}", 1); + //~^ bool_assert_comparison assert_eq!("a".is_empty(), false, "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(false, "a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison assert_eq!(a, true, "tadam {}", false); debug_assert_eq!("a".len(), 1, "tadam {}", 1); debug_assert_eq!("a".len(), 1, "tadam {}", true); debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); + //~^ bool_assert_comparison debug_assert_eq!("a".is_empty(), false, "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); + //~^ bool_assert_comparison debug_assert_eq!(a, true, "tadam {}", false); assert_eq!(a!(), true); + //~^ bool_assert_comparison assert_eq!(true, b!()); + //~^ bool_assert_comparison use debug_assert_eq as renamed; renamed!(a, true); renamed!(b, true); + //~^ bool_assert_comparison let non_copy = NonCopy; assert_eq!(non_copy, true); @@ -158,12 +183,20 @@ fn main() { in_macro!(a); assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison assert_ne!("".is_empty(), false); + //~^ bool_assert_comparison assert_ne!("requires negation".is_empty(), true); + //~^ bool_assert_comparison assert_eq!("requires negation".is_empty(), false); + //~^ bool_assert_comparison debug_assert_eq!("".is_empty(), true); + //~^ bool_assert_comparison debug_assert_ne!("".is_empty(), false); + //~^ bool_assert_comparison debug_assert_ne!("requires negation".is_empty(), true); + //~^ bool_assert_comparison debug_assert_eq!("requires negation".is_empty(), false); + //~^ bool_assert_comparison } diff --git a/tests/ui/bool_assert_comparison.stderr b/tests/ui/bool_assert_comparison.stderr index 41183c61ee01..a1d0af543617 100644 --- a/tests/ui/bool_assert_comparison.stderr +++ b/tests/ui/bool_assert_comparison.stderr @@ -13,7 +13,7 @@ LL + assert!(!"a".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:88:5 + --> tests/ui/bool_assert_comparison.rs:89:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:89:5 + --> tests/ui/bool_assert_comparison.rs:91:5 | LL | assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:94:5 + --> tests/ui/bool_assert_comparison.rs:97:5 | LL | assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + assert!(b); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:97:5 + --> tests/ui/bool_assert_comparison.rs:101:5 | LL | assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!("a".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:98:5 + --> tests/ui/bool_assert_comparison.rs:103:5 | LL | assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:99:5 + --> tests/ui/bool_assert_comparison.rs:105:5 | LL | assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:104:5 + --> tests/ui/bool_assert_comparison.rs:111:5 | LL | assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + assert!(!b); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:107:5 + --> tests/ui/bool_assert_comparison.rs:115:5 | LL | debug_assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + debug_assert!(!"a".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:108:5 + --> tests/ui/bool_assert_comparison.rs:117:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:109:5 + --> tests/ui/bool_assert_comparison.rs:119:5 | LL | debug_assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:114:5 + --> tests/ui/bool_assert_comparison.rs:125:5 | LL | debug_assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + debug_assert!(b); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:117:5 + --> tests/ui/bool_assert_comparison.rs:129:5 | LL | debug_assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + debug_assert!("a".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:118:5 + --> tests/ui/bool_assert_comparison.rs:131:5 | LL | debug_assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:119:5 + --> tests/ui/bool_assert_comparison.rs:133:5 | LL | debug_assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:124:5 + --> tests/ui/bool_assert_comparison.rs:139:5 | LL | debug_assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + debug_assert!(!b); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:129:5 + --> tests/ui/bool_assert_comparison.rs:145:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", 1); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:130:5 + --> tests/ui/bool_assert_comparison.rs:147:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:131:5 + --> tests/ui/bool_assert_comparison.rs:149:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:136:5 + --> tests/ui/bool_assert_comparison.rs:155:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", 1); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:137:5 + --> tests/ui/bool_assert_comparison.rs:157:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:138:5 + --> tests/ui/bool_assert_comparison.rs:159:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:141:5 + --> tests/ui/bool_assert_comparison.rs:163:5 | LL | assert_eq!(a!(), true); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + assert!(a!()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:142:5 + --> tests/ui/bool_assert_comparison.rs:165:5 | LL | assert_eq!(true, b!()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + assert!(b!()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:146:5 + --> tests/ui/bool_assert_comparison.rs:170:5 | LL | renamed!(b, true); | ^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + debug_assert!(b); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:160:5 + --> tests/ui/bool_assert_comparison.rs:185:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:161:5 + --> tests/ui/bool_assert_comparison.rs:187:5 | LL | assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:162:5 + --> tests/ui/bool_assert_comparison.rs:189:5 | LL | assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:163:5 + --> tests/ui/bool_assert_comparison.rs:191:5 | LL | assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:165:5 + --> tests/ui/bool_assert_comparison.rs:194:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:166:5 + --> tests/ui/bool_assert_comparison.rs:196:5 | LL | debug_assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:167:5 + --> tests/ui/bool_assert_comparison.rs:198:5 | LL | debug_assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL + debug_assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:168:5 + --> tests/ui/bool_assert_comparison.rs:200: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 3db91eec8fa7..724bf9253d33 100644 --- a/tests/ui/bool_comparison.fixed +++ b/tests/ui/bool_comparison.fixed @@ -5,72 +5,86 @@ fn main() { let x = true; if x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; if x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; if x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; if x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; if x { + //~^ bool_comparison "yes" } else { "no" }; if x { + //~^ bool_comparison "yes" } else { "no" }; if !x { + //~^ bool_comparison "yes" } else { "no" }; let y = true; if !x & y { + //~^ bool_comparison "yes" } else { "no" }; if x & !y { + //~^ bool_comparison "yes" } else { "no" @@ -119,12 +133,16 @@ fn issue4983() { let b = false; if a != b {}; + //~^ bool_comparison if a != b {}; + //~^ bool_comparison if a == b {}; if !a == !b {}; if b != a {}; + //~^ bool_comparison if b != a {}; + //~^ bool_comparison if b == a {}; if !b == !a {}; } @@ -149,9 +167,13 @@ fn issue3973() { // lint, could be simplified if !m!(func) {} + //~^ bool_comparison if !m!(func) {} + //~^ bool_comparison if m!(func) {} + //~^ bool_comparison if m!(func) {} + //~^ bool_comparison // no lint with a variable let is_debug = false; @@ -169,8 +191,11 @@ fn issue3973() { #[allow(clippy::unnecessary_cast)] fn issue9907() { let _ = (1 >= 2) as usize; + //~^ bool_comparison let _ = (!m!(func)) as usize; + //~^ bool_comparison // This is not part of the issue, but an unexpected found when fixing the issue, // the provided span was inside of macro rather than the macro callsite. let _ = ((1 < 2) != m!(func)) as usize; + //~^ bool_comparison } diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index fbcfb1cee7bf..6d11f9efe569 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -5,72 +5,86 @@ fn main() { let x = true; if x == true { + //~^ bool_comparison "yes" } else { "no" }; if x == false { + //~^ bool_comparison "yes" } else { "no" }; if true == x { + //~^ bool_comparison "yes" } else { "no" }; if false == x { + //~^ bool_comparison "yes" } else { "no" }; if x != true { + //~^ bool_comparison "yes" } else { "no" }; if x != false { + //~^ bool_comparison "yes" } else { "no" }; if true != x { + //~^ bool_comparison "yes" } else { "no" }; if false != x { + //~^ bool_comparison "yes" } else { "no" }; if x < true { + //~^ bool_comparison "yes" } else { "no" }; if false < x { + //~^ bool_comparison "yes" } else { "no" }; if x > false { + //~^ bool_comparison "yes" } else { "no" }; if true > x { + //~^ bool_comparison "yes" } else { "no" }; let y = true; if x < y { + //~^ bool_comparison "yes" } else { "no" }; if x > y { + //~^ bool_comparison "yes" } else { "no" @@ -119,12 +133,16 @@ fn issue4983() { let b = false; if a == !b {}; + //~^ bool_comparison if !a == b {}; + //~^ bool_comparison if a == b {}; if !a == !b {}; if b == !a {}; + //~^ bool_comparison if !b == a {}; + //~^ bool_comparison if b == a {}; if !b == !a {}; } @@ -149,9 +167,13 @@ fn issue3973() { // lint, could be simplified if false == m!(func) {} + //~^ bool_comparison if m!(func) == false {} + //~^ bool_comparison if true == m!(func) {} + //~^ bool_comparison if m!(func) == true {} + //~^ bool_comparison // no lint with a variable let is_debug = false; @@ -169,8 +191,11 @@ fn issue3973() { #[allow(clippy::unnecessary_cast)] fn issue9907() { let _ = ((1 < 2) == false) as usize; + //~^ bool_comparison let _ = (false == m!(func)) as usize; + //~^ bool_comparison // This is not part of the issue, but an unexpected found when fixing the issue, // the provided span was inside of macro rather than the macro callsite. let _ = ((1 < 2) == !m!(func)) as usize; + //~^ bool_comparison } diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index 7c8b906221fa..ddbb9ff78edb 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -8,145 +8,145 @@ LL | if x == true { = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation - --> tests/ui/bool_comparison.rs:12:8 + --> tests/ui/bool_comparison.rs:13:8 | LL | if x == false { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> tests/ui/bool_comparison.rs:17:8 + --> tests/ui/bool_comparison.rs:19:8 | LL | if true == x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> tests/ui/bool_comparison.rs:22:8 + --> tests/ui/bool_comparison.rs:25:8 | LL | if false == x { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against true can be replaced by a negation - --> tests/ui/bool_comparison.rs:27:8 + --> tests/ui/bool_comparison.rs:31:8 | LL | if x != true { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> tests/ui/bool_comparison.rs:32:8 + --> tests/ui/bool_comparison.rs:37:8 | LL | if x != false { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: inequality checks against true can be replaced by a negation - --> tests/ui/bool_comparison.rs:37:8 + --> tests/ui/bool_comparison.rs:43:8 | LL | if true != x { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> tests/ui/bool_comparison.rs:42:8 + --> tests/ui/bool_comparison.rs:49:8 | LL | if false != x { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> tests/ui/bool_comparison.rs:47:8 + --> tests/ui/bool_comparison.rs:55:8 | LL | if x < true { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: greater than checks against false are unnecessary - --> tests/ui/bool_comparison.rs:52:8 + --> tests/ui/bool_comparison.rs:61:8 | LL | if false < x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: greater than checks against false are unnecessary - --> tests/ui/bool_comparison.rs:57:8 + --> tests/ui/bool_comparison.rs:67:8 | LL | if x > false { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> tests/ui/bool_comparison.rs:62:8 + --> tests/ui/bool_comparison.rs:73:8 | LL | if true > x { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: order comparisons between booleans can be simplified - --> tests/ui/bool_comparison.rs:68:8 + --> tests/ui/bool_comparison.rs:80:8 | LL | if x < y { | ^^^^^ help: try simplifying it as shown: `!x & y` error: order comparisons between booleans can be simplified - --> tests/ui/bool_comparison.rs:73:8 + --> tests/ui/bool_comparison.rs:86:8 | LL | if x > y { | ^^^^^ help: try simplifying it as shown: `x & !y` error: this comparison might be written more concisely - --> tests/ui/bool_comparison.rs:121:8 + --> tests/ui/bool_comparison.rs:135:8 | LL | if a == !b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> tests/ui/bool_comparison.rs:122:8 + --> tests/ui/bool_comparison.rs:137:8 | LL | if !a == b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> tests/ui/bool_comparison.rs:126:8 + --> tests/ui/bool_comparison.rs:142:8 | LL | if b == !a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: this comparison might be written more concisely - --> tests/ui/bool_comparison.rs:127:8 + --> tests/ui/bool_comparison.rs:144:8 | LL | if !b == a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: equality checks against false can be replaced by a negation - --> tests/ui/bool_comparison.rs:151:8 + --> tests/ui/bool_comparison.rs:169: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 - --> tests/ui/bool_comparison.rs:152:8 + --> tests/ui/bool_comparison.rs:171:8 | LL | if m!(func) == false {} | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: equality checks against true are unnecessary - --> tests/ui/bool_comparison.rs:153:8 + --> tests/ui/bool_comparison.rs:173:8 | LL | if true == m!(func) {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` error: equality checks against true are unnecessary - --> tests/ui/bool_comparison.rs:154:8 + --> tests/ui/bool_comparison.rs:175:8 | LL | if m!(func) == true {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` error: equality checks against false can be replaced by a negation - --> tests/ui/bool_comparison.rs:171:14 + --> tests/ui/bool_comparison.rs:193:14 | LL | let _ = ((1 < 2) == false) as usize; | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `1 >= 2` error: equality checks against false can be replaced by a negation - --> tests/ui/bool_comparison.rs:172:14 + --> tests/ui/bool_comparison.rs:195:14 | LL | let _ = (false == m!(func)) as usize; | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: this comparison might be written more concisely - --> tests/ui/bool_comparison.rs:175:14 + --> tests/ui/bool_comparison.rs:199:14 | LL | let _ = ((1 < 2) == !m!(func)) as usize; | ^^^^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `(1 < 2) != m!(func)` diff --git a/tests/ui/bool_to_int_with_if.fixed b/tests/ui/bool_to_int_with_if.fixed index f7dad28b0369..0080801d46b7 100644 --- a/tests/ui/bool_to_int_with_if.fixed +++ b/tests/ui/bool_to_int_with_if.fixed @@ -88,6 +88,7 @@ fn main() { // Lint returns and type inference fn some_fn(a: bool) -> u8 { u8::from(a) + //~^ bool_to_int_with_if } fn side_effect() {} diff --git a/tests/ui/bool_to_int_with_if.rs b/tests/ui/bool_to_int_with_if.rs index d22871d2c8f2..d12b0af5312e 100644 --- a/tests/ui/bool_to_int_with_if.rs +++ b/tests/ui/bool_to_int_with_if.rs @@ -12,31 +12,37 @@ fn main() { // Should lint // precedence if a { + //~^ bool_to_int_with_if 1 } else { 0 }; if a { + //~^ bool_to_int_with_if 0 } else { 1 }; if !a { + //~^ bool_to_int_with_if 1 } else { 0 }; if a || b { + //~^ bool_to_int_with_if 1 } else { 0 }; if cond(a, b) { + //~^ bool_to_int_with_if 1 } else { 0 }; if x + y < 4 { + //~^ bool_to_int_with_if 1 } else { 0 @@ -46,6 +52,7 @@ fn main() { if a { 123 } else if b { + //~^ bool_to_int_with_if 1 } else { 0 @@ -55,6 +62,7 @@ fn main() { if a { 123 } else if b { + //~^ bool_to_int_with_if 0 } else { 1 @@ -120,6 +128,7 @@ fn main() { // Lint returns and type inference fn some_fn(a: bool) -> u8 { if a { 1 } else { 0 } + //~^ bool_to_int_with_if } fn side_effect() {} diff --git a/tests/ui/bool_to_int_with_if.stderr b/tests/ui/bool_to_int_with_if.stderr index 1e4a843071a1..415e80f8d73d 100644 --- a/tests/ui/bool_to_int_with_if.stderr +++ b/tests/ui/bool_to_int_with_if.stderr @@ -2,6 +2,7 @@ error: boolean to int conversion using if --> tests/ui/bool_to_int_with_if.rs:14:5 | LL | / if a { +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -13,9 +14,10 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::bool_to_int_with_if)]` error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:19:5 + --> tests/ui/bool_to_int_with_if.rs:20:5 | LL | / if a { +LL | | LL | | 0 LL | | } else { LL | | 1 @@ -25,9 +27,10 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:24:5 + --> tests/ui/bool_to_int_with_if.rs:26:5 | LL | / if !a { +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -37,9 +40,10 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:29:5 + --> tests/ui/bool_to_int_with_if.rs:32:5 | LL | / if a || b { +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -49,9 +53,10 @@ LL | | }; = note: `(a || b) as i32` or `(a || b).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:34:5 + --> tests/ui/bool_to_int_with_if.rs:38:5 | LL | / if cond(a, b) { +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -61,9 +66,10 @@ LL | | }; = note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:39:5 + --> tests/ui/bool_to_int_with_if.rs:44:5 | LL | / if x + y < 4 { +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -73,10 +79,11 @@ LL | | }; = note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:48:12 + --> tests/ui/bool_to_int_with_if.rs:54:12 | LL | } else if b { | ____________^ +LL | | LL | | 1 LL | | } else { LL | | 0 @@ -86,10 +93,11 @@ LL | | }; = note: `b as i32` or `b.into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:57:12 + --> tests/ui/bool_to_int_with_if.rs:64:12 | LL | } else if b { | ____________^ +LL | | LL | | 0 LL | | } else { LL | | 1 @@ -99,7 +107,7 @@ LL | | }; = note: `!b as i32` or `(!b).into()` can also be valid options error: boolean to int conversion using if - --> tests/ui/bool_to_int_with_if.rs:122:5 + --> tests/ui/bool_to_int_with_if.rs:130:5 | LL | if a { 1 } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)` diff --git a/tests/ui/borrow_and_ref_as_ptr.fixed b/tests/ui/borrow_and_ref_as_ptr.fixed index 2950b158deb6..b7ee4c6165a7 100644 --- a/tests/ui/borrow_and_ref_as_ptr.fixed +++ b/tests/ui/borrow_and_ref_as_ptr.fixed @@ -7,5 +7,7 @@ fn f(_: T) {} fn main() { let mut val = 0; f(&raw const val); + //~^ borrow_as_ptr f(&raw mut val); + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_and_ref_as_ptr.rs b/tests/ui/borrow_and_ref_as_ptr.rs index 19eb8f292337..d16ed5aa7b29 100644 --- a/tests/ui/borrow_and_ref_as_ptr.rs +++ b/tests/ui/borrow_and_ref_as_ptr.rs @@ -7,5 +7,7 @@ fn f(_: T) {} fn main() { let mut val = 0; f(&val as *const _); + //~^ borrow_as_ptr f(&mut val as *mut i32); + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_and_ref_as_ptr.stderr b/tests/ui/borrow_and_ref_as_ptr.stderr index 82a27af303c2..e02f3d8bed97 100644 --- a/tests/ui/borrow_and_ref_as_ptr.stderr +++ b/tests/ui/borrow_and_ref_as_ptr.stderr @@ -8,7 +8,7 @@ LL | f(&val as *const _); = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> tests/ui/borrow_and_ref_as_ptr.rs:10:7 + --> tests/ui/borrow_and_ref_as_ptr.rs:11:7 | LL | f(&mut val as *mut i32); | ^^^^^^^^^^^^^^^^^^^^ help: try: `&raw mut val` diff --git a/tests/ui/borrow_as_ptr.fixed b/tests/ui/borrow_as_ptr.fixed index 5365f3dd443c..3dca06fce4b8 100644 --- a/tests/ui/borrow_as_ptr.fixed +++ b/tests/ui/borrow_as_ptr.fixed @@ -9,6 +9,7 @@ fn a() -> i32 { fn main() { let val = 1; let _p = std::ptr::addr_of!(val); + //~^ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; @@ -16,12 +17,15 @@ fn main() { let mut val_mut = 1; let _p_mut = std::ptr::addr_of_mut!(val_mut); + //~^ borrow_as_ptr let mut x: [i32; 2] = [42, 43]; let _raw = std::ptr::addr_of_mut!(x[1]).wrapping_offset(-1); + //~^ borrow_as_ptr } fn issue_13882() { let mut x: [i32; 2] = [42, 43]; let _raw = (&raw mut x[1]).wrapping_offset(-1); + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr.rs b/tests/ui/borrow_as_ptr.rs index 261894f1341c..3559dc23d018 100644 --- a/tests/ui/borrow_as_ptr.rs +++ b/tests/ui/borrow_as_ptr.rs @@ -9,6 +9,7 @@ fn a() -> i32 { fn main() { let val = 1; let _p = &val as *const i32; + //~^ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; @@ -16,12 +17,15 @@ fn main() { let mut val_mut = 1; let _p_mut = &mut val_mut as *mut i32; + //~^ borrow_as_ptr let mut x: [i32; 2] = [42, 43]; let _raw = (&mut x[1] as *mut i32).wrapping_offset(-1); + //~^ borrow_as_ptr } fn issue_13882() { let mut x: [i32; 2] = [42, 43]; let _raw = (&mut x[1] as *mut i32).wrapping_offset(-1); + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr.stderr b/tests/ui/borrow_as_ptr.stderr index 4595fa4f2487..4a9f2ed4aa00 100644 --- a/tests/ui/borrow_as_ptr.stderr +++ b/tests/ui/borrow_as_ptr.stderr @@ -8,19 +8,19 @@ LL | let _p = &val as *const i32; = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> tests/ui/borrow_as_ptr.rs:18:18 + --> tests/ui/borrow_as_ptr.rs:19:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of_mut!(val_mut)` error: borrow as raw pointer - --> tests/ui/borrow_as_ptr.rs:21:16 + --> tests/ui/borrow_as_ptr.rs:23:16 | LL | let _raw = (&mut x[1] as *mut i32).wrapping_offset(-1); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of_mut!(x[1])` error: borrow as raw pointer - --> tests/ui/borrow_as_ptr.rs:26:17 + --> tests/ui/borrow_as_ptr.rs:29:17 | LL | let _raw = (&mut x[1] as *mut i32).wrapping_offset(-1); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `&raw mut x[1]` diff --git a/tests/ui/borrow_as_ptr_no_std.fixed b/tests/ui/borrow_as_ptr_no_std.fixed index 26c6a5033d16..8972fc0a5e0d 100644 --- a/tests/ui/borrow_as_ptr_no_std.fixed +++ b/tests/ui/borrow_as_ptr_no_std.fixed @@ -6,8 +6,10 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let val = 1; let _p = core::ptr::addr_of!(val); + //~^ borrow_as_ptr let mut val_mut = 1; let _p_mut = core::ptr::addr_of_mut!(val_mut); + //~^ borrow_as_ptr 0 } diff --git a/tests/ui/borrow_as_ptr_no_std.rs b/tests/ui/borrow_as_ptr_no_std.rs index d8d8b4c380ce..6b4c732dc56e 100644 --- a/tests/ui/borrow_as_ptr_no_std.rs +++ b/tests/ui/borrow_as_ptr_no_std.rs @@ -6,8 +6,10 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let val = 1; let _p = &val as *const i32; + //~^ borrow_as_ptr let mut val_mut = 1; let _p_mut = &mut val_mut as *mut i32; + //~^ borrow_as_ptr 0 } diff --git a/tests/ui/borrow_as_ptr_no_std.stderr b/tests/ui/borrow_as_ptr_no_std.stderr index 488e0bd96776..6012577559d0 100644 --- a/tests/ui/borrow_as_ptr_no_std.stderr +++ b/tests/ui/borrow_as_ptr_no_std.stderr @@ -8,7 +8,7 @@ LL | let _p = &val as *const i32; = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> tests/ui/borrow_as_ptr_no_std.rs:11:18 + --> tests/ui/borrow_as_ptr_no_std.rs:12: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_as_ptr_raw_ref.fixed b/tests/ui/borrow_as_ptr_raw_ref.fixed index d6842e60a3e9..7fbb942b5bc7 100644 --- a/tests/ui/borrow_as_ptr_raw_ref.fixed +++ b/tests/ui/borrow_as_ptr_raw_ref.fixed @@ -9,6 +9,7 @@ fn a() -> i32 { fn main() { let val = 1; let _p = &raw const val; + //~^ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; @@ -16,4 +17,5 @@ fn main() { let mut val_mut = 1; let _p_mut = &raw mut val_mut; + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr_raw_ref.rs b/tests/ui/borrow_as_ptr_raw_ref.rs index 3c9daed18f15..9cbf2e5c266d 100644 --- a/tests/ui/borrow_as_ptr_raw_ref.rs +++ b/tests/ui/borrow_as_ptr_raw_ref.rs @@ -9,6 +9,7 @@ fn a() -> i32 { fn main() { let val = 1; let _p = &val as *const i32; + //~^ borrow_as_ptr let _p = &0 as *const i32; let _p = &a() as *const i32; let vec = vec![1]; @@ -16,4 +17,5 @@ fn main() { let mut val_mut = 1; let _p_mut = &mut val_mut as *mut i32; + //~^ borrow_as_ptr } diff --git a/tests/ui/borrow_as_ptr_raw_ref.stderr b/tests/ui/borrow_as_ptr_raw_ref.stderr index 5611fcae8d4b..e5c8aec77986 100644 --- a/tests/ui/borrow_as_ptr_raw_ref.stderr +++ b/tests/ui/borrow_as_ptr_raw_ref.stderr @@ -8,7 +8,7 @@ LL | let _p = &val as *const i32; = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> tests/ui/borrow_as_ptr_raw_ref.rs:18:18 + --> tests/ui/borrow_as_ptr_raw_ref.rs:19:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&raw mut val_mut` diff --git a/tests/ui/borrow_box.fixed b/tests/ui/borrow_box.fixed index 08ea60583ea4..4529138c0edc 100644 --- a/tests/ui/borrow_box.fixed +++ b/tests/ui/borrow_box.fixed @@ -23,17 +23,20 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &bool; - //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` + //~^ borrowed_box + } struct Test3<'a> { foo: &'a bool, - //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` + //~^ borrowed_box + } trait Test4 { fn test4(a: &bool); - //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` + //~^ borrowed_box + } use std::any::Any; @@ -94,24 +97,31 @@ pub fn test13(boxed_slice: &mut Box<[i32]>) { // The suggestion should include proper parentheses to avoid a syntax error. pub fn test14(_display: &dyn Display) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test15(_display: &(dyn Display + Send)) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test16<'a>(_display: &'a (dyn Display + 'a)) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test17(_display: &impl Display) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test18(_display: &(impl Display + Send)) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test19<'a>(_display: &'a (impl Display + 'a)) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + // 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: &(dyn Display + Send)) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + #[allow(clippy::borrowed_box)] trait Trait { diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index b55de1701daa..3f2a0168ef42 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -23,17 +23,20 @@ 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` + //~^ borrowed_box + } struct Test3<'a> { foo: &'a Box, - //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` + //~^ borrowed_box + } trait Test4 { fn test4(a: &Box); - //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` + //~^ borrowed_box + } use std::any::Any; @@ -94,24 +97,31 @@ 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` +//~^ borrowed_box + pub fn test15(_display: &Box) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test16<'a>(_display: &'a Box) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test17(_display: &Box) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test18(_display: &Box) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + pub fn test19<'a>(_display: &'a Box) {} -//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` +//~^ borrowed_box + // 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` +//~^ borrowed_box + #[allow(clippy::borrowed_box)] trait Trait { diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 6f80f86c3b3d..e23e49f1c88b 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` - --> tests/ui/borrow_box.rs:30:10 + --> tests/ui/borrow_box.rs:31:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:35:17 + --> tests/ui/borrow_box.rs:37:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:96:25 + --> tests/ui/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` - --> tests/ui/borrow_box.rs:98:25 + --> tests/ui/borrow_box.rs:102: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` - --> tests/ui/borrow_box.rs:100:29 + --> tests/ui/borrow_box.rs:105: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` - --> tests/ui/borrow_box.rs:103:25 + --> tests/ui/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` - --> tests/ui/borrow_box.rs:105:25 + --> tests/ui/borrow_box.rs:112: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` - --> tests/ui/borrow_box.rs:107:29 + --> tests/ui/borrow_box.rs:115: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` - --> tests/ui/borrow_box.rs:113:25 + --> tests/ui/borrow_box.rs:122: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 22e984c46d24..93cd3e3b5e59 100644 --- a/tests/ui/borrow_deref_ref.fixed +++ b/tests/ui/borrow_deref_ref.fixed @@ -11,8 +11,10 @@ mod should_lint { fn one_help() { let a = &12; let b = a; + //~^ borrow_deref_ref let b = &mut bar(&12); + //~^ borrow_deref_ref } fn bar(x: &u32) -> &u32 { @@ -67,6 +69,7 @@ mod false_negative { let x = &12; let addr_x = &x as *const _ as usize; let addr_y = &x as *const _ as usize; // assert ok + //~^ borrow_deref_ref // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); } diff --git a/tests/ui/borrow_deref_ref.rs b/tests/ui/borrow_deref_ref.rs index 61d89193f42f..1e41d24998f9 100644 --- a/tests/ui/borrow_deref_ref.rs +++ b/tests/ui/borrow_deref_ref.rs @@ -11,8 +11,10 @@ mod should_lint { fn one_help() { let a = &12; let b = &*a; + //~^ borrow_deref_ref let b = &mut &*bar(&12); + //~^ borrow_deref_ref } fn bar(x: &u32) -> &u32 { @@ -67,6 +69,7 @@ mod false_negative { let x = &12; let addr_x = &x as *const _ as usize; let addr_y = &&*x as *const _ as usize; // assert ok + //~^ borrow_deref_ref // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); } diff --git a/tests/ui/borrow_deref_ref.stderr b/tests/ui/borrow_deref_ref.stderr index 7fa43ef49cf7..f5868aa87490 100644 --- a/tests/ui/borrow_deref_ref.stderr +++ b/tests/ui/borrow_deref_ref.stderr @@ -8,13 +8,13 @@ LL | let b = &*a; = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` error: deref on an immutable reference - --> tests/ui/borrow_deref_ref.rs:15:22 + --> tests/ui/borrow_deref_ref.rs:16:22 | LL | let b = &mut &*bar(&12); | ^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `bar(&12)` error: deref on an immutable reference - --> tests/ui/borrow_deref_ref.rs:69:23 + --> tests/ui/borrow_deref_ref.rs:71: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 be9887339597..e51d9912b308 100644 --- a/tests/ui/borrow_deref_ref_unfixable.rs +++ b/tests/ui/borrow_deref_ref_unfixable.rs @@ -7,7 +7,8 @@ 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` + //~^ borrow_deref_ref + + } } diff --git a/tests/ui/borrow_interior_mutable_const/others.rs b/tests/ui/borrow_interior_mutable_const/others.rs index a49d53fbbd38..eaf90ce6a8dd 100644 --- a/tests/ui/borrow_interior_mutable_const/others.rs +++ b/tests/ui/borrow_interior_mutable_const/others.rs @@ -62,14 +62,20 @@ mod issue12979 { const CELL_REF: StaticRef<(UnsafeCell,)> = unsafe { StaticRef::new(std::ptr::null()) }; fn main() { - ATOMIC.store(1, Ordering::SeqCst); //~ ERROR: interior mutability - assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR: interior mutability +ATOMIC.store(1, Ordering::SeqCst); +//~^ borrow_interior_mutable_const +assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); +//~^ borrow_interior_mutable_const let _once = ONCE_INIT; - let _once_ref = &ONCE_INIT; //~ ERROR: interior mutability - let _once_ref_2 = &&ONCE_INIT; //~ ERROR: interior mutability - let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR: interior mutability - let _once_mut = &mut ONCE_INIT; //~ ERROR: interior mutability +let _once_ref = &ONCE_INIT; +//~^ borrow_interior_mutable_const +let _once_ref_2 = &&ONCE_INIT; +//~^ borrow_interior_mutable_const +let _once_ref_4 = &&&&ONCE_INIT; +//~^ borrow_interior_mutable_const +let _once_mut = &mut ONCE_INIT; +//~^ borrow_interior_mutable_const let _atomic_into_inner = ATOMIC.into_inner(); // these should be all fine. let _twice = (ONCE_INIT, ONCE_INIT); @@ -80,22 +86,30 @@ fn main() { let _ref_array_once = &[ONCE_INIT, ONCE_INIT][0]; // referencing projection is still bad. - let _ = &ATOMIC_TUPLE; //~ ERROR: interior mutability - let _ = &ATOMIC_TUPLE.0; //~ ERROR: interior mutability - let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR: interior mutability - let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability - let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR: interior mutability +let _ = &ATOMIC_TUPLE; +//~^ borrow_interior_mutable_const +let _ = &ATOMIC_TUPLE.0; +//~^ borrow_interior_mutable_const +let _ = &(&&&&ATOMIC_TUPLE).0; +//~^ borrow_interior_mutable_const +let _ = &ATOMIC_TUPLE.0[0]; +//~^ borrow_interior_mutable_const +let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); +//~^ borrow_interior_mutable_const let _ = &ATOMIC_TUPLE.2; let _ = (&&&&ATOMIC_TUPLE).0; let _ = (&&&&ATOMIC_TUPLE).2; let _ = ATOMIC_TUPLE.0; - let _ = ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability +let _ = ATOMIC_TUPLE.0[0]; +//~^ borrow_interior_mutable_const let _ = ATOMIC_TUPLE.1.into_iter(); let _ = ATOMIC_TUPLE.2; let _ = &{ ATOMIC_TUPLE }; - CELL.set(2); //~ ERROR: interior mutability - assert_eq!(CELL.get(), 6); //~ ERROR: interior mutability +CELL.set(2); +//~^ borrow_interior_mutable_const +assert_eq!(CELL.get(), 6); +//~^ borrow_interior_mutable_const assert_eq!(INTEGER, 8); assert!(STRING.is_empty()); diff --git a/tests/ui/borrow_interior_mutable_const/others.stderr b/tests/ui/borrow_interior_mutable_const/others.stderr index 4cefcc28008d..f15664030151 100644 --- a/tests/ui/borrow_interior_mutable_const/others.stderr +++ b/tests/ui/borrow_interior_mutable_const/others.stderr @@ -1,8 +1,8 @@ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:65:5 + --> tests/ui/borrow_interior_mutable_const/others.rs:65:1 | -LL | ATOMIC.store(1, Ordering::SeqCst); - | ^^^^^^ +LL | ATOMIC.store(1, Ordering::SeqCst); + | ^^^^^^ | = help: assign this const to a local or static variable, and use the variable here note: the lint level is defined here @@ -12,106 +12,106 @@ LL | #![deny(clippy::borrow_interior_mutable_const)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:66:16 + --> tests/ui/borrow_interior_mutable_const/others.rs:67:12 | -LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); - | ^^^^^^ +LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); + | ^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:69:22 + --> tests/ui/borrow_interior_mutable_const/others.rs:71:18 | -LL | let _once_ref = &ONCE_INIT; +LL | let _once_ref = &ONCE_INIT; + | ^^^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:73:21 + | +LL | let _once_ref_2 = &&ONCE_INIT; + | ^^^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:75:23 + | +LL | let _once_ref_4 = &&&&ONCE_INIT; + | ^^^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:77:22 + | +LL | let _once_mut = &mut ONCE_INIT; | ^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:70:25 + --> tests/ui/borrow_interior_mutable_const/others.rs:89:10 | -LL | let _once_ref_2 = &&ONCE_INIT; - | ^^^^^^^^^ +LL | let _ = &ATOMIC_TUPLE; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:71:27 + --> tests/ui/borrow_interior_mutable_const/others.rs:91:10 | -LL | let _once_ref_4 = &&&&ONCE_INIT; - | ^^^^^^^^^ +LL | let _ = &ATOMIC_TUPLE.0; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:72:26 + --> tests/ui/borrow_interior_mutable_const/others.rs:93:15 | -LL | let _once_mut = &mut ONCE_INIT; - | ^^^^^^^^^ +LL | let _ = &(&&&&ATOMIC_TUPLE).0; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:83:14 + --> tests/ui/borrow_interior_mutable_const/others.rs:95:10 | -LL | let _ = &ATOMIC_TUPLE; - | ^^^^^^^^^^^^ +LL | let _ = &ATOMIC_TUPLE.0[0]; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:84:14 + --> tests/ui/borrow_interior_mutable_const/others.rs:97:9 | -LL | let _ = &ATOMIC_TUPLE.0; - | ^^^^^^^^^^^^ +LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:85:19 + --> tests/ui/borrow_interior_mutable_const/others.rs:103:9 | -LL | let _ = &(&&&&ATOMIC_TUPLE).0; - | ^^^^^^^^^^^^ +LL | let _ = ATOMIC_TUPLE.0[0]; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:86:14 + --> tests/ui/borrow_interior_mutable_const/others.rs:109:1 | -LL | let _ = &ATOMIC_TUPLE.0[0]; - | ^^^^^^^^^^^^ +LL | CELL.set(2); + | ^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:87:13 + --> tests/ui/borrow_interior_mutable_const/others.rs:111:12 | -LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); - | ^^^^^^^^^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:92:13 - | -LL | let _ = ATOMIC_TUPLE.0[0]; - | ^^^^^^^^^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:97:5 - | -LL | CELL.set(2); - | ^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:98:16 - | -LL | assert_eq!(CELL.get(), 6); - | ^^^^ +LL | assert_eq!(CELL.get(), 6); + | ^^^^ | = help: assign this const to a local or static variable, and use the variable here diff --git a/tests/ui/borrow_interior_mutable_const/traits.rs b/tests/ui/borrow_interior_mutable_const/traits.rs index 5570e7cd6d2e..8e2b7ffd554f 100644 --- a/tests/ui/borrow_interior_mutable_const/traits.rs +++ b/tests/ui/borrow_interior_mutable_const/traits.rs @@ -12,7 +12,8 @@ trait ConcreteTypes { const STRING: String; fn function() { - let _ = &Self::ATOMIC; //~ ERROR: interior mutability +let _ = &Self::ATOMIC; +//~^ borrow_interior_mutable_const let _ = &Self::STRING; } } @@ -23,7 +24,8 @@ impl ConcreteTypes for u64 { fn function() { // Lint this again since implementers can choose not to borrow it. - let _ = &Self::ATOMIC; //~ ERROR: interior mutability +let _ = &Self::ATOMIC; +//~^ borrow_interior_mutable_const let _ = &Self::STRING; } } @@ -48,7 +50,8 @@ impl GenericTypes for Vec { fn function() { let _ = &Self::TO_REMAIN_GENERIC; - let _ = &Self::TO_BE_CONCRETE; //~ ERROR: interior mutability +let _ = &Self::TO_BE_CONCRETE; +//~^ borrow_interior_mutable_const } } @@ -83,8 +86,10 @@ impl AssocTypes for Vec { fn function() { let _ = &Self::TO_BE_FROZEN; - let _ = &Self::TO_BE_UNFROZEN; //~ ERROR: interior mutability - let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR: interior mutability +let _ = &Self::TO_BE_UNFROZEN; +//~^ borrow_interior_mutable_const +let _ = &Self::WRAPPED_TO_BE_UNFROZEN; +//~^ borrow_interior_mutable_const let _ = &Self::WRAPPED_TO_BE_GENERIC_PARAM; } } @@ -106,7 +111,8 @@ where fn function() { let _ = &Self::NOT_BOUNDED; - let _ = &Self::BOUNDED; //~ ERROR: interior mutability +let _ = &Self::BOUNDED; +//~^ borrow_interior_mutable_const } } @@ -119,7 +125,8 @@ where fn function() { let _ = &Self::NOT_BOUNDED; - let _ = &Self::BOUNDED; //~ ERROR: interior mutability +let _ = &Self::BOUNDED; +//~^ borrow_interior_mutable_const } } @@ -148,8 +155,10 @@ impl SelfType for AtomicUsize { const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); fn function() { - let _ = &Self::SELF; //~ ERROR: interior mutability - let _ = &Self::WRAPPED_SELF; //~ ERROR: interior mutability +let _ = &Self::SELF; +//~^ borrow_interior_mutable_const +let _ = &Self::WRAPPED_SELF; +//~^ borrow_interior_mutable_const } } @@ -158,8 +167,10 @@ trait BothOfCellAndGeneric { const INDIRECT: Cell<*const T>; fn function() { - let _ = &Self::DIRECT; //~ ERROR: interior mutability - let _ = &Self::INDIRECT; //~ ERROR: interior mutability +let _ = &Self::DIRECT; +//~^ borrow_interior_mutable_const +let _ = &Self::INDIRECT; +//~^ borrow_interior_mutable_const } } @@ -168,8 +179,10 @@ impl BothOfCellAndGeneric for Vec { const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null()); fn function() { - let _ = &Self::DIRECT; //~ ERROR: interior mutability - let _ = &Self::INDIRECT; //~ ERROR: interior mutability +let _ = &Self::DIRECT; +//~^ borrow_interior_mutable_const +let _ = &Self::INDIRECT; +//~^ borrow_interior_mutable_const } } @@ -188,15 +201,19 @@ where const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); fn function() { - let _ = &Self::ATOMIC; //~ ERROR: interior mutability +let _ = &Self::ATOMIC; +//~^ borrow_interior_mutable_const let _ = &Self::COW; let _ = &Self::GENERIC_TYPE; let _ = &Self::ASSOC_TYPE; - let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR: interior mutability +let _ = &Self::BOUNDED_ASSOC_TYPE; +//~^ borrow_interior_mutable_const } } fn main() { - u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR: interior mutability - assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR: interior mutability +u64::ATOMIC.store(5, Ordering::SeqCst); +//~^ borrow_interior_mutable_const +assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); +//~^ borrow_interior_mutable_const } diff --git a/tests/ui/borrow_interior_mutable_const/traits.stderr b/tests/ui/borrow_interior_mutable_const/traits.stderr index 8602b46b0dcf..6998ba6fc090 100644 --- a/tests/ui/borrow_interior_mutable_const/traits.stderr +++ b/tests/ui/borrow_interior_mutable_const/traits.stderr @@ -1,8 +1,8 @@ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:15:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:15:10 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here note: the lint level is defined here @@ -12,130 +12,130 @@ LL | #![deny(clippy::borrow_interior_mutable_const)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:26:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:27:10 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:51:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:53:10 | -LL | let _ = &Self::TO_BE_CONCRETE; - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::TO_BE_CONCRETE; + | ^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:86:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:89:10 | -LL | let _ = &Self::TO_BE_UNFROZEN; - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::TO_BE_UNFROZEN; + | ^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:87:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:91:10 | -LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:109:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:114:10 | -LL | let _ = &Self::BOUNDED; - | ^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED; + | ^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:122:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:128:10 | -LL | let _ = &Self::BOUNDED; - | ^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED; + | ^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:151:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:158:10 | -LL | let _ = &Self::SELF; - | ^^^^^^^^^^ +LL | let _ = &Self::SELF; + | ^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:152:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:160:10 | -LL | let _ = &Self::WRAPPED_SELF; - | ^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::WRAPPED_SELF; + | ^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:161:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:170:10 | -LL | let _ = &Self::DIRECT; - | ^^^^^^^^^^^^ +LL | let _ = &Self::DIRECT; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:162:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:172:10 | -LL | let _ = &Self::INDIRECT; - | ^^^^^^^^^^^^^^ +LL | let _ = &Self::INDIRECT; + | ^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:171:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:182:10 | -LL | let _ = &Self::DIRECT; - | ^^^^^^^^^^^^ +LL | let _ = &Self::DIRECT; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:172:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:184:10 | -LL | let _ = &Self::INDIRECT; - | ^^^^^^^^^^^^^^ +LL | let _ = &Self::INDIRECT; + | ^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:191:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:204:10 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:195:18 + --> tests/ui/borrow_interior_mutable_const/traits.rs:209:10 | -LL | let _ = &Self::BOUNDED_ASSOC_TYPE; - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED_ASSOC_TYPE; + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:200:5 + --> tests/ui/borrow_interior_mutable_const/traits.rs:215:1 | -LL | u64::ATOMIC.store(5, Ordering::SeqCst); - | ^^^^^^^^^^^ +LL | u64::ATOMIC.store(5, Ordering::SeqCst); + | ^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:201:16 + --> tests/ui/borrow_interior_mutable_const/traits.rs:217:12 | -LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); - | ^^^^^^^^^^^ +LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); + | ^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here diff --git a/tests/ui/box_collection.rs b/tests/ui/box_collection.rs index 499625ea9c31..61117412016a 100644 --- a/tests/ui/box_collection.rs +++ b/tests/ui/box_collection.rs @@ -19,7 +19,8 @@ fn test_macro() { } fn test1(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Vec<..>` +//~^ box_collection + fn test2(foo: Box)>) { // pass if #31 is fixed @@ -27,28 +28,36 @@ fn test2(foo: Box)>) { } fn test3(foo: Box) {} -//~^ ERROR: you seem to be trying to use `Box`. Consider using just `String` +//~^ box_collection + fn test4(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashMap< +//~^ box_collection + fn test5(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashSet< +//~^ box_collection + fn test6(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `VecDequ +//~^ box_collection + fn test7(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Linke +//~^ box_collection + fn test8(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeMa +//~^ box_collection + fn test9(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeSe +//~^ box_collection + fn test10(foo: Box>) {} -//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Binar +//~^ box_collection + fn test_local_not_linted() { let _: Box>; diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index ebbc3d92b57f..644556edd572 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -9,7 +9,7 @@ LL | fn test1(foo: Box>) {} = help: to override `-D warnings` add `#[allow(clippy::box_collection)]` error: you seem to be trying to use `Box`. Consider using just `String` - --> tests/ui/box_collection.rs:29:15 + --> tests/ui/box_collection.rs:30:15 | LL | fn test3(foo: Box) {} | ^^^^^^^^^^^ @@ -17,7 +17,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<..>` - --> tests/ui/box_collection.rs:32:15 + --> tests/ui/box_collection.rs:34:15 | LL | fn test4(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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<..>` - --> tests/ui/box_collection.rs:35:15 + --> tests/ui/box_collection.rs:38:15 | LL | fn test5(foo: Box>) {} | ^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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<..>` - --> tests/ui/box_collection.rs:38:15 + --> tests/ui/box_collection.rs:42:15 | LL | fn test6(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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<..>` - --> tests/ui/box_collection.rs:41:15 + --> tests/ui/box_collection.rs:46:15 | LL | fn test7(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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<..>` - --> tests/ui/box_collection.rs:44:15 + --> tests/ui/box_collection.rs:50:15 | LL | fn test8(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,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<..>` - --> tests/ui/box_collection.rs:47:15 + --> tests/ui/box_collection.rs:54:15 | LL | fn test9(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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<..>` - --> tests/ui/box_collection.rs:50:16 + --> tests/ui/box_collection.rs:58:16 | LL | fn test10(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 1f2f57c2507d..80000f5de4fd 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -32,14 +32,22 @@ macro_rules! box_new { fn main() { let string1: Box = Box::default(); + //~^ box_default let string2: Box = Box::default(); + //~^ box_default let impl1: Box = Box::default(); + //~^ box_default let vec: Box> = Box::default(); + //~^ box_default let byte: Box = Box::default(); + //~^ box_default let vec2: Box> = Box::default(); + //~^ box_default let vec3: Box> = Box::default(); + //~^ box_default let plain_default = Box::default(); + //~^ box_default let _: Box = plain_default; let _: Box = Box::new(default!()); @@ -57,6 +65,7 @@ fn main() { let vec4: Box<_> = Box::new(Vec::from([false; 0])); let more = ret_ty_fn(); call_ty_fn(Box::default()); + //~^ box_default issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or @@ -84,6 +93,7 @@ impl X { fn same_generic_param() { Self::x(Box::default()); + //~^ box_default } } diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index addfebc24f58..4681016d7cd3 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -32,14 +32,22 @@ macro_rules! box_new { fn main() { let string1: Box = Box::new(Default::default()); + //~^ box_default let string2: Box = Box::new(String::new()); + //~^ box_default let impl1: Box = Box::new(Default::default()); + //~^ box_default let vec: Box> = Box::new(Vec::new()); + //~^ box_default let byte: Box = Box::new(u8::default()); + //~^ box_default let vec2: Box> = Box::new(vec![]); + //~^ box_default let vec3: Box> = Box::new(Vec::from([])); + //~^ box_default let plain_default = Box::new(Default::default()); + //~^ box_default let _: Box = plain_default; let _: Box = Box::new(default!()); @@ -57,6 +65,7 @@ fn main() { let vec4: Box<_> = Box::new(Vec::from([false; 0])); let more = ret_ty_fn(); call_ty_fn(Box::new(u8::default())); + //~^ box_default issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or @@ -84,6 +93,7 @@ impl X { fn same_generic_param() { Self::x(Box::new(T::default())); + //~^ box_default } } diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index 39fd0d29bbf9..f63d97665b34 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -8,55 +8,55 @@ LL | let string1: Box = Box::new(Default::default()); = help: to override `-D warnings` add `#[allow(clippy::box_default)]` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:35:32 + --> tests/ui/box_default.rs:36:32 | LL | let string2: Box = Box::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:36:41 + --> tests/ui/box_default.rs:38:41 | LL | let impl1: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:37:29 + --> tests/ui/box_default.rs:40:29 | LL | let vec: Box> = Box::new(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:38:25 + --> tests/ui/box_default.rs:42:25 | LL | let byte: Box = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:39:45 + --> tests/ui/box_default.rs:44:45 | LL | let vec2: Box> = Box::new(vec![]); | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:40:32 + --> tests/ui/box_default.rs:46:32 | LL | let vec3: Box> = Box::new(Vec::from([])); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:42:25 + --> tests/ui/box_default.rs:49:25 | LL | let plain_default = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:59:16 + --> tests/ui/box_default.rs:67:16 | LL | call_ty_fn(Box::new(u8::default())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:86:17 + --> tests/ui/box_default.rs:95:17 | LL | Self::x(Box::new(T::default())); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` diff --git a/tests/ui/box_default_no_std.rs b/tests/ui/box_default_no_std.rs index edb701fcd084..2881caf0c185 100644 --- a/tests/ui/box_default_no_std.rs +++ b/tests/ui/box_default_no_std.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::box_default)] #![no_std] #![crate_type = "lib"] diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index 4f361f5162be..fa234dce1a99 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -38,8 +38,9 @@ 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` +//~^ boxed_local + + x.foo(); } @@ -121,7 +122,8 @@ pub struct PeekableSeekable { } pub fn new(_needs_name: Box>) -> () {} -//~^ ERROR: local variable doesn't need to be boxed here +//~^ boxed_local + /// Regression for #916, #1123 /// @@ -187,7 +189,8 @@ 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 + //~^ boxed_local + 4 } } @@ -195,7 +198,8 @@ mod issue4804 { trait WarnTrait { // warn on `x: Box` fn foo(x: Box) {} - //~^ ERROR: local variable doesn't need to be boxed here + //~^ boxed_local + } } diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 08fe375afb23..5ce2c8083f15 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -8,19 +8,19 @@ LL | fn warn_arg(x: Box) { = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:123:12 + --> tests/ui/boxed_local.rs:124:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:189:44 + --> tests/ui/boxed_local.rs:191:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:197:16 + --> tests/ui/boxed_local.rs:200:16 | LL | fn foo(x: Box) {} | ^ diff --git a/tests/ui/branches_sharing_code/false_positives.rs b/tests/ui/branches_sharing_code/false_positives.rs index 5e3a1a29693f..49496e631fb1 100644 --- a/tests/ui/branches_sharing_code/false_positives.rs +++ b/tests/ui/branches_sharing_code/false_positives.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code)] #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.rs b/tests/ui/branches_sharing_code/shared_at_bottom.rs index 549908b8770e..050c8c0d53f2 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -33,8 +33,9 @@ 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 + //~^ branches_sharing_code + + println!("Block end!"); result }; @@ -53,7 +54,8 @@ 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 + //~^ branches_sharing_code + } // Use of outer scope value @@ -71,7 +73,8 @@ 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 + //~^ branches_sharing_code + "I'm moveable because I know: `outer_scope_value`: '{}'", outer_scope_value ); @@ -84,7 +87,8 @@ fn simple_examples() { println!("Hello World"); } else { println!("Hello World"); - //~^ ERROR: all if blocks contain the same code at the end + //~^ branches_sharing_code + } } } @@ -101,7 +105,8 @@ 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 + //~^ branches_sharing_code + println!("{}", later_used_value); // I'm expecting a note about this } @@ -115,7 +120,8 @@ 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 + //~^ branches_sharing_code + println!("This is the new simple_example: {}", simple_examples); } simple_examples(); @@ -181,8 +187,9 @@ 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 + //~^ branches_sharing_code + + }; if x == 9 { @@ -190,8 +197,9 @@ 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 + //~^ branches_sharing_code + + } } @@ -204,7 +212,8 @@ 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 + //~^ branches_sharing_code + } 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 36b177739732..b7bb07775241 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -2,9 +2,7 @@ error: all if blocks contain the same code at the end --> tests/ui/branches_sharing_code/shared_at_bottom.rs:35:5 | LL | / let result = false; -LL | | -LL | | -LL | | println!("Block end!"); +... | LL | | result LL | | }; | |_____^ @@ -20,16 +18,17 @@ help: consider moving these statements after the if LL ~ } LL + let result = false; LL + -LL + +LL + +LL + LL + println!("Block end!"); LL ~ result; | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:55:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:56:5 | LL | / println!("Same end of block"); -LL | | +... | LL | | } | |_____^ | @@ -40,10 +39,11 @@ LL + println!("Same end of block"); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:73:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:75:5 | LL | / println!( LL | | +LL | | LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | outer_scope_value LL | | ); @@ -55,16 +55,17 @@ help: consider moving these statements after the if LL ~ } LL + println!( LL + +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 - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:86:9 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:89:9 | LL | / println!("Hello World"); -LL | | +... | LL | | } | |_________^ | @@ -75,10 +76,11 @@ LL + println!("Hello World"); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:103:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:107:5 | LL | / let later_used_value = "A string value"; LL | | +LL | | LL | | println!("{}", later_used_value); LL | | // I'm expecting a note about this LL | | } @@ -90,14 +92,16 @@ help: consider moving these statements after the if LL ~ } LL + let later_used_value = "A string value"; LL + +LL + LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:117:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:122:5 | LL | / let simple_examples = "I now identify as a &str :)"; LL | | +LL | | LL | | println!("This is the new simple_example: {}", simple_examples); LL | | } | |_____^ @@ -108,11 +112,12 @@ help: consider moving these statements after the if LL ~ } LL + let simple_examples = "I now identify as a &str :)"; LL + +LL + LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:183:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:189:5 | LL | / x << 2 ... | @@ -127,7 +132,7 @@ LL ~ x << 2; | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:192:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:199:5 | LL | / x * 4 ... | @@ -142,7 +147,7 @@ LL + x * 4 | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:206:44 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:214: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 9af81f6f7cdd..a6f8ce8a3816 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/tests/ui/branches_sharing_code/shared_at_top.rs @@ -9,16 +9,18 @@ fn simple_examples() { // Simple if true { + //~^ branches_sharing_code println!("Hello World!"); println!("I'm branch nr: 1"); } else { println!("Hello World!"); println!("I'm branch nr: 2"); } - //~^^^^^^^ ERROR: all if blocks contain the same code at the start + // Else if if x == 0 { + //~^ branches_sharing_code let y = 9; println!("The value y was set to: `{}`", y); let _z = y; @@ -37,11 +39,12 @@ fn simple_examples() { println!("Ha, Pascal allows you to start the array where you want") } - //~^^^^^^^^^^^^^^^^^^^ ERROR: all if blocks contain the same code at the start + // Return a value let _ = if x == 7 { - //~^ ERROR: all if blocks contain the same code at the start + //~^ branches_sharing_code + let y = 16; println!("What can I say except: \"you're welcome?\""); let _ = y; @@ -60,6 +63,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 { + //~^ branches_sharing_code let used_value_name = "Different type"; println!("Str: {}", used_value_name); let _ = 1; @@ -68,14 +72,15 @@ fn simple_but_suggestion_is_invalid() { println!("Str: {}", used_value_name); let _ = 2; } - //~^^^^^^^^^ ERROR: all if blocks contain the same code at the start + let _ = used_value_name; // This can be automatically moved as `can_be_overridden` is not used again let can_be_overridden = 8; let _ = can_be_overridden; if x == 11 { - //~^ ERROR: all if blocks contain the same code at the start + //~^ branches_sharing_code + let can_be_overridden = "Move me"; println!("I'm also moveable"); let _ = 111; @@ -92,7 +97,8 @@ 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 + //~^ branches_sharing_code + println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); println!("Because `IF_SAME_THEN_ELSE` is allowed here"); } else { @@ -105,7 +111,8 @@ fn check_if_same_than_else_mask() { } else { println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); } - //~^^^^^ ERROR: this `if` has identical blocks + //~^^^^^ if_same_then_else + } #[allow(clippy::vec_init_then_push)] diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index 0d4e19be1f52..5b0422d5df18 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 --> tests/ui/branches_sharing_code/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 - --> tests/ui/branches_sharing_code/shared_at_top.rs:21:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:22:5 | LL | / if x == 0 { +LL | | LL | | let y = 9; LL | | println!("The value y was set to: `{}`", y); LL | | let _z = y; @@ -35,10 +37,10 @@ LL + if x == 0 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:43:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:45:5 | LL | / let _ = if x == 7 { -LL | | +... | LL | | let y = 16; | |___________________^ | @@ -49,9 +51,10 @@ LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:62:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:65:5 | LL | / if x == 10 { +LL | | LL | | let used_value_name = "Different type"; LL | | println!("Str: {}", used_value_name); | |_____________________________________________^ @@ -65,10 +68,11 @@ LL + if x == 10 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:77:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:81:5 | LL | / if x == 11 { LL | | +LL | | LL | | let can_be_overridden = "Move me"; LL | | println!("I'm also moveable"); | |______________________________________^ @@ -82,10 +86,11 @@ LL + if x == 11 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:94:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:99:5 | LL | / if x == 2020 { LL | | +LL | | LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); | |________________________________________________________________^ @@ -98,7 +103,7 @@ LL + if x == 2020 { | error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/shared_at_top.rs:103:18 + --> tests/ui/branches_sharing_code/shared_at_top.rs:109:18 | LL | if x == 2019 { | __________________^ @@ -107,7 +112,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/shared_at_top.rs:105:12 + --> tests/ui/branches_sharing_code/shared_at_top.rs:111: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 36620ee1a9bf..799f58d28430 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,7 +15,8 @@ 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 + //~^ branches_sharing_code + let t = 7; let _overlap_start = t * 2; let _overlap_end = 2 * t; @@ -32,7 +33,8 @@ 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 + //~^ branches_sharing_code + let r = 7; let _overlap_start = r; let _overlap_middle = r * r; @@ -62,7 +64,8 @@ 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 + //~^ branches_sharing_code + let a = 0xcafe; let b = 0xffff00ff; let e_id = gen_id(a, b); @@ -96,7 +99,8 @@ 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 + //~^ branches_sharing_code + let _ = 19; let _splitter = 6; @@ -109,7 +113,8 @@ 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 + //~^ branches_sharing_code + 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 b79307f96778..2200ab450890 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 @@ -3,13 +3,14 @@ error: all if blocks contain the same code at both the start and the end | LL | / if x == 7 { LL | | +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 - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:30:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:31:5 | LL | / let _u = 9; LL | | } @@ -33,17 +34,18 @@ LL + let _u = 9; | error: all if blocks contain the same code at both the start and the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:34:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:35:5 | LL | / if x == 99 { LL | | +LL | | LL | | let r = 7; LL | | let _overlap_start = r; LL | | let _overlap_middle = r * r; | |____________________________________^ | note: this code is shared at the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:46:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:48:5 | LL | / let _overlap_end = r * r * r; LL | | let z = "end"; @@ -65,17 +67,18 @@ LL + let z = "end"; | error: all if blocks contain the same code at both the start and the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:64:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:66:5 | LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 { LL | | +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 - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:85:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:88:5 | LL | / let pack = DataPack { LL | | id: e_id, @@ -105,15 +108,15 @@ LL + process_data(pack); | error: all if blocks contain the same code at both the start and the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:98:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:101:5 | LL | / let _ = if x == 7 { -LL | | +... | LL | | let _ = 19; | |___________________^ | note: this code is shared at the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:108:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:112:5 | LL | / x << 2 LL | | }; @@ -131,15 +134,15 @@ LL ~ x << 2; | error: all if blocks contain the same code at both the start and the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:111:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:115:5 | LL | / if x == 9 { -LL | | +... | LL | | let _ = 17; | |___________________^ | note: this code is shared at the end - --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:121:5 + --> tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs:126: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 b63819d7c393..23ea86c88f54 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.rs +++ b/tests/ui/branches_sharing_code/valid_if_blocks.rs @@ -109,7 +109,8 @@ fn valid_examples() { if false { } else { } - //~^^^ ERROR: this `if` has identical blocks + //~^^^ if_same_then_else + } /// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint @@ -127,11 +128,13 @@ fn trigger_other_lint() { println!("How are u today?"); let _ = "This is a string"; } - //~^^^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^^^ if_same_then_else + // Only same expression let _ = if x == 6 { 7 } else { 7 }; - //~^ ERROR: this `if` has identical blocks + //~^ if_same_then_else + // Same in else if block let _ = if x == 67 { @@ -146,7 +149,8 @@ fn trigger_other_lint() { if y == 90 { "=^.^=" } else { ":D" } }; - //~^^^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^^^ if_same_then_else + if x == 0 { println!("I'm single"); @@ -155,7 +159,8 @@ fn trigger_other_lint() { } else { println!("I'm a doppelgänger"); } - //~^^^^^ ERROR: this `if` has identical blocks + //~^^^^^ if_same_then_else + } fn main() {} diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/tests/ui/branches_sharing_code/valid_if_blocks.stderr index 4c7e4141b629..a0c4dd24d6b4 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -20,7 +20,7 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:121:15 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:122:15 | LL | if x == 0 { | _______________^ @@ -31,7 +31,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:125:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:126:12 | LL | } else { | ____________^ @@ -42,19 +42,19 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:133:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:135:23 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:133:34 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:135:34 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:140:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:143:23 | LL | } else if x == 68 { | _______________________^ @@ -65,7 +65,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:144:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:147:12 | LL | } else { | ____________^ @@ -76,7 +76,7 @@ LL | | }; | |_____^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:153:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:157:23 | LL | } else if x == 68 { | _______________________^ @@ -85,7 +85,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:155:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:159:12 | LL | } else { | ____________^ diff --git a/tests/ui/builtin_type_shadow.rs b/tests/ui/builtin_type_shadow.rs index c5addd53434c..41d6207ea3f5 100644 --- a/tests/ui/builtin_type_shadow.rs +++ b/tests/ui/builtin_type_shadow.rs @@ -2,8 +2,9 @@ #![allow(non_camel_case_types)] fn foo(a: u32) -> u32 { +//~^ builtin_type_shadow 42 - //~^ ERROR: mismatched types + } fn main() {} diff --git a/tests/ui/builtin_type_shadow.stderr b/tests/ui/builtin_type_shadow.stderr index 033204af9255..a62b41d5c271 100644 --- a/tests/ui/builtin_type_shadow.stderr +++ b/tests/ui/builtin_type_shadow.stderr @@ -8,12 +8,13 @@ LL | fn foo(a: u32) -> u32 { = help: to override `-D warnings` add `#[allow(clippy::builtin_type_shadow)]` error[E0308]: mismatched types - --> tests/ui/builtin_type_shadow.rs:5:5 + --> tests/ui/builtin_type_shadow.rs:6:5 | LL | fn foo(a: u32) -> u32 { | --- --- expected `u32` because of return type | | | expected this type parameter +LL | LL | 42 | ^^ expected type parameter `u32`, found integer | diff --git a/tests/ui/byte_char_slices.fixed b/tests/ui/byte_char_slices.fixed index d1db58f9363e..b0c1b1f034b4 100644 --- a/tests/ui/byte_char_slices.fixed +++ b/tests/ui/byte_char_slices.fixed @@ -3,11 +3,16 @@ fn main() { let bad = b"abc"; + //~^ byte_char_slices let quotes = b"\"Hi"; + //~^ byte_char_slices let quotes = b"'Sup"; + //~^ byte_char_slices let escapes = b"\x42Esc"; + //~^ byte_char_slices let good = &[b'a', 0x42]; let good = [b'a', b'a']; + //~^ useless_vec let good: u8 = [b'a', b'c'].into_iter().sum(); } diff --git a/tests/ui/byte_char_slices.rs b/tests/ui/byte_char_slices.rs index 18648fffceb4..0d6953dda97e 100644 --- a/tests/ui/byte_char_slices.rs +++ b/tests/ui/byte_char_slices.rs @@ -3,11 +3,16 @@ fn main() { let bad = &[b'a', b'b', b'c']; + //~^ byte_char_slices let quotes = &[b'"', b'H', b'i']; + //~^ byte_char_slices let quotes = &[b'\'', b'S', b'u', b'p']; + //~^ byte_char_slices let escapes = &[b'\x42', b'E', b's', b'c']; + //~^ byte_char_slices let good = &[b'a', 0x42]; let good = vec![b'a', b'a']; + //~^ useless_vec let good: u8 = [b'a', b'c'].into_iter().sum(); } diff --git a/tests/ui/byte_char_slices.stderr b/tests/ui/byte_char_slices.stderr index 4e2b5d8a7329..2556aa9c0f76 100644 --- a/tests/ui/byte_char_slices.stderr +++ b/tests/ui/byte_char_slices.stderr @@ -8,25 +8,25 @@ LL | let bad = &[b'a', b'b', b'c']; = help: to override `-D warnings` add `#[allow(clippy::byte_char_slices)]` error: can be more succinctly written as a byte str - --> tests/ui/byte_char_slices.rs:6:18 + --> tests/ui/byte_char_slices.rs:7:18 | LL | let quotes = &[b'"', b'H', b'i']; | ^^^^^^^^^^^^^^^^^^^ help: try: `b"\"Hi"` error: can be more succinctly written as a byte str - --> tests/ui/byte_char_slices.rs:7:18 + --> tests/ui/byte_char_slices.rs:9:18 | LL | let quotes = &[b'\'', b'S', b'u', b'p']; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b"'Sup"` error: can be more succinctly written as a byte str - --> tests/ui/byte_char_slices.rs:8:19 + --> tests/ui/byte_char_slices.rs:11:19 | LL | let escapes = &[b'\x42', b'E', b's', b'c']; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b"\x42Esc"` error: useless use of `vec!` - --> tests/ui/byte_char_slices.rs:11:16 + --> tests/ui/byte_char_slices.rs:15:16 | LL | let good = vec![b'a', b'a']; | ^^^^^^^^^^^^^^^^ help: you can use an array directly: `[b'a', b'a']` diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index f3b02fda8a81..bad39fcf8f66 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -8,11 +8,13 @@ fn main() { // naive byte count let _ = x.iter().filter(|&&a| a == 0).count(); - //~^ ERROR: you appear to be counting bytes the naive way + //~^ naive_bytecount + // naive byte count let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); - //~^ ERROR: you appear to be counting bytes the naive way + //~^ naive_bytecount + // not an equality count, OK. let _ = x.iter().filter(|a| **a > 0).count(); @@ -30,7 +32,8 @@ fn main() { // naive byte count let _ = x.iter().filter(|a| b + 1 == **a).count(); - //~^ ERROR: you appear to be counting bytes the naive way + //~^ naive_bytecount + let y = vec![0_u16; 3]; diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index d1a73fe98358..9a0986f56478 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 - --> tests/ui/bytecount.rs:14:13 + --> tests/ui/bytecount.rs:15: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 - --> tests/ui/bytecount.rs:32:13 + --> tests/ui/bytecount.rs:34: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/bytes_count_to_len.fixed b/tests/ui/bytes_count_to_len.fixed index fb31ceaad7c4..aa0484a83110 100644 --- a/tests/ui/bytes_count_to_len.fixed +++ b/tests/ui/bytes_count_to_len.fixed @@ -5,15 +5,19 @@ use std::io::{BufReader, Read}; fn main() { // should fix, because type is String let _ = String::from("foo").len(); + //~^ bytes_count_to_len let s1 = String::from("foo"); let _ = s1.len(); + //~^ bytes_count_to_len // should fix, because type is &str let _ = "foo".len(); + //~^ bytes_count_to_len let s2 = "foo"; let _ = s2.len(); + //~^ bytes_count_to_len // make sure using count() normally doesn't trigger warning let vector = [0, 1, 2]; diff --git a/tests/ui/bytes_count_to_len.rs b/tests/ui/bytes_count_to_len.rs index 0250059afeb2..7e38858bf783 100644 --- a/tests/ui/bytes_count_to_len.rs +++ b/tests/ui/bytes_count_to_len.rs @@ -5,15 +5,19 @@ use std::io::{BufReader, Read}; fn main() { // should fix, because type is String let _ = String::from("foo").bytes().count(); + //~^ bytes_count_to_len let s1 = String::from("foo"); let _ = s1.bytes().count(); + //~^ bytes_count_to_len // should fix, because type is &str let _ = "foo".bytes().count(); + //~^ bytes_count_to_len let s2 = "foo"; let _ = s2.bytes().count(); + //~^ bytes_count_to_len // make sure using count() normally doesn't trigger warning let vector = [0, 1, 2]; diff --git a/tests/ui/bytes_count_to_len.stderr b/tests/ui/bytes_count_to_len.stderr index b80f3af18f78..999da9ca1365 100644 --- a/tests/ui/bytes_count_to_len.stderr +++ b/tests/ui/bytes_count_to_len.stderr @@ -8,19 +8,19 @@ LL | let _ = String::from("foo").bytes().count(); = help: to override `-D warnings` add `#[allow(clippy::bytes_count_to_len)]` error: using long and hard to read `.bytes().count()` - --> tests/ui/bytes_count_to_len.rs:10:13 + --> tests/ui/bytes_count_to_len.rs:11:13 | LL | let _ = s1.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s1.len()` error: using long and hard to read `.bytes().count()` - --> tests/ui/bytes_count_to_len.rs:13:13 + --> tests/ui/bytes_count_to_len.rs:15:13 | LL | let _ = "foo".bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `"foo".len()` error: using long and hard to read `.bytes().count()` - --> tests/ui/bytes_count_to_len.rs:16:13 + --> tests/ui/bytes_count_to_len.rs:19: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 da35fcb55e5a..6f4c2e7116e9 100644 --- a/tests/ui/bytes_nth.fixed +++ b/tests/ui/bytes_nth.fixed @@ -5,6 +5,9 @@ fn main() { let s = String::from("String"); let _ = s.as_bytes().get(3).copied(); + //~^ bytes_nth let _ = &s.as_bytes()[3]; + //~^ bytes_nth let _ = s[..].as_bytes().get(3).copied(); + //~^ bytes_nth } diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs index 5dbe84ecec8b..27655bebb264 100644 --- a/tests/ui/bytes_nth.rs +++ b/tests/ui/bytes_nth.rs @@ -5,6 +5,9 @@ fn main() { let s = String::from("String"); let _ = s.bytes().nth(3); + //~^ bytes_nth let _ = &s.bytes().nth(3).unwrap(); + //~^ bytes_nth let _ = s[..].bytes().nth(3); + //~^ bytes_nth } diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr index c5f341cb37f6..c421839ff3f5 100644 --- a/tests/ui/bytes_nth.stderr +++ b/tests/ui/bytes_nth.stderr @@ -8,13 +8,13 @@ LL | let _ = s.bytes().nth(3); = help: to override `-D warnings` add `#[allow(clippy::bytes_nth)]` error: called `.bytes().nth().unwrap()` on a `String` - --> tests/ui/bytes_nth.rs:8:14 + --> tests/ui/bytes_nth.rs:9:14 | LL | let _ = &s.bytes().nth(3).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.as_bytes()[3]` error: called `.bytes().nth()` on a `str` - --> tests/ui/bytes_nth.rs:9:13 + --> tests/ui/bytes_nth.rs:11: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 c4d77f24f126..bf7635fdf09b 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.fixed +++ b/tests/ui/case_sensitive_file_extension_comparisons.fixed @@ -14,6 +14,7 @@ fn is_rust_file(filename: &str) -> bool { std::path::Path::new(filename) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) + //~^ case_sensitive_file_extension_comparisons } fn main() { @@ -21,15 +22,18 @@ fn main() { let _ = std::path::Path::new(&String::new()) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons // The fixup should preserve the indentation level { let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); + //~^ case_sensitive_file_extension_comparisons } // The test struct should not trigger the lint failure with .ext12 @@ -39,9 +43,11 @@ fn main() { let _ = std::path::Path::new(&String::new()) .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); + //~^ case_sensitive_file_extension_comparisons let _ = std::path::Path::new("str") .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); + //~^ case_sensitive_file_extension_comparisons // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase let _ = String::new().to_lowercase().ends_with(".EXT12"); diff --git a/tests/ui/case_sensitive_file_extension_comparisons.rs b/tests/ui/case_sensitive_file_extension_comparisons.rs index 690e93c2639a..0c4070a42d4b 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -12,16 +12,20 @@ impl TestStruct { #[allow(dead_code)] fn is_rust_file(filename: &str) -> bool { filename.ends_with(".rs") + //~^ case_sensitive_file_extension_comparisons } fn main() { // std::string::String and &str should trigger the lint failure with .ext12 let _ = String::new().ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons let _ = "str".ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons // The fixup should preserve the indentation level { let _ = "str".ends_with(".ext12"); + //~^ case_sensitive_file_extension_comparisons } // The test struct should not trigger the lint failure with .ext12 @@ -29,7 +33,9 @@ fn main() { // std::string::String and &str should trigger the lint failure with .EXT12 let _ = String::new().ends_with(".EXT12"); + //~^ case_sensitive_file_extension_comparisons let _ = "str".ends_with(".EXT12"); + //~^ case_sensitive_file_extension_comparisons // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase let _ = String::new().to_lowercase().ends_with(".EXT12"); diff --git a/tests/ui/case_sensitive_file_extension_comparisons.stderr b/tests/ui/case_sensitive_file_extension_comparisons.stderr index e21815f251b7..e035534d2699 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -15,7 +15,7 @@ LL + .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) | error: case-sensitive file extension comparison - --> tests/ui/case_sensitive_file_extension_comparisons.rs:19:13 + --> tests/ui/case_sensitive_file_extension_comparisons.rs:20:13 | LL | let _ = String::new().ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> tests/ui/case_sensitive_file_extension_comparisons.rs:20:13 + --> tests/ui/case_sensitive_file_extension_comparisons.rs:22:13 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> tests/ui/case_sensitive_file_extension_comparisons.rs:24:17 + --> tests/ui/case_sensitive_file_extension_comparisons.rs:27:17 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> tests/ui/case_sensitive_file_extension_comparisons.rs:31:13 + --> tests/ui/case_sensitive_file_extension_comparisons.rs:35:13 | LL | let _ = String::new().ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); | error: case-sensitive file extension comparison - --> tests/ui/case_sensitive_file_extension_comparisons.rs:32:13 + --> tests/ui/case_sensitive_file_extension_comparisons.rs:37:13 | LL | let _ = "str".ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 0de53a75c623..b2e92d36f402 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -23,101 +23,141 @@ 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` + //~^ cast_precision_loss + + let x1 = 1i64; x1 as f32; - //~^ ERROR: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, + //~^ cast_precision_loss + x1 as f64; - //~^ ERROR: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, + //~^ cast_precision_loss + let x2 = 1u32; x2 as f32; - //~^ ERROR: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, + //~^ cast_precision_loss + let x3 = 1u64; x3 as f32; - //~^ ERROR: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, + //~^ cast_precision_loss + x3 as f64; - //~^ ERROR: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, + //~^ cast_precision_loss + // Test clippy::cast_possible_truncation 1f32 as i32; - //~^ ERROR: casting `f32` to `i32` may truncate the value + //~^ cast_possible_truncation + 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` + //~^ cast_possible_truncation + //~| cast_sign_loss + + + 1f64 as f32; - //~^ ERROR: casting `f64` to `f32` may truncate the value + //~^ cast_possible_truncation + 1i32 as i8; - //~^ ERROR: casting `i32` to `i8` may truncate the value + //~^ cast_possible_truncation + 1i32 as u8; - //~^ ERROR: casting `i32` to `u8` may truncate the value + //~^ cast_possible_truncation + 1f64 as isize; - //~^ ERROR: casting `f64` to `isize` may truncate the value + //~^ cast_possible_truncation + 1f64 as usize; - //~^ ERROR: casting `f64` to `usize` may truncate the value - //~| ERROR: casting `f64` to `usize` may lose the sign of the value + //~^ cast_possible_truncation + //~| cast_sign_loss + + 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 + //~^ cast_possible_truncation + //~| cast_possible_truncation + //~| cast_sign_loss + + + { let _x: i8 = 1i32 as _; - //~^ ERROR: casting `i32` to `i8` may truncate the value + //~^ cast_possible_truncation + 1f32 as i32; - //~^ ERROR: casting `f32` to `i32` may truncate the value + //~^ cast_possible_truncation + 1f64 as i32; - //~^ ERROR: casting `f64` to `i32` may truncate the value + //~^ cast_possible_truncation + 1f32 as u8; - //~^ ERROR: casting `f32` to `u8` may truncate the value - //~| ERROR: casting `f32` to `u8` may lose the sign of the value + //~^ cast_possible_truncation + //~| cast_sign_loss + + } // 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` + //~^ cast_possible_wrap + + 1u16 as i16; - //~^ ERROR: casting `u16` to `i16` may wrap around the value + //~^ cast_possible_wrap + 1u32 as i32; - //~^ ERROR: casting `u32` to `i32` may wrap around the value + //~^ cast_possible_wrap + 1u64 as i64; - //~^ ERROR: casting `u64` to `i64` may wrap around the value + //~^ cast_possible_wrap + 1usize as isize; - //~^ ERROR: casting `usize` to `isize` may wrap around the value + //~^ cast_possible_wrap + // should not wrap, usize is never 8 bits 1usize as i8; - //~^ ERROR: casting `usize` to `i8` may truncate the value + //~^ cast_possible_truncation + // 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 + //~^ cast_possible_truncation + //~| cast_possible_wrap + + + // 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 + //~^ cast_possible_truncation + //~| cast_possible_wrap + + // wraps on 64 bit ptr size 1usize as i64; - //~^ ERROR: casting `usize` to `i64` may wrap around the value on targets with 64-bit + //~^ cast_possible_wrap + // 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 + //~^ cast_possible_wrap + + // wraps on 32 bit ptr size 1u32 as isize; - //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit + //~^ cast_possible_wrap + // 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 + //~^ cast_possible_truncation + //~| cast_possible_wrap + + // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + 1isize as usize; -1isize as usize; - //~^ ERROR: casting `isize` to `usize` may lose the sign of the value + //~^ cast_sign_loss + 0i8 as u8; i8::MAX as u8; i16::MAX as u16; @@ -128,11 +168,14 @@ fn main() { (-1i8).saturating_abs() as u8; // abs() can return a negative value in release builds (i8::MIN).abs() as u8; - //~^ ERROR: casting `i8` to `u8` may lose the sign of the value + //~^ cast_sign_loss + (-1i16).saturating_abs() as u16; (-1i32).saturating_abs() as u32; (-1i64).abs() as u64; + //~^ cast_sign_loss (-1isize).abs() as usize; + //~^ cast_sign_loss (-1i8).checked_abs().unwrap() as u8; (i8::MIN).checked_abs().unwrap() as u8; @@ -140,6 +183,7 @@ fn main() { (-1i32).checked_abs().unwrap() as u32; // SAFETY: -1 is a small number which will always return Some (unsafe { (-1i64).checked_abs().unwrap_unchecked() }) as u64; + //~^ cast_sign_loss (-1isize).checked_abs().expect("-1 is a small number") as usize; (-1i8).isqrt() as u8; @@ -155,6 +199,7 @@ fn main() { (-1i32).checked_isqrt().unwrap() as u32; // SAFETY: -1 is a small number which will always return Some (unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }) as u64; + //~^ cast_sign_loss (-1isize).checked_isqrt().expect("-1 is a small number") as usize; (-1i8).rem_euclid(1i8) as u8; @@ -206,7 +251,8 @@ 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 + //~^ cast_possible_truncation + // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -220,7 +266,8 @@ 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 + //~^ cast_possible_truncation + #[derive(Clone, Copy)] enum E1 { @@ -243,10 +290,12 @@ fn main() { impl E2 { fn test(self) { let _ = self as u8; - //~^ ERROR: casting `main::E2` to `u8` may truncate the value + //~^ cast_possible_truncation + 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` + //~^ cast_enum_truncation + + // Don't lint. `255..=256` fits in i16 let _ = self as i16; // Don't lint. @@ -287,9 +336,11 @@ fn main() { impl E5 { fn test(self) { let _ = self as i8; - //~^ ERROR: casting `main::E5` to `i8` may truncate the value + //~^ cast_possible_truncation + let _ = Self::A as i8; - //~^ ERROR: casting `main::E5::A` to `i8` will truncate the value + //~^ cast_enum_truncation + // Don't lint. `-129..=127` fits in i16 let _ = self as i16; // Don't lint. @@ -306,7 +357,8 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; - //~^ ERROR: casting `main::E6` to `i16` may truncate the value + //~^ cast_possible_truncation + // 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 @@ -325,7 +377,8 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; - //~^ ERROR: casting `main::E7` to `usize` may truncate the value on targets wi + //~^ cast_possible_truncation + // Don't lint. let _ = Self::A as usize; // Don't lint. `2^32-1..=2^32` fits in u64 @@ -372,7 +425,8 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; - //~^ ERROR: casting `main::E10` to `u16` may truncate the value + //~^ cast_possible_truncation + // Don't lint. let _ = Self::B as u32; // Don't lint. @@ -383,11 +437,13 @@ fn main() { fn avoid_subtract_overflow(q: u32) { let c = (q >> 16) as u8; - //~^ ERROR: casting `u32` to `u8` may truncate the value + //~^ cast_possible_truncation + c as usize; let c = (q / 1000) as u8; - //~^ ERROR: casting `u32` to `u8` may truncate the value + //~^ cast_possible_truncation + c as usize; } @@ -399,70 +455,99 @@ fn issue11642() { fn square(x: i16) -> u32 { let x = x as i32; (x * x) as u32; + //~^ cast_sign_loss x.pow(2) as u32; (-2_i32).saturating_pow(2) as u32 } let _a = |x: i32| -> u32 { (x * x * x * x) as u32 }; + //~^ cast_sign_loss (2_i32).checked_pow(3).unwrap() as u32; + //~^ cast_sign_loss (-2_i32).pow(3) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (3_i32 % 2) as u32; (3_i32 % -2) as u32; (-5_i32 % 2) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (-5_i32 % -2) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (2_i32 >> 1) as u32; (-2_i32 >> 1) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + let x: i32 = 10; (x * x) as u32; + //~^ cast_sign_loss (x * x * x) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + let y: i16 = -2; (y * y * y * y * -2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + (y * y * y / y * 2) as u16; + //~^ cast_sign_loss (y * y / y * 2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + (y / y * y * -2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + //~| eq_op + (y + y + y + -2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + (y + y + y + 2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + let z: i16 = 2; (z + -2) as u16; - //~^ ERROR: casting `i16` to `u16` may lose the sign of the value + //~^ cast_sign_loss + (z + z + 2) as u16; + //~^ cast_sign_loss fn foo(a: i32, b: i32, c: i32) -> u32 { (a * a * b * b * c * c) as u32; + //~^ cast_sign_loss (a * b * c) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a * -b * c) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a * b * c * c) as u32; + //~^ cast_sign_loss (a * -2) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a * b * c * -2) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a / b) as u32; + //~^ cast_sign_loss (a / b * c) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a / b + b * c) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + a.saturating_pow(3) as u32; - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + (a.abs() * b.pow(2) / c.abs()) as u32 - //~^ ERROR: casting `i32` to `u32` may lose the sign of the value + //~^ cast_sign_loss + } } @@ -470,8 +555,11 @@ fn issue11738() { macro_rules! m { () => { let _ = i32::MIN as u32; // cast_sign_loss + //~^ cast_sign_loss let _ = u32::MAX as u8; // cast_possible_truncation + //~^ cast_possible_truncation let _ = std::f64::consts::PI as f32; // cast_possible_truncation + //~^ cast_possible_truncation let _ = 0i8 as i32; // cast_lossless }; } @@ -481,6 +569,8 @@ fn issue11738() { fn issue12506() -> usize { let bar: Result, u32> = Ok(Some(10)); bar.unwrap().unwrap() as usize + //~^ cast_possible_truncation + //~| cast_sign_loss } fn issue12721() { @@ -496,7 +586,9 @@ fn issue12721() { let _ = (999999 & (x() & 255)) as u8; (256 & 999999u64) as u8; - //~^ ERROR: casting `u64` to `u8` may truncate the value + //~^ cast_possible_truncation + (255 % 999999u64) as u8; - //~^ ERROR: casting `u64` to `u8` may truncate the value + //~^ cast_possible_truncation + } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 452482fc88e2..daabb8192141 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -8,37 +8,37 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:29:5 + --> tests/ui/cast.rs:30: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) - --> tests/ui/cast.rs:31:5 + --> tests/ui/cast.rs:33: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) - --> tests/ui/cast.rs:34:5 + --> tests/ui/cast.rs:37: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) - --> tests/ui/cast.rs:37:5 + --> tests/ui/cast.rs:41: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) - --> tests/ui/cast.rs:39:5 + --> tests/ui/cast.rs:44:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:42:5 + --> tests/ui/cast.rs:48:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | 1f32 as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:44:5 + --> tests/ui/cast.rs:51:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -56,7 +56,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 - --> tests/ui/cast.rs:44:5 + --> tests/ui/cast.rs:51:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | 1f32 as u32; = help: to override `-D warnings` add `#[allow(clippy::cast_sign_loss)]` error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:48:5 + --> tests/ui/cast.rs:57:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/cast.rs:50:5 + --> tests/ui/cast.rs:60:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> tests/ui/cast.rs:52:5 + --> tests/ui/cast.rs:63:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> tests/ui/cast.rs:54:5 + --> tests/ui/cast.rs:66:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/cast.rs:56:5 + --> tests/ui/cast.rs:69:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -113,13 +113,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 - --> tests/ui/cast.rs:56:5 + --> tests/ui/cast.rs:69:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> tests/ui/cast.rs:59:5 + --> tests/ui/cast.rs:74:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:59:5 + --> tests/ui/cast.rs:74:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -139,13 +139,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 - --> tests/ui/cast.rs:59:5 + --> tests/ui/cast.rs:74:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> tests/ui/cast.rs:64:22 + --> tests/ui/cast.rs:82:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -157,7 +157,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:66:9 + --> tests/ui/cast.rs:85:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -165,7 +165,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 - --> tests/ui/cast.rs:68:9 + --> tests/ui/cast.rs:88:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -173,7 +173,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 - --> tests/ui/cast.rs:70:9 + --> tests/ui/cast.rs:91:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -181,13 +181,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 - --> tests/ui/cast.rs:70:9 + --> tests/ui/cast.rs:91:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> tests/ui/cast.rs:75:5 + --> tests/ui/cast.rs:98:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -196,31 +196,31 @@ LL | 1u8 as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `u16` to `i16` may wrap around the value - --> tests/ui/cast.rs:78:5 + --> tests/ui/cast.rs:102:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> tests/ui/cast.rs:80:5 + --> tests/ui/cast.rs:105:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> tests/ui/cast.rs:82:5 + --> tests/ui/cast.rs:108:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> tests/ui/cast.rs:84:5 + --> tests/ui/cast.rs:111:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> tests/ui/cast.rs:87:5 + --> tests/ui/cast.rs:115:5 | LL | 1usize as i8; | ^^^^^^^^^^^^ @@ -232,7 +232,7 @@ LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> tests/ui/cast.rs:90:5 + --> tests/ui/cast.rs:119:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -244,7 +244,7 @@ LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:90:5 + --> tests/ui/cast.rs:119:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -253,7 +253,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 - --> tests/ui/cast.rs:95:5 + --> tests/ui/cast.rs:126:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -265,19 +265,19 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:95:5 + --> tests/ui/cast.rs:126:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:99:5 + --> tests/ui/cast.rs:132:5 | LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:104:5 + --> tests/ui/cast.rs:138:5 | LL | 1u16 as isize; | ^^^^^^^^^^^^^ @@ -286,13 +286,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 - --> tests/ui/cast.rs:108:5 + --> tests/ui/cast.rs:143:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:111:5 + --> tests/ui/cast.rs:147:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -304,55 +304,55 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:111:5 + --> tests/ui/cast.rs:147:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:116:5 + --> tests/ui/cast.rs:154:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:119:5 + --> tests/ui/cast.rs:158:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i8` to `u8` may lose the sign of the value - --> tests/ui/cast.rs:130:5 + --> tests/ui/cast.rs:170:5 | LL | (i8::MIN).abs() as u8; | ^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:134:5 + --> tests/ui/cast.rs:175:5 | LL | (-1i64).abs() as u64; | ^^^^^^^^^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:135:5 + --> tests/ui/cast.rs:177:5 | LL | (-1isize).abs() as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:142:5 + --> tests/ui/cast.rs:185:5 | LL | (unsafe { (-1i64).checked_abs().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:157:5 + --> tests/ui/cast.rs:201:5 | LL | (unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> tests/ui/cast.rs:208:5 + --> tests/ui/cast.rs:253:5 | LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:222:5 + --> tests/ui/cast.rs:268:5 | LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -376,7 +376,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> tests/ui/cast.rs:245:21 + --> tests/ui/cast.rs:292:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -388,7 +388,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> tests/ui/cast.rs:247:21 + --> tests/ui/cast.rs:295:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _ = Self::B as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_enum_truncation)]` error: casting `main::E5` to `i8` may truncate the value - --> tests/ui/cast.rs:289:21 + --> tests/ui/cast.rs:338:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -409,13 +409,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> tests/ui/cast.rs:291:21 + --> tests/ui/cast.rs:341:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> tests/ui/cast.rs:308:21 + --> tests/ui/cast.rs:359:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -427,7 +427,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:327:21 + --> tests/ui/cast.rs:379:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -439,7 +439,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> tests/ui/cast.rs:374:21 + --> tests/ui/cast.rs:427:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -451,7 +451,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:385:13 + --> tests/ui/cast.rs:439:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -463,7 +463,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:389:13 + --> tests/ui/cast.rs:444:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ @@ -475,85 +475,85 @@ LL | let c = u8::try_from(q / 1000); | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:401:9 + --> tests/ui/cast.rs:457:9 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:406:32 + --> tests/ui/cast.rs:463:32 | LL | let _a = |x: i32| -> u32 { (x * x * x * x) as u32 }; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:408:5 + --> tests/ui/cast.rs:466:5 | LL | (2_i32).checked_pow(3).unwrap() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:409:5 + --> tests/ui/cast.rs:468:5 | LL | (-2_i32).pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:414:5 + --> tests/ui/cast.rs:474:5 | LL | (-5_i32 % 2) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:416:5 + --> tests/ui/cast.rs:477:5 | LL | (-5_i32 % -2) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:419:5 + --> tests/ui/cast.rs:481:5 | LL | (-2_i32 >> 1) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:423:5 + --> tests/ui/cast.rs:486:5 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:424:5 + --> tests/ui/cast.rs:488:5 | LL | (x * x * x) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:428:5 + --> tests/ui/cast.rs:493:5 | LL | (y * y * y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:430:5 + --> tests/ui/cast.rs:496:5 | LL | (y * y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:431:5 + --> tests/ui/cast.rs:498:5 | LL | (y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:433:5 + --> tests/ui/cast.rs:501:5 | LL | (y / y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `/` - --> tests/ui/cast.rs:433:6 + --> tests/ui/cast.rs:501:6 | LL | (y / y * y * -2) as u16; | ^^^^^ @@ -561,97 +561,97 @@ LL | (y / y * y * -2) as u16; = note: `#[deny(clippy::eq_op)]` on by default error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:436:5 + --> tests/ui/cast.rs:506:5 | LL | (y + y + y + -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:438:5 + --> tests/ui/cast.rs:509:5 | LL | (y + y + y + 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:442:5 + --> tests/ui/cast.rs:514:5 | LL | (z + -2) as u16; | ^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:444:5 + --> tests/ui/cast.rs:517:5 | LL | (z + z + 2) as u16; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:447:9 + --> tests/ui/cast.rs:521:9 | LL | (a * a * b * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:448:9 + --> tests/ui/cast.rs:523:9 | LL | (a * b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:450:9 + --> tests/ui/cast.rs:526:9 | LL | (a * -b * c) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:452:9 + --> tests/ui/cast.rs:529:9 | LL | (a * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:453:9 + --> tests/ui/cast.rs:531:9 | LL | (a * -2) as u32; | ^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:455:9 + --> tests/ui/cast.rs:534:9 | LL | (a * b * c * -2) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:457:9 + --> tests/ui/cast.rs:537:9 | LL | (a / b) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:458:9 + --> tests/ui/cast.rs:539:9 | LL | (a / b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:460:9 + --> tests/ui/cast.rs:542:9 | LL | (a / b + b * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:462:9 + --> tests/ui/cast.rs:545:9 | LL | a.saturating_pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:464:9 + --> tests/ui/cast.rs:548:9 | LL | (a.abs() * b.pow(2) / c.abs()) as u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:472:21 + --> tests/ui/cast.rs:557:21 | LL | let _ = i32::MIN as u32; // cast_sign_loss | ^^^^^^^^^^^^^^^ @@ -662,7 +662,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:473:21 + --> tests/ui/cast.rs:559:21 | LL | let _ = u32::MAX as u8; // cast_possible_truncation | ^^^^^^^^^^^^^^ @@ -678,7 +678,7 @@ LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:474:21 + --> tests/ui/cast.rs:561:21 | LL | let _ = std::f64::consts::PI as f32; // cast_possible_truncation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -690,7 +690,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:483:5 + --> tests/ui/cast.rs:571:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -702,13 +702,13 @@ LL | usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:483:5 + --> tests/ui/cast.rs:571:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:498:5 + --> tests/ui/cast.rs:588:5 | LL | (256 & 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL | u8::try_from(256 & 999999u64); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:500:5 + --> tests/ui/cast.rs:591:5 | LL | (255 % 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_abs_to_unsigned.fixed b/tests/ui/cast_abs_to_unsigned.fixed index 6ca01b7cc367..b55c22f5ca83 100644 --- a/tests/ui/cast_abs_to_unsigned.fixed +++ b/tests/ui/cast_abs_to_unsigned.fixed @@ -4,30 +4,47 @@ fn main() { let x: i32 = -42; let y: u32 = x.unsigned_abs(); + //~^ cast_abs_to_unsigned println!("The absolute value of {} is {}", x, y); let a: i32 = -3; let _: usize = a.unsigned_abs() as usize; + //~^ cast_abs_to_unsigned let _: usize = a.unsigned_abs() as _; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as usize; + //~^ cast_abs_to_unsigned let a: i64 = -3; let _ = a.unsigned_abs() as usize; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u8; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u16; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u32; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs(); + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u128; + //~^ cast_abs_to_unsigned let a: isize = -3; let _ = a.unsigned_abs(); + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u8; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u16; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u32; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u64; + //~^ cast_abs_to_unsigned let _ = a.unsigned_abs() as u128; + //~^ cast_abs_to_unsigned let _ = (x as i64 - y as i64).unsigned_abs() as u32; + //~^ cast_abs_to_unsigned } #[clippy::msrv = "1.50"] @@ -40,4 +57,5 @@ fn msrv_1_50() { fn msrv_1_51() { let x: i32 = 10; assert_eq!(10u32, x.unsigned_abs()); + //~^ cast_abs_to_unsigned } diff --git a/tests/ui/cast_abs_to_unsigned.rs b/tests/ui/cast_abs_to_unsigned.rs index 190a77c10232..466aa6aeb1fb 100644 --- a/tests/ui/cast_abs_to_unsigned.rs +++ b/tests/ui/cast_abs_to_unsigned.rs @@ -4,30 +4,47 @@ fn main() { let x: i32 = -42; let y: u32 = x.abs() as u32; + //~^ cast_abs_to_unsigned println!("The absolute value of {} is {}", x, y); let a: i32 = -3; let _: usize = a.abs() as usize; + //~^ cast_abs_to_unsigned let _: usize = a.abs() as _; + //~^ cast_abs_to_unsigned let _ = a.abs() as usize; + //~^ cast_abs_to_unsigned let a: i64 = -3; let _ = a.abs() as usize; + //~^ cast_abs_to_unsigned let _ = a.abs() as u8; + //~^ cast_abs_to_unsigned let _ = a.abs() as u16; + //~^ cast_abs_to_unsigned let _ = a.abs() as u32; + //~^ cast_abs_to_unsigned let _ = a.abs() as u64; + //~^ cast_abs_to_unsigned let _ = a.abs() as u128; + //~^ cast_abs_to_unsigned let a: isize = -3; let _ = a.abs() as usize; + //~^ cast_abs_to_unsigned let _ = a.abs() as u8; + //~^ cast_abs_to_unsigned let _ = a.abs() as u16; + //~^ cast_abs_to_unsigned let _ = a.abs() as u32; + //~^ cast_abs_to_unsigned let _ = a.abs() as u64; + //~^ cast_abs_to_unsigned let _ = a.abs() as u128; + //~^ cast_abs_to_unsigned let _ = (x as i64 - y as i64).abs() as u32; + //~^ cast_abs_to_unsigned } #[clippy::msrv = "1.50"] @@ -40,4 +57,5 @@ fn msrv_1_50() { fn msrv_1_51() { let x: i32 = 10; assert_eq!(10u32, x.abs() as u32); + //~^ cast_abs_to_unsigned } diff --git a/tests/ui/cast_abs_to_unsigned.stderr b/tests/ui/cast_abs_to_unsigned.stderr index 96e5c1724a51..26220693969c 100644 --- a/tests/ui/cast_abs_to_unsigned.stderr +++ b/tests/ui/cast_abs_to_unsigned.stderr @@ -8,103 +8,103 @@ LL | let y: u32 = x.abs() as u32; = help: to override `-D warnings` add `#[allow(clippy::cast_abs_to_unsigned)]` error: casting the result of `i32::abs()` to usize - --> tests/ui/cast_abs_to_unsigned.rs:10:20 + --> tests/ui/cast_abs_to_unsigned.rs:11:20 | LL | let _: usize = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> tests/ui/cast_abs_to_unsigned.rs:11:20 + --> tests/ui/cast_abs_to_unsigned.rs:13:20 | LL | let _: usize = a.abs() as _; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> tests/ui/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 --> tests/ui/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 usize + --> tests/ui/cast_abs_to_unsigned.rs:19:13 + | +LL | let _ = a.abs() as usize; + | ^^^^^^^ help: replace with: `a.unsigned_abs()` + error: casting the result of `i64::abs()` to u8 - --> tests/ui/cast_abs_to_unsigned.rs:16:13 + --> tests/ui/cast_abs_to_unsigned.rs:21:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u16 - --> tests/ui/cast_abs_to_unsigned.rs:17:13 + --> tests/ui/cast_abs_to_unsigned.rs:23:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> tests/ui/cast_abs_to_unsigned.rs:18:13 + --> tests/ui/cast_abs_to_unsigned.rs:25:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u64 - --> tests/ui/cast_abs_to_unsigned.rs:19:13 + --> tests/ui/cast_abs_to_unsigned.rs:27:13 | LL | let _ = a.abs() as u64; | ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u128 - --> tests/ui/cast_abs_to_unsigned.rs:20:13 + --> tests/ui/cast_abs_to_unsigned.rs:29:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to usize - --> tests/ui/cast_abs_to_unsigned.rs:23:13 + --> tests/ui/cast_abs_to_unsigned.rs:33:13 | LL | let _ = a.abs() as usize; | ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u8 - --> tests/ui/cast_abs_to_unsigned.rs:24:13 + --> tests/ui/cast_abs_to_unsigned.rs:35:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u16 - --> tests/ui/cast_abs_to_unsigned.rs:25:13 + --> tests/ui/cast_abs_to_unsigned.rs:37:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u32 - --> tests/ui/cast_abs_to_unsigned.rs:26:13 + --> tests/ui/cast_abs_to_unsigned.rs:39:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u64 - --> tests/ui/cast_abs_to_unsigned.rs:27:13 + --> tests/ui/cast_abs_to_unsigned.rs:41:13 | LL | let _ = a.abs() as u64; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u128 - --> tests/ui/cast_abs_to_unsigned.rs:28:13 + --> tests/ui/cast_abs_to_unsigned.rs:43:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> tests/ui/cast_abs_to_unsigned.rs:30:13 + --> tests/ui/cast_abs_to_unsigned.rs:46: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 - --> tests/ui/cast_abs_to_unsigned.rs:42:23 + --> tests/ui/cast_abs_to_unsigned.rs:59:23 | LL | assert_eq!(10u32, x.abs() as u32); | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` diff --git a/tests/ui/cast_alignment.rs b/tests/ui/cast_alignment.rs index 72f5d4268cc1..1f14cb8a8452 100644 --- a/tests/ui/cast_alignment.rs +++ b/tests/ui/cast_alignment.rs @@ -17,16 +17,20 @@ 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` + //~^ cast_ptr_alignment + + (&mut 1u8 as *mut u8) as *mut u16; - //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 + //~^ cast_ptr_alignment + // 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`) + //~^ cast_ptr_alignment + (&mut 1u8 as *mut u8).cast::(); - //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 + //~^ cast_ptr_alignment + /* These should be ok */ diff --git a/tests/ui/cast_alignment.stderr b/tests/ui/cast_alignment.stderr index b32624f958fc..a1598eb1b6b4 100644 --- a/tests/ui/cast_alignment.stderr +++ b/tests/ui/cast_alignment.stderr @@ -8,19 +8,19 @@ LL | (&1u8 as *const u8) as *const u16; = help: to override `-D warnings` add `#[allow(clippy::cast_ptr_alignment)]` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> tests/ui/cast_alignment.rs:22:5 + --> tests/ui/cast_alignment.rs:23: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) - --> tests/ui/cast_alignment.rs:26:5 + --> tests/ui/cast_alignment.rs:28:5 | LL | (&1u8 as *const u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> tests/ui/cast_alignment.rs:28:5 + --> tests/ui/cast_alignment.rs:31: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 3226f487b3af..9de5b4095556 100644 --- a/tests/ui/cast_enum_constructor.rs +++ b/tests/ui/cast_enum_constructor.rs @@ -11,10 +11,12 @@ 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` + //~^ cast_enum_constructor + + let _ = Foo::Y as isize; - //~^ ERROR: cast of an enum tuple constructor to an integer + //~^ cast_enum_constructor + 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 67cca6807315..890d88cacdf2 100644 --- a/tests/ui/cast_enum_constructor.stderr +++ b/tests/ui/cast_enum_constructor.stderr @@ -8,7 +8,7 @@ LL | let _ = Foo::Y as usize; = help: to override `-D warnings` add `#[allow(clippy::cast_enum_constructor)]` error: cast of an enum tuple constructor to an integer - --> tests/ui/cast_enum_constructor.rs:16:13 + --> tests/ui/cast_enum_constructor.rs:17:13 | LL | let _ = Foo::Y as isize; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_lossless_bool.fixed b/tests/ui/cast_lossless_bool.fixed index 51a38a60cf6b..21dc280a5864 100644 --- a/tests/ui/cast_lossless_bool.fixed +++ b/tests/ui/cast_lossless_bool.fixed @@ -6,23 +6,37 @@ type U8 = u8; fn main() { // Test clippy::cast_lossless with casts to integer types let _ = u8::from(true); + //~^ cast_lossless let _ = u16::from(true); + //~^ cast_lossless let _ = u32::from(true); + //~^ cast_lossless let _ = u64::from(true); + //~^ cast_lossless let _ = u128::from(true); + //~^ cast_lossless let _ = usize::from(true); + //~^ cast_lossless let _ = i8::from(true); + //~^ cast_lossless let _ = i16::from(true); + //~^ cast_lossless let _ = i32::from(true); + //~^ cast_lossless let _ = i64::from(true); + //~^ cast_lossless let _ = i128::from(true); + //~^ cast_lossless let _ = isize::from(true); + //~^ cast_lossless // Test with an expression wrapped in parens let _ = u16::from(true | false); + //~^ cast_lossless let _ = U8::from(true); + //~^ cast_lossless } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, @@ -51,4 +65,5 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { let _ = u8::from(true); + //~^ cast_lossless } diff --git a/tests/ui/cast_lossless_bool.rs b/tests/ui/cast_lossless_bool.rs index cb307bd68e43..d03badd9a7bc 100644 --- a/tests/ui/cast_lossless_bool.rs +++ b/tests/ui/cast_lossless_bool.rs @@ -6,23 +6,37 @@ type U8 = u8; fn main() { // Test clippy::cast_lossless with casts to integer types let _ = true as u8; + //~^ cast_lossless let _ = true as u16; + //~^ cast_lossless let _ = true as u32; + //~^ cast_lossless let _ = true as u64; + //~^ cast_lossless let _ = true as u128; + //~^ cast_lossless let _ = true as usize; + //~^ cast_lossless let _ = true as i8; + //~^ cast_lossless let _ = true as i16; + //~^ cast_lossless let _ = true as i32; + //~^ cast_lossless let _ = true as i64; + //~^ cast_lossless let _ = true as i128; + //~^ cast_lossless let _ = true as isize; + //~^ cast_lossless // Test with an expression wrapped in parens let _ = (true | false) as u16; + //~^ cast_lossless let _ = true as U8; + //~^ cast_lossless } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, @@ -51,4 +65,5 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { let _ = true as u8; + //~^ cast_lossless } diff --git a/tests/ui/cast_lossless_bool.stderr b/tests/ui/cast_lossless_bool.stderr index 82d6b2e4b8e6..54edab2856cb 100644 --- a/tests/ui/cast_lossless_bool.stderr +++ b/tests/ui/cast_lossless_bool.stderr @@ -13,7 +13,7 @@ LL | let _ = u8::from(true); | ~~~~~~~~~~~~~~ error: casts from `bool` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:9:13 + --> tests/ui/cast_lossless_bool.rs:10:13 | LL | let _ = true as u16; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = u16::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:10:13 + --> tests/ui/cast_lossless_bool.rs:12:13 | LL | let _ = true as u32; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _ = u32::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:11:13 + --> tests/ui/cast_lossless_bool.rs:14:13 | LL | let _ = true as u64; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = u64::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:12:13 + --> tests/ui/cast_lossless_bool.rs:16:13 | LL | let _ = true as u128; | ^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _ = u128::from(true); | ~~~~~~~~~~~~~~~~ error: casts from `bool` to `usize` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:13:13 + --> tests/ui/cast_lossless_bool.rs:18:13 | LL | let _ = true as usize; | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = usize::from(true); | ~~~~~~~~~~~~~~~~~ error: casts from `bool` to `i8` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:15:13 + --> tests/ui/cast_lossless_bool.rs:21:13 | LL | let _ = true as i8; | ^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | let _ = i8::from(true); | ~~~~~~~~~~~~~~ error: casts from `bool` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:16:13 + --> tests/ui/cast_lossless_bool.rs:23:13 | LL | let _ = true as i16; | ^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = i16::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:17:13 + --> tests/ui/cast_lossless_bool.rs:25:13 | LL | let _ = true as i32; | ^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | let _ = i32::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:18:13 + --> tests/ui/cast_lossless_bool.rs:27:13 | LL | let _ = true as i64; | ^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | let _ = i64::from(true); | ~~~~~~~~~~~~~~~ error: casts from `bool` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:19:13 + --> tests/ui/cast_lossless_bool.rs:29:13 | LL | let _ = true as i128; | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = i128::from(true); | ~~~~~~~~~~~~~~~~ error: casts from `bool` to `isize` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:20:13 + --> tests/ui/cast_lossless_bool.rs:31:13 | LL | let _ = true as isize; | ^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let _ = isize::from(true); | ~~~~~~~~~~~~~~~~~ error: casts from `bool` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:23:13 + --> tests/ui/cast_lossless_bool.rs:35:13 | LL | let _ = (true | false) as u16; | ^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | let _ = u16::from(true | false); | ~~~~~~~~~~~~~~~~~~~~~~~ error: casts from `bool` to `u8` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:25:13 + --> tests/ui/cast_lossless_bool.rs:38:13 | LL | let _ = true as U8; | ^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | let _ = U8::from(true); | ~~~~~~~~~~~~~~ error: casts from `bool` to `u8` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_bool.rs:53:13 + --> tests/ui/cast_lossless_bool.rs:67:13 | LL | let _ = true as u8; | ^^^^^^^^^^ diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed index 163432631e13..6ddd5f10a2ca 100644 --- a/tests/ui/cast_lossless_float.fixed +++ b/tests/ui/cast_lossless_float.fixed @@ -10,25 +10,38 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; let _ = f32::from(x0); + //~^ cast_lossless let _ = f64::from(x0); + //~^ cast_lossless let _ = F32::from(x0); + //~^ cast_lossless let _ = F64::from(x0); + //~^ cast_lossless let x1 = 1u8; let _ = f32::from(x1); + //~^ cast_lossless let _ = f64::from(x1); + //~^ cast_lossless let x2 = 1i16; let _ = f32::from(x2); + //~^ cast_lossless let _ = f64::from(x2); + //~^ cast_lossless let x3 = 1u16; let _ = f32::from(x3); + //~^ cast_lossless let _ = f64::from(x3); + //~^ cast_lossless let x4 = 1i32; let _ = f64::from(x4); + //~^ cast_lossless let x5 = 1u32; let _ = f64::from(x5); + //~^ cast_lossless // Test with casts from floating-point types let _ = f64::from(1.0f32); + //~^ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index afb2a3d890ee..fe5a90544538 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -10,25 +10,38 @@ fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; let _ = x0 as f32; + //~^ cast_lossless let _ = x0 as f64; + //~^ cast_lossless let _ = x0 as F32; + //~^ cast_lossless let _ = x0 as F64; + //~^ cast_lossless let x1 = 1u8; let _ = x1 as f32; + //~^ cast_lossless let _ = x1 as f64; + //~^ cast_lossless let x2 = 1i16; let _ = x2 as f32; + //~^ cast_lossless let _ = x2 as f64; + //~^ cast_lossless let x3 = 1u16; let _ = x3 as f32; + //~^ cast_lossless let _ = x3 as f64; + //~^ cast_lossless let x4 = 1i32; let _ = x4 as f64; + //~^ cast_lossless let x5 = 1u32; let _ = x5 as f64; + //~^ cast_lossless // Test with casts from floating-point types let _ = 1.0f32 as f64; + //~^ cast_lossless } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index b36f8bcecf58..c983d4ccc6be 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -13,7 +13,7 @@ LL | let _ = f32::from(x0); | ~~~~~~~~~~~~~ error: casts from `i8` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:13:13 + --> tests/ui/cast_lossless_float.rs:14:13 | LL | let _ = x0 as f64; | ^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = f64::from(x0); | ~~~~~~~~~~~~~ error: casts from `i8` to `f32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:14:13 + --> tests/ui/cast_lossless_float.rs:16:13 | LL | let _ = x0 as F32; | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _ = F32::from(x0); | ~~~~~~~~~~~~~ error: casts from `i8` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:15:13 + --> tests/ui/cast_lossless_float.rs:18:13 | LL | let _ = x0 as F64; | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = F64::from(x0); | ~~~~~~~~~~~~~ error: casts from `u8` to `f32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:17:13 + --> tests/ui/cast_lossless_float.rs:21:13 | LL | let _ = x1 as f32; | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _ = f32::from(x1); | ~~~~~~~~~~~~~ error: casts from `u8` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:18:13 + --> tests/ui/cast_lossless_float.rs:23:13 | LL | let _ = x1 as f64; | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = f64::from(x1); | ~~~~~~~~~~~~~ error: casts from `i16` to `f32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:20:13 + --> tests/ui/cast_lossless_float.rs:26:13 | LL | let _ = x2 as f32; | ^^^^^^^^^ @@ -85,7 +85,7 @@ LL | let _ = f32::from(x2); | ~~~~~~~~~~~~~ error: casts from `i16` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:21:13 + --> tests/ui/cast_lossless_float.rs:28:13 | LL | let _ = x2 as f64; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = f64::from(x2); | ~~~~~~~~~~~~~ error: casts from `u16` to `f32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:23:13 + --> tests/ui/cast_lossless_float.rs:31:13 | LL | let _ = x3 as f32; | ^^^^^^^^^ @@ -109,7 +109,7 @@ LL | let _ = f32::from(x3); | ~~~~~~~~~~~~~ error: casts from `u16` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:24:13 + --> tests/ui/cast_lossless_float.rs:33:13 | LL | let _ = x3 as f64; | ^^^^^^^^^ @@ -121,7 +121,7 @@ LL | let _ = f64::from(x3); | ~~~~~~~~~~~~~ error: casts from `i32` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:26:13 + --> tests/ui/cast_lossless_float.rs:36:13 | LL | let _ = x4 as f64; | ^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = f64::from(x4); | ~~~~~~~~~~~~~ error: casts from `u32` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:28:13 + --> tests/ui/cast_lossless_float.rs:39:13 | LL | let _ = x5 as f64; | ^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let _ = f64::from(x5); | ~~~~~~~~~~~~~ error: casts from `f32` to `f64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_float.rs:31:13 + --> tests/ui/cast_lossless_float.rs:43:13 | LL | let _ = 1.0f32 as f64; | ^^^^^^^^^^^^^ diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed index cdb065678368..cd689801702a 100644 --- a/tests/ui/cast_lossless_integer.fixed +++ b/tests/ui/cast_lossless_integer.fixed @@ -7,87 +7,123 @@ fn main() { // Test clippy::cast_lossless with casts to integer types u16::from(0u8); //~^ cast_lossless + i16::from(0u8); //~^ cast_lossless + u32::from(0u8); //~^ cast_lossless + i32::from(0u8); //~^ cast_lossless + u64::from(0u8); //~^ cast_lossless + i64::from(0u8); //~^ cast_lossless + u128::from(0u8); //~^ cast_lossless + i128::from(0u8); //~^ cast_lossless + u32::from(0u16); //~^ cast_lossless + i32::from(0u16); //~^ cast_lossless + u64::from(0u16); //~^ cast_lossless + i64::from(0u16); //~^ cast_lossless + u128::from(0u16); //~^ cast_lossless + i128::from(0u16); //~^ cast_lossless + u64::from(0u32); //~^ cast_lossless + i64::from(0u32); //~^ cast_lossless + u128::from(0u32); //~^ cast_lossless + i128::from(0u32); //~^ cast_lossless + u128::from(0u64); //~^ cast_lossless + i128::from(0u64); //~^ cast_lossless + i16::from(0i8); //~^ cast_lossless + i32::from(0i8); //~^ cast_lossless + i64::from(0i8); //~^ cast_lossless + i128::from(0i8); //~^ cast_lossless + i32::from(0i16); //~^ cast_lossless + i64::from(0i16); //~^ cast_lossless + i128::from(0i16); //~^ cast_lossless + i64::from(0i32); //~^ cast_lossless + i128::from(0i32); //~^ cast_lossless + i128::from(0i64); //~^ cast_lossless + // Test with an expression wrapped in parens let _ = u16::from(1u8 + 1u8); //~^ cast_lossless + let _ = I64Alias::from(1i8); //~^ cast_lossless + let _: u16 = 0u8.into(); //~^ cast_lossless + let _: i16 = (-1i8).into(); //~^ cast_lossless + let _: u16 = (1u8 + 2).into(); //~^ cast_lossless + let _: u32 = (1i8 as u16).into(); //~^ cast_lossless + } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -123,8 +159,10 @@ fn issue11458() { let x = 10_u128; let _ = i32::from(sign_cast!(x, u8, i8)); //~^ cast_lossless + let _ = i32::from(sign_cast!(x, u8, i8) + 1); //~^ cast_lossless + } fn issue12695() { @@ -132,6 +170,7 @@ fn issue12695() { () => { u32::from(1u8) //~^ cast_lossless + }; } @@ -146,6 +185,7 @@ fn ty_from_macro() { } let _ = ::from(0u8); + //~^ cast_lossless } const IN_CONST: u64 = 0u8 as u64; diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index 1f510b1a3036..03c1a77c34ad 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -7,87 +7,123 @@ fn main() { // Test clippy::cast_lossless with casts to integer types 0u8 as u16; //~^ cast_lossless + 0u8 as i16; //~^ cast_lossless + 0u8 as u32; //~^ cast_lossless + 0u8 as i32; //~^ cast_lossless + 0u8 as u64; //~^ cast_lossless + 0u8 as i64; //~^ cast_lossless + 0u8 as u128; //~^ cast_lossless + 0u8 as i128; //~^ cast_lossless + 0u16 as u32; //~^ cast_lossless + 0u16 as i32; //~^ cast_lossless + 0u16 as u64; //~^ cast_lossless + 0u16 as i64; //~^ cast_lossless + 0u16 as u128; //~^ cast_lossless + 0u16 as i128; //~^ cast_lossless + 0u32 as u64; //~^ cast_lossless + 0u32 as i64; //~^ cast_lossless + 0u32 as u128; //~^ cast_lossless + 0u32 as i128; //~^ cast_lossless + 0u64 as u128; //~^ cast_lossless + 0u64 as i128; //~^ cast_lossless + 0i8 as i16; //~^ cast_lossless + 0i8 as i32; //~^ cast_lossless + 0i8 as i64; //~^ cast_lossless + 0i8 as i128; //~^ cast_lossless + 0i16 as i32; //~^ cast_lossless + 0i16 as i64; //~^ cast_lossless + 0i16 as i128; //~^ cast_lossless + 0i32 as i64; //~^ cast_lossless + 0i32 as i128; //~^ cast_lossless + 0i64 as i128; //~^ cast_lossless + // Test with an expression wrapped in parens let _ = (1u8 + 1u8) as u16; //~^ cast_lossless + let _ = 1i8 as I64Alias; //~^ cast_lossless + let _: u16 = 0u8 as _; //~^ cast_lossless + let _: i16 = -1i8 as _; //~^ cast_lossless + let _: u16 = (1u8 + 2) as _; //~^ cast_lossless + let _: u32 = 1i8 as u16 as _; //~^ cast_lossless + } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -123,8 +159,10 @@ fn issue11458() { let x = 10_u128; let _ = sign_cast!(x, u8, i8) as i32; //~^ cast_lossless + let _ = (sign_cast!(x, u8, i8) + 1) as i32; //~^ cast_lossless + } fn issue12695() { @@ -132,6 +170,7 @@ fn issue12695() { () => { 1u8 as u32 //~^ cast_lossless + }; } @@ -146,6 +185,7 @@ fn ty_from_macro() { } let _ = 0u8 as ty!(); + //~^ cast_lossless } const IN_CONST: u64 = 0u8 as u64; diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index c93ecb8fb561..3bec773ff861 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -13,7 +13,7 @@ LL | u16::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:10:5 + --> tests/ui/cast_lossless_integer.rs:11:5 | LL | 0u8 as i16; | ^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | i16::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:12:5 + --> tests/ui/cast_lossless_integer.rs:14:5 | LL | 0u8 as u32; | ^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | u32::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:14:5 + --> tests/ui/cast_lossless_integer.rs:17:5 | LL | 0u8 as i32; | ^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | i32::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:16:5 + --> tests/ui/cast_lossless_integer.rs:20:5 | LL | 0u8 as u64; | ^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | u64::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:18:5 + --> tests/ui/cast_lossless_integer.rs:23:5 | LL | 0u8 as i64; | ^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | i64::from(0u8); | ~~~~~~~~~~~~~~ error: casts from `u8` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:20:5 + --> tests/ui/cast_lossless_integer.rs:26:5 | LL | 0u8 as u128; | ^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | u128::from(0u8); | ~~~~~~~~~~~~~~~ error: casts from `u8` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:22:5 + --> tests/ui/cast_lossless_integer.rs:29:5 | LL | 0u8 as i128; | ^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | i128::from(0u8); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:25:5 + --> tests/ui/cast_lossless_integer.rs:33:5 | LL | 0u16 as u32; | ^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | u32::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:27:5 + --> tests/ui/cast_lossless_integer.rs:36:5 | LL | 0u16 as i32; | ^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | i32::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:29:5 + --> tests/ui/cast_lossless_integer.rs:39:5 | LL | 0u16 as u64; | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | u64::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:31:5 + --> tests/ui/cast_lossless_integer.rs:42:5 | LL | 0u16 as i64; | ^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | i64::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:33:5 + --> tests/ui/cast_lossless_integer.rs:45:5 | LL | 0u16 as u128; | ^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | u128::from(0u16); | ~~~~~~~~~~~~~~~~ error: casts from `u16` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:35:5 + --> tests/ui/cast_lossless_integer.rs:48:5 | LL | 0u16 as i128; | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | i128::from(0u16); | ~~~~~~~~~~~~~~~~ error: casts from `u32` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:38:5 + --> tests/ui/cast_lossless_integer.rs:52:5 | LL | 0u32 as u64; | ^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL | u64::from(0u32); | ~~~~~~~~~~~~~~~ error: casts from `u32` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:40:5 + --> tests/ui/cast_lossless_integer.rs:55:5 | LL | 0u32 as i64; | ^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | i64::from(0u32); | ~~~~~~~~~~~~~~~ error: casts from `u32` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:42:5 + --> tests/ui/cast_lossless_integer.rs:58:5 | LL | 0u32 as u128; | ^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL | u128::from(0u32); | ~~~~~~~~~~~~~~~~ error: casts from `u32` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:44:5 + --> tests/ui/cast_lossless_integer.rs:61:5 | LL | 0u32 as i128; | ^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | i128::from(0u32); | ~~~~~~~~~~~~~~~~ error: casts from `u64` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:47:5 + --> tests/ui/cast_lossless_integer.rs:65:5 | LL | 0u64 as u128; | ^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL | u128::from(0u64); | ~~~~~~~~~~~~~~~~ error: casts from `u64` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:49:5 + --> tests/ui/cast_lossless_integer.rs:68:5 | LL | 0u64 as i128; | ^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL | i128::from(0u64); | ~~~~~~~~~~~~~~~~ error: casts from `i8` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:52:5 + --> tests/ui/cast_lossless_integer.rs:72:5 | LL | 0i8 as i16; | ^^^^^^^^^^ @@ -253,7 +253,7 @@ LL | i16::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:54:5 + --> tests/ui/cast_lossless_integer.rs:75:5 | LL | 0i8 as i32; | ^^^^^^^^^^ @@ -265,7 +265,7 @@ LL | i32::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:56:5 + --> tests/ui/cast_lossless_integer.rs:78:5 | LL | 0i8 as i64; | ^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | i64::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:58:5 + --> tests/ui/cast_lossless_integer.rs:81:5 | LL | 0i8 as i128; | ^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL | i128::from(0i8); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:61:5 + --> tests/ui/cast_lossless_integer.rs:85:5 | LL | 0i16 as i32; | ^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL | i32::from(0i16); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:63:5 + --> tests/ui/cast_lossless_integer.rs:88:5 | LL | 0i16 as i64; | ^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | i64::from(0i16); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:65:5 + --> tests/ui/cast_lossless_integer.rs:91:5 | LL | 0i16 as i128; | ^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL | i128::from(0i16); | ~~~~~~~~~~~~~~~~ error: casts from `i32` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:68:5 + --> tests/ui/cast_lossless_integer.rs:95:5 | LL | 0i32 as i64; | ^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | i64::from(0i32); | ~~~~~~~~~~~~~~~ error: casts from `i32` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:70:5 + --> tests/ui/cast_lossless_integer.rs:98:5 | LL | 0i32 as i128; | ^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL | i128::from(0i32); | ~~~~~~~~~~~~~~~~ error: casts from `i64` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:73:5 + --> tests/ui/cast_lossless_integer.rs:102:5 | LL | 0i64 as i128; | ^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL | i128::from(0i64); | ~~~~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:77:13 + --> tests/ui/cast_lossless_integer.rs:107:13 | LL | let _ = (1u8 + 1u8) as u16; | ^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL | let _ = u16::from(1u8 + 1u8); | ~~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:80:13 + --> tests/ui/cast_lossless_integer.rs:111:13 | LL | let _ = 1i8 as I64Alias; | ^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL | let _ = I64Alias::from(1i8); | ~~~~~~~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:83:18 + --> tests/ui/cast_lossless_integer.rs:115:18 | LL | let _: u16 = 0u8 as _; | ^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _: u16 = 0u8.into(); | ~~~~~~~~~~ error: casts from `i8` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:85:18 + --> tests/ui/cast_lossless_integer.rs:118:18 | LL | let _: i16 = -1i8 as _; | ^^^^^^^^^ @@ -409,7 +409,7 @@ LL | let _: i16 = (-1i8).into(); | ~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:87:18 + --> tests/ui/cast_lossless_integer.rs:121:18 | LL | let _: u16 = (1u8 + 2) as _; | ^^^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL | let _: u16 = (1u8 + 2).into(); | ~~~~~~~~~~~~~~~~ error: casts from `u16` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:89:18 + --> tests/ui/cast_lossless_integer.rs:124:18 | LL | let _: u32 = 1i8 as u16 as _; | ^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ LL | let _: u32 = (1i8 as u16).into(); | ~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:124:13 + --> tests/ui/cast_lossless_integer.rs:160:13 | LL | let _ = sign_cast!(x, u8, i8) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -445,7 +445,7 @@ LL | let _ = i32::from(sign_cast!(x, u8, i8)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:126:13 + --> tests/ui/cast_lossless_integer.rs:163:13 | LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -457,7 +457,7 @@ LL | let _ = i32::from(sign_cast!(x, u8, i8) + 1); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casts from `u8` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:133:13 + --> tests/ui/cast_lossless_integer.rs:171:13 | LL | 1u8 as u32 | ^^^^^^^^^^ @@ -473,7 +473,7 @@ LL | u32::from(1u8) | error: casts from `u8` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:148:13 + --> tests/ui/cast_lossless_integer.rs:187:13 | LL | let _ = 0u8 as ty!(); | ^^^^^^^^^^^^ diff --git a/tests/ui/cast_nan_to_int.rs b/tests/ui/cast_nan_to_int.rs index aee38da9a159..227dae3b1c4b 100644 --- a/tests/ui/cast_nan_to_int.rs +++ b/tests/ui/cast_nan_to_int.rs @@ -5,24 +5,30 @@ fn main() { let _ = (0.0_f32 / -0.0) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + let _ = (f64::INFINITY * -0.0) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + let _ = (0.0 * f32::INFINITY) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + let _ = (f32::INFINITY - f32::INFINITY) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; - //~^ ERROR: casting a known NaN to usize - //~| NOTE: this always evaluates to 0 + //~^ cast_nan_to_int + + // 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 3aeb2d545251..0f9b3565485f 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -9,7 +9,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; = help: to override `-D warnings` add `#[allow(clippy::cast_nan_to_int)]` error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:10:13 + --> tests/ui/cast_nan_to_int.rs:11:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:13:13 + --> tests/ui/cast_nan_to_int.rs:15:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:17:13 + --> tests/ui/cast_nan_to_int.rs:20:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:20:13 + --> tests/ui/cast_nan_to_int.rs:24:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:23:13 + --> tests/ui/cast_nan_to_int.rs:28:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_raw_slice_pointer_cast.fixed b/tests/ui/cast_raw_slice_pointer_cast.fixed index e78bd66c3cb5..bddcb0ebf64e 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.fixed +++ b/tests/ui/cast_raw_slice_pointer_cast.fixed @@ -6,18 +6,25 @@ fn main() { let ptr: *const u8 = vec.as_ptr(); let mptr = vec.as_mut_ptr(); let _: *const [u8] = unsafe { core::ptr::slice_from_raw_parts(ptr, 1) }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { core::ptr::slice_from_raw_parts_mut(mptr, 1) }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts { use core::slice; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts } { use std::slice; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = core::ptr::slice_from_raw_parts(ptr, 1); + //~^ cast_slice_from_raw_parts } } diff --git a/tests/ui/cast_raw_slice_pointer_cast.rs b/tests/ui/cast_raw_slice_pointer_cast.rs index c3d8c7bee989..0a1eb276d5e9 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.rs +++ b/tests/ui/cast_raw_slice_pointer_cast.rs @@ -6,18 +6,25 @@ fn main() { let ptr: *const u8 = vec.as_ptr(); let mptr = vec.as_mut_ptr(); let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *const [u8] }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] }; + //~^ cast_slice_from_raw_parts let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts { use core::slice; let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts } { use std::slice; let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts use slice as one; let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; + //~^ cast_slice_from_raw_parts } } diff --git a/tests/ui/cast_raw_slice_pointer_cast.stderr b/tests/ui/cast_raw_slice_pointer_cast.stderr index 2aedd320a428..60794a988db7 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.stderr +++ b/tests/ui/cast_raw_slice_pointer_cast.stderr @@ -8,37 +8,37 @@ LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *co = help: to override `-D warnings` add `#[allow(clippy::cast_slice_from_raw_parts)]` error: casting the result of `from_raw_parts_mut` to *mut [u8] - --> tests/ui/cast_raw_slice_pointer_cast.rs:9:35 + --> tests/ui/cast_raw_slice_pointer_cast.rs:10: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] - --> tests/ui/cast_raw_slice_pointer_cast.rs:10:26 + --> tests/ui/cast_raw_slice_pointer_cast.rs:12: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] - --> tests/ui/cast_raw_slice_pointer_cast.rs:13:30 + --> tests/ui/cast_raw_slice_pointer_cast.rs:16: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] - --> tests/ui/cast_raw_slice_pointer_cast.rs:15:30 + --> tests/ui/cast_raw_slice_pointer_cast.rs:19: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] - --> tests/ui/cast_raw_slice_pointer_cast.rs:19:30 + --> tests/ui/cast_raw_slice_pointer_cast.rs:24: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] - --> tests/ui/cast_raw_slice_pointer_cast.rs:21:30 + --> tests/ui/cast_raw_slice_pointer_cast.rs:27: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.64bit.stderr b/tests/ui/cast_size.64bit.stderr index bc37107d80e3..d67040bcc1cb 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -13,7 +13,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ 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) - --> tests/ui/cast_size.rs:21:5 + --> tests/ui/cast_size.rs:22:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -22,25 +22,25 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` 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) - --> tests/ui/cast_size.rs:22:5 + --> tests/ui/cast_size.rs:24:5 | LL | x1 as f32; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:23:5 + --> tests/ui/cast_size.rs:26:5 | LL | x0 as f64; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:24:5 + --> tests/ui/cast_size.rs:28:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:33:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:29:5 + --> tests/ui/cast_size.rs:35:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:30:5 + --> tests/ui/cast_size.rs:37:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:31:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:31:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:32:5 + --> tests/ui/cast_size.rs:42:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:33:5 + --> tests/ui/cast_size.rs:44:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:34:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:34:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:35:5 + --> tests/ui/cast_size.rs:49:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,19 +151,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:36:5 + --> tests/ui/cast_size.rs:51: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) - --> tests/ui/cast_size.rs:43:5 + --> tests/ui/cast_size.rs:59: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) - --> tests/ui/cast_size.rs:44:5 + --> tests/ui/cast_size.rs:61:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index d0ed8e57d7ae..9fc07b2ae4fd 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -13,27 +13,43 @@ fn main() { // Casting from *size 1isize as i8; + //~^ cast_possible_truncation let x0 = 1isize; let x1 = 1usize; // FIXME(f16_f128): enable f16 and f128 conversions once const eval supports them // x0 as f16; // x1 as f16; x0 as f32; + //~^ cast_precision_loss x1 as f32; + //~^ cast_precision_loss x0 as f64; + //~^ cast_precision_loss x1 as f64; + //~^ cast_precision_loss // x0 as f128; // x1 as f128; 1isize as i32; + //~^ cast_possible_truncation 1isize as u32; + //~^ cast_possible_truncation 1usize as u32; + //~^ cast_possible_truncation 1usize as i32; + //~^ cast_possible_truncation + //~| cast_possible_wrap 1i64 as isize; + //~^ cast_possible_truncation 1i64 as usize; + //~^ cast_possible_truncation 1u64 as isize; + //~^ cast_possible_truncation + //~| cast_possible_wrap 1u64 as usize; + //~^ cast_possible_truncation 1u32 as isize; + //~^ cast_possible_wrap 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; @@ -41,6 +57,8 @@ fn main() { // Big integer literal to float // 999_999 as f16; 999_999_999 as f32; + //~^ cast_precision_loss 9_999_999_999_999_999usize as f64; + //~^ cast_precision_loss // 999_999_999_999_999_999_999_999_999_999u128 as f128; } diff --git a/tests/ui/cast_slice_different_sizes.rs b/tests/ui/cast_slice_different_sizes.rs index d8101030a8a2..2db14d4f2515 100644 --- a/tests/ui/cast_slice_different_sizes.rs +++ b/tests/ui/cast_slice_different_sizes.rs @@ -8,14 +8,17 @@ 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 + //~^ cast_slice_different_sizes + + let c = b as *const [u32]; - //~^ ERROR: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (eleme + //~^ cast_slice_different_sizes + // 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_slice_different_sizes + // 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 @@ -23,9 +26,11 @@ 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 + //~^ cast_slice_different_sizes + let loss_block_2 = { - //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme + //~^ cast_slice_different_sizes + let _ = (); r_x as *const [i32] } as *const [u8]; @@ -43,7 +48,8 @@ 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 + //~^ cast_slice_different_sizes + let long_chain_restore = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8] as *const [u32]; } @@ -59,40 +65,48 @@ 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 +//~^ cast_slice_different_sizes + 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 +//~^ cast_slice_different_sizes + x as *mut _ } fn bar2(x: *mut [u16]) -> *mut [u8] { - //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s +//~^ cast_slice_different_sizes + x as _ } // constify fn bar3(x: *mut [u16]) -> *const [u8] { - //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s +//~^ cast_slice_different_sizes + x as _ } // unconstify fn bar4(x: *const [u16]) -> *mut [u8] { - //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s +//~^ cast_slice_different_sizes + 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 +//~^ cast_slice_different_sizes + ({ x }) as _ } fn more_blocks(x: *mut [u16]) -> *mut [u8] { - //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s +//~^ cast_slice_different_sizes + { ({ x }) as _ } - //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (eleme + //~^ cast_slice_different_sizes + } diff --git a/tests/ui/cast_slice_different_sizes.stderr b/tests/ui/cast_slice_different_sizes.stderr index 625de4a8359b..e028e13db616 100644 --- a/tests/ui/cast_slice_different_sizes.stderr +++ b/tests/ui/cast_slice_different_sizes.stderr @@ -7,29 +7,30 @@ 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 - --> tests/ui/cast_slice_different_sizes.rs:13:13 + --> tests/ui/cast_slice_different_sizes.rs:14: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 - --> tests/ui/cast_slice_different_sizes.rs:17:16 + --> tests/ui/cast_slice_different_sizes.rs:19: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 - --> tests/ui/cast_slice_different_sizes.rs:25:24 + --> tests/ui/cast_slice_different_sizes.rs:28: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 - --> tests/ui/cast_slice_different_sizes.rs:27:24 + --> tests/ui/cast_slice_different_sizes.rs:31:24 | LL | let loss_block_2 = { | ________________________^ LL | | +LL | | LL | | let _ = (); LL | | r_x as *const [i32] LL | | } as *const [u8]; @@ -39,90 +40,98 @@ help: replace with `ptr::slice_from_raw_parts` | LL ~ let loss_block_2 = core::ptr::slice_from_raw_parts({ LL + +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 - --> tests/ui/cast_slice_different_sizes.rs:45:27 + --> tests/ui/cast_slice_different_sizes.rs:50: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 - --> tests/ui/cast_slice_different_sizes.rs:61:36 + --> tests/ui/cast_slice_different_sizes.rs:67:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:66:36 + --> tests/ui/cast_slice_different_sizes.rs:73:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:71:37 + --> tests/ui/cast_slice_different_sizes.rs:79:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:77:39 + --> tests/ui/cast_slice_different_sizes.rs:86:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:83:39 + --> tests/ui/cast_slice_different_sizes.rs:93:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:89:39 + --> tests/ui/cast_slice_different_sizes.rs:100:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ LL | | +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 - --> tests/ui/cast_slice_different_sizes.rs:94:44 + --> tests/ui/cast_slice_different_sizes.rs:106:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ LL | | -LL | | { ({ x }) as _ } 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 - --> tests/ui/cast_slice_different_sizes.rs:96:5 + --> tests/ui/cast_slice_different_sizes.rs:109: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_cargo_clippy.fixed b/tests/ui/cfg_attr_cargo_clippy.fixed index 89815ffe9cbc..f55920db5503 100644 --- a/tests/ui/cfg_attr_cargo_clippy.fixed +++ b/tests/ui/cfg_attr_cargo_clippy.fixed @@ -1,13 +1,20 @@ #![warn(clippy::deprecated_clippy_cfg_attr)] #![allow(clippy::non_minimal_cfg)] -#![cfg_attr(clippy, doc = "a")] //~ ERROR: `feature = "cargo-clippy"` was +#![cfg_attr(clippy, doc = "a")] +//~^ deprecated_clippy_cfg_attr -#[cfg_attr(clippy, derive(Debug))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg_attr(not(clippy), derive(Debug))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(clippy)] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(not(clippy))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(any(clippy))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(all(clippy))] //~ ERROR: `feature = "cargo-clippy"` was +#[cfg_attr(clippy, derive(Debug))] +//~^ deprecated_clippy_cfg_attr +#[cfg_attr(not(clippy), derive(Debug))] +//~^ deprecated_clippy_cfg_attr +#[cfg(clippy)] +//~^ deprecated_clippy_cfg_attr +#[cfg(not(clippy))] +//~^ deprecated_clippy_cfg_attr +#[cfg(any(clippy))] +//~^ deprecated_clippy_cfg_attr +#[cfg(all(clippy))] +//~^ deprecated_clippy_cfg_attr pub struct Bar; fn main() {} diff --git a/tests/ui/cfg_attr_cargo_clippy.rs b/tests/ui/cfg_attr_cargo_clippy.rs index 745f8957641e..faf36d98f2b3 100644 --- a/tests/ui/cfg_attr_cargo_clippy.rs +++ b/tests/ui/cfg_attr_cargo_clippy.rs @@ -1,13 +1,20 @@ #![warn(clippy::deprecated_clippy_cfg_attr)] #![allow(clippy::non_minimal_cfg)] -#![cfg_attr(feature = "cargo-clippy", doc = "a")] //~ ERROR: `feature = "cargo-clippy"` was +#![cfg_attr(feature = "cargo-clippy", doc = "a")] +//~^ deprecated_clippy_cfg_attr -#[cfg_attr(feature = "cargo-clippy", derive(Debug))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg_attr(not(feature = "cargo-clippy"), derive(Debug))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(feature = "cargo-clippy")] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(not(feature = "cargo-clippy"))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(any(feature = "cargo-clippy"))] //~ ERROR: `feature = "cargo-clippy"` was -#[cfg(all(feature = "cargo-clippy"))] //~ ERROR: `feature = "cargo-clippy"` was +#[cfg_attr(feature = "cargo-clippy", derive(Debug))] +//~^ deprecated_clippy_cfg_attr +#[cfg_attr(not(feature = "cargo-clippy"), derive(Debug))] +//~^ deprecated_clippy_cfg_attr +#[cfg(feature = "cargo-clippy")] +//~^ deprecated_clippy_cfg_attr +#[cfg(not(feature = "cargo-clippy"))] +//~^ deprecated_clippy_cfg_attr +#[cfg(any(feature = "cargo-clippy"))] +//~^ deprecated_clippy_cfg_attr +#[cfg(all(feature = "cargo-clippy"))] +//~^ deprecated_clippy_cfg_attr pub struct Bar; fn main() {} diff --git a/tests/ui/cfg_attr_cargo_clippy.stderr b/tests/ui/cfg_attr_cargo_clippy.stderr index 0a358f1a6847..4f5c39b78415 100644 --- a/tests/ui/cfg_attr_cargo_clippy.stderr +++ b/tests/ui/cfg_attr_cargo_clippy.stderr @@ -8,37 +8,37 @@ LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")] = help: to override `-D warnings` add `#[allow(clippy::deprecated_clippy_cfg_attr)]` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:5:12 + --> tests/ui/cfg_attr_cargo_clippy.rs:6:12 | LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:6:16 + --> tests/ui/cfg_attr_cargo_clippy.rs:8:16 | LL | #[cfg_attr(not(feature = "cargo-clippy"), derive(Debug))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:7:7 + --> tests/ui/cfg_attr_cargo_clippy.rs:10:7 | LL | #[cfg(feature = "cargo-clippy")] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:8:11 + --> tests/ui/cfg_attr_cargo_clippy.rs:12:11 | LL | #[cfg(not(feature = "cargo-clippy"))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:9:11 + --> tests/ui/cfg_attr_cargo_clippy.rs:14:11 | LL | #[cfg(any(feature = "cargo-clippy"))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` error: `feature = "cargo-clippy"` was replaced by `clippy` - --> tests/ui/cfg_attr_cargo_clippy.rs:10:11 + --> tests/ui/cfg_attr_cargo_clippy.rs:16:11 | LL | #[cfg(all(feature = "cargo-clippy"))] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy` diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed index 05d5b3d10eaf..401476a9c1fe 100644 --- a/tests/ui/cfg_attr_rustfmt.fixed +++ b/tests/ui/cfg_attr_rustfmt.fixed @@ -16,10 +16,12 @@ fn foo( fn skip_on_statements() { #[rustfmt::skip] + //~^ deprecated_cfg_attr 5+3; } #[rustfmt::skip] +//~^ deprecated_cfg_attr fn main() { foo::f(); } @@ -39,5 +41,6 @@ fn msrv_1_29() { #[clippy::msrv = "1.30"] fn msrv_1_30() { #[rustfmt::skip] + //~^ deprecated_cfg_attr 1+30; } diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs index bc29e20210e8..3cf368129fd8 100644 --- a/tests/ui/cfg_attr_rustfmt.rs +++ b/tests/ui/cfg_attr_rustfmt.rs @@ -16,10 +16,12 @@ fn foo( fn skip_on_statements() { #[cfg_attr(rustfmt, rustfmt::skip)] + //~^ deprecated_cfg_attr 5+3; } #[cfg_attr(rustfmt, rustfmt_skip)] +//~^ deprecated_cfg_attr fn main() { foo::f(); } @@ -39,5 +41,6 @@ fn msrv_1_29() { #[clippy::msrv = "1.30"] fn msrv_1_30() { #[cfg_attr(rustfmt, rustfmt::skip)] + //~^ deprecated_cfg_attr 1+30; } diff --git a/tests/ui/cfg_attr_rustfmt.stderr b/tests/ui/cfg_attr_rustfmt.stderr index 24b6ed1b0458..d7825f854be5 100644 --- a/tests/ui/cfg_attr_rustfmt.stderr +++ b/tests/ui/cfg_attr_rustfmt.stderr @@ -8,13 +8,13 @@ LL | #[cfg_attr(rustfmt, rustfmt::skip)] = help: to override `-D warnings` add `#[allow(clippy::deprecated_cfg_attr)]` error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes - --> tests/ui/cfg_attr_rustfmt.rs:22:1 + --> tests/ui/cfg_attr_rustfmt.rs:23:1 | LL | #[cfg_attr(rustfmt, rustfmt_skip)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]` error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes - --> tests/ui/cfg_attr_rustfmt.rs:41:5 + --> tests/ui/cfg_attr_rustfmt.rs:43:5 | LL | #[cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]` diff --git a/tests/ui/cfg_not_test.rs b/tests/ui/cfg_not_test.rs index da3e29d28966..d93e16f3b185 100644 --- a/tests/ui/cfg_not_test.rs +++ b/tests/ui/cfg_not_test.rs @@ -6,10 +6,12 @@ fn important_check() {} fn main() { // Statement #[cfg(not(test))] + //~^ cfg_not_test let answer = 42; // Expression #[cfg(not(test))] + //~^ cfg_not_test important_check(); // Make sure only not(test) are checked, not other attributes @@ -22,10 +24,13 @@ struct CfgNotTest; // Deeply nested `not(test)` #[cfg(not(test))] +//~^ cfg_not_test fn foo() {} #[cfg(all(debug_assertions, not(test)))] +//~^ cfg_not_test fn bar() {} #[cfg(not(any(not(debug_assertions), test)))] +//~^ cfg_not_test fn baz() {} #[cfg(test)] diff --git a/tests/ui/cfg_not_test.stderr b/tests/ui/cfg_not_test.stderr index c1bf626887af..e452ef2b5ab6 100644 --- a/tests/ui/cfg_not_test.stderr +++ b/tests/ui/cfg_not_test.stderr @@ -10,7 +10,7 @@ LL | #[cfg(not(test))] = help: to override `-D warnings` add `#[allow(clippy::cfg_not_test)]` error: code is excluded from test builds - --> tests/ui/cfg_not_test.rs:12:5 + --> tests/ui/cfg_not_test.rs:13:5 | LL | #[cfg(not(test))] | ^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | #[cfg(not(test))] = help: consider not excluding any code from test builds error: code is excluded from test builds - --> tests/ui/cfg_not_test.rs:24:1 + --> tests/ui/cfg_not_test.rs:26:1 | LL | #[cfg(not(test))] | ^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | #[cfg(not(test))] = help: consider not excluding any code from test builds error: code is excluded from test builds - --> tests/ui/cfg_not_test.rs:26:1 + --> tests/ui/cfg_not_test.rs:29:1 | LL | #[cfg(all(debug_assertions, not(test)))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | #[cfg(all(debug_assertions, not(test)))] = help: consider not excluding any code from test builds error: code is excluded from test builds - --> tests/ui/cfg_not_test.rs:28:1 + --> tests/ui/cfg_not_test.rs:32:1 | LL | #[cfg(not(any(not(debug_assertions), test)))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index 7bb3daf0f1e7..41e3c5e545cb 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -3,6 +3,7 @@ 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 + //~^ char_lit_as_u8 + + } diff --git a/tests/ui/char_lit_as_u8_suggestions.fixed b/tests/ui/char_lit_as_u8_suggestions.fixed index 6f13078a3ae9..64aacedfd36a 100644 --- a/tests/ui/char_lit_as_u8_suggestions.fixed +++ b/tests/ui/char_lit_as_u8_suggestions.fixed @@ -2,7 +2,11 @@ fn main() { let _ = b'a'; + //~^ char_lit_as_u8 let _ = b'\n'; + //~^ char_lit_as_u8 let _ = b'\0'; + //~^ char_lit_as_u8 let _ = b'\x01'; + //~^ char_lit_as_u8 } diff --git a/tests/ui/char_lit_as_u8_suggestions.rs b/tests/ui/char_lit_as_u8_suggestions.rs index 7737eb5135fb..a8f39e27605e 100644 --- a/tests/ui/char_lit_as_u8_suggestions.rs +++ b/tests/ui/char_lit_as_u8_suggestions.rs @@ -2,7 +2,11 @@ fn main() { let _ = 'a' as u8; + //~^ char_lit_as_u8 let _ = '\n' as u8; + //~^ char_lit_as_u8 let _ = '\0' as u8; + //~^ char_lit_as_u8 let _ = '\x01' as u8; + //~^ char_lit_as_u8 } diff --git a/tests/ui/char_lit_as_u8_suggestions.stderr b/tests/ui/char_lit_as_u8_suggestions.stderr index 4826aca42e1c..158dfd6bed26 100644 --- a/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/tests/ui/char_lit_as_u8_suggestions.stderr @@ -9,7 +9,7 @@ LL | let _ = 'a' as u8; = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` error: casting a character literal to `u8` truncates - --> tests/ui/char_lit_as_u8_suggestions.rs:5:13 + --> tests/ui/char_lit_as_u8_suggestions.rs:6:13 | LL | let _ = '\n' as u8; | ^^^^^^^^^^ help: use a byte literal instead: `b'\n'` @@ -17,7 +17,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 - --> tests/ui/char_lit_as_u8_suggestions.rs:6:13 + --> tests/ui/char_lit_as_u8_suggestions.rs:8:13 | LL | let _ = '\0' as u8; | ^^^^^^^^^^ help: use a byte literal instead: `b'\0'` @@ -25,7 +25,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 - --> tests/ui/char_lit_as_u8_suggestions.rs:7:13 + --> tests/ui/char_lit_as_u8_suggestions.rs:10: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 1e8da3316141..279a5b6e1ff8 100644 --- a/tests/ui/checked_conversions.fixed +++ b/tests/ui/checked_conversions.fixed @@ -13,46 +13,62 @@ pub fn i64_to_u32(value: i64) { let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions } pub fn i64_to_u16(value: i64) { let _ = u16::try_from(value).is_ok(); + //~^ checked_conversions let _ = u16::try_from(value).is_ok(); + //~^ checked_conversions } pub fn isize_to_u8(value: isize) { let _ = u8::try_from(value).is_ok(); + //~^ checked_conversions let _ = u8::try_from(value).is_ok(); + //~^ checked_conversions } // Signed to signed pub fn i64_to_i32(value: i64) { let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions } pub fn i64_to_i16(value: i64) { let _ = i16::try_from(value).is_ok(); + //~^ checked_conversions let _ = i16::try_from(value).is_ok(); + //~^ checked_conversions } // Unsigned to X pub fn u32_to_i32(value: u32) { let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions let _ = i32::try_from(value).is_ok(); + //~^ checked_conversions } pub fn usize_to_isize(value: usize) { let _ = isize::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions let _ = isize::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions } pub fn u32_to_u16(value: u32) { let _ = u16::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions let _ = u16::try_from(value).is_ok() && value as i32 == 5; + //~^ checked_conversions } // Negative tests @@ -86,6 +102,7 @@ fn msrv_1_33() { fn msrv_1_34() { let value: i64 = 34; let _ = u32::try_from(value).is_ok(); + //~^ checked_conversions } fn main() {} diff --git a/tests/ui/checked_conversions.rs b/tests/ui/checked_conversions.rs index 67a9adc049ea..c339bc674bbb 100644 --- a/tests/ui/checked_conversions.rs +++ b/tests/ui/checked_conversions.rs @@ -13,46 +13,62 @@ pub fn i64_to_u32(value: i64) { let _ = value <= (u32::max_value() as i64) && value >= 0; + //~^ checked_conversions let _ = value <= (u32::MAX as i64) && value >= 0; + //~^ checked_conversions } pub fn i64_to_u16(value: i64) { let _ = value <= i64::from(u16::max_value()) && value >= 0; + //~^ checked_conversions let _ = value <= i64::from(u16::MAX) && value >= 0; + //~^ checked_conversions } pub fn isize_to_u8(value: isize) { let _ = value <= (u8::max_value() as isize) && value >= 0; + //~^ checked_conversions let _ = value <= (u8::MAX as isize) && value >= 0; + //~^ checked_conversions } // Signed to signed pub fn i64_to_i32(value: i64) { let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64); + //~^ checked_conversions let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64); + //~^ checked_conversions } pub fn i64_to_i16(value: i64) { let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()); + //~^ checked_conversions let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN); + //~^ checked_conversions } // Unsigned to X pub fn u32_to_i32(value: u32) { let _ = value <= i32::max_value() as u32; + //~^ checked_conversions let _ = value <= i32::MAX as u32; + //~^ checked_conversions } pub fn usize_to_isize(value: usize) { let _ = value <= isize::max_value() as usize && value as i32 == 5; + //~^ checked_conversions let _ = value <= isize::MAX as usize && value as i32 == 5; + //~^ checked_conversions } pub fn u32_to_u16(value: u32) { let _ = value <= u16::max_value() as u32 && value as i32 == 5; + //~^ checked_conversions let _ = value <= u16::MAX as u32 && value as i32 == 5; + //~^ checked_conversions } // Negative tests @@ -86,6 +102,7 @@ fn msrv_1_33() { fn msrv_1_34() { let value: i64 = 34; let _ = value <= (u32::MAX as i64) && value >= 0; + //~^ checked_conversions } fn main() {} diff --git a/tests/ui/checked_conversions.stderr b/tests/ui/checked_conversions.stderr index 453cd7fcf016..3841b9d5a4dd 100644 --- a/tests/ui/checked_conversions.stderr +++ b/tests/ui/checked_conversions.stderr @@ -8,97 +8,97 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0; = help: to override `-D warnings` add `#[allow(clippy::checked_conversions)]` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:16:13 + --> tests/ui/checked_conversions.rs:17:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:20:13 + --> tests/ui/checked_conversions.rs:22: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 - --> tests/ui/checked_conversions.rs:21:13 + --> tests/ui/checked_conversions.rs:24:13 | LL | let _ = value <= i64::from(u16::MAX) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:25:13 + --> tests/ui/checked_conversions.rs:29: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 - --> tests/ui/checked_conversions.rs:26:13 + --> tests/ui/checked_conversions.rs:31:13 | LL | let _ = value <= (u8::MAX as isize) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:32:13 + --> tests/ui/checked_conversions.rs:38: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 - --> tests/ui/checked_conversions.rs:33:13 + --> tests/ui/checked_conversions.rs:40: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 - --> tests/ui/checked_conversions.rs:37:13 + --> tests/ui/checked_conversions.rs:45: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 - --> tests/ui/checked_conversions.rs:38:13 + --> tests/ui/checked_conversions.rs:47: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 - --> tests/ui/checked_conversions.rs:44:13 + --> tests/ui/checked_conversions.rs:54:13 | LL | let _ = value <= i32::max_value() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:45:13 + --> tests/ui/checked_conversions.rs:56:13 | LL | let _ = value <= i32::MAX as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> tests/ui/checked_conversions.rs:49:13 + --> tests/ui/checked_conversions.rs:61: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 - --> tests/ui/checked_conversions.rs:50:13 + --> tests/ui/checked_conversions.rs:63: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 - --> tests/ui/checked_conversions.rs:54:13 + --> tests/ui/checked_conversions.rs:68: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 - --> tests/ui/checked_conversions.rs:55:13 + --> tests/ui/checked_conversions.rs:70: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 - --> tests/ui/checked_conversions.rs:88:13 + --> tests/ui/checked_conversions.rs:104: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.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 323dae380633..3eedb659ebf6 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -11,16 +11,20 @@ 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` + //~^ unnecessary_unwrap + // will panic x.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + // will panic y.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary y.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err` + //~^ unnecessary_unwrap + } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -36,37 +40,47 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary x.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // will panic y.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary y.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + } 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` + //~^ unnecessary_unwrap + // will panic x.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + // will panic y.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary y.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // unnecessary z.unwrap(); - //~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err` + //~^ unnecessary_unwrap + // will panic z.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -76,22 +90,28 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary x.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // unnecessary y.unwrap(); - //~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // will panic y.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + // will panic z.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary z.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err` + //~^ unnecessary_unwrap + } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index aa72e8cce590..02118affe731 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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:16:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:17: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:19:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:21: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:22:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:25: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:38:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:42: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:41:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:46: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:44:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:50: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:47:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:54: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:53:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:61: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:56:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:65: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:59:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:69: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:62:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:73: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:65:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:77: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:68:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:81: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:78:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:92: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:81:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:96: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:84:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:100: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:87:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:104: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:90:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:108: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:93:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:112: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 68923793dcdf..145885702a9b 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -11,11 +11,11 @@ fn test_nested() { if x.is_some() { // unnecessary x.unwrap(); - //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` + //~^ unnecessary_unwrap } else { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap } } } diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index c3c8562edffb..7736643d894c 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -11,6 +11,7 @@ macro_rules! m { if $a.is_some() { // unnecessary $a.unwrap(); + //~^ unnecessary_unwrap } }; } @@ -44,26 +45,32 @@ fn main() { if x.is_some() { // unnecessary x.unwrap(); - //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` + //~^ unnecessary_unwrap + // unnecessary x.expect("an error message"); - //~^ ERROR: called `expect` on `x` after checking its variant with `is_some` + //~^ unnecessary_unwrap + } else { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // will panic x.expect("an error message"); - //~^ ERROR: this call to `expect()` will always panic + //~^ panicking_unwrap + } if x.is_none() { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + } else { // unnecessary x.unwrap(); - //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_none` + //~^ unnecessary_unwrap + } m!(x); // ok @@ -76,38 +83,48 @@ fn main() { if x.is_ok() { // unnecessary x.unwrap(); - //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // unnecessary x.expect("an error message"); - //~^ ERROR: called `expect` on `x` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + // will panic x.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + } else { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // will panic x.expect("an error message"); - //~^ ERROR: this call to `expect()` will always panic + //~^ panicking_unwrap + // unnecessary x.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + } if x.is_err() { // will panic x.unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + // unnecessary x.unwrap_err(); - //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_err` + //~^ unnecessary_unwrap + } else { // unnecessary x.unwrap(); - //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_err` + //~^ unnecessary_unwrap + // will panic x.unwrap_err(); - //~^ ERROR: this call to `unwrap_err()` will always panic + //~^ panicking_unwrap + } if x.is_ok() { x = Err(()); @@ -132,38 +149,46 @@ fn issue11371() { if option.is_some() { option.as_ref().unwrap(); - //~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some` + //~^ unnecessary_unwrap + } else { option.as_ref().unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + } let result = Ok::<(), ()>(()); if result.is_ok() { result.as_ref().unwrap(); - //~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + } else { result.as_ref().unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + } let mut option = Some(()); if option.is_some() { option.as_mut().unwrap(); - //~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some` + //~^ unnecessary_unwrap + } else { option.as_mut().unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + } let mut result = Ok::<(), ()>(()); if result.is_ok() { result.as_mut().unwrap(); - //~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok` + //~^ unnecessary_unwrap + } else { result.as_mut().unwrap(); - //~^ ERROR: this call to `unwrap()` will always panic + //~^ panicking_unwrap + } // This should not lint. Statics are, at the time of writing, not linted on anyway, @@ -172,6 +197,7 @@ fn issue11371() { static mut X: Option = Some(123); unsafe { if X.is_some() { + //~^ ERROR: creating a shared reference X = None; X.unwrap(); } diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index d92c03f48881..789a4a8f92bc 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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:46:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:47:9 | LL | if x.is_some() { | -------------- help: try: `if let Some() = x` @@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:49:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:51: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:53:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:56: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:56:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:60: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:61:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:66: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:65:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:71: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:78:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:85: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:81:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:89: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:84:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:93: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:88:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:98: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:91:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:102: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:94:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:106: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:99:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:112: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:102:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:116: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:106:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:121: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:109:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:125:9 | LL | if x.is_err() { | ---------- because of this check @@ -169,7 +169,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:134:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:151:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &option` @@ -177,7 +177,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:137:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:155:9 | LL | if option.is_some() { | ---------------- because of this check @@ -186,7 +186,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:144:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:163:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &result` @@ -194,7 +194,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:147:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:167:9 | LL | if result.is_ok() { | -------------- because of this check @@ -203,7 +203,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:174:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &mut option` @@ -211,7 +211,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:178:9 | LL | if option.is_some() { | ---------------- because of this check @@ -220,7 +220,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:162:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:185:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &mut result` @@ -228,7 +228,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:165:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:189:9 | LL | if result.is_ok() { | -------------- because of this check @@ -237,7 +237,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: creating a shared reference to mutable static is discouraged - --> tests/ui/checked_unwrap/simple_conditionals.rs:174:12 + --> tests/ui/checked_unwrap/simple_conditionals.rs:199:12 | LL | if X.is_some() { | ^^^^^^^^^^^ shared reference to mutable static diff --git a/tests/ui/clear_with_drain.fixed b/tests/ui/clear_with_drain.fixed index 15777a4ea5b3..92fd86668b76 100644 --- a/tests/ui/clear_with_drain.fixed +++ b/tests/ui/clear_with_drain.fixed @@ -20,10 +20,12 @@ fn vec_range() { // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain } fn vec_range_from() { @@ -43,10 +45,12 @@ fn vec_range_from() { // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain } fn vec_range_full() { @@ -63,6 +67,7 @@ fn vec_range_full() { // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain } fn vec_range_to() { @@ -80,6 +85,7 @@ fn vec_range_to() { // Do lint let mut v = vec![1, 2, 3]; v.clear(); + //~^ clear_with_drain } fn vec_partial_drains() { @@ -118,10 +124,12 @@ fn vec_deque_range() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain } fn vec_deque_range_from() { @@ -141,10 +149,12 @@ fn vec_deque_range_from() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain } fn vec_deque_range_full() { @@ -161,6 +171,7 @@ fn vec_deque_range_full() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain } fn vec_deque_range_to() { @@ -178,6 +189,7 @@ fn vec_deque_range_to() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.clear(); + //~^ clear_with_drain } fn vec_deque_partial_drains() { @@ -216,10 +228,12 @@ fn string_range() { // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain } fn string_range_from() { @@ -239,10 +253,12 @@ fn string_range_from() { // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain } fn string_range_full() { @@ -259,6 +275,7 @@ fn string_range_full() { // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain } fn string_range_to() { @@ -276,6 +293,7 @@ fn string_range_to() { // Do lint let mut s = String::from("Hello, world!"); s.clear(); + //~^ clear_with_drain } fn string_partial_drains() { @@ -314,6 +332,7 @@ fn hash_set() { // Do lint let mut set = HashSet::from([1, 2, 3]); set.clear(); + //~^ clear_with_drain } fn hash_map() { @@ -333,6 +352,7 @@ fn hash_map() { // Do lint let mut map = HashMap::from([(1, "a"), (2, "b")]); map.clear(); + //~^ clear_with_drain } fn binary_heap() { @@ -352,6 +372,7 @@ fn binary_heap() { // Do lint let mut heap = BinaryHeap::from([1, 2]); heap.clear(); + //~^ clear_with_drain } fn main() {} diff --git a/tests/ui/clear_with_drain.rs b/tests/ui/clear_with_drain.rs index 1dea7235ef66..28122fcaeded 100644 --- a/tests/ui/clear_with_drain.rs +++ b/tests/ui/clear_with_drain.rs @@ -20,10 +20,12 @@ fn vec_range() { // Do lint let mut v = vec![1, 2, 3]; v.drain(0..v.len()); + //~^ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; v.drain(usize::MIN..v.len()); + //~^ clear_with_drain } fn vec_range_from() { @@ -43,10 +45,12 @@ fn vec_range_from() { // Do lint let mut v = vec![1, 2, 3]; v.drain(0..); + //~^ clear_with_drain // Do lint let mut v = vec![1, 2, 3]; v.drain(usize::MIN..); + //~^ clear_with_drain } fn vec_range_full() { @@ -63,6 +67,7 @@ fn vec_range_full() { // Do lint let mut v = vec![1, 2, 3]; v.drain(..); + //~^ clear_with_drain } fn vec_range_to() { @@ -80,6 +85,7 @@ fn vec_range_to() { // Do lint let mut v = vec![1, 2, 3]; v.drain(..v.len()); + //~^ clear_with_drain } fn vec_partial_drains() { @@ -118,10 +124,12 @@ fn vec_deque_range() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(0..deque.len()); + //~^ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(usize::MIN..deque.len()); + //~^ clear_with_drain } fn vec_deque_range_from() { @@ -141,10 +149,12 @@ fn vec_deque_range_from() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(0..); + //~^ clear_with_drain // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(usize::MIN..); + //~^ clear_with_drain } fn vec_deque_range_full() { @@ -161,6 +171,7 @@ fn vec_deque_range_full() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(..); + //~^ clear_with_drain } fn vec_deque_range_to() { @@ -178,6 +189,7 @@ fn vec_deque_range_to() { // Do lint let mut deque = VecDeque::from([1, 2, 3]); deque.drain(..deque.len()); + //~^ clear_with_drain } fn vec_deque_partial_drains() { @@ -216,10 +228,12 @@ fn string_range() { // Do lint let mut s = String::from("Hello, world!"); s.drain(0..s.len()); + //~^ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); s.drain(usize::MIN..s.len()); + //~^ clear_with_drain } fn string_range_from() { @@ -239,10 +253,12 @@ fn string_range_from() { // Do lint let mut s = String::from("Hello, world!"); s.drain(0..); + //~^ clear_with_drain // Do lint let mut s = String::from("Hello, world!"); s.drain(usize::MIN..); + //~^ clear_with_drain } fn string_range_full() { @@ -259,6 +275,7 @@ fn string_range_full() { // Do lint let mut s = String::from("Hello, world!"); s.drain(..); + //~^ clear_with_drain } fn string_range_to() { @@ -276,6 +293,7 @@ fn string_range_to() { // Do lint let mut s = String::from("Hello, world!"); s.drain(..s.len()); + //~^ clear_with_drain } fn string_partial_drains() { @@ -314,6 +332,7 @@ fn hash_set() { // Do lint let mut set = HashSet::from([1, 2, 3]); set.drain(); + //~^ clear_with_drain } fn hash_map() { @@ -333,6 +352,7 @@ fn hash_map() { // Do lint let mut map = HashMap::from([(1, "a"), (2, "b")]); map.drain(); + //~^ clear_with_drain } fn binary_heap() { @@ -352,6 +372,7 @@ fn binary_heap() { // Do lint let mut heap = BinaryHeap::from([1, 2]); heap.drain(); + //~^ clear_with_drain } fn main() {} diff --git a/tests/ui/clear_with_drain.stderr b/tests/ui/clear_with_drain.stderr index 3c7d22192dc7..0f060fa9dade 100644 --- a/tests/ui/clear_with_drain.stderr +++ b/tests/ui/clear_with_drain.stderr @@ -8,121 +8,121 @@ LL | v.drain(0..v.len()); = help: to override `-D warnings` add `#[allow(clippy::clear_with_drain)]` error: `drain` used to clear a `Vec` - --> tests/ui/clear_with_drain.rs:26:7 + --> tests/ui/clear_with_drain.rs:27:7 | LL | v.drain(usize::MIN..v.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> tests/ui/clear_with_drain.rs:45:7 + --> tests/ui/clear_with_drain.rs:47:7 | LL | v.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> tests/ui/clear_with_drain.rs:49:7 + --> tests/ui/clear_with_drain.rs:52:7 | LL | v.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> tests/ui/clear_with_drain.rs:65:7 + --> tests/ui/clear_with_drain.rs:69:7 | LL | v.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> tests/ui/clear_with_drain.rs:82:7 + --> tests/ui/clear_with_drain.rs:87:7 | LL | v.drain(..v.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:120:11 + --> tests/ui/clear_with_drain.rs:126:11 | LL | deque.drain(0..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:124:11 + --> tests/ui/clear_with_drain.rs:131:11 | LL | deque.drain(usize::MIN..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:143:11 + --> tests/ui/clear_with_drain.rs:151:11 | LL | deque.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:147:11 + --> tests/ui/clear_with_drain.rs:156:11 | LL | deque.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:163:11 + --> tests/ui/clear_with_drain.rs:173:11 | LL | deque.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> tests/ui/clear_with_drain.rs:180:11 + --> tests/ui/clear_with_drain.rs:191:11 | LL | deque.drain(..deque.len()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:218:7 + --> tests/ui/clear_with_drain.rs:230:7 | LL | s.drain(0..s.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:222:7 + --> tests/ui/clear_with_drain.rs:235:7 | LL | s.drain(usize::MIN..s.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:241:7 + --> tests/ui/clear_with_drain.rs:255:7 | LL | s.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:245:7 + --> tests/ui/clear_with_drain.rs:260:7 | LL | s.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:261:7 + --> tests/ui/clear_with_drain.rs:277:7 | LL | s.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> tests/ui/clear_with_drain.rs:278:7 + --> tests/ui/clear_with_drain.rs:295:7 | LL | s.drain(..s.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashSet` - --> tests/ui/clear_with_drain.rs:316:9 + --> tests/ui/clear_with_drain.rs:334:9 | LL | set.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashMap` - --> tests/ui/clear_with_drain.rs:335:9 + --> tests/ui/clear_with_drain.rs:354:9 | LL | map.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `BinaryHeap` - --> tests/ui/clear_with_drain.rs:354:10 + --> tests/ui/clear_with_drain.rs:374:10 | LL | heap.drain(); | ^^^^^^^ help: try: `clear()` diff --git a/tests/ui/clone_on_copy.fixed b/tests/ui/clone_on_copy.fixed index 9d9a5bf20f43..f965aa5c182d 100644 --- a/tests/ui/clone_on_copy.fixed +++ b/tests/ui/clone_on_copy.fixed @@ -21,16 +21,20 @@ fn is_ascii(ch: char) -> bool { fn clone_on_copy() -> Option<(i32)> { 42; + //~^ clone_on_copy vec![1].clone(); // ok, not a Copy type Some(vec![1]).clone(); // ok, not a Copy type *(&42); + //~^ clone_on_copy let rc = RefCell::new(0); *rc.borrow(); + //~^ clone_on_copy let x = 0u32; x.rotate_left(1); + //~^ clone_on_copy #[derive(Clone, Copy)] struct Foo; @@ -45,6 +49,7 @@ fn clone_on_copy() -> Option<(i32)> { ($e:expr) => {{ $e }}; } m!(42); + //~^ clone_on_copy struct Wrap([u32; 2]); impl core::ops::Deref for Wrap { @@ -55,6 +60,7 @@ fn clone_on_copy() -> Option<(i32)> { } let x = Wrap([0, 0]); (*x)[0]; + //~^ clone_on_copy let x = 42; let ref y = x.clone(); // ok, binds by reference @@ -65,13 +71,16 @@ fn clone_on_copy() -> Option<(i32)> { let _ = &x.clone(); // ok, getting a ref 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate is_ascii('z'); + //~^ clone_on_copy // Issue #5436 let mut vec = Vec::new(); vec.push(42); + //~^ clone_on_copy // Issue #9277 let opt: &Option = &None; let value = (*opt)?; // operator precedence needed (*opt)? + //~^ clone_on_copy None } diff --git a/tests/ui/clone_on_copy.rs b/tests/ui/clone_on_copy.rs index 305bc6816e1b..f6a542296de1 100644 --- a/tests/ui/clone_on_copy.rs +++ b/tests/ui/clone_on_copy.rs @@ -21,16 +21,20 @@ fn is_ascii(ch: char) -> bool { fn clone_on_copy() -> Option<(i32)> { 42.clone(); + //~^ clone_on_copy vec![1].clone(); // ok, not a Copy type Some(vec![1]).clone(); // ok, not a Copy type (&42).clone(); + //~^ clone_on_copy let rc = RefCell::new(0); rc.borrow().clone(); + //~^ clone_on_copy let x = 0u32; x.clone().rotate_left(1); + //~^ clone_on_copy #[derive(Clone, Copy)] struct Foo; @@ -45,6 +49,7 @@ fn clone_on_copy() -> Option<(i32)> { ($e:expr) => {{ $e }}; } m!(42).clone(); + //~^ clone_on_copy struct Wrap([u32; 2]); impl core::ops::Deref for Wrap { @@ -55,6 +60,7 @@ fn clone_on_copy() -> Option<(i32)> { } let x = Wrap([0, 0]); x.clone()[0]; + //~^ clone_on_copy let x = 42; let ref y = x.clone(); // ok, binds by reference @@ -65,13 +71,16 @@ fn clone_on_copy() -> Option<(i32)> { let _ = &x.clone(); // ok, getting a ref 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate is_ascii('z'.clone()); + //~^ clone_on_copy // Issue #5436 let mut vec = Vec::new(); vec.push(42.clone()); + //~^ clone_on_copy // Issue #9277 let opt: &Option = &None; let value = opt.clone()?; // operator precedence needed (*opt)? + //~^ clone_on_copy None } diff --git a/tests/ui/clone_on_copy.stderr b/tests/ui/clone_on_copy.stderr index 314fd13afca4..92cdd635d20a 100644 --- a/tests/ui/clone_on_copy.stderr +++ b/tests/ui/clone_on_copy.stderr @@ -8,49 +8,49 @@ LL | 42.clone(); = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `i32` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:27:5 + --> tests/ui/clone_on_copy.rs:28:5 | LL | (&42).clone(); | ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)` error: using `clone` on type `i32` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:30:5 + --> tests/ui/clone_on_copy.rs:32:5 | LL | rc.borrow().clone(); | ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()` error: using `clone` on type `u32` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:33:5 + --> tests/ui/clone_on_copy.rs:36: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 - --> tests/ui/clone_on_copy.rs:47:5 + --> tests/ui/clone_on_copy.rs:51: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 - --> tests/ui/clone_on_copy.rs:57:5 + --> tests/ui/clone_on_copy.rs:62:5 | LL | x.clone()[0]; | ^^^^^^^^^ help: try dereferencing it: `(*x)` error: using `clone` on type `char` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:67:14 + --> tests/ui/clone_on_copy.rs:73:14 | LL | is_ascii('z'.clone()); | ^^^^^^^^^^^ help: try removing the `clone` call: `'z'` error: using `clone` on type `i32` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:71:14 + --> tests/ui/clone_on_copy.rs:78:14 | LL | vec.push(42.clone()); | ^^^^^^^^^^ help: try removing the `clone` call: `42` error: using `clone` on type `Option` which implements the `Copy` trait - --> tests/ui/clone_on_copy.rs:75:17 + --> tests/ui/clone_on_copy.rs:83:17 | LL | let value = opt.clone()?; // operator precedence needed (*opt)? | ^^^^^^^^^^^ help: try dereferencing it: `(*opt)` diff --git a/tests/ui/clone_on_copy_impl.rs b/tests/ui/clone_on_copy_impl.rs index 2d03544ad8b6..33375aead4d5 100644 --- a/tests/ui/clone_on_copy_impl.rs +++ b/tests/ui/clone_on_copy_impl.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::non_canonical_clone_impl)] use std::fmt; diff --git a/tests/ui/cloned_instead_of_copied.fixed b/tests/ui/cloned_instead_of_copied.fixed index bc939bb3dbb9..94784b4747e8 100644 --- a/tests/ui/cloned_instead_of_copied.fixed +++ b/tests/ui/cloned_instead_of_copied.fixed @@ -5,10 +5,15 @@ fn main() { // yay let _ = [1].iter().copied(); + //~^ cloned_instead_of_copied let _ = vec!["hi"].iter().copied(); + //~^ cloned_instead_of_copied let _ = Some(&1).copied(); + //~^ cloned_instead_of_copied let _ = Box::new([1].iter()).copied(); + //~^ cloned_instead_of_copied let _ = Box::new(Some(&1)).copied(); + //~^ cloned_instead_of_copied // nay let _ = [String::new()].iter().cloned(); @@ -25,10 +30,13 @@ fn msrv_1_34() { fn msrv_1_35() { let _ = [1].iter().cloned(); let _ = Some(&1).copied(); // Option::copied needs 1.35 + //~^ cloned_instead_of_copied } #[clippy::msrv = "1.36"] fn msrv_1_36() { let _ = [1].iter().copied(); // Iterator::copied needs 1.36 + //~^ cloned_instead_of_copied let _ = Some(&1).copied(); + //~^ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.rs b/tests/ui/cloned_instead_of_copied.rs index 27346adbfbf1..54e01e369f9d 100644 --- a/tests/ui/cloned_instead_of_copied.rs +++ b/tests/ui/cloned_instead_of_copied.rs @@ -5,10 +5,15 @@ fn main() { // yay let _ = [1].iter().cloned(); + //~^ cloned_instead_of_copied let _ = vec!["hi"].iter().cloned(); + //~^ cloned_instead_of_copied let _ = Some(&1).cloned(); + //~^ cloned_instead_of_copied let _ = Box::new([1].iter()).cloned(); + //~^ cloned_instead_of_copied let _ = Box::new(Some(&1)).cloned(); + //~^ cloned_instead_of_copied // nay let _ = [String::new()].iter().cloned(); @@ -25,10 +30,13 @@ fn msrv_1_34() { fn msrv_1_35() { let _ = [1].iter().cloned(); let _ = Some(&1).cloned(); // Option::copied needs 1.35 + //~^ cloned_instead_of_copied } #[clippy::msrv = "1.36"] fn msrv_1_36() { let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 + //~^ cloned_instead_of_copied let _ = Some(&1).cloned(); + //~^ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.stderr b/tests/ui/cloned_instead_of_copied.stderr index ad857c4ef7d0..70ac0a767daf 100644 --- a/tests/ui/cloned_instead_of_copied.stderr +++ b/tests/ui/cloned_instead_of_copied.stderr @@ -8,43 +8,43 @@ LL | let _ = [1].iter().cloned(); = help: to override `-D warnings` add `#[allow(clippy::cloned_instead_of_copied)]` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:8:31 + --> tests/ui/cloned_instead_of_copied.rs:9:31 | LL | let _ = vec!["hi"].iter().cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:9:22 + --> tests/ui/cloned_instead_of_copied.rs:11:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:10:34 + --> tests/ui/cloned_instead_of_copied.rs:13:34 | LL | let _ = Box::new([1].iter()).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:11:32 + --> tests/ui/cloned_instead_of_copied.rs:15:32 | LL | let _ = Box::new(Some(&1)).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:27:22 + --> tests/ui/cloned_instead_of_copied.rs:32:22 | LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:32:24 + --> tests/ui/cloned_instead_of_copied.rs:38:24 | LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:33:22 + --> tests/ui/cloned_instead_of_copied.rs:40:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` diff --git a/tests/ui/cmp_null.fixed b/tests/ui/cmp_null.fixed index e5ab765bc861..27b831950dc7 100644 --- a/tests/ui/cmp_null.fixed +++ b/tests/ui/cmp_null.fixed @@ -7,26 +7,31 @@ fn main() { let x = 0; let p: *const usize = &x; if p.is_null() { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method - //~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` + //~^ cmp_null + + println!("This is surprising!"); } if p.is_null() { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + println!("This is surprising!"); } let mut y = 0; let mut m: *mut usize = &mut y; if m.is_null() { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + println!("This is surprising, too!"); } if m.is_null() { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + println!("This is surprising, too!"); } let _ = (x as *const ()).is_null(); - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + } diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index 257f7ba26627..ac1bf83e094c 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -7,26 +7,31 @@ 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` + //~^ cmp_null + + println!("This is surprising!"); } if ptr::null() == p { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + 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 + //~^ cmp_null + println!("This is surprising, too!"); } if ptr::null_mut() == m { - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + println!("This is surprising, too!"); } let _ = x as *const () == ptr::null(); - //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~^ cmp_null + } diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index f3b35f3afba8..a44dd8067613 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -8,25 +8,25 @@ LL | if p == ptr::null() { = help: to override `-D warnings` add `#[allow(clippy::cmp_null)]` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:14:8 + --> tests/ui/cmp_null.rs:15:8 | LL | if ptr::null() == p { | ^^^^^^^^^^^^^^^^ help: try: `p.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:21:8 + --> tests/ui/cmp_null.rs:23:8 | LL | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:25:8 + --> tests/ui/cmp_null.rs:28:8 | LL | if ptr::null_mut() == m { | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:30:13 + --> tests/ui/cmp_null.rs:34:13 | LL | let _ = x as *const () == ptr::null(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(x as *const ()).is_null()` diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed index 9fc70ab6f4a0..8d543b042200 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed @@ -44,7 +44,9 @@ mod borrowed_eq_owned { let borrowed = Borrowed {}; if borrowed == owned {} + //~^ cmp_owned if borrowed == owned {} + //~^ cmp_owned } } @@ -63,7 +65,9 @@ mod owned_eq_borrowed { let borrowed = Borrowed {}; if owned == borrowed {} + //~^ cmp_owned if owned == borrowed {} + //~^ cmp_owned } } @@ -90,7 +94,9 @@ mod issue_4874 { let borrowed = Borrowed {}; if borrowed == "Hi" {} + //~^ cmp_owned if borrowed == "Hi" {} + //~^ cmp_owned } } diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.rs b/tests/ui/cmp_owned/asymmetric_partial_eq.rs index 5cd43ea1d411..6da311c50ee7 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.rs +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.rs @@ -44,7 +44,9 @@ mod borrowed_eq_owned { let borrowed = Borrowed {}; if borrowed.to_owned() == owned {} + //~^ cmp_owned if owned == borrowed.to_owned() {} + //~^ cmp_owned } } @@ -63,7 +65,9 @@ mod owned_eq_borrowed { let borrowed = Borrowed {}; if owned == borrowed.to_owned() {} + //~^ cmp_owned if borrowed.to_owned() == owned {} + //~^ cmp_owned } } @@ -90,7 +94,9 @@ mod issue_4874 { let borrowed = Borrowed {}; if "Hi" == borrowed.to_string() {} + //~^ cmp_owned if borrowed.to_string() == "Hi" {} + //~^ cmp_owned } } diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr index e230d5f06bb0..1d2645d358f3 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr @@ -8,7 +8,7 @@ LL | if borrowed.to_owned() == owned {} = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:47:21 + --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:48:21 | LL | if owned == borrowed.to_owned() {} | ---------^^^^^^^^^^^^^^^^^^^ @@ -16,13 +16,13 @@ LL | if owned == borrowed.to_owned() {} | help: try: `borrowed == owned` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:65:21 + --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:67:21 | LL | if owned == borrowed.to_owned() {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:66:12 + --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:69:12 | LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^--------- @@ -30,7 +30,7 @@ LL | if borrowed.to_owned() == owned {} | help: try: `owned == borrowed` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:92:20 + --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:96:20 | LL | if "Hi" == borrowed.to_string() {} | --------^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | if "Hi" == borrowed.to_string() {} | help: try: `borrowed == "Hi"` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:93:12 + --> tests/ui/cmp_owned/asymmetric_partial_eq.rs:98: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 40d7b5e49fcd..a926857c78a1 100644 --- a/tests/ui/cmp_owned/comparison_flip.fixed +++ b/tests/ui/cmp_owned/comparison_flip.fixed @@ -4,10 +4,12 @@ fn main() { let a = Foo; if a != "bar" { + //~^ cmp_owned println!("foo"); } if a != "bar" { + //~^ cmp_owned println!("foo"); } } diff --git a/tests/ui/cmp_owned/comparison_flip.rs b/tests/ui/cmp_owned/comparison_flip.rs index 59a945668b2e..169d472203c5 100644 --- a/tests/ui/cmp_owned/comparison_flip.rs +++ b/tests/ui/cmp_owned/comparison_flip.rs @@ -4,10 +4,12 @@ fn main() { let a = Foo; if a.to_string() != "bar" { + //~^ cmp_owned println!("foo"); } if "bar" != a.to_string() { + //~^ cmp_owned println!("foo"); } } diff --git a/tests/ui/cmp_owned/comparison_flip.stderr b/tests/ui/cmp_owned/comparison_flip.stderr index cfb6978158b3..ca571837039d 100644 --- a/tests/ui/cmp_owned/comparison_flip.stderr +++ b/tests/ui/cmp_owned/comparison_flip.stderr @@ -8,7 +8,7 @@ LL | if a.to_string() != "bar" { = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/comparison_flip.rs:10:17 + --> tests/ui/cmp_owned/comparison_flip.rs:11: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 ab72e096cc7c..eb01633a25fd 100644 --- a/tests/ui/cmp_owned/with_suggestion.fixed +++ b/tests/ui/cmp_owned/with_suggestion.fixed @@ -3,8 +3,10 @@ fn main() { fn with_to_string(x: &str) { x != "foo"; + //~^ cmp_owned "foo" != x; + //~^ cmp_owned } let x = "oh"; @@ -12,14 +14,18 @@ fn main() { with_to_string(x); x != "foo"; + //~^ cmp_owned x != "foo"; + //~^ cmp_owned 42.to_string() == "42"; Foo == Foo; + //~^ cmp_owned "abc".chars().filter(|c| *c != 'X'); + //~^ cmp_owned "abc".chars().filter(|c| *c != 'X'); } diff --git a/tests/ui/cmp_owned/with_suggestion.rs b/tests/ui/cmp_owned/with_suggestion.rs index cb5268734d32..82409f27b129 100644 --- a/tests/ui/cmp_owned/with_suggestion.rs +++ b/tests/ui/cmp_owned/with_suggestion.rs @@ -3,8 +3,10 @@ fn main() { fn with_to_string(x: &str) { x != "foo".to_string(); + //~^ cmp_owned "foo".to_string() != x; + //~^ cmp_owned } let x = "oh"; @@ -12,14 +14,18 @@ fn main() { with_to_string(x); x != "foo".to_owned(); + //~^ cmp_owned x != String::from("foo"); + //~^ cmp_owned 42.to_string() == "42"; Foo.to_owned() == Foo; + //~^ cmp_owned "abc".chars().filter(|c| c.to_owned() != 'X'); + //~^ cmp_owned "abc".chars().filter(|c| *c != 'X'); } diff --git a/tests/ui/cmp_owned/with_suggestion.stderr b/tests/ui/cmp_owned/with_suggestion.stderr index 41448e012003..ca2ab4484727 100644 --- a/tests/ui/cmp_owned/with_suggestion.stderr +++ b/tests/ui/cmp_owned/with_suggestion.stderr @@ -8,31 +8,31 @@ LL | x != "foo".to_string(); = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/with_suggestion.rs:7:9 + --> tests/ui/cmp_owned/with_suggestion.rs:8:9 | LL | "foo".to_string() != x; | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/with_suggestion.rs:14:10 + --> tests/ui/cmp_owned/with_suggestion.rs:16:10 | LL | x != "foo".to_owned(); | ^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/with_suggestion.rs:16:10 + --> tests/ui/cmp_owned/with_suggestion.rs:19:10 | LL | x != String::from("foo"); | ^^^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/with_suggestion.rs:20:5 + --> tests/ui/cmp_owned/with_suggestion.rs:24:5 | LL | Foo.to_owned() == Foo; | ^^^^^^^^^^^^^^ help: try: `Foo` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/with_suggestion.rs:22:30 + --> tests/ui/cmp_owned/with_suggestion.rs:27:30 | LL | "abc".chars().filter(|c| c.to_owned() != 'X'); | ^^^^^^^^^^^^ help: try: `*c` diff --git a/tests/ui/cmp_owned/without_suggestion.rs b/tests/ui/cmp_owned/without_suggestion.rs index 913aab727471..71bcac44ed7c 100644 --- a/tests/ui/cmp_owned/without_suggestion.rs +++ b/tests/ui/cmp_owned/without_suggestion.rs @@ -5,13 +5,15 @@ 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` + //~^ cmp_owned + + let x = &&Baz; let y = &Baz; y.to_owned() == **x; - //~^ ERROR: this creates an owned instance just for comparison + //~^ cmp_owned + let x = 0u32; let y = U32Wrapper(x); @@ -23,7 +25,8 @@ 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 + //~^ cmp_owned + } } diff --git a/tests/ui/cmp_owned/without_suggestion.stderr b/tests/ui/cmp_owned/without_suggestion.stderr index 13ca699b9fd3..6efaf9688e20 100644 --- a/tests/ui/cmp_owned/without_suggestion.stderr +++ b/tests/ui/cmp_owned/without_suggestion.stderr @@ -8,13 +8,13 @@ LL | y.to_owned() == *x; = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/without_suggestion.rs:13:5 + --> tests/ui/cmp_owned/without_suggestion.rs:14:5 | LL | y.to_owned() == **x; | ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/without_suggestion.rs:25:9 + --> tests/ui/cmp_owned/without_suggestion.rs:27: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 e8fd063a98f2..d750202d00ec 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -4,7 +4,8 @@ #[rustfmt::skip] fn main() { -//~^ ERROR: the function has a cognitive complexity of (28/25) +//~^ cognitive_complexity + if true { println!("a"); } @@ -90,7 +91,8 @@ fn main() { #[clippy::cognitive_complexity = "1"] fn kaboom() { - //~^ ERROR: the function has a cognitive complexity of (7/1) +//~^ cognitive_complexity + let n = 0; 'a: for i in 0..20 { 'b: for j in i..20 { @@ -149,9 +151,11 @@ fn lots_of_short_circuits2() -> bool { #[clippy::cognitive_complexity = "1"] fn baa() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + let x = || match 99 { - //~^ ERROR: the function has a cognitive complexity of (2/1) + //~^ cognitive_complexity + 0 => 0, 1 => 1, 2 => 2, @@ -169,7 +173,8 @@ fn baa() { #[clippy::cognitive_complexity = "1"] fn bar() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -181,7 +186,8 @@ 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) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -190,7 +196,8 @@ fn dont_warn_on_tests() { #[clippy::cognitive_complexity = "1"] fn barr() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -201,7 +208,8 @@ fn barr() { #[clippy::cognitive_complexity = "1"] fn barr2() { - //~^ ERROR: the function has a cognitive complexity of (3/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -218,7 +226,8 @@ fn barr2() { #[clippy::cognitive_complexity = "1"] fn barrr() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -229,7 +238,8 @@ fn barrr() { #[clippy::cognitive_complexity = "1"] fn barrr2() { - //~^ ERROR: the function has a cognitive complexity of (3/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -246,7 +256,8 @@ fn barrr2() { #[clippy::cognitive_complexity = "1"] fn barrrr() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -257,7 +268,8 @@ fn barrrr() { #[clippy::cognitive_complexity = "1"] fn barrrr2() { - //~^ ERROR: the function has a cognitive complexity of (3/1) +//~^ cognitive_complexity + match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -274,7 +286,8 @@ fn barrrr2() { #[clippy::cognitive_complexity = "1"] fn cake() { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + if 4 == 5 { println!("yea"); } else { @@ -285,7 +298,8 @@ fn cake() { #[clippy::cognitive_complexity = "1"] pub fn read_file(input_path: &str) -> String { - //~^ ERROR: the function has a cognitive complexity of (4/1) +//~^ cognitive_complexity + use std::fs::File; use std::io::{Read, Write}; use std::path::Path; @@ -317,7 +331,8 @@ enum Void {} #[clippy::cognitive_complexity = "1"] fn void(void: Void) { - //~^ ERROR: the function has a cognitive complexity of (2/1) +//~^ cognitive_complexity + if true { match void {} } @@ -369,7 +384,8 @@ fn early() -> Result { #[rustfmt::skip] #[clippy::cognitive_complexity = "1"] fn early_ret() -> i32 { -//~^ ERROR: the function has a cognitive complexity of (8/1) +//~^ cognitive_complexity + 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; }; @@ -391,7 +407,8 @@ 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) + //~^ cognitive_complexity + if true { println!("moo"); } @@ -405,7 +422,8 @@ struct Moo; #[clippy::cognitive_complexity = "1"] impl Moo { fn moo(&self) { - //~^ ERROR: the function has a cognitive complexity of (2/1) + //~^ cognitive_complexity + if true { println!("moo"); } @@ -415,7 +433,8 @@ impl Moo { #[clippy::cognitive_complexity = "1"] mod issue9300 { async fn a() { - //~^ ERROR: the function has a cognitive complexity of (2/1) + //~^ cognitive_complexity + let a = 0; if a == 0 {} } @@ -423,7 +442,8 @@ mod issue9300 { pub struct S; impl S { pub async fn async_method() { - //~^ ERROR: the function has a cognitive complexity of (2/1) + //~^ cognitive_complexity + let a = 0; if a == 0 {} } diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index 1e60247e5f58..60a834765a6b 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -9,7 +9,7 @@ LL | fn main() { = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: the function has a cognitive complexity of (7/1) - --> tests/ui/cognitive_complexity.rs:92:4 + --> tests/ui/cognitive_complexity.rs:93:4 | LL | fn kaboom() { | ^^^^^^ @@ -17,7 +17,7 @@ LL | fn kaboom() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:151:4 + --> tests/ui/cognitive_complexity.rs:153:4 | LL | fn baa() { | ^^^ @@ -25,7 +25,7 @@ LL | fn baa() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:153:13 + --> tests/ui/cognitive_complexity.rs:156:13 | LL | let x = || match 99 { | ^^ @@ -33,7 +33,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) - --> tests/ui/cognitive_complexity.rs:171:4 + --> tests/ui/cognitive_complexity.rs:175:4 | LL | fn bar() { | ^^^ @@ -41,7 +41,7 @@ LL | fn bar() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:183:4 + --> tests/ui/cognitive_complexity.rs:188:4 | LL | fn dont_warn_on_tests() { | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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) - --> tests/ui/cognitive_complexity.rs:192:4 + --> tests/ui/cognitive_complexity.rs:198:4 | LL | fn barr() { | ^^^^ @@ -57,7 +57,7 @@ LL | fn barr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:203:4 + --> tests/ui/cognitive_complexity.rs:210:4 | LL | fn barr2() { | ^^^^^ @@ -65,7 +65,7 @@ LL | fn barr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:220:4 + --> tests/ui/cognitive_complexity.rs:228:4 | LL | fn barrr() { | ^^^^^ @@ -73,7 +73,7 @@ LL | fn barrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:231:4 + --> tests/ui/cognitive_complexity.rs:240:4 | LL | fn barrr2() { | ^^^^^^ @@ -81,7 +81,7 @@ LL | fn barrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:248:4 + --> tests/ui/cognitive_complexity.rs:258:4 | LL | fn barrrr() { | ^^^^^^ @@ -89,7 +89,7 @@ LL | fn barrrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:259:4 + --> tests/ui/cognitive_complexity.rs:270:4 | LL | fn barrrr2() { | ^^^^^^^ @@ -97,7 +97,7 @@ LL | fn barrrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:276:4 + --> tests/ui/cognitive_complexity.rs:288:4 | LL | fn cake() { | ^^^^ @@ -105,7 +105,7 @@ LL | fn cake() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (4/1) - --> tests/ui/cognitive_complexity.rs:287:8 + --> tests/ui/cognitive_complexity.rs:300:8 | LL | pub fn read_file(input_path: &str) -> String { | ^^^^^^^^^ @@ -113,7 +113,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) - --> tests/ui/cognitive_complexity.rs:319:4 + --> tests/ui/cognitive_complexity.rs:333:4 | LL | fn void(void: Void) { | ^^^^ @@ -121,7 +121,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) - --> tests/ui/cognitive_complexity.rs:371:4 + --> tests/ui/cognitive_complexity.rs:386:4 | LL | fn early_ret() -> i32 { | ^^^^^^^^^ @@ -129,7 +129,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) - --> tests/ui/cognitive_complexity.rs:393:13 + --> tests/ui/cognitive_complexity.rs:409:13 | LL | let x = |a: i32, b: i32| -> i32 { | ^^^^^^^^^^^^^^^^ @@ -137,7 +137,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) - --> tests/ui/cognitive_complexity.rs:407:8 + --> tests/ui/cognitive_complexity.rs:424:8 | LL | fn moo(&self) { | ^^^ @@ -145,7 +145,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) - --> tests/ui/cognitive_complexity.rs:417:14 + --> tests/ui/cognitive_complexity.rs:435:14 | LL | async fn a() { | ^ @@ -153,7 +153,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) - --> tests/ui/cognitive_complexity.rs:425:22 + --> tests/ui/cognitive_complexity.rs:444: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 6f6e89983d2b..ed62dd7b933e 100644 --- a/tests/ui/cognitive_complexity_attr_used.rs +++ b/tests/ui/cognitive_complexity_attr_used.rs @@ -7,7 +7,8 @@ fn main() { #[clippy::cognitive_complexity = "0"] fn kaboom() { - //~^ ERROR: the function has a cognitive complexity of (3/0) +//~^ cognitive_complexity + if 42 == 43 { panic!(); } else if "cake" == "lie" { diff --git a/tests/ui/collapsible_else_if.fixed b/tests/ui/collapsible_else_if.fixed index c2d76146c641..9f530ad670a0 100644 --- a/tests/ui/collapsible_else_if.fixed +++ b/tests/ui/collapsible_else_if.fixed @@ -11,12 +11,14 @@ fn main() { } else if y == "world" { println!("world!") } + //~^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); } else if let Some(42) = Some(42) { println!("world!") } + //~^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -26,6 +28,7 @@ fn main() { else { println!("!") } + //~^^^^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -35,6 +38,7 @@ fn main() { else { println!("!") } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -44,6 +48,7 @@ fn main() { else { println!("!") } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -53,6 +58,7 @@ fn main() { else { println!("!") } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -62,6 +68,7 @@ fn main() { else { println!("!") } + //~^^^^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -77,4 +84,5 @@ fn main() { fn issue_7318() { if true { println!("I've been resolved!") }else if false {} + //~^^^ collapsible_else_if } diff --git a/tests/ui/collapsible_else_if.rs b/tests/ui/collapsible_else_if.rs index 3579e46cd447..2c646cd1d4da 100644 --- a/tests/ui/collapsible_else_if.rs +++ b/tests/ui/collapsible_else_if.rs @@ -13,6 +13,7 @@ fn main() { println!("world!") } } + //~^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -21,6 +22,7 @@ fn main() { println!("world!") } } + //~^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -32,6 +34,7 @@ fn main() { println!("!") } } + //~^^^^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -43,6 +46,7 @@ fn main() { println!("!") } } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -54,6 +58,7 @@ fn main() { println!("!") } } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -65,6 +70,7 @@ fn main() { println!("!") } } + //~^^^^^^^^ collapsible_else_if if let Some(42) = Some(42) { print!("Hello "); @@ -76,6 +82,7 @@ fn main() { println!("!") } } + //~^^^^^^^^ collapsible_else_if if x == "hello" { print!("Hello "); @@ -93,4 +100,5 @@ fn issue_7318() { }else{ if false {} } + //~^^^ collapsible_else_if } diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr deleted file mode 100644 index 45566a78bd81..000000000000 --- a/tests/ui/collapsible_else_if.stderr +++ /dev/null @@ -1,154 +0,0 @@ -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:11:12 - | -LL | } else { - | ____________^ -LL | | if y == "world" { -LL | | println!("world!") -LL | | } -LL | | } - | |_____^ - | - = note: `-D clippy::collapsible-else-if` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::collapsible_else_if)]` -help: collapse nested if block - | -LL ~ } else if y == "world" { -LL + println!("world!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:19:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world!") -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if let Some(42) = Some(42) { -LL + println!("world!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:27:12 - | -LL | } else { - | ____________^ -LL | | if y == "world" { -LL | | println!("world") -... | -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if y == "world" { -LL + println!("world") -LL + } -LL + else { -LL + println!("!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:38:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -... | -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if let Some(42) = Some(42) { -LL + println!("world") -LL + } -LL + else { -LL + println!("!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:49:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -... | -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if let Some(42) = Some(42) { -LL + println!("world") -LL + } -LL + else { -LL + println!("!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:60:12 - | -LL | } else { - | ____________^ -LL | | if x == "hello" { -LL | | println!("world") -... | -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if x == "hello" { -LL + println!("world") -LL + } -LL + else { -LL + println!("!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:71:12 - | -LL | } else { - | ____________^ -LL | | if let Some(42) = Some(42) { -LL | | println!("world") -... | -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ } else if let Some(42) = Some(42) { -LL + println!("world") -LL + } -LL + else { -LL + println!("!") -LL + } - | - -error: this `else { if .. }` block can be collapsed - --> tests/ui/collapsible_else_if.rs:93:10 - | -LL | }else{ - | __________^ -LL | | if false {} -LL | | } - | |_____^ help: collapse nested if block: `if false {}` - -error: aborting due to 8 previous errors - diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed index 44b0b6e73915..6e994018aef0 100644 --- a/tests/ui/collapsible_if.fixed +++ b/tests/ui/collapsible_if.fixed @@ -15,26 +15,32 @@ fn main() { if x == "hello" && y == "world" { println!("Hello world!"); } + //~^^^^^ collapsible_if if (x == "hello" || x == "world") && (y == "world" || y == "hello") { println!("Hello world!"); } + //~^^^^^ collapsible_if if x == "hello" && x == "world" && (y == "world" || y == "hello") { println!("Hello world!"); } + //~^^^^^ collapsible_if if (x == "hello" || x == "world") && y == "world" && y == "hello" { println!("Hello world!"); } + //~^^^^^ collapsible_if if x == "hello" && x == "world" && y == "world" && y == "hello" { println!("Hello world!"); } + //~^^^^^ collapsible_if if 42 == 1337 && 'a' != 'A' { println!("world!") } + //~^^^^^ collapsible_if // Works because any if with an else statement cannot be collapsed. if x == "hello" { @@ -89,6 +95,7 @@ fn main() { if x == "hello" && y == "world" { // Collapsible println!("Hello world!"); } + //~^^^^^ collapsible_if if x == "hello" { print!("Hello "); @@ -144,9 +151,11 @@ fn main() { // Fix #5962 if matches!(true, true) && matches!(true, true) {} + //~^^^ collapsible_if // Issue #9375 if matches!(true, true) && truth() && matches!(true, true) {} + //~^^^ collapsible_if if true { #[cfg(not(teehee))] diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index 563a273dcddd..5cf591a658c7 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -17,36 +17,42 @@ fn main() { println!("Hello world!"); } } + //~^^^^^ collapsible_if if x == "hello" || x == "world" { if y == "world" || y == "hello" { println!("Hello world!"); } } + //~^^^^^ collapsible_if if x == "hello" && x == "world" { if y == "world" || y == "hello" { println!("Hello world!"); } } + //~^^^^^ collapsible_if if x == "hello" || x == "world" { if y == "world" && y == "hello" { println!("Hello world!"); } } + //~^^^^^ collapsible_if if x == "hello" && x == "world" { if y == "world" && y == "hello" { println!("Hello world!"); } } + //~^^^^^ collapsible_if if 42 == 1337 { if 'a' != 'A' { println!("world!") } } + //~^^^^^ collapsible_if // Works because any if with an else statement cannot be collapsed. if x == "hello" { @@ -103,6 +109,7 @@ fn main() { println!("Hello world!"); } } + //~^^^^^ collapsible_if if x == "hello" { print!("Hello "); @@ -160,11 +167,13 @@ fn main() { if matches!(true, true) { if matches!(true, true) {} } + //~^^^ collapsible_if // Issue #9375 if matches!(true, true) && truth() { if matches!(true, true) {} } + //~^^^ collapsible_if if true { #[cfg(not(teehee))] diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr deleted file mode 100644 index 5bcbdf2fd08d..000000000000 --- a/tests/ui/collapsible_if.stderr +++ /dev/null @@ -1,139 +0,0 @@ -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:15:5 - | -LL | / if x == "hello" { -LL | | if y == "world" { -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | - = note: `-D clippy::collapsible-if` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` -help: collapse nested if block - | -LL ~ if x == "hello" && y == "world" { -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:21:5 - | -LL | / if x == "hello" || x == "world" { -LL | | if y == "world" || y == "hello" { -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if (x == "hello" || x == "world") && (y == "world" || y == "hello") { -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:27:5 - | -LL | / if x == "hello" && x == "world" { -LL | | if y == "world" || y == "hello" { -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if x == "hello" && x == "world" && (y == "world" || y == "hello") { -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:33:5 - | -LL | / if x == "hello" || x == "world" { -LL | | if y == "world" && y == "hello" { -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if (x == "hello" || x == "world") && y == "world" && y == "hello" { -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:39:5 - | -LL | / if x == "hello" && x == "world" { -LL | | if y == "world" && y == "hello" { -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if x == "hello" && x == "world" && y == "world" && y == "hello" { -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:45:5 - | -LL | / if 42 == 1337 { -LL | | if 'a' != 'A' { -LL | | println!("world!") -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if 42 == 1337 && 'a' != 'A' { -LL + println!("world!") -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:101:5 - | -LL | / if x == "hello" { -LL | | if y == "world" { // Collapsible -LL | | println!("Hello world!"); -LL | | } -LL | | } - | |_____^ - | -help: collapse nested if block - | -LL ~ if x == "hello" && y == "world" { // Collapsible -LL + println!("Hello world!"); -LL + } - | - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:160:5 - | -LL | / if matches!(true, true) { -LL | | if matches!(true, true) {} -LL | | } - | |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}` - -error: this `if` statement can be collapsed - --> tests/ui/collapsible_if.rs:165:5 - | -LL | / if matches!(true, true) && truth() { -LL | | if matches!(true, true) {} -LL | | } - | |_____^ help: collapse nested if block: `if matches!(true, true) && truth() && matches!(true, true) {}` - -error: aborting due to 9 previous errors - diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs index 2264b560791a..14e3ab95dbd1 100644 --- a/tests/ui/collapsible_match.rs +++ b/tests/ui/collapsible_match.rs @@ -12,7 +12,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, }, @@ -22,7 +23,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, }, @@ -32,7 +34,8 @@ 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` + //~^ collapsible_match + take(n); } } @@ -40,7 +43,8 @@ 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` + //~^ collapsible_match + take(n); } else { return; @@ -52,7 +56,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => (), } @@ -62,7 +67,8 @@ 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` + //~^ collapsible_match + take(n); } }, @@ -72,7 +78,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, } @@ -84,7 +91,8 @@ 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` + //~^ collapsible_match + take(n); } else { return; @@ -96,7 +104,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), None => return, }, @@ -106,7 +115,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, }, @@ -250,6 +260,7 @@ fn negative_cases(res_opt: Result, String>, res_res: Result>>() { Some(val) => match val { + //~^ collapsible_match E::A(val) | E::B(val) => foo(val), _ => return, }, @@ -281,7 +292,8 @@ 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` + //~^ collapsible_match + println!("{u:?}") } } @@ -290,7 +302,8 @@ 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` + //~^ collapsible_match + println!("{u}") } } diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 1da78b56239c..471e58f27770 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -4,6 +4,7 @@ error: this `match` can be collapsed into the outer `match` LL | Ok(val) => match val { | ____________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -14,43 +15,45 @@ 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` = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:24:20 + --> tests/ui/collapsible_match.rs:25:20 | LL | Ok(val) => match val { | ____________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:24:12 + --> tests/ui/collapsible_match.rs:25: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` - --> tests/ui/collapsible_match.rs:34:9 + --> tests/ui/collapsible_match.rs:36:9 | LL | / if let Some(n) = val { LL | | +LL | | LL | | take(n); LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:33:15 + --> tests/ui/collapsible_match.rs:35:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -58,10 +61,11 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:42:9 + --> tests/ui/collapsible_match.rs:45:9 | LL | / if let Some(n) = val { LL | | +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -69,7 +73,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:41:15 + --> tests/ui/collapsible_match.rs:44:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -77,17 +81,18 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:54:9 + --> tests/ui/collapsible_match.rs:58:9 | LL | / match val { LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => (), LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:53:15 + --> tests/ui/collapsible_match.rs:57:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -96,16 +101,17 @@ LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:64:13 + --> tests/ui/collapsible_match.rs:69:13 | LL | / if let Some(n) = val { LL | | +LL | | LL | | take(n); LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:63:12 + --> tests/ui/collapsible_match.rs:68:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -113,17 +119,18 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:74:9 + --> tests/ui/collapsible_match.rs:80:9 | LL | / match val { LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:73:15 + --> tests/ui/collapsible_match.rs:79:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -132,10 +139,11 @@ LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:86:13 + --> tests/ui/collapsible_match.rs:93:13 | LL | / if let Some(n) = val { LL | | +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -143,7 +151,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:85:12 + --> tests/ui/collapsible_match.rs:92:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -151,74 +159,79 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:98:20 + --> tests/ui/collapsible_match.rs:106:20 | LL | Ok(val) => match val { | ____________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | None => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:98:12 + --> tests/ui/collapsible_match.rs:106: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` - --> tests/ui/collapsible_match.rs:108:22 + --> tests/ui/collapsible_match.rs:117:22 | LL | Some(val) => match val { | ______________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:108:14 + --> tests/ui/collapsible_match.rs:117:14 | LL | Some(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` - --> tests/ui/collapsible_match.rs:252:22 + --> tests/ui/collapsible_match.rs:262:22 | LL | Some(val) => match val { | ______________________^ +LL | | LL | | E::A(val) | E::B(val) => foo(val), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:252:14 + --> tests/ui/collapsible_match.rs:262:14 | LL | Some(val) => match val { | ^^^ replace this binding +LL | LL | E::A(val) | E::B(val) => foo(val), | ^^^^^^^^^^^^^^^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:283:9 + --> tests/ui/collapsible_match.rs:294:9 | LL | / if let Some(u) = a { LL | | +LL | | LL | | println!("{u:?}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:282:27 + --> tests/ui/collapsible_match.rs:293:27 | LL | if let Issue9647::A { a, .. } = x { | ^ replace this binding @@ -226,16 +239,17 @@ LL | if let Some(u) = a { | ^^^^^^^ with this pattern, prefixed by `a`: error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:292:9 + --> tests/ui/collapsible_match.rs:304:9 | LL | / if let Some(u) = a { LL | | +LL | | LL | | println!("{u}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:291:35 + --> tests/ui/collapsible_match.rs:303: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 56801f99e454..1831fc3f0e35 100644 --- a/tests/ui/collapsible_match2.rs +++ b/tests/ui/collapsible_match2.rs @@ -11,7 +11,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, }, @@ -19,7 +20,8 @@ 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` + //~^ collapsible_match + Some(n) => foo(n), _ => return, }, @@ -34,6 +36,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> ($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => { match $outer { $pat => match $e { + //~^ collapsible_match $inner_pat => $then, _ => return, }, @@ -51,7 +54,8 @@ 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` + //~^ collapsible_match + [n] => foo(n), _ => (), }, @@ -61,7 +65,8 @@ 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` + //~^ collapsible_match + [n] => foo(n), _ => (), }, diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 13caa78fbeb5..322c583fda77 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -4,6 +4,7 @@ error: this `match` can be collapsed into the outer `match` LL | Ok(val) if make() => match val { | __________________________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -14,37 +15,39 @@ 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` = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match2.rs:21:24 + --> tests/ui/collapsible_match2.rs:22:24 | LL | Ok(val) => match val { | ________________________^ LL | | +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match2.rs:21:16 + --> tests/ui/collapsible_match2.rs:22: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` - --> tests/ui/collapsible_match2.rs:36:29 + --> tests/ui/collapsible_match2.rs:38:29 | LL | $pat => match $e { | _____________________________^ +LL | | LL | | $inner_pat => $then, LL | | _ => return, LL | | }, @@ -54,7 +57,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 - --> tests/ui/collapsible_match2.rs:48:28 + --> tests/ui/collapsible_match2.rs:51:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -63,30 +66,11 @@ 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` - --> tests/ui/collapsible_match2.rs:53:20 + --> tests/ui/collapsible_match2.rs:56: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 - --> tests/ui/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` - --> tests/ui/collapsible_match2.rs:63:24 - | -LL | Some(ref s) => match s { - | ________________________^ LL | | LL | | [n] => foo(n), LL | | _ => (), @@ -94,11 +78,32 @@ LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match2.rs:63:14 + --> tests/ui/collapsible_match2.rs:56:14 + | +LL | Some(s) => match *s { + | ^ replace this binding +... +LL | [n] => foo(n), + | ^^^ with this pattern + +error: this `match` can be collapsed into the outer `match` + --> tests/ui/collapsible_match2.rs:67:24 + | +LL | Some(ref s) => match s { + | ________________________^ +LL | | +LL | | +LL | | [n] => foo(n), +LL | | _ => (), +LL | | }, + | |_________^ + | +help: the outer pattern can be modified to include the inner pattern + --> tests/ui/collapsible_match2.rs:67:14 | LL | Some(ref s) => match s { | ^^^^^ replace this binding -LL | +... LL | [n] => foo(n), | ^^^ with this pattern diff --git a/tests/ui/collapsible_str_replace.fixed b/tests/ui/collapsible_str_replace.fixed index 03b393d5a674..e9a7384b761b 100644 --- a/tests/ui/collapsible_str_replace.fixed +++ b/tests/ui/collapsible_str_replace.fixed @@ -16,32 +16,44 @@ fn main() { // LINT CASES let _ = "hesuo worpd".replace(['s', 'u'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(['s', 'u'], l); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(['s', 'u', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd" .replace(['s', 'u', 'p', 'd'], "l"); let _ = "hesuo world".replace([s, 'u'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, 'u', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, u, 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace([s, u, p], "l"); + //~^ collapsible_str_replace let _ = "hesuo worlp".replace(['s', 'u'], "l").replace('p', "d"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "x").replace(['u', 'p'], "l"); + //~^ collapsible_str_replace // Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")` let _ = "hesudo worpd".replace("su", "l").replace(['d', 'p'], "l"); + //~^ collapsible_str_replace let _ = "hesudo worpd".replace([d, 'p'], "l").replace("su", "l"); + //~^ collapsible_str_replace let _ = "hesuo world".replace([get_filter(), 's'], "l"); + //~^ collapsible_str_replace // NO LINT CASES let _ = "hesuo world".replace('s', "l").replace('u', "p"); @@ -79,4 +91,5 @@ fn msrv_1_57() { #[clippy::msrv = "1.58"] fn msrv_1_58() { let _ = "".replace(['a', 'b'], "1.58"); + //~^ collapsible_str_replace } diff --git a/tests/ui/collapsible_str_replace.rs b/tests/ui/collapsible_str_replace.rs index 364e5493b872..4dc12c1b1c6e 100644 --- a/tests/ui/collapsible_str_replace.rs +++ b/tests/ui/collapsible_str_replace.rs @@ -16,35 +16,48 @@ fn main() { // LINT CASES let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', l).replace('u', l); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd" .replace('s', "l") + //~^ collapsible_str_replace .replace('u', "l") .replace('p', "l") .replace('d', "l"); let _ = "hesuo world".replace(s, "l").replace('u', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l"); + //~^ collapsible_str_replace let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d"); + //~^ collapsible_str_replace let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l"); + //~^ collapsible_str_replace // Note: Future iterations could lint `replace(|c| matches!(c, "su" | 'd' | 'p'), "l")` let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l"); + //~^ collapsible_str_replace let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l"); + //~^ collapsible_str_replace let _ = "hesuo world".replace(get_filter(), "l").replace('s', "l"); + //~^ collapsible_str_replace // NO LINT CASES let _ = "hesuo world".replace('s', "l").replace('u', "p"); @@ -82,4 +95,5 @@ fn msrv_1_57() { #[clippy::msrv = "1.58"] fn msrv_1_58() { let _ = "".replace('a', "1.58").replace('b', "1.58"); + //~^ collapsible_str_replace } diff --git a/tests/ui/collapsible_str_replace.stderr b/tests/ui/collapsible_str_replace.stderr index da681dffd875..a634b857dd46 100644 --- a/tests/ui/collapsible_str_replace.stderr +++ b/tests/ui/collapsible_str_replace.stderr @@ -8,83 +8,84 @@ LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); = help: to override `-D warnings` add `#[allow(clippy::collapsible_str_replace)]` error: used consecutive `str::replace` call - --> tests/ui/collapsible_str_replace.rs:20:27 + --> tests/ui/collapsible_str_replace.rs:21:27 | LL | let _ = "hesuo worpd".replace('s', l).replace('u', l); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], l)` error: used consecutive `str::replace` call - --> tests/ui/collapsible_str_replace.rs:22:27 + --> tests/ui/collapsible_str_replace.rs:24: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 - --> tests/ui/collapsible_str_replace.rs:25:10 + --> tests/ui/collapsible_str_replace.rs:28:10 | LL | .replace('s', "l") | __________^ +LL | | LL | | .replace('u', "l") LL | | .replace('p', "l") LL | | .replace('d', "l"); | |__________________________^ help: replace with: `replace(['s', 'u', 'p', 'd'], "l")` error: used consecutive `str::replace` call - --> tests/ui/collapsible_str_replace.rs:30:27 + --> tests/ui/collapsible_str_replace.rs:34:27 | LL | let _ = "hesuo world".replace(s, "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u'], "l")` error: used consecutive `str::replace` call - --> tests/ui/collapsible_str_replace.rs:32:27 + --> tests/ui/collapsible_str_replace.rs:37: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 - --> tests/ui/collapsible_str_replace.rs:34:27 + --> tests/ui/collapsible_str_replace.rs:40: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 - --> tests/ui/collapsible_str_replace.rs:36:27 + --> tests/ui/collapsible_str_replace.rs:43: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 - --> tests/ui/collapsible_str_replace.rs:38:27 + --> tests/ui/collapsible_str_replace.rs:46: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 - --> tests/ui/collapsible_str_replace.rs:40:45 + --> tests/ui/collapsible_str_replace.rs:49: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 - --> tests/ui/collapsible_str_replace.rs:43:47 + --> tests/ui/collapsible_str_replace.rs:53: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 - --> tests/ui/collapsible_str_replace.rs:45:28 + --> tests/ui/collapsible_str_replace.rs:56: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 - --> tests/ui/collapsible_str_replace.rs:47:27 + --> tests/ui/collapsible_str_replace.rs:59: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 - --> tests/ui/collapsible_str_replace.rs:84:16 + --> tests/ui/collapsible_str_replace.rs:97:16 | LL | let _ = "".replace('a', "1.58").replace('b', "1.58"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['a', 'b'], "1.58")` diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index eeb10da3402a..406b5f8f9f69 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -19,8 +19,9 @@ 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` + //~^ collection_is_never_read + + x.insert(1, 2); } @@ -60,7 +61,8 @@ fn read_in_closure() { fn write_in_closure() { let mut x = vec![1, 2, 3]; - //~^ ERROR: collection is never read + //~^ collection_is_never_read + let _ = || { x.push(4); }; @@ -76,13 +78,15 @@ fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); let mut x = HashMap::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(1, 2); } fn shadowing_2() { let mut x = HashMap::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -91,21 +95,24 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { let mut x = vec![1, 2, 3]; - //~^ ERROR: collection is never read + //~^ 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 + //~^ collection_is_never_read + x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { let mut x = vec![1, 2, 3]; - //~^ ERROR: collection is never read + //~^ collection_is_never_read + let y = vec![4, 5, 6]; // Ok x = y; } @@ -113,7 +120,8 @@ fn assignment() { #[allow(clippy::self_assignment)] fn self_assignment() { let mut x = vec![1, 2, 3]; - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x = x; } @@ -131,7 +139,8 @@ fn method_argument_but_not_target() { fn insert_is_not_a_read() { let mut x = HashSet::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(5); } @@ -146,7 +155,8 @@ 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 + //~^ collection_is_never_read + x.is_empty(); } @@ -182,44 +192,54 @@ fn function_argument() { fn supported_types() { let mut x = std::collections::BTreeMap::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(true, 1); let mut x = std::collections::BTreeSet::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(1); let mut x = std::collections::BinaryHeap::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.push(1); let mut x = std::collections::HashMap::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(1, 2); let mut x = std::collections::HashSet::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(1); let mut x = std::collections::LinkedList::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.push_front(1); let mut x = Some(true); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.insert(false); let mut x = String::from("hello"); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.push('!'); let mut x = Vec::new(); - //~^ ERROR: collection is never read + //~^ collection_is_never_read + x.clear(); x.push(1); let mut x = std::collections::VecDeque::new(); - //~^ ERROR: collection is never read + //~^ 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 f91ce07483c3..674552629f7d 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -8,115 +8,115 @@ LL | let mut x = HashMap::new(); = help: to override `-D warnings` add `#[allow(clippy::collection_is_never_read)]` error: collection is never read - --> tests/ui/collection_is_never_read.rs:62:5 + --> tests/ui/collection_is_never_read.rs:63:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:78:5 + --> tests/ui/collection_is_never_read.rs:80:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:84:5 + --> tests/ui/collection_is_never_read.rs:87:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:93:5 + --> tests/ui/collection_is_never_read.rs:97:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:100:5 + --> tests/ui/collection_is_never_read.rs:105:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:107:5 + --> tests/ui/collection_is_never_read.rs:113:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:115:5 + --> tests/ui/collection_is_never_read.rs:122:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:133:5 + --> tests/ui/collection_is_never_read.rs:141:5 | LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:148:5 + --> tests/ui/collection_is_never_read.rs:157:5 | LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:184:5 + --> tests/ui/collection_is_never_read.rs:194:5 | LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:188:5 + --> tests/ui/collection_is_never_read.rs:199:5 | LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:192:5 + --> tests/ui/collection_is_never_read.rs:204:5 | LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:196:5 + --> tests/ui/collection_is_never_read.rs:209:5 | LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:200:5 + --> tests/ui/collection_is_never_read.rs:214:5 | LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:204:5 + --> tests/ui/collection_is_never_read.rs:219:5 | LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:208:5 + --> tests/ui/collection_is_never_read.rs:224:5 | LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:212:5 + --> tests/ui/collection_is_never_read.rs:229:5 | LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:216:5 + --> tests/ui/collection_is_never_read.rs:234:5 | LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:221:5 + --> tests/ui/collection_is_never_read.rs:240:5 | LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/comparison_chain.rs b/tests/ui/comparison_chain.rs index cab460d100dd..418c88b7d5a3 100644 --- a/tests/ui/comparison_chain.rs +++ b/tests/ui/comparison_chain.rs @@ -13,7 +13,8 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if x < y { b() @@ -27,7 +28,8 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if x < y { b() @@ -36,7 +38,8 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if y > x { b() @@ -45,7 +48,8 @@ fn f(x: u8, y: u8, z: u8) { } if x > 1 { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if x < 1 { b() @@ -120,14 +124,16 @@ 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` + //~^ comparison_chain + a() } else if x < y { b() } if x > y { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if x < y { b() @@ -136,7 +142,8 @@ fn h(x: T, y: T, z: T) { } if x > y { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + a() } else if y > x { b() @@ -242,7 +249,8 @@ const fn sign_i8(n: i8) -> Sign { fn needs_parens() -> &'static str { let (x, y) = (1, 2); if x + 1 > y * 2 { - //~^ ERROR: `if` chain can be rewritten with `match` + //~^ comparison_chain + "aa" } else if x + 1 < y * 2 { "bb" diff --git a/tests/ui/comparison_chain.stderr b/tests/ui/comparison_chain.stderr index 814004e3d4b1..0256573d0d90 100644 --- a/tests/ui/comparison_chain.stderr +++ b/tests/ui/comparison_chain.stderr @@ -3,6 +3,7 @@ error: `if` chain can be rewritten with `match` | LL | / if x > y { LL | | +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -13,46 +14,47 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::comparison_chain)]` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:29:5 + --> tests/ui/comparison_chain.rs:30:5 | LL | / if x > y { LL | | +LL | | LL | | a() -LL | | } else if x < y { ... | LL | | c() LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&y) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:38:5 + --> tests/ui/comparison_chain.rs:40:5 | LL | / if x > y { LL | | +LL | | LL | | a() -LL | | } else if y > x { ... | LL | | c() LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&y) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:47:5 + --> tests/ui/comparison_chain.rs:50:5 | LL | / if x > 1 { LL | | +LL | | LL | | a() -LL | | } else if x < 1 { ... | LL | | c() LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&1) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:122:5 + --> tests/ui/comparison_chain.rs:126:5 | LL | / if x > y { LL | | +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -60,36 +62,36 @@ LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&y) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:129:5 + --> tests/ui/comparison_chain.rs:134:5 | LL | / if x > y { LL | | +LL | | LL | | a() -LL | | } else if x < y { ... | LL | | c() LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&y) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:138:5 + --> tests/ui/comparison_chain.rs:144:5 | LL | / if x > y { LL | | +LL | | LL | | a() -LL | | } else if y > x { ... | LL | | c() LL | | } | |_____^ help: consider rewriting the `if` chain with `match`: `match x.cmp(&y) {...}` error: `if` chain can be rewritten with `match` - --> tests/ui/comparison_chain.rs:244:5 + --> tests/ui/comparison_chain.rs:251:5 | LL | / if x + 1 > y * 2 { LL | | +LL | | LL | | "aa" -LL | | } else if x + 1 < y * 2 { ... | LL | | "cc" LL | | } diff --git a/tests/ui/comparison_to_empty.fixed b/tests/ui/comparison_to_empty.fixed index a2a3dd9086d4..205abe31cd86 100644 --- a/tests/ui/comparison_to_empty.fixed +++ b/tests/ui/comparison_to_empty.fixed @@ -6,17 +6,26 @@ fn main() { // Disallow comparisons to empty let s = String::new(); let _ = s.is_empty(); + //~^ comparison_to_empty let _ = !s.is_empty(); + //~^ comparison_to_empty let v = vec![0]; let _ = v.is_empty(); + //~^ comparison_to_empty let _ = !v.is_empty(); + //~^ comparison_to_empty if (*v).is_empty() {} + //~^ comparison_to_empty let s = [0].as_slice(); if s.is_empty() {} + //~^ comparison_to_empty if s.is_empty() {} + //~^ comparison_to_empty if s.is_empty() + //~^ comparison_to_empty && s.is_empty() + //~^ comparison_to_empty {} // Allow comparisons to non-empty @@ -37,8 +46,12 @@ fn main() { // Also lint the `PartialEq` methods let s = String::new(); let _ = s.is_empty(); + //~^ comparison_to_empty let _ = !s.is_empty(); + //~^ comparison_to_empty let v = vec![0]; let _ = v.is_empty(); + //~^ comparison_to_empty let _ = !v.is_empty(); + //~^ comparison_to_empty } diff --git a/tests/ui/comparison_to_empty.rs b/tests/ui/comparison_to_empty.rs index 7c5689a4bbec..4da6327050a8 100644 --- a/tests/ui/comparison_to_empty.rs +++ b/tests/ui/comparison_to_empty.rs @@ -6,17 +6,26 @@ fn main() { // Disallow comparisons to empty let s = String::new(); let _ = s == ""; + //~^ comparison_to_empty let _ = s != ""; + //~^ comparison_to_empty let v = vec![0]; let _ = v == []; + //~^ comparison_to_empty let _ = v != []; + //~^ comparison_to_empty if let [] = &*v {} + //~^ comparison_to_empty let s = [0].as_slice(); if let [] = s {} + //~^ comparison_to_empty if let [] = &*s {} + //~^ comparison_to_empty if let [] = &*s + //~^ comparison_to_empty && s == [] + //~^ comparison_to_empty {} // Allow comparisons to non-empty @@ -37,8 +46,12 @@ fn main() { // Also lint the `PartialEq` methods let s = String::new(); let _ = s.eq(""); + //~^ comparison_to_empty let _ = s.ne(""); + //~^ comparison_to_empty let v = vec![0]; let _ = v.eq(&[]); + //~^ comparison_to_empty let _ = v.ne(&[]); + //~^ comparison_to_empty } diff --git a/tests/ui/comparison_to_empty.stderr b/tests/ui/comparison_to_empty.stderr index 2ee0efc7dbb1..00a50430a3ee 100644 --- a/tests/ui/comparison_to_empty.stderr +++ b/tests/ui/comparison_to_empty.stderr @@ -8,73 +8,73 @@ LL | let _ = s == ""; = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:9:13 + --> tests/ui/comparison_to_empty.rs:10:13 | LL | let _ = s != ""; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:12:13 + --> tests/ui/comparison_to_empty.rs:14:13 | LL | let _ = v == []; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:13:13 + --> tests/ui/comparison_to_empty.rs:16:13 | LL | let _ = v != []; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()` error: comparison to empty slice using `if let` - --> tests/ui/comparison_to_empty.rs:14:8 + --> tests/ui/comparison_to_empty.rs:18: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` - --> tests/ui/comparison_to_empty.rs:16:8 + --> tests/ui/comparison_to_empty.rs:21: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` - --> tests/ui/comparison_to_empty.rs:17:8 + --> tests/ui/comparison_to_empty.rs:23: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` - --> tests/ui/comparison_to_empty.rs:18:8 + --> tests/ui/comparison_to_empty.rs:25:8 | LL | if let [] = &*s | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:19:12 + --> tests/ui/comparison_to_empty.rs:27:12 | LL | && s == [] | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:39:13 + --> tests/ui/comparison_to_empty.rs:48:13 | LL | let _ = s.eq(""); | ^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:40:13 + --> tests/ui/comparison_to_empty.rs:50:13 | LL | let _ = s.ne(""); | ^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:42:13 + --> tests/ui/comparison_to_empty.rs:53:13 | LL | let _ = v.eq(&[]); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()` error: comparison to empty slice - --> tests/ui/comparison_to_empty.rs:43:13 + --> tests/ui/comparison_to_empty.rs:55:13 | LL | let _ = v.ne(&[]); | ^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()` diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index 0898b4ebd465..0df4b8eb356e 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -43,42 +43,53 @@ fn main() { // 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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` + //~^ impossible_comparisons + + // 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + // 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + // Yoda conditions // Correct @@ -87,12 +98,14 @@ fn main() { 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 + //~^ impossible_comparisons + + // 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 + //~^ impossible_comparisons + + // Yoda conditions, comparing two different types // Correct @@ -101,50 +114,62 @@ fn main() { 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 + //~^ impossible_comparisons + + // 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 + //~^ impossible_comparisons + + // Expressions where one of the sides has no effect status_code < 200 && status_code <= 299; - //~^ ERROR: right-hand side of `&&` operator has no effect + //~^ redundant_comparisons + status_code > 200 && status_code >= 299; - //~^ ERROR: left-hand side of `&&` operator has no effect + //~^ redundant_comparisons + // Useless left status_code >= 500 && status_code > 500; - //~^ ERROR: left-hand side of `&&` operator has no effect + //~^ redundant_comparisons + // Useless right status_code > 500 && status_code >= 500; - //~^ ERROR: right-hand side of `&&` operator has no effect + //~^ redundant_comparisons + // Useless left status_code <= 500 && status_code < 500; - //~^ ERROR: left-hand side of `&&` operator has no effect + //~^ redundant_comparisons + // Useless right status_code < 500 && status_code <= 500; - //~^ ERROR: right-hand side of `&&` operator has no effect + //~^ redundant_comparisons + // 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + 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 + //~^ impossible_comparisons + + } diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index 1b8fd9733fae..2f3f5c9523e3 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -9,7 +9,7 @@ LL | status_code <= 400 && status_code > 500; = help: to override `-D warnings` add `#[allow(clippy::impossible_comparisons)]` error: boolean expression will never evaluate to 'true' - --> tests/ui/const_comparisons.rs:48:5 + --> tests/ui/const_comparisons.rs:49:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,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' - --> tests/ui/const_comparisons.rs:51:5 + --> tests/ui/const_comparisons.rs:53:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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' - --> tests/ui/const_comparisons.rs:56:5 + --> tests/ui/const_comparisons.rs:59:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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' - --> tests/ui/const_comparisons.rs:59:5 + --> tests/ui/const_comparisons.rs:63:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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' - --> tests/ui/const_comparisons.rs:62:5 + --> tests/ui/const_comparisons.rs:67:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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' - --> tests/ui/const_comparisons.rs:65:5 + --> tests/ui/const_comparisons.rs:71:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,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' - --> tests/ui/const_comparisons.rs:70:5 + --> tests/ui/const_comparisons.rs:77:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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' - --> tests/ui/const_comparisons.rs:73:5 + --> tests/ui/const_comparisons.rs:81:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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' - --> tests/ui/const_comparisons.rs:76:5 + --> tests/ui/const_comparisons.rs:85:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,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' - --> tests/ui/const_comparisons.rs:79:5 + --> tests/ui/const_comparisons.rs:89:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,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' - --> tests/ui/const_comparisons.rs:89:5 + --> tests/ui/const_comparisons.rs:100:5 | LL | 500 >= status_code && 600 < status_code; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ 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' - --> tests/ui/const_comparisons.rs:93:5 + --> tests/ui/const_comparisons.rs:105:5 | LL | 500 >= status_code && status_code > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ 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' - --> tests/ui/const_comparisons.rs:103:5 + --> tests/ui/const_comparisons.rs:116:5 | LL | 500 >= status && 600 < status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ 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' - --> tests/ui/const_comparisons.rs:107:5 + --> tests/ui/const_comparisons.rs:121:5 | LL | 500 >= status && status > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,13 +121,13 @@ 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 - --> tests/ui/const_comparisons.rs:112:5 + --> tests/ui/const_comparisons.rs:127: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 - --> tests/ui/const_comparisons.rs:112:23 + --> tests/ui/const_comparisons.rs:127:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ @@ -135,67 +135,67 @@ LL | status_code < 200 && status_code <= 299; = help: to override `-D warnings` add `#[allow(clippy::redundant_comparisons)]` error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:114:5 + --> tests/ui/const_comparisons.rs:130: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 - --> tests/ui/const_comparisons.rs:114:5 + --> tests/ui/const_comparisons.rs:130:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:118:5 + --> tests/ui/const_comparisons.rs:135:5 | 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 - --> tests/ui/const_comparisons.rs:118:5 + --> tests/ui/const_comparisons.rs:135:5 | LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:121:5 + --> tests/ui/const_comparisons.rs:139:5 | 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 - --> tests/ui/const_comparisons.rs:121:23 + --> tests/ui/const_comparisons.rs:139:23 | LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:124:5 + --> tests/ui/const_comparisons.rs:143:5 | 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 - --> tests/ui/const_comparisons.rs:124:5 + --> tests/ui/const_comparisons.rs:143:5 | LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:127:5 + --> tests/ui/const_comparisons.rs:147:5 | 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 - --> tests/ui/const_comparisons.rs:127:23 + --> tests/ui/const_comparisons.rs:147:23 | LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> tests/ui/const_comparisons.rs:132:5 + --> tests/ui/const_comparisons.rs:153:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,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' - --> tests/ui/const_comparisons.rs:137:5 + --> tests/ui/const_comparisons.rs:159:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -211,7 +211,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' - --> tests/ui/const_comparisons.rs:142:5 + --> tests/ui/const_comparisons.rs:165:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,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' - --> tests/ui/const_comparisons.rs:147:5 + --> tests/ui/const_comparisons.rs:171:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const_is_empty.rs b/tests/ui/const_is_empty.rs index b5e27b61548a..29891ae4c0e5 100644 --- a/tests/ui/const_is_empty.rs +++ b/tests/ui/const_is_empty.rs @@ -3,19 +3,23 @@ fn test_literal() { if "".is_empty() { - //~^ERROR: this expression always evaluates to true + //~^ const_is_empty + } if "foobar".is_empty() { - //~^ERROR: this expression always evaluates to false + //~^ const_is_empty + } } fn test_byte_literal() { if b"".is_empty() { - //~^ERROR: this expression always evaluates to true + //~^ const_is_empty + } if b"foobar".is_empty() { - //~^ERROR: this expression always evaluates to false + //~^ const_is_empty + } } @@ -32,10 +36,12 @@ fn test_propagated() { let empty2 = empty; let non_empty2 = non_empty; if empty2.is_empty() { - //~^ERROR: this expression always evaluates to true + //~^ const_is_empty + } if non_empty2.is_empty() { - //~^ERROR: this expression always evaluates to false + //~^ const_is_empty + } } @@ -57,48 +63,67 @@ const NON_EMPTY_REF_ARRAY: &[u32; 3] = &[1, 2, 3]; fn test_from_const() { let _ = EMPTY_STR.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = NON_EMPTY_STR.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = EMPTY_BSTR.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = NON_EMPTY_BSTR.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = EMPTY_ARRAY.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = EMPTY_ARRAY_REPEAT.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = EMPTY_U8_SLICE.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = NON_EMPTY_U8_SLICE.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = NON_EMPTY_ARRAY.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = EMPTY_REF_ARRAY.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = NON_EMPTY_REF_ARRAY.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = EMPTY_SLICE.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = NON_EMPTY_SLICE.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + } fn main() { let value = "foobar"; let _ = value.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let x = value; let _ = x.is_empty(); - //~^ ERROR: this expression always evaluates to false + //~^ const_is_empty + let _ = "".is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + let _ = b"".is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + } fn str_from_arg(var: &str) { @@ -152,7 +177,8 @@ fn not_cfg_conditioned() { let val = ""; #[cfg(not(target_os = "inexistent"))] let _ = val.is_empty(); - //~^ ERROR: this expression always evaluates to true + //~^ const_is_empty + } const fn const_rand() -> &'static str { @@ -183,5 +209,6 @@ fn issue_13106() { const { EMPTY_STR.is_empty(); + //~^ const_is_empty } } diff --git a/tests/ui/const_is_empty.stderr b/tests/ui/const_is_empty.stderr index 0afba940d8b4..9557ad18dfc8 100644 --- a/tests/ui/const_is_empty.stderr +++ b/tests/ui/const_is_empty.stderr @@ -8,157 +8,157 @@ LL | if "".is_empty() { = help: to override `-D warnings` add `#[allow(clippy::const_is_empty)]` error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:8:8 + --> tests/ui/const_is_empty.rs:9:8 | LL | if "foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:14:8 + --> tests/ui/const_is_empty.rs:16:8 | LL | if b"".is_empty() { | ^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:17:8 + --> tests/ui/const_is_empty.rs:20:8 | LL | if b"foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:34:8 + --> tests/ui/const_is_empty.rs:38:8 | LL | if empty2.is_empty() { | ^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:37:8 + --> tests/ui/const_is_empty.rs:42:8 | LL | if non_empty2.is_empty() { | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:59:13 + --> tests/ui/const_is_empty.rs:65:13 | LL | let _ = EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:61:13 + --> tests/ui/const_is_empty.rs:68:13 | LL | let _ = NON_EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:63:13 + --> tests/ui/const_is_empty.rs:71:13 | LL | let _ = EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:65:13 + --> tests/ui/const_is_empty.rs:74:13 | LL | let _ = NON_EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:67:13 + --> tests/ui/const_is_empty.rs:77:13 | LL | let _ = EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:69:13 + --> tests/ui/const_is_empty.rs:80:13 | LL | let _ = EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:71:13 + --> tests/ui/const_is_empty.rs:83:13 | LL | let _ = EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:73:13 + --> tests/ui/const_is_empty.rs:86:13 | LL | let _ = NON_EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:75:13 + --> tests/ui/const_is_empty.rs:89:13 | LL | let _ = NON_EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:77:13 + --> tests/ui/const_is_empty.rs:92:13 | LL | let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:79:13 + --> tests/ui/const_is_empty.rs:95:13 | LL | let _ = EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:81:13 + --> tests/ui/const_is_empty.rs:98:13 | LL | let _ = NON_EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:83:13 + --> tests/ui/const_is_empty.rs:101:13 | LL | let _ = EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:85:13 + --> tests/ui/const_is_empty.rs:104:13 | LL | let _ = NON_EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:87:13 + --> tests/ui/const_is_empty.rs:107:13 | LL | let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:93:13 + --> tests/ui/const_is_empty.rs:114:13 | LL | let _ = value.is_empty(); | ^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:96:13 + --> tests/ui/const_is_empty.rs:118:13 | LL | let _ = x.is_empty(); | ^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:98:13 + --> tests/ui/const_is_empty.rs:121:13 | LL | let _ = "".is_empty(); | ^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:100:13 + --> tests/ui/const_is_empty.rs:124:13 | LL | let _ = b"".is_empty(); | ^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:154:13 + --> tests/ui/const_is_empty.rs:179:13 | LL | let _ = val.is_empty(); | ^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:185:9 + --> tests/ui/const_is_empty.rs:211:9 | LL | EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/copy_iterator.rs b/tests/ui/copy_iterator.rs index ea3a4face93f..f048f7541bc6 100644 --- a/tests/ui/copy_iterator.rs +++ b/tests/ui/copy_iterator.rs @@ -5,8 +5,9 @@ struct Countdown(u8); impl Iterator for Countdown { - //~^ ERROR: you are implementing `Iterator` on a `Copy` type - //~| NOTE: consider implementing `IntoIterator` instead +//~^ copy_iterator + + type Item = u8; fn next(&mut self) -> Option { diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 2f6378a85fee..86fd326c36c5 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -2,9 +2,6 @@ error: you are implementing `Iterator` on a `Copy` type --> tests/ui/copy_iterator.rs:7:1 | LL | / impl Iterator for Countdown { -LL | | -LL | | -LL | | type Item = u8; ... | LL | | } | |_^ diff --git a/tests/ui/crashes/associated-constant-ice.rs b/tests/ui/crashes/associated-constant-ice.rs index fec16671eeb3..c5767cd656e9 100644 --- a/tests/ui/crashes/associated-constant-ice.rs +++ b/tests/ui/crashes/associated-constant-ice.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/1698 pub trait Trait { diff --git a/tests/ui/crashes/cc_seme.rs b/tests/ui/crashes/cc_seme.rs index 98897d6d7aaf..1d8e635ffe44 100644 --- a/tests/ui/crashes/cc_seme.rs +++ b/tests/ui/crashes/cc_seme.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/478 enum Baz { diff --git a/tests/ui/crashes/enum-glob-import-crate.rs b/tests/ui/crashes/enum-glob-import-crate.rs index dca32aa3b561..bbcd599f6d0b 100644 --- a/tests/ui/crashes/enum-glob-import-crate.rs +++ b/tests/ui/crashes/enum-glob-import-crate.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::all)] #![allow(unused_imports)] diff --git a/tests/ui/crashes/ice-10148.rs b/tests/ui/crashes/ice-10148.rs index d89d94edbcdb..8baaccd811d7 100644 --- a/tests/ui/crashes/ice-10148.rs +++ b/tests/ui/crashes/ice-10148.rs @@ -6,4 +6,5 @@ use proc_macros::with_span; fn main() { println!(with_span!(""something "")); + //~^ println_empty_string } diff --git a/tests/ui/crashes/ice-10508a.rs b/tests/ui/crashes/ice-10508a.rs index f45057217b43..43da01344555 100644 --- a/tests/ui/crashes/ice-10508a.rs +++ b/tests/ui/crashes/ice-10508a.rs @@ -1,3 +1,4 @@ +//@ check-pass // Used to overflow in `is_normalizable` use std::marker::PhantomData; diff --git a/tests/ui/crashes/ice-10508b.rs b/tests/ui/crashes/ice-10508b.rs index 41d4f0234b94..7588419381cf 100644 --- a/tests/ui/crashes/ice-10508b.rs +++ b/tests/ui/crashes/ice-10508b.rs @@ -1,3 +1,5 @@ +//@ check-pass + use std::marker::PhantomData; struct Digit { diff --git a/tests/ui/crashes/ice-10508c.rs b/tests/ui/crashes/ice-10508c.rs index fb84d85fd675..d207fdb2c87a 100644 --- a/tests/ui/crashes/ice-10508c.rs +++ b/tests/ui/crashes/ice-10508c.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[derive(Debug)] struct S { t: T, diff --git a/tests/ui/crashes/ice-10972-tait.rs b/tests/ui/crashes/ice-10972-tait.rs index f3ab9cebb7c2..11ddbfc3a04b 100644 --- a/tests/ui/crashes/ice-10972-tait.rs +++ b/tests/ui/crashes/ice-10972-tait.rs @@ -1,3 +1,4 @@ +//@ check-pass // ICE: #10972 // asked to assemble constituent types of unexpected type: Binder(Foo, []) #![feature(type_alias_impl_trait)] diff --git a/tests/ui/crashes/ice-11065.rs b/tests/ui/crashes/ice-11065.rs index a17d7e38e0c3..434f11a2c577 100644 --- a/tests/ui/crashes/ice-11065.rs +++ b/tests/ui/crashes/ice-11065.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::useless_conversion)] use std::option::IntoIter as OptionIter; diff --git a/tests/ui/crashes/ice-11230.fixed b/tests/ui/crashes/ice-11230.fixed index 1d4c3dd9dcc4..181e1ebbe5a3 100644 --- a/tests/ui/crashes/ice-11230.fixed +++ b/tests/ui/crashes/ice-11230.fixed @@ -6,6 +6,7 @@ fn main() { const A: &[for<'a> fn(&'a ())] = &[]; for v in A {} + //~^ explicit_iter_loop } // needless_collect @@ -13,4 +14,5 @@ trait Helper<'a>: Iterator {} fn x(w: &mut dyn for<'a> Helper<'a>) { w.next().is_none(); + //~^ needless_collect } diff --git a/tests/ui/crashes/ice-11230.rs b/tests/ui/crashes/ice-11230.rs index a16fb271497c..fb05dc781bc0 100644 --- a/tests/ui/crashes/ice-11230.rs +++ b/tests/ui/crashes/ice-11230.rs @@ -6,6 +6,7 @@ fn main() { const A: &[for<'a> fn(&'a ())] = &[]; for v in A.iter() {} + //~^ explicit_iter_loop } // needless_collect @@ -13,4 +14,5 @@ trait Helper<'a>: Iterator {} fn x(w: &mut dyn for<'a> Helper<'a>) { w.collect::>().is_empty(); + //~^ needless_collect } diff --git a/tests/ui/crashes/ice-11230.stderr b/tests/ui/crashes/ice-11230.stderr index 7167d90e456e..b4a3f67081ae 100644 --- a/tests/ui/crashes/ice-11230.stderr +++ b/tests/ui/crashes/ice-11230.stderr @@ -8,7 +8,7 @@ LL | for v in A.iter() {} = help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]` error: avoid using `collect()` when not needed - --> tests/ui/crashes/ice-11230.rs:15:7 + --> tests/ui/crashes/ice-11230.rs:16:7 | LL | w.collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` diff --git a/tests/ui/crashes/ice-11337.rs b/tests/ui/crashes/ice-11337.rs index 0bed4035f6bf..317b7a7083a6 100644 --- a/tests/ui/crashes/ice-11337.rs +++ b/tests/ui/crashes/ice-11337.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(trait_alias)] trait Confusing = Fn(i32) where F: Fn(u32); diff --git a/tests/ui/crashes/ice-11422.fixed b/tests/ui/crashes/ice-11422.fixed index d996b1db08a6..be07a9d8c1f9 100644 --- a/tests/ui/crashes/ice-11422.fixed +++ b/tests/ui/crashes/ice-11422.fixed @@ -4,6 +4,7 @@ use std::fmt::Debug; use std::ops::*; fn r#gen() -> impl PartialOrd + Debug {} +//~^ implied_bounds_in_impls struct Bar {} trait Foo {} diff --git a/tests/ui/crashes/ice-11422.rs b/tests/ui/crashes/ice-11422.rs index eb89b7c38f43..43de882caa11 100644 --- a/tests/ui/crashes/ice-11422.rs +++ b/tests/ui/crashes/ice-11422.rs @@ -4,6 +4,7 @@ use std::fmt::Debug; use std::ops::*; fn r#gen() -> impl PartialOrd + PartialEq + Debug {} +//~^ implied_bounds_in_impls struct Bar {} trait Foo {} diff --git a/tests/ui/crashes/ice-11755.rs b/tests/ui/crashes/ice-11755.rs index 367cb6998578..d6aa1e5183d2 100644 --- a/tests/ui/crashes/ice-11755.rs +++ b/tests/ui/crashes/ice-11755.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::unused_enumerate_index)] fn main() { diff --git a/tests/ui/crashes/ice-11803.rs b/tests/ui/crashes/ice-11803.rs index 1bb8bf0c746b..aced75b3ad12 100644 --- a/tests/ui/crashes/ice-11803.rs +++ b/tests/ui/crashes/ice-11803.rs @@ -3,6 +3,8 @@ #![warn(clippy::impl_trait_in_params)] pub fn g>>() { +//~^ impl_trait_in_params +//~| impl_trait_in_params extern "C" fn implementation_detail() {} } diff --git a/tests/ui/crashes/ice-11939.rs b/tests/ui/crashes/ice-11939.rs index 5e7193b68264..ce7a0de1ac3a 100644 --- a/tests/ui/crashes/ice-11939.rs +++ b/tests/ui/crashes/ice-11939.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::unit_arg, clippy::no_effect)] const fn v(_: ()) {} diff --git a/tests/ui/crashes/ice-12253.rs b/tests/ui/crashes/ice-12253.rs index 41f50035144a..58ad7c3bfbf5 100644 --- a/tests/ui/crashes/ice-12253.rs +++ b/tests/ui/crashes/ice-12253.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[allow(overflowing_literals, unconditional_panic, clippy::no_effect)] fn main() { let arr: [i32; 5] = [0; 5]; diff --git a/tests/ui/crashes/ice-12491.fixed b/tests/ui/crashes/ice-12491.fixed index 4ea480b0663c..ab9c61463e92 100644 --- a/tests/ui/crashes/ice-12491.fixed +++ b/tests/ui/crashes/ice-12491.fixed @@ -3,5 +3,6 @@ fn main() { if (true) { // anything一些中文 + //~^^ needless_return } } diff --git a/tests/ui/crashes/ice-12491.rs b/tests/ui/crashes/ice-12491.rs index 60add6afa2c4..b774bd3788a7 100644 --- a/tests/ui/crashes/ice-12491.rs +++ b/tests/ui/crashes/ice-12491.rs @@ -4,5 +4,6 @@ fn main() { if (true) { // anything一些中文 return; + //~^^ needless_return } } diff --git a/tests/ui/crashes/ice-12585.rs b/tests/ui/crashes/ice-12585.rs index 7928115c0a94..f35e95c6bc34 100644 --- a/tests/ui/crashes/ice-12585.rs +++ b/tests/ui/crashes/ice-12585.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::unit_arg)] struct One { diff --git a/tests/ui/crashes/ice-12616.fixed b/tests/ui/crashes/ice-12616.fixed index a5a5b3d1e78e..b7840cabc6b4 100644 --- a/tests/ui/crashes/ice-12616.fixed +++ b/tests/ui/crashes/ice-12616.fixed @@ -4,4 +4,5 @@ fn main() { let s = std::ptr::null::<()>; s().cast::<()>(); + //~^ ptr_as_ptr } diff --git a/tests/ui/crashes/ice-12616.rs b/tests/ui/crashes/ice-12616.rs index 6ee9a5ec08fe..bb37b2e6a679 100644 --- a/tests/ui/crashes/ice-12616.rs +++ b/tests/ui/crashes/ice-12616.rs @@ -4,4 +4,5 @@ fn main() { let s = std::ptr::null::<()>; s() as *const (); + //~^ ptr_as_ptr } diff --git a/tests/ui/crashes/ice-13862.rs b/tests/ui/crashes/ice-13862.rs index a5f010054b2f..774774e6245b 100644 --- a/tests/ui/crashes/ice-13862.rs +++ b/tests/ui/crashes/ice-13862.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![crate_type = "lib"] #![no_std] diff --git a/tests/ui/crashes/ice-1588.rs b/tests/ui/crashes/ice-1588.rs index 9ec093721c17..3ccd33052cd6 100644 --- a/tests/ui/crashes/ice-1588.rs +++ b/tests/ui/crashes/ice-1588.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::all)] // Test for https://github.com/rust-lang/rust-clippy/issues/1588 diff --git a/tests/ui/crashes/ice-1782.rs b/tests/ui/crashes/ice-1782.rs index 73de5721cbc1..fefdc405cce2 100644 --- a/tests/ui/crashes/ice-1782.rs +++ b/tests/ui/crashes/ice-1782.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code, unused_variables)] #![allow(clippy::unnecessary_cast, clippy::missing_transmute_annotations)] diff --git a/tests/ui/crashes/ice-1969.rs b/tests/ui/crashes/ice-1969.rs index eb901c767294..34ff725d7117 100644 --- a/tests/ui/crashes/ice-1969.rs +++ b/tests/ui/crashes/ice-1969.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::all)] // Test for https://github.com/rust-lang/rust-clippy/issues/1969 diff --git a/tests/ui/crashes/ice-2499.rs b/tests/ui/crashes/ice-2499.rs index 732f331ad145..685c28ff4d6a 100644 --- a/tests/ui/crashes/ice-2499.rs +++ b/tests/ui/crashes/ice-2499.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code, clippy::char_lit_as_u8, clippy::needless_bool)] // Should not trigger an ICE in `SpanlessHash` / `consts::constant` diff --git a/tests/ui/crashes/ice-2594.rs b/tests/ui/crashes/ice-2594.rs index dddf860bd178..d4d9e74cc193 100644 --- a/tests/ui/crashes/ice-2594.rs +++ b/tests/ui/crashes/ice-2594.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code, unused_variables)] /// Should not trigger an ICE in `SpanlessHash` / `consts::constant` diff --git a/tests/ui/crashes/ice-2727.rs b/tests/ui/crashes/ice-2727.rs index 59fb9b04b86d..92287459424f 100644 --- a/tests/ui/crashes/ice-2727.rs +++ b/tests/ui/crashes/ice-2727.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/2727 pub fn f(new: fn()) { diff --git a/tests/ui/crashes/ice-2760.rs b/tests/ui/crashes/ice-2760.rs index 5f7d91abf995..188d90fcae22 100644 --- a/tests/ui/crashes/ice-2760.rs +++ b/tests/ui/crashes/ice-2760.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow( unused_variables, clippy::disallowed_names, diff --git a/tests/ui/crashes/ice-2774.fixed b/tests/ui/crashes/ice-2774.fixed index 96cf0d8540cd..d096584fa75c 100644 --- a/tests/ui/crashes/ice-2774.fixed +++ b/tests/ui/crashes/ice-2774.fixed @@ -13,8 +13,9 @@ 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` +//~^ needless_lifetimes + + 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 464d7891c9f4..83fb7be626df 100644 --- a/tests/ui/crashes/ice-2774.rs +++ b/tests/ui/crashes/ice-2774.rs @@ -13,8 +13,9 @@ 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` +//~^ needless_lifetimes + + let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/tests/ui/crashes/ice-2862.rs b/tests/ui/crashes/ice-2862.rs index 2573b571f55c..e27bdba04e80 100644 --- a/tests/ui/crashes/ice-2862.rs +++ b/tests/ui/crashes/ice-2862.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/2862 pub trait FooMap { diff --git a/tests/ui/crashes/ice-2865.rs b/tests/ui/crashes/ice-2865.rs index 28363707acca..681d10a75014 100644 --- a/tests/ui/crashes/ice-2865.rs +++ b/tests/ui/crashes/ice-2865.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code, clippy::extra_unused_lifetimes)] // Test for https://github.com/rust-lang/rust-clippy/issues/2865 diff --git a/tests/ui/crashes/ice-3151.rs b/tests/ui/crashes/ice-3151.rs index f88a26cb4859..f0c57d2f19f4 100644 --- a/tests/ui/crashes/ice-3151.rs +++ b/tests/ui/crashes/ice-3151.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/3151 #[derive(Clone)] diff --git a/tests/ui/crashes/ice-3462.rs b/tests/ui/crashes/ice-3462.rs index ccd617e305da..4ce484917ae2 100644 --- a/tests/ui/crashes/ice-3462.rs +++ b/tests/ui/crashes/ice-3462.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::all)] #![allow(clippy::disallowed_names, clippy::equatable_if_let, clippy::needless_if)] #![allow(unused)] diff --git a/tests/ui/crashes/ice-360.rs b/tests/ui/crashes/ice-360.rs index 0d10932b0987..43becad3183f 100644 --- a/tests/ui/crashes/ice-360.rs +++ b/tests/ui/crashes/ice-360.rs @@ -3,14 +3,17 @@ fn main() {} fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { - //~^ ERROR: this loop never actually loops - //~| ERROR: this loop could be written as a `while let` loop - //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` + //~^ never_loop + //~| while_let_loop + + + let _ = match iter.next() { Some(ele) => ele, None => break, }; loop {} - //~^ ERROR: empty `loop {}` wastes CPU cycles + //~^ empty_loop + } } diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index 9961eb21485d..e4bd436abc54 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -20,7 +20,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: empty `loop {}` wastes CPU cycles - --> tests/ui/crashes/ice-360.rs:13:9 + --> tests/ui/crashes/ice-360.rs:15:9 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/crashes/ice-3717.fixed b/tests/ui/crashes/ice-3717.fixed index 3f54b326979c..0d7c38f95217 100644 --- a/tests/ui/crashes/ice-3717.fixed +++ b/tests/ui/crashes/ice-3717.fixed @@ -5,7 +5,8 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { - //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers +//~^ implicit_hasher + let _ = [0u8; 0]; let _: HashSet = HashSet::default(); } diff --git a/tests/ui/crashes/ice-3717.rs b/tests/ui/crashes/ice-3717.rs index 2890a9277c71..7c286abf32b0 100644 --- a/tests/ui/crashes/ice-3717.rs +++ b/tests/ui/crashes/ice-3717.rs @@ -5,7 +5,8 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { - //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers +//~^ implicit_hasher + let _ = [0u8; 0]; let _: HashSet = HashSet::new(); } diff --git a/tests/ui/crashes/ice-3717.stderr b/tests/ui/crashes/ice-3717.stderr index aac72c669654..2e53b610922e 100644 --- a/tests/ui/crashes/ice-3717.stderr +++ b/tests/ui/crashes/ice-3717.stderr @@ -13,6 +13,7 @@ help: add a type parameter for `BuildHasher` | LL ~ pub fn ice_3717(_: &HashSet) { LL | +LL | LL | let _ = [0u8; 0]; LL ~ let _: HashSet = HashSet::default(); | diff --git a/tests/ui/crashes/ice-3741.rs b/tests/ui/crashes/ice-3741.rs index 3106a2e72169..d8c02b1ba452 100644 --- a/tests/ui/crashes/ice-3741.rs +++ b/tests/ui/crashes/ice-3741.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:proc_macro_crash.rs #![warn(clippy::suspicious_else_formatting)] diff --git a/tests/ui/crashes/ice-3747.rs b/tests/ui/crashes/ice-3747.rs index 44b1d7ed1b2e..62c7835ac55c 100644 --- a/tests/ui/crashes/ice-3747.rs +++ b/tests/ui/crashes/ice-3747.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/3747 macro_rules! a { diff --git a/tests/ui/crashes/ice-3969.rs b/tests/ui/crashes/ice-3969.rs index ac09ce08753a..1db7f0ad8b5b 100644 --- a/tests/ui/crashes/ice-3969.rs +++ b/tests/ui/crashes/ice-3969.rs @@ -18,13 +18,12 @@ struct Dst { struct TwoStrs(str, str) where str: Sized; -//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetime -//~| NOTE: `-D trivial-bounds` implied by `-D warnings` +//~^ ERROR: trait bound fn unsized_local() where for<'a> Dst: Sized, - //~^ ERROR: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend +//~^ ERROR: trait bound { let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); } @@ -32,7 +31,7 @@ where fn return_str() -> str where str: Sized, - //~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim +//~^ ERROR: trait bound { *"Sized".to_string().into_boxed_str() } @@ -40,7 +39,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 +//~^ ERROR: trait bound { -s } @@ -48,7 +47,7 @@ where fn use_for() where i32: Iterator, - //~^ ERROR: trait bound i32: std::iter::Iterator does not depend on any type or lifeti +//~^ ERROR: trait bound { for _ in 2i32 {} } diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index 285efee36bd8..b820ecf7e332 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -8,25 +8,25 @@ LL | str: Sized; = help: to override `-D warnings` add `#[allow(trivial_bounds)]` error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters - --> tests/ui/crashes/ice-3969.rs:26:30 + --> tests/ui/crashes/ice-3969.rs:25:30 | LL | for<'a> Dst: Sized, | ^^^^^ error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters - --> tests/ui/crashes/ice-3969.rs:34:10 + --> tests/ui/crashes/ice-3969.rs:33:10 | LL | str: Sized, | ^^^^^ error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters - --> tests/ui/crashes/ice-3969.rs:42:13 + --> tests/ui/crashes/ice-3969.rs:41:13 | LL | String: ::std::ops::Neg, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters - --> tests/ui/crashes/ice-3969.rs:50:10 + --> tests/ui/crashes/ice-3969.rs:49:10 | LL | i32: Iterator, | ^^^^^^^^ diff --git a/tests/ui/crashes/ice-4121.rs b/tests/ui/crashes/ice-4121.rs index e1a142fdcb67..a1192b229ecd 100644 --- a/tests/ui/crashes/ice-4121.rs +++ b/tests/ui/crashes/ice-4121.rs @@ -1,3 +1,5 @@ +//@ check-pass + use std::mem; pub struct Foo(A, B); diff --git a/tests/ui/crashes/ice-4545.rs b/tests/ui/crashes/ice-4545.rs index d9c9c2096d97..1d7cb53ee7be 100644 --- a/tests/ui/crashes/ice-4545.rs +++ b/tests/ui/crashes/ice-4545.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn repro() { trait Foo { type Bar; diff --git a/tests/ui/crashes/ice-4579.rs b/tests/ui/crashes/ice-4579.rs index 2e7e279f847d..14c8113e315b 100644 --- a/tests/ui/crashes/ice-4579.rs +++ b/tests/ui/crashes/ice-4579.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::single_match)] use std::ptr; diff --git a/tests/ui/crashes/ice-4671.rs b/tests/ui/crashes/ice-4671.rs index 64e8e7769412..3309d51302e2 100644 --- a/tests/ui/crashes/ice-4671.rs +++ b/tests/ui/crashes/ice-4671.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::use_self)] #[macro_use] diff --git a/tests/ui/crashes/ice-4727.rs b/tests/ui/crashes/ice-4727.rs index 2a4bc83f58a5..f90c6ca9a679 100644 --- a/tests/ui/crashes/ice-4727.rs +++ b/tests/ui/crashes/ice-4727.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::use_self)] #[path = "auxiliary/ice-4727-aux.rs"] diff --git a/tests/ui/crashes/ice-4760.rs b/tests/ui/crashes/ice-4760.rs index e1265169762f..07387db7b294 100644 --- a/tests/ui/crashes/ice-4760.rs +++ b/tests/ui/crashes/ice-4760.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(non_local_definitions)] const COUNT: usize = 2; diff --git a/tests/ui/crashes/ice-4775.rs b/tests/ui/crashes/ice-4775.rs index f693aafd1cbb..dd6c6b8de25a 100644 --- a/tests/ui/crashes/ice-4775.rs +++ b/tests/ui/crashes/ice-4775.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::uninlined_format_args)] pub struct ArrayWrapper([usize; N]); diff --git a/tests/ui/crashes/ice-4968.rs b/tests/ui/crashes/ice-4968.rs index 50473868005e..542cb63516da 100644 --- a/tests/ui/crashes/ice-4968.rs +++ b/tests/ui/crashes/ice-4968.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/4968 #![warn(clippy::unsound_collection_transmute)] diff --git a/tests/ui/crashes/ice-5207.rs b/tests/ui/crashes/ice-5207.rs index 0df8b88fea2f..6e438bcc2843 100644 --- a/tests/ui/crashes/ice-5207.rs +++ b/tests/ui/crashes/ice-5207.rs @@ -1,3 +1,4 @@ +//@ check-pass // Regression test for https://github.com/rust-lang/rust-clippy/issues/5207 pub async fn bar<'a, T: 'a>(_: T) {} diff --git a/tests/ui/crashes/ice-5223.rs b/tests/ui/crashes/ice-5223.rs index e3b3b27a6fc3..c055e551b298 100644 --- a/tests/ui/crashes/ice-5223.rs +++ b/tests/ui/crashes/ice-5223.rs @@ -1,3 +1,4 @@ +//@ check-pass // Regression test for #5233 #![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)] diff --git a/tests/ui/crashes/ice-5238.rs b/tests/ui/crashes/ice-5238.rs index ee2ae4f1a042..1d7dd8c76507 100644 --- a/tests/ui/crashes/ice-5238.rs +++ b/tests/ui/crashes/ice-5238.rs @@ -1,3 +1,4 @@ +//@ check-pass // Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 #![feature(coroutines, coroutine_trait, stmt_expr_attributes)] diff --git a/tests/ui/crashes/ice-5389.rs b/tests/ui/crashes/ice-5389.rs index de262199004b..b54562095a21 100644 --- a/tests/ui/crashes/ice-5389.rs +++ b/tests/ui/crashes/ice-5389.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::explicit_counter_loop)] fn main() { diff --git a/tests/ui/crashes/ice-5579.rs b/tests/ui/crashes/ice-5579.rs index 8ab36bbf93cb..e3e408a52539 100644 --- a/tests/ui/crashes/ice-5579.rs +++ b/tests/ui/crashes/ice-5579.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::unnecessary_literal_unwrap)] trait IsErr { diff --git a/tests/ui/crashes/ice-5835.fixed b/tests/ui/crashes/ice-5835.fixed deleted file mode 100644 index c0532d685786..000000000000 --- a/tests/ui/crashes/ice-5835.fixed +++ /dev/null @@ -1,11 +0,0 @@ -#[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, -} - -fn main() {} diff --git a/tests/ui/crashes/ice-5835.rs b/tests/ui/crashes/ice-5835.rs index 122bddd6ae67..149ba4786181 100644 --- a/tests/ui/crashes/ice-5835.rs +++ b/tests/ui/crashes/ice-5835.rs @@ -1,8 +1,10 @@ #[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` + //~^ tabs_in_doc_comments + //~| empty_line_after_doc_comments + + /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5835.stderr b/tests/ui/crashes/ice-5835.stderr index 45e5e9a4b83d..b342b43d0416 100644 --- a/tests/ui/crashes/ice-5835.stderr +++ b/tests/ui/crashes/ice-5835.stderr @@ -7,5 +7,21 @@ LL | /// 位 = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` -error: aborting due to 1 previous error +error: empty lines after doc comment + --> tests/ui/crashes/ice-5835.rs:3:5 + | +LL | / /// 位 +... | +LL | | + | |_^ + | + = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` + = help: if the empty lines are unintentional remove them +help: if the doc comment should not document `bar` comment it out + | +LL | // /// 位 + | ++ + +error: aborting due to 2 previous errors diff --git a/tests/ui/crashes/ice-5872.fixed b/tests/ui/crashes/ice-5872.fixed index c8e870c62fbf..a3235c3c7b7c 100644 --- a/tests/ui/crashes/ice-5872.fixed +++ b/tests/ui/crashes/ice-5872.fixed @@ -2,6 +2,7 @@ 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` + //~^ needless_collect + + } diff --git a/tests/ui/crashes/ice-5872.rs b/tests/ui/crashes/ice-5872.rs index c6ed31365892..7d3ad01f56e7 100644 --- a/tests/ui/crashes/ice-5872.rs +++ b/tests/ui/crashes/ice-5872.rs @@ -2,6 +2,7 @@ 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` + //~^ needless_collect + + } diff --git a/tests/ui/crashes/ice-5944.rs b/tests/ui/crashes/ice-5944.rs index ce46bc1acc1b..2a93c5436511 100644 --- a/tests/ui/crashes/ice-5944.rs +++ b/tests/ui/crashes/ice-5944.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::repeat_once)] #![allow(clippy::let_unit_value)] diff --git a/tests/ui/crashes/ice-6139.rs b/tests/ui/crashes/ice-6139.rs index f3966e47f5e8..866e13a86592 100644 --- a/tests/ui/crashes/ice-6139.rs +++ b/tests/ui/crashes/ice-6139.rs @@ -1,3 +1,5 @@ +//@ check-pass + trait T<'a> {} fn foo(_: Vec>>) {} diff --git a/tests/ui/crashes/ice-6153.rs b/tests/ui/crashes/ice-6153.rs index 9f73f39f10d7..84873c2ecf4c 100644 --- a/tests/ui/crashes/ice-6153.rs +++ b/tests/ui/crashes/ice-6153.rs @@ -1,3 +1,5 @@ +//@ check-pass + pub struct S<'a, 'e>(&'a str, &'e str); pub type T<'a, 'e> = std::collections::HashMap, ()>; diff --git a/tests/ui/crashes/ice-6179.rs b/tests/ui/crashes/ice-6179.rs index 91160eef03df..640b51517f74 100644 --- a/tests/ui/crashes/ice-6179.rs +++ b/tests/ui/crashes/ice-6179.rs @@ -1,3 +1,4 @@ +//@ check-pass //! This is a minimal reproducer for the ICE in https://github.com/rust-lang/rust-clippy/pull/6179. //! The ICE is mainly caused by using `lower_ty`. See the discussion in the PR for details. diff --git a/tests/ui/crashes/ice-6250.rs b/tests/ui/crashes/ice-6250.rs index 32849f2ca6f0..37db2ce68757 100644 --- a/tests/ui/crashes/ice-6250.rs +++ b/tests/ui/crashes/ice-6250.rs @@ -10,6 +10,8 @@ pub fn list_data(cache: &Cache, key: usize) { if /* let */ Some(reference) = cache.data.get(key) { + //~^ ERROR: mismatched types + //~| ERROR: mismatched types unimplemented!() } } diff --git a/tests/ui/crashes/ice-6251.rs b/tests/ui/crashes/ice-6251.rs index 73e919b6dd2e..8191a53b3e59 100644 --- a/tests/ui/crashes/ice-6251.rs +++ b/tests/ui/crashes/ice-6251.rs @@ -2,5 +2,8 @@ // assertion failed: `(left == right)` ; different DefIds //@no-rustfix fn bug() -> impl Iterator { +//~^ ERROR: the size for values +//~| ERROR: the size for values +//~| ERROR: mismatched types std::iter::empty() } diff --git a/tests/ui/crashes/ice-6252.rs b/tests/ui/crashes/ice-6252.rs index 67fbb0ff699c..829cb447211c 100644 --- a/tests/ui/crashes/ice-6252.rs +++ b/tests/ui/crashes/ice-6252.rs @@ -7,8 +7,11 @@ trait TypeVal { struct Five; struct Multiply { _n: PhantomData, + //~^ ERROR: cannot find type } impl TypeVal for Multiply where N: TypeVal {} +//~^ ERROR: cannot find type +//~| ERROR: not all trait items fn main() { [1; >::VAL]; diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index cd2031af1c6d..201a897b2319 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -10,7 +10,7 @@ LL + use std::marker::PhantomData; | error[E0412]: cannot find type `VAL` in this scope - --> tests/ui/crashes/ice-6252.rs:11:63 + --> tests/ui/crashes/ice-6252.rs:12:63 | LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^ not found in this scope @@ -21,7 +21,7 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | +++++ error[E0046]: not all trait items implemented, missing: `VAL` - --> tests/ui/crashes/ice-6252.rs:11:1 + --> tests/ui/crashes/ice-6252.rs:12:1 | LL | const VAL: T; | ------------ `VAL` from trait diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs index aaca32ab2d93..45144fd9e5ec 100644 --- a/tests/ui/crashes/ice-6254.rs +++ b/tests/ui/crashes/ice-6254.rs @@ -1,3 +1,4 @@ +//@ check-pass // originally from ./tests/ui/pattern/usefulness/consts-opaque.rs // panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', // compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5 diff --git a/tests/ui/crashes/ice-6332.rs b/tests/ui/crashes/ice-6332.rs index 9dc92aa500b2..25660a3ce853 100644 --- a/tests/ui/crashes/ice-6332.rs +++ b/tests/ui/crashes/ice-6332.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn cmark_check() { let mut link_err = false; macro_rules! cmark_error { diff --git a/tests/ui/crashes/ice-6539.rs b/tests/ui/crashes/ice-6539.rs index ac6c3e4aba04..cff0882cbee3 100644 --- a/tests/ui/crashes/ice-6539.rs +++ b/tests/ui/crashes/ice-6539.rs @@ -1,3 +1,4 @@ +//@ check-pass // The test for the ICE 6539: https://github.com/rust-lang/rust-clippy/issues/6539. // The cause is that `zero_sized_map_values` used `layout_of` with types from type aliases, // which is essentially the same as the ICE 4968. diff --git a/tests/ui/crashes/ice-6792.rs b/tests/ui/crashes/ice-6792.rs index 9cbafc716b50..372ce5ac06f3 100644 --- a/tests/ui/crashes/ice-6792.rs +++ b/tests/ui/crashes/ice-6792.rs @@ -1,3 +1,4 @@ +//@ check-pass //! This is a reproducer for the ICE 6792: https://github.com/rust-lang/rust-clippy/issues/6792. //! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`. diff --git a/tests/ui/crashes/ice-6793.rs b/tests/ui/crashes/ice-6793.rs index 12a4a0d25ef5..d83a2ee251db 100644 --- a/tests/ui/crashes/ice-6793.rs +++ b/tests/ui/crashes/ice-6793.rs @@ -1,3 +1,4 @@ +//@ check-pass //! This is a reproducer for the ICE 6793: https://github.com/rust-lang/rust-clippy/issues/6793. //! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`, which is the same as the ICE 6792. diff --git a/tests/ui/crashes/ice-6840.rs b/tests/ui/crashes/ice-6840.rs index d789f60c5d5a..94481f248998 100644 --- a/tests/ui/crashes/ice-6840.rs +++ b/tests/ui/crashes/ice-6840.rs @@ -1,3 +1,4 @@ +//@ check-pass //! This is a reproducer for the ICE 6840: https://github.com/rust-lang/rust-clippy/issues/6840. //! The ICE is caused by `TyCtxt::layout_of` and `is_normalizable` not being strict enough #![allow(dead_code)] diff --git a/tests/ui/crashes/ice-700.rs b/tests/ui/crashes/ice-700.rs index 5e004b94330e..aa3bf493c201 100644 --- a/tests/ui/crashes/ice-700.rs +++ b/tests/ui/crashes/ice-700.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::all)] // Test for https://github.com/rust-lang/rust-clippy/issues/700 diff --git a/tests/ui/crashes/ice-7012.rs b/tests/ui/crashes/ice-7012.rs index 60bdbc4f124e..d76995adadf1 100644 --- a/tests/ui/crashes/ice-7012.rs +++ b/tests/ui/crashes/ice-7012.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::all)] enum _MyOption { diff --git a/tests/ui/crashes/ice-7126.rs b/tests/ui/crashes/ice-7126.rs index b2dc2248b556..f0c23c7e852d 100644 --- a/tests/ui/crashes/ice-7126.rs +++ b/tests/ui/crashes/ice-7126.rs @@ -1,3 +1,4 @@ +//@ check-pass // This test requires a feature gated const fn and will stop working in the future. #![feature(const_btree_len)] diff --git a/tests/ui/crashes/ice-7169.fixed b/tests/ui/crashes/ice-7169.fixed index cf4077e4d898..d69b472a3617 100644 --- a/tests/ui/crashes/ice-7169.fixed +++ b/tests/ui/crashes/ice-7169.fixed @@ -8,6 +8,7 @@ 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` + //~^ redundant_pattern_matching + + } diff --git a/tests/ui/crashes/ice-7169.rs b/tests/ui/crashes/ice-7169.rs index b09e6f384632..918f2b0f0b3c 100644 --- a/tests/ui/crashes/ice-7169.rs +++ b/tests/ui/crashes/ice-7169.rs @@ -8,6 +8,7 @@ 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` + //~^ redundant_pattern_matching + + } diff --git a/tests/ui/crashes/ice-7231.rs b/tests/ui/crashes/ice-7231.rs index 4ad0d351372f..873cdbb0516c 100644 --- a/tests/ui/crashes/ice-7231.rs +++ b/tests/ui/crashes/ice-7231.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::never_loop)] async fn f() { diff --git a/tests/ui/crashes/ice-7272.rs b/tests/ui/crashes/ice-7272.rs index e949038c8d0b..e1910096418b 100644 --- a/tests/ui/crashes/ice-7272.rs +++ b/tests/ui/crashes/ice-7272.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:ice-7272-aux.rs #![allow(clippy::no_effect)] diff --git a/tests/ui/crashes/ice-7340.rs b/tests/ui/crashes/ice-7340.rs index 7d2351d606f1..6c71c232fddb 100644 --- a/tests/ui/crashes/ice-7340.rs +++ b/tests/ui/crashes/ice-7340.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::no_effect)] fn main() { diff --git a/tests/ui/crashes/ice-7410.rs b/tests/ui/crashes/ice-7410.rs index addbca54e80a..71f00fb9aede 100644 --- a/tests/ui/crashes/ice-7410.rs +++ b/tests/ui/crashes/ice-7410.rs @@ -1,3 +1,4 @@ +//@ check-pass //@compile-flags: -Clink-arg=-nostartfiles //@ignore-target: apple windows diff --git a/tests/ui/crashes/ice-7423.rs b/tests/ui/crashes/ice-7423.rs index 31340b012dd0..a03981842fcc 100644 --- a/tests/ui/crashes/ice-7423.rs +++ b/tests/ui/crashes/ice-7423.rs @@ -1,3 +1,5 @@ +//@ check-pass + pub trait Trait { fn f(); } diff --git a/tests/ui/crashes/ice-7868.rs b/tests/ui/crashes/ice-7868.rs index c6932164e3bf..727dd41aa322 100644 --- a/tests/ui/crashes/ice-7868.rs +++ b/tests/ui/crashes/ice-7868.rs @@ -1,3 +1,4 @@ +//@error-in-other-file: #![warn(clippy::undocumented_unsafe_blocks)] #![allow(clippy::no_effect)] diff --git a/tests/ui/crashes/ice-7869.rs b/tests/ui/crashes/ice-7869.rs index 774e22f6b4c5..68648462b57a 100644 --- a/tests/ui/crashes/ice-7869.rs +++ b/tests/ui/crashes/ice-7869.rs @@ -1,5 +1,6 @@ enum Tila { - //~^ ERROR: all variants have the same prefix: `Työ` +//~^ enum_variant_names + TyöAlkoi, TyöKeskeytyi, TyöValmis, diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 2377b4fd5b6b..7d70e3834e9d 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -3,6 +3,7 @@ error: all variants have the same prefix: `Työ` | LL | / enum Tila { LL | | +LL | | LL | | TyöAlkoi, LL | | TyöKeskeytyi, LL | | TyöValmis, diff --git a/tests/ui/crashes/ice-7934.rs b/tests/ui/crashes/ice-7934.rs index a4691c4131b3..c7a8d68d63b6 100644 --- a/tests/ui/crashes/ice-7934.rs +++ b/tests/ui/crashes/ice-7934.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::undocumented_unsafe_blocks)] #![allow(clippy::no_effect)] diff --git a/tests/ui/crashes/ice-8250.fixed b/tests/ui/crashes/ice-8250.fixed index 984b61258c78..2474c47944ef 100644 --- a/tests/ui/crashes/ice-8250.fixed +++ b/tests/ui/crashes/ice-8250.fixed @@ -1,7 +1,8 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].split('.').next()?; - //~^ ERROR: unnecessary use of `splitn` - //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` + //~^ needless_splitn + + Some(()) } diff --git a/tests/ui/crashes/ice-8250.rs b/tests/ui/crashes/ice-8250.rs index c1b2e48ba3c0..8f938246f37a 100644 --- a/tests/ui/crashes/ice-8250.rs +++ b/tests/ui/crashes/ice-8250.rs @@ -1,7 +1,8 @@ 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` + //~^ needless_splitn + + Some(()) } diff --git a/tests/ui/crashes/ice-8386.rs b/tests/ui/crashes/ice-8386.rs index 3e38b1408d8c..1c7a809174b6 100644 --- a/tests/ui/crashes/ice-8386.rs +++ b/tests/ui/crashes/ice-8386.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn f(x: u32, mut arg: &String) {} fn main() {} diff --git a/tests/ui/crashes/ice-8681.rs b/tests/ui/crashes/ice-8681.rs index 607b9caa3249..b7d6c4556bbd 100644 --- a/tests/ui/crashes/ice-8681.rs +++ b/tests/ui/crashes/ice-8681.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build: ice-8681-aux.rs #![warn(clippy::undocumented_unsafe_blocks)] diff --git a/tests/ui/crashes/ice-8821.rs b/tests/ui/crashes/ice-8821.rs index fb87b79aeed8..c9fea3d1ccb8 100644 --- a/tests/ui/crashes/ice-8821.rs +++ b/tests/ui/crashes/ice-8821.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::let_unit_value)] fn f() {} diff --git a/tests/ui/crashes/ice-8850.fixed b/tests/ui/crashes/ice-8850.fixed index 4569b9e8793e..0e1d8d5a2aae 100644 --- a/tests/ui/crashes/ice-8850.fixed +++ b/tests/ui/crashes/ice-8850.fixed @@ -2,15 +2,14 @@ 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` + //~^ let_and_return } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; FN() + 1 - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return } fn deref_to_dyn_fn() -> usize { @@ -25,7 +24,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; FN() + 1 - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return } fn main() {} diff --git a/tests/ui/crashes/ice-8850.rs b/tests/ui/crashes/ice-8850.rs index 499756ecefe9..0109911bca68 100644 --- a/tests/ui/crashes/ice-8850.rs +++ b/tests/ui/crashes/ice-8850.rs @@ -2,15 +2,14 @@ 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` + //~^ let_and_return } 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 + //~^ let_and_return } fn deref_to_dyn_fn() -> usize { @@ -25,7 +24,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 + //~^ let_and_return } fn main() {} diff --git a/tests/ui/crashes/ice-8850.stderr b/tests/ui/crashes/ice-8850.stderr index 5a8f24ee8c0b..1a44f103beb3 100644 --- a/tests/ui/crashes/ice-8850.stderr +++ b/tests/ui/crashes/ice-8850.stderr @@ -15,7 +15,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> tests/ui/crashes/ice-8850.rs:12:5 + --> tests/ui/crashes/ice-8850.rs:11:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding @@ -29,7 +29,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> tests/ui/crashes/ice-8850.rs:27:5 + --> tests/ui/crashes/ice-8850.rs:26: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 727d88f7fbd2..69e74e6e394b 100644 --- a/tests/ui/crashes/ice-9041.rs +++ b/tests/ui/crashes/ice-9041.rs @@ -3,8 +3,9 @@ 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` + //~^ search_is_some + + } fn main() {} diff --git a/tests/ui/crashes/ice-9238.rs b/tests/ui/crashes/ice-9238.rs index ee6abd519f16..cbce84305ba8 100644 --- a/tests/ui/crashes/ice-9238.rs +++ b/tests/ui/crashes/ice-9238.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(incomplete_features)] #![feature(generic_const_exprs)] #![warn(clippy::branches_sharing_code)] diff --git a/tests/ui/crashes/ice-9242.rs b/tests/ui/crashes/ice-9242.rs index 0099e6e2f34b..ac5bbad98c14 100644 --- a/tests/ui/crashes/ice-9242.rs +++ b/tests/ui/crashes/ice-9242.rs @@ -1,3 +1,5 @@ +//@ check-pass + enum E { X(), Y, diff --git a/tests/ui/crashes/ice-9405.rs b/tests/ui/crashes/ice-9405.rs index e2d274aeb044..74a56f4d2ef8 100644 --- a/tests/ui/crashes/ice-9405.rs +++ b/tests/ui/crashes/ice-9405.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::useless_format)] #![allow(clippy::print_literal)] diff --git a/tests/ui/crashes/ice-9405.stderr b/tests/ui/crashes/ice-9405.stderr index e8a73b9e782e..96e0f2ea736a 100644 --- a/tests/ui/crashes/ice-9405.stderr +++ b/tests/ui/crashes/ice-9405.stderr @@ -1,5 +1,5 @@ warning: multiple lines skipped by escaped newline - --> tests/ui/crashes/ice-9405.rs:6:10 + --> tests/ui/crashes/ice-9405.rs:8:10 | LL | "\ | __________^ diff --git a/tests/ui/crashes/ice-9414.rs b/tests/ui/crashes/ice-9414.rs index 02cf5d5c240f..2341c99b2390 100644 --- a/tests/ui/crashes/ice-9414.rs +++ b/tests/ui/crashes/ice-9414.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::result_large_err)] trait T {} diff --git a/tests/ui/crashes/ice-9445.rs b/tests/ui/crashes/ice-9445.rs index c67b22f6f8c4..232b8e4a7959 100644 --- a/tests/ui/crashes/ice-9445.rs +++ b/tests/ui/crashes/ice-9445.rs @@ -1,3 +1,4 @@ const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); +//~^ declare_interior_mutable_const fn main() {} diff --git a/tests/ui/crashes/ice-9459.rs b/tests/ui/crashes/ice-9459.rs index 55615124fcf0..43d3264b264d 100644 --- a/tests/ui/crashes/ice-9459.rs +++ b/tests/ui/crashes/ice-9459.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(unsized_fn_params)] pub fn f0(_f: dyn FnOnce()) {} diff --git a/tests/ui/crashes/ice-9463.rs b/tests/ui/crashes/ice-9463.rs index fa83d25b3942..93808e0f8923 100644 --- a/tests/ui/crashes/ice-9463.rs +++ b/tests/ui/crashes/ice-9463.rs @@ -4,6 +4,5 @@ fn main() { //~^ 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 + //~| ERROR: literal out of range } diff --git a/tests/ui/crashes/ice-9625.rs b/tests/ui/crashes/ice-9625.rs index a765882b5d81..52117883aa7d 100644 --- a/tests/ui/crashes/ice-9625.rs +++ b/tests/ui/crashes/ice-9625.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn main() { let x = &1; let _ = &1 < x && x < &10; diff --git a/tests/ui/crashes/ice-9746.rs b/tests/ui/crashes/ice-9746.rs index fbd373c70bf2..39fa8ff7a915 100644 --- a/tests/ui/crashes/ice-9746.rs +++ b/tests/ui/crashes/ice-9746.rs @@ -1,3 +1,4 @@ +//@ check-pass //! trait Trait {} diff --git a/tests/ui/crashes/ice-rust-107877.rs b/tests/ui/crashes/ice-rust-107877.rs index 7f5bae60d55d..55fe418bed12 100644 --- a/tests/ui/crashes/ice-rust-107877.rs +++ b/tests/ui/crashes/ice-rust-107877.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code)] struct Foo; diff --git a/tests/ui/crashes/ice_exact_size.rs b/tests/ui/crashes/ice_exact_size.rs index c0671eaff145..cb4685e78e22 100644 --- a/tests/ui/crashes/ice_exact_size.rs +++ b/tests/ui/crashes/ice_exact_size.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::all)] // Test for https://github.com/rust-lang/rust-clippy/issues/1336 diff --git a/tests/ui/crashes/if_same_then_else.rs b/tests/ui/crashes/if_same_then_else.rs index a900fe5e6bc6..58ee751948b5 100644 --- a/tests/ui/crashes/if_same_then_else.rs +++ b/tests/ui/crashes/if_same_then_else.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::comparison_chain)] #![deny(clippy::if_same_then_else)] diff --git a/tests/ui/crashes/implements-trait.rs b/tests/ui/crashes/implements-trait.rs index 4502b0147a83..0e68c40be999 100644 --- a/tests/ui/crashes/implements-trait.rs +++ b/tests/ui/crashes/implements-trait.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[allow(clippy::needless_borrowed_reference)] fn main() { let mut v = Vec::::new(); diff --git a/tests/ui/crashes/inherent_impl.rs b/tests/ui/crashes/inherent_impl.rs index 800a5a383f62..87f1347ecfca 100644 --- a/tests/ui/crashes/inherent_impl.rs +++ b/tests/ui/crashes/inherent_impl.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::multiple_inherent_impl)] // Test for https://github.com/rust-lang/rust-clippy/issues/4578 diff --git a/tests/ui/crashes/issue-825.rs b/tests/ui/crashes/issue-825.rs index e8b455a0ec67..9bbb86e4c65a 100644 --- a/tests/ui/crashes/issue-825.rs +++ b/tests/ui/crashes/issue-825.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(warnings)] // Test for https://github.com/rust-lang/rust-clippy/issues/825 diff --git a/tests/ui/crashes/issues_loop_mut_cond.rs b/tests/ui/crashes/issues_loop_mut_cond.rs index bb238c81ebc0..635580c6a6e7 100644 --- a/tests/ui/crashes/issues_loop_mut_cond.rs +++ b/tests/ui/crashes/issues_loop_mut_cond.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code)] /// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 diff --git a/tests/ui/crashes/match_same_arms_const.rs b/tests/ui/crashes/match_same_arms_const.rs index 626179c00155..a70623f0c51f 100644 --- a/tests/ui/crashes/match_same_arms_const.rs +++ b/tests/ui/crashes/match_same_arms_const.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::match_same_arms)] // Test for https://github.com/rust-lang/rust-clippy/issues/2427 diff --git a/tests/ui/crashes/needless_borrow_fp.rs b/tests/ui/crashes/needless_borrow_fp.rs index 4f61c76828db..68e39531682a 100644 --- a/tests/ui/crashes/needless_borrow_fp.rs +++ b/tests/ui/crashes/needless_borrow_fp.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[deny(clippy::all)] #[derive(Debug)] pub enum Error { diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index 837069cae6d1..cc5ed052d264 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -10,10 +10,12 @@ struct Baz<'a> { } impl Foo for Baz<'_> {} +//~^ needless_lifetimes impl Bar { fn baz(&self) -> impl Foo + '_ { - //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~^ needless_lifetimes + Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 06947e3a3513..258fb3118ef0 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -10,10 +10,12 @@ struct Baz<'a> { } impl<'a> Foo for Baz<'a> {} +//~^ needless_lifetimes impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { - //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~^ needless_lifetimes + Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr index bed6aab25c4d..97fb6d29cfbe 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr @@ -16,7 +16,7 @@ LL + impl Foo for Baz<'_> {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12 + --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:16:12 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ 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 774dea391939..128ff4a1c036 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,6 +5,7 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: &Foo<'_>) {} -//~^ ERROR: this argument is passed by value, but not consumed in the function body +//~^ needless_pass_by_value + 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 f3d8871929a2..b82cc831c6e0 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,6 +5,7 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: Foo<'_>) {} -//~^ ERROR: this argument is passed by value, but not consumed in the function body +//~^ needless_pass_by_value + fn main() {} diff --git a/tests/ui/crashes/regressions.rs b/tests/ui/crashes/regressions.rs index b34997d4ee0b..8fda12fab06a 100644 --- a/tests/ui/crashes/regressions.rs +++ b/tests/ui/crashes/regressions.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(clippy::disallowed_names, clippy::uninlined_format_args)] pub fn foo(bar: *const u8) { diff --git a/tests/ui/crashes/returns.rs b/tests/ui/crashes/returns.rs index 91cdb5306c89..ccab9522753e 100644 --- a/tests/ui/crashes/returns.rs +++ b/tests/ui/crashes/returns.rs @@ -1,3 +1,4 @@ +//@ check-pass // Test for https://github.com/rust-lang/rust-clippy/issues/1346 #[deny(warnings)] diff --git a/tests/ui/crashes/shadow.rs b/tests/ui/crashes/shadow.rs index 843e8ef64dcd..237988a01681 100644 --- a/tests/ui/crashes/shadow.rs +++ b/tests/ui/crashes/shadow.rs @@ -1,3 +1,5 @@ +//@ check-pass + fn main() { let x: [i32; { let u = 2; diff --git a/tests/ui/crashes/single-match-else.rs b/tests/ui/crashes/single-match-else.rs index 1ba7ac082132..2ef5dd891c56 100644 --- a/tests/ui/crashes/single-match-else.rs +++ b/tests/ui/crashes/single-match-else.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::single_match_else)] //! Test for https://github.com/rust-lang/rust-clippy/issues/1588 diff --git a/tests/ui/crashes/third-party/conf_allowlisted.rs b/tests/ui/crashes/third-party/conf_allowlisted.rs index f328e4d9d04c..20c76a4d46d9 100644 --- a/tests/ui/crashes/third-party/conf_allowlisted.rs +++ b/tests/ui/crashes/third-party/conf_allowlisted.rs @@ -1 +1,3 @@ +//@ check-pass + fn main() {} diff --git a/tests/ui/crashes/trivial_bounds.rs b/tests/ui/crashes/trivial_bounds.rs index 60105a8213fe..23982fca7e7c 100644 --- a/tests/ui/crashes/trivial_bounds.rs +++ b/tests/ui/crashes/trivial_bounds.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(trivial_bounds)] #![allow(unused, trivial_bounds)] diff --git a/tests/ui/crashes/unreachable-array-or-slice.rs b/tests/ui/crashes/unreachable-array-or-slice.rs index e920e58d6ec6..bc2e9aa92ce1 100644 --- a/tests/ui/crashes/unreachable-array-or-slice.rs +++ b/tests/ui/crashes/unreachable-array-or-slice.rs @@ -2,6 +2,7 @@ struct Foo(isize, isize, isize, isize); pub fn main() { let Self::anything_here_kills_it(a, b, ..) = Foo(5, 5, 5, 5); + //~^ ERROR: failed to resolve match [5, 5, 5, 5] { [..] => {}, } diff --git a/tests/ui/crashes/used_underscore_binding_macro.rs b/tests/ui/crashes/used_underscore_binding_macro.rs index 901eb4e50398..0fff0afdf1fe 100644 --- a/tests/ui/crashes/used_underscore_binding_macro.rs +++ b/tests/ui/crashes/used_underscore_binding_macro.rs @@ -1,3 +1,5 @@ +//@ check-pass + use serde::Deserialize; /// Tests that we do not lint for unused underscores in a `MacroAttribute` diff --git a/tests/ui/crate_in_macro_def.fixed b/tests/ui/crate_in_macro_def.fixed index bd91389c8219..d7d8e2a64419 100644 --- a/tests/ui/crate_in_macro_def.fixed +++ b/tests/ui/crate_in_macro_def.fixed @@ -16,6 +16,7 @@ mod unhygienic { macro_rules! print_message_unhygienic { () => { println!("{}", $crate::unhygienic::MESSAGE); + //~^ crate_in_macro_def }; } diff --git a/tests/ui/crate_in_macro_def.rs b/tests/ui/crate_in_macro_def.rs index f6fa338eedbf..9ed9dacee48b 100644 --- a/tests/ui/crate_in_macro_def.rs +++ b/tests/ui/crate_in_macro_def.rs @@ -16,6 +16,7 @@ mod unhygienic { macro_rules! print_message_unhygienic { () => { println!("{}", crate::unhygienic::MESSAGE); + //~^ crate_in_macro_def }; } diff --git a/tests/ui/crate_level_checks/entrypoint_recursion.rs b/tests/ui/crate_level_checks/entrypoint_recursion.rs index 5d853d97bc35..3ded902e36b1 100644 --- a/tests/ui/crate_level_checks/entrypoint_recursion.rs +++ b/tests/ui/crate_level_checks/entrypoint_recursion.rs @@ -1,3 +1,4 @@ +//@check-pass //@ignore-target: apple #![feature(rustc_attrs)] diff --git a/tests/ui/crate_level_checks/no_std_swap.rs b/tests/ui/crate_level_checks/no_std_swap.rs index 536e71b4a25a..e332e10ea4ba 100644 --- a/tests/ui/crate_level_checks/no_std_swap.rs +++ b/tests/ui/crate_level_checks/no_std_swap.rs @@ -9,7 +9,8 @@ pub 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`? + //~^ almost_swapped + + b = a; } diff --git a/tests/ui/crate_level_checks/std_main_recursion.rs b/tests/ui/crate_level_checks/std_main_recursion.rs index c2c3e0958ec7..b582d560668a 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.rs +++ b/tests/ui/crate_level_checks/std_main_recursion.rs @@ -3,5 +3,6 @@ fn main() { println!("Hello, World!"); main(); - //~^ ERROR: recursing into entrypoint `main` + //~^ main_recursion + } diff --git a/tests/ui/create_dir.fixed b/tests/ui/create_dir.fixed index 8fbf7dd19b83..4a5b1b77be6b 100644 --- a/tests/ui/create_dir.fixed +++ b/tests/ui/create_dir.fixed @@ -8,7 +8,9 @@ fn create_dir() {} fn main() { // Should be warned create_dir_all("foo"); + //~^ create_dir create_dir_all("bar").unwrap(); + //~^ create_dir // Shouldn't be warned create_dir(); diff --git a/tests/ui/create_dir.rs b/tests/ui/create_dir.rs index af2c326ec436..bf185ba3a7c3 100644 --- a/tests/ui/create_dir.rs +++ b/tests/ui/create_dir.rs @@ -8,7 +8,9 @@ fn create_dir() {} fn main() { // Should be warned std::fs::create_dir("foo"); + //~^ create_dir std::fs::create_dir("bar").unwrap(); + //~^ create_dir // Shouldn't be warned create_dir(); diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr index ab51705bb55a..2aba2944aa60 100644 --- a/tests/ui/create_dir.stderr +++ b/tests/ui/create_dir.stderr @@ -12,7 +12,7 @@ LL | create_dir_all("foo"); | ~~~~~~~~~~~~~~~~~~~~~ error: calling `std::fs::create_dir` where there may be a better way - --> tests/ui/create_dir.rs:11:5 + --> tests/ui/create_dir.rs:12:5 | LL | std::fs::create_dir("bar").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/dbg_macro/dbg_macro.fixed b/tests/ui/dbg_macro/dbg_macro.fixed index bda9221a5e1e..de715db8faab 100644 --- a/tests/ui/dbg_macro/dbg_macro.fixed +++ b/tests/ui/dbg_macro/dbg_macro.fixed @@ -3,28 +3,35 @@ fn foo(n: u32) -> u32 { if let Some(n) = n.checked_sub(4) { n } else { n } - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if n <= 1 { - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + 1 - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } else { n * factorial(n - 1) - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } fn main() { 42; - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo(3) + factorial(4); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + (1, 2, 3, 4, 5); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } fn issue9914() { @@ -41,21 +48,27 @@ fn issue9914() { macro_rules! expand_to_dbg { () => { - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + }; } - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + #[allow(clippy::let_unit_value)] let _ = (); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + bar(()); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo!(()); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo2!(foo!(())); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + expand_to_dbg!(); } @@ -77,35 +90,41 @@ mod issue7274 { struct MyThing; define_thing!(MyThing, { 2; - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + }); } #[test] pub fn issue8481() { 1; - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } #[cfg(test)] fn foo2() { 1; - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } #[cfg(test)] mod mod1 { fn func() { 1; - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } mod issue12131 { fn dbg_in_print(s: &str) { println!("dbg: {:?}", s); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + print!("{}", s); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } diff --git a/tests/ui/dbg_macro/dbg_macro.rs b/tests/ui/dbg_macro/dbg_macro.rs index 8244254026be..90a72d131667 100644 --- a/tests/ui/dbg_macro/dbg_macro.rs +++ b/tests/ui/dbg_macro/dbg_macro.rs @@ -3,28 +3,35 @@ 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 + //~^ dbg_macro + } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + dbg!(1) - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } else { dbg!(n * factorial(n - 1)) - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } fn main() { dbg!(42); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo(3) + dbg!(factorial(4)); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + dbg!(1, 2, 3, 4, 5); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } fn issue9914() { @@ -41,21 +48,27 @@ fn issue9914() { macro_rules! expand_to_dbg { () => { dbg!(); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + }; } dbg!(); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + #[allow(clippy::let_unit_value)] let _ = dbg!(); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + bar(dbg!()); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo!(dbg!()); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + foo2!(foo!(dbg!())); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + expand_to_dbg!(); } @@ -77,35 +90,41 @@ mod issue7274 { struct MyThing; define_thing!(MyThing, { dbg!(2); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + }); } #[test] pub fn issue8481() { dbg!(1); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } #[cfg(test)] fn foo2() { dbg!(1); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } #[cfg(test)] mod mod1 { fn func() { dbg!(1); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } mod issue12131 { fn dbg_in_print(s: &str) { println!("dbg: {:?}", dbg!(s)); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + print!("{}", dbg!(s)); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + } } diff --git a/tests/ui/dbg_macro/dbg_macro.stderr b/tests/ui/dbg_macro/dbg_macro.stderr index b3d74b9ff617..ee0cfc12b347 100644 --- a/tests/ui/dbg_macro/dbg_macro.stderr +++ b/tests/ui/dbg_macro/dbg_macro.stderr @@ -12,7 +12,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:11:8 + --> tests/ui/dbg_macro/dbg_macro.rs:12:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:13:9 + --> tests/ui/dbg_macro/dbg_macro.rs:15:9 | LL | dbg!(1) | ^^^^^^^ @@ -34,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:16:9 + --> tests/ui/dbg_macro/dbg_macro.rs:19:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:22:5 + --> tests/ui/dbg_macro/dbg_macro.rs:26:5 | LL | dbg!(42); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:24:14 + --> tests/ui/dbg_macro/dbg_macro.rs:29:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:26:5 + --> tests/ui/dbg_macro/dbg_macro.rs:32:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:48:5 + --> tests/ui/dbg_macro/dbg_macro.rs:56:5 | LL | dbg!(); | ^^^^^^ @@ -89,7 +89,7 @@ LL - dbg!(); | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:51:13 + --> tests/ui/dbg_macro/dbg_macro.rs:60:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:53:9 + --> tests/ui/dbg_macro/dbg_macro.rs:63:9 | LL | bar(dbg!()); | ^^^^^^ @@ -111,7 +111,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:55:10 + --> tests/ui/dbg_macro/dbg_macro.rs:66:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -122,7 +122,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:57:16 + --> tests/ui/dbg_macro/dbg_macro.rs:69:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -133,7 +133,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:43:13 + --> tests/ui/dbg_macro/dbg_macro.rs:50:13 | LL | dbg!(); | ^^^^^^ @@ -148,7 +148,7 @@ LL - dbg!(); | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:79:9 + --> tests/ui/dbg_macro/dbg_macro.rs:92:9 | LL | dbg!(2); | ^^^^^^^ @@ -159,7 +159,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:86:5 + --> tests/ui/dbg_macro/dbg_macro.rs:100:5 | LL | dbg!(1); | ^^^^^^^ @@ -170,7 +170,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:92:5 + --> tests/ui/dbg_macro/dbg_macro.rs:107:5 | LL | dbg!(1); | ^^^^^^^ @@ -181,7 +181,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:99:9 + --> tests/ui/dbg_macro/dbg_macro.rs:115:9 | LL | dbg!(1); | ^^^^^^^ @@ -192,7 +192,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:106:31 + --> tests/ui/dbg_macro/dbg_macro.rs:123:31 | LL | println!("dbg: {:?}", dbg!(s)); | ^^^^^^^ @@ -203,7 +203,7 @@ LL | println!("dbg: {:?}", s); | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:108:22 + --> tests/ui/dbg_macro/dbg_macro.rs:126:22 | LL | print!("{}", dbg!(s)); | ^^^^^^^ diff --git a/tests/ui/dbg_macro/dbg_macro_unfixable.rs b/tests/ui/dbg_macro/dbg_macro_unfixable.rs index 0e83766ccaec..bd16306b89db 100644 --- a/tests/ui/dbg_macro/dbg_macro_unfixable.rs +++ b/tests/ui/dbg_macro/dbg_macro_unfixable.rs @@ -1,4 +1,5 @@ //@no-rustfix +//@error-in-other-file: #![warn(clippy::dbg_macro)] #[path = "auxiliary/submodule.rs"] @@ -6,7 +7,12 @@ mod submodule; fn main() { dbg!(dbg!(dbg!(42))); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + //~| dbg_macro + //~| dbg_macro + dbg!(1, 2, dbg!(3, 4)); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~^ dbg_macro + //~| dbg_macro + } diff --git a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr index b8e91906b931..df053a7a5f21 100644 --- a/tests/ui/dbg_macro/dbg_macro_unfixable.stderr +++ b/tests/ui/dbg_macro/dbg_macro_unfixable.stderr @@ -12,7 +12,7 @@ LL - dbg!(); | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:5 + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:9:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:10 + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:9:10 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:15 + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:9:15 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | dbg!(dbg!(42)); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:5 + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:14:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:16 + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:14:16 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^ diff --git a/tests/ui/debug_assert_with_mut_call.rs b/tests/ui/debug_assert_with_mut_call.rs index 8d04be777c7b..74d59b7593fa 100644 --- a/tests/ui/debug_assert_with_mut_call.rs +++ b/tests/ui/debug_assert_with_mut_call.rs @@ -40,20 +40,26 @@ 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_with_mut_call + + debug_assert!(!bool_mut(&mut 3)); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~^ debug_assert_with_mut_call + debug_assert_eq!(0, u32_mut(&mut 3)); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` + //~^ debug_assert_with_mut_call + debug_assert_eq!(u32_mut(&mut 3), 0); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` + //~^ debug_assert_with_mut_call + debug_assert_ne!(1, u32_mut(&mut 3)); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` + //~^ debug_assert_with_mut_call + debug_assert_ne!(u32_mut(&mut 3), 1); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` + //~^ debug_assert_with_mut_call + } fn method_non_mutable() { @@ -69,33 +75,46 @@ 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_with_mut_call + debug_assert!(!S.bool_self_mut()); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~^ debug_assert_with_mut_call + 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_with_mut_call + debug_assert!(S.bool_self_mut_arg_ref(&3)); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~^ debug_assert_with_mut_call + 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_with_mut_call + debug_assert_eq!(S.u32_self_mut(), 0); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` + //~^ debug_assert_with_mut_call + 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_with_mut_call + 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_with_mut_call + 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_with_mut_call + debug_assert_ne!(S.u32_self_mut(), 1); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` + //~^ debug_assert_with_mut_call + 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_with_mut_call + 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_with_mut_call + 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!` + //~^ debug_assert_with_mut_call + } fn misc() { @@ -104,35 +123,43 @@ 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_with_mut_call + debug_assert_ne!(Some(3), v.pop()); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` + //~^ debug_assert_with_mut_call + let a = &mut 3; debug_assert!(bool_mut(a)); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~^ debug_assert_with_mut_call + // nested debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~^ debug_assert_with_mut_call + // chained debug_assert_eq!(v.pop().unwrap(), 3); - //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` + //~^ debug_assert_with_mut_call + // 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_with_mut_call + 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!` + //~^ debug_assert_with_mut_call + // 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! + //~^ debug_assert_with_mut_call + x > 10 }); @@ -140,7 +167,8 @@ 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! + //~^ debug_assert_with_mut_call + x > 10 })()); } diff --git a/tests/ui/debug_assert_with_mut_call.stderr b/tests/ui/debug_assert_with_mut_call.stderr index 83e1105a07df..216ab27264c1 100644 --- a/tests/ui/debug_assert_with_mut_call.stderr +++ b/tests/ui/debug_assert_with_mut_call.stderr @@ -8,163 +8,163 @@ LL | debug_assert!(bool_mut(&mut 3)); = help: to override `-D warnings` add `#[allow(clippy::debug_assert_with_mut_call)]` error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:45:20 + --> tests/ui/debug_assert_with_mut_call.rs:46:20 | LL | debug_assert!(!bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> tests/ui/debug_assert_with_mut_call.rs:48:25 + --> tests/ui/debug_assert_with_mut_call.rs:50:25 | LL | debug_assert_eq!(0, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> tests/ui/debug_assert_with_mut_call.rs:50:22 + --> tests/ui/debug_assert_with_mut_call.rs:53:22 | LL | debug_assert_eq!(u32_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> tests/ui/debug_assert_with_mut_call.rs:53:25 + --> tests/ui/debug_assert_with_mut_call.rs:57:25 | LL | debug_assert_ne!(1, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> tests/ui/debug_assert_with_mut_call.rs:55:22 + --> tests/ui/debug_assert_with_mut_call.rs:60:22 | LL | debug_assert_ne!(u32_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:71:19 + --> tests/ui/debug_assert_with_mut_call.rs:77:19 | LL | debug_assert!(S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:73:20 + --> tests/ui/debug_assert_with_mut_call.rs:80:20 | LL | debug_assert!(!S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:75:19 + --> tests/ui/debug_assert_with_mut_call.rs:83: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!` - --> tests/ui/debug_assert_with_mut_call.rs:77:19 + --> tests/ui/debug_assert_with_mut_call.rs:86:19 | LL | debug_assert!(S.bool_self_mut_arg_ref(&3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:79:19 + --> tests/ui/debug_assert_with_mut_call.rs:89: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!` - --> tests/ui/debug_assert_with_mut_call.rs:82:22 + --> tests/ui/debug_assert_with_mut_call.rs:93:22 | LL | debug_assert_eq!(S.u32_self_mut(), 0); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> tests/ui/debug_assert_with_mut_call.rs:84:22 + --> tests/ui/debug_assert_with_mut_call.rs:96: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!` - --> tests/ui/debug_assert_with_mut_call.rs:86:22 + --> tests/ui/debug_assert_with_mut_call.rs:99: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!` - --> tests/ui/debug_assert_with_mut_call.rs:88:22 + --> tests/ui/debug_assert_with_mut_call.rs:102: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!` - --> tests/ui/debug_assert_with_mut_call.rs:91:22 + --> tests/ui/debug_assert_with_mut_call.rs:106:22 | LL | debug_assert_ne!(S.u32_self_mut(), 1); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> tests/ui/debug_assert_with_mut_call.rs:93:22 + --> tests/ui/debug_assert_with_mut_call.rs:109: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!` - --> tests/ui/debug_assert_with_mut_call.rs:95:22 + --> tests/ui/debug_assert_with_mut_call.rs:112: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!` - --> tests/ui/debug_assert_with_mut_call.rs:97:22 + --> tests/ui/debug_assert_with_mut_call.rs:115: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!` - --> tests/ui/debug_assert_with_mut_call.rs:106:22 + --> tests/ui/debug_assert_with_mut_call.rs:125:22 | LL | debug_assert_eq!(v.pop(), Some(1)); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> tests/ui/debug_assert_with_mut_call.rs:108:31 + --> tests/ui/debug_assert_with_mut_call.rs:128:31 | LL | debug_assert_ne!(Some(3), v.pop()); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:112:19 + --> tests/ui/debug_assert_with_mut_call.rs:133:19 | LL | debug_assert!(bool_mut(a)); | ^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:116:31 + --> tests/ui/debug_assert_with_mut_call.rs:138:31 | LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> tests/ui/debug_assert_with_mut_call.rs:120:22 + --> tests/ui/debug_assert_with_mut_call.rs:143:22 | LL | debug_assert_eq!(v.pop().unwrap(), 3); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:125:19 + --> tests/ui/debug_assert_with_mut_call.rs:149:19 | LL | debug_assert!(bool_mut(&mut 3), "w/o format"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:128:19 + --> tests/ui/debug_assert_with_mut_call.rs:153:19 | LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:134:9 + --> tests/ui/debug_assert_with_mut_call.rs:160:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> tests/ui/debug_assert_with_mut_call.rs:142:9 + --> tests/ui/debug_assert_with_mut_call.rs:169:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/decimal_literal_representation.fixed b/tests/ui/decimal_literal_representation.fixed index e34f48b65dd1..e0477578488c 100644 --- a/tests/ui/decimal_literal_representation.fixed +++ b/tests/ui/decimal_literal_representation.fixed @@ -14,12 +14,19 @@ fn main() { ); let bad = ( // Hex: 0x8005, // 0x8005 + //~^ decimal_literal_representation 0xFF00, // 0xFF00 + //~^ decimal_literal_representation 0x7F0F_F00F, // 0x7F0F_F00F + //~^ decimal_literal_representation 0x7FFF_FFFF, // 0x7FFF_FFFF + //~^ decimal_literal_representation #[allow(overflowing_literals)] 0xF0F0_F0F0, // 0xF0F0_F0F0 + //~^ decimal_literal_representation 0x8005_usize, // 0x8005_usize + //~^ decimal_literal_representation 0x7F0F_F00F_isize, // 0x7F0F_F00F_isize + //~^ decimal_literal_representation ); } diff --git a/tests/ui/decimal_literal_representation.rs b/tests/ui/decimal_literal_representation.rs index bcc4d0df9c0e..85dc4fac0928 100644 --- a/tests/ui/decimal_literal_representation.rs +++ b/tests/ui/decimal_literal_representation.rs @@ -14,12 +14,19 @@ fn main() { ); let bad = ( // Hex: 32_773, // 0x8005 + //~^ decimal_literal_representation 65_280, // 0xFF00 + //~^ decimal_literal_representation 2_131_750_927, // 0x7F0F_F00F + //~^ decimal_literal_representation 2_147_483_647, // 0x7FFF_FFFF + //~^ decimal_literal_representation #[allow(overflowing_literals)] 4_042_322_160, // 0xF0F0_F0F0 + //~^ decimal_literal_representation 32_773usize, // 0x8005_usize + //~^ decimal_literal_representation 2_131_750_927isize, // 0x7F0F_F00F_isize + //~^ decimal_literal_representation ); } diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr index 824e7ec85ee0..0196350ce402 100644 --- a/tests/ui/decimal_literal_representation.stderr +++ b/tests/ui/decimal_literal_representation.stderr @@ -8,37 +8,37 @@ LL | 32_773, // 0x8005 = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:17:9 + --> tests/ui/decimal_literal_representation.rs:18:9 | LL | 65_280, // 0xFF00 | ^^^^^^ help: consider: `0xFF00` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:18:9 + --> tests/ui/decimal_literal_representation.rs:20:9 | LL | 2_131_750_927, // 0x7F0F_F00F | ^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:19:9 + --> tests/ui/decimal_literal_representation.rs:22:9 | LL | 2_147_483_647, // 0x7FFF_FFFF | ^^^^^^^^^^^^^ help: consider: `0x7FFF_FFFF` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:21:9 + --> tests/ui/decimal_literal_representation.rs:25:9 | LL | 4_042_322_160, // 0xF0F0_F0F0 | ^^^^^^^^^^^^^ help: consider: `0xF0F0_F0F0` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:22:9 + --> tests/ui/decimal_literal_representation.rs:27:9 | LL | 32_773usize, // 0x8005_usize | ^^^^^^^^^^^ help: consider: `0x8005_usize` error: integer literal has a better hexadecimal representation - --> tests/ui/decimal_literal_representation.rs:23:9 + --> tests/ui/decimal_literal_representation.rs:29:9 | LL | 2_131_750_927isize, // 0x7F0F_F00F_isize | ^^^^^^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F_isize` diff --git a/tests/ui/declare_interior_mutable_const/enums.rs b/tests/ui/declare_interior_mutable_const/enums.rs index a88bf7b21b8b..0f454786156e 100644 --- a/tests/ui/declare_interior_mutable_const/enums.rs +++ b/tests/ui/declare_interior_mutable_const/enums.rs @@ -9,7 +9,8 @@ enum OptionalCell { } // a constant with enums should be linted only when the used variant is unfrozen (#3962). -const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR: interior mutable +const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); +//~^ declare_interior_mutable_const const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; const fn unfrozen_variant() -> OptionalCell { @@ -20,7 +21,8 @@ const fn frozen_variant() -> OptionalCell { OptionalCell::Frozen } -const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR: interior mutable +const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); +//~^ declare_interior_mutable_const const FROZEN_VARIANT_FROM_FN: OptionalCell = frozen_variant(); enum NestedInnermost { @@ -43,7 +45,8 @@ struct NestedOutermost { // a constant with enums should be linted according to its value, no matter how structs involve. const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { - //~^ ERROR: interior mutable +//~^ declare_interior_mutable_const + outer: NestedOuter::NestedInner(NestedInner { inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), }), @@ -57,11 +60,14 @@ const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost { trait AssocConsts { // When there's no default value, lint it only according to its type. // Further details are on the corresponding code (`NonCopyConst::check_trait_item`). - const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR: interior mutable - const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR: interior mutable +const TO_BE_UNFROZEN_VARIANT: OptionalCell; +//~^ declare_interior_mutable_const +const TO_BE_FROZEN_VARIANT: OptionalCell; +//~^ declare_interior_mutable_const // Lint default values accordingly. - const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR: interior mutable +const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); +//~^ declare_interior_mutable_const const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; } @@ -87,7 +93,8 @@ trait AssocTypes { impl AssocTypes for u64 { type ToBeUnfrozen = AtomicUsize; - const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR: interior mutable +const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); +//~^ declare_interior_mutable_const const TO_BE_FROZEN_VARIANT: Option = None; } @@ -99,25 +106,30 @@ enum BothOfCellAndGeneric { } impl BothOfCellAndGeneric { - const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR: interior mutable +const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); +//~^ declare_interior_mutable_const // This is a false positive. The argument about this is on `is_value_unfrozen_raw` - const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR: interior mutable +const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); +//~^ declare_interior_mutable_const const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); // This is what is likely to be a false negative when one tries to fix // the `GENERIC_VARIANT` false positive. - const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR: interior mutable +const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); +//~^ declare_interior_mutable_const } // associated types here is basically the same as the one above. trait BothOfCellAndGenericWithAssocType { type AssocType; - const UNFROZEN_VARIANT: BothOfCellAndGeneric = //~ ERROR: interior mutable +const UNFROZEN_VARIANT: BothOfCellAndGeneric = +//~^ declare_interior_mutable_const BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); - const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR: interior mutable +const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); +//~^ declare_interior_mutable_const const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); } diff --git a/tests/ui/declare_interior_mutable_const/enums.stderr b/tests/ui/declare_interior_mutable_const/enums.stderr index 22329172c3af..a6f14ec71feb 100644 --- a/tests/ui/declare_interior_mutable_const/enums.stderr +++ b/tests/ui/declare_interior_mutable_const/enums.stderr @@ -9,7 +9,7 @@ LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(tru = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:23:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:24:1 | LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,10 +17,11 @@ LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); = help: consider making this `Sync` so that it can go in a static item or using a `thread_local` error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:45:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:47:1 | LL | / const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { LL | | +LL | | LL | | outer: NestedOuter::NestedInner(NestedInner { LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), LL | | }), @@ -30,59 +31,60 @@ LL | | }; = help: consider making this a static item error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:60:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:63:1 | -LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:61:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:65:1 | -LL | const TO_BE_FROZEN_VARIANT: OptionalCell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_FROZEN_VARIANT: OptionalCell; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:64:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:69:1 | -LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:90:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:96:1 | -LL | const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:102:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:109:1 | -LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:105:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:113:1 | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:111:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:120:1 | -LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:118:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:128:1 | -LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric = +LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric = +LL | | LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); | |____________________________________________________________________^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:120:5 + --> tests/ui/declare_interior_mutable_const/enums.rs:131:1 | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 12 previous errors diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs index 0dccf18c4930..9820626ae454 100644 --- a/tests/ui/declare_interior_mutable_const/others.rs +++ b/tests/ui/declare_interior_mutable_const/others.rs @@ -7,15 +7,19 @@ use std::ptr; use std::sync::Once; use std::sync::atomic::AtomicUsize; -const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR: interior mutable -const CELL: Cell = Cell::new(6); //~ ERROR: interior mutable +const ATOMIC: AtomicUsize = AtomicUsize::new(5); +//~^ declare_interior_mutable_const +const CELL: Cell = Cell::new(6); +//~^ declare_interior_mutable_const const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); -//~^ ERROR: interior mutable +//~^ declare_interior_mutable_const + macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { const $name: $ty = $e; - //~^ ERROR: interior mutable + //~^ declare_interior_mutable_const + }; } declare_const!(_ONCE: Once = Once::new()); @@ -43,6 +47,7 @@ mod issue_8493 { macro_rules! issue_8493 { () => { const _BAZ: Cell = Cell::new(0); + //~^ declare_interior_mutable_const static _FOOBAR: () = { thread_local! { static _VAR: Cell = const { Cell::new(0) }; diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr index 4a7251471424..3c388e3bcf37 100644 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ b/tests/ui/declare_interior_mutable_const/others.stderr @@ -9,7 +9,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:11:1 + --> tests/ui/declare_interior_mutable_const/others.rs:12:1 | LL | const CELL: Cell = Cell::new(6); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | const CELL: Cell = Cell::new(6); = help: consider making this `Sync` so that it can go in a static item or using a `thread_local` error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:12:1 + --> tests/ui/declare_interior_mutable_const/others.rs:14:1 | LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], V = help: consider making this a static item error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:17:9 + --> tests/ui/declare_interior_mutable_const/others.rs:20:9 | LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | declare_const!(_ONCE: Once = Once::new()); = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:45:13 + --> tests/ui/declare_interior_mutable_const/others.rs:49:13 | LL | const _BAZ: Cell = Cell::new(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs index 490073f97fb1..83d6c1307ea2 100644 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ b/tests/ui/declare_interior_mutable_const/traits.rs @@ -7,13 +7,15 @@ use std::sync::atomic::AtomicUsize; macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { const $name: $ty = $e; - //~^ ERROR: interior mutable + //~^ declare_interior_mutable_const + }; } // a constant whose type is a concrete type should be linted at the definition site. trait ConcreteTypes { - const ATOMIC: AtomicUsize; //~ ERROR: interior mutable +const ATOMIC: AtomicUsize; +//~^ declare_interior_mutable_const const INTEGER: u64; const STRING: String; declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); @@ -41,7 +43,8 @@ trait GenericTypes { impl GenericTypes for u64 { const TO_REMAIN_GENERIC: T = T::DEFAULT; - const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR: interior mutable +const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); +//~^ declare_interior_mutable_const } // a helper type used below @@ -66,8 +69,10 @@ impl AssocTypes for Vec { type ToBeGenericParam = T; const TO_BE_FROZEN: Self::ToBeFrozen = 12; - const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR: interior mutable - const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); //~ ERROR: interior mutable +const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); +//~^ declare_interior_mutable_const +const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); +//~^ declare_interior_mutable_const const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper = Wrapper(T::DEFAULT); } @@ -86,7 +91,8 @@ where T: AssocTypesHelper, { const NOT_BOUNDED: T::NotToBeBounded; - const BOUNDED: T::ToBeBounded; //~ ERROR: interior mutable +const BOUNDED: T::ToBeBounded; +//~^ declare_interior_mutable_const } impl AssocTypesFromGenericParam for u64 @@ -114,19 +120,24 @@ impl SelfType for u64 { impl SelfType for AtomicUsize { // this (interior mutable `Self` const) exists in `parking_lot`. // `const_trait_impl` will replace it in the future, hopefully. - const SELF: Self = AtomicUsize::new(17); //~ ERROR: interior mutable - const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); //~ ERROR: interior mutable +const SELF: Self = AtomicUsize::new(17); +//~^ declare_interior_mutable_const +const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); +//~^ declare_interior_mutable_const } // Even though a constant contains a generic type, if it also have an interior mutable type, // it should be linted at the definition site. trait BothOfCellAndGeneric { - const DIRECT: Cell; //~ ERROR: interior mutable - const INDIRECT: Cell<*const T>; //~ ERROR: interior mutable +const DIRECT: Cell; +//~^ declare_interior_mutable_const +const INDIRECT: Cell<*const T>; +//~^ declare_interior_mutable_const } impl BothOfCellAndGeneric for u64 { - const DIRECT: Cell = Cell::new(T::DEFAULT); //~ ERROR: interior mutable +const DIRECT: Cell = Cell::new(T::DEFAULT); +//~^ declare_interior_mutable_const const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null()); } @@ -138,13 +149,15 @@ impl Local where T: ConstDefault + AssocTypesHelper, { - const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR: interior mutable +const ATOMIC: AtomicUsize = AtomicUsize::new(18); +//~^ declare_interior_mutable_const const COW: Cow<'static, str> = Cow::Borrowed("tuvwxy"); const GENERIC_TYPE: T = T::DEFAULT; const ASSOC_TYPE: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED; - const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR: interior mutable +const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); +//~^ declare_interior_mutable_const } fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr index 4a793d985e5e..1be6b9d2ec60 100644 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/tests/ui/declare_interior_mutable_const/traits.stderr @@ -1,8 +1,8 @@ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:16:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:17:1 | -LL | const ATOMIC: AtomicUsize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const ATOMIC: AtomicUsize; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` @@ -19,70 +19,70 @@ LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:44:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:46:1 | -LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:69:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:72:1 | -LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:70:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:74:1 | -LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:89:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:94:1 | -LL | const BOUNDED: T::ToBeBounded; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BOUNDED: T::ToBeBounded; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:117:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:123:1 | -LL | const SELF: Self = AtomicUsize::new(17); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const SELF: Self = AtomicUsize::new(17); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:118:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:125:1 | -LL | const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:124:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:132:1 | -LL | const DIRECT: Cell; - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const DIRECT: Cell; + | ^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:125:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:134:1 | -LL | const INDIRECT: Cell<*const T>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const INDIRECT: Cell<*const T>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:129:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:139:1 | -LL | const DIRECT: Cell = Cell::new(T::DEFAULT); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DIRECT: Cell = Cell::new(T::DEFAULT); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:141:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:152:1 | -LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:147:5 + --> tests/ui/declare_interior_mutable_const/traits.rs:159:1 | -LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 13 previous errors diff --git a/tests/ui/default_constructed_unit_structs.fixed b/tests/ui/default_constructed_unit_structs.fixed index 3047c221d457..fa4d55177823 100644 --- a/tests/ui/default_constructed_unit_structs.fixed +++ b/tests/ui/default_constructed_unit_structs.fixed @@ -9,6 +9,7 @@ impl UnitStruct { fn new() -> Self { //should lint Self + //~^ default_constructed_unit_structs } } @@ -51,6 +52,7 @@ impl NormalStruct { // should lint Self { inner: PhantomData, + //~^ default_constructed_unit_structs } } @@ -124,9 +126,13 @@ mod issue_10755 { fn main() { // should lint let _ = PhantomData::; + //~^ default_constructed_unit_structs let _: PhantomData = PhantomData; + //~^ default_constructed_unit_structs let _: PhantomData = std::marker::PhantomData; + //~^ default_constructed_unit_structs let _ = UnitStruct; + //~^ default_constructed_unit_structs // should not lint let _ = TupleStruct::default(); diff --git a/tests/ui/default_constructed_unit_structs.rs b/tests/ui/default_constructed_unit_structs.rs index 66afedb23801..291cd89da0b7 100644 --- a/tests/ui/default_constructed_unit_structs.rs +++ b/tests/ui/default_constructed_unit_structs.rs @@ -9,6 +9,7 @@ impl UnitStruct { fn new() -> Self { //should lint Self::default() + //~^ default_constructed_unit_structs } } @@ -51,6 +52,7 @@ impl NormalStruct { // should lint Self { inner: PhantomData::default(), + //~^ default_constructed_unit_structs } } @@ -124,9 +126,13 @@ mod issue_10755 { fn main() { // should lint let _ = PhantomData::::default(); + //~^ default_constructed_unit_structs let _: PhantomData = PhantomData::default(); + //~^ default_constructed_unit_structs let _: PhantomData = std::marker::PhantomData::default(); + //~^ default_constructed_unit_structs let _ = UnitStruct::default(); + //~^ default_constructed_unit_structs // should not lint let _ = TupleStruct::default(); diff --git a/tests/ui/default_constructed_unit_structs.stderr b/tests/ui/default_constructed_unit_structs.stderr index c0fa73515c03..6d4e1bdc2cc8 100644 --- a/tests/ui/default_constructed_unit_structs.stderr +++ b/tests/ui/default_constructed_unit_structs.stderr @@ -8,31 +8,31 @@ LL | Self::default() = help: to override `-D warnings` add `#[allow(clippy::default_constructed_unit_structs)]` error: use of `default` to create a unit struct - --> tests/ui/default_constructed_unit_structs.rs:53:31 + --> tests/ui/default_constructed_unit_structs.rs:54:31 | LL | inner: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> tests/ui/default_constructed_unit_structs.rs:126:33 + --> tests/ui/default_constructed_unit_structs.rs:128:33 | LL | let _ = PhantomData::::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> tests/ui/default_constructed_unit_structs.rs:127:42 + --> tests/ui/default_constructed_unit_structs.rs:130:42 | LL | let _: PhantomData = PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> tests/ui/default_constructed_unit_structs.rs:128:55 + --> tests/ui/default_constructed_unit_structs.rs:132:55 | LL | let _: PhantomData = std::marker::PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> tests/ui/default_constructed_unit_structs.rs:129:23 + --> tests/ui/default_constructed_unit_structs.rs:134: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 3298a222bda6..548de9379927 100644 --- a/tests/ui/default_instead_of_iter_empty.fixed +++ b/tests/ui/default_instead_of_iter_empty.fixed @@ -10,8 +10,11 @@ struct Iter { fn main() { // Do lint. let _ = std::iter::empty::(); + //~^ default_instead_of_iter_empty let _ = std::iter::empty::>(); + //~^ default_instead_of_iter_empty let _foo: std::iter::Empty = std::iter::empty(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Vec::::default(); diff --git a/tests/ui/default_instead_of_iter_empty.rs b/tests/ui/default_instead_of_iter_empty.rs index 75b088a99590..824cc20566de 100644 --- a/tests/ui/default_instead_of_iter_empty.rs +++ b/tests/ui/default_instead_of_iter_empty.rs @@ -10,8 +10,11 @@ struct Iter { fn main() { // Do lint. let _ = std::iter::Empty::::default(); + //~^ default_instead_of_iter_empty let _ = std::iter::Empty::>::default(); + //~^ default_instead_of_iter_empty let _foo: std::iter::Empty = std::iter::Empty::default(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Vec::::default(); diff --git a/tests/ui/default_instead_of_iter_empty.stderr b/tests/ui/default_instead_of_iter_empty.stderr index 4bd4d060a3f7..dc0b757adc2e 100644 --- a/tests/ui/default_instead_of_iter_empty.stderr +++ b/tests/ui/default_instead_of_iter_empty.stderr @@ -8,13 +8,13 @@ LL | let _ = std::iter::Empty::::default(); = help: to override `-D warnings` add `#[allow(clippy::default_instead_of_iter_empty)]` error: `std::iter::empty()` is the more idiomatic way - --> tests/ui/default_instead_of_iter_empty.rs:13:13 + --> tests/ui/default_instead_of_iter_empty.rs:14:13 | LL | let _ = std::iter::Empty::>::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::>()` error: `std::iter::empty()` is the more idiomatic way - --> tests/ui/default_instead_of_iter_empty.rs:14:41 + --> tests/ui/default_instead_of_iter_empty.rs:16:41 | LL | let _foo: std::iter::Empty = std::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/default_instead_of_iter_empty_no_std.fixed b/tests/ui/default_instead_of_iter_empty_no_std.fixed index 7300bd9bd2ab..76d75ea7e591 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.fixed +++ b/tests/ui/default_instead_of_iter_empty_no_std.fixed @@ -21,7 +21,9 @@ struct Iter { fn main() { // Do lint. let _ = core::iter::empty::(); + //~^ default_instead_of_iter_empty let _foo: core::iter::Empty = core::iter::empty(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Iter::default(); diff --git a/tests/ui/default_instead_of_iter_empty_no_std.rs b/tests/ui/default_instead_of_iter_empty_no_std.rs index 0bc5c7169d12..639b73ba38de 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.rs +++ b/tests/ui/default_instead_of_iter_empty_no_std.rs @@ -21,7 +21,9 @@ struct Iter { fn main() { // Do lint. let _ = core::iter::Empty::::default(); + //~^ default_instead_of_iter_empty let _foo: core::iter::Empty = core::iter::Empty::default(); + //~^ default_instead_of_iter_empty // Do not lint. let _ = Iter::default(); diff --git a/tests/ui/default_instead_of_iter_empty_no_std.stderr b/tests/ui/default_instead_of_iter_empty_no_std.stderr index eb80da13e850..69812eba5423 100644 --- a/tests/ui/default_instead_of_iter_empty_no_std.stderr +++ b/tests/ui/default_instead_of_iter_empty_no_std.stderr @@ -8,7 +8,7 @@ LL | let _ = core::iter::Empty::::default(); = help: to override `-D warnings` add `#[allow(clippy::default_instead_of_iter_empty)]` error: `core::iter::empty()` is the more idiomatic way - --> tests/ui/default_instead_of_iter_empty_no_std.rs:24:42 + --> tests/ui/default_instead_of_iter_empty_no_std.rs:25:42 | LL | let _foo: core::iter::Empty = core::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::iter::empty()` diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed index 00f0d7644340..a4d66f951f75 100644 --- a/tests/ui/default_numeric_fallback_f64.fixed +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -19,10 +19,20 @@ mod basic_expr { fn test() { // Should lint unsuffixed literals typed `f64`. let x = 0.12_f64; + //~^ default_numeric_fallback let x = [1.0_f64, 2.0_f64, 3.0_f64]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1.0_f64, 2.0_f64) } else { (3.0_f64, 4.0_f64) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = match 1.0_f64 { + //~^ default_numeric_fallback _ => 1.0_f64, + //~^ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,6 +52,7 @@ mod nested_local { let x: _ = { // Should lint this because this literal is not bound to any types. let y = 1.0_f64; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -50,12 +61,14 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. let y = 1.0_f64; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. } else { // Should lint this because this literal is not bound to any types. let y = 1.0_f64; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2. @@ -64,6 +77,7 @@ mod nested_local { const X: f32 = { // Should lint this because this literal is not bound to any types. let y = 1.0_f64; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -80,10 +94,12 @@ mod function_def { // Should lint this because return type is inferred to `f64` and NOT bound to a concrete // type. let f = || -> _ { 1.0_f64 }; + //~^ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. let f = || -> f64 { 1.0_f64 }; + //~^ default_numeric_fallback } } @@ -98,9 +114,11 @@ mod function_calls { // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. generic_arg(1.0_f64); + //~^ default_numeric_fallback // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. let x: _ = generic_arg(1.0_f64); + //~^ default_numeric_fallback } } @@ -119,9 +137,11 @@ mod struct_ctor { // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. GenericStruct { x: 1.0_f64 }; + //~^ default_numeric_fallback // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. let _ = GenericStruct { x: 1.0_f64 }; + //~^ default_numeric_fallback } } @@ -140,6 +160,7 @@ mod enum_ctor { // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. GenericEnum::X(1.0_f64); + //~^ default_numeric_fallback } } @@ -160,6 +181,7 @@ mod method_calls { // Should lint this because the argument type is bound to a concrete type. s.generic_arg(1.0_f64); + //~^ default_numeric_fallback } } @@ -170,6 +192,7 @@ mod in_macro { #[inline_macros] fn internal() { inline!(let x = 22.0_f64;); + //~^ default_numeric_fallback } // Should NOT lint in external macro. diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index 942cedac2753..d1446c35557f 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -19,10 +19,20 @@ mod basic_expr { fn test() { // Should lint unsuffixed literals typed `f64`. let x = 0.12; + //~^ default_numeric_fallback let x = [1., 2., 3.]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1., 2.) } else { (3., 4.) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = match 1. { + //~^ default_numeric_fallback _ => 1., + //~^ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,6 +52,7 @@ mod nested_local { let x: _ = { // Should lint this because this literal is not bound to any types. let y = 1.; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -50,12 +61,14 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. let y = 1.; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. } else { // Should lint this because this literal is not bound to any types. let y = 1.; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2. @@ -64,6 +77,7 @@ mod nested_local { const X: f32 = { // Should lint this because this literal is not bound to any types. let y = 1.; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1. @@ -80,10 +94,12 @@ mod function_def { // Should lint this because return type is inferred to `f64` and NOT bound to a concrete // type. let f = || -> _ { 1. }; + //~^ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. let f = || -> f64 { 1. }; + //~^ default_numeric_fallback } } @@ -98,9 +114,11 @@ mod function_calls { // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. generic_arg(1.); + //~^ default_numeric_fallback // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. let x: _ = generic_arg(1.); + //~^ default_numeric_fallback } } @@ -119,9 +137,11 @@ mod struct_ctor { // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. GenericStruct { x: 1. }; + //~^ default_numeric_fallback // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. let _ = GenericStruct { x: 1. }; + //~^ default_numeric_fallback } } @@ -140,6 +160,7 @@ mod enum_ctor { // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. GenericEnum::X(1.); + //~^ default_numeric_fallback } } @@ -160,6 +181,7 @@ mod method_calls { // Should lint this because the argument type is bound to a concrete type. s.generic_arg(1.); + //~^ default_numeric_fallback } } @@ -170,6 +192,7 @@ mod in_macro { #[inline_macros] fn internal() { inline!(let x = 22.;); + //~^ default_numeric_fallback } // Should NOT lint in external macro. diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index d7e4dbd63771..f9451211e1ac 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -8,133 +8,133 @@ LL | let x = 0.12; = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:22:18 + --> tests/ui/default_numeric_fallback_f64.rs:23:18 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:22:22 + --> tests/ui/default_numeric_fallback_f64.rs:23:22 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:22:26 + --> tests/ui/default_numeric_fallback_f64.rs:23:26 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:23:28 + --> tests/ui/default_numeric_fallback_f64.rs:27:28 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:23:32 + --> tests/ui/default_numeric_fallback_f64.rs:27:32 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:23:46 + --> tests/ui/default_numeric_fallback_f64.rs:27:46 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:23:50 + --> tests/ui/default_numeric_fallback_f64.rs:27:50 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `4.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:24:23 + --> tests/ui/default_numeric_fallback_f64.rs:32:23 | LL | let x = match 1. { | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:25:18 + --> tests/ui/default_numeric_fallback_f64.rs:34:18 | LL | _ => 1., | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:44:21 + --> tests/ui/default_numeric_fallback_f64.rs:54:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:52:21 + --> tests/ui/default_numeric_fallback_f64.rs:63:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:58:21 + --> tests/ui/default_numeric_fallback_f64.rs:70:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:66:21 + --> tests/ui/default_numeric_fallback_f64.rs:79:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:82:27 + --> tests/ui/default_numeric_fallback_f64.rs:96:27 | LL | let f = || -> _ { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:86:29 + --> tests/ui/default_numeric_fallback_f64.rs:101:29 | LL | let f = || -> f64 { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:100:21 + --> tests/ui/default_numeric_fallback_f64.rs:116:21 | LL | generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:103:32 + --> tests/ui/default_numeric_fallback_f64.rs:120:32 | LL | let x: _ = generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:121:28 + --> tests/ui/default_numeric_fallback_f64.rs:139:28 | LL | GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:124:36 + --> tests/ui/default_numeric_fallback_f64.rs:143:36 | LL | let _ = GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:142:24 + --> tests/ui/default_numeric_fallback_f64.rs:162:24 | LL | GenericEnum::X(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:162:23 + --> tests/ui/default_numeric_fallback_f64.rs:183:23 | LL | s.generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_f64.rs:172:25 + --> tests/ui/default_numeric_fallback_f64.rs:194: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 f28ae04fd0a4..e95c49dd6b66 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -18,11 +18,23 @@ mod basic_expr { fn test() { // Should lint unsuffixed literals typed `i32`. let x = 22_i32; + //~^ default_numeric_fallback let x = [1_i32, 2_i32, 3_i32]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1_i32, 2_i32) } else { (3_i32, 4_i32) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = match 1_i32 { + //~^ default_numeric_fallback 1_i32 => 1_i32, + //~^ default_numeric_fallback + //~| default_numeric_fallback _ => 2_i32, + //~^ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,6 +54,7 @@ mod nested_local { let x: _ = { // Should lint this because this literal is not bound to any types. let y = 1_i32; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -50,12 +63,14 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. let y = 1_i32; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 } else { // Should lint this because this literal is not bound to any types. let y = 1_i32; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2 @@ -64,6 +79,7 @@ mod nested_local { const CONST_X: i32 = { // Should lint this because this literal is not bound to any types. let y = 1_i32; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -80,10 +96,12 @@ mod function_def { // Should lint this because return type is inferred to `i32` and NOT bound to a concrete // type. let f = || -> _ { 1_i32 }; + //~^ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. let f = || -> i32 { 1_i32 }; + //~^ default_numeric_fallback } } @@ -98,9 +116,11 @@ mod function_calls { // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. generic_arg(1_i32); + //~^ default_numeric_fallback // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. let x: _ = generic_arg(1_i32); + //~^ default_numeric_fallback } } @@ -119,9 +139,11 @@ mod struct_ctor { // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. GenericStruct { x: 1_i32 }; + //~^ default_numeric_fallback // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. let _ = GenericStruct { x: 1_i32 }; + //~^ default_numeric_fallback } } @@ -140,6 +162,7 @@ mod enum_ctor { // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. GenericEnum::X(1_i32); + //~^ default_numeric_fallback } } @@ -160,6 +183,7 @@ mod method_calls { // Should lint this because the argument type is bound to a concrete type. s.generic_arg(1_i32); + //~^ default_numeric_fallback } } @@ -170,6 +194,7 @@ mod in_macro { #[inline_macros] fn internal() { inline!(let x = 22_i32;); + //~^ default_numeric_fallback } // Should NOT lint in external macro. @@ -212,6 +237,9 @@ mod type_already_inferred { // Should NOT lint in `vec!` call if the type was already stated let data_i32: Vec = vec![1, 2, 3]; let data_i32 = vec![1_i32, 2_i32, 3_i32]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback } } diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index 78a5006444ee..377c8934c5be 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -18,11 +18,23 @@ mod basic_expr { fn test() { // Should lint unsuffixed literals typed `i32`. let x = 22; + //~^ default_numeric_fallback let x = [1, 2, 3]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = if true { (1, 2) } else { (3, 4) }; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback let x = match 1 { + //~^ default_numeric_fallback 1 => 1, + //~^ default_numeric_fallback + //~| default_numeric_fallback _ => 2, + //~^ default_numeric_fallback }; // Should NOT lint suffixed literals. @@ -42,6 +54,7 @@ mod nested_local { let x: _ = { // Should lint this because this literal is not bound to any types. let y = 1; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -50,12 +63,14 @@ mod nested_local { let x: _ = if true { // Should lint this because this literal is not bound to any types. let y = 1; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 } else { // Should lint this because this literal is not bound to any types. let y = 1; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 2 @@ -64,6 +79,7 @@ mod nested_local { const CONST_X: i32 = { // Should lint this because this literal is not bound to any types. let y = 1; + //~^ default_numeric_fallback // Should NOT lint this because this literal is bound to `_` of outer `Local`. 1 @@ -80,10 +96,12 @@ mod function_def { // Should lint this because return type is inferred to `i32` and NOT bound to a concrete // type. let f = || -> _ { 1 }; + //~^ default_numeric_fallback // Even though the output type is specified, // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. let f = || -> i32 { 1 }; + //~^ default_numeric_fallback } } @@ -98,9 +116,11 @@ mod function_calls { // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. generic_arg(1); + //~^ default_numeric_fallback // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. let x: _ = generic_arg(1); + //~^ default_numeric_fallback } } @@ -119,9 +139,11 @@ mod struct_ctor { // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. GenericStruct { x: 1 }; + //~^ default_numeric_fallback // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. let _ = GenericStruct { x: 1 }; + //~^ default_numeric_fallback } } @@ -140,6 +162,7 @@ mod enum_ctor { // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. GenericEnum::X(1); + //~^ default_numeric_fallback } } @@ -160,6 +183,7 @@ mod method_calls { // Should lint this because the argument type is bound to a concrete type. s.generic_arg(1); + //~^ default_numeric_fallback } } @@ -170,6 +194,7 @@ mod in_macro { #[inline_macros] fn internal() { inline!(let x = 22;); + //~^ default_numeric_fallback } // Should NOT lint in external macro. @@ -212,6 +237,9 @@ mod type_already_inferred { // Should NOT lint in `vec!` call if the type was already stated let data_i32: Vec = vec![1, 2, 3]; let data_i32 = vec![1, 2, 3]; + //~^ default_numeric_fallback + //~| default_numeric_fallback + //~| default_numeric_fallback } } diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 67ab923ecf5f..02afbddcb3be 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -8,145 +8,145 @@ LL | let x = 22; = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:21:18 + --> tests/ui/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 - --> tests/ui/default_numeric_fallback_i32.rs:21:21 + --> tests/ui/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 - --> tests/ui/default_numeric_fallback_i32.rs:21:24 + --> tests/ui/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 - --> tests/ui/default_numeric_fallback_i32.rs:22:28 + --> tests/ui/default_numeric_fallback_i32.rs:26:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:31 + --> tests/ui/default_numeric_fallback_i32.rs:26:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:44 + --> tests/ui/default_numeric_fallback_i32.rs:26:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:22:47 + --> tests/ui/default_numeric_fallback_i32.rs:26:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:23:23 + --> tests/ui/default_numeric_fallback_i32.rs:31:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:24:13 + --> tests/ui/default_numeric_fallback_i32.rs:33:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:24:18 + --> tests/ui/default_numeric_fallback_i32.rs:33:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:25:18 + --> tests/ui/default_numeric_fallback_i32.rs:36:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:44:21 + --> tests/ui/default_numeric_fallback_i32.rs:56:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:52:21 + --> tests/ui/default_numeric_fallback_i32.rs:65:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:58:21 + --> tests/ui/default_numeric_fallback_i32.rs:72:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:66:21 + --> tests/ui/default_numeric_fallback_i32.rs:81:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:82:27 + --> tests/ui/default_numeric_fallback_i32.rs:98:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:86:29 + --> tests/ui/default_numeric_fallback_i32.rs:103:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:100:21 + --> tests/ui/default_numeric_fallback_i32.rs:118:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:103:32 + --> tests/ui/default_numeric_fallback_i32.rs:122:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:121:28 + --> tests/ui/default_numeric_fallback_i32.rs:141:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:124:36 + --> tests/ui/default_numeric_fallback_i32.rs:145:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:142:24 + --> tests/ui/default_numeric_fallback_i32.rs:164:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:162:23 + --> tests/ui/default_numeric_fallback_i32.rs:185:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:172:25 + --> tests/ui/default_numeric_fallback_i32.rs:196:25 | LL | inline!(let x = 22;); | ^^ help: consider adding suffix: `22_i32` @@ -154,19 +154,19 @@ LL | inline!(let x = 22;); = note: this error originates in the macro `__inline_mac_fn_internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:214:29 + --> tests/ui/default_numeric_fallback_i32.rs:239:29 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:214:32 + --> tests/ui/default_numeric_fallback_i32.rs:239:32 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> tests/ui/default_numeric_fallback_i32.rs:214:35 + --> tests/ui/default_numeric_fallback_i32.rs:239:35 | LL | let data_i32 = vec![1, 2, 3]; | ^ help: consider adding suffix: `3_i32` diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index 6f1e72c5a6c0..d3fe09a052ef 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -11,16 +11,20 @@ use std::{default, string}; fn main() { let s1: String = String::default(); + //~^ default_trait_access let s2 = String::default(); let s3: String = String::default(); + //~^ default_trait_access let s4: String = String::default(); + //~^ default_trait_access let s5 = string::String::default(); let s6: String = String::default(); + //~^ default_trait_access let s7 = std::string::String::default(); @@ -31,18 +35,22 @@ fn main() { let s10 = DerivedDefault::default(); let s11: GenericDerivedDefault = GenericDerivedDefault::default(); + //~^ default_trait_access let s12 = GenericDerivedDefault::::default(); let s13 = TupleDerivedDefault::default(); let s14: TupleDerivedDefault = TupleDerivedDefault::default(); + //~^ default_trait_access let s15: ArrayDerivedDefault = ArrayDerivedDefault::default(); + //~^ default_trait_access let s16 = ArrayDerivedDefault::default(); let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default(); + //~^ default_trait_access let s18 = TupleStructDerivedDefault::default(); diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index 5528ca8b7936..cdffb2a2ee8c 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -11,16 +11,20 @@ use std::{default, string}; fn main() { let s1: String = Default::default(); + //~^ default_trait_access let s2 = String::default(); let s3: String = D2::default(); + //~^ default_trait_access let s4: String = std::default::Default::default(); + //~^ default_trait_access let s5 = string::String::default(); let s6: String = default::Default::default(); + //~^ default_trait_access let s7 = std::string::String::default(); @@ -31,18 +35,22 @@ fn main() { let s10 = DerivedDefault::default(); let s11: GenericDerivedDefault = Default::default(); + //~^ default_trait_access let s12 = GenericDerivedDefault::::default(); let s13 = TupleDerivedDefault::default(); let s14: TupleDerivedDefault = Default::default(); + //~^ default_trait_access let s15: ArrayDerivedDefault = Default::default(); + //~^ default_trait_access let s16 = ArrayDerivedDefault::default(); let s17: TupleStructDerivedDefault = Default::default(); + //~^ default_trait_access let s18 = TupleStructDerivedDefault::default(); diff --git a/tests/ui/default_trait_access.stderr b/tests/ui/default_trait_access.stderr index 276f03d79df1..aa7eb4f89558 100644 --- a/tests/ui/default_trait_access.stderr +++ b/tests/ui/default_trait_access.stderr @@ -11,43 +11,43 @@ LL | #![deny(clippy::default_trait_access)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `String::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:17:22 + --> tests/ui/default_trait_access.rs:18:22 | LL | let s3: String = D2::default(); | ^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:19:22 + --> tests/ui/default_trait_access.rs:21:22 | LL | let s4: String = std::default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:23:22 + --> tests/ui/default_trait_access.rs:26:22 | LL | let s6: String = default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `GenericDerivedDefault::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:33:46 + --> tests/ui/default_trait_access.rs:37:46 | LL | let s11: GenericDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()` error: calling `TupleDerivedDefault::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:39:36 + --> tests/ui/default_trait_access.rs:44:36 | LL | let s14: TupleDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()` error: calling `ArrayDerivedDefault::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:41:36 + --> tests/ui/default_trait_access.rs:47:36 | LL | let s15: ArrayDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()` error: calling `TupleStructDerivedDefault::default()` is more clear than this expression - --> tests/ui/default_trait_access.rs:45:42 + --> tests/ui/default_trait_access.rs:52:42 | LL | let s17: TupleStructDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()` diff --git a/tests/ui/default_union_representation.rs b/tests/ui/default_union_representation.rs index ba63cde2fa9d..90d1a20e6d8d 100644 --- a/tests/ui/default_union_representation.rs +++ b/tests/ui/default_union_representation.rs @@ -3,7 +3,8 @@ #![allow(clippy::repr_packed_without_abi)] union NoAttribute { - //~^ ERROR: this union has the default representation +//~^ default_union_representation + a: i32, b: u32, } @@ -16,7 +17,8 @@ union ReprC { #[repr(packed)] union ReprPacked { - //~^ ERROR: this union has the default representation +//~^ default_union_representation + a: i32, b: u32, } @@ -35,7 +37,8 @@ union ReprCAlign { #[repr(align(32))] union ReprAlign { - //~^ ERROR: this union has the default representation +//~^ default_union_representation + a: i32, b: u32, } @@ -56,7 +59,8 @@ union ZSTsAndField2 { f3: (), } union ZSTAndTwoFields { - //~^ ERROR: this union has the default representation +//~^ default_union_representation + f0: u32, f1: u64, f2: (), diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index d558a3e8de1b..07c106d4092d 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -3,6 +3,7 @@ error: this union has the default representation | LL | / union NoAttribute { LL | | +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -13,10 +14,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::default_union_representation)]` error: this union has the default representation - --> tests/ui/default_union_representation.rs:18:1 + --> tests/ui/default_union_representation.rs:19:1 | LL | / union ReprPacked { LL | | +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -25,10 +27,11 @@ LL | | } = help: consider annotating `ReprPacked` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> tests/ui/default_union_representation.rs:37:1 + --> tests/ui/default_union_representation.rs:39:1 | LL | / union ReprAlign { LL | | +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -37,10 +40,11 @@ LL | | } = help: consider annotating `ReprAlign` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> tests/ui/default_union_representation.rs:58:1 + --> tests/ui/default_union_representation.rs:61:1 | LL | / union ZSTAndTwoFields { LL | | +LL | | LL | | f0: u32, LL | | f1: u64, LL | | f2: (), diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed index f412c57d6505..35dbd790e890 100644 --- a/tests/ui/deref_addrof.fixed +++ b/tests/ui/deref_addrof.fixed @@ -21,30 +21,39 @@ fn main() { let aref = &a; let b = a; + //~^ deref_addrof let b = get_number(); + //~^ deref_addrof let b = *get_reference(&a); let bytes: Vec = vec![1, 2, 3, 4]; let b = bytes[1..2][0]; + //~^ deref_addrof //This produces a suggestion of 'let b = (a);' which //will trigger the 'unused_parens' lint let b = (a); + //~^ deref_addrof let b = a; + //~^ deref_addrof #[rustfmt::skip] let b = a; + //~^ deref_addrof let b = &a; + //~^ deref_addrof let b = *aref; + //~^ deref_addrof let _ = unsafe { *core::ptr::addr_of!(a) }; let _repeat = [0; 64]; + //~^ deref_addrof // do NOT lint for array as semantic differences with/out `*&`. let _arr = *&[0, 1, 2, 3, 4]; } @@ -55,9 +64,11 @@ pub struct S; impl S { pub fn f(&self) -> &Self { inline!($(@expr self)) + //~^ deref_addrof } #[allow(unused_mut)] // mut will be unused, once the macro is fixed pub fn f_mut(mut self) -> Self { inline!($(@expr self)) + //~^ deref_addrof } } diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs index 67836b0de52d..96d1b92ef7be 100644 --- a/tests/ui/deref_addrof.rs +++ b/tests/ui/deref_addrof.rs @@ -21,30 +21,39 @@ fn main() { let aref = &a; let b = *&a; + //~^ deref_addrof let b = *&get_number(); + //~^ deref_addrof let b = *get_reference(&a); let bytes: Vec = vec![1, 2, 3, 4]; let b = *&bytes[1..2][0]; + //~^ deref_addrof //This produces a suggestion of 'let b = (a);' which //will trigger the 'unused_parens' lint let b = *&(a); + //~^ deref_addrof let b = *(&a); + //~^ deref_addrof #[rustfmt::skip] let b = *((&a)); + //~^ deref_addrof let b = *&&a; + //~^ deref_addrof let b = **&aref; + //~^ deref_addrof let _ = unsafe { *core::ptr::addr_of!(a) }; let _repeat = *&[0; 64]; + //~^ deref_addrof // do NOT lint for array as semantic differences with/out `*&`. let _arr = *&[0, 1, 2, 3, 4]; } @@ -55,9 +64,11 @@ pub struct S; impl S { pub fn f(&self) -> &Self { inline!(*& $(@expr self)) + //~^ deref_addrof } #[allow(unused_mut)] // mut will be unused, once the macro is fixed pub fn f_mut(mut self) -> Self { inline!(*&mut $(@expr self)) + //~^ deref_addrof } } diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr index 20069f746c81..81414b625b2f 100644 --- a/tests/ui/deref_addrof.stderr +++ b/tests/ui/deref_addrof.stderr @@ -8,55 +8,55 @@ LL | let b = *&a; = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:25:13 + --> tests/ui/deref_addrof.rs:26:13 | LL | let b = *&get_number(); | ^^^^^^^^^^^^^^ help: try: `get_number()` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:30:13 + --> tests/ui/deref_addrof.rs:32:13 | LL | let b = *&bytes[1..2][0]; | ^^^^^^^^^^^^^^^^ help: try: `bytes[1..2][0]` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:34:13 + --> tests/ui/deref_addrof.rs:37:13 | LL | let b = *&(a); | ^^^^^ help: try: `(a)` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:36:13 + --> tests/ui/deref_addrof.rs:40:13 | LL | let b = *(&a); | ^^^^^ help: try: `a` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:39:13 + --> tests/ui/deref_addrof.rs:44:13 | LL | let b = *((&a)); | ^^^^^^^ help: try: `a` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:41:13 + --> tests/ui/deref_addrof.rs:47:13 | LL | let b = *&&a; | ^^^^ help: try: `&a` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:43:14 + --> tests/ui/deref_addrof.rs:50:14 | LL | let b = **&aref; | ^^^^^^ help: try: `aref` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:47:19 + --> tests/ui/deref_addrof.rs:55:19 | LL | let _repeat = *&[0; 64]; | ^^^^^^^^^ help: try: `[0; 64]` error: immediately dereferencing a reference - --> tests/ui/deref_addrof.rs:57:17 + --> tests/ui/deref_addrof.rs:66:17 | LL | inline!(*& $(@expr self)) | ^^^^^^^^^^^^^^^^ help: try: `$(@expr self)` @@ -64,7 +64,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 - --> tests/ui/deref_addrof.rs:61:17 + --> tests/ui/deref_addrof.rs:71: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 6f997875777e..928907f516a4 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -8,13 +8,15 @@ 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` + //~^ deref_addrof + + { let mut x = 10; let y = *&mut x; - //~^ ERROR: immediately dereferencing a reference + //~^ deref_addrof + } { @@ -22,6 +24,7 @@ fn main() { //will trigger the 'clippy::deref_addrof' lint again let mut x = 10; let y = **&mut &mut x; - //~^ ERROR: immediately dereferencing a reference + //~^ deref_addrof + } } diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr index 8905b1424674..8e69f986b056 100644 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -8,13 +8,13 @@ LL | let b = **&&a; = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference - --> tests/ui/deref_addrof_double_trigger.rs:16:17 + --> tests/ui/deref_addrof_double_trigger.rs:17:17 | LL | let y = *&mut x; | ^^^^^^^ help: try: `x` error: immediately dereferencing a reference - --> tests/ui/deref_addrof_double_trigger.rs:24:18 + --> tests/ui/deref_addrof_double_trigger.rs:26:18 | LL | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try: `&mut x` diff --git a/tests/ui/deref_addrof_macro.rs b/tests/ui/deref_addrof_macro.rs index c7e60f365060..452ccd173a16 100644 --- a/tests/ui/deref_addrof_macro.rs +++ b/tests/ui/deref_addrof_macro.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:proc_macros.rs #![warn(clippy::deref_addrof)] diff --git a/tests/ui/deref_by_slicing.fixed b/tests/ui/deref_by_slicing.fixed index 87b33b1f881d..78a8f292bc9a 100644 --- a/tests/ui/deref_by_slicing.fixed +++ b/tests/ui/deref_by_slicing.fixed @@ -6,27 +6,37 @@ use std::io::Read; fn main() { let mut vec = vec![0]; let _ = &*vec; + //~^ deref_by_slicing let _ = &mut *vec; + //~^ deref_by_slicing let ref_vec = &mut vec; let _ = &**ref_vec; + //~^ deref_by_slicing let mut_slice = &mut **ref_vec; + //~^ deref_by_slicing let _ = &mut *mut_slice; // Err, re-borrows slice + //~^ deref_by_slicing let s = String::new(); let _ = &*s; + //~^ deref_by_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &*S; // Err, re-borrows slice + //~^ deref_by_slicing let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; let _ = *slice_ref; // Err, derefs slice + //~^ deref_by_slicing let bytes: &[u8] = &[]; let _ = (&*bytes).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice + //~^ deref_by_slicing // issue 12751 let a = &mut [1, 2, 3][..]; let _ = &*a; + //~^ deref_by_slicing } diff --git a/tests/ui/deref_by_slicing.rs b/tests/ui/deref_by_slicing.rs index 8d8882a1781e..205cad63ddac 100644 --- a/tests/ui/deref_by_slicing.rs +++ b/tests/ui/deref_by_slicing.rs @@ -6,27 +6,37 @@ use std::io::Read; fn main() { let mut vec = vec![0]; let _ = &vec[..]; + //~^ deref_by_slicing let _ = &mut vec[..]; + //~^ deref_by_slicing let ref_vec = &mut vec; let _ = &ref_vec[..]; + //~^ deref_by_slicing let mut_slice = &mut ref_vec[..]; + //~^ deref_by_slicing let _ = &mut mut_slice[..]; // Err, re-borrows slice + //~^ deref_by_slicing let s = String::new(); let _ = &s[..]; + //~^ deref_by_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Err, re-borrows slice + //~^ deref_by_slicing let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; let _ = &slice_ref[..]; // Err, derefs slice + //~^ deref_by_slicing let bytes: &[u8] = &[]; let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice + //~^ deref_by_slicing // issue 12751 let a = &mut [1, 2, 3][..]; let _ = &a[..]; + //~^ deref_by_slicing } diff --git a/tests/ui/deref_by_slicing.stderr b/tests/ui/deref_by_slicing.stderr index ceb9ab6db73d..a1fda3b3ec50 100644 --- a/tests/ui/deref_by_slicing.stderr +++ b/tests/ui/deref_by_slicing.stderr @@ -8,55 +8,55 @@ LL | let _ = &vec[..]; = help: to override `-D warnings` add `#[allow(clippy::deref_by_slicing)]` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:9:13 + --> tests/ui/deref_by_slicing.rs:10:13 | LL | let _ = &mut vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&mut *vec` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:12:13 + --> tests/ui/deref_by_slicing.rs:14:13 | LL | let _ = &ref_vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&**ref_vec` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:13:21 + --> tests/ui/deref_by_slicing.rs:16:21 | LL | let mut_slice = &mut ref_vec[..]; | ^^^^^^^^^^^^^^^^ help: dereference the original value instead: `&mut **ref_vec` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:14:13 + --> tests/ui/deref_by_slicing.rs:18: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 - --> tests/ui/deref_by_slicing.rs:17:13 + --> tests/ui/deref_by_slicing.rs:22:13 | LL | let _ = &s[..]; | ^^^^^^ help: dereference the original value instead: `&*s` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:20:18 + --> tests/ui/deref_by_slicing.rs:26:18 | LL | let _ = &mut &S[..]; // Err, re-borrows slice | ^^^^^^ help: reborrow the original value instead: `&*S` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:24:13 + --> tests/ui/deref_by_slicing.rs:31:13 | LL | let _ = &slice_ref[..]; // Err, derefs slice | ^^^^^^^^^^^^^^ help: dereference the original value instead: `*slice_ref` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:27:13 + --> tests/ui/deref_by_slicing.rs:35:13 | LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:31:13 + --> tests/ui/deref_by_slicing.rs:40:13 | LL | let _ = &a[..]; | ^^^^^^ help: reborrow the original value instead: `&*a` diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index eb9a007bf10f..1df2d88824b0 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -18,6 +18,7 @@ struct FooDefault<'a> { } impl std::default::Default for FooDefault<'_> { +//~^ derivable_impls fn default() -> Self { Self { a: false, @@ -39,6 +40,7 @@ impl std::default::Default for FooDefault<'_> { struct TupleDefault(bool, i32, u64); impl std::default::Default for TupleDefault { +//~^ derivable_impls fn default() -> Self { Self(false, 0, 0u64) } @@ -91,6 +93,7 @@ impl Default for FooNDVec { struct StrDefault<'a>(&'a str); impl Default for StrDefault<'_> { +//~^ derivable_impls fn default() -> Self { Self("") } @@ -117,6 +120,7 @@ mac!(0); struct Y(u32); impl Default for Y { +//~^ derivable_impls fn default() -> Self { Self(mac!()) } @@ -156,6 +160,7 @@ struct WithoutSelfCurly { } impl Default for WithoutSelfCurly { +//~^ derivable_impls fn default() -> Self { WithoutSelfCurly { a: false } } @@ -164,6 +169,7 @@ impl Default for WithoutSelfCurly { struct WithoutSelfParan(bool); impl Default for WithoutSelfParan { +//~^ derivable_impls fn default() -> Self { WithoutSelfParan(false) } @@ -186,6 +192,7 @@ pub struct DirectDefaultDefaultCall { } impl Default for DirectDefaultDefaultCall { +//~^ derivable_impls fn default() -> Self { // When calling `Default::default()` in all fields, we know it is the same as deriving. Self { v: Default::default() } @@ -197,6 +204,7 @@ pub struct EquivalentToDefaultDefaultCallVec { } impl Default for EquivalentToDefaultDefaultCallVec { +//~^ derivable_impls fn default() -> Self { // The body of `::default()` is `Vec::new()`, so they are equivalent. Self { v: Vec::new() } @@ -224,6 +232,7 @@ pub struct EquivalentToDefaultDefaultCallLocal { } impl Default for EquivalentToDefaultDefaultCallLocal { +//~^ derivable_impls fn default() -> Self { // The body of `::default()` is `S::new()`, so they are equivalent. Self { v: S::new() } @@ -263,6 +272,7 @@ pub struct RepeatDefault1 { } impl Default for RepeatDefault1 { +//~^ derivable_impls fn default() -> Self { RepeatDefault1 { a: [0; 32] } } @@ -297,6 +307,7 @@ pub enum SimpleEnum { } impl Default for SimpleEnum { +//~^ derivable_impls fn default() -> Self { SimpleEnum::Bar } diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index a14c0b28c4ea..0f73ad55a85e 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -2,9 +2,9 @@ error: this `impl` can be derived --> tests/ui/derivable_impls.rs:20:1 | LL | / impl std::default::Default for FooDefault<'_> { +LL | | LL | | fn default() -> Self { LL | | Self { -LL | | a: false, ... | LL | | } | |_^ @@ -18,9 +18,10 @@ LL ~ struct FooDefault<'a> { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:41:1 + --> tests/ui/derivable_impls.rs:42:1 | LL | / impl std::default::Default for TupleDefault { +LL | | LL | | fn default() -> Self { LL | | Self(false, 0, 0u64) LL | | } @@ -34,9 +35,10 @@ LL ~ struct TupleDefault(bool, i32, u64); | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:93:1 + --> tests/ui/derivable_impls.rs:95:1 | LL | / impl Default for StrDefault<'_> { +LL | | LL | | fn default() -> Self { LL | | Self("") LL | | } @@ -50,9 +52,10 @@ LL ~ struct StrDefault<'a>(&'a str); | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:119:1 + --> tests/ui/derivable_impls.rs:122:1 | LL | / impl Default for Y { +LL | | LL | | fn default() -> Self { LL | | Self(mac!()) LL | | } @@ -66,9 +69,10 @@ LL ~ struct Y(u32); | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:158:1 + --> tests/ui/derivable_impls.rs:162:1 | LL | / impl Default for WithoutSelfCurly { +LL | | LL | | fn default() -> Self { LL | | WithoutSelfCurly { a: false } LL | | } @@ -82,9 +86,10 @@ LL ~ struct WithoutSelfCurly { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:166:1 + --> tests/ui/derivable_impls.rs:171:1 | LL | / impl Default for WithoutSelfParan { +LL | | LL | | fn default() -> Self { LL | | WithoutSelfParan(false) LL | | } @@ -98,13 +103,12 @@ LL ~ struct WithoutSelfParan(bool); | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:188:1 + --> tests/ui/derivable_impls.rs:194:1 | LL | / impl Default for DirectDefaultDefaultCall { +LL | | LL | | fn default() -> Self { -LL | | // When calling `Default::default()` in all fields, we know it is the same as deriving. -LL | | Self { v: Default::default() } -LL | | } +... | LL | | } | |_^ | @@ -115,13 +119,12 @@ LL ~ pub struct DirectDefaultDefaultCall { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:199:1 + --> tests/ui/derivable_impls.rs:206:1 | LL | / impl Default for EquivalentToDefaultDefaultCallVec { +LL | | LL | | fn default() -> Self { -LL | | // The body of `::default()` is `Vec::new()`, so they are equivalent. -LL | | Self { v: Vec::new() } -LL | | } +... | LL | | } | |_^ | @@ -132,13 +135,12 @@ LL ~ pub struct EquivalentToDefaultDefaultCallVec { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:226:1 + --> tests/ui/derivable_impls.rs:234:1 | LL | / impl Default for EquivalentToDefaultDefaultCallLocal { +LL | | LL | | fn default() -> Self { -LL | | // The body of `::default()` is `S::new()`, so they are equivalent. -LL | | Self { v: S::new() } -LL | | } +... | LL | | } | |_^ | @@ -149,9 +151,10 @@ LL ~ pub struct EquivalentToDefaultDefaultCallLocal { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:265:1 + --> tests/ui/derivable_impls.rs:274:1 | LL | / impl Default for RepeatDefault1 { +LL | | LL | | fn default() -> Self { LL | | RepeatDefault1 { a: [0; 32] } LL | | } @@ -165,9 +168,10 @@ LL ~ pub struct RepeatDefault1 { | error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:299:1 + --> tests/ui/derivable_impls.rs:309:1 | LL | / impl Default for SimpleEnum { +LL | | LL | | fn default() -> Self { LL | | SimpleEnum::Bar LL | | } diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index dabc06bd7d16..2e8b5959d498 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -11,7 +11,8 @@ struct Qux; impl Clone for Qux { - //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type +//~^ expl_impl_clone_on_copy + fn clone(&self) -> Self { Qux } @@ -36,7 +37,8 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { - //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type +//~^ expl_impl_clone_on_copy + fn clone(&self) -> Self { unimplemented!() } @@ -48,7 +50,8 @@ struct BigArray { } impl Clone for BigArray { - //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type +//~^ expl_impl_clone_on_copy + fn clone(&self) -> Self { unimplemented!() } @@ -60,7 +63,8 @@ struct FnPtr { } impl Clone for FnPtr { - //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type +//~^ expl_impl_clone_on_copy + fn clone(&self) -> Self { unimplemented!() } @@ -81,7 +85,8 @@ impl Clone for Generic { #[derive(Copy)] struct Generic2(T); impl Clone for Generic2 { - //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type +//~^ expl_impl_clone_on_copy + fn clone(&self) -> Self { Self(self.0.clone()) } diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index 0eb4b3c1adaa..bda8800e80a9 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -3,9 +3,9 @@ error: you are implementing `Clone` explicitly on a `Copy` type | LL | / impl Clone for Qux { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | Qux -LL | | } +... | LL | | } | |_^ | @@ -14,99 +14,99 @@ note: consider deriving `Clone` or removing `Copy` | LL | / impl Clone for Qux { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | Qux -LL | | } +... | LL | | } | |_^ = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:38:1 + --> tests/ui/derive.rs:39:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:38:1 + --> tests/ui/derive.rs:39:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:50:1 + --> tests/ui/derive.rs:52:1 | LL | / impl Clone for BigArray { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:50:1 + --> tests/ui/derive.rs:52:1 | LL | / impl Clone for BigArray { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:62:1 + --> tests/ui/derive.rs:65:1 | LL | / impl Clone for FnPtr { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:62:1 + --> tests/ui/derive.rs:65:1 | LL | / impl Clone for FnPtr { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | unimplemented!() -LL | | } +... | LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:83:1 + --> tests/ui/derive.rs:87:1 | LL | / impl Clone for Generic2 { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | Self(self.0.clone()) -LL | | } +... | LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:83:1 + --> tests/ui/derive.rs:87:1 | LL | / impl Clone for Generic2 { LL | | +LL | | LL | | fn clone(&self) -> Self { -LL | | Self(self.0.clone()) -LL | | } +... | LL | | } | |_^ diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs index 1c7e6d1c2023..0a2a1ee7bc9f 100644 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ b/tests/ui/derive_ord_xor_partial_ord.rs @@ -20,7 +20,8 @@ impl PartialOrd for DeriveBoth { } #[derive(Ord, PartialEq, Eq)] -//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly +//~^ derive_ord_xor_partial_ord + struct DeriveOrd; impl PartialOrd for DeriveOrd { @@ -30,7 +31,8 @@ impl PartialOrd for DeriveOrd { } #[derive(Ord, PartialEq, Eq)] -//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly +//~^ derive_ord_xor_partial_ord + struct DeriveOrdWithExplicitTypeVariable; impl PartialOrd for DeriveOrdWithExplicitTypeVariable { @@ -43,7 +45,8 @@ impl PartialOrd for DeriveOrdWithExplicitType struct DerivePartialOrd; impl std::cmp::Ord for DerivePartialOrd { - //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` +//~^ derive_ord_xor_partial_ord + fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } @@ -64,7 +67,8 @@ mod use_ord { struct DerivePartialOrdInUseOrd; impl Ord for DerivePartialOrdInUseOrd { - //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` + //~^ derive_ord_xor_partial_ord + 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 dcf32419baa2..6bbe54eeaa6a 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 - --> tests/ui/derive_ord_xor_partial_ord.rs:26:1 + --> tests/ui/derive_ord_xor_partial_ord.rs:27:1 | LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,49 +14,49 @@ 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 - --> tests/ui/derive_ord_xor_partial_ord.rs:32:10 + --> tests/ui/derive_ord_xor_partial_ord.rs:33:10 | LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> tests/ui/derive_ord_xor_partial_ord.rs:36:1 + --> tests/ui/derive_ord_xor_partial_ord.rs:38: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` - --> tests/ui/derive_ord_xor_partial_ord.rs:45:1 + --> tests/ui/derive_ord_xor_partial_ord.rs:47:1 | LL | / impl std::cmp::Ord for DerivePartialOrd { LL | | +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { -LL | | Ordering::Less -LL | | } +... | LL | | } | |_^ | note: `PartialOrd` implemented here - --> tests/ui/derive_ord_xor_partial_ord.rs:42:10 + --> tests/ui/derive_ord_xor_partial_ord.rs:44: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` - --> tests/ui/derive_ord_xor_partial_ord.rs:66:5 + --> tests/ui/derive_ord_xor_partial_ord.rs:69:5 | LL | / impl Ord for DerivePartialOrdInUseOrd { LL | | +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { -LL | | Ordering::Less -LL | | } +... | LL | | } | |_____^ | note: `PartialOrd` implemented here - --> tests/ui/derive_ord_xor_partial_ord.rs:63:14 + --> tests/ui/derive_ord_xor_partial_ord.rs:66:14 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ diff --git a/tests/ui/derive_partial_eq_without_eq.fixed b/tests/ui/derive_partial_eq_without_eq.fixed index e4a33193a1ab..00f51d6acb94 100644 --- a/tests/ui/derive_partial_eq_without_eq.fixed +++ b/tests/ui/derive_partial_eq_without_eq.fixed @@ -9,6 +9,7 @@ pub struct NotPartialEq { // Eq can be derived but is missing #[derive(Debug, PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct MissingEq { foo: u32, bar: String, @@ -67,33 +68,39 @@ impl PartialEq for ManualPartialEqImpl { // Generic fields should be properly checked for Eq-ness #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct GenericNotEq { foo: T, bar: U, } #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct GenericEq { foo: T, bar: U, } #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct TupleStruct(u32); #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct GenericTupleStruct(T); #[derive(PartialEq)] pub struct TupleStructNotEq(f32); #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub enum Enum { Foo(u32), Bar { a: String, b: () }, } #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub enum GenericEnum { Foo(T), Bar { a: U, b: V }, @@ -107,9 +114,11 @@ pub enum EnumNotEq { // Ensure that rustfix works properly when `PartialEq` has other derives on either side #[derive(Debug, PartialEq, Eq, Clone)] +//~^ derive_partial_eq_without_eq pub struct RustFixWithOtherDerives; #[derive(PartialEq, Eq)] +//~^ derive_partial_eq_without_eq pub struct Generic(T); #[derive(PartialEq, Eq)] @@ -117,9 +126,11 @@ pub struct GenericPhantom(core::marker::PhantomData); mod _hidden { #[derive(PartialEq, Eq)] + //~^ derive_partial_eq_without_eq pub struct Reexported; #[derive(PartialEq, Eq)] + //~^ derive_partial_eq_without_eq pub struct InPubFn; #[derive(PartialEq)] @@ -180,7 +191,8 @@ mod struct_gen { } #[derive(PartialEq, Eq)] - //~^ ERROR: you are deriving `PartialEq` and can implement `Eq` + //~^ derive_partial_eq_without_eq + pub struct Foo(::Element); #[derive(PartialEq, Eq)] @@ -188,7 +200,8 @@ mod struct_gen { // issue 9319 #[derive(PartialEq, Eq)] - //~^ ERROR: you are deriving `PartialEq` and can implement `Eq` + //~^ derive_partial_eq_without_eq + pub struct Oof(T); #[derive(PartialEq, Eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.rs b/tests/ui/derive_partial_eq_without_eq.rs index a418b38e3499..073330468d31 100644 --- a/tests/ui/derive_partial_eq_without_eq.rs +++ b/tests/ui/derive_partial_eq_without_eq.rs @@ -9,6 +9,7 @@ pub struct NotPartialEq { // Eq can be derived but is missing #[derive(Debug, PartialEq)] +//~^ derive_partial_eq_without_eq pub struct MissingEq { foo: u32, bar: String, @@ -67,33 +68,39 @@ impl PartialEq for ManualPartialEqImpl { // Generic fields should be properly checked for Eq-ness #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub struct GenericNotEq { foo: T, bar: U, } #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub struct GenericEq { foo: T, bar: U, } #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub struct TupleStruct(u32); #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub struct GenericTupleStruct(T); #[derive(PartialEq)] pub struct TupleStructNotEq(f32); #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub enum Enum { Foo(u32), Bar { a: String, b: () }, } #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub enum GenericEnum { Foo(T), Bar { a: U, b: V }, @@ -107,9 +114,11 @@ pub enum EnumNotEq { // Ensure that rustfix works properly when `PartialEq` has other derives on either side #[derive(Debug, PartialEq, Clone)] +//~^ derive_partial_eq_without_eq pub struct RustFixWithOtherDerives; #[derive(PartialEq)] +//~^ derive_partial_eq_without_eq pub struct Generic(T); #[derive(PartialEq, Eq)] @@ -117,9 +126,11 @@ pub struct GenericPhantom(core::marker::PhantomData); mod _hidden { #[derive(PartialEq)] + //~^ derive_partial_eq_without_eq pub struct Reexported; #[derive(PartialEq)] + //~^ derive_partial_eq_without_eq pub struct InPubFn; #[derive(PartialEq)] @@ -180,7 +191,8 @@ mod struct_gen { } #[derive(PartialEq)] - //~^ ERROR: you are deriving `PartialEq` and can implement `Eq` + //~^ derive_partial_eq_without_eq + pub struct Foo(::Element); #[derive(PartialEq, Eq)] @@ -188,7 +200,8 @@ mod struct_gen { // issue 9319 #[derive(PartialEq)] - //~^ ERROR: you are deriving `PartialEq` and can implement `Eq` + //~^ derive_partial_eq_without_eq + pub struct Oof(T); #[derive(PartialEq, Eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.stderr b/tests/ui/derive_partial_eq_without_eq.stderr index 7436114fadb2..fd9bac28a711 100644 --- a/tests/ui/derive_partial_eq_without_eq.stderr +++ b/tests/ui/derive_partial_eq_without_eq.stderr @@ -8,19 +8,13 @@ LL | #[derive(Debug, PartialEq)] = help: to override `-D warnings` add `#[allow(clippy::derive_partial_eq_without_eq)]` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:69:10 + --> tests/ui/derive_partial_eq_without_eq.rs:70:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:75:10 - | -LL | #[derive(PartialEq)] - | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` - -error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:81:10 + --> tests/ui/derive_partial_eq_without_eq.rs:77:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` @@ -32,49 +26,55 @@ LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:90:10 + --> tests/ui/derive_partial_eq_without_eq.rs:88:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:96:10 + --> tests/ui/derive_partial_eq_without_eq.rs:95:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:109:17 + --> tests/ui/derive_partial_eq_without_eq.rs:102:10 + | +LL | #[derive(PartialEq)] + | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` + +error: you are deriving `PartialEq` and can implement `Eq` + --> tests/ui/derive_partial_eq_without_eq.rs:116:17 | LL | #[derive(Debug, PartialEq, Clone)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:112:10 + --> tests/ui/derive_partial_eq_without_eq.rs:120:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:119:14 + --> tests/ui/derive_partial_eq_without_eq.rs:128:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:122:14 + --> tests/ui/derive_partial_eq_without_eq.rs:132:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:182:14 + --> tests/ui/derive_partial_eq_without_eq.rs:193:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> tests/ui/derive_partial_eq_without_eq.rs:190:14 + --> tests/ui/derive_partial_eq_without_eq.rs:202:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` diff --git a/tests/ui/derived_hash_with_manual_eq.rs b/tests/ui/derived_hash_with_manual_eq.rs index 8423699d99ed..88b574add3f2 100644 --- a/tests/ui/derived_hash_with_manual_eq.rs +++ b/tests/ui/derived_hash_with_manual_eq.rs @@ -10,7 +10,8 @@ impl PartialEq for Foo { } #[derive(Hash)] -//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly +//~^ derived_hash_with_manual_eq + struct Bar; impl PartialEq for Bar { @@ -20,7 +21,8 @@ impl PartialEq for Bar { } #[derive(Hash)] -//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly +//~^ derived_hash_with_manual_eq + 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 af4d247f95ba..19a24e752810 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 - --> tests/ui/derived_hash_with_manual_eq.rs:16:1 + --> tests/ui/derived_hash_with_manual_eq.rs:17: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 - --> tests/ui/derived_hash_with_manual_eq.rs:22:10 + --> tests/ui/derived_hash_with_manual_eq.rs:23:10 | LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> tests/ui/derived_hash_with_manual_eq.rs:26:1 + --> tests/ui/derived_hash_with_manual_eq.rs:28:1 | LL | impl PartialEq for Baz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/disallowed_names.rs b/tests/ui/disallowed_names.rs index 96531bf8d88c..d6e26dfcf202 100644 --- a/tests/ui/disallowed_names.rs +++ b/tests/ui/disallowed_names.rs @@ -10,16 +10,20 @@ #![warn(clippy::disallowed_names)] fn test(foo: ()) {} -//~^ ERROR: use of a disallowed/placeholder name `foo` -//~| NOTE: `-D clippy::disallowed-names` implied by `-D warnings` +//~^ disallowed_names + + fn main() { let foo = 42; - //~^ ERROR: use of a disallowed/placeholder name `foo` + //~^ disallowed_names + let baz = 42; - //~^ ERROR: use of a disallowed/placeholder name `baz` + //~^ disallowed_names + let quux = 42; - //~^ ERROR: use of a disallowed/placeholder name `quux` + //~^ disallowed_names + // 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. @@ -31,33 +35,43 @@ 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` + //~^ disallowed_names + //~| disallowed_names + //~| disallowed_names + + + _ => (), } } fn issue_1647(mut foo: u8) { - //~^ ERROR: use of a disallowed/placeholder name `foo` +//~^ disallowed_names + let mut baz = 0; - //~^ ERROR: use of a disallowed/placeholder name `baz` + //~^ disallowed_names + if let Some(mut quux) = Some(42) {} - //~^ ERROR: use of a disallowed/placeholder name `quux` + //~^ disallowed_names + } fn issue_1647_ref() { let ref baz = 0; - //~^ ERROR: use of a disallowed/placeholder name `baz` + //~^ disallowed_names + if let Some(ref quux) = Some(42) {} - //~^ ERROR: use of a disallowed/placeholder name `quux` + //~^ disallowed_names + } fn issue_1647_ref_mut() { let ref mut baz = 0; - //~^ ERROR: use of a disallowed/placeholder name `baz` + //~^ disallowed_names + if let Some(ref mut quux) = Some(42) {} - //~^ ERROR: use of a disallowed/placeholder name `quux` + //~^ disallowed_names + } #[cfg(test)] diff --git a/tests/ui/disallowed_names.stderr b/tests/ui/disallowed_names.stderr index d131cad8e11e..e412d27e7fca 100644 --- a/tests/ui/disallowed_names.stderr +++ b/tests/ui/disallowed_names.stderr @@ -8,79 +8,79 @@ LL | fn test(foo: ()) {} = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:17:9 + --> tests/ui/disallowed_names.rs:18:9 | LL | let foo = 42; | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:19:9 + --> tests/ui/disallowed_names.rs:21:9 | LL | let baz = 42; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:21:9 + --> tests/ui/disallowed_names.rs:24:9 | LL | let quux = 42; | ^^^^ error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:33:10 + --> tests/ui/disallowed_names.rs:37:10 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:33:20 + --> tests/ui/disallowed_names.rs:37:20 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:33:26 + --> tests/ui/disallowed_names.rs:37:26 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:41:19 + --> tests/ui/disallowed_names.rs:48:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:43:13 + --> tests/ui/disallowed_names.rs:51:13 | LL | let mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:45:21 + --> tests/ui/disallowed_names.rs:54:21 | LL | if let Some(mut quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:50:13 + --> tests/ui/disallowed_names.rs:60:13 | LL | let ref baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:52:21 + --> tests/ui/disallowed_names.rs:63:21 | LL | if let Some(ref quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:57:17 + --> tests/ui/disallowed_names.rs:69:17 | LL | let ref mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:59:25 + --> tests/ui/disallowed_names.rs:72: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 6b68fae318c0..00308d0063a8 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -9,8 +9,10 @@ fn main() { // Cyrillic is not allowed by default. let счётчик = 10; - //~^ ERROR: identifier `счётчик` has a Unicode script that is not allowed by configura + //~^ disallowed_script_idents + // Same for japanese. let カウンタ = 10; - //~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuratio + //~^ disallowed_script_idents + } diff --git a/tests/ui/disallowed_script_idents.stderr b/tests/ui/disallowed_script_idents.stderr index c11655ab6021..edbcea5e5dd6 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 - --> tests/ui/disallowed_script_idents.rs:14:9 + --> tests/ui/disallowed_script_idents.rs:15:9 | LL | let カウンタ = 10; | ^^^^^^^^ diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index 1abba60fd34a..e3b40a0cae11 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -18,10 +18,12 @@ impl A { fn main() { let b = true; b || diverge(); - //~^ ERROR: sub-expression diverges - //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` + //~^ diverging_sub_expression + + b || A.foo(); - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + } #[allow(dead_code, unused_variables)] @@ -32,28 +34,36 @@ fn foobar() { 4 => return, 5 => continue, 6 => true || return, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + 7 => true || continue, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + 8 => break, 9 => diverge(), 3 => true || diverge(), - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + 10 => match 42 { 99 => return, _ => true || panic!("boo"), - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + }, // lint blocks as well 15 => true || { return; }, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + 16 => false || { return; }, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + // ... and when it's a single expression 17 => true || { return }, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + 18 => false || { return }, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + // ... but not when there's both an expression and a statement 19 => true || { _ = 1; return }, 20 => false || { _ = 1; return }, @@ -63,7 +73,8 @@ fn foobar() { 23 => true || { return; true }, 24 => true || { return; true }, _ => true || break, - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + }; } } diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index f90c95696a9c..617c7a0be8ab 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -8,31 +8,31 @@ LL | b || diverge(); = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:23:10 + --> tests/ui/diverging_sub_expression.rs:24:10 | LL | b || A.foo(); | ^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:34:26 + --> tests/ui/diverging_sub_expression.rs:36:26 | LL | 6 => true || return, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:36:26 + --> tests/ui/diverging_sub_expression.rs:39:26 | LL | 7 => true || continue, | ^^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:40:26 + --> tests/ui/diverging_sub_expression.rs:44:26 | LL | 3 => true || diverge(), | ^^^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:44:30 + --> tests/ui/diverging_sub_expression.rs:49:30 | LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ @@ -40,31 +40,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 - --> tests/ui/diverging_sub_expression.rs:48:29 + --> tests/ui/diverging_sub_expression.rs:54:29 | LL | 15 => true || { return; }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:50:30 + --> tests/ui/diverging_sub_expression.rs:57:30 | LL | 16 => false || { return; }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:53:29 + --> tests/ui/diverging_sub_expression.rs:61:29 | LL | 17 => true || { return }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:55:30 + --> tests/ui/diverging_sub_expression.rs:64:30 | LL | 18 => false || { return }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:65:26 + --> tests/ui/diverging_sub_expression.rs:75:26 | LL | _ => true || break, | ^^^^^ diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed index 83574a5cd98d..5f2b697f88b0 100644 --- a/tests/ui/doc/doc-fixable.fixed +++ b/tests/ui/doc/doc-fixable.fixed @@ -7,13 +7,22 @@ #![rustfmt::skip] /// The `foo_bar` function does _nothing_. See also `foo::bar`. (note the dot there) +//~^ doc_markdown +//~| doc_markdown /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` +//~^ doc_markdown /// which should be reported only once despite being __doubly bad__. /// Here be `::a::global:path`, and _`::another::global::path`_. :: is not a path though. +//~^ doc_markdown +//~| doc_markdown /// Import an item from `::awesome::global::blob::` (Intended postfix) +//~^ doc_markdown /// These are the options for `::Cat`: (Intended trailing single colon, shouldn't be linted) +//~^ doc_markdown /// That's not code ~`NotInCodeBlock`~. +//~^ doc_markdown /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn foo_bar() { } @@ -28,6 +37,7 @@ fn foo_bar() { /// _foo bar_ /// ~~~ /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn multiline_codeblock() { } @@ -35,6 +45,7 @@ fn multiline_codeblock() { /// multiline /// emphasis_. /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn test_emphasis() { } @@ -49,6 +60,7 @@ fn test_emphasis() { /// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb /// NaN /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn test_units() { } @@ -77,6 +89,7 @@ fn test_units() { /// MinGW /// CamelCase (see also #2395) /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn test_allowed() { } @@ -94,6 +107,7 @@ fn test_allowed() { /// expression of the type `_ m c` (where `` /// is one of {`&`, '|'} and `` is one of {`!=`, `>=`, `>` , /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn main() { foo_bar(); multiline_codeblock(); @@ -102,12 +116,16 @@ fn main() { } /// ## `CamelCaseThing` +//~^ doc_markdown /// Talks about `CamelCaseThing`. Titles should be ignored; see issue #897. /// /// # `CamelCaseThing` +//~^ doc_markdown /// /// Not a title #897 `CamelCaseThing` +//~^ doc_markdown /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn issue897() { } @@ -115,6 +133,7 @@ fn issue897() { /// I am confused by brackets? (foo `x_y`) /// I am confused by brackets? (`x_y` foo) /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn issue900() { } @@ -128,6 +147,7 @@ fn issue900() { /// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html /// [helper_types]: ../helper_types/index.html /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn issue883() { } @@ -146,6 +166,9 @@ That's in a code block: `PackedNode` And `BarQuz` too. `be_sure_we_got_to_the_end_of_it` */ +//~^^^ doc_markdown +//~^^^ doc_markdown +//~^^^^^^^^^^ doc_markdown fn issue1073() { } @@ -157,6 +180,9 @@ That's in a code block: PackedNode And `BarQuz` too. `be_sure_we_got_to_the_end_of_it` */ +//~^^ doc_markdown +//~^^^^ doc_markdown +//~^^^^^^^^^^ doc_markdown fn issue1073_alt() { } @@ -167,6 +193,7 @@ fn issue1073_alt() { /// StillDont /// ```` /// `be_sure_we_got_to_the_end_of_it` +//~^ doc_markdown fn four_quotes() { } @@ -186,6 +213,7 @@ fn issue_1469() {} fn issue_1920() {} /// An iterator over `mycrate::Collection`'s values. +//~^ doc_markdown /// It should not lint a `'static` lifetime in ticks. fn issue_2210() {} @@ -210,6 +238,7 @@ fn intra_doc_link() {} fn issue_2581() {} /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` +//~^ doc_markdown fn lint_after_escaped_chars() {} // issue #7033 - generic_const_exprs ICE @@ -233,17 +262,22 @@ where [(); N.checked_next_power_of_two().unwrap()]: { fn issue_11568() {} /// There is no try (`do()` or `do_not()`). +//~^ doc_markdown +//~| doc_markdown fn parenthesized_word() {} /// `ABes` +//~^ doc_markdown /// OSes /// UXes fn plural_acronym_test() {} extern "C" { /// `foo()` + //~^ doc_markdown fn in_extern(); } /// +//~^ doc_markdown fn check_autofix_for_base_urls() {} diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs index 20fe89cdc536..ed3925694c67 100644 --- a/tests/ui/doc/doc-fixable.rs +++ b/tests/ui/doc/doc-fixable.rs @@ -7,13 +7,22 @@ #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) +//~^ doc_markdown +//~| doc_markdown /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun +//~^ doc_markdown /// which should be reported only once despite being __doubly bad__. /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. +//~^ doc_markdown +//~| doc_markdown /// Import an item from ::awesome::global::blob:: (Intended postfix) +//~^ doc_markdown /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) +//~^ doc_markdown /// That's not code ~NotInCodeBlock~. +//~^ doc_markdown /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn foo_bar() { } @@ -28,6 +37,7 @@ fn foo_bar() { /// _foo bar_ /// ~~~ /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn multiline_codeblock() { } @@ -35,6 +45,7 @@ fn multiline_codeblock() { /// multiline /// emphasis_. /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn test_emphasis() { } @@ -49,6 +60,7 @@ fn test_emphasis() { /// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb /// NaN /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn test_units() { } @@ -77,6 +89,7 @@ fn test_units() { /// MinGW /// CamelCase (see also #2395) /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn test_allowed() { } @@ -94,6 +107,7 @@ fn test_allowed() { /// expression of the type `_ m c` (where `` /// is one of {`&`, '|'} and `` is one of {`!=`, `>=`, `>` , /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn main() { foo_bar(); multiline_codeblock(); @@ -102,12 +116,16 @@ fn main() { } /// ## CamelCaseThing +//~^ doc_markdown /// Talks about `CamelCaseThing`. Titles should be ignored; see issue #897. /// /// # CamelCaseThing +//~^ doc_markdown /// /// Not a title #897 CamelCaseThing +//~^ doc_markdown /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn issue897() { } @@ -115,6 +133,7 @@ fn issue897() { /// I am confused by brackets? (foo `x_y`) /// I am confused by brackets? (`x_y` foo) /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn issue900() { } @@ -128,6 +147,7 @@ fn issue900() { /// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html /// [helper_types]: ../helper_types/index.html /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn issue883() { } @@ -146,6 +166,9 @@ That's in a code block: `PackedNode` And BarQuz too. be_sure_we_got_to_the_end_of_it */ +//~^^^ doc_markdown +//~^^^ doc_markdown +//~^^^^^^^^^^ doc_markdown fn issue1073() { } @@ -157,6 +180,9 @@ That's in a code block: PackedNode And BarQuz too. be_sure_we_got_to_the_end_of_it */ +//~^^ doc_markdown +//~^^^^ doc_markdown +//~^^^^^^^^^^ doc_markdown fn issue1073_alt() { } @@ -167,6 +193,7 @@ fn issue1073_alt() { /// StillDont /// ```` /// be_sure_we_got_to_the_end_of_it +//~^ doc_markdown fn four_quotes() { } @@ -186,6 +213,7 @@ fn issue_1469() {} fn issue_1920() {} /// An iterator over mycrate::Collection's values. +//~^ doc_markdown /// It should not lint a `'static` lifetime in ticks. fn issue_2210() {} @@ -210,6 +238,7 @@ fn intra_doc_link() {} fn issue_2581() {} /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint +//~^ doc_markdown fn lint_after_escaped_chars() {} // issue #7033 - generic_const_exprs ICE @@ -233,17 +262,22 @@ where [(); N.checked_next_power_of_two().unwrap()]: { fn issue_11568() {} /// There is no try (do() or do_not()). +//~^ doc_markdown +//~| doc_markdown fn parenthesized_word() {} /// ABes +//~^ doc_markdown /// OSes /// UXes fn plural_acronym_test() {} extern "C" { /// foo() + //~^ doc_markdown fn in_extern(); } /// https://github.com/rust-lang/rust-clippy/pull/12836 +//~^ doc_markdown fn check_autofix_for_base_urls() {} diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index 27a04e4b5583..f630f72ca854 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -23,7 +23,7 @@ LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot | ~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:10:83 + --> tests/ui/doc/doc-fixable.rs:12:83 | LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun | ^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. B | ~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:12:13 + --> tests/ui/doc/doc-fixable.rs:15:13 | LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. | ^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | /// Here be `::a::global:path`, and _::another::global::path_. :: is not a | ~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:12:36 + --> tests/ui/doc/doc-fixable.rs:15:36 | LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though. | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | /// Here be ::a::global:path, and _`::another::global::path`_. :: is not a | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:13:25 + --> tests/ui/doc/doc-fixable.rs:18:25 | LL | /// Import an item from ::awesome::global::blob:: (Intended postfix) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | /// Import an item from `::awesome::global::blob::` (Intended postfix) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:14:31 + --> tests/ui/doc/doc-fixable.rs:20:31 | LL | /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted) | ^^^^^ @@ -78,7 +78,7 @@ LL | /// These are the options for `::Cat`: (Intended trailing single colon, sho | ~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:15:22 + --> tests/ui/doc/doc-fixable.rs:22:22 | LL | /// That's not code ~NotInCodeBlock~. | ^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | /// That's not code ~`NotInCodeBlock`~. | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:16:5 + --> tests/ui/doc/doc-fixable.rs:24:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:30:5 + --> tests/ui/doc/doc-fixable.rs:39:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:37:5 + --> tests/ui/doc/doc-fixable.rs:47:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:51:5 + --> tests/ui/doc/doc-fixable.rs:62:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:79:5 + --> tests/ui/doc/doc-fixable.rs:91:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:96:5 + --> tests/ui/doc/doc-fixable.rs:109:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:104:8 + --> tests/ui/doc/doc-fixable.rs:118:8 | LL | /// ## CamelCaseThing | ^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | /// ## `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:107:7 + --> tests/ui/doc/doc-fixable.rs:122:7 | LL | /// # CamelCaseThing | ^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | /// # `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:109:22 + --> tests/ui/doc/doc-fixable.rs:125:22 | LL | /// Not a title #897 CamelCaseThing | ^^^^^^^^^^^^^^ @@ -188,7 +188,7 @@ LL | /// Not a title #897 `CamelCaseThing` | ~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:110:5 + --> tests/ui/doc/doc-fixable.rs:127:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:117:5 + --> tests/ui/doc/doc-fixable.rs:135:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +210,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:130:5 + --> tests/ui/doc/doc-fixable.rs:149:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -221,7 +221,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:141:43 + --> tests/ui/doc/doc-fixable.rs:161:43 | LL | /** E.g., serialization of an empty list: FooBar | ^^^^^^ @@ -232,7 +232,7 @@ LL | /** E.g., serialization of an empty list: `FooBar` | ~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:146:5 + --> tests/ui/doc/doc-fixable.rs:166:5 | LL | And BarQuz too. | ^^^^^^ @@ -243,7 +243,7 @@ LL | And `BarQuz` too. | ~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:147:1 + --> tests/ui/doc/doc-fixable.rs:167:1 | LL | be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -254,7 +254,7 @@ LL | `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:152:43 + --> tests/ui/doc/doc-fixable.rs:175:43 | LL | /** E.g., serialization of an empty list: FooBar | ^^^^^^ @@ -265,7 +265,7 @@ LL | /** E.g., serialization of an empty list: `FooBar` | ~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:157:5 + --> tests/ui/doc/doc-fixable.rs:180:5 | LL | And BarQuz too. | ^^^^^^ @@ -276,7 +276,7 @@ LL | And `BarQuz` too. | ~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:158:1 + --> tests/ui/doc/doc-fixable.rs:181:1 | LL | be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | `be_sure_we_got_to_the_end_of_it` | error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:169:5 + --> tests/ui/doc/doc-fixable.rs:195:5 | LL | /// be_sure_we_got_to_the_end_of_it | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -298,7 +298,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it` | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:188:22 + --> tests/ui/doc/doc-fixable.rs:215:22 | LL | /// An iterator over mycrate::Collection's values. | ^^^^^^^^^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL | /// An iterator over `mycrate::Collection`'s values. | ~~~~~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:212:34 + --> tests/ui/doc/doc-fixable.rs:240:34 | LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint | ^^^^^^^^^^^^^^^ @@ -320,7 +320,7 @@ LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` | ~~~~~~~~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:235:22 + --> tests/ui/doc/doc-fixable.rs:264:22 | LL | /// There is no try (do() or do_not()). | ^^^^ @@ -331,7 +331,7 @@ LL | /// There is no try (`do()` or do_not()). | ~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:235:30 + --> tests/ui/doc/doc-fixable.rs:264:30 | LL | /// There is no try (do() or do_not()). | ^^^^^^^^ @@ -342,7 +342,7 @@ LL | /// There is no try (do() or `do_not()`). | ~~~~~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:238:5 + --> tests/ui/doc/doc-fixable.rs:269:5 | LL | /// ABes | ^^^^ @@ -353,7 +353,7 @@ LL | /// `ABes` | ~~~~~~ error: item in documentation is missing backticks - --> tests/ui/doc/doc-fixable.rs:244:9 + --> tests/ui/doc/doc-fixable.rs:276:9 | LL | /// foo() | ^^^^^ @@ -364,7 +364,7 @@ LL | /// `foo()` | ~~~~~~~ error: you should put bare URLs between `<`/`>` or make a proper Markdown link - --> tests/ui/doc/doc-fixable.rs:248:5 + --> tests/ui/doc/doc-fixable.rs:281:5 | LL | /// https://github.com/rust-lang/rust-clippy/pull/12836 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `` diff --git a/tests/ui/doc/doc_include_without_cfg.fixed b/tests/ui/doc/doc_include_without_cfg.fixed index d4ae810d7385..a05954adf5a5 100644 --- a/tests/ui/doc/doc_include_without_cfg.fixed +++ b/tests/ui/doc/doc_include_without_cfg.fixed @@ -1,7 +1,8 @@ #![warn(clippy::doc_include_without_cfg)] // Should not lint. #![doc(html_playground_url = "https://playground.example.com/")] -#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg +#![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] +//~^ doc_include_without_cfg // Should not lint. #![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] #![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] @@ -28,7 +29,8 @@ tst! { /// This is a test with no included file } -#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] //~ doc_include_without_cfg +#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))] +//~^ doc_include_without_cfg // Should not lint. #[doc = man_link!("bla", "blob")] #[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] diff --git a/tests/ui/doc/doc_include_without_cfg.rs b/tests/ui/doc/doc_include_without_cfg.rs index c82f6bf20356..26aa7a3a706a 100644 --- a/tests/ui/doc/doc_include_without_cfg.rs +++ b/tests/ui/doc/doc_include_without_cfg.rs @@ -1,7 +1,8 @@ #![warn(clippy::doc_include_without_cfg)] // Should not lint. #![doc(html_playground_url = "https://playground.example.com/")] -#![doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg +#![doc = include_str!("../approx_const.rs")] +//~^ doc_include_without_cfg // Should not lint. #![cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] #![cfg_attr(doc, doc = include_str!("../approx_const.rs"))] @@ -28,7 +29,8 @@ tst! { /// This is a test with no included file } -#[doc = include_str!("../approx_const.rs")] //~ doc_include_without_cfg +#[doc = include_str!("../approx_const.rs")] +//~^ doc_include_without_cfg // Should not lint. #[doc = man_link!("bla", "blob")] #[cfg_attr(feature = "whatever", doc = include_str!("../approx_const.rs"))] diff --git a/tests/ui/doc/doc_include_without_cfg.stderr b/tests/ui/doc/doc_include_without_cfg.stderr index 17ea53c7c318..24991df581e8 100644 --- a/tests/ui/doc/doc_include_without_cfg.stderr +++ b/tests/ui/doc/doc_include_without_cfg.stderr @@ -8,7 +8,7 @@ LL | #![doc = include_str!("../approx_const.rs")] = help: to override `-D warnings` add `#[allow(clippy::doc_include_without_cfg)]` error: included a file in documentation unconditionally - --> tests/ui/doc/doc_include_without_cfg.rs:31:1 + --> tests/ui/doc/doc_include_without_cfg.rs:32:1 | LL | #[doc = include_str!("../approx_const.rs")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `cfg_attr(doc, doc = "...")`: `#[cfg_attr(doc, doc = include_str!("../approx_const.rs"))]` diff --git a/tests/ui/doc/footnote_issue_13183.rs b/tests/ui/doc/footnote_issue_13183.rs index a18b4c3ac539..dbb01bd5155b 100644 --- a/tests/ui/doc/footnote_issue_13183.rs +++ b/tests/ui/doc/footnote_issue_13183.rs @@ -1,3 +1,4 @@ +//@ check-pass // This is a regression test for . // It should not warn on missing backticks on footnote references. diff --git a/tests/ui/doc/issue_12795.fixed b/tests/ui/doc/issue_12795.fixed index ade23bf975c2..ff252c07ae8c 100644 --- a/tests/ui/doc/issue_12795.fixed +++ b/tests/ui/doc/issue_12795.fixed @@ -1,9 +1,13 @@ #![warn(clippy::doc_markdown)] //! A comment with `a_b(x)` and `a_c` in it and (`a_b((c))` ) too and (maybe `a_b((c))`) -//~^ ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks +//~^ doc_markdown +//~| doc_markdown +//~| doc_markdown +//~| doc_markdown + + + + pub fn main() {} diff --git a/tests/ui/doc/issue_12795.rs b/tests/ui/doc/issue_12795.rs index 6d94a07e3036..b7e89cf4ea0e 100644 --- a/tests/ui/doc/issue_12795.rs +++ b/tests/ui/doc/issue_12795.rs @@ -1,9 +1,13 @@ #![warn(clippy::doc_markdown)] //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c))) -//~^ ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks -//~| ERROR: item in documentation is missing backticks +//~^ doc_markdown +//~| doc_markdown +//~| doc_markdown +//~| doc_markdown + + + + pub fn main() {} diff --git a/tests/ui/doc/issue_1832.rs b/tests/ui/doc/issue_1832.rs index 10586f16d466..9678badd11c8 100644 --- a/tests/ui/doc/issue_1832.rs +++ b/tests/ui/doc/issue_1832.rs @@ -1,3 +1,4 @@ +//@ check-pass /// Ok: /// /// Not ok: http://www.unicode.org diff --git a/tests/ui/doc/issue_902.rs b/tests/ui/doc/issue_902.rs index 4b0c835dd3f0..1be6db01dcb2 100644 --- a/tests/ui/doc/issue_902.rs +++ b/tests/ui/doc/issue_902.rs @@ -1,3 +1,4 @@ +//@ check-pass /// See [NIST SP 800-56A, revision 2]. /// /// [NIST SP 800-56A, revision 2]: diff --git a/tests/ui/doc/issue_9473.fixed b/tests/ui/doc/issue_9473.fixed index 276ce7620ca7..2d910c43b263 100644 --- a/tests/ui/doc/issue_9473.fixed +++ b/tests/ui/doc/issue_9473.fixed @@ -6,4 +6,5 @@ pub struct Foo(u32); // Should warn. /// Blah blah blah [FooBar]<[FooBar]>[`FooBar`]. +//~^ doc_markdown pub struct FooBar(u32); diff --git a/tests/ui/doc/issue_9473.rs b/tests/ui/doc/issue_9473.rs index 52527f7106d1..e5798685382a 100644 --- a/tests/ui/doc/issue_9473.rs +++ b/tests/ui/doc/issue_9473.rs @@ -6,4 +6,5 @@ pub struct Foo(u32); // Should warn. /// Blah blah blah [FooBar]<[FooBar]>[FooBar]. +//~^ doc_markdown pub struct FooBar(u32); diff --git a/tests/ui/doc/needless_doctest_main.rs b/tests/ui/doc/needless_doctest_main.rs index f1a2c0575ee5..633a435ca5ed 100644 --- a/tests/ui/doc/needless_doctest_main.rs +++ b/tests/ui/doc/needless_doctest_main.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::needless_doctest_main)] //! issue 10491: //! ```rust,no_test diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 04446787b6c2..8adbb1f7f714 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -5,20 +5,22 @@ #![warn(clippy::doc_markdown)] /// This is a doc comment with `unbalanced_tick marks and several words that -//~^ ERROR: backticks are unbalanced +//~^ empty_line_after_doc_comments + /// 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 +//~^ empty_line_after_doc_comments + /// /// 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() {} @@ -32,15 +34,16 @@ fn in_code_block() {} /// # `Fine` /// /// ## not_fine -//~^ ERROR: item in documentation is missing backticks +//~^ empty_line_after_doc_comments + /// /// ### `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] @@ -51,7 +54,8 @@ fn other_markdown() {} fn issue_7421() {} /// ` -//~^ ERROR: backticks are unbalanced +//~^ empty_line_after_doc_comments + fn escape_0() {} /// Escaped \` backticks don't count. @@ -61,7 +65,8 @@ fn escape_1() {} fn escape_2() {} /// Escaped \` ` backticks don't count, but unescaped backticks do. -//~^ ERROR: backticks are unbalanced +//~^ empty_line_after_doc_comments + fn escape_3() {} /// Backslashes ` \` within code blocks don't count. diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 50324010e97f..563d86376481 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -1,98 +1,112 @@ -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:7:5 +error: empty line after doc comment + --> tests/ui/doc/unbalanced_ticks.rs:7:1 | -LL | /// This is a doc comment with `unbalanced_tick marks and several words that - | _____^ +LL | / /// This is a doc comment with `unbalanced_tick marks and several words that LL | | -LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`. -LL | | /// Because of the initial `unbalanced_tick` pair, the error message is -LL | | /// very `confusing_and_misleading`. - | |____________________________________^ +LL | | + | |_^ +... +LL | fn main() {} + | --------- the comment documents this function | - = help: a backtick may be missing a pair - = note: `-D clippy::doc-markdown` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` + = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` + = help: if the empty line is unintentional remove it +help: if the doc comment should not document `main` comment it out + | +LL | // /// This is a doc comment with `unbalanced_tick marks and several words that + | ++ -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:14:5 +error: empty lines after doc comment + --> tests/ui/doc/unbalanced_ticks.rs:15:1 | -LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / /// This paragraph has `unbalanced_tick marks and should stop_linting. +LL | | +LL | | +LL | | /// +... | +LL | | /// Double unbalanced backtick from ``here to here` should lint. +LL | | + | |_^ +... +LL | fn multiple_paragraphs() {} + | ------------------------ the comment documents this function + | + = help: if the empty lines are unintentional remove them +help: if the doc comment should not document `multiple_paragraphs` comment it out + | +LL ~ // /// This paragraph has `unbalanced_tick marks and should stop_linting. +LL | +LL | +LL ~ // /// +LL ~ // /// This paragraph is fine and should_be linted normally. +LL | +LL ~ // /// +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 - --> tests/ui/doc/unbalanced_ticks.rs:17:32 +error: empty lines after doc comment + --> tests/ui/doc/unbalanced_ticks.rs:36:1 | -LL | /// This paragraph is fine and should_be linted normally. - | ^^^^^^^^^ +LL | / /// ## not_fine +LL | | +LL | | +LL | | /// +... | +LL | | /// - This item needs backticks_here +LL | | + | |_^ +LL | fn other_markdown() {} + | ------------------- the comment documents this function | -help: try + = help: if the empty lines are unintentional remove them +help: if the doc comment should not document `other_markdown` comment it out + | +LL ~ // /// # `Fine` +LL ~ // /// +LL ~ // /// ## not_fine +LL | +LL | +LL ~ // /// +LL ~ // /// ### `unbalanced +LL | +LL ~ // /// +LL ~ // /// - This `item has unbalanced tick marks +LL | +LL ~ // /// - This item needs backticks_here | -LL | /// This paragraph is fine and `should_be` linted normally. - | ~~~~~~~~~~~ -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:20:5 +error: empty line after doc comment + --> tests/ui/doc/unbalanced_ticks.rs:56:1 | -LL | /// Double unbalanced backtick from ``here to here` should lint. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / /// ` +LL | | +LL | | + | |_^ +LL | fn escape_0() {} + | ------------- the comment documents this function | - = help: a backtick may be missing a pair + = help: if the empty line is unintentional remove it +help: if the doc comment should not document `escape_0` comment it out + | +LL | // /// ` + | ++ -error: item in documentation is missing backticks - --> tests/ui/doc/unbalanced_ticks.rs:34:8 +error: empty line after doc comment + --> tests/ui/doc/unbalanced_ticks.rs:67:1 | -LL | /// ## not_fine - | ^^^^^^^^ +LL | / /// Escaped \` ` backticks don't count, but unescaped backticks do. +LL | | +LL | | + | |_^ +LL | fn escape_3() {} + | ------------- the comment documents this function | -help: try + = help: if the empty line is unintentional remove it +help: if the doc comment should not document `escape_3` comment it out | -LL | /// ## `not_fine` - | ~~~~~~~~~~ +LL | // /// Escaped \` ` backticks don't count, but unescaped backticks do. + | ++ -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:37:5 - | -LL | /// ### `unbalanced - | ^^^^^^^^^^^^^^^ - | - = help: a backtick may be missing a pair - -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:40:5 - | -LL | /// - This `item has unbalanced tick marks - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: a backtick may be missing a pair - -error: item in documentation is missing backticks - --> tests/ui/doc/unbalanced_ticks.rs:42:23 - | -LL | /// - This item needs backticks_here - | ^^^^^^^^^^^^^^ - | -help: try - | -LL | /// - This item needs `backticks_here` - | ~~~~~~~~~~~~~~~~ - -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:53:5 - | -LL | /// ` - | ^ - | - = help: a backtick may be missing a pair - -error: backticks are unbalanced - --> tests/ui/doc/unbalanced_ticks.rs:63:5 - | -LL | /// Escaped \` ` backticks don't count, but unescaped backticks do. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: a backtick may be missing a pair - -error: aborting due to 10 previous errors +error: aborting due to 5 previous errors diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index 9b3783aaf09d..65783b22a58c 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -5,25 +5,29 @@ 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` +//~^ missing_errors_doc + + unimplemented!(); } pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { - //~^ ERROR: docs for function returning `Result` missing `# Errors` section +//~^ missing_errors_doc + unimplemented!(); } /// This is not sufficiently documented. pub fn pub_fn_returning_io_result() -> io::Result<()> { - //~^ ERROR: docs for function returning `Result` missing `# Errors` section +//~^ missing_errors_doc + 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 +//~^ missing_errors_doc + unimplemented!(); } @@ -54,13 +58,15 @@ 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 + //~^ missing_errors_doc + 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 + //~^ missing_errors_doc + unimplemented!(); } @@ -111,7 +117,8 @@ 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 + //~^ missing_errors_doc + /// # Errors /// A description of the errors goes here. diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index c5b9479adace..e719c186e600 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -8,37 +8,37 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { = help: to override `-D warnings` add `#[allow(clippy::missing_errors_doc)]` error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:13:1 + --> tests/ui/doc_errors.rs:14:1 | LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:19:1 + --> tests/ui/doc_errors.rs:21:1 | LL | pub fn pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:25:1 + --> tests/ui/doc_errors.rs:28:1 | LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:56:5 + --> tests/ui/doc_errors.rs:60:5 | LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:62:5 + --> tests/ui/doc_errors.rs:67:5 | LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:113:5 + --> tests/ui/doc_errors.rs:119: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 48e1b1819c6f..e2614e6b4318 100644 --- a/tests/ui/doc_link_with_quotes.rs +++ b/tests/ui/doc_link_with_quotes.rs @@ -1,18 +1,18 @@ #![warn(clippy::doc_link_with_quotes)] +#![allow(clippy::empty_line_after_doc_comments)] fn main() { foo() } /// Calls ['bar'] uselessly -//~^ ERROR: possible intra-doc link using quotes instead of backticks -//~| NOTE: `-D clippy::doc-link-with-quotes` implied by `-D warnings` +//~^ doc_link_with_quotes pub fn foo() { bar() } /// Calls ["bar"] uselessly -//~^ ERROR: possible intra-doc link using quotes instead of backticks +//~^ doc_link_with_quotes pub fn foo2() { bar() } diff --git a/tests/ui/doc_link_with_quotes.stderr b/tests/ui/doc_link_with_quotes.stderr index e4be59c65719..1c1d8e0ffd52 100644 --- a/tests/ui/doc_link_with_quotes.stderr +++ b/tests/ui/doc_link_with_quotes.stderr @@ -1,5 +1,5 @@ error: possible intra-doc link using quotes instead of backticks - --> tests/ui/doc_link_with_quotes.rs:7:12 + --> tests/ui/doc_link_with_quotes.rs:8:12 | LL | /// Calls ['bar'] uselessly | ^^^^^ diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index f7f41c915e3f..ccdc59bfb5a2 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -7,6 +7,7 @@ use proc_macros::external; /// This is not sufficiently documented pub unsafe fn destroy_the_planet() { +//~^ missing_safety_doc unimplemented!(); } @@ -30,6 +31,7 @@ mod private_mod { } pub unsafe fn republished() { + //~^ missing_safety_doc unimplemented!(); } } @@ -38,12 +40,14 @@ pub use private_mod::republished; pub trait SafeTraitUnsafeMethods { unsafe fn woefully_underdocumented(self); + //~^ missing_safety_doc /// # Safety unsafe fn at_least_somewhat_documented(self); } pub unsafe trait UnsafeTrait { +//~^ missing_safety_doc fn method(); } @@ -74,6 +78,7 @@ unsafe impl DocumentedUnsafeTrait for Struct { impl Struct { pub unsafe fn more_undocumented_unsafe() -> Self { + //~^ missing_safety_doc unimplemented!(); } @@ -90,6 +95,7 @@ impl Struct { macro_rules! very_unsafe { () => { pub unsafe fn whee() { + //~^ missing_safety_doc unimplemented!() } diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index 929afbceb879..6e128133d498 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -8,31 +8,31 @@ LL | pub unsafe fn destroy_the_planet() { = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]` error: unsafe function's docs are missing a `# Safety` section - --> tests/ui/doc_unsafe.rs:32:5 + --> tests/ui/doc_unsafe.rs:33:5 | LL | pub unsafe fn republished() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs are missing a `# Safety` section - --> tests/ui/doc_unsafe.rs:40:5 + --> tests/ui/doc_unsafe.rs:42:5 | LL | unsafe fn woefully_underdocumented(self); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for unsafe trait missing `# Safety` section - --> tests/ui/doc_unsafe.rs:46:1 + --> tests/ui/doc_unsafe.rs:49:1 | LL | pub unsafe trait UnsafeTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs are missing a `# Safety` section - --> tests/ui/doc_unsafe.rs:76:5 + --> tests/ui/doc_unsafe.rs:80:5 | LL | pub unsafe fn more_undocumented_unsafe() -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe function's docs are missing a `# Safety` section - --> tests/ui/doc_unsafe.rs:92:9 + --> tests/ui/doc_unsafe.rs:97:9 | LL | pub unsafe fn whee() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_comparison.fixed b/tests/ui/double_comparison.fixed index 788f3224b418..e9d707cdb53d 100644 --- a/tests/ui/double_comparison.fixed +++ b/tests/ui/double_comparison.fixed @@ -4,27 +4,35 @@ fn main() { let x = 1; let y = 2; if x <= y { + //~^ double_comparisons // do something } if x <= y { + //~^ double_comparisons // do something } if x >= y { + //~^ double_comparisons // do something } if x >= y { + //~^ double_comparisons // do something } if x != y { + //~^ double_comparisons // do something } if x != y { + //~^ double_comparisons // do something } if x == y { + //~^ double_comparisons // do something } if x == y { + //~^ double_comparisons // do something } } diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs index 245a83d5709d..4b9a141747db 100644 --- a/tests/ui/double_comparison.rs +++ b/tests/ui/double_comparison.rs @@ -4,27 +4,35 @@ fn main() { let x = 1; let y = 2; if x == y || x < y { + //~^ double_comparisons // do something } if x < y || x == y { + //~^ double_comparisons // do something } if x == y || x > y { + //~^ double_comparisons // do something } if x > y || x == y { + //~^ double_comparisons // do something } if x < y || x > y { + //~^ double_comparisons // do something } if x > y || x < y { + //~^ double_comparisons // do something } if x <= y && x >= y { + //~^ double_comparisons // do something } if x >= y && x <= y { + //~^ double_comparisons // do something } } diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr index 01ba7a8ee108..984614c203eb 100644 --- a/tests/ui/double_comparison.stderr +++ b/tests/ui/double_comparison.stderr @@ -8,43 +8,43 @@ LL | if x == y || x < y { = help: to override `-D warnings` add `#[allow(clippy::double_comparisons)]` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:9:8 + --> tests/ui/double_comparison.rs:10:8 | LL | if x < y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:12:8 + --> tests/ui/double_comparison.rs:14:8 | LL | if x == y || x > y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:15:8 + --> tests/ui/double_comparison.rs:18:8 | LL | if x > y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:18:8 + --> tests/ui/double_comparison.rs:22:8 | LL | if x < y || x > y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:21:8 + --> tests/ui/double_comparison.rs:26:8 | LL | if x > y || x < y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:24:8 + --> tests/ui/double_comparison.rs:30:8 | LL | if x <= y && x >= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` error: this binary expression can be simplified - --> tests/ui/double_comparison.rs:27:8 + --> tests/ui/double_comparison.rs:34:8 | LL | if x >= y && x <= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` diff --git a/tests/ui/double_ended_iterator_last.fixed b/tests/ui/double_ended_iterator_last.fixed index 06c48e337537..08f3d4907153 100644 --- a/tests/ui/double_ended_iterator_last.fixed +++ b/tests/ui/double_ended_iterator_last.fixed @@ -3,6 +3,7 @@ // Typical case pub fn last_arg(s: &str) -> Option<&str> { s.split(' ').next_back() + //~^ double_ended_iterator_last } fn main() { @@ -20,6 +21,7 @@ fn main() { } } let _ = DeIterator.next_back(); + //~^ double_ended_iterator_last // Should not apply to other methods of Iterator let _ = DeIterator.count(); diff --git a/tests/ui/double_ended_iterator_last.rs b/tests/ui/double_ended_iterator_last.rs index 9c13b496d117..2c2f311805ef 100644 --- a/tests/ui/double_ended_iterator_last.rs +++ b/tests/ui/double_ended_iterator_last.rs @@ -3,6 +3,7 @@ // Typical case pub fn last_arg(s: &str) -> Option<&str> { s.split(' ').last() + //~^ double_ended_iterator_last } fn main() { @@ -20,6 +21,7 @@ fn main() { } } let _ = DeIterator.last(); + //~^ double_ended_iterator_last // Should not apply to other methods of Iterator let _ = DeIterator.count(); diff --git a/tests/ui/double_ended_iterator_last.stderr b/tests/ui/double_ended_iterator_last.stderr index b795c18a736e..ea1962176a61 100644 --- a/tests/ui/double_ended_iterator_last.stderr +++ b/tests/ui/double_ended_iterator_last.stderr @@ -8,7 +8,7 @@ LL | s.split(' ').last() = help: to override `-D warnings` add `#[allow(clippy::double_ended_iterator_last)]` error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator - --> tests/ui/double_ended_iterator_last.rs:22:24 + --> tests/ui/double_ended_iterator_last.rs:23:24 | LL | let _ = DeIterator.last(); | ^^^^^^ help: try: `next_back()` diff --git a/tests/ui/double_must_use.rs b/tests/ui/double_must_use.rs index 4460aeb075bf..1f69afad25d4 100644 --- a/tests/ui/double_must_use.rs +++ b/tests/ui/double_must_use.rs @@ -3,19 +3,22 @@ #[must_use] pub fn must_use_result() -> Result<(), ()> { - //~^ ERROR: this function has a `#[must_use]` attribute with no message, but returns a type already +//~^ double_must_use + unimplemented!(); } #[must_use] pub fn must_use_tuple() -> (Result<(), ()>, u8) { - //~^ ERROR: this function has a `#[must_use]` attribute with no message, but returns a type already +//~^ double_must_use + unimplemented!(); } #[must_use] pub fn must_use_array() -> [Result<(), ()>; 1] { - //~^ ERROR: this function has a `#[must_use]` attribute with no message, but returns a type already +//~^ double_must_use + unimplemented!(); } @@ -32,7 +35,8 @@ async fn async_must_use() -> usize { #[must_use] async fn async_must_use_result() -> Result<(), ()> { - //~^ ERROR: this function has a `#[must_use]` attribute with no message, but returns a type already +//~^ double_must_use + Ok(()) } diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index b26d1e48a8b8..555dd8902cac 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -9,7 +9,7 @@ LL | pub fn must_use_result() -> Result<(), ()> { = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` - --> tests/ui/double_must_use.rs:11:1 + --> tests/ui/double_must_use.rs:12:1 | LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { = help: either add some descriptive message or remove the attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` - --> tests/ui/double_must_use.rs:17:1 + --> tests/ui/double_must_use.rs:19:1 | LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | pub fn must_use_array() -> [Result<(), ()>; 1] { = help: either add some descriptive message or remove the attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` - --> tests/ui/double_must_use.rs:34:1 + --> tests/ui/double_must_use.rs:37:1 | LL | async fn async_must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_parens.rs b/tests/ui/double_parens.rs index ab1459eed48b..7c976015b4e7 100644 --- a/tests/ui/double_parens.rs +++ b/tests/ui/double_parens.rs @@ -13,28 +13,33 @@ impl DummyStruct { fn simple_double_parens() -> i32 { ((0)) - //~^ ERROR: consider removing unnecessary double parentheses - //~| NOTE: `-D clippy::double-parens` implied by `-D warnings` + //~^ double_parens + + } fn fn_double_parens() { dummy_fn((0)); - //~^ ERROR: consider removing unnecessary double parentheses + //~^ double_parens + } fn method_double_parens(x: DummyStruct) { x.dummy_method((0)); - //~^ ERROR: consider removing unnecessary double parentheses + //~^ double_parens + } fn tuple_double_parens() -> (i32, i32) { ((1, 2)) - //~^ ERROR: consider removing unnecessary double parentheses + //~^ double_parens + } fn unit_double_parens() { (()) - //~^ ERROR: consider removing unnecessary double parentheses + //~^ double_parens + } fn fn_tuple_ok() { @@ -57,7 +62,8 @@ 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 + //~^ double_parens + } fn main() {} diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr index aba301e9f072..e119f54949b1 100644 --- a/tests/ui/double_parens.stderr +++ b/tests/ui/double_parens.stderr @@ -8,31 +8,31 @@ LL | ((0)) = help: to override `-D warnings` add `#[allow(clippy::double_parens)]` error: consider removing unnecessary double parentheses - --> tests/ui/double_parens.rs:21:14 + --> tests/ui/double_parens.rs:22:14 | LL | dummy_fn((0)); | ^^^ error: consider removing unnecessary double parentheses - --> tests/ui/double_parens.rs:26:20 + --> tests/ui/double_parens.rs:28:20 | LL | x.dummy_method((0)); | ^^^ error: consider removing unnecessary double parentheses - --> tests/ui/double_parens.rs:31:5 + --> tests/ui/double_parens.rs:34:5 | LL | ((1, 2)) | ^^^^^^^^ error: consider removing unnecessary double parentheses - --> tests/ui/double_parens.rs:36:5 + --> tests/ui/double_parens.rs:40:5 | LL | (()) | ^^^^ error: consider removing unnecessary double parentheses - --> tests/ui/double_parens.rs:59:16 + --> tests/ui/double_parens.rs:64:16 | LL | assert_eq!(((1, 2)), (1, 2), "Error"); | ^^^^^^^^ diff --git a/tests/ui/drain_collect.fixed b/tests/ui/drain_collect.fixed index 6f597243fe6f..7ae971d975b1 100644 --- a/tests/ui/drain_collect.fixed +++ b/tests/ui/drain_collect.fixed @@ -5,6 +5,7 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn binaryheap(b: &mut BinaryHeap) -> BinaryHeap { std::mem::take(b) + //~^ drain_collect } fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { @@ -13,6 +14,7 @@ fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { fn hashmap(b: &mut HashMap) -> HashMap { std::mem::take(b) + //~^ drain_collect } fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { @@ -21,6 +23,7 @@ fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { fn hashset(b: &mut HashSet) -> HashSet { std::mem::take(b) + //~^ drain_collect } fn hashset_dont_lint(b: &mut HashSet) -> Vec { @@ -29,6 +32,7 @@ fn hashset_dont_lint(b: &mut HashSet) -> Vec { fn vecdeque(b: &mut VecDeque) -> VecDeque { std::mem::take(b) + //~^ drain_collect } fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { @@ -37,23 +41,28 @@ fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { fn vec(b: &mut Vec) -> Vec { std::mem::take(b) + //~^ drain_collect } fn vec2(b: &mut Vec) -> Vec { std::mem::take(b) + //~^ drain_collect } fn vec3(b: &mut Vec) -> Vec { std::mem::take(b) + //~^ drain_collect } fn vec4(b: &mut Vec) -> Vec { std::mem::take(b) + //~^ drain_collect } fn vec_no_reborrow() -> Vec { let mut b = vec![1, 2, 3]; std::mem::take(&mut b) + //~^ drain_collect } fn vec_dont_lint(b: &mut Vec) -> HashSet { @@ -62,6 +71,7 @@ fn vec_dont_lint(b: &mut Vec) -> HashSet { fn string(b: &mut String) -> String { std::mem::take(b) + //~^ drain_collect } fn string_dont_lint(b: &mut String) -> HashSet { diff --git a/tests/ui/drain_collect.rs b/tests/ui/drain_collect.rs index 353aac4da9a4..e99d84fa8b66 100644 --- a/tests/ui/drain_collect.rs +++ b/tests/ui/drain_collect.rs @@ -5,6 +5,7 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn binaryheap(b: &mut BinaryHeap) -> BinaryHeap { b.drain().collect() + //~^ drain_collect } fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { @@ -13,6 +14,7 @@ fn binaryheap_dont_lint(b: &mut BinaryHeap) -> HashSet { fn hashmap(b: &mut HashMap) -> HashMap { b.drain().collect() + //~^ drain_collect } fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { @@ -21,6 +23,7 @@ fn hashmap_dont_lint(b: &mut HashMap) -> Vec<(i32, i32)> { fn hashset(b: &mut HashSet) -> HashSet { b.drain().collect() + //~^ drain_collect } fn hashset_dont_lint(b: &mut HashSet) -> Vec { @@ -29,6 +32,7 @@ fn hashset_dont_lint(b: &mut HashSet) -> Vec { fn vecdeque(b: &mut VecDeque) -> VecDeque { b.drain(..).collect() + //~^ drain_collect } fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { @@ -37,23 +41,28 @@ fn vecdeque_dont_lint(b: &mut VecDeque) -> HashSet { fn vec(b: &mut Vec) -> Vec { b.drain(..).collect() + //~^ drain_collect } fn vec2(b: &mut Vec) -> Vec { b.drain(0..).collect() + //~^ drain_collect } fn vec3(b: &mut Vec) -> Vec { b.drain(..b.len()).collect() + //~^ drain_collect } fn vec4(b: &mut Vec) -> Vec { b.drain(0..b.len()).collect() + //~^ drain_collect } fn vec_no_reborrow() -> Vec { let mut b = vec![1, 2, 3]; b.drain(..).collect() + //~^ drain_collect } fn vec_dont_lint(b: &mut Vec) -> HashSet { @@ -62,6 +71,7 @@ fn vec_dont_lint(b: &mut Vec) -> HashSet { fn string(b: &mut String) -> String { b.drain(..).collect() + //~^ drain_collect } fn string_dont_lint(b: &mut String) -> HashSet { diff --git a/tests/ui/drain_collect.stderr b/tests/ui/drain_collect.stderr index 1dfd0f1e3463..cfb1e01b65cf 100644 --- a/tests/ui/drain_collect.stderr +++ b/tests/ui/drain_collect.stderr @@ -11,25 +11,19 @@ LL | #![deny(clippy::drain_collect)] | ^^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to move all elements into a new `HashMap` - --> tests/ui/drain_collect.rs:15:5 + --> tests/ui/drain_collect.rs:16: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` - --> tests/ui/drain_collect.rs:23:5 + --> tests/ui/drain_collect.rs:25: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` - --> tests/ui/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` - --> tests/ui/drain_collect.rs:39:5 + --> tests/ui/drain_collect.rs:34:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` @@ -37,29 +31,35 @@ LL | b.drain(..).collect() error: you seem to be trying to move all elements into a new `Vec` --> tests/ui/drain_collect.rs:43: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` + --> tests/ui/drain_collect.rs:48: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` - --> tests/ui/drain_collect.rs:47:5 + --> tests/ui/drain_collect.rs:53: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` - --> tests/ui/drain_collect.rs:51:5 + --> tests/ui/drain_collect.rs:58: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` - --> tests/ui/drain_collect.rs:56:5 + --> tests/ui/drain_collect.rs:64: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` - --> tests/ui/drain_collect.rs:64:5 + --> tests/ui/drain_collect.rs:73:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` diff --git a/tests/ui/drain_collect_nostd.fixed b/tests/ui/drain_collect_nostd.fixed index a4ab2956f2a6..4741922d1dc4 100644 --- a/tests/ui/drain_collect_nostd.fixed +++ b/tests/ui/drain_collect_nostd.fixed @@ -5,4 +5,5 @@ use alloc::vec::Vec; fn remove_all(v: &mut Vec) -> Vec { core::mem::take(v) + //~^ drain_collect } diff --git a/tests/ui/drain_collect_nostd.rs b/tests/ui/drain_collect_nostd.rs index a8be1ce6bbd3..69dcb1c41658 100644 --- a/tests/ui/drain_collect_nostd.rs +++ b/tests/ui/drain_collect_nostd.rs @@ -5,4 +5,5 @@ use alloc::vec::Vec; fn remove_all(v: &mut Vec) -> Vec { v.drain(..).collect() + //~^ drain_collect } diff --git a/tests/ui/drop_non_drop.rs b/tests/ui/drop_non_drop.rs index 6dbcb7777d49..0345e8670ab8 100644 --- a/tests/ui/drop_non_drop.rs +++ b/tests/ui/drop_non_drop.rs @@ -20,7 +20,8 @@ fn main() { struct Foo; // Lint drop(Foo); - //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop + //~^ drop_non_drop + // Don't lint drop(make_result(Foo)); // Don't lint @@ -36,7 +37,8 @@ fn main() { struct Baz(T); // Lint drop(Baz(Foo)); - //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop + //~^ drop_non_drop + // Don't lint drop(Baz(Bar)); } diff --git a/tests/ui/drop_non_drop.stderr b/tests/ui/drop_non_drop.stderr index fac89bf1f26a..b431c62c92c5 100644 --- a/tests/ui/drop_non_drop.stderr +++ b/tests/ui/drop_non_drop.stderr @@ -13,13 +13,13 @@ LL | drop(Foo); = help: to override `-D warnings` add `#[allow(clippy::drop_non_drop)]` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> tests/ui/drop_non_drop.rs:38:5 + --> tests/ui/drop_non_drop.rs:39:5 | LL | drop(Baz(Foo)); | ^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> tests/ui/drop_non_drop.rs:38:10 + --> tests/ui/drop_non_drop.rs:39:10 | LL | drop(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index a725538436cb..cb4930363e8f 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -1,8 +1,9 @@ #![warn(clippy::duplicate_underscore_argument)] 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` +//~^ duplicate_underscore_argument + + fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one fn main() { diff --git a/tests/ui/duration_subsec.fixed b/tests/ui/duration_subsec.fixed index 114c516ed1a1..a8c2f78ca383 100644 --- a/tests/ui/duration_subsec.fixed +++ b/tests/ui/duration_subsec.fixed @@ -7,21 +7,26 @@ fn main() { let dur = Duration::new(5, 0); let bad_millis_1 = dur.subsec_millis(); + //~^ duration_subsec let bad_millis_2 = dur.subsec_millis(); + //~^ duration_subsec let good_millis = dur.subsec_millis(); assert_eq!(bad_millis_1, good_millis); assert_eq!(bad_millis_2, good_millis); let bad_micros = dur.subsec_micros(); + //~^ duration_subsec let good_micros = dur.subsec_micros(); assert_eq!(bad_micros, good_micros); // Handle refs let _ = (&dur).subsec_micros(); + //~^ duration_subsec // Handle constants const NANOS_IN_MICRO: u32 = 1_000; let _ = dur.subsec_micros(); + //~^ duration_subsec // Other literals aren't linted let _ = dur.subsec_nanos() / 699; diff --git a/tests/ui/duration_subsec.rs b/tests/ui/duration_subsec.rs index 8469fe086b10..582f4717de27 100644 --- a/tests/ui/duration_subsec.rs +++ b/tests/ui/duration_subsec.rs @@ -7,21 +7,26 @@ fn main() { let dur = Duration::new(5, 0); let bad_millis_1 = dur.subsec_micros() / 1_000; + //~^ duration_subsec let bad_millis_2 = dur.subsec_nanos() / 1_000_000; + //~^ duration_subsec let good_millis = dur.subsec_millis(); assert_eq!(bad_millis_1, good_millis); assert_eq!(bad_millis_2, good_millis); let bad_micros = dur.subsec_nanos() / 1_000; + //~^ duration_subsec let good_micros = dur.subsec_micros(); assert_eq!(bad_micros, good_micros); // Handle refs let _ = (&dur).subsec_nanos() / 1_000; + //~^ duration_subsec // Handle constants const NANOS_IN_MICRO: u32 = 1_000; let _ = dur.subsec_nanos() / NANOS_IN_MICRO; + //~^ duration_subsec // Other literals aren't linted let _ = dur.subsec_nanos() / 699; diff --git a/tests/ui/duration_subsec.stderr b/tests/ui/duration_subsec.stderr index 55e44f149cf1..1a41742e1fa6 100644 --- a/tests/ui/duration_subsec.stderr +++ b/tests/ui/duration_subsec.stderr @@ -8,25 +8,25 @@ LL | let bad_millis_1 = dur.subsec_micros() / 1_000; = help: to override `-D warnings` add `#[allow(clippy::duration_subsec)]` error: calling `subsec_millis()` is more concise than this calculation - --> tests/ui/duration_subsec.rs:10:24 + --> tests/ui/duration_subsec.rs:11: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 - --> tests/ui/duration_subsec.rs:15:22 + --> tests/ui/duration_subsec.rs:17: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 - --> tests/ui/duration_subsec.rs:20:13 + --> tests/ui/duration_subsec.rs:23:13 | LL | let _ = (&dur).subsec_nanos() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&dur).subsec_micros()` error: calling `subsec_micros()` is more concise than this calculation - --> tests/ui/duration_subsec.rs:24:13 + --> tests/ui/duration_subsec.rs:28:13 | LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` diff --git a/tests/ui/eager_transmute.fixed b/tests/ui/eager_transmute.fixed index ba4342462dca..14cbb6113e62 100644 --- a/tests/ui/eager_transmute.fixed +++ b/tests/ui/eager_transmute.fixed @@ -19,20 +19,27 @@ struct Data { fn int_to_opcode(op: u8) -> Option { (op < 4).then(|| unsafe { std::mem::transmute(op) }) + //~^ eager_transmute } fn f(op: u8, op2: Data, unrelated: u8) { true.then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (unrelated < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // lint even when the transmutable goes through field/array accesses let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| unsafe { std::mem::transmute(op2.foo[0]) }); + //~^ eager_transmute // don't lint: wrong index used in the transmute let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[1]) }); @@ -45,11 +52,17 @@ fn f(op: u8, op2: Data, unrelated: u8) { // range contains checks let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // unrelated binding in contains let _: Option = (1..=3) @@ -59,6 +72,7 @@ fn f(op: u8, op2: Data, unrelated: u8) { unsafe fn f2(op: u8) { (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); + //~^ eager_transmute } #[rustc_layout_scalar_valid_range_end(254)] @@ -88,18 +102,21 @@ impls!(NonMaxU8, NonZeroNonMaxU8); fn niche_tests(v1: u8, v2: NonZero, v3: NonZeroNonMaxU8) { // u8 -> NonZero, do lint let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) }); + //~^ eager_transmute // NonZero -> u8, don't lint, target type has no niche and therefore a higher validity range let _: Option = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); // NonZero -> NonMaxU8, do lint, different niche let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); // NonZero -> NonZeroNonMaxU8, do lint, target type has less validity let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute } fn main() {} diff --git a/tests/ui/eager_transmute.rs b/tests/ui/eager_transmute.rs index 9750e87ce574..48d7d50cdaef 100644 --- a/tests/ui/eager_transmute.rs +++ b/tests/ui/eager_transmute.rs @@ -19,20 +19,27 @@ struct Data { fn int_to_opcode(op: u8) -> Option { (op < 4).then_some(unsafe { std::mem::transmute(op) }) + //~^ eager_transmute } fn f(op: u8, op2: Data, unrelated: u8) { true.then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (unrelated < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // lint even when the transmutable goes through field/array accesses let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); + //~^ eager_transmute // don't lint: wrong index used in the transmute let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[1]) }); @@ -45,11 +52,17 @@ fn f(op: u8, op2: Data, unrelated: u8) { // range contains checks let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); + //~^ eager_transmute // unrelated binding in contains let _: Option = (1..=3) @@ -59,6 +72,7 @@ fn f(op: u8, op2: Data, unrelated: u8) { unsafe fn f2(op: u8) { (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); + //~^ eager_transmute } #[rustc_layout_scalar_valid_range_end(254)] @@ -88,18 +102,21 @@ impls!(NonMaxU8, NonZeroNonMaxU8); fn niche_tests(v1: u8, v2: NonZero, v3: NonZeroNonMaxU8) { // u8 -> NonZero, do lint let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); + //~^ eager_transmute // NonZero -> u8, don't lint, target type has no niche and therefore a higher validity range let _: Option = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); // NonZero -> NonMaxU8, do lint, different niche let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute // NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity let _: Option = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) }); // NonZero -> NonZeroNonMaxU8, do lint, target type has less validity let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); + //~^ eager_transmute } fn main() {} diff --git a/tests/ui/eager_transmute.stderr b/tests/ui/eager_transmute.stderr index 5cf7bd49a929..e31c12eb5222 100644 --- a/tests/ui/eager_transmute.stderr +++ b/tests/ui/eager_transmute.stderr @@ -12,7 +12,7 @@ LL | (op < 4).then(|| unsafe { std::mem::transmute(op) }) | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:27:33 + --> tests/ui/eager_transmute.rs:28:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:28:33 + --> tests/ui/eager_transmute.rs:30:33 | LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:29:34 + --> tests/ui/eager_transmute.rs:32:34 | LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:31:68 + --> tests/ui/eager_transmute.rs:35:68 | LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:32:86 + --> tests/ui/eager_transmute.rs:37:86 | LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| u | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:35:84 + --> tests/ui/eager_transmute.rs:41:84 | LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| uns | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:47:70 + --> tests/ui/eager_transmute.rs:54:70 | LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:48:83 + --> tests/ui/eager_transmute.rs:56:83 | LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsa | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:49:69 + --> tests/ui/eager_transmute.rs:58:69 | LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:50:68 + --> tests/ui/eager_transmute.rs:60:68 | LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _: Option = (1..).contains(&op).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:51:68 + --> tests/ui/eager_transmute.rs:62:68 | LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _: Option = (..3).contains(&op).then(|| unsafe { std::mem:: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:52:69 + --> tests/ui/eager_transmute.rs:64:69 | LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem: | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:61:24 + --> tests/ui/eager_transmute.rs:74:24 | LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:90:62 + --> tests/ui/eager_transmute.rs:104:62 | LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transm | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:96:86 + --> tests/ui/eager_transmute.rs:111:86 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| u | ~~~~ ++ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:102:93 + --> tests/ui/eager_transmute.rs:118:93 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/else_if_without_else.rs b/tests/ui/else_if_without_else.rs index b04c22fa2aed..8c0df6ee8786 100644 --- a/tests/ui/else_if_without_else.rs +++ b/tests/ui/else_if_without_else.rs @@ -49,7 +49,8 @@ fn main() { if bla1() { println!("if"); } else if bla2() { - //~^ ERROR: `if` expression with an `else if`, but without a final `else` + //~^ else_if_without_else + println!("else if"); } @@ -58,7 +59,8 @@ fn main() { } else if bla2() { println!("else if 1"); } else if bla3() { - //~^ ERROR: `if` expression with an `else if`, but without a final `else` + //~^ else_if_without_else + println!("else if 2"); } @@ -85,7 +87,8 @@ fn main() { } else if bla4() { println!("else if 3"); } else if bla5() { - //~^ ERROR: `if` expression with an `else if`, but without a final `else` + //~^ else_if_without_else + println!("else if 4"); } @@ -115,7 +118,8 @@ fn main() { } else if bla4() { println!("else if 3"); } else if bla5() { - //~^ ERROR: `if` expression with an `else if`, but without a final `else` + //~^ else_if_without_else + println!("else if 4"); } } diff --git a/tests/ui/else_if_without_else.stderr b/tests/ui/else_if_without_else.stderr index bc7174852293..ac7802345b97 100644 --- a/tests/ui/else_if_without_else.stderr +++ b/tests/ui/else_if_without_else.stderr @@ -4,6 +4,7 @@ error: `if` expression with an `else if`, but without a final `else` LL | } else if bla2() { | ____________^ LL | | +LL | | LL | | println!("else if"); LL | | } | |_____^ @@ -13,11 +14,12 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::else_if_without_else)]` error: `if` expression with an `else if`, but without a final `else` - --> tests/ui/else_if_without_else.rs:60:12 + --> tests/ui/else_if_without_else.rs:61:12 | LL | } else if bla3() { | ____________^ LL | | +LL | | LL | | println!("else if 2"); LL | | } | |_____^ @@ -25,11 +27,12 @@ LL | | } = help: add an `else` block here error: `if` expression with an `else if`, but without a final `else` - --> tests/ui/else_if_without_else.rs:87:12 + --> tests/ui/else_if_without_else.rs:89:12 | LL | } else if bla5() { | ____________^ LL | | +LL | | LL | | println!("else if 4"); LL | | } | |_____^ @@ -37,11 +40,12 @@ LL | | } = help: add an `else` block here error: `if` expression with an `else if`, but without a final `else` - --> tests/ui/else_if_without_else.rs:117:16 + --> tests/ui/else_if_without_else.rs:120:16 | LL | } else if bla5() { | ________________^ LL | | +LL | | LL | | println!("else if 4"); LL | | } | |_________^ diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index 00e64eebc5fb..d7768e07901a 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -7,6 +7,7 @@ mod outer { //! + //~^ empty_docs /// this is a struct struct Bananas { @@ -15,8 +16,10 @@ mod outer { } /// + //~^ empty_docs enum Warn { /// + //~^ empty_docs A, B, } @@ -28,16 +31,19 @@ mod outer { } #[doc = ""] + //~^ empty_docs fn warn_about_this() {} #[doc = ""] #[doc = ""] + //~^^ empty_docs fn this_doesn_warn() {} #[doc = "a fine function"] fn this_is_fine() {} /// + //~^ empty_docs mod inner { /// fn dont_warn_inner_outer() { @@ -51,6 +57,7 @@ mod outer { fn warn() { /*! */ + //~^ empty_docs } fn dont_warn() { @@ -59,6 +66,7 @@ mod outer { trait NoDoc { /// + //~^ empty_docs fn some() {} } } @@ -67,6 +75,7 @@ mod outer { /// lint y x: i32, /// + //~^ empty_docs y: i32, } } diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 5fd7272d7c16..2eba6806852b 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -9,7 +9,7 @@ LL | //! = help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` error: empty doc comment - --> tests/ui/empty_docs.rs:17:5 + --> tests/ui/empty_docs.rs:18:5 | LL | /// | ^^^ @@ -17,7 +17,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:19:9 + --> tests/ui/empty_docs.rs:21:9 | LL | /// | ^^^ @@ -25,7 +25,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:30:13 + --> tests/ui/empty_docs.rs:33:13 | LL | #[doc = ""] | ^^ @@ -33,7 +33,7 @@ LL | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:33:13 + --> tests/ui/empty_docs.rs:37:13 | LL | #[doc = ""] | _____________^ @@ -43,7 +43,7 @@ LL | | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:40:5 + --> tests/ui/empty_docs.rs:45:5 | LL | /// | ^^^ @@ -51,7 +51,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:53:13 + --> tests/ui/empty_docs.rs:59:13 | LL | /*! */ | ^^^^^^ @@ -59,7 +59,7 @@ LL | /*! */ = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:61:13 + --> tests/ui/empty_docs.rs:68:13 | LL | /// | ^^^ @@ -67,7 +67,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:69:9 + --> tests/ui/empty_docs.rs:77:9 | LL | /// | ^^^ diff --git a/tests/ui/empty_drop.rs b/tests/ui/empty_drop.rs index 74822ea50ec7..c2dc7a0193a3 100644 --- a/tests/ui/empty_drop.rs +++ b/tests/ui/empty_drop.rs @@ -5,6 +5,7 @@ struct Foo; impl Drop for Foo { +//~^ empty_drop fn drop(&mut self) {} } @@ -21,6 +22,7 @@ impl Drop for Bar { struct Baz; impl Drop for Baz { +//~^ empty_drop fn drop(&mut self) { {} } diff --git a/tests/ui/empty_drop.stderr b/tests/ui/empty_drop.stderr index d4d020fec30c..3073bf553969 100644 --- a/tests/ui/empty_drop.stderr +++ b/tests/ui/empty_drop.stderr @@ -2,6 +2,7 @@ error: empty drop implementation --> tests/ui/empty_drop.rs:7:1 | LL | / impl Drop for Foo { +LL | | LL | | fn drop(&mut self) {} LL | | } | |_^ @@ -11,9 +12,10 @@ LL | | } = help: try removing this impl error: empty drop implementation - --> tests/ui/empty_drop.rs:23:1 + --> tests/ui/empty_drop.rs:24:1 | LL | / impl Drop for Baz { +LL | | LL | | fn drop(&mut self) { LL | | {} LL | | } diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index 77357c15d957..cc22a76734fe 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -3,6 +3,7 @@ // Enable never type to test empty enum lint #![feature(never_type)] enum Empty {} -//~^ ERROR: enum with no variants +//~^ empty_enum + fn main() {} diff --git a/tests/ui/empty_enum_variants_with_brackets.fixed b/tests/ui/empty_enum_variants_with_brackets.fixed index 1a5e78dd47fe..8316d3b8fd34 100644 --- a/tests/ui/empty_enum_variants_with_brackets.fixed +++ b/tests/ui/empty_enum_variants_with_brackets.fixed @@ -4,15 +4,19 @@ pub enum PublicTestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error - EmptyBraces, //~ ERROR: enum variant has empty brackets - EmptyParentheses, //~ ERROR: enum variant has empty brackets +EmptyBraces, +//~^ empty_enum_variants_with_brackets +EmptyParentheses, +//~^ empty_enum_variants_with_brackets } enum TestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error - EmptyBraces, //~ ERROR: enum variant has empty brackets - EmptyParentheses, //~ ERROR: enum variant has empty brackets +EmptyBraces, +//~^ empty_enum_variants_with_brackets +EmptyParentheses, +//~^ empty_enum_variants_with_brackets AnotherEnum, // No error } diff --git a/tests/ui/empty_enum_variants_with_brackets.rs b/tests/ui/empty_enum_variants_with_brackets.rs index ca20b969a240..6cce2533b979 100644 --- a/tests/ui/empty_enum_variants_with_brackets.rs +++ b/tests/ui/empty_enum_variants_with_brackets.rs @@ -4,15 +4,19 @@ pub enum PublicTestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error - EmptyBraces {}, //~ ERROR: enum variant has empty brackets - EmptyParentheses(), //~ ERROR: enum variant has empty brackets +EmptyBraces {}, +//~^ empty_enum_variants_with_brackets +EmptyParentheses(), +//~^ empty_enum_variants_with_brackets } enum TestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error - EmptyBraces {}, //~ ERROR: enum variant has empty brackets - EmptyParentheses(), //~ ERROR: enum variant has empty brackets +EmptyBraces {}, +//~^ empty_enum_variants_with_brackets +EmptyParentheses(), +//~^ empty_enum_variants_with_brackets AnotherEnum, // No error } diff --git a/tests/ui/empty_enum_variants_with_brackets.stderr b/tests/ui/empty_enum_variants_with_brackets.stderr index 2b187b8f755b..f49e526584c8 100644 --- a/tests/ui/empty_enum_variants_with_brackets.stderr +++ b/tests/ui/empty_enum_variants_with_brackets.stderr @@ -1,34 +1,34 @@ error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:7:16 + --> tests/ui/empty_enum_variants_with_brackets.rs:7:12 | -LL | EmptyBraces {}, - | ^^^ +LL | EmptyBraces {}, + | ^^^ | = note: `-D clippy::empty-enum-variants-with-brackets` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_enum_variants_with_brackets)]` = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:8:21 + --> tests/ui/empty_enum_variants_with_brackets.rs:9:17 | -LL | EmptyParentheses(), - | ^^ +LL | EmptyParentheses(), + | ^^ | = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:14:16 + --> tests/ui/empty_enum_variants_with_brackets.rs:16:12 | -LL | EmptyBraces {}, - | ^^^ +LL | EmptyBraces {}, + | ^^^ | = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:15:21 + --> tests/ui/empty_enum_variants_with_brackets.rs:18:17 | -LL | EmptyParentheses(), - | ^^ +LL | EmptyParentheses(), + | ^^ | = help: remove the brackets diff --git a/tests/ui/empty_enum_without_never_type.rs b/tests/ui/empty_enum_without_never_type.rs index 386677352e29..3661a1537208 100644 --- a/tests/ui/empty_enum_without_never_type.rs +++ b/tests/ui/empty_enum_without_never_type.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(dead_code)] #![warn(clippy::empty_enum)] diff --git a/tests/ui/empty_line_after/doc_comments.1.fixed b/tests/ui/empty_line_after/doc_comments.1.fixed index fd6a94b6a80c..cf2cc497799f 100644 --- a/tests/ui/empty_line_after/doc_comments.1.fixed +++ b/tests/ui/empty_line_after/doc_comments.1.fixed @@ -1,16 +1,18 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] -//~vvv empty_line_after_doc_comments + /// Meant to be an /// inner doc comment /// for the crate +//~^ empty_line_after_doc_comments fn first_in_crate() {} mod m { - //~vvv empty_line_after_doc_comments + /// Meant to be an /// inner doc comment /// for the module + //~^ empty_line_after_doc_comments fn first_in_module() {} } @@ -21,14 +23,16 @@ mod some_mod { fn some_noop() {} } - //~v empty_line_after_doc_comments + /// # Indented + //~^ empty_line_after_doc_comments /// Blank line fn indented() {} } -//~v empty_line_after_doc_comments + /// This should produce a warning +//~^ empty_line_after_doc_comments fn with_doc_and_newline() {} // This should *NOT* produce a warning @@ -36,8 +40,9 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} -//~v empty_line_after_doc_comments + /// This doc comment should produce a warning +//~^ empty_line_after_doc_comments /** This is also a doc comment and is part of the warning */ #[allow(non_camel_case_types)] @@ -46,14 +51,16 @@ fn with_no_newline_and_comment() {} fn three_attributes() {} mod misattributed { - //~v empty_line_after_doc_comments + /// docs for `old_code` + //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} - //~vv empty_line_after_doc_comments + /// Docs /// for OldA + //~^ empty_line_after_doc_comments // struct OldA; /// Docs /// for OldB @@ -65,14 +72,16 @@ mod misattributed { } mod block_comments { - //~v empty_line_after_doc_comments + /** + //~^ empty_line_after_doc_comments * Meant to be inner doc comment */ fn first_in_module() {} - //~v empty_line_after_doc_comments + /** + //~^ empty_line_after_doc_comments * Docs for `old_code` */ /* fn old_code() {} */ @@ -81,8 +90,9 @@ mod block_comments { */ fn new_code() {} - //~v empty_line_after_doc_comments + /// Docs for `old_code2` + //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` fn new_code2() {} diff --git a/tests/ui/empty_line_after/doc_comments.2.fixed b/tests/ui/empty_line_after/doc_comments.2.fixed index 7a57dcd92332..ee02e2f87d2d 100644 --- a/tests/ui/empty_line_after/doc_comments.2.fixed +++ b/tests/ui/empty_line_after/doc_comments.2.fixed @@ -1,17 +1,19 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] -//~vvv empty_line_after_doc_comments -//! Meant to be an -//! inner doc comment -//! for the crate + +// /// Meant to be an +// /// inner doc comment +// /// for the crate +//~^ empty_line_after_doc_comments fn first_in_crate() {} mod m { - //~vvv empty_line_after_doc_comments - //! Meant to be an - //! inner doc comment - //! for the module + + // /// Meant to be an + // /// inner doc comment + // /// for the module + //~^ empty_line_after_doc_comments fn first_in_module() {} } @@ -23,15 +25,18 @@ mod some_mod { fn some_noop() {} } - //~v empty_line_after_doc_comments - /// # Indented - /// + + // /// # Indented + //~^ empty_line_after_doc_comments + /// Blank line fn indented() {} } -//~v empty_line_after_doc_comments -/// This should produce a warning + +// /// This should produce a warning +//~^ empty_line_after_doc_comments + fn with_doc_and_newline() {} // This should *NOT* produce a warning @@ -39,25 +44,30 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} -//~v empty_line_after_doc_comments -/// This doc comment should produce a warning -/** This is also a doc comment and is part of the warning + +// /// This doc comment should produce a warning +//~^ empty_line_after_doc_comments + +/* This is also a doc comment and is part of the warning */ + #[allow(non_camel_case_types)] #[allow(missing_docs)] #[allow(dead_code)] fn three_attributes() {} mod misattributed { - //~v empty_line_after_doc_comments + // /// docs for `old_code` + //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} - //~vv empty_line_after_doc_comments + // /// Docs // /// for OldA + //~^ empty_line_after_doc_comments // struct OldA; // /// Docs @@ -71,15 +81,17 @@ mod misattributed { } mod block_comments { - //~v empty_line_after_doc_comments + /*! + //~^ empty_line_after_doc_comments * Meant to be inner doc comment */ fn first_in_module() {} - //~v empty_line_after_doc_comments + /* + //~^ empty_line_after_doc_comments * Docs for `old_code` */ /* fn old_code() {} */ @@ -89,8 +101,9 @@ mod block_comments { */ fn new_code() {} - //~v empty_line_after_doc_comments + // /// Docs for `old_code2` + //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` diff --git a/tests/ui/empty_line_after/doc_comments.rs b/tests/ui/empty_line_after/doc_comments.rs index 1da761a5c3d5..789f14f39777 100644 --- a/tests/ui/empty_line_after/doc_comments.rs +++ b/tests/ui/empty_line_after/doc_comments.rs @@ -1,17 +1,19 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] -//~vvv empty_line_after_doc_comments + /// Meant to be an /// inner doc comment /// for the crate +//~^ empty_line_after_doc_comments fn first_in_crate() {} mod m { - //~vvv empty_line_after_doc_comments + /// Meant to be an /// inner doc comment /// for the module + //~^ empty_line_after_doc_comments fn first_in_module() {} } @@ -23,15 +25,17 @@ mod some_mod { fn some_noop() {} } - //~v empty_line_after_doc_comments + /// # Indented + //~^ empty_line_after_doc_comments /// Blank line fn indented() {} } -//~v empty_line_after_doc_comments + /// This should produce a warning +//~^ empty_line_after_doc_comments fn with_doc_and_newline() {} @@ -40,8 +44,9 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} -//~v empty_line_after_doc_comments + /// This doc comment should produce a warning +//~^ empty_line_after_doc_comments /** This is also a doc comment and is part of the warning */ @@ -52,15 +57,17 @@ fn with_no_newline_and_comment() {} fn three_attributes() {} mod misattributed { - //~v empty_line_after_doc_comments + /// docs for `old_code` + //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} - //~vv empty_line_after_doc_comments + /// Docs /// for OldA + //~^ empty_line_after_doc_comments // struct OldA; /// Docs @@ -74,15 +81,17 @@ mod misattributed { } mod block_comments { - //~v empty_line_after_doc_comments + /** + //~^ empty_line_after_doc_comments * Meant to be inner doc comment */ fn first_in_module() {} - //~v empty_line_after_doc_comments + /** + //~^ empty_line_after_doc_comments * Docs for `old_code` */ /* fn old_code() {} */ @@ -92,8 +101,9 @@ mod block_comments { */ fn new_code() {} - //~v empty_line_after_doc_comments + /// Docs for `old_code2` + //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index c5d5f3d37594..91745dac3a79 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -2,6 +2,7 @@ error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:6:1 | LL | / /// for the crate +LL | | LL | | | |_^ LL | fn first_in_crate() {} @@ -10,34 +11,36 @@ LL | fn first_in_crate() {} = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` = help: if the empty line is unintentional remove it -help: if the comment should document the crate use an inner doc comment +help: if the doc comment should not document `first_in_crate` comment it out | -LL ~ //! Meant to be an -LL ~ //! inner doc comment -LL ~ //! for the crate +LL ~ // /// Meant to be an +LL ~ // /// inner doc comment +LL ~ // /// for the crate | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:14:5 + --> tests/ui/empty_line_after/doc_comments.rs:15:5 | LL | / /// for the module +LL | | LL | | | |_^ LL | fn first_in_module() {} | -------------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the comment should document the parent module use an inner doc comment +help: if the doc comment should not document `first_in_module` comment it out | -LL ~ //! Meant to be an -LL ~ //! inner doc comment -LL ~ //! for the module +LL ~ // /// Meant to be an +LL ~ // /// inner doc comment +LL ~ // /// for the module | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:27:5 + --> tests/ui/empty_line_after/doc_comments.rs:29:5 | LL | / /// # Indented +LL | | LL | | | |_^ LL | /// Blank line @@ -45,27 +48,33 @@ LL | fn indented() {} | ------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the documentation should include the empty line include it in the comment - | -LL | /// +help: if the doc comment should not document `indented` comment it out | +LL | // /// # Indented + | ++ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:34:1 + --> tests/ui/empty_line_after/doc_comments.rs:37:1 | LL | / /// This should produce a warning +LL | | LL | | | |_^ LL | fn with_doc_and_newline() {} | ------------------------- the comment documents this function | = help: if the empty line is unintentional remove it +help: if the doc comment should not document `with_doc_and_newline` comment it out + | +LL | // /// This should produce a warning + | ++ error: empty lines after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:44:1 + --> tests/ui/empty_line_after/doc_comments.rs:48:1 | LL | / /// This doc comment should produce a warning LL | | +LL | | LL | | /** This is also a doc comment and is part of the warning LL | | */ LL | | @@ -75,12 +84,19 @@ LL | fn three_attributes() {} | --------------------- the comment documents this function | = help: if the empty lines are unintentional remove them +help: if the doc comment should not document `three_attributes` comment it out + | +LL ~ // /// This doc comment should produce a warning +LL | +LL | +LL ~ /* This is also a doc comment and is part of the warning + | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:56:5 + --> tests/ui/empty_line_after/doc_comments.rs:61:5 | LL | / /// docs for `old_code` -LL | | // fn old_code() {} +... | LL | | | |_^ LL | fn new_code() {} @@ -93,12 +109,9 @@ LL | // /// docs for `old_code` | ++ error: empty lines after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:63:5 + --> tests/ui/empty_line_after/doc_comments.rs:69:5 | LL | / /// for OldA -LL | | // struct OldA; -LL | | -LL | | /// Docs ... | LL | | | |_^ @@ -111,6 +124,7 @@ help: if the doc comment should not document `Multiple` comment it out | LL ~ // /// Docs LL ~ // /// for OldA +LL | LL | // struct OldA; LL | LL ~ // /// Docs @@ -118,9 +132,10 @@ LL ~ // /// for OldB | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:78:5 + --> tests/ui/empty_line_after/doc_comments.rs:85:5 | LL | / /** +LL | | LL | | * Meant to be inner doc comment LL | | */ LL | | @@ -135,9 +150,10 @@ LL | /*! | ~ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:85:5 + --> tests/ui/empty_line_after/doc_comments.rs:93:5 | LL | / /** +LL | | LL | | * Docs for `old_code` LL | | */ LL | | /* fn old_code() {} */ @@ -155,9 +171,10 @@ LL + /* | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:96:5 + --> tests/ui/empty_line_after/doc_comments.rs:105:5 | LL | / /// Docs for `old_code2` +LL | | LL | | /* fn old_code2() {} */ LL | | | |_^ diff --git a/tests/ui/empty_loop.rs b/tests/ui/empty_loop.rs index be347563135c..e2d4ff84b56a 100644 --- a/tests/ui/empty_loop.rs +++ b/tests/ui/empty_loop.rs @@ -7,14 +7,17 @@ use proc_macros::{external, inline_macros}; fn should_trigger() { loop {} + //~^ empty_loop #[allow(clippy::never_loop)] loop { loop {} + //~^ empty_loop } #[allow(clippy::never_loop)] 'outer: loop { 'inner: loop {} + //~^ empty_loop } } diff --git a/tests/ui/empty_loop.stderr b/tests/ui/empty_loop.stderr index 3ac93f4ece0c..bc723ceefbb3 100644 --- a/tests/ui/empty_loop.stderr +++ b/tests/ui/empty_loop.stderr @@ -9,7 +9,7 @@ LL | loop {} = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: empty `loop {}` wastes CPU cycles - --> tests/ui/empty_loop.rs:12:9 + --> tests/ui/empty_loop.rs:13:9 | LL | loop {} | ^^^^^^^ @@ -17,7 +17,7 @@ LL | loop {} = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body error: empty `loop {}` wastes CPU cycles - --> tests/ui/empty_loop.rs:17:9 + --> tests/ui/empty_loop.rs:19:9 | LL | 'inner: loop {} | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs index 9bfcbfba9697..c3b2bafe2f87 100644 --- a/tests/ui/empty_loop_no_std.rs +++ b/tests/ui/empty_loop_no_std.rs @@ -8,5 +8,6 @@ pub fn main(argc: isize, argv: *const *const u8) -> isize { // This should trigger the lint loop {} - //~^ ERROR: empty `loop {}` wastes CPU cycles + //~^ empty_loop + } diff --git a/tests/ui/empty_structs_with_brackets.fixed b/tests/ui/empty_structs_with_brackets.fixed index 80572645f5d1..b1600862a8f6 100644 --- a/tests/ui/empty_structs_with_brackets.fixed +++ b/tests/ui/empty_structs_with_brackets.fixed @@ -2,7 +2,9 @@ #![allow(dead_code)] pub struct MyEmptyStruct; // should trigger lint +//~^ empty_structs_with_brackets struct MyEmptyTupleStruct; // should trigger lint +//~^ empty_structs_with_brackets // should not trigger lint struct MyCfgStruct { diff --git a/tests/ui/empty_structs_with_brackets.rs b/tests/ui/empty_structs_with_brackets.rs index 8fb3e247a419..1f69c4be9ec7 100644 --- a/tests/ui/empty_structs_with_brackets.rs +++ b/tests/ui/empty_structs_with_brackets.rs @@ -2,7 +2,9 @@ #![allow(dead_code)] pub struct MyEmptyStruct {} // should trigger lint +//~^ empty_structs_with_brackets struct MyEmptyTupleStruct(); // should trigger lint +//~^ empty_structs_with_brackets // should not trigger lint struct MyCfgStruct { diff --git a/tests/ui/empty_structs_with_brackets.stderr b/tests/ui/empty_structs_with_brackets.stderr index e57249aec023..86ef43aa9600 100644 --- a/tests/ui/empty_structs_with_brackets.stderr +++ b/tests/ui/empty_structs_with_brackets.stderr @@ -9,7 +9,7 @@ LL | pub struct MyEmptyStruct {} // should trigger lint = help: remove the brackets error: found empty brackets on struct declaration - --> tests/ui/empty_structs_with_brackets.rs:5:26 + --> tests/ui/empty_structs_with_brackets.rs:6:26 | LL | struct MyEmptyTupleStruct(); // should trigger lint | ^^^ diff --git a/tests/ui/endian_bytes.rs b/tests/ui/endian_bytes.rs index 580fc2fc24d7..879467c7f6e2 100644 --- a/tests/ui/endian_bytes.rs +++ b/tests/ui/endian_bytes.rs @@ -7,62 +7,118 @@ macro_rules! fn_body { () => { 2u8.to_ne_bytes(); + //~^ host_endian_bytes 2i8.to_ne_bytes(); + //~^ host_endian_bytes 2u16.to_ne_bytes(); + //~^ host_endian_bytes 2i16.to_ne_bytes(); + //~^ host_endian_bytes 2u32.to_ne_bytes(); + //~^ host_endian_bytes 2i32.to_ne_bytes(); + //~^ host_endian_bytes 2u64.to_ne_bytes(); + //~^ host_endian_bytes 2i64.to_ne_bytes(); + //~^ host_endian_bytes 2u128.to_ne_bytes(); + //~^ host_endian_bytes 2i128.to_ne_bytes(); + //~^ host_endian_bytes 2.0f32.to_ne_bytes(); + //~^ host_endian_bytes 2.0f64.to_ne_bytes(); + //~^ host_endian_bytes 2usize.to_ne_bytes(); + //~^ host_endian_bytes 2isize.to_ne_bytes(); + //~^ host_endian_bytes u8::from_ne_bytes(todo!()); + //~^ host_endian_bytes i8::from_ne_bytes(todo!()); + //~^ host_endian_bytes u16::from_ne_bytes(todo!()); + //~^ host_endian_bytes i16::from_ne_bytes(todo!()); + //~^ host_endian_bytes u32::from_ne_bytes(todo!()); + //~^ host_endian_bytes i32::from_ne_bytes(todo!()); + //~^ host_endian_bytes u64::from_ne_bytes(todo!()); + //~^ host_endian_bytes i64::from_ne_bytes(todo!()); + //~^ host_endian_bytes u128::from_ne_bytes(todo!()); + //~^ host_endian_bytes i128::from_ne_bytes(todo!()); + //~^ host_endian_bytes usize::from_ne_bytes(todo!()); + //~^ host_endian_bytes isize::from_ne_bytes(todo!()); + //~^ host_endian_bytes f32::from_ne_bytes(todo!()); + //~^ host_endian_bytes f64::from_ne_bytes(todo!()); + //~^ host_endian_bytes 2u8.to_le_bytes(); + //~^ little_endian_bytes 2i8.to_le_bytes(); + //~^ little_endian_bytes 2u16.to_le_bytes(); + //~^ little_endian_bytes 2i16.to_le_bytes(); + //~^ little_endian_bytes 2u32.to_le_bytes(); + //~^ little_endian_bytes 2i32.to_le_bytes(); + //~^ little_endian_bytes 2u64.to_le_bytes(); + //~^ little_endian_bytes 2i64.to_le_bytes(); + //~^ little_endian_bytes 2u128.to_le_bytes(); + //~^ little_endian_bytes 2i128.to_le_bytes(); + //~^ little_endian_bytes 2.0f32.to_le_bytes(); + //~^ little_endian_bytes 2.0f64.to_le_bytes(); + //~^ little_endian_bytes 2usize.to_le_bytes(); + //~^ little_endian_bytes 2isize.to_le_bytes(); + //~^ little_endian_bytes u8::from_le_bytes(todo!()); + //~^ little_endian_bytes i8::from_le_bytes(todo!()); + //~^ little_endian_bytes u16::from_le_bytes(todo!()); + //~^ little_endian_bytes i16::from_le_bytes(todo!()); + //~^ little_endian_bytes u32::from_le_bytes(todo!()); + //~^ little_endian_bytes i32::from_le_bytes(todo!()); + //~^ little_endian_bytes u64::from_le_bytes(todo!()); + //~^ little_endian_bytes i64::from_le_bytes(todo!()); + //~^ little_endian_bytes u128::from_le_bytes(todo!()); + //~^ little_endian_bytes i128::from_le_bytes(todo!()); + //~^ little_endian_bytes usize::from_le_bytes(todo!()); + //~^ little_endian_bytes isize::from_le_bytes(todo!()); + //~^ little_endian_bytes f32::from_le_bytes(todo!()); + //~^ little_endian_bytes f64::from_le_bytes(todo!()); + //~^ little_endian_bytes }; } @@ -70,13 +126,43 @@ macro_rules! fn_body { macro_rules! fn_body_smol { () => { 2u8.to_ne_bytes(); + //~^ host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes u8::from_ne_bytes(todo!()); + //~^ host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes + //~| host_endian_bytes 2u8.to_le_bytes(); + //~^ little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes u8::from_le_bytes(todo!()); + //~^ little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes + //~| little_endian_bytes 2u8.to_be_bytes(); + //~^ big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes u8::from_be_bytes(todo!()); + //~^ big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes + //~| big_endian_bytes }; } diff --git a/tests/ui/endian_bytes.stderr b/tests/ui/endian_bytes.stderr index fd19ec45872b..edc2a3309f24 100644 --- a/tests/ui/endian_bytes.stderr +++ b/tests/ui/endian_bytes.stderr @@ -13,7 +13,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:10:9 + --> tests/ui/endian_bytes.rs:11:9 | LL | 2i8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:11:9 + --> tests/ui/endian_bytes.rs:13:9 | LL | 2u16.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:12:9 + --> tests/ui/endian_bytes.rs:15:9 | LL | 2i16.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:13:9 + --> tests/ui/endian_bytes.rs:17:9 | LL | 2u32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:14:9 + --> tests/ui/endian_bytes.rs:19:9 | LL | 2i32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:15:9 + --> tests/ui/endian_bytes.rs:21:9 | LL | 2u64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:16:9 + --> tests/ui/endian_bytes.rs:23:9 | LL | 2i64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:17:9 + --> tests/ui/endian_bytes.rs:25:9 | LL | 2u128.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:18:9 + --> tests/ui/endian_bytes.rs:27:9 | LL | 2i128.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:19:9 + --> tests/ui/endian_bytes.rs:29:9 | LL | 2.0f32.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:20:9 + --> tests/ui/endian_bytes.rs:31:9 | LL | 2.0f64.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `usize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:21:9 + --> tests/ui/endian_bytes.rs:33:9 | LL | 2usize.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `isize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:22:9 + --> tests/ui/endian_bytes.rs:35:9 | LL | 2isize.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:23:9 + --> tests/ui/endian_bytes.rs:37:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:24:9 + --> tests/ui/endian_bytes.rs:39:9 | LL | i8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:25:9 + --> tests/ui/endian_bytes.rs:41:9 | LL | u16::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:26:9 + --> tests/ui/endian_bytes.rs:43:9 | LL | i16::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:27:9 + --> tests/ui/endian_bytes.rs:45:9 | LL | u32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:28:9 + --> tests/ui/endian_bytes.rs:47:9 | LL | i32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:29:9 + --> tests/ui/endian_bytes.rs:49:9 | LL | u64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:30:9 + --> tests/ui/endian_bytes.rs:51:9 | LL | i64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:31:9 + --> tests/ui/endian_bytes.rs:53:9 | LL | u128::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:32:9 + --> tests/ui/endian_bytes.rs:55:9 | LL | i128::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `usize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:33:9 + --> tests/ui/endian_bytes.rs:57:9 | LL | usize::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `isize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:34:9 + --> tests/ui/endian_bytes.rs:59:9 | LL | isize::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:35:9 + --> tests/ui/endian_bytes.rs:61:9 | LL | f32::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:36:9 + --> tests/ui/endian_bytes.rs:63:9 | LL | f64::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | fn host() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:38:9 + --> tests/ui/endian_bytes.rs:66:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -351,7 +351,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:39:9 + --> tests/ui/endian_bytes.rs:68:9 | LL | 2i8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -363,7 +363,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:40:9 + --> tests/ui/endian_bytes.rs:70:9 | LL | 2u16.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:41:9 + --> tests/ui/endian_bytes.rs:72:9 | LL | 2i16.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:42:9 + --> tests/ui/endian_bytes.rs:74:9 | LL | 2u32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -399,7 +399,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:43:9 + --> tests/ui/endian_bytes.rs:76:9 | LL | 2i32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -411,7 +411,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:44:9 + --> tests/ui/endian_bytes.rs:78:9 | LL | 2u64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -423,7 +423,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:45:9 + --> tests/ui/endian_bytes.rs:80:9 | LL | 2i64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:46:9 + --> tests/ui/endian_bytes.rs:82:9 | LL | 2u128.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -447,7 +447,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:47:9 + --> tests/ui/endian_bytes.rs:84:9 | LL | 2i128.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:48:9 + --> tests/ui/endian_bytes.rs:86:9 | LL | 2.0f32.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `f64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:49:9 + --> tests/ui/endian_bytes.rs:88:9 | LL | 2.0f64.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `usize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:50:9 + --> tests/ui/endian_bytes.rs:90:9 | LL | 2usize.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -495,7 +495,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `isize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:51:9 + --> tests/ui/endian_bytes.rs:92:9 | LL | 2isize.to_le_bytes(); | ^^^^^^^^^^^^^^^^^^^^ @@ -507,7 +507,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:52:9 + --> tests/ui/endian_bytes.rs:94:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -519,7 +519,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i8::from_le_bytes` - --> tests/ui/endian_bytes.rs:53:9 + --> tests/ui/endian_bytes.rs:96:9 | LL | i8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -531,7 +531,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u16::from_le_bytes` - --> tests/ui/endian_bytes.rs:54:9 + --> tests/ui/endian_bytes.rs:98:9 | LL | u16::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i16::from_le_bytes` - --> tests/ui/endian_bytes.rs:55:9 + --> tests/ui/endian_bytes.rs:100:9 | LL | i16::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u32::from_le_bytes` - --> tests/ui/endian_bytes.rs:56:9 + --> tests/ui/endian_bytes.rs:102:9 | LL | u32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i32::from_le_bytes` - --> tests/ui/endian_bytes.rs:57:9 + --> tests/ui/endian_bytes.rs:104:9 | LL | i32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u64::from_le_bytes` - --> tests/ui/endian_bytes.rs:58:9 + --> tests/ui/endian_bytes.rs:106:9 | LL | u64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -591,7 +591,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i64::from_le_bytes` - --> tests/ui/endian_bytes.rs:59:9 + --> tests/ui/endian_bytes.rs:108:9 | LL | i64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -603,7 +603,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u128::from_le_bytes` - --> tests/ui/endian_bytes.rs:60:9 + --> tests/ui/endian_bytes.rs:110:9 | LL | u128::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -615,7 +615,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `i128::from_le_bytes` - --> tests/ui/endian_bytes.rs:61:9 + --> tests/ui/endian_bytes.rs:112:9 | LL | i128::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -627,7 +627,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `usize::from_le_bytes` - --> tests/ui/endian_bytes.rs:62:9 + --> tests/ui/endian_bytes.rs:114:9 | LL | usize::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -639,7 +639,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `isize::from_le_bytes` - --> tests/ui/endian_bytes.rs:63:9 + --> tests/ui/endian_bytes.rs:116:9 | LL | isize::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -651,7 +651,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f32::from_le_bytes` - --> tests/ui/endian_bytes.rs:64:9 + --> tests/ui/endian_bytes.rs:118:9 | LL | f32::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -663,7 +663,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `f64::from_le_bytes` - --> tests/ui/endian_bytes.rs:65:9 + --> tests/ui/endian_bytes.rs:120:9 | LL | f64::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -675,7 +675,7 @@ LL | fn little() { fn_body!(); } = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:72:9 + --> tests/ui/endian_bytes.rs:128:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -687,7 +687,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:134:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -699,7 +699,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:78:9 + --> tests/ui/endian_bytes.rs:154:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -713,7 +713,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:79:9 + --> tests/ui/endian_bytes.rs:160:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -725,7 +725,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:72:9 + --> tests/ui/endian_bytes.rs:128:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -737,7 +737,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:134:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -749,7 +749,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 + --> tests/ui/endian_bytes.rs:141:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -761,7 +761,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:147:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -773,7 +773,7 @@ LL | fn host_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:72:9 + --> tests/ui/endian_bytes.rs:128:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -784,7 +784,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:134:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -795,7 +795,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 + --> tests/ui/endian_bytes.rs:141:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -806,7 +806,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:147:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -817,7 +817,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:78:9 + --> tests/ui/endian_bytes.rs:154:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -828,7 +828,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:79:9 + --> tests/ui/endian_bytes.rs:160:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -839,7 +839,7 @@ LL | fn no_help() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 + --> tests/ui/endian_bytes.rs:141:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -851,7 +851,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:147:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -863,7 +863,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:78:9 + --> tests/ui/endian_bytes.rs:154:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -875,7 +875,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:79:9 + --> tests/ui/endian_bytes.rs:160:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -887,7 +887,7 @@ LL | fn little_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:72:9 + --> tests/ui/endian_bytes.rs:128:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -899,7 +899,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:134:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -911,7 +911,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 + --> tests/ui/endian_bytes.rs:141:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -923,7 +923,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:147:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -935,7 +935,7 @@ LL | fn little_encourage_big() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 + --> tests/ui/endian_bytes.rs:141:9 | LL | 2u8.to_le_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -947,7 +947,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:76:9 + --> tests/ui/endian_bytes.rs:147:9 | LL | u8::from_le_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -959,7 +959,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:78:9 + --> tests/ui/endian_bytes.rs:154:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -971,7 +971,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:79:9 + --> tests/ui/endian_bytes.rs:160:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -983,7 +983,7 @@ LL | fn big_encourage_host() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:72:9 + --> tests/ui/endian_bytes.rs:128:9 | LL | 2u8.to_ne_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -995,7 +995,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:73:9 + --> tests/ui/endian_bytes.rs:134:9 | LL | u8::from_ne_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1007,7 +1007,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:78:9 + --> tests/ui/endian_bytes.rs:154:9 | LL | 2u8.to_be_bytes(); | ^^^^^^^^^^^^^^^^^ @@ -1019,7 +1019,7 @@ LL | fn big_encourage_little() { fn_body_smol!(); } = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:79:9 + --> tests/ui/endian_bytes.rs:160:9 | LL | u8::from_be_bytes(todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index abdfae2a3e13..87dc7a8de920 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -25,6 +25,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on insert, use or_insert_with(..) m.entry(k).or_insert_with(|| { + //~^ map_entry if true { v } else { @@ -34,6 +35,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on if, use or_insert_with(..) m.entry(k).or_insert_with(|| { + //~^ map_entry if true { v } else { @@ -43,6 +45,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // early return, use if let if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { + //~^ map_entry if true { e.insert(v); } else { @@ -53,12 +56,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with(..) m.entry(k).or_insert_with(|| { + //~^ map_entry foo(); v }); // semicolon on insert and match, use or_insert_with(..) m.entry(k).or_insert_with(|| { + //~^ map_entry match 0 { 1 if true => { v @@ -71,6 +76,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // one branch doesn't insert, use if let if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { + //~^ map_entry match 0 { 0 => foo(), _ => { @@ -81,6 +87,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with m.entry(k).or_insert_with(|| { + //~^ map_entry foo(); match 0 { 0 if false => { @@ -145,6 +152,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // or_insert_with. Partial move of a local declared in the closure is ok. m.entry(k).or_insert_with(|| { + //~^ map_entry let x = (String::new(), String::new()); let _ = x.0; v @@ -178,6 +186,7 @@ pub fn issue_11935() { fn issue12489(map: &mut HashMap) -> Option<()> { if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) { + //~^ map_entry let Some(1) = Some(2) else { return None; }; diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 7774f99a2a22..c795d3b97590 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -22,11 +22,13 @@ fn foo() {} fn hash_map(m: &mut HashMap, m2: &mut HashMap, k: K, k2: K, v: V, v2: V) { // or_insert(v) if !m.contains_key(&k) { + //~^ map_entry m.insert(k, v); } // semicolon on insert, use or_insert_with(..) if !m.contains_key(&k) { + //~^ map_entry if true { m.insert(k, v); } else { @@ -36,6 +38,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on if, use or_insert_with(..) if !m.contains_key(&k) { + //~^ map_entry if true { m.insert(k, v) } else { @@ -45,6 +48,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // early return, use if let if !m.contains_key(&k) { + //~^ map_entry if true { m.insert(k, v); } else { @@ -55,12 +59,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with(..) if !m.contains_key(&k) { + //~^ map_entry foo(); m.insert(k, v); } // semicolon on insert and match, use or_insert_with(..) if !m.contains_key(&k) { + //~^ map_entry match 0 { 1 if true => { m.insert(k, v); @@ -73,6 +79,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // one branch doesn't insert, use if let if !m.contains_key(&k) { + //~^ map_entry match 0 { 0 => foo(), _ => { @@ -83,6 +90,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with if !m.contains_key(&k) { + //~^ map_entry foo(); match 0 { 0 if false => { @@ -117,6 +125,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // macro_expansion test, use or_insert(..) if !m.contains_key(&m!(k)) { + //~^ map_entry m.insert(m!(k), m!(v)); } @@ -149,6 +158,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // or_insert_with. Partial move of a local declared in the closure is ok. if !m.contains_key(&k) { + //~^ map_entry let x = (String::new(), String::new()); let _ = x.0; m.insert(k, v); @@ -182,6 +192,7 @@ pub fn issue_11935() { fn issue12489(map: &mut HashMap) -> Option<()> { if !map.contains_key(&1) { + //~^ map_entry let Some(1) = Some(2) else { return None; }; diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index 4b6bd3b4a258..009b78d29073 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -2,6 +2,7 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` --> tests/ui/entry.rs:24:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | } | |_____^ help: try: `m.entry(k).or_insert(v);` @@ -10,12 +11,12 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:29:5 + --> tests/ui/entry.rs:30:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | if true { LL | | m.insert(k, v); -LL | | } else { ... | LL | | } | |_____^ @@ -23,6 +24,7 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + if true { LL + v LL + } else { @@ -32,13 +34,13 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:38:5 + --> tests/ui/entry.rs:40:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | if true { LL | | m.insert(k, v) -LL | | } else { -LL | | m.insert(k, v2) +... | LL | | }; LL | | } | |_____^ @@ -46,6 +48,7 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + if true { LL + v LL + } else { @@ -55,12 +58,12 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:47:5 + --> tests/ui/entry.rs:50:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | if true { LL | | m.insert(k, v); -LL | | } else { ... | LL | | } | |_____^ @@ -68,6 +71,7 @@ LL | | } help: try | LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + LL + if true { LL + e.insert(v); LL + } else { @@ -78,9 +82,10 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:57:5 + --> tests/ui/entry.rs:61:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | foo(); LL | | m.insert(k, v); LL | | } @@ -89,18 +94,19 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + foo(); LL + v LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:63:5 + --> tests/ui/entry.rs:68:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | match 0 { LL | | 1 if true => { -LL | | m.insert(k, v); ... | LL | | }; LL | | } @@ -109,6 +115,7 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + match 0 { LL + 1 if true => { LL + v @@ -121,12 +128,12 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:75:5 + --> tests/ui/entry.rs:81:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | match 0 { LL | | 0 => foo(), -LL | | _ => { ... | LL | | }; LL | | } @@ -135,6 +142,7 @@ LL | | } help: try | LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + LL + match 0 { LL + 0 => foo(), LL + _ => { @@ -145,12 +153,12 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:85:5 + --> tests/ui/entry.rs:92:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | foo(); LL | | match 0 { -LL | | 0 if false => { ... | LL | | } | |_____^ @@ -158,6 +166,7 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + foo(); LL + match 0 { LL + 0 if false => { @@ -185,17 +194,19 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:119:5 + --> tests/ui/entry.rs:127:5 | LL | / if !m.contains_key(&m!(k)) { +LL | | LL | | m.insert(m!(k), m!(v)); LL | | } | |_____^ help: try: `m.entry(m!(k)).or_insert_with(|| m!(v));` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:151:5 + --> tests/ui/entry.rs:160:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | let x = (String::new(), String::new()); LL | | let _ = x.0; LL | | m.insert(k, v); @@ -205,6 +216,7 @@ LL | | } help: try | LL ~ m.entry(k).or_insert_with(|| { +LL + LL + let x = (String::new(), String::new()); LL + let _ = x.0; LL + v @@ -212,9 +224,10 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry.rs:184:5 + --> tests/ui/entry.rs:194:5 | LL | / if !map.contains_key(&1) { +LL | | LL | | let Some(1) = Some(2) else { LL | | return None; LL | | }; @@ -225,6 +238,7 @@ LL | | } help: try | LL ~ if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) { +LL + LL + let Some(1) = Some(2) else { LL + return None; LL + }; diff --git a/tests/ui/entry_btree.fixed b/tests/ui/entry_btree.fixed index 228212c79eaf..518f503475fc 100644 --- a/tests/ui/entry_btree.fixed +++ b/tests/ui/entry_btree.fixed @@ -8,6 +8,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { + //~^ map_entry e.insert(v); foo(); } diff --git a/tests/ui/entry_btree.rs b/tests/ui/entry_btree.rs index 44703c567113..4e4b3a502e03 100644 --- a/tests/ui/entry_btree.rs +++ b/tests/ui/entry_btree.rs @@ -8,6 +8,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let if !m.contains_key(&k) { + //~^ map_entry m.insert(k, v); foo(); } diff --git a/tests/ui/entry_btree.stderr b/tests/ui/entry_btree.stderr index 290e6b788054..671340b89532 100644 --- a/tests/ui/entry_btree.stderr +++ b/tests/ui/entry_btree.stderr @@ -2,6 +2,7 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap` --> tests/ui/entry_btree.rs:10:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | foo(); LL | | } @@ -12,6 +13,7 @@ LL | | } help: try | LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { +LL + LL + e.insert(v); LL + foo(); LL + } diff --git a/tests/ui/entry_with_else.fixed b/tests/ui/entry_with_else.fixed index 34804b9ee5d7..995611803908 100644 --- a/tests/ui/entry_with_else.fixed +++ b/tests/ui/entry_with_else.fixed @@ -13,6 +13,7 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Occupied(mut e) => { @@ -22,6 +23,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Vacant(e) => { @@ -30,6 +32,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { + //~^ map_entry e.insert(v); } else { foo(); @@ -38,11 +41,13 @@ fn insert_if_absent0(m: &mut HashMap, k: K, if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { e.insert(v); } else { + //~^ map_entry foo(); } match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Occupied(mut e) => { @@ -52,6 +57,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { + //~^ map_entry if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } } std::collections::hash_map::Entry::Vacant(e) => { @@ -61,6 +67,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, }; if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { + //~^ map_entry foo(); Some(e.insert(v)) } else { diff --git a/tests/ui/entry_with_else.rs b/tests/ui/entry_with_else.rs index 0515748fd733..dcfafedc11f8 100644 --- a/tests/ui/entry_with_else.rs +++ b/tests/ui/entry_with_else.rs @@ -12,42 +12,49 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { if !m.contains_key(&k) { + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if m.contains_key(&k) { + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if !m.contains_key(&k) { + //~^ map_entry m.insert(k, v); } else { foo(); } if !m.contains_key(&k) { + //~^ map_entry foo(); } else { m.insert(k, v); } if !m.contains_key(&k) { + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if m.contains_key(&k) { + //~^ map_entry if true { m.insert(k, v) } else { m.insert(k, v2) } } else { m.insert(k, v) }; if m.contains_key(&k) { + //~^ map_entry foo(); m.insert(k, v) } else { diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index 26b21b076b6c..d483ac95ad5b 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -2,6 +2,7 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` --> tests/ui/entry_with_else.rs:14:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | } else { LL | | m.insert(k, v2); @@ -14,6 +15,7 @@ help: try | LL ~ match m.entry(k) { LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Occupied(mut e) => { @@ -23,9 +25,10 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:20:5 + --> tests/ui/entry_with_else.rs:21:5 | LL | / if m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | } else { LL | | m.insert(k, v2); @@ -36,6 +39,7 @@ help: try | LL ~ match m.entry(k) { LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Vacant(e) => { @@ -45,9 +49,10 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:26:5 + --> tests/ui/entry_with_else.rs:28:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | } else { LL | | foo(); @@ -57,6 +62,7 @@ LL | | } help: try | LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { +LL + LL + e.insert(v); LL + } else { LL + foo(); @@ -64,9 +70,10 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:32:5 + --> tests/ui/entry_with_else.rs:35:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | foo(); LL | | } else { LL | | m.insert(k, v); @@ -78,14 +85,16 @@ help: try LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { LL + e.insert(v); LL + } else { +LL + LL + foo(); LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:38:5 + --> tests/ui/entry_with_else.rs:42:5 | LL | / if !m.contains_key(&k) { +LL | | LL | | m.insert(k, v); LL | | } else { LL | | m.insert(k, v2); @@ -96,6 +105,7 @@ help: try | LL ~ match m.entry(k) { LL + std::collections::hash_map::Entry::Vacant(e) => { +LL + LL + e.insert(v); LL + } LL + std::collections::hash_map::Entry::Occupied(mut e) => { @@ -105,9 +115,10 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:44:5 + --> tests/ui/entry_with_else.rs:49:5 | LL | / if m.contains_key(&k) { +LL | | LL | | if true { m.insert(k, v) } else { m.insert(k, v2) } LL | | } else { LL | | m.insert(k, v) @@ -118,6 +129,7 @@ help: try | LL ~ match m.entry(k) { LL + std::collections::hash_map::Entry::Occupied(mut e) => { +LL + LL + if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } LL + } LL + std::collections::hash_map::Entry::Vacant(e) => { @@ -128,9 +140,10 @@ LL ~ }; | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> tests/ui/entry_with_else.rs:50:5 + --> tests/ui/entry_with_else.rs:56:5 | LL | / if m.contains_key(&k) { +LL | | LL | | foo(); LL | | m.insert(k, v) LL | | } else { @@ -141,6 +154,7 @@ LL | | }; help: try | LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { +LL + LL + foo(); LL + Some(e.insert(v)) LL + } else { diff --git a/tests/ui/enum_clike_unportable_variant.rs b/tests/ui/enum_clike_unportable_variant.rs index 37849179d6a0..f54cca9c611c 100644 --- a/tests/ui/enum_clike_unportable_variant.rs +++ b/tests/ui/enum_clike_unportable_variant.rs @@ -6,8 +6,9 @@ #[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` + //~^ enum_clike_unportable_variant + + Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, @@ -15,11 +16,13 @@ enum NonPortable { enum NonPortableNoHint { X = 0x1_0000_0000, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + } #[repr(isize)] @@ -27,27 +30,33 @@ enum NonPortableSigned { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + A = 0x1_0000_0000, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + 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_clike_unportable_variant + } enum NonPortableSignedNoHint { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + A = 0x1_0000_0000, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + } #[repr(usize)] enum NonPortable2 { X = ::Number, - //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~^ enum_clike_unportable_variant + Y = 0, } diff --git a/tests/ui/enum_clike_unportable_variant.stderr b/tests/ui/enum_clike_unportable_variant.stderr index 741de179a497..ade2106ad96c 100644 --- a/tests/ui/enum_clike_unportable_variant.stderr +++ b/tests/ui/enum_clike_unportable_variant.stderr @@ -8,49 +8,49 @@ LL | X = 0x1_0000_0000, = help: to override `-D warnings` add `#[allow(clippy::enum_clike_unportable_variant)]` error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:17:5 + --> tests/ui/enum_clike_unportable_variant.rs:18:5 | LL | X = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:21:5 + --> tests/ui/enum_clike_unportable_variant.rs:23:5 | LL | A = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:29:5 + --> tests/ui/enum_clike_unportable_variant.rs:32:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:31:5 + --> tests/ui/enum_clike_unportable_variant.rs:35:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:34:5 + --> tests/ui/enum_clike_unportable_variant.rs:39:5 | LL | C = (i32::MIN as isize) - 1, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:41:5 + --> tests/ui/enum_clike_unportable_variant.rs:47:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:43:5 + --> tests/ui/enum_clike_unportable_variant.rs:50:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:49:5 + --> tests/ui/enum_clike_unportable_variant.rs:57:5 | LL | X = ::Number, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed index 3c0db9beb1a6..881493f3d5ff 100644 --- a/tests/ui/enum_glob_use.fixed +++ b/tests/ui/enum_glob_use.fixed @@ -3,16 +3,19 @@ #![warn(unused_imports)] use std::cmp::Ordering::Less; +//~^ enum_glob_use enum Enum { Foo, } use self::Enum::Foo; +//~^ enum_glob_use mod in_fn_test { fn blarg() { use crate::Enum::Foo; + //~^ enum_glob_use let _ = Foo; } diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 2538477f7978..a510462ecb2f 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -3,16 +3,19 @@ #![warn(unused_imports)] use std::cmp::Ordering::*; +//~^ enum_glob_use enum Enum { Foo, } use self::Enum::*; +//~^ enum_glob_use mod in_fn_test { fn blarg() { use crate::Enum::*; + //~^ enum_glob_use let _ = Foo; } diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr index 6825383b769d..a2cef8008e21 100644 --- a/tests/ui/enum_glob_use.stderr +++ b/tests/ui/enum_glob_use.stderr @@ -8,13 +8,13 @@ LL | use std::cmp::Ordering::*; = help: to override `-D warnings` add `#[allow(clippy::enum_glob_use)]` error: usage of wildcard import for enum variants - --> tests/ui/enum_glob_use.rs:11:5 + --> tests/ui/enum_glob_use.rs:12:5 | LL | use self::Enum::*; | ^^^^^^^^^^^^^ help: try: `self::Enum::Foo` error: usage of wildcard import for enum variants - --> tests/ui/enum_glob_use.rs:15:13 + --> tests/ui/enum_glob_use.rs:17:13 | LL | use crate::Enum::*; | ^^^^^^^^^^^^^^ help: try: `crate::Enum::Foo` diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index ddf2dfdaea9b..f3c81b2111ce 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -12,10 +12,9 @@ enum FakeCallType2 { } enum Foo { - //~^ ERROR: all variants have the same prefix: `c` +//~^ enum_variant_names cFoo, - //~^ ERROR: variant name ends with the enum's name - //~| NOTE: `-D clippy::enum-variant-names` implied by `-D warnings` + //~^ enum_variant_names cBar, cBaz, } @@ -26,13 +25,13 @@ enum Fooo { } enum Food { - //~^ ERROR: all variants have the same prefix: `Food` +//~^ enum_variant_names FoodGood, - //~^ ERROR: variant name starts with the enum's name + //~^ enum_variant_names FoodMiddle, - //~^ ERROR: variant name starts with the enum's name + //~^ enum_variant_names FoodBad, - //~^ ERROR: variant name starts with the enum's name + //~^ enum_variant_names } enum Stuff { @@ -40,7 +39,8 @@ enum Stuff { } enum BadCallType { - //~^ ERROR: all variants have the same prefix: `CallType` +//~^ enum_variant_names + CallTypeCall, CallTypeCreate, CallTypeDestroy, @@ -53,7 +53,7 @@ enum TwoCallType { } enum Consts { - //~^ ERROR: all variants have the same prefix: `Constant` +//~^ enum_variant_names ConstantInt, ConstantCake, ConstantLie, @@ -66,7 +66,7 @@ enum Two { } enum Something { - //~^ ERROR: all variants have the same prefix: `C` +//~^ enum_variant_names CCall, CCreate, CCryogenize, @@ -89,7 +89,7 @@ enum Sealll { } enum Seallll { - //~^ ERROR: all variants have the same prefix: `WithOut` +//~^ enum_variant_names WithOutCake, WithOutTea, WithOut, @@ -145,14 +145,14 @@ pub enum NetworkLayer { // should lint suggesting `IData`, not only `Data` (see #4639) enum IDataRequest { - //~^ ERROR: all variants have the same postfix: `IData` +//~^ enum_variant_names PutIData(String), GetIData(String), DeleteUnpubIData(String), } enum HIDataRequest { - //~^ ERROR: all variants have the same postfix: `HIData` +//~^ enum_variant_names PutHIData(String), GetHIData(String), DeleteUnpubHIData(String), @@ -173,7 +173,7 @@ enum Phase { mod issue9018 { enum DoLint { - //~^ ERROR: all variants have the same prefix: `_Type` + //~^ enum_variant_names _TypeCreate, _TypeRead, _TypeUpdate, @@ -181,7 +181,7 @@ mod issue9018 { } enum DoLintToo { - //~^ ERROR: all variants have the same postfix: `Type` + //~^ enum_variant_names _CreateType, _UpdateType, _DeleteType, @@ -210,12 +210,12 @@ mod issue11494 { Valid, Invalid, DataDependent, - //~^ ERROR: variant name starts with the enum's name + //~^ enum_variant_names } enum Datas { DatasDependent, - //~^ ERROR: variant name starts with the enum's name + //~^ enum_variant_names Valid, Invalid, } diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index ecca6c833ac5..2f0b0e6149d2 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -21,25 +21,25 @@ 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 - --> tests/ui/enum_variants.rs:30:5 + --> tests/ui/enum_variants.rs:29:5 | LL | FoodGood, | ^^^^^^^^ error: variant name starts with the enum's name - --> tests/ui/enum_variants.rs:32:5 + --> tests/ui/enum_variants.rs:31:5 | LL | FoodMiddle, | ^^^^^^^^^^ error: variant name starts with the enum's name - --> tests/ui/enum_variants.rs:34:5 + --> tests/ui/enum_variants.rs:33:5 | LL | FoodBad, | ^^^^^^^ error: all variants have the same prefix: `Food` - --> tests/ui/enum_variants.rs:28:1 + --> tests/ui/enum_variants.rs:27:1 | LL | / enum Food { LL | | @@ -51,10 +51,11 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `CallType` - --> tests/ui/enum_variants.rs:42:1 + --> tests/ui/enum_variants.rs:41:1 | LL | / enum BadCallType { LL | | +LL | | LL | | CallTypeCall, LL | | CallTypeCreate, LL | | CallTypeDestroy, diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index 7383d784c841..cb6cff419e9d 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -3,16 +3,21 @@ 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` + //~^ print_with_newline + + eprintln!("Hello {}", "world"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprintln!("Hello {} {}", "world", "#2"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprintln!("{}", 1265); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprintln!(); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + // these are all fine eprint!(""); @@ -35,7 +40,8 @@ fn main() { // #3514 eprint!("\\n"); eprintln!("\\"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprint!("\\\\n"); // Raw strings @@ -44,11 +50,13 @@ fn main() { // Literal newlines should also fail eprintln!( - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + ); eprintln!( - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + ); @@ -56,7 +64,8 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprintln!("\\r"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_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 5b114056411d..cfe503cec1f1 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -3,16 +3,21 @@ 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` + //~^ print_with_newline + + eprint!("Hello {}\n", "world"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprint!("Hello {} {}\n", "world", "#2"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprint!("{}\n", 1265); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprint!("\n"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + // these are all fine eprint!(""); @@ -35,7 +40,8 @@ fn main() { // #3514 eprint!("\\n"); eprint!("\\\n"); - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + eprint!("\\\\n"); // Raw strings @@ -44,12 +50,14 @@ fn main() { // Literal newlines should also fail eprint!( - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + " " ); eprint!( - //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~^ print_with_newline + r" " ); @@ -58,7 +66,8 @@ 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 + //~^ print_with_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 de450090a66e..87dcb9126b6d 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -13,7 +13,7 @@ LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:8:5 + --> tests/ui/eprint_with_newline.rs:9:5 | LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:10:5 + --> tests/ui/eprint_with_newline.rs:12:5 | LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:12:5 + --> tests/ui/eprint_with_newline.rs:15:5 | LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:14:5 + --> tests/ui/eprint_with_newline.rs:18:5 | LL | eprint!("\n"); | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:37:5 + --> tests/ui/eprint_with_newline.rs:42:5 | LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ @@ -73,10 +73,11 @@ LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:46:5 + --> tests/ui/eprint_with_newline.rs:52:5 | LL | / eprint!( LL | | +LL | | LL | | " LL | | " LL | | ); @@ -86,14 +87,16 @@ help: use `eprintln!` instead | LL ~ eprintln!( LL | +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:51:5 + --> tests/ui/eprint_with_newline.rs:58:5 | LL | / eprint!( LL | | +LL | | LL | | r" LL | | " LL | | ); @@ -103,11 +106,12 @@ help: use `eprintln!` instead | LL ~ eprintln!( LL | +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:60:5 + --> tests/ui/eprint_with_newline.rs:68:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index 7c2c13187518..757a7e011903 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -5,80 +5,107 @@ fn main() { // simple values and comparisons let _ = 1 == 1; - //~^ ERROR: equal expressions as operands to `==` - //~| NOTE: `-D clippy::eq-op` implied by `-D warnings` + //~^ eq_op + + let _ = "no" == "no"; - //~^ ERROR: equal expressions as operands to `==` + //~^ eq_op + // even though I agree that no means no ;-) let _ = false != false; - //~^ ERROR: equal expressions as operands to `!=` + //~^ eq_op + let _ = 1.5 < 1.5; - //~^ ERROR: equal expressions as operands to `<` + //~^ eq_op + let _ = 1u64 >= 1u64; - //~^ ERROR: equal expressions as operands to `>=` + //~^ eq_op + 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 + //~^ eq_op + + // casts, methods, parentheses let _ = (1u32 as u64) & (1u32 as u64); - //~^ ERROR: equal expressions as operands to `&` + //~^ eq_op + #[rustfmt::skip] { let _ = 1 ^ ((((((1)))))); - //~^ ERROR: equal expressions as operands to `^` + //~^ eq_op + }; // unary and binary operators let _ = (-(2) < -(2)); - //~^ ERROR: equal expressions as operands to `<` + //~^ eq_op + 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 `&` + //~^ eq_op + //~| eq_op + //~| eq_op + + + let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; - //~^ ERROR: equal expressions as operands to `==` + //~^ eq_op + // various other things let _ = ([1] != [1]); - //~^ ERROR: equal expressions as operands to `!=` + //~^ eq_op + let _ = ((1, 2) != (1, 2)); - //~^ ERROR: equal expressions as operands to `!=` + //~^ eq_op + 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 `==` + //~^ eq_op + let _ = 1 - 1 == 0; - //~^ ERROR: equal expressions as operands to `==` - //~| ERROR: equal expressions as operands to `-` + //~^ eq_op + //~| eq_op + + let _ = 1 - 1; - //~^ ERROR: equal expressions as operands to `-` + //~^ eq_op + let _ = 1 / 1; - //~^ ERROR: equal expressions as operands to `/` + //~^ eq_op + let _ = true && true; - //~^ ERROR: equal expressions as operands to `&&` + //~^ eq_op + let _ = true || true; - //~^ ERROR: equal expressions as operands to `||` + //~^ eq_op + let a: u32 = 0; let b: u32 = 0; let _ = a == b && b == a; - //~^ ERROR: equal expressions as operands to `&&` + //~^ eq_op + let _ = a != b && b != a; - //~^ ERROR: equal expressions as operands to `&&` + //~^ eq_op + let _ = a < b && b > a; - //~^ ERROR: equal expressions as operands to `&&` + //~^ eq_op + let _ = a <= b && b >= a; - //~^ ERROR: equal expressions as operands to `&&` + //~^ eq_op + let mut a = vec![1]; let _ = a == a; - //~^ ERROR: equal expressions as operands to `==` + //~^ eq_op + let _ = 2 * a.len() == 2 * a.len(); // ok, functions let _ = a.pop() == a.pop(); // ok, functions @@ -89,7 +116,8 @@ 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 `/` + //~^ eq_op + } macro_rules! check_if_named_foo { @@ -121,7 +149,8 @@ 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 `==` + //~^ eq_op + } #[test] diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index bd3c115d8b8b..bd9362f3e0dd 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -8,31 +8,31 @@ LL | let _ = 1 == 1; = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:10:13 + --> tests/ui/eq_op.rs:11:13 | LL | let _ = "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:13:13 + --> tests/ui/eq_op.rs:15:13 | LL | let _ = false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> tests/ui/eq_op.rs:15:13 + --> tests/ui/eq_op.rs:18:13 | LL | let _ = 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> tests/ui/eq_op.rs:17:13 + --> tests/ui/eq_op.rs:21:13 | LL | let _ = 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:20:13 + --> tests/ui/eq_op.rs:25:13 | LL | let _ = x != x; | ^^^^^^ @@ -40,139 +40,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 `&` - --> tests/ui/eq_op.rs:25:13 + --> tests/ui/eq_op.rs:31:13 | LL | let _ = (1u32 as u64) & (1u32 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> tests/ui/eq_op.rs:29:17 + --> tests/ui/eq_op.rs:36:17 | LL | let _ = 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> tests/ui/eq_op.rs:34:13 + --> tests/ui/eq_op.rs:42:13 | LL | let _ = (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:36:13 + --> tests/ui/eq_op.rs:45:13 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> tests/ui/eq_op.rs:36:14 + --> tests/ui/eq_op.rs:45:14 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> tests/ui/eq_op.rs:36:35 + --> tests/ui/eq_op.rs:45:35 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:40:13 + --> tests/ui/eq_op.rs:52:13 | LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:44:13 + --> tests/ui/eq_op.rs:57:13 | LL | let _ = ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:46:13 + --> tests/ui/eq_op.rs:60:13 | LL | let _ = ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:51:13 + --> tests/ui/eq_op.rs:66:13 | LL | let _ = 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:53:13 + --> tests/ui/eq_op.rs:69:13 | LL | let _ = 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> tests/ui/eq_op.rs:53:13 + --> tests/ui/eq_op.rs:69:13 | LL | let _ = 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> tests/ui/eq_op.rs:57:13 + --> tests/ui/eq_op.rs:75:13 | LL | let _ = 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> tests/ui/eq_op.rs:59:13 + --> tests/ui/eq_op.rs:78:13 | LL | let _ = 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:61:13 + --> tests/ui/eq_op.rs:81:13 | LL | let _ = true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> tests/ui/eq_op.rs:64:13 + --> tests/ui/eq_op.rs:85:13 | LL | let _ = true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:70:13 + --> tests/ui/eq_op.rs:92:13 | LL | let _ = a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:72:13 + --> tests/ui/eq_op.rs:95:13 | LL | let _ = a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:74:13 + --> tests/ui/eq_op.rs:98:13 | LL | let _ = a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:76:13 + --> tests/ui/eq_op.rs:101:13 | LL | let _ = a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:80:13 + --> tests/ui/eq_op.rs:106:13 | LL | let _ = a == a; | ^^^^^^ error: equal expressions as operands to `/` - --> tests/ui/eq_op.rs:91:20 + --> tests/ui/eq_op.rs:118:20 | LL | const D: u32 = A / A; | ^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:123:5 + --> tests/ui/eq_op.rs:151: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 a511af4a31c8..82242d0eb196 100644 --- a/tests/ui/eq_op_macros.rs +++ b/tests/ui/eq_op_macros.rs @@ -6,9 +6,13 @@ macro_rules! assert_in_macro_def { () => { let a = 42; assert_eq!(a, a); + //~^ eq_op assert_ne!(a, a); + //~^ eq_op debug_assert_eq!(a, a); + //~^ eq_op debug_assert_ne!(a, a); + //~^ eq_op }; } @@ -21,9 +25,11 @@ fn main() { // lint identical args in `assert_eq!` assert_eq!(a, a); - //~^ ERROR: identical args used in this `assert_eq!` macro call + //~^ eq_op + assert_eq!(a + 1, a + 1); - //~^ ERROR: identical args used in this `assert_eq!` macro call + //~^ eq_op + // ok assert_eq!(a, b); assert_eq!(a, a + 1); @@ -31,9 +37,11 @@ fn main() { // lint identical args in `assert_ne!` assert_ne!(a, a); - //~^ ERROR: identical args used in this `assert_ne!` macro call + //~^ eq_op + assert_ne!(a + 1, a + 1); - //~^ ERROR: identical args used in this `assert_ne!` macro call + //~^ eq_op + // ok assert_ne!(a, b); assert_ne!(a, a + 1); @@ -41,9 +49,11 @@ 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 + //~^ eq_op + debug_assert_eq!(a + 1, a + 1); - //~^ ERROR: identical args used in this `debug_assert_eq!` macro call + //~^ eq_op + // ok debug_assert_eq!(a, b); debug_assert_eq!(a, a + 1); @@ -51,9 +61,11 @@ 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 + //~^ eq_op + debug_assert_ne!(a + 1, a + 1); - //~^ ERROR: identical args used in this `debug_assert_ne!` macro call + //~^ eq_op + // 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 b114db0ca98e..72315e87bfef 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -12,7 +12,7 @@ LL | assert_in_macro_def!(); = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:9:20 + --> tests/ui/eq_op_macros.rs:10:20 | LL | assert_ne!(a, a); | ^^^^ @@ -23,7 +23,7 @@ LL | assert_in_macro_def!(); = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `debug_assert_eq!` macro call - --> tests/ui/eq_op_macros.rs:10:26 + --> tests/ui/eq_op_macros.rs:12:26 | LL | debug_assert_eq!(a, a); | ^^^^ @@ -34,7 +34,7 @@ LL | assert_in_macro_def!(); = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `debug_assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:11:26 + --> tests/ui/eq_op_macros.rs:14:26 | LL | debug_assert_ne!(a, a); | ^^^^ @@ -45,49 +45,49 @@ LL | assert_in_macro_def!(); = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_eq!` macro call - --> tests/ui/eq_op_macros.rs:23:16 + --> tests/ui/eq_op_macros.rs:27:16 | LL | assert_eq!(a, a); | ^^^^ error: identical args used in this `assert_eq!` macro call - --> tests/ui/eq_op_macros.rs:25:16 + --> tests/ui/eq_op_macros.rs:30:16 | LL | assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:33:16 + --> tests/ui/eq_op_macros.rs:39:16 | LL | assert_ne!(a, a); | ^^^^ error: identical args used in this `assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:35:16 + --> tests/ui/eq_op_macros.rs:42:16 | LL | assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> tests/ui/eq_op_macros.rs:43:22 + --> tests/ui/eq_op_macros.rs:51:22 | LL | debug_assert_eq!(a, a); | ^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> tests/ui/eq_op_macros.rs:45:22 + --> tests/ui/eq_op_macros.rs:54:22 | LL | debug_assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:53:22 + --> tests/ui/eq_op_macros.rs:63:22 | LL | debug_assert_ne!(a, a); | ^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> tests/ui/eq_op_macros.rs:55:22 + --> tests/ui/eq_op_macros.rs:66:22 | LL | debug_assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ diff --git a/tests/ui/equatable_if_let.fixed b/tests/ui/equatable_if_let.fixed index 2b523e1e185c..2f39c34cb394 100644 --- a/tests/ui/equatable_if_let.fixed +++ b/tests/ui/equatable_if_let.fixed @@ -62,13 +62,21 @@ fn main() { // true if a == 2 {} + //~^ equatable_if_let if a.cmp(&b) == Ordering::Greater {} + //~^ equatable_if_let if c == Some(2) {} + //~^ equatable_if_let if d == (Struct { a: 2, b: false }) {} + //~^ equatable_if_let if e == Enum::TupleVariant(32, 64) {} + //~^ equatable_if_let if e == (Enum::RecordVariant { a: 64, b: 32 }) {} + //~^ equatable_if_let if e == Enum::UnitVariant {} + //~^ equatable_if_let if (e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false }) {} + //~^ equatable_if_let // false @@ -78,12 +86,18 @@ fn main() { if let Struct { a, b: false } = d {} if let Struct { a: 2, b: x } = d {} if matches!(f, NotPartialEq::A) {} + //~^ equatable_if_let if g == NotStructuralEq::A {} + //~^ equatable_if_let if matches!(Some(f), Some(NotPartialEq::A)) {} + //~^ equatable_if_let if Some(g) == Some(NotStructuralEq::A) {} + //~^ equatable_if_let if matches!(h, NoPartialEqStruct { a: 2, b: false }) {} + //~^ equatable_if_let if "abc" == inline!("abc") { + //~^ equatable_if_let println!("OK"); } diff --git a/tests/ui/equatable_if_let.rs b/tests/ui/equatable_if_let.rs index f7e3bb2964da..f7289a9ee56f 100644 --- a/tests/ui/equatable_if_let.rs +++ b/tests/ui/equatable_if_let.rs @@ -62,13 +62,21 @@ fn main() { // true if let 2 = a {} + //~^ equatable_if_let if let Ordering::Greater = a.cmp(&b) {} + //~^ equatable_if_let if let Some(2) = c {} + //~^ equatable_if_let if let Struct { a: 2, b: false } = d {} + //~^ equatable_if_let if let Enum::TupleVariant(32, 64) = e {} + //~^ equatable_if_let if let Enum::RecordVariant { a: 64, b: 32 } = e {} + //~^ equatable_if_let if let Enum::UnitVariant = e {} + //~^ equatable_if_let if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {} + //~^ equatable_if_let // false @@ -78,12 +86,18 @@ fn main() { if let Struct { a, b: false } = d {} if let Struct { a: 2, b: x } = d {} if let NotPartialEq::A = f {} + //~^ equatable_if_let if let NotStructuralEq::A = g {} + //~^ equatable_if_let if let Some(NotPartialEq::A) = Some(f) {} + //~^ equatable_if_let if let Some(NotStructuralEq::A) = Some(g) {} + //~^ equatable_if_let if let NoPartialEqStruct { a: 2, b: false } = h {} + //~^ equatable_if_let if let inline!("abc") = "abc" { + //~^ equatable_if_let println!("OK"); } diff --git a/tests/ui/equatable_if_let.stderr b/tests/ui/equatable_if_let.stderr index 9e93a33cd7e2..81e0e15a5c74 100644 --- a/tests/ui/equatable_if_let.stderr +++ b/tests/ui/equatable_if_let.stderr @@ -8,79 +8,79 @@ LL | if let 2 = a {} = help: to override `-D warnings` add `#[allow(clippy::equatable_if_let)]` error: this pattern matching can be expressed using equality - --> tests/ui/equatable_if_let.rs:65:8 + --> tests/ui/equatable_if_let.rs:66: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 - --> tests/ui/equatable_if_let.rs:66:8 + --> tests/ui/equatable_if_let.rs:68:8 | LL | if let Some(2) = c {} | ^^^^^^^^^^^^^^^ help: try: `c == Some(2)` error: this pattern matching can be expressed using equality - --> tests/ui/equatable_if_let.rs:67:8 + --> tests/ui/equatable_if_let.rs:70: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 - --> tests/ui/equatable_if_let.rs:68:8 + --> tests/ui/equatable_if_let.rs:72: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 - --> tests/ui/equatable_if_let.rs:69:8 + --> tests/ui/equatable_if_let.rs:74: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 - --> tests/ui/equatable_if_let.rs:70:8 + --> tests/ui/equatable_if_let.rs:76:8 | LL | if let Enum::UnitVariant = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant` error: this pattern matching can be expressed using equality - --> tests/ui/equatable_if_let.rs:71:8 + --> tests/ui/equatable_if_let.rs:78: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!` - --> tests/ui/equatable_if_let.rs:80:8 + --> tests/ui/equatable_if_let.rs:88:8 | LL | if let NotPartialEq::A = f {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)` error: this pattern matching can be expressed using equality - --> tests/ui/equatable_if_let.rs:81:8 + --> tests/ui/equatable_if_let.rs:90:8 | LL | if let NotStructuralEq::A = g {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A` error: this pattern matching can be expressed using `matches!` - --> tests/ui/equatable_if_let.rs:82:8 + --> tests/ui/equatable_if_let.rs:92: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 - --> tests/ui/equatable_if_let.rs:83:8 + --> tests/ui/equatable_if_let.rs:94: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!` - --> tests/ui/equatable_if_let.rs:84:8 + --> tests/ui/equatable_if_let.rs:96: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 - --> tests/ui/equatable_if_let.rs:86:8 + --> tests/ui/equatable_if_let.rs:99:8 | LL | if let inline!("abc") = "abc" { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")` diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index 00c74f23fed0..9387a20cb5a0 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -33,17 +33,22 @@ 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` + //~^ erasing_op + + 0 & x; - //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~^ erasing_op + 0 / x; - //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~^ erasing_op + 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 + //~^ erasing_op + Vec1 { x: 5 } * 0; - //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~^ erasing_op + } fn main() { diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 6ed8bffeb24d..7029fac6c130 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -8,25 +8,25 @@ LL | x * 0; = help: to override `-D warnings` add `#[allow(clippy::erasing_op)]` error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:38:5 + --> tests/ui/erasing_op.rs:39:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:40:5 + --> tests/ui/erasing_op.rs:42:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:43:5 + --> tests/ui/erasing_op.rs:46:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:45:5 + --> tests/ui/erasing_op.rs:49:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/err_expect.fixed b/tests/ui/err_expect.fixed index abbc6dbebedb..9e1a3a0c739c 100644 --- a/tests/ui/err_expect.fixed +++ b/tests/ui/err_expect.fixed @@ -8,6 +8,7 @@ struct MyTypeDebug; fn main() { let test_debug: Result = Ok(MyTypeDebug); test_debug.expect_err("Testing debug type"); + //~^ err_expect let test_non_debug: Result = Ok(MyTypeNonDebug); test_non_debug.err().expect("Testing non debug type"); @@ -23,4 +24,5 @@ fn msrv_1_16() { fn msrv_1_17() { let x: Result = Ok(17); x.expect_err("17"); + //~^ err_expect } diff --git a/tests/ui/err_expect.rs b/tests/ui/err_expect.rs index 0c7ad185dfbe..8e9063a2e1d4 100644 --- a/tests/ui/err_expect.rs +++ b/tests/ui/err_expect.rs @@ -8,6 +8,7 @@ struct MyTypeDebug; fn main() { let test_debug: Result = Ok(MyTypeDebug); test_debug.err().expect("Testing debug type"); + //~^ err_expect let test_non_debug: Result = Ok(MyTypeNonDebug); test_non_debug.err().expect("Testing non debug type"); @@ -23,4 +24,5 @@ fn msrv_1_16() { fn msrv_1_17() { let x: Result = Ok(17); x.err().expect("17"); + //~^ err_expect } diff --git a/tests/ui/err_expect.stderr b/tests/ui/err_expect.stderr index 68f39cc45c5b..5b591e1604db 100644 --- a/tests/ui/err_expect.stderr +++ b/tests/ui/err_expect.stderr @@ -8,7 +8,7 @@ LL | test_debug.err().expect("Testing debug type"); = help: to override `-D warnings` add `#[allow(clippy::err_expect)]` error: called `.err().expect()` on a `Result` value - --> tests/ui/err_expect.rs:25:7 + --> tests/ui/err_expect.rs:26:7 | LL | x.err().expect("17"); | ^^^^^^^^^^^^ help: try: `expect_err` diff --git a/tests/ui/error_impl_error.rs b/tests/ui/error_impl_error.rs index 05003f7d047c..3606e1bcefbb 100644 --- a/tests/ui/error_impl_error.rs +++ b/tests/ui/error_impl_error.rs @@ -5,7 +5,8 @@ pub mod a { #[derive(Debug)] pub struct Error; - //~^ ERROR: exported type named `Error` that implements `Error` + //~^ error_impl_error + impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -19,7 +20,8 @@ pub mod a { mod b { #[derive(Debug)] pub(super) enum Error {} - //~^ ERROR: exported type named `Error` that implements `Error` + //~^ error_impl_error + impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -32,7 +34,8 @@ mod b { pub mod c { pub union Error { - //~^ ERROR: exported type named `Error` that implements `Error` + //~^ error_impl_error + a: u32, b: u32, } @@ -54,7 +57,8 @@ pub mod c { pub mod d { pub type Error = std::fmt::Error; - //~^ ERROR: exported type alias named `Error` that implements `Error` + //~^ error_impl_error + } mod e { diff --git a/tests/ui/error_impl_error.stderr b/tests/ui/error_impl_error.stderr index 087d43d1d083..4fa1ffeb4c92 100644 --- a/tests/ui/error_impl_error.stderr +++ b/tests/ui/error_impl_error.stderr @@ -5,7 +5,7 @@ LL | pub struct Error; | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:16:5 + --> tests/ui/error_impl_error.rs:17:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,31 +13,31 @@ LL | impl std::error::Error for Error {} = help: to override `-D warnings` add `#[allow(clippy::error_impl_error)]` error: exported type named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:21:21 + --> tests/ui/error_impl_error.rs:22:21 | LL | pub(super) enum Error {} | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:30:5 + --> tests/ui/error_impl_error.rs:32:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:34:15 + --> tests/ui/error_impl_error.rs:36:15 | LL | pub union Error { | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:52:5 + --> tests/ui/error_impl_error.rs:55:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type alias named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:56:14 + --> tests/ui/error_impl_error.rs:59:14 | LL | pub type Error = std::fmt::Error; | ^^^^^ diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index abccc30ef87d..2be5c7d2b4b0 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -29,12 +29,16 @@ macro_rules! closure_mac { fn main() { let a = Some(1u8).map(foo); + //~^ redundant_closure let c = Some(1u8).map(|a| {1+2; foo}(a)); true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion let _: Option> = true.then(std::vec::Vec::new); // special case vec! + //~^ redundant_closure let d = Some(1u8).map(|a| foo(foo2(a))); //is adjusted? + //~^ redundant_closure all(&[1, 2, 3], &&2, below); //is adjusted + //~^ redundant_closure unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } @@ -42,6 +46,7 @@ fn main() { // See #815 let e = Some(1u8).map(|a| divergent(a)); let e = Some(1u8).map(generic); + //~^ redundant_closure let e = Some(1u8).map(generic); // See #515 let a: Option)>> = @@ -94,16 +99,22 @@ impl<'a> std::ops::Deref for TestStruct<'a> { fn test_redundant_closures_containing_method_calls() { let i = 10; let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear); + //~^ redundant_closure_for_method_calls unsafe { let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); } let e = Some("str").map(std::string::ToString::to_string); + //~^ redundant_closure_for_method_calls let e = Some('a').map(char::to_uppercase); + //~^ redundant_closure_for_method_calls let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect(); + //~^ redundant_closure_for_method_calls let e = Some(PathBuf::new()).as_ref().and_then(|s| s.to_str()); let c = Some(TestStruct { some_ref: &i }) .as_ref() @@ -120,6 +131,7 @@ fn test_redundant_closures_containing_method_calls() { fn issue14096() { let x = Some("42"); let _ = x.map(str::parse::); + //~^ redundant_closure_for_method_calls } } @@ -172,6 +184,7 @@ fn generic(_: T) -> u8 { fn passes_fn_mut(mut x: Box) { requires_fn_once(x); + //~^ redundant_closure } fn requires_fn_once(_: T) {} @@ -179,11 +192,13 @@ fn test_redundant_closure_with_function_pointer() { type FnPtrType = fn(u8); let foo_ptr: FnPtrType = foo; let a = Some(1u8).map(foo_ptr); + //~^ redundant_closure } fn test_redundant_closure_with_another_closure() { let closure = |a| println!("{}", a); let a = Some(1u8).map(closure); + //~^ redundant_closure } fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { @@ -216,8 +231,11 @@ fn mutable_closure_used_again(x: Vec, y: Vec, z: Vec) { let mut res = Vec::new(); let mut add_to_res = |n| res.push(n); x.into_iter().for_each(&mut add_to_res); + //~^ redundant_closure y.into_iter().for_each(&mut add_to_res); + //~^ redundant_closure z.into_iter().for_each(add_to_res); + //~^ redundant_closure } fn mutable_closure_in_loop() { @@ -225,10 +243,12 @@ fn mutable_closure_in_loop() { let mut closure = |n| value += n; for _ in 0..5 { Some(1).map(&mut closure); + //~^ redundant_closure let mut value = 0; let mut in_loop = |n| value += n; Some(1).map(in_loop); + //~^ redundant_closure } } @@ -322,13 +342,16 @@ fn not_general_enough() { pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} takes_fn_mut(&mut f); + //~^ redundant_closure fn takes_fn_once(_: impl FnOnce()) {} takes_fn_once(&mut f); + //~^ redundant_closure f(); move || takes_fn_mut(&mut f_used_once) + //~^ redundant_closure } impl dyn TestTrait + '_ { @@ -341,16 +364,20 @@ impl dyn TestTrait + '_ { fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(<[u8; 3]>::as_slice); + //~^ redundant_closure_for_method_calls let slice_opt: Option<&[u8]> = Some(b"slice"); slice_opt.map(<[u8]>::len); + //~^ redundant_closure_for_method_calls let ptr_opt: Option<*const usize> = Some(&487); ptr_opt.map(<*const usize>::is_null); + //~^ redundant_closure_for_method_calls let test_struct = TestStruct { some_ref: &487 }; let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct); dyn_opt.map(::method_on_dyn); + //~^ redundant_closure_for_method_calls } // https://github.com/rust-lang/rust-clippy/issues/12199 @@ -411,6 +438,7 @@ fn _mixed_late_bound_and_early_bound_regions() { *y } let _ = f(&0, f2); + //~^ redundant_closure } fn _closure_with_types() { @@ -439,10 +467,12 @@ mod issue_10854 { pub fn calls_test(test: Option) -> Option { test.map(Test::method) + //~^ redundant_closure_for_method_calls } pub fn calls_outer(test: Option) -> Option { test.map(super::Outer::method) + //~^ redundant_closure_for_method_calls } } @@ -456,6 +486,7 @@ mod issue_10854 { pub fn calls_into_mod(test: Option) -> Option { test.map(test_mod::Test::method) + //~^ redundant_closure_for_method_calls } mod a { @@ -463,6 +494,7 @@ mod issue_10854 { pub mod c { pub fn extreme_nesting(test: Option) -> Option { test.map(crate::issue_10854::d::Test::method) + //~^ redundant_closure_for_method_calls } } } @@ -482,10 +514,12 @@ mod issue_10854 { mod issue_12853 { fn f_by_value(f: F) { let x = Box::new(|| None.map(&f)); + //~^ redundant_closure x(); } fn f_by_ref(f: &F) { let x = Box::new(|| None.map(f)); + //~^ redundant_closure x(); } } @@ -503,5 +537,6 @@ mod issue_13073 { let _field = bind.as_deref().or_else(|| get_default()).unwrap(); // should lint let _field = bind.or_else(get_default).unwrap(); + //~^ redundant_closure } } diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 9bcee4eba340..7c9a92306b95 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -29,12 +29,16 @@ macro_rules! closure_mac { fn main() { let a = Some(1u8).map(|a| foo(a)); + //~^ redundant_closure let c = Some(1u8).map(|a| {1+2; foo}(a)); true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion let _: Option> = true.then(|| vec![]); // special case vec! + //~^ redundant_closure let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? + //~^ redundant_closure all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted + //~^ redundant_closure unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } @@ -42,6 +46,7 @@ fn main() { // See #815 let e = Some(1u8).map(|a| divergent(a)); let e = Some(1u8).map(|a| generic(a)); + //~^ redundant_closure let e = Some(1u8).map(generic); // See #515 let a: Option)>> = @@ -94,16 +99,22 @@ impl<'a> std::ops::Deref for TestStruct<'a> { fn test_redundant_closures_containing_method_calls() { let i = 10; let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); + //~^ redundant_closure_for_method_calls let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref()); let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); + //~^ redundant_closure_for_method_calls unsafe { let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe()); } let e = Some("str").map(|s| s.to_string()); + //~^ redundant_closure_for_method_calls let e = Some('a').map(|s| s.to_uppercase()); + //~^ redundant_closure_for_method_calls let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect(); let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); + //~^ redundant_closure_for_method_calls let e = Some(PathBuf::new()).as_ref().and_then(|s| s.to_str()); let c = Some(TestStruct { some_ref: &i }) .as_ref() @@ -120,6 +131,7 @@ fn test_redundant_closures_containing_method_calls() { fn issue14096() { let x = Some("42"); let _ = x.map(|x| x.parse::()); + //~^ redundant_closure_for_method_calls } } @@ -172,6 +184,7 @@ fn generic(_: T) -> u8 { fn passes_fn_mut(mut x: Box) { requires_fn_once(|| x()); + //~^ redundant_closure } fn requires_fn_once(_: T) {} @@ -179,11 +192,13 @@ fn test_redundant_closure_with_function_pointer() { type FnPtrType = fn(u8); let foo_ptr: FnPtrType = foo; let a = Some(1u8).map(|a| foo_ptr(a)); + //~^ redundant_closure } fn test_redundant_closure_with_another_closure() { let closure = |a| println!("{}", a); let a = Some(1u8).map(|a| closure(a)); + //~^ redundant_closure } fn make_lazy(f: impl Fn() -> fn(u8) -> u8) -> impl Fn(u8) -> u8 { @@ -216,8 +231,11 @@ fn mutable_closure_used_again(x: Vec, y: Vec, z: Vec) { let mut res = Vec::new(); let mut add_to_res = |n| res.push(n); x.into_iter().for_each(|x| add_to_res(x)); + //~^ redundant_closure y.into_iter().for_each(|x| add_to_res(x)); + //~^ redundant_closure z.into_iter().for_each(|x| add_to_res(x)); + //~^ redundant_closure } fn mutable_closure_in_loop() { @@ -225,10 +243,12 @@ fn mutable_closure_in_loop() { let mut closure = |n| value += n; for _ in 0..5 { Some(1).map(|n| closure(n)); + //~^ redundant_closure let mut value = 0; let mut in_loop = |n| value += n; Some(1).map(|n| in_loop(n)); + //~^ redundant_closure } } @@ -322,13 +342,16 @@ fn not_general_enough() { pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() { fn takes_fn_mut(_: impl FnMut()) {} takes_fn_mut(|| f()); + //~^ redundant_closure fn takes_fn_once(_: impl FnOnce()) {} takes_fn_once(|| f()); + //~^ redundant_closure f(); move || takes_fn_mut(|| f_used_once()) + //~^ redundant_closure } impl dyn TestTrait + '_ { @@ -341,16 +364,20 @@ impl dyn TestTrait + '_ { fn angle_brackets_and_args() { let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]); array_opt.map(|a| a.as_slice()); + //~^ redundant_closure_for_method_calls let slice_opt: Option<&[u8]> = Some(b"slice"); slice_opt.map(|s| s.len()); + //~^ redundant_closure_for_method_calls let ptr_opt: Option<*const usize> = Some(&487); ptr_opt.map(|p| p.is_null()); + //~^ redundant_closure_for_method_calls let test_struct = TestStruct { some_ref: &487 }; let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct); dyn_opt.map(|d| d.method_on_dyn()); + //~^ redundant_closure_for_method_calls } // https://github.com/rust-lang/rust-clippy/issues/12199 @@ -411,6 +438,7 @@ fn _mixed_late_bound_and_early_bound_regions() { *y } let _ = f(&0, |x, y| f2(x, y)); + //~^ redundant_closure } fn _closure_with_types() { @@ -439,10 +467,12 @@ mod issue_10854 { pub fn calls_test(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } pub fn calls_outer(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } } @@ -456,6 +486,7 @@ mod issue_10854 { pub fn calls_into_mod(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } mod a { @@ -463,6 +494,7 @@ mod issue_10854 { pub mod c { pub fn extreme_nesting(test: Option) -> Option { test.map(|t| t.method()) + //~^ redundant_closure_for_method_calls } } } @@ -482,10 +514,12 @@ mod issue_10854 { mod issue_12853 { fn f_by_value(f: F) { let x = Box::new(|| None.map(|x| f(x))); + //~^ redundant_closure x(); } fn f_by_ref(f: &F) { let x = Box::new(|| None.map(|x| f(x))); + //~^ redundant_closure x(); } } @@ -503,5 +537,6 @@ mod issue_13073 { let _field = bind.as_deref().or_else(|| get_default()).unwrap(); // should lint let _field = bind.or_else(|| get_default()).unwrap(); + //~^ redundant_closure } } diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index ac58e87bc5ec..434a034a4f8e 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -8,31 +8,31 @@ LL | let a = Some(1u8).map(|a| foo(a)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: redundant closure - --> tests/ui/eta.rs:35:40 + --> tests/ui/eta.rs:36:40 | LL | let _: Option> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> tests/ui/eta.rs:36:35 + --> tests/ui/eta.rs:38: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 - --> tests/ui/eta.rs:37:26 + --> tests/ui/eta.rs:40: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 - --> tests/ui/eta.rs:44:27 + --> tests/ui/eta.rs:48:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> tests/ui/eta.rs:96:51 + --> tests/ui/eta.rs:101:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -41,175 +41,175 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure - --> tests/ui/eta.rs:97:51 + --> tests/ui/eta.rs:103: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 - --> tests/ui/eta.rs:99:42 + --> tests/ui/eta.rs:106: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 - --> tests/ui/eta.rs:103:29 + --> tests/ui/eta.rs:111: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 - --> tests/ui/eta.rs:104:27 + --> tests/ui/eta.rs:113: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 - --> tests/ui/eta.rs:106:65 + --> tests/ui/eta.rs:116: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 - --> tests/ui/eta.rs:122:23 + --> tests/ui/eta.rs:133:23 | LL | let _ = x.map(|x| x.parse::()); | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `str::parse::` error: redundant closure - --> tests/ui/eta.rs:174:22 + --> tests/ui/eta.rs:186:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> tests/ui/eta.rs:181:27 + --> tests/ui/eta.rs:194:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> tests/ui/eta.rs:186:27 + --> tests/ui/eta.rs:200:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> tests/ui/eta.rs:218:28 + --> tests/ui/eta.rs:233: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 - --> tests/ui/eta.rs:219:28 + --> tests/ui/eta.rs:235: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 - --> tests/ui/eta.rs:220:28 + --> tests/ui/eta.rs:237: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 - --> tests/ui/eta.rs:227:21 + --> tests/ui/eta.rs:245:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> tests/ui/eta.rs:231:21 + --> tests/ui/eta.rs:250:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> tests/ui/eta.rs:324:18 + --> tests/ui/eta.rs:344:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:327:19 + --> tests/ui/eta.rs:348:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:331:26 + --> tests/ui/eta.rs:353:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> tests/ui/eta.rs:343:19 + --> tests/ui/eta.rs:366:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> tests/ui/eta.rs:346:19 + --> tests/ui/eta.rs:370:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> tests/ui/eta.rs:349:17 + --> tests/ui/eta.rs:374:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> tests/ui/eta.rs:353:17 + --> tests/ui/eta.rs:379:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `::method_on_dyn` error: redundant closure - --> tests/ui/eta.rs:413:19 + --> tests/ui/eta.rs:440:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> tests/ui/eta.rs:441:22 + --> tests/ui/eta.rs:469:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> tests/ui/eta.rs:445:22 + --> tests/ui/eta.rs:474:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> tests/ui/eta.rs:458:18 + --> tests/ui/eta.rs:488:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> tests/ui/eta.rs:465:30 + --> tests/ui/eta.rs:496:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` error: redundant closure - --> tests/ui/eta.rs:484:38 + --> tests/ui/eta.rs:516:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `&f` error: redundant closure - --> tests/ui/eta.rs:488:38 + --> tests/ui/eta.rs:521:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` error: redundant closure - --> tests/ui/eta.rs:505:35 + --> tests/ui/eta.rs:539:35 | LL | let _field = bind.or_else(|| get_default()).unwrap(); | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default` diff --git a/tests/ui/eta_nostd.fixed b/tests/ui/eta_nostd.fixed index 23059c52b67f..134af34a826a 100644 --- a/tests/ui/eta_nostd.fixed +++ b/tests/ui/eta_nostd.fixed @@ -7,4 +7,5 @@ use alloc::vec::Vec; fn issue_13895() { let _: Option> = true.then(alloc::vec::Vec::new); + //~^ redundant_closure } diff --git a/tests/ui/eta_nostd.rs b/tests/ui/eta_nostd.rs index ae44ac348c64..8d0541bedb2e 100644 --- a/tests/ui/eta_nostd.rs +++ b/tests/ui/eta_nostd.rs @@ -7,4 +7,5 @@ use alloc::vec::Vec; fn issue_13895() { let _: Option> = true.then(|| vec![]); + //~^ redundant_closure } diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed index 372f64f7d99e..99d09774d16d 100644 --- a/tests/ui/excessive_precision.fixed +++ b/tests/ui/excessive_precision.fixed @@ -18,16 +18,22 @@ fn main() { const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; const BAD32_1: f32 = 0.123_456_79_f32; + //~^ excessive_precision const BAD32_2: f32 = 0.123_456_79; + //~^ excessive_precision const BAD32_3: f32 = 0.1; + //~^ excessive_precision const BAD32_EDGE: f32 = 1.000_001; + //~^ excessive_precision const BAD64_1: f64 = 0.123_456_789_012_345_67f64; const BAD64_2: f64 = 0.123_456_789_012_345_67; const BAD64_3: f64 = 0.1; + //~^ excessive_precision // Literal as param println!("{:?}", 8.888_888_888_888_89); + //~^ excessive_precision // // TODO add inferred type tests for f32 // Locals @@ -39,8 +45,11 @@ fn main() { let good64_inf = 0.123_456_789_012; let bad32: f32 = 1.123_456_8; + //~^ excessive_precision let bad32_suf: f32 = 1.123_456_8_f32; + //~^ excessive_precision let bad32_inf = 1.123_456_8_f32; + //~^ excessive_precision let bad64: f64 = 0.123_456_789_012_345_67; let bad64_suf: f64 = 0.123_456_789_012_345_67f64; @@ -51,14 +60,18 @@ fn main() { let good_vec64: Vec = vec![0.123_456_789]; let bad_vec32: Vec = vec![0.123_456_79]; + //~^ excessive_precision let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; + //~^ excessive_precision // Exponential float notation let good_e32: f32 = 1e-10; let bad_e32: f32 = 1.123_456_8e-10; + //~^ excessive_precision let good_bige32: f32 = 1E-10; let bad_bige32: f32 = 1.123_456_8E-10; + //~^ excessive_precision // Inferred type let good_inferred: f32 = 1f32 * 1_000_000_000.; @@ -68,9 +81,11 @@ fn main() { // issue #7744 let _ = 2.225_073_858_507_201e-308_f64; + //~^ excessive_precision // issue #7745 let _ = 0_f64; + //~^ excessive_precision // issue #9910 const INF1: f32 = 1.0e+33f32; @@ -81,5 +96,6 @@ fn main() { // issue #12954 const _: f64 = 3.0; + //~^ excessive_precision const _: f64 = 3.0000000000000000; } diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs index 1e40efbf2452..a542fb2e7e3c 100644 --- a/tests/ui/excessive_precision.rs +++ b/tests/ui/excessive_precision.rs @@ -18,16 +18,22 @@ fn main() { const GOOD64_DOT: f32 = 10_000_000_000_000_000.0; const BAD32_1: f32 = 0.123_456_789_f32; + //~^ excessive_precision const BAD32_2: f32 = 0.123_456_789; + //~^ excessive_precision const BAD32_3: f32 = 0.100_000_000_000_1; + //~^ excessive_precision const BAD32_EDGE: f32 = 1.000_000_9; + //~^ excessive_precision const BAD64_1: f64 = 0.123_456_789_012_345_67f64; const BAD64_2: f64 = 0.123_456_789_012_345_67; const BAD64_3: f64 = 0.100_000_000_000_000_000_1; + //~^ excessive_precision // Literal as param println!("{:?}", 8.888_888_888_888_888_888_888); + //~^ excessive_precision // // TODO add inferred type tests for f32 // Locals @@ -39,8 +45,11 @@ fn main() { let good64_inf = 0.123_456_789_012; let bad32: f32 = 1.123_456_789; + //~^ excessive_precision let bad32_suf: f32 = 1.123_456_789_f32; + //~^ excessive_precision let bad32_inf = 1.123_456_789_f32; + //~^ excessive_precision let bad64: f64 = 0.123_456_789_012_345_67; let bad64_suf: f64 = 0.123_456_789_012_345_67f64; @@ -51,14 +60,18 @@ fn main() { let good_vec64: Vec = vec![0.123_456_789]; let bad_vec32: Vec = vec![0.123_456_789]; + //~^ excessive_precision let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; + //~^ excessive_precision // Exponential float notation let good_e32: f32 = 1e-10; let bad_e32: f32 = 1.123_456_788_888e-10; + //~^ excessive_precision let good_bige32: f32 = 1E-10; let bad_bige32: f32 = 1.123_456_788_888E-10; + //~^ excessive_precision // Inferred type let good_inferred: f32 = 1f32 * 1_000_000_000.; @@ -68,9 +81,11 @@ fn main() { // issue #7744 let _ = 2.225_073_858_507_201_1e-308_f64; + //~^ excessive_precision // issue #7745 let _ = 1.000_000_000_000_001e-324_f64; + //~^ excessive_precision // issue #9910 const INF1: f32 = 1.0e+33f32; @@ -81,5 +96,6 @@ fn main() { // issue #12954 const _: f64 = 3.0000000000000000e+00; + //~^ excessive_precision const _: f64 = 3.0000000000000000; } diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 81e4fb6765d0..09fe3de4993a 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -12,7 +12,7 @@ LL | const BAD32_1: f32 = 0.123_456_79_f32; | ~~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:21:26 + --> tests/ui/excessive_precision.rs:22:26 | LL | const BAD32_2: f32 = 0.123_456_789; | ^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | const BAD32_2: f32 = 0.123_456_79; | ~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:22:26 + --> tests/ui/excessive_precision.rs:24:26 | LL | const BAD32_3: f32 = 0.100_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | const BAD32_3: f32 = 0.1; | ~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:23:29 + --> tests/ui/excessive_precision.rs:26:29 | LL | const BAD32_EDGE: f32 = 1.000_000_9; | ^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | const BAD32_EDGE: f32 = 1.000_001; | ~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:27:26 + --> tests/ui/excessive_precision.rs:31:26 | LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | const BAD64_3: f64 = 0.1; | ~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:30:22 + --> tests/ui/excessive_precision.rs:35:22 | LL | println!("{:?}", 8.888_888_888_888_888_888_888); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | println!("{:?}", 8.888_888_888_888_89); | ~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:41:22 + --> tests/ui/excessive_precision.rs:47:22 | LL | let bad32: f32 = 1.123_456_789; | ^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let bad32: f32 = 1.123_456_8; | ~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:42:26 + --> tests/ui/excessive_precision.rs:49:26 | LL | let bad32_suf: f32 = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let bad32_suf: f32 = 1.123_456_8_f32; | ~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:43:21 + --> tests/ui/excessive_precision.rs:51:21 | LL | let bad32_inf = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let bad32_inf = 1.123_456_8_f32; | ~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:53:36 + --> tests/ui/excessive_precision.rs:62:36 | LL | let bad_vec32: Vec = vec![0.123_456_789]; | ^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let bad_vec32: Vec = vec![0.123_456_79]; | ~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:54:36 + --> tests/ui/excessive_precision.rs:64:36 | LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_78]; | ~~~~~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:58:24 + --> tests/ui/excessive_precision.rs:69:24 | LL | let bad_e32: f32 = 1.123_456_788_888e-10; | ^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let bad_e32: f32 = 1.123_456_8e-10; | ~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:61:27 + --> tests/ui/excessive_precision.rs:73:27 | LL | let bad_bige32: f32 = 1.123_456_788_888E-10; | ^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let bad_bige32: f32 = 1.123_456_8E-10; | ~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:70:13 + --> tests/ui/excessive_precision.rs:83:13 | LL | let _ = 2.225_073_858_507_201_1e-308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | let _ = 2.225_073_858_507_201e-308_f64; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:73:13 + --> tests/ui/excessive_precision.rs:87:13 | LL | let _ = 1.000_000_000_000_001e-324_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | let _ = 0_f64; | ~~~~~ error: float has excessive precision - --> tests/ui/excessive_precision.rs:83:20 + --> tests/ui/excessive_precision.rs:98:20 | LL | const _: f64 = 3.0000000000000000e+00; | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/exhaustive_items.fixed b/tests/ui/exhaustive_items.fixed index 1bf33a5f2f13..a3c584c2a269 100644 --- a/tests/ui/exhaustive_items.fixed +++ b/tests/ui/exhaustive_items.fixed @@ -8,6 +8,7 @@ fn main() { pub mod enums { #[non_exhaustive] pub enum Exhaustive { + //~^ exhaustive_enums Foo, Bar, Baz, @@ -18,6 +19,7 @@ pub mod enums { #[repr(C)] #[non_exhaustive] pub enum ExhaustiveWithAttrs { + //~^ exhaustive_enums Foo, Bar, Baz, @@ -54,6 +56,7 @@ pub mod enums { pub mod structs { #[non_exhaustive] pub struct Exhaustive { + //~^ exhaustive_structs pub foo: u8, pub bar: String, } diff --git a/tests/ui/exhaustive_items.rs b/tests/ui/exhaustive_items.rs index 1328791e186d..b1f0c789b709 100644 --- a/tests/ui/exhaustive_items.rs +++ b/tests/ui/exhaustive_items.rs @@ -7,6 +7,7 @@ fn main() { pub mod enums { pub enum Exhaustive { + //~^ exhaustive_enums Foo, Bar, Baz, @@ -16,6 +17,7 @@ pub mod enums { /// Some docs #[repr(C)] pub enum ExhaustiveWithAttrs { + //~^ exhaustive_enums Foo, Bar, Baz, @@ -51,6 +53,7 @@ pub mod enums { pub mod structs { pub struct Exhaustive { + //~^ exhaustive_structs pub foo: u8, pub bar: String, } diff --git a/tests/ui/exhaustive_items.stderr b/tests/ui/exhaustive_items.stderr index 536fbe8d790f..c92c8a9efaae 100644 --- a/tests/ui/exhaustive_items.stderr +++ b/tests/ui/exhaustive_items.stderr @@ -2,6 +2,7 @@ error: exported enums should not be exhaustive --> tests/ui/exhaustive_items.rs:9:5 | LL | / pub enum Exhaustive { +LL | | LL | | Foo, LL | | Bar, LL | | Baz, @@ -21,9 +22,10 @@ LL ~ pub enum Exhaustive { | error: exported enums should not be exhaustive - --> tests/ui/exhaustive_items.rs:18:5 + --> tests/ui/exhaustive_items.rs:19:5 | LL | / pub enum ExhaustiveWithAttrs { +LL | | LL | | Foo, LL | | Bar, LL | | Baz, @@ -38,9 +40,10 @@ LL ~ pub enum ExhaustiveWithAttrs { | error: exported structs should not be exhaustive - --> tests/ui/exhaustive_items.rs:53:5 + --> tests/ui/exhaustive_items.rs:55:5 | LL | / pub struct Exhaustive { +LL | | LL | | pub foo: u8, LL | | pub bar: String, LL | | } diff --git a/tests/ui/exit1.rs b/tests/ui/exit1.rs index 36b3c42fd995..127c72aac99f 100644 --- a/tests/ui/exit1.rs +++ b/tests/ui/exit1.rs @@ -3,8 +3,9 @@ fn not_main() { if true { std::process::exit(4); - //~^ ERROR: usage of `process::exit` - //~| NOTE: `-D clippy::exit` implied by `-D warnings` + //~^ exit + + } } diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs index 9bbb7b073a4b..2e2c4828afe6 100644 --- a/tests/ui/exit2.rs +++ b/tests/ui/exit2.rs @@ -2,8 +2,9 @@ fn also_not_main() { std::process::exit(3); - //~^ ERROR: usage of `process::exit` - //~| NOTE: `-D clippy::exit` implied by `-D warnings` + //~^ exit + + } fn main() { diff --git a/tests/ui/exit3.rs b/tests/ui/exit3.rs index cab908aafd33..a8af1b225788 100644 --- a/tests/ui/exit3.rs +++ b/tests/ui/exit3.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::exit)] fn main() { diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs index f15b3d37e154..575c29e6f31c 100644 --- a/tests/ui/expect.rs +++ b/tests/ui/expect.rs @@ -4,15 +4,18 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); - //~^ ERROR: used `expect()` on an `Option` value + //~^ expect_used + } fn expect_result() { let res: Result = Ok(0); let _ = res.expect(""); - //~^ ERROR: used `expect()` on a `Result` value + //~^ expect_used + let _ = res.expect_err(""); - //~^ ERROR: used `expect_err()` on a `Result` value + //~^ expect_used + } fn main() { diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index c0ba3390aac5..b44429a3b71d 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -9,7 +9,7 @@ LL | let _ = opt.expect(""); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value - --> tests/ui/expect.rs:12:13 + --> tests/ui/expect.rs:13:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value - --> tests/ui/expect.rs:14:13 + --> tests/ui/expect.rs:16:13 | LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed index 8f800c71941a..73eaebf773c8 100644 --- a/tests/ui/expect_fun_call.fixed +++ b/tests/ui/expect_fun_call.fixed @@ -33,12 +33,15 @@ fn main() { let error_code = 123_i32; let with_none_and_format: Option = None; with_none_and_format.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_as_str: Option = None; with_none_and_as_str.unwrap_or_else(|| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_format_with_macro: Option = None; with_none_and_format_with_macro.unwrap_or_else(|| panic!("Error {}: fake error", one!())); + //~^ expect_fun_call let with_ok: Result<(), ()> = Ok(()); with_ok.expect("error"); @@ -49,9 +52,11 @@ fn main() { let error_code = 123_i32; let with_err_and_format: Result<(), ()> = Err(()); with_err_and_format.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_err_and_as_str: Result<(), ()> = Err(()); with_err_and_as_str.unwrap_or_else(|_| panic!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_dummy_type = Foo::new(); with_dummy_type.expect("another test string"); @@ -64,6 +69,7 @@ fn main() { //Issue #2937 Some("foo").unwrap_or_else(|| panic!("{} {}", 1, 2)); + //~^ expect_fun_call //Issue #2979 - this should not lint { @@ -85,26 +91,35 @@ fn main() { } Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + //~^ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + //~^ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) }); + //~^ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) }); + //~^ expect_fun_call Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) }); + //~^ expect_fun_call } //Issue #3839 Some(true).unwrap_or_else(|| panic!("key {}, {}", 1, 2)); + //~^ expect_fun_call //Issue #4912 - the receiver is a &Option { let opt = Some(1); let opt_ref = &opt; opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref)); + //~^ expect_fun_call } let format_capture: Option = None; format_capture.unwrap_or_else(|| panic!("{error_code}")); + //~^ expect_fun_call let format_capture_and_value: Option = None; format_capture_and_value.unwrap_or_else(|| panic!("{error_code}, {}", 1)); + //~^ expect_fun_call } diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs index b5cfafb2993e..ecebc9ebfb6f 100644 --- a/tests/ui/expect_fun_call.rs +++ b/tests/ui/expect_fun_call.rs @@ -33,12 +33,15 @@ fn main() { let error_code = 123_i32; let with_none_and_format: Option = None; with_none_and_format.expect(&format!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_none_and_as_str: Option = None; with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); + //~^ expect_fun_call let with_none_and_format_with_macro: Option = None; with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); + //~^ expect_fun_call let with_ok: Result<(), ()> = Ok(()); with_ok.expect("error"); @@ -49,9 +52,11 @@ fn main() { let error_code = 123_i32; let with_err_and_format: Result<(), ()> = Err(()); with_err_and_format.expect(&format!("Error {}: fake error", error_code)); + //~^ expect_fun_call let with_err_and_as_str: Result<(), ()> = Err(()); with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); + //~^ expect_fun_call let with_dummy_type = Foo::new(); with_dummy_type.expect("another test string"); @@ -64,6 +69,7 @@ fn main() { //Issue #2937 Some("foo").expect(format!("{} {}", 1, 2).as_ref()); + //~^ expect_fun_call //Issue #2979 - this should not lint { @@ -85,26 +91,35 @@ fn main() { } Some("foo").expect(&get_string()); + //~^ expect_fun_call Some("foo").expect(get_string().as_ref()); + //~^ expect_fun_call Some("foo").expect(get_string().as_str()); + //~^ expect_fun_call Some("foo").expect(get_static_str()); + //~^ expect_fun_call Some("foo").expect(get_non_static_str(&0)); + //~^ expect_fun_call } //Issue #3839 Some(true).expect(&format!("key {}, {}", 1, 2)); + //~^ expect_fun_call //Issue #4912 - the receiver is a &Option { let opt = Some(1); let opt_ref = &opt; opt_ref.expect(&format!("{:?}", opt_ref)); + //~^ expect_fun_call } let format_capture: Option = None; format_capture.expect(&format!("{error_code}")); + //~^ expect_fun_call let format_capture_and_value: Option = None; format_capture_and_value.expect(&format!("{error_code}, {}", 1)); + //~^ expect_fun_call } diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index 050c039f834d..36713196cb92 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -8,85 +8,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code = help: to override `-D warnings` add `#[allow(clippy::expect_fun_call)]` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:38:26 + --> tests/ui/expect_fun_call.rs:39: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: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:41:37 + --> tests/ui/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: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:51:25 + --> tests/ui/expect_fun_call.rs:54: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: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:54:25 + --> tests/ui/expect_fun_call.rs:58: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: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:66:17 + --> tests/ui/expect_fun_call.rs:71:17 | LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:87:21 + --> tests/ui/expect_fun_call.rs:93:21 | LL | Some("foo").expect(&get_string()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:88:21 + --> tests/ui/expect_fun_call.rs:95:21 | LL | Some("foo").expect(get_string().as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:89:21 + --> tests/ui/expect_fun_call.rs:97:21 | LL | Some("foo").expect(get_string().as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:91:21 + --> tests/ui/expect_fun_call.rs:100:21 | LL | Some("foo").expect(get_static_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:92:21 + --> tests/ui/expect_fun_call.rs:102:21 | LL | Some("foo").expect(get_non_static_str(&0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:96:16 + --> tests/ui/expect_fun_call.rs:107:16 | LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:102:17 + --> tests/ui/expect_fun_call.rs:114:17 | LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:106:20 + --> tests/ui/expect_fun_call.rs:119:20 | LL | format_capture.expect(&format!("{error_code}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))` error: function call inside of `expect` - --> tests/ui/expect_fun_call.rs:109:30 + --> tests/ui/expect_fun_call.rs:123: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 9d476259b87e..c7edf33012e0 100644 --- a/tests/ui/explicit_auto_deref.fixed +++ b/tests/ui/explicit_auto_deref.fixed @@ -67,43 +67,54 @@ fn main() { let s = String::new(); let _: &str = &s; + //~^ explicit_auto_deref let _: &str = &{ String::new() }; + //~^ explicit_auto_deref let _: &str = &mut { String::new() }; + //~^ explicit_auto_deref let _ = &*s; // Don't lint. Inferred type would change. let _: &_ = &*s; // Don't lint. Inferred type would change. f_str(&s); + //~^ explicit_auto_deref f_t(&*s); // Don't lint. Inferred type would change. f_ref_t(&*s); // Don't lint. Inferred type would change. f_str_t(&s, &*s); // Don't lint second param. + //~^ explicit_auto_deref let b = Box::new(Box::new(Box::new(5))); let _: &Box = &b; + //~^ explicit_auto_deref let _: &Box<_> = &**b; // Don't lint. Inferred type would change. f_box_t(&**b); // Don't lint. Inferred type would change. let c = |_x: &str| (); c(&s); + //~^ explicit_auto_deref let c = |_x| (); c(&*s); // Don't lint. Inferred type would change. fn _f(x: &String) -> &str { x + //~^ explicit_auto_deref } fn _f1(x: &String) -> &str { { x } + //~^ explicit_auto_deref } fn _f2(x: &String) -> &str { { x } + //~^ explicit_auto_deref } fn _f3(x: &Box>>) -> &Box { x + //~^ explicit_auto_deref } fn _f4( @@ -121,25 +132,38 @@ fn main() { f11: &dyn CallableT, ) { f1(&x); + //~^ explicit_auto_deref f2(&x); + //~^ explicit_auto_deref f3(&x); + //~^ explicit_auto_deref f4.callable_str()(&x); + //~^ explicit_auto_deref f5(&x); + //~^ explicit_auto_deref f6(&x); + //~^ explicit_auto_deref f7.callable_str()(&x); + //~^ explicit_auto_deref f8.callable_t()(&x); + //~^ explicit_auto_deref f9(&x); + //~^ explicit_auto_deref f10(&x); + //~^ explicit_auto_deref f11.callable_t()(&x); + //~^ explicit_auto_deref } struct S1<'a>(&'a str); let _ = S1(&s); + //~^ explicit_auto_deref struct S2<'a> { s: &'a str, } let _ = S2 { s: &s }; + //~^ explicit_auto_deref struct S3<'a, T: ?Sized>(&'a T); let _ = S3(&*s); // Don't lint. Inferred type would change. @@ -156,11 +180,15 @@ fn main() { impl<'a> E1<'a> { fn m1(s: &'a String) { let _ = Self::S1(s); + //~^ explicit_auto_deref let _ = Self::S2 { s: s }; + //~^ explicit_auto_deref } } let _ = E1::S1(&s); + //~^ explicit_auto_deref let _ = E1::S2 { s: &s }; + //~^ explicit_auto_deref enum E2<'a, T: ?Sized> { S1(&'a T), @@ -179,7 +207,9 @@ fn main() { let b = Box::new(Box::new(S5 { foo: 5 })); let _ = b.foo; let _ = b.foo; + //~^ explicit_auto_deref let _ = b.foo; + //~^ explicit_auto_deref struct S6 { foo: S5, @@ -195,8 +225,10 @@ fn main() { let ref_str = &"foo"; let _ = f_str(ref_str); + //~^ explicit_auto_deref let ref_ref_str = &ref_str; let _ = f_str(ref_ref_str); + //~^ explicit_auto_deref fn _f5(x: &u32) -> u32 { if true { @@ -207,7 +239,9 @@ fn main() { } f_str(&ref_str); // `needless_borrow` will suggest removing both references + //~^ explicit_auto_deref f_str(&ref_str); // `needless_borrow` will suggest removing only one reference + //~^ explicit_auto_deref let x = &&40; unsafe { @@ -217,6 +251,7 @@ fn main() { let s = &"str"; let _ = || return *s; let _ = || -> &'static str { return s }; + //~^ explicit_auto_deref struct X; struct Y(X); @@ -236,6 +271,7 @@ fn main() { fn deref_to_u>(x: &T) -> &U { x + //~^ explicit_auto_deref } let _ = |x: &'static Box>| -> &'static dyn Iterator { &**x }; @@ -259,11 +295,14 @@ fn main() { let c1 = |_: &Vec<&u32>| {}; let x = &&vec![&1u32]; c1(x); + //~^ explicit_auto_deref let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { if b { return x; + //~^ explicit_auto_deref } x + //~^ explicit_auto_deref }; trait WithAssoc { @@ -298,6 +337,7 @@ fn main() { // Issue #11366 let _: &mut u32 = match &mut Some(&mut 0u32) { Some(x) => x, + //~^ explicit_auto_deref None => panic!(), }; @@ -331,18 +371,23 @@ fn main() { }; let _ = &mut (*x.u).x; let _ = &mut { x.u }.x; + //~^ explicit_auto_deref let _ = &mut ({ *x.u }).x; let mut x = U { u: Wrap(core::mem::ManuallyDrop::new(S8 { x: "" })), }; let _ = &mut (*x.u).x; + //~^ explicit_auto_deref let _ = &mut { x.u }.x; + //~^ explicit_auto_deref let _ = &mut ({ **x.u }).x; let mut x = U { u: Wrap(S8 { x: "" }) }; let _ = &mut x.u.x; + //~^ explicit_auto_deref let _ = &mut { x.u }.x; + //~^ explicit_auto_deref let _ = &mut ({ *x.u }).x; } } @@ -366,6 +411,7 @@ mod issue_12969 { let wrapped_bar = Wrapper(""); foo(&wrapped_bar); + //~^ explicit_auto_deref } } diff --git a/tests/ui/explicit_auto_deref.rs b/tests/ui/explicit_auto_deref.rs index 23307c837f0e..4d2b2fc3fc39 100644 --- a/tests/ui/explicit_auto_deref.rs +++ b/tests/ui/explicit_auto_deref.rs @@ -67,43 +67,54 @@ fn main() { let s = String::new(); let _: &str = &*s; + //~^ explicit_auto_deref let _: &str = &*{ String::new() }; + //~^ explicit_auto_deref let _: &str = &mut *{ String::new() }; + //~^ explicit_auto_deref let _ = &*s; // Don't lint. Inferred type would change. let _: &_ = &*s; // Don't lint. Inferred type would change. f_str(&*s); + //~^ explicit_auto_deref f_t(&*s); // Don't lint. Inferred type would change. f_ref_t(&*s); // Don't lint. Inferred type would change. f_str_t(&*s, &*s); // Don't lint second param. + //~^ explicit_auto_deref let b = Box::new(Box::new(Box::new(5))); let _: &Box = &**b; + //~^ explicit_auto_deref let _: &Box<_> = &**b; // Don't lint. Inferred type would change. f_box_t(&**b); // Don't lint. Inferred type would change. let c = |_x: &str| (); c(&*s); + //~^ explicit_auto_deref let c = |_x| (); c(&*s); // Don't lint. Inferred type would change. fn _f(x: &String) -> &str { &**x + //~^ explicit_auto_deref } fn _f1(x: &String) -> &str { { &**x } + //~^ explicit_auto_deref } fn _f2(x: &String) -> &str { &**{ x } + //~^ explicit_auto_deref } fn _f3(x: &Box>>) -> &Box { &***x + //~^ explicit_auto_deref } fn _f4( @@ -121,25 +132,38 @@ fn main() { f11: &dyn CallableT, ) { f1(&*x); + //~^ explicit_auto_deref f2(&*x); + //~^ explicit_auto_deref f3(&*x); + //~^ explicit_auto_deref f4.callable_str()(&*x); + //~^ explicit_auto_deref f5(&*x); + //~^ explicit_auto_deref f6(&*x); + //~^ explicit_auto_deref f7.callable_str()(&*x); + //~^ explicit_auto_deref f8.callable_t()(&*x); + //~^ explicit_auto_deref f9(&*x); + //~^ explicit_auto_deref f10(&*x); + //~^ explicit_auto_deref f11.callable_t()(&*x); + //~^ explicit_auto_deref } struct S1<'a>(&'a str); let _ = S1(&*s); + //~^ explicit_auto_deref struct S2<'a> { s: &'a str, } let _ = S2 { s: &*s }; + //~^ explicit_auto_deref struct S3<'a, T: ?Sized>(&'a T); let _ = S3(&*s); // Don't lint. Inferred type would change. @@ -156,11 +180,15 @@ fn main() { impl<'a> E1<'a> { fn m1(s: &'a String) { let _ = Self::S1(&**s); + //~^ explicit_auto_deref let _ = Self::S2 { s: &**s }; + //~^ explicit_auto_deref } } let _ = E1::S1(&*s); + //~^ explicit_auto_deref let _ = E1::S2 { s: &*s }; + //~^ explicit_auto_deref enum E2<'a, T: ?Sized> { S1(&'a T), @@ -179,7 +207,9 @@ fn main() { let b = Box::new(Box::new(S5 { foo: 5 })); let _ = b.foo; let _ = (*b).foo; + //~^ explicit_auto_deref let _ = (**b).foo; + //~^ explicit_auto_deref struct S6 { foo: S5, @@ -195,8 +225,10 @@ fn main() { let ref_str = &"foo"; let _ = f_str(*ref_str); + //~^ explicit_auto_deref let ref_ref_str = &ref_str; let _ = f_str(**ref_ref_str); + //~^ explicit_auto_deref fn _f5(x: &u32) -> u32 { if true { @@ -207,7 +239,9 @@ fn main() { } f_str(&&*ref_str); // `needless_borrow` will suggest removing both references + //~^ explicit_auto_deref f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference + //~^ explicit_auto_deref let x = &&40; unsafe { @@ -217,6 +251,7 @@ fn main() { let s = &"str"; let _ = || return *s; let _ = || -> &'static str { return *s }; + //~^ explicit_auto_deref struct X; struct Y(X); @@ -236,6 +271,7 @@ fn main() { fn deref_to_u>(x: &T) -> &U { &**x + //~^ explicit_auto_deref } let _ = |x: &'static Box>| -> &'static dyn Iterator { &**x }; @@ -259,11 +295,14 @@ fn main() { let c1 = |_: &Vec<&u32>| {}; let x = &&vec![&1u32]; c1(*x); + //~^ explicit_auto_deref let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { if b { return *x; + //~^ explicit_auto_deref } *x + //~^ explicit_auto_deref }; trait WithAssoc { @@ -298,6 +337,7 @@ fn main() { // Issue #11366 let _: &mut u32 = match &mut Some(&mut 0u32) { Some(x) => &mut *x, + //~^ explicit_auto_deref None => panic!(), }; @@ -331,18 +371,23 @@ fn main() { }; let _ = &mut (*x.u).x; let _ = &mut (*{ x.u }).x; + //~^ explicit_auto_deref let _ = &mut ({ *x.u }).x; let mut x = U { u: Wrap(core::mem::ManuallyDrop::new(S8 { x: "" })), }; let _ = &mut (**x.u).x; + //~^ explicit_auto_deref let _ = &mut (**{ x.u }).x; + //~^ explicit_auto_deref let _ = &mut ({ **x.u }).x; let mut x = U { u: Wrap(S8 { x: "" }) }; let _ = &mut (*x.u).x; + //~^ explicit_auto_deref let _ = &mut (*{ x.u }).x; + //~^ explicit_auto_deref let _ = &mut ({ *x.u }).x; } } @@ -366,6 +411,7 @@ mod issue_12969 { let wrapped_bar = Wrapper(""); foo(&*wrapped_bar); + //~^ explicit_auto_deref } } diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index 0b05a554eb11..e1cfb214864f 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -8,271 +8,271 @@ LL | let _: &str = &*s; = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:70:19 + --> tests/ui/explicit_auto_deref.rs:71:19 | LL | let _: &str = &*{ String::new() }; | ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:71:19 + --> tests/ui/explicit_auto_deref.rs:73:19 | LL | let _: &str = &mut *{ String::new() }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:75:11 + --> tests/ui/explicit_auto_deref.rs:78:11 | LL | f_str(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:79:13 + --> tests/ui/explicit_auto_deref.rs:83:13 | LL | f_str_t(&*s, &*s); // Don't lint second param. | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:82:24 + --> tests/ui/explicit_auto_deref.rs:87:24 | LL | let _: &Box = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:88:7 + --> tests/ui/explicit_auto_deref.rs:94:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:94:9 + --> tests/ui/explicit_auto_deref.rs:101:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:98:11 + --> tests/ui/explicit_auto_deref.rs:106:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:102:9 + --> tests/ui/explicit_auto_deref.rs:111:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:106:9 + --> tests/ui/explicit_auto_deref.rs:116:9 | LL | &***x | ^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:123:12 + --> tests/ui/explicit_auto_deref.rs:134:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:124:12 + --> tests/ui/explicit_auto_deref.rs:136:12 | LL | f2(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:125:12 + --> tests/ui/explicit_auto_deref.rs:138:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:126:27 + --> tests/ui/explicit_auto_deref.rs:140:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:127:12 + --> tests/ui/explicit_auto_deref.rs:142:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:128:12 + --> tests/ui/explicit_auto_deref.rs:144:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:129:27 + --> tests/ui/explicit_auto_deref.rs:146:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:130:25 + --> tests/ui/explicit_auto_deref.rs:148:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:131:12 + --> tests/ui/explicit_auto_deref.rs:150:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:132:13 + --> tests/ui/explicit_auto_deref.rs:152:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:133:26 + --> tests/ui/explicit_auto_deref.rs:154:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:137:16 + --> tests/ui/explicit_auto_deref.rs:159:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:142:21 + --> tests/ui/explicit_auto_deref.rs:165:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:158:30 + --> tests/ui/explicit_auto_deref.rs:182:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:159:35 + --> tests/ui/explicit_auto_deref.rs:184:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:162:20 + --> tests/ui/explicit_auto_deref.rs:188:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:163:25 + --> tests/ui/explicit_auto_deref.rs:190:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:181:13 + --> tests/ui/explicit_auto_deref.rs:209:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:182:13 + --> tests/ui/explicit_auto_deref.rs:211:13 | LL | let _ = (**b).foo; | ^^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:197:19 + --> tests/ui/explicit_auto_deref.rs:227:19 | LL | let _ = f_str(*ref_str); | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:199:19 + --> tests/ui/explicit_auto_deref.rs:230:19 | LL | let _ = f_str(**ref_ref_str); | ^^^^^^^^^^^^^ help: try: `ref_ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:209:12 + --> tests/ui/explicit_auto_deref.rs:241:12 | 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 - --> tests/ui/explicit_auto_deref.rs:210:12 + --> tests/ui/explicit_auto_deref.rs:243: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 - --> tests/ui/explicit_auto_deref.rs:219:41 + --> tests/ui/explicit_auto_deref.rs:253:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:238:9 + --> tests/ui/explicit_auto_deref.rs:273:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:261:8 + --> tests/ui/explicit_auto_deref.rs:297:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:264:20 + --> tests/ui/explicit_auto_deref.rs:301:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:266:9 + --> tests/ui/explicit_auto_deref.rs:304:9 | LL | *x | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:300:20 + --> tests/ui/explicit_auto_deref.rs:339:20 | LL | Some(x) => &mut *x, | ^^^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:333:22 + --> tests/ui/explicit_auto_deref.rs:373:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:339:22 + --> tests/ui/explicit_auto_deref.rs:380:22 | LL | let _ = &mut (**x.u).x; | ^^^^^^^ help: try: `(*x.u)` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:340:22 + --> tests/ui/explicit_auto_deref.rs:382:22 | LL | let _ = &mut (**{ x.u }).x; | ^^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:344:22 + --> tests/ui/explicit_auto_deref.rs:387:22 | LL | let _ = &mut (*x.u).x; | ^^^^^^ help: try: `x.u` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:345:22 + --> tests/ui/explicit_auto_deref.rs:389:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:368:13 + --> tests/ui/explicit_auto_deref.rs:413:13 | LL | foo(&*wrapped_bar); | ^^^^^^^^^^^^^ help: try: `&wrapped_bar` diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index 28b477b69215..585e261c2f43 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -5,27 +5,31 @@ 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` + //~^ explicit_counter_loop + + _index += 1 } let mut _index = 1; _index = 0; for _v in &vec { - //~^ ERROR: the variable `_index` is used as a loop counter + //~^ explicit_counter_loop + _index += 1 } let mut _index = 0; for _v in &mut vec { - //~^ ERROR: the variable `_index` is used as a loop counter + //~^ explicit_counter_loop + _index += 1; } let mut _index = 0; for _v in vec { - //~^ ERROR: the variable `_index` is used as a loop counter + //~^ explicit_counter_loop + _index += 1; } @@ -113,7 +117,8 @@ 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 + //~^ explicit_counter_loop + println!("{}", count); count += 1; if ch == 'a' { @@ -125,7 +130,8 @@ 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 + //~^ explicit_counter_loop + println!("{}", count); count += 1; for i in 0..2 { @@ -184,7 +190,8 @@ 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 + //~^ explicit_counter_loop + count += 1; } } @@ -225,7 +232,8 @@ mod issue_7920 { // should suggest `enumerate` for _item in slice { - //~^ ERROR: the variable `idx_usize` is used as a loop counter + //~^ explicit_counter_loop + if idx_usize == index_usize { break; } @@ -238,8 +246,9 @@ 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 + //~^ explicit_counter_loop + + if idx_u32 == index_u32 { break; } @@ -284,6 +293,7 @@ mod issue_13123 { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; 'label: for v in vec { + //~^ explicit_counter_loop _index += 1; if v == 1 { break 'label; diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index 1b2d1f8570a3..c565bd4cf356 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -8,49 +8,49 @@ LL | for _v in &vec { = help: to override `-D warnings` add `#[allow(clippy::explicit_counter_loop)]` error: the variable `_index` is used as a loop counter - --> tests/ui/explicit_counter_loop.rs:15:5 + --> tests/ui/explicit_counter_loop.rs:16: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 - --> tests/ui/explicit_counter_loop.rs:21:5 + --> tests/ui/explicit_counter_loop.rs:23: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 - --> tests/ui/explicit_counter_loop.rs:27:5 + --> tests/ui/explicit_counter_loop.rs:30: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 - --> tests/ui/explicit_counter_loop.rs:115:9 + --> tests/ui/explicit_counter_loop.rs:119: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 - --> tests/ui/explicit_counter_loop.rs:127:9 + --> tests/ui/explicit_counter_loop.rs:132: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 - --> tests/ui/explicit_counter_loop.rs:186:9 + --> tests/ui/explicit_counter_loop.rs:192: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 - --> tests/ui/explicit_counter_loop.rs:227:9 + --> tests/ui/explicit_counter_loop.rs:234: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 - --> tests/ui/explicit_counter_loop.rs:240:9 + --> tests/ui/explicit_counter_loop.rs:248:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())` @@ -58,7 +58,7 @@ LL | for _item in slice { = note: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumerate` error: the variable `_index` is used as a loop counter - --> tests/ui/explicit_counter_loop.rs:286:9 + --> tests/ui/explicit_counter_loop.rs:295:9 | LL | 'label: for v in vec { | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `'label: for (_index, v) in vec.into_iter().enumerate()` diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index 7b2dd2fe6eb8..ae63f7cbfd8c 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -52,29 +52,40 @@ fn main() { // these should require linting let b: &str = &*a; + //~^ explicit_deref_methods let b: &mut str = &mut **a; + //~^ explicit_deref_methods // both derefs should get linted here let b: String = format!("{}, {}", &*a, &*a); + //~^ explicit_deref_methods + //~| explicit_deref_methods println!("{}", &*a); + //~^ explicit_deref_methods #[allow(clippy::match_single_binding)] match &*a { + //~^ explicit_deref_methods _ => (), } let b: String = concat(&*a); + //~^ explicit_deref_methods let b = just_return(a); + //~^ explicit_deref_methods let b: String = concat(just_return(a)); + //~^ explicit_deref_methods let b: &str = &**a; + //~^ explicit_deref_methods let opt_a = Some(a.clone()); let b = &*opt_a.unwrap(); + //~^ explicit_deref_methods // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified // syntax @@ -112,6 +123,7 @@ fn main() { let b: &str = expr_deref!(a); let b: &str = expr_deref!(&*a); + //~^ explicit_deref_methods // The struct does not implement Deref trait #[derive(Copy, Clone)] diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index eb52cfb0d857..a1378bda85fa 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -52,29 +52,40 @@ fn main() { // these should require linting let b: &str = a.deref(); + //~^ explicit_deref_methods let b: &mut str = a.deref_mut(); + //~^ explicit_deref_methods // both derefs should get linted here let b: String = format!("{}, {}", a.deref(), a.deref()); + //~^ explicit_deref_methods + //~| explicit_deref_methods println!("{}", a.deref()); + //~^ explicit_deref_methods #[allow(clippy::match_single_binding)] match a.deref() { + //~^ explicit_deref_methods _ => (), } let b: String = concat(a.deref()); + //~^ explicit_deref_methods let b = just_return(a).deref(); + //~^ explicit_deref_methods let b: String = concat(just_return(a).deref()); + //~^ explicit_deref_methods let b: &str = a.deref().deref(); + //~^ explicit_deref_methods let opt_a = Some(a.clone()); let b = opt_a.unwrap().deref(); + //~^ explicit_deref_methods // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified // syntax @@ -112,6 +123,7 @@ fn main() { let b: &str = expr_deref!(a); let b: &str = expr_deref!(a.deref()); + //~^ explicit_deref_methods // The struct does not implement Deref trait #[derive(Copy, Clone)] diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr index aab862baf599..2ca376cba00b 100644 --- a/tests/ui/explicit_deref_methods.stderr +++ b/tests/ui/explicit_deref_methods.stderr @@ -8,67 +8,67 @@ LL | let b: &str = a.deref(); = help: to override `-D warnings` add `#[allow(clippy::explicit_deref_methods)]` error: explicit `deref_mut` method call - --> tests/ui/explicit_deref_methods.rs:56:23 + --> tests/ui/explicit_deref_methods.rs:57:23 | LL | let b: &mut str = a.deref_mut(); | ^^^^^^^^^^^^^ help: try: `&mut **a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:59:39 + --> tests/ui/explicit_deref_methods.rs:61:39 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:59:50 + --> tests/ui/explicit_deref_methods.rs:61:50 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:61:20 + --> tests/ui/explicit_deref_methods.rs:65:20 | LL | println!("{}", a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:64:11 + --> tests/ui/explicit_deref_methods.rs:69:11 | LL | match a.deref() { | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:68:28 + --> tests/ui/explicit_deref_methods.rs:74:28 | LL | let b: String = concat(a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:70:13 + --> tests/ui/explicit_deref_methods.rs:77:13 | LL | let b = just_return(a).deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:72:28 + --> tests/ui/explicit_deref_methods.rs:80:28 | LL | let b: String = concat(just_return(a).deref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:74:19 + --> tests/ui/explicit_deref_methods.rs:83:19 | LL | let b: &str = a.deref().deref(); | ^^^^^^^^^^^^^^^^^ help: try: `&**a` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:77:13 + --> tests/ui/explicit_deref_methods.rs:87:13 | LL | let b = opt_a.unwrap().deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()` error: explicit `deref` method call - --> tests/ui/explicit_deref_methods.rs:114:31 + --> tests/ui/explicit_deref_methods.rs:125: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 6d67488a7130..2b68906ae39f 100644 --- a/tests/ui/explicit_into_iter_loop.fixed +++ b/tests/ui/explicit_into_iter_loop.fixed @@ -8,6 +8,7 @@ fn main() { for<'a> &'a T: IntoIterator, { for _ in iterator {} + //~^ explicit_into_iter_loop } struct T; @@ -21,9 +22,11 @@ fn main() { let mut t = T; for _ in &t {} + //~^ explicit_into_iter_loop let r = &t; for _ in r {} + //~^ explicit_into_iter_loop // No suggestion for this. // We'd have to suggest `for _ in *rr {}` which is less clear. @@ -32,6 +35,7 @@ fn main() { let mr = &mut t; for _ in &*mr {} + //~^ explicit_into_iter_loop struct U; impl IntoIterator for &mut U { @@ -44,9 +48,11 @@ fn main() { let mut u = U; for _ in &mut u {} + //~^ explicit_into_iter_loop let mr = &mut u; for _ in &mut *mr {} + //~^ explicit_into_iter_loop // Issue #6900 struct S; diff --git a/tests/ui/explicit_into_iter_loop.rs b/tests/ui/explicit_into_iter_loop.rs index 14630c07c5cc..ca335b62d906 100644 --- a/tests/ui/explicit_into_iter_loop.rs +++ b/tests/ui/explicit_into_iter_loop.rs @@ -8,6 +8,7 @@ fn main() { for<'a> &'a T: IntoIterator, { for _ in iterator.into_iter() {} + //~^ explicit_into_iter_loop } struct T; @@ -21,9 +22,11 @@ fn main() { let mut t = T; for _ in t.into_iter() {} + //~^ explicit_into_iter_loop let r = &t; for _ in r.into_iter() {} + //~^ explicit_into_iter_loop // No suggestion for this. // We'd have to suggest `for _ in *rr {}` which is less clear. @@ -32,6 +35,7 @@ fn main() { let mr = &mut t; for _ in mr.into_iter() {} + //~^ explicit_into_iter_loop struct U; impl IntoIterator for &mut U { @@ -44,9 +48,11 @@ fn main() { let mut u = U; for _ in u.into_iter() {} + //~^ explicit_into_iter_loop let mr = &mut u; for _ in mr.into_iter() {} + //~^ explicit_into_iter_loop // Issue #6900 struct S; diff --git a/tests/ui/explicit_into_iter_loop.stderr b/tests/ui/explicit_into_iter_loop.stderr index f0e2048e036f..1c3156755d4e 100644 --- a/tests/ui/explicit_into_iter_loop.stderr +++ b/tests/ui/explicit_into_iter_loop.stderr @@ -8,31 +8,31 @@ LL | for _ in iterator.into_iter() {} = help: to override `-D warnings` add `#[allow(clippy::explicit_into_iter_loop)]` error: it is more concise to loop over containers instead of using explicit iteration methods - --> tests/ui/explicit_into_iter_loop.rs:23:14 + --> tests/ui/explicit_into_iter_loop.rs:24: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 - --> tests/ui/explicit_into_iter_loop.rs:26:14 + --> tests/ui/explicit_into_iter_loop.rs:28: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 - --> tests/ui/explicit_into_iter_loop.rs:34:14 + --> tests/ui/explicit_into_iter_loop.rs:37: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 - --> tests/ui/explicit_into_iter_loop.rs:46:14 + --> tests/ui/explicit_into_iter_loop.rs:50: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 - --> tests/ui/explicit_into_iter_loop.rs:49:14 + --> tests/ui/explicit_into_iter_loop.rs:54: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 1148f0f6c6a6..cd0898dfc367 100644 --- a/tests/ui/explicit_iter_loop.fixed +++ b/tests/ui/explicit_iter_loop.fixed @@ -16,10 +16,13 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; for _ in &vec {} + //~^ explicit_iter_loop for _ in &mut vec {} + //~^ explicit_iter_loop let rvec = &vec; for _ in rvec {} + //~^ explicit_iter_loop let rmvec = &mut vec; for _ in rmvec.iter() {} @@ -29,36 +32,48 @@ fn main() { for _ in &mut vec {} // these are fine for _ in &[1, 2, 3] {} + //~^ explicit_iter_loop for _ in (&mut [1, 2, 3]).iter() {} for _ in &[0; 32] {} + //~^ explicit_iter_loop for _ in &[0; 33] {} + //~^ explicit_iter_loop let ll: LinkedList<()> = LinkedList::new(); for _ in &ll {} + //~^ explicit_iter_loop let rll = ≪ for _ in rll {} + //~^ explicit_iter_loop let vd: VecDeque<()> = VecDeque::new(); for _ in &vd {} + //~^ explicit_iter_loop let rvd = &vd; for _ in rvd {} + //~^ explicit_iter_loop let bh: BinaryHeap<()> = BinaryHeap::new(); for _ in &bh {} + //~^ explicit_iter_loop let hm: HashMap<(), ()> = HashMap::new(); for _ in &hm {} + //~^ explicit_iter_loop let bt: BTreeMap<(), ()> = BTreeMap::new(); for _ in &bt {} + //~^ explicit_iter_loop let hs: HashSet<()> = HashSet::new(); for _ in &hs {} + //~^ explicit_iter_loop let bs: BTreeSet<()> = BTreeSet::new(); for _ in &bs {} + //~^ explicit_iter_loop struct NoIntoIter(); impl NoIntoIter { @@ -148,10 +163,13 @@ fn main() { } let mut x = CustomType; for _ in &x {} + //~^ explicit_iter_loop for _ in &mut x {} + //~^ explicit_iter_loop let r = &x; for _ in r {} + //~^ explicit_iter_loop } #[clippy::msrv = "1.79"] diff --git a/tests/ui/explicit_iter_loop.rs b/tests/ui/explicit_iter_loop.rs index 4dda2f13e5b8..02405280ce42 100644 --- a/tests/ui/explicit_iter_loop.rs +++ b/tests/ui/explicit_iter_loop.rs @@ -16,10 +16,13 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; for _ in vec.iter() {} + //~^ explicit_iter_loop for _ in vec.iter_mut() {} + //~^ explicit_iter_loop let rvec = &vec; for _ in rvec.iter() {} + //~^ explicit_iter_loop let rmvec = &mut vec; for _ in rmvec.iter() {} @@ -29,36 +32,48 @@ fn main() { for _ in &mut vec {} // these are fine for _ in [1, 2, 3].iter() {} + //~^ explicit_iter_loop for _ in (&mut [1, 2, 3]).iter() {} for _ in [0; 32].iter() {} + //~^ explicit_iter_loop for _ in [0; 33].iter() {} + //~^ explicit_iter_loop let ll: LinkedList<()> = LinkedList::new(); for _ in ll.iter() {} + //~^ explicit_iter_loop let rll = ≪ for _ in rll.iter() {} + //~^ explicit_iter_loop let vd: VecDeque<()> = VecDeque::new(); for _ in vd.iter() {} + //~^ explicit_iter_loop let rvd = &vd; for _ in rvd.iter() {} + //~^ explicit_iter_loop let bh: BinaryHeap<()> = BinaryHeap::new(); for _ in bh.iter() {} + //~^ explicit_iter_loop let hm: HashMap<(), ()> = HashMap::new(); for _ in hm.iter() {} + //~^ explicit_iter_loop let bt: BTreeMap<(), ()> = BTreeMap::new(); for _ in bt.iter() {} + //~^ explicit_iter_loop let hs: HashSet<()> = HashSet::new(); for _ in hs.iter() {} + //~^ explicit_iter_loop let bs: BTreeSet<()> = BTreeSet::new(); for _ in bs.iter() {} + //~^ explicit_iter_loop struct NoIntoIter(); impl NoIntoIter { @@ -148,10 +163,13 @@ fn main() { } let mut x = CustomType; for _ in x.iter() {} + //~^ explicit_iter_loop for _ in x.iter_mut() {} + //~^ explicit_iter_loop let r = &x; for _ in r.iter() {} + //~^ explicit_iter_loop } #[clippy::msrv = "1.79"] diff --git a/tests/ui/explicit_iter_loop.stderr b/tests/ui/explicit_iter_loop.stderr index c646e61aa045..3816bb4db98b 100644 --- a/tests/ui/explicit_iter_loop.stderr +++ b/tests/ui/explicit_iter_loop.stderr @@ -11,103 +11,103 @@ LL | #![deny(clippy::explicit_iter_loop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> tests/ui/explicit_iter_loop.rs:19:14 + --> tests/ui/explicit_iter_loop.rs:20: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 - --> tests/ui/explicit_iter_loop.rs:22:14 + --> tests/ui/explicit_iter_loop.rs:24: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 - --> tests/ui/explicit_iter_loop.rs:31:14 + --> tests/ui/explicit_iter_loop.rs:34: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 - --> tests/ui/explicit_iter_loop.rs:35:14 + --> tests/ui/explicit_iter_loop.rs:39: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 - --> tests/ui/explicit_iter_loop.rs:36:14 + --> tests/ui/explicit_iter_loop.rs:41: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 - --> tests/ui/explicit_iter_loop.rs:39:14 + --> tests/ui/explicit_iter_loop.rs:45: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 - --> tests/ui/explicit_iter_loop.rs:41:14 + --> tests/ui/explicit_iter_loop.rs:48: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 - --> tests/ui/explicit_iter_loop.rs:44:14 + --> tests/ui/explicit_iter_loop.rs:52: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 - --> tests/ui/explicit_iter_loop.rs:46:14 + --> tests/ui/explicit_iter_loop.rs:55: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 - --> tests/ui/explicit_iter_loop.rs:49:14 + --> tests/ui/explicit_iter_loop.rs:59: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 - --> tests/ui/explicit_iter_loop.rs:52:14 + --> tests/ui/explicit_iter_loop.rs:63: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 - --> tests/ui/explicit_iter_loop.rs:55:14 + --> tests/ui/explicit_iter_loop.rs:67: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 - --> tests/ui/explicit_iter_loop.rs:58:14 + --> tests/ui/explicit_iter_loop.rs:71: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 - --> tests/ui/explicit_iter_loop.rs:61:14 + --> tests/ui/explicit_iter_loop.rs:75: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 - --> tests/ui/explicit_iter_loop.rs:150:14 + --> tests/ui/explicit_iter_loop.rs:165: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 - --> tests/ui/explicit_iter_loop.rs:151:14 + --> tests/ui/explicit_iter_loop.rs:167: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 - --> tests/ui/explicit_iter_loop.rs:154:14 + --> tests/ui/explicit_iter_loop.rs:171: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 77a910dc1963..024999fc609e 100644 --- a/tests/ui/explicit_write.fixed +++ b/tests/ui/explicit_write.fixed @@ -21,23 +21,36 @@ fn main() { { use std::io::Write; print!("test"); + //~^ explicit_write eprint!("test"); + //~^ explicit_write println!("test"); + //~^ explicit_write eprintln!("test"); + //~^ explicit_write print!("test"); + //~^ explicit_write eprint!("test"); + //~^ explicit_write // including newlines println!("test\ntest"); + //~^ explicit_write eprintln!("test\ntest"); + //~^ explicit_write let value = 1; eprintln!("with {}", value); + //~^ explicit_write eprintln!("with {} {}", 2, value); + //~^ explicit_write eprintln!("with {value}"); + //~^ explicit_write eprintln!("macro arg {}", one!()); + //~^ explicit_write let width = 2; eprintln!("{:w$}", value, w = width); + //~^ explicit_write } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs index c77956264f6d..c83c760d48c8 100644 --- a/tests/ui/explicit_write.rs +++ b/tests/ui/explicit_write.rs @@ -21,23 +21,36 @@ fn main() { { use std::io::Write; write!(std::io::stdout(), "test").unwrap(); + //~^ explicit_write write!(std::io::stderr(), "test").unwrap(); + //~^ explicit_write writeln!(std::io::stdout(), "test").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "test").unwrap(); + //~^ explicit_write std::io::stdout().write_fmt(format_args!("test")).unwrap(); + //~^ explicit_write std::io::stderr().write_fmt(format_args!("test")).unwrap(); + //~^ explicit_write // including newlines writeln!(std::io::stdout(), "test\ntest").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "test\ntest").unwrap(); + //~^ explicit_write let value = 1; writeln!(std::io::stderr(), "with {}", value).unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "with {value}").unwrap(); + //~^ explicit_write writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); + //~^ explicit_write let width = 2; writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); + //~^ explicit_write } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index 0d22f02c36f2..670a0411b310 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -8,73 +8,73 @@ LL | write!(std::io::stdout(), "test").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::explicit_write)]` error: use of `write!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:24:9 + --> tests/ui/explicit_write.rs:25:9 | LL | write!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> tests/ui/explicit_write.rs:25:9 + --> tests/ui/explicit_write.rs:27:9 | LL | writeln!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test")` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:26:9 + --> tests/ui/explicit_write.rs:29:9 | LL | writeln!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test")` error: use of `stdout().write_fmt(...).unwrap()` - --> tests/ui/explicit_write.rs:27:9 + --> tests/ui/explicit_write.rs:31:9 | LL | std::io::stdout().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` error: use of `stderr().write_fmt(...).unwrap()` - --> tests/ui/explicit_write.rs:28:9 + --> tests/ui/explicit_write.rs:33:9 | LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> tests/ui/explicit_write.rs:31:9 + --> tests/ui/explicit_write.rs:37:9 | LL | writeln!(std::io::stdout(), "test\ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:32:9 + --> tests/ui/explicit_write.rs:39:9 | LL | writeln!(std::io::stderr(), "test\ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:35:9 + --> tests/ui/explicit_write.rs:43:9 | LL | writeln!(std::io::stderr(), "with {}", value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {}", value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:36:9 + --> tests/ui/explicit_write.rs:45:9 | LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {} {}", 2, value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:37:9 + --> tests/ui/explicit_write.rs:47:9 | LL | writeln!(std::io::stderr(), "with {value}").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {value}")` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:38:9 + --> tests/ui/explicit_write.rs:49:9 | LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("macro arg {}", one!())` error: use of `writeln!(stderr(), ...).unwrap()` - --> tests/ui/explicit_write.rs:40:9 + --> tests/ui/explicit_write.rs:52: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 856c1a42dafc..7b314381e9a3 100644 --- a/tests/ui/extend_with_drain.fixed +++ b/tests/ui/extend_with_drain.fixed @@ -6,15 +6,18 @@ fn main() { let mut vec1 = vec![0u8; 1024]; let mut vec2: std::vec::Vec = Vec::new(); vec2.append(&mut vec1); + //~^ extend_with_drain let mut vec3 = vec![0u8; 1024]; let mut vec4: std::vec::Vec = Vec::new(); vec4.append(&mut vec3); + //~^ extend_with_drain let mut vec11: std::vec::Vec = Vec::new(); vec11.append(&mut return_vector()); + //~^ extend_with_drain //won't get linted it doesn't move the entire content of a vec into another let mut test1 = vec![0u8, 10]; @@ -46,6 +49,7 @@ fn main() { let ref_x = &mut x; let mut y = Vec::new(); y.append(ref_x); + //~^ extend_with_drain } fn return_vector() -> Vec { diff --git a/tests/ui/extend_with_drain.rs b/tests/ui/extend_with_drain.rs index 7d538097639f..77214c053979 100644 --- a/tests/ui/extend_with_drain.rs +++ b/tests/ui/extend_with_drain.rs @@ -6,15 +6,18 @@ fn main() { let mut vec1 = vec![0u8; 1024]; let mut vec2: std::vec::Vec = Vec::new(); vec2.extend(vec1.drain(..)); + //~^ extend_with_drain let mut vec3 = vec![0u8; 1024]; let mut vec4: std::vec::Vec = Vec::new(); vec4.extend(vec3.drain(..)); + //~^ extend_with_drain let mut vec11: std::vec::Vec = Vec::new(); vec11.extend(return_vector().drain(..)); + //~^ extend_with_drain //won't get linted it doesn't move the entire content of a vec into another let mut test1 = vec![0u8, 10]; @@ -46,6 +49,7 @@ fn main() { let ref_x = &mut x; let mut y = Vec::new(); y.extend(ref_x.drain(..)); + //~^ extend_with_drain } fn return_vector() -> Vec { diff --git a/tests/ui/extend_with_drain.stderr b/tests/ui/extend_with_drain.stderr index 444cc82bbae7..2ee7aa7294e0 100644 --- a/tests/ui/extend_with_drain.stderr +++ b/tests/ui/extend_with_drain.stderr @@ -8,19 +8,19 @@ LL | vec2.extend(vec1.drain(..)); = help: to override `-D warnings` add `#[allow(clippy::extend_with_drain)]` error: use of `extend` instead of `append` for adding the full range of a second vector - --> tests/ui/extend_with_drain.rs:13:5 + --> tests/ui/extend_with_drain.rs:14: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 - --> tests/ui/extend_with_drain.rs:17:5 + --> tests/ui/extend_with_drain.rs:19: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 - --> tests/ui/extend_with_drain.rs:48:5 + --> tests/ui/extend_with_drain.rs:51:5 | LL | y.extend(ref_x.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `y.append(ref_x)` diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index aa964af3fc2d..fb853bb58305 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -17,6 +17,7 @@ fn empty() {} fn used_lt<'a>(x: &'a u8) {} fn unused_lt<'a>(x: u8) {} +//~^ extra_unused_lifetimes fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { // 'a is useless here since it's not directly bound @@ -44,6 +45,7 @@ struct Bar; impl Bar { fn x<'a>(&self) {} + //~^ extra_unused_lifetimes } // test for #489 (used lifetimes in bounds) @@ -70,6 +72,7 @@ impl X { mod issue4291 { trait BadTrait { fn unused_lt<'a>(x: u8) {} + //~^ extra_unused_lifetimes } impl BadTrait for () { @@ -81,13 +84,16 @@ mod issue6437 { pub struct Scalar; impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar { + //~^ extra_unused_lifetimes fn add_assign(&mut self, _rhs: &Scalar) { unimplemented!(); } } impl<'b> Scalar { + //~^ extra_unused_lifetimes pub fn something<'c>() -> Self { + //~^ extra_unused_lifetimes Self } } @@ -117,6 +123,7 @@ mod second_case { // Should lint. The response to the above comment incorrectly called this a false positive. The // lifetime `'a` can be removed, as demonstrated below. impl<'a, T: Source + ?Sized + 'a> Source for Box { + //~^ extra_unused_lifetimes fn hey() {} } diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index 85fbb7568ff4..0cecbbe80f76 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -8,37 +8,37 @@ LL | fn unused_lt<'a>(x: u8) {} = help: to override `-D warnings` add `#[allow(clippy::extra_unused_lifetimes)]` error: this lifetime isn't used in the function definition - --> tests/ui/extra_unused_lifetimes.rs:46:10 + --> tests/ui/extra_unused_lifetimes.rs:47:10 | LL | fn x<'a>(&self) {} | ^^ error: this lifetime isn't used in the function definition - --> tests/ui/extra_unused_lifetimes.rs:72:22 + --> tests/ui/extra_unused_lifetimes.rs:74:22 | LL | fn unused_lt<'a>(x: u8) {} | ^^ error: this lifetime isn't used in the impl - --> tests/ui/extra_unused_lifetimes.rs:83:10 + --> tests/ui/extra_unused_lifetimes.rs:86:10 | LL | impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar { | ^^ error: this lifetime isn't used in the impl - --> tests/ui/extra_unused_lifetimes.rs:89:10 + --> tests/ui/extra_unused_lifetimes.rs:93:10 | LL | impl<'b> Scalar { | ^^ error: this lifetime isn't used in the function definition - --> tests/ui/extra_unused_lifetimes.rs:90:26 + --> tests/ui/extra_unused_lifetimes.rs:95:26 | LL | pub fn something<'c>() -> Self { | ^^ error: this lifetime isn't used in the impl - --> tests/ui/extra_unused_lifetimes.rs:119:10 + --> tests/ui/extra_unused_lifetimes.rs:125:10 | LL | impl<'a, T: Source + ?Sized + 'a> Source for Box { | ^^ diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed index c9bebabdf17a..1ab74d398314 100644 --- a/tests/ui/extra_unused_type_parameters.fixed +++ b/tests/ui/extra_unused_type_parameters.fixed @@ -7,14 +7,17 @@ extern crate proc_macros; use proc_macros::with_span; fn unused_ty(x: u8) { +//~^ extra_unused_type_parameters unimplemented!() } fn unused_multi(x: u8) { +//~^ extra_unused_type_parameters unimplemented!() } fn unused_with_lt<'a>(x: &'a u8) { +//~^ extra_unused_type_parameters unimplemented!() } @@ -27,10 +30,12 @@ fn used_ret(x: u8) -> T { } fn unused_bounded(x: U) { +//~^ extra_unused_type_parameters unimplemented!(); } fn some_unused(b: B, c: C) { +//~^ extra_unused_type_parameters unimplemented!(); } @@ -56,6 +61,7 @@ struct S; impl S { fn unused_ty_impl(&self) { + //~^ extra_unused_type_parameters unimplemented!() } } @@ -78,6 +84,7 @@ where } fn unused_opaque(dummy: impl Default) { +//~^ extra_unused_type_parameters unimplemented!() } @@ -91,6 +98,7 @@ mod unexported_trait_bounds { } fn unused_with_priv_trait_bound() { + //~^ extra_unused_type_parameters unimplemented!(); } } diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs index 1bc0047adf01..0837efef27bb 100644 --- a/tests/ui/extra_unused_type_parameters.rs +++ b/tests/ui/extra_unused_type_parameters.rs @@ -7,14 +7,17 @@ extern crate proc_macros; use proc_macros::with_span; fn unused_ty(x: u8) { +//~^ extra_unused_type_parameters unimplemented!() } fn unused_multi(x: u8) { +//~^ extra_unused_type_parameters unimplemented!() } fn unused_with_lt<'a, T>(x: &'a u8) { +//~^ extra_unused_type_parameters unimplemented!() } @@ -27,10 +30,12 @@ fn used_ret(x: u8) -> T { } fn unused_bounded(x: U) { +//~^ extra_unused_type_parameters unimplemented!(); } fn some_unused, E>(b: B, c: C) { +//~^ extra_unused_type_parameters unimplemented!(); } @@ -56,6 +61,7 @@ struct S; impl S { fn unused_ty_impl(&self) { + //~^ extra_unused_type_parameters unimplemented!() } } @@ -78,6 +84,7 @@ where } fn unused_opaque(dummy: impl Default) { +//~^ extra_unused_type_parameters unimplemented!() } @@ -91,6 +98,7 @@ mod unexported_trait_bounds { } fn unused_with_priv_trait_bound() { + //~^ extra_unused_type_parameters unimplemented!(); } } diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr index 928c0038c2c3..5086826ae5c0 100644 --- a/tests/ui/extra_unused_type_parameters.stderr +++ b/tests/ui/extra_unused_type_parameters.stderr @@ -8,19 +8,19 @@ LL | fn unused_ty(x: u8) { = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, U - --> tests/ui/extra_unused_type_parameters.rs:13:16 + --> tests/ui/extra_unused_type_parameters.rs:14:16 | LL | fn unused_multi(x: u8) { | ^^^^^^ help: consider removing the parameters error: type parameter `T` goes unused in function definition - --> tests/ui/extra_unused_type_parameters.rs:17:21 + --> tests/ui/extra_unused_type_parameters.rs:19: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 - --> tests/ui/extra_unused_type_parameters.rs:29:19 + --> tests/ui/extra_unused_type_parameters.rs:32:19 | LL | fn unused_bounded(x: U) { | ^^^^^^^^^^^^ ^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL + fn unused_bounded(x: U) { | error: type parameters go unused in function definition: A, D, E - --> tests/ui/extra_unused_type_parameters.rs:33:16 + --> tests/ui/extra_unused_type_parameters.rs:37:16 | LL | fn some_unused, E>(b: B, c: C) { | ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,19 +44,19 @@ LL + fn some_unused(b: B, c: C) { | error: type parameter `T` goes unused in function definition - --> tests/ui/extra_unused_type_parameters.rs:58:22 + --> tests/ui/extra_unused_type_parameters.rs:63:22 | LL | fn unused_ty_impl(&self) { | ^^^ help: consider removing the parameter error: type parameters go unused in function definition: A, B - --> tests/ui/extra_unused_type_parameters.rs:80:17 + --> tests/ui/extra_unused_type_parameters.rs:86:17 | LL | fn unused_opaque(dummy: impl Default) { | ^^^^^^ help: consider removing the parameters error: type parameter `U` goes unused in function definition - --> tests/ui/extra_unused_type_parameters.rs:93:56 + --> tests/ui/extra_unused_type_parameters.rs:100:56 | LL | fn unused_with_priv_trait_bound() { | ^^^ help: consider removing the parameter diff --git a/tests/ui/extra_unused_type_parameters_unfixable.rs b/tests/ui/extra_unused_type_parameters_unfixable.rs index 65b53eb2e4b3..e69c924af00d 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.rs +++ b/tests/ui/extra_unused_type_parameters_unfixable.rs @@ -1,7 +1,8 @@ #![warn(clippy::extra_unused_type_parameters)] fn unused_where_clause(x: U) -//~^ ERROR: type parameter `T` goes unused in function definition +//~^ extra_unused_type_parameters + where T: Default, { @@ -9,7 +10,8 @@ where } fn unused_multi_where_clause(x: U) -//~^ ERROR: type parameters go unused in function definition: T, V +//~^ extra_unused_type_parameters + where T: Default, { @@ -17,7 +19,8 @@ where } fn unused_all_where_clause() -//~^ ERROR: type parameters go unused in function definition: T, U, V +//~^ extra_unused_type_parameters + where T: Default, { diff --git a/tests/ui/extra_unused_type_parameters_unfixable.stderr b/tests/ui/extra_unused_type_parameters_unfixable.stderr index 0765c4160936..8accb7e5924e 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -9,7 +9,7 @@ LL | fn unused_where_clause(x: U) = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, V - --> tests/ui/extra_unused_type_parameters_unfixable.rs:11:30 + --> tests/ui/extra_unused_type_parameters_unfixable.rs:12:30 | LL | fn unused_multi_where_clause(x: U) | ^ ^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/extra_unused_type_parameters_unfixable.rs:19:28 + --> tests/ui/extra_unused_type_parameters_unfixable.rs:21:28 | LL | fn unused_all_where_clause() | ^ ^^^^^^^^^^ ^^^^^^^^^^ diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index a81e51fcac75..56bd8a482684 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -4,7 +4,8 @@ // docs example struct Foo(i32); impl From for Foo { - //~^ ERROR: consider implementing `TryFrom` instead +//~^ fallible_impl_from + fn from(s: String) -> Self { Foo(s.parse().unwrap()) } @@ -26,7 +27,8 @@ impl From for Valid { struct Invalid; impl From for Invalid { - //~^ ERROR: consider implementing `TryFrom` instead +//~^ fallible_impl_from + fn from(i: usize) -> Invalid { if i != 42 { panic!(); @@ -36,7 +38,8 @@ impl From for Invalid { } impl From> for Invalid { - //~^ ERROR: consider implementing `TryFrom` instead +//~^ fallible_impl_from + fn from(s: Option) -> Invalid { let s = s.unwrap(); if !s.is_empty() { @@ -55,7 +58,8 @@ impl ProjStrTrait for Box { type ProjString = String; } impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { - //~^ ERROR: consider implementing `TryFrom` instead +//~^ fallible_impl_from + 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 cc3739031b76..d773fc3a6d7c 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -3,15 +3,15 @@ error: consider implementing `TryFrom` instead | LL | / impl From for Foo { LL | | +LL | | LL | | fn from(s: String) -> Self { -LL | | Foo(s.parse().unwrap()) -LL | | } +... | 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) - --> tests/ui/fallible_impl_from.rs:9:13 + --> tests/ui/fallible_impl_from.rs:10:13 | LL | Foo(s.parse().unwrap()) | ^^^^^^^^^^^^^^^^^^ @@ -22,38 +22,38 @@ LL | #![deny(clippy::fallible_impl_from)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider implementing `TryFrom` instead - --> tests/ui/fallible_impl_from.rs:28:1 + --> tests/ui/fallible_impl_from.rs:29:1 | LL | / impl From for Invalid { LL | | +LL | | LL | | fn from(i: usize) -> Invalid { -LL | | if i != 42 { ... | 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) - --> tests/ui/fallible_impl_from.rs:32:13 + --> tests/ui/fallible_impl_from.rs:34: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 - --> tests/ui/fallible_impl_from.rs:38:1 + --> tests/ui/fallible_impl_from.rs:40:1 | LL | / impl From> for Invalid { LL | | +LL | | LL | | fn from(s: Option) -> Invalid { -LL | | let s = s.unwrap(); ... | 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) - --> tests/ui/fallible_impl_from.rs:41:17 + --> tests/ui/fallible_impl_from.rs:44:17 | LL | let s = s.unwrap(); | ^^^^^^^^^^ @@ -67,19 +67,19 @@ 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 - --> tests/ui/fallible_impl_from.rs:57:1 + --> tests/ui/fallible_impl_from.rs:60:1 | LL | / impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { LL | | +LL | | LL | | fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { -LL | | if s.parse::().ok().unwrap() != 42 { ... | 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) - --> tests/ui/fallible_impl_from.rs:60:12 + --> tests/ui/fallible_impl_from.rs:64:12 | LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/field_reassign_with_default.rs b/tests/ui/field_reassign_with_default.rs index 2a432751952d..f3179b78ecb7 100644 --- a/tests/ui/field_reassign_with_default.rs +++ b/tests/ui/field_reassign_with_default.rs @@ -55,6 +55,7 @@ fn main() { // wrong, produces first error in stderr let mut a: A = Default::default(); a.i = 42; + //~^ field_reassign_with_default // right let mut a: A = Default::default(); @@ -95,17 +96,20 @@ fn main() { // wrong, produces second error in stderr let mut a: A = Default::default(); a.j = 43; + //~^ field_reassign_with_default a.i = 42; // wrong, produces third error in stderr let mut a: A = Default::default(); a.i = 42; + //~^ field_reassign_with_default a.j = 43; a.j = 44; // wrong, produces fourth error in stderr let mut a = A::default(); a.i = 42; + //~^ field_reassign_with_default // wrong, but does not produce an error in stderr, because we can't produce a correct kind of // suggestion with current implementation @@ -116,10 +120,12 @@ fn main() { // wrong, produces the fifth error in stderr let mut a: A = Default::default(); a.i = Default::default(); + //~^ field_reassign_with_default // wrong, produces the sixth error in stderr let mut a: A = Default::default(); a.i = Default::default(); + //~^ field_reassign_with_default a.j = 45; // right, because an assignment refers to another field @@ -142,6 +148,7 @@ fn main() { // don't expand macros in the suggestion (#6522) let mut a: C = C::default(); a.i = vec![1]; + //~^ field_reassign_with_default // Don't lint in external macros external! { @@ -160,9 +167,11 @@ fn main() { // be sure suggestion is correct with generics let mut a: Wrapper = Default::default(); a.i = true; + //~^ field_reassign_with_default let mut a: WrapperMulti = Default::default(); a.i = 42; + //~^ field_reassign_with_default // Don't lint in macros inline!( @@ -234,6 +243,7 @@ mod issue6312 { fn new(name: &str) -> Self { let mut f = ImplDropAllCopy::default(); f.name = name.len(); + //~^ field_reassign_with_default f } fn close(&self) {} @@ -250,6 +260,7 @@ mod issue6312 { fn new(name: &str) -> Self { let mut f = NoDropAllCopy::default(); f.name = name.len(); + //~^ field_reassign_with_default f } } diff --git a/tests/ui/field_reassign_with_default.stderr b/tests/ui/field_reassign_with_default.stderr index ae909475c6f2..19382e671510 100644 --- a/tests/ui/field_reassign_with_default.stderr +++ b/tests/ui/field_reassign_with_default.stderr @@ -13,121 +13,121 @@ LL | let mut a: A = Default::default(); = help: to override `-D warnings` add `#[allow(clippy::field_reassign_with_default)]` error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:97:5 + --> tests/ui/field_reassign_with_default.rs:98:5 | LL | a.j = 43; | ^^^^^^^^^ | note: consider initializing the variable with `main::A { j: 43, i: 42 }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:96:5 + --> tests/ui/field_reassign_with_default.rs:97:5 | LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:102:5 + --> tests/ui/field_reassign_with_default.rs:104:5 | LL | a.i = 42; | ^^^^^^^^^ | note: consider initializing the variable with `main::A { i: 42, j: 44 }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:101:5 + --> tests/ui/field_reassign_with_default.rs:103:5 | LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:108:5 + --> tests/ui/field_reassign_with_default.rs:111:5 | LL | a.i = 42; | ^^^^^^^^^ | note: consider initializing the variable with `main::A { i: 42, ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:107:5 + --> tests/ui/field_reassign_with_default.rs:110:5 | LL | let mut a = A::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:118:5 - | -LL | a.i = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: consider initializing the variable with `main::A { i: Default::default(), ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:117:5 - | -LL | let mut a: A = Default::default(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: field assignment outside of initializer for an instance created with Default::default() --> tests/ui/field_reassign_with_default.rs:122:5 | LL | a.i = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: consider initializing the variable with `main::A { i: Default::default(), j: 45 }` and removing relevant reassignments +note: consider initializing the variable with `main::A { i: Default::default(), ..Default::default() }` and removing relevant reassignments --> tests/ui/field_reassign_with_default.rs:121:5 | LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:144:5 + --> tests/ui/field_reassign_with_default.rs:127:5 + | +LL | a.i = Default::default(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: consider initializing the variable with `main::A { i: Default::default(), j: 45 }` and removing relevant reassignments + --> tests/ui/field_reassign_with_default.rs:126:5 + | +LL | let mut a: A = Default::default(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: field assignment outside of initializer for an instance created with Default::default() + --> tests/ui/field_reassign_with_default.rs:150:5 | LL | a.i = vec![1]; | ^^^^^^^^^^^^^^ | note: consider initializing the variable with `C { i: vec![1], ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:143:5 + --> tests/ui/field_reassign_with_default.rs:149:5 | LL | let mut a: C = C::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:162:5 + --> tests/ui/field_reassign_with_default.rs:169:5 | LL | a.i = true; | ^^^^^^^^^^^ | note: consider initializing the variable with `Wrapper:: { i: true }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:161:5 + --> tests/ui/field_reassign_with_default.rs:168:5 | LL | let mut a: Wrapper = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:165:5 + --> tests/ui/field_reassign_with_default.rs:173:5 | LL | a.i = 42; | ^^^^^^^^^ | note: consider initializing the variable with `WrapperMulti:: { i: 42, ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:164:5 + --> tests/ui/field_reassign_with_default.rs:172:5 | LL | let mut a: WrapperMulti = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:236:13 + --> tests/ui/field_reassign_with_default.rs:245:13 | LL | f.name = name.len(); | ^^^^^^^^^^^^^^^^^^^^ | note: consider initializing the variable with `issue6312::ImplDropAllCopy { name: name.len(), ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:235:13 + --> tests/ui/field_reassign_with_default.rs:244:13 | LL | let mut f = ImplDropAllCopy::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: field assignment outside of initializer for an instance created with Default::default() - --> tests/ui/field_reassign_with_default.rs:252:13 + --> tests/ui/field_reassign_with_default.rs:262:13 | LL | f.name = name.len(); | ^^^^^^^^^^^^^^^^^^^^ | note: consider initializing the variable with `issue6312::NoDropAllCopy { name: name.len(), ..Default::default() }` and removing relevant reassignments - --> tests/ui/field_reassign_with_default.rs:251:13 + --> tests/ui/field_reassign_with_default.rs:261:13 | LL | let mut f = NoDropAllCopy::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/field_scoped_visibility_modifiers.rs b/tests/ui/field_scoped_visibility_modifiers.rs index 5789dbf9b1d7..159cabad1b43 100644 --- a/tests/ui/field_scoped_visibility_modifiers.rs +++ b/tests/ui/field_scoped_visibility_modifiers.rs @@ -7,8 +7,11 @@ pub mod pub_module { private_field: bool, pub pub_field: bool, pub(crate) pub_crate_field: bool, + //~^ field_scoped_visibility_modifiers pub(in crate::pub_module) pub_in_path_field: bool, + //~^ field_scoped_visibility_modifiers pub(super) pub_super_field: bool, + //~^ field_scoped_visibility_modifiers #[allow(clippy::needless_pub_self)] pub(self) pub_self_field: bool, } diff --git a/tests/ui/field_scoped_visibility_modifiers.stderr b/tests/ui/field_scoped_visibility_modifiers.stderr index beea6c92107c..c0c202fd87af 100644 --- a/tests/ui/field_scoped_visibility_modifiers.stderr +++ b/tests/ui/field_scoped_visibility_modifiers.stderr @@ -9,7 +9,7 @@ LL | pub(crate) pub_crate_field: bool, = help: to override `-D warnings` add `#[allow(clippy::field_scoped_visibility_modifiers)]` error: scoped visibility modifier on a field - --> tests/ui/field_scoped_visibility_modifiers.rs:10:9 + --> tests/ui/field_scoped_visibility_modifiers.rs:11:9 | LL | pub(in crate::pub_module) pub_in_path_field: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub(in crate::pub_module) pub_in_path_field: bool, = help: consider making the field private and adding a scoped visibility method for it error: scoped visibility modifier on a field - --> tests/ui/field_scoped_visibility_modifiers.rs:11:9 + --> tests/ui/field_scoped_visibility_modifiers.rs:13:9 | LL | pub(super) pub_super_field: bool, | ^^^^^^^^^^ diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs index 9e8a4c04324b..0e9c160e4a90 100644 --- a/tests/ui/filetype_is_file.rs +++ b/tests/ui/filetype_is_file.rs @@ -7,19 +7,22 @@ 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 + //~^ filetype_is_file + // read file } // positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file() { - //~^ ERROR: `!FileType::is_file()` only denies regular files + //~^ filetype_is_file + // 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 + //~^ filetype_is_file + // ... } diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 0c66910c1b61..b930ac929748 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -9,7 +9,7 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { = help: to override `-D warnings` add `#[allow(clippy::filetype_is_file)]` error: `!FileType::is_file()` only denies regular files - --> tests/ui/filetype_is_file.rs:15:8 + --> tests/ui/filetype_is_file.rs:16:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/filetype_is_file.rs:21:9 + --> tests/ui/filetype_is_file.rs:23:9 | LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed index 6a1b81fdbcbe..6d9564dc828b 100644 --- a/tests/ui/filter_map_bool_then.fixed +++ b/tests/ui/filter_map_bool_then.fixed @@ -17,24 +17,30 @@ 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); + //~^ filter_map_bool_then v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); + //~^ filter_map_bool_then // 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); + //~^ filter_map_bool_then // Do not lint let v = vec![NonCopy, NonCopy]; v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); @@ -59,14 +65,17 @@ fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str fn issue11503() { let bools: &[bool] = &[true, false, false, true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Need to insert multiple derefs if there is more than one layer of references let bools: &[&&bool] = &[&&true, &&false, &&false, &&true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| ***b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a mutable reference let bools: &[&mut bool] = &[&mut true]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| **b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a custom deref struct DerefToBool; @@ -78,4 +87,5 @@ fn issue11503() { } let bools: &[&&DerefToBool] = &[&&DerefToBool]; let _: Vec = bools.iter().enumerate().filter(|&(i, b)| ****b).map(|(i, b)| i).collect(); + //~^ filter_map_bool_then } diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs index a41e88f8805d..dffd798da254 100644 --- a/tests/ui/filter_map_bool_then.rs +++ b/tests/ui/filter_map_bool_then.rs @@ -17,24 +17,30 @@ 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)); + //~^ filter_map_bool_then v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then v.clone() .into_iter() .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter_map(|i| (i % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); + //~^ filter_map_bool_then // 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)); + //~^ filter_map_bool_then // Do not lint let v = vec![NonCopy, NonCopy]; v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); @@ -59,14 +65,17 @@ fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str fn issue11503() { let bools: &[bool] = &[true, false, false, true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Need to insert multiple derefs if there is more than one layer of references let bools: &[&&bool] = &[&&true, &&false, &&false, &&true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a mutable reference let bools: &[&mut bool] = &[&mut true]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then // Should also suggest derefs when going through a custom deref struct DerefToBool; @@ -78,4 +87,5 @@ fn issue11503() { } let bools: &[&&DerefToBool] = &[&&DerefToBool]; let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + //~^ filter_map_bool_then } diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr index 088b9ba12867..aeb1baeb35e6 100644 --- a/tests/ui/filter_map_bool_then.stderr +++ b/tests/ui/filter_map_bool_then.stderr @@ -8,55 +8,55 @@ LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); = help: to override `-D warnings` add `#[allow(clippy::filter_map_bool_then)]` error: usage of `bool::then` in `filter_map` - --> tests/ui/filter_map_bool_then.rs:20:27 + --> tests/ui/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` - --> tests/ui/filter_map_bool_then.rs:23:10 + --> tests/ui/filter_map_bool_then.rs:25: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` - --> tests/ui/filter_map_bool_then.rs:27:10 + --> tests/ui/filter_map_bool_then.rs:30: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` - --> tests/ui/filter_map_bool_then.rs:31:10 + --> tests/ui/filter_map_bool_then.rs:35: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` - --> tests/ui/filter_map_bool_then.rs:37:22 + --> tests/ui/filter_map_bool_then.rs:42: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: usage of `bool::then` in `filter_map` - --> tests/ui/filter_map_bool_then.rs:61:50 + --> tests/ui/filter_map_bool_then.rs:67:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| *b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> tests/ui/filter_map_bool_then.rs:65:50 + --> tests/ui/filter_map_bool_then.rs:72:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ***b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> tests/ui/filter_map_bool_then.rs:69:50 + --> tests/ui/filter_map_bool_then.rs:77:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| **b).map(|(i, b)| i)` error: usage of `bool::then` in `filter_map` - --> tests/ui/filter_map_bool_then.rs:80:50 + --> tests/ui/filter_map_bool_then.rs:89:50 | LL | let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ****b).map(|(i, b)| i)` diff --git a/tests/ui/filter_map_identity.fixed b/tests/ui/filter_map_identity.fixed index fdd020fcd773..40c3f58da976 100644 --- a/tests/ui/filter_map_identity.fixed +++ b/tests/ui/filter_map_identity.fixed @@ -26,59 +26,81 @@ fn main() { { // into_iter copy_vec_non_inferred().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of - non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + + non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + + non_copy_vec().into_iter().flatten(); + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + // we are forced to pass the type in the call. copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + #[rustfmt::skip] copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + #[rustfmt::skip] copy_vec::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + // note, the compiler requires that we pass the type to `opaque`. This is mostly for reference, // it behaves the same as copy_vec. opaque::().into_iter().flatten(); - //~^ ERROR: use of + //~^ filter_map_identity + } } diff --git a/tests/ui/filter_map_identity.rs b/tests/ui/filter_map_identity.rs index a626de9f5bbd..f11f80437e85 100644 --- a/tests/ui/filter_map_identity.rs +++ b/tests/ui/filter_map_identity.rs @@ -26,59 +26,81 @@ fn main() { { // into_iter copy_vec_non_inferred().into_iter().filter_map(|x| x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().filter_map(std::convert::identity); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().filter_map(identity); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().filter_map(|x| return x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec_non_inferred().into_iter().filter_map(|x| return x); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(|x| x); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(|x| x); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(std::convert::identity); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(identity); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(|x| return x); - //~^ ERROR: use of + //~^ filter_map_identity + non_copy_vec().into_iter().filter_map(|x| return x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option<_>| x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option<_>| x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option<_>| return x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option<_>| return x); - //~^ ERROR: use of + //~^ filter_map_identity + // we are forced to pass the type in the call. copy_vec::().into_iter().filter_map(|x: Option| x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option| x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option| return x); - //~^ ERROR: use of + //~^ filter_map_identity + copy_vec::().into_iter().filter_map(|x: Option| return x); - //~^ ERROR: use of + //~^ filter_map_identity + #[rustfmt::skip] copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ x }}); - //~^ ERROR: use of + //~^ filter_map_identity + #[rustfmt::skip] copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ return x }}); - //~^ ERROR: use of + //~^ filter_map_identity + // note, the compiler requires that we pass the type to `opaque`. This is mostly for reference, // it behaves the same as copy_vec. opaque::().into_iter().filter_map(|x| x); - //~^ ERROR: use of + //~^ filter_map_identity + } } diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index 55068db4e9d0..4223343251f1 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -8,127 +8,127 @@ LL | copy_vec_non_inferred().into_iter().filter_map(|x| x); = help: to override `-D warnings` add `#[allow(clippy::filter_map_identity)]` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:30:45 + --> tests/ui/filter_map_identity.rs:31:45 | LL | copy_vec_non_inferred().into_iter().filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:32:45 + --> tests/ui/filter_map_identity.rs:34:45 | LL | copy_vec_non_inferred().into_iter().filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:34:45 + --> tests/ui/filter_map_identity.rs:37:45 | LL | copy_vec_non_inferred().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:36:45 + --> tests/ui/filter_map_identity.rs:40:45 | LL | copy_vec_non_inferred().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:39:36 - | -LL | non_copy_vec().into_iter().filter_map(|x| x); - | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:41:36 - | -LL | non_copy_vec().into_iter().filter_map(|x| x); - | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` - error: use of `filter_map` with an identity function --> tests/ui/filter_map_identity.rs:44:36 | +LL | non_copy_vec().into_iter().filter_map(|x| x); + | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:47:36 + | +LL | non_copy_vec().into_iter().filter_map(|x| x); + | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:51:36 + | LL | non_copy_vec().into_iter().filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:46:36 + --> tests/ui/filter_map_identity.rs:54:36 | LL | non_copy_vec().into_iter().filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:48:36 + --> tests/ui/filter_map_identity.rs:57:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:50:36 + --> tests/ui/filter_map_identity.rs:60:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:53:39 + --> tests/ui/filter_map_identity.rs:64:39 | LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:55:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:57:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:59:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:63:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option| x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:65:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option| x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - error: use of `filter_map` with an identity function --> tests/ui/filter_map_identity.rs:67:39 | -LL | copy_vec::().into_iter().filter_map(|x: Option| return x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` +LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:69:39 + --> tests/ui/filter_map_identity.rs:70:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:73:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:78:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option| x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:81:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option| x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:84:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:72:43 + --> tests/ui/filter_map_identity.rs:87:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option| return x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:91:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:75:43 + --> tests/ui/filter_map_identity.rs:95:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ return x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:80:37 + --> tests/ui/filter_map_identity.rs:101:37 | LL | opaque::().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs index 9077b8fca23e..2a2237ed16cf 100644 --- a/tests/ui/filter_map_next.rs +++ b/tests/ui/filter_map_next.rs @@ -5,8 +5,9 @@ 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` + //~^ filter_map_next + + .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 cd3ffe3aa7f0..974bb946d46a 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -3,9 +3,6 @@ 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 | | }) LL | | .next(); diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next_fixable.fixed index 193ac3aea433..285863ef340d 100644 --- a/tests/ui/filter_map_next_fixable.fixed +++ b/tests/ui/filter_map_next_fixable.fixed @@ -5,6 +5,7 @@ fn main() { let a = ["1", "lol", "3", "NaN", "5"]; let element: Option = a.iter().find_map(|s| s.parse().ok()); + //~^ filter_map_next assert_eq!(element, Some(1)); } @@ -18,4 +19,5 @@ fn msrv_1_29() { fn msrv_1_30() { let a = ["1", "lol", "3", "NaN", "5"]; let _: Option = a.iter().find_map(|s| s.parse().ok()); + //~^ filter_map_next } diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs index dab8d289817e..af911689b7c7 100644 --- a/tests/ui/filter_map_next_fixable.rs +++ b/tests/ui/filter_map_next_fixable.rs @@ -5,6 +5,7 @@ fn main() { let a = ["1", "lol", "3", "NaN", "5"]; let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next assert_eq!(element, Some(1)); } @@ -18,4 +19,5 @@ fn msrv_1_29() { fn msrv_1_30() { let a = ["1", "lol", "3", "NaN", "5"]; let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next } diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr index 2c6148f3f4b6..707dec8687b1 100644 --- a/tests/ui/filter_map_next_fixable.stderr +++ b/tests/ui/filter_map_next_fixable.stderr @@ -8,7 +8,7 @@ LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> tests/ui/filter_map_next_fixable.rs:20:26 + --> tests/ui/filter_map_next_fixable.rs:21: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/find_map.rs b/tests/ui/find_map.rs index bbd395d50ef2..aba1f2cbe581 100644 --- a/tests/ui/find_map.rs +++ b/tests/ui/find_map.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/flat_map_identity.fixed b/tests/ui/flat_map_identity.fixed index c142cf719808..f62062326126 100644 --- a/tests/ui/flat_map_identity.fixed +++ b/tests/ui/flat_map_identity.fixed @@ -6,10 +6,13 @@ use std::convert; fn main() { let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flatten(); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flatten(); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flatten(); + //~^ flat_map_identity } diff --git a/tests/ui/flat_map_identity.rs b/tests/ui/flat_map_identity.rs index 8505ba9005d3..c59e749474ee 100644 --- a/tests/ui/flat_map_identity.rs +++ b/tests/ui/flat_map_identity.rs @@ -6,10 +6,13 @@ use std::convert; fn main() { let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flat_map(|x| x); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flat_map(convert::identity); + //~^ flat_map_identity let iterator = [[0, 1], [2, 3], [4, 5]].iter(); let _ = iterator.flat_map(|x| return x); + //~^ flat_map_identity } diff --git a/tests/ui/flat_map_identity.stderr b/tests/ui/flat_map_identity.stderr index 496fd972a498..75137f5d9e57 100644 --- a/tests/ui/flat_map_identity.stderr +++ b/tests/ui/flat_map_identity.stderr @@ -8,13 +8,13 @@ LL | let _ = iterator.flat_map(|x| x); = help: to override `-D warnings` add `#[allow(clippy::flat_map_identity)]` error: use of `flat_map` with an identity function - --> tests/ui/flat_map_identity.rs:11:22 + --> tests/ui/flat_map_identity.rs:12:22 | LL | let _ = iterator.flat_map(convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `flat_map` with an identity function - --> tests/ui/flat_map_identity.rs:14:22 + --> tests/ui/flat_map_identity.rs:16: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 e08d9a14533b..e65e77ab79dc 100644 --- a/tests/ui/flat_map_option.fixed +++ b/tests/ui/flat_map_option.fixed @@ -5,7 +5,9 @@ fn main() { // yay let c = |x| Some(x); let _ = [1].iter().filter_map(c); + //~^ flat_map_option let _ = [1].iter().filter_map(Some); + //~^ flat_map_option // nay let _ = [1].iter().flat_map(|_| &Some(1)); diff --git a/tests/ui/flat_map_option.rs b/tests/ui/flat_map_option.rs index 4d0f32ac0fda..6784100a4fc9 100644 --- a/tests/ui/flat_map_option.rs +++ b/tests/ui/flat_map_option.rs @@ -5,7 +5,9 @@ fn main() { // yay let c = |x| Some(x); let _ = [1].iter().flat_map(c); + //~^ flat_map_option let _ = [1].iter().flat_map(Some); + //~^ flat_map_option // nay let _ = [1].iter().flat_map(|_| &Some(1)); diff --git a/tests/ui/flat_map_option.stderr b/tests/ui/flat_map_option.stderr index 6e151965fad5..7f5f2c14ec8e 100644 --- a/tests/ui/flat_map_option.stderr +++ b/tests/ui/flat_map_option.stderr @@ -8,7 +8,7 @@ LL | let _ = [1].iter().flat_map(c); = help: to override `-D warnings` add `#[allow(clippy::flat_map_option)]` error: used `flat_map` where `filter_map` could be used instead - --> tests/ui/flat_map_option.rs:8:24 + --> tests/ui/flat_map_option.rs:9:24 | LL | let _ = [1].iter().flat_map(Some); | ^^^^^^^^ help: try: `filter_map` diff --git a/tests/ui/float_arithmetic.rs b/tests/ui/float_arithmetic.rs index 1647273c436d..3b87d2ec066d 100644 --- a/tests/ui/float_arithmetic.rs +++ b/tests/ui/float_arithmetic.rs @@ -13,58 +13,75 @@ fn main() { let mut f = 1.0f32; f * 2.0; - //~^ ERROR: floating-point arithmetic detected - //~| NOTE: `-D clippy::float-arithmetic` implied by `-D warnings` + //~^ float_arithmetic + + 1.0 + f; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f * 2.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f / 2.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f - 2.0 * 4.2; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + -f; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f += 1.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f -= 1.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f *= 2.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + f /= 2.0; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } // 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 + //~^ float_arithmetic + &3.4_f32 + 1.5_f32; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + &3.5_f32 + &1.3_f32; - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } pub fn float_foo(f: &f32) -> f32 { let a = 5.1; a + f - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } pub fn float_bar(f1: &f32, f2: &f32) -> f32 { f1 + f2 - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } pub fn float_baz(f1: f32, f2: &f32) -> f32 { f1 + f2 - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } pub fn float_qux(f1: f32, f2: f32) -> f32 { (&f1 + &f2) - //~^ ERROR: floating-point arithmetic detected + //~^ float_arithmetic + } diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr index 66455f061455..c01fdf8b46ec 100644 --- a/tests/ui/float_arithmetic.stderr +++ b/tests/ui/float_arithmetic.stderr @@ -8,97 +8,97 @@ LL | f * 2.0; = help: to override `-D warnings` add `#[allow(clippy::float_arithmetic)]` error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:19:5 + --> tests/ui/float_arithmetic.rs:20:5 | LL | 1.0 + f; | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:21:5 + --> tests/ui/float_arithmetic.rs:23:5 | LL | f * 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:23:5 + --> tests/ui/float_arithmetic.rs:26:5 | LL | f / 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:25:5 + --> tests/ui/float_arithmetic.rs:29:5 | LL | f - 2.0 * 4.2; | ^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:27:5 + --> tests/ui/float_arithmetic.rs:32:5 | LL | -f; | ^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:30:5 + --> tests/ui/float_arithmetic.rs:36:5 | LL | f += 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:32:5 + --> tests/ui/float_arithmetic.rs:39:5 | LL | f -= 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:34:5 + --> tests/ui/float_arithmetic.rs:42:5 | LL | f *= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:36:5 + --> tests/ui/float_arithmetic.rs:45:5 | LL | f /= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:43:5 + --> tests/ui/float_arithmetic.rs:53:5 | LL | 3.1_f32 + &1.2_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:45:5 + --> tests/ui/float_arithmetic.rs:56:5 | LL | &3.4_f32 + 1.5_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:47:5 + --> tests/ui/float_arithmetic.rs:59:5 | LL | &3.5_f32 + &1.3_f32; | ^^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:53:5 + --> tests/ui/float_arithmetic.rs:66:5 | LL | a + f | ^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:58:5 + --> tests/ui/float_arithmetic.rs:72:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:63:5 + --> tests/ui/float_arithmetic.rs:78:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:68:5 + --> tests/ui/float_arithmetic.rs:84:5 | LL | (&f1 + &f2) | ^^^^^^^^^^^ diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index a1dfd1954fce..84cf67ed4f10 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -70,17 +70,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` + //~^ float_cmp + 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` + //~^ float_cmp + x != 0f64; // no error, comparison with zero is ok twice(x) != twice(ONE as f64); - //~^ ERROR: strict comparison of `f32` or `f64` + //~^ float_cmp + x < 0.0; // no errors, lower or greater comparisons need no fuzzyness x > 0.0; @@ -101,15 +104,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` + //~^ float_cmp + let a1: [f32; 1] = [0.0]; let a2: [f32; 1] = [1.1]; a1 == a2; - //~^ ERROR: strict comparison of `f32` or `f64` arrays + //~^ float_cmp + a1[0] == a2[0]; - //~^ ERROR: strict comparison of `f32` or `f64` + //~^ float_cmp + // 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 d10da8a99a9d..1b57e15bbb97 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -8,31 +8,31 @@ LL | ONE as f64 != 2.0; = help: to override `-D warnings` add `#[allow(clippy::float_cmp)]` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:78:5 + --> tests/ui/float_cmp.rs:79:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:82:5 + --> tests/ui/float_cmp.rs:84: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` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:103:5 + --> tests/ui/float_cmp.rs:106: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` error: strict comparison of `f32` or `f64` arrays - --> tests/ui/float_cmp.rs:109:5 + --> tests/ui/float_cmp.rs:113:5 | LL | a1 == a2; | ^^^^^^^^ error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:111:5 + --> tests/ui/float_cmp.rs:116: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 ba760a18f28a..86b3e5d46a06 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -13,22 +13,29 @@ fn eq_one(x: f32) -> bool { fn main() { // has errors 1f32 == ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + TWO == ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + TWO != ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + ONE + ONE == TWO; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + let x = 1; x as f32 == ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + let v = 0.9; v == ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + v != ONE; - //~^ ERROR: strict comparison of `f32` or `f64` constant + //~^ float_cmp_const + // no errors, lower than or greater than comparisons v < ONE; @@ -61,5 +68,6 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; - //~^ ERROR: strict comparison of `f32` or `f64` constant arrays + //~^ float_cmp_const + } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index e0cd6faf4b3a..c2c7b229870a 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -8,43 +8,43 @@ LL | 1f32 == ONE; = help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:17:5 + --> tests/ui/float_cmp_const.rs:18:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:19:5 + --> tests/ui/float_cmp_const.rs:21:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:21:5 + --> tests/ui/float_cmp_const.rs:24:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:24:5 + --> tests/ui/float_cmp_const.rs:28:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:28:5 + --> tests/ui/float_cmp_const.rs:33:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:30:5 + --> tests/ui/float_cmp_const.rs:36:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> tests/ui/float_cmp_const.rs:63:5 + --> tests/ui/float_cmp_const.rs:70: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 500b3035390f..db0a4f492607 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -5,8 +5,9 @@ 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` + //~^ float_equality_without_abs + + } pub fn main() { @@ -16,26 +17,36 @@ pub fn main() { let b = 0.0500001; let _ = (a - b) < f32::EPSILON; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = a - b < f32::EPSILON; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = a - b.abs() < f32::EPSILON; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = (a as f64 - b as f64) < f64::EPSILON; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = 1.0 - 2.0 < f32::EPSILON; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = f32::EPSILON > (a - b); - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = f32::EPSILON > a - b; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = f32::EPSILON > a - b.abs(); - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = f64::EPSILON > (a as f64 - b as f64); - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_without_abs + let _ = f32::EPSILON > 1.0 - 2.0; - //~^ ERROR: float equality check without `.abs()` + //~^ float_equality_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 cdaaf0cdbcf7..5696ec54d765 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -10,7 +10,7 @@ LL | (a - b) < f32::EPSILON = help: to override `-D warnings` add `#[allow(clippy::float_equality_without_abs)]` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:18:13 + --> tests/ui/float_equality_without_abs.rs:19:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:20:13 + --> tests/ui/float_equality_without_abs.rs:22:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:22:13 + --> tests/ui/float_equality_without_abs.rs:25:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:24:13 + --> tests/ui/float_equality_without_abs.rs:28:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -42,7 +42,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()` - --> tests/ui/float_equality_without_abs.rs:26:13 + --> tests/ui/float_equality_without_abs.rs:31:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:29:13 + --> tests/ui/float_equality_without_abs.rs:35:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -58,7 +58,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:31:13 + --> tests/ui/float_equality_without_abs.rs:38:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -66,7 +66,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:33:13 + --> tests/ui/float_equality_without_abs.rs:41:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -74,7 +74,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:35:13 + --> tests/ui/float_equality_without_abs.rs:44:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -82,7 +82,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()` - --> tests/ui/float_equality_without_abs.rs:37:13 + --> tests/ui/float_equality_without_abs.rs:47:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/tests/ui/floating_point_abs.fixed b/tests/ui/floating_point_abs.fixed index 33183c769724..e8d64a3d7c29 100644 --- a/tests/ui/floating_point_abs.fixed +++ b/tests/ui/floating_point_abs.fixed @@ -12,35 +12,43 @@ struct A { fn fake_abs1(num: f64) -> f64 { num.abs() + //~^ suboptimal_flops } fn fake_abs2(num: f64) -> f64 { num.abs() + //~^ suboptimal_flops } fn fake_abs3(a: A) -> f64 { a.a.abs() + //~^ suboptimal_flops } fn fake_abs4(num: f64) -> f64 { num.abs() + //~^ suboptimal_flops } fn fake_abs5(a: A) -> f64 { a.a.abs() + //~^ suboptimal_flops } fn fake_nabs1(num: f64) -> f64 { -num.abs() + //~^ suboptimal_flops } fn fake_nabs2(num: f64) -> f64 { -num.abs() + //~^ suboptimal_flops } fn fake_nabs3(a: A) -> A { A { a: -a.a.abs(), + //~^ suboptimal_flops b: a.b, } } diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs index a08d5bbcef5c..a27279b0662f 100644 --- a/tests/ui/floating_point_abs.rs +++ b/tests/ui/floating_point_abs.rs @@ -12,35 +12,43 @@ struct A { fn fake_abs1(num: f64) -> f64 { if num >= 0.0 { num } else { -num } + //~^ suboptimal_flops } fn fake_abs2(num: f64) -> f64 { if 0.0 < num { num } else { -num } + //~^ suboptimal_flops } fn fake_abs3(a: A) -> f64 { if a.a > 0.0 { a.a } else { -a.a } + //~^ suboptimal_flops } fn fake_abs4(num: f64) -> f64 { if 0.0 >= num { -num } else { num } + //~^ suboptimal_flops } fn fake_abs5(a: A) -> f64 { if a.a < 0.0 { -a.a } else { a.a } + //~^ suboptimal_flops } fn fake_nabs1(num: f64) -> f64 { if num < 0.0 { num } else { -num } + //~^ suboptimal_flops } fn fake_nabs2(num: f64) -> f64 { if 0.0 >= num { num } else { -num } + //~^ suboptimal_flops } fn fake_nabs3(a: A) -> A { A { a: if a.a >= 0.0 { -a.a } else { a.a }, + //~^ suboptimal_flops b: a.b, } } diff --git a/tests/ui/floating_point_abs.stderr b/tests/ui/floating_point_abs.stderr index 0c1f68f3b7fd..f031ac25114d 100644 --- a/tests/ui/floating_point_abs.stderr +++ b/tests/ui/floating_point_abs.stderr @@ -8,43 +8,43 @@ LL | if num >= 0.0 { num } else { -num } = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: manual implementation of `abs` method - --> tests/ui/floating_point_abs.rs:18:5 + --> tests/ui/floating_point_abs.rs:19:5 | LL | if 0.0 < num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> tests/ui/floating_point_abs.rs:22:5 + --> tests/ui/floating_point_abs.rs:24:5 | LL | if a.a > 0.0 { a.a } else { -a.a } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of `abs` method - --> tests/ui/floating_point_abs.rs:26:5 + --> tests/ui/floating_point_abs.rs:29:5 | LL | if 0.0 >= num { -num } else { num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> tests/ui/floating_point_abs.rs:30:5 + --> tests/ui/floating_point_abs.rs:34: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 - --> tests/ui/floating_point_abs.rs:34:5 + --> tests/ui/floating_point_abs.rs:39:5 | LL | if num < 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> tests/ui/floating_point_abs.rs:38:5 + --> tests/ui/floating_point_abs.rs:44:5 | LL | if 0.0 >= num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> tests/ui/floating_point_abs.rs:43:12 + --> tests/ui/floating_point_abs.rs:50: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_arithmetic_nostd.rs b/tests/ui/floating_point_arithmetic_nostd.rs index 81e4e0380dad..c4456bf870cd 100644 --- a/tests/ui/floating_point_arithmetic_nostd.rs +++ b/tests/ui/floating_point_arithmetic_nostd.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![crate_type = "lib"] #![warn(clippy::imprecise_flops)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_exp.fixed b/tests/ui/floating_point_exp.fixed index fbd91cbc9d70..72a6f4fcfbd3 100644 --- a/tests/ui/floating_point_exp.fixed +++ b/tests/ui/floating_point_exp.fixed @@ -6,15 +6,20 @@ fn main() { let x = 2f32; let _ = x.exp_m1(); + //~^ imprecise_flops let _ = x.exp_m1() + 2.0; + //~^ imprecise_flops let _ = (x as f32).exp_m1() + 2.0; + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; let x = 2f64; let _ = x.exp_m1(); + //~^ imprecise_flops let _ = x.exp_m1() + 2.0; + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs index 340bacaf56b5..ce584c038a49 100644 --- a/tests/ui/floating_point_exp.rs +++ b/tests/ui/floating_point_exp.rs @@ -6,15 +6,20 @@ fn main() { let x = 2f32; let _ = x.exp() - 1.0; + //~^ imprecise_flops let _ = x.exp() - 1.0 + 2.0; + //~^ imprecise_flops let _ = (x as f32).exp() - 1.0 + 2.0; + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; let x = 2f64; let _ = x.exp() - 1.0; + //~^ imprecise_flops let _ = x.exp() - 1.0 + 2.0; + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = x.exp() - 2.0; let _ = x.exp() - 1.0 * 2.0; diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr index 6ce67254abc9..7736a8e7ac36 100644 --- a/tests/ui/floating_point_exp.stderr +++ b/tests/ui/floating_point_exp.stderr @@ -8,25 +8,25 @@ LL | let _ = x.exp() - 1.0; = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:9:13 + --> tests/ui/floating_point_exp.rs:10: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 - --> tests/ui/floating_point_exp.rs:10:13 + --> tests/ui/floating_point_exp.rs:12: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 - --> tests/ui/floating_point_exp.rs:16:13 + --> tests/ui/floating_point_exp.rs:19:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> tests/ui/floating_point_exp.rs:17:13 + --> tests/ui/floating_point_exp.rs:21: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 75a224440b0d..1fa684e78e0b 100644 --- a/tests/ui/floating_point_hypot.fixed +++ b/tests/ui/floating_point_hypot.fixed @@ -4,8 +4,11 @@ fn main() { let x = 3f32; let y = 4f32; let _ = x.hypot(y); + //~^ imprecise_flops let _ = (x + 1f32).hypot(y); + //~^ imprecise_flops let _ = x.hypot(y); + //~^ imprecise_flops // Cases where the lint shouldn't be applied // TODO: linting this adds some complexity, but could be done let _ = x.mul_add(x, y * y).sqrt(); diff --git a/tests/ui/floating_point_hypot.rs b/tests/ui/floating_point_hypot.rs index ed4dbf6382e7..9b4e74d28d0f 100644 --- a/tests/ui/floating_point_hypot.rs +++ b/tests/ui/floating_point_hypot.rs @@ -4,8 +4,11 @@ fn main() { let x = 3f32; let y = 4f32; let _ = (x * x + y * y).sqrt(); + //~^ imprecise_flops let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); + //~^ imprecise_flops let _ = (x.powi(2) + y.powi(2)).sqrt(); + //~^ imprecise_flops // Cases where the lint shouldn't be applied // TODO: linting this adds some complexity, but could be done let _ = x.mul_add(x, y * y).sqrt(); diff --git a/tests/ui/floating_point_hypot.stderr b/tests/ui/floating_point_hypot.stderr index 8942e86910da..3526df2cf265 100644 --- a/tests/ui/floating_point_hypot.stderr +++ b/tests/ui/floating_point_hypot.stderr @@ -8,13 +8,13 @@ LL | let _ = (x * x + y * y).sqrt(); = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: hypotenuse can be computed more accurately - --> tests/ui/floating_point_hypot.rs:7:13 + --> tests/ui/floating_point_hypot.rs:8:13 | LL | let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 1f32).hypot(y)` error: hypotenuse can be computed more accurately - --> tests/ui/floating_point_hypot.rs:8:13 + --> tests/ui/floating_point_hypot.rs:10: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 75e9c40a5218..275c9b4a3ab9 100644 --- a/tests/ui/floating_point_log.fixed +++ b/tests/ui/floating_point_log.fixed @@ -9,31 +9,51 @@ const E: f32 = std::f32::consts::E; fn check_log_base() { let x = 1f32; let _ = x.log2(); + //~^ suboptimal_flops let _ = x.log10(); + //~^ suboptimal_flops let _ = x.ln(); + //~^ suboptimal_flops let _ = x.log2(); + //~^ suboptimal_flops let _ = x.ln(); + //~^ suboptimal_flops let _ = (x as f32).log2(); + //~^ suboptimal_flops let x = 1f64; let _ = x.log2(); + //~^ suboptimal_flops let _ = x.log10(); + //~^ suboptimal_flops let _ = x.ln(); + //~^ suboptimal_flops } fn check_ln1p() { let x = 1f32; let _ = 2.0f32.ln_1p(); + //~^ imprecise_flops let _ = 2.0f32.ln_1p(); + //~^ imprecise_flops let _ = x.ln_1p(); + //~^ imprecise_flops let _ = (x / 2.0).ln_1p(); + //~^ imprecise_flops let _ = x.powi(3).ln_1p(); + //~^ imprecise_flops let _ = (x.powi(3) / 2.0).ln_1p(); + //~^ imprecise_flops let _ = (std::f32::consts::E - 1.0).ln_1p(); + //~^ imprecise_flops let _ = x.ln_1p(); + //~^ imprecise_flops let _ = x.powi(3).ln_1p(); + //~^ imprecise_flops let _ = (x + 2.0).ln_1p(); + //~^ imprecise_flops let _ = (x / 2.0).ln_1p(); + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); @@ -42,14 +62,23 @@ fn check_ln1p() { let x = 1f64; let _ = 2.0f64.ln_1p(); + //~^ imprecise_flops let _ = 2.0f64.ln_1p(); + //~^ imprecise_flops let _ = x.ln_1p(); + //~^ imprecise_flops let _ = (x / 2.0).ln_1p(); + //~^ imprecise_flops let _ = x.powi(3).ln_1p(); + //~^ imprecise_flops let _ = x.ln_1p(); + //~^ imprecise_flops let _ = x.powi(3).ln_1p(); + //~^ imprecise_flops let _ = (x + 2.0).ln_1p(); + //~^ imprecise_flops let _ = (x / 2.0).ln_1p(); + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs index d68369a38618..a372ccbb9fb0 100644 --- a/tests/ui/floating_point_log.rs +++ b/tests/ui/floating_point_log.rs @@ -9,31 +9,51 @@ const E: f32 = std::f32::consts::E; fn check_log_base() { let x = 1f32; let _ = x.log(2f32); + //~^ suboptimal_flops let _ = x.log(10f32); + //~^ suboptimal_flops let _ = x.log(std::f32::consts::E); + //~^ suboptimal_flops let _ = x.log(TWO); + //~^ suboptimal_flops let _ = x.log(E); + //~^ suboptimal_flops let _ = (x as f32).log(2f32); + //~^ suboptimal_flops let x = 1f64; let _ = x.log(2f64); + //~^ suboptimal_flops let _ = x.log(10f64); + //~^ suboptimal_flops let _ = x.log(std::f64::consts::E); + //~^ suboptimal_flops } fn check_ln1p() { let x = 1f32; let _ = (1f32 + 2.).ln(); + //~^ imprecise_flops let _ = (1f32 + 2.0).ln(); + //~^ imprecise_flops let _ = (1.0 + x).ln(); + //~^ imprecise_flops let _ = (1.0 + x / 2.0).ln(); + //~^ imprecise_flops let _ = (1.0 + x.powi(3)).ln(); + //~^ imprecise_flops let _ = (1.0 + x.powi(3) / 2.0).ln(); + //~^ imprecise_flops let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); + //~^ imprecise_flops let _ = (x + 1.0).ln(); + //~^ imprecise_flops let _ = (x.powi(3) + 1.0).ln(); + //~^ imprecise_flops let _ = (x + 2.0 + 1.0).ln(); + //~^ imprecise_flops let _ = (x / 2.0 + 1.0).ln(); + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); @@ -42,14 +62,23 @@ fn check_ln1p() { let x = 1f64; let _ = (1f64 + 2.).ln(); + //~^ imprecise_flops let _ = (1f64 + 2.0).ln(); + //~^ imprecise_flops let _ = (1.0 + x).ln(); + //~^ imprecise_flops let _ = (1.0 + x / 2.0).ln(); + //~^ imprecise_flops let _ = (1.0 + x.powi(3)).ln(); + //~^ imprecise_flops let _ = (x + 1.0).ln(); + //~^ imprecise_flops let _ = (x.powi(3) + 1.0).ln(); + //~^ imprecise_flops let _ = (x + 2.0 + 1.0).ln(); + //~^ imprecise_flops let _ = (x / 2.0 + 1.0).ln(); + //~^ imprecise_flops // Cases where the lint shouldn't be applied let _ = (1.0 + x + 2.0).ln(); let _ = (x + 1.0 + 2.0).ln(); diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr index 19c28de8e39a..e93b3af851cb 100644 --- a/tests/ui/floating_point_log.stderr +++ b/tests/ui/floating_point_log.stderr @@ -8,55 +8,55 @@ LL | let _ = x.log(2f32); = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:12:13 + --> tests/ui/floating_point_log.rs:13:13 | LL | let _ = x.log(10f32); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:13:13 + --> tests/ui/floating_point_log.rs:15: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 - --> tests/ui/floating_point_log.rs:14:13 + --> tests/ui/floating_point_log.rs:17:13 | LL | let _ = x.log(TWO); | ^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:15:13 + --> tests/ui/floating_point_log.rs:19:13 | LL | let _ = x.log(E); | ^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:16:13 + --> tests/ui/floating_point_log.rs:21: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 - --> tests/ui/floating_point_log.rs:19:13 + --> tests/ui/floating_point_log.rs:25:13 | LL | let _ = x.log(2f64); | ^^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:20:13 + --> tests/ui/floating_point_log.rs:27:13 | LL | let _ = x.log(10f64); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> tests/ui/floating_point_log.rs:21:13 + --> tests/ui/floating_point_log.rs:29:13 | LL | let _ = x.log(std::f64::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:26:13 + --> tests/ui/floating_point_log.rs:35:13 | LL | let _ = (1f32 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` @@ -65,95 +65,41 @@ LL | let _ = (1f32 + 2.).ln(); = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:27:13 + --> tests/ui/floating_point_log.rs:37:13 | LL | let _ = (1f32 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:28:13 + --> tests/ui/floating_point_log.rs:39:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:29:13 + --> tests/ui/floating_point_log.rs:41: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 - --> tests/ui/floating_point_log.rs:30:13 + --> tests/ui/floating_point_log.rs:43: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 - --> tests/ui/floating_point_log.rs:31:13 + --> tests/ui/floating_point_log.rs:45: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 - --> tests/ui/floating_point_log.rs:32:13 + --> tests/ui/floating_point_log.rs:47: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 - --> tests/ui/floating_point_log.rs:33:13 - | -LL | let _ = (x + 1.0).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:34: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 - --> tests/ui/floating_point_log.rs:35: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 - --> tests/ui/floating_point_log.rs:36: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 - --> tests/ui/floating_point_log.rs:44:13 - | -LL | let _ = (1f64 + 2.).ln(); - | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:45:13 - | -LL | let _ = (1f64 + 2.0).ln(); - | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:46:13 - | -LL | let _ = (1.0 + x).ln(); - | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` - -error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:47: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 - --> tests/ui/floating_point_log.rs:48: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 --> tests/ui/floating_point_log.rs:49:13 | @@ -161,19 +107,73 @@ LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> tests/ui/floating_point_log.rs:50:13 + --> tests/ui/floating_point_log.rs:51: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 - --> tests/ui/floating_point_log.rs:51:13 + --> tests/ui/floating_point_log.rs:53: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 - --> tests/ui/floating_point_log.rs:52:13 + --> tests/ui/floating_point_log.rs:55: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 + --> tests/ui/floating_point_log.rs:64:13 + | +LL | let _ = (1f64 + 2.).ln(); + | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` + +error: ln(1 + x) can be computed more accurately + --> tests/ui/floating_point_log.rs:66:13 + | +LL | let _ = (1f64 + 2.0).ln(); + | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` + +error: ln(1 + x) can be computed more accurately + --> tests/ui/floating_point_log.rs:68:13 + | +LL | let _ = (1.0 + x).ln(); + | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` + +error: ln(1 + x) can be computed more accurately + --> tests/ui/floating_point_log.rs:70: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 + --> tests/ui/floating_point_log.rs:72: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 + --> tests/ui/floating_point_log.rs:74:13 + | +LL | let _ = (x + 1.0).ln(); + | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` + +error: ln(1 + x) can be computed more accurately + --> tests/ui/floating_point_log.rs:76: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 + --> tests/ui/floating_point_log.rs:78: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 + --> tests/ui/floating_point_log.rs:80: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 451673d109c6..d03882c774c0 100644 --- a/tests/ui/floating_point_logbase.fixed +++ b/tests/ui/floating_point_logbase.fixed @@ -5,10 +5,15 @@ fn main() { let x = 3f32; let y = 5f32; let _ = x.log(y); + //~^ suboptimal_flops let _ = (x as f32).log(y); + //~^ suboptimal_flops let _ = x.log(y); + //~^ suboptimal_flops let _ = x.log(y); + //~^ suboptimal_flops let _ = x.log(y); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.ln() / y.powf(3.2); let _ = x.powf(3.2) / y.powf(3.2); diff --git a/tests/ui/floating_point_logbase.rs b/tests/ui/floating_point_logbase.rs index c309114599d9..c29f4deb3738 100644 --- a/tests/ui/floating_point_logbase.rs +++ b/tests/ui/floating_point_logbase.rs @@ -5,10 +5,15 @@ fn main() { let x = 3f32; let y = 5f32; let _ = x.ln() / y.ln(); + //~^ suboptimal_flops let _ = (x as f32).ln() / y.ln(); + //~^ suboptimal_flops let _ = x.log2() / y.log2(); + //~^ suboptimal_flops let _ = x.log10() / y.log10(); + //~^ suboptimal_flops let _ = x.log(5f32) / y.log(5f32); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.ln() / y.powf(3.2); let _ = x.powf(3.2) / y.powf(3.2); diff --git a/tests/ui/floating_point_logbase.stderr b/tests/ui/floating_point_logbase.stderr index 8dfc57b133c6..1f30e5cbc177 100644 --- a/tests/ui/floating_point_logbase.stderr +++ b/tests/ui/floating_point_logbase.stderr @@ -8,25 +8,25 @@ LL | let _ = x.ln() / y.ln(); = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: log base can be expressed more clearly - --> tests/ui/floating_point_logbase.rs:8:13 + --> tests/ui/floating_point_logbase.rs:9: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 - --> tests/ui/floating_point_logbase.rs:9:13 + --> tests/ui/floating_point_logbase.rs:11:13 | LL | let _ = x.log2() / y.log2(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> tests/ui/floating_point_logbase.rs:10:13 + --> tests/ui/floating_point_logbase.rs:13:13 | LL | let _ = x.log10() / y.log10(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> tests/ui/floating_point_logbase.rs:11:13 + --> tests/ui/floating_point_logbase.rs:15: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 164aac2601a5..83aeddb2a1f4 100644 --- a/tests/ui/floating_point_mul_add.fixed +++ b/tests/ui/floating_point_mul_add.fixed @@ -17,23 +17,36 @@ fn main() { let d: f64 = 0.0001; let _ = a.mul_add(b, c); + //~^ suboptimal_flops let _ = a.mul_add(b, -c); + //~^ suboptimal_flops let _ = a.mul_add(b, c); + //~^ suboptimal_flops let _ = a.mul_add(-b, c); + //~^ suboptimal_flops let _ = 2.0f64.mul_add(4.0, a); + //~^ suboptimal_flops let _ = 2.0f64.mul_add(4., a); + //~^ suboptimal_flops let _ = a.mul_add(b, c); + //~^ suboptimal_flops let _ = a.mul_add(b, c); + //~^ suboptimal_flops let _ = (a * b).mul_add(c, d); + //~^ suboptimal_flops let _ = a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c)) + c; + //~^ suboptimal_flops let _ = 1234.567_f64.mul_add(45.67834_f64, 0.0004_f64); + //~^ suboptimal_flops let _ = a.mul_add(a, b).sqrt(); + //~^ suboptimal_flops let u = 1usize; let _ = b.mul_add(-(u as f64), a); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs index ae024b7f224b..039ee8d053fc 100644 --- a/tests/ui/floating_point_mul_add.rs +++ b/tests/ui/floating_point_mul_add.rs @@ -17,23 +17,36 @@ fn main() { let d: f64 = 0.0001; let _ = a * b + c; + //~^ suboptimal_flops let _ = a * b - c; + //~^ suboptimal_flops let _ = c + a * b; + //~^ suboptimal_flops let _ = c - a * b; + //~^ suboptimal_flops let _ = a + 2.0 * 4.0; + //~^ suboptimal_flops let _ = a + 2. * 4.; + //~^ suboptimal_flops let _ = (a * b) + c; + //~^ suboptimal_flops let _ = c + (a * b); + //~^ suboptimal_flops let _ = a * b * c + d; + //~^ suboptimal_flops let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; + //~^ suboptimal_flops let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; + //~^ suboptimal_flops let _ = (a * a + b).sqrt(); + //~^ suboptimal_flops let u = 1usize; let _ = a - (b * u as f64); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = (a * a + b * b).sqrt(); diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr index 9c75909f7158..6482127bcc00 100644 --- a/tests/ui/floating_point_mul_add.stderr +++ b/tests/ui/floating_point_mul_add.stderr @@ -8,73 +8,73 @@ LL | let _ = a * b + c; = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:20:13 + --> tests/ui/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 - --> tests/ui/floating_point_mul_add.rs:21:13 + --> tests/ui/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 - --> tests/ui/floating_point_mul_add.rs:22:13 + --> tests/ui/floating_point_mul_add.rs:25: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 - --> tests/ui/floating_point_mul_add.rs:23:13 + --> tests/ui/floating_point_mul_add.rs:27: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 - --> tests/ui/floating_point_mul_add.rs:24:13 + --> tests/ui/floating_point_mul_add.rs:29: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 - --> tests/ui/floating_point_mul_add.rs:26:13 + --> tests/ui/floating_point_mul_add.rs:32: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 - --> tests/ui/floating_point_mul_add.rs:27:13 + --> tests/ui/floating_point_mul_add.rs:34: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 - --> tests/ui/floating_point_mul_add.rs:28:13 + --> tests/ui/floating_point_mul_add.rs:36: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 - --> tests/ui/floating_point_mul_add.rs:30:13 + --> tests/ui/floating_point_mul_add.rs:39: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 - --> tests/ui/floating_point_mul_add.rs:31:13 + --> tests/ui/floating_point_mul_add.rs:41: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 - --> tests/ui/floating_point_mul_add.rs:33:13 + --> tests/ui/floating_point_mul_add.rs:44:13 | LL | let _ = (a * a + b).sqrt(); | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` error: multiply and add expressions can be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:36:13 + --> tests/ui/floating_point_mul_add.rs:48:13 | LL | let _ = a - (b * u as f64); | ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)` diff --git a/tests/ui/floating_point_powf.fixed b/tests/ui/floating_point_powf.fixed index 25f09a637951..293df9bfe9b9 100644 --- a/tests/ui/floating_point_powf.fixed +++ b/tests/ui/floating_point_powf.fixed @@ -6,24 +6,43 @@ fn main() { let x = 3f32; let _ = x.exp2(); + //~^ suboptimal_flops let _ = 3.1f32.exp2(); + //~^ suboptimal_flops let _ = (-3.1f32).exp2(); + //~^ suboptimal_flops let _ = x.exp(); + //~^ suboptimal_flops let _ = 3.1f32.exp(); + //~^ suboptimal_flops let _ = (-3.1f32).exp(); + //~^ suboptimal_flops let _ = x.sqrt(); + //~^ suboptimal_flops let _ = x.cbrt(); + //~^ imprecise_flops let _ = (x as f32).cbrt(); + //~^ imprecise_flops let _ = x.powi(3); + //~^ suboptimal_flops let _ = x.powi(-2); + //~^ suboptimal_flops let _ = x.powi(16_777_215); + //~^ suboptimal_flops let _ = x.powi(-16_777_215); + //~^ suboptimal_flops let _ = (x as f32).powi(-16_777_215); + //~^ suboptimal_flops let _ = (x as f32).powi(3); + //~^ suboptimal_flops let _ = (1.5_f32 + 1.0).cbrt(); + //~^ imprecise_flops let _ = 1.5_f64.cbrt(); + //~^ imprecise_flops let _ = 1.5_f64.sqrt(); + //~^ suboptimal_flops let _ = 1.5_f64.powi(3); + //~^ suboptimal_flops macro_rules! m { ($e:expr) => { @@ -32,6 +51,7 @@ fn main() { } let _ = (1f32 + m!(2.0)).exp2(); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); @@ -41,17 +61,29 @@ fn main() { let x = 3f64; let _ = x.exp2(); + //~^ suboptimal_flops let _ = 3.1f64.exp2(); + //~^ suboptimal_flops let _ = (-3.1f64).exp2(); + //~^ suboptimal_flops let _ = x.exp(); + //~^ suboptimal_flops let _ = 3.1f64.exp(); + //~^ suboptimal_flops let _ = (-3.1f64).exp(); + //~^ suboptimal_flops let _ = x.sqrt(); + //~^ suboptimal_flops let _ = x.cbrt(); + //~^ imprecise_flops let _ = x.powi(3); + //~^ suboptimal_flops let _ = x.powi(-2); + //~^ suboptimal_flops let _ = x.powi(-2_147_483_648); + //~^ suboptimal_flops let _ = x.powi(2_147_483_647); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); let _ = x.powf(-2.1); diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs index 9e9878de4bad..5b1940a369a5 100644 --- a/tests/ui/floating_point_powf.rs +++ b/tests/ui/floating_point_powf.rs @@ -6,24 +6,43 @@ fn main() { let x = 3f32; let _ = 2f32.powf(x); + //~^ suboptimal_flops let _ = 2f32.powf(3.1); + //~^ suboptimal_flops let _ = 2f32.powf(-3.1); + //~^ suboptimal_flops let _ = std::f32::consts::E.powf(x); + //~^ suboptimal_flops let _ = std::f32::consts::E.powf(3.1); + //~^ suboptimal_flops let _ = std::f32::consts::E.powf(-3.1); + //~^ suboptimal_flops let _ = x.powf(1.0 / 2.0); + //~^ suboptimal_flops let _ = x.powf(1.0 / 3.0); + //~^ imprecise_flops let _ = (x as f32).powf(1.0 / 3.0); + //~^ imprecise_flops let _ = x.powf(3.0); + //~^ suboptimal_flops let _ = x.powf(-2.0); + //~^ suboptimal_flops let _ = x.powf(16_777_215.0); + //~^ suboptimal_flops let _ = x.powf(-16_777_215.0); + //~^ suboptimal_flops let _ = (x as f32).powf(-16_777_215.0); + //~^ suboptimal_flops let _ = (x as f32).powf(3.0); + //~^ suboptimal_flops let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); + //~^ imprecise_flops let _ = 1.5_f64.powf(1.0 / 3.0); + //~^ imprecise_flops let _ = 1.5_f64.powf(1.0 / 2.0); + //~^ suboptimal_flops let _ = 1.5_f64.powf(3.0); + //~^ suboptimal_flops macro_rules! m { ($e:expr) => { @@ -32,6 +51,7 @@ fn main() { } let _ = 2f32.powf(1f32 + m!(2.0)); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); @@ -41,17 +61,29 @@ fn main() { let x = 3f64; let _ = 2f64.powf(x); + //~^ suboptimal_flops let _ = 2f64.powf(3.1); + //~^ suboptimal_flops let _ = 2f64.powf(-3.1); + //~^ suboptimal_flops let _ = std::f64::consts::E.powf(x); + //~^ suboptimal_flops let _ = std::f64::consts::E.powf(3.1); + //~^ suboptimal_flops let _ = std::f64::consts::E.powf(-3.1); + //~^ suboptimal_flops let _ = x.powf(1.0 / 2.0); + //~^ suboptimal_flops let _ = x.powf(1.0 / 3.0); + //~^ imprecise_flops let _ = x.powf(3.0); + //~^ suboptimal_flops let _ = x.powf(-2.0); + //~^ suboptimal_flops let _ = x.powf(-2_147_483_648.0); + //~^ suboptimal_flops let _ = x.powf(2_147_483_647.0); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powf(2.1); let _ = x.powf(-2.1); diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr index c944f14fa34d..dec30a94cc78 100644 --- a/tests/ui/floating_point_powf.stderr +++ b/tests/ui/floating_point_powf.stderr @@ -8,43 +8,43 @@ LL | let _ = 2f32.powf(x); = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:9:13 + --> tests/ui/floating_point_powf.rs:10: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 - --> tests/ui/floating_point_powf.rs:10:13 + --> tests/ui/floating_point_powf.rs:12: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 - --> tests/ui/floating_point_powf.rs:11:13 + --> tests/ui/floating_point_powf.rs:14: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 - --> tests/ui/floating_point_powf.rs:12:13 + --> tests/ui/floating_point_powf.rs:16: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 - --> tests/ui/floating_point_powf.rs:13:13 + --> tests/ui/floating_point_powf.rs:18: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 - --> tests/ui/floating_point_powf.rs:14:13 + --> tests/ui/floating_point_powf.rs:20: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 - --> tests/ui/floating_point_powf.rs:15:13 + --> tests/ui/floating_point_powf.rs:22:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` @@ -53,145 +53,145 @@ LL | let _ = x.powf(1.0 / 3.0); = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: cube-root of a number can be computed more accurately - --> tests/ui/floating_point_powf.rs:16:13 + --> tests/ui/floating_point_powf.rs:24: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 - --> tests/ui/floating_point_powf.rs:17:13 + --> tests/ui/floating_point_powf.rs:26:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:18:13 + --> tests/ui/floating_point_powf.rs:28:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:19:13 + --> tests/ui/floating_point_powf.rs:30: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 - --> tests/ui/floating_point_powf.rs:20:13 + --> tests/ui/floating_point_powf.rs:32: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 - --> tests/ui/floating_point_powf.rs:21:13 + --> tests/ui/floating_point_powf.rs:34: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 - --> tests/ui/floating_point_powf.rs:22:13 + --> tests/ui/floating_point_powf.rs:36: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 - --> tests/ui/floating_point_powf.rs:23:13 + --> tests/ui/floating_point_powf.rs:38: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 - --> tests/ui/floating_point_powf.rs:24:13 + --> tests/ui/floating_point_powf.rs:40: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 - --> tests/ui/floating_point_powf.rs:25:13 + --> tests/ui/floating_point_powf.rs:42: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 - --> tests/ui/floating_point_powf.rs:26:13 + --> tests/ui/floating_point_powf.rs:44: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 - --> tests/ui/floating_point_powf.rs:34:13 + --> tests/ui/floating_point_powf.rs:53:13 | LL | let _ = 2f32.powf(1f32 + m!(2.0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(1f32 + m!(2.0)).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:43:13 + --> tests/ui/floating_point_powf.rs:63:13 | LL | let _ = 2f64.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> tests/ui/floating_point_powf.rs:44:13 + --> tests/ui/floating_point_powf.rs:65: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 - --> tests/ui/floating_point_powf.rs:45:13 + --> tests/ui/floating_point_powf.rs:67: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 - --> tests/ui/floating_point_powf.rs:46:13 + --> tests/ui/floating_point_powf.rs:69: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 - --> tests/ui/floating_point_powf.rs:47:13 + --> tests/ui/floating_point_powf.rs:71: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 - --> tests/ui/floating_point_powf.rs:48:13 + --> tests/ui/floating_point_powf.rs:73: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 - --> tests/ui/floating_point_powf.rs:49:13 + --> tests/ui/floating_point_powf.rs:75: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 - --> tests/ui/floating_point_powf.rs:50:13 + --> tests/ui/floating_point_powf.rs:77:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:51:13 + --> tests/ui/floating_point_powf.rs:79:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:52:13 + --> tests/ui/floating_point_powf.rs:81:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> tests/ui/floating_point_powf.rs:53:13 + --> tests/ui/floating_point_powf.rs:83: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 - --> tests/ui/floating_point_powf.rs:54:13 + --> tests/ui/floating_point_powf.rs:85: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 cb033c899f31..5f0618ab1c72 100644 --- a/tests/ui/floating_point_powi.fixed +++ b/tests/ui/floating_point_powi.fixed @@ -7,20 +7,34 @@ fn main() { let y = 4f32; let _ = x.mul_add(x, y); + //~^ suboptimal_flops let _ = x.mul_add(x, -y); + //~^ suboptimal_flops let _ = y.mul_add(y, x); + //~^ suboptimal_flops let _ = y.mul_add(-y, x); + //~^ suboptimal_flops let _ = (y as f32).mul_add(y as f32, x); + //~^ suboptimal_flops let _ = x.mul_add(x, y).sqrt(); + //~^ suboptimal_flops let _ = y.mul_add(y, x).sqrt(); + //~^ suboptimal_flops let _ = (x - 1.0).mul_add(x - 1.0, -y); + //~^ suboptimal_flops let _ = (x - 1.0).mul_add(x - 1.0, -y) + 3.0; + //~^ suboptimal_flops let _ = (x - 1.0).mul_add(x - 1.0, -(y + 3.0)); + //~^ suboptimal_flops let _ = (y + 1.0).mul_add(-(y + 1.0), x); + //~^ suboptimal_flops let _ = (3.0 * y).mul_add(-(3.0 * y), x); + //~^ suboptimal_flops let _ = (y + 1.0 + x).mul_add(-(y + 1.0 + x), x); + //~^ suboptimal_flops let _ = (y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powi(2); diff --git a/tests/ui/floating_point_powi.rs b/tests/ui/floating_point_powi.rs index f02e0e8ddb36..bb97a8eddf33 100644 --- a/tests/ui/floating_point_powi.rs +++ b/tests/ui/floating_point_powi.rs @@ -7,20 +7,34 @@ fn main() { let y = 4f32; let _ = x.powi(2) + y; + //~^ suboptimal_flops let _ = x.powi(2) - y; + //~^ suboptimal_flops let _ = x + y.powi(2); + //~^ suboptimal_flops let _ = x - y.powi(2); + //~^ suboptimal_flops let _ = x + (y as f32).powi(2); + //~^ suboptimal_flops let _ = (x.powi(2) + y).sqrt(); + //~^ suboptimal_flops let _ = (x + y.powi(2)).sqrt(); + //~^ suboptimal_flops let _ = (x - 1.0).powi(2) - y; + //~^ suboptimal_flops let _ = (x - 1.0).powi(2) - y + 3.0; + //~^ suboptimal_flops let _ = (x - 1.0).powi(2) - (y + 3.0); + //~^ suboptimal_flops let _ = x - (y + 1.0).powi(2); + //~^ suboptimal_flops let _ = x - (3.0 * y).powi(2); + //~^ suboptimal_flops let _ = x - (y + 1.0 + x).powi(2); + //~^ suboptimal_flops let _ = x - (y + 1.0 + 2.0).powi(2); + //~^ suboptimal_flops // Cases where the lint shouldn't be applied let _ = x.powi(2); diff --git a/tests/ui/floating_point_powi.stderr b/tests/ui/floating_point_powi.stderr index dfed20cb8c5a..211589382911 100644 --- a/tests/ui/floating_point_powi.stderr +++ b/tests/ui/floating_point_powi.stderr @@ -8,79 +8,79 @@ LL | let _ = x.powi(2) + y; = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately - --> tests/ui/floating_point_powi.rs:10:13 + --> tests/ui/floating_point_powi.rs:11: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 - --> tests/ui/floating_point_powi.rs:11:13 + --> tests/ui/floating_point_powi.rs:13: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 - --> tests/ui/floating_point_powi.rs:12:13 + --> tests/ui/floating_point_powi.rs:15: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 - --> tests/ui/floating_point_powi.rs:13:13 + --> tests/ui/floating_point_powi.rs:17: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 - --> tests/ui/floating_point_powi.rs:14:13 + --> tests/ui/floating_point_powi.rs:19: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 - --> tests/ui/floating_point_powi.rs:15:13 + --> tests/ui/floating_point_powi.rs:21: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 - --> tests/ui/floating_point_powi.rs:17:13 + --> tests/ui/floating_point_powi.rs:24: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 - --> tests/ui/floating_point_powi.rs:18:13 + --> tests/ui/floating_point_powi.rs:26: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 - --> tests/ui/floating_point_powi.rs:19:13 + --> tests/ui/floating_point_powi.rs:28: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 - --> tests/ui/floating_point_powi.rs:20:13 + --> tests/ui/floating_point_powi.rs:30: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 - --> tests/ui/floating_point_powi.rs:21:13 + --> tests/ui/floating_point_powi.rs:32: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 - --> tests/ui/floating_point_powi.rs:22:13 + --> tests/ui/floating_point_powi.rs:34: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 - --> tests/ui/floating_point_powi.rs:23:13 + --> tests/ui/floating_point_powi.rs:36: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 2f93d233cb40..61f3ccc8bd02 100644 --- a/tests/ui/floating_point_rad.fixed +++ b/tests/ui/floating_point_rad.fixed @@ -8,17 +8,25 @@ pub const fn const_context() { pub fn issue9391(degrees: i64) { let _ = (degrees as f64).to_radians(); + //~^ suboptimal_flops let _ = (degrees as f64).to_degrees(); + //~^ suboptimal_flops } fn main() { let x = 3f32; let _ = x.to_degrees(); + //~^ suboptimal_flops let _ = 90.0_f64.to_degrees(); + //~^ suboptimal_flops let _ = 90.5_f64.to_degrees(); + //~^ suboptimal_flops let _ = x.to_radians(); + //~^ suboptimal_flops let _ = 90.0_f64.to_radians(); + //~^ suboptimal_flops let _ = 90.5_f64.to_radians(); + //~^ suboptimal_flops // let _ = 90.5 * 80. * std::f32::consts::PI / 180f32; // Cases where the lint shouldn't be applied let _ = x * 90f32 / std::f32::consts::PI; diff --git a/tests/ui/floating_point_rad.rs b/tests/ui/floating_point_rad.rs index 9690effc4e10..f57359e15fe1 100644 --- a/tests/ui/floating_point_rad.rs +++ b/tests/ui/floating_point_rad.rs @@ -8,17 +8,25 @@ pub const fn const_context() { pub fn issue9391(degrees: i64) { let _ = degrees as f64 * std::f64::consts::PI / 180.0; + //~^ suboptimal_flops let _ = degrees as f64 * 180.0 / std::f64::consts::PI; + //~^ suboptimal_flops } fn main() { let x = 3f32; let _ = x * 180f32 / std::f32::consts::PI; + //~^ suboptimal_flops let _ = 90. * 180f64 / std::f64::consts::PI; + //~^ suboptimal_flops let _ = 90.5 * 180f64 / std::f64::consts::PI; + //~^ suboptimal_flops let _ = x * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops let _ = 90. * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops let _ = 90.5 * std::f32::consts::PI / 180f32; + //~^ suboptimal_flops // let _ = 90.5 * 80. * std::f32::consts::PI / 180f32; // Cases where the lint shouldn't be applied let _ = x * 90f32 / std::f32::consts::PI; diff --git a/tests/ui/floating_point_rad.stderr b/tests/ui/floating_point_rad.stderr index b834f5374e0b..b888edd59bfd 100644 --- a/tests/ui/floating_point_rad.stderr +++ b/tests/ui/floating_point_rad.stderr @@ -8,43 +8,43 @@ LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: conversion to degrees can be done more accurately - --> tests/ui/floating_point_rad.rs:11:13 + --> tests/ui/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 - --> tests/ui/floating_point_rad.rs:16:13 + --> tests/ui/floating_point_rad.rs:18:13 | LL | let _ = x * 180f32 / std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` error: conversion to degrees can be done more accurately - --> tests/ui/floating_point_rad.rs:17:13 + --> tests/ui/floating_point_rad.rs:20: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 - --> tests/ui/floating_point_rad.rs:18:13 + --> tests/ui/floating_point_rad.rs:22: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 - --> tests/ui/floating_point_rad.rs:19:13 + --> tests/ui/floating_point_rad.rs:24:13 | LL | let _ = x * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` error: conversion to radians can be done more accurately - --> tests/ui/floating_point_rad.rs:20:13 + --> tests/ui/floating_point_rad.rs:26: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 - --> tests/ui/floating_point_rad.rs:21:13 + --> tests/ui/floating_point_rad.rs:28: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.64bit.stderr b/tests/ui/fn_to_numeric_cast.64bit.stderr index 58f55f19a745..1c2a0dab10b5 100644 --- a/tests/ui/fn_to_numeric_cast.64bit.stderr +++ b/tests/ui/fn_to_numeric_cast.64bit.stderr @@ -8,19 +8,19 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:11:13 + --> tests/ui/fn_to_numeric_cast.rs:12:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:12:13 + --> tests/ui/fn_to_numeric_cast.rs:14:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:13:13 + --> tests/ui/fn_to_numeric_cast.rs:16:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` @@ -29,115 +29,115 @@ LL | let _ = foo as i64; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:14:13 + --> tests/ui/fn_to_numeric_cast.rs:18:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:15:13 + --> tests/ui/fn_to_numeric_cast.rs:20:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:17:13 + --> tests/ui/fn_to_numeric_cast.rs:23:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:18:13 + --> tests/ui/fn_to_numeric_cast.rs:25:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:19:13 + --> tests/ui/fn_to_numeric_cast.rs:27:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:20:13 + --> tests/ui/fn_to_numeric_cast.rs:29:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:21:13 + --> tests/ui/fn_to_numeric_cast.rs:31:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:34:13 + --> tests/ui/fn_to_numeric_cast.rs:45:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:35:13 + --> tests/ui/fn_to_numeric_cast.rs:47:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:36:13 + --> tests/ui/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:37:13 + --> tests/ui/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:38:13 + --> tests/ui/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:39:13 + --> tests/ui/fn_to_numeric_cast.rs:55:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:41:13 + --> tests/ui/fn_to_numeric_cast.rs:58:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:42:13 + --> tests/ui/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:43:13 + --> tests/ui/fn_to_numeric_cast.rs:62:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:44:13 + --> tests/ui/fn_to_numeric_cast.rs:64:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:45:13 + --> tests/ui/fn_to_numeric_cast.rs:66:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:52:5 + --> tests/ui/fn_to_numeric_cast.rs:74:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 9501eb5da4b2..70be37c0f959 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -8,17 +8,28 @@ fn foo() -> String { fn test_function_to_numeric_cast() { let _ = foo as i8; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as i16; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as i32; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as i64; + //~^ fn_to_numeric_cast let _ = foo as i128; + //~^ fn_to_numeric_cast let _ = foo as isize; + //~^ fn_to_numeric_cast let _ = foo as u8; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as u16; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as u32; + //~^ fn_to_numeric_cast_with_truncation let _ = foo as u64; + //~^ fn_to_numeric_cast let _ = foo as u128; + //~^ fn_to_numeric_cast // Casting to usize is OK and should not warn let _ = foo as usize; @@ -32,17 +43,28 @@ fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; let _ = abc as i8; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as i16; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as i32; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as i64; + //~^ fn_to_numeric_cast let _ = abc as i128; + //~^ fn_to_numeric_cast let _ = abc as isize; + //~^ fn_to_numeric_cast let _ = abc as u8; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as u16; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as u32; + //~^ fn_to_numeric_cast_with_truncation let _ = abc as u64; + //~^ fn_to_numeric_cast let _ = abc as u128; + //~^ fn_to_numeric_cast // Casting to usize is OK and should not warn let _ = abc as usize; @@ -50,6 +72,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 + //~^ fn_to_numeric_cast_with_truncation } fn main() {} diff --git a/tests/ui/fn_to_numeric_cast_any.rs b/tests/ui/fn_to_numeric_cast_any.rs index 95abc0ac68dd..3359e24c2b6a 100644 --- a/tests/ui/fn_to_numeric_cast_any.rs +++ b/tests/ui/fn_to_numeric_cast_any.rs @@ -21,58 +21,75 @@ 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` + //~^ fn_to_numeric_cast_any + + let _ = foo as i16; - //~^ ERROR: casting function pointer `foo` to `i16` + //~^ fn_to_numeric_cast_any + let _ = foo as i32; - //~^ ERROR: casting function pointer `foo` to `i32` + //~^ fn_to_numeric_cast_any + let _ = foo as i64; - //~^ ERROR: casting function pointer `foo` to `i64` + //~^ fn_to_numeric_cast_any + let _ = foo as i128; - //~^ ERROR: casting function pointer `foo` to `i128` + //~^ fn_to_numeric_cast_any + let _ = foo as isize; - //~^ ERROR: casting function pointer `foo` to `isize` + //~^ fn_to_numeric_cast_any + let _ = foo as u8; - //~^ ERROR: casting function pointer `foo` to `u8` + //~^ fn_to_numeric_cast_any + let _ = foo as u16; - //~^ ERROR: casting function pointer `foo` to `u16` + //~^ fn_to_numeric_cast_any + let _ = foo as u32; - //~^ ERROR: casting function pointer `foo` to `u32` + //~^ fn_to_numeric_cast_any + let _ = foo as u64; - //~^ ERROR: casting function pointer `foo` to `u64` + //~^ fn_to_numeric_cast_any + let _ = foo as u128; - //~^ ERROR: casting function pointer `foo` to `u128` + //~^ fn_to_numeric_cast_any + let _ = foo as usize; - //~^ ERROR: casting function pointer `foo` to `usize` + //~^ fn_to_numeric_cast_any + } fn static_method_to_integer() { let _ = Struct::static_method as usize; - //~^ ERROR: casting function pointer `Struct::static_method` to `usize` + //~^ fn_to_numeric_cast_any + } fn fn_with_fn_arg(f: fn(i32) -> u32) -> usize { f as usize - //~^ ERROR: casting function pointer `f` to `usize` + //~^ fn_to_numeric_cast_any + } fn fn_with_generic_static_trait_method() -> usize { T::static_method as usize - //~^ ERROR: casting function pointer `T::static_method` to `usize` + //~^ fn_to_numeric_cast_any + } 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_to_numeric_cast_any + } fn fn_to_raw_ptr() { let _ = foo as *const (); - //~^ ERROR: casting function pointer `foo` to `*const ()` + //~^ fn_to_numeric_cast_any + } 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 a05b7138bc99..c6a7b2403395 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -12,7 +12,7 @@ LL | let _ = foo() as i8; | ~~~~~~~~~~~ error: casting function pointer `foo` to `i16` - --> tests/ui/fn_to_numeric_cast_any.rs:26:13 + --> tests/ui/fn_to_numeric_cast_any.rs:27:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = foo() as i16; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i32` - --> tests/ui/fn_to_numeric_cast_any.rs:28:13 + --> tests/ui/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = foo() as i32; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast_any.rs:30:13 + --> tests/ui/fn_to_numeric_cast_any.rs:33:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = foo() as i64; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast_any.rs:32:13 + --> tests/ui/fn_to_numeric_cast_any.rs:36:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = foo() as i128; | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast_any.rs:34:13 + --> tests/ui/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _ = foo() as isize; | ~~~~~~~~~~~~~~ error: casting function pointer `foo` to `u8` - --> tests/ui/fn_to_numeric_cast_any.rs:37:13 + --> tests/ui/fn_to_numeric_cast_any.rs:43:13 | LL | let _ = foo as u8; | ^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _ = foo() as u8; | ~~~~~~~~~~~ error: casting function pointer `foo` to `u16` - --> tests/ui/fn_to_numeric_cast_any.rs:39:13 + --> tests/ui/fn_to_numeric_cast_any.rs:46:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = foo() as u16; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u32` - --> tests/ui/fn_to_numeric_cast_any.rs:41:13 + --> tests/ui/fn_to_numeric_cast_any.rs:49:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = foo() as u32; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast_any.rs:43:13 + --> tests/ui/fn_to_numeric_cast_any.rs:52:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _ = foo() as u64; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast_any.rs:45:13 + --> tests/ui/fn_to_numeric_cast_any.rs:55:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = foo() as u128; | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:47:13 + --> tests/ui/fn_to_numeric_cast_any.rs:58:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = foo() as usize; | ~~~~~~~~~~~~~~ error: casting function pointer `Struct::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:52:13 + --> tests/ui/fn_to_numeric_cast_any.rs:64:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _ = Struct::static_method() as usize; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `f` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:57:5 + --> tests/ui/fn_to_numeric_cast_any.rs:70:5 | LL | f as usize | ^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | f() as usize | error: casting function pointer `T::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:62:5 + --> tests/ui/fn_to_numeric_cast_any.rs:76:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | T::static_method() as usize | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:69:13 + --> tests/ui/fn_to_numeric_cast_any.rs:84:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _ = (clos as fn(u32) -> u32)() as usize; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `foo` to `*const ()` - --> tests/ui/fn_to_numeric_cast_any.rs:74:13 + --> tests/ui/fn_to_numeric_cast_any.rs:90:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/for_kv_map.fixed b/tests/ui/for_kv_map.fixed index 1733b29128fe..402098e9394b 100644 --- a/tests/ui/for_kv_map.fixed +++ b/tests/ui/for_kv_map.fixed @@ -7,14 +7,16 @@ 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` + //~^ for_kv_map + + 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 + //~^ for_kv_map + let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -23,27 +25,31 @@ 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 + //~^ for_kv_map + 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 + //~^ for_kv_map + 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 + //~^ for_kv_map + let _k = k; } let m: HashMap = HashMap::new(); let rm = &m; 'label: for k in rm.keys() { - //~^ ERROR: you seem to want to iterate on a map's keys + //~^ for_kv_map + let _k = k; if *k == 0u64 { break 'label; diff --git a/tests/ui/for_kv_map.rs b/tests/ui/for_kv_map.rs index de465a7c8e6e..407590747a4b 100644 --- a/tests/ui/for_kv_map.rs +++ b/tests/ui/for_kv_map.rs @@ -7,14 +7,16 @@ 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` + //~^ for_kv_map + + 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 + //~^ for_kv_map + let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -23,27 +25,31 @@ 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 + //~^ for_kv_map + 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 + //~^ for_kv_map + 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 + //~^ for_kv_map + let _k = k; } let m: HashMap = HashMap::new(); let rm = &m; 'label: for (k, _value) in rm { - //~^ ERROR: you seem to want to iterate on a map's keys + //~^ for_kv_map + let _k = k; if *k == 0u64 { break 'label; diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index adcc3ab8fdb9..5c28da81a961 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -12,7 +12,7 @@ LL | for v in m.values() { | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:16:19 + --> tests/ui/for_kv_map.rs:17:19 | LL | for (_, v) in &*m { | ^^^ @@ -23,7 +23,7 @@ LL | for v in (*m).values() { | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:25:19 + --> tests/ui/for_kv_map.rs:27:19 | LL | for (_, v) in &mut m { | ^^^^^^ @@ -34,7 +34,7 @@ LL | for v in m.values_mut() { | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:31:19 + --> tests/ui/for_kv_map.rs:34:19 | LL | for (_, v) in &mut *m { | ^^^^^^^ @@ -45,7 +45,7 @@ LL | for v in (*m).values_mut() { | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> tests/ui/for_kv_map.rs:38:24 + --> tests/ui/for_kv_map.rs:42:24 | LL | for (k, _value) in rm { | ^^ @@ -56,7 +56,7 @@ LL | for k in rm.keys() { | ~ ~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> tests/ui/for_kv_map.rs:45:32 + --> tests/ui/for_kv_map.rs:50:32 | LL | 'label: for (k, _value) in rm { | ^^ diff --git a/tests/ui/forget_non_drop.rs b/tests/ui/forget_non_drop.rs index 2459f51a38da..a69fa0f20359 100644 --- a/tests/ui/forget_non_drop.rs +++ b/tests/ui/forget_non_drop.rs @@ -11,7 +11,8 @@ fn main() { struct Foo; // Lint forget(Foo); - //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo + //~^ forget_non_drop + struct Bar; impl Drop for Bar { @@ -23,7 +24,8 @@ fn main() { struct Baz(T); // Lint forget(Baz(Foo)); - //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo + //~^ forget_non_drop + // Don't lint forget(Baz(Bar)); } diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index e121984154c7..0bff152a7132 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -13,13 +13,13 @@ LL | forget(Foo); = help: to override `-D warnings` add `#[allow(clippy::forget_non_drop)]` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it - --> tests/ui/forget_non_drop.rs:25:5 + --> tests/ui/forget_non_drop.rs:26:5 | LL | forget(Baz(Foo)); | ^^^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> tests/ui/forget_non_drop.rs:25:12 + --> tests/ui/forget_non_drop.rs:26:12 | LL | forget(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index 3dc8eb79ba28..16437c62094a 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -18,14 +18,19 @@ macro_rules! foo { fn main() { "foo".to_string(); + //~^ useless_format "{}".to_string(); + //~^ useless_format "{} abc {}".to_string(); + //~^ useless_format r##"foo {} " bar"##.to_string(); let _ = String::new(); + //~^ useless_format "foo".to_string(); + //~^ useless_format format!("{:?}", "foo"); // Don't warn about `Debug`. format!("{:8}", "foo"); format!("{:width$}", "foo", width = 8); @@ -34,6 +39,7 @@ fn main() { let arg = String::new(); arg.to_string(); + //~^ useless_format format!("{:?}", arg); // Don't warn about debug. format!("{:8}", arg); format!("{:width$}", arg, width = 8); @@ -64,28 +70,36 @@ fn main() { format!("{:.prec$}", "foo", prec = 10); 42.to_string(); + //~^ useless_format let x = std::path::PathBuf::from("/bar/foo/qux"); x.display().to_string(); + //~^ useless_format // False positive let a = "foo".to_string(); let _ = Some(a + "bar"); + //~^ useless_format // Wrap it with braces let v: Vec = vec!["foo".to_string(), "bar".to_string()]; let _s: String = (&*v.join("\n")).to_string(); + //~^ useless_format format!("prepend {:+}", "s"); // Issue #8290 let x = "foo"; let _ = x.to_string(); + //~^ useless_format let _ = format!("{x:?}"); // Don't lint on debug let _ = x.to_string(); + //~^ useless_format // Issue #9234 let abc = "abc"; let _ = abc.to_string(); + //~^ useless_format let xx = "xx"; let _ = xx.to_string(); + //~^ useless_format } diff --git a/tests/ui/format.rs b/tests/ui/format.rs index eaf33c2a6c92..b40eb9d1eb9e 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -18,16 +18,22 @@ macro_rules! foo { fn main() { format!("foo"); + //~^ useless_format format!("{{}}"); + //~^ useless_format format!("{{}} abc {{}}"); + //~^ useless_format format!( + //~^ useless_format r##"foo {{}} " bar"## ); let _ = format!(""); + //~^ useless_format format!("{}", "foo"); + //~^ useless_format format!("{:?}", "foo"); // Don't warn about `Debug`. format!("{:8}", "foo"); format!("{:width$}", "foo", width = 8); @@ -36,6 +42,7 @@ fn main() { let arg = String::new(); format!("{}", arg); + //~^ useless_format format!("{:?}", arg); // Don't warn about debug. format!("{:8}", arg); format!("{:width$}", arg, width = 8); @@ -66,28 +73,36 @@ fn main() { format!("{:.prec$}", "foo", prec = 10); format!("{}", 42.to_string()); + //~^ useless_format let x = std::path::PathBuf::from("/bar/foo/qux"); format!("{}", x.display().to_string()); + //~^ useless_format // False positive let a = "foo".to_string(); let _ = Some(format!("{}", a + "bar")); + //~^ useless_format // Wrap it with braces let v: Vec = vec!["foo".to_string(), "bar".to_string()]; let _s: String = format!("{}", &*v.join("\n")); + //~^ useless_format format!("prepend {:+}", "s"); // Issue #8290 let x = "foo"; let _ = format!("{x}"); + //~^ useless_format let _ = format!("{x:?}"); // Don't lint on debug let _ = format!("{y}", y = x); + //~^ useless_format // Issue #9234 let abc = "abc"; let _ = format!("{abc}"); + //~^ useless_format let xx = "xx"; let _ = format!("{xx}"); + //~^ useless_format } diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 1368c8cd77e0..da990d32cb80 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -8,21 +8,22 @@ LL | format!("foo"); = help: to override `-D warnings` add `#[allow(clippy::useless_format)]` error: useless use of `format!` - --> tests/ui/format.rs:21:5 + --> tests/ui/format.rs:22:5 | LL | format!("{{}}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` - --> tests/ui/format.rs:22:5 + --> tests/ui/format.rs:24:5 | LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> tests/ui/format.rs:23:5 + --> tests/ui/format.rs:26:5 | LL | / format!( +LL | | LL | | r##"foo {{}} LL | | " bar"## LL | | ); @@ -35,67 +36,67 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> tests/ui/format.rs:28:13 + --> tests/ui/format.rs:32:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> tests/ui/format.rs:30:5 + --> tests/ui/format.rs:35:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> tests/ui/format.rs:38:5 + --> tests/ui/format.rs:44:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> tests/ui/format.rs:68:5 + --> tests/ui/format.rs:75:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> tests/ui/format.rs:70:5 + --> tests/ui/format.rs:78:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> tests/ui/format.rs:74:18 + --> tests/ui/format.rs:83:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> tests/ui/format.rs:78:22 + --> tests/ui/format.rs:88:22 | LL | let _s: String = format!("{}", &*v.join("\n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("\n")).to_string()` error: useless use of `format!` - --> tests/ui/format.rs:84:13 + --> tests/ui/format.rs:95:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> tests/ui/format.rs:86:13 + --> tests/ui/format.rs:98:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> tests/ui/format.rs:90:13 + --> tests/ui/format.rs:103:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> tests/ui/format.rs:92:13 + --> tests/ui/format.rs:106: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 20d1e3d90504..075450451b24 100644 --- a/tests/ui/format_args.fixed +++ b/tests/ui/format_args.fixed @@ -75,36 +75,58 @@ fn main() { let x_ref = &x; let _ = format!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args let _ = write!( stdout(), "error: something failed at {}", Location::caller() + //~^ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", Location::caller() + //~^ to_string_in_format_args ); print!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args println!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args eprint!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args eprintln!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args let _ = format_args!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert!(true, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert_eq!(0, 0, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args assert_ne!(0, 0, "error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args panic!("error: something failed at {}", Location::caller()); + //~^ to_string_in_format_args println!("{}", *X(1)); + //~^ to_string_in_format_args println!("{}", ***Y(&X(1))); + //~^ to_string_in_format_args println!("{}", Z(1)); + //~^ to_string_in_format_args println!("{}", **x); + //~^ to_string_in_format_args println!("{}", ***x_ref); + //~^ to_string_in_format_args // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{bar}", foo = "foo", bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", foo = "foo", bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo"); + //~^ to_string_in_format_args println!("{}", my_other_macro!()); + //~^ to_string_in_format_args // negative tests println!("error: something failed at {}", Somewhere.to_string()); @@ -117,7 +139,9 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{foo:?}", foo = "foo".to_string()); print!("{}", (Location::caller())); + //~^ to_string_in_format_args print!("{}", ((Location::caller()))); + //~^ to_string_in_format_args } fn issue8643(vendor_id: usize, product_id: usize, name: &str) { @@ -146,6 +170,7 @@ mod issue_8855 { let b = A {}; let x = format!("{} {}", a, b); + //~^ to_string_in_format_args dbg!(x); let x = format!("{:>6} {:>6}", a, b.to_string()); @@ -160,6 +185,7 @@ mod issue_9256 { fn print_substring(original: &str) { assert!(original.len() > 10); println!("{}", &original[..10]); + //~^ to_string_in_format_args } fn main() { diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs index 18ab223db78a..4d7a018732c7 100644 --- a/tests/ui/format_args.rs +++ b/tests/ui/format_args.rs @@ -75,36 +75,58 @@ fn main() { let x_ref = &x; let _ = format!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args let _ = write!( stdout(), "error: something failed at {}", Location::caller().to_string() + //~^ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", Location::caller().to_string() + //~^ to_string_in_format_args ); print!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args println!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args eprint!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args eprintln!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args let _ = format_args!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert!(true, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args panic!("error: something failed at {}", Location::caller().to_string()); + //~^ to_string_in_format_args println!("{}", X(1).to_string()); + //~^ to_string_in_format_args println!("{}", Y(&X(1)).to_string()); + //~^ to_string_in_format_args println!("{}", Z(1).to_string()); + //~^ to_string_in_format_args println!("{}", x.to_string()); + //~^ to_string_in_format_args println!("{}", x_ref.to_string()); + //~^ to_string_in_format_args // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); + //~^ to_string_in_format_args println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); + //~^ to_string_in_format_args println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); + //~^ to_string_in_format_args println!("{}", my_other_macro!().to_string()); + //~^ to_string_in_format_args // negative tests println!("error: something failed at {}", Somewhere.to_string()); @@ -117,7 +139,9 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/7903 println!("{foo}{foo:?}", foo = "foo".to_string()); print!("{}", (Location::caller().to_string())); + //~^ to_string_in_format_args print!("{}", ((Location::caller()).to_string())); + //~^ to_string_in_format_args } fn issue8643(vendor_id: usize, product_id: usize, name: &str) { @@ -146,6 +170,7 @@ mod issue_8855 { let b = A {}; let x = format!("{} {}", a, b.to_string()); + //~^ to_string_in_format_args dbg!(x); let x = format!("{:>6} {:>6}", a, b.to_string()); @@ -160,6 +185,7 @@ mod issue_9256 { fn print_substring(original: &str) { assert!(original.len() > 10); println!("{}", original[..10].to_string()); + //~^ to_string_in_format_args } fn main() { diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index 91a45e270081..68c3c9c322d9 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -8,151 +8,151 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_ = help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]` error: `to_string` applied to a type that implements `Display` in `write!` args - --> tests/ui/format_args.rs:81:27 + --> tests/ui/format_args.rs:82:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `writeln!` args - --> tests/ui/format_args.rs:86:27 + --> tests/ui/format_args.rs:88:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> tests/ui/format_args.rs:88:63 + --> tests/ui/format_args.rs:91: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 - --> tests/ui/format_args.rs:89:65 + --> tests/ui/format_args.rs:93: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 - --> tests/ui/format_args.rs:90:64 + --> tests/ui/format_args.rs:95: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 - --> tests/ui/format_args.rs:91:66 + --> tests/ui/format_args.rs:97: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 - --> tests/ui/format_args.rs:92:77 + --> tests/ui/format_args.rs:99: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 - --> tests/ui/format_args.rs:93:70 + --> tests/ui/format_args.rs:101: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 - --> tests/ui/format_args.rs:94:73 + --> tests/ui/format_args.rs:103: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 - --> tests/ui/format_args.rs:95:73 + --> tests/ui/format_args.rs:105: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 - --> tests/ui/format_args.rs:96:63 + --> tests/ui/format_args.rs:107: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 - --> tests/ui/format_args.rs:97:20 + --> tests/ui/format_args.rs:109: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 - --> tests/ui/format_args.rs:98:20 + --> tests/ui/format_args.rs:111: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 - --> tests/ui/format_args.rs:99:24 + --> tests/ui/format_args.rs:113:24 | LL | println!("{}", Z(1).to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> tests/ui/format_args.rs:100:20 + --> tests/ui/format_args.rs:115:20 | LL | println!("{}", x.to_string()); | ^^^^^^^^^^^^^ help: use this: `**x` error: `to_string` applied to a type that implements `Display` in `println!` args - --> tests/ui/format_args.rs:101:20 + --> tests/ui/format_args.rs:117: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 - --> tests/ui/format_args.rs:103:39 + --> tests/ui/format_args.rs:120: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 - --> tests/ui/format_args.rs:104:52 + --> tests/ui/format_args.rs:122: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 - --> tests/ui/format_args.rs:105:39 + --> tests/ui/format_args.rs:124: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 - --> tests/ui/format_args.rs:106:52 + --> tests/ui/format_args.rs:126: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 `println!` args - --> tests/ui/format_args.rs:107:37 + --> tests/ui/format_args.rs:128:37 | LL | println!("{}", my_other_macro!().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> tests/ui/format_args.rs:119:37 + --> tests/ui/format_args.rs:141:37 | LL | print!("{}", (Location::caller().to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> tests/ui/format_args.rs:120:39 + --> tests/ui/format_args.rs:143:39 | LL | print!("{}", ((Location::caller()).to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `format!` args - --> tests/ui/format_args.rs:148:38 + --> tests/ui/format_args.rs:172: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 - --> tests/ui/format_args.rs:162:24 + --> tests/ui/format_args.rs:187:24 | LL | println!("{}", original[..10].to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]` diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs index 7590de3751a8..adbdaca7313b 100644 --- a/tests/ui/format_args_unfixable.rs +++ b/tests/ui/format_args_unfixable.rs @@ -24,49 +24,67 @@ fn main() { let x = 'x'; println!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!("{}: {}", error, format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!("{{}}: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + println!("error: {}", format!("something failed at {} {0}", Location::caller())); - //~^ ERROR: `format!` in `println!` args + //~^ format_in_format_args + let _ = format!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `format!` args + //~^ format_in_format_args + let _ = write!( - //~^ ERROR: `format!` in `write!` args + //~^ format_in_format_args + stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); let _ = writeln!( - //~^ ERROR: `format!` in `writeln!` args + //~^ format_in_format_args + stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); print!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `print!` args + //~^ format_in_format_args + eprint!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `eprint!` args + //~^ format_in_format_args + eprintln!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `eprintln!` args + //~^ format_in_format_args + let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `format_args!` args + //~^ format_in_format_args + assert!(true, "error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `assert!` args + //~^ format_in_format_args + assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `assert_eq!` args + //~^ format_in_format_args + assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `assert_ne!` args + //~^ format_in_format_args + panic!("error: {}", format!("something failed at {}", Location::caller())); - //~^ ERROR: `format!` in `panic!` args + //~^ format_in_format_args + // negative tests println!("error: {}", format_args!("something failed at {}", Location::caller())); @@ -134,17 +152,24 @@ fn user_format() { let x = 'x'; usr_println!(true, "error: {}", format!("boom at {}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, "{}: {}", error, format!("boom at {}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, "{:?}: {}", error, format!("boom at {}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, "{{}}: {}", format!("boom at {}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, r#"error: "{}""#, format!("boom at {}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, "error: {}", format!(r#"boom at "{}""#, Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + usr_println!(true, "error: {}", format!("boom at {} {0}", Location::caller())); - //~^ ERROR: `format!` in `usr_println!` args + //~^ format_in_format_args + } diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index 1b4b683fd6c6..82af72229066 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -10,7 +10,7 @@ LL | println!("error: {}", format!("something failed at {}", Location::calle = help: to override `-D warnings` add `#[allow(clippy::format_in_format_args)]` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:28:5 + --> tests/ui/format_args_unfixable.rs:29:5 | LL | println!("{}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | println!("{}: {}", error, format!("something failed at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:30:5 + --> tests/ui/format_args_unfixable.rs:32:5 | LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | println!("{:?}: {}", error, format!("something failed at {}", Location: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:32:5 + --> tests/ui/format_args_unfixable.rs:35:5 | LL | println!("{{}}: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | println!("{{}}: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:34:5 + --> tests/ui/format_args_unfixable.rs:38:5 | LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | println!(r#"error: "{}""#, format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:36:5 + --> tests/ui/format_args_unfixable.rs:41:5 | LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | println!("error: {}", format!(r#"something failed at "{}""#, Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> tests/ui/format_args_unfixable.rs:38:5 + --> tests/ui/format_args_unfixable.rs:44:5 | LL | println!("error: {}", format!("something failed at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | println!("error: {}", format!("something failed at {} {0}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `format!` args - --> tests/ui/format_args_unfixable.rs:40:13 + --> tests/ui/format_args_unfixable.rs:47:13 | LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,11 +73,12 @@ LL | let _ = format!("error: {}", format!("something failed at {}", Location = help: or consider changing `format!` to `format_args!` error: `format!` in `write!` args - --> tests/ui/format_args_unfixable.rs:42:13 + --> tests/ui/format_args_unfixable.rs:50:13 | LL | let _ = write!( | _____________^ LL | | +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -88,11 +89,12 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `writeln!` args - --> tests/ui/format_args_unfixable.rs:48:13 + --> tests/ui/format_args_unfixable.rs:57:13 | LL | let _ = writeln!( | _____________^ LL | | +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -103,7 +105,7 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `print!` args - --> tests/ui/format_args_unfixable.rs:54:5 + --> tests/ui/format_args_unfixable.rs:64:5 | LL | print!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +114,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `eprint!` args - --> tests/ui/format_args_unfixable.rs:56:5 + --> tests/ui/format_args_unfixable.rs:67:5 | LL | eprint!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +123,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `eprintln!` args - --> tests/ui/format_args_unfixable.rs:58:5 + --> tests/ui/format_args_unfixable.rs:70:5 | LL | eprintln!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -130,7 +132,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call = help: or consider changing `format!` to `format_args!` error: `format!` in `format_args!` args - --> tests/ui/format_args_unfixable.rs:60:13 + --> tests/ui/format_args_unfixable.rs:73:13 | LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,7 +141,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc = help: or consider changing `format!` to `format_args!` error: `format!` in `assert!` args - --> tests/ui/format_args_unfixable.rs:62:5 + --> tests/ui/format_args_unfixable.rs:76:5 | LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,7 +150,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_eq!` args - --> tests/ui/format_args_unfixable.rs:64:5 + --> tests/ui/format_args_unfixable.rs:79:5 | LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +159,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 - --> tests/ui/format_args_unfixable.rs:66:5 + --> tests/ui/format_args_unfixable.rs:82:5 | LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +168,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 - --> tests/ui/format_args_unfixable.rs:68:5 + --> tests/ui/format_args_unfixable.rs:85:5 | LL | panic!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -175,7 +177,7 @@ LL | panic!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:136:5 + --> tests/ui/format_args_unfixable.rs:154:5 | LL | usr_println!(true, "error: {}", format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -184,7 +186,7 @@ LL | usr_println!(true, "error: {}", format!("boom at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:138:5 + --> tests/ui/format_args_unfixable.rs:157:5 | LL | usr_println!(true, "{}: {}", error, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +195,7 @@ LL | usr_println!(true, "{}: {}", error, format!("boom at {}", Location::cal = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:140:5 + --> tests/ui/format_args_unfixable.rs:160:5 | LL | usr_println!(true, "{:?}: {}", error, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -202,7 +204,7 @@ LL | usr_println!(true, "{:?}: {}", error, format!("boom at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:142:5 + --> tests/ui/format_args_unfixable.rs:163:5 | LL | usr_println!(true, "{{}}: {}", format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -211,7 +213,7 @@ LL | usr_println!(true, "{{}}: {}", format!("boom at {}", Location::caller() = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:144:5 + --> tests/ui/format_args_unfixable.rs:166:5 | LL | usr_println!(true, r#"error: "{}""#, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -220,7 +222,7 @@ LL | usr_println!(true, r#"error: "{}""#, format!("boom at {}", Location::ca = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:146:5 + --> tests/ui/format_args_unfixable.rs:169:5 | LL | usr_println!(true, "error: {}", format!(r#"boom at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +231,7 @@ LL | usr_println!(true, "error: {}", format!(r#"boom at "{}""#, Location::ca = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:148:5 + --> tests/ui/format_args_unfixable.rs:172:5 | LL | usr_println!(true, "error: {}", format!("boom at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_collect.rs b/tests/ui/format_collect.rs index 26ebdc6c0cb6..85dbd5692fef 100644 --- a/tests/ui/format_collect.rs +++ b/tests/ui/format_collect.rs @@ -3,13 +3,15 @@ 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 + //~^ format_collect + } #[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 + //~^ format_collect + } macro_rules! fmt { @@ -24,7 +26,8 @@ fn from_macro(bytes: &[u8]) -> String { fn with_block() -> String { (1..10) - //~^ ERROR: use of `format!` to build up a string from an iterator + //~^ format_collect + .map(|s| { let y = 1; format!("{s} {y}") diff --git a/tests/ui/format_collect.stderr b/tests/ui/format_collect.stderr index 863b457a7905..a87951efa543 100644 --- a/tests/ui/format_collect.stderr +++ b/tests/ui/format_collect.stderr @@ -19,42 +19,42 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() = help: to override `-D warnings` add `#[allow(clippy::format_collect)]` error: use of `format!` to build up a string from an iterator - --> tests/ui/format_collect.rs:11:5 + --> tests/ui/format_collect.rs:12:5 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: call `fold` instead - --> tests/ui/format_collect.rs:11:18 + --> tests/ui/format_collect.rs:12:18 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^ help: ... and use the `write!` macro here - --> tests/ui/format_collect.rs:11:32 + --> tests/ui/format_collect.rs:12: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 - --> tests/ui/format_collect.rs:26:5 + --> tests/ui/format_collect.rs:28:5 | LL | / (1..10) LL | | +LL | | LL | | .map(|s| { -LL | | let y = 1; -LL | | format!("{s} {y}") +... | LL | | }) LL | | .collect() | |__________________^ | help: call `fold` instead - --> tests/ui/format_collect.rs:28:10 + --> tests/ui/format_collect.rs:31:10 | LL | .map(|s| { | ^^^ help: ... and use the `write!` macro here - --> tests/ui/format_collect.rs:30:13 + --> tests/ui/format_collect.rs:33:13 | LL | format!("{s} {y}") | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_push_string.rs b/tests/ui/format_push_string.rs index 735ae3393289..c047118b5f50 100644 --- a/tests/ui/format_push_string.rs +++ b/tests/ui/format_push_string.rs @@ -3,9 +3,11 @@ fn main() { let mut string = String::new(); string += &format!("{:?}", 1234); - //~^ ERROR: `format!(..)` appended to existing `String` + //~^ format_push_string + string.push_str(&format!("{:?}", 5678)); - //~^ ERROR: `format!(..)` appended to existing `String` + //~^ format_push_string + } mod issue9493 { @@ -13,7 +15,8 @@ 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_push_string + format!("{byte:02X}") } else { format!("{byte:02x}") @@ -26,14 +29,16 @@ mod issue9493 { let mut s = String::new(); // if let s += &(if let Some(_a) = Some(1234) { - //~^ ERROR: `format!(..)` appended to existing `String` + //~^ format_push_string + format!("{}", 1234) } else { format!("{}", 1234) }); // match s += &(match Some(1234) { - //~^ ERROR: `format!(..)` appended to existing `String` + //~^ format_push_string + Some(_) => format!("{}", 1234), None => format!("{}", 1234), }); diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index a9520600f52a..a496371938e9 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -9,7 +9,7 @@ LL | string += &format!("{:?}", 1234); = help: to override `-D warnings` add `#[allow(clippy::format_push_string)]` error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:7:5 + --> tests/ui/format_push_string.rs:8:5 | LL | string.push_str(&format!("{:?}", 5678)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,10 +17,11 @@ LL | string.push_str(&format!("{:?}", 5678)); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:15:13 + --> tests/ui/format_push_string.rs:17:13 | LL | / hex += &(if upper { LL | | +LL | | LL | | format!("{byte:02X}") LL | | } else { LL | | format!("{byte:02x}") @@ -30,10 +31,11 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:28:9 + --> tests/ui/format_push_string.rs:31:9 | LL | / s += &(if let Some(_a) = Some(1234) { LL | | +LL | | LL | | format!("{}", 1234) LL | | } else { LL | | format!("{}", 1234) @@ -43,10 +45,11 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:35:9 + --> tests/ui/format_push_string.rs:39:9 | LL | / s += &(match Some(1234) { LL | | +LL | | LL | | Some(_) => format!("{}", 1234), LL | | None => format!("{}", 1234), LL | | }); diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 312fa2aa40ad..4e84dcf7d5b7 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -14,16 +14,19 @@ 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 `= -` + //~^ suspicious_assignment_formatting + + a =* &191; - //~^ ERROR: this looks like you are trying to use `.. *= ..`, but you really are doing - //~| NOTE: to remove this lint, use either `*=` or `= *` + //~^ suspicious_assignment_formatting + + 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 `= !` + //~^ suspicious_assignment_formatting + + // those are ok: a = -35; @@ -33,14 +36,16 @@ 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 + //~^ possible_missing_comma + + -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 + //~^ possible_missing_comma + + *4, -5, -6 ]; @@ -78,8 +83,9 @@ 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 + //~^ possible_missing_comma + + -4, ]; } diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index e823e6512b8d..972bd3a6a2e6 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -9,7 +9,7 @@ LL | a =- 35; = help: to override `-D warnings` add `#[allow(clippy::suspicious_assignment_formatting)]` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> tests/ui/formatting.rs:19:6 + --> tests/ui/formatting.rs:20:6 | LL | a =* &191; | ^^^^ @@ -17,7 +17,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 `.. = (! ..)` - --> tests/ui/formatting.rs:24:6 + --> tests/ui/formatting.rs:26:6 | LL | b =! false; | ^^^^ @@ -25,7 +25,7 @@ LL | b =! false; = note: to remove this lint, use either `!=` or `= !` error: possibly missing a comma here - --> tests/ui/formatting.rs:35:19 + --> tests/ui/formatting.rs:38:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -35,7 +35,7 @@ LL | -1, -2, -3 // <= no comma here = help: to override `-D warnings` add `#[allow(clippy::possible_missing_comma)]` error: possibly missing a comma here - --> tests/ui/formatting.rs:41:19 + --> tests/ui/formatting.rs:45:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -43,7 +43,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 - --> tests/ui/formatting.rs:80:11 + --> tests/ui/formatting.rs:85:11 | LL | -1 | ^ diff --git a/tests/ui/four_forward_slashes.fixed b/tests/ui/four_forward_slashes.fixed index 6d31c543d727..6f387b67ccbf 100644 --- a/tests/ui/four_forward_slashes.fixed +++ b/tests/ui/four_forward_slashes.fixed @@ -1,4 +1,3 @@ - //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] @@ -10,14 +9,17 @@ extern crate proc_macros; /// whoops +//~^ four_forward_slashes fn a() {} /// whoops +//~^ four_forward_slashes #[allow(dead_code)] fn b() {} /// whoops /// two borked comments! +//~^^ four_forward_slashes #[track_caller] fn c() {} @@ -25,10 +27,12 @@ fn d() {} #[test] /// between attributes +//~^ four_forward_slashes #[allow(dead_code)] fn g() {} /// not very start of contents + //~^ four_forward_slashes fn h() {} fn i() { diff --git a/tests/ui/four_forward_slashes.rs b/tests/ui/four_forward_slashes.rs index 458b8de53e15..fae07e7d6094 100644 --- a/tests/ui/four_forward_slashes.rs +++ b/tests/ui/four_forward_slashes.rs @@ -1,4 +1,3 @@ - //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] @@ -10,14 +9,17 @@ extern crate proc_macros; //// whoops +//~^ four_forward_slashes fn a() {} //// whoops +//~^ four_forward_slashes #[allow(dead_code)] fn b() {} //// whoops //// two borked comments! +//~^^ four_forward_slashes #[track_caller] fn c() {} @@ -25,10 +27,12 @@ fn d() {} #[test] //// between attributes +//~^ four_forward_slashes #[allow(dead_code)] fn g() {} //// not very start of contents + //~^ four_forward_slashes fn h() {} fn i() { diff --git a/tests/ui/four_forward_slashes.stderr b/tests/ui/four_forward_slashes.stderr index 3606a2227a00..4ac5d13c4fa8 100644 --- a/tests/ui/four_forward_slashes.stderr +++ b/tests/ui/four_forward_slashes.stderr @@ -1,7 +1,8 @@ error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> tests/ui/four_forward_slashes.rs:12:1 + --> tests/ui/four_forward_slashes.rs:11:1 | LL | / //// whoops +LL | | LL | | fn a() {} | |_^ | @@ -16,6 +17,7 @@ error: this item has comments with 4 forward slashes (`////`). These look like d --> tests/ui/four_forward_slashes.rs:15:1 | LL | / //// whoops +LL | | LL | | #[allow(dead_code)] LL | | fn b() {} | |_^ @@ -26,10 +28,11 @@ LL + /// whoops | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> tests/ui/four_forward_slashes.rs:19:1 + --> tests/ui/four_forward_slashes.rs:20:1 | LL | / //// whoops LL | | //// two borked comments! +LL | | LL | | #[track_caller] LL | | fn c() {} | |_^ @@ -41,9 +44,10 @@ LL ~ /// two borked comments! | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> tests/ui/four_forward_slashes.rs:27:1 + --> tests/ui/four_forward_slashes.rs:29:1 | LL | / //// between attributes +LL | | LL | | #[allow(dead_code)] LL | | fn g() {} | |_^ @@ -54,9 +58,10 @@ LL + /// between attributes | error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't - --> tests/ui/four_forward_slashes.rs:31:1 + --> tests/ui/four_forward_slashes.rs:34:1 | LL | / //// not very start of contents +LL | | LL | | fn h() {} | |_^ | diff --git a/tests/ui/four_forward_slashes_first_line.fixed b/tests/ui/four_forward_slashes_first_line.fixed index 5ef40015d88b..34604a6461b9 100644 --- a/tests/ui/four_forward_slashes_first_line.fixed +++ b/tests/ui/four_forward_slashes_first_line.fixed @@ -1,4 +1,5 @@ /// borked doc comment on the first line. doesn't combust! +//~^ four_forward_slashes fn a() {} // This test's entire purpose is to make sure we don't panic if the comment with four slashes diff --git a/tests/ui/four_forward_slashes_first_line.rs b/tests/ui/four_forward_slashes_first_line.rs index 9c835e745f65..150e9ba2711c 100644 --- a/tests/ui/four_forward_slashes_first_line.rs +++ b/tests/ui/four_forward_slashes_first_line.rs @@ -1,4 +1,5 @@ //// borked doc comment on the first line. doesn't combust! +//~^ four_forward_slashes fn a() {} // This test's entire purpose is to make sure we don't panic if the comment with four slashes diff --git a/tests/ui/four_forward_slashes_first_line.stderr b/tests/ui/four_forward_slashes_first_line.stderr index 81732346412a..3cb95797319f 100644 --- a/tests/ui/four_forward_slashes_first_line.stderr +++ b/tests/ui/four_forward_slashes_first_line.stderr @@ -2,6 +2,7 @@ error: this item has comments with 4 forward slashes (`////`). These look like d --> tests/ui/four_forward_slashes_first_line.rs:1:1 | LL | / //// borked doc comment on the first line. doesn't combust! +LL | | LL | | fn a() {} | |_^ | diff --git a/tests/ui/from_iter_instead_of_collect.fixed b/tests/ui/from_iter_instead_of_collect.fixed index 67da45a348f9..8618004efb89 100644 --- a/tests/ui/from_iter_instead_of_collect.fixed +++ b/tests/ui/from_iter_instead_of_collect.fixed @@ -15,46 +15,61 @@ impl FromIterator for Foo { impl<'a> FromIterator<&'a bool> for Foo { fn from_iter>(iter: T) -> Self { iter.into_iter().copied().collect::() + //~^ from_iter_instead_of_collect } } fn main() { let iter_expr = std::iter::repeat(5).take(5); let _ = iter_expr.collect::>(); + //~^ from_iter_instead_of_collect let _ = vec![5, 5, 5, 5].iter().enumerate().collect::>(); + //~^ from_iter_instead_of_collect Vec::from_iter(vec![42u32]); let a = vec![0, 1, 2]; assert_eq!(a, (0..3).collect::>()); + //~^ from_iter_instead_of_collect assert_eq!(a, (0..3).collect::>()); + //~^ from_iter_instead_of_collect let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); { use std::collections; let mut b = (0..3).collect::>(); + //~^ from_iter_instead_of_collect b.push_back(4); } let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]; let bm = values.iter().cloned().collect::>(); + //~^ from_iter_instead_of_collect let mut bar = bm.range(0..2).collect::>(); + //~^ from_iter_instead_of_collect bar.insert(&4, &'e'); let mut bts = (0..3).collect::>(); + //~^ from_iter_instead_of_collect bts.insert(2); { use std::collections; let _ = (0..3).collect::>(); + //~^ from_iter_instead_of_collect let _ = (0..3).collect::>(); + //~^ from_iter_instead_of_collect } for _i in [1, 2, 3].iter().collect::>() {} + //~^ from_iter_instead_of_collect for _i in [1, 2, 3].iter().collect::>() {} + //~^ from_iter_instead_of_collect } diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs index 423a7454bed7..c46397e8ff56 100644 --- a/tests/ui/from_iter_instead_of_collect.rs +++ b/tests/ui/from_iter_instead_of_collect.rs @@ -15,46 +15,61 @@ impl FromIterator for Foo { impl<'a> FromIterator<&'a bool> for Foo { fn from_iter>(iter: T) -> Self { >::from_iter(iter.into_iter().copied()) + //~^ from_iter_instead_of_collect } } fn main() { let iter_expr = std::iter::repeat(5).take(5); let _ = Vec::from_iter(iter_expr); + //~^ from_iter_instead_of_collect let _ = HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); + //~^ from_iter_instead_of_collect Vec::from_iter(vec![42u32]); let a = vec![0, 1, 2]; assert_eq!(a, Vec::from_iter(0..3)); + //~^ from_iter_instead_of_collect assert_eq!(a, Vec::::from_iter(0..3)); + //~^ from_iter_instead_of_collect let mut b = VecDeque::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); let mut b = VecDeque::::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); { use std::collections; let mut b = collections::VecDeque::::from_iter(0..3); + //~^ from_iter_instead_of_collect b.push_back(4); } let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]; let bm = BTreeMap::from_iter(values.iter().cloned()); + //~^ from_iter_instead_of_collect let mut bar = BTreeMap::from_iter(bm.range(0..2)); + //~^ from_iter_instead_of_collect bar.insert(&4, &'e'); let mut bts = BTreeSet::from_iter(0..3); + //~^ from_iter_instead_of_collect bts.insert(2); { use std::collections; let _ = collections::BTreeSet::from_iter(0..3); + //~^ from_iter_instead_of_collect let _ = collections::BTreeSet::::from_iter(0..3); + //~^ from_iter_instead_of_collect } for _i in Vec::from_iter([1, 2, 3].iter()) {} + //~^ from_iter_instead_of_collect for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {} + //~^ from_iter_instead_of_collect } diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr index 0824a526b793..b46d97af152f 100644 --- a/tests/ui/from_iter_instead_of_collect.stderr +++ b/tests/ui/from_iter_instead_of_collect.stderr @@ -8,85 +8,85 @@ LL | >::from_iter(iter.into_iter().copied()) = help: to override `-D warnings` add `#[allow(clippy::from_iter_instead_of_collect)]` error: usage of `FromIterator::from_iter` - --> tests/ui/from_iter_instead_of_collect.rs:23:13 + --> tests/ui/from_iter_instead_of_collect.rs:24:13 | LL | let _ = Vec::from_iter(iter_expr); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect::>()` error: usage of `FromIterator::from_iter` - --> tests/ui/from_iter_instead_of_collect.rs:25:13 + --> tests/ui/from_iter_instead_of_collect.rs:27: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` - --> tests/ui/from_iter_instead_of_collect.rs:30:19 + --> tests/ui/from_iter_instead_of_collect.rs:33: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` - --> tests/ui/from_iter_instead_of_collect.rs:31:19 + --> tests/ui/from_iter_instead_of_collect.rs:35: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` - --> tests/ui/from_iter_instead_of_collect.rs:33:17 + --> tests/ui/from_iter_instead_of_collect.rs:38: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` - --> tests/ui/from_iter_instead_of_collect.rs:36:17 + --> tests/ui/from_iter_instead_of_collect.rs:42: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` - --> tests/ui/from_iter_instead_of_collect.rs:41:21 + --> tests/ui/from_iter_instead_of_collect.rs:48: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` - --> tests/ui/from_iter_instead_of_collect.rs:46:14 + --> tests/ui/from_iter_instead_of_collect.rs:54: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` - --> tests/ui/from_iter_instead_of_collect.rs:47:19 + --> tests/ui/from_iter_instead_of_collect.rs:56: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` - --> tests/ui/from_iter_instead_of_collect.rs:50:19 + --> tests/ui/from_iter_instead_of_collect.rs:60: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` - --> tests/ui/from_iter_instead_of_collect.rs:54:17 + --> tests/ui/from_iter_instead_of_collect.rs:65: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` - --> tests/ui/from_iter_instead_of_collect.rs:55:17 + --> tests/ui/from_iter_instead_of_collect.rs:67: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` - --> tests/ui/from_iter_instead_of_collect.rs:58:15 + --> tests/ui/from_iter_instead_of_collect.rs:71: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` - --> tests/ui/from_iter_instead_of_collect.rs:59:15 + --> tests/ui/from_iter_instead_of_collect.rs:73: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 a33c1ea5738b..85befb87fe5b 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -7,6 +7,7 @@ struct StringWrapper(String); impl From for StringWrapper { +//~^ from_over_into fn from(val: String) -> Self { StringWrapper(val) } @@ -15,6 +16,7 @@ impl From for StringWrapper { struct SelfType(String); impl From for SelfType { +//~^ from_over_into fn from(val: String) -> Self { SelfType(String::new()) } @@ -30,6 +32,7 @@ impl X { struct SelfKeywords; impl From for SelfKeywords { +//~^ from_over_into fn from(val: X) -> Self { let _ = X; let _ = X::FOO; @@ -42,6 +45,7 @@ impl From for SelfKeywords { struct ExplicitPaths(bool); impl core::convert::From for bool { +//~^ from_over_into fn from(mut val: crate::ExplicitPaths) -> Self { let in_closure = || val.0; @@ -62,6 +66,7 @@ impl From for A { struct PathInExpansion; impl From for String { +//~^ from_over_into fn from(val: PathInExpansion) -> Self { // non self/Self paths in expansions are fine panic!() @@ -84,6 +89,7 @@ fn msrv_1_41() { struct FromOverInto(Vec); impl From> for FromOverInto { + //~^ from_over_into fn from(val: Vec) -> Self { FromOverInto(val) } @@ -94,6 +100,7 @@ fn issue_12138() { struct Hello; impl From for () { + //~^ from_over_into fn from(val: Hello) {} } } diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index 6cd811ae401e..d4bdad56473a 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -7,6 +7,7 @@ struct StringWrapper(String); impl Into for String { +//~^ from_over_into fn into(self) -> StringWrapper { StringWrapper(self) } @@ -15,6 +16,7 @@ impl Into for String { struct SelfType(String); impl Into for String { +//~^ from_over_into fn into(self) -> SelfType { SelfType(Self::new()) } @@ -30,6 +32,7 @@ impl X { struct SelfKeywords; impl Into for X { +//~^ from_over_into fn into(self) -> SelfKeywords { let _ = Self; let _ = Self::FOO; @@ -42,6 +45,7 @@ impl Into for X { struct ExplicitPaths(bool); impl core::convert::Into for crate::ExplicitPaths { +//~^ from_over_into fn into(mut self) -> bool { let in_closure = || self.0; @@ -62,6 +66,7 @@ impl From for A { struct PathInExpansion; impl Into for PathInExpansion { +//~^ from_over_into fn into(self) -> String { // non self/Self paths in expansions are fine panic!() @@ -84,6 +89,7 @@ fn msrv_1_41() { struct FromOverInto(Vec); impl Into> for Vec { + //~^ from_over_into fn into(self) -> FromOverInto { FromOverInto(self) } @@ -94,6 +100,7 @@ fn issue_12138() { struct Hello; impl Into<()> for Hello { + //~^ from_over_into fn into(self) {} } } diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index f913ae0bb506..a564bccbaf71 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -9,12 +9,13 @@ LL | impl Into for String { help: replace the `Into` implementation with `From` | LL ~ impl From for StringWrapper { +LL | LL ~ fn from(val: String) -> Self { LL ~ StringWrapper(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> tests/ui/from_over_into.rs:17:1 + --> tests/ui/from_over_into.rs:18:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,12 +23,13 @@ LL | impl Into for String { help: replace the `Into` implementation with `From` | LL ~ impl From for SelfType { +LL | LL ~ fn from(val: String) -> Self { LL ~ SelfType(String::new()) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> tests/ui/from_over_into.rs:32:1 + --> tests/ui/from_over_into.rs:34:1 | LL | impl Into for X { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,6 +37,7 @@ LL | impl Into for X { help: replace the `Into` implementation with `From` | LL ~ impl From for SelfKeywords { +LL | LL ~ fn from(val: X) -> Self { LL ~ let _ = X; LL ~ let _ = X::FOO; @@ -42,7 +45,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 - --> tests/ui/from_over_into.rs:44:1 + --> tests/ui/from_over_into.rs:47:1 | LL | impl core::convert::Into for crate::ExplicitPaths { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,6 +55,7 @@ LL | impl core::convert::Into for crate::ExplicitPaths { help: replace the `Into` implementation with `From` | LL ~ impl core::convert::From for bool { +LL | LL ~ fn from(mut val: crate::ExplicitPaths) -> Self { LL ~ let in_closure = || val.0; LL | @@ -60,7 +64,7 @@ LL ~ val.0 | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> tests/ui/from_over_into.rs:64:1 + --> tests/ui/from_over_into.rs:68:1 | LL | impl Into for PathInExpansion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,11 +74,12 @@ LL | impl Into for PathInExpansion { help: replace the `Into` implementation with `From` | LL ~ impl From for String { +LL | 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 - --> tests/ui/from_over_into.rs:86:5 + --> tests/ui/from_over_into.rs:91:5 | LL | impl Into> for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,12 +87,13 @@ LL | impl Into> for Vec { help: replace the `Into` implementation with `From>` | LL ~ impl From> for FromOverInto { +LL | LL ~ fn from(val: Vec) -> Self { LL ~ FromOverInto(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> tests/ui/from_over_into.rs:96:5 + --> tests/ui/from_over_into.rs:102:5 | LL | impl Into<()> for Hello { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,6 +103,7 @@ LL | impl Into<()> for Hello { help: replace the `Into` implementation with `From` | LL ~ impl From for () { +LL | LL ~ fn from(val: Hello) {} | diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index 0c1f39f93fd3..23aab9b52e1b 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -9,7 +9,8 @@ macro_rules! in_macro { } impl Into for String { - //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free +//~^ from_over_into + fn into(self) -> InMacro { InMacro(in_macro!()) } @@ -18,7 +19,8 @@ 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 +//~^ from_over_into + fn into(self) -> WeirdUpperSelf { let _ = Self::default(); WeirdUpperSelf @@ -28,7 +30,8 @@ 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 +//~^ from_over_into + fn into(self) -> u8 { let val = 1; val + 1 @@ -40,7 +43,8 @@ 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 +//~^ from_over_into + 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 1776b86e40dd..0e9264a153bb 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -9,7 +9,7 @@ LL | impl Into for String { = help: to override `-D warnings` add `#[allow(clippy::from_over_into)]` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> tests/ui/from_over_into_unfixable.rs:20:1 + --> tests/ui/from_over_into_unfixable.rs:21:1 | LL | impl Into for &'static [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/from_over_into_unfixable.rs:30:1 + --> tests/ui/from_over_into_unfixable.rs:32:1 | LL | impl Into for ContainsVal { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,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 - --> tests/ui/from_over_into_unfixable.rs:42:1 + --> tests/ui/from_over_into_unfixable.rs:45: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 81472070eb4c..840508ad340d 100644 --- a/tests/ui/from_raw_with_void_ptr.rs +++ b/tests/ui/from_raw_with_void_ptr.rs @@ -9,7 +9,8 @@ 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 + //~^ from_raw_with_void_ptr + // shouldn't be linted let _ = unsafe { Box::from_raw(ptr as *mut usize) }; @@ -21,20 +22,24 @@ 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 + //~^ from_raw_with_void_ptr + // 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 + //~^ from_raw_with_void_ptr + // 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 + //~^ from_raw_with_void_ptr + // 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 + //~^ from_raw_with_void_ptr + } diff --git a/tests/ui/from_raw_with_void_ptr.stderr b/tests/ui/from_raw_with_void_ptr.stderr index e5bcb783d18b..ab55cfd48a5b 100644 --- a/tests/ui/from_raw_with_void_ptr.stderr +++ b/tests/ui/from_raw_with_void_ptr.stderr @@ -13,49 +13,49 @@ LL | let _ = unsafe { Box::from_raw(ptr) }; = help: to override `-D warnings` add `#[allow(clippy::from_raw_with_void_ptr)]` error: creating a `Rc` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:23:22 + --> tests/ui/from_raw_with_void_ptr.rs:24:22 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> tests/ui/from_raw_with_void_ptr.rs:23:35 + --> tests/ui/from_raw_with_void_ptr.rs:24:35 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^ error: creating a `Arc` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:28:22 + --> tests/ui/from_raw_with_void_ptr.rs:30:22 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> tests/ui/from_raw_with_void_ptr.rs:28:36 + --> tests/ui/from_raw_with_void_ptr.rs:30:36 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:33:22 + --> tests/ui/from_raw_with_void_ptr.rs:36:22 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> tests/ui/from_raw_with_void_ptr.rs:33:46 + --> tests/ui/from_raw_with_void_ptr.rs:36:46 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:38:22 + --> tests/ui/from_raw_with_void_ptr.rs:42:22 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> tests/ui/from_raw_with_void_ptr.rs:38:48 + --> tests/ui/from_raw_with_void_ptr.rs:42: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 6c582190b442..e9f4de518bbc 100644 --- a/tests/ui/from_str_radix_10.fixed +++ b/tests/ui/from_str_radix_10.fixed @@ -26,26 +26,34 @@ 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` + //~^ from_str_radix_10 + + "24".parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + "100".parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + "7".parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + ("10".to_owned() + "5").parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + (Test + Test).parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + let string = "300"; string.parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + let stringier = "400".to_string(); stringier.parse::()?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + // 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 0df6a0a202ae..9ebead7f75ba 100644 --- a/tests/ui/from_str_radix_10.rs +++ b/tests/ui/from_str_radix_10.rs @@ -26,26 +26,34 @@ 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` + //~^ from_str_radix_10 + + i64::from_str_radix("24", 10)?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + isize::from_str_radix("100", 10)?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + u8::from_str_radix("7", 10)?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + 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` + //~^ from_str_radix_10 + i128::from_str_radix(Test + Test, 10)?; - //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~^ from_str_radix_10 + 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` + //~^ from_str_radix_10 + 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` + //~^ from_str_radix_10 + // 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 4aa84eca2612..7f0a12a03f3c 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -8,43 +8,43 @@ LL | u32::from_str_radix("30", 10)?; = help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> tests/ui/from_str_radix_10.rs:31:5 + --> tests/ui/from_str_radix_10.rs:32: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` - --> tests/ui/from_str_radix_10.rs:33:5 + --> tests/ui/from_str_radix_10.rs:35: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` - --> tests/ui/from_str_radix_10.rs:35:5 + --> tests/ui/from_str_radix_10.rs:38: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` - --> tests/ui/from_str_radix_10.rs:37:5 + --> tests/ui/from_str_radix_10.rs:41: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` - --> tests/ui/from_str_radix_10.rs:39:5 + --> tests/ui/from_str_radix_10.rs:44: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` - --> tests/ui/from_str_radix_10.rs:43:5 + --> tests/ui/from_str_radix_10.rs:49: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` - --> tests/ui/from_str_radix_10.rs:47:5 + --> tests/ui/from_str_radix_10.rs:54: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 0aef60959593..9114dd96ce4d 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -6,12 +6,14 @@ 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` +//~^ too_many_arguments + + #[rustfmt::skip] fn bad_multiline( -//~^ ERROR: this function has too many arguments (8/7) +//~^ too_many_arguments + one: u32, two: u32, three: &str, @@ -46,7 +48,8 @@ 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) + //~^ too_many_arguments + fn ptr(p: *const u8); } @@ -56,7 +59,8 @@ 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) + //~^ too_many_arguments + } // ok, we don’t want to warn implementations @@ -66,12 +70,15 @@ 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` + //~^ not_unsafe_ptr_arg_deref + + println!("{:?}", unsafe { p.as_ref() }); - //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~^ not_unsafe_ptr_arg_deref + unsafe { std::ptr::read(p) }; - //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~^ not_unsafe_ptr_arg_deref + } } @@ -83,22 +90,28 @@ 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 + //~^ not_unsafe_ptr_arg_deref + println!("{:?}", unsafe { p.as_ref() }); - //~^ ERROR: this public function might dereference a raw pointer but is not marked `un + //~^ not_unsafe_ptr_arg_deref + unsafe { std::ptr::read(p) }; - //~^ ERROR: this public function might dereference a raw pointer but is not marked `un + //~^ not_unsafe_ptr_arg_deref + } 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 + //~^ not_unsafe_ptr_arg_deref + println!("{:?}", unsafe { p.as_ref() }); - //~^ ERROR: this public function might dereference a raw pointer but is not marked `un + //~^ not_unsafe_ptr_arg_deref + unsafe { std::ptr::read(p) }; - //~^ ERROR: this public function might dereference a raw pointer but is not marked `un + //~^ not_unsafe_ptr_arg_deref + } impl Bar { @@ -108,11 +121,14 @@ 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 + //~^ not_unsafe_ptr_arg_deref + println!("{:?}", unsafe { p.as_ref() }); - //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~^ not_unsafe_ptr_arg_deref + unsafe { std::ptr::read(p) }; - //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~^ not_unsafe_ptr_arg_deref + } pub fn public_ok(self, p: *const u8) { diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 8fdceb8d8cd0..4e3cf2edb085 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -8,31 +8,31 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` error: this function has too many arguments (8/7) - --> tests/ui/functions.rs:13:1 + --> tests/ui/functions.rs:14:1 | LL | / fn bad_multiline( LL | | +LL | | LL | | one: u32, -LL | | two: u32, ... | LL | | eight: () LL | | ) { | |_^ error: this function has too many arguments (8/7) - --> tests/ui/functions.rs:48:5 + --> tests/ui/functions.rs:50: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) - --> tests/ui/functions.rs:58:5 + --> tests/ui/functions.rs:61: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` - --> tests/ui/functions.rs:68:34 + --> tests/ui/functions.rs:72:34 | LL | println!("{}", unsafe { *p }); | ^ @@ -41,67 +41,67 @@ LL | println!("{}", unsafe { *p }); = help: to override `-D warnings` add `#[allow(clippy::not_unsafe_ptr_arg_deref)]` error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:71:35 + --> tests/ui/functions.rs:76:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:73:33 + --> tests/ui/functions.rs:79:33 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:85:30 + --> tests/ui/functions.rs:92:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:87:31 + --> tests/ui/functions.rs:95:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:89:29 + --> tests/ui/functions.rs:98:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:96:30 + --> tests/ui/functions.rs:106:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:98:31 + --> tests/ui/functions.rs:109:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:100:29 + --> tests/ui/functions.rs:112:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:110:34 + --> tests/ui/functions.rs:123:34 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:112:35 + --> tests/ui/functions.rs:126:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:114:33 + --> tests/ui/functions.rs:129:33 | LL | unsafe { std::ptr::read(p) }; | ^ diff --git a/tests/ui/functions_maxlines.rs b/tests/ui/functions_maxlines.rs index a3496f56d4a6..3c32e88c6880 100644 --- a/tests/ui/functions_maxlines.rs +++ b/tests/ui/functions_maxlines.rs @@ -56,8 +56,9 @@ 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` +//~^ too_many_lines + + 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 f42a2b2a22a2..82d5fc8d5859 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -2,9 +2,6 @@ error: this function has too many lines (102/100) --> tests/ui/functions_maxlines.rs:58:1 | LL | / fn bad_lines() { -LL | | -LL | | -LL | | println!("Dont get confused by braces: {{}}"); ... | LL | | println!("This is bad."); LL | | } diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs index 626ee6de9e4f..1df0b1334827 100644 --- a/tests/ui/future_not_send.rs +++ b/tests/ui/future_not_send.rs @@ -6,12 +6,14 @@ 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 +//~^ future_not_send + async { true }.await } pub async fn public_future(rc: Rc<[u8]>) { - //~^ ERROR: future cannot be sent between threads safely +//~^ future_not_send + async { true }.await; } @@ -20,12 +22,14 @@ 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 +//~^ future_not_send + true } pub async fn public_future2(rc: Rc<[u8]>) {} -//~^ ERROR: future cannot be sent between threads safely +//~^ future_not_send + pub async fn public_send2(arc: Arc<[u8]>) -> bool { false @@ -37,13 +41,15 @@ struct Dummy { impl Dummy { async fn private_future(&self) -> usize { - //~^ ERROR: future cannot be sent between threads safely + //~^ future_not_send + async { true }.await; self.rc.len() } pub async fn public_future(&self) { - //~^ ERROR: future cannot be sent between threads safely + //~^ future_not_send + self.private_future().await; } @@ -54,7 +60,8 @@ impl Dummy { } async fn generic_future(t: T) -> T -//~^ ERROR: future cannot be sent between threads safely +//~^ future_not_send + where T: Send, { @@ -76,7 +83,8 @@ async fn maybe_send_generic_future2 Fut, Fut: Future>(f: F) { } async fn generic_future_always_unsend(_: Rc) { - //~^ ERROR: future cannot be sent between threads safely +//~^ future_not_send + async { true }.await; } diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 3807c7470136..4dcff55942a6 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -5,11 +5,11 @@ 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 - --> tests/ui/future_not_send.rs:10:20 + --> tests/ui/future_not_send.rs:11: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 = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` @@ -23,93 +23,94 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:13:1 + --> tests/ui/future_not_send.rs:14:1 | 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 - --> tests/ui/future_not_send.rs:15:20 + --> tests/ui/future_not_send.rs:17: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 = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:22:1 + --> tests/ui/future_not_send.rs:24:1 | 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` - --> tests/ui/future_not_send.rs:22:26 + --> tests/ui/future_not_send.rs:24: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` - --> tests/ui/future_not_send.rs:22:40 + --> tests/ui/future_not_send.rs:24: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 - --> tests/ui/future_not_send.rs:27:1 + --> tests/ui/future_not_send.rs:30:1 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future2` is not `Send` | note: captured value is not `Send` - --> tests/ui/future_not_send.rs:27:29 + --> tests/ui/future_not_send.rs:30: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 - --> tests/ui/future_not_send.rs:39:5 + --> tests/ui/future_not_send.rs:43:5 | 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 - --> tests/ui/future_not_send.rs:41:24 + --> tests/ui/future_not_send.rs:46: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 = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:45:5 + --> tests/ui/future_not_send.rs:50:5 | LL | pub async fn public_future(&self) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send` | note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` - --> tests/ui/future_not_send.rs:45:32 + --> tests/ui/future_not_send.rs:50:32 | LL | pub async fn public_future(&self) { | ^^^^^ has type `&Dummy` which is not `Send`, because `Dummy` is not `Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:56:1 + --> tests/ui/future_not_send.rs:62:1 | LL | / async fn generic_future(t: T) -> T LL | | +LL | | LL | | where LL | | T: Send, | |____________^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> tests/ui/future_not_send.rs:62:20 + --> tests/ui/future_not_send.rs:69:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` @@ -118,17 +119,17 @@ LL | async { true }.await; = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:78:1 + --> tests/ui/future_not_send.rs:85:1 | LL | async fn generic_future_always_unsend(_: Rc) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `generic_future_always_unsend` is not `Send` | note: future is not `Send` as this value is used across an await - --> tests/ui/future_not_send.rs:80:20 + --> tests/ui/future_not_send.rs:88:20 | LL | async fn generic_future_always_unsend(_: Rc) { | - has type `std::rc::Rc` which is not `Send` -LL | +... LL | async { true }.await; | ^^^^^ await occurs here, with `_` maybe used later = note: `std::rc::Rc` doesn't implement `std::marker::Send` diff --git a/tests/ui/get_first.fixed b/tests/ui/get_first.fixed index 710ebab1ef2d..090fe48096ae 100644 --- a/tests/ui/get_first.fixed +++ b/tests/ui/get_first.fixed @@ -15,25 +15,29 @@ impl Bar { fn main() { let x = vec![2, 3, 5]; let _ = x.first(); - //~^ ERROR: accessing first element with `x.get(0)` + //~^ get_first + let _ = x.get(1); let _ = x[0]; let y = [2, 3, 5]; let _ = y.first(); - //~^ ERROR: accessing first element with `y.get(0)` + //~^ get_first + let _ = y.get(1); let _ = y[0]; let z = &[2, 3, 5]; let _ = z.first(); - //~^ ERROR: accessing first element with `z.get(0)` + //~^ get_first + let _ = z.get(1); let _ = z[0]; let vecdeque: VecDeque<_> = x.iter().cloned().collect(); let _ = vecdeque.front(); - //~^ ERROR: accessing first element with `vecdeque.get(0)` + //~^ get_first + let _ = vecdeque.get(1); let hashmap: HashMap = HashMap::from_iter(vec![(0, 'a'), (1, 'b')]); @@ -46,5 +50,6 @@ fn main() { let non_primitives = [vec![1, 2], vec![3, 4]]; let _ = non_primitives.first(); - //~^ ERROR: accessing first element with `non_primitives.get(0)` + //~^ get_first + } diff --git a/tests/ui/get_first.rs b/tests/ui/get_first.rs index ad2ba6ce2c3b..c85d5aa89ca2 100644 --- a/tests/ui/get_first.rs +++ b/tests/ui/get_first.rs @@ -15,25 +15,29 @@ impl Bar { fn main() { let x = vec![2, 3, 5]; let _ = x.get(0); - //~^ ERROR: accessing first element with `x.get(0)` + //~^ get_first + let _ = x.get(1); let _ = x[0]; let y = [2, 3, 5]; let _ = y.get(0); - //~^ ERROR: accessing first element with `y.get(0)` + //~^ get_first + let _ = y.get(1); let _ = y[0]; let z = &[2, 3, 5]; let _ = z.get(0); - //~^ ERROR: accessing first element with `z.get(0)` + //~^ get_first + let _ = z.get(1); let _ = z[0]; let vecdeque: VecDeque<_> = x.iter().cloned().collect(); let _ = vecdeque.get(0); - //~^ ERROR: accessing first element with `vecdeque.get(0)` + //~^ get_first + let _ = vecdeque.get(1); let hashmap: HashMap = HashMap::from_iter(vec![(0, 'a'), (1, 'b')]); @@ -46,5 +50,6 @@ fn main() { let non_primitives = [vec![1, 2], vec![3, 4]]; let _ = non_primitives.get(0); - //~^ ERROR: accessing first element with `non_primitives.get(0)` + //~^ get_first + } diff --git a/tests/ui/get_first.stderr b/tests/ui/get_first.stderr index 155d341b5a77..4e19ebbc7589 100644 --- a/tests/ui/get_first.stderr +++ b/tests/ui/get_first.stderr @@ -8,25 +8,25 @@ LL | let _ = x.get(0); = help: to override `-D warnings` add `#[allow(clippy::get_first)]` error: accessing first element with `y.get(0)` - --> tests/ui/get_first.rs:23:13 + --> tests/ui/get_first.rs:24:13 | LL | let _ = y.get(0); | ^^^^^^^^ help: try: `y.first()` error: accessing first element with `z.get(0)` - --> tests/ui/get_first.rs:29:13 + --> tests/ui/get_first.rs:31:13 | LL | let _ = z.get(0); | ^^^^^^^^ help: try: `z.first()` error: accessing first element with `vecdeque.get(0)` - --> tests/ui/get_first.rs:35:13 + --> tests/ui/get_first.rs:38:13 | LL | let _ = vecdeque.get(0); | ^^^^^^^^^^^^^^^ help: try: `vecdeque.front()` error: accessing first element with `non_primitives.get(0)` - --> tests/ui/get_first.rs:48:13 + --> tests/ui/get_first.rs:52:13 | LL | let _ = non_primitives.get(0); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `non_primitives.first()` diff --git a/tests/ui/get_last_with_len.fixed b/tests/ui/get_last_with_len.fixed index 377906cb2448..15b6e1666af2 100644 --- a/tests/ui/get_last_with_len.fixed +++ b/tests/ui/get_last_with_len.fixed @@ -6,6 +6,7 @@ use std::collections::VecDeque; fn dont_use_last() { let x = vec![2, 3, 5]; let _ = x.last(); + //~^ get_last_with_len } fn indexing_two_from_end() { @@ -30,18 +31,23 @@ struct S { fn in_field(s: &S) { let _ = s.field.last(); + //~^ get_last_with_len } fn main() { let slice = &[1, 2, 3]; let _ = slice.last(); + //~^ get_last_with_len let array = [4, 5, 6]; let _ = array.last(); + //~^ get_last_with_len let deq = VecDeque::from([7, 8, 9]); let _ = deq.back(); + //~^ get_last_with_len let nested = [[1]]; let _ = nested[0].last(); + //~^ get_last_with_len } diff --git a/tests/ui/get_last_with_len.rs b/tests/ui/get_last_with_len.rs index 2735932043a3..5b132e001e7b 100644 --- a/tests/ui/get_last_with_len.rs +++ b/tests/ui/get_last_with_len.rs @@ -6,6 +6,7 @@ use std::collections::VecDeque; fn dont_use_last() { let x = vec![2, 3, 5]; let _ = x.get(x.len() - 1); + //~^ get_last_with_len } fn indexing_two_from_end() { @@ -30,18 +31,23 @@ struct S { fn in_field(s: &S) { let _ = s.field.get(s.field.len() - 1); + //~^ get_last_with_len } fn main() { let slice = &[1, 2, 3]; let _ = slice.get(slice.len() - 1); + //~^ get_last_with_len let array = [4, 5, 6]; let _ = array.get(array.len() - 1); + //~^ get_last_with_len let deq = VecDeque::from([7, 8, 9]); let _ = deq.get(deq.len() - 1); + //~^ get_last_with_len let nested = [[1]]; let _ = nested[0].get(nested[0].len() - 1); + //~^ get_last_with_len } diff --git a/tests/ui/get_last_with_len.stderr b/tests/ui/get_last_with_len.stderr index ba08f5db7cfa..83a03a438e44 100644 --- a/tests/ui/get_last_with_len.stderr +++ b/tests/ui/get_last_with_len.stderr @@ -8,31 +8,31 @@ LL | let _ = x.get(x.len() - 1); = help: to override `-D warnings` add `#[allow(clippy::get_last_with_len)]` error: accessing last element with `s.field.get(s.field.len() - 1)` - --> tests/ui/get_last_with_len.rs:32:13 + --> tests/ui/get_last_with_len.rs:33: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)` - --> tests/ui/get_last_with_len.rs:37:13 + --> tests/ui/get_last_with_len.rs:39:13 | LL | let _ = slice.get(slice.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice.last()` error: accessing last element with `array.get(array.len() - 1)` - --> tests/ui/get_last_with_len.rs:40:13 + --> tests/ui/get_last_with_len.rs:43:13 | LL | let _ = array.get(array.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array.last()` error: accessing last element with `deq.get(deq.len() - 1)` - --> tests/ui/get_last_with_len.rs:43:13 + --> tests/ui/get_last_with_len.rs:47:13 | LL | let _ = deq.get(deq.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `deq.back()` error: accessing last element with `nested[0].get(nested[0].len() - 1)` - --> tests/ui/get_last_with_len.rs:46:13 + --> tests/ui/get_last_with_len.rs:51: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 2dd3c30a4e29..3115c1462f5a 100644 --- a/tests/ui/get_unwrap.fixed +++ b/tests/ui/get_unwrap.fixed @@ -35,23 +35,45 @@ fn main() { { // Test `get().unwrap()` let _ = &boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_slice[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vec[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vecdeque[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_hashmap[&1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_btreemap[&1]; + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` boxed_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vec[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vecdeque[0] = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -64,7 +86,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used } } mod issue9909 { @@ -76,12 +102,15 @@ mod issue9909 { // include a borrow in the suggestion, even if the argument is not just a numeric literal let _x: &i32 = &f[1 + 2]; + //~^ get_unwrap // don't include a borrow here let _x = f[1 + 2].to_string(); + //~^ get_unwrap // don't include a borrow here let _x = f[1 + 2].abs(); + //~^ get_unwrap } // original code: @@ -99,6 +128,7 @@ mod issue9909 { let (x, rest) = mat.split_at_mut(linidx(i, k) + 1); let a = x.last_mut().unwrap(); let b = &mut rest[linidx(j, k) - linidx(i, k) - 1]; + //~^ get_unwrap ::std::mem::swap(a, b); } } diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs index 94226564cacb..963238a88983 100644 --- a/tests/ui/get_unwrap.rs +++ b/tests/ui/get_unwrap.rs @@ -35,23 +35,45 @@ fn main() { { // Test `get().unwrap()` let _ = boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_slice.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vecdeque.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_hashmap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_btreemap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = *boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` *boxed_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vec.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vecdeque.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -64,7 +86,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec.get(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get_mut(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used } } mod issue9909 { @@ -76,12 +102,15 @@ mod issue9909 { // include a borrow in the suggestion, even if the argument is not just a numeric literal let _x: &i32 = f.get(1 + 2).unwrap(); + //~^ get_unwrap // don't include a borrow here let _x = f.get(1 + 2).unwrap().to_string(); + //~^ get_unwrap // don't include a borrow here let _x = f.get(1 + 2).unwrap().abs(); + //~^ get_unwrap } // original code: @@ -99,6 +128,7 @@ mod issue9909 { let (x, rest) = mat.split_at_mut(linidx(i, k) + 1); let a = x.last_mut().unwrap(); let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); + //~^ get_unwrap ::std::mem::swap(a, b); } } diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 8eacb249c60c..f663362dbb3e 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -26,7 +26,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:38:17 + --> tests/ui/get_unwrap.rs:40:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _ = &some_slice[0]; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:38:17 + --> tests/ui/get_unwrap.rs:40:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | let _ = some_slice.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec - --> tests/ui/get_unwrap.rs:39:17 + --> tests/ui/get_unwrap.rs:43:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = &some_vec[0]; | ~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:39:17 + --> tests/ui/get_unwrap.rs:43:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | let _ = some_vec.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque - --> tests/ui/get_unwrap.rs:40:17 + --> tests/ui/get_unwrap.rs:46:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | let _ = &some_vecdeque[0]; | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:40:17 + --> tests/ui/get_unwrap.rs:46:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap - --> tests/ui/get_unwrap.rs:41:17 + --> tests/ui/get_unwrap.rs:49:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = &some_hashmap[&1]; | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:41:17 + --> tests/ui/get_unwrap.rs:49:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap - --> tests/ui/get_unwrap.rs:42:17 + --> tests/ui/get_unwrap.rs:52:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | let _ = &some_btreemap[&1]; | ~~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:42:17 + --> tests/ui/get_unwrap.rs:52:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:46:21 + --> tests/ui/get_unwrap.rs:58:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ LL | let _: u8 = boxed_slice[1]; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:46:22 + --> tests/ui/get_unwrap.rs:58:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -146,7 +146,7 @@ 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 - --> tests/ui/get_unwrap.rs:51:9 + --> tests/ui/get_unwrap.rs:65:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | boxed_slice[0] = 1; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:51:10 + --> tests/ui/get_unwrap.rs:65:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ 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 - --> tests/ui/get_unwrap.rs:52:9 + --> tests/ui/get_unwrap.rs:68:9 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | some_slice[0] = 1; | ~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:52:10 + --> tests/ui/get_unwrap.rs:68:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -186,7 +186,7 @@ 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 - --> tests/ui/get_unwrap.rs:53:9 + --> tests/ui/get_unwrap.rs:71:9 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | some_vec[0] = 1; | ~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:53:10 + --> tests/ui/get_unwrap.rs:71:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -206,7 +206,7 @@ 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 - --> tests/ui/get_unwrap.rs:54:9 + --> tests/ui/get_unwrap.rs:74:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | some_vecdeque[0] = 1; | ~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:54:10 + --> tests/ui/get_unwrap.rs:74:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,7 +226,7 @@ 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 - --> tests/ui/get_unwrap.rs:66:17 + --> tests/ui/get_unwrap.rs:88:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL | let _ = some_vec[0..1].to_vec(); | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:66:17 + --> tests/ui/get_unwrap.rs:88:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -246,7 +246,7 @@ 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 - --> tests/ui/get_unwrap.rs:67:17 + --> tests/ui/get_unwrap.rs:91:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -257,7 +257,7 @@ LL | let _ = some_vec[0..1].to_vec(); | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui/get_unwrap.rs:67:17 + --> tests/ui/get_unwrap.rs:91:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -266,7 +266,7 @@ 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 - --> tests/ui/get_unwrap.rs:78:24 + --> tests/ui/get_unwrap.rs:104:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | let _x: &i32 = &f[1 + 2]; | ~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:81:18 + --> tests/ui/get_unwrap.rs:108:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL | let _x = f[1 + 2].to_string(); | ~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:84:18 + --> tests/ui/get_unwrap.rs:112:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +299,7 @@ LL | let _x = f[1 + 2].abs(); | ~~~~~~~~ error: called `.get_mut().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:101:33 + --> tests/ui/get_unwrap.rs:130:33 | LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/identity_op.fixed b/tests/ui/identity_op.fixed index 2e8e2366de6f..b3836bda2b6f 100644 --- a/tests/ui/identity_op.fixed +++ b/tests/ui/identity_op.fixed @@ -42,45 +42,58 @@ fn main() { let x = 0; x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x + 1; x; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 + x; x - ZERO; //no error, as we skip lookups (for now) x; - //~^ ERROR: this operation has no effect + //~^ identity_op + ((ZERO)) | x; //no error, as we skip lookups (for now) x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x / ONE; //no error, as we skip lookups (for now) x / 2; //no false positive x & NEG_ONE; //no error, as we skip lookups (for now) x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let u: u8 = 0; u; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 << 0; // no error, this case is allowed, see issue 3430 42; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1; - //~^ ERROR: this operation has no effect + //~^ identity_op + 42; - //~^ ERROR: this operation has no effect + //~^ identity_op + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let mut a = A(String::new()); let b = a << 0; // no error: non-integer @@ -88,15 +101,20 @@ fn main() { 1 * Meter; // no error: non-integer 2; - //~^ ERROR: this operation has no effect + //~^ identity_op + -2; - //~^ ERROR: this operation has no effect + //~^ identity_op + 2 + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + -2 + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x + 1; - //~^ ERROR: this operation has no effect + //~^ identity_op + (x + 1) % 3; // no error 4 % 3; // no error 4 % -3; // no error @@ -105,63 +123,85 @@ fn main() { let a = 0; let b = true; (if b { 1 } else { 2 }); - //~^ ERROR: this operation has no effect + //~^ identity_op + (if b { 1 } else { 2 }) + if b { 3 } else { 4 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + (match a { 0 => 10, _ => 20 }); - //~^ ERROR: this operation has no effect + //~^ identity_op + (match a { 0 => 10, _ => 20 }) + match a { 0 => 30, _ => 40 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + (if b { 1 } else { 2 }) + match a { 0 => 30, _ => 40 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + (match a { 0 => 10, _ => 20 }) + if b { 3 } else { 4 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + ((if b { 1 } else { 2 })); - //~^ ERROR: this operation has no effect + //~^ identity_op + ({ a }) + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + ({ a } * 2); - //~^ ERROR: this operation has no effect + //~^ identity_op + (loop { let mut c = 0; if c == 10 { break c; } c += 1; }) + { a * 2 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + fn f(_: i32) { todo!(); } f(a + { 8 * 5 }); - //~^ ERROR: this operation has no effect + //~^ identity_op + f(if b { 1 } else { 2 } + 3); - //~^ ERROR: this operation has no effect + //~^ identity_op + const _: i32 = { 2 * 4 } + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + const _: i32 = { 1 + 2 * 3 } + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + a as usize; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _ = a as usize; - //~^ ERROR: this operation has no effect + //~^ identity_op + ({ a } as usize); - //~^ ERROR: this operation has no effect + //~^ identity_op + 2 * { a }; - //~^ ERROR: this operation has no effect + //~^ identity_op + (({ a } + 4)); - //~^ ERROR: this operation has no effect + //~^ identity_op + 1; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Issue #9904 let x = 0i32; let _: i32 = x; - //~^ ERROR: this operation has no effect + //~^ identity_op + } pub fn decide(a: bool, b: bool) -> u32 { (if a { 1 } else { 2 }) + if b { 3 } else { 5 } + //~^ identity_op } /// The following tests are from / for issue #12050 @@ -173,43 +213,55 @@ fn issue_12050() { { let x = &0i32; let _: i32 = *x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = *x; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { let x = &&0i32; let _: i32 = **x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = &&0i32; let _: i32 = **x; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { // this is just silly let x = &&&0i32; let _: i32 = ***x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = ***x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = 0i32; let _: i32 = *&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **&&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = *&*&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **&&*&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { // this is getting ridiculous, but we should still see the same // error message so let's just keep going let x = &0i32; let _: i32 = ***&&*&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = ***&&*&x; - //~^ ERROR: this operation has no effect + //~^ identity_op + } } @@ -218,41 +270,52 @@ fn issue_13470() { let y = 1i32; // Removes the + 0i32 while keeping the parentheses around x + y so the cast operation works let _: u64 = (x + y) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // both of the next two lines should look the same after rustfix let _: u64 = 1u64 & (x + y) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Same as above, but with extra redundant parenthesis let _: u64 = 1u64 & ((x + y)) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Should maintain parenthesis even if the surrounding expr has the same precedence let _: u64 = 5u64 + ((x + y)) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // If we don't maintain the parens here, the behavior changes let _ = -(x + y); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Similarly, we need to maintain parens here let _ = -(x / y); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is of higher precedence let _ = 2i32 * (x + y); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is the same precedence // as not all operations are associative let _ = 2i32 - (x - y); - //~^ ERROR: this operation has no effect + //~^ identity_op + // But make sure that inner parens still exist let z = 1i32; let _ = 2 + (x + (y * z)); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is of lower precedence // This is for clarity, and clippy will not warn on these being unnecessary let _ = 2i32 + (x * y); - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = 1i16; let y = 1i16; let _: u64 = 1u64 + ((x as i32 + y as i32) as u64); - //~^ ERROR: this operation has no effect + //~^ identity_op + } diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index 3e20fa6f2b89..9d545a95bdd3 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -42,45 +42,58 @@ fn main() { let x = 0; x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + x + (1 - 1); - //~^ ERROR: this operation has no effect + //~^ identity_op + x + 1; 0 + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 + x; x - ZERO; //no error, as we skip lookups (for now) x | (0); - //~^ ERROR: this operation has no effect + //~^ identity_op + ((ZERO)) | x; //no error, as we skip lookups (for now) x * 1; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 * x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x / ONE; //no error, as we skip lookups (for now) x / 2; //no false positive x & NEG_ONE; //no error, as we skip lookups (for now) -1 & x; - //~^ ERROR: this operation has no effect + //~^ identity_op + let u: u8 = 0; u & 255; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 << 0; // no error, this case is allowed, see issue 3430 42 << 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 >> 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + 42 >> 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + &x >> 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + x >> &0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let mut a = A(String::new()); let b = a << 0; // no error: non-integer @@ -88,15 +101,20 @@ fn main() { 1 * Meter; // no error: non-integer 2 % 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + -2 % 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + 2 % -3 + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + -2 % -3 + x; - //~^ ERROR: this operation has no effect + //~^ identity_op + x + 1 % 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + (x + 1) % 3; // no error 4 % 3; // no error 4 % -3; // no error @@ -105,63 +123,85 @@ fn main() { let a = 0; let b = true; 0 + if b { 1 } else { 2 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + if b { 1 } else { 2 } + if b { 3 } else { 4 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + match a { 0 => 10, _ => 20 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + match a { 0 => 10, _ => 20 } + match a { 0 => 30, _ => 40 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + if b { 1 } else { 2 } + match a { 0 => 30, _ => 40 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + match a { 0 => 10, _ => 20 } + if b { 3 } else { 4 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + (if b { 1 } else { 2 }) + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + { a } + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + { a } * 2; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + loop { let mut c = 0; if c == 10 { break c; } c += 1; } + { a * 2 }; - //~^ ERROR: this operation has no effect + //~^ identity_op + fn f(_: i32) { todo!(); } f(1 * a + { 8 * 5 }); - //~^ ERROR: this operation has no effect + //~^ identity_op + f(0 + if b { 1 } else { 2 } + 3); - //~^ ERROR: this operation has no effect + //~^ identity_op + const _: i32 = { 2 * 4 } + 0 + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + const _: i32 = 0 + { 1 + 2 * 3 } + 3; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + a as usize; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _ = 0 + a as usize; - //~^ ERROR: this operation has no effect + //~^ identity_op + 0 + { a } as usize; - //~^ ERROR: this operation has no effect + //~^ identity_op + 2 * (0 + { a }); - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 * ({ a } + 4); - //~^ ERROR: this operation has no effect + //~^ identity_op + 1 * 1; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Issue #9904 let x = 0i32; let _: i32 = &x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + } pub fn decide(a: bool, b: bool) -> u32 { 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } + //~^ identity_op } /// The following tests are from / for issue #12050 @@ -173,43 +213,55 @@ fn issue_12050() { { let x = &0i32; let _: i32 = *x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { let x = &&0i32; let _: i32 = **x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = &&0i32; let _: i32 = *x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { // this is just silly let x = &&&0i32; let _: i32 = ***x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = 0i32; let _: i32 = *&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **&&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = *&*&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **&&*&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + } { // this is getting ridiculous, but we should still see the same // error message so let's just keep going let x = &0i32; let _: i32 = **&&*&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + let _: i32 = **&&*&x + 0; - //~^ ERROR: this operation has no effect + //~^ identity_op + } } @@ -218,41 +270,52 @@ fn issue_13470() { let y = 1i32; // Removes the + 0i32 while keeping the parentheses around x + y so the cast operation works let _: u64 = (x + y + 0i32) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // both of the next two lines should look the same after rustfix let _: u64 = 1u64 & (x + y + 0i32) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Same as above, but with extra redundant parenthesis let _: u64 = 1u64 & ((x + y) + 0i32) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // Should maintain parenthesis even if the surrounding expr has the same precedence let _: u64 = 5u64 + ((x + y) + 0i32) as u64; - //~^ ERROR: this operation has no effect + //~^ identity_op + // If we don't maintain the parens here, the behavior changes let _ = -(x + y + 0i32); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Similarly, we need to maintain parens here let _ = -(x / y / 1i32); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is of higher precedence let _ = 2i32 * (x + y + 0i32); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is the same precedence // as not all operations are associative let _ = 2i32 - (x - y - 0i32); - //~^ ERROR: this operation has no effect + //~^ identity_op + // But make sure that inner parens still exist let z = 1i32; let _ = 2 + (x + (y * z) + 0); - //~^ ERROR: this operation has no effect + //~^ identity_op + // Maintain parenthesis if the parent expr is of lower precedence // This is for clarity, and clippy will not warn on these being unnecessary let _ = 2i32 + (x * y * 1i32); - //~^ ERROR: this operation has no effect + //~^ identity_op + let x = 1i16; let y = 1i16; let _: u64 = 1u64 + ((x as i32 + y as i32) as u64 + 0u64); - //~^ ERROR: this operation has no effect + //~^ identity_op + } diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index 99a58ef2c1b5..8952f2fb7b8b 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -8,373 +8,373 @@ LL | x + 0; = help: to override `-D warnings` add `#[allow(clippy::identity_op)]` error: this operation has no effect - --> tests/ui/identity_op.rs:46:5 + --> tests/ui/identity_op.rs:47:5 | LL | x + (1 - 1); | ^^^^^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:49:5 + --> tests/ui/identity_op.rs:51:5 | LL | 0 + x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:53:5 + --> tests/ui/identity_op.rs:56:5 | LL | x | (0); | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:57:5 + --> tests/ui/identity_op.rs:61:5 | LL | x * 1; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:59:5 + --> tests/ui/identity_op.rs:64:5 | LL | 1 * x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:66:5 + --> tests/ui/identity_op.rs:72:5 | LL | -1 & x; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:70:5 + --> tests/ui/identity_op.rs:77:5 | LL | u & 255; | ^^^^^^^ help: consider reducing it to: `u` error: this operation has no effect - --> tests/ui/identity_op.rs:74:5 + --> tests/ui/identity_op.rs:82:5 | LL | 42 << 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> tests/ui/identity_op.rs:76:5 + --> tests/ui/identity_op.rs:85:5 | LL | 1 >> 0; | ^^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> tests/ui/identity_op.rs:78:5 + --> tests/ui/identity_op.rs:88:5 | LL | 42 >> 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> tests/ui/identity_op.rs:80:5 + --> tests/ui/identity_op.rs:91:5 | LL | &x >> 0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:82:5 + --> tests/ui/identity_op.rs:94:5 | LL | x >> &0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:90:5 + --> tests/ui/identity_op.rs:103:5 | LL | 2 % 3; | ^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> tests/ui/identity_op.rs:92:5 + --> tests/ui/identity_op.rs:106:5 | LL | -2 % 3; | ^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> tests/ui/identity_op.rs:94:5 + --> tests/ui/identity_op.rs:109:5 | LL | 2 % -3 + x; | ^^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> tests/ui/identity_op.rs:96:5 + --> tests/ui/identity_op.rs:112:5 | LL | -2 % -3 + x; | ^^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> tests/ui/identity_op.rs:98:9 + --> tests/ui/identity_op.rs:115:9 | LL | x + 1 % 3; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> tests/ui/identity_op.rs:107:5 + --> tests/ui/identity_op.rs:125:5 | LL | 0 + if b { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> tests/ui/identity_op.rs:109:5 + --> tests/ui/identity_op.rs:128: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 - --> tests/ui/identity_op.rs:111:5 + --> tests/ui/identity_op.rs:131:5 | LL | 0 + match a { 0 => 10, _ => 20 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> tests/ui/identity_op.rs:113:5 + --> tests/ui/identity_op.rs:134: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 - --> tests/ui/identity_op.rs:115:5 + --> tests/ui/identity_op.rs:137: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 - --> tests/ui/identity_op.rs:117:5 + --> tests/ui/identity_op.rs:140: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 - --> tests/ui/identity_op.rs:119:5 + --> tests/ui/identity_op.rs:143:5 | LL | (if b { 1 } else { 2 }) + 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `((if b { 1 } else { 2 }))` error: this operation has no effect - --> tests/ui/identity_op.rs:122:5 + --> tests/ui/identity_op.rs:147:5 | LL | 0 + { a } + 3; | ^^^^^^^^^ help: consider reducing it to: `({ a })` error: this operation has no effect - --> tests/ui/identity_op.rs:124:5 + --> tests/ui/identity_op.rs:150:5 | LL | 0 + { a } * 2; | ^^^^^^^^^^^^^ help: consider reducing it to: `({ a } * 2)` error: this operation has no effect - --> tests/ui/identity_op.rs:126:5 + --> tests/ui/identity_op.rs:153: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 - --> tests/ui/identity_op.rs:133:7 + --> tests/ui/identity_op.rs:161:7 | LL | f(1 * a + { 8 * 5 }); | ^^^^^ help: consider reducing it to: `a` error: this operation has no effect - --> tests/ui/identity_op.rs:135:7 + --> tests/ui/identity_op.rs:164: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 - --> tests/ui/identity_op.rs:138:20 + --> tests/ui/identity_op.rs:168:20 | LL | const _: i32 = { 2 * 4 } + 0 + 3; | ^^^^^^^^^^^^^ help: consider reducing it to: `{ 2 * 4 }` error: this operation has no effect - --> tests/ui/identity_op.rs:140:20 + --> tests/ui/identity_op.rs:171:20 | LL | const _: i32 = 0 + { 1 + 2 * 3 } + 3; | ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `{ 1 + 2 * 3 }` error: this operation has no effect - --> tests/ui/identity_op.rs:143:5 + --> tests/ui/identity_op.rs:175:5 | LL | 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> tests/ui/identity_op.rs:145:13 + --> tests/ui/identity_op.rs:178:13 | LL | let _ = 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> tests/ui/identity_op.rs:147:5 + --> tests/ui/identity_op.rs:181:5 | LL | 0 + { a } as usize; | ^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `({ a } as usize)` error: this operation has no effect - --> tests/ui/identity_op.rs:150:9 + --> tests/ui/identity_op.rs:185:9 | LL | 2 * (0 + { a }); | ^^^^^^^^^^^ help: consider reducing it to: `{ a }` error: this operation has no effect - --> tests/ui/identity_op.rs:152:5 + --> tests/ui/identity_op.rs:188:5 | LL | 1 * ({ a } + 4); | ^^^^^^^^^^^^^^^ help: consider reducing it to: `(({ a } + 4))` error: this operation has no effect - --> tests/ui/identity_op.rs:154:5 + --> tests/ui/identity_op.rs:191:5 | LL | 1 * 1; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> tests/ui/identity_op.rs:159:18 + --> tests/ui/identity_op.rs:197:18 | LL | let _: i32 = &x + 0; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> tests/ui/identity_op.rs:164:5 + --> tests/ui/identity_op.rs:203:5 | LL | 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if a { 1 } else { 2 })` error: this operation has no effect - --> tests/ui/identity_op.rs:175:22 + --> tests/ui/identity_op.rs:215:22 | LL | let _: i32 = *x + 0; | ^^^^^^ help: consider reducing it to: `*x` error: this operation has no effect - --> tests/ui/identity_op.rs:177:22 + --> tests/ui/identity_op.rs:218:22 | LL | let _: i32 = x + 0; | ^^^^^ help: consider reducing it to: `*x` error: this operation has no effect - --> tests/ui/identity_op.rs:182:22 + --> tests/ui/identity_op.rs:224:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> tests/ui/identity_op.rs:185:22 + --> tests/ui/identity_op.rs:228:22 | LL | let _: i32 = *x + 0; | ^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> tests/ui/identity_op.rs:191:22 + --> tests/ui/identity_op.rs:235:22 | LL | let _: i32 = ***x + 0; | ^^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> tests/ui/identity_op.rs:193:22 + --> tests/ui/identity_op.rs:238:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> tests/ui/identity_op.rs:196:22 + --> tests/ui/identity_op.rs:242:22 | LL | let _: i32 = *&x + 0; | ^^^^^^^ help: consider reducing it to: `*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:198:22 + --> tests/ui/identity_op.rs:245:22 | LL | let _: i32 = **&&x + 0; | ^^^^^^^^^ help: consider reducing it to: `**&&x` error: this operation has no effect - --> tests/ui/identity_op.rs:200:22 + --> tests/ui/identity_op.rs:248:22 | LL | let _: i32 = *&*&x + 0; | ^^^^^^^^^ help: consider reducing it to: `*&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:202:22 + --> tests/ui/identity_op.rs:251:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `**&&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:209:22 + --> tests/ui/identity_op.rs:259:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:211:22 + --> tests/ui/identity_op.rs:262:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:220:18 + --> tests/ui/identity_op.rs:272:18 | LL | let _: u64 = (x + y + 0i32) as u64; | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:223:25 + --> tests/ui/identity_op.rs:276:25 | LL | let _: u64 = 1u64 & (x + y + 0i32) as u64; | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:226:25 + --> tests/ui/identity_op.rs:280:25 | LL | let _: u64 = 1u64 & ((x + y) + 0i32) as u64; | ^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x + y))` error: this operation has no effect - --> tests/ui/identity_op.rs:229:25 + --> tests/ui/identity_op.rs:284:25 | LL | let _: u64 = 5u64 + ((x + y) + 0i32) as u64; | ^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x + y))` error: this operation has no effect - --> tests/ui/identity_op.rs:233:14 + --> tests/ui/identity_op.rs:289:14 | LL | let _ = -(x + y + 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:236:14 + --> tests/ui/identity_op.rs:293:14 | LL | let _ = -(x / y / 1i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x / y)` error: this operation has no effect - --> tests/ui/identity_op.rs:239:20 + --> tests/ui/identity_op.rs:297:20 | LL | let _ = 2i32 * (x + y + 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:243:20 + --> tests/ui/identity_op.rs:302:20 | LL | let _ = 2i32 - (x - y - 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x - y)` error: this operation has no effect - --> tests/ui/identity_op.rs:247:17 + --> tests/ui/identity_op.rs:307:17 | LL | let _ = 2 + (x + (y * z) + 0); | ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(x + (y * z))` error: this operation has no effect - --> tests/ui/identity_op.rs:251:20 + --> tests/ui/identity_op.rs:312:20 | LL | let _ = 2i32 + (x * y * 1i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x * y)` error: this operation has no effect - --> tests/ui/identity_op.rs:256:25 + --> tests/ui/identity_op.rs:318:25 | LL | let _: u64 = 1u64 + ((x as i32 + y as i32) as u64 + 0u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x as i32 + y as i32) as u64)` diff --git a/tests/ui/if_let_mutex.rs b/tests/ui/if_let_mutex.rs index 80eee2939890..ddf178b63048 100644 --- a/tests/ui/if_let_mutex.rs +++ b/tests/ui/if_let_mutex.rs @@ -62,6 +62,10 @@ fn multiple_mutexes(m1: &Mutex<()>, m2: &Mutex<()>) { } else { m1.lock(); } + //~^ if_let_mutex + //~^ if_let_mutex + //~^ if_let_mutex + //~^ if_let_mutex } fn main() {} diff --git a/tests/ui/if_not_else.fixed b/tests/ui/if_not_else.fixed index 11d1e13179c4..1b58bdda5217 100644 --- a/tests/ui/if_not_else.fixed +++ b/tests/ui/if_not_else.fixed @@ -12,13 +12,15 @@ fn main() { if bla() { println!("Bunny"); } else { - //~^ ERROR: unnecessary boolean `not` operation + //~^ if_not_else + println!("Bugs"); } if 4 == 5 { println!("Bunny"); } else { - //~^ ERROR: unnecessary `!=` operation + //~^ if_not_else + println!("Bugs"); } if !foo() { @@ -32,6 +34,7 @@ fn main() { if (foo() && bla()) { println!("both true"); } else { + //~^ if_not_else #[cfg(not(debug_assertions))] println!("not debug"); #[cfg(debug_assertions)] @@ -50,6 +53,7 @@ fn with_comments() { if foo() { println!("foo"); /* foo */ } else { + //~^ if_not_else /* foo is false */ println!("foo is false"); } @@ -57,6 +61,7 @@ fn with_comments() { if bla() { println!("bla"); // bla } else { + //~^ if_not_else // bla is false println!("bla"); } @@ -67,6 +72,7 @@ fn with_annotations() { if foo() { println!("foo"); /* foo */ } else { + //~^ if_not_else /* foo is false */ println!("foo is false"); } diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index fcc67e163e8a..0d035e283774 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -10,13 +10,15 @@ fn bla() -> bool { fn main() { if !bla() { - //~^ ERROR: unnecessary boolean `not` operation + //~^ if_not_else + println!("Bugs"); } else { println!("Bunny"); } if 4 != 5 { - //~^ ERROR: unnecessary `!=` operation + //~^ if_not_else + println!("Bugs"); } else { println!("Bunny"); @@ -30,6 +32,7 @@ fn main() { } if !(foo() && bla()) { + //~^ if_not_else #[cfg(not(debug_assertions))] println!("not debug"); #[cfg(debug_assertions)] @@ -48,6 +51,7 @@ fn main() { fn with_comments() { if !foo() { + //~^ if_not_else /* foo is false */ println!("foo is false"); } else { @@ -55,6 +59,7 @@ fn with_comments() { } if !bla() { + //~^ if_not_else // bla is false println!("bla"); } else { @@ -65,6 +70,7 @@ fn with_comments() { fn with_annotations() { #[cfg(debug_assertions)] if !foo() { + //~^ if_not_else /* foo is false */ println!("foo is false"); } else { diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index b01cb5af11f7..f44dd0aabc86 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -3,6 +3,7 @@ error: unnecessary boolean `not` operation | LL | / if !bla() { LL | | +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); @@ -17,15 +18,17 @@ LL ~ if bla() { LL + println!("Bunny"); LL + } else { LL + +LL + LL + println!("Bugs"); LL + } | error: unnecessary `!=` operation - --> tests/ui/if_not_else.rs:18:5 + --> tests/ui/if_not_else.rs:19:5 | LL | / if 4 != 5 { LL | | +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); @@ -38,17 +41,18 @@ LL ~ if 4 == 5 { LL + println!("Bunny"); LL + } else { LL + +LL + LL + println!("Bugs"); LL + } | error: unnecessary boolean `not` operation - --> tests/ui/if_not_else.rs:32:5 + --> tests/ui/if_not_else.rs:34:5 | LL | / if !(foo() && bla()) { +LL | | LL | | #[cfg(not(debug_assertions))] LL | | println!("not debug"); -LL | | #[cfg(debug_assertions)] ... | LL | | println!("both true"); LL | | } @@ -59,6 +63,7 @@ help: try LL ~ if (foo() && bla()) { LL + println!("both true"); LL + } else { +LL + LL + #[cfg(not(debug_assertions))] LL + println!("not debug"); LL + #[cfg(debug_assertions)] @@ -74,9 +79,10 @@ LL + } | error: unnecessary boolean `not` operation - --> tests/ui/if_not_else.rs:50:5 + --> tests/ui/if_not_else.rs:53:5 | LL | / if !foo() { +LL | | LL | | /* foo is false */ LL | | println!("foo is false"); LL | | } else { @@ -89,15 +95,17 @@ help: try LL ~ if foo() { LL + println!("foo"); /* foo */ LL + } else { +LL + LL + /* foo is false */ LL + println!("foo is false"); LL + } | error: unnecessary boolean `not` operation - --> tests/ui/if_not_else.rs:57:5 + --> tests/ui/if_not_else.rs:61:5 | LL | / if !bla() { +LL | | LL | | // bla is false LL | | println!("bla"); LL | | } else { @@ -110,15 +118,17 @@ help: try LL ~ if bla() { LL + println!("bla"); // bla LL + } else { +LL + LL + // bla is false LL + println!("bla"); LL + } | error: unnecessary boolean `not` operation - --> tests/ui/if_not_else.rs:67:5 + --> tests/ui/if_not_else.rs:72:5 | LL | / if !foo() { +LL | | LL | | /* foo is false */ LL | | println!("foo is false"); LL | | } else { @@ -131,6 +141,7 @@ help: try LL ~ if foo() { LL + println!("foo"); /* foo */ LL + } else { +LL + LL + /* foo is false */ LL + println!("foo is false"); LL + } diff --git a/tests/ui/if_not_else_bittest.rs b/tests/ui/if_not_else_bittest.rs index 586ce6ce1bcc..205823c5a8ab 100644 --- a/tests/ui/if_not_else_bittest.rs +++ b/tests/ui/if_not_else_bittest.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::if_not_else)] fn show_permissions(flags: u32) { diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index d53e1383d845..5eaf4015b77b 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -37,7 +37,8 @@ fn if_same_then_else() { 0..=10; foo(); } - //~^^^^^^^^^^^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^^^^^^^^^^^ if_same_then_else + if true { Foo { bar: 42 }; @@ -65,10 +66,12 @@ fn if_same_then_else() { } let _ = if true { 0.0 } else { 0.0 }; - //~^ ERROR: this `if` has identical blocks + //~^ if_same_then_else + let _ = if true { -0.0 } else { -0.0 }; - //~^ ERROR: this `if` has identical blocks + //~^ if_same_then_else + let _ = if true { 0.0 } else { -0.0 }; @@ -80,7 +83,8 @@ fn if_same_then_else() { } let _ = if true { 42 } else { 42 }; - //~^ ERROR: this `if` has identical blocks + //~^ if_same_then_else + if true { let bar = if true { 42 } else { 43 }; @@ -97,7 +101,8 @@ fn if_same_then_else() { } bar + 1; } - //~^^^^^^^^^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^^^^^^^^^ if_same_then_else + if true { let _ = match 42 { @@ -240,6 +245,7 @@ mod issue_11213 { } else { 0_u8.is_power_of_two() } + //~^^^^^ if_same_then_else } } diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index b76da3fb1cb5..e715dbfa2258 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -27,43 +27,43 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:67:21 + --> tests/ui/if_same_then_else.rs:68:21 | LL | let _ = if true { 0.0 } else { 0.0 }; | ^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:67:34 + --> tests/ui/if_same_then_else.rs:68:34 | LL | let _ = if true { 0.0 } else { 0.0 }; | ^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:70:21 + --> tests/ui/if_same_then_else.rs:72:21 | LL | let _ = if true { -0.0 } else { -0.0 }; | ^^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:70:35 + --> tests/ui/if_same_then_else.rs:72:35 | LL | let _ = if true { -0.0 } else { -0.0 }; | ^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:82:21 + --> tests/ui/if_same_then_else.rs:85:21 | LL | let _ = if true { 42 } else { 42 }; | ^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:82:33 + --> tests/ui/if_same_then_else.rs:85:33 | LL | let _ = if true { 42 } else { 42 }; | ^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:85:13 + --> tests/ui/if_same_then_else.rs:89:13 | LL | if true { | _____________^ @@ -76,7 +76,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else.rs:92:12 + --> tests/ui/if_same_then_else.rs:96:12 | LL | } else { | ____________^ @@ -89,7 +89,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:238:14 + --> tests/ui/if_same_then_else.rs:243:14 | LL | if x { | ______________^ @@ -98,7 +98,7 @@ LL | | } else { | |_________^ | note: same as this - --> tests/ui/if_same_then_else.rs:240:16 + --> tests/ui/if_same_then_else.rs:245:16 | LL | } else { | ________________^ diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index e23c77b08274..2ccd85224cd3 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -31,21 +31,24 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } } } - //~^^^^^^^^^^^^^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^^^^^^^^^^^^^ if_same_then_else + if true { if let Some(a) = Some(42) {} } else { if let Some(a) = Some(42) {} } - //~^^^^^ ERROR: this `if` has identical blocks + //~^^^^^ if_same_then_else + if true { if let (1, .., 3) = (1, 2, 3) {} } else { if let (1, .., 3) = (1, 2, 3) {} } - //~^^^^^ ERROR: this `if` has identical blocks + //~^^^^^ if_same_then_else + if true { if let (1, .., 3) = (1, 2, 3) {} @@ -91,14 +94,16 @@ fn if_same_then_else2() -> Result<&'static str, ()> { // Same NaNs let _ = if true { f32::NAN } else { f32::NAN }; - //~^ ERROR: this `if` has identical blocks + //~^ if_same_then_else + if true { Ok("foo")?; } else { Ok("foo")?; } - //~^^^^^ ERROR: this `if` has identical blocks + //~^^^^^ if_same_then_else + if true { let foo = ""; @@ -124,7 +129,8 @@ fn if_same_then_else2() -> Result<&'static str, ()> { let foo = ""; return Ok(&foo[0..]); } - //~^^^^^^^ ERROR: this `if` has identical blocks + //~^^^^^^^ if_same_then_else + // False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559. if true { diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 369d6f667372..3465482f9872 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -25,7 +25,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:36:13 + --> tests/ui/if_same_then_else2.rs:37:13 | LL | if true { | _____________^ @@ -34,7 +34,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:38:12 + --> tests/ui/if_same_then_else2.rs:39:12 | LL | } else { | ____________^ @@ -43,7 +43,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:43:13 + --> tests/ui/if_same_then_else2.rs:45:13 | LL | if true { | _____________^ @@ -52,7 +52,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:45:12 + --> tests/ui/if_same_then_else2.rs:47:12 | LL | } else { | ____________^ @@ -61,19 +61,19 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:93:21 + --> tests/ui/if_same_then_else2.rs:96:21 | LL | let _ = if true { f32::NAN } else { f32::NAN }; | ^^^^^^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else2.rs:93:39 + --> tests/ui/if_same_then_else2.rs:96:39 | LL | let _ = if true { f32::NAN } else { f32::NAN }; | ^^^^^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:96:13 + --> tests/ui/if_same_then_else2.rs:100:13 | LL | if true { | _____________^ @@ -82,7 +82,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:98:12 + --> tests/ui/if_same_then_else2.rs:102:12 | LL | } else { | ____________^ @@ -91,7 +91,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:120:20 + --> tests/ui/if_same_then_else2.rs:125:20 | LL | } else if true { | ____________________^ @@ -101,7 +101,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:123:12 + --> tests/ui/if_same_then_else2.rs:128:12 | LL | } else { | ____________^ diff --git a/tests/ui/if_then_some_else_none.fixed b/tests/ui/if_then_some_else_none.fixed index 1f47dddcbc40..1f9ea9bf9bc0 100644 --- a/tests/ui/if_then_some_else_none.fixed +++ b/tests/ui/if_then_some_else_none.fixed @@ -11,12 +11,14 @@ fn main() { // Should issue an error. Binary expression `o < 32` should be parenthesized. let x = Some(5); let _ = x.and_then(|o| (o < 32).then_some(o)); - //~^ ERROR: this could be simplified with `bool::then_some` + //~^ if_then_some_else_none + // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = (!x).then_some(0); - //~^ ERROR: this could be simplified with `bool::then_some` + //~^ if_then_some_else_none + // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { @@ -115,6 +117,7 @@ fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> { fn issue13407(s: &str) -> Option { (s == "1").then(|| true) + //~^ if_then_some_else_none } const fn issue12103(x: u32) -> Option { diff --git a/tests/ui/if_then_some_else_none.rs b/tests/ui/if_then_some_else_none.rs index 499f008fb876..238d524a5522 100644 --- a/tests/ui/if_then_some_else_none.rs +++ b/tests/ui/if_then_some_else_none.rs @@ -4,7 +4,8 @@ fn main() { // Should issue an error. let _ = if foo() { - //~^ ERROR: this could be simplified with `bool::then` + //~^ if_then_some_else_none + println!("true!"); Some("foo") } else { @@ -13,7 +14,8 @@ fn main() { // Should issue an error when macros are used. let _ = if matches!(true, true) { - //~^ ERROR: this could be simplified with `bool::then` + //~^ if_then_some_else_none + println!("true!"); Some(matches!(true, false)) } else { @@ -23,12 +25,14 @@ 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` + //~^ if_then_some_else_none + // 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` + //~^ if_then_some_else_none + // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { @@ -84,7 +88,8 @@ fn _msrv_1_49() { #[clippy::msrv = "1.50"] fn _msrv_1_50() { let _ = if foo() { - //~^ ERROR: this could be simplified with `bool::then` + //~^ if_then_some_else_none + println!("true!"); Some(150) } else { @@ -133,6 +138,7 @@ fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> { fn issue13407(s: &str) -> Option { if s == "1" { Some(true) } else { None } + //~^ if_then_some_else_none } const fn issue12103(x: u32) -> Option { diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index e7bc66b3ee88..a996dec236d6 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -4,9 +4,9 @@ error: this could be simplified with `bool::then` LL | let _ = if foo() { | _____________^ LL | | +LL | | LL | | println!("true!"); -LL | | Some("foo") -LL | | } else { +... | LL | | None LL | | }; | |_____^ help: try: `foo().then(|| { println!("true!"); "foo" })` @@ -15,45 +15,45 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]` error: this could be simplified with `bool::then` - --> tests/ui/if_then_some_else_none.rs:15:13 + --> tests/ui/if_then_some_else_none.rs:16:13 | LL | let _ = if matches!(true, true) { | _____________^ LL | | +LL | | LL | | println!("true!"); -LL | | Some(matches!(true, false)) -LL | | } else { +... | LL | | None LL | | }; | |_____^ help: try: `matches!(true, true).then(|| { println!("true!"); matches!(true, false) })` error: this could be simplified with `bool::then_some` - --> tests/ui/if_then_some_else_none.rs:25:28 + --> tests/ui/if_then_some_else_none.rs:27:28 | LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` - --> tests/ui/if_then_some_else_none.rs:30:13 + --> tests/ui/if_then_some_else_none.rs:33:13 | LL | let _ = if !x { Some(0) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!x).then_some(0)` error: this could be simplified with `bool::then` - --> tests/ui/if_then_some_else_none.rs:86:13 + --> tests/ui/if_then_some_else_none.rs:90:13 | LL | let _ = if foo() { | _____________^ LL | | +LL | | LL | | println!("true!"); -LL | | Some(150) -LL | | } else { +... | LL | | None LL | | }; | |_____^ help: try: `foo().then(|| { println!("true!"); 150 })` error: this could be simplified with `bool::then` - --> tests/ui/if_then_some_else_none.rs:135:5 + --> tests/ui/if_then_some_else_none.rs:140:5 | LL | if s == "1" { Some(true) } else { None } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(s == "1").then(|| true)` diff --git a/tests/ui/ifs_same_cond.rs b/tests/ui/ifs_same_cond.rs index ad77346b75f2..202b164d03ba 100644 --- a/tests/ui/ifs_same_cond.rs +++ b/tests/ui/ifs_same_cond.rs @@ -12,18 +12,21 @@ fn ifs_same_cond() { if b { } else if b { - //~^ ERROR: this `if` has the same condition as a previous `if` + //~^ ifs_same_cond + } if a == 1 { } else if a == 1 { - //~^ ERROR: this `if` has the same condition as a previous `if` + //~^ ifs_same_cond + } if 2 * a == 1 { } else if 2 * a == 2 { } else if 2 * a == 1 { - //~^ ERROR: this `if` has the same condition as a previous `if` + //~^ ifs_same_cond + } else if a == 1 { } @@ -56,7 +59,8 @@ fn issue10272() { let a = String::from("ha"); if a.contains("ah") { } else if a.contains("ah") { - //~^ ERROR: this `if` has the same condition as a previous `if` + //~^ ifs_same_cond + // Trigger this lint } else if a.contains("ha") { } else if a == "wow" { diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr index 81fbb921e846..a45e01d26227 100644 --- a/tests/ui/ifs_same_cond.stderr +++ b/tests/ui/ifs_same_cond.stderr @@ -13,37 +13,37 @@ LL | if b { = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:19:15 + --> tests/ui/ifs_same_cond.rs:20:15 | LL | } else if a == 1 { | ^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:18:8 + --> tests/ui/ifs_same_cond.rs:19:8 | LL | if a == 1 { | ^^^^^^ error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:25:15 + --> tests/ui/ifs_same_cond.rs:27:15 | LL | } else if 2 * a == 1 { | ^^^^^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:23:8 + --> tests/ui/ifs_same_cond.rs:25:8 | LL | if 2 * a == 1 { | ^^^^^^^^^^ error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:58:15 + --> tests/ui/ifs_same_cond.rs:61:15 | LL | } else if a.contains("ah") { | ^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:57:8 + --> tests/ui/ifs_same_cond.rs:60:8 | LL | if a.contains("ah") { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index 7f452cb46e06..423c8d501741 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -8,7 +8,8 @@ impl MyStruct { } impl MyStruct { - //~^ ERROR: multiple implementations of this structure +//~^ multiple_inherent_impl + fn second() {} } @@ -23,7 +24,8 @@ mod submod { } impl super::MyStruct { - //~^ ERROR: multiple implementations of this structure + //~^ multiple_inherent_impl + fn third() {} } } @@ -44,7 +46,8 @@ impl WithArgs { fn f2() {} } impl WithArgs { - //~^ ERROR: multiple implementations of this structure +//~^ multiple_inherent_impl + fn f3() {} } @@ -66,6 +69,7 @@ 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 +//~^ multiple_inherent_impl + fn main() {} diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr index bb906957a0d3..355927b78253 100644 --- a/tests/ui/impl.stderr +++ b/tests/ui/impl.stderr @@ -3,6 +3,7 @@ error: multiple implementations of this structure | LL | / impl MyStruct { LL | | +LL | | LL | | fn second() {} LL | | } | |_^ @@ -18,10 +19,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::multiple_inherent_impl)]` error: multiple implementations of this structure - --> tests/ui/impl.rs:25:5 + --> tests/ui/impl.rs:26:5 | LL | / impl super::MyStruct { LL | | +LL | | LL | | fn third() {} LL | | } | |_____^ @@ -35,16 +37,17 @@ LL | | } | |_^ error: multiple implementations of this structure - --> tests/ui/impl.rs:46:1 + --> tests/ui/impl.rs:48:1 | LL | / impl WithArgs { LL | | +LL | | LL | | fn f3() {} LL | | } | |_^ | note: first implementation here - --> tests/ui/impl.rs:43:1 + --> tests/ui/impl.rs:45:1 | LL | / impl WithArgs { LL | | fn f2() {} @@ -52,13 +55,13 @@ LL | | } | |_^ error: multiple implementations of this structure - --> tests/ui/impl.rs:68:1 + --> tests/ui/impl.rs:71:1 | LL | impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. | ^^^^^^^^^^^^^^^^^^^^^^ | note: first implementation here - --> tests/ui/impl.rs:65:1 + --> tests/ui/impl.rs:68:1 | LL | impl OneAllowedImpl {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl_trait_in_params.rs b/tests/ui/impl_trait_in_params.rs index a6251a370d1d..6d502a685bf7 100644 --- a/tests/ui/impl_trait_in_params.rs +++ b/tests/ui/impl_trait_in_params.rs @@ -7,9 +7,11 @@ pub trait AnotherTrait {} // Should warn pub fn a(_: impl Trait) {} -//~^ ERROR: `impl Trait` used as a function parameter +//~^ impl_trait_in_params + pub fn c(_: C, _: impl Trait) {} -//~^ ERROR: `impl Trait` used as a function parameter +//~^ impl_trait_in_params + // Shouldn't warn @@ -33,10 +35,12 @@ trait Private { struct S; impl S { - pub fn h(_: impl Trait) {} //~ ERROR: `impl Trait` used as a function parameter +pub fn h(_: impl Trait) {} +//~^ impl_trait_in_params fn i(_: impl Trait) {} pub fn j(_: J) {} - pub fn k>(_: K, _: impl AnotherTrait) {} //~ ERROR: `impl Trait` used as a function parameter +pub fn k>(_: K, _: impl AnotherTrait) {} +//~^ impl_trait_in_params } // Trying with traits diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr index 0ec0a34ea8db..ad735d034317 100644 --- a/tests/ui/impl_trait_in_params.stderr +++ b/tests/ui/impl_trait_in_params.stderr @@ -12,7 +12,7 @@ LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {} | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> tests/ui/impl_trait_in_params.rs:11:29 + --> tests/ui/impl_trait_in_params.rs:12:29 | LL | pub fn c(_: C, _: impl Trait) {} | ^^^^^^^^^^ @@ -23,26 +23,26 @@ LL | pub fn c(_: C, _: impl Trait) {} | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> tests/ui/impl_trait_in_params.rs:36:17 + --> tests/ui/impl_trait_in_params.rs:38:13 | -LL | pub fn h(_: impl Trait) {} - | ^^^^^^^^^^ +LL | pub fn h(_: impl Trait) {} + | ^^^^^^^^^^ | help: add a type parameter | -LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {} - | +++++++++++++++++++++++++++++++ +LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {} + | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> tests/ui/impl_trait_in_params.rs:39:45 + --> tests/ui/impl_trait_in_params.rs:42:41 | -LL | pub fn k>(_: K, _: impl AnotherTrait) {} - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | pub fn k>(_: K, _: impl AnotherTrait) {} + | ^^^^^^^^^^^^^^^^^^^^^^ | help: add a type parameter | -LL | pub fn k, { /* Generic name */ }: AnotherTrait>(_: K, _: impl AnotherTrait) {} - | +++++++++++++++++++++++++++++++++++++++++++ +LL | pub fn k, { /* Generic name */ }: AnotherTrait>(_: K, _: impl AnotherTrait) {} + | +++++++++++++++++++++++++++++++++++++++++++ error: aborting due to 4 previous errors diff --git a/tests/ui/implicit_clone.fixed b/tests/ui/implicit_clone.fixed index 98556b4dd303..d60d1cb0ec04 100644 --- a/tests/ui/implicit_clone.fixed +++ b/tests/ui/implicit_clone.fixed @@ -63,12 +63,15 @@ fn main() { let vec = vec![5]; let _ = return_owned_from_slice(&vec); let _ = vec.clone(); + //~^ implicit_clone let _ = vec.clone(); + //~^ implicit_clone let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); let _ = vec_ref.to_owned(); let _ = vec_ref.clone(); + //~^ implicit_clone // we expect no lint for this let _ = weird::to_vec(&vec); @@ -81,10 +84,12 @@ fn main() { let str = "hello world".to_string(); let _ = str.clone(); + //~^ implicit_clone // testing w/ an arbitrary type let kitten = Kitten {}; let _ = kitten.clone(); + //~^ implicit_clone let _ = own_same_from_ref(&kitten); // this shouldn't lint let _ = kitten.to_vec(); @@ -95,11 +100,15 @@ fn main() { let pathbuf = PathBuf::new(); let _ = pathbuf.clone(); + //~^ implicit_clone let _ = pathbuf.clone(); + //~^ implicit_clone let os_string = OsString::from("foo"); let _ = os_string.clone(); + //~^ implicit_clone let _ = os_string.clone(); + //~^ implicit_clone // we expect no lints for this let os_str = OsStr::new("foo"); @@ -111,9 +120,11 @@ fn main() { let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf` let _ = (*pathbuf_ref).clone(); + //~^ implicit_clone let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf` let _ = (**pathbuf_ref).clone(); + //~^ implicit_clone struct NoClone; impl ToOwned for NoClone { diff --git a/tests/ui/implicit_clone.rs b/tests/ui/implicit_clone.rs index a064bd23a338..b96828f28c82 100644 --- a/tests/ui/implicit_clone.rs +++ b/tests/ui/implicit_clone.rs @@ -63,12 +63,15 @@ fn main() { let vec = vec![5]; let _ = return_owned_from_slice(&vec); let _ = vec.to_owned(); + //~^ implicit_clone let _ = vec.to_vec(); + //~^ implicit_clone let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); let _ = vec_ref.to_owned(); let _ = vec_ref.to_vec(); + //~^ implicit_clone // we expect no lint for this let _ = weird::to_vec(&vec); @@ -81,10 +84,12 @@ fn main() { let str = "hello world".to_string(); let _ = str.to_owned(); + //~^ implicit_clone // testing w/ an arbitrary type let kitten = Kitten {}; let _ = kitten.to_owned(); + //~^ implicit_clone let _ = own_same_from_ref(&kitten); // this shouldn't lint let _ = kitten.to_vec(); @@ -95,11 +100,15 @@ fn main() { let pathbuf = PathBuf::new(); let _ = pathbuf.to_owned(); + //~^ implicit_clone let _ = pathbuf.to_path_buf(); + //~^ implicit_clone let os_string = OsString::from("foo"); let _ = os_string.to_owned(); + //~^ implicit_clone let _ = os_string.to_os_string(); + //~^ implicit_clone // we expect no lints for this let os_str = OsStr::new("foo"); @@ -111,9 +120,11 @@ fn main() { let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf` let _ = pathbuf_ref.to_path_buf(); + //~^ implicit_clone let pathbuf_ref = &pathbuf_ref; let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf` let _ = pathbuf_ref.to_path_buf(); + //~^ implicit_clone struct NoClone; impl ToOwned for NoClone { diff --git a/tests/ui/implicit_clone.stderr b/tests/ui/implicit_clone.stderr index 31c212eba2c8..1eb6ff1fe429 100644 --- a/tests/ui/implicit_clone.stderr +++ b/tests/ui/implicit_clone.stderr @@ -8,61 +8,61 @@ LL | let _ = vec.to_owned(); = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> tests/ui/implicit_clone.rs:66:13 + --> tests/ui/implicit_clone.rs:67:13 | LL | let _ = vec.to_vec(); | ^^^^^^^^^^^^ help: consider using: `vec.clone()` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> tests/ui/implicit_clone.rs:71:13 + --> tests/ui/implicit_clone.rs:73: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 - --> tests/ui/implicit_clone.rs:83:13 + --> tests/ui/implicit_clone.rs:86:13 | LL | let _ = str.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `str.clone()` error: implicitly cloning a `Kitten` by calling `to_owned` on its dereferenced type - --> tests/ui/implicit_clone.rs:87:13 + --> tests/ui/implicit_clone.rs:91:13 | LL | let _ = kitten.to_owned(); | ^^^^^^^^^^^^^^^^^ help: consider using: `kitten.clone()` error: implicitly cloning a `PathBuf` by calling `to_owned` on its dereferenced type - --> tests/ui/implicit_clone.rs:97:13 + --> tests/ui/implicit_clone.rs:102: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 - --> tests/ui/implicit_clone.rs:98:13 + --> tests/ui/implicit_clone.rs:104: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 - --> tests/ui/implicit_clone.rs:101:13 + --> tests/ui/implicit_clone.rs:108: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 - --> tests/ui/implicit_clone.rs:102:13 + --> tests/ui/implicit_clone.rs:110: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 - --> tests/ui/implicit_clone.rs:113:13 + --> tests/ui/implicit_clone.rs:122: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 - --> tests/ui/implicit_clone.rs:116:13 + --> tests/ui/implicit_clone.rs:126:13 | LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(**pathbuf_ref).clone()` diff --git a/tests/ui/implicit_hasher.fixed b/tests/ui/implicit_hasher.fixed index 971746ae95d7..fd6c4ffc9122 100644 --- a/tests/ui/implicit_hasher.fixed +++ b/tests/ui/implicit_hasher.fixed @@ -13,6 +13,7 @@ pub trait Foo: Sized { } impl Foo for HashMap { +//~^ implicit_hasher fn make() -> (Self, Self) { // OK, don't suggest to modify these let _: HashMap = HashMap::new(); @@ -22,11 +23,13 @@ impl Foo for HashMap } } impl Foo for (HashMap,) { +//~^ implicit_hasher fn make() -> (Self, Self) { ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) } } impl Foo for HashMap { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) } @@ -44,11 +47,13 @@ impl Foo for HashMap { } impl Foo for HashSet { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) } } impl Foo for HashSet { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) } @@ -66,14 +71,17 @@ impl Foo for HashSet { } pub fn map(map: &mut HashMap) {} +//~^ implicit_hasher pub fn set(set: &mut HashSet) {} +//~^ implicit_hasher #[inline_macros] pub mod gen_ { use super::*; inline! { impl Foo for HashMap { + //~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) } @@ -98,5 +106,6 @@ external! { // #7712 pub async fn election_vote(_data: HashMap) {} +//~^ implicit_hasher fn main() {} diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs index b34aa1f81374..29a1afd2efc8 100644 --- a/tests/ui/implicit_hasher.rs +++ b/tests/ui/implicit_hasher.rs @@ -13,6 +13,7 @@ pub trait Foo: Sized { } impl Foo for HashMap { +//~^ implicit_hasher fn make() -> (Self, Self) { // OK, don't suggest to modify these let _: HashMap = HashMap::new(); @@ -22,11 +23,13 @@ impl Foo for HashMap { } } impl Foo for (HashMap,) { +//~^ implicit_hasher fn make() -> (Self, Self) { ((HashMap::new(),), (HashMap::with_capacity(10),)) } } impl Foo for HashMap { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::new(), HashMap::with_capacity(10)) } @@ -44,11 +47,13 @@ impl Foo for HashMap { } impl Foo for HashSet { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::new(), HashSet::with_capacity(10)) } } impl Foo for HashSet { +//~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::new(), HashSet::with_capacity(10)) } @@ -66,14 +71,17 @@ impl Foo for HashSet { } pub fn map(map: &mut HashMap) {} +//~^ implicit_hasher pub fn set(set: &mut HashSet) {} +//~^ implicit_hasher #[inline_macros] pub mod gen_ { use super::*; inline! { impl Foo for HashMap { + //~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::new(), HashMap::with_capacity(10)) } @@ -98,5 +106,6 @@ external! { // #7712 pub async fn election_vote(_data: HashMap) {} +//~^ implicit_hasher fn main() {} diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 442f4789aacf..a4b2b5066daf 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -12,14 +12,14 @@ LL | #![deny(clippy::implicit_hasher)] help: add a type parameter for `BuildHasher` | LL ~ impl Foo for HashMap { -LL | fn make() -> (Self, Self) { +LL | ... LL | LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) | error: impl for `HashMap` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:24:36 + --> tests/ui/implicit_hasher.rs:25:36 | LL | impl Foo for (HashMap,) { | ^^^^^^^^^^^^^ @@ -27,12 +27,13 @@ LL | impl Foo for (HashMap,) { help: add a type parameter for `BuildHasher` | LL ~ impl Foo for (HashMap,) { +LL | LL | fn make() -> (Self, Self) { LL ~ ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) | error: impl for `HashMap` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:29:19 + --> tests/ui/implicit_hasher.rs:31:19 | LL | impl Foo for HashMap { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,12 +41,13 @@ LL | impl Foo for HashMap { help: add a type parameter for `BuildHasher` | LL ~ impl Foo for HashMap { +LL | LL | fn make() -> (Self, Self) { LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) | error: impl for `HashSet` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:46:32 + --> tests/ui/implicit_hasher.rs:49:32 | LL | impl Foo for HashSet { | ^^^^^^^^^^ @@ -53,12 +55,13 @@ LL | impl Foo for HashSet { help: add a type parameter for `BuildHasher` | LL ~ impl Foo for HashSet { +LL | LL | fn make() -> (Self, Self) { LL ~ (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) | error: impl for `HashSet` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:51:19 + --> tests/ui/implicit_hasher.rs:55:19 | LL | impl Foo for HashSet { | ^^^^^^^^^^^^^^^ @@ -66,12 +69,13 @@ LL | impl Foo for HashSet { help: add a type parameter for `BuildHasher` | LL ~ impl Foo for HashSet { +LL | LL | fn make() -> (Self, Self) { LL ~ (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) | error: parameter of type `HashMap` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:68:22 + --> tests/ui/implicit_hasher.rs:73:22 | LL | pub fn map(map: &mut HashMap) {} | ^^^^^^^^^^^^^^^^^ @@ -82,7 +86,7 @@ LL | pub fn map(map: &mut HashMap) {} | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ error: parameter of type `HashSet` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:70:22 + --> tests/ui/implicit_hasher.rs:76:22 | LL | pub fn set(set: &mut HashSet) {} | ^^^^^^^^^^^^ @@ -93,7 +97,7 @@ LL | pub fn set(set: &mut HashSet) {} | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ error: impl for `HashMap` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:76:43 + --> tests/ui/implicit_hasher.rs:83:43 | LL | impl Foo for HashMap { | ^^^^^^^^^^^^^ @@ -102,12 +106,13 @@ LL | impl Foo for HashMap { help: add a type parameter for `BuildHasher` | LL ~ impl Foo for HashMap { +LL | LL | fn make() -> (Self, Self) { LL ~ (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) | error: parameter of type `HashMap` should be generalized over different hashers - --> tests/ui/implicit_hasher.rs:100:35 + --> tests/ui/implicit_hasher.rs:108:35 | LL | pub async fn election_vote(_data: HashMap) {} | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index 56fe29b4e677..1cb639b60a9a 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -13,17 +13,22 @@ fn test_end_of_fn() -> bool { } return true + //~^ implicit_return } fn test_if_block() -> bool { if true { return true } else { return false } + //~^ implicit_return + //~| implicit_return } #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { true => return false, + //~^ implicit_return false => { return true }, + //~^ implicit_return } } @@ -37,6 +42,7 @@ fn test_match_with_unreachable(x: bool) -> bool { fn test_loop() -> bool { loop { return true; + //~^ implicit_return } } @@ -44,6 +50,7 @@ fn test_loop_with_block() -> bool { loop { { return true; + //~^ implicit_return } } } @@ -52,6 +59,7 @@ fn test_loop_with_nests() -> bool { loop { if true { return true; + //~^ implicit_return } else { let _ = true; } @@ -70,7 +78,9 @@ fn test_loop_with_if_let() -> bool { fn test_closure() { #[rustfmt::skip] let _ = || { return true }; + //~^ implicit_return let _ = || return true; + //~^ implicit_return } fn test_panic() -> bool { @@ -79,6 +89,7 @@ fn test_panic() -> bool { fn test_return_macro() -> String { return format!("test {}", "test") + //~^ implicit_return } fn macro_branch_test() -> bool { @@ -88,17 +99,20 @@ fn macro_branch_test() -> bool { }; } return m!(true, false) + //~^ implicit_return } fn loop_test() -> bool { 'outer: loop { if true { return true; + //~^ implicit_return } let _ = loop { if false { return false; + //~^ implicit_return } if true { break true; @@ -117,6 +131,7 @@ fn loop_macro_test() -> bool { m!(true); } } +//~^^^^ implicit_return fn divergent_test() -> bool { fn diverge() -> ! { @@ -128,6 +143,7 @@ fn divergent_test() -> bool { // issue #6940 async fn foo() -> bool { return true + //~^ implicit_return } fn main() {} diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index f066ce20cfd1..99d75e4987e4 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -13,17 +13,22 @@ fn test_end_of_fn() -> bool { } true + //~^ implicit_return } fn test_if_block() -> bool { if true { true } else { false } + //~^ implicit_return + //~| implicit_return } #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { true => false, + //~^ implicit_return false => { true }, + //~^ implicit_return } } @@ -37,6 +42,7 @@ fn test_match_with_unreachable(x: bool) -> bool { fn test_loop() -> bool { loop { break true; + //~^ implicit_return } } @@ -44,6 +50,7 @@ fn test_loop_with_block() -> bool { loop { { break true; + //~^ implicit_return } } } @@ -52,6 +59,7 @@ fn test_loop_with_nests() -> bool { loop { if true { break true; + //~^ implicit_return } else { let _ = true; } @@ -70,7 +78,9 @@ fn test_loop_with_if_let() -> bool { fn test_closure() { #[rustfmt::skip] let _ = || { true }; + //~^ implicit_return let _ = || true; + //~^ implicit_return } fn test_panic() -> bool { @@ -79,6 +89,7 @@ fn test_panic() -> bool { fn test_return_macro() -> String { format!("test {}", "test") + //~^ implicit_return } fn macro_branch_test() -> bool { @@ -88,17 +99,20 @@ fn macro_branch_test() -> bool { }; } m!(true, false) + //~^ implicit_return } fn loop_test() -> bool { 'outer: loop { if true { break true; + //~^ implicit_return } let _ = loop { if false { break 'outer false; + //~^ implicit_return } if true { break true; @@ -117,6 +131,7 @@ fn loop_macro_test() -> bool { m!(true); } } +//~^^^^ implicit_return fn divergent_test() -> bool { fn diverge() -> ! { @@ -128,6 +143,7 @@ fn divergent_test() -> bool { // issue #6940 async fn foo() -> bool { true + //~^ implicit_return } fn main() {} diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 3b06f26f5a05..940324c25491 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -12,7 +12,7 @@ LL | return true | error: missing `return` statement - --> tests/ui/implicit_return.rs:19:15 + --> tests/ui/implicit_return.rs:20:15 | LL | if true { true } else { false } | ^^^^ @@ -23,7 +23,7 @@ LL | if true { return true } else { false } | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:19:29 + --> tests/ui/implicit_return.rs:20:29 | LL | if true { true } else { false } | ^^^^^ @@ -34,7 +34,7 @@ LL | if true { true } else { return false } | ~~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:25:17 + --> tests/ui/implicit_return.rs:28:17 | LL | true => false, | ^^^^^ @@ -45,7 +45,7 @@ LL | true => return false, | ~~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:26:20 + --> tests/ui/implicit_return.rs:30:20 | LL | false => { true }, | ^^^^ @@ -56,7 +56,7 @@ LL | false => { return true }, | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:39:9 + --> tests/ui/implicit_return.rs:44:9 | LL | break true; | ^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | return true; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:46:13 + --> tests/ui/implicit_return.rs:52:13 | LL | break true; | ^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | return true; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:54:13 + --> tests/ui/implicit_return.rs:61:13 | LL | break true; | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | return true; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:72:18 + --> tests/ui/implicit_return.rs:80:18 | LL | let _ = || { true }; | ^^^^ @@ -100,7 +100,7 @@ LL | let _ = || { return true }; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:73:16 + --> tests/ui/implicit_return.rs:82:16 | LL | let _ = || true; | ^^^^ @@ -111,7 +111,7 @@ LL | let _ = || return true; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:81:5 + --> tests/ui/implicit_return.rs:91:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | return format!("test {}", "test") | error: missing `return` statement - --> tests/ui/implicit_return.rs:90:5 + --> tests/ui/implicit_return.rs:101:5 | LL | m!(true, false) | ^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | return m!(true, false) | error: missing `return` statement - --> tests/ui/implicit_return.rs:96:13 + --> tests/ui/implicit_return.rs:108:13 | LL | break true; | ^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | return true; | ~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:101:17 + --> tests/ui/implicit_return.rs:114:17 | LL | break 'outer false; | ^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | return false; | ~~~~~~~~~~~~ error: missing `return` statement - --> tests/ui/implicit_return.rs:116:5 + --> tests/ui/implicit_return.rs:130:5 | LL | / loop { LL | | m!(true); @@ -170,7 +170,7 @@ LL + } | error: missing `return` statement - --> tests/ui/implicit_return.rs:130:5 + --> tests/ui/implicit_return.rs:145:5 | LL | true | ^^^^ diff --git a/tests/ui/implicit_saturating_add.rs b/tests/ui/implicit_saturating_add.rs index 94513f34c262..2396db8daa0c 100644 --- a/tests/ui/implicit_saturating_add.rs +++ b/tests/ui/implicit_saturating_add.rs @@ -19,10 +19,12 @@ fn main() { } if u_8 != u8::MAX { + //~^ implicit_saturating_add u_8 += 1; } if u_8 < u8::MAX { + //~^ implicit_saturating_add u_8 += 1; } @@ -31,86 +33,107 @@ fn main() { } if u_16 != u16::MAX { + //~^ implicit_saturating_add u_16 += 1; } if u_16 < u16::MAX { + //~^ implicit_saturating_add u_16 += 1; } if u16::MAX > u_16 { + //~^ implicit_saturating_add u_16 += 1; } if u_32 != u32::MAX { + //~^ implicit_saturating_add u_32 += 1; } if u_32 < u32::MAX { + //~^ implicit_saturating_add u_32 += 1; } if u32::MAX > u_32 { + //~^ implicit_saturating_add u_32 += 1; } if u_64 != u64::MAX { + //~^ implicit_saturating_add u_64 += 1; } if u_64 < u64::MAX { + //~^ implicit_saturating_add u_64 += 1; } if u64::MAX > u_64 { + //~^ implicit_saturating_add u_64 += 1; } if i_8 != i8::MAX { + //~^ implicit_saturating_add i_8 += 1; } if i_8 < i8::MAX { + //~^ implicit_saturating_add i_8 += 1; } if i8::MAX > i_8 { + //~^ implicit_saturating_add i_8 += 1; } if i_16 != i16::MAX { + //~^ implicit_saturating_add i_16 += 1; } if i_16 < i16::MAX { + //~^ implicit_saturating_add i_16 += 1; } if i16::MAX > i_16 { + //~^ implicit_saturating_add i_16 += 1; } if i_32 != i32::MAX { + //~^ implicit_saturating_add i_32 += 1; } if i_32 < i32::MAX { + //~^ implicit_saturating_add i_32 += 1; } if i32::MAX > i_32 { + //~^ implicit_saturating_add i_32 += 1; } if i_64 != i64::MAX { + //~^ implicit_saturating_add i_64 += 1; } if i_64 < i64::MAX { + //~^ implicit_saturating_add i_64 += 1; } if i64::MAX > i_64 { + //~^ implicit_saturating_add i_64 += 1; } @@ -147,6 +170,7 @@ fn main() { if u_32 < 42 { println!("brace yourself!"); } else if u_32 < u32::MAX { + //~^ implicit_saturating_add u_32 += 1; } } diff --git a/tests/ui/implicit_saturating_add.stderr b/tests/ui/implicit_saturating_add.stderr index 4fb9282bc91d..8ae7dc4b884b 100644 --- a/tests/ui/implicit_saturating_add.stderr +++ b/tests/ui/implicit_saturating_add.stderr @@ -2,6 +2,7 @@ error: manual saturating add detected --> tests/ui/implicit_saturating_add.rs:21:5 | LL | / if u_8 != u8::MAX { +LL | | LL | | u_8 += 1; LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` @@ -10,33 +11,28 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_add)]` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:25:5 + --> tests/ui/implicit_saturating_add.rs:26:5 | LL | / if u_8 < u8::MAX { +LL | | LL | | u_8 += 1; LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:33:5 + --> tests/ui/implicit_saturating_add.rs:35:5 | LL | / if u_16 != u16::MAX { +LL | | LL | | u_16 += 1; LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:37:5 + --> tests/ui/implicit_saturating_add.rs:40:5 | LL | / if u_16 < u16::MAX { -LL | | u_16 += 1; -LL | | } - | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:41:5 - | -LL | / if u16::MAX > u_16 { +LL | | LL | | u_16 += 1; LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` @@ -44,152 +40,180 @@ LL | | } error: manual saturating add detected --> tests/ui/implicit_saturating_add.rs:45:5 | +LL | / if u16::MAX > u_16 { +LL | | +LL | | u_16 += 1; +LL | | } + | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:50:5 + | LL | / if u_32 != u32::MAX { +LL | | LL | | u_32 += 1; LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:49:5 + --> tests/ui/implicit_saturating_add.rs:55:5 | LL | / if u_32 < u32::MAX { +LL | | LL | | u_32 += 1; LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:53:5 + --> tests/ui/implicit_saturating_add.rs:60:5 | LL | / if u32::MAX > u_32 { +LL | | LL | | u_32 += 1; LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:57:5 - | -LL | / if u_64 != u64::MAX { -LL | | u_64 += 1; -LL | | } - | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:61:5 - | -LL | / if u_64 < u64::MAX { -LL | | u_64 += 1; -LL | | } - | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` - error: manual saturating add detected --> tests/ui/implicit_saturating_add.rs:65:5 | -LL | / if u64::MAX > u_64 { +LL | / if u_64 != u64::MAX { +LL | | LL | | u_64 += 1; LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:69:5 + --> tests/ui/implicit_saturating_add.rs:70:5 + | +LL | / if u_64 < u64::MAX { +LL | | +LL | | u_64 += 1; +LL | | } + | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:75:5 + | +LL | / if u64::MAX > u_64 { +LL | | +LL | | u_64 += 1; +LL | | } + | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:80:5 | LL | / if i_8 != i8::MAX { +LL | | LL | | i_8 += 1; LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:73:5 - | -LL | / if i_8 < i8::MAX { -LL | | i_8 += 1; -LL | | } - | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:77:5 - | -LL | / if i8::MAX > i_8 { -LL | | i_8 += 1; -LL | | } - | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:81:5 - | -LL | / if i_16 != i16::MAX { -LL | | i_16 += 1; -LL | | } - | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` - error: manual saturating add detected --> tests/ui/implicit_saturating_add.rs:85:5 | +LL | / if i_8 < i8::MAX { +LL | | +LL | | i_8 += 1; +LL | | } + | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:90:5 + | +LL | / if i8::MAX > i_8 { +LL | | +LL | | i_8 += 1; +LL | | } + | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:95:5 + | +LL | / if i_16 != i16::MAX { +LL | | +LL | | i_16 += 1; +LL | | } + | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:100:5 + | LL | / if i_16 < i16::MAX { +LL | | LL | | i_16 += 1; LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:89:5 - | -LL | / if i16::MAX > i_16 { -LL | | i_16 += 1; -LL | | } - | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:93:5 - | -LL | / if i_32 != i32::MAX { -LL | | i_32 += 1; -LL | | } - | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:97:5 - | -LL | / if i_32 < i32::MAX { -LL | | i_32 += 1; -LL | | } - | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` - -error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:101:5 - | -LL | / if i32::MAX > i_32 { -LL | | i_32 += 1; -LL | | } - | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` - error: manual saturating add detected --> tests/ui/implicit_saturating_add.rs:105:5 | +LL | / if i16::MAX > i_16 { +LL | | +LL | | i_16 += 1; +LL | | } + | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:110:5 + | +LL | / if i_32 != i32::MAX { +LL | | +LL | | i_32 += 1; +LL | | } + | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:115:5 + | +LL | / if i_32 < i32::MAX { +LL | | +LL | | i_32 += 1; +LL | | } + | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:120:5 + | +LL | / if i32::MAX > i_32 { +LL | | +LL | | i_32 += 1; +LL | | } + | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` + +error: manual saturating add detected + --> tests/ui/implicit_saturating_add.rs:125:5 + | LL | / if i_64 != i64::MAX { +LL | | LL | | i_64 += 1; LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:109:5 + --> tests/ui/implicit_saturating_add.rs:130:5 | LL | / if i_64 < i64::MAX { +LL | | LL | | i_64 += 1; LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:113:5 + --> tests/ui/implicit_saturating_add.rs:135:5 | LL | / if i64::MAX > i_64 { +LL | | LL | | i_64 += 1; LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> tests/ui/implicit_saturating_add.rs:149:12 + --> tests/ui/implicit_saturating_add.rs:172:12 | LL | } else if u_32 < u32::MAX { | ____________^ +LL | | LL | | u_32 += 1; LL | | } | |_____^ help: use instead: `{u_32 = u_32.saturating_add(1); }` diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index e371e37fb2f6..5b7221b7060f 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -25,6 +25,7 @@ fn main() { // Lint if u_8 > 0 { + //~^ implicit_saturating_sub u_8 = u_8 - 1; } @@ -32,6 +33,7 @@ fn main() { 10 => { // Lint if u_8 > 0 { + //~^ implicit_saturating_sub u_8 -= 1; } }, @@ -46,6 +48,7 @@ fn main() { // Lint if u_16 > 0 { + //~^ implicit_saturating_sub u_16 -= 1; } @@ -56,6 +59,7 @@ fn main() { // Lint if u_32 != 0 { + //~^ implicit_saturating_sub u_32 -= 1; } @@ -77,16 +81,19 @@ fn main() { // Lint if u_64 > 0 { + //~^ implicit_saturating_sub u_64 -= 1; } // Lint if 0 < u_64 { + //~^ implicit_saturating_sub u_64 -= 1; } // Lint if 0 != u_64 { + //~^ implicit_saturating_sub u_64 -= 1; } @@ -108,6 +115,7 @@ fn main() { // Lint if u_usize > 0 { + //~^ implicit_saturating_sub u_usize -= 1; } @@ -120,21 +128,25 @@ fn main() { // Lint if i_8 > i8::MIN { + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 > i8::MIN { + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 != i8::MIN { + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 != i8::MIN { + //~^ implicit_saturating_sub i_8 -= 1; } @@ -145,21 +157,25 @@ fn main() { // Lint if i_16 > i16::MIN { + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 > i16::MIN { + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 != i16::MIN { + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 != i16::MIN { + //~^ implicit_saturating_sub i_16 -= 1; } @@ -170,21 +186,25 @@ fn main() { // Lint if i_32 > i32::MIN { + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 > i32::MIN { + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 != i32::MIN { + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 != i32::MIN { + //~^ implicit_saturating_sub i_32 -= 1; } @@ -195,16 +215,19 @@ fn main() { // Lint if i64::MIN < i_64 { + //~^ implicit_saturating_sub i_64 -= 1; } // Lint if i64::MIN != i_64 { + //~^ implicit_saturating_sub i_64 -= 1; } // Lint if i64::MIN < i_64 { + //~^ implicit_saturating_sub i_64 -= 1; } @@ -273,6 +296,7 @@ fn regression_13524(a: usize, b: usize, c: bool) -> usize { if c { 123 } else if a >= b { + //~^ implicit_saturating_sub 0 } else { b - a diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index 613198512280..f9c94d3ad841 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -2,6 +2,7 @@ error: implicitly performing saturating subtraction --> tests/ui/implicit_saturating_sub.rs:27:5 | LL | / if u_8 > 0 { +LL | | LL | | u_8 = u_8 - 1; LL | | } | |_____^ help: try: `u_8 = u_8.saturating_sub(1);` @@ -10,41 +11,37 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:34:13 + --> tests/ui/implicit_saturating_sub.rs:35:13 | LL | / if u_8 > 0 { +LL | | LL | | u_8 -= 1; LL | | } | |_____________^ help: try: `u_8 = u_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:48:5 + --> tests/ui/implicit_saturating_sub.rs:50:5 | LL | / if u_16 > 0 { +LL | | LL | | u_16 -= 1; LL | | } | |_____^ help: try: `u_16 = u_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:58:5 + --> tests/ui/implicit_saturating_sub.rs:61:5 | LL | / if u_32 != 0 { +LL | | LL | | u_32 -= 1; LL | | } | |_____^ help: try: `u_32 = u_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:79:5 + --> tests/ui/implicit_saturating_sub.rs:83:5 | LL | / if u_64 > 0 { -LL | | u_64 -= 1; -LL | | } - | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:84:5 - | -LL | / if 0 < u_64 { +LL | | LL | | u_64 -= 1; LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` @@ -52,144 +49,171 @@ LL | | } error: implicitly performing saturating subtraction --> tests/ui/implicit_saturating_sub.rs:89:5 | -LL | / if 0 != u_64 { +LL | / if 0 < u_64 { +LL | | LL | | u_64 -= 1; LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:110:5 + --> tests/ui/implicit_saturating_sub.rs:95:5 + | +LL | / if 0 != u_64 { +LL | | +LL | | u_64 -= 1; +LL | | } + | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` + +error: implicitly performing saturating subtraction + --> tests/ui/implicit_saturating_sub.rs:117:5 | LL | / if u_usize > 0 { +LL | | LL | | u_usize -= 1; LL | | } | |_____^ help: try: `u_usize = u_usize.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:122:5 + --> tests/ui/implicit_saturating_sub.rs:130:5 | LL | / if i_8 > i8::MIN { +LL | | LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:127:5 + --> tests/ui/implicit_saturating_sub.rs:136:5 | LL | / if i_8 > i8::MIN { +LL | | LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:132:5 + --> tests/ui/implicit_saturating_sub.rs:142:5 | LL | / if i_8 != i8::MIN { +LL | | LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:137:5 + --> tests/ui/implicit_saturating_sub.rs:148:5 | LL | / if i_8 != i8::MIN { +LL | | LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:147:5 + --> tests/ui/implicit_saturating_sub.rs:159:5 | LL | / if i_16 > i16::MIN { +LL | | LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:152:5 + --> tests/ui/implicit_saturating_sub.rs:165:5 | LL | / if i_16 > i16::MIN { +LL | | LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:157:5 + --> tests/ui/implicit_saturating_sub.rs:171:5 | LL | / if i_16 != i16::MIN { +LL | | LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` -error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:162:5 - | -LL | / if i_16 != i16::MIN { -LL | | i_16 -= 1; -LL | | } - | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` - -error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:172:5 - | -LL | / if i_32 > i32::MIN { -LL | | i_32 -= 1; -LL | | } - | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` - error: implicitly performing saturating subtraction --> tests/ui/implicit_saturating_sub.rs:177:5 | +LL | / if i_16 != i16::MIN { +LL | | +LL | | i_16 -= 1; +LL | | } + | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` + +error: implicitly performing saturating subtraction + --> tests/ui/implicit_saturating_sub.rs:188:5 + | LL | / if i_32 > i32::MIN { +LL | | LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:182:5 + --> tests/ui/implicit_saturating_sub.rs:194:5 + | +LL | / if i_32 > i32::MIN { +LL | | +LL | | i_32 -= 1; +LL | | } + | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` + +error: implicitly performing saturating subtraction + --> tests/ui/implicit_saturating_sub.rs:200:5 | LL | / if i_32 != i32::MIN { +LL | | LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:187:5 + --> tests/ui/implicit_saturating_sub.rs:206:5 | LL | / if i_32 != i32::MIN { +LL | | LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:197:5 + --> tests/ui/implicit_saturating_sub.rs:217:5 | LL | / if i64::MIN < i_64 { +LL | | LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:202:5 + --> tests/ui/implicit_saturating_sub.rs:223:5 | LL | / if i64::MIN != i_64 { +LL | | LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> tests/ui/implicit_saturating_sub.rs:207:5 + --> tests/ui/implicit_saturating_sub.rs:229:5 | LL | / if i64::MIN < i_64 { +LL | | LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: manual arithmetic check found - --> tests/ui/implicit_saturating_sub.rs:275:12 + --> tests/ui/implicit_saturating_sub.rs:298:12 | LL | } else if a >= b { | ____________^ +LL | | LL | | 0 LL | | } else { LL | | b - a diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed index 6fd4cbd80fe4..fe44d7c64b6e 100644 --- a/tests/ui/implied_bounds_in_impls.fixed +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -11,6 +11,7 @@ fn normal_deref(x: T) -> impl Deref { // Deref implied by DerefMut fn deref_derefmut(x: T) -> impl DerefMut { +//~^ implied_bounds_in_impls Box::new(x) } @@ -28,14 +29,19 @@ impl GenericSubtrait<(), i32, V> for () {} impl GenericSubtrait<(), i64, V> for () {} fn generics_implied() -> impl GenericSubtrait +//~^ implied_bounds_in_impls where (): GenericSubtrait, { } fn generics_implied_multi() -> impl GenericSubtrait<(), i32, V> {} +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls fn generics_implied_multi2() -> impl GenericSubtrait<(), T, V> +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls where (): GenericSubtrait<(), T, V> + GenericTrait, { @@ -46,21 +52,25 @@ fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> // i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} +//~^ implied_bounds_in_impls trait SomeTrait { // Check that it works in trait declarations. fn f() -> impl DerefMut; + //~^ implied_bounds_in_impls } struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. fn f() -> impl DerefMut { + //~^ implied_bounds_in_impls Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. fn f() -> impl DerefMut { + //~^ implied_bounds_in_impls Box::new(42) } } @@ -72,7 +82,9 @@ mod issue11422 { // `PartialOrd` has a default generic parameter and does not need to be explicitly specified. // This needs special handling. fn default_generic_param1() -> impl PartialOrd + Debug {} + //~^ implied_bounds_in_impls fn default_generic_param2() -> impl PartialOrd + Debug {} + //~^ implied_bounds_in_impls // Referring to `Self` in the supertrait clause needs special handling. trait Trait1 {} @@ -86,11 +98,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion fn my_iter() -> impl DoubleEndedIterator { + //~^ implied_bounds_in_impls 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion fn f() -> impl Copy { + //~^ implied_bounds_in_impls 1 } @@ -105,6 +119,7 @@ mod issue11435 { // When the other trait has generics, it shouldn't add another pair of `<>` fn f2() -> impl Trait2 {} + //~^ implied_bounds_in_impls trait Trait3 { type X; @@ -120,6 +135,7 @@ mod issue11435 { // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved // over fn f3() -> impl Trait4 {} + //~^ implied_bounds_in_impls } fn issue11880() { @@ -147,14 +163,19 @@ fn issue11880() { // X::T is never constrained in the first place, so it can be omitted // and left unconstrained fn f3() -> impl Y {} + //~^ implied_bounds_in_impls fn f4() -> impl Y {} + //~^ implied_bounds_in_impls fn f5() -> impl Y {} + //~^ implied_bounds_in_impls } fn apit(_: impl DerefMut) {} +//~^ implied_bounds_in_impls trait Rpitit { fn f() -> impl DerefMut; + //~^ implied_bounds_in_impls } trait Atpit { @@ -163,12 +184,14 @@ trait Atpit { } impl Atpit for () { type Assoc = impl DerefMut; + //~^ implied_bounds_in_impls fn define() -> Self::Assoc { &mut [] as &mut [()] } } type Tait = impl DerefMut; +//~^ implied_bounds_in_impls fn define() -> Tait { &mut [] as &mut [()] } diff --git a/tests/ui/implied_bounds_in_impls.rs b/tests/ui/implied_bounds_in_impls.rs index 52076c9f998e..0e100262d2d9 100644 --- a/tests/ui/implied_bounds_in_impls.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -11,6 +11,7 @@ fn normal_deref(x: T) -> impl Deref { // Deref implied by DerefMut fn deref_derefmut(x: T) -> impl Deref + DerefMut { +//~^ implied_bounds_in_impls Box::new(x) } @@ -28,14 +29,19 @@ impl GenericSubtrait<(), i32, V> for () {} impl GenericSubtrait<(), i64, V> for () {} fn generics_implied() -> impl GenericTrait + GenericSubtrait +//~^ implied_bounds_in_impls where (): GenericSubtrait, { } fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +//~^ implied_bounds_in_impls +//~| implied_bounds_in_impls where (): GenericSubtrait<(), T, V> + GenericTrait, { @@ -46,21 +52,25 @@ fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> // i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} +//~^ implied_bounds_in_impls trait SomeTrait { // Check that it works in trait declarations. fn f() -> impl Deref + DerefMut; + //~^ implied_bounds_in_impls } struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. fn f() -> impl Deref + DerefMut { + //~^ implied_bounds_in_impls Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. fn f() -> impl Deref + DerefMut { + //~^ implied_bounds_in_impls Box::new(42) } } @@ -72,7 +82,9 @@ mod issue11422 { // `PartialOrd` has a default generic parameter and does not need to be explicitly specified. // This needs special handling. fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} + //~^ implied_bounds_in_impls fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} + //~^ implied_bounds_in_impls // Referring to `Self` in the supertrait clause needs special handling. trait Trait1 {} @@ -86,11 +98,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion fn my_iter() -> impl Iterator + DoubleEndedIterator { + //~^ implied_bounds_in_impls 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion fn f() -> impl Copy + Clone { + //~^ implied_bounds_in_impls 1 } @@ -105,6 +119,7 @@ mod issue11435 { // When the other trait has generics, it shouldn't add another pair of `<>` fn f2() -> impl Trait1 + Trait2 {} + //~^ implied_bounds_in_impls trait Trait3 { type X; @@ -120,6 +135,7 @@ mod issue11435 { // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved // over fn f3() -> impl Trait3 + Trait4 {} + //~^ implied_bounds_in_impls } fn issue11880() { @@ -147,14 +163,19 @@ fn issue11880() { // X::T is never constrained in the first place, so it can be omitted // and left unconstrained fn f3() -> impl X + Y {} + //~^ implied_bounds_in_impls fn f4() -> impl X + Y {} + //~^ implied_bounds_in_impls fn f5() -> impl X + Y {} + //~^ implied_bounds_in_impls } fn apit(_: impl Deref + DerefMut) {} +//~^ implied_bounds_in_impls trait Rpitit { fn f() -> impl Deref + DerefMut; + //~^ implied_bounds_in_impls } trait Atpit { @@ -163,12 +184,14 @@ trait Atpit { } impl Atpit for () { type Assoc = impl Deref + DerefMut; + //~^ implied_bounds_in_impls fn define() -> Self::Assoc { &mut [] as &mut [()] } } type Tait = impl Deref + DerefMut; +//~^ implied_bounds_in_impls fn define() -> Tait { &mut [] as &mut [()] } diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr index 805532a56802..e2888d86f315 100644 --- a/tests/ui/implied_bounds_in_impls.stderr +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -13,7 +13,7 @@ LL + fn deref_derefmut(x: T) -> impl DerefMut { | error: this bound is already specified as the supertrait of `GenericSubtrait` - --> tests/ui/implied_bounds_in_impls.rs:30:37 + --> tests/ui/implied_bounds_in_impls.rs:31:37 | LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait | ^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + fn generics_implied() -> impl GenericSubtrait | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> tests/ui/implied_bounds_in_impls.rs:36:40 + --> tests/ui/implied_bounds_in_impls.rs:38:40 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait2 + GenericSubtrait<( | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` - --> tests/ui/implied_bounds_in_impls.rs:36:60 + --> tests/ui/implied_bounds_in_impls.rs:38:60 | LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + fn generics_implied_multi() -> impl GenericTrait + GenericSubtrait< | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> tests/ui/implied_bounds_in_impls.rs:38:44 + --> tests/ui/implied_bounds_in_impls.rs:42:44 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait2 + GenericSubtra | error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` - --> tests/ui/implied_bounds_in_impls.rs:38:62 + --> tests/ui/implied_bounds_in_impls.rs:42:62 | LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + fn generics_implied_multi2() -> impl GenericTrait + GenericSubtrai | error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>` - --> tests/ui/implied_bounds_in_impls.rs:48:28 + --> tests/ui/implied_bounds_in_impls.rs:54:28 | LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} | ^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:52:20 + --> tests/ui/implied_bounds_in_impls.rs:59:20 | LL | fn f() -> impl Deref + DerefMut; | ^^^^^ @@ -97,7 +97,7 @@ LL + fn f() -> impl DerefMut; | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:57:20 + --> tests/ui/implied_bounds_in_impls.rs:65:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -109,7 +109,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:63:20 + --> tests/ui/implied_bounds_in_impls.rs:72:20 | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ @@ -121,7 +121,7 @@ LL + fn f() -> impl DerefMut { | error: this bound is already specified as the supertrait of `PartialOrd` - --> tests/ui/implied_bounds_in_impls.rs:74:41 + --> tests/ui/implied_bounds_in_impls.rs:84:41 | LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} | ^^^^^^^^^ @@ -133,7 +133,7 @@ LL + fn default_generic_param1() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `PartialOrd` - --> tests/ui/implied_bounds_in_impls.rs:75:54 + --> tests/ui/implied_bounds_in_impls.rs:86:54 | LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} | ^^^^^^^^^ @@ -145,7 +145,7 @@ LL + fn default_generic_param2() -> impl PartialOrd + Debug {} | error: this bound is already specified as the supertrait of `DoubleEndedIterator` - --> tests/ui/implied_bounds_in_impls.rs:88:26 + --> tests/ui/implied_bounds_in_impls.rs:100:26 | LL | fn my_iter() -> impl Iterator + DoubleEndedIterator { | ^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + fn my_iter() -> impl DoubleEndedIterator { | error: this bound is already specified as the supertrait of `Copy` - --> tests/ui/implied_bounds_in_impls.rs:93:27 + --> tests/ui/implied_bounds_in_impls.rs:106:27 | LL | fn f() -> impl Copy + Clone { | ^^^^^ @@ -169,7 +169,7 @@ LL + fn f() -> impl Copy { | error: this bound is already specified as the supertrait of `Trait2` - --> tests/ui/implied_bounds_in_impls.rs:107:21 + --> tests/ui/implied_bounds_in_impls.rs:121:21 | LL | fn f2() -> impl Trait1 + Trait2 {} | ^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + fn f2() -> impl Trait2 {} | error: this bound is already specified as the supertrait of `Trait4` - --> tests/ui/implied_bounds_in_impls.rs:122:21 + --> tests/ui/implied_bounds_in_impls.rs:137:21 | LL | fn f3() -> impl Trait3 + Trait4 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + fn f3() -> impl Trait4 {} | error: this bound is already specified as the supertrait of `Y` - --> tests/ui/implied_bounds_in_impls.rs:149:21 + --> tests/ui/implied_bounds_in_impls.rs:165:21 | LL | fn f3() -> impl X + Y {} | ^ @@ -205,7 +205,7 @@ LL + fn f3() -> impl Y {} | error: this bound is already specified as the supertrait of `Y` - --> tests/ui/implied_bounds_in_impls.rs:150:21 + --> tests/ui/implied_bounds_in_impls.rs:167:21 | LL | fn f4() -> impl X + Y {} | ^ @@ -217,7 +217,7 @@ LL + fn f4() -> impl Y {} | error: this bound is already specified as the supertrait of `Y` - --> tests/ui/implied_bounds_in_impls.rs:151:21 + --> tests/ui/implied_bounds_in_impls.rs:169:21 | LL | fn f5() -> impl X + Y {} | ^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + fn f5() -> impl Y {} | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:154:17 + --> tests/ui/implied_bounds_in_impls.rs:173:17 | LL | fn apit(_: impl Deref + DerefMut) {} | ^^^^^ @@ -241,7 +241,7 @@ LL + fn apit(_: impl DerefMut) {} | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:157:20 + --> tests/ui/implied_bounds_in_impls.rs:177:20 | LL | fn f() -> impl Deref + DerefMut; | ^^^^^ @@ -253,7 +253,7 @@ LL + fn f() -> impl DerefMut; | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:165:23 + --> tests/ui/implied_bounds_in_impls.rs:186:23 | LL | type Assoc = impl Deref + DerefMut; | ^^^^^ @@ -265,7 +265,7 @@ LL + type Assoc = impl DerefMut; | error: this bound is already specified as the supertrait of `DerefMut` - --> tests/ui/implied_bounds_in_impls.rs:171:18 + --> tests/ui/implied_bounds_in_impls.rs:193:18 | LL | type Tait = impl Deref + DerefMut; | ^^^^^ diff --git a/tests/ui/incompatible_msrv.rs b/tests/ui/incompatible_msrv.rs index c23df223d508..523c754437aa 100644 --- a/tests/ui/incompatible_msrv.rs +++ b/tests/ui/incompatible_msrv.rs @@ -11,14 +11,17 @@ use std::time::Duration; fn foo() { let mut map: HashMap<&str, u32> = HashMap::new(); assert_eq!(map.entry("poneyland").key(), &"poneyland"); - //~^ ERROR: is `1.3.0` but this item is stable since `1.10.0` + //~^ incompatible_msrv + if let Entry::Vacant(v) = map.entry("poneyland") { v.into_key(); - //~^ ERROR: is `1.3.0` but this item is stable since `1.12.0` + //~^ incompatible_msrv + } // Should warn for `sleep` but not for `Duration` (which was added in `1.3.0`). sleep(Duration::new(1, 0)); - //~^ ERROR: is `1.3.0` but this item is stable since `1.4.0` + //~^ incompatible_msrv + } #[test] diff --git a/tests/ui/incompatible_msrv.stderr b/tests/ui/incompatible_msrv.stderr index 34f01c3e14a1..f14e9810b203 100644 --- a/tests/ui/incompatible_msrv.stderr +++ b/tests/ui/incompatible_msrv.stderr @@ -8,13 +8,13 @@ LL | assert_eq!(map.entry("poneyland").key(), &"poneyland"); = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]` error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.12.0` - --> tests/ui/incompatible_msrv.rs:16:11 + --> tests/ui/incompatible_msrv.rs:17:11 | LL | v.into_key(); | ^^^^^^^^^^ error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` - --> tests/ui/incompatible_msrv.rs:20:5 + --> tests/ui/incompatible_msrv.rs:22:5 | LL | sleep(Duration::new(1, 0)); | ^^^^^ diff --git a/tests/ui/inconsistent_digit_grouping.fixed b/tests/ui/inconsistent_digit_grouping.fixed index 3f1dfbbae97b..23d2d7cc0aa4 100644 --- a/tests/ui/inconsistent_digit_grouping.fixed +++ b/tests/ui/inconsistent_digit_grouping.fixed @@ -23,15 +23,25 @@ fn main() { 1.123_456_7_f32, ); let bad = (123_456, 12_345_678, 1_234_567, 1_234.567_8_f32, 1.234_567_8_f32); + //~^ inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping // Test padding let _ = 0x0010_0000; + //~^ unreadable_literal let _ = 0x0100_0000; + //~^ unreadable_literal let _ = 0x1000_0000; + //~^ unreadable_literal let _ = 0x0001_0000_0000_u64; + //~^ unreadable_literal // Test suggestion when fraction has no digits let _: f32 = 123_456.; + //~^ inconsistent_digit_grouping // Test UUID formatted literal let _: u128 = 0x12345678_1234_1234_1234_123456789012; diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs index ac47ae175948..a172c5450ef8 100644 --- a/tests/ui/inconsistent_digit_grouping.rs +++ b/tests/ui/inconsistent_digit_grouping.rs @@ -23,15 +23,25 @@ fn main() { 1.123_456_7_f32, ); let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); + //~^ inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping + //~| inconsistent_digit_grouping // Test padding let _ = 0x100000; + //~^ unreadable_literal let _ = 0x1000000; + //~^ unreadable_literal let _ = 0x10000000; + //~^ unreadable_literal let _ = 0x100000000_u64; + //~^ unreadable_literal // Test suggestion when fraction has no digits let _: f32 = 1_23_456.; + //~^ inconsistent_digit_grouping // Test UUID formatted literal let _: u128 = 0x12345678_1234_1234_1234_123456789012; diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr index 173b824935c8..be54de5e7c16 100644 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ b/tests/ui/inconsistent_digit_grouping.stderr @@ -32,7 +32,7 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f | ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32` error: long literal lacking separators - --> tests/ui/inconsistent_digit_grouping.rs:28:13 + --> tests/ui/inconsistent_digit_grouping.rs:33:13 | LL | let _ = 0x100000; | ^^^^^^^^ help: consider: `0x0010_0000` @@ -44,25 +44,25 @@ LL | #[deny(clippy::unreadable_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> tests/ui/inconsistent_digit_grouping.rs:29:13 + --> tests/ui/inconsistent_digit_grouping.rs:35:13 | LL | let _ = 0x1000000; | ^^^^^^^^^ help: consider: `0x0100_0000` error: long literal lacking separators - --> tests/ui/inconsistent_digit_grouping.rs:30:13 + --> tests/ui/inconsistent_digit_grouping.rs:37:13 | LL | let _ = 0x10000000; | ^^^^^^^^^^ help: consider: `0x1000_0000` error: long literal lacking separators - --> tests/ui/inconsistent_digit_grouping.rs:31:13 + --> tests/ui/inconsistent_digit_grouping.rs:39:13 | LL | let _ = 0x100000000_u64; | ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64` error: digits grouped inconsistently by underscores - --> tests/ui/inconsistent_digit_grouping.rs:34:18 + --> tests/ui/inconsistent_digit_grouping.rs:43: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 67bd3e4d2797..1b3f27a45d6a 100644 --- a/tests/ui/inconsistent_struct_constructor.fixed +++ b/tests/ui/inconsistent_struct_constructor.fixed @@ -34,6 +34,7 @@ mod without_base { // Should lint. Foo { x, y, z }; + //~^ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -65,6 +66,7 @@ mod with_base { z, ..Default::default() }; + //~^^^^ inconsistent_struct_constructor // Should NOT lint because the order is consistent with the definition. Foo { diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs index d49f236b9b07..ec29bdaf93f0 100644 --- a/tests/ui/inconsistent_struct_constructor.rs +++ b/tests/ui/inconsistent_struct_constructor.rs @@ -34,6 +34,7 @@ mod without_base { // Should lint. Foo { y, x, z }; + //~^ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -65,6 +66,7 @@ mod with_base { x, ..Default::default() }; + //~^^^^ inconsistent_struct_constructor // Should NOT lint because the order is consistent with the definition. Foo { diff --git a/tests/ui/inconsistent_struct_constructor.stderr b/tests/ui/inconsistent_struct_constructor.stderr index c145eb2a239e..2f48a011d26f 100644 --- a/tests/ui/inconsistent_struct_constructor.stderr +++ b/tests/ui/inconsistent_struct_constructor.stderr @@ -8,7 +8,7 @@ LL | Foo { y, x, z }; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_struct_constructor)]` error: struct constructor field order is inconsistent with struct definition field order - --> tests/ui/inconsistent_struct_constructor.rs:64:13 + --> tests/ui/inconsistent_struct_constructor.rs:65:13 | LL | / z, LL | | x, 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 ea8e56e18b08..f5f66d6eca61 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -12,21 +12,24 @@ 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 + //~^ index_refutable_slice + 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 + //~^ index_refutable_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 { - //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~^ index_refutable_slice + println!("{}", slice_2); println!("{}", slice_0); } @@ -34,7 +37,8 @@ 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 + //~^ index_refutable_slice + println!("{}", slice_0); } @@ -42,8 +46,10 @@ 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 + //~^ index_refutable_slice + //~| index_refutable_slice + + println!("{} -> {}", a_2, b_1); } @@ -51,7 +57,8 @@ 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 + //~^ index_refutable_slice + println!("{:?}", slice_1); } println!("{:?}", slice); @@ -60,7 +67,8 @@ 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 + //~^ index_refutable_slice + println!("{:?}", slice_0); } println!("{:?}", slice); @@ -130,7 +138,8 @@ 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 + //~^ index_refutable_slice + if wrap.is_awesome { println!("This is awesome! {}", slice_0); } @@ -138,7 +147,8 @@ 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 + //~^ index_refutable_slice + 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 1c1d1c4cbe46..408fd85cfe6a 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -12,21 +12,24 @@ 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 + //~^ index_refutable_slice + 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 + //~^ index_refutable_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) = slice { - //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~^ index_refutable_slice + println!("{}", slice[2]); println!("{}", slice[0]); } @@ -34,7 +37,8 @@ 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 + //~^ index_refutable_slice + println!("{}", slice[0]); } @@ -42,8 +46,10 @@ 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 + //~^ index_refutable_slice + //~| index_refutable_slice + + println!("{} -> {}", a[2], b[1]); } @@ -51,7 +57,8 @@ 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 + //~^ index_refutable_slice + println!("{:?}", slice[1]); } println!("{:?}", slice); @@ -60,7 +67,8 @@ 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 + //~^ index_refutable_slice + println!("{:?}", slice[0]); } println!("{:?}", slice); @@ -130,7 +138,8 @@ 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 + //~^ index_refutable_slice + if wrap.is_awesome { println!("This is awesome! {}", slice[0]); } @@ -138,7 +147,8 @@ 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 + //~^ index_refutable_slice + 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 14ee2e54cab1..6abbc3d7dfad 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr @@ -13,11 +13,12 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([slice_0, ..]) = slice { LL | +LL | LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:21:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:22:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -26,11 +27,12 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([slice_0, ..]) = slice { LL | +LL | LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:28:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:30:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -39,12 +41,13 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([slice_0, _, slice_2, ..]) = slice { LL | +LL | LL ~ println!("{}", slice_2); LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:36:26 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:39:26 | LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { | ^^^^^ @@ -53,11 +56,12 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let SomeEnum::One([slice_0, ..]) | SomeEnum::Three([slice_0, ..]) = slice_wrapped { LL | +LL | LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:44:29 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:48:29 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -66,12 +70,13 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let (SomeEnum::Three([_, _, a_2, ..]), Some(b)) = (a_wrapped, b_wrapped) { LL | +... LL | LL ~ println!("{} -> {}", a_2, b[1]); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:44:38 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:48:38 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -80,12 +85,13 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let (SomeEnum::Three(a), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { LL | +... LL | LL ~ println!("{} -> {}", a[2], b_1); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:53:21 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:59:21 | LL | if let Some(ref slice) = slice { | ^^^^^ @@ -94,11 +100,12 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([_, ref slice_1, ..]) = slice { LL | +LL | LL ~ println!("{:?}", slice_1); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:62:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:69:17 | LL | if let Some(slice) = &slice { | ^^^^^ @@ -107,21 +114,8 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([slice_0, ..]) = &slice { LL | -LL ~ println!("{:?}", slice_0); - | - -error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:132:17 - | -LL | if let Some(slice) = wrap.inner { - | ^^^^^ - | -help: replace the binding and indexed access with a slice pattern - | -LL ~ if let Some([slice_0, ..]) = wrap.inner { LL | -LL | if wrap.is_awesome { -LL ~ println!("This is awesome! {}", slice_0); +LL ~ println!("{:?}", slice_0); | error: this binding can be a slice pattern to avoid indexing @@ -134,6 +128,22 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let Some([slice_0, ..]) = wrap.inner { LL | +LL | +LL | if wrap.is_awesome { +LL ~ println!("This is awesome! {}", slice_0); + | + +error: this binding can be a slice pattern to avoid indexing + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:149:17 + | +LL | if let Some(slice) = wrap.inner { + | ^^^^^ + | +help: replace the binding and indexed access with a slice pattern + | +LL ~ if let Some([slice_0, ..]) = wrap.inner { +LL | +LL | LL | if wrap.is_super_awesome() { LL ~ println!("This is super awesome! {}", slice_0); | diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 2af5fcc82a9b..cfa1c2f7c75f 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -49,8 +49,10 @@ fn main() { //~^ ERROR: indexing may panic // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[4]; + //~^ out_of_bounds_indexing // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[1 << 3]; + //~^ out_of_bounds_indexing // Ok, should not produce stderr. x[0]; @@ -66,12 +68,14 @@ fn main() { // This should be linted, since `suppress-restriction-lint-in-const` default is false. const { &ARR[idx4()] }; //~^ ERROR: indexing may panic + //~| ERROR: evaluation of `main let y = &x; // Ok, referencing shouldn't affect this lint. See the issue 6021 y[0]; // Ok, rustc will handle references too. y[4]; + //~^ out_of_bounds_indexing let v = vec![0; 5]; v[0]; @@ -87,6 +91,7 @@ fn main() { const M: usize = 3; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[N]; + //~^ out_of_bounds_indexing // Ok, should not produce stderr. x[M]; v[N]; @@ -96,4 +101,5 @@ fn main() { let slice = &x; let _ = x[4]; + //~^ out_of_bounds_indexing } diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 71677584d25b..50ee9b9edc75 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -10,13 +10,13 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error[E0080]: evaluation of `main::{constant#3}` failed - --> tests/ui/indexing_slicing_index.rs:67:14 + --> tests/ui/indexing_slicing_index.rs:69:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant encountered - --> tests/ui/indexing_slicing_index.rs:67:5 + --> tests/ui/indexing_slicing_index.rs:69:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -39,13 +39,13 @@ LL | x[4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:53:5 + --> tests/ui/indexing_slicing_index.rs:54:5 | LL | x[1 << 3]; | ^^^^^^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:64:14 + --> tests/ui/indexing_slicing_index.rs:66:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:67:14 + --> tests/ui/indexing_slicing_index.rs:69:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -63,13 +63,13 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:74:5 + --> tests/ui/indexing_slicing_index.rs:77:5 | LL | y[4]; | ^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:77:5 + --> tests/ui/indexing_slicing_index.rs:81:5 | LL | v[0]; | ^^^^ @@ -77,7 +77,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:79:5 + --> tests/ui/indexing_slicing_index.rs:83:5 | LL | v[10]; | ^^^^^ @@ -85,7 +85,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:81:5 + --> tests/ui/indexing_slicing_index.rs:85:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -93,13 +93,13 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:89:5 + --> tests/ui/indexing_slicing_index.rs:93:5 | LL | x[N]; | ^^^^ error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:92:5 + --> tests/ui/indexing_slicing_index.rs:97:5 | LL | v[N]; | ^^^^ @@ -107,7 +107,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_index.rs:94:5 + --> tests/ui/indexing_slicing_index.rs:99:5 | LL | v[M]; | ^^^^ @@ -115,7 +115,7 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> tests/ui/indexing_slicing_index.rs:98:13 + --> tests/ui/indexing_slicing_index.rs:103:13 | LL | let _ = x[4]; | ^^^^ diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index f37bcc4aa0ca..cad77f56d03a 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -113,22 +113,21 @@ fn main() { let index_from: usize = 2; let index_to: usize = 3; &x[index..]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[..index]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[index_from..index_to]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[index_from..][..index_to]; - //~^ ERROR: slicing may panic - //~| ERROR: slicing may panic + //~^ indexing_slicing + //~| indexing_slicing &x[5..][..10]; - //~^ ERROR: slicing may panic - //~| ERROR: range is out of bounds - //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + //~^ indexing_slicing + //~| out_of_bounds_indexing &x[0..][..3]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[1..][..5]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[0..].get(..3); // Ok, should not produce stderr. &x[0..3]; // Ok, should not produce stderr. @@ -136,22 +135,22 @@ fn main() { let y = &x; &y[1..2]; &y[0..=4]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing &y[..=4]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing &y[..]; // Ok, should not produce stderr. let v = vec![0; 5]; &v[10..100]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &x[10..][..100]; - //~^ ERROR: slicing may panic - //~| ERROR: range is out of bounds + //~^ indexing_slicing + //~| out_of_bounds_indexing &v[10..]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &v[..100]; - //~^ ERROR: slicing may panic + //~^ indexing_slicing &v[..]; // Ok, should not produce stderr. @@ -169,12 +168,15 @@ fn main() { // Lint on this, because `get` does exist with same signature map_with_get[true]; + //~^ indexing_slicing let s = S::(1); s[0]; + //~^ indexing_slicing let y = Y::(1); y[0]; + //~^ indexing_slicing let z = Z::(1); z[0]; diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index 1e72506746ec..e3ef89823e3d 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -58,7 +58,7 @@ LL | &x[5..][..10]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:128:6 + --> tests/ui/indexing_slicing_slice.rs:127:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | &x[0..][..3]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:130:6 + --> tests/ui/indexing_slicing_slice.rs:129:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -74,19 +74,19 @@ LL | &x[1..][..5]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:138:12 + --> tests/ui/indexing_slicing_slice.rs:137:12 | LL | &y[0..=4]; | ^ error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:140:11 + --> tests/ui/indexing_slicing_slice.rs:139:11 | LL | &y[..=4]; | ^ error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:146:6 + --> tests/ui/indexing_slicing_slice.rs:145:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | &v[10..100]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:148:6 + --> tests/ui/indexing_slicing_slice.rs:147:6 | LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ @@ -102,13 +102,13 @@ LL | &x[10..][..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:148:8 + --> tests/ui/indexing_slicing_slice.rs:147:8 | LL | &x[10..][..100]; | ^^ error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:151:6 + --> tests/ui/indexing_slicing_slice.rs:150:6 | LL | &v[10..]; | ^^^^^^^ @@ -116,7 +116,7 @@ LL | &v[10..]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:153:6 + --> tests/ui/indexing_slicing_slice.rs:152:6 | LL | &v[..100]; | ^^^^^^^^ @@ -124,7 +124,7 @@ LL | &v[..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_slice.rs:171:5 + --> tests/ui/indexing_slicing_slice.rs:170:5 | LL | map_with_get[true]; | ^^^^^^^^^^^^^^^^^^ @@ -140,7 +140,7 @@ LL | s[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_slice.rs:177:5 + --> tests/ui/indexing_slicing_slice.rs:178:5 | LL | y[0]; | ^^^^ diff --git a/tests/ui/ineffective_open_options.fixed b/tests/ui/ineffective_open_options.fixed index 88489dc46bbb..c229278e78b2 100644 --- a/tests/ui/ineffective_open_options.fixed +++ b/tests/ui/ineffective_open_options.fixed @@ -5,7 +5,7 @@ use std::fs::OpenOptions; fn main() { let file = OpenOptions::new() .create(true) - //~ ERROR: unnecessary use of `.write(true)` +//~^ ineffective_open_options .append(true) .open("dump.json") .unwrap(); @@ -13,7 +13,7 @@ fn main() { let file = OpenOptions::new() .create(true) .append(true) - //~ ERROR: unnecessary use of `.write(true)` +//~^ ineffective_open_options .open("dump.json") .unwrap(); diff --git a/tests/ui/ineffective_open_options.rs b/tests/ui/ineffective_open_options.rs index db8bca3e2acd..ed1fe79a2782 100644 --- a/tests/ui/ineffective_open_options.rs +++ b/tests/ui/ineffective_open_options.rs @@ -5,7 +5,8 @@ use std::fs::OpenOptions; fn main() { let file = OpenOptions::new() .create(true) - .write(true) //~ ERROR: unnecessary use of `.write(true)` +.write(true) +//~^ ineffective_open_options .append(true) .open("dump.json") .unwrap(); @@ -13,7 +14,8 @@ fn main() { let file = OpenOptions::new() .create(true) .append(true) - .write(true) //~ ERROR: unnecessary use of `.write(true)` +.write(true) +//~^ ineffective_open_options .open("dump.json") .unwrap(); diff --git a/tests/ui/ineffective_open_options.stderr b/tests/ui/ineffective_open_options.stderr index 0d6933bb449e..afc97ecd755c 100644 --- a/tests/ui/ineffective_open_options.stderr +++ b/tests/ui/ineffective_open_options.stderr @@ -1,17 +1,17 @@ error: unnecessary use of `.write(true)` because there is `.append(true)` - --> tests/ui/ineffective_open_options.rs:8:9 + --> tests/ui/ineffective_open_options.rs:8:1 | -LL | .write(true) - | ^^^^^^^^^^^^ help: remove `.write(true)` +LL | .write(true) + | ^^^^^^^^^^^^ help: remove `.write(true)` | = note: `-D clippy::ineffective-open-options` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ineffective_open_options)]` error: unnecessary use of `.write(true)` because there is `.append(true)` - --> tests/ui/ineffective_open_options.rs:16:9 + --> tests/ui/ineffective_open_options.rs:17:1 | -LL | .write(true) - | ^^^^^^^^^^^^ help: remove `.write(true)` +LL | .write(true) + | ^^^^^^^^^^^^ help: remove `.write(true)` error: aborting due to 2 previous errors diff --git a/tests/ui/inefficient_to_string.fixed b/tests/ui/inefficient_to_string.fixed index 1e19323113c5..a0d34e58a925 100644 --- a/tests/ui/inefficient_to_string.fixed +++ b/tests/ui/inefficient_to_string.fixed @@ -8,7 +8,9 @@ fn main() { let rrrstr: &&&str = &rrstr; let _: String = rstr.to_string(); let _: String = (*rrstr).to_string(); + //~^ inefficient_to_string let _: String = (**rrrstr).to_string(); + //~^ inefficient_to_string let string: String = String::from("hello"); let rstring: &String = &string; @@ -17,7 +19,9 @@ fn main() { let _: String = string.to_string(); let _: String = rstring.to_string(); let _: String = (*rrstring).to_string(); + //~^ inefficient_to_string let _: String = (**rrrstring).to_string(); + //~^ inefficient_to_string let cow: Cow<'_, str> = Cow::Borrowed("hello"); let rcow: &Cow<'_, str> = &cow; @@ -26,5 +30,7 @@ fn main() { let _: String = cow.to_string(); let _: String = rcow.to_string(); let _: String = (*rrcow).to_string(); + //~^ inefficient_to_string let _: String = (**rrrcow).to_string(); + //~^ inefficient_to_string } diff --git a/tests/ui/inefficient_to_string.rs b/tests/ui/inefficient_to_string.rs index f027bae6fe34..cbe90d4a125b 100644 --- a/tests/ui/inefficient_to_string.rs +++ b/tests/ui/inefficient_to_string.rs @@ -8,7 +8,9 @@ fn main() { let rrrstr: &&&str = &rrstr; let _: String = rstr.to_string(); let _: String = rrstr.to_string(); + //~^ inefficient_to_string let _: String = rrrstr.to_string(); + //~^ inefficient_to_string let string: String = String::from("hello"); let rstring: &String = &string; @@ -17,7 +19,9 @@ fn main() { let _: String = string.to_string(); let _: String = rstring.to_string(); let _: String = rrstring.to_string(); + //~^ inefficient_to_string let _: String = rrrstring.to_string(); + //~^ inefficient_to_string let cow: Cow<'_, str> = Cow::Borrowed("hello"); let rcow: &Cow<'_, str> = &cow; @@ -26,5 +30,7 @@ fn main() { let _: String = cow.to_string(); let _: String = rcow.to_string(); let _: String = rrcow.to_string(); + //~^ inefficient_to_string let _: String = rrrcow.to_string(); + //~^ inefficient_to_string } diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr index e71e667cf0cf..8593c0addc5f 100644 --- a/tests/ui/inefficient_to_string.stderr +++ b/tests/ui/inefficient_to_string.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::inefficient_to_string)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `to_string` on `&&&str` - --> tests/ui/inefficient_to_string.rs:11:21 + --> tests/ui/inefficient_to_string.rs:12: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` - --> tests/ui/inefficient_to_string.rs:19:21 + --> tests/ui/inefficient_to_string.rs:21: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` - --> tests/ui/inefficient_to_string.rs:20:21 + --> tests/ui/inefficient_to_string.rs:23: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>` - --> tests/ui/inefficient_to_string.rs:28:21 + --> tests/ui/inefficient_to_string.rs:32: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>` - --> tests/ui/inefficient_to_string.rs:29:21 + --> tests/ui/inefficient_to_string.rs:34:21 | LL | let _: String = rrrcow.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()` diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs index 7cc7cb9d6878..3db3aca18f23 100644 --- a/tests/ui/infallible_destructuring_match.rs +++ b/tests/ui/infallible_destructuring_match.rs @@ -26,6 +26,7 @@ fn infallible_destructuring_match_enum() { // This should lint! let data = match wrapper { + //~^ infallible_destructuring_match SingleVariantEnum::Variant(i) => i, }; @@ -58,6 +59,7 @@ fn infallible_destructuring_match_struct() { // This should lint! let data = match wrapper { + //~^ infallible_destructuring_match TupleStruct(i) => i, }; @@ -82,6 +84,7 @@ fn infallible_destructuring_match_struct_with_noncopy() { // This should lint! (keeping `ref` in the suggestion) let data = match wrapper { + //~^ infallible_destructuring_match TupleStructWithNonCopy(ref n) => n, }; @@ -101,6 +104,7 @@ fn never_enum() { // This should lint! let data = match wrapper { + //~^ infallible_destructuring_match Ok(i) => i, }; diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr index b709fd8630e9..1e784bc598bf 100644 --- a/tests/ui/infallible_destructuring_match.stderr +++ b/tests/ui/infallible_destructuring_match.stderr @@ -2,6 +2,7 @@ error: you seem to be trying to use `match` to destructure a single infallible p --> tests/ui/infallible_destructuring_match.rs:28:5 | LL | / let data = match wrapper { +LL | | LL | | SingleVariantEnum::Variant(i) => i, LL | | }; | |______^ help: try: `let SingleVariantEnum::Variant(data) = wrapper;` @@ -10,25 +11,28 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::infallible_destructuring_match)]` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> tests/ui/infallible_destructuring_match.rs:60:5 + --> tests/ui/infallible_destructuring_match.rs:61:5 | LL | / let data = match wrapper { +LL | | LL | | TupleStruct(i) => i, 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` - --> tests/ui/infallible_destructuring_match.rs:84:5 + --> tests/ui/infallible_destructuring_match.rs:86:5 | LL | / let data = match wrapper { +LL | | LL | | TupleStructWithNonCopy(ref n) => n, 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` - --> tests/ui/infallible_destructuring_match.rs:103:5 + --> tests/ui/infallible_destructuring_match.rs:106:5 | LL | / let data = match wrapper { +LL | | LL | | Ok(i) => i, LL | | }; | |______^ help: try: `let Ok(data) = wrapper;` diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 178e300ff5bf..2f8cc954e70c 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -9,13 +9,16 @@ 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 + // infinite iter (0..8_u32).take_while(square_is_lower_64).cycle().count(); - //~^ ERROR: infinite iteration detected + //~^ infinite_iter + // infinite iter (0..8_u64).chain(0..).max(); - //~^ ERROR: infinite iteration detected + //~^ infinite_iter + // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) @@ -23,7 +26,8 @@ fn infinite_iters() { .min(); // infinite iter (0..8_u32) - //~^ ERROR: infinite iteration detected + //~^ infinite_iter + .rev() .cycle() .map(|x| x + 1_u32) @@ -32,10 +36,12 @@ 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 + // infinite iter (0_u64..).filter(|x| x % 2 == 0).last(); - //~^ ERROR: infinite iteration detected + //~^ infinite_iter + // not an infinite, because ranges are double-ended (0..42_u64).by_ref().last(); // iterator is not exhausted @@ -46,13 +52,16 @@ 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 + // maybe infinite iter repeat(42).take_while(|x| *x == 42).chain(0..42).max(); - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + // maybe infinite iter (1..) - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + .scan(0, |state, x| { *state += x; Some(*state) @@ -60,16 +69,20 @@ fn potential_infinite_iters() { .min(); // maybe infinite iter (0..).find(|x| *x == 24); - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + // maybe infinite iter (0..).position(|x| x == 24); - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + // maybe infinite iter (0..).any(|x| x == 24); - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + // maybe infinite iter (0..).all(|x| x == 24); - //~^ ERROR: possible infinite iteration detected + //~^ maybe_infinite_iter + // not infinite (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); @@ -95,8 +108,9 @@ mod finite_collect { fn check_collect() { // Infinite iter let _: HashSet = (0..).collect(); - //~^ ERROR: infinite iteration detected - //~| NOTE: `#[deny(clippy::infinite_iter)]` on by default + //~^ infinite_iter + + // 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 e33d83b75edb..ef3836a5ab59 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -11,22 +11,23 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:14:5 + --> tests/ui/infinite_iter.rs:15:5 | LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:17:5 + --> tests/ui/infinite_iter.rs:19:5 | LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:25:5 + --> tests/ui/infinite_iter.rs:28:5 | LL | / (0..8_u32) LL | | +LL | | LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) @@ -34,73 +35,73 @@ LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:34:5 + --> tests/ui/infinite_iter.rs:38:5 | LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:37:5 + --> tests/ui/infinite_iter.rs:42:5 | LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:48:5 + --> tests/ui/infinite_iter.rs:54:5 | LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/infinite_iter.rs:45:8 + --> tests/ui/infinite_iter.rs:51:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:51:5 + --> tests/ui/infinite_iter.rs:58:5 | LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:54:5 + --> tests/ui/infinite_iter.rs:62:5 | LL | / (1..) LL | | +LL | | LL | | .scan(0, |state, x| { -LL | | *state += x; -LL | | Some(*state) +... | LL | | }) LL | | .min(); | |______________^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:62:5 + --> tests/ui/infinite_iter.rs:71:5 | LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:65:5 + --> tests/ui/infinite_iter.rs:75:5 | LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:68:5 + --> tests/ui/infinite_iter.rs:79:5 | LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:71:5 + --> tests/ui/infinite_iter.rs:83:5 | LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:97:31 + --> tests/ui/infinite_iter.rs:110:31 | LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 765c67011474..02d40e84eed9 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -20,15 +20,17 @@ 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 + //~^ while_immutable_condition + + 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 + //~^ while_immutable_condition + + let mut k = 1; k += 2; println!("KO - x and y immutable"); @@ -36,8 +38,9 @@ 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 + //~^ while_immutable_condition + + println!("KO - cond immutable"); } @@ -82,21 +85,24 @@ 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 + //~^ while_immutable_condition + + 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 + //~^ while_immutable_condition + + 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 + //~^ while_immutable_condition + + let mut i = 5; fn_mutref(&mut i); println!("KO - shadowed"); @@ -112,15 +118,17 @@ 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 + //~^ while_immutable_condition + + 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 + //~^ while_immutable_condition + + fn_val(i); println!("KO - passed by value"); } @@ -187,8 +195,9 @@ 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 + //~^ while_immutable_condition + + println!("KO - {} is not mutated", self.count); } } @@ -197,8 +206,9 @@ 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 + //~^ while_immutable_condition + + if y == 0 { break; } @@ -206,8 +216,9 @@ 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 + //~^ while_immutable_condition + + if y == 0 { return; } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 7ba1374d64f4..f2876fd6ddb8 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -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 - --> tests/ui/infinite_loop.rs:29:11 + --> tests/ui/infinite_loop.rs:30: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 - --> tests/ui/infinite_loop.rs:38:11 + --> tests/ui/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 - --> tests/ui/infinite_loop.rs:84:11 + --> tests/ui/infinite_loop.rs:87: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 - --> tests/ui/infinite_loop.rs:91:11 + --> tests/ui/infinite_loop.rs:95: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 - --> tests/ui/infinite_loop.rs:97:11 + --> tests/ui/infinite_loop.rs:102: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 - --> tests/ui/infinite_loop.rs:114:11 + --> tests/ui/infinite_loop.rs:120: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 - --> tests/ui/infinite_loop.rs:121:11 + --> tests/ui/infinite_loop.rs:128:11 | LL | while i < 3 { | ^^^^^ @@ -64,23 +64,13 @@ 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 - --> tests/ui/infinite_loop.rs:189:15 + --> tests/ui/infinite_loop.rs:197:15 | 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 - --> tests/ui/infinite_loop.rs:199:11 - | -LL | while y < 10 { - | ^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - = note: this loop contains `return`s or `break`s - = help: rewrite it as `if cond { loop { } }` - error: variables in the condition are not mutated in the loop body --> tests/ui/infinite_loop.rs:208:11 | @@ -91,5 +81,15 @@ LL | while y < 10 { = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` +error: variables in the condition are not mutated in the loop body + --> tests/ui/infinite_loop.rs:218:11 + | +LL | while y < 10 { + | ^^^^^^ + | + = note: this may lead to an infinite or to a never running loop + = note: this loop contains `return`s or `break`s + = help: rewrite it as `if cond { loop { } }` + error: aborting due to 11 previous errors diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs index d7be6f9ce7e9..b5c1a5688eca 100644 --- a/tests/ui/infinite_loops.rs +++ b/tests/ui/infinite_loops.rs @@ -11,18 +11,18 @@ fn do_something() {} fn no_break() { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } } fn all_inf() { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } } @@ -36,7 +36,7 @@ fn no_break_return_some_ty() -> Option { return None; } loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } } @@ -49,6 +49,7 @@ fn no_break_never_ret() -> ! { fn no_break_never_ret_noise() { loop { + //~^ infinite_loop fn inner_fn() -> ! { std::process::exit(0); } @@ -92,7 +93,7 @@ fn has_indirect_break_2(stop_num: i32) { fn break_inner_but_not_outer_1(cond: bool) { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop loop { if cond { break; @@ -103,7 +104,7 @@ fn break_inner_but_not_outer_1(cond: bool) { fn break_inner_but_not_outer_2(cond: bool) { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop 'inner: loop { loop { if cond { @@ -117,7 +118,7 @@ fn break_inner_but_not_outer_2(cond: bool) { fn break_outer_but_not_inner() { loop { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } break; @@ -140,7 +141,7 @@ fn break_wrong_loop(cond: bool) { // 'inner has statement to break 'outer loop, but it was broken out of early by a labeled child loop 'outer: loop { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop 'inner: loop { loop { loop { @@ -180,7 +181,7 @@ enum Foo { fn match_like() { let opt: Option = Some(1); loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop match opt { Some(v) => { println!("{v}"); @@ -221,12 +222,12 @@ fn match_like() { } loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop let _x = matches!(result, Ok(v) if v != 0).then_some(0); } loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop // This `return` does not return the function, so it doesn't count let _x = matches!(result, Ok(v) if v != 0).then(|| { if true { @@ -331,7 +332,7 @@ fn exit_directly(cond: bool) { trait MyTrait { fn problematic_trait_method() { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } } @@ -341,7 +342,7 @@ trait MyTrait { impl MyTrait for String { fn could_be_problematic() { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } } @@ -350,7 +351,7 @@ impl MyTrait for String { fn inf_loop_in_closure() { let _loop_forever = || { loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop do_something(); } }; @@ -364,6 +365,7 @@ fn inf_loop_in_closure() { fn inf_loop_in_res() -> Result<(), i32> { Ok(loop { + //~^ infinite_loop do_something() }) } @@ -406,15 +408,16 @@ fn continue_outer() { // This should lint as we continue the loop itself 'infinite: loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop loop { continue 'infinite; } } // This should lint as we continue an inner loop loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop 'inner: loop { + //~^ infinite_loop loop { continue 'inner; } @@ -423,7 +426,7 @@ fn continue_outer() { // This should lint as we continue the loop itself loop { - //~^ ERROR: infinite loop detected + //~^ infinite_loop continue; } } diff --git a/tests/ui/infinite_loops.stderr b/tests/ui/infinite_loops.stderr index 3b5705d5f21d..4d02636ef4ae 100644 --- a/tests/ui/infinite_loops.stderr +++ b/tests/ui/infinite_loops.stderr @@ -74,9 +74,11 @@ error: infinite loop detected --> tests/ui/infinite_loops.rs:51:5 | LL | / loop { +LL | | LL | | fn inner_fn() -> ! { LL | | std::process::exit(0); -... | +LL | | } +LL | | do_something(); LL | | } | |_____^ | @@ -86,7 +88,7 @@ LL | fn no_break_never_ret_noise() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:94:5 + --> tests/ui/infinite_loops.rs:95:5 | LL | / loop { LL | | @@ -102,7 +104,7 @@ LL | fn break_inner_but_not_outer_1(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:105:5 + --> tests/ui/infinite_loops.rs:106:5 | LL | / loop { LL | | @@ -118,7 +120,7 @@ LL | fn break_inner_but_not_outer_2(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:119:9 + --> tests/ui/infinite_loops.rs:120:9 | LL | / loop { LL | | @@ -132,7 +134,7 @@ LL | fn break_outer_but_not_inner() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:142:9 + --> tests/ui/infinite_loops.rs:143:9 | LL | / loop { LL | | @@ -148,7 +150,7 @@ LL | fn break_wrong_loop(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:182:5 + --> tests/ui/infinite_loops.rs:183:5 | LL | / loop { LL | | @@ -164,7 +166,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:223:5 + --> tests/ui/infinite_loops.rs:224:5 | LL | / loop { LL | | @@ -178,7 +180,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:228:5 + --> tests/ui/infinite_loops.rs:229:5 | LL | / loop { LL | | @@ -195,7 +197,7 @@ LL | fn match_like() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:333:9 + --> tests/ui/infinite_loops.rs:334:9 | LL | / loop { LL | | @@ -209,7 +211,7 @@ LL | fn problematic_trait_method() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:343:9 + --> tests/ui/infinite_loops.rs:344:9 | LL | / loop { LL | | @@ -223,7 +225,7 @@ LL | fn could_be_problematic() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:352:9 + --> tests/ui/infinite_loops.rs:353:9 | LL | / loop { LL | | @@ -237,10 +239,11 @@ LL | let _loop_forever = || -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:366:8 + --> tests/ui/infinite_loops.rs:367:8 | LL | Ok(loop { | ________^ +LL | | LL | | do_something() LL | | }) | |_____^ @@ -248,7 +251,7 @@ LL | | }) = help: if this is not intended, try adding a `break` or `return` condition in the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:408:5 + --> tests/ui/infinite_loops.rs:410:5 | LL | / 'infinite: loop { LL | | @@ -264,12 +267,11 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:415:5 + --> tests/ui/infinite_loops.rs:417:5 | LL | / loop { LL | | LL | | 'inner: loop { -LL | | loop { ... | LL | | } | |_____^ @@ -280,9 +282,10 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:417:9 + --> tests/ui/infinite_loops.rs:419:9 | LL | / 'inner: loop { +LL | | LL | | loop { LL | | continue 'inner; LL | | } @@ -295,7 +298,7 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:425:5 + --> tests/ui/infinite_loops.rs:428:5 | LL | / loop { LL | | diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs index 7b938cdd758c..a1a810dad1e4 100644 --- a/tests/ui/inherent_to_string.rs +++ b/tests/ui/inherent_to_string.rs @@ -20,7 +20,8 @@ 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 + //~^ inherent_to_string + "A.to_string()".to_string() } @@ -45,7 +46,8 @@ 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 + //~^ inherent_to_string_shadow_display + "C.to_string()".to_string() } } diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index eb22525a2491..f1d415a45755 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -3,6 +3,7 @@ error: implementation of inherent method `to_string(&self) -> String` for type ` | LL | / fn to_string(&self) -> String { LL | | +LL | | LL | | "A.to_string()".to_string() LL | | } | |_____^ @@ -12,10 +13,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::inherent_to_string)]` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` - --> tests/ui/inherent_to_string.rs:47:5 + --> tests/ui/inherent_to_string.rs:48:5 | LL | / fn to_string(&self) -> String { LL | | +LL | | LL | | "C.to_string()".to_string() LL | | } | |_____^ diff --git a/tests/ui/init_numbered_fields.fixed b/tests/ui/init_numbered_fields.fixed index dca4e8da4d2f..b4c5fa83ce95 100644 --- a/tests/ui/init_numbered_fields.fixed +++ b/tests/ui/init_numbered_fields.fixed @@ -39,6 +39,7 @@ fn main() { struct TupleStructVec(Vec); let _ = TupleStructVec(vec![0, 1, 2, 3]); + //~^ init_numbered_fields { struct S(i32, i32); diff --git a/tests/ui/init_numbered_fields.rs b/tests/ui/init_numbered_fields.rs index 8cb34705b4f6..dc33921e3df9 100644 --- a/tests/ui/init_numbered_fields.rs +++ b/tests/ui/init_numbered_fields.rs @@ -15,6 +15,7 @@ fn main() { // This should lint let _ = TupleStruct { + //~^ init_numbered_fields 0: 1u32, 1: 42, 2: 23u8, @@ -22,6 +23,7 @@ fn main() { // This should also lint and order the fields correctly let _ = TupleStruct { + //~^ init_numbered_fields 0: 1u32, 2: 2u8, 1: 3u32, @@ -47,6 +49,7 @@ fn main() { struct TupleStructVec(Vec); let _ = TupleStructVec { 0: vec![0, 1, 2, 3] }; + //~^ init_numbered_fields { struct S(i32, i32); diff --git a/tests/ui/init_numbered_fields.stderr b/tests/ui/init_numbered_fields.stderr index f176e0c2ff30..89828b7e2fce 100644 --- a/tests/ui/init_numbered_fields.stderr +++ b/tests/ui/init_numbered_fields.stderr @@ -3,6 +3,7 @@ error: used a field initializer for a tuple struct | LL | let _ = TupleStruct { | _____________^ +LL | | LL | | 0: 1u32, LL | | 1: 42, LL | | 2: 23u8, @@ -13,10 +14,11 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::init_numbered_fields)]` error: used a field initializer for a tuple struct - --> tests/ui/init_numbered_fields.rs:24:13 + --> tests/ui/init_numbered_fields.rs:25:13 | LL | let _ = TupleStruct { | _____________^ +LL | | LL | | 0: 1u32, LL | | 2: 2u8, LL | | 1: 3u32, @@ -24,7 +26,7 @@ LL | | }; | |_____^ help: use tuple initialization: `TupleStruct(1u32, 3u32, 2u8)` error: used a field initializer for a tuple struct - --> tests/ui/init_numbered_fields.rs:49:13 + --> tests/ui/init_numbered_fields.rs:51:13 | LL | let _ = TupleStructVec { 0: vec![0, 1, 2, 3] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use tuple initialization: `TupleStructVec(vec![0, 1, 2, 3])` diff --git a/tests/ui/inline_fn_without_body.fixed b/tests/ui/inline_fn_without_body.fixed index acd808ed49bb..3567209b41f7 100644 --- a/tests/ui/inline_fn_without_body.fixed +++ b/tests/ui/inline_fn_without_body.fixed @@ -2,10 +2,13 @@ #![allow(clippy::inline_always)] trait Foo { + //~^ inline_fn_without_body fn default_inline(); + //~^ inline_fn_without_body fn always_inline(); + //~^ inline_fn_without_body fn never_inline(); #[inline] diff --git a/tests/ui/inline_fn_without_body.rs b/tests/ui/inline_fn_without_body.rs index af81feaa374a..9ca90e637f15 100644 --- a/tests/ui/inline_fn_without_body.rs +++ b/tests/ui/inline_fn_without_body.rs @@ -3,12 +3,15 @@ trait Foo { #[inline] + //~^ inline_fn_without_body fn default_inline(); #[inline(always)] + //~^ inline_fn_without_body fn always_inline(); #[inline(never)] + //~^ inline_fn_without_body fn never_inline(); #[inline] diff --git a/tests/ui/inline_fn_without_body.stderr b/tests/ui/inline_fn_without_body.stderr index 89db710fabe7..61bc5505ea30 100644 --- a/tests/ui/inline_fn_without_body.stderr +++ b/tests/ui/inline_fn_without_body.stderr @@ -3,26 +3,26 @@ error: use of `#[inline]` on trait method `default_inline` which has no body | LL | #[inline] | _____-^^^^^^^^ -LL | | fn default_inline(); +LL | | | |____- help: remove | = note: `-D clippy::inline-fn-without-body` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::inline_fn_without_body)]` error: use of `#[inline]` on trait method `always_inline` which has no body - --> tests/ui/inline_fn_without_body.rs:8:5 + --> tests/ui/inline_fn_without_body.rs:9:5 | LL | #[inline(always)] | _____-^^^^^^^^^^^^^^^^ -LL | | fn always_inline(); +LL | | | |____- help: remove error: use of `#[inline]` on trait method `never_inline` which has no body - --> tests/ui/inline_fn_without_body.rs:11:5 + --> tests/ui/inline_fn_without_body.rs:13:5 | LL | #[inline(never)] | _____-^^^^^^^^^^^^^^^ -LL | | fn never_inline(); +LL | | | |____- help: remove error: aborting due to 3 previous errors diff --git a/tests/ui/inspect_for_each.rs b/tests/ui/inspect_for_each.rs index 974690eaa8e4..d3eb7fcbba4d 100644 --- a/tests/ui/inspect_for_each.rs +++ b/tests/ui/inspect_for_each.rs @@ -5,7 +5,8 @@ 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` + //~^ inspect_for_each + 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 3c2dee15ebd5..6a715c9c4efc 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -4,6 +4,7 @@ error: called `inspect(..).for_each(..)` on an `Iterator` LL | a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { | ___________________^ LL | | +LL | | LL | | let y = do_some(x); LL | | let z = do_more(y); LL | | b.push(z); diff --git a/tests/ui/int_plus_one.fixed b/tests/ui/int_plus_one.fixed index 77d9cd3f773a..a1aba6bf7f64 100644 --- a/tests/ui/int_plus_one.fixed +++ b/tests/ui/int_plus_one.fixed @@ -5,10 +5,14 @@ fn main() { let y = 0i32; let _ = x > y; + //~^ int_plus_one let _ = y < x; + //~^ int_plus_one let _ = x > y; + //~^ int_plus_one let _ = y < x; + //~^ int_plus_one let _ = x > y; // should be ok let _ = y < x; // should be ok diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs index 57c87819dbfe..f804fc9047de 100644 --- a/tests/ui/int_plus_one.rs +++ b/tests/ui/int_plus_one.rs @@ -5,10 +5,14 @@ fn main() { let y = 0i32; let _ = x >= y + 1; + //~^ int_plus_one let _ = y + 1 <= x; + //~^ int_plus_one let _ = x - 1 >= y; + //~^ int_plus_one let _ = y <= x - 1; + //~^ int_plus_one let _ = x > y; // should be ok let _ = y < x; // should be ok diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr index cedac14f350d..052706028141 100644 --- a/tests/ui/int_plus_one.stderr +++ b/tests/ui/int_plus_one.stderr @@ -8,19 +8,19 @@ LL | let _ = x >= y + 1; = help: to override `-D warnings` add `#[allow(clippy::int_plus_one)]` error: unnecessary `>= y + 1` or `x - 1 >=` - --> tests/ui/int_plus_one.rs:8:13 + --> tests/ui/int_plus_one.rs:9:13 | LL | let _ = y + 1 <= x; | ^^^^^^^^^^ help: change it to: `y < x` error: unnecessary `>= y + 1` or `x - 1 >=` - --> tests/ui/int_plus_one.rs:10:13 + --> tests/ui/int_plus_one.rs:12:13 | LL | let _ = x - 1 >= y; | ^^^^^^^^^^ help: change it to: `x > y` error: unnecessary `>= y + 1` or `x - 1 >=` - --> tests/ui/int_plus_one.rs:11:13 + --> tests/ui/int_plus_one.rs:14:13 | LL | let _ = y <= x - 1; | ^^^^^^^^^^ help: change it to: `y < x` diff --git a/tests/ui/integer_division.rs b/tests/ui/integer_division.rs index 137548fecf4a..632fedc9e8fe 100644 --- a/tests/ui/integer_division.rs +++ b/tests/ui/integer_division.rs @@ -3,10 +3,13 @@ fn main() { let two = 2; let n = 1 / 2; - //~^ ERROR: integer division + //~^ integer_division + let o = 1 / two; - //~^ ERROR: integer division + //~^ integer_division + let p = two / 4; - //~^ ERROR: integer division + //~^ integer_division + let x = 1. / 2.0; } diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr index 5f0d905a48b6..0fe2021a1a9c 100644 --- a/tests/ui/integer_division.stderr +++ b/tests/ui/integer_division.stderr @@ -9,7 +9,7 @@ LL | let n = 1 / 2; = help: to override `-D warnings` add `#[allow(clippy::integer_division)]` error: integer division - --> tests/ui/integer_division.rs:7:13 + --> tests/ui/integer_division.rs:8:13 | LL | let o = 1 / two; | ^^^^^^^ @@ -17,7 +17,7 @@ LL | let o = 1 / two; = help: division of integers may cause loss of precision. consider using floats error: integer division - --> tests/ui/integer_division.rs:9:13 + --> tests/ui/integer_division.rs:11:13 | LL | let p = two / 4; | ^^^^^^^ diff --git a/tests/ui/integer_division_remainder_used.rs b/tests/ui/integer_division_remainder_used.rs index 5d1b02095d18..4d3a7c5eaa15 100644 --- a/tests/ui/integer_division_remainder_used.rs +++ b/tests/ui/integer_division_remainder_used.rs @@ -8,6 +8,7 @@ impl std::ops::Div for CustomOps { fn div(self, rhs: Self) -> Self::Output { Self(self.0 / rhs.0) + //~^ integer_division_remainder_used } } impl std::ops::Rem for CustomOps { @@ -15,6 +16,7 @@ impl std::ops::Rem for CustomOps { fn rem(self, rhs: Self) -> Self::Output { Self(self.0 % rhs.0) + //~^ integer_division_remainder_used } } @@ -23,12 +25,19 @@ fn main() { let a = 10; let b = 5; let c = a / b; + //~^ integer_division_remainder_used let d = a % b; + //~^ integer_division_remainder_used let e = &a / b; + //~^ integer_division_remainder_used let f = a % &b; + //~^ integer_division_remainder_used let g = &a / &b; + //~^ integer_division_remainder_used let h = &10 % b; + //~^ integer_division_remainder_used let i = a / &4; + //~^ integer_division_remainder_used // should not trigger on custom Div and Rem let w = CustomOps(3); diff --git a/tests/ui/integer_division_remainder_used.stderr b/tests/ui/integer_division_remainder_used.stderr index 8adfda28893d..ea9f0e716c7d 100644 --- a/tests/ui/integer_division_remainder_used.stderr +++ b/tests/ui/integer_division_remainder_used.stderr @@ -8,49 +8,49 @@ LL | Self(self.0 / rhs.0) = help: to override `-D warnings` add `#[allow(clippy::integer_division_remainder_used)]` error: use of % has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:17:14 + --> tests/ui/integer_division_remainder_used.rs:18:14 | LL | Self(self.0 % rhs.0) | ^^^^^^^^^^^^^^ error: use of / has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:25:13 + --> tests/ui/integer_division_remainder_used.rs:27:13 | LL | let c = a / b; | ^^^^^ error: use of % has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:26:13 + --> tests/ui/integer_division_remainder_used.rs:29:13 | LL | let d = a % b; | ^^^^^ error: use of / has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:27:13 + --> tests/ui/integer_division_remainder_used.rs:31:13 | LL | let e = &a / b; | ^^^^^^ error: use of % has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:28:13 + --> tests/ui/integer_division_remainder_used.rs:33:13 | LL | let f = a % &b; | ^^^^^^ error: use of / has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:29:13 + --> tests/ui/integer_division_remainder_used.rs:35:13 | LL | let g = &a / &b; | ^^^^^^^ error: use of % has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:30:13 + --> tests/ui/integer_division_remainder_used.rs:37:13 | LL | let h = &10 % b; | ^^^^^^^ error: use of / has been disallowed in this context - --> tests/ui/integer_division_remainder_used.rs:31:13 + --> tests/ui/integer_division_remainder_used.rs:39:13 | LL | let i = a / &4; | ^^^^^^ diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index 72b39c982bf7..6d62a6547427 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -10,34 +10,60 @@ fn main() { for _ in &vec![X, X] {} let _ = vec![1, 2, 3].into_iter(); - let _ = (&vec![1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter() - let _ = std::rc::Rc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter() - let _ = std::sync::Arc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter() +let _ = (&vec![1, 2, 3]).iter(); +//~^ into_iter_on_ref +let _ = std::rc::Rc::from(&[X][..]).iter(); +//~^ into_iter_on_ref +let _ = std::sync::Arc::from(&[X][..]).iter(); +//~^ into_iter_on_ref - let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR: equivalent to `.iter_mut() +let _ = (&&&&&&&[1, 2, 3]).iter(); +//~^ into_iter_on_ref +let _ = (&&&&mut &&&[1, 2, 3]).iter(); +//~^ into_iter_on_ref +let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); +//~^ into_iter_on_ref - let _ = (&Some(4)).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Some(5)).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&Ok::<_, i32>(6)).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Err::(7)).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&Vec::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Vec::::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&BTreeMap::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut BTreeMap::::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&VecDeque::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut VecDeque::::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&LinkedList::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut LinkedList::::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&HashMap::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut HashMap::::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut() +let _ = (&Some(4)).iter(); +//~^ into_iter_on_ref +let _ = (&mut Some(5)).iter_mut(); +//~^ into_iter_on_ref +let _ = (&Ok::<_, i32>(6)).iter(); +//~^ into_iter_on_ref +let _ = (&mut Err::(7)).iter_mut(); +//~^ into_iter_on_ref +let _ = (&Vec::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&mut Vec::::new()).iter_mut(); +//~^ into_iter_on_ref +let _ = (&BTreeMap::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&mut BTreeMap::::new()).iter_mut(); +//~^ into_iter_on_ref +let _ = (&VecDeque::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&mut VecDeque::::new()).iter_mut(); +//~^ into_iter_on_ref +let _ = (&LinkedList::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&mut LinkedList::::new()).iter_mut(); +//~^ into_iter_on_ref +let _ = (&HashMap::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&mut HashMap::::new()).iter_mut(); +//~^ into_iter_on_ref - let _ = (&BTreeSet::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&BinaryHeap::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = (&HashSet::::new()).iter(); //~ ERROR: equivalent to `.iter() - let _ = std::path::Path::new("12/34").iter(); //~ ERROR: equivalent to `.iter() - let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR: equivalent to `.iter() +let _ = (&BTreeSet::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&BinaryHeap::::new()).iter(); +//~^ into_iter_on_ref +let _ = (&HashSet::::new()).iter(); +//~^ into_iter_on_ref +let _ = std::path::Path::new("12/34").iter(); +//~^ into_iter_on_ref +let _ = std::path::PathBuf::from("12/34").iter(); +//~^ into_iter_on_ref - let _ = (&[1, 2, 3]).iter().next(); //~ ERROR: equivalent to `.iter() +let _ = (&[1, 2, 3]).iter().next(); +//~^ into_iter_on_ref } diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 5ba224720d34..3e678761d751 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -10,34 +10,60 @@ fn main() { for _ in &vec![X, X] {} let _ = vec![1, 2, 3].into_iter(); - let _ = (&vec![1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter() +let _ = (&vec![1, 2, 3]).into_iter(); +//~^ into_iter_on_ref +let _ = std::rc::Rc::from(&[X][..]).into_iter(); +//~^ into_iter_on_ref +let _ = std::sync::Arc::from(&[X][..]).into_iter(); +//~^ into_iter_on_ref - let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter_mut() +let _ = (&&&&&&&[1, 2, 3]).into_iter(); +//~^ into_iter_on_ref +let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); +//~^ into_iter_on_ref - let _ = (&Some(4)).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Some(5)).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&Ok::<_, i32>(6)).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Err::(7)).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&Vec::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut Vec::::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&BTreeMap::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut BTreeMap::::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&VecDeque::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut VecDeque::::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&LinkedList::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut LinkedList::::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut() - let _ = (&HashMap::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&mut HashMap::::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut() +let _ = (&Some(4)).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut Some(5)).into_iter(); +//~^ into_iter_on_ref +let _ = (&Ok::<_, i32>(6)).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut Err::(7)).into_iter(); +//~^ into_iter_on_ref +let _ = (&Vec::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut Vec::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&BTreeMap::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut BTreeMap::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&VecDeque::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut VecDeque::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&LinkedList::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut LinkedList::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&HashMap::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&mut HashMap::::new()).into_iter(); +//~^ into_iter_on_ref - let _ = (&BTreeSet::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&BinaryHeap::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = (&HashSet::::new()).into_iter(); //~ ERROR: equivalent to `.iter() - let _ = std::path::Path::new("12/34").into_iter(); //~ ERROR: equivalent to `.iter() - let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR: equivalent to `.iter() +let _ = (&BTreeSet::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&BinaryHeap::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = (&HashSet::::new()).into_iter(); +//~^ into_iter_on_ref +let _ = std::path::Path::new("12/34").into_iter(); +//~^ into_iter_on_ref +let _ = std::path::PathBuf::from("12/34").into_iter(); +//~^ into_iter_on_ref - let _ = (&[1, 2, 3]).into_iter().next(); //~ ERROR: equivalent to `.iter() +let _ = (&[1, 2, 3]).into_iter().next(); +//~^ into_iter_on_ref } diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 64d814074da4..2c472fca9da5 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,161 +1,161 @@ error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> tests/ui/into_iter_on_ref.rs:13:30 + --> tests/ui/into_iter_on_ref.rs:13:26 | -LL | let _ = (&vec![1, 2, 3]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +LL | let _ = (&vec![1, 2, 3]).into_iter(); + | ^^^^^^^^^ help: call directly: `iter` | = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::into_iter_on_ref)]` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> tests/ui/into_iter_on_ref.rs:14:41 + --> tests/ui/into_iter_on_ref.rs:15:37 | -LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:15:44 + --> tests/ui/into_iter_on_ref.rs:17:40 | -LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:17:32 + --> tests/ui/into_iter_on_ref.rs:20:28 | -LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); +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` + --> tests/ui/into_iter_on_ref.rs:22:32 + | +LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:18: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` - --> tests/ui/into_iter_on_ref.rs:19:40 + --> tests/ui/into_iter_on_ref.rs:24:36 | -LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:21:24 + --> tests/ui/into_iter_on_ref.rs:27:20 | -LL | let _ = (&Some(4)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:22:28 + --> tests/ui/into_iter_on_ref.rs:29:24 | -LL | let _ = (&mut Some(5)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:23:32 + --> tests/ui/into_iter_on_ref.rs:31:28 | -LL | let _ = (&Ok::<_, i32>(6)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:24:37 + --> tests/ui/into_iter_on_ref.rs:33:33 | -LL | let _ = (&mut Err::(7)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:25:34 + --> tests/ui/into_iter_on_ref.rs:35:30 | -LL | let _ = (&Vec::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:26:38 + --> tests/ui/into_iter_on_ref.rs:37:34 | -LL | let _ = (&mut Vec::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:27:44 + --> tests/ui/into_iter_on_ref.rs:39:40 | -LL | let _ = (&BTreeMap::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:28:48 + --> tests/ui/into_iter_on_ref.rs:41:44 | -LL | let _ = (&mut BTreeMap::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:29:39 + --> tests/ui/into_iter_on_ref.rs:43:35 | -LL | let _ = (&VecDeque::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:30:43 + --> tests/ui/into_iter_on_ref.rs:45:39 | -LL | let _ = (&mut VecDeque::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:31:41 + --> tests/ui/into_iter_on_ref.rs:47:37 | -LL | let _ = (&LinkedList::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:32:45 + --> tests/ui/into_iter_on_ref.rs:49:41 | -LL | let _ = (&mut LinkedList::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:33:43 + --> tests/ui/into_iter_on_ref.rs:51:39 | -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` - --> tests/ui/into_iter_on_ref.rs:34: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` - --> tests/ui/into_iter_on_ref.rs:36:39 - | -LL | let _ = (&BTreeSet::::new()).into_iter(); +LL | let _ = (&HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BinaryHeap` - --> tests/ui/into_iter_on_ref.rs:37:41 +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` + --> tests/ui/into_iter_on_ref.rs:53:43 | -LL | let _ = (&BinaryHeap::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` + --> tests/ui/into_iter_on_ref.rs:56:35 + | +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` + --> tests/ui/into_iter_on_ref.rs:58:37 + | +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` - --> tests/ui/into_iter_on_ref.rs:38:38 + --> tests/ui/into_iter_on_ref.rs:60:34 | -LL | let _ = (&HashSet::::new()).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:39:43 + --> tests/ui/into_iter_on_ref.rs:62:39 | -LL | let _ = std::path::Path::new("12/34").into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:40:47 + --> tests/ui/into_iter_on_ref.rs:64:43 | -LL | let _ = std::path::PathBuf::from("12/34").into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:42:26 + --> tests/ui/into_iter_on_ref.rs:67:22 | -LL | let _ = (&[1, 2, 3]).into_iter().next(); - | ^^^^^^^^^ help: call directly: `iter` +LL | let _ = (&[1, 2, 3]).into_iter().next(); + | ^^^^^^^^^ help: call directly: `iter` error: aborting due to 26 previous errors diff --git a/tests/ui/into_iter_without_iter.rs b/tests/ui/into_iter_without_iter.rs index 109259d6975c..368313af6f91 100644 --- a/tests/ui/into_iter_without_iter.rs +++ b/tests/ui/into_iter_without_iter.rs @@ -7,7 +7,7 @@ use std::iter::IntoIterator; pub struct S1; impl<'a> IntoIterator for &'a S1 { - //~^ ERROR: `IntoIterator` implemented for a reference type without an `iter` method +//~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, u8>; type Item = &'a u8; fn into_iter(self) -> Self::IntoIter { @@ -15,7 +15,7 @@ impl<'a> IntoIterator for &'a S1 { } } impl<'a> IntoIterator for &'a mut S1 { - //~^ ERROR: `IntoIterator` implemented for a reference type without an `iter_mut` method +//~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, u8>; type Item = &'a mut u8; fn into_iter(self) -> Self::IntoIter { @@ -25,7 +25,7 @@ impl<'a> IntoIterator for &'a mut S1 { pub struct S2(T); impl<'a, T> IntoIterator for &'a S2 { - //~^ ERROR: `IntoIterator` implemented for a reference type without an `iter` method +//~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, T>; type Item = &'a T; fn into_iter(self) -> Self::IntoIter { @@ -33,7 +33,7 @@ impl<'a, T> IntoIterator for &'a S2 { } } impl<'a, T> IntoIterator for &'a mut S2 { - //~^ ERROR: `IntoIterator` implemented for a reference type without an `iter_mut` method +//~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, T>; type Item = &'a mut T; fn into_iter(self) -> Self::IntoIter { @@ -84,7 +84,7 @@ impl<'a, T> IntoIterator for &S4<'a, T> { } impl<'a, T> IntoIterator for &mut S4<'a, T> { - //~^ ERROR: `IntoIterator` implemented for a reference type without an `iter_mut` method +//~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, T>; type Item = &'a mut T; fn into_iter(self) -> Self::IntoIter { @@ -118,6 +118,7 @@ pub struct Issue12037; macro_rules! generate_impl { () => { impl<'a> IntoIterator for &'a Issue12037 { + //~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, u8>; type Item = &'a u8; fn into_iter(self) -> Self::IntoIter { diff --git a/tests/ui/into_iter_without_iter.stderr b/tests/ui/into_iter_without_iter.stderr index cde1b60c2abc..a033ff645f49 100644 --- a/tests/ui/into_iter_without_iter.stderr +++ b/tests/ui/into_iter_without_iter.stderr @@ -109,9 +109,9 @@ error: `IntoIterator` implemented for a reference type without an `iter` method --> tests/ui/into_iter_without_iter.rs:120:9 | LL | / impl<'a> IntoIterator for &'a Issue12037 { +LL | | LL | | type IntoIter = std::slice::Iter<'a, u8>; LL | | type Item = &'a u8; -LL | | fn into_iter(self) -> Self::IntoIter { ... | LL | | } | |_________^ diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index ba225102c984..ce78e89ee829 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -1,44 +1,66 @@ fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(std::mem::size_of::(), 0); let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::replace(std::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); std::ptr::swap::(std::ptr::NonNull::dangling().as_ptr(), &mut A); + //~^ invalid_null_ptr_usage std::ptr::swap::(&mut A, std::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(&mut A, std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::write(std::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_unaligned(std::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_volatile(std::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage std::ptr::write_bytes::(std::ptr::NonNull::dangling().as_ptr(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage.rs b/tests/ui/invalid_null_ptr_usage.rs index 480b6642a3e3..361865fbd960 100644 --- a/tests/ui/invalid_null_ptr_usage.rs +++ b/tests/ui/invalid_null_ptr_usage.rs @@ -1,44 +1,66 @@ fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(std::mem::size_of::(), 0); let _a: A = std::ptr::read(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = std::ptr::replace(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); std::ptr::swap::(std::ptr::null_mut(), &mut A); + //~^ invalid_null_ptr_usage std::ptr::swap::(&mut A, std::ptr::null_mut()); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); + //~^ invalid_null_ptr_usage std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage std::ptr::write(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_unaligned(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_volatile(std::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index 613a2cc36885..3f9d15b90401 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -7,127 +7,127 @@ 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 - --> tests/ui/invalid_null_ptr_usage.rs:4:59 + --> tests/ui/invalid_null_ptr_usage.rs:5:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:6:63 + --> tests/ui/invalid_null_ptr_usage.rs:8:63 | LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:8:33 + --> tests/ui/invalid_null_ptr_usage.rs:11:33 | LL | std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:9:73 + --> tests/ui/invalid_null_ptr_usage.rs:13:73 | LL | std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:11:48 + --> tests/ui/invalid_null_ptr_usage.rs:16:48 | LL | std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:12:88 + --> tests/ui/invalid_null_ptr_usage.rs:18:88 | LL | std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:17:36 + --> tests/ui/invalid_null_ptr_usage.rs:24:36 | LL | let _a: A = std::ptr::read(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:18:36 + --> tests/ui/invalid_null_ptr_usage.rs:26:36 | LL | let _a: A = std::ptr::read(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:20:46 + --> tests/ui/invalid_null_ptr_usage.rs:29:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:21:46 + --> tests/ui/invalid_null_ptr_usage.rs:31:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:23:45 + --> tests/ui/invalid_null_ptr_usage.rs:34:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:24:45 + --> tests/ui/invalid_null_ptr_usage.rs:36:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:26:39 + --> tests/ui/invalid_null_ptr_usage.rs:39:39 | LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:30:29 + --> tests/ui/invalid_null_ptr_usage.rs:44:29 | LL | std::ptr::swap::(std::ptr::null_mut(), &mut A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:31:37 + --> tests/ui/invalid_null_ptr_usage.rs:46:37 | LL | std::ptr::swap::(&mut A, std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:33:44 + --> tests/ui/invalid_null_ptr_usage.rs:49:44 | LL | std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:34:52 + --> tests/ui/invalid_null_ptr_usage.rs:51:52 | LL | std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:36:25 + --> tests/ui/invalid_null_ptr_usage.rs:54:25 | LL | std::ptr::write(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:38:35 + --> tests/ui/invalid_null_ptr_usage.rs:57:35 | LL | std::ptr::write_unaligned(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:40:34 + --> tests/ui/invalid_null_ptr_usage.rs:60:34 | LL | std::ptr::write_volatile(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage.rs:42:40 + --> tests/ui/invalid_null_ptr_usage.rs:63:40 | LL | std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` diff --git a/tests/ui/invalid_null_ptr_usage_no_std.fixed b/tests/ui/invalid_null_ptr_usage_no_std.fixed index 2bbfe7274242..df7ab166187d 100644 --- a/tests/ui/invalid_null_ptr_usage_no_std.fixed +++ b/tests/ui/invalid_null_ptr_usage_no_std.fixed @@ -14,44 +14,66 @@ fn panic(info: &PanicInfo) -> ! { fn main() { unsafe { let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(core::mem::size_of::(), 0); let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); core::ptr::swap::(core::ptr::NonNull::dangling().as_ptr(), &mut A); + //~^ invalid_null_ptr_usage core::ptr::swap::(&mut A, core::ptr::NonNull::dangling().as_ptr()); + //~^ invalid_null_ptr_usage core::ptr::swap_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + //~^ invalid_null_ptr_usage core::ptr::swap_nonoverlapping::(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage core::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage core::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + //~^ invalid_null_ptr_usage core::ptr::write_bytes::(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage_no_std.rs b/tests/ui/invalid_null_ptr_usage_no_std.rs index cbce44f7c0d9..38ddfff05535 100644 --- a/tests/ui/invalid_null_ptr_usage_no_std.rs +++ b/tests/ui/invalid_null_ptr_usage_no_std.rs @@ -14,44 +14,66 @@ fn panic(info: &PanicInfo) -> ! { fn main() { unsafe { let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy_nonoverlapping::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + //~^ invalid_null_ptr_usage core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage struct A; // zero sized struct assert_eq!(core::mem::size_of::(), 0); let _a: A = core::ptr::read(core::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read(core::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_unaligned(core::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_volatile(core::ptr::null()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); + //~^ invalid_null_ptr_usage let _a: A = core::ptr::replace(core::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); core::ptr::swap::(core::ptr::null_mut(), &mut A); + //~^ invalid_null_ptr_usage core::ptr::swap::(&mut A, core::ptr::null_mut()); + //~^ invalid_null_ptr_usage core::ptr::swap_nonoverlapping::(core::ptr::null_mut(), &mut A, 0); + //~^ invalid_null_ptr_usage core::ptr::swap_nonoverlapping::(&mut A, core::ptr::null_mut(), 0); + //~^ invalid_null_ptr_usage core::ptr::write(core::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage core::ptr::write_unaligned(core::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage core::ptr::write_volatile(core::ptr::null_mut(), A); + //~^ invalid_null_ptr_usage core::ptr::write_bytes::(core::ptr::null_mut(), 42, 0); + //~^ invalid_null_ptr_usage } } diff --git a/tests/ui/invalid_null_ptr_usage_no_std.stderr b/tests/ui/invalid_null_ptr_usage_no_std.stderr index df0d40e9e072..b5dd21ce6248 100644 --- a/tests/ui/invalid_null_ptr_usage_no_std.stderr +++ b/tests/ui/invalid_null_ptr_usage_no_std.stderr @@ -7,127 +7,127 @@ LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null( = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:17:60 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:18:60 | LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:19:64 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:21:64 | LL | let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:21:34 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:24:34 | LL | core::ptr::copy::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:22:75 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:26:75 | LL | core::ptr::copy::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:24:49 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:29:49 | LL | core::ptr::copy_nonoverlapping::(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:25:90 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:31:90 | LL | core::ptr::copy_nonoverlapping::(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:30:37 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:37:37 | LL | let _a: A = core::ptr::read(core::ptr::null()); | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:31:37 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:39:37 | LL | let _a: A = core::ptr::read(core::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:33:47 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:42:47 | LL | let _a: A = core::ptr::read_unaligned(core::ptr::null()); | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:34:47 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:44:47 | LL | let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:36:46 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:47:46 | LL | let _a: A = core::ptr::read_volatile(core::ptr::null()); | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:37:46 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:49:46 | LL | let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:39:40 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:52:40 | LL | let _a: A = core::ptr::replace(core::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:43:30 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:57:30 | LL | core::ptr::swap::(core::ptr::null_mut(), &mut A); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:44:38 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:59:38 | LL | core::ptr::swap::(&mut A, core::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:46:45 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:62:45 | LL | core::ptr::swap_nonoverlapping::(core::ptr::null_mut(), &mut A, 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:47:53 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:64:53 | LL | core::ptr::swap_nonoverlapping::(&mut A, core::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:49:26 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:67:26 | LL | core::ptr::write(core::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:51:36 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:70:36 | LL | core::ptr::write_unaligned(core::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:53:35 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:73:35 | LL | core::ptr::write_volatile(core::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> tests/ui/invalid_null_ptr_usage_no_std.rs:55:41 + --> tests/ui/invalid_null_ptr_usage_no_std.rs:76:41 | LL | core::ptr::write_bytes::(core::ptr::null_mut(), 42, 0); | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index a9db15f20973..bb2166862efc 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -19,61 +19,85 @@ 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` + //~^ invalid_upcast_comparisons + + (u8 as i32) > 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u8 as u32) == 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u8 as i32) == 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 < (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 < (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 == (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 == (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // inverted of the above (u8 as u32) <= 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u8 as i32) <= 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u8 as u32) != 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u8 as i32) != 300; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 >= (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 >= (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 != (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 300 != (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // 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 + //~^ invalid_upcast_comparisons + -5 != (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // inverted of the above (u8 as i32) >= 0; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + -5 == (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // 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 + //~^ invalid_upcast_comparisons + 1337 == (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // inverted of the above 1337 != (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + 1337 != (u8 as u32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + // Those are Ok: (u8 as u32) > 20; @@ -88,9 +112,11 @@ 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 + //~^ invalid_upcast_comparisons + (u8 as i32) < -1; - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + (u32 as i32) < -5; (u32 as i32) < 10; @@ -107,7 +133,8 @@ fn main() { -5 > (u32 as i32); -5 >= (u8 as i32); - //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~^ invalid_upcast_comparisons + -5 == (u32 as i32); } diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index b1fbe2951577..911022c005c9 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -8,157 +8,157 @@ LL | (u8 as u32) > 300; = help: to override `-D warnings` add `#[allow(clippy::invalid_upcast_comparisons)]` error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:24:5 + --> tests/ui/invalid_upcast_comparisons.rs:25:5 | LL | (u8 as i32) > 300; | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:26:5 + --> tests/ui/invalid_upcast_comparisons.rs:28:5 | LL | (u8 as u32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:28:5 + --> tests/ui/invalid_upcast_comparisons.rs:31:5 | LL | (u8 as i32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:30:5 + --> tests/ui/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 - --> tests/ui/invalid_upcast_comparisons.rs:32:5 + --> tests/ui/invalid_upcast_comparisons.rs:37:5 | LL | 300 < (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:34:5 + --> tests/ui/invalid_upcast_comparisons.rs:40:5 | LL | 300 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:36:5 + --> tests/ui/invalid_upcast_comparisons.rs:43:5 | LL | 300 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:39:5 + --> tests/ui/invalid_upcast_comparisons.rs:47:5 | LL | (u8 as u32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:41:5 + --> tests/ui/invalid_upcast_comparisons.rs:50:5 | LL | (u8 as i32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:43:5 + --> tests/ui/invalid_upcast_comparisons.rs:53:5 | LL | (u8 as u32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:45:5 + --> tests/ui/invalid_upcast_comparisons.rs:56:5 | LL | (u8 as i32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:47:5 + --> tests/ui/invalid_upcast_comparisons.rs:59:5 | LL | 300 >= (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:49:5 + --> tests/ui/invalid_upcast_comparisons.rs:62:5 | LL | 300 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:51:5 + --> tests/ui/invalid_upcast_comparisons.rs:65:5 | LL | 300 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:53:5 + --> tests/ui/invalid_upcast_comparisons.rs:68:5 | LL | 300 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:57:5 + --> tests/ui/invalid_upcast_comparisons.rs:73:5 | LL | (u8 as i32) < 0; | ^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:59:5 + --> tests/ui/invalid_upcast_comparisons.rs:76:5 | LL | -5 != (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:62:5 + --> tests/ui/invalid_upcast_comparisons.rs:80:5 | LL | (u8 as i32) >= 0; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:64:5 + --> tests/ui/invalid_upcast_comparisons.rs:83:5 | LL | -5 == (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:68:5 + --> tests/ui/invalid_upcast_comparisons.rs:88:5 | LL | 1337 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:70:5 + --> tests/ui/invalid_upcast_comparisons.rs:91:5 | LL | 1337 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:73:5 + --> tests/ui/invalid_upcast_comparisons.rs:95:5 | LL | 1337 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:75:5 + --> tests/ui/invalid_upcast_comparisons.rs:98:5 | LL | 1337 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:90:5 + --> tests/ui/invalid_upcast_comparisons.rs:114:5 | LL | (u8 as i32) > -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:92:5 + --> tests/ui/invalid_upcast_comparisons.rs:117:5 | LL | (u8 as i32) < -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:109:5 + --> tests/ui/invalid_upcast_comparisons.rs:135:5 | LL | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/is_digit_ascii_radix.fixed b/tests/ui/is_digit_ascii_radix.fixed index 62953ff74cfc..b0509ed2a751 100644 --- a/tests/ui/is_digit_ascii_radix.fixed +++ b/tests/ui/is_digit_ascii_radix.fixed @@ -7,8 +7,11 @@ fn main() { // Should trigger the lint. let _ = c.is_ascii_digit(); + //~^ is_digit_ascii_radix let _ = c.is_ascii_hexdigit(); + //~^ is_digit_ascii_radix let _ = c.is_ascii_hexdigit(); + //~^ is_digit_ascii_radix // Should not trigger the lint. let _ = c.is_digit(11); diff --git a/tests/ui/is_digit_ascii_radix.rs b/tests/ui/is_digit_ascii_radix.rs index 229f530f611d..68d4b56063b5 100644 --- a/tests/ui/is_digit_ascii_radix.rs +++ b/tests/ui/is_digit_ascii_radix.rs @@ -7,8 +7,11 @@ fn main() { // Should trigger the lint. let _ = c.is_digit(10); + //~^ is_digit_ascii_radix let _ = c.is_digit(16); + //~^ is_digit_ascii_radix let _ = c.is_digit(0x10); + //~^ is_digit_ascii_radix // Should not trigger the lint. let _ = c.is_digit(11); diff --git a/tests/ui/is_digit_ascii_radix.stderr b/tests/ui/is_digit_ascii_radix.stderr index f26183ddab84..b6e53eb5829f 100644 --- a/tests/ui/is_digit_ascii_radix.stderr +++ b/tests/ui/is_digit_ascii_radix.stderr @@ -8,13 +8,13 @@ LL | let _ = c.is_digit(10); = help: to override `-D warnings` add `#[allow(clippy::is_digit_ascii_radix)]` error: use of `char::is_digit` with literal radix of 16 - --> tests/ui/is_digit_ascii_radix.rs:10:13 + --> tests/ui/is_digit_ascii_radix.rs:11:13 | LL | let _ = c.is_digit(16); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` error: use of `char::is_digit` with literal radix of 16 - --> tests/ui/is_digit_ascii_radix.rs:11:13 + --> tests/ui/is_digit_ascii_radix.rs:13:13 | LL | let _ = c.is_digit(0x10); | ^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` diff --git a/tests/ui/issue-111399.rs b/tests/ui/issue-111399.rs index b65e6c7261a5..2a6436b4b4eb 100644 --- a/tests/ui/issue-111399.rs +++ b/tests/ui/issue-111399.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(inherent_associated_types)] #![allow(incomplete_features)] diff --git a/tests/ui/issue-7447.rs b/tests/ui/issue-7447.rs index 7e7ef209d485..25ace345ad14 100644 --- a/tests/ui/issue-7447.rs +++ b/tests/ui/issue-7447.rs @@ -24,8 +24,10 @@ pub struct ByteView<'a> { fn main() { byte_view(panic!()); - //~^ ERROR: sub-expression diverges - //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` + //~^ diverging_sub_expression + + group_entries(panic!()); - //~^ ERROR: sub-expression diverges + //~^ diverging_sub_expression + } diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 5e28c1423840..1ba53631b52d 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -9,7 +9,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 - --> tests/ui/issue-7447.rs:29:19 + --> tests/ui/issue-7447.rs:30:19 | LL | group_entries(panic!()); | ^^^^^^^^ diff --git a/tests/ui/issue_2356.fixed b/tests/ui/issue_2356.fixed index 892aa4e34216..c96d3c1a24f9 100644 --- a/tests/ui/issue_2356.fixed +++ b/tests/ui/issue_2356.fixed @@ -15,6 +15,7 @@ impl Foo { fn foo2>(mut it: I) { for e in it { + //~^ while_let_on_iterator println!("{:?}", e); } } diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs index da0eead15b39..a4040cb37ced 100644 --- a/tests/ui/issue_2356.rs +++ b/tests/ui/issue_2356.rs @@ -15,6 +15,7 @@ impl Foo { fn foo2>(mut it: I) { while let Some(e) = it.next() { + //~^ while_let_on_iterator println!("{:?}", e); } } diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index 23453207b4e5..aabf72a93ce2 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -2,13 +2,15 @@ #![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` +//~^ needless_lifetimes + + 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 +//~^ needless_lifetimes + s } @@ -29,7 +31,8 @@ struct Foo; impl Foo { // ok pub async fn new(&mut self) -> Self { - //~^ ERROR: methods called `new` usually take no `self` + //~^ wrong_self_convention + Foo {} } } diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 63c568a153b2..ce0588521810 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -8,13 +8,13 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` error: the following explicit lifetimes could be elided: 'a - --> tests/ui/issue_4266.rs:10:21 + --> tests/ui/issue_4266.rs:11:21 | LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { | ^^ ^^ ^^ error: methods called `new` usually take no `self` - --> tests/ui/issue_4266.rs:31:22 + --> tests/ui/issue_4266.rs:33: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 943e7c116760..db3583464e9a 100644 --- a/tests/ui/items_after_statement.rs +++ b/tests/ui/items_after_statement.rs @@ -11,8 +11,9 @@ 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` + //~^ items_after_statements + + println!("foo"); } } @@ -20,7 +21,8 @@ fn last() { fn main() { foo(); fn foo() { - //~^ ERROR: adding items after statements is confusing, since items exist from the sta + //~^ items_after_statements + println!("foo"); } foo(); @@ -34,6 +36,7 @@ fn mac() { () => {{ a = 6; fn say_something() { + //~^ items_after_statements println!("something"); } }}; diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index 0f1989d4c9fc..d6186f1305a0 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -2,9 +2,7 @@ error: adding items after statements is confusing, since items exist from the st --> tests/ui/items_after_statement.rs:13:5 | LL | / fn foo() { -LL | | -LL | | -LL | | println!("foo"); +... | LL | | } | |_____^ | @@ -12,18 +10,20 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::items_after_statements)]` error: adding items after statements is confusing, since items exist from the start of the scope - --> tests/ui/items_after_statement.rs:22:5 + --> tests/ui/items_after_statement.rs:23:5 | LL | / fn foo() { LL | | +LL | | LL | | println!("foo"); LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> tests/ui/items_after_statement.rs:36:13 + --> tests/ui/items_after_statement.rs:38:13 | LL | / fn say_something() { +LL | | LL | | println!("something"); LL | | } | |_____________^ diff --git a/tests/ui/items_after_test_module/after_proc_macros.rs b/tests/ui/items_after_test_module/after_proc_macros.rs index d9c0aef88c8c..54a04988cda0 100644 --- a/tests/ui/items_after_test_module/after_proc_macros.rs +++ b/tests/ui/items_after_test_module/after_proc_macros.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:../auxiliary/proc_macros.rs extern crate proc_macros; diff --git a/tests/ui/items_after_test_module/imported_module.rs b/tests/ui/items_after_test_module/imported_module.rs index 6a757aef48e7..d756be5b433e 100644 --- a/tests/ui/items_after_test_module/imported_module.rs +++ b/tests/ui/items_after_test_module/imported_module.rs @@ -1,3 +1,4 @@ +//@ check-pass //@compile-flags: --test #![allow(unused)] #![warn(clippy::items_after_test_module)] diff --git a/tests/ui/items_after_test_module/in_submodule.rs b/tests/ui/items_after_test_module/in_submodule.rs index 7132e71764eb..6ca100c07f96 100644 --- a/tests/ui/items_after_test_module/in_submodule.rs +++ b/tests/ui/items_after_test_module/in_submodule.rs @@ -1,3 +1,4 @@ +//@error-in-other-file: #[path = "auxiliary/submodule.rs"] mod submodule; diff --git a/tests/ui/items_after_test_module/multiple_modules.rs b/tests/ui/items_after_test_module/multiple_modules.rs index 8ab9e8200f18..8618710654a5 100644 --- a/tests/ui/items_after_test_module/multiple_modules.rs +++ b/tests/ui/items_after_test_module/multiple_modules.rs @@ -1,3 +1,5 @@ +//@ check-pass + #[cfg(test)] mod tests { #[test] diff --git a/tests/ui/items_after_test_module/root_module.fixed b/tests/ui/items_after_test_module/root_module.fixed index d444100a76b9..25eff3d38f76 100644 --- a/tests/ui/items_after_test_module/root_module.fixed +++ b/tests/ui/items_after_test_module/root_module.fixed @@ -17,6 +17,7 @@ macro_rules! should_lint { #[allow(clippy::allow_attributes)] #[cfg(test)] mod tests { +//~^ items_after_test_module #[test] fn hi() {} } diff --git a/tests/ui/items_after_test_module/root_module.rs b/tests/ui/items_after_test_module/root_module.rs index 57da01639cca..94afffd92de5 100644 --- a/tests/ui/items_after_test_module/root_module.rs +++ b/tests/ui/items_after_test_module/root_module.rs @@ -10,6 +10,7 @@ fn should_not_lint() {} #[allow(clippy::allow_attributes)] #[cfg(test)] mod tests { +//~^ items_after_test_module #[test] fn hi() {} } diff --git a/tests/ui/iter_cloned_collect.fixed b/tests/ui/iter_cloned_collect.fixed index 1d623642a713..e9fb44e89598 100644 --- a/tests/ui/iter_cloned_collect.fixed +++ b/tests/ui/iter_cloned_collect.fixed @@ -6,11 +6,13 @@ use std::collections::{HashSet, VecDeque}; fn main() { let v = [1, 2, 3, 4, 5]; let v2: Vec = v.to_vec(); + //~^ iter_cloned_collect let v3: HashSet = v.iter().cloned().collect(); let v4: VecDeque = v.iter().cloned().collect(); // Handle macro expansion in suggestion let _: Vec = vec![1, 2, 3].to_vec(); + //~^ iter_cloned_collect // Issue #3704 unsafe { @@ -21,7 +23,9 @@ fn main() { // Issue #6808 let arr: [u8; 64] = [0; 64]; let _: Vec<_> = arr.to_vec(); + //~^ iter_cloned_collect // Issue #6703 let _: Vec = v.to_vec(); + //~^ iter_cloned_collect } diff --git a/tests/ui/iter_cloned_collect.rs b/tests/ui/iter_cloned_collect.rs index 091bd9eaf081..c9b8abcc9a0d 100644 --- a/tests/ui/iter_cloned_collect.rs +++ b/tests/ui/iter_cloned_collect.rs @@ -6,16 +6,19 @@ use std::collections::{HashSet, VecDeque}; fn main() { let v = [1, 2, 3, 4, 5]; let v2: Vec = v.iter().cloned().collect(); + //~^ iter_cloned_collect let v3: HashSet = v.iter().cloned().collect(); let v4: VecDeque = v.iter().cloned().collect(); // Handle macro expansion in suggestion let _: Vec = vec![1, 2, 3].iter().cloned().collect(); + //~^ iter_cloned_collect // Issue #3704 unsafe { let _: Vec = std::ffi::CStr::from_ptr(std::ptr::null()) .to_bytes() + //~^ iter_cloned_collect .iter() .cloned() .collect(); @@ -24,7 +27,9 @@ fn main() { // Issue #6808 let arr: [u8; 64] = [0; 64]; let _: Vec<_> = arr.iter().cloned().collect(); + //~^ iter_cloned_collect // Issue #6703 let _: Vec = v.iter().copied().collect(); + //~^ iter_cloned_collect } diff --git a/tests/ui/iter_cloned_collect.stderr b/tests/ui/iter_cloned_collect.stderr index e8d82ec2c1b3..119698cb4634 100644 --- a/tests/ui/iter_cloned_collect.stderr +++ b/tests/ui/iter_cloned_collect.stderr @@ -8,29 +8,30 @@ LL | let v2: Vec = v.iter().cloned().collect(); = help: to override `-D warnings` add `#[allow(clippy::iter_cloned_collect)]` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> tests/ui/iter_cloned_collect.rs:13:38 + --> tests/ui/iter_cloned_collect.rs:14: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 - --> tests/ui/iter_cloned_collect.rs:18:24 + --> tests/ui/iter_cloned_collect.rs:20:24 | LL | .to_bytes() | ________________________^ +LL | | LL | | .iter() LL | | .cloned() 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 - --> tests/ui/iter_cloned_collect.rs:26:24 + --> tests/ui/iter_cloned_collect.rs:29: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 - --> tests/ui/iter_cloned_collect.rs:29:26 + --> tests/ui/iter_cloned_collect.rs:33: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 75c007bb0c99..2e187e5bfa75 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -52,32 +52,57 @@ fn main() { binary_heap.push(1); &vec[..].len(); + //~^ iter_count vec.len(); + //~^ iter_count boxed_slice.len(); + //~^ iter_count vec_deque.len(); + //~^ iter_count hash_set.len(); + //~^ iter_count hash_map.len(); + //~^ iter_count b_tree_map.len(); + //~^ iter_count b_tree_set.len(); + //~^ iter_count linked_list.len(); + //~^ iter_count binary_heap.len(); + //~^ iter_count vec.len(); + //~^ iter_count &vec[..].len(); + //~^ iter_count vec_deque.len(); + //~^ iter_count hash_map.len(); + //~^ iter_count b_tree_map.len(); + //~^ iter_count linked_list.len(); + //~^ iter_count &vec[..].len(); + //~^ iter_count vec.len(); + //~^ iter_count vec_deque.len(); + //~^ iter_count hash_set.len(); + //~^ iter_count hash_map.len(); + //~^ iter_count b_tree_map.len(); + //~^ iter_count b_tree_set.len(); + //~^ iter_count linked_list.len(); + //~^ iter_count binary_heap.len(); + //~^ iter_count // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index cd8207b2c5dc..e941892136ec 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -52,32 +52,57 @@ fn main() { binary_heap.push(1); &vec[..].iter().count(); + //~^ iter_count vec.iter().count(); + //~^ iter_count boxed_slice.iter().count(); + //~^ iter_count vec_deque.iter().count(); + //~^ iter_count hash_set.iter().count(); + //~^ iter_count hash_map.iter().count(); + //~^ iter_count b_tree_map.iter().count(); + //~^ iter_count b_tree_set.iter().count(); + //~^ iter_count linked_list.iter().count(); + //~^ iter_count binary_heap.iter().count(); + //~^ iter_count vec.iter_mut().count(); + //~^ iter_count &vec[..].iter_mut().count(); + //~^ iter_count vec_deque.iter_mut().count(); + //~^ iter_count hash_map.iter_mut().count(); + //~^ iter_count b_tree_map.iter_mut().count(); + //~^ iter_count linked_list.iter_mut().count(); + //~^ iter_count &vec[..].into_iter().count(); + //~^ iter_count vec.into_iter().count(); + //~^ iter_count vec_deque.into_iter().count(); + //~^ iter_count hash_set.into_iter().count(); + //~^ iter_count hash_map.into_iter().count(); + //~^ iter_count b_tree_map.into_iter().count(); + //~^ iter_count b_tree_set.into_iter().count(); + //~^ iter_count linked_list.into_iter().count(); + //~^ iter_count binary_heap.into_iter().count(); + //~^ iter_count // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_count.stderr b/tests/ui/iter_count.stderr index b703310731f3..a5ccefd9048d 100644 --- a/tests/ui/iter_count.stderr +++ b/tests/ui/iter_count.stderr @@ -8,145 +8,145 @@ LL | &vec[..].iter().count(); = help: to override `-D warnings` add `#[allow(clippy::iter_count)]` error: called `.iter().count()` on a `Vec` - --> tests/ui/iter_count.rs:55:5 + --> tests/ui/iter_count.rs:56:5 | LL | vec.iter().count(); | ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter().count()` on a `slice` - --> tests/ui/iter_count.rs:56:5 + --> tests/ui/iter_count.rs:58:5 | LL | boxed_slice.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()` error: called `.iter().count()` on a `VecDeque` - --> tests/ui/iter_count.rs:57:5 + --> tests/ui/iter_count.rs:60:5 | LL | vec_deque.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter().count()` on a `HashSet` - --> tests/ui/iter_count.rs:58:5 + --> tests/ui/iter_count.rs:62:5 | LL | hash_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.iter().count()` on a `HashMap` - --> tests/ui/iter_count.rs:59:5 + --> tests/ui/iter_count.rs:64:5 | LL | hash_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter().count()` on a `BTreeMap` - --> tests/ui/iter_count.rs:60:5 + --> tests/ui/iter_count.rs:66:5 | LL | b_tree_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter().count()` on a `BTreeSet` - --> tests/ui/iter_count.rs:61:5 + --> tests/ui/iter_count.rs:68:5 | LL | b_tree_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.iter().count()` on a `LinkedList` - --> tests/ui/iter_count.rs:62:5 + --> tests/ui/iter_count.rs:70:5 | LL | linked_list.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.iter().count()` on a `BinaryHeap` - --> tests/ui/iter_count.rs:63:5 + --> tests/ui/iter_count.rs:72:5 | LL | binary_heap.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` error: called `.iter_mut().count()` on a `Vec` - --> tests/ui/iter_count.rs:65:5 + --> tests/ui/iter_count.rs:75:5 | LL | vec.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter_mut().count()` on a `slice` - --> tests/ui/iter_count.rs:66:6 + --> tests/ui/iter_count.rs:77:6 | LL | &vec[..].iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.iter_mut().count()` on a `VecDeque` - --> tests/ui/iter_count.rs:67:5 + --> tests/ui/iter_count.rs:79:5 | LL | vec_deque.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter_mut().count()` on a `HashMap` - --> tests/ui/iter_count.rs:68:5 + --> tests/ui/iter_count.rs:81:5 | LL | hash_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter_mut().count()` on a `BTreeMap` - --> tests/ui/iter_count.rs:69:5 + --> tests/ui/iter_count.rs:83:5 | LL | b_tree_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter_mut().count()` on a `LinkedList` - --> tests/ui/iter_count.rs:70:5 + --> tests/ui/iter_count.rs:85:5 | LL | linked_list.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `slice` - --> tests/ui/iter_count.rs:72:6 + --> tests/ui/iter_count.rs:88:6 | LL | &vec[..].into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.into_iter().count()` on a `Vec` - --> tests/ui/iter_count.rs:73:5 + --> tests/ui/iter_count.rs:90:5 | LL | vec.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.into_iter().count()` on a `VecDeque` - --> tests/ui/iter_count.rs:74:5 + --> tests/ui/iter_count.rs:92:5 | LL | vec_deque.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.into_iter().count()` on a `HashSet` - --> tests/ui/iter_count.rs:75:5 + --> tests/ui/iter_count.rs:94:5 | LL | hash_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.into_iter().count()` on a `HashMap` - --> tests/ui/iter_count.rs:76:5 + --> tests/ui/iter_count.rs:96:5 | LL | hash_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.into_iter().count()` on a `BTreeMap` - --> tests/ui/iter_count.rs:77:5 + --> tests/ui/iter_count.rs:98:5 | LL | b_tree_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.into_iter().count()` on a `BTreeSet` - --> tests/ui/iter_count.rs:78:5 + --> tests/ui/iter_count.rs:100:5 | LL | b_tree_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.into_iter().count()` on a `LinkedList` - --> tests/ui/iter_count.rs:79:5 + --> tests/ui/iter_count.rs:102:5 | LL | linked_list.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `BinaryHeap` - --> tests/ui/iter_count.rs:80:5 + --> tests/ui/iter_count.rs:104:5 | LL | binary_heap.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` diff --git a/tests/ui/iter_filter_is_ok.fixed b/tests/ui/iter_filter_is_ok.fixed index 80db8b29c18e..d3aeeff7d7b4 100644 --- a/tests/ui/iter_filter_is_ok.fixed +++ b/tests/ui/iter_filter_is_ok.fixed @@ -9,51 +9,63 @@ fn main() { { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } } diff --git a/tests/ui/iter_filter_is_ok.rs b/tests/ui/iter_filter_is_ok.rs index 89b083b84f32..7ed974876693 100644 --- a/tests/ui/iter_filter_is_ok.rs +++ b/tests/ui/iter_filter_is_ok.rs @@ -9,51 +9,63 @@ fn main() { { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(Result::is_ok); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| a.is_ok()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(std::result::Result::is_ok); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(|a| std::result::Result::is_ok(a)); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_ok + } } diff --git a/tests/ui/iter_filter_is_ok.stderr b/tests/ui/iter_filter_is_ok.stderr index 0aff60224e0e..56c60c093a4b 100644 --- a/tests/ui/iter_filter_is_ok.stderr +++ b/tests/ui/iter_filter_is_ok.stderr @@ -8,23 +8,17 @@ LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(Result::is_ok = help: to override `-D warnings` add `#[allow(clippy::iter_filter_is_ok)]` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:13:56 + --> tests/ui/iter_filter_is_ok.rs:14:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:16:49 + --> tests/ui/iter_filter_is_ok.rs:18:49 | LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` -error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:21:56 - | -LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); - | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` - error: `filter` for `is_ok` on iterator over `Result`s --> tests/ui/iter_filter_is_ok.rs:24:56 | @@ -32,43 +26,49 @@ LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok( | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:28:49 + --> tests/ui/iter_filter_is_ok.rs:28:56 + | +LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` + +error: `filter` for `is_ok` on iterator over `Result`s + --> tests/ui/iter_filter_is_ok.rs:33:49 | LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:35:14 + --> tests/ui/iter_filter_is_ok.rs:41:14 | LL | .filter(std::result::Result::is_ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:40:14 + --> tests/ui/iter_filter_is_ok.rs:47:14 | LL | .filter(|a| std::result::Result::is_ok(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:43:56 + --> tests/ui/iter_filter_is_ok.rs:51:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:48:56 + --> tests/ui/iter_filter_is_ok.rs:57:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:51:56 + --> tests/ui/iter_filter_is_ok.rs:61:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:55:49 + --> tests/ui/iter_filter_is_ok.rs:66:49 | LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/iter_filter_is_some.fixed b/tests/ui/iter_filter_is_some.fixed index 8a818c0c6728..f76e7a619079 100644 --- a/tests/ui/iter_filter_is_some.fixed +++ b/tests/ui/iter_filter_is_some.fixed @@ -13,45 +13,55 @@ use std::collections::HashMap; fn main() { { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } } diff --git a/tests/ui/iter_filter_is_some.rs b/tests/ui/iter_filter_is_some.rs index 9eda93a25921..536af0021420 100644 --- a/tests/ui/iter_filter_is_some.rs +++ b/tests/ui/iter_filter_is_some.rs @@ -13,45 +13,55 @@ use std::collections::HashMap; fn main() { { let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_some); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| a.is_some()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(std::option::Option::is_some); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(|a| std::option::Option::is_some(a)); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); - //~^ HELP: consider using `flatten` instead + //~^ iter_filter_is_some + } } diff --git a/tests/ui/iter_filter_is_some.stderr b/tests/ui/iter_filter_is_some.stderr index 54aff892b1f0..d1653fe1b7a3 100644 --- a/tests/ui/iter_filter_is_some.stderr +++ b/tests/ui/iter_filter_is_some.stderr @@ -8,55 +8,55 @@ LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(Option::is_ = help: to override `-D warnings` add `#[allow(clippy::iter_filter_is_some)]` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:17:58 + --> tests/ui/iter_filter_is_some.rs:18:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:20:58 + --> tests/ui/iter_filter_is_some.rs:22:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:27:14 + --> tests/ui/iter_filter_is_some.rs:30:14 | LL | .filter(std::option::Option::is_some); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:32:14 + --> tests/ui/iter_filter_is_some.rs:36:14 | LL | .filter(|a| std::option::Option::is_some(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:35:58 + --> tests/ui/iter_filter_is_some.rs:40:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:40:58 + --> tests/ui/iter_filter_is_some.rs:46:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:44:58 + --> tests/ui/iter_filter_is_some.rs:51:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:49:58 + --> tests/ui/iter_filter_is_some.rs:57:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:53:58 + --> tests/ui/iter_filter_is_some.rs:62:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/iter_kv_map.fixed b/tests/ui/iter_kv_map.fixed index 2cbf972fca5f..b9d86d8dd803 100644 --- a/tests/ui/iter_kv_map.fixed +++ b/tests/ui/iter_kv_map.fixed @@ -12,17 +12,26 @@ fn main() { let map: HashMap = HashMap::new(); let _ = map.keys().collect::>(); + //~^ iter_kv_map let _ = map.values().collect::>(); + //~^ iter_kv_map let _ = map.values().map(|v| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().map(|val| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().values().collect::>(); + //~^ iter_kv_map let _ = map.keys().filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -33,13 +42,17 @@ fn main() { // Lint let _ = map.keys().map(|key| key * 9).count(); + //~^ iter_kv_map let _ = map.values().map(|value| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. let _ = map + //~^ iter_kv_map .clone().into_values().map(|mut val| { val += 2; val @@ -48,21 +61,31 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_values().count(); + //~^ iter_kv_map let map: BTreeMap = BTreeMap::new(); let _ = map.keys().collect::>(); + //~^ iter_kv_map let _ = map.values().collect::>(); + //~^ iter_kv_map let _ = map.values().map(|v| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().collect::>(); + //~^ iter_kv_map let _ = map.clone().into_values().map(|val| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().values().collect::>(); + //~^ iter_kv_map let _ = map.keys().filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -73,13 +96,17 @@ fn main() { // Lint let _ = map.keys().map(|key| key * 9).count(); + //~^ iter_kv_map let _ = map.values().map(|value| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. let _ = map + //~^ iter_kv_map .clone().into_values().map(|mut val| { val += 2; val @@ -88,6 +115,7 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_values().count(); + //~^ iter_kv_map } #[clippy::msrv = "1.53"] @@ -103,11 +131,14 @@ fn msrv_1_53() { // Lint let _ = map.keys().collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.values().collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.values().map(|v| v + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + } #[clippy::msrv = "1.54"] @@ -116,19 +147,26 @@ fn msrv_1_54() { let map: HashMap = HashMap::new(); let _ = map.clone().into_keys().collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.clone().into_values().collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.clone().into_values().map(|val| val + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.keys().collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.values().collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.values().map(|v| v + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + } diff --git a/tests/ui/iter_kv_map.rs b/tests/ui/iter_kv_map.rs index 6a9a4267a765..b14786180b1f 100644 --- a/tests/ui/iter_kv_map.rs +++ b/tests/ui/iter_kv_map.rs @@ -12,17 +12,26 @@ fn main() { let map: HashMap = HashMap::new(); let _ = map.iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, value)| value).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, v)| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -33,13 +42,17 @@ fn main() { // Lint let _ = map.iter().map(|(key, _value)| key * 9).count(); + //~^ iter_kv_map let _ = map.iter().map(|(_key, value)| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. let _ = map + //~^ iter_kv_map .clone() .into_iter() .map(|(_, mut val)| { @@ -50,21 +63,31 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); + //~^ iter_kv_map let map: BTreeMap = BTreeMap::new(); let _ = map.iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, value)| value).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(_, v)| v + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); + //~^ iter_kv_map let _ = map.clone().iter().map(|(_, val)| val).collect::>(); + //~^ iter_kv_map let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); + //~^ iter_kv_map // Don't lint let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count(); @@ -75,13 +98,17 @@ fn main() { // Lint let _ = map.iter().map(|(key, _value)| key * 9).count(); + //~^ iter_kv_map let _ = map.iter().map(|(_key, value)| value * 17).count(); + //~^ iter_kv_map // Preserve the ref in the fix. let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); + //~^ iter_kv_map // Preserve the mut in the fix. let _ = map + //~^ iter_kv_map .clone() .into_iter() .map(|(_, mut val)| { @@ -92,6 +119,7 @@ fn main() { // Don't let a mut interfere. let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); + //~^ iter_kv_map } #[clippy::msrv = "1.53"] @@ -107,11 +135,14 @@ fn msrv_1_53() { // Lint let _ = map.iter().map(|(key, _)| key).collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.iter().map(|(_, value)| value).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.iter().map(|(_, v)| v + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + } #[clippy::msrv = "1.54"] @@ -120,19 +151,26 @@ fn msrv_1_54() { let map: HashMap = HashMap::new(); let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.iter().map(|(key, _)| key).collect::>(); - //~^ ERROR: iterating on a map's keys + //~^ iter_kv_map + let _ = map.iter().map(|(_, value)| value).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + let _ = map.iter().map(|(_, v)| v + 2).collect::>(); - //~^ ERROR: iterating on a map's values + //~^ iter_kv_map + } diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr index ad23dba55cb6..d99fea1124a7 100644 --- a/tests/ui/iter_kv_map.stderr +++ b/tests/ui/iter_kv_map.stderr @@ -8,80 +8,80 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::>(); = help: to override `-D warnings` add `#[allow(clippy::iter_kv_map)]` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:15:13 + --> tests/ui/iter_kv_map.rs:16:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:16:13 + --> tests/ui/iter_kv_map.rs:18: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 - --> tests/ui/iter_kv_map.rs:18:13 + --> tests/ui/iter_kv_map.rs:21:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> tests/ui/iter_kv_map.rs:19:13 + --> tests/ui/iter_kv_map.rs:23: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 - --> tests/ui/iter_kv_map.rs:21:13 + --> tests/ui/iter_kv_map.rs:26:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:22:13 + --> tests/ui/iter_kv_map.rs:28: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 - --> tests/ui/iter_kv_map.rs:24:13 + --> tests/ui/iter_kv_map.rs:31:13 | LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` error: iterating on a map's keys - --> tests/ui/iter_kv_map.rs:25:13 + --> tests/ui/iter_kv_map.rs:33: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 - --> tests/ui/iter_kv_map.rs:35:13 + --> tests/ui/iter_kv_map.rs:44: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 - --> tests/ui/iter_kv_map.rs:36:13 + --> tests/ui/iter_kv_map.rs:46: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 - --> tests/ui/iter_kv_map.rs:39:13 + --> tests/ui/iter_kv_map.rs:50: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 - --> tests/ui/iter_kv_map.rs:42:13 + --> tests/ui/iter_kv_map.rs:54:13 | LL | let _ = map | _____________^ +LL | | LL | | .clone() LL | | .into_iter() -LL | | .map(|(_, mut val)| { -LL | | val += 2; +... | LL | | val LL | | }) | |__________^ @@ -89,6 +89,7 @@ LL | | }) help: try | LL ~ let _ = map +LL + LL + .clone().into_values().map(|mut val| { LL + val += 2; LL + val @@ -96,92 +97,92 @@ LL + }) | error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:52:13 + --> tests/ui/iter_kv_map.rs:65: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 - --> tests/ui/iter_kv_map.rs:56:13 + --> tests/ui/iter_kv_map.rs:70:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:57:13 + --> tests/ui/iter_kv_map.rs:72:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:58:13 + --> tests/ui/iter_kv_map.rs:74: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 - --> tests/ui/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 - --> tests/ui/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 - --> tests/ui/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 - --> tests/ui/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 - --> tests/ui/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 - --> tests/ui/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 --> tests/ui/iter_kv_map.rs:77:13 | +LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` + +error: iterating on a map's keys + --> tests/ui/iter_kv_map.rs:79: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 + --> tests/ui/iter_kv_map.rs:82:13 + | +LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` + +error: iterating on a map's values + --> tests/ui/iter_kv_map.rs:84: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 + --> tests/ui/iter_kv_map.rs:87:13 + | +LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` + +error: iterating on a map's keys + --> tests/ui/iter_kv_map.rs:89: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 + --> tests/ui/iter_kv_map.rs:100: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 - --> tests/ui/iter_kv_map.rs:78:13 + --> tests/ui/iter_kv_map.rs:102: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 - --> tests/ui/iter_kv_map.rs:81:13 + --> tests/ui/iter_kv_map.rs:106: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 - --> tests/ui/iter_kv_map.rs:84:13 + --> tests/ui/iter_kv_map.rs:110:13 | LL | let _ = map | _____________^ +LL | | LL | | .clone() LL | | .into_iter() -LL | | .map(|(_, mut val)| { -LL | | val += 2; +... | LL | | val LL | | }) | |__________^ @@ -189,6 +190,7 @@ LL | | }) help: try | LL ~ let _ = map +LL + LL + .clone().into_values().map(|mut val| { LL + val += 2; LL + val @@ -196,67 +198,67 @@ LL + }) | error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:94:13 + --> tests/ui/iter_kv_map.rs:121: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 - --> tests/ui/iter_kv_map.rs:109:13 + --> tests/ui/iter_kv_map.rs:137:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:111:13 + --> tests/ui/iter_kv_map.rs:140:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:113:13 + --> tests/ui/iter_kv_map.rs:143: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 - --> tests/ui/iter_kv_map.rs:122:13 + --> tests/ui/iter_kv_map.rs:153:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> tests/ui/iter_kv_map.rs:124:13 + --> tests/ui/iter_kv_map.rs:156: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 - --> tests/ui/iter_kv_map.rs:127:13 + --> tests/ui/iter_kv_map.rs:160:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:129:13 + --> tests/ui/iter_kv_map.rs:163: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 keys - --> tests/ui/iter_kv_map.rs:132:13 + --> tests/ui/iter_kv_map.rs:167:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:134:13 + --> tests/ui/iter_kv_map.rs:170:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:136:13 + --> tests/ui/iter_kv_map.rs:173:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` diff --git a/tests/ui/iter_next_loop.rs b/tests/ui/iter_next_loop.rs index d425f4da0e81..32711c7ef623 100644 --- a/tests/ui/iter_next_loop.rs +++ b/tests/ui/iter_next_loop.rs @@ -4,6 +4,7 @@ fn main() { let x = [1, 2, 3, 4]; for _ in x.iter().next() {} + //~^ iter_next_loop struct Unrelated(&'static [u8]); impl Unrelated { diff --git a/tests/ui/iter_next_slice.fixed b/tests/ui/iter_next_slice.fixed index 83be12c4e254..2e7b4e632840 100644 --- a/tests/ui/iter_next_slice.fixed +++ b/tests/ui/iter_next_slice.fixed @@ -7,15 +7,19 @@ fn main() { let v = vec![1, 2, 3]; let _ = s.first(); + //~^ iter_next_slice // Should be replaced by s.first() let _ = s.get(2); + //~^ iter_next_slice // Should be replaced by s.get(2) let _ = v.get(5); + //~^ iter_next_slice // Should be replaced by v.get(5) let _ = v.first(); + //~^ iter_next_slice // Should be replaced by v.first() let o = Some(5); diff --git a/tests/ui/iter_next_slice.rs b/tests/ui/iter_next_slice.rs index 1b257514d23e..b2e047f5d817 100644 --- a/tests/ui/iter_next_slice.rs +++ b/tests/ui/iter_next_slice.rs @@ -7,15 +7,19 @@ fn main() { let v = vec![1, 2, 3]; let _ = s.iter().next(); + //~^ iter_next_slice // Should be replaced by s.first() let _ = s[2..].iter().next(); + //~^ iter_next_slice // Should be replaced by s.get(2) let _ = v[5..].iter().next(); + //~^ iter_next_slice // Should be replaced by v.get(5) let _ = v.iter().next(); + //~^ iter_next_slice // Should be replaced by v.first() let o = Some(5); diff --git a/tests/ui/iter_next_slice.stderr b/tests/ui/iter_next_slice.stderr index 55cce2b9103d..0a22ab7f6a15 100644 --- a/tests/ui/iter_next_slice.stderr +++ b/tests/ui/iter_next_slice.stderr @@ -8,19 +8,19 @@ LL | let _ = s.iter().next(); = help: to override `-D warnings` add `#[allow(clippy::iter_next_slice)]` error: using `.iter().next()` on a Slice without end index - --> tests/ui/iter_next_slice.rs:12:13 + --> tests/ui/iter_next_slice.rs:13:13 | LL | let _ = s[2..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` error: using `.iter().next()` on a Slice without end index - --> tests/ui/iter_next_slice.rs:15:13 + --> tests/ui/iter_next_slice.rs:17:13 | LL | let _ = v[5..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` error: using `.iter().next()` on an array - --> tests/ui/iter_next_slice.rs:18:13 + --> tests/ui/iter_next_slice.rs:21:13 | LL | let _ = v.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `v.first()` diff --git a/tests/ui/iter_not_returning_iterator.rs b/tests/ui/iter_not_returning_iterator.rs index e694bc7ac62f..4c0c667be80f 100644 --- a/tests/ui/iter_not_returning_iterator.rs +++ b/tests/ui/iter_not_returning_iterator.rs @@ -28,13 +28,15 @@ 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` + //~^ iter_not_returning_iterator + + todo!() } fn iter_mut(&self) -> Counter2 { - //~^ ERROR: this method is named `iter_mut` but its return type does not implement `It + //~^ iter_not_returning_iterator + todo!() } } @@ -51,7 +53,8 @@ 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 + //~^ iter_not_returning_iterator + } impl Iter for () { diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr index c3ee8bae772d..8c0ebd847110 100644 --- a/tests/ui/iter_not_returning_iterator.stderr +++ b/tests/ui/iter_not_returning_iterator.stderr @@ -8,13 +8,13 @@ LL | fn iter(&self) -> Counter2 { = help: to override `-D warnings` add `#[allow(clippy::iter_not_returning_iterator)]` error: this method is named `iter_mut` but its return type does not implement `Iterator` - --> tests/ui/iter_not_returning_iterator.rs:36:5 + --> tests/ui/iter_not_returning_iterator.rs:37:5 | LL | fn iter_mut(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this method is named `iter` but its return type does not implement `Iterator` - --> tests/ui/iter_not_returning_iterator.rs:53:5 + --> tests/ui/iter_not_returning_iterator.rs:55:5 | LL | fn iter(&self) -> Self::I; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_nth.fixed b/tests/ui/iter_nth.fixed index aff3731a8837..5650903a5dcb 100644 --- a/tests/ui/iter_nth.fixed +++ b/tests/ui/iter_nth.fixed @@ -32,24 +32,32 @@ fn iter_nth() { { // Make sure we lint `.iter()` for relevant types. let bad_vec = some_vec.get(3); + //~^ iter_nth let bad_slice = &some_vec[..].get(3); + //~^ iter_nth let bad_boxed_slice = boxed_slice.get(3); + //~^ iter_nth let bad_vec_deque = some_vec_deque.get(3); + //~^ iter_nth } { // Make sure we lint `.iter_mut()` for relevant types. let bad_vec = some_vec.get_mut(3); + //~^ iter_nth } { let bad_slice = &some_vec[..].get_mut(3); + //~^ iter_nth } { let bad_vec_deque = some_vec_deque.get_mut(3); + //~^ iter_nth } let vec_ref = &Vec::::new(); vec_ref.get(3); + //~^ iter_nth // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_nth.rs b/tests/ui/iter_nth.rs index 89d68044ddda..cfd0629420e1 100644 --- a/tests/ui/iter_nth.rs +++ b/tests/ui/iter_nth.rs @@ -32,24 +32,32 @@ fn iter_nth() { { // Make sure we lint `.iter()` for relevant types. let bad_vec = some_vec.iter().nth(3); + //~^ iter_nth let bad_slice = &some_vec[..].iter().nth(3); + //~^ iter_nth let bad_boxed_slice = boxed_slice.iter().nth(3); + //~^ iter_nth let bad_vec_deque = some_vec_deque.iter().nth(3); + //~^ iter_nth } { // Make sure we lint `.iter_mut()` for relevant types. let bad_vec = some_vec.iter_mut().nth(3); + //~^ iter_nth } { let bad_slice = &some_vec[..].iter_mut().nth(3); + //~^ iter_nth } { let bad_vec_deque = some_vec_deque.iter_mut().nth(3); + //~^ iter_nth } let vec_ref = &Vec::::new(); vec_ref.iter().nth(3); + //~^ iter_nth // Make sure we don't lint for non-relevant types. let false_positive = HasIter; diff --git a/tests/ui/iter_nth.stderr b/tests/ui/iter_nth.stderr index 178463f53475..ae6e66f8cbf4 100644 --- a/tests/ui/iter_nth.stderr +++ b/tests/ui/iter_nth.stderr @@ -12,7 +12,7 @@ LL | let bad_vec = some_vec.get(3); | ~~~ error: called `.iter().nth()` on a slice - --> tests/ui/iter_nth.rs:35:26 + --> tests/ui/iter_nth.rs:36:26 | LL | let bad_slice = &some_vec[..].iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let bad_slice = &some_vec[..].get(3); | ~~~ error: called `.iter().nth()` on a slice - --> tests/ui/iter_nth.rs:36:31 + --> tests/ui/iter_nth.rs:38:31 | LL | let bad_boxed_slice = boxed_slice.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let bad_boxed_slice = boxed_slice.get(3); | ~~~ error: called `.iter().nth()` on a `VecDeque` - --> tests/ui/iter_nth.rs:37:29 + --> tests/ui/iter_nth.rs:40:29 | LL | let bad_vec_deque = some_vec_deque.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let bad_vec_deque = some_vec_deque.get(3); | ~~~ error: called `.iter_mut().nth()` on a `Vec` - --> tests/ui/iter_nth.rs:42:23 + --> tests/ui/iter_nth.rs:46:23 | LL | let bad_vec = some_vec.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let bad_vec = some_vec.get_mut(3); | ~~~~~~~ error: called `.iter_mut().nth()` on a slice - --> tests/ui/iter_nth.rs:45:26 + --> tests/ui/iter_nth.rs:50:26 | LL | let bad_slice = &some_vec[..].iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let bad_slice = &some_vec[..].get_mut(3); | ~~~~~~~ error: called `.iter_mut().nth()` on a `VecDeque` - --> tests/ui/iter_nth.rs:48:29 + --> tests/ui/iter_nth.rs:54:29 | LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let bad_vec_deque = some_vec_deque.get_mut(3); | ~~~~~~~ error: called `.iter().nth()` on a `Vec` - --> tests/ui/iter_nth.rs:52:5 + --> tests/ui/iter_nth.rs:59:5 | LL | vec_ref.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_nth_zero.fixed b/tests/ui/iter_nth_zero.fixed index a3cdb2e59bff..07153db90c19 100644 --- a/tests/ui/iter_nth_zero.fixed +++ b/tests/ui/iter_nth_zero.fixed @@ -16,16 +16,19 @@ fn main() { let mut s = HashSet::new(); s.insert(1); let _x = s.iter().next(); + //~^ iter_nth_zero let mut s2 = HashSet::new(); s2.insert(2); let mut iter = s2.iter(); let _y = iter.next(); + //~^ iter_nth_zero let mut s3 = HashSet::new(); s3.insert(3); let mut iter2 = s3.iter(); let _unwrapped = iter2.next().unwrap(); + //~^ iter_nth_zero } struct Issue9820; diff --git a/tests/ui/iter_nth_zero.rs b/tests/ui/iter_nth_zero.rs index 64229b5128a3..45d008cd7040 100644 --- a/tests/ui/iter_nth_zero.rs +++ b/tests/ui/iter_nth_zero.rs @@ -16,16 +16,19 @@ fn main() { let mut s = HashSet::new(); s.insert(1); let _x = s.iter().nth(0); + //~^ iter_nth_zero let mut s2 = HashSet::new(); s2.insert(2); let mut iter = s2.iter(); let _y = iter.nth(0); + //~^ iter_nth_zero let mut s3 = HashSet::new(); s3.insert(3); let mut iter2 = s3.iter(); let _unwrapped = iter2.nth(0).unwrap(); + //~^ iter_nth_zero } struct Issue9820; diff --git a/tests/ui/iter_nth_zero.stderr b/tests/ui/iter_nth_zero.stderr index b5e5cf45c26b..edd44838b7ec 100644 --- a/tests/ui/iter_nth_zero.stderr +++ b/tests/ui/iter_nth_zero.stderr @@ -8,13 +8,13 @@ LL | let _x = s.iter().nth(0); = help: to override `-D warnings` add `#[allow(clippy::iter_nth_zero)]` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> tests/ui/iter_nth_zero.rs:23:14 + --> tests/ui/iter_nth_zero.rs:24: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 - --> tests/ui/iter_nth_zero.rs:28:22 + --> tests/ui/iter_nth_zero.rs:30: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 0f28b48d9ab8..e1e4e331843b 100644 --- a/tests/ui/iter_on_empty_collections.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -3,11 +3,17 @@ fn array() { assert_eq!(std::iter::empty().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(std::iter::empty().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections // Don't trigger on non-iter methods let _: Option = None.clone(); @@ -26,6 +32,7 @@ fn array() { // Don't trigger when the empty collection iter is relied upon for its concrete type // But do trigger if it is just an iterator, despite being an argument to a method for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain(std::iter::empty()) { + //~^ iter_on_empty_collections println!("{i}"); } diff --git a/tests/ui/iter_on_empty_collections.rs b/tests/ui/iter_on_empty_collections.rs index 702da514df7d..3a4ad7fb372a 100644 --- a/tests/ui/iter_on_empty_collections.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -3,11 +3,17 @@ fn array() { assert_eq!([].into_iter().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!([].iter().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections assert_eq!(None.into_iter().next(), Option::::None); + //~^ iter_on_empty_collections assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); + //~^ iter_on_empty_collections assert_eq!(None.iter().next(), Option::<&i32>::None); + //~^ iter_on_empty_collections // Don't trigger on non-iter methods let _: Option = None.clone(); @@ -26,6 +32,7 @@ fn array() { // Don't trigger when the empty collection iter is relied upon for its concrete type // But do trigger if it is just an iterator, despite being an argument to a method for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain([].iter()) { + //~^ iter_on_empty_collections println!("{i}"); } diff --git a/tests/ui/iter_on_empty_collections.stderr b/tests/ui/iter_on_empty_collections.stderr index da9caa6925bd..2803999cc735 100644 --- a/tests/ui/iter_on_empty_collections.stderr +++ b/tests/ui/iter_on_empty_collections.stderr @@ -8,37 +8,37 @@ LL | assert_eq!([].into_iter().next(), Option::::None); = help: to override `-D warnings` add `#[allow(clippy::iter_on_empty_collections)]` error: `iter_mut` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:6:16 + --> tests/ui/iter_on_empty_collections.rs:7:16 | LL | assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:7:16 + --> tests/ui/iter_on_empty_collections.rs:9:16 | LL | assert_eq!([].iter().next(), Option::<&i32>::None); | ^^^^^^^^^ help: try: `std::iter::empty()` error: `into_iter` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:8:16 + --> tests/ui/iter_on_empty_collections.rs:11:16 | LL | assert_eq!(None.into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter_mut` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:9:16 + --> tests/ui/iter_on_empty_collections.rs:13:16 | LL | assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:10:16 + --> tests/ui/iter_on_empty_collections.rs:15:16 | LL | assert_eq!(None.iter().next(), Option::<&i32>::None); | ^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> tests/ui/iter_on_empty_collections.rs:28:66 + --> tests/ui/iter_on_empty_collections.rs:34:66 | LL | for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain([].iter()) { | ^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/iter_on_single_items.fixed b/tests/ui/iter_on_single_items.fixed index 117ec8429c37..b43fad6449c1 100644 --- a/tests/ui/iter_on_single_items.fixed +++ b/tests/ui/iter_on_single_items.fixed @@ -3,11 +3,17 @@ fn array() { assert_eq!(std::iter::once(123).next(), Some(123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&mut 123).next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&123).next(), Some(&123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(123).next(), Some(123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&mut 123).next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(std::iter::once(&123).next(), Some(&123)); + //~^ iter_on_single_items // Don't trigger on non-iter methods let _: Option = Some("test".to_string()).clone(); diff --git a/tests/ui/iter_on_single_items.rs b/tests/ui/iter_on_single_items.rs index d059370d996c..625c96d3ef1f 100644 --- a/tests/ui/iter_on_single_items.rs +++ b/tests/ui/iter_on_single_items.rs @@ -3,11 +3,17 @@ fn array() { assert_eq!([123].into_iter().next(), Some(123)); + //~^ iter_on_single_items assert_eq!([123].iter_mut().next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!([123].iter().next(), Some(&123)); + //~^ iter_on_single_items assert_eq!(Some(123).into_iter().next(), Some(123)); + //~^ iter_on_single_items assert_eq!(Some(123).iter_mut().next(), Some(&mut 123)); + //~^ iter_on_single_items assert_eq!(Some(123).iter().next(), Some(&123)); + //~^ iter_on_single_items // Don't trigger on non-iter methods let _: Option = Some("test".to_string()).clone(); diff --git a/tests/ui/iter_on_single_items.stderr b/tests/ui/iter_on_single_items.stderr index 0252c859581b..536e9eb36d88 100644 --- a/tests/ui/iter_on_single_items.stderr +++ b/tests/ui/iter_on_single_items.stderr @@ -8,31 +8,31 @@ LL | assert_eq!([123].into_iter().next(), Some(123)); = help: to override `-D warnings` add `#[allow(clippy::iter_on_single_items)]` error: `iter_mut` call on a collection with only one item - --> tests/ui/iter_on_single_items.rs:6:16 + --> tests/ui/iter_on_single_items.rs:7: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 - --> tests/ui/iter_on_single_items.rs:7:16 + --> tests/ui/iter_on_single_items.rs:9: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 - --> tests/ui/iter_on_single_items.rs:8:16 + --> tests/ui/iter_on_single_items.rs:11: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 - --> tests/ui/iter_on_single_items.rs:9:16 + --> tests/ui/iter_on_single_items.rs:13: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 - --> tests/ui/iter_on_single_items.rs:10:16 + --> tests/ui/iter_on_single_items.rs:15:16 | LL | assert_eq!(Some(123).iter().next(), Some(&123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)` diff --git a/tests/ui/iter_out_of_bounds.rs b/tests/ui/iter_out_of_bounds.rs index 3cfe6e82fc1e..243dce9939c1 100644 --- a/tests/ui/iter_out_of_bounds.rs +++ b/tests/ui/iter_out_of_bounds.rs @@ -10,57 +10,71 @@ fn opaque_empty_iter() -> impl Iterator { fn main() { #[allow(clippy::never_loop)] for _ in [1, 2, 3].iter().skip(4) { - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + unreachable!(); } for (i, _) in [1, 2, 3].iter().take(4).enumerate() { - //~^ ERROR: this `.take()` call takes more items than the iterator will produce + //~^ iter_out_of_bounds + assert!(i <= 2); } #[allow(clippy::needless_borrow)] for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} - //~^ ERROR: this `.take()` call takes more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in [1, 2, 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in [1; 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + // Should not lint for _ in opaque_empty_iter().skip(1) {} for _ in vec![1, 2, 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in vec![1; 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + let x = [1, 2, 3]; for _ in x.iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + let n = 4; for _ in x.iter().skip(n) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + let empty = std::iter::empty::; for _ in empty().skip(1) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in empty().take(1) {} - //~^ ERROR: this `.take()` call takes more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in std::iter::once(1).skip(2) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + //~^ iter_out_of_bounds + for _ in std::iter::once(1).take(2) {} - //~^ ERROR: this `.take()` call takes more items than the iterator will produce + //~^ iter_out_of_bounds + for x in [].iter().take(1) { - //~^ ERROR: this `.take()` call takes more items than the iterator will produce + //~^ iter_out_of_bounds + let _: &i32 = x; } diff --git a/tests/ui/iter_out_of_bounds.stderr b/tests/ui/iter_out_of_bounds.stderr index 96df04251fc9..42984e00e1d4 100644 --- a/tests/ui/iter_out_of_bounds.stderr +++ b/tests/ui/iter_out_of_bounds.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::iter_out_of_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:16:19 + --> tests/ui/iter_out_of_bounds.rs:17:19 | LL | for (i, _) in [1, 2, 3].iter().take(4).enumerate() { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | for (i, _) in [1, 2, 3].iter().take(4).enumerate() { = note: this operation is useless and the returned iterator will simply yield the same items error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:22:14 + --> tests/ui/iter_out_of_bounds.rs:24:14 | LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:25:14 + --> tests/ui/iter_out_of_bounds.rs:28:14 | LL | for _ in [1, 2, 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | for _ in [1, 2, 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:28:14 + --> tests/ui/iter_out_of_bounds.rs:32:14 | LL | for _ in [1; 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | for _ in [1; 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:34:14 + --> tests/ui/iter_out_of_bounds.rs:39:14 | LL | for _ in vec![1, 2, 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | for _ in vec![1, 2, 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:37:14 + --> tests/ui/iter_out_of_bounds.rs:43:14 | LL | for _ in vec![1; 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | for _ in vec![1; 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:41:14 + --> tests/ui/iter_out_of_bounds.rs:48:14 | LL | for _ in x.iter().skip(4) {} | ^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | for _ in x.iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:45:14 + --> tests/ui/iter_out_of_bounds.rs:53:14 | LL | for _ in x.iter().skip(n) {} | ^^^^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | for _ in x.iter().skip(n) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:50:14 + --> tests/ui/iter_out_of_bounds.rs:59:14 | LL | for _ in empty().skip(1) {} | ^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL | for _ in empty().skip(1) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:53:14 + --> tests/ui/iter_out_of_bounds.rs:63:14 | LL | for _ in empty().take(1) {} | ^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | for _ in empty().take(1) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:56:14 + --> tests/ui/iter_out_of_bounds.rs:67:14 | LL | for _ in std::iter::once(1).skip(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | for _ in std::iter::once(1).skip(2) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:59:14 + --> tests/ui/iter_out_of_bounds.rs:71:14 | LL | for _ in std::iter::once(1).take(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | for _ in std::iter::once(1).take(2) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:62:14 + --> tests/ui/iter_out_of_bounds.rs:75:14 | LL | for x in [].iter().take(1) { | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_over_hash_type.rs b/tests/ui/iter_over_hash_type.rs index 65bae1df4218..0dd9544cfe01 100644 --- a/tests/ui/iter_over_hash_type.rs +++ b/tests/ui/iter_over_hash_type.rs @@ -16,46 +16,59 @@ fn main() { // test hashset for x in &hash_set { + //~^ iter_over_hash_type let _ = x; } for x in hash_set.iter() { + //~^ iter_over_hash_type let _ = x; } for x in hash_set.clone() { + //~^ iter_over_hash_type let _ = x; } for x in hash_set.drain() { + //~^ iter_over_hash_type let _ = x; } // test hashmap for (x, y) in &hash_map { + //~^ iter_over_hash_type let _ = (x, y); } for x in hash_map.keys() { + //~^ iter_over_hash_type let _ = x; } for x in hash_map.values() { + //~^ iter_over_hash_type let _ = x; } for x in hash_map.values_mut() { + //~^ iter_over_hash_type *x += 1; } for x in hash_map.iter() { + //~^ iter_over_hash_type let _ = x; } for x in hash_map.clone() { + //~^ iter_over_hash_type let _ = x; } for x in hash_map.drain() { + //~^ iter_over_hash_type let _ = x; } // test type-aliased hashers for x in fx_hash_set { + //~^ iter_over_hash_type let _ = x; } for x in fx_hash_map { + //~^ iter_over_hash_type let _ = x; } diff --git a/tests/ui/iter_over_hash_type.stderr b/tests/ui/iter_over_hash_type.stderr index 6afe69ee20e1..1bc6f4588d44 100644 --- a/tests/ui/iter_over_hash_type.stderr +++ b/tests/ui/iter_over_hash_type.stderr @@ -2,6 +2,7 @@ error: iteration over unordered hash-based type --> tests/ui/iter_over_hash_type.rs:18:5 | LL | / for x in &hash_set { +LL | | LL | | let _ = x; LL | | } | |_____^ @@ -10,97 +11,109 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::iter_over_hash_type)]` error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:21:5 + --> tests/ui/iter_over_hash_type.rs:22:5 | LL | / for x in hash_set.iter() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:24:5 + --> tests/ui/iter_over_hash_type.rs:26:5 | LL | / for x in hash_set.clone() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:27:5 + --> tests/ui/iter_over_hash_type.rs:30:5 | LL | / for x in hash_set.drain() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:32:5 + --> tests/ui/iter_over_hash_type.rs:36:5 | LL | / for (x, y) in &hash_map { +LL | | LL | | let _ = (x, y); LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:35:5 + --> tests/ui/iter_over_hash_type.rs:40:5 | LL | / for x in hash_map.keys() { +LL | | LL | | let _ = x; LL | | } | |_____^ -error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:38:5 - | -LL | / for x in hash_map.values() { -LL | | let _ = x; -LL | | } - | |_____^ - -error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:41:5 - | -LL | / for x in hash_map.values_mut() { -LL | | *x += 1; -LL | | } - | |_____^ - error: iteration over unordered hash-based type --> tests/ui/iter_over_hash_type.rs:44:5 | -LL | / for x in hash_map.iter() { +LL | / for x in hash_map.values() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:47:5 + --> tests/ui/iter_over_hash_type.rs:48:5 + | +LL | / for x in hash_map.values_mut() { +LL | | +LL | | *x += 1; +LL | | } + | |_____^ + +error: iteration over unordered hash-based type + --> tests/ui/iter_over_hash_type.rs:52:5 + | +LL | / for x in hash_map.iter() { +LL | | +LL | | let _ = x; +LL | | } + | |_____^ + +error: iteration over unordered hash-based type + --> tests/ui/iter_over_hash_type.rs:56:5 | LL | / for x in hash_map.clone() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:50:5 + --> tests/ui/iter_over_hash_type.rs:60:5 | LL | / for x in hash_map.drain() { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:55:5 + --> tests/ui/iter_over_hash_type.rs:66:5 | LL | / for x in fx_hash_set { +LL | | LL | | let _ = x; LL | | } | |_____^ error: iteration over unordered hash-based type - --> tests/ui/iter_over_hash_type.rs:58:5 + --> tests/ui/iter_over_hash_type.rs:70:5 | LL | / for x in fx_hash_map { +LL | | LL | | let _ = x; LL | | } | |_____^ diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index d7d3d299349e..bc6cf76a58d8 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -10,36 +10,49 @@ fn main() { let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()]; let _: Option = vec.iter().last().cloned(); + //~^ iter_overeager_cloned let _: Option = vec.iter().chain(vec.iter()).next().cloned(); + //~^ iter_overeager_cloned let _: usize = vec.iter().filter(|x| x == &"2").count(); + //~^ redundant_clone let _: Vec<_> = vec.iter().take(2).cloned().collect(); + //~^ iter_overeager_cloned let _: Vec<_> = vec.iter().skip(2).cloned().collect(); + //~^ iter_overeager_cloned let _ = vec.iter().filter(|x| x == &"2").nth(2).cloned(); + //~^ iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] + //~^ iter_overeager_cloned .iter() .flatten().cloned(); let _ = vec.iter().filter(|&x| x.starts_with('2')).cloned(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| x == "2").cloned(); + //~^ iter_overeager_cloned { let f = |x: &String| x.starts_with('2'); let _ = vec.iter().filter(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| f(x)).cloned(); + //~^ iter_overeager_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(); + //~^ iter_overeager_cloned let _ = vec.iter().find(|&x| f(x)).cloned(); + //~^ iter_overeager_cloned } fn test_move<'a>( @@ -47,6 +60,7 @@ fn main() { target: String, ) -> impl Iterator + 'a { iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned() + //~^ iter_overeager_cloned } { @@ -58,19 +72,24 @@ fn main() { fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { iter.filter(move |&S { a, b }| **a == 1 && b == &target).cloned() + //~^ iter_overeager_cloned } } let _ = vec.iter().map(|x| x.len()); + //~^ redundant_clone // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); let _ = vec.iter().for_each(|x| assert!(!x.is_empty())); + //~^ redundant_clone let _ = vec.iter().all(|x| x.len() == 1); + //~^ redundant_clone let _ = vec.iter().any(|x| x.len() == 1); + //~^ redundant_clone // Should probably stay as it is. let _ = [0, 1, 2, 3, 4].iter().cloned().take(10); diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 45e1349febd0..094760893c3e 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -10,37 +10,50 @@ fn main() { let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()]; let _: Option = vec.iter().cloned().last(); + //~^ iter_overeager_cloned let _: Option = vec.iter().chain(vec.iter()).cloned().next(); + //~^ iter_overeager_cloned let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); + //~^ redundant_clone let _: Vec<_> = vec.iter().cloned().take(2).collect(); + //~^ iter_overeager_cloned let _: Vec<_> = vec.iter().cloned().skip(2).collect(); + //~^ iter_overeager_cloned let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); + //~^ iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] + //~^ iter_overeager_cloned .iter() .cloned() .flatten(); let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(|x| x == "2"); + //~^ iter_overeager_cloned { let f = |x: &String| x.starts_with('2'); let _ = vec.iter().cloned().filter(f); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(f); + //~^ iter_overeager_cloned } { let vec: Vec<(String, String)> = vec![]; let f = move |x: &(String, String)| x.0.starts_with('2'); let _ = vec.iter().cloned().filter(f); + //~^ iter_overeager_cloned let _ = vec.iter().cloned().find(f); + //~^ iter_overeager_cloned } fn test_move<'a>( @@ -48,6 +61,7 @@ fn main() { target: String, ) -> impl Iterator + 'a { iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) + //~^ iter_overeager_cloned } { @@ -59,19 +73,24 @@ fn main() { fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) + //~^ iter_overeager_cloned } } let _ = vec.iter().cloned().map(|x| x.len()); + //~^ redundant_clone // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); + //~^ redundant_clone let _ = vec.iter().cloned().all(|x| x.len() == 1); + //~^ redundant_clone let _ = vec.iter().cloned().any(|x| x.len() == 1); + //~^ redundant_clone // Should probably stay as it is. let _ = [0, 1, 2, 3, 4].iter().cloned().take(10); diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index e6680266f107..f3239b59582e 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -10,7 +10,7 @@ LL | let _: Option = vec.iter().cloned().last(); = help: to override `-D warnings` add `#[allow(clippy::iter_overeager_cloned)]` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:14:29 + --> tests/ui/iter_overeager_cloned.rs:15:29 | LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -18,7 +18,7 @@ LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | help: try: `.next().cloned()` error: unneeded cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:16:20 + --> tests/ui/iter_overeager_cloned.rs:18:20 | LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------- @@ -29,7 +29,7 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:18:21 + --> tests/ui/iter_overeager_cloned.rs:21:21 | LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | ^^^^^^^^^^----------------- @@ -37,7 +37,7 @@ LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | help: try: `.take(2).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:20:21 + --> tests/ui/iter_overeager_cloned.rs:24:21 | LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | ^^^^^^^^^^----------------- @@ -45,7 +45,7 @@ LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | help: try: `.skip(2).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:22:13 + --> tests/ui/iter_overeager_cloned.rs:27:13 | LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -53,10 +53,11 @@ LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | help: try: `.nth(2).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:24:13 + --> tests/ui/iter_overeager_cloned.rs:30:13 | LL | let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] | _____________^ +LL | | LL | | .iter() LL | | .cloned() LL | | .flatten(); @@ -69,7 +70,7 @@ LL ~ .flatten().cloned(); | error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:29:13 + --> tests/ui/iter_overeager_cloned.rs:36:13 | LL | let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); | ^^^^^^^^^^---------------------------------------- @@ -77,7 +78,7 @@ 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 - --> tests/ui/iter_overeager_cloned.rs:31:13 + --> tests/ui/iter_overeager_cloned.rs:39:13 | LL | let _ = vec.iter().cloned().find(|x| x == "2"); | ^^^^^^^^^^---------------------------- @@ -85,7 +86,7 @@ LL | let _ = vec.iter().cloned().find(|x| x == "2"); | help: try: `.find(|&x| x == "2").cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:35:17 + --> tests/ui/iter_overeager_cloned.rs:44:17 | LL | let _ = vec.iter().cloned().filter(f); | ^^^^^^^^^^------------------- @@ -93,7 +94,7 @@ LL | let _ = vec.iter().cloned().filter(f); | help: try: `.filter(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:36:17 + --> tests/ui/iter_overeager_cloned.rs:46:17 | LL | let _ = vec.iter().cloned().find(f); | ^^^^^^^^^^----------------- @@ -101,7 +102,7 @@ LL | let _ = vec.iter().cloned().find(f); | help: try: `.find(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:42:17 + --> tests/ui/iter_overeager_cloned.rs:53:17 | LL | let _ = vec.iter().cloned().filter(f); | ^^^^^^^^^^------------------- @@ -109,7 +110,7 @@ LL | let _ = vec.iter().cloned().filter(f); | help: try: `.filter(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:43:17 + --> tests/ui/iter_overeager_cloned.rs:55:17 | LL | let _ = vec.iter().cloned().find(f); | ^^^^^^^^^^----------------- @@ -117,7 +118,7 @@ LL | let _ = vec.iter().cloned().find(f); | help: try: `.find(|&x| f(x)).cloned()` error: unnecessarily eager cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:50:9 + --> tests/ui/iter_overeager_cloned.rs:63:9 | LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) | ^^^^------------------------------------------------------- @@ -125,7 +126,7 @@ 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 - --> tests/ui/iter_overeager_cloned.rs:61:13 + --> tests/ui/iter_overeager_cloned.rs:75:13 | LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) | ^^^^------------------------------------------------------------ @@ -133,7 +134,7 @@ 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: unneeded cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:65:13 + --> tests/ui/iter_overeager_cloned.rs:80:13 | LL | let _ = vec.iter().cloned().map(|x| x.len()); | ^^^^^^^^^^-------------------------- @@ -141,7 +142,7 @@ LL | let _ = vec.iter().cloned().map(|x| x.len()); | help: try: `.map(|x| x.len())` error: unneeded cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:70:13 + --> tests/ui/iter_overeager_cloned.rs:86:13 | LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); | ^^^^^^^^^^---------------------------------------------- @@ -149,7 +150,7 @@ LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); | help: try: `.for_each(|x| assert!(!x.is_empty()))` error: unneeded cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:72:13 + --> tests/ui/iter_overeager_cloned.rs:89:13 | LL | let _ = vec.iter().cloned().all(|x| x.len() == 1); | ^^^^^^^^^^------------------------------- @@ -157,7 +158,7 @@ LL | let _ = vec.iter().cloned().all(|x| x.len() == 1); | help: try: `.all(|x| x.len() == 1)` error: unneeded cloning of iterator items - --> tests/ui/iter_overeager_cloned.rs:74:13 + --> tests/ui/iter_overeager_cloned.rs:92:13 | LL | let _ = vec.iter().cloned().any(|x| x.len() == 1); | ^^^^^^^^^^------------------------------- diff --git a/tests/ui/iter_skip_next.fixed b/tests/ui/iter_skip_next.fixed index 3e41b3632490..1d6a07f2d828 100644 --- a/tests/ui/iter_skip_next.fixed +++ b/tests/ui/iter_skip_next.fixed @@ -15,9 +15,13 @@ use option_helpers::IteratorFalsePositives; fn main() { let some_vec = vec![0, 1, 2, 3]; let _ = some_vec.iter().nth(42); + //~^ iter_skip_next let _ = some_vec.iter().cycle().nth(42); + //~^ iter_skip_next let _ = (1..10).nth(10); + //~^ iter_skip_next let _ = &some_vec[..].iter().nth(3); + //~^ iter_skip_next let foo = IteratorFalsePositives { foo: 0 }; let _ = foo.skip(42).next(); let _ = foo.filter().skip(42).next(); @@ -26,13 +30,16 @@ fn main() { let test_string = "1|1 2"; let mut sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next }; fn check(mut s: T) where T: Iterator, { let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect(); + //~^ iter_skip_next } } diff --git a/tests/ui/iter_skip_next.rs b/tests/ui/iter_skip_next.rs index 6d96441ca96f..7570e17a0925 100644 --- a/tests/ui/iter_skip_next.rs +++ b/tests/ui/iter_skip_next.rs @@ -15,9 +15,13 @@ use option_helpers::IteratorFalsePositives; fn main() { let some_vec = vec![0, 1, 2, 3]; let _ = some_vec.iter().skip(42).next(); + //~^ iter_skip_next let _ = some_vec.iter().cycle().skip(42).next(); + //~^ iter_skip_next let _ = (1..10).skip(10).next(); + //~^ iter_skip_next let _ = &some_vec[..].iter().skip(3).next(); + //~^ iter_skip_next let foo = IteratorFalsePositives { foo: 0 }; let _ = foo.skip(42).next(); let _ = foo.filter().skip(42).next(); @@ -26,13 +30,16 @@ fn main() { let test_string = "1|1 2"; let mut sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next }; fn check(mut s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ iter_skip_next } } diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr index 0fa04465ff15..9f6d708c2f41 100644 --- a/tests/ui/iter_skip_next.stderr +++ b/tests/ui/iter_skip_next.stderr @@ -8,37 +8,37 @@ LL | let _ = some_vec.iter().skip(42).next(); = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next.rs:18:36 + --> tests/ui/iter_skip_next.rs:19:36 | LL | let _ = some_vec.iter().cycle().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next.rs:19:20 + --> tests/ui/iter_skip_next.rs:21:20 | LL | let _ = (1..10).skip(10).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next.rs:20:33 + --> tests/ui/iter_skip_next.rs:23:33 | LL | let _ = &some_vec[..].iter().skip(3).next(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)` error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next.rs:28:26 + --> tests/ui/iter_skip_next.rs:32: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 - --> tests/ui/iter_skip_next.rs:30:29 + --> tests/ui/iter_skip_next.rs:35: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 - --> tests/ui/iter_skip_next.rs:36:29 + --> tests/ui/iter_skip_next.rs:42: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 6c98bdc8c880..273ccd25ddcc 100644 --- a/tests/ui/iter_skip_next_unfixable.rs +++ b/tests/ui/iter_skip_next_unfixable.rs @@ -7,16 +7,19 @@ 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 + //~^ iter_skip_next + 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 + //~^ iter_skip_next + }; fn check(s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); - //~^ ERROR: called `skip(..).next()` on an iterator + //~^ iter_skip_next + } } diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index 9bfffb07ca62..cfbf75d85304 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -13,25 +13,25 @@ LL | let sp = test_string.split('|').map(|s| s.trim()); = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next_unfixable.rs:12:29 + --> tests/ui/iter_skip_next_unfixable.rs:13: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 - --> tests/ui/iter_skip_next_unfixable.rs:11:17 + --> tests/ui/iter_skip_next_unfixable.rs:12:17 | LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { | ^ error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next_unfixable.rs:19:29 + --> tests/ui/iter_skip_next_unfixable.rs:21: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 - --> tests/ui/iter_skip_next_unfixable.rs:15:17 + --> tests/ui/iter_skip_next_unfixable.rs:17:17 | LL | fn check(s: T) | ^ diff --git a/tests/ui/iter_skip_zero.fixed b/tests/ui/iter_skip_zero.fixed index 447d07100e95..498af9bb4ff6 100644 --- a/tests/ui/iter_skip_zero.fixed +++ b/tests/ui/iter_skip_zero.fixed @@ -9,9 +9,14 @@ use std::iter::once; fn main() { let _ = [1, 2, 3].iter().skip(1); + //~^ iter_skip_zero let _ = vec![1, 2, 3].iter().skip(1); + //~^ iter_skip_zero let _ = once([1, 2, 3]).skip(1); + //~^ iter_skip_zero let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(1)).skip(1); + //~^ iter_skip_zero + //~| iter_skip_zero // Don't lint let _ = [1, 2, 3].iter().skip(1); let _ = vec![1, 2, 3].iter().skip(1); diff --git a/tests/ui/iter_skip_zero.rs b/tests/ui/iter_skip_zero.rs index ba63c3981808..f168e9109953 100644 --- a/tests/ui/iter_skip_zero.rs +++ b/tests/ui/iter_skip_zero.rs @@ -9,9 +9,14 @@ use std::iter::once; fn main() { let _ = [1, 2, 3].iter().skip(0); + //~^ iter_skip_zero let _ = vec![1, 2, 3].iter().skip(0); + //~^ iter_skip_zero let _ = once([1, 2, 3]).skip(0); + //~^ iter_skip_zero let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); + //~^ iter_skip_zero + //~| iter_skip_zero // Don't lint let _ = [1, 2, 3].iter().skip(1); let _ = vec![1, 2, 3].iter().skip(1); diff --git a/tests/ui/iter_skip_zero.stderr b/tests/ui/iter_skip_zero.stderr index ef46db843377..235074374aa1 100644 --- a/tests/ui/iter_skip_zero.stderr +++ b/tests/ui/iter_skip_zero.stderr @@ -9,7 +9,7 @@ LL | let _ = [1, 2, 3].iter().skip(0); = help: to override `-D warnings` add `#[allow(clippy::iter_skip_zero)]` error: usage of `.skip(0)` - --> tests/ui/iter_skip_zero.rs:12:39 + --> tests/ui/iter_skip_zero.rs:13:39 | LL | let _ = vec![1, 2, 3].iter().skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -17,7 +17,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)` - --> tests/ui/iter_skip_zero.rs:13:34 + --> tests/ui/iter_skip_zero.rs:15:34 | LL | let _ = once([1, 2, 3]).skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -25,7 +25,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)` - --> tests/ui/iter_skip_zero.rs:14:71 + --> tests/ui/iter_skip_zero.rs:17: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` @@ -33,7 +33,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)` - --> tests/ui/iter_skip_zero.rs:14:62 + --> tests/ui/iter_skip_zero.rs:17: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 a03efceed4ca..b0661ffb981b 100644 --- a/tests/ui/iter_with_drain.fixed +++ b/tests/ui/iter_with_drain.fixed @@ -8,20 +8,26 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn full() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.into_iter().map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } fn closed() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.into_iter().collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.into_iter().map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } diff --git a/tests/ui/iter_with_drain.rs b/tests/ui/iter_with_drain.rs index a8cd47f83d04..746b0f9a5eda 100644 --- a/tests/ui/iter_with_drain.rs +++ b/tests/ui/iter_with_drain.rs @@ -8,20 +8,26 @@ use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; fn full() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.drain(..).collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.drain(..).collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } fn closed() { let mut a = vec!["aaa".to_string(), "bbb".to_string()]; let mut a: BinaryHeap<_> = a.drain(0..).collect(); + //~^ iter_with_drain let mut a: HashSet<_> = a.drain().collect(); let mut a: VecDeque<_> = a.drain().collect(); let mut a: Vec<_> = a.drain(..a.len()).collect(); + //~^ iter_with_drain let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect(); + //~^ iter_with_drain let _: Vec<(String, String)> = a.drain().collect(); } diff --git a/tests/ui/iter_with_drain.stderr b/tests/ui/iter_with_drain.stderr index 265e18c263be..370658961b9b 100644 --- a/tests/ui/iter_with_drain.stderr +++ b/tests/ui/iter_with_drain.stderr @@ -8,31 +8,31 @@ LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); = help: to override `-D warnings` add `#[allow(clippy::iter_with_drain)]` error: `drain(..)` used on a `VecDeque` - --> tests/ui/iter_with_drain.rs:13:27 + --> tests/ui/iter_with_drain.rs:14:27 | LL | let mut a: Vec<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> tests/ui/iter_with_drain.rs:14:34 + --> tests/ui/iter_with_drain.rs:16:34 | LL | let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> tests/ui/iter_with_drain.rs:20:34 + --> tests/ui/iter_with_drain.rs:23:34 | LL | let mut a: BinaryHeap<_> = a.drain(0..).collect(); | ^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `VecDeque` - --> tests/ui/iter_with_drain.rs:23:27 + --> tests/ui/iter_with_drain.rs:27:27 | LL | let mut a: Vec<_> = a.drain(..a.len()).collect(); | ^^^^^^^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> tests/ui/iter_with_drain.rs:24:34 + --> tests/ui/iter_with_drain.rs:29: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/iter_without_into_iter.rs b/tests/ui/iter_without_into_iter.rs index d5b28e45453b..80fb736b9bde 100644 --- a/tests/ui/iter_without_into_iter.rs +++ b/tests/ui/iter_without_into_iter.rs @@ -7,11 +7,11 @@ extern crate proc_macros; pub struct S1; impl S1 { pub fn iter(&self) -> std::slice::Iter<'_, u8> { - //~^ ERROR: `iter` method without an `IntoIterator` impl + //~^ iter_without_into_iter [].iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { - //~^ ERROR: `iter_mut` method without an `IntoIterator` impl + //~^ iter_without_into_iter [].iter_mut() } } @@ -27,11 +27,11 @@ impl S2 { pub struct S3<'a>(&'a mut [u8]); impl<'a> S3<'a> { pub fn iter(&self) -> std::slice::Iter<'_, u8> { - //~^ ERROR: `iter` method without an `IntoIterator` impl + //~^ iter_without_into_iter self.0.iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { - //~^ ERROR: `iter_mut` method without an `IntoIterator` impl + //~^ iter_without_into_iter self.0.iter_mut() } } @@ -68,6 +68,7 @@ impl S7 { pub struct S8(T); impl S8 { pub fn iter(&self) -> std::slice::Iter<'static, T> { + //~^ iter_without_into_iter todo!() } } @@ -76,11 +77,11 @@ impl S8 { pub struct S9(T); impl S9 { pub fn iter(&self) -> std::slice::Iter<'_, T> { - //~^ ERROR: `iter` method without an `IntoIterator` impl + //~^ iter_without_into_iter todo!() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { - //~^ ERROR: `iter_mut` method without an `IntoIterator` impl + //~^ iter_without_into_iter todo!() } } @@ -129,6 +130,7 @@ macro_rules! generate_impl { () => { impl Issue12037 { fn iter(&self) -> std::slice::Iter<'_, u8> { + //~^ iter_without_into_iter todo!() } } diff --git a/tests/ui/iter_without_into_iter.stderr b/tests/ui/iter_without_into_iter.stderr index d748c85003bb..8f86bee09670 100644 --- a/tests/ui/iter_without_into_iter.stderr +++ b/tests/ui/iter_without_into_iter.stderr @@ -88,6 +88,7 @@ error: `iter` method without an `IntoIterator` impl for `&S8` --> tests/ui/iter_without_into_iter.rs:70:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'static, T> { +LL | | LL | | todo!() LL | | } | |_____^ @@ -105,7 +106,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S9` - --> tests/ui/iter_without_into_iter.rs:78:5 + --> tests/ui/iter_without_into_iter.rs:79:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'_, T> { LL | | @@ -126,7 +127,7 @@ LL + } | error: `iter_mut` method without an `IntoIterator` impl for `&mut S9` - --> tests/ui/iter_without_into_iter.rs:82:5 + --> tests/ui/iter_without_into_iter.rs:83:5 | LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { LL | | @@ -147,9 +148,10 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&Issue12037` - --> tests/ui/iter_without_into_iter.rs:131:13 + --> tests/ui/iter_without_into_iter.rs:132:13 | LL | / fn iter(&self) -> std::slice::Iter<'_, u8> { +LL | | LL | | todo!() LL | | } | |_____________^ diff --git a/tests/ui/iterator_step_by_zero.rs b/tests/ui/iterator_step_by_zero.rs index 0b51842df2e3..c416095cb426 100644 --- a/tests/ui/iterator_step_by_zero.rs +++ b/tests/ui/iterator_step_by_zero.rs @@ -2,12 +2,15 @@ #[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` + //~^ iterator_step_by_zero + + let _ = "XXX".chars().step_by(0); - //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~^ iterator_step_by_zero + let _ = (0..1).step_by(0); - //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~^ iterator_step_by_zero + // No error, not an iterator. let y = NotIterator; @@ -17,18 +20,22 @@ fn main() { let _ = (0..1).step_by(1); let _ = (1..).step_by(0); - //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~^ iterator_step_by_zero + let _ = (1..=2).step_by(0); - //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~^ iterator_step_by_zero + let x = 0..1; let _ = x.step_by(0); - //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~^ iterator_step_by_zero + // 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 + //~^ iterator_step_by_zero + } struct NotIterator; diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr index 4156642d6dbb..8cc79a978bca 100644 --- a/tests/ui/iterator_step_by_zero.stderr +++ b/tests/ui/iterator_step_by_zero.stderr @@ -8,37 +8,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); = help: to override `-D warnings` add `#[allow(clippy::iterator_step_by_zero)]` error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:7:13 + --> tests/ui/iterator_step_by_zero.rs:8:13 | LL | let _ = "XXX".chars().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:9:13 + --> tests/ui/iterator_step_by_zero.rs:11:13 | LL | let _ = (0..1).step_by(0); | ^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:19:13 + --> tests/ui/iterator_step_by_zero.rs:22:13 | LL | let _ = (1..).step_by(0); | ^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:21:13 + --> tests/ui/iterator_step_by_zero.rs:25:13 | LL | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:25:13 + --> tests/ui/iterator_step_by_zero.rs:30:13 | LL | let _ = x.step_by(0); | ^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:30:13 + --> tests/ui/iterator_step_by_zero.rs:36:13 | LL | let _ = v1.iter().step_by(2 / 3); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/join_absolute_paths.rs b/tests/ui/join_absolute_paths.rs index efa77a0492e6..ada160d963a6 100644 --- a/tests/ui/join_absolute_paths.rs +++ b/tests/ui/join_absolute_paths.rs @@ -8,19 +8,23 @@ use std::path::{Path, PathBuf}; fn main() { let path = Path::new("/bin"); path.join("/sh"); - //~^ ERROR: argument to `Path::join` starts with a path separator + //~^ join_absolute_paths + let path = Path::new("C:\\Users"); path.join("\\user"); - //~^ ERROR: argument to `Path::join` starts with a path separator + //~^ join_absolute_paths + let path = PathBuf::from("/bin"); path.join("/sh"); - //~^ ERROR: argument to `Path::join` starts with a path separator + //~^ join_absolute_paths + let path = PathBuf::from("/bin"); path.join(r#"/sh"#); - //~^ ERROR: argument to `Path::join` starts with a path separator + //~^ join_absolute_paths + let path: &[&str] = &["/bin"]; path.join("/sh"); diff --git a/tests/ui/join_absolute_paths.stderr b/tests/ui/join_absolute_paths.stderr index e7fd5508823a..94e8beb38446 100644 --- a/tests/ui/join_absolute_paths.stderr +++ b/tests/ui/join_absolute_paths.stderr @@ -17,7 +17,7 @@ LL | PathBuf::from("/sh"); | ~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:14:15 + --> tests/ui/join_absolute_paths.rs:15:15 | LL | path.join("\\user"); | ^^^^^^^^ @@ -33,7 +33,7 @@ LL | PathBuf::from("\\user"); | ~~~~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:18:15 + --> tests/ui/join_absolute_paths.rs:20:15 | LL | path.join("/sh"); | ^^^^^ @@ -49,7 +49,7 @@ LL | PathBuf::from("/sh"); | ~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:22:15 + --> tests/ui/join_absolute_paths.rs:25:15 | LL | path.join(r#"/sh"#); | ^^^^^^^^ diff --git a/tests/ui/large_const_arrays.fixed b/tests/ui/large_const_arrays.fixed index e5b28cb6a9dd..7c3868fc8ffd 100644 --- a/tests/ui/large_const_arrays.fixed +++ b/tests/ui/large_const_arrays.fixed @@ -8,9 +8,13 @@ pub struct S { // Should lint pub(crate) static FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays static FOO_COMPUTED: [u32; 1_000 * 100] = [0u32; 1_000 * 100]; +//~^ large_const_arrays static FOO: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays // Good pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250]; @@ -21,11 +25,17 @@ const G_FOO: [u32; 250] = [0u32; 250]; fn main() { // Should lint pub static BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays static BAR: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays pub static BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays static BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays pub static BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays // Good pub const G_BAR_PUB: [u32; 250] = [0u32; 250]; diff --git a/tests/ui/large_const_arrays.rs b/tests/ui/large_const_arrays.rs index b9593225da2f..3e811520f063 100644 --- a/tests/ui/large_const_arrays.rs +++ b/tests/ui/large_const_arrays.rs @@ -8,9 +8,13 @@ pub struct S { // Should lint pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays const FOO_COMPUTED: [u32; 1_000 * 100] = [0u32; 1_000 * 100]; +//~^ large_const_arrays const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; +//~^ large_const_arrays // Good pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250]; @@ -21,11 +25,17 @@ const G_FOO: [u32; 250] = [0u32; 250]; fn main() { // Should lint pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; + //~^ large_const_arrays pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; + //~^ large_const_arrays pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; + //~^ large_const_arrays // Good pub const G_BAR_PUB: [u32; 250] = [0u32; 250]; diff --git a/tests/ui/large_const_arrays.stderr b/tests/ui/large_const_arrays.stderr index 271122053908..56cddeaf628d 100644 --- a/tests/ui/large_const_arrays.stderr +++ b/tests/ui/large_const_arrays.stderr @@ -10,7 +10,7 @@ LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: large array defined as const - --> tests/ui/large_const_arrays.rs:11:1 + --> tests/ui/large_const_arrays.rs:12:1 | LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,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 - --> tests/ui/large_const_arrays.rs:12:1 + --> tests/ui/large_const_arrays.rs:14:1 | LL | const FOO_COMPUTED: [u32; 1_000 * 100] = [0u32; 1_000 * 100]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | const FOO_COMPUTED: [u32; 1_000 * 100] = [0u32; 1_000 * 100]; | help: make this a static item: `static` error: large array defined as const - --> tests/ui/large_const_arrays.rs:13:1 + --> tests/ui/large_const_arrays.rs:16:1 | LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,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 - --> tests/ui/large_const_arrays.rs:23:5 + --> tests/ui/large_const_arrays.rs:27:5 | LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,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 - --> tests/ui/large_const_arrays.rs:24:5 + --> tests/ui/large_const_arrays.rs:29:5 | LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,7 +50,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 - --> tests/ui/large_const_arrays.rs:25:5 + --> tests/ui/large_const_arrays.rs:31:5 | LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,7 +58,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 - --> tests/ui/large_const_arrays.rs:26:5 + --> tests/ui/large_const_arrays.rs:33:5 | LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,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 - --> tests/ui/large_const_arrays.rs:27:5 + --> tests/ui/large_const_arrays.rs:35:5 | LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,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 - --> tests/ui/large_const_arrays.rs:28:5 + --> tests/ui/large_const_arrays.rs:37: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 cdb001e47e2b..0ad2ebf522b8 100644 --- a/tests/ui/large_digit_groups.fixed +++ b/tests/ui/large_digit_groups.fixed @@ -20,10 +20,15 @@ fn main() { let _bad = ( 0b1_10110_i64, 0xdead_beef_usize, + //~^ unusual_byte_groupings 123_456_f32, + //~^ large_digit_groups 123_456.12_f32, + //~^ large_digit_groups 123_456.123_45_f64, + //~^ large_digit_groups 123_456.123_456_f64, + //~^ large_digit_groups ); // Ignore literals in macros let _ = mac!(); diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index 3c30c8670284..1cf489fd69b2 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -20,10 +20,15 @@ fn main() { let _bad = ( 0b1_10110_i64, 0xd_e_adbee_f_usize, + //~^ unusual_byte_groupings 1_23456_f32, + //~^ large_digit_groups 1_23456.12_f32, + //~^ large_digit_groups 1_23456.12345_f64, + //~^ large_digit_groups 1_23456.12345_6_f64, + //~^ large_digit_groups ); // Ignore literals in macros let _ = mac!(); diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr index da34a91bc3bc..281a6267c8d6 100644 --- a/tests/ui/large_digit_groups.stderr +++ b/tests/ui/large_digit_groups.stderr @@ -8,7 +8,7 @@ LL | 0xd_e_adbee_f_usize, = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: digit groups should be smaller - --> tests/ui/large_digit_groups.rs:23:9 + --> tests/ui/large_digit_groups.rs:24:9 | LL | 1_23456_f32, | ^^^^^^^^^^^ help: consider: `123_456_f32` @@ -17,19 +17,19 @@ LL | 1_23456_f32, = help: to override `-D warnings` add `#[allow(clippy::large_digit_groups)]` error: digit groups should be smaller - --> tests/ui/large_digit_groups.rs:24:9 + --> tests/ui/large_digit_groups.rs:26:9 | LL | 1_23456.12_f32, | ^^^^^^^^^^^^^^ help: consider: `123_456.12_f32` error: digit groups should be smaller - --> tests/ui/large_digit_groups.rs:25:9 + --> tests/ui/large_digit_groups.rs:28:9 | LL | 1_23456.12345_f64, | ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f64` error: digit groups should be smaller - --> tests/ui/large_digit_groups.rs:26:9 + --> tests/ui/large_digit_groups.rs:30:9 | LL | 1_23456.12345_6_f64, | ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64` diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index 31576a5863fc..8f70ad2b5b72 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -2,6 +2,7 @@ error: large size difference between variants --> tests/ui/large_enum_variant.rs:11:1 | LL | / enum LargeEnum { +LL | | LL | | A(i32), | | ------ the second-largest variant contains at least 4 bytes LL | | B([i32; 8000]), @@ -17,9 +18,10 @@ LL | B(Box<[i32; 8000]>), | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:35:1 + --> tests/ui/large_enum_variant.rs:36:1 | LL | / enum LargeEnum2 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | ContainingLargeEnum(LargeEnum), @@ -33,9 +35,10 @@ LL | ContainingLargeEnum(Box), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:40:1 + --> tests/ui/large_enum_variant.rs:42:1 | LL | / enum LargeEnum3 { +LL | | LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), | | --------------------------------------------------------- the largest variant contains at least 70004 bytes LL | | VoidVariant, @@ -50,9 +53,10 @@ LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:46:1 + --> tests/ui/large_enum_variant.rs:49:1 | LL | / enum LargeEnum4 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | StructLikeLarge { x: [i32; 8000], y: i32 }, @@ -66,9 +70,10 @@ LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:51:1 + --> tests/ui/large_enum_variant.rs:55:1 | LL | / enum LargeEnum5 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | StructLikeLarge2 { x: [i32; 8000] }, @@ -82,9 +87,10 @@ LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:67:1 + --> tests/ui/large_enum_variant.rs:72:1 | LL | / enum LargeEnum7 { +LL | | LL | | A, LL | | B([u8; 1255]), | | ------------- the largest variant contains at least 1255 bytes @@ -99,9 +105,10 @@ LL | B(Box<[u8; 1255]>), | ~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:73:1 + --> tests/ui/large_enum_variant.rs:79:1 | LL | / enum LargeEnum8 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), @@ -115,9 +122,10 @@ LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]> | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:78:1 + --> tests/ui/large_enum_variant.rs:85:1 | LL | / enum LargeEnum9 { +LL | | LL | | A(Struct<()>), | | ------------- the second-largest variant contains at least 4 bytes LL | | B(Struct2), @@ -131,9 +139,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:83:1 + --> tests/ui/large_enum_variant.rs:91:1 | LL | / enum LargeEnumOk2 { +LL | | LL | | A(T), | | ---- the second-largest variant contains at least 0 bytes LL | | B(Struct2), @@ -147,9 +156,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:88:1 + --> tests/ui/large_enum_variant.rs:97:1 | LL | / enum LargeEnumOk3 { +LL | | LL | | A(Struct), | | ------------ the second-largest variant contains at least 4 bytes LL | | B(Struct2), @@ -163,9 +173,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:103:1 + --> tests/ui/large_enum_variant.rs:113:1 | LL | / enum CopyableLargeEnum { +LL | | LL | | A(bool), | | ------- the second-largest variant contains at least 1 bytes LL | | B([u64; 8000]), @@ -174,20 +185,21 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:103:6 + --> tests/ui/large_enum_variant.rs:113:6 | LL | enum CopyableLargeEnum { | ^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:105:5 + --> tests/ui/large_enum_variant.rs:116:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:108:1 + --> tests/ui/large_enum_variant.rs:119:1 | LL | / enum ManuallyCopyLargeEnum { +LL | | LL | | A(bool), | | ------- the second-largest variant contains at least 1 bytes LL | | B([u64; 8000]), @@ -196,20 +208,21 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:108:6 + --> tests/ui/large_enum_variant.rs:119:6 | LL | enum ManuallyCopyLargeEnum { | ^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:110:5 + --> tests/ui/large_enum_variant.rs:122:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:121:1 + --> tests/ui/large_enum_variant.rs:133:1 | LL | / enum SomeGenericPossiblyCopyEnum { +LL | | LL | | A(bool, std::marker::PhantomData), | | ------------------------------------ the second-largest variant contains at least 1 bytes LL | | B([u64; 4000]), @@ -218,20 +231,21 @@ LL | | } | |_^ the entire enum is at least 32008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:121:6 + --> tests/ui/large_enum_variant.rs:133:6 | LL | enum SomeGenericPossiblyCopyEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:123:5 + --> tests/ui/large_enum_variant.rs:136:5 | LL | B([u64; 4000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:134:1 + --> tests/ui/large_enum_variant.rs:147:1 | LL | / enum LargeEnumWithGenerics { +LL | | LL | | Small, | | ----- the second-largest variant carries no data at all LL | | Large((T, [u8; 512])), @@ -245,9 +259,10 @@ LL | Large(Box<(T, [u8; 512])>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:143:1 + --> tests/ui/large_enum_variant.rs:157:1 | LL | / enum WithGenerics { +LL | | LL | | Large([Foo; 64]), | | --------------------- the largest variant contains at least 512 bytes LL | | Small(u8), @@ -261,9 +276,10 @@ LL | Large(Box<[Foo; 64]>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:153:1 + --> tests/ui/large_enum_variant.rs:168:1 | LL | / enum LargeEnumOfConst { +LL | | LL | | Ok, | | -- the second-largest variant carries no data at all LL | | Error(PossiblyLargeEnumWithConst<256>), @@ -277,9 +293,10 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:158:1 + --> tests/ui/large_enum_variant.rs:174:1 | LL | / enum WithRecursion { +LL | | LL | | Large([u64; 64]), | | ---------------- the largest variant contains at least 512 bytes LL | | Recursive(Box), @@ -293,9 +310,10 @@ LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:168:1 + --> tests/ui/large_enum_variant.rs:185:1 | LL | / enum LargeEnumWithGenericsAndRecursive { +LL | | LL | | Ok(), | | ---- the second-largest variant carries no data at all LL | | Error(WithRecursionAndGenerics), @@ -309,9 +327,10 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:203:5 + --> tests/ui/large_enum_variant.rs:221:5 | LL | / enum NoWarnings { +LL | | LL | | BigBoi(PublishWithBytes), | | ------------------------ the largest variant contains at least 296 bytes LL | | _SmallBoi(u8), @@ -325,9 +344,10 @@ LL | BigBoi(Box), | ~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:208:5 + --> tests/ui/large_enum_variant.rs:227:5 | LL | / enum MakesClippyAngry { +LL | | LL | | BigBoi(PublishWithVec), | | ---------------------- the largest variant contains at least 224 bytes LL | | _SmallBoi(u8), diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 57722f63b225..0ed562f90bc0 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -9,6 +9,7 @@ extern crate proc_macros; use proc_macros::external; enum LargeEnum { +//~^ large_enum_variant A(i32), B([i32; 8000]), } @@ -33,22 +34,26 @@ enum LargeEnumGeneric { } enum LargeEnum2 { +//~^ large_enum_variant VariantOk(i32, u32), ContainingLargeEnum(LargeEnum), } enum LargeEnum3 { +//~^ large_enum_variant ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), VoidVariant, StructLikeLittle { x: i32, y: i32 }, } enum LargeEnum4 { +//~^ large_enum_variant VariantOk(i32, u32), StructLikeLarge { x: [i32; 8000], y: i32 }, } enum LargeEnum5 { +//~^ large_enum_variant VariantOk(i32, u32), StructLikeLarge2 { x: [i32; 8000] }, } @@ -65,27 +70,32 @@ enum LargeEnum6 { } enum LargeEnum7 { +//~^ large_enum_variant A, B([u8; 1255]), C([u8; 200]), } enum LargeEnum8 { +//~^ large_enum_variant VariantOk(i32, u32), ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), } enum LargeEnum9 { +//~^ large_enum_variant A(Struct<()>), B(Struct2), } enum LargeEnumOk2 { +//~^ large_enum_variant A(T), B(Struct2), } enum LargeEnumOk3 { +//~^ large_enum_variant A(Struct), B(Struct2), } @@ -101,11 +111,13 @@ struct Struct2 { #[derive(Copy, Clone)] enum CopyableLargeEnum { +//~^ large_enum_variant A(bool), B([u64; 8000]), } enum ManuallyCopyLargeEnum { +//~^ large_enum_variant A(bool), B([u64; 8000]), } @@ -119,6 +131,7 @@ impl Clone for ManuallyCopyLargeEnum { impl Copy for ManuallyCopyLargeEnum {} enum SomeGenericPossiblyCopyEnum { +//~^ large_enum_variant A(bool, std::marker::PhantomData), B([u64; 4000]), } @@ -132,6 +145,7 @@ impl Clone for SomeGenericPossiblyCopyEnum { impl Copy for SomeGenericPossiblyCopyEnum {} enum LargeEnumWithGenerics { +//~^ large_enum_variant Small, Large((T, [u8; 512])), } @@ -141,6 +155,7 @@ struct Foo { } enum WithGenerics { +//~^ large_enum_variant Large([Foo; 64]), Small(u8), } @@ -151,11 +166,13 @@ enum PossiblyLargeEnumWithConst { } enum LargeEnumOfConst { +//~^ large_enum_variant Ok, Error(PossiblyLargeEnumWithConst<256>), } enum WithRecursion { +//~^ large_enum_variant Large([u64; 64]), Recursive(Box), } @@ -166,6 +183,7 @@ enum WithRecursionAndGenerics { } enum LargeEnumWithGenericsAndRecursive { +//~^ large_enum_variant Ok(), Error(WithRecursionAndGenerics), } @@ -201,11 +219,13 @@ mod issue11915 { } enum NoWarnings { + //~^ large_enum_variant BigBoi(PublishWithBytes), _SmallBoi(u8), } enum MakesClippyAngry { + //~^ large_enum_variant BigBoi(PublishWithVec), _SmallBoi(u8), } diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index 1e87859f4526..dabb96e42918 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -8,21 +8,25 @@ 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` + //~^ large_futures + + }; Box::pin(f).await - //~^ ERROR: large future with a size of 16386 bytes + //~^ large_futures + } async fn calls_fut(fut: impl std::future::Future) { loop { Box::pin(wait()).await; - //~^ ERROR: large future with a size of 16387 bytes + //~^ large_futures + if true { return fut.await; } else { Box::pin(wait()).await; - //~^ ERROR: large future with a size of 16387 bytes + //~^ large_futures + } } } @@ -30,9 +34,11 @@ 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 + //~^ large_futures + Box::pin(calls_fut(fut)).await; - //~^ ERROR: large future with a size of 49159 bytes + //~^ large_futures + } pub fn foo() -> impl std::future::Future { @@ -45,7 +51,8 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { Box::pin(async { - //~^ ERROR: large future with a size of 65540 bytes + //~^ large_futures + let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); @@ -57,6 +64,7 @@ pub async fn macro_expn() { macro_rules! macro_ { () => { Box::pin(async { + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; println!("macro: {:?}", x); diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index 3f4ea2ebf8bb..bafb0e2e3ba5 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -8,21 +8,25 @@ 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` + //~^ large_futures + + }; f.await - //~^ ERROR: large future with a size of 16386 bytes + //~^ large_futures + } async fn calls_fut(fut: impl std::future::Future) { loop { wait().await; - //~^ ERROR: large future with a size of 16387 bytes + //~^ large_futures + if true { return fut.await; } else { wait().await; - //~^ ERROR: large future with a size of 16387 bytes + //~^ large_futures + } } } @@ -30,9 +34,11 @@ 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 + //~^ large_futures + calls_fut(fut).await; - //~^ ERROR: large future with a size of 49159 bytes + //~^ large_futures + } pub fn foo() -> impl std::future::Future { @@ -45,7 +51,8 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { async { - //~^ ERROR: large future with a size of 65540 bytes + //~^ large_futures + let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); @@ -57,6 +64,7 @@ pub async fn macro_expn() { macro_rules! macro_ { () => { async { + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; println!("macro: {:?}", x); diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 00082e579c59..cefc4769e846 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -8,40 +8,41 @@ LL | big_fut([0u8; 1024 * 16]).await; = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: large future with a size of 16386 bytes - --> tests/ui/large_futures.rs:14:5 + --> tests/ui/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 - --> tests/ui/large_futures.rs:19:9 + --> tests/ui/large_futures.rs:21:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> tests/ui/large_futures.rs:24:13 + --> tests/ui/large_futures.rs:27:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:32:5 + --> tests/ui/large_futures.rs:36:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> tests/ui/large_futures.rs:34:5 + --> tests/ui/large_futures.rs:39: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 - --> tests/ui/large_futures.rs:47:5 + --> tests/ui/large_futures.rs:53:5 | LL | / async { LL | | +LL | | LL | | let x = [0i32; 1024 * 16]; LL | | async {}.await; LL | | println!("{:?}", x); @@ -52,6 +53,7 @@ help: consider `Box::pin` on it | LL ~ Box::pin(async { LL + +LL + LL + let x = [0i32; 1024 * 16]; LL + async {}.await; LL + println!("{:?}", x); @@ -59,9 +61,10 @@ LL + }) | error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:59:13 + --> tests/ui/large_futures.rs:66:13 | LL | / async { +LL | | LL | | let x = [0i32; 1024 * 16]; LL | | async {}.await; LL | | println!("macro: {:?}", x); @@ -75,6 +78,7 @@ LL | macro_!().await help: consider `Box::pin` on it | LL ~ Box::pin(async { +LL + LL + let x = [0i32; 1024 * 16]; LL + async {}.await; LL + println!("macro: {:?}", x); diff --git a/tests/ui/large_stack_frames.rs b/tests/ui/large_stack_frames.rs index e6c030b8a9e8..81d89cc1c5ca 100644 --- a/tests/ui/large_stack_frames.rs +++ b/tests/ui/large_stack_frames.rs @@ -25,7 +25,8 @@ impl Default for ArrayDefault { } fn many_small_arrays() { - //~^ ERROR: this function may allocate +//~^ large_stack_frames + let x = [0u8; 500_000]; let x2 = [0u8; 500_000]; let x3 = [0u8; 500_000]; @@ -35,18 +36,21 @@ fn many_small_arrays() { } fn large_return_value() -> ArrayDefault<1_000_000> { - //~^ ERROR: this function may allocate 1000000 bytes on the stack +//~^ large_stack_frames + Default::default() } fn large_fn_arg(x: ArrayDefault<1_000_000>) { - //~^ ERROR: this function may allocate +//~^ large_stack_frames + black_box(&x); } fn has_large_closure() { let f = || black_box(&[0u8; 1_000_000]); - //~^ ERROR: this function may allocate + //~^ large_stack_frames + f(); } diff --git a/tests/ui/large_stack_frames.stderr b/tests/ui/large_stack_frames.stderr index f2e0a127f5f5..0ff49e9f5b37 100644 --- a/tests/ui/large_stack_frames.stderr +++ b/tests/ui/large_stack_frames.stderr @@ -13,7 +13,7 @@ LL | let x5 = [0u8; 500_000]; = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]` error: this function may allocate 1000000 bytes on the stack - --> tests/ui/large_stack_frames.rs:37:4 + --> tests/ui/large_stack_frames.rs:38:4 | LL | fn large_return_value() -> ArrayDefault<1_000_000> { | ^^^^^^^^^^^^^^^^^^ ----------------------- this is the largest part, at 1000000 bytes for type `ArrayDefault<1000000>` @@ -21,7 +21,7 @@ LL | fn large_return_value() -> ArrayDefault<1_000_000> { = note: 1000000 bytes is larger than Clippy's configured `stack-size-threshold` of 512000 error: this function may allocate 100$PTR bytes on the stack - --> tests/ui/large_stack_frames.rs:42:4 + --> tests/ui/large_stack_frames.rs:44:4 | LL | fn large_fn_arg(x: ArrayDefault<1_000_000>) { | ^^^^^^^^^^^^ - `x` is the largest part, at 1000000 bytes for type `ArrayDefault<1000000>` @@ -29,7 +29,7 @@ LL | fn large_fn_arg(x: ArrayDefault<1_000_000>) { = note: 100$PTR bytes is larger than Clippy's configured `stack-size-threshold` of 512000 error: this function may allocate 100$PTR bytes on the stack - --> tests/ui/large_stack_frames.rs:48:13 + --> tests/ui/large_stack_frames.rs:51:13 | LL | let f = || black_box(&[0u8; 1_000_000]); | ^^^^^^^^^^^^^^----------------^ diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs index 78994a2988a2..cd0c88b6834c 100644 --- a/tests/ui/large_types_passed_by_value.rs +++ b/tests/ui/large_types_passed_by_value.rs @@ -18,19 +18,25 @@ fn not_copy(a: Large) {} fn by_ref(a: &Large, b: &LargeAndCopy) {} fn mutable(mut a: LargeAndCopy) {} fn bad(a: LargeAndCopy) {} +//~^ large_types_passed_by_value pub fn bad_but_pub(a: LargeAndCopy) {} impl LargeAndCopy { fn self_is_ok(self) {} fn other_is_not_ok(self, other: LargeAndCopy) {} + //~^ large_types_passed_by_value fn unless_other_can_change(self, mut other: LargeAndCopy) {} pub fn or_were_in_public(self, other: LargeAndCopy) {} } trait LargeTypeDevourer { fn devoure_array(&self, array: [u8; 6666]); + //~^ large_types_passed_by_value fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); + //~^ large_types_passed_by_value fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); + //~^ large_types_passed_by_value + //~| large_types_passed_by_value } pub trait PubLargeTypeDevourer { @@ -56,10 +62,12 @@ fn foo_always(x: LargeAndCopy) { } #[inline(never)] fn foo_never(x: LargeAndCopy) { +//~^ large_types_passed_by_value todo!(); } #[inline] fn foo(x: LargeAndCopy) { +//~^ large_types_passed_by_value todo!(); } diff --git a/tests/ui/large_types_passed_by_value.stderr b/tests/ui/large_types_passed_by_value.stderr index 5b42ab9e02ac..0ad68bc326e0 100644 --- a/tests/ui/large_types_passed_by_value.stderr +++ b/tests/ui/large_types_passed_by_value.stderr @@ -8,43 +8,43 @@ LL | fn bad(a: LargeAndCopy) {} = help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:25:37 + --> tests/ui/large_types_passed_by_value.rs:26:37 | LL | fn other_is_not_ok(self, other: LargeAndCopy) {} | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:31:36 + --> tests/ui/large_types_passed_by_value.rs:33:36 | LL | fn devoure_array(&self, array: [u8; 6666]); | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:32:34 + --> tests/ui/large_types_passed_by_value.rs:35:34 | LL | fn devoure_tuple(&self, tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:33:50 + --> tests/ui/large_types_passed_by_value.rs:37:50 | LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^ help: consider passing by reference instead: `&[u8; 6666]` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:33:67 + --> tests/ui/large_types_passed_by_value.rs:37:67 | LL | fn devoure_array_and_tuple_wow(&self, array: [u8; 6666], tup: (LargeAndCopy, LargeAndCopy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider passing by reference instead: `&(LargeAndCopy, LargeAndCopy)` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:58:17 + --> tests/ui/large_types_passed_by_value.rs:64:17 | LL | fn foo_never(x: LargeAndCopy) { | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) - --> tests/ui/large_types_passed_by_value.rs:62:11 + --> tests/ui/large_types_passed_by_value.rs:69:11 | LL | fn foo(x: LargeAndCopy) { | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` diff --git a/tests/ui/legacy_numeric_constants.fixed b/tests/ui/legacy_numeric_constants.fixed index 3a2294ef4c59..30bb549a9d65 100644 --- a/tests/ui/legacy_numeric_constants.fixed +++ b/tests/ui/legacy_numeric_constants.fixed @@ -1,4 +1,5 @@ //@aux-build:proc_macros.rs +//@require-annotations-for-level: WARN #![allow(clippy::no_effect, deprecated, unused)] #![allow(clippy::legacy_numeric_constants)] // For imports. diff --git a/tests/ui/legacy_numeric_constants.rs b/tests/ui/legacy_numeric_constants.rs index 6cb3e694ea14..d3878199055f 100644 --- a/tests/ui/legacy_numeric_constants.rs +++ b/tests/ui/legacy_numeric_constants.rs @@ -1,4 +1,5 @@ //@aux-build:proc_macros.rs +//@require-annotations-for-level: WARN #![allow(clippy::no_effect, deprecated, unused)] #![allow(clippy::legacy_numeric_constants)] // For imports. diff --git a/tests/ui/legacy_numeric_constants.stderr b/tests/ui/legacy_numeric_constants.stderr index 267b9ac8e4d1..af9b003ed540 100644 --- a/tests/ui/legacy_numeric_constants.stderr +++ b/tests/ui/legacy_numeric_constants.stderr @@ -1,5 +1,5 @@ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:31:5 + --> tests/ui/legacy_numeric_constants.rs:32:5 | LL | std::f32::EPSILON; | ^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | f32::EPSILON; | ~~~~~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:34:5 + --> tests/ui/legacy_numeric_constants.rs:35:5 | LL | std::u8::MIN; | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | u8::MIN; | ~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:37:5 + --> tests/ui/legacy_numeric_constants.rs:38:5 | LL | std::usize::MIN; | ^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | usize::MIN; | ~~~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:40:5 + --> tests/ui/legacy_numeric_constants.rs:41:5 | LL | std::u32::MAX; | ^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | u32::MAX; | ~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:43:5 + --> tests/ui/legacy_numeric_constants.rs:44:5 | LL | core::u32::MAX; | ^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | u32::MAX; | ~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:46:5 + --> tests/ui/legacy_numeric_constants.rs:47:5 | LL | MAX; | ^^^ @@ -67,7 +67,7 @@ LL | u32::MAX; | ~~~~~~~~ error: usage of a legacy numeric method - --> tests/ui/legacy_numeric_constants.rs:49:10 + --> tests/ui/legacy_numeric_constants.rs:50:10 | LL | i32::max_value(); | ^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | i32::MAX; | ~~~ error: usage of a legacy numeric method - --> tests/ui/legacy_numeric_constants.rs:52:9 + --> tests/ui/legacy_numeric_constants.rs:53:9 | LL | u8::max_value(); | ^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | u8::MAX; | ~~~ error: usage of a legacy numeric method - --> tests/ui/legacy_numeric_constants.rs:55:9 + --> tests/ui/legacy_numeric_constants.rs:56:9 | LL | u8::min_value(); | ^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | u8::MIN; | ~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:58:5 + --> tests/ui/legacy_numeric_constants.rs:59:5 | LL | ::std::u8::MIN; | ^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | u8::MIN; | ~~~~~~~ error: usage of a legacy numeric method - --> tests/ui/legacy_numeric_constants.rs:61:27 + --> tests/ui/legacy_numeric_constants.rs:62:27 | LL | ::std::primitive::u8::min_value(); | ^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | ::std::primitive::u8::MIN; | ~~~ error: usage of a legacy numeric method - --> tests/ui/legacy_numeric_constants.rs:64:26 + --> tests/ui/legacy_numeric_constants.rs:65:26 | LL | std::primitive::i32::max_value(); | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | std::primitive::i32::MAX; | ~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:67:5 + --> tests/ui/legacy_numeric_constants.rs:68:5 | LL | self::a::u128::MAX; | ^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | u128::MAX; | ~~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:17:25 + --> tests/ui/legacy_numeric_constants.rs:18:25 | LL | let x = std::u64::MAX; | ^^^^^^^^^^^^^ @@ -159,7 +159,7 @@ LL | let x = u64::MAX; | ~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:81:14 + --> tests/ui/legacy_numeric_constants.rs:82:14 | LL | [(0, "", std::i128::MAX)]; | ^^^^^^^^^^^^^^ @@ -170,7 +170,7 @@ LL | [(0, "", i128::MAX)]; | ~~~~~~~~~ error: usage of a legacy numeric constant - --> tests/ui/legacy_numeric_constants.rs:115:5 + --> tests/ui/legacy_numeric_constants.rs:116:5 | LL | std::u32::MAX; | ^^^^^^^^^^^^^ diff --git a/tests/ui/legacy_numeric_constants_unfixable.rs b/tests/ui/legacy_numeric_constants_unfixable.rs index 86738ede210c..9bf0f7f355ae 100644 --- a/tests/ui/legacy_numeric_constants_unfixable.rs +++ b/tests/ui/legacy_numeric_constants_unfixable.rs @@ -1,4 +1,5 @@ //@no-rustfix +//@require-annotations-for-level: WARN //@aux-build:proc_macros.rs #![allow(clippy::no_effect, deprecated, unused)] #![warn(clippy::legacy_numeric_constants)] diff --git a/tests/ui/legacy_numeric_constants_unfixable.stderr b/tests/ui/legacy_numeric_constants_unfixable.stderr index 2edcf7188362..96e6c9ef9759 100644 --- a/tests/ui/legacy_numeric_constants_unfixable.stderr +++ b/tests/ui/legacy_numeric_constants_unfixable.stderr @@ -1,5 +1,5 @@ error: importing legacy numeric constants - --> tests/ui/legacy_numeric_constants_unfixable.rs:9:5 + --> tests/ui/legacy_numeric_constants_unfixable.rs:10:5 | LL | use std::u128 as _; | ^^^^^^^^^ @@ -9,7 +9,7 @@ LL | use std::u128 as _; = help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]` error: importing legacy numeric constants - --> tests/ui/legacy_numeric_constants_unfixable.rs:13:24 + --> tests/ui/legacy_numeric_constants_unfixable.rs:14:24 | LL | pub use std::{mem, u128}; | ^^^^ @@ -18,7 +18,7 @@ LL | pub use std::{mem, u128}; = note: then `u128::` will resolve to the respective associated constant error: importing a legacy numeric constant - --> tests/ui/legacy_numeric_constants_unfixable.rs:29:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:30:9 | LL | use std::u32::MAX; | ^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | use std::u32::MAX; = help: remove this import and use the associated constant `u32::MAX` from the primitive type instead error: importing a legacy numeric constant - --> tests/ui/legacy_numeric_constants_unfixable.rs:32:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:33:9 | LL | use std::u8::MIN; | ^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | use std::u8::MIN; = help: remove this import and use the associated constant `u8::MIN` from the primitive type instead error: importing legacy numeric constants - --> tests/ui/legacy_numeric_constants_unfixable.rs:36:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:37:9 | LL | use std::u32; | ^^^^^^^^ @@ -43,7 +43,7 @@ LL | use std::u32; = note: then `u32::` will resolve to the respective associated constant error: importing a legacy numeric constant - --> tests/ui/legacy_numeric_constants_unfixable.rs:40:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:41:9 | LL | use std::f32::MIN_POSITIVE; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL | use std::f32::MIN_POSITIVE; = help: remove this import and use the associated constant `f32::MIN_POSITIVE` from the primitive type instead error: importing legacy numeric constants - --> tests/ui/legacy_numeric_constants_unfixable.rs:44:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:45:9 | LL | use std::i16::*; | ^^^^^^^^ @@ -59,7 +59,7 @@ LL | use std::i16::*; = help: remove this import and use associated constants `i16::` from the primitive type instead error: importing legacy numeric constants - --> tests/ui/legacy_numeric_constants_unfixable.rs:21:17 + --> tests/ui/legacy_numeric_constants_unfixable.rs:22:17 | LL | use std::u32; | ^^^^^^^^ @@ -72,7 +72,7 @@ LL | b!(); = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) error: importing a legacy numeric constant - --> tests/ui/legacy_numeric_constants_unfixable.rs:76:9 + --> tests/ui/legacy_numeric_constants_unfixable.rs:77:9 | LL | use std::u32::MAX; | ^^^^^^^^^^^^^ diff --git a/tests/ui/len_without_is_empty.rs b/tests/ui/len_without_is_empty.rs index d623601110e2..781c28d04bec 100644 --- a/tests/ui/len_without_is_empty.rs +++ b/tests/ui/len_without_is_empty.rs @@ -5,8 +5,9 @@ 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` + //~^ len_without_is_empty + + 1 } } @@ -55,7 +56,8 @@ impl PubAllowedStruct { } pub trait PubTraitsToo { - //~^ ERROR: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` +//~^ len_without_is_empty + fn len(&self) -> isize; } @@ -69,7 +71,8 @@ pub struct HasIsEmpty; impl HasIsEmpty { pub fn len(&self) -> isize { - //~^ ERROR: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` me + //~^ len_without_is_empty + 1 } @@ -82,7 +85,8 @@ pub struct HasWrongIsEmpty; impl HasWrongIsEmpty { pub fn len(&self) -> isize { - //~^ ERROR: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` met + //~^ len_without_is_empty + 1 } @@ -95,7 +99,8 @@ pub struct MismatchedSelf; impl MismatchedSelf { pub fn len(self) -> isize { - //~^ ERROR: struct `MismatchedSelf` has a public `len` method, but the `is_empty` meth + //~^ len_without_is_empty + 1 } @@ -175,7 +180,8 @@ 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` +//~^ len_without_is_empty + fn len(&mut self) -> usize; } @@ -221,7 +227,8 @@ 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 + //~^ len_without_is_empty + 0 } @@ -234,8 +241,10 @@ 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<_, ()>` + //~^ len_without_is_empty + //~| result_unit_err + + Ok(0) } @@ -248,12 +257,14 @@ impl ResultLen { pub struct ResultLen2; impl ResultLen2 { pub fn len(&self) -> Result { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Ok(0) } pub fn is_empty(&self) -> Result { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Ok(true) } } @@ -261,7 +272,8 @@ impl ResultLen2 { pub struct ResultLen3; impl ResultLen3 { pub fn len(&self) -> Result { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Ok(0) } @@ -303,7 +315,8 @@ impl AsyncLenWithoutIsEmpty { } pub async fn len(&self) -> usize { - //~^ ERROR: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empt + //~^ len_without_is_empty + usize::from(!self.async_task().await) } } @@ -316,7 +329,8 @@ impl AsyncOptionLenWithoutIsEmpty { } pub async fn len(&self) -> Option { - //~^ ERROR: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `i + //~^ len_without_is_empty + None } } @@ -338,7 +352,8 @@ impl AsyncResultLenWithoutIsEmpty { } pub async fn len(&self) -> Result { - //~^ ERROR: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `i + //~^ len_without_is_empty + Err(()) } } @@ -454,7 +469,8 @@ pub struct Aliased2; pub type Alias2 = Aliased2; impl Alias2 { pub fn len(&self) -> usize { - //~^ ERROR: type `Alias2` has a public `len` method, but no `is_empty` method + //~^ len_without_is_empty + todo!() } } diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index 11d0d855fc0b..0fd445c720bd 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -8,89 +8,91 @@ LL | pub fn len(&self) -> isize { = help: to override `-D warnings` add `#[allow(clippy::len_without_is_empty)]` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> tests/ui/len_without_is_empty.rs:57:1 + --> tests/ui/len_without_is_empty.rs:58:1 | LL | / pub trait PubTraitsToo { LL | | +LL | | LL | | fn len(&self) -> isize; LL | | } | |_^ error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method - --> tests/ui/len_without_is_empty.rs:71:5 + --> tests/ui/len_without_is_empty.rs:73:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:76:5 + --> tests/ui/len_without_is_empty.rs:79:5 | LL | fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature - --> tests/ui/len_without_is_empty.rs:84:5 + --> tests/ui/len_without_is_empty.rs:87:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:89:5 + --> tests/ui/len_without_is_empty.rs:93: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 - --> tests/ui/len_without_is_empty.rs:97:5 + --> tests/ui/len_without_is_empty.rs:101:5 | LL | pub fn len(self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:102:5 + --> tests/ui/len_without_is_empty.rs:107: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 - --> tests/ui/len_without_is_empty.rs:177:1 + --> tests/ui/len_without_is_empty.rs:182:1 | LL | / pub trait DependsOnFoo: Foo { LL | | +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 - --> tests/ui/len_without_is_empty.rs:223:5 + --> tests/ui/len_without_is_empty.rs:229:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:229:5 + --> tests/ui/len_without_is_empty.rs:236: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 - --> tests/ui/len_without_is_empty.rs:236:5 + --> tests/ui/len_without_is_empty.rs:243:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:243:5 + --> tests/ui/len_without_is_empty.rs:252:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` or `(&self) -> Result error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:236:5 + --> tests/ui/len_without_is_empty.rs:243:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +102,7 @@ LL | pub fn len(&self) -> Result { = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:250:5 + --> tests/ui/len_without_is_empty.rs:259:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +110,7 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:255:5 + --> tests/ui/len_without_is_empty.rs:265:5 | LL | pub fn is_empty(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -116,7 +118,7 @@ LL | pub fn is_empty(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:263:5 + --> tests/ui/len_without_is_empty.rs:274:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -124,25 +126,25 @@ 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 - --> tests/ui/len_without_is_empty.rs:305:5 + --> tests/ui/len_without_is_empty.rs:317:5 | LL | pub async fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:318:5 + --> tests/ui/len_without_is_empty.rs:331:5 | LL | pub async fn len(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:340:5 + --> tests/ui/len_without_is_empty.rs:354:5 | LL | pub async fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `Alias2` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:456:5 + --> tests/ui/len_without_is_empty.rs:471:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/len_zero.fixed b/tests/ui/len_zero.fixed index c9c476ba4214..e24a569cfde8 100644 --- a/tests/ui/len_zero.fixed +++ b/tests/ui/len_zero.fixed @@ -86,10 +86,12 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; if x.is_empty() { + //~^ len_zero println!("This should not happen!"); } if "".is_empty() {} + //~^ len_zero let s = "Hello, world!"; let s1 = &s; @@ -99,16 +101,24 @@ fn main() { let s5 = &s4; let s6 = &s5; println!("{}", s1.is_empty()); + //~^ comparison_to_empty println!("{}", s2.is_empty()); + //~^ comparison_to_empty println!("{}", s3.is_empty()); + //~^ comparison_to_empty println!("{}", s4.is_empty()); + //~^ comparison_to_empty println!("{}", s5.is_empty()); + //~^ comparison_to_empty println!("{}", (s6).is_empty()); + //~^ comparison_to_empty let d2s = DerefToDerefToString {}; println!("{}", (**d2s).is_empty()); + //~^ comparison_to_empty println!("{}", std::borrow::Cow::Borrowed("").is_empty()); + //~^ comparison_to_empty let y = One; if y.len() == 0 { @@ -124,18 +134,23 @@ fn main() { let has_is_empty = HasIsEmpty; if has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 1 { @@ -147,18 +162,23 @@ fn main() { println!("This can happen."); } if has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if has_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } if 1 < has_is_empty.len() { @@ -173,6 +193,7 @@ fn main() { let with_is_empty: &dyn WithIsEmpty = &Wither; if with_is_empty.is_empty() { + //~^ len_zero println!("Or this!"); } assert!(!with_is_empty.is_empty()); @@ -185,11 +206,14 @@ fn main() { // issue #10529 (!has_is_empty.is_empty()).then(|| println!("This can happen.")); + //~^ len_zero (has_is_empty.is_empty()).then(|| println!("Or this!")); + //~^ len_zero } fn test_slice(b: &[u8]) { if !b.is_empty() {} + //~^ len_zero } // issue #11992 @@ -224,9 +248,12 @@ fn binop_with_macros() { if has_is_empty.len() == compare_to!(1) {} if has_is_empty.is_empty() {} + //~^ len_zero if has_is_empty.is_empty() {} + //~^ len_zero (!has_is_empty.is_empty()).then(|| println!("This can happen.")); + //~^ len_zero } fn no_infinite_recursion() -> bool { diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index 610a5448d10e..b558dd9a215e 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -86,10 +86,12 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; if x.len() == 0 { + //~^ len_zero println!("This should not happen!"); } if "".len() == 0 {} + //~^ len_zero let s = "Hello, world!"; let s1 = &s; @@ -99,16 +101,24 @@ fn main() { let s5 = &s4; let s6 = &s5; println!("{}", *s1 == ""); + //~^ comparison_to_empty println!("{}", **s2 == ""); + //~^ comparison_to_empty println!("{}", ***s3 == ""); + //~^ comparison_to_empty println!("{}", ****s4 == ""); + //~^ comparison_to_empty println!("{}", *****s5 == ""); + //~^ comparison_to_empty println!("{}", ******(s6) == ""); + //~^ comparison_to_empty let d2s = DerefToDerefToString {}; println!("{}", &**d2s == ""); + //~^ comparison_to_empty println!("{}", std::borrow::Cow::Borrowed("") == ""); + //~^ comparison_to_empty let y = One; if y.len() == 0 { @@ -124,18 +134,23 @@ fn main() { let has_is_empty = HasIsEmpty; if has_is_empty.len() == 0 { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() != 0 { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 0 { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() < 1 { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() >= 1 { + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 1 { @@ -147,18 +162,23 @@ fn main() { println!("This can happen."); } if 0 == has_is_empty.len() { + //~^ len_zero println!("Or this!"); } if 0 != has_is_empty.len() { + //~^ len_zero println!("Or this!"); } if 0 < has_is_empty.len() { + //~^ len_zero println!("Or this!"); } if 1 <= has_is_empty.len() { + //~^ len_zero println!("Or this!"); } if 1 > has_is_empty.len() { + //~^ len_zero println!("Or this!"); } if 1 < has_is_empty.len() { @@ -173,6 +193,7 @@ fn main() { let with_is_empty: &dyn WithIsEmpty = &Wither; if with_is_empty.len() == 0 { + //~^ len_zero println!("Or this!"); } assert!(!with_is_empty.is_empty()); @@ -185,11 +206,14 @@ fn main() { // issue #10529 (has_is_empty.len() > 0).then(|| println!("This can happen.")); + //~^ len_zero (has_is_empty.len() == 0).then(|| println!("Or this!")); + //~^ len_zero } fn test_slice(b: &[u8]) { if b.len() != 0 {} + //~^ len_zero } // issue #11992 @@ -224,9 +248,12 @@ fn binop_with_macros() { if has_is_empty.len() == compare_to!(1) {} if has_is_empty.len() == compare_to!(0) {} + //~^ len_zero if has_is_empty.len() == zero!() {} + //~^ len_zero (compare_to!(0) < has_is_empty.len()).then(|| println!("This can happen.")); + //~^ len_zero } fn no_infinite_recursion() -> bool { diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 8d6b57e4b6d4..25052f39ad33 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -8,13 +8,13 @@ LL | if x.len() == 0 { = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> tests/ui/len_zero.rs:92:8 + --> tests/ui/len_zero.rs:93:8 | LL | if "".len() == 0 {} | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:101:20 + --> tests/ui/len_zero.rs:103:20 | LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` @@ -23,145 +23,145 @@ LL | println!("{}", *s1 == ""); = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> tests/ui/len_zero.rs:102:20 + --> tests/ui/len_zero.rs:105:20 | LL | println!("{}", **s2 == ""); | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s2.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:103:20 + --> tests/ui/len_zero.rs:107:20 | LL | println!("{}", ***s3 == ""); | ^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s3.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:104:20 + --> tests/ui/len_zero.rs:109:20 | LL | println!("{}", ****s4 == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s4.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:105:20 + --> tests/ui/len_zero.rs:111:20 | LL | println!("{}", *****s5 == ""); | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s5.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:106:20 + --> tests/ui/len_zero.rs:113:20 | LL | println!("{}", ******(s6) == ""); | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(s6).is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:109:20 + --> tests/ui/len_zero.rs:117:20 | LL | println!("{}", &**d2s == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(**d2s).is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:111:20 + --> tests/ui/len_zero.rs:120:20 | LL | println!("{}", std::borrow::Cow::Borrowed("") == ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `std::borrow::Cow::Borrowed("").is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:126:8 + --> tests/ui/len_zero.rs:136: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 - --> tests/ui/len_zero.rs:129:8 + --> tests/ui/len_zero.rs:140: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 - --> tests/ui/len_zero.rs:132:8 + --> tests/ui/len_zero.rs:144: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 - --> tests/ui/len_zero.rs:135:8 + --> tests/ui/len_zero.rs:148: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 - --> tests/ui/len_zero.rs:138:8 + --> tests/ui/len_zero.rs:152: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 - --> tests/ui/len_zero.rs:149:8 + --> tests/ui/len_zero.rs:164: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 - --> tests/ui/len_zero.rs:152:8 + --> tests/ui/len_zero.rs:168: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 - --> tests/ui/len_zero.rs:155:8 + --> tests/ui/len_zero.rs:172: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 - --> tests/ui/len_zero.rs:158:8 + --> tests/ui/len_zero.rs:176: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 - --> tests/ui/len_zero.rs:161:8 + --> tests/ui/len_zero.rs:180: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 - --> tests/ui/len_zero.rs:175:8 + --> tests/ui/len_zero.rs:195: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 - --> tests/ui/len_zero.rs:187:6 + --> tests/ui/len_zero.rs:208: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 - --> tests/ui/len_zero.rs:188:6 + --> tests/ui/len_zero.rs:210: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 - --> tests/ui/len_zero.rs:192:8 + --> tests/ui/len_zero.rs:215:8 | LL | if b.len() != 0 {} | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:226:8 + --> tests/ui/len_zero.rs:250:8 | LL | if has_is_empty.len() == compare_to!(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:227:8 + --> tests/ui/len_zero.rs:252:8 | LL | if has_is_empty.len() == zero!() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:229:6 + --> tests/ui/len_zero.rs:255:6 | LL | (compare_to!(0) < has_is_empty.len()).then(|| println!("This can happen.")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` diff --git a/tests/ui/len_zero_ranges.fixed b/tests/ui/len_zero_ranges.fixed index 1fdeb2c7a37b..d5b514d98113 100644 --- a/tests/ui/len_zero_ranges.fixed +++ b/tests/ui/len_zero_ranges.fixed @@ -5,10 +5,12 @@ mod issue_3807 { fn suggestion_is_fine_range() { let _ = (0..42).is_empty(); + //~^ len_zero } fn suggestion_is_fine_range_inclusive() { let _ = (0_u8..=42).is_empty(); + //~^ len_zero } } diff --git a/tests/ui/len_zero_ranges.rs b/tests/ui/len_zero_ranges.rs index a5c9a969aaa6..98c97ca02457 100644 --- a/tests/ui/len_zero_ranges.rs +++ b/tests/ui/len_zero_ranges.rs @@ -5,10 +5,12 @@ mod issue_3807 { fn suggestion_is_fine_range() { let _ = (0..42).len() == 0; + //~^ len_zero } fn suggestion_is_fine_range_inclusive() { let _ = (0_u8..=42).len() == 0; + //~^ len_zero } } diff --git a/tests/ui/len_zero_ranges.stderr b/tests/ui/len_zero_ranges.stderr index 0b2991e15ea3..10845bcade47 100644 --- a/tests/ui/len_zero_ranges.stderr +++ b/tests/ui/len_zero_ranges.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..42).len() == 0; = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> tests/ui/len_zero_ranges.rs:11:17 + --> tests/ui/len_zero_ranges.rs:12: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.edition2021.fixed b/tests/ui/let_and_return.edition2021.fixed index c160d5df30fd..83e4a0298a7d 100644 --- a/tests/ui/let_and_return.edition2021.fixed +++ b/tests/ui/let_and_return.edition2021.fixed @@ -11,15 +11,17 @@ 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` + //~^ let_and_return + + } fn test_inner() -> i32 { if true { 5 - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } else { 0 } @@ -82,7 +84,8 @@ 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 + //~^ let_and_return + } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -105,7 +108,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = value.borrow().baz(); ret - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn borrows_in_closure(value: Weak>) -> u32 { @@ -116,7 +119,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = f(|| value.borrow().baz())(); ret - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } mod free_function { @@ -148,14 +151,14 @@ mod no_lint_if_stmt_borrows { let x = Inner {}; let value = some_foo(&x).value(); value - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn test2() -> i32 { let x = Inner {}; let value = Foo::new(&x).value(); value - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } } } @@ -177,7 +180,8 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { (Arc::clone(&self.foo)) as _ - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } } } @@ -196,7 +200,8 @@ mod issue_11335 { E::A(x) => x, E::B(x) => x, }) as _ - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } } } @@ -222,19 +227,22 @@ fn issue12801() { fn left_is_if() -> String { (if true { "a".to_string() } else { "b".to_string() } + "c") - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn no_par_needed() -> String { "c".to_string() + if true { "a" } else { "b" } - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn conjunctive_blocks() -> String { ({ "a".to_string() } + "b" + { "c" } + "d") - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } #[allow(clippy::overly_complex_bool_expr)] @@ -242,12 +250,14 @@ fn issue12801() { let _ = || { (if true { 2 } else { 3 } << 4) - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; let _ = || { ({ true } || { false } && { 2 <= 3 }) - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; } } @@ -259,7 +269,7 @@ fn issue14164() -> Result { None => Ok(Ok(0)), }?; r - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn main() {} diff --git a/tests/ui/let_and_return.edition2021.stderr b/tests/ui/let_and_return.edition2021.stderr index 105fa7a722d7..4302053c7815 100644 --- a/tests/ui/let_and_return.edition2021.stderr +++ b/tests/ui/let_and_return.edition2021.stderr @@ -15,7 +15,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:21:9 + --> tests/ui/let_and_return.rs:22:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -29,7 +29,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:84:5 + --> tests/ui/let_and_return.rs:86:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -43,7 +43,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:179:13 + --> tests/ui/let_and_return.rs:182:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding @@ -57,7 +57,7 @@ LL ~ (Arc::clone(&self.foo)) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:198:13 + --> tests/ui/let_and_return.rs:202:13 | LL | / let result = match self { LL | | E::A(x) => x, @@ -79,7 +79,7 @@ LL + }) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:224:9 + --> tests/ui/let_and_return.rs:229:9 | LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; | ------------------------------------------------------------------- unnecessary `let` binding @@ -93,7 +93,7 @@ LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:230:9 + --> tests/ui/let_and_return.rs:236:9 | LL | let s = "c".to_string() + if true { "a" } else { "b" }; | ------------------------------------------------------- unnecessary `let` binding @@ -107,7 +107,7 @@ LL ~ "c".to_string() + if true { "a" } else { "b" } | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:236:9 + --> tests/ui/let_and_return.rs:243:9 | LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; | -------------------------------------------------- unnecessary `let` binding @@ -121,7 +121,7 @@ LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:244:13 + --> tests/ui/let_and_return.rs:252:13 | LL | let s = if true { 2 } else { 3 } << 4; | -------------------------------------- unnecessary `let` binding @@ -135,7 +135,7 @@ LL ~ (if true { 2 } else { 3 } << 4) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:249:13 + --> tests/ui/let_and_return.rs:258:13 | LL | let s = { true } || { false } && { 2 <= 3 }; | -------------------------------------------- unnecessary `let` binding diff --git a/tests/ui/let_and_return.edition2024.fixed b/tests/ui/let_and_return.edition2024.fixed index f958f70e1dcf..4846d6ada3ca 100644 --- a/tests/ui/let_and_return.edition2024.fixed +++ b/tests/ui/let_and_return.edition2024.fixed @@ -11,15 +11,17 @@ 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` + //~^ let_and_return + + } fn test_inner() -> i32 { if true { 5 - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } else { 0 } @@ -82,7 +84,8 @@ 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 + //~^ let_and_return + } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -105,7 +108,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); value.borrow().baz() - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn borrows_in_closure(value: Weak>) -> u32 { @@ -116,7 +119,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); f(|| value.borrow().baz())() - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } mod free_function { @@ -148,14 +151,14 @@ mod no_lint_if_stmt_borrows { let x = Inner {}; some_foo(&x).value() - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn test2() -> i32 { let x = Inner {}; Foo::new(&x).value() - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } } } @@ -177,7 +180,8 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { (Arc::clone(&self.foo)) as _ - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } } } @@ -196,7 +200,8 @@ mod issue_11335 { E::A(x) => x, E::B(x) => x, }) as _ - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } } } @@ -222,19 +227,22 @@ fn issue12801() { fn left_is_if() -> String { (if true { "a".to_string() } else { "b".to_string() } + "c") - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn no_par_needed() -> String { "c".to_string() + if true { "a" } else { "b" } - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn conjunctive_blocks() -> String { ({ "a".to_string() } + "b" + { "c" } + "d") - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } #[allow(clippy::overly_complex_bool_expr)] @@ -242,12 +250,14 @@ fn issue12801() { let _ = || { (if true { 2 } else { 3 } << 4) - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; let _ = || { ({ true } || { false } && { 2 <= 3 }) - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; } } @@ -259,7 +269,7 @@ fn issue14164() -> Result { Some(v) => Ok(Ok(v[0])), None => Ok(Ok(0)), }? - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn main() {} diff --git a/tests/ui/let_and_return.edition2024.stderr b/tests/ui/let_and_return.edition2024.stderr index ec87e32b582d..4b7f1a019f27 100644 --- a/tests/ui/let_and_return.edition2024.stderr +++ b/tests/ui/let_and_return.edition2024.stderr @@ -15,7 +15,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:21:9 + --> tests/ui/let_and_return.rs:22:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -29,7 +29,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:84:5 + --> tests/ui/let_and_return.rs:86:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -43,7 +43,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:107:9 + --> tests/ui/let_and_return.rs:110:9 | LL | let ret = value.borrow().baz(); | ------------------------------- unnecessary `let` binding @@ -57,7 +57,7 @@ LL ~ value.borrow().baz() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:118:9 + --> tests/ui/let_and_return.rs:121:9 | LL | let ret = f(|| value.borrow().baz())(); | --------------------------------------- unnecessary `let` binding @@ -71,7 +71,7 @@ LL ~ f(|| value.borrow().baz())() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:150:13 + --> tests/ui/let_and_return.rs:153:13 | LL | let value = some_foo(&x).value(); | --------------------------------- unnecessary `let` binding @@ -85,7 +85,7 @@ LL ~ some_foo(&x).value() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:157:13 + --> tests/ui/let_and_return.rs:160:13 | LL | let value = Foo::new(&x).value(); | --------------------------------- unnecessary `let` binding @@ -99,7 +99,7 @@ LL ~ Foo::new(&x).value() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:179:13 + --> tests/ui/let_and_return.rs:182:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding @@ -113,7 +113,7 @@ LL ~ (Arc::clone(&self.foo)) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:198:13 + --> tests/ui/let_and_return.rs:202:13 | LL | / let result = match self { LL | | E::A(x) => x, @@ -135,7 +135,7 @@ LL + }) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:224:9 + --> tests/ui/let_and_return.rs:229:9 | LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; | ------------------------------------------------------------------- unnecessary `let` binding @@ -149,7 +149,7 @@ LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:230:9 + --> tests/ui/let_and_return.rs:236:9 | LL | let s = "c".to_string() + if true { "a" } else { "b" }; | ------------------------------------------------------- unnecessary `let` binding @@ -163,7 +163,7 @@ LL ~ "c".to_string() + if true { "a" } else { "b" } | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:236:9 + --> tests/ui/let_and_return.rs:243:9 | LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; | -------------------------------------------------- unnecessary `let` binding @@ -177,7 +177,7 @@ LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:244:13 + --> tests/ui/let_and_return.rs:252:13 | LL | let s = if true { 2 } else { 3 } << 4; | -------------------------------------- unnecessary `let` binding @@ -191,7 +191,7 @@ LL ~ (if true { 2 } else { 3 } << 4) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:249:13 + --> tests/ui/let_and_return.rs:258:13 | LL | let s = { true } || { false } && { 2 <= 3 }; | -------------------------------------------- unnecessary `let` binding @@ -205,7 +205,7 @@ LL ~ ({ true } || { false } && { 2 <= 3 }) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:261:5 + --> tests/ui/let_and_return.rs:271:5 | LL | / let r = match &*v.borrow() { LL | | Some(v) => Ok(Ok(v[0])), diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 0b7a1e26890f..ab5338837a53 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -11,15 +11,17 @@ 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` + //~^ let_and_return + + } fn test_inner() -> i32 { if true { let x = 5; x - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } else { 0 } @@ -82,7 +84,8 @@ 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 + //~^ let_and_return + } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -105,7 +108,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = value.borrow().baz(); ret - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn borrows_in_closure(value: Weak>) -> u32 { @@ -116,7 +119,7 @@ mod no_lint_if_stmt_borrows { let value = value.upgrade().unwrap(); let ret = f(|| value.borrow().baz())(); ret - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } mod free_function { @@ -148,14 +151,14 @@ mod no_lint_if_stmt_borrows { let x = Inner {}; let value = some_foo(&x).value(); value - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn test2() -> i32 { let x = Inner {}; let value = Foo::new(&x).value(); value - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } } } @@ -177,7 +180,8 @@ 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 + //~^ let_and_return + } } } @@ -196,7 +200,8 @@ mod issue_11335 { }; result - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } } } @@ -222,19 +227,22 @@ fn issue12801() { fn left_is_if() -> String { let s = if true { "a".to_string() } else { "b".to_string() } + "c"; s - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn no_par_needed() -> String { let s = "c".to_string() + if true { "a" } else { "b" }; s - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } fn conjunctive_blocks() -> String { let s = { "a".to_string() } + "b" + { "c" } + "d"; s - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + } #[allow(clippy::overly_complex_bool_expr)] @@ -242,12 +250,14 @@ fn issue12801() { let _ = || { let s = if true { 2 } else { 3 } << 4; s - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; let _ = || { let s = { true } || { false } && { 2 <= 3 }; s - //~^ ERROR: returning the result of a `let` binding from a block + //~^ let_and_return + }; } } @@ -259,7 +269,7 @@ fn issue14164() -> Result { None => Ok(Ok(0)), }?; r - //~[edition2024]^ ERROR: returning the result of a `let` binding from a block + //~[edition2024]^ let_and_return } fn main() {} diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index a29d35880b8d..cc482155eda7 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -75,15 +75,17 @@ fn main() { issue985_alt(); let mut foo = 0; - //~^ ERROR: `if _ { .. } else { .. }` is an expression - //~| NOTE: you might not need `mut` at all + //~^ useless_let_if_seq + + if f() { foo = 42; } let mut bar = 0; - //~^ ERROR: `if _ { .. } else { .. }` is an expression - //~| NOTE: you might not need `mut` at all + //~^ useless_let_if_seq + + if f() { f(); bar = 42; @@ -92,7 +94,8 @@ fn main() { } let quz; - //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~^ useless_let_if_seq + if f() { quz = 42; } else { @@ -122,8 +125,9 @@ 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 + //~^ useless_let_if_seq + + if f() { baz = 42; } diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index 41930108fb1a..b63a31b99129 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -2,9 +2,7 @@ error: `if _ { .. } else { .. }` is an expression --> tests/ui/let_if_seq.rs:77:5 | LL | / let mut foo = 0; -LL | | -LL | | -LL | | if f() { +... | LL | | foo = 42; LL | | } | |_____^ help: it is more idiomatic to write: `let foo = if f() { 42 } else { 0 };` @@ -14,12 +12,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:84:5 + --> tests/ui/let_if_seq.rs:85:5 | LL | / let mut bar = 0; -LL | | -LL | | -LL | | if f() { ... | LL | | f(); LL | | } @@ -28,24 +23,22 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:94:5 + --> tests/ui/let_if_seq.rs:96:5 | LL | / let quz; LL | | +LL | | LL | | if f() { -LL | | quz = 42; -LL | | } else { +... | LL | | quz = 0; LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:124:5 + --> tests/ui/let_if_seq.rs:127:5 | LL | / let mut baz = 0; -LL | | -LL | | -LL | | if f() { +... | LL | | baz = 42; LL | | } | |_____^ help: it is more idiomatic to write: `let baz = if f() { 42 } else { 0 };` diff --git a/tests/ui/let_underscore_future.rs b/tests/ui/let_underscore_future.rs index c2185e9785d8..2d57e83fd54d 100644 --- a/tests/ui/let_underscore_future.rs +++ b/tests/ui/let_underscore_future.rs @@ -12,12 +12,15 @@ fn do_something_to_future(future: &mut impl Future) {} fn main() { let _ = some_async_fn(); - //~^ ERROR: non-binding `let` on a future + //~^ let_underscore_future + let _ = custom(); - //~^ ERROR: non-binding `let` on a future + //~^ let_underscore_future + let mut future = some_async_fn(); do_something_to_future(&mut future); let _ = future; - //~^ ERROR: non-binding `let` on a future + //~^ let_underscore_future + } diff --git a/tests/ui/let_underscore_future.stderr b/tests/ui/let_underscore_future.stderr index 66aeb5035394..e59e1f68911a 100644 --- a/tests/ui/let_underscore_future.stderr +++ b/tests/ui/let_underscore_future.stderr @@ -9,7 +9,7 @@ LL | let _ = some_async_fn(); = help: to override `-D warnings` add `#[allow(clippy::let_underscore_future)]` error: non-binding `let` on a future - --> tests/ui/let_underscore_future.rs:16:5 + --> tests/ui/let_underscore_future.rs:17:5 | LL | let _ = custom(); | ^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = custom(); = help: consider awaiting the future or dropping explicitly with `std::mem::drop` error: non-binding `let` on a future - --> tests/ui/let_underscore_future.rs:21:5 + --> tests/ui/let_underscore_future.rs:23:5 | LL | let _ = future; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 3290d087724e..730e586eea79 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -65,42 +65,54 @@ impl Trait for S { fn main() { let _ = f(); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let _ = g(); - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + let _ = h(); let _ = l(0_u32); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let s = S {}; let _ = s.f(); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let _ = s.g(); - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + let _ = s.k(); let _ = S::h(); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let _ = S::p(); - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + let _ = S::a(); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let _ = if true { Ok(()) } else { Err(()) }; - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); - //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function + //~^ let_underscore_must_use + let _ = a.map(|_| ()); - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + let _ = a; - //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type + //~^ let_underscore_must_use + #[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 e8785b92b815..fda2a2b2adaa 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -9,7 +9,7 @@ LL | let _ = f(); = help: to override `-D warnings` add `#[allow(clippy::let_underscore_must_use)]` error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:69:5 + --> tests/ui/let_underscore_must_use.rs:70:5 | LL | let _ = g(); | ^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:72:5 + --> tests/ui/let_underscore_must_use.rs:74:5 | LL | let _ = l(0_u32); | ^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = l(0_u32); = help: consider explicitly using function result error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:77:5 + --> tests/ui/let_underscore_must_use.rs:80:5 | LL | let _ = s.f(); | ^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = s.f(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:79:5 + --> tests/ui/let_underscore_must_use.rs:83:5 | LL | let _ = s.g(); | ^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = s.g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:83:5 + --> tests/ui/let_underscore_must_use.rs:88:5 | LL | let _ = S::h(); | ^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = S::h(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:85:5 + --> tests/ui/let_underscore_must_use.rs:91:5 | LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = S::p(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:88:5 + --> tests/ui/let_underscore_must_use.rs:95:5 | LL | let _ = S::a(); | ^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = S::a(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:91:5 + --> tests/ui/let_underscore_must_use.rs:99:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/let_underscore_must_use.rs:96:5 + --> tests/ui/let_underscore_must_use.rs:105:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:99:5 + --> tests/ui/let_underscore_must_use.rs:109:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = a.map(|_| ()); = help: consider explicitly using expression value error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:102:5 + --> tests/ui/let_underscore_must_use.rs:113:5 | LL | let _ = a; | ^^^^^^^^^^ diff --git a/tests/ui/let_underscore_untyped.rs b/tests/ui/let_underscore_untyped.rs index 6275b6f970a1..26ba8682dc2d 100644 --- a/tests/ui/let_underscore_untyped.rs +++ b/tests/ui/let_underscore_untyped.rs @@ -49,11 +49,16 @@ with_span!( fn main() { let _ = a(); + //~^ let_underscore_untyped let _ = b(1); + //~^ let_underscore_untyped let _ = c(); let _ = d(&1); + //~^ let_underscore_untyped let _ = e(); + //~^ let_underscore_untyped let _ = f(); + //~^ let_underscore_untyped let _ = g(); let closure = || {}; diff --git a/tests/ui/let_underscore_untyped.stderr b/tests/ui/let_underscore_untyped.stderr index 1dd51e1e59b1..86cdd5c662cc 100644 --- a/tests/ui/let_underscore_untyped.stderr +++ b/tests/ui/let_underscore_untyped.stderr @@ -13,49 +13,49 @@ LL | let _ = a(); = help: to override `-D warnings` add `#[allow(clippy::let_underscore_untyped)]` error: non-binding `let` without a type annotation - --> tests/ui/let_underscore_untyped.rs:52:5 + --> tests/ui/let_underscore_untyped.rs:53:5 | LL | let _ = b(1); | ^^^^^^^^^^^^^ | help: consider adding a type annotation - --> tests/ui/let_underscore_untyped.rs:52:10 + --> tests/ui/let_underscore_untyped.rs:53:10 | LL | let _ = b(1); | ^ error: non-binding `let` without a type annotation - --> tests/ui/let_underscore_untyped.rs:54:5 + --> tests/ui/let_underscore_untyped.rs:56:5 | LL | let _ = d(&1); | ^^^^^^^^^^^^^^ | help: consider adding a type annotation - --> tests/ui/let_underscore_untyped.rs:54:10 + --> tests/ui/let_underscore_untyped.rs:56:10 | LL | let _ = d(&1); | ^ error: non-binding `let` without a type annotation - --> tests/ui/let_underscore_untyped.rs:55:5 + --> tests/ui/let_underscore_untyped.rs:58:5 | LL | let _ = e(); | ^^^^^^^^^^^^ | help: consider adding a type annotation - --> tests/ui/let_underscore_untyped.rs:55:10 + --> tests/ui/let_underscore_untyped.rs:58:10 | LL | let _ = e(); | ^ error: non-binding `let` without a type annotation - --> tests/ui/let_underscore_untyped.rs:56:5 + --> tests/ui/let_underscore_untyped.rs:60:5 | LL | let _ = f(); | ^^^^^^^^^^^^ | help: consider adding a type annotation - --> tests/ui/let_underscore_untyped.rs:56:10 + --> tests/ui/let_underscore_untyped.rs:60:10 | LL | let _ = f(); | ^ diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 3456e274f6a4..23145bd132f5 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -9,6 +9,7 @@ macro_rules! let_and_return { fn main() { println!("x"); + //~^ let_unit_value let _y = 1; // this is fine let _z = ((), 1); // this as well if true { @@ -57,6 +58,7 @@ fn multiline_sugg() { let v: Vec = vec![2]; v + //~^ let_unit_value .into_iter() .map(|i| i * 2) .filter(|i| i % 2 == 0) @@ -106,6 +108,7 @@ fn _returns_generic() { let x: () = if true { f() } else { f2(0) }; match Some(0) { + //~^ let_unit_value None => f2(1), Some(0) => f(), Some(1) => f2(3), @@ -187,6 +190,7 @@ pub fn issue12594() { fn actual_test() { // create first a unit value'd value returns_unit(); + //~^ let_unit_value returns_result(()).unwrap(); returns_result(()).unwrap(); // make sure we replace only the first variable diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index e2dafbcb7714..59800b553a8c 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -9,6 +9,7 @@ macro_rules! let_and_return { fn main() { let _x = println!("x"); + //~^ let_unit_value let _y = 1; // this is fine let _z = ((), 1); // this as well if true { @@ -57,6 +58,7 @@ fn multiline_sugg() { let v: Vec = vec![2]; let _ = v + //~^ let_unit_value .into_iter() .map(|i| i * 2) .filter(|i| i % 2 == 0) @@ -106,6 +108,7 @@ fn _returns_generic() { let x: () = if true { f() } else { f2(0) }; let x = match Some(0) { + //~^ let_unit_value None => f2(1), Some(0) => f(), Some(1) => f2(3), @@ -187,6 +190,7 @@ pub fn issue12594() { fn actual_test() { // create first a unit value'd value let res = returns_unit(); + //~^ let_unit_value returns_result(res).unwrap(); returns_result(res).unwrap(); // make sure we replace only the first variable diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index a2f368f22e5b..d7d01d304cad 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -8,13 +8,13 @@ LL | let _x = println!("x"); = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: this let-binding has unit value - --> tests/ui/let_unit.rs:59:5 + --> tests/ui/let_unit.rs:60:5 | LL | / let _ = v +LL | | LL | | .into_iter() LL | | .map(|i| i * 2) -LL | | .filter(|i| i % 2 == 0) -LL | | .map(|_| ()) +... | LL | | .next() LL | | .unwrap(); | |__________________^ @@ -22,6 +22,7 @@ LL | | .unwrap(); help: omit the `let` binding | LL ~ v +LL + LL + .into_iter() LL + .map(|i| i * 2) LL + .filter(|i| i % 2 == 0) @@ -31,9 +32,10 @@ LL + .unwrap(); | error: this let-binding has unit value - --> tests/ui/let_unit.rs:108:5 + --> tests/ui/let_unit.rs:110:5 | LL | / let x = match Some(0) { +LL | | LL | | None => f2(1), LL | | Some(0) => f(), LL | | Some(1) => f2(3), @@ -44,6 +46,7 @@ LL | | }; help: omit the `let` binding | LL ~ match Some(0) { +LL + LL + None => f2(1), LL + Some(0) => f(), LL + Some(1) => f2(3), @@ -52,7 +55,7 @@ LL + }; | error: this let-binding has unit value - --> tests/ui/let_unit.rs:189:9 + --> tests/ui/let_unit.rs:192:9 | LL | let res = returns_unit(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,6 +63,7 @@ LL | let res = returns_unit(); help: omit the `let` binding and replace variable usages with `()` | LL ~ returns_unit(); +LL | LL ~ returns_result(()).unwrap(); LL ~ returns_result(()).unwrap(); | diff --git a/tests/ui/let_with_type_underscore.rs b/tests/ui/let_with_type_underscore.rs index ae1a480bcfc5..a7c2f598b56d 100644 --- a/tests/ui/let_with_type_underscore.rs +++ b/tests/ui/let_with_type_underscore.rs @@ -13,9 +13,13 @@ fn func() -> &'static str { fn main() { // Will lint let x: _ = 1; + //~^ let_with_type_underscore let _: _ = 2; + //~^ let_with_type_underscore let x: _ = func(); + //~^ let_with_type_underscore let x: _; + //~^ let_with_type_underscore x = (); let x = 1; // Will not lint, Rust infers this to an integer before Clippy @@ -23,6 +27,7 @@ fn main() { let x: Vec<_> = Vec::::new(); let x: [_; 1] = [1]; let x : _ = 1; + //~^ let_with_type_underscore // Do not lint from procedural macros proc_macros::with_span! { diff --git a/tests/ui/let_with_type_underscore.stderr b/tests/ui/let_with_type_underscore.stderr index 29ec25a5b2ac..2284d1fe2e48 100644 --- a/tests/ui/let_with_type_underscore.stderr +++ b/tests/ui/let_with_type_underscore.stderr @@ -13,49 +13,49 @@ LL | let x: _ = 1; = help: to override `-D warnings` add `#[allow(clippy::let_with_type_underscore)]` error: variable declared with type underscore - --> tests/ui/let_with_type_underscore.rs:16:5 + --> tests/ui/let_with_type_underscore.rs:17:5 | LL | let _: _ = 2; | ^^^^^^^^^^^^^ | help: remove the explicit type `_` declaration - --> tests/ui/let_with_type_underscore.rs:16:10 + --> tests/ui/let_with_type_underscore.rs:17:10 | LL | let _: _ = 2; | ^^^ error: variable declared with type underscore - --> tests/ui/let_with_type_underscore.rs:17:5 + --> tests/ui/let_with_type_underscore.rs:19:5 | LL | let x: _ = func(); | ^^^^^^^^^^^^^^^^^^ | help: remove the explicit type `_` declaration - --> tests/ui/let_with_type_underscore.rs:17:10 + --> tests/ui/let_with_type_underscore.rs:19:10 | LL | let x: _ = func(); | ^^^ error: variable declared with type underscore - --> tests/ui/let_with_type_underscore.rs:18:5 + --> tests/ui/let_with_type_underscore.rs:21:5 | LL | let x: _; | ^^^^^^^^^ | help: remove the explicit type `_` declaration - --> tests/ui/let_with_type_underscore.rs:18:10 + --> tests/ui/let_with_type_underscore.rs:21:10 | LL | let x: _; | ^^^ error: variable declared with type underscore - --> tests/ui/let_with_type_underscore.rs:25:5 + --> tests/ui/let_with_type_underscore.rs:29:5 | LL | let x : _ = 1; | ^^^^^^^^^^^^^^ | help: remove the explicit type `_` declaration - --> tests/ui/let_with_type_underscore.rs:25:10 + --> tests/ui/let_with_type_underscore.rs:29:10 | LL | let x : _ = 1; | ^^^^ diff --git a/tests/ui/lines_filter_map_ok.fixed b/tests/ui/lines_filter_map_ok.fixed index ae388ec39a15..977e31c744a2 100644 --- a/tests/ui/lines_filter_map_ok.fixed +++ b/tests/ui/lines_filter_map_ok.fixed @@ -7,20 +7,26 @@ fn main() -> io::Result<()> { let f = std::fs::File::open("/")?; // Lint BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok let s = "foo\nbar\nbaz\n"; // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().map_while(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Do not lint (not a `Lines` iterator) io::stdin() .lines() diff --git a/tests/ui/lines_filter_map_ok.rs b/tests/ui/lines_filter_map_ok.rs index 4f486534e9b0..2196075bc445 100644 --- a/tests/ui/lines_filter_map_ok.rs +++ b/tests/ui/lines_filter_map_ok.rs @@ -7,20 +7,26 @@ fn main() -> io::Result<()> { let f = std::fs::File::open("/")?; // Lint BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint let f = std::fs::File::open("/")?; BufReader::new(f).lines().flatten().for_each(|_| ()); + //~^ lines_filter_map_ok let s = "foo\nbar\nbaz\n"; // Lint io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); + //~^ lines_filter_map_ok // Lint io::stdin().lines().flatten().for_each(|_| ()); + //~^ lines_filter_map_ok // Do not lint (not a `Lines` iterator) io::stdin() .lines() diff --git a/tests/ui/lines_filter_map_ok.stderr b/tests/ui/lines_filter_map_ok.stderr index 558c0532be95..f9038eec9fb2 100644 --- a/tests/ui/lines_filter_map_ok.stderr +++ b/tests/ui/lines_filter_map_ok.stderr @@ -13,61 +13,61 @@ LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); = help: to override `-D warnings` add `#[allow(clippy::lines_filter_map_ok)]` error: `flat_map()` will run forever if the iterator repeatedly produces an `Err` - --> tests/ui/lines_filter_map_ok.rs:12:31 + --> tests/ui/lines_filter_map_ok.rs:13: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 - --> tests/ui/lines_filter_map_ok.rs:12:5 + --> tests/ui/lines_filter_map_ok.rs:13:5 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `flatten()` will run forever if the iterator repeatedly produces an `Err` - --> tests/ui/lines_filter_map_ok.rs:15:31 + --> tests/ui/lines_filter_map_ok.rs:17:31 | LL | BufReader::new(f).lines().flatten().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 - --> tests/ui/lines_filter_map_ok.rs:15:5 + --> tests/ui/lines_filter_map_ok.rs:17:5 | LL | BufReader::new(f).lines().flatten().for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> tests/ui/lines_filter_map_ok.rs:19:25 + --> tests/ui/lines_filter_map_ok.rs:22: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 - --> tests/ui/lines_filter_map_ok.rs:19:5 + --> tests/ui/lines_filter_map_ok.rs:22:5 | LL | io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> tests/ui/lines_filter_map_ok.rs:21:25 + --> tests/ui/lines_filter_map_ok.rs:25: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 - --> tests/ui/lines_filter_map_ok.rs:21:5 + --> tests/ui/lines_filter_map_ok.rs:25:5 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ error: `flatten()` will run forever if the iterator repeatedly produces an `Err` - --> tests/ui/lines_filter_map_ok.rs:23:25 + --> tests/ui/lines_filter_map_ok.rs:28:25 | LL | io::stdin().lines().flatten().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 - --> tests/ui/lines_filter_map_ok.rs:23:5 + --> tests/ui/lines_filter_map_ok.rs:28:5 | LL | io::stdin().lines().flatten().for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/linkedlist.rs b/tests/ui/linkedlist.rs index e1e6cff98097..eddbe730c174 100644 --- a/tests/ui/linkedlist.rs +++ b/tests/ui/linkedlist.rs @@ -6,17 +6,22 @@ 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 +//~^ linkedlist + static S: LinkedList = LinkedList::new(); -//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu +//~^ linkedlist + trait Foo { type Baz = LinkedList; - //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str + //~^ linkedlist + fn foo(_: LinkedList); - //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str + //~^ linkedlist + const BAR: Option>; - //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str + //~^ linkedlist + } // Ok, we don’t want to warn for implementations; see issue #605. @@ -27,20 +32,24 @@ 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 + //~^ linkedlist + 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 + //~^ linkedlist + } // 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 +//~^ linkedlist + fn test_ret() -> Option> { - //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu +//~^ linkedlist + None } fn test_local_not_linted() { diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index d19176c7b0d2..22382d49e3a4 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -9,7 +9,7 @@ LL | const C: LinkedList = LinkedList::new(); = help: to override `-D warnings` add `#[allow(clippy::linkedlist)]` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> tests/ui/linkedlist.rs:10:11 + --> tests/ui/linkedlist.rs:11:11 | LL | static S: LinkedList = LinkedList::new(); | ^^^^^^^^^^^^^^^ @@ -17,7 +17,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? - --> tests/ui/linkedlist.rs:14:16 + --> tests/ui/linkedlist.rs:16:16 | LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ @@ -25,7 +25,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? - --> tests/ui/linkedlist.rs:16:15 + --> tests/ui/linkedlist.rs:19:15 | LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ @@ -33,7 +33,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? - --> tests/ui/linkedlist.rs:18:23 + --> tests/ui/linkedlist.rs:22:23 | LL | const BAR: Option>; | ^^^^^^^^^^^^^^ @@ -41,7 +41,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? - --> tests/ui/linkedlist.rs:29:29 + --> tests/ui/linkedlist.rs:34:29 | LL | priv_linked_list_field: LinkedList, | ^^^^^^^^^^^^^^ @@ -49,7 +49,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? - --> tests/ui/linkedlist.rs:34:15 + --> tests/ui/linkedlist.rs:40:15 | LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -57,7 +57,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? - --> tests/ui/linkedlist.rs:40:34 + --> tests/ui/linkedlist.rs:47:34 | LL | fn test(my_favorite_linked_list: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -65,7 +65,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? - --> tests/ui/linkedlist.rs:42:25 + --> tests/ui/linkedlist.rs:50:25 | LL | fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/literal_string_with_formatting_arg.rs b/tests/ui/literal_string_with_formatting_arg.rs index b9a6654d4276..b6f865b1ef28 100644 --- a/tests/ui/literal_string_with_formatting_arg.rs +++ b/tests/ui/literal_string_with_formatting_arg.rs @@ -40,7 +40,8 @@ fn main() { x.expect(r##" {y:?} {y:?} "##); //~ literal_string_with_formatting_args assert!("{y}".is_ascii()); //~ literal_string_with_formatting_args // Ensure that it doesn't try to go in the middle of a unicode character. - x.expect("———{:?}"); //~ literal_string_with_formatting_args + x.expect("———{:?}"); + //~^ literal_string_with_formatting_args // Should not lint! format!("{y:?}"); @@ -51,6 +52,7 @@ fn main() { x.expect("{{y:?}"); x.expect(" {0}"); // If it only contains an integer, we ignore it. x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint + //~^ literal_string_with_formatting_args x.expect("{y:...}"); let _ = "fn main {\n\ }"; diff --git a/tests/ui/literal_string_with_formatting_arg.stderr b/tests/ui/literal_string_with_formatting_arg.stderr index 021983056bf6..55425d01c587 100644 --- a/tests/ui/literal_string_with_formatting_arg.stderr +++ b/tests/ui/literal_string_with_formatting_arg.stderr @@ -74,7 +74,7 @@ LL | x.expect("———{:?}"); | ^^^^ error: this looks like a formatting argument but it is not part of a formatting macro - --> tests/ui/literal_string_with_formatting_arg.rs:53:19 + --> tests/ui/literal_string_with_formatting_arg.rs:54:19 | LL | x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint | ^^^^^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index c275b04d886b..300a2d7802dd 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -11,32 +11,44 @@ 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` + //~^ separated_literal_suffix + + let ok5 = 0xAB_CD_u32; - //~^ ERROR: integer type suffix should not be separated by an underscore + //~^ separated_literal_suffix + let ok5 = 0xAB_CD_isize; - //~^ ERROR: integer type suffix should not be separated by an underscore + //~^ separated_literal_suffix + let fail1 = 0xabCD; - //~^ ERROR: inconsistent casing in hexadecimal literal - //~| NOTE: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` + //~^ mixed_case_hex_literals + + let fail2 = 0xabCD_u32; - //~^ ERROR: integer type suffix should not be separated by an underscore - //~| ERROR: inconsistent casing in hexadecimal literal + //~^ separated_literal_suffix + //~| mixed_case_hex_literals + + let fail2 = 0xabCD_isize; - //~^ ERROR: integer type suffix should not be separated by an underscore - //~| ERROR: inconsistent casing in hexadecimal literal + //~^ separated_literal_suffix + //~| mixed_case_hex_literals + + 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` + //~^ unseparated_literal_suffix + //~| zero_prefixed_literal + + + + let ok9 = 0; let ok10 = 0_i64; - //~^ ERROR: integer type suffix should not be separated by an underscore + //~^ separated_literal_suffix + let fail8 = 0123; - //~^ ERROR: this is a decimal constant + //~^ zero_prefixed_literal + let ok11 = 0o123; let ok12 = 0b10_1010; @@ -46,20 +58,25 @@ 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 + //~^ separated_literal_suffix + let ok18 = 0xF; let fail19 = 12_3456_21; - //~^ ERROR: digits grouped inconsistently by underscores - //~| NOTE: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + //~^ inconsistent_digit_grouping + + let fail22 = 3__4___23; - //~^ ERROR: digits grouped inconsistently by underscores + //~^ inconsistent_digit_grouping + let fail23 = 3__16___23; - //~^ ERROR: digits grouped inconsistently by underscores + //~^ inconsistent_digit_grouping + 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` + //~^ unusual_byte_groupings + + let fail25 = 0b01_100_101; let ok26 = 0x6_A0_BF; let ok27 = 0b1_0010_0101; @@ -68,9 +85,12 @@ fn main() { fn issue9651() { // lint but octal form is not possible here let _ = 08; - //~^ ERROR: this is a decimal constant + //~^ zero_prefixed_literal + let _ = 09; - //~^ ERROR: this is a decimal constant + //~^ zero_prefixed_literal + let _ = 089; - //~^ ERROR: this is a decimal constant + //~^ zero_prefixed_literal + } diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 564e0bc4f747..1e19af071f82 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -8,19 +8,19 @@ LL | let ok4 = 0xab_cd_i32; = help: to override `-D warnings` add `#[allow(clippy::separated_literal_suffix)]` error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:16:15 + --> tests/ui/literals.rs:17:15 | LL | let ok5 = 0xAB_CD_u32; | ^^^^^^^^^^^ help: remove the underscore: `0xAB_CDu32` error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:18:15 + --> tests/ui/literals.rs:20:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:20:17 + --> tests/ui/literals.rs:23:17 | LL | let fail1 = 0xabCD; | ^^^^^^ @@ -29,31 +29,31 @@ LL | let fail1 = 0xabCD; = help: to override `-D warnings` add `#[allow(clippy::mixed_case_hex_literals)]` error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:23:17 + --> tests/ui/literals.rs:27:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:23:17 + --> tests/ui/literals.rs:27:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:26:17 + --> tests/ui/literals.rs:32:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:26:17 + --> tests/ui/literals.rs:32:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> tests/ui/literals.rs:29:27 + --> tests/ui/literals.rs:37:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` @@ -62,7 +62,7 @@ LL | let fail_multi_zero = 000_123usize; = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: this is a decimal constant - --> tests/ui/literals.rs:29:27 + --> tests/ui/literals.rs:37:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ @@ -79,13 +79,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:36:16 + --> tests/ui/literals.rs:46:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> tests/ui/literals.rs:38:17 + --> tests/ui/literals.rs:49:17 | LL | let fail8 = 0123; | ^^^^ @@ -100,13 +100,13 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:48:16 + --> tests/ui/literals.rs:60:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:52:18 + --> tests/ui/literals.rs:65:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` @@ -115,19 +115,19 @@ LL | let fail19 = 12_3456_21; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:55:18 + --> tests/ui/literals.rs:69:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:57:18 + --> tests/ui/literals.rs:72: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 - --> tests/ui/literals.rs:60:18 + --> tests/ui/literals.rs:76:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` @@ -136,7 +136,7 @@ LL | let fail24 = 0xAB_ABC_AB; = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: this is a decimal constant - --> tests/ui/literals.rs:70:13 + --> tests/ui/literals.rs:87:13 | LL | let _ = 08; | ^^ @@ -147,7 +147,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> tests/ui/literals.rs:72:13 + --> tests/ui/literals.rs:90:13 | LL | let _ = 09; | ^^ @@ -158,7 +158,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> tests/ui/literals.rs:74:13 + --> tests/ui/literals.rs:93:13 | LL | let _ = 089; | ^^^ diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed index cc8c0b4a0d17..925a1465cc30 100644 --- a/tests/ui/lossy_float_literal.fixed +++ b/tests/ui/lossy_float_literal.fixed @@ -12,17 +12,28 @@ fn main() { let _: f16 = -4_097.0; let _: f32 = 16_777_216.0; + //~^ lossy_float_literal let _: f32 = 16_777_220.0; + //~^ lossy_float_literal let _: f32 = 16_777_220.0; + //~^ lossy_float_literal let _: f32 = 16_777_220.0; + //~^ lossy_float_literal let _ = 16_777_220_f32; + //~^ lossy_float_literal let _: f32 = -16_777_220.0; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_992.0; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_992.0; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_992.0; + //~^ lossy_float_literal let _ = 9_007_199_254_740_992_f64; + //~^ lossy_float_literal let _: f64 = -9_007_199_254_740_992.0; + //~^ lossy_float_literal let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.0; let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.; diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs index c84eef396d58..7341388d4816 100644 --- a/tests/ui/lossy_float_literal.rs +++ b/tests/ui/lossy_float_literal.rs @@ -12,17 +12,28 @@ fn main() { let _: f16 = -4_097.0; let _: f32 = 16_777_217.0; + //~^ lossy_float_literal let _: f32 = 16_777_219.0; + //~^ lossy_float_literal let _: f32 = 16_777_219.; + //~^ lossy_float_literal let _: f32 = 16_777_219.000; + //~^ lossy_float_literal let _ = 16_777_219f32; + //~^ lossy_float_literal let _: f32 = -16_777_219.0; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_993.0; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_993.; + //~^ lossy_float_literal let _: f64 = 9_007_199_254_740_993.00; + //~^ lossy_float_literal let _ = 9_007_199_254_740_993f64; + //~^ lossy_float_literal let _: f64 = -9_007_199_254_740_993.0; + //~^ lossy_float_literal let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.0; let _: f128 = 10_384_593_717_069_655_257_060_992_658_440_193.; diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index 3026854e317a..a83f9a7aa241 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -12,7 +12,7 @@ LL | let _: f32 = 16_777_216.0; | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:15:18 + --> tests/ui/lossy_float_literal.rs:16:18 | LL | let _: f32 = 16_777_219.0; | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _: f32 = 16_777_220.0; | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:16:18 + --> tests/ui/lossy_float_literal.rs:18:18 | LL | let _: f32 = 16_777_219.; | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _: f32 = 16_777_220.0; | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:17:18 + --> tests/ui/lossy_float_literal.rs:20:18 | LL | let _: f32 = 16_777_219.000; | ^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _: f32 = 16_777_220.0; | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:18:13 + --> tests/ui/lossy_float_literal.rs:22:13 | LL | let _ = 16_777_219f32; | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = 16_777_220_f32; | ~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:19:19 + --> tests/ui/lossy_float_literal.rs:24:19 | LL | let _: f32 = -16_777_219.0; | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _: f32 = -16_777_220.0; | ~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:21:18 + --> tests/ui/lossy_float_literal.rs:27:18 | LL | let _: f64 = 9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: f64 = 9_007_199_254_740_992.0; | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:22:18 + --> tests/ui/lossy_float_literal.rs:29:18 | LL | let _: f64 = 9_007_199_254_740_993.; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: f64 = 9_007_199_254_740_992.0; | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:23:18 + --> tests/ui/lossy_float_literal.rs:31:18 | LL | let _: f64 = 9_007_199_254_740_993.00; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _: f64 = 9_007_199_254_740_992.0; | ~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:24:13 + --> tests/ui/lossy_float_literal.rs:33:13 | LL | let _ = 9_007_199_254_740_993f64; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _ = 9_007_199_254_740_992_f64; | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:25:19 + --> tests/ui/lossy_float_literal.rs:35:19 | LL | let _: f64 = -9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 28844fab7479..d12222fce3eb 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -16,12 +16,16 @@ extern crate proc_macro_derive as mini_mac; mod a { use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; + //~^ macro_use_imports use mac; use mini_mac::ClippyMiniMacroTest; + //~^ macro_use_imports use mini_mac; use mac::{inner::mut_mut, inner::try_err}; + //~^ macro_use_imports use mac::inner; use mac::inner::nested::string_add; + //~^ macro_use_imports use mac::inner::nested; #[derive(ClippyMiniMacroTest)] diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index 5381f2959898..3baa9f8b5e59 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -16,12 +16,16 @@ extern crate proc_macro_derive as mini_mac; mod a { #[macro_use] + //~^ macro_use_imports use mac; #[macro_use] + //~^ macro_use_imports use mini_mac; #[macro_use] + //~^ macro_use_imports use mac::inner; #[macro_use] + //~^ macro_use_imports use mac::inner::nested; #[derive(ClippyMiniMacroTest)] diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index ea0670d36667..cdef5bc79e0c 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -8,19 +8,19 @@ LL | #[macro_use] = help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:22:5 + --> tests/ui/macro_use_imports.rs:24:5 | LL | #[macro_use] | ^^^^^^^^^^^^ 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 - --> tests/ui/macro_use_imports.rs:24:5 + --> tests/ui/macro_use_imports.rs:27:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> tests/ui/macro_use_imports.rs:20:5 + --> tests/ui/macro_use_imports.rs:21:5 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` diff --git a/tests/ui/macro_use_imports_expect.rs b/tests/ui/macro_use_imports_expect.rs index 60cce1d24a28..115b30d3877f 100644 --- a/tests/ui/macro_use_imports_expect.rs +++ b/tests/ui/macro_use_imports_expect.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs //@aux-build:proc_macro_derive.rs diff --git a/tests/ui/manual_arithmetic_check-2.rs b/tests/ui/manual_arithmetic_check-2.rs index e97e3bdfef76..51515e7d9dcf 100644 --- a/tests/ui/manual_arithmetic_check-2.rs +++ b/tests/ui/manual_arithmetic_check-2.rs @@ -7,18 +7,24 @@ fn main() { let b = 13u32; let result = if a > b { b - a } else { 0 }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let result = if b < a { b - a } else { 0 }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let result = if a > b { 0 } else { a - b }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let result = if a >= b { 0 } else { a - b }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let result = if b < a { 0 } else { a - b }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let result = if b <= a { 0 } else { a - b }; - //~^ ERROR: inverted arithmetic check before subtraction + //~^ inverted_saturating_sub + let af = 12f32; let bf = 13f32; diff --git a/tests/ui/manual_arithmetic_check-2.stderr b/tests/ui/manual_arithmetic_check-2.stderr index 4121aa7464f0..3d51a8be670c 100644 --- a/tests/ui/manual_arithmetic_check-2.stderr +++ b/tests/ui/manual_arithmetic_check-2.stderr @@ -12,61 +12,61 @@ LL | let result = if a > b { b - a } else { 0 }; = note: `#[deny(clippy::inverted_saturating_sub)]` on by default error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:11:23 + --> tests/ui/manual_arithmetic_check-2.rs:12:23 | LL | let result = if b < a { b - a } else { 0 }; | ^ ----- help: try replacing it with: `a - b` | note: this subtraction underflows when `b < a` - --> tests/ui/manual_arithmetic_check-2.rs:11:29 + --> tests/ui/manual_arithmetic_check-2.rs:12:29 | LL | let result = if b < a { b - a } else { 0 }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:14:23 + --> tests/ui/manual_arithmetic_check-2.rs:16:23 | LL | let result = if a > b { 0 } else { a - b }; | ^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:14:40 + --> tests/ui/manual_arithmetic_check-2.rs:16:40 | LL | let result = if a > b { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:16:23 + --> tests/ui/manual_arithmetic_check-2.rs:19:23 | LL | let result = if a >= b { 0 } else { a - b }; | ^^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:16:41 + --> tests/ui/manual_arithmetic_check-2.rs:19:41 | LL | let result = if a >= b { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:18:23 + --> tests/ui/manual_arithmetic_check-2.rs:22:23 | LL | let result = if b < a { 0 } else { a - b }; | ^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:18:40 + --> tests/ui/manual_arithmetic_check-2.rs:22:40 | LL | let result = if b < a { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:20:23 + --> tests/ui/manual_arithmetic_check-2.rs:25:23 | LL | let result = if b <= a { 0 } else { a - b }; | ^^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:20:41 + --> tests/ui/manual_arithmetic_check-2.rs:25:41 | LL | let result = if b <= a { 0 } else { a - b }; | ^^^^^ diff --git a/tests/ui/manual_arithmetic_check.fixed b/tests/ui/manual_arithmetic_check.fixed index 29ecbb9ad2ad..5bda101c7b7c 100644 --- a/tests/ui/manual_arithmetic_check.fixed +++ b/tests/ui/manual_arithmetic_check.fixed @@ -7,14 +7,18 @@ fn main() { let c = 8u32; let result = a.saturating_sub(b); - //~^ ERROR: manual arithmetic check found - let result = a.saturating_sub(b); - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub let result = a.saturating_sub(b); - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + + let result = a.saturating_sub(b); - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + + let result = a.saturating_sub(b); + //~^ implicit_saturating_sub + // Should not warn! let result = if a > b { a - b } else { a - c }; diff --git a/tests/ui/manual_arithmetic_check.rs b/tests/ui/manual_arithmetic_check.rs index 69554c6b61ca..ba296c736f01 100644 --- a/tests/ui/manual_arithmetic_check.rs +++ b/tests/ui/manual_arithmetic_check.rs @@ -7,14 +7,18 @@ fn main() { let c = 8u32; let result = if a > b { a - b } else { 0 }; - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + let result = if b < a { a - b } else { 0 }; - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + let result = if a < b { 0 } else { a - b }; - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + let result = if b > a { 0 } else { a - b }; - //~^ ERROR: manual arithmetic check found + //~^ implicit_saturating_sub + // Should not warn! let result = if a > b { a - b } else { a - c }; diff --git a/tests/ui/manual_arithmetic_check.stderr b/tests/ui/manual_arithmetic_check.stderr index b0cf73cd9151..fe5663f586f4 100644 --- a/tests/ui/manual_arithmetic_check.stderr +++ b/tests/ui/manual_arithmetic_check.stderr @@ -8,19 +8,19 @@ LL | let result = if a > b { a - b } else { 0 }; = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` error: manual arithmetic check found - --> tests/ui/manual_arithmetic_check.rs:11:18 + --> tests/ui/manual_arithmetic_check.rs:12:18 | LL | let result = if b < a { a - b } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` error: manual arithmetic check found - --> tests/ui/manual_arithmetic_check.rs:14:18 + --> tests/ui/manual_arithmetic_check.rs:16:18 | LL | let result = if a < b { 0 } else { a - b }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` error: manual arithmetic check found - --> tests/ui/manual_arithmetic_check.rs:16:18 + --> tests/ui/manual_arithmetic_check.rs:19:18 | LL | let result = if b > a { 0 } else { a - b }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 004463720e26..f9fa8cf04d96 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -2,76 +2,123 @@ error: only a `panic!` in `if`-then statement --> tests/ui/manual_assert.rs:32:5 | LL | / if !a.is_empty() { +LL | | LL | | panic!("qaqaq{:?}", a); LL | | } - | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` + | |_____^ | = note: `-D clippy::manual-assert` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` +help: try instead + | +LL | assert!(a.is_empty(), "qaqaq{:?}", a); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:35:5 + --> tests/ui/manual_assert.rs:36:5 | LL | / if !a.is_empty() { +LL | | LL | | panic!("qwqwq"); LL | | } - | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` + | |_____^ + | +help: try instead + | +LL | assert!(a.is_empty(), "qwqwq"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:52:5 + --> tests/ui/manual_assert.rs:54:5 | LL | / if b.is_empty() { +LL | | LL | | panic!("panic1"); LL | | } - | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:55:5 + | |_____^ + | +help: try instead + | +LL | assert!(!b.is_empty(), "panic1"); | -LL | / if b.is_empty() && a.is_empty() { -LL | | panic!("panic2"); -LL | | } - | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement --> tests/ui/manual_assert.rs:58:5 | +LL | / if b.is_empty() && a.is_empty() { +LL | | +LL | | panic!("panic2"); +LL | | } + | |_____^ + | +help: try instead + | +LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); + | + +error: only a `panic!` in `if`-then statement + --> tests/ui/manual_assert.rs:62:5 + | LL | / if a.is_empty() && !b.is_empty() { +LL | | LL | | panic!("panic3"); LL | | } - | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` + | |_____^ + | +help: try instead + | +LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:61:5 + --> tests/ui/manual_assert.rs:66:5 | LL | / if b.is_empty() || a.is_empty() { +LL | | LL | | panic!("panic4"); LL | | } - | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` + | |_____^ + | +help: try instead + | +LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:64:5 + --> tests/ui/manual_assert.rs:70:5 | LL | / if a.is_empty() || !b.is_empty() { +LL | | LL | | panic!("panic5"); LL | | } - | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` + | |_____^ + | +help: try instead + | +LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:67:5 + --> tests/ui/manual_assert.rs:74:5 | LL | / if a.is_empty() { +LL | | LL | | panic!("with expansion {}", one!()) LL | | } - | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` + | |_____^ + | +help: try instead + | +LL | assert!(!a.is_empty(), "with expansion {}", one!()); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:79:5 + --> tests/ui/manual_assert.rs:87:5 | LL | / if a > 2 { +LL | | LL | | // comment LL | | /* this is a -LL | | multiline ... | LL | | panic!("panic with comment") // comment after `panic!` LL | | } @@ -83,13 +130,19 @@ LL | assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:93:25 + --> tests/ui/manual_assert.rs:102:25 | LL | const BAR: () = if N == 0 { | _________________________^ +LL | | LL | | panic!() LL | | }; - | |_________^ help: try instead: `assert!(!(N == 0), )` + | |_________^ + | +help: try instead + | +LL | const BAR: () = assert!(!(N == 0), ); + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to 10 previous errors diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 004463720e26..f9fa8cf04d96 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -2,76 +2,123 @@ error: only a `panic!` in `if`-then statement --> tests/ui/manual_assert.rs:32:5 | LL | / if !a.is_empty() { +LL | | LL | | panic!("qaqaq{:?}", a); LL | | } - | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` + | |_____^ | = note: `-D clippy::manual-assert` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` +help: try instead + | +LL | assert!(a.is_empty(), "qaqaq{:?}", a); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:35:5 + --> tests/ui/manual_assert.rs:36:5 | LL | / if !a.is_empty() { +LL | | LL | | panic!("qwqwq"); LL | | } - | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` + | |_____^ + | +help: try instead + | +LL | assert!(a.is_empty(), "qwqwq"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:52:5 + --> tests/ui/manual_assert.rs:54:5 | LL | / if b.is_empty() { +LL | | LL | | panic!("panic1"); LL | | } - | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:55:5 + | |_____^ + | +help: try instead + | +LL | assert!(!b.is_empty(), "panic1"); | -LL | / if b.is_empty() && a.is_empty() { -LL | | panic!("panic2"); -LL | | } - | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement --> tests/ui/manual_assert.rs:58:5 | +LL | / if b.is_empty() && a.is_empty() { +LL | | +LL | | panic!("panic2"); +LL | | } + | |_____^ + | +help: try instead + | +LL | assert!(!(b.is_empty() && a.is_empty()), "panic2"); + | + +error: only a `panic!` in `if`-then statement + --> tests/ui/manual_assert.rs:62:5 + | LL | / if a.is_empty() && !b.is_empty() { +LL | | LL | | panic!("panic3"); LL | | } - | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` + | |_____^ + | +help: try instead + | +LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:61:5 + --> tests/ui/manual_assert.rs:66:5 | LL | / if b.is_empty() || a.is_empty() { +LL | | LL | | panic!("panic4"); LL | | } - | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` + | |_____^ + | +help: try instead + | +LL | assert!(!(b.is_empty() || a.is_empty()), "panic4"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:64:5 + --> tests/ui/manual_assert.rs:70:5 | LL | / if a.is_empty() || !b.is_empty() { +LL | | LL | | panic!("panic5"); LL | | } - | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` + | |_____^ + | +help: try instead + | +LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5"); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:67:5 + --> tests/ui/manual_assert.rs:74:5 | LL | / if a.is_empty() { +LL | | LL | | panic!("with expansion {}", one!()) LL | | } - | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` + | |_____^ + | +help: try instead + | +LL | assert!(!a.is_empty(), "with expansion {}", one!()); + | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:79:5 + --> tests/ui/manual_assert.rs:87:5 | LL | / if a > 2 { +LL | | LL | | // comment LL | | /* this is a -LL | | multiline ... | LL | | panic!("panic with comment") // comment after `panic!` LL | | } @@ -83,13 +130,19 @@ LL | assert!(!(a > 2), "panic with comment"); | error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:93:25 + --> tests/ui/manual_assert.rs:102:25 | LL | const BAR: () = if N == 0 { | _________________________^ +LL | | LL | | panic!() LL | | }; - | |_________^ help: try instead: `assert!(!(N == 0), )` + | |_________^ + | +help: try instead + | +LL | const BAR: () = assert!(!(N == 0), ); + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to 10 previous errors diff --git a/tests/ui/manual_assert.rs b/tests/ui/manual_assert.rs index 6337920a3eea..2c9b17bb8b1b 100644 --- a/tests/ui/manual_assert.rs +++ b/tests/ui/manual_assert.rs @@ -30,9 +30,11 @@ fn main() { panic!("qaqaq{:?}", a); } if !a.is_empty() { + //~^ manual_assert panic!("qaqaq{:?}", a); } if !a.is_empty() { + //~^ manual_assert panic!("qwqwq"); } if a.len() == 3 { @@ -50,21 +52,27 @@ fn main() { } let b = vec![1, 2, 3]; if b.is_empty() { + //~^ manual_assert panic!("panic1"); } if b.is_empty() && a.is_empty() { + //~^ manual_assert panic!("panic2"); } if a.is_empty() && !b.is_empty() { + //~^ manual_assert panic!("panic3"); } if b.is_empty() || a.is_empty() { + //~^ manual_assert panic!("panic4"); } if a.is_empty() || !b.is_empty() { + //~^ manual_assert panic!("panic5"); } if a.is_empty() { + //~^ manual_assert panic!("with expansion {}", one!()) } if a.is_empty() { @@ -77,6 +85,7 @@ fn main() { fn issue7730(a: u8) { // Suggestion should preserve comment if a > 2 { + //~^ manual_assert // comment /* this is a multiline @@ -91,6 +100,7 @@ fn issue12505() { impl Foo { const BAR: () = if N == 0 { + //~^ manual_assert panic!() }; } diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index 87973222c0bb..a699e40868d7 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -4,34 +4,41 @@ use std::future::Future; fn fut() -> impl Future { +//~^ manual_async_fn async { 42 } } #[rustfmt::skip] fn fut2() ->impl Future { +//~^ manual_async_fn async { 42 } } #[rustfmt::skip] fn fut3()-> impl Future { +//~^ manual_async_fn async { 42 } } fn empty_fut() -> impl Future { +//~^ manual_async_fn async {} } #[rustfmt::skip] fn empty_fut2() ->impl Future { +//~^ manual_async_fn async {} } #[rustfmt::skip] fn empty_fut3()-> impl Future { +//~^ manual_async_fn async {} } fn core_fut() -> impl core::future::Future { +//~^ manual_async_fn async move { 42 } } @@ -54,6 +61,7 @@ async fn already_async() -> impl Future { struct S; impl S { fn inh_fut() -> impl Future { + //~^ manual_async_fn async { // NOTE: this code is here just to check that the indentation is correct in the suggested fix let a = 42; @@ -89,6 +97,7 @@ impl S { // Tests related to lifetime capture fn elided(_: &i32) -> impl Future + '_ { +//~^ manual_async_fn async { 42 } } @@ -99,6 +108,7 @@ fn elided_not_bound(_: &i32) -> impl Future { #[allow(clippy::needless_lifetimes)] fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { +//~^ manual_async_fn async { 42 } } @@ -128,14 +138,17 @@ mod issue_5765 { } pub fn issue_10450() -> impl Future { +//~^ manual_async_fn async { 42 } } pub(crate) fn issue_10450_2() -> impl Future { +//~^ manual_async_fn async { 42 } } pub(self) fn issue_10450_3() -> impl Future { +//~^ manual_async_fn async { 42 } } diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index 68a97243436d..5d063e550f28 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -12,7 +12,7 @@ LL | async fn fut() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:11:1 + --> tests/ui/manual_async_fn.rs:12:1 | LL | fn fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | async fn fut2() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:16:1 + --> tests/ui/manual_async_fn.rs:18:1 | LL | fn fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | async fn fut3() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:20:1 + --> tests/ui/manual_async_fn.rs:23:1 | LL | fn empty_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | async fn empty_fut() {} | ~~~~~~~~~~~~~~~~~~~~ ~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:25:1 + --> tests/ui/manual_async_fn.rs:29:1 | LL | fn empty_fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | async fn empty_fut2() {} | ~~~~~~~~~~~~~~~~~~~~~ ~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:30:1 + --> tests/ui/manual_async_fn.rs:35:1 | LL | fn empty_fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | async fn empty_fut3() {} | ~~~~~~~~~~~~~~~~~~~~~ ~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:34:1 + --> tests/ui/manual_async_fn.rs:40:1 | LL | fn core_fut() -> impl core::future::Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | async fn core_fut() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:56:5 + --> tests/ui/manual_async_fn.rs:63:5 | LL | fn inh_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL + } | error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:91:1 + --> tests/ui/manual_async_fn.rs:99:1 | LL | fn elided(_: &i32) -> impl Future + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | async fn elided(_: &i32) -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:101:1 + --> tests/ui/manual_async_fn.rs:110:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:130:1 + --> tests/ui/manual_async_fn.rs:140:1 | LL | pub fn issue_10450() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | pub async fn issue_10450() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:134:1 + --> tests/ui/manual_async_fn.rs:145:1 | LL | pub(crate) fn issue_10450_2() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | pub(crate) async fn issue_10450_2() -> i32 { 42 } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> tests/ui/manual_async_fn.rs:138:1 + --> tests/ui/manual_async_fn.rs:150: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 8e5cb7d38b9b..db2ad2ace625 100644 --- a/tests/ui/manual_bits.fixed +++ b/tests/ui/manual_bits.fixed @@ -12,32 +12,56 @@ use std::mem::{size_of, size_of_val}; fn main() { i8::BITS as usize; + //~^ manual_bits i16::BITS as usize; + //~^ manual_bits i32::BITS as usize; + //~^ manual_bits i64::BITS as usize; + //~^ manual_bits i128::BITS as usize; + //~^ manual_bits isize::BITS as usize; + //~^ manual_bits u8::BITS as usize; + //~^ manual_bits u16::BITS as usize; + //~^ manual_bits u32::BITS as usize; + //~^ manual_bits u64::BITS as usize; + //~^ manual_bits u128::BITS as usize; + //~^ manual_bits usize::BITS as usize; + //~^ manual_bits i8::BITS as usize; + //~^ manual_bits i16::BITS as usize; + //~^ manual_bits i32::BITS as usize; + //~^ manual_bits i64::BITS as usize; + //~^ manual_bits i128::BITS as usize; + //~^ manual_bits isize::BITS as usize; + //~^ manual_bits u8::BITS as usize; + //~^ manual_bits u16::BITS as usize; + //~^ manual_bits u32::BITS as usize; + //~^ manual_bits u64::BITS as usize; + //~^ manual_bits u128::BITS as usize; + //~^ manual_bits usize::BITS as usize; + //~^ manual_bits size_of::() * 4; 4 * size_of::(); @@ -48,13 +72,18 @@ fn main() { type Word = u32; Word::BITS as usize; + //~^ manual_bits type Bool = bool; size_of::() * 8; let _: u32 = u128::BITS as u32; + //~^ manual_bits let _: u32 = u128::BITS.try_into().unwrap(); + //~^ manual_bits let _ = (u128::BITS as usize).pow(5); + //~^ manual_bits let _ = &(u128::BITS as usize); + //~^ manual_bits } fn should_not_lint() { diff --git a/tests/ui/manual_bits.rs b/tests/ui/manual_bits.rs index 5e492ed15d21..6d1f0de1c19d 100644 --- a/tests/ui/manual_bits.rs +++ b/tests/ui/manual_bits.rs @@ -12,32 +12,56 @@ use std::mem::{size_of, size_of_val}; fn main() { size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits size_of::() * 8; + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits 8 * size_of::(); + //~^ manual_bits size_of::() * 4; 4 * size_of::(); @@ -48,13 +72,18 @@ fn main() { type Word = u32; size_of::() * 8; + //~^ manual_bits type Bool = bool; size_of::() * 8; let _: u32 = (size_of::() * 8) as u32; + //~^ manual_bits let _: u32 = (size_of::() * 8).try_into().unwrap(); + //~^ manual_bits let _ = (size_of::() * 8).pow(5); + //~^ manual_bits let _ = &(size_of::() * 8); + //~^ manual_bits } fn should_not_lint() { diff --git a/tests/ui/manual_bits.stderr b/tests/ui/manual_bits.stderr index 4383aa49df9b..a50975ed474e 100644 --- a/tests/ui/manual_bits.stderr +++ b/tests/ui/manual_bits.stderr @@ -8,169 +8,169 @@ LL | size_of::() * 8; = help: to override `-D warnings` add `#[allow(clippy::manual_bits)]` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> tests/ui/manual_bits.rs:15:5 + --> tests/ui/manual_bits.rs:16: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 - --> tests/ui/manual_bits.rs:16:5 + --> tests/ui/manual_bits.rs:18: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 - --> tests/ui/manual_bits.rs:17:5 + --> tests/ui/manual_bits.rs:20: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 - --> tests/ui/manual_bits.rs:18:5 + --> tests/ui/manual_bits.rs:22: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 - --> tests/ui/manual_bits.rs:19:5 + --> tests/ui/manual_bits.rs:24: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 - --> tests/ui/manual_bits.rs:21:5 + --> tests/ui/manual_bits.rs:27: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 - --> tests/ui/manual_bits.rs:22:5 + --> tests/ui/manual_bits.rs:29: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 - --> tests/ui/manual_bits.rs:23:5 + --> tests/ui/manual_bits.rs:31: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 - --> tests/ui/manual_bits.rs:24:5 + --> tests/ui/manual_bits.rs:33: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 - --> tests/ui/manual_bits.rs:25:5 + --> tests/ui/manual_bits.rs:35: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 - --> tests/ui/manual_bits.rs:26:5 + --> tests/ui/manual_bits.rs:37: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 - --> tests/ui/manual_bits.rs:28:5 + --> tests/ui/manual_bits.rs:40: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 - --> tests/ui/manual_bits.rs:29:5 + --> tests/ui/manual_bits.rs:42: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 - --> tests/ui/manual_bits.rs:30:5 + --> tests/ui/manual_bits.rs:44: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 - --> tests/ui/manual_bits.rs:31:5 + --> tests/ui/manual_bits.rs:46: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 - --> tests/ui/manual_bits.rs:32:5 + --> tests/ui/manual_bits.rs:48: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 - --> tests/ui/manual_bits.rs:33:5 + --> tests/ui/manual_bits.rs:50: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 - --> tests/ui/manual_bits.rs:35:5 + --> tests/ui/manual_bits.rs:53: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 - --> tests/ui/manual_bits.rs:36:5 + --> tests/ui/manual_bits.rs:55: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 - --> tests/ui/manual_bits.rs:37:5 + --> tests/ui/manual_bits.rs:57: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 - --> tests/ui/manual_bits.rs:38:5 + --> tests/ui/manual_bits.rs:59: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 - --> tests/ui/manual_bits.rs:39:5 + --> tests/ui/manual_bits.rs:61: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 - --> tests/ui/manual_bits.rs:40:5 + --> tests/ui/manual_bits.rs:63: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 - --> tests/ui/manual_bits.rs:50:5 + --> tests/ui/manual_bits.rs:74: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 - --> tests/ui/manual_bits.rs:54:18 + --> tests/ui/manual_bits.rs:79: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 - --> tests/ui/manual_bits.rs:55:18 + --> tests/ui/manual_bits.rs:81: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 - --> tests/ui/manual_bits.rs:56:13 + --> tests/ui/manual_bits.rs:83: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 - --> tests/ui/manual_bits.rs:57:14 + --> tests/ui/manual_bits.rs:85:14 | LL | let _ = &(size_of::() * 8); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` diff --git a/tests/ui/manual_c_str_literals.edition2021.fixed b/tests/ui/manual_c_str_literals.edition2021.fixed index 391c63bb4b89..3ffaef0386ce 100644 --- a/tests/ui/manual_c_str_literals.edition2021.fixed +++ b/tests/ui/manual_c_str_literals.edition2021.fixed @@ -1,6 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 +//@[edition2018] check-pass #![warn(clippy::manual_c_str_literals)] #![allow(clippy::no_effect)] @@ -32,29 +33,42 @@ fn pre_stabilization() { #[clippy::msrv = "1.77.0"] fn post_stabilization() { c"foo"; + //~[edition2021]^ manual_c_str_literals } fn main() { c"foo"; + //~[edition2021]^ manual_c_str_literals c"foo"; + //~[edition2021]^ manual_c_str_literals c"foo"; + //~[edition2021]^ manual_c_str_literals c"foo\\0sdsd"; + //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); unsafe { c"foo" }; + //~[edition2021]^ manual_c_str_literals unsafe { c"foo" }; + //~[edition2021]^ manual_c_str_literals let _: *const _ = c"foo".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _: *const _ = c"foo".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string let _: *const _ = "".as_ptr(); let _: *const _ = c"foo".as_ptr().cast::(); + //~[edition2021]^ manual_c_str_literals let _ = "电脑".as_ptr(); let _ = "电脑\\".as_ptr(); let _ = c"电脑\\".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _ = c"电脑".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _ = c"电脑".as_ptr(); + //~[edition2021]^ manual_c_str_literals // Macro cases, don't lint: cstr!("foo"); diff --git a/tests/ui/manual_c_str_literals.edition2021.stderr b/tests/ui/manual_c_str_literals.edition2021.stderr index beab29ccdda0..2119bbc5b425 100644 --- a/tests/ui/manual_c_str_literals.edition2021.stderr +++ b/tests/ui/manual_c_str_literals.edition2021.stderr @@ -1,5 +1,5 @@ error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:34:5 + --> tests/ui/manual_c_str_literals.rs:35:5 | LL | CStr::from_bytes_with_nul(b"foo\0"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` @@ -8,73 +8,73 @@ LL | CStr::from_bytes_with_nul(b"foo\0"); = help: to override `-D warnings` add `#[allow(clippy::manual_c_str_literals)]` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:38:5 + --> tests/ui/manual_c_str_literals.rs:40:5 | LL | CStr::from_bytes_with_nul(b"foo\0"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:39:5 + --> tests/ui/manual_c_str_literals.rs:42:5 | LL | CStr::from_bytes_with_nul(b"foo\x00"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:40:5 + --> tests/ui/manual_c_str_literals.rs:44:5 | LL | CStr::from_bytes_with_nul(b"foo\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:41:5 + --> tests/ui/manual_c_str_literals.rs:46:5 | LL | CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo\\0sdsd"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:46:14 + --> tests/ui/manual_c_str_literals.rs:52:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:47:14 + --> tests/ui/manual_c_str_literals.rs:54:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:48:23 + --> tests/ui/manual_c_str_literals.rs:56:23 | LL | let _: *const _ = b"foo\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:49:23 + --> tests/ui/manual_c_str_literals.rs:58:23 | LL | let _: *const _ = "foo\0".as_ptr(); | ^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:52:23 + --> tests/ui/manual_c_str_literals.rs:62:23 | LL | let _: *const _ = b"foo\0".as_ptr().cast::(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:55:13 + --> tests/ui/manual_c_str_literals.rs:66:13 | LL | let _ = "电脑\\\0".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑\\"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:56:13 + --> tests/ui/manual_c_str_literals.rs:68:13 | LL | let _ = "电脑\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"电脑"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:57:13 + --> tests/ui/manual_c_str_literals.rs:70:13 | LL | let _ = "电脑\x00".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑"` diff --git a/tests/ui/manual_c_str_literals.rs b/tests/ui/manual_c_str_literals.rs index 39b622580774..ec3b8e587724 100644 --- a/tests/ui/manual_c_str_literals.rs +++ b/tests/ui/manual_c_str_literals.rs @@ -1,6 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 +//@[edition2018] check-pass #![warn(clippy::manual_c_str_literals)] #![allow(clippy::no_effect)] @@ -32,29 +33,42 @@ fn pre_stabilization() { #[clippy::msrv = "1.77.0"] fn post_stabilization() { CStr::from_bytes_with_nul(b"foo\0"); + //~[edition2021]^ manual_c_str_literals } fn main() { CStr::from_bytes_with_nul(b"foo\0"); + //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\x00"); + //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\0").unwrap(); + //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); + //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; + //~[edition2021]^ manual_c_str_literals unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; + //~[edition2021]^ manual_c_str_literals let _: *const _ = b"foo\0".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _: *const _ = "foo\0".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string let _: *const _ = "".as_ptr(); let _: *const _ = b"foo\0".as_ptr().cast::(); + //~[edition2021]^ manual_c_str_literals let _ = "电脑".as_ptr(); let _ = "电脑\\".as_ptr(); let _ = "电脑\\\0".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _ = "电脑\0".as_ptr(); + //~[edition2021]^ manual_c_str_literals let _ = "电脑\x00".as_ptr(); + //~[edition2021]^ manual_c_str_literals // Macro cases, don't lint: cstr!("foo"); diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed index 8d57cbbf51bf..1e2b1d009907 100644 --- a/tests/ui/manual_clamp.fixed +++ b/tests/ui/manual_clamp.fixed @@ -150,12 +150,14 @@ fn const_main() { let x3 = input.clamp(CONST_MIN, CONST_MAX); let x4 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x5 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x6 = input.clamp(CONST_MIN, CONST_MAX); @@ -187,54 +189,70 @@ fn const_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 + //~^ manual_clamp + + let x17 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x18 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x19 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x20 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x21 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x22 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x23 = input.clamp(CONST_MIN, CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + } let mut x32 = input; x32 = x32.clamp(CONST_MIN, CONST_MAX); diff --git a/tests/ui/manual_clamp.rs b/tests/ui/manual_clamp.rs index 4d2a0c47bbd7..bf40e09969a4 100644 --- a/tests/ui/manual_clamp.rs +++ b/tests/ui/manual_clamp.rs @@ -142,8 +142,9 @@ fn const_main() { let input = 0; // Min and max are const, so this should trigger the lint. let x0 = if CONST_MAX < input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MAX } else if CONST_MIN > input { CONST_MIN @@ -152,8 +153,9 @@ fn const_main() { }; let x1 = if input > CONST_MAX { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MAX } else if input < CONST_MIN { CONST_MIN @@ -162,8 +164,9 @@ fn const_main() { }; let x2 = if input < CONST_MIN { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MIN } else if input > CONST_MAX { CONST_MAX @@ -172,8 +175,9 @@ fn const_main() { }; let x3 = if CONST_MIN > input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MIN } else if CONST_MAX < input { CONST_MAX @@ -182,32 +186,37 @@ fn const_main() { }; let x4 = input.max(CONST_MIN).min(CONST_MAX); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x5 = input.min(CONST_MAX).max(CONST_MIN); - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + let x6 = match input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x if x > CONST_MAX => CONST_MAX, x if x < CONST_MIN => CONST_MIN, x => x, }; let x7 = match input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x if x < CONST_MIN => CONST_MIN, x if x > CONST_MAX => CONST_MAX, x => x, }; let x8 = match input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x if CONST_MAX < x => CONST_MAX, x if CONST_MIN > x => CONST_MIN, x => x, @@ -215,8 +224,9 @@ fn const_main() { let mut x9 = input; if x9 < CONST_MIN { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x9 = CONST_MIN; } if x9 > CONST_MAX { @@ -224,8 +234,9 @@ fn const_main() { } let x10 = match input { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x if CONST_MIN > x => CONST_MIN, x if CONST_MAX < x => CONST_MAX, x => x, @@ -234,8 +245,9 @@ fn const_main() { let mut x11 = input; let _ = 1; if x11 > CONST_MAX { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x11 = CONST_MAX; } if x11 < CONST_MIN { @@ -244,8 +256,9 @@ fn const_main() { let mut x12 = input; if CONST_MIN > x12 { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x12 = CONST_MIN; } if CONST_MAX < x12 { @@ -254,8 +267,9 @@ fn const_main() { let mut x13 = input; if CONST_MAX < x13 { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x13 = CONST_MAX; } if CONST_MIN > x13 { @@ -263,8 +277,9 @@ fn const_main() { } let x14 = if input > CONST_MAX { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MAX } else if input < CONST_MIN { CONST_MIN @@ -274,8 +289,9 @@ fn const_main() { { let input = 0.0f64; let x15 = if input > CONST_F64_MAX { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_F64_MAX } else if input < CONST_F64_MIN { CONST_F64_MIN @@ -287,59 +303,76 @@ fn const_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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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 + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + 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() + //~^ manual_clamp + + } let mut x32 = input; if x32 < CONST_MIN { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x32 = CONST_MIN; } else if x32 > CONST_MAX { x32 = CONST_MAX; @@ -368,8 +401,9 @@ fn const_main() { // It's important this be the last set of statements let mut x35 = input; if CONST_MAX < x35 { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + x35 = CONST_MAX; } if CONST_MIN > x35 { @@ -530,8 +564,9 @@ fn msrv_1_49() { fn msrv_1_50() { let input = 0; let _ = if input > CONST_MAX { - //~^ ERROR: clamp-like pattern without using clamp function - //~| NOTE: clamp will panic if max < min + //~^ manual_clamp + + CONST_MAX } else if input < CONST_MIN { CONST_MIN diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index 459d46796d87..ca7da23efec2 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -1,10 +1,7 @@ error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:217:5 + --> tests/ui/manual_clamp.rs:226:5 | LL | / if x9 < CONST_MIN { -LL | | -LL | | -LL | | x9 = CONST_MIN; ... | LL | | x9 = CONST_MAX; LL | | } @@ -15,12 +12,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_clamp)]` error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:236:5 + --> tests/ui/manual_clamp.rs:247:5 | LL | / if x11 > CONST_MAX { -LL | | -LL | | -LL | | x11 = CONST_MAX; ... | LL | | x11 = CONST_MIN; LL | | } @@ -29,12 +23,9 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:246:5 + --> tests/ui/manual_clamp.rs:258:5 | LL | / if CONST_MIN > x12 { -LL | | -LL | | -LL | | x12 = CONST_MIN; ... | LL | | x12 = CONST_MAX; LL | | } @@ -43,12 +34,9 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:256:5 + --> tests/ui/manual_clamp.rs:269:5 | LL | / if CONST_MAX < x13 { -LL | | -LL | | -LL | | x13 = CONST_MAX; ... | LL | | x13 = CONST_MIN; LL | | } @@ -57,12 +45,9 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:370:5 + --> tests/ui/manual_clamp.rs:403:5 | LL | / if CONST_MAX < x35 { -LL | | -LL | | -LL | | x35 = CONST_MAX; ... | LL | | x35 = CONST_MIN; LL | | } @@ -75,9 +60,6 @@ error: clamp-like pattern without using clamp function | LL | let x0 = if CONST_MAX < input { | ______________^ -LL | | -LL | | -LL | | CONST_MAX ... | LL | | input LL | | }; @@ -86,13 +68,10 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:154:14 + --> tests/ui/manual_clamp.rs:155:14 | LL | let x1 = if input > CONST_MAX { | ______________^ -LL | | -LL | | -LL | | CONST_MAX ... | LL | | input LL | | }; @@ -101,13 +80,10 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:164:14 + --> tests/ui/manual_clamp.rs:166:14 | LL | let x2 = if input < CONST_MIN { | ______________^ -LL | | -LL | | -LL | | CONST_MIN ... | LL | | input LL | | }; @@ -116,13 +92,10 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:174:14 + --> tests/ui/manual_clamp.rs:177:14 | LL | let x3 = if CONST_MIN > input { | ______________^ -LL | | -LL | | -LL | | CONST_MIN ... | LL | | input LL | | }; @@ -131,7 +104,7 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:184:14 + --> tests/ui/manual_clamp.rs:188:14 | LL | let x4 = input.max(CONST_MIN).min(CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -139,7 +112,7 @@ LL | let x4 = input.max(CONST_MIN).min(CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:188:14 + --> tests/ui/manual_clamp.rs:193:14 | LL | let x5 = input.min(CONST_MAX).max(CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -147,14 +120,11 @@ LL | let x5 = input.min(CONST_MAX).max(CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:192:14 + --> tests/ui/manual_clamp.rs:198:14 | LL | let x6 = match input { | ______________^ -LL | | -LL | | -LL | | x if x > CONST_MAX => CONST_MAX, -LL | | x if x < CONST_MIN => CONST_MIN, +... | LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -162,14 +132,11 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:200:14 + --> tests/ui/manual_clamp.rs:207:14 | LL | let x7 = match input { | ______________^ -LL | | -LL | | -LL | | x if x < CONST_MIN => CONST_MIN, -LL | | x if x > CONST_MAX => CONST_MAX, +... | LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -177,14 +144,11 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:208:14 + --> tests/ui/manual_clamp.rs:216:14 | LL | let x8 = match input { | ______________^ -LL | | -LL | | -LL | | x if CONST_MAX < x => CONST_MAX, -LL | | x if CONST_MIN > x => CONST_MIN, +... | LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -192,14 +156,11 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:226:15 + --> tests/ui/manual_clamp.rs:236:15 | LL | let x10 = match input { | _______________^ -LL | | -LL | | -LL | | x if CONST_MIN > x => CONST_MIN, -LL | | x if CONST_MAX < x => CONST_MAX, +... | LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -207,13 +168,10 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:265:15 + --> tests/ui/manual_clamp.rs:279:15 | LL | let x14 = if input > CONST_MAX { | _______________^ -LL | | -LL | | -LL | | CONST_MAX ... | LL | | input LL | | }; @@ -222,13 +180,10 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:276:19 + --> tests/ui/manual_clamp.rs:291:19 | LL | let x15 = if input > CONST_F64_MAX { | ___________________^ -LL | | -LL | | -LL | | CONST_F64_MAX ... | LL | | input LL | | }; @@ -238,7 +193,7 @@ LL | | }; = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:289:19 + --> tests/ui/manual_clamp.rs:305:19 | LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -246,7 +201,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 - --> tests/ui/manual_clamp.rs:292:19 + --> tests/ui/manual_clamp.rs:309:19 | LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -254,7 +209,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 - --> tests/ui/manual_clamp.rs:295:19 + --> tests/ui/manual_clamp.rs:313:19 | LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -262,7 +217,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 - --> tests/ui/manual_clamp.rs:298:19 + --> tests/ui/manual_clamp.rs:317:19 | LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -270,7 +225,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 - --> tests/ui/manual_clamp.rs:301:19 + --> tests/ui/manual_clamp.rs:321:19 | LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -278,7 +233,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 - --> tests/ui/manual_clamp.rs:304:19 + --> tests/ui/manual_clamp.rs:325:19 | LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -286,7 +241,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 - --> tests/ui/manual_clamp.rs:307:19 + --> tests/ui/manual_clamp.rs:329:19 | LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -294,7 +249,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 - --> tests/ui/manual_clamp.rs:310:19 + --> tests/ui/manual_clamp.rs:333:19 | LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -302,7 +257,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 - --> tests/ui/manual_clamp.rs:314:19 + --> tests/ui/manual_clamp.rs:338: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)` @@ -311,7 +266,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 - --> tests/ui/manual_clamp.rs:317:19 + --> tests/ui/manual_clamp.rs:342: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)` @@ -320,7 +275,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 - --> tests/ui/manual_clamp.rs:320:19 + --> tests/ui/manual_clamp.rs:346: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)` @@ -329,7 +284,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 - --> tests/ui/manual_clamp.rs:323:19 + --> tests/ui/manual_clamp.rs:350: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)` @@ -338,7 +293,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 - --> tests/ui/manual_clamp.rs:326:19 + --> tests/ui/manual_clamp.rs:354: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)` @@ -347,7 +302,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 - --> tests/ui/manual_clamp.rs:329:19 + --> tests/ui/manual_clamp.rs:358: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)` @@ -356,7 +311,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 - --> tests/ui/manual_clamp.rs:332:19 + --> tests/ui/manual_clamp.rs:362: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)` @@ -365,7 +320,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 - --> tests/ui/manual_clamp.rs:335:19 + --> tests/ui/manual_clamp.rs:366: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)` @@ -374,13 +329,10 @@ 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 - --> tests/ui/manual_clamp.rs:340:5 + --> tests/ui/manual_clamp.rs:372:5 | LL | / if x32 < CONST_MIN { -LL | | -LL | | -LL | | x32 = CONST_MIN; -LL | | } else if x32 > CONST_MAX { +... | LL | | x32 = CONST_MAX; LL | | } | |_____^ help: replace with clamp: `x32 = x32.clamp(CONST_MIN, CONST_MAX);` @@ -388,13 +340,10 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:532:13 + --> tests/ui/manual_clamp.rs:566:13 | LL | let _ = if input > CONST_MAX { | _____________^ -LL | | -LL | | -LL | | CONST_MAX ... | LL | | input LL | | }; diff --git a/tests/ui/manual_div_ceil.fixed b/tests/ui/manual_div_ceil.fixed index f6eb5a9784ac..6657c695abea 100644 --- a/tests/ui/manual_div_ceil.fixed +++ b/tests/ui/manual_div_ceil.fixed @@ -6,12 +6,17 @@ fn main() { let z = 11_u32; // Lint - let _ = x.div_ceil(y); //~ ERROR: manually reimplementing `div_ceil` - let _ = x.div_ceil(y); //~ ERROR: manually reimplementing `div_ceil` - let _ = x.div_ceil(y); //~ ERROR: manually reimplementing `div_ceil` +let _ = x.div_ceil(y); +//~^ manual_div_ceil +let _ = x.div_ceil(y); +//~^ manual_div_ceil +let _ = x.div_ceil(y); +//~^ manual_div_ceil - let _ = 7_u32.div_ceil(4); //~ ERROR: manually reimplementing `div_ceil` - let _ = (7_i32 as u32).div_ceil(4); //~ ERROR: manually reimplementing `div_ceil` +let _ = 7_u32.div_ceil(4); +//~^ manual_div_ceil +let _ = (7_i32 as u32).div_ceil(4); +//~^ manual_div_ceil // No lint let _ = (x + (y - 2)) / y; @@ -32,29 +37,40 @@ fn main() { fn issue_13843() { let x = 3usize; let _ = 2048_usize.div_ceil(x); + //~^ manual_div_ceil let x = 5usize; let _ = 2048usize.div_ceil(x); + //~^ manual_div_ceil let x = 5usize; let _ = 2048_usize.div_ceil(x); + //~^ manual_div_ceil let x = 2048usize; let _ = x.div_ceil(4); + //~^ manual_div_ceil let _: u32 = 2048_u32.div_ceil(6); + //~^ manual_div_ceil let _: usize = 2048_usize.div_ceil(6); + //~^ manual_div_ceil let _: u32 = 0x2048_u32.div_ceil(0x6); + //~^ manual_div_ceil let _ = 2048_u32.div_ceil(6u32); + //~^ manual_div_ceil let _ = 1_000_000_u32.div_ceil(6u32); + //~^ manual_div_ceil } fn issue_13950() { let x = 33u32; let _ = x.div_ceil(8); + //~^ manual_div_ceil let _ = x.div_ceil(8); + //~^ manual_div_ceil let y = -33i32; let _ = (y + -8) / -7; diff --git a/tests/ui/manual_div_ceil.rs b/tests/ui/manual_div_ceil.rs index 2f063afe787d..2c8506e84cb5 100644 --- a/tests/ui/manual_div_ceil.rs +++ b/tests/ui/manual_div_ceil.rs @@ -6,12 +6,17 @@ fn main() { let z = 11_u32; // Lint - let _ = (x + (y - 1)) / y; //~ ERROR: manually reimplementing `div_ceil` - let _ = ((y - 1) + x) / y; //~ ERROR: manually reimplementing `div_ceil` - let _ = (x + y - 1) / y; //~ ERROR: manually reimplementing `div_ceil` +let _ = (x + (y - 1)) / y; +//~^ manual_div_ceil +let _ = ((y - 1) + x) / y; +//~^ manual_div_ceil +let _ = (x + y - 1) / y; +//~^ manual_div_ceil - let _ = (7_u32 + (4 - 1)) / 4; //~ ERROR: manually reimplementing `div_ceil` - let _ = (7_i32 as u32 + (4 - 1)) / 4; //~ ERROR: manually reimplementing `div_ceil` +let _ = (7_u32 + (4 - 1)) / 4; +//~^ manual_div_ceil +let _ = (7_i32 as u32 + (4 - 1)) / 4; +//~^ manual_div_ceil // No lint let _ = (x + (y - 2)) / y; @@ -32,29 +37,40 @@ fn main() { fn issue_13843() { let x = 3usize; let _ = (2048 + x - 1) / x; + //~^ manual_div_ceil let x = 5usize; let _ = (2048usize + x - 1) / x; + //~^ manual_div_ceil let x = 5usize; let _ = (2048_usize + x - 1) / x; + //~^ manual_div_ceil let x = 2048usize; let _ = (x + 4 - 1) / 4; + //~^ manual_div_ceil let _: u32 = (2048 + 6 - 1) / 6; + //~^ manual_div_ceil let _: usize = (2048 + 6 - 1) / 6; + //~^ manual_div_ceil let _: u32 = (0x2048 + 0x6 - 1) / 0x6; + //~^ manual_div_ceil let _ = (2048 + 6u32 - 1) / 6u32; + //~^ manual_div_ceil let _ = (1_000_000 + 6u32 - 1) / 6u32; + //~^ manual_div_ceil } fn issue_13950() { let x = 33u32; let _ = (x + 7) / 8; + //~^ manual_div_ceil let _ = (7 + x) / 8; + //~^ manual_div_ceil let y = -33i32; let _ = (y + -8) / -7; diff --git a/tests/ui/manual_div_ceil.stderr b/tests/ui/manual_div_ceil.stderr index 0bac5d8ef1c1..d6793dcfb5f3 100644 --- a/tests/ui/manual_div_ceil.stderr +++ b/tests/ui/manual_div_ceil.stderr @@ -1,98 +1,98 @@ error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:9:13 + --> tests/ui/manual_div_ceil.rs:9:9 | -LL | let _ = (x + (y - 1)) / y; - | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = (x + (y - 1)) / y; + | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` | = note: `-D clippy::manual-div-ceil` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_div_ceil)]` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:10:13 + --> tests/ui/manual_div_ceil.rs:11:9 | -LL | let _ = ((y - 1) + x) / y; - | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = ((y - 1) + x) / y; + | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:11:13 + --> tests/ui/manual_div_ceil.rs:13:9 | -LL | let _ = (x + y - 1) / y; - | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = (x + y - 1) / y; + | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:13:13 + --> tests/ui/manual_div_ceil.rs:16:9 | -LL | let _ = (7_u32 + (4 - 1)) / 4; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `7_u32.div_ceil(4)` +LL | let _ = (7_u32 + (4 - 1)) / 4; + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `7_u32.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:14:13 + --> tests/ui/manual_div_ceil.rs:18:9 | -LL | let _ = (7_i32 as u32 + (4 - 1)) / 4; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_i32 as u32).div_ceil(4)` +LL | let _ = (7_i32 as u32 + (4 - 1)) / 4; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_i32 as u32).div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:34:13 + --> tests/ui/manual_div_ceil.rs:39:13 | LL | let _ = (2048 + x - 1) / x; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:37:13 + --> tests/ui/manual_div_ceil.rs:43:13 | LL | let _ = (2048usize + x - 1) / x; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:40:13 + --> tests/ui/manual_div_ceil.rs:47:13 | LL | let _ = (2048_usize + x - 1) / x; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:43:13 + --> tests/ui/manual_div_ceil.rs:51:13 | LL | let _ = (x + 4 - 1) / 4; | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:45:18 + --> tests/ui/manual_div_ceil.rs:54:18 | LL | let _: u32 = (2048 + 6 - 1) / 6; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_u32.div_ceil(6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:46:20 + --> tests/ui/manual_div_ceil.rs:56:20 | LL | let _: usize = (2048 + 6 - 1) / 6; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:47:18 + --> tests/ui/manual_div_ceil.rs:58:18 | LL | let _: u32 = (0x2048 + 0x6 - 1) / 0x6; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `0x2048_u32.div_ceil(0x6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:49:13 + --> tests/ui/manual_div_ceil.rs:61:13 | LL | let _ = (2048 + 6u32 - 1) / 6u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_u32.div_ceil(6u32)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:51:13 + --> tests/ui/manual_div_ceil.rs:64:13 | LL | let _ = (1_000_000 + 6u32 - 1) / 6u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `1_000_000_u32.div_ceil(6u32)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:56:13 + --> tests/ui/manual_div_ceil.rs:70:13 | LL | let _ = (x + 7) / 8; | ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:57:13 + --> tests/ui/manual_div_ceil.rs:72:13 | LL | let _ = (7 + x) / 8; | ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)` diff --git a/tests/ui/manual_div_ceil_with_feature.fixed b/tests/ui/manual_div_ceil_with_feature.fixed index 01c58151bc94..f55999c5ad08 100644 --- a/tests/ui/manual_div_ceil_with_feature.fixed +++ b/tests/ui/manual_div_ceil_with_feature.fixed @@ -9,13 +9,20 @@ fn main() { // Lint. let _ = x.div_ceil(y); + //~^ manual_div_ceil let _ = x.div_ceil(y); + //~^ manual_div_ceil let _ = x.div_ceil(y); + //~^ manual_div_ceil let _ = 7_i32.div_ceil(4); + //~^ manual_div_ceil let _ = (7_i32 as u32).div_ceil(4); + //~^ manual_div_ceil let _ = (7_u32 as i32).div_ceil(4); + //~^ manual_div_ceil let _ = z_u.div_ceil(4); + //~^ manual_div_ceil // No lint. let _ = (x + (y - 2)) / y; @@ -27,37 +34,53 @@ fn main() { fn issue_13843() { let x = 3usize; let _ = 2048_usize.div_ceil(x); + //~^ manual_div_ceil let x = 5usize; let _ = 2048usize.div_ceil(x); + //~^ manual_div_ceil let x = 5usize; let _ = 2048_usize.div_ceil(x); + //~^ manual_div_ceil let x = 2048usize; let _ = x.div_ceil(4); + //~^ manual_div_ceil let _ = 2048_i32.div_ceil(4); + //~^ manual_div_ceil let _: u32 = 2048_u32.div_ceil(6); + //~^ manual_div_ceil let _: usize = 2048_usize.div_ceil(6); + //~^ manual_div_ceil let _: u32 = 0x2048_u32.div_ceil(0x6); + //~^ manual_div_ceil let _ = 2048_u32.div_ceil(6u32); + //~^ manual_div_ceil let x = -2; let _ = (-2048_i32).div_ceil(x); + //~^ manual_div_ceil let _ = 1_000_000_u32.div_ceil(6u32); + //~^ manual_div_ceil } fn issue_13950() { let x = 33u32; let _ = x.div_ceil(8); + //~^ manual_div_ceil let _ = x.div_ceil(8); + //~^ manual_div_ceil let y = -33i32; let _ = y.div_ceil(-7); + //~^ manual_div_ceil let _ = y.div_ceil(-7); + //~^ manual_div_ceil let _ = y.div_ceil(-7); + //~^ manual_div_ceil } diff --git a/tests/ui/manual_div_ceil_with_feature.rs b/tests/ui/manual_div_ceil_with_feature.rs index 048ff401581f..8a895f634cb4 100644 --- a/tests/ui/manual_div_ceil_with_feature.rs +++ b/tests/ui/manual_div_ceil_with_feature.rs @@ -9,13 +9,20 @@ fn main() { // Lint. let _ = (x + (y - 1)) / y; + //~^ manual_div_ceil let _ = ((y - 1) + x) / y; + //~^ manual_div_ceil let _ = (x + y - 1) / y; + //~^ manual_div_ceil let _ = (7_i32 + (4 - 1)) / 4; + //~^ manual_div_ceil let _ = (7_i32 as u32 + (4 - 1)) / 4; + //~^ manual_div_ceil let _ = (7_u32 as i32 + (4 - 1)) / 4; + //~^ manual_div_ceil let _ = (z_u + (4 - 1)) / 4; + //~^ manual_div_ceil // No lint. let _ = (x + (y - 2)) / y; @@ -27,37 +34,53 @@ fn main() { fn issue_13843() { let x = 3usize; let _ = (2048 + x - 1) / x; + //~^ manual_div_ceil let x = 5usize; let _ = (2048usize + x - 1) / x; + //~^ manual_div_ceil let x = 5usize; let _ = (2048_usize + x - 1) / x; + //~^ manual_div_ceil let x = 2048usize; let _ = (x + 4 - 1) / 4; + //~^ manual_div_ceil let _ = (2048 + 4 - 1) / 4; + //~^ manual_div_ceil let _: u32 = (2048 + 6 - 1) / 6; + //~^ manual_div_ceil let _: usize = (2048 + 6 - 1) / 6; + //~^ manual_div_ceil let _: u32 = (0x2048 + 0x6 - 1) / 0x6; + //~^ manual_div_ceil let _ = (2048 + 6u32 - 1) / 6u32; + //~^ manual_div_ceil let x = -2; let _ = (-2048 + x - 1) / x; + //~^ manual_div_ceil let _ = (1_000_000 + 6u32 - 1) / 6u32; + //~^ manual_div_ceil } fn issue_13950() { let x = 33u32; let _ = (x + 7) / 8; + //~^ manual_div_ceil let _ = (7 + x) / 8; + //~^ manual_div_ceil let y = -33i32; let _ = (y + -8) / -7; + //~^ manual_div_ceil let _ = (-8 + y) / -7; + //~^ manual_div_ceil let _ = (y - 8) / -7; + //~^ manual_div_ceil } diff --git a/tests/ui/manual_div_ceil_with_feature.stderr b/tests/ui/manual_div_ceil_with_feature.stderr index 807cfd82724e..e1160d962996 100644 --- a/tests/ui/manual_div_ceil_with_feature.stderr +++ b/tests/ui/manual_div_ceil_with_feature.stderr @@ -8,133 +8,133 @@ LL | let _ = (x + (y - 1)) / y; = help: to override `-D warnings` add `#[allow(clippy::manual_div_ceil)]` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:12:13 + --> tests/ui/manual_div_ceil_with_feature.rs:13:13 | LL | let _ = ((y - 1) + x) / y; | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:13:13 + --> tests/ui/manual_div_ceil_with_feature.rs:15:13 | LL | let _ = (x + y - 1) / y; | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:15:13 + --> tests/ui/manual_div_ceil_with_feature.rs:18:13 | LL | let _ = (7_i32 + (4 - 1)) / 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `7_i32.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:16:13 + --> tests/ui/manual_div_ceil_with_feature.rs:20:13 | LL | let _ = (7_i32 as u32 + (4 - 1)) / 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_i32 as u32).div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:17:13 + --> tests/ui/manual_div_ceil_with_feature.rs:22:13 | LL | let _ = (7_u32 as i32 + (4 - 1)) / 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_u32 as i32).div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:18:13 + --> tests/ui/manual_div_ceil_with_feature.rs:24:13 | LL | let _ = (z_u + (4 - 1)) / 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `z_u.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:29:13 + --> tests/ui/manual_div_ceil_with_feature.rs:36:13 | LL | let _ = (2048 + x - 1) / x; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:32:13 + --> tests/ui/manual_div_ceil_with_feature.rs:40:13 | LL | let _ = (2048usize + x - 1) / x; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:35:13 + --> tests/ui/manual_div_ceil_with_feature.rs:44:13 | LL | let _ = (2048_usize + x - 1) / x; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:38:13 + --> tests/ui/manual_div_ceil_with_feature.rs:48:13 | LL | let _ = (x + 4 - 1) / 4; | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:40:13 + --> tests/ui/manual_div_ceil_with_feature.rs:51:13 | LL | let _ = (2048 + 4 - 1) / 4; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_i32.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:42:18 + --> tests/ui/manual_div_ceil_with_feature.rs:54:18 | LL | let _: u32 = (2048 + 6 - 1) / 6; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_u32.div_ceil(6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:43:20 + --> tests/ui/manual_div_ceil_with_feature.rs:56:20 | LL | let _: usize = (2048 + 6 - 1) / 6; | ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_usize.div_ceil(6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:44:18 + --> tests/ui/manual_div_ceil_with_feature.rs:58:18 | LL | let _: u32 = (0x2048 + 0x6 - 1) / 0x6; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `0x2048_u32.div_ceil(0x6)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:46:13 + --> tests/ui/manual_div_ceil_with_feature.rs:61:13 | LL | let _ = (2048 + 6u32 - 1) / 6u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `2048_u32.div_ceil(6u32)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:49:13 + --> tests/ui/manual_div_ceil_with_feature.rs:65:13 | LL | let _ = (-2048 + x - 1) / x; | ^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(-2048_i32).div_ceil(x)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:51:13 + --> tests/ui/manual_div_ceil_with_feature.rs:68:13 | LL | let _ = (1_000_000 + 6u32 - 1) / 6u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `1_000_000_u32.div_ceil(6u32)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:56:13 + --> tests/ui/manual_div_ceil_with_feature.rs:74:13 | LL | let _ = (x + 7) / 8; | ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:57:13 + --> tests/ui/manual_div_ceil_with_feature.rs:76:13 | LL | let _ = (7 + x) / 8; | ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(8)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:60:13 + --> tests/ui/manual_div_ceil_with_feature.rs:80:13 | LL | let _ = (y + -8) / -7; | ^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `y.div_ceil(-7)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:61:13 + --> tests/ui/manual_div_ceil_with_feature.rs:82:13 | LL | let _ = (-8 + y) / -7; | ^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `y.div_ceil(-7)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil_with_feature.rs:62:13 + --> tests/ui/manual_div_ceil_with_feature.rs:84:13 | LL | let _ = (y - 8) / -7; | ^^^^^^^^^^^^ help: consider using `.div_ceil()`: `y.div_ceil(-7)` diff --git a/tests/ui/manual_filter.rs b/tests/ui/manual_filter.rs index 0ac6cbefc4ec..a83a316f95ad 100644 --- a/tests/ui/manual_filter.rs +++ b/tests/ui/manual_filter.rs @@ -3,6 +3,7 @@ fn main() { match Some(0) { + //~^ manual_filter None => None, Some(x) => { if x > 0 { @@ -14,6 +15,7 @@ fn main() { }; match Some(1) { + //~^ manual_filter Some(x) => { if x > 0 { None @@ -25,6 +27,7 @@ fn main() { }; match Some(2) { + //~^ manual_filter Some(x) => { if x > 0 { None @@ -36,6 +39,7 @@ fn main() { }; match Some(3) { + //~^ manual_filter Some(x) => { if x > 0 { Some(x) @@ -48,6 +52,7 @@ fn main() { let y = Some(4); match y { + //~^ manual_filter // Some(4) None => None, Some(x) => { @@ -60,6 +65,7 @@ fn main() { }; match Some(5) { + //~^ manual_filter Some(x) => { if x > 0 { Some(x) @@ -71,6 +77,7 @@ fn main() { }; match Some(6) { + //~^ manual_filter Some(ref x) => { if x > &0 { Some(x) @@ -83,6 +90,7 @@ fn main() { let external_cond = true; match Some(String::new()) { + //~^ manual_filter Some(x) => { if external_cond { Some(x) @@ -94,12 +102,14 @@ fn main() { }; if let Some(x) = Some(7) { + //~^ manual_filter if external_cond { Some(x) } else { None } } else { None }; match &Some(8) { + //~^ manual_filter &Some(x) => { if x != 0 { Some(x) @@ -111,6 +121,7 @@ fn main() { }; match Some(9) { + //~^ manual_filter Some(x) => { if x > 10 && x < 100 { Some(x) @@ -137,6 +148,7 @@ fn main() { #[allow(clippy::blocks_in_conditions)] match Some(11) { + //~^ manual_filter // Lint, statement is preserved by `.filter` Some(x) => { if { @@ -181,6 +193,7 @@ fn main() { true } let _ = match Some(14) { + //~^ manual_filter Some(x) => { if unsafe { f(x) } { Some(x) @@ -191,6 +204,7 @@ fn main() { None => None, }; let _ = match Some(15) { + //~^ manual_filter Some(x) => unsafe { if f(x) { Some(x) } else { None } }, None => None, }; @@ -199,6 +213,7 @@ fn main() { if let Some(_) = Some(16) { Some(16) } else if let Some(x) = Some(16) { + //~^ manual_filter // Lint starting from here if x % 2 == 0 { Some(x) } else { None } } else { diff --git a/tests/ui/manual_filter.stderr b/tests/ui/manual_filter.stderr index 3add706d7f73..63463997f435 100644 --- a/tests/ui/manual_filter.stderr +++ b/tests/ui/manual_filter.stderr @@ -2,9 +2,9 @@ error: manual implementation of `Option::filter` --> tests/ui/manual_filter.rs:5:5 | LL | / match Some(0) { +LL | | LL | | None => None, LL | | Some(x) => { -LL | | if x > 0 { ... | LL | | }, LL | | }; @@ -14,93 +14,94 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:16:5 + --> tests/ui/manual_filter.rs:17:5 | LL | / match Some(1) { +LL | | LL | | Some(x) => { LL | | if x > 0 { -LL | | None ... | LL | | None => None, LL | | }; | |_____^ help: try: `Some(1).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:27:5 + --> tests/ui/manual_filter.rs:29:5 | LL | / match Some(2) { +LL | | LL | | Some(x) => { LL | | if x > 0 { -LL | | None ... | LL | | _ => None, LL | | }; | |_____^ help: try: `Some(2).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:38:5 + --> tests/ui/manual_filter.rs:41:5 | LL | / match Some(3) { +LL | | LL | | Some(x) => { LL | | if x > 0 { -LL | | Some(x) ... | LL | | None => None, LL | | }; | |_____^ help: try: `Some(3).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:50:5 + --> tests/ui/manual_filter.rs:54:5 | LL | / match y { +LL | | LL | | // Some(4) LL | | None => None, -LL | | Some(x) => { ... | LL | | }, LL | | }; | |_____^ help: try: `y.filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:62:5 + --> tests/ui/manual_filter.rs:67:5 | LL | / match Some(5) { +LL | | LL | | Some(x) => { LL | | if x > 0 { -LL | | Some(x) ... | LL | | _ => None, LL | | }; | |_____^ help: try: `Some(5).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:73:5 + --> tests/ui/manual_filter.rs:79:5 | LL | / match Some(6) { +LL | | LL | | Some(ref x) => { LL | | if x > &0 { -LL | | Some(x) ... | LL | | _ => None, LL | | }; | |_____^ help: try: `Some(6).as_ref().filter(|&x| x > &0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:85:5 + --> tests/ui/manual_filter.rs:92:5 | LL | / match Some(String::new()) { +LL | | LL | | Some(x) => { LL | | if external_cond { -LL | | Some(x) ... | LL | | _ => None, LL | | }; | |_____^ help: try: `Some(String::new()).filter(|x| external_cond)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:96:5 + --> tests/ui/manual_filter.rs:104:5 | LL | / if let Some(x) = Some(7) { +LL | | LL | | if external_cond { Some(x) } else { None } LL | | } else { LL | | None @@ -108,36 +109,36 @@ LL | | }; | |_____^ help: try: `Some(7).filter(|&x| external_cond)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:102:5 + --> tests/ui/manual_filter.rs:111:5 | LL | / match &Some(8) { +LL | | LL | | &Some(x) => { LL | | if x != 0 { -LL | | Some(x) ... | LL | | _ => None, LL | | }; | |_____^ help: try: `Some(8).filter(|&x| x != 0)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:113:5 + --> tests/ui/manual_filter.rs:123:5 | LL | / match Some(9) { +LL | | LL | | Some(x) => { LL | | if x > 10 && x < 100 { -LL | | Some(x) ... | LL | | None => None, LL | | }; | |_____^ help: try: `Some(9).filter(|&x| x > 10 && x < 100)` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:139:5 + --> tests/ui/manual_filter.rs:150:5 | LL | / match Some(11) { +LL | | LL | | // Lint, statement is preserved by `.filter` LL | | Some(x) => { -LL | | if { ... | LL | | None => None, LL | | }; @@ -152,33 +153,35 @@ LL ~ }); | error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:183:13 + --> tests/ui/manual_filter.rs:195:13 | LL | let _ = match Some(14) { | _____________^ +LL | | LL | | Some(x) => { LL | | if unsafe { f(x) } { -LL | | Some(x) ... | LL | | None => None, LL | | }; | |_____^ help: try: `Some(14).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:193:13 + --> tests/ui/manual_filter.rs:206:13 | LL | let _ = match Some(15) { | _____________^ +LL | | LL | | Some(x) => unsafe { if f(x) { Some(x) } else { None } }, LL | | None => None, LL | | }; | |_____^ help: try: `Some(15).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> tests/ui/manual_filter.rs:201:12 + --> tests/ui/manual_filter.rs:215:12 | LL | } else if let Some(x) = Some(16) { | ____________^ +LL | | LL | | // Lint starting from here LL | | if x % 2 == 0 { Some(x) } else { None } LL | | } else { diff --git a/tests/ui/manual_filter_map.fixed b/tests/ui/manual_filter_map.fixed index a44c46c145c6..caf82289031f 100644 --- a/tests/ui/manual_filter_map.fixed +++ b/tests/ui/manual_filter_map.fixed @@ -7,12 +7,15 @@ fn main() { // is_some(), unwrap() let _ = (0..).filter_map(|a| to_opt(a)); + //~^ manual_filter_map // ref pattern, expect() let _ = (0..).filter_map(|a| to_opt(a)); + //~^ manual_filter_map // is_ok(), unwrap_or() let _ = (0..).filter_map(|a| to_res(a).ok()); + //~^ manual_filter_map let _ = (1..5) .filter_map(|y| *to_ref(to_opt(y))); @@ -28,17 +31,28 @@ fn main() { #[rustfmt::skip] fn simple_equal() { iter::>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option<&u8>>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option>().find_map(|x| x.as_deref()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned()); + //~^ manual_find_map iter::>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.as_deref().ok()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned().ok()); + //~^ manual_find_map } fn no_lint() { diff --git a/tests/ui/manual_filter_map.rs b/tests/ui/manual_filter_map.rs index e72d0c4305b3..75e15d3b5a5a 100644 --- a/tests/ui/manual_filter_map.rs +++ b/tests/ui/manual_filter_map.rs @@ -7,42 +7,60 @@ fn main() { // is_some(), unwrap() let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); + //~^ manual_filter_map // ref pattern, expect() let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); + //~^ manual_filter_map // is_ok(), unwrap_or() let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); + //~^ manual_filter_map let _ = (1..5) .filter(|&x| to_ref(to_opt(x)).is_some()) + //~^ manual_filter_map .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) .filter(|x| to_ref(to_opt(*x)).is_some()) + //~^ manual_filter_map .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) .filter(|&x| to_ref(to_res(x)).is_ok()) + //~^ manual_filter_map .map(|y| to_ref(to_res(y)).unwrap()); let _ = (1..5) .filter(|x| to_ref(to_res(*x)).is_ok()) + //~^ manual_filter_map .map(|y| to_ref(to_res(y)).unwrap()); } #[rustfmt::skip] fn simple_equal() { iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map } fn no_lint() { @@ -91,46 +109,55 @@ fn issue_8920() { let _ = vec .iter() .filter(|f| f.option_field.is_some()) + //~^ manual_filter_map .map(|f| f.option_field.clone().unwrap()); let _ = vec .iter() .filter(|f| f.ref_field.is_some()) + //~^ manual_filter_map .map(|f| f.ref_field.cloned().unwrap()); let _ = vec .iter() .filter(|f| f.ref_field.is_some()) + //~^ manual_filter_map .map(|f| f.ref_field.copied().unwrap()); let _ = vec .iter() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.clone().unwrap()); let _ = vec .iter() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.as_ref().unwrap()); let _ = vec .iter() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.as_deref().unwrap()); let _ = vec .iter_mut() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.as_mut().unwrap()); let _ = vec .iter_mut() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.as_deref_mut().unwrap()); let _ = vec .iter() .filter(|f| f.result_field.is_ok()) + //~^ manual_filter_map .map(|f| f.result_field.to_owned().unwrap()); } @@ -144,6 +171,7 @@ fn issue8010() { let iter = [Enum::A(123), Enum::B].into_iter(); let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { + //~^ manual_filter_map Enum::A(s) => s, _ => unreachable!(), }); @@ -154,6 +182,7 @@ fn issue8010() { let _x = iter .clone() .filter(|x| matches!(x, Enum::A(_))) + //~^ manual_filter_map .map(|x| if let Enum::A(s) = x { s } else { unreachable!() }); #[allow(clippy::unused_unit)] let _x = iter diff --git a/tests/ui/manual_filter_map.stderr b/tests/ui/manual_filter_map.stderr index 2e5056727831..07c894bf0e66 100644 --- a/tests/ui/manual_filter_map.stderr +++ b/tests/ui/manual_filter_map.stderr @@ -13,87 +13,91 @@ LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap = help: to override `-D warnings` add `#[allow(clippy::manual_filter_map)]` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:12:19 + --> tests/ui/manual_filter_map.rs:13: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 - --> tests/ui/manual_filter_map.rs:12:31 + --> tests/ui/manual_filter_map.rs:13: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(..)` - --> tests/ui/manual_filter_map.rs:15:19 + --> tests/ui/manual_filter_map.rs:17: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 - --> tests/ui/manual_filter_map.rs:15:31 + --> tests/ui/manual_filter_map.rs:17: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(..)` - --> tests/ui/manual_filter_map.rs:18:10 + --> tests/ui/manual_filter_map.rs:21:10 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | __________^ +LL | | 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 - --> tests/ui/manual_filter_map.rs:18:22 + --> tests/ui/manual_filter_map.rs:21:22 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:21:10 + --> tests/ui/manual_filter_map.rs:25:10 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | __________^ +LL | | 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 - --> tests/ui/manual_filter_map.rs:21:21 + --> tests/ui/manual_filter_map.rs:25:21 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:25:10 + --> tests/ui/manual_filter_map.rs:30:10 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | __________^ +LL | | 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 - --> tests/ui/manual_filter_map.rs:25:22 + --> tests/ui/manual_filter_map.rs:30:22 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:28:10 + --> tests/ui/manual_filter_map.rs:34:10 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | __________^ +LL | | 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 - --> tests/ui/manual_filter_map.rs:28:21 + --> tests/ui/manual_filter_map.rs:34:21 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_filter_map.rs:34:27 + --> tests/ui/manual_filter_map.rs:41:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` @@ -102,164 +106,175 @@ LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap() = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_filter_map.rs:35:28 + --> tests/ui/manual_filter_map.rs:43: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(..)` - --> tests/ui/manual_filter_map.rs:36:31 + --> tests/ui/manual_filter_map.rs:45: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(..)` - --> tests/ui/manual_filter_map.rs:37:31 + --> tests/ui/manual_filter_map.rs:47: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 - --> tests/ui/manual_filter_map.rs:37:41 + --> tests/ui/manual_filter_map.rs:47: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(..)` - --> tests/ui/manual_filter_map.rs:39:30 + --> tests/ui/manual_filter_map.rs:50: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(..)` - --> tests/ui/manual_filter_map.rs:40:31 + --> tests/ui/manual_filter_map.rs:52: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(..)` - --> tests/ui/manual_filter_map.rs:41:32 + --> tests/ui/manual_filter_map.rs:54: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(..)` - --> tests/ui/manual_filter_map.rs:42:31 + --> tests/ui/manual_filter_map.rs:56: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(..)` - --> tests/ui/manual_filter_map.rs:43:32 + --> tests/ui/manual_filter_map.rs:58: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(..)` - --> tests/ui/manual_filter_map.rs:44:35 + --> tests/ui/manual_filter_map.rs:60: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(..)` - --> tests/ui/manual_filter_map.rs:45:35 + --> tests/ui/manual_filter_map.rs:62: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 - --> tests/ui/manual_filter_map.rs:45:45 + --> tests/ui/manual_filter_map.rs:62: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(..)` - --> tests/ui/manual_filter_map.rs:93:10 + --> tests/ui/manual_filter_map.rs:111:10 | LL | .filter(|f| f.option_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:98:10 + --> tests/ui/manual_filter_map.rs:117:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:103:10 + --> tests/ui/manual_filter_map.rs:123:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:108:10 + --> tests/ui/manual_filter_map.rs:129:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:113:10 + --> tests/ui/manual_filter_map.rs:135:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:118:10 + --> tests/ui/manual_filter_map.rs:141:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:123:10 + --> tests/ui/manual_filter_map.rs:147:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:128:10 + --> tests/ui/manual_filter_map.rs:153:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_filter_map.rs:133:10 + --> tests/ui/manual_filter_map.rs:159:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ +LL | | LL | | .map(|f| f.result_field.to_owned().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:146:27 + --> tests/ui/manual_filter_map.rs:173:27 | LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { | ___________________________^ +LL | | LL | | Enum::A(s) => s, LL | | _ => unreachable!(), LL | | }); | |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:156:10 + --> tests/ui/manual_filter_map.rs:184:10 | LL | .filter(|x| matches!(x, Enum::A(_))) | __________^ +LL | | LL | | .map(|x| if let Enum::A(s) = x { s } else { unreachable!() }); | |_____________________________________________________________________^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` diff --git a/tests/ui/manual_find.rs b/tests/ui/manual_find.rs index 0a105b0359e5..d3c24d0b8849 100644 --- a/tests/ui/manual_find.rs +++ b/tests/ui/manual_find.rs @@ -3,8 +3,9 @@ //@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 + //~^ manual_find + + if s == String::new() { return Some(s); } @@ -14,8 +15,9 @@ 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 + //~^ manual_find + + if s == String::new() { return Some(s); } diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index a4e7878a247c..2dbe0b16b75a 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -2,9 +2,6 @@ error: manual implementation of `Iterator::find` --> tests/ui/manual_find.rs:5:5 | LL | / for s in strings { -LL | | -LL | | -LL | | if s == String::new() { ... | LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` @@ -14,12 +11,9 @@ LL | | None = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find.rs:16:5 + --> tests/ui/manual_find.rs:17:5 | LL | / for (s, _) in arr { -LL | | -LL | | -LL | | if s == String::new() { ... | LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(s, _)| s).find(|s| s == String::new())` diff --git a/tests/ui/manual_find_fixable.rs b/tests/ui/manual_find_fixable.rs index 56c3f2629c7a..3966d8df89b9 100644 --- a/tests/ui/manual_find_fixable.rs +++ b/tests/ui/manual_find_fixable.rs @@ -8,6 +8,7 @@ const ARRAY: &[u32; 5] = &[2, 7, 1, 9, 3]; fn lookup(n: u32) -> Option { for &v in ARRAY { + //~^ manual_find if v == n { return Some(v); } @@ -17,6 +18,7 @@ fn lookup(n: u32) -> Option { fn with_pat(arr: Vec<(u32, u32)>) -> Option { for (a, _) in arr { + //~^ manual_find if a % 2 == 0 { return Some(a); } @@ -30,6 +32,7 @@ struct Data { } fn with_struct(arr: Vec) -> Option { for el in arr { + //~^ manual_find if el.name.len() == 10 { return Some(el); } @@ -40,6 +43,7 @@ fn with_struct(arr: Vec) -> Option { struct Tuple(usize, usize); fn with_tuple_struct(arr: Vec) -> Option { for Tuple(a, _) in arr { + //~^ manual_find if a >= 3 { return Some(a); } @@ -55,6 +59,7 @@ impl A { } fn with_method_call(arr: Vec) -> Option { for el in arr { + //~^ manual_find if el.should_keep() { return Some(el); } @@ -65,6 +70,7 @@ fn with_method_call(arr: Vec) -> Option { fn with_closure(arr: Vec) -> Option { let f = |el: u32| -> u32 { el + 10 }; for el in arr { + //~^ manual_find if f(el) == 20 { return Some(el); } @@ -75,6 +81,7 @@ fn with_closure(arr: Vec) -> Option { fn with_closure2(arr: HashMap) -> Option { let f = |el: i32| -> bool { el == 10 }; for &el in arr.values() { + //~^ manual_find if f(el) { return Some(el); } @@ -84,6 +91,7 @@ fn with_closure2(arr: HashMap) -> Option { fn with_bool(arr: Vec) -> Option { for el in arr { + //~^ manual_find if el.is_true { return Some(el); } @@ -114,6 +122,7 @@ fn with_else(arr: Vec) -> Option { fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { for (_, &x) in v { + //~^ manual_find if x > 10 { return Some(x); } @@ -123,6 +132,7 @@ fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { for &(_, &x) in v { + //~^ manual_find if x > 10 { return Some(x); } @@ -132,6 +142,7 @@ fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { fn explicit_ret(arr: Vec) -> Option { for x in arr { + //~^ manual_find if x >= 5 { return Some(x); } @@ -187,6 +198,7 @@ fn as_closure() { #[rustfmt::skip] let f = |arr: Vec| -> Option { for x in arr { + //~^ manual_find if x < 1 { return Some(x); } diff --git a/tests/ui/manual_find_fixable.stderr b/tests/ui/manual_find_fixable.stderr index 5ed8be1b3eed..afa453c5a876 100644 --- a/tests/ui/manual_find_fixable.stderr +++ b/tests/ui/manual_find_fixable.stderr @@ -2,6 +2,7 @@ error: manual implementation of `Iterator::find` --> tests/ui/manual_find_fixable.rs:10:5 | LL | / for &v in ARRAY { +LL | | LL | | if v == n { LL | | return Some(v); ... | @@ -12,9 +13,10 @@ LL | | None = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:19:5 + --> tests/ui/manual_find_fixable.rs:20:5 | LL | / for (a, _) in arr { +LL | | LL | | if a % 2 == 0 { LL | | return Some(a); ... | @@ -22,9 +24,10 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:32:5 + --> tests/ui/manual_find_fixable.rs:34:5 | LL | / for el in arr { +LL | | LL | | if el.name.len() == 10 { LL | | return Some(el); ... | @@ -34,9 +37,10 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:42:5 + --> tests/ui/manual_find_fixable.rs:45:5 | LL | / for Tuple(a, _) in arr { +LL | | LL | | if a >= 3 { LL | | return Some(a); ... | @@ -44,9 +48,10 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:57:5 + --> tests/ui/manual_find_fixable.rs:61:5 | LL | / for el in arr { +LL | | LL | | if el.should_keep() { LL | | return Some(el); ... | @@ -56,9 +61,10 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:67:5 + --> tests/ui/manual_find_fixable.rs:72:5 | LL | / for el in arr { +LL | | LL | | if f(el) == 20 { LL | | return Some(el); ... | @@ -66,9 +72,10 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().find(|&el| f(el) == 20)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:77:5 + --> tests/ui/manual_find_fixable.rs:83:5 | LL | / for &el in arr.values() { +LL | | LL | | if f(el) { LL | | return Some(el); ... | @@ -76,9 +83,10 @@ LL | | None | |________^ help: replace with an iterator: `arr.values().find(|&&el| f(el)).copied()` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:86:5 + --> tests/ui/manual_find_fixable.rs:93:5 | LL | / for el in arr { +LL | | LL | | if el.is_true { LL | | return Some(el); ... | @@ -88,9 +96,10 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:116:5 + --> tests/ui/manual_find_fixable.rs:124:5 | LL | / for (_, &x) in v { +LL | | LL | | if x > 10 { LL | | return Some(x); ... | @@ -98,9 +107,10 @@ LL | | None | |________^ help: replace with an iterator: `v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:125:5 + --> tests/ui/manual_find_fixable.rs:134:5 | LL | / for &(_, &x) in v { +LL | | LL | | if x > 10 { LL | | return Some(x); ... | @@ -108,9 +118,10 @@ LL | | None | |________^ help: replace with an iterator: `v.iter().map(|&(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:134:5 + --> tests/ui/manual_find_fixable.rs:144:5 | LL | / for x in arr { +LL | | LL | | if x >= 5 { LL | | return Some(x); ... | @@ -118,9 +129,10 @@ LL | | return None; | |________________^ help: replace with an iterator: `arr.into_iter().find(|&x| x >= 5)` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find_fixable.rs:189:9 + --> tests/ui/manual_find_fixable.rs:200:9 | LL | / for x in arr { +LL | | LL | | if x < 1 { LL | | return Some(x); ... | diff --git a/tests/ui/manual_find_map.fixed b/tests/ui/manual_find_map.fixed index 2d9a356b9bcd..1a452d50261f 100644 --- a/tests/ui/manual_find_map.fixed +++ b/tests/ui/manual_find_map.fixed @@ -7,12 +7,15 @@ fn main() { // is_some(), unwrap() let _ = (0..).find_map(|a| to_opt(a)); + //~^ manual_find_map // ref pattern, expect() let _ = (0..).find_map(|a| to_opt(a)); + //~^ manual_find_map // is_ok(), unwrap_or() let _ = (0..).find_map(|a| to_res(a).ok()); + //~^ manual_find_map let _ = (1..5) .find_map(|y| *to_ref(to_opt(y))); @@ -28,20 +31,34 @@ fn main() { #[rustfmt::skip] fn simple_equal() { iter::>().find_map(|x| x); + //~^ manual_find_map iter::<&Option>().find_map(|x| *x); + //~^ manual_find_map iter::<&&Option>().find_map(|x| **x); + //~^ manual_find_map iter::>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option<&u8>>().find_map(|x| x.cloned()); + //~^ manual_find_map iter::<&Option>().find_map(|x| x.as_deref()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned()); + //~^ manual_find_map iter::>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::<&&Result>().find_map(|x| x.ok()); + //~^ manual_find_map iter::>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find_map(|x| x.cloned().ok()); + //~^ manual_find_map iter::<&Result>().find_map(|x| x.as_deref().ok()); + //~^ manual_find_map iter::>().find_map(|y| to_ref(y).cloned().ok()); + //~^ manual_find_map } fn no_lint() { diff --git a/tests/ui/manual_find_map.rs b/tests/ui/manual_find_map.rs index 7c5cc136695a..9415a2d2b572 100644 --- a/tests/ui/manual_find_map.rs +++ b/tests/ui/manual_find_map.rs @@ -7,45 +7,66 @@ fn main() { // is_some(), unwrap() let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); + //~^ manual_find_map // ref pattern, expect() let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); + //~^ manual_find_map // is_ok(), unwrap_or() let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); + //~^ manual_find_map let _ = (1..5) .find(|&x| to_ref(to_opt(x)).is_some()) + //~^ manual_find_map .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) .find(|x| to_ref(to_opt(*x)).is_some()) + //~^ manual_find_map .map(|y| to_ref(to_opt(y)).unwrap()); let _ = (1..5) .find(|&x| to_ref(to_res(x)).is_ok()) + //~^ manual_find_map .map(|y| to_ref(to_res(y)).unwrap()); let _ = (1..5) .find(|x| to_ref(to_res(*x)).is_ok()) + //~^ manual_find_map .map(|y| to_ref(to_res(y)).unwrap()); } #[rustfmt::skip] fn simple_equal() { iter::>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); + //~^ manual_find_map iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); + //~^ manual_find_map iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); + //~^ manual_find_map iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); + //~^ manual_find_map } fn no_lint() { @@ -94,45 +115,54 @@ fn issue_8920() { let _ = vec .iter() .find(|f| f.option_field.is_some()) + //~^ manual_find_map .map(|f| f.option_field.clone().unwrap()); let _ = vec .iter() .find(|f| f.ref_field.is_some()) + //~^ manual_find_map .map(|f| f.ref_field.cloned().unwrap()); let _ = vec .iter() .find(|f| f.ref_field.is_some()) + //~^ manual_find_map .map(|f| f.ref_field.copied().unwrap()); let _ = vec .iter() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.clone().unwrap()); let _ = vec .iter() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.as_ref().unwrap()); let _ = vec .iter() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.as_deref().unwrap()); let _ = vec .iter_mut() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.as_mut().unwrap()); let _ = vec .iter_mut() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.as_deref_mut().unwrap()); let _ = vec .iter() .find(|f| f.result_field.is_ok()) + //~^ manual_find_map .map(|f| f.result_field.to_owned().unwrap()); } diff --git a/tests/ui/manual_find_map.stderr b/tests/ui/manual_find_map.stderr index 2722d59f52a9..8fa6c090e6d2 100644 --- a/tests/ui/manual_find_map.stderr +++ b/tests/ui/manual_find_map.stderr @@ -13,250 +13,263 @@ LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap() = help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_find_map.rs:12:19 + --> tests/ui/manual_find_map.rs:13: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 - --> tests/ui/manual_find_map.rs:12:29 + --> tests/ui/manual_find_map.rs:13: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(..)` - --> tests/ui/manual_find_map.rs:15:19 + --> tests/ui/manual_find_map.rs:17: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 - --> tests/ui/manual_find_map.rs:15:29 + --> tests/ui/manual_find_map.rs:17: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(..)` - --> tests/ui/manual_find_map.rs:18:10 + --> tests/ui/manual_find_map.rs:21:10 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | __________^ +LL | | 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 - --> tests/ui/manual_find_map.rs:18:20 + --> tests/ui/manual_find_map.rs:21:20 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_find_map.rs:21:10 + --> tests/ui/manual_find_map.rs:25:10 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | __________^ +LL | | 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 - --> tests/ui/manual_find_map.rs:21:19 + --> tests/ui/manual_find_map.rs:25:19 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_find_map.rs:25:10 + --> tests/ui/manual_find_map.rs:30:10 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | __________^ +LL | | 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 - --> tests/ui/manual_find_map.rs:25:20 + --> tests/ui/manual_find_map.rs:30:20 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_find_map.rs:28:10 + --> tests/ui/manual_find_map.rs:34:10 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | __________^ +LL | | 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 - --> tests/ui/manual_find_map.rs:28:19 + --> tests/ui/manual_find_map.rs:34:19 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> tests/ui/manual_find_map.rs:34:26 + --> tests/ui/manual_find_map.rs:41: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(..)` - --> tests/ui/manual_find_map.rs:35:27 + --> tests/ui/manual_find_map.rs:43: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(..)` - --> tests/ui/manual_find_map.rs:36:28 + --> tests/ui/manual_find_map.rs:45: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(..)` - --> tests/ui/manual_find_map.rs:37:27 + --> tests/ui/manual_find_map.rs:47: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(..)` - --> tests/ui/manual_find_map.rs:38:28 + --> tests/ui/manual_find_map.rs:49: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(..)` - --> tests/ui/manual_find_map.rs:39:31 + --> tests/ui/manual_find_map.rs:51: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(..)` - --> tests/ui/manual_find_map.rs:40:31 + --> tests/ui/manual_find_map.rs:53: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 - --> tests/ui/manual_find_map.rs:40:41 + --> tests/ui/manual_find_map.rs:53: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(..)` - --> tests/ui/manual_find_map.rs:42:30 + --> tests/ui/manual_find_map.rs:56: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(..)` - --> tests/ui/manual_find_map.rs:43:31 + --> tests/ui/manual_find_map.rs:58: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(..)` - --> tests/ui/manual_find_map.rs:44:32 + --> tests/ui/manual_find_map.rs:60: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(..)` - --> tests/ui/manual_find_map.rs:45:31 + --> tests/ui/manual_find_map.rs:62: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(..)` - --> tests/ui/manual_find_map.rs:46:32 + --> tests/ui/manual_find_map.rs:64: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(..)` - --> tests/ui/manual_find_map.rs:47:35 + --> tests/ui/manual_find_map.rs:66: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(..)` - --> tests/ui/manual_find_map.rs:48:35 + --> tests/ui/manual_find_map.rs:68: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 - --> tests/ui/manual_find_map.rs:48:45 + --> tests/ui/manual_find_map.rs:68: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(..)` - --> tests/ui/manual_find_map.rs:96:10 + --> tests/ui/manual_find_map.rs:117:10 | LL | .find(|f| f.option_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:101:10 + --> tests/ui/manual_find_map.rs:123:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:106:10 + --> tests/ui/manual_find_map.rs:129:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:111:10 + --> tests/ui/manual_find_map.rs:135:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:116:10 + --> tests/ui/manual_find_map.rs:141:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:121:10 + --> tests/ui/manual_find_map.rs:147:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:126:10 + --> tests/ui/manual_find_map.rs:153:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:131:10 + --> tests/ui/manual_find_map.rs:159:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | 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(..)` - --> tests/ui/manual_find_map.rs:136:10 + --> tests/ui/manual_find_map.rs:165:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ +LL | | LL | | .map(|f| f.result_field.to_owned().unwrap()); | |____________________________________________________^ help: try: `find_map(|f| f.result_field.to_owned().ok())` diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs index d57333ace040..e22025c6f1a8 100644 --- a/tests/ui/manual_flatten.rs +++ b/tests/ui/manual_flatten.rs @@ -5,7 +5,8 @@ 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 + //~^ manual_flatten + if let Some(y) = n { println!("{}", y); } @@ -14,7 +15,8 @@ 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 + //~^ manual_flatten + if let Ok(n) = n { println!("{}", n); }; @@ -22,7 +24,8 @@ 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 + //~^ manual_flatten + if let Ok(n) = n { println!("{}", n); } @@ -31,7 +34,8 @@ 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 + //~^ manual_flatten + if let Ok(n) = n { println!("{}", n); } @@ -41,7 +45,8 @@ 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 + //~^ manual_flatten + if let Some(m) = n { println!("{}", m); } @@ -75,7 +80,8 @@ 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 + //~^ manual_flatten + if let Some(n) = n { println!("{:?}", n); } @@ -83,7 +89,8 @@ 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 + //~^ manual_flatten + if let Some(n) = n { println!("{:?}", n); } @@ -91,7 +98,8 @@ 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 + //~^ manual_flatten + if let Some(n) = n { println!("{:?}", n); } @@ -122,7 +130,8 @@ 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 + //~^ manual_flatten + Some(1), Some(2), Some(3) diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index cf1b0a1c8bbf..564c0eba8260 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -6,14 +6,14 @@ LL | for n in x { | _____| | | LL | | +LL | | LL | | if let Some(y) = n { -LL | | println!("{}", y); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:9:9 + --> tests/ui/manual_flatten.rs:10:9 | LL | / if let Some(y) = n { LL | | println!("{}", y); @@ -23,13 +23,14 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_flatten)]` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:16:5 + --> tests/ui/manual_flatten.rs:17:5 | LL | for n in y.clone() { | ^ --------- help: try: `y.clone().into_iter().flatten()` | _____| | | LL | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | }; @@ -37,7 +38,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:18:9 + --> tests/ui/manual_flatten.rs:20:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -45,21 +46,21 @@ LL | | }; | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:24:5 + --> tests/ui/manual_flatten.rs:26:5 | LL | for n in &y { | ^ -- help: try: `y.iter().flatten()` | _____| | | LL | | +LL | | LL | | if let Ok(n) = n { -LL | | println!("{}", n); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:26:9 + --> tests/ui/manual_flatten.rs:29:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -67,21 +68,21 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:33:5 + --> tests/ui/manual_flatten.rs:36:5 | LL | for n in z { | ^ - help: try: `z.iter().flatten()` | _____| | | LL | | +LL | | LL | | if let Ok(n) = n { -LL | | println!("{}", n); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:35:9 + --> tests/ui/manual_flatten.rs:39:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -89,21 +90,21 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:43:5 + --> tests/ui/manual_flatten.rs:47:5 | LL | for n in z { | ^ - help: try: `z.flatten()` | _____| | | LL | | +LL | | LL | | if let Some(m) = n { -LL | | println!("{}", m); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:45:9 + --> tests/ui/manual_flatten.rs:50:9 | LL | / if let Some(m) = n { LL | | println!("{}", m); @@ -111,21 +112,21 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:77:5 + --> tests/ui/manual_flatten.rs:82:5 | LL | for n in &vec_of_ref { | ^ ----------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | LL | | +LL | | LL | | if let Some(n) = n { -LL | | println!("{:?}", n); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:79:9 + --> tests/ui/manual_flatten.rs:85:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -133,21 +134,21 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:85:5 + --> tests/ui/manual_flatten.rs:91:5 | LL | for n in vec_of_ref { | ^ ---------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | LL | | +LL | | LL | | if let Some(n) = n { -LL | | println!("{:?}", n); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:87:9 + --> tests/ui/manual_flatten.rs:94:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -155,21 +156,21 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:93:5 + --> tests/ui/manual_flatten.rs:100:5 | LL | for n in slice_of_ref { | ^ ------------ help: try: `slice_of_ref.iter().copied().flatten()` | _____| | | LL | | +LL | | LL | | if let Some(n) = n { -LL | | println!("{:?}", n); -LL | | } +... | LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> tests/ui/manual_flatten.rs:95:9 + --> tests/ui/manual_flatten.rs:103:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -177,18 +178,18 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> tests/ui/manual_flatten.rs:124:5 + --> tests/ui/manual_flatten.rs:132:5 | LL | / for n in vec![ LL | | +LL | | LL | | Some(1), -LL | | Some(2), ... | LL | | } | |_____^ | help: remove the `if let` statement in the for loop and then... - --> tests/ui/manual_flatten.rs:130:9 + --> tests/ui/manual_flatten.rs:139:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -198,6 +199,7 @@ help: try | LL ~ for n in vec![ LL + +LL + LL + Some(1), LL + Some(2), LL + Some(3) diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index 66545d180ef9..62cdc1c141d0 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -22,12 +22,18 @@ fn fn_test_not_inf() -> f64 { fn main() { let x = 1.0f32; if x == f32::INFINITY || x == f32::NEG_INFINITY {} + //~^ manual_is_infinite if x != f32::INFINITY && x != f32::NEG_INFINITY {} + //~^ manual_is_finite if x == INFINITE || x == NEG_INFINITE {} + //~^ manual_is_infinite if x != INFINITE && x != NEG_INFINITE {} + //~^ manual_is_finite let x = 1.0f64; if x == f64::INFINITY || x == f64::NEG_INFINITY {} + //~^ manual_is_infinite if x != f64::INFINITY && x != f64::NEG_INFINITY {} + //~^ manual_is_finite // Don't lint if x.is_infinite() {} if x.is_finite() {} @@ -42,6 +48,7 @@ fn main() { const { let x = 1.0f64; if x == f64::INFINITY || x == f64::NEG_INFINITY {} + //~^ manual_is_infinite } const X: f64 = 1.0f64; if const { X == f64::INFINITY || X == f64::NEG_INFINITY } {} diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 676a4485ab4d..d2ed50642178 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -8,7 +8,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite - --> tests/ui/manual_float_methods.rs:25:8 + --> tests/ui/manual_float_methods.rs:26:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,13 +29,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:26:8 + --> tests/ui/manual_float_methods.rs:28: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 - --> tests/ui/manual_float_methods.rs:27:8 + --> tests/ui/manual_float_methods.rs:30:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:29:8 + --> tests/ui/manual_float_methods.rs:33: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 - --> tests/ui/manual_float_methods.rs:30:8 + --> tests/ui/manual_float_methods.rs:35:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> tests/ui/manual_float_methods.rs:44:12 + --> tests/ui/manual_float_methods.rs:50:12 | LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` diff --git a/tests/ui/manual_hash_one.fixed b/tests/ui/manual_hash_one.fixed index edfd9c4a47bb..e45e4bbc3ce7 100644 --- a/tests/ui/manual_hash_one.fixed +++ b/tests/ui/manual_hash_one.fixed @@ -7,18 +7,21 @@ fn returned(b: impl BuildHasher) -> u64 { b.hash_one(&true) + //~^ manual_hash_one } fn unsized_receiver(b: impl BuildHasher, s: &str) { let _ = b.hash_one(&s[4..10]); + //~^ manual_hash_one } fn owned_value(b: impl BuildHasher, v: Vec) -> Vec { let _ = b.hash_one(&v); + //~^ manual_hash_one v } @@ -86,4 +89,5 @@ fn msrv_1_71(b: impl BuildHasher, v: impl Hash) { let _ = b.hash_one(&v); + //~^ manual_hash_one } diff --git a/tests/ui/manual_hash_one.rs b/tests/ui/manual_hash_one.rs index ee61522853f0..c93e26c8f6bf 100644 --- a/tests/ui/manual_hash_one.rs +++ b/tests/ui/manual_hash_one.rs @@ -7,18 +7,21 @@ fn returned(b: impl BuildHasher) -> u64 { let mut hasher = b.build_hasher(); true.hash(&mut hasher); hasher.finish() + //~^ manual_hash_one } fn unsized_receiver(b: impl BuildHasher, s: &str) { let mut hasher = b.build_hasher(); s[4..10].hash(&mut hasher); let _ = hasher.finish(); + //~^ manual_hash_one } fn owned_value(b: impl BuildHasher, v: Vec) -> Vec { let mut hasher = b.build_hasher(); v.hash(&mut hasher); let _ = hasher.finish(); + //~^ manual_hash_one v } @@ -86,4 +89,5 @@ fn msrv_1_71(b: impl BuildHasher, v: impl Hash) { let mut hasher = b.build_hasher(); v.hash(&mut hasher); let _ = hasher.finish(); + //~^ manual_hash_one } diff --git a/tests/ui/manual_hash_one.stderr b/tests/ui/manual_hash_one.stderr index bcff36d9bafc..b0691e2d396c 100644 --- a/tests/ui/manual_hash_one.stderr +++ b/tests/ui/manual_hash_one.stderr @@ -14,7 +14,7 @@ LL ~ b.hash_one(&true) | error: manual implementation of `BuildHasher::hash_one` - --> tests/ui/manual_hash_one.rs:15:13 + --> tests/ui/manual_hash_one.rs:16:13 | LL | let _ = hasher.finish(); | ^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL ~ let _ = b.hash_one(&s[4..10]); | error: manual implementation of `BuildHasher::hash_one` - --> tests/ui/manual_hash_one.rs:21:13 + --> tests/ui/manual_hash_one.rs:23:13 | LL | let _ = hasher.finish(); | ^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL ~ let _ = b.hash_one(&v); | error: manual implementation of `BuildHasher::hash_one` - --> tests/ui/manual_hash_one.rs:88:13 + --> tests/ui/manual_hash_one.rs:91:13 | LL | let _ = hasher.finish(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_ignore_case_cmp.fixed b/tests/ui/manual_ignore_case_cmp.fixed index 53a124f59c8d..a75b0702a5ff 100644 --- a/tests/ui/manual_ignore_case_cmp.fixed +++ b/tests/ui/manual_ignore_case_cmp.fixed @@ -7,24 +7,34 @@ fn main() {} fn variants(a: &str, b: &str) { if a.eq_ignore_ascii_case(b) { + //~^ manual_ignore_case_cmp return; } if a.eq_ignore_ascii_case(b) { + //~^ manual_ignore_case_cmp return; } let r = a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp let r = r || a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp r && a.eq_ignore_ascii_case(&b.to_uppercase()); + //~^ manual_ignore_case_cmp // != if !a.eq_ignore_ascii_case(b) { + //~^ manual_ignore_case_cmp return; } if !a.eq_ignore_ascii_case(b) { + //~^ manual_ignore_case_cmp return; } let r = !a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp let r = r || !a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp r && !a.eq_ignore_ascii_case(&b.to_uppercase()); + //~^ manual_ignore_case_cmp } fn unsupported(a: char, b: char) { @@ -36,72 +46,111 @@ fn unsupported(a: char, b: char) { fn char(a: char, b: char) { a.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == *&b.to_ascii_lowercase(); *&a.to_ascii_lowercase() == b.to_ascii_lowercase(); a.eq_ignore_ascii_case(&'a'); + //~^ manual_ignore_case_cmp 'a'.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp } fn u8(a: u8, b: u8) { a.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case(&b'a'); + //~^ manual_ignore_case_cmp b'a'.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp } fn ref_str(a: &str, b: &str) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.to_uppercase().eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp } fn ref_ref_str(a: &&str, b: &&str) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.to_uppercase().eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp } fn string(a: String, b: String) { a.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp &a.to_ascii_lowercase() == &b.to_ascii_lowercase(); &&a.to_ascii_lowercase() == &&b.to_ascii_lowercase(); a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp } fn ref_string(a: String, b: &String) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case(&a); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(&a); + //~^ manual_ignore_case_cmp } fn string_ref_str(a: String, b: &str) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp a.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case(&a); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case("a"); + //~^ manual_ignore_case_cmp "a".eq_ignore_ascii_case(&a); + //~^ manual_ignore_case_cmp } fn ref_u8slice(a: &[u8], b: &[u8]) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp } fn u8vec(a: Vec, b: Vec) { a.eq_ignore_ascii_case(&b); + //~^ manual_ignore_case_cmp } fn ref_u8vec(a: Vec, b: &Vec) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case(&a); + //~^ manual_ignore_case_cmp } fn ref_osstr(a: &OsStr, b: &OsStr) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp } fn osstring(a: OsString, b: OsString) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp } fn ref_osstring(a: OsString, b: &OsString) { a.eq_ignore_ascii_case(b); + //~^ manual_ignore_case_cmp b.eq_ignore_ascii_case(a); + //~^ manual_ignore_case_cmp } diff --git a/tests/ui/manual_ignore_case_cmp.rs b/tests/ui/manual_ignore_case_cmp.rs index 2a4d84b30ace..822f171a4506 100644 --- a/tests/ui/manual_ignore_case_cmp.rs +++ b/tests/ui/manual_ignore_case_cmp.rs @@ -7,24 +7,34 @@ fn main() {} fn variants(a: &str, b: &str) { if a.to_ascii_lowercase() == b.to_ascii_lowercase() { + //~^ manual_ignore_case_cmp return; } if a.to_ascii_uppercase() == b.to_ascii_uppercase() { + //~^ manual_ignore_case_cmp return; } let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); + //~^ manual_ignore_case_cmp r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); + //~^ manual_ignore_case_cmp // != if a.to_ascii_lowercase() != b.to_ascii_lowercase() { + //~^ manual_ignore_case_cmp return; } if a.to_ascii_uppercase() != b.to_ascii_uppercase() { + //~^ manual_ignore_case_cmp return; } let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); + //~^ manual_ignore_case_cmp r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn unsupported(a: char, b: char) { @@ -36,72 +46,111 @@ fn unsupported(a: char, b: char) { fn char(a: char, b: char) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == *&b.to_ascii_lowercase(); *&a.to_ascii_lowercase() == b.to_ascii_lowercase(); a.to_ascii_lowercase() == 'a'; + //~^ manual_ignore_case_cmp 'a' == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn u8(a: u8, b: u8) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == b'a'; + //~^ manual_ignore_case_cmp b'a' == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_str(a: &str, b: &str) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_ref_str(a: &&str, b: &&str) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn string(a: String, b: String) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp &a.to_ascii_lowercase() == &b.to_ascii_lowercase(); &&a.to_ascii_lowercase() == &&b.to_ascii_lowercase(); a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_string(a: String, b: &String) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn string_ref_str(a: String, b: &str) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp a.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == "a"; + //~^ manual_ignore_case_cmp "a" == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_u8slice(a: &[u8], b: &[u8]) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn u8vec(a: Vec, b: Vec) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_u8vec(a: Vec, b: &Vec) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_osstr(a: &OsStr, b: &OsStr) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn osstring(a: OsString, b: OsString) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } fn ref_osstring(a: OsString, b: &OsString) { a.to_ascii_lowercase() == b.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp b.to_ascii_lowercase() == a.to_ascii_lowercase(); + //~^ manual_ignore_case_cmp } diff --git a/tests/ui/manual_ignore_case_cmp.stderr b/tests/ui/manual_ignore_case_cmp.stderr index 11e8b8aebb54..14cd8cfc1731 100644 --- a/tests/ui/manual_ignore_case_cmp.stderr +++ b/tests/ui/manual_ignore_case_cmp.stderr @@ -15,7 +15,7 @@ LL | if a.eq_ignore_ascii_case(b) { | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:12:8 + --> tests/ui/manual_ignore_case_cmp.rs:13:8 | LL | if a.to_ascii_uppercase() == b.to_ascii_uppercase() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | if a.eq_ignore_ascii_case(b) { | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:15:13 + --> tests/ui/manual_ignore_case_cmp.rs:17:13 | LL | let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let r = a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:16:18 + --> tests/ui/manual_ignore_case_cmp.rs:19:18 | LL | let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let r = r || a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:17:10 + --> tests/ui/manual_ignore_case_cmp.rs:21:10 | LL | r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,7 +59,7 @@ LL | r && a.eq_ignore_ascii_case(&b.to_uppercase()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:19:8 + --> tests/ui/manual_ignore_case_cmp.rs:24:8 | LL | if a.to_ascii_lowercase() != b.to_ascii_lowercase() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | if !a.eq_ignore_ascii_case(b) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:22:8 + --> tests/ui/manual_ignore_case_cmp.rs:28:8 | LL | if a.to_ascii_uppercase() != b.to_ascii_uppercase() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | if !a.eq_ignore_ascii_case(b) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:25:13 + --> tests/ui/manual_ignore_case_cmp.rs:32:13 | LL | let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | let r = !a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:26:18 + --> tests/ui/manual_ignore_case_cmp.rs:34:18 | LL | let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL | let r = r || !a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:27:10 + --> tests/ui/manual_ignore_case_cmp.rs:36:10 | LL | r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +114,7 @@ LL | r && !a.eq_ignore_ascii_case(&b.to_uppercase()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:38:5 + --> tests/ui/manual_ignore_case_cmp.rs:48:5 | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -125,7 +125,7 @@ LL | a.eq_ignore_ascii_case(&b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:41:5 + --> tests/ui/manual_ignore_case_cmp.rs:52:5 | LL | a.to_ascii_lowercase() == 'a'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | a.eq_ignore_ascii_case(&'a'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:42:5 + --> tests/ui/manual_ignore_case_cmp.rs:54:5 | LL | 'a' == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -147,7 +147,7 @@ LL | 'a'.eq_ignore_ascii_case(&b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:45:5 + --> tests/ui/manual_ignore_case_cmp.rs:58:5 | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -158,7 +158,7 @@ LL | a.eq_ignore_ascii_case(&b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:46:5 + --> tests/ui/manual_ignore_case_cmp.rs:60:5 | LL | a.to_ascii_lowercase() == b'a'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | a.eq_ignore_ascii_case(&b'a'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:47:5 + --> tests/ui/manual_ignore_case_cmp.rs:62:5 | LL | b'a' == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL | b'a'.eq_ignore_ascii_case(&b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:50:5 + --> tests/ui/manual_ignore_case_cmp.rs:66:5 | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -190,151 +190,19 @@ help: consider using `.eq_ignore_ascii_case()` instead LL | a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~ -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:51:5 - | -LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:52:5 - | -LL | a.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:53:5 - | -LL | "a" == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:56:5 - | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:57:5 - | -LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.to_uppercase().eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:58:5 - | -LL | a.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:59:5 - | -LL | "a" == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | "a".eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:62:5 - | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:63:5 - | -LL | a.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:64:5 - | -LL | "a" == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:67:5 - | -LL | a.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:68:5 | -LL | "a" == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `.eq_ignore_ascii_case()` instead | -LL | "a".eq_ignore_ascii_case(&b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | a.to_uppercase().eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:71:5 - | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:72:5 + --> tests/ui/manual_ignore_case_cmp.rs:70:5 | LL | a.to_ascii_lowercase() == "a"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -345,7 +213,7 @@ LL | a.eq_ignore_ascii_case("a"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:73:5 + --> tests/ui/manual_ignore_case_cmp.rs:72:5 | LL | "a" == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -355,42 +223,9 @@ help: consider using `.eq_ignore_ascii_case()` instead LL | "a".eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:75:5 - | -LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ - error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:76:5 | -LL | b.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:77:5 - | -LL | "a" == a.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:80:5 - | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -400,7 +235,18 @@ LL | a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:81:5 + --> tests/ui/manual_ignore_case_cmp.rs:78:5 + | +LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.to_uppercase().eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:80:5 | LL | a.to_ascii_lowercase() == "a"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -421,53 +267,9 @@ help: consider using `.eq_ignore_ascii_case()` instead LL | "a".eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:84:5 - | -LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:85:5 - | -LL | b.to_ascii_lowercase() == "a"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | b.eq_ignore_ascii_case("a"); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:86:5 | -LL | "a" == a.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | "a".eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:89:5 - | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider using `.eq_ignore_ascii_case()` instead - | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:92:5 - | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -477,29 +279,51 @@ LL | a.eq_ignore_ascii_case(&b); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:95:5 + --> tests/ui/manual_ignore_case_cmp.rs:88:5 | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:90:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:94:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:96:5 | -LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `.eq_ignore_ascii_case()` instead | -LL | b.eq_ignore_ascii_case(&a); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | "a".eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:99:5 + --> tests/ui/manual_ignore_case_cmp.rs:100:5 | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -512,16 +336,60 @@ LL | a.eq_ignore_ascii_case(b); error: manual case-insensitive ASCII comparison --> tests/ui/manual_ignore_case_cmp.rs:102:5 | -LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:104:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:107:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider using `.eq_ignore_ascii_case()` instead | -LL | a.eq_ignore_ascii_case(b); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:105:5 + --> tests/ui/manual_ignore_case_cmp.rs:109:5 + | +LL | b.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:111:5 + | +LL | "a" == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:115:5 | LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +400,139 @@ LL | a.eq_ignore_ascii_case(b); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: manual case-insensitive ASCII comparison - --> tests/ui/manual_ignore_case_cmp.rs:106:5 + --> tests/ui/manual_ignore_case_cmp.rs:117:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:119:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:122:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:124:5 + | +LL | b.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:126:5 + | +LL | "a" == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:130:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:134:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:138:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:140:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:144:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:148:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:152:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:154:5 | LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_inspect.fixed b/tests/ui/manual_inspect.fixed index 0e1b8fe3edb5..8512da0bdf62 100644 --- a/tests/ui/manual_inspect.fixed +++ b/tests/ui/manual_inspect.fixed @@ -3,24 +3,29 @@ fn main() { let _ = Some(0).inspect(|&x| { + //~^ manual_inspect println!("{}", x); }); let _ = Some(0).inspect(|&x| { + //~^ manual_inspect println!("{x}"); }); let _ = Some(0).inspect(|&x| { + //~^ manual_inspect println!("{}", x * 5 + 1); }); let _ = Some(0).inspect(|&x| { + //~^ manual_inspect if x == 0 { panic!(); } }); let _ = Some(0).inspect(|&x| { + //~^ manual_inspect if &x == &0 { let _y = x; panic!(); @@ -71,6 +76,7 @@ fn main() { } let _ = Some((String::new(), 0u32)).inspect(|x| { + //~^ manual_inspect if x.1 == 0 { let _x = x.1; panic!(); @@ -96,6 +102,7 @@ fn main() { }); let _ = Some(String::new()).inspect(|x| { + //~^ manual_inspect if x.is_empty() { let _ = || { let _x = x; @@ -106,6 +113,7 @@ fn main() { }); let _ = Some(0).inspect(|&x| { + //~^ manual_inspect if x == 0 { let _ = || { let _x = x; @@ -120,6 +128,7 @@ fn main() { struct Cell2(core::cell::Cell); let _ = Some(Cell2(Cell::new(0u32))).inspect(|x| { + //~^ manual_inspect x.0.set(1); }); @@ -135,16 +144,20 @@ fn main() { } let _: Result<_, ()> = Ok(0).inspect(|&x| { + //~^ manual_inspect println!("{}", x); }); let _: Result<(), _> = Err(0).inspect_err(|&x| { + //~^ manual_inspect println!("{}", x); }); let _ = [0] + //~^ suspicious_map .into_iter() .inspect(|&x| { + //~^ manual_inspect println!("{}", x); }) .count(); diff --git a/tests/ui/manual_inspect.rs b/tests/ui/manual_inspect.rs index 94cdfe391400..7f07394d4b22 100644 --- a/tests/ui/manual_inspect.rs +++ b/tests/ui/manual_inspect.rs @@ -3,21 +3,25 @@ fn main() { let _ = Some(0).map(|x| { + //~^ manual_inspect println!("{}", x); x }); let _ = Some(0).map(|x| { + //~^ manual_inspect println!("{x}"); x }); let _ = Some(0).map(|x| { + //~^ manual_inspect println!("{}", x * 5 + 1); x }); let _ = Some(0).map(|x| { + //~^ manual_inspect if x == 0 { panic!(); } @@ -25,6 +29,7 @@ fn main() { }); let _ = Some(0).map(|x| { + //~^ manual_inspect if &x == &0 { let _y = x; panic!(); @@ -76,6 +81,7 @@ fn main() { } let _ = Some((String::new(), 0u32)).map(|x| { + //~^ manual_inspect if x.1 == 0 { let _x = x.1; panic!(); @@ -102,6 +108,7 @@ fn main() { }); let _ = Some(String::new()).map(|x| { + //~^ manual_inspect if x.is_empty() { let _ = || { let _x = &x; @@ -113,6 +120,7 @@ fn main() { }); let _ = Some(0).map(|x| { + //~^ manual_inspect if x == 0 { let _ = || { let _x = x; @@ -128,6 +136,7 @@ fn main() { struct Cell2(core::cell::Cell); let _ = Some(Cell2(Cell::new(0u32))).map(|x| { + //~^ manual_inspect x.0.set(1); x }); @@ -144,18 +153,22 @@ fn main() { } let _: Result<_, ()> = Ok(0).map(|x| { + //~^ manual_inspect println!("{}", x); x }); let _: Result<(), _> = Err(0).map_err(|x| { + //~^ manual_inspect println!("{}", x); x }); let _ = [0] + //~^ suspicious_map .into_iter() .map(|x| { + //~^ manual_inspect println!("{}", x); x }) diff --git a/tests/ui/manual_inspect.stderr b/tests/ui/manual_inspect.stderr index 0559b3bd6611..510325d2baaa 100644 --- a/tests/ui/manual_inspect.stderr +++ b/tests/ui/manual_inspect.stderr @@ -9,11 +9,12 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { +LL | LL ~ println!("{}", x); | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:10:21 + --> tests/ui/manual_inspect.rs:11:21 | LL | let _ = Some(0).map(|x| { | ^^^ @@ -21,11 +22,12 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { +LL | LL ~ println!("{x}"); | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:15:21 + --> tests/ui/manual_inspect.rs:17:21 | LL | let _ = Some(0).map(|x| { | ^^^ @@ -33,11 +35,12 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { +LL | LL ~ println!("{}", x * 5 + 1); | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:20:21 + --> tests/ui/manual_inspect.rs:23:21 | LL | let _ = Some(0).map(|x| { | ^^^ @@ -45,13 +48,14 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { +LL | LL | if x == 0 { LL | panic!(); LL ~ } | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:27:21 + --> tests/ui/manual_inspect.rs:31:21 | LL | let _ = Some(0).map(|x| { | ^^^ @@ -59,14 +63,14 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { -LL | if &x == &0 { -LL | let _y = x; +LL | +... LL | panic!(); LL ~ } | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:78:41 + --> tests/ui/manual_inspect.rs:83:41 | LL | let _ = Some((String::new(), 0u32)).map(|x| { | ^^^ @@ -74,14 +78,14 @@ LL | let _ = Some((String::new(), 0u32)).map(|x| { help: try | LL ~ let _ = Some((String::new(), 0u32)).inspect(|x| { -LL | if x.1 == 0 { -LL | let _x = x.1; +LL | +... LL | panic!(); LL ~ } | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:104:33 + --> tests/ui/manual_inspect.rs:110:33 | LL | let _ = Some(String::new()).map(|x| { | ^^^ @@ -89,6 +93,7 @@ LL | let _ = Some(String::new()).map(|x| { help: try | LL ~ let _ = Some(String::new()).inspect(|x| { +LL | LL | if x.is_empty() { LL | let _ = || { LL ~ let _x = x; @@ -99,7 +104,7 @@ LL ~ println!("test"); | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:115:21 + --> tests/ui/manual_inspect.rs:122:21 | LL | let _ = Some(0).map(|x| { | ^^^ @@ -107,14 +112,14 @@ LL | let _ = Some(0).map(|x| { help: try | LL ~ let _ = Some(0).inspect(|&x| { -LL | if x == 0 { +LL | ... LL | panic!(); LL ~ } | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:130:46 + --> tests/ui/manual_inspect.rs:138:46 | LL | let _ = Some(Cell2(Cell::new(0u32))).map(|x| { | ^^^ @@ -122,11 +127,12 @@ LL | let _ = Some(Cell2(Cell::new(0u32))).map(|x| { help: try | LL ~ let _ = Some(Cell2(Cell::new(0u32))).inspect(|x| { +LL | LL ~ x.0.set(1); | error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:146:34 + --> tests/ui/manual_inspect.rs:155:34 | LL | let _: Result<_, ()> = Ok(0).map(|x| { | ^^^ @@ -134,11 +140,12 @@ LL | let _: Result<_, ()> = Ok(0).map(|x| { help: try | LL ~ let _: Result<_, ()> = Ok(0).inspect(|&x| { +LL | LL ~ println!("{}", x); | error: using `map_err` over `inspect_err` - --> tests/ui/manual_inspect.rs:151:35 + --> tests/ui/manual_inspect.rs:161:35 | LL | let _: Result<(), _> = Err(0).map_err(|x| { | ^^^^^^^ @@ -146,18 +153,19 @@ LL | let _: Result<(), _> = Err(0).map_err(|x| { help: try | LL ~ let _: Result<(), _> = Err(0).inspect_err(|&x| { +LL | LL ~ println!("{}", x); | error: this call to `map()` won't have an effect on the call to `count()` - --> tests/ui/manual_inspect.rs:156:13 + --> tests/ui/manual_inspect.rs:167:13 | LL | let _ = [0] | _____________^ +LL | | LL | | .into_iter() LL | | .map(|x| { -LL | | println!("{}", x); -LL | | x +... | LL | | }) LL | | .count(); | |________________^ @@ -167,7 +175,7 @@ LL | | .count(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]` error: using `map` over `inspect` - --> tests/ui/manual_inspect.rs:158:10 + --> tests/ui/manual_inspect.rs:170:10 | LL | .map(|x| { | ^^^ @@ -175,6 +183,7 @@ LL | .map(|x| { help: try | LL ~ .inspect(|&x| { +LL | LL ~ println!("{}", x); | diff --git a/tests/ui/manual_instant_elapsed.fixed b/tests/ui/manual_instant_elapsed.fixed index 1811337652dd..4ef22002226e 100644 --- a/tests/ui/manual_instant_elapsed.fixed +++ b/tests/ui/manual_instant_elapsed.fixed @@ -15,6 +15,7 @@ fn main() { } let duration = prev_instant.elapsed(); + //~^ manual_instant_elapsed // don't catch let duration = prev_instant.elapsed(); @@ -24,4 +25,5 @@ fn main() { let ref_to_instant = &Instant::now(); (*ref_to_instant).elapsed(); // to ensure parens are added correctly + //~^ manual_instant_elapsed } diff --git a/tests/ui/manual_instant_elapsed.rs b/tests/ui/manual_instant_elapsed.rs index fedca38b158a..4586b33cf880 100644 --- a/tests/ui/manual_instant_elapsed.rs +++ b/tests/ui/manual_instant_elapsed.rs @@ -15,6 +15,7 @@ fn main() { } let duration = Instant::now() - prev_instant; + //~^ manual_instant_elapsed // don't catch let duration = prev_instant.elapsed(); @@ -24,4 +25,5 @@ fn main() { let ref_to_instant = &Instant::now(); Instant::now() - *ref_to_instant; // to ensure parens are added correctly + //~^ manual_instant_elapsed } diff --git a/tests/ui/manual_instant_elapsed.stderr b/tests/ui/manual_instant_elapsed.stderr index e8ffeb5f8ca3..e84f3126f707 100644 --- a/tests/ui/manual_instant_elapsed.stderr +++ b/tests/ui/manual_instant_elapsed.stderr @@ -8,7 +8,7 @@ LL | let duration = Instant::now() - prev_instant; = help: to override `-D warnings` add `#[allow(clippy::manual_instant_elapsed)]` error: manual implementation of `Instant::elapsed` - --> tests/ui/manual_instant_elapsed.rs:26:5 + --> tests/ui/manual_instant_elapsed.rs:27: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 179149f697db..7b0d19068346 100644 --- a/tests/ui/manual_is_ascii_check.fixed +++ b/tests/ui/manual_is_ascii_check.fixed @@ -3,29 +3,45 @@ fn main() { assert!('x'.is_ascii_lowercase()); + //~^ manual_is_ascii_check assert!('X'.is_ascii_uppercase()); + //~^ manual_is_ascii_check assert!(b'x'.is_ascii_lowercase()); + //~^ manual_is_ascii_check assert!(b'X'.is_ascii_uppercase()); + //~^ manual_is_ascii_check let num = '2'; assert!(num.is_ascii_digit()); + //~^ manual_is_ascii_check assert!(b'1'.is_ascii_digit()); + //~^ manual_is_ascii_check assert!('x'.is_ascii_alphabetic()); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); b'0'.is_ascii_digit(); + //~^ manual_is_ascii_check b'a'.is_ascii_lowercase(); + //~^ manual_is_ascii_check b'A'.is_ascii_uppercase(); + //~^ manual_is_ascii_check '0'.is_ascii_digit(); + //~^ manual_is_ascii_check 'a'.is_ascii_lowercase(); + //~^ manual_is_ascii_check 'A'.is_ascii_uppercase(); + //~^ manual_is_ascii_check let cool_letter = &'g'; cool_letter.is_ascii_digit(); + //~^ manual_is_ascii_check cool_letter.is_ascii_lowercase(); + //~^ manual_is_ascii_check cool_letter.is_ascii_uppercase(); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.23"] @@ -39,9 +55,13 @@ fn msrv_1_23() { #[clippy::msrv = "1.24"] fn msrv_1_24() { assert!(b'1'.is_ascii_digit()); + //~^ manual_is_ascii_check assert!('X'.is_ascii_uppercase()); + //~^ manual_is_ascii_check assert!('x'.is_ascii_alphabetic()); + //~^ manual_is_ascii_check assert!('x'.is_ascii_hexdigit()); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.46"] @@ -53,14 +73,18 @@ fn msrv_1_46() { #[clippy::msrv = "1.47"] fn msrv_1_47() { const FOO: bool = 'x'.is_ascii_digit(); + //~^ manual_is_ascii_check const BAR: bool = 'x'.is_ascii_hexdigit(); + //~^ manual_is_ascii_check } #[allow(clippy::deref_addrof, clippy::needless_borrow)] fn with_refs() { let cool_letter = &&'g'; cool_letter.is_ascii_digit(); + //~^ manual_is_ascii_check cool_letter.is_ascii_lowercase(); + //~^ manual_is_ascii_check } fn generics() { @@ -79,11 +103,16 @@ fn generics() { { } take_while(|c: char| c.is_ascii_uppercase()); + //~^ manual_is_ascii_check take_while(|c: u8| c.is_ascii_uppercase()); + //~^ manual_is_ascii_check take_while(|c: char| c.is_ascii_uppercase()); + //~^ manual_is_ascii_check } fn adds_type_reference() { let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ascii_digit()).collect(); + //~^ manual_is_ascii_check let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c: &&mut char| c.is_ascii_digit()).collect(); + //~^ manual_is_ascii_check } diff --git a/tests/ui/manual_is_ascii_check.rs b/tests/ui/manual_is_ascii_check.rs index 74f35ce94e84..e4f7fe9f5838 100644 --- a/tests/ui/manual_is_ascii_check.rs +++ b/tests/ui/manual_is_ascii_check.rs @@ -3,29 +3,45 @@ fn main() { assert!(matches!('x', 'a'..='z')); + //~^ manual_is_ascii_check assert!(matches!('X', 'A'..='Z')); + //~^ manual_is_ascii_check assert!(matches!(b'x', b'a'..=b'z')); + //~^ manual_is_ascii_check assert!(matches!(b'X', b'A'..=b'Z')); + //~^ manual_is_ascii_check let num = '2'; assert!(matches!(num, '0'..='9')); + //~^ manual_is_ascii_check assert!(matches!(b'1', b'0'..=b'9')); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_')); (b'0'..=b'9').contains(&b'0'); + //~^ manual_is_ascii_check (b'a'..=b'z').contains(&b'a'); + //~^ manual_is_ascii_check (b'A'..=b'Z').contains(&b'A'); + //~^ manual_is_ascii_check ('0'..='9').contains(&'0'); + //~^ manual_is_ascii_check ('a'..='z').contains(&'a'); + //~^ manual_is_ascii_check ('A'..='Z').contains(&'A'); + //~^ manual_is_ascii_check let cool_letter = &'g'; ('0'..='9').contains(cool_letter); + //~^ manual_is_ascii_check ('a'..='z').contains(cool_letter); + //~^ manual_is_ascii_check ('A'..='Z').contains(cool_letter); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.23"] @@ -39,9 +55,13 @@ fn msrv_1_23() { #[clippy::msrv = "1.24"] fn msrv_1_24() { assert!(matches!(b'1', b'0'..=b'9')); + //~^ manual_is_ascii_check assert!(matches!('X', 'A'..='Z')); + //~^ manual_is_ascii_check assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + //~^ manual_is_ascii_check assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); + //~^ manual_is_ascii_check } #[clippy::msrv = "1.46"] @@ -53,14 +73,18 @@ fn msrv_1_46() { #[clippy::msrv = "1.47"] fn msrv_1_47() { const FOO: bool = matches!('x', '0'..='9'); + //~^ manual_is_ascii_check const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'); + //~^ manual_is_ascii_check } #[allow(clippy::deref_addrof, clippy::needless_borrow)] fn with_refs() { let cool_letter = &&'g'; ('0'..='9').contains(&&cool_letter); + //~^ manual_is_ascii_check ('a'..='z').contains(*cool_letter); + //~^ manual_is_ascii_check } fn generics() { @@ -79,11 +103,16 @@ fn generics() { { } take_while(|c| ('A'..='Z').contains(&c)); + //~^ manual_is_ascii_check take_while(|c| (b'A'..=b'Z').contains(&c)); + //~^ manual_is_ascii_check take_while(|c: char| ('A'..='Z').contains(&c)); + //~^ manual_is_ascii_check } fn adds_type_reference() { let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').contains(c)).collect(); + //~^ manual_is_ascii_check let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'..='9').contains(c)).collect(); + //~^ manual_is_ascii_check } diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index 92d93208006a..cbb7aa2205b6 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -8,145 +8,145 @@ LL | assert!(matches!('x', 'a'..='z')); = help: to override `-D warnings` add `#[allow(clippy::manual_is_ascii_check)]` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:6:13 + --> tests/ui/manual_is_ascii_check.rs:7:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:7:13 + --> tests/ui/manual_is_ascii_check.rs:9:13 | LL | assert!(matches!(b'x', b'a'..=b'z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'x'.is_ascii_lowercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:8:13 + --> tests/ui/manual_is_ascii_check.rs:11:13 | LL | assert!(matches!(b'X', b'A'..=b'Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:11:13 + --> tests/ui/manual_is_ascii_check.rs:15:13 | LL | assert!(matches!(num, '0'..='9')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:12:13 + --> tests/ui/manual_is_ascii_check.rs:17:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:13:13 + --> tests/ui/manual_is_ascii_check.rs:19:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:17:5 + --> tests/ui/manual_is_ascii_check.rs:24:5 | LL | (b'0'..=b'9').contains(&b'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:18:5 + --> tests/ui/manual_is_ascii_check.rs:26:5 | LL | (b'a'..=b'z').contains(&b'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:19:5 + --> tests/ui/manual_is_ascii_check.rs:28:5 | LL | (b'A'..=b'Z').contains(&b'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:21:5 + --> tests/ui/manual_is_ascii_check.rs:31:5 | LL | ('0'..='9').contains(&'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:22:5 + --> tests/ui/manual_is_ascii_check.rs:33:5 | LL | ('a'..='z').contains(&'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:23:5 + --> tests/ui/manual_is_ascii_check.rs:35:5 | LL | ('A'..='Z').contains(&'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:26:5 + --> tests/ui/manual_is_ascii_check.rs:39:5 | LL | ('0'..='9').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:27:5 + --> tests/ui/manual_is_ascii_check.rs:41:5 | LL | ('a'..='z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:28:5 + --> tests/ui/manual_is_ascii_check.rs:43:5 | LL | ('A'..='Z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:41:13 + --> tests/ui/manual_is_ascii_check.rs:57:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:42:13 + --> tests/ui/manual_is_ascii_check.rs:59:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:43:13 + --> tests/ui/manual_is_ascii_check.rs:61:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:44:13 + --> tests/ui/manual_is_ascii_check.rs:63:13 | LL | assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:55:23 + --> tests/ui/manual_is_ascii_check.rs:75:23 | LL | const FOO: bool = matches!('x', '0'..='9'); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:56:23 + --> tests/ui/manual_is_ascii_check.rs:77:23 | LL | const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:62:5 + --> tests/ui/manual_is_ascii_check.rs:84:5 | LL | ('0'..='9').contains(&&cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:63:5 + --> tests/ui/manual_is_ascii_check.rs:86:5 | LL | ('a'..='z').contains(*cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:81:20 + --> tests/ui/manual_is_ascii_check.rs:105:20 | LL | take_while(|c| ('A'..='Z').contains(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | take_while(|c: char| c.is_ascii_uppercase()); | ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:82:20 + --> tests/ui/manual_is_ascii_check.rs:107:20 | LL | take_while(|c| (b'A'..=b'Z').contains(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,13 +168,13 @@ LL | take_while(|c: u8| c.is_ascii_uppercase()); | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:83:26 + --> tests/ui/manual_is_ascii_check.rs:109:26 | LL | take_while(|c: char| ('A'..='Z').contains(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_uppercase()` error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:87:63 + --> tests/ui/manual_is_ascii_check.rs:114:63 | LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c| ('0'..='9').contains(c)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,7 +185,7 @@ LL | let digits: Vec<&char> = ['1', 'A'].iter().take_while(|c: &&char| c.is_ | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ error: manual check for common ascii range - --> tests/ui/manual_is_ascii_check.rs:88:71 + --> tests/ui/manual_is_ascii_check.rs:116:71 | LL | let digits: Vec<&mut char> = ['1', 'A'].iter_mut().take_while(|c| ('0'..='9').contains(c)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_is_power_of_two.fixed b/tests/ui/manual_is_power_of_two.fixed index dda5fe0ec3e7..6f29d76bd210 100644 --- a/tests/ui/manual_is_power_of_two.fixed +++ b/tests/ui/manual_is_power_of_two.fixed @@ -4,13 +4,19 @@ fn main() { let a = 16_u64; let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two // Test different orders of expression let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two let _ = a.is_power_of_two(); + //~^ manual_is_power_of_two let b = 4_i64; diff --git a/tests/ui/manual_is_power_of_two.rs b/tests/ui/manual_is_power_of_two.rs index a1d3a95c4102..0c44d7a660b4 100644 --- a/tests/ui/manual_is_power_of_two.rs +++ b/tests/ui/manual_is_power_of_two.rs @@ -4,13 +4,19 @@ fn main() { let a = 16_u64; let _ = a.count_ones() == 1; + //~^ manual_is_power_of_two let _ = a & (a - 1) == 0; + //~^ manual_is_power_of_two // Test different orders of expression let _ = 1 == a.count_ones(); + //~^ manual_is_power_of_two let _ = (a - 1) & a == 0; + //~^ manual_is_power_of_two let _ = 0 == a & (a - 1); + //~^ manual_is_power_of_two let _ = 0 == (a - 1) & a; + //~^ manual_is_power_of_two let b = 4_i64; diff --git a/tests/ui/manual_is_power_of_two.stderr b/tests/ui/manual_is_power_of_two.stderr index 3cfc6297abf2..ad12ee10565f 100644 --- a/tests/ui/manual_is_power_of_two.stderr +++ b/tests/ui/manual_is_power_of_two.stderr @@ -8,31 +8,31 @@ LL | let _ = a.count_ones() == 1; = help: to override `-D warnings` add `#[allow(clippy::manual_is_power_of_two)]` error: manually reimplementing `is_power_of_two` - --> tests/ui/manual_is_power_of_two.rs:7:13 + --> tests/ui/manual_is_power_of_two.rs:8:13 | LL | let _ = a & (a - 1) == 0; | ^^^^^^^^^^^^^^^^ help: consider using `.is_power_of_two()`: `a.is_power_of_two()` error: manually reimplementing `is_power_of_two` - --> tests/ui/manual_is_power_of_two.rs:10:13 + --> tests/ui/manual_is_power_of_two.rs:12:13 | LL | let _ = 1 == a.count_ones(); | ^^^^^^^^^^^^^^^^^^^ help: consider using `.is_power_of_two()`: `a.is_power_of_two()` error: manually reimplementing `is_power_of_two` - --> tests/ui/manual_is_power_of_two.rs:11:13 + --> tests/ui/manual_is_power_of_two.rs:14:13 | LL | let _ = (a - 1) & a == 0; | ^^^^^^^^^^^^^^^^ help: consider using `.is_power_of_two()`: `a.is_power_of_two()` error: manually reimplementing `is_power_of_two` - --> tests/ui/manual_is_power_of_two.rs:12:13 + --> tests/ui/manual_is_power_of_two.rs:16:13 | LL | let _ = 0 == a & (a - 1); | ^^^^^^^^^^^^^^^^ help: consider using `.is_power_of_two()`: `a.is_power_of_two()` error: manually reimplementing `is_power_of_two` - --> tests/ui/manual_is_power_of_two.rs:13:13 + --> tests/ui/manual_is_power_of_two.rs:18:13 | LL | let _ = 0 == (a - 1) & a; | ^^^^^^^^^^^^^^^^ help: consider using `.is_power_of_two()`: `a.is_power_of_two()` diff --git a/tests/ui/manual_is_variant_and.fixed b/tests/ui/manual_is_variant_and.fixed index 8c34b51103c1..c9c184561dd6 100644 --- a/tests/ui/manual_is_variant_and.fixed +++ b/tests/ui/manual_is_variant_and.fixed @@ -13,9 +13,11 @@ fn option_methods() { let _ = opt.is_some_and(|x| x > 1); // Multi-line cases. let _ = opt.is_some_and(|x| { + //~^ manual_is_variant_and x > 1 }); let _ = opt.is_some_and(|x| x > 1); + //~^ manual_is_variant_and let _ = opt .is_some_and(|x| x > 1); @@ -24,6 +26,7 @@ fn option_methods() { let opt2 = Some('a'); let _ = opt2.is_some_and(char::is_alphanumeric); // should lint + //~^ manual_is_variant_and let _ = opt_map!(opt2, |x| x == 'a').unwrap_or_default(); // should not lint } @@ -33,6 +36,7 @@ fn result_methods() { // multi line cases let _ = res.is_ok_and(|x| { + //~^ manual_is_variant_and x > 1 }); let _ = res.is_ok_and(|x| x > 1); @@ -42,6 +46,7 @@ fn result_methods() { let res2: Result = Ok('a'); let _ = res2.is_ok_and(char::is_alphanumeric); // should lint + //~^ manual_is_variant_and let _ = opt_map!(res2, |x| x == 'a').unwrap_or_default(); // should not lint } diff --git a/tests/ui/manual_is_variant_and.rs b/tests/ui/manual_is_variant_and.rs index 25b2489d9421..52c7b56804ce 100644 --- a/tests/ui/manual_is_variant_and.rs +++ b/tests/ui/manual_is_variant_and.rs @@ -11,16 +11,20 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_default()` use. // Single line case. let _ = opt.map(|x| x > 1) + //~^ manual_is_variant_and // Should lint even though this call is on a separate line. .unwrap_or_default(); // Multi-line cases. let _ = opt.map(|x| { + //~^ manual_is_variant_and x > 1 } ).unwrap_or_default(); let _ = opt.map(|x| x > 1).unwrap_or_default(); + //~^ manual_is_variant_and let _ = opt .map(|x| x > 1) + //~^ manual_is_variant_and .unwrap_or_default(); // won't fix because the return type of the closure is not `bool` @@ -28,6 +32,7 @@ fn option_methods() { let opt2 = Some('a'); let _ = opt2.map(char::is_alphanumeric).unwrap_or_default(); // should lint + //~^ manual_is_variant_and let _ = opt_map!(opt2, |x| x == 'a').unwrap_or_default(); // should not lint } @@ -37,10 +42,12 @@ fn result_methods() { // multi line cases let _ = res.map(|x| { + //~^ manual_is_variant_and x > 1 } ).unwrap_or_default(); let _ = res.map(|x| x > 1) + //~^ manual_is_variant_and .unwrap_or_default(); // won't fix because the return type of the closure is not `bool` @@ -48,6 +55,7 @@ fn result_methods() { let res2: Result = Ok('a'); let _ = res2.map(char::is_alphanumeric).unwrap_or_default(); // should lint + //~^ manual_is_variant_and let _ = opt_map!(res2, |x| x == 'a').unwrap_or_default(); // should not lint } diff --git a/tests/ui/manual_is_variant_and.stderr b/tests/ui/manual_is_variant_and.stderr index d3ff7cf8b316..a4fa500580d0 100644 --- a/tests/ui/manual_is_variant_and.stderr +++ b/tests/ui/manual_is_variant_and.stderr @@ -3,7 +3,7 @@ error: called `map().unwrap_or_default()` on an `Option` value | LL | let _ = opt.map(|x| x > 1) | _________________^ -LL | | // Should lint even though this call is on a separate line. +... | LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_some_and(|x| x > 1)` | @@ -11,10 +11,11 @@ LL | | .unwrap_or_default(); = help: to override `-D warnings` add `#[allow(clippy::manual_is_variant_and)]` error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:17:17 + --> tests/ui/manual_is_variant_and.rs:18:17 | LL | let _ = opt.map(|x| { | _________________^ +LL | | LL | | x > 1 LL | | } LL | | ).unwrap_or_default(); @@ -23,35 +24,38 @@ LL | | ).unwrap_or_default(); help: use | LL ~ let _ = opt.is_some_and(|x| { +LL + LL + x > 1 LL ~ }); | error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:21:17 + --> tests/ui/manual_is_variant_and.rs:23:17 | LL | let _ = opt.map(|x| x > 1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_some_and(|x| x > 1)` error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:23:10 + --> tests/ui/manual_is_variant_and.rs:26:10 | LL | .map(|x| x > 1) | __________^ +LL | | LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_some_and(|x| x > 1)` error: called `map().unwrap_or_default()` on an `Option` value - --> tests/ui/manual_is_variant_and.rs:30:18 + --> tests/ui/manual_is_variant_and.rs:34:18 | LL | let _ = opt2.map(char::is_alphanumeric).unwrap_or_default(); // should lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_some_and(char::is_alphanumeric)` error: called `map().unwrap_or_default()` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:39:17 + --> tests/ui/manual_is_variant_and.rs:44:17 | LL | let _ = res.map(|x| { | _________________^ +LL | | LL | | x > 1 LL | | } LL | | ).unwrap_or_default(); @@ -60,20 +64,22 @@ LL | | ).unwrap_or_default(); help: use | LL ~ let _ = res.is_ok_and(|x| { +LL + LL + x > 1 LL ~ }); | error: called `map().unwrap_or_default()` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:43:17 + --> tests/ui/manual_is_variant_and.rs:49:17 | LL | let _ = res.map(|x| x > 1) | _________________^ +LL | | LL | | .unwrap_or_default(); | |____________________________^ help: use: `is_ok_and(|x| x > 1)` error: called `map().unwrap_or_default()` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:50:18 + --> tests/ui/manual_is_variant_and.rs:57:18 | LL | let _ = res2.map(char::is_alphanumeric).unwrap_or_default(); // should lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `is_ok_and(char::is_alphanumeric)` diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index 2b36c3f3c2fb..e5ef55c0b8a8 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -27,17 +27,20 @@ fn main() {} fn fire() { let v = if let Some(v_some) = g() { v_some } else { return }; - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { return; }; let v = if let Some(v) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + // Blocks around the identity should have no impact { { v } } } else { @@ -49,18 +52,22 @@ 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` + //~^ manual_let_else + let v = if let Some(v_some) = g() { v_some } else { break }; - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_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` + //~^ manual_let_else + // abort also diverges let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { std::process::abort() @@ -68,7 +75,8 @@ 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` + //~^ manual_let_else + v_some } else { if true { return } else { panic!() } @@ -76,7 +84,8 @@ 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` + //~^ manual_let_else + v_some } else { if true {} @@ -85,7 +94,8 @@ fn fire() { // The final expression will need to be turned into a statement. let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { panic!(); @@ -94,7 +104,8 @@ fn fire() { // Even if the result is buried multiple expressions deep. let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { panic!(); @@ -110,7 +121,8 @@ fn fire() { // Or if a break gives the value. let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { loop { @@ -121,7 +133,8 @@ fn fire() { // Even if the break is in a weird position. let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { 'a: loop { @@ -137,7 +150,8 @@ fn fire() { // A match diverges if all branches diverge: let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { match 0 { @@ -148,7 +162,8 @@ fn fire() { // An if's expression can cause divergence: let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { if panic!() {}; @@ -156,7 +171,8 @@ fn fire() { // An expression of a match can cause divergence: let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { match panic!() { @@ -166,7 +182,8 @@ fn fire() { // Top level else if let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else if true { return; @@ -176,7 +193,8 @@ fn fire() { // All match arms diverge let v = if let Some(v_some) = g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + v_some } else { match (g(), g()) { @@ -194,7 +212,8 @@ 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` + //~^ manual_let_else + v_some } else { return; @@ -202,7 +221,8 @@ 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` + //~^ manual_let_else + (w_some, v_some) } else { return; @@ -212,6 +232,7 @@ fn fire() { macro_rules! create_binding_if_some { ($n:ident, $e:expr) => { let $n = if let Some(v) = $e { v } else { return }; + //~^ manual_let_else }; } create_binding_if_some!(w, g()); @@ -221,31 +242,37 @@ fn fire() { } let v = if let Variant::A(a, 0) = e() { a } else { return }; - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_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` + //~^ manual_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` + //~^ manual_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` + //~^ manual_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` + //~^ manual_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` + //~^ manual_let_else + x } else { return; @@ -253,7 +280,8 @@ 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` + //~^ manual_let_else + x } else { return; @@ -261,7 +289,8 @@ 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` + //~^ manual_let_else + (x, v, w) } else { return; @@ -378,7 +407,8 @@ fn not_fire() { let ff = Some(1); let _ = match ff { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + Some(value) => value, _ => macro_call!(), }; @@ -455,5 +485,6 @@ fn issue12337() { // we still emit a lint for manual_let_else let _: Option<()> = try { let v = if let Some(v_some) = g() { v_some } else { return }; + //~^ manual_let_else }; } diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index dcd5d4561113..8982a1c567bf 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -8,10 +8,11 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:32:5 + --> tests/ui/manual_let_else.rs:33:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some LL | | } else { LL | | return; @@ -26,12 +27,9 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:39:5 + --> tests/ui/manual_let_else.rs:41:5 | LL | / let v = if let Some(v) = g() { -LL | | -LL | | // Blocks around the identity should have no impact -LL | | { { v } } ... | LL | | return; LL | | }; @@ -47,28 +45,29 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:51:9 + --> tests/ui/manual_let_else.rs:54: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` - --> tests/ui/manual_let_else.rs:53:9 + --> tests/ui/manual_let_else.rs:57: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` - --> tests/ui/manual_let_else.rs:58:5 + --> tests/ui/manual_let_else.rs:63: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` - --> tests/ui/manual_let_else.rs:62:5 + --> tests/ui/manual_let_else.rs:68:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some LL | | } else { LL | | std::process::abort() @@ -83,10 +82,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:70:5 + --> tests/ui/manual_let_else.rs:77:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some LL | | } else { LL | | if true { return } else { panic!() } @@ -101,13 +101,13 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:78:5 + --> tests/ui/manual_let_else.rs:86:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { -LL | | if true {} +... | LL | | panic!(); LL | | }; | |______^ @@ -121,13 +121,13 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:87:5 + --> tests/ui/manual_let_else.rs:96:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { -LL | | panic!(); +... | LL | | () LL | | }; | |______^ @@ -141,12 +141,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:96:5 + --> tests/ui/manual_let_else.rs:106:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; | |______^ @@ -167,12 +167,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:112:5 + --> tests/ui/manual_let_else.rs:123:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; | |______^ @@ -188,12 +188,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:123:5 + --> tests/ui/manual_let_else.rs:135:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; | |______^ @@ -214,12 +214,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:139:5 + --> tests/ui/manual_let_else.rs:152:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; LL | | }; @@ -236,10 +236,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:150:5 + --> tests/ui/manual_let_else.rs:164:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some LL | | } else { LL | | if panic!() {}; @@ -254,12 +255,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:158:5 + --> tests/ui/manual_let_else.rs:173:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; LL | | }; @@ -275,12 +276,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:168:5 + --> tests/ui/manual_let_else.rs:184:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else if true { ... | LL | | panic!("diverge"); LL | | }; @@ -296,12 +297,12 @@ LL + } }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:178:5 + --> tests/ui/manual_let_else.rs:195:5 | LL | / let v = if let Some(v_some) = g() { LL | | +LL | | LL | | v_some -LL | | } else { ... | LL | | }; | |______^ @@ -324,10 +325,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:196:5 + --> tests/ui/manual_let_else.rs:214:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { LL | | +LL | | LL | | v_some LL | | } else { LL | | return; @@ -342,10 +344,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:204:5 + --> tests/ui/manual_let_else.rs:223:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { LL | | +LL | | LL | | (w_some, v_some) LL | | } else { LL | | return; @@ -360,7 +363,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:214:13 + --> tests/ui/manual_let_else.rs:234:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -371,22 +374,23 @@ 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` - --> tests/ui/manual_let_else.rs:223:5 + --> tests/ui/manual_let_else.rs:244: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` - --> tests/ui/manual_let_else.rs:227:5 + --> tests/ui/manual_let_else.rs:249: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` - --> tests/ui/manual_let_else.rs:232:5 + --> tests/ui/manual_let_else.rs:255:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { LL | | +LL | | LL | | b LL | | } else { LL | | return; @@ -401,22 +405,23 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:239:5 + --> tests/ui/manual_let_else.rs:263: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` - --> tests/ui/manual_let_else.rs:243:5 + --> tests/ui/manual_let_else.rs:268: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` - --> tests/ui/manual_let_else.rs:247:5 + --> tests/ui/manual_let_else.rs:273:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | +LL | | LL | | x LL | | } else { LL | | return; @@ -431,10 +436,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:255:5 + --> tests/ui/manual_let_else.rs:282:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | +LL | | LL | | x LL | | } else { LL | | return; @@ -449,10 +455,11 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:263:5 + --> tests/ui/manual_let_else.rs:291:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { LL | | +LL | | LL | | (x, v, w) LL | | } else { LL | | return; @@ -467,17 +474,18 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:380:5 + --> tests/ui/manual_let_else.rs:409:5 | LL | / let _ = match ff { LL | | +LL | | LL | | Some(value) => value, LL | | _ => macro_call!(), LL | | }; | |______^ help: consider writing: `let Some(_) = ff else { macro_call!() };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:457:9 + --> tests/ui/manual_let_else.rs:487:9 | LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs index c37b5613ff7d..cdb407030111 100644 --- a/tests/ui/manual_let_else_match.rs +++ b/tests/ui/manual_let_else_match.rs @@ -34,14 +34,16 @@ 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` + //~^ manual_let_else + + Some(v_some) => v_some, None => return, }; let v = match g() { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + Some(v_some) => v_some, _ => return, }; @@ -49,13 +51,15 @@ 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` + //~^ manual_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` + //~^ manual_let_else + Variant::Bar(v) | Variant::Baz(v) => v, _ => continue, }; @@ -64,14 +68,16 @@ 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` + //~^ manual_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` + //~^ manual_let_else + Ok(v) => v, Err(()) => return, }; @@ -79,20 +85,23 @@ fn fire() { let f = Variant::Bar(1); let _value = match f { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + Variant::Bar(v) | Variant::Baz(v) => v, _ => return, }; let _value = match Some(build_enum()) { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_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` + //~^ manual_let_else + [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, _ => return, }; @@ -173,7 +182,8 @@ fn not_fire() { fn issue11579() { let msg = match Some("hi") { - //~^ ERROR: this could be rewritten as `let...else` + //~^ manual_let_else + Some(m) => m, _ => unreachable!("can't happen"), }; diff --git a/tests/ui/manual_let_else_match.stderr b/tests/ui/manual_let_else_match.stderr index 3c0065f64033..6a65186d6b53 100644 --- a/tests/ui/manual_let_else_match.stderr +++ b/tests/ui/manual_let_else_match.stderr @@ -2,9 +2,7 @@ error: this could be rewritten as `let...else` --> tests/ui/manual_let_else_match.rs:36:5 | LL | / let v = match g() { -LL | | -LL | | -LL | | Some(v_some) => v_some, +... | LL | | None => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` @@ -13,90 +11,99 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_match.rs:43:5 + --> tests/ui/manual_let_else_match.rs:44:5 | LL | / let v = match g() { LL | | +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` - --> tests/ui/manual_let_else_match.rs:51:9 + --> tests/ui/manual_let_else_match.rs:53:9 | LL | / let v = match h() { LL | | +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` - --> tests/ui/manual_let_else_match.rs:57:9 + --> tests/ui/manual_let_else_match.rs:60:9 | LL | / let v = match build_enum() { LL | | +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` - --> tests/ui/manual_let_else_match.rs:66:5 + --> tests/ui/manual_let_else_match.rs:70:5 | LL | / let v = match f() { LL | | +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` - --> tests/ui/manual_let_else_match.rs:73:5 + --> tests/ui/manual_let_else_match.rs:78:5 | LL | / let v = match f().map_err(|_| ()) { LL | | +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` - --> tests/ui/manual_let_else_match.rs:81:5 + --> tests/ui/manual_let_else_match.rs:87:5 | LL | / let _value = match f { LL | | +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` - --> tests/ui/manual_let_else_match.rs:87:5 + --> tests/ui/manual_let_else_match.rs:94:5 | LL | / let _value = match Some(build_enum()) { LL | | +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` - --> tests/ui/manual_let_else_match.rs:94:5 + --> tests/ui/manual_let_else_match.rs:102:5 | LL | / let data = match data.as_slice() { LL | | +LL | | LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0]) = data.as_slice() else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_match.rs:175:5 + --> tests/ui/manual_let_else_match.rs:184:5 | LL | / let msg = match Some("hi") { LL | | +LL | | LL | | Some(m) => m, LL | | _ => unreachable!("can't happen"), LL | | }; diff --git a/tests/ui/manual_let_else_question_mark.fixed b/tests/ui/manual_let_else_question_mark.fixed index 6b29ce759857..aca32a49c13b 100644 --- a/tests/ui/manual_let_else_question_mark.fixed +++ b/tests/ui/manual_let_else_question_mark.fixed @@ -27,15 +27,18 @@ fn main() {} fn foo() -> Option<()> { // Fire here, normal case let v = g()?; + //~^ question_mark // Don't fire here, the pattern is refutable let Variant::A(v, w) = e() else { return None }; // Fire here, the pattern is irrefutable let (v, w) = g()?; + //~^ question_mark // Don't fire manual_let_else in this instance: question mark can be used instead. let v = g()?; + //~^ question_mark // Do fire manual_let_else in this instance: question mark cannot be used here due to the return // body. @@ -56,6 +59,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let Some(v) = g() else { return None }; + //~^ manual_let_else } Some(()) @@ -64,6 +68,7 @@ fn foo() -> Option<()> { // lint not just `return None`, but also `return None;` (note the semicolon) fn issue11993(y: Option) -> Option { let x = y?; + //~^^^ question_mark // don't lint: more than one statement in the else body let Some(x) = y else { diff --git a/tests/ui/manual_let_else_question_mark.rs b/tests/ui/manual_let_else_question_mark.rs index e92c4c1375e5..a07801ce0681 100644 --- a/tests/ui/manual_let_else_question_mark.rs +++ b/tests/ui/manual_let_else_question_mark.rs @@ -27,19 +27,23 @@ fn main() {} fn foo() -> Option<()> { // Fire here, normal case let Some(v) = g() else { return None }; + //~^ question_mark // Don't fire here, the pattern is refutable let Variant::A(v, w) = e() else { return None }; // Fire here, the pattern is irrefutable let Some((v, w)) = g() else { return None }; + //~^ question_mark // Don't fire manual_let_else in this instance: question mark can be used instead. let v = if let Some(v_some) = g() { v_some } else { return None }; + //~^ question_mark // Do fire manual_let_else in this instance: question mark cannot be used here due to the return // body. let v = if let Some(v_some) = g() { + //~^ manual_let_else v_some } else { return Some(()); @@ -51,6 +55,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let v = match g() { + //~^ manual_let_else Some(v_some) => v_some, _ => return None, }; @@ -61,6 +66,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let v = if let Some(v_some) = g() { v_some } else { return None }; + //~^ manual_let_else } Some(()) @@ -71,6 +77,7 @@ fn issue11993(y: Option) -> Option { let Some(x) = y else { return None; }; + //~^^^ question_mark // don't lint: more than one statement in the else body let Some(x) = y else { diff --git a/tests/ui/manual_let_else_question_mark.stderr b/tests/ui/manual_let_else_question_mark.stderr index 434872ca2677..4fdd64d98491 100644 --- a/tests/ui/manual_let_else_question_mark.stderr +++ b/tests/ui/manual_let_else_question_mark.stderr @@ -8,21 +8,22 @@ LL | let Some(v) = g() else { return None }; = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/manual_let_else_question_mark.rs:35:5 + --> tests/ui/manual_let_else_question_mark.rs:36: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 - --> tests/ui/manual_let_else_question_mark.rs:38:13 + --> tests/ui/manual_let_else_question_mark.rs:40: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` - --> tests/ui/manual_let_else_question_mark.rs:42:5 + --> tests/ui/manual_let_else_question_mark.rs:45:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | return Some(()); @@ -39,22 +40,23 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_question_mark.rs:53:9 + --> tests/ui/manual_let_else_question_mark.rs:57:9 | LL | / let v = match g() { +LL | | LL | | Some(v_some) => v_some, LL | | _ => return None, LL | | }; | |__________^ help: consider writing: `let Some(v) = g() else { return None };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_question_mark.rs:63:9 + --> tests/ui/manual_let_else_question_mark.rs:68: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 };` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/manual_let_else_question_mark.rs:71:5 + --> tests/ui/manual_let_else_question_mark.rs:77:5 | LL | / let Some(x) = y else { LL | | return None; diff --git a/tests/ui/manual_main_separator_str.fixed b/tests/ui/manual_main_separator_str.fixed index 6441d6edef8c..6e5478ad009e 100644 --- a/tests/ui/manual_main_separator_str.fixed +++ b/tests/ui/manual_main_separator_str.fixed @@ -19,12 +19,16 @@ struct V { fn main() { // Should lint let _: &str = std::path::MAIN_SEPARATOR_STR; + //~^ manual_main_separator_str let _ = len(std::path::MAIN_SEPARATOR_STR); + //~^ manual_main_separator_str let _: Vec = std::path::MAIN_SEPARATOR_STR.encode_utf16().collect(); + //~^ manual_main_separator_str // Should lint for field `f` only let _ = U { f: std::path::MAIN_SEPARATOR_STR, + //~^ manual_main_separator_str g: &MAIN_SEPARATOR.to_string(), }; diff --git a/tests/ui/manual_main_separator_str.rs b/tests/ui/manual_main_separator_str.rs index 339dfd8bb473..170af2da143f 100644 --- a/tests/ui/manual_main_separator_str.rs +++ b/tests/ui/manual_main_separator_str.rs @@ -19,12 +19,16 @@ struct V { fn main() { // Should lint let _: &str = &MAIN_SEPARATOR.to_string(); + //~^ manual_main_separator_str let _ = len(&MAIN_SEPARATOR.to_string()); + //~^ manual_main_separator_str let _: Vec = MAIN_SEPARATOR.to_string().encode_utf16().collect(); + //~^ manual_main_separator_str // Should lint for field `f` only let _ = U { f: &MAIN_SEPARATOR.to_string(), + //~^ manual_main_separator_str g: &MAIN_SEPARATOR.to_string(), }; diff --git a/tests/ui/manual_main_separator_str.stderr b/tests/ui/manual_main_separator_str.stderr index 78395eb7d664..1c58b8261d4f 100644 --- a/tests/ui/manual_main_separator_str.stderr +++ b/tests/ui/manual_main_separator_str.stderr @@ -8,19 +8,19 @@ LL | let _: &str = &MAIN_SEPARATOR.to_string(); = help: to override `-D warnings` add `#[allow(clippy::manual_main_separator_str)]` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> tests/ui/manual_main_separator_str.rs:22:17 + --> tests/ui/manual_main_separator_str.rs:23: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` - --> tests/ui/manual_main_separator_str.rs:23:23 + --> tests/ui/manual_main_separator_str.rs:25: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` - --> tests/ui/manual_main_separator_str.rs:27:12 + --> tests/ui/manual_main_separator_str.rs:30:12 | LL | f: &MAIN_SEPARATOR.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index 2f21628977cf..9d7cf754f4b8 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -12,21 +12,25 @@ fn main() { match Some(0) { + //~^ manual_map Some(_) => Some(2), None:: => None, }; match Some(0) { + //~^ manual_map Some(x) => Some(x + 1), _ => None, }; match Some("") { + //~^ manual_map Some(x) => Some(x.is_empty()), None => None, }; if let Some(x) = Some(0) { + //~^ manual_map Some(!x) } else { None @@ -34,11 +38,13 @@ fn main() { #[rustfmt::skip] match Some(0) { + //~^ manual_map Some(x) => { Some(std::convert::identity(x)) } None => { None } }; match Some(&String::new()) { + //~^ manual_map Some(x) => Some(str::len(x)), None => None, }; @@ -49,26 +55,31 @@ fn main() { }; match &Some([0, 1]) { + //~^ manual_map Some(x) => Some(x[0]), &None => None, }; match &Some(0) { + //~^ manual_map &Some(x) => Some(x * 2), None => None, }; match Some(String::new()) { + //~^ manual_map Some(ref x) => Some(x.is_empty()), _ => None, }; match &&Some(String::new()) { + //~^ manual_map Some(x) => Some(x.len()), _ => None, }; match &&Some(0) { + //~^ manual_map &&Some(x) => Some(x + x), &&_ => None, }; @@ -82,32 +93,38 @@ fn main() { #[allow(clippy::option_map_unit_fn)] { match &mut Some(String::new()) { + //~^ manual_map Some(x) => Some(x.push_str("")), None => None, }; } match &mut Some(String::new()) { + //~^ manual_map Some(ref x) => Some(x.len()), None => None, }; match &mut &Some(String::new()) { + //~^ manual_map Some(x) => Some(x.is_empty()), &mut _ => None, }; match Some((0, 1, 2)) { + //~^ manual_map Some((x, y, z)) => Some(x + y + z), None => None, }; match Some([1, 2, 3]) { + //~^ manual_map Some([first, ..]) => Some(first), None => None, }; match &Some((String::new(), "test")) { + //~^ manual_map Some((x, y)) => Some((y, x)), None => None, }; @@ -177,6 +194,7 @@ fn main() { }; match option_env!("") { + //~^ manual_map Some(x) => Some(String::from(x)), None => None, }; @@ -197,6 +215,7 @@ fn main() { if let Some(_) = Some(0) { Some(0) } else if let Some(x) = Some(0) { + //~^ manual_map Some(x + 1) } else { None @@ -205,6 +224,7 @@ fn main() { if true { Some(0) } else if let Some(x) = Some(0) { + //~^ manual_map Some(x + 1) } else { None diff --git a/tests/ui/manual_map_option.stderr b/tests/ui/manual_map_option.stderr index c496752e2f6d..8f9bce4c265c 100644 --- a/tests/ui/manual_map_option.stderr +++ b/tests/ui/manual_map_option.stderr @@ -2,6 +2,7 @@ error: manual implementation of `Option::map` --> tests/ui/manual_map_option.rs:14:5 | LL | / match Some(0) { +LL | | LL | | Some(_) => Some(2), LL | | None:: => None, LL | | }; @@ -11,27 +12,30 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:19:5 + --> tests/ui/manual_map_option.rs:20:5 | LL | / match Some(0) { +LL | | LL | | Some(x) => Some(x + 1), LL | | _ => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| x + 1)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:24:5 + --> tests/ui/manual_map_option.rs:26:5 | LL | / match Some("") { +LL | | LL | | Some(x) => Some(x.is_empty()), LL | | None => None, LL | | }; | |_____^ help: try: `Some("").map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:29:5 + --> tests/ui/manual_map_option.rs:32:5 | LL | / if let Some(x) = Some(0) { +LL | | LL | | Some(!x) LL | | } else { LL | | None @@ -39,136 +43,151 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| !x)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:36:5 + --> tests/ui/manual_map_option.rs:40:5 | LL | / match Some(0) { +LL | | LL | | Some(x) => { Some(std::convert::identity(x)) } LL | | None => { None } LL | | }; | |_____^ help: try: `Some(0).map(std::convert::identity)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:41:5 + --> tests/ui/manual_map_option.rs:46:5 | LL | / match Some(&String::new()) { +LL | | LL | | Some(x) => Some(str::len(x)), LL | | None => None, LL | | }; | |_____^ help: try: `Some(&String::new()).map(|x| str::len(x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:51:5 + --> tests/ui/manual_map_option.rs:57:5 | LL | / match &Some([0, 1]) { +LL | | LL | | Some(x) => Some(x[0]), LL | | &None => None, LL | | }; | |_____^ help: try: `Some([0, 1]).as_ref().map(|x| x[0])` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:56:5 + --> tests/ui/manual_map_option.rs:63:5 | LL | / match &Some(0) { +LL | | LL | | &Some(x) => Some(x * 2), LL | | None => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| x * 2)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:61:5 + --> tests/ui/manual_map_option.rs:69:5 | LL | / match Some(String::new()) { +LL | | LL | | Some(ref x) => Some(x.is_empty()), LL | | _ => None, LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:66:5 + --> tests/ui/manual_map_option.rs:75:5 | LL | / match &&Some(String::new()) { +LL | | LL | | Some(x) => Some(x.len()), LL | | _ => None, LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:71:5 + --> tests/ui/manual_map_option.rs:81:5 | LL | / match &&Some(0) { +LL | | LL | | &&Some(x) => Some(x + x), LL | | &&_ => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| x + x)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:84:9 + --> tests/ui/manual_map_option.rs:95:9 | LL | / match &mut Some(String::new()) { +LL | | LL | | Some(x) => Some(x.push_str("")), LL | | None => None, LL | | }; | |_________^ help: try: `Some(String::new()).as_mut().map(|x| x.push_str(""))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:90:5 + --> tests/ui/manual_map_option.rs:102:5 | LL | / match &mut Some(String::new()) { +LL | | LL | | Some(ref x) => Some(x.len()), LL | | None => None, LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:95:5 + --> tests/ui/manual_map_option.rs:108:5 | LL | / match &mut &Some(String::new()) { +LL | | LL | | Some(x) => Some(x.is_empty()), LL | | &mut _ => None, LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:100:5 + --> tests/ui/manual_map_option.rs:114:5 | LL | / match Some((0, 1, 2)) { +LL | | LL | | Some((x, y, z)) => Some(x + y + z), LL | | None => None, LL | | }; | |_____^ help: try: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:105:5 + --> tests/ui/manual_map_option.rs:120:5 | LL | / match Some([1, 2, 3]) { +LL | | LL | | Some([first, ..]) => Some(first), LL | | None => None, LL | | }; | |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:110:5 + --> tests/ui/manual_map_option.rs:126:5 | LL | / match &Some((String::new(), "test")) { +LL | | LL | | Some((x, y)) => Some((y, x)), LL | | None => None, LL | | }; | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:179:5 + --> tests/ui/manual_map_option.rs:196:5 | LL | / match option_env!("") { +LL | | LL | | Some(x) => Some(String::from(x)), LL | | None => None, LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:199:12 + --> tests/ui/manual_map_option.rs:217:12 | LL | } else if let Some(x) = Some(0) { | ____________^ +LL | | LL | | Some(x + 1) LL | | } else { LL | | None @@ -176,10 +195,11 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:207:12 + --> tests/ui/manual_map_option.rs:226:12 | LL | } else if let Some(x) = Some(0) { | ____________^ +LL | | LL | | Some(x + 1) LL | | } else { LL | | None diff --git a/tests/ui/manual_map_option_2.fixed b/tests/ui/manual_map_option_2.fixed index 49b9e77b441f..d698cc74ea65 100644 --- a/tests/ui/manual_map_option_2.fixed +++ b/tests/ui/manual_map_option_2.fixed @@ -90,7 +90,6 @@ mod with_type_coercion { None => None, }; - //~v ERROR: manual implementation of `Option::map` let _ = Some(0).map(|_| match f() { Ok(res) => Ok(Box::new(res)), _ => Err(()), @@ -110,7 +109,6 @@ mod with_type_coercion { None => None, }); - //~v ERROR: manual implementation of `Option::map` let _: Option> = Some(0).map(|_| g(x)); } diff --git a/tests/ui/manual_map_option_2.rs b/tests/ui/manual_map_option_2.rs index 962455daf7ba..9f45349d5c89 100644 --- a/tests/ui/manual_map_option_2.rs +++ b/tests/ui/manual_map_option_2.rs @@ -4,6 +4,7 @@ fn main() { // Lint. `y` is declared within the arm, so it isn't captured by the map closure let _ = match Some(0) { + //~^ manual_map Some(x) => Some({ let y = (String::new(), String::new()); (x, y.0) @@ -46,6 +47,7 @@ fn main() { let s = Some(String::new()); // Lint. `s` is captured by reference, so no lifetime issues. let _ = match &s { + //~^ manual_map Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), None => None, }; @@ -61,15 +63,18 @@ fn main() { } unsafe { let _ = match Some(0) { + //~^ manual_map Some(x) => Some(f(x)), None => None, }; } let _ = match Some(0) { + //~^ manual_map Some(x) => unsafe { Some(f(x)) }, None => None, }; let _ = match Some(0) { + //~^ manual_map Some(x) => Some(unsafe { f(x) }), None => None, }; @@ -105,8 +110,8 @@ mod with_type_coercion { None => None, }; - //~v ERROR: manual implementation of `Option::map` let _ = match Some(0) { + //~^ manual_map Some(_) => Some(match f() { Ok(res) => Ok(Box::new(res)), _ => Err(()), @@ -128,8 +133,8 @@ mod with_type_coercion { None => None, }); - //~v ERROR: manual implementation of `Option::map` let _: Option> = match Some(0) { + //~^ manual_map Some(_) => Some(g(x)), None => None, }; diff --git a/tests/ui/manual_map_option_2.stderr b/tests/ui/manual_map_option_2.stderr index db048221db6a..c9e040ce1d0e 100644 --- a/tests/ui/manual_map_option_2.stderr +++ b/tests/ui/manual_map_option_2.stderr @@ -3,10 +3,10 @@ error: manual implementation of `Option::map` | LL | let _ = match Some(0) { | _____________^ +LL | | LL | | Some(x) => Some({ LL | | let y = (String::new(), String::new()); -LL | | (x, y.0) -LL | | }), +... | LL | | None => None, LL | | }; | |_____^ @@ -22,54 +22,58 @@ LL ~ }); | error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:48:13 + --> tests/ui/manual_map_option_2.rs:49:13 | LL | let _ = match &s { | _____________^ +LL | | LL | | Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), LL | | None => None, LL | | }; | |_____^ help: try: `s.as_ref().map(|x| { if let Some(ref s) = s { (x.clone(), s) } else { panic!() } })` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:63:17 + --> tests/ui/manual_map_option_2.rs:65:17 | LL | let _ = match Some(0) { | _________________^ +LL | | LL | | Some(x) => Some(f(x)), LL | | None => None, LL | | }; | |_________^ help: try: `Some(0).map(|x| f(x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:68:13 + --> tests/ui/manual_map_option_2.rs:71:13 | LL | let _ = match Some(0) { | _____________^ +LL | | LL | | Some(x) => unsafe { Some(f(x)) }, LL | | None => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:72:13 + --> tests/ui/manual_map_option_2.rs:76:13 | LL | let _ = match Some(0) { | _____________^ +LL | | LL | | Some(x) => Some(unsafe { f(x) }), LL | | None => None, LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:109:17 + --> tests/ui/manual_map_option_2.rs:113:17 | LL | let _ = match Some(0) { | _________________^ +LL | | LL | | Some(_) => Some(match f() { LL | | Ok(res) => Ok(Box::new(res)), -LL | | _ => Err(()), -LL | | }), +... | LL | | None => None, LL | | }; | |_________^ @@ -83,10 +87,11 @@ LL ~ }); | error: manual implementation of `Option::map` - --> tests/ui/manual_map_option_2.rs:132:37 + --> tests/ui/manual_map_option_2.rs:136:37 | LL | let _: Option> = match Some(0) { | _____________________________________^ +LL | | LL | | Some(_) => Some(g(x)), LL | | None => None, LL | | }; diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index 786d7e6e2445..eee6c8235daa 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -3,57 +3,65 @@ 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` + //~^ manual_memcpy + + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + 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 + //~^ manual_memcpy + dst[i] = src[count]; count += 1; } @@ -61,7 +69,8 @@ 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 + //~^ manual_memcpy + dst[count] = src[i]; dst2[count2] = src[i]; count += 1; @@ -72,7 +81,8 @@ 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 + //~^ manual_memcpy + dst[count] = src[i + 2]; count += 1; } @@ -80,7 +90,8 @@ 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 + //~^ manual_memcpy + 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 41a991e9688f..fe42842b969b 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -2,9 +2,7 @@ error: it looks like you're manually copying between slices --> tests/ui/manual_memcpy/with_loop_counters.rs:5:5 | LL | / for i in 3..src.len() { -LL | | -LL | | -LL | | dst[i] = src[count]; +... | LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..src.len()].copy_from_slice(&src[..(src.len() - 3)]);` @@ -13,83 +11,90 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/with_loop_counters.rs:13:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:14:5 | LL | / for i in 3..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:20:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:22:5 | LL | / for i in 0..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:27:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:30:5 | LL | / for i in 0..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:34:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:38:5 | LL | / for i in 3..(3 + src.len()) { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:41:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:46:5 | LL | / for i in 5..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:48:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:54:5 | LL | / for i in 0..dst.len() { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:55:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:62:5 | LL | / for i in 3..10 { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:63:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:71:5 | LL | / for i in 0..src.len() { LL | | +LL | | LL | | dst[count] = src[i]; -LL | | dst2[count2] = src[i]; -LL | | count += 1; +... | LL | | count2 += 1; LL | | } | |_____^ @@ -101,20 +106,22 @@ LL + dst2[30..(src.len() + 30)].copy_from_slice(&src[..]); | error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/with_loop_counters.rs:74:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:83:5 | LL | / for i in 0..1 << 1 { LL | | +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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:82:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:92:5 | LL | / for i in 3..src.len() { LL | | +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 2f8640cd3f50..65254df0aab4 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -12,32 +12,37 @@ 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` + //~^ manual_memcpy + + dst[i] = src[i]; } // dst offset memcpy for i in 0..src.len() { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i + 10] = src[i]; } // src offset memcpy for i in 0..src.len() { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i + 10]; } // src offset memcpy for i in 11..src.len() { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i - 10]; } // overwrite entire dst for i in 0..dst.len() { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i]; } @@ -51,7 +56,8 @@ 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 + //~^ manual_memcpy + dst[i] = src[i - 5]; dst2[i + 500] = src[i] } @@ -64,7 +70,8 @@ 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 + //~^ manual_memcpy + dst[i + LOOP_OFFSET] = src[i - some_var]; } @@ -78,7 +85,8 @@ 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 + //~^ manual_memcpy + dst_vec[i] = src_vec[i]; } @@ -108,24 +116,28 @@ 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 + //~^ manual_memcpy + dst[i] = src[i - from]; } for i in from..from + 3 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i - from]; } #[allow(clippy::identity_op)] for i in 0..5 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + 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 + //~^ manual_memcpy + dst[i] = src[i]; } @@ -149,19 +161,22 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let src = [0, 1, 2, 3, 4]; let mut dst = [0; 4]; for i in 0..4 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i]; } let mut dst = [0; 6]; for i in 0..5 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i]; } let mut dst = [0; 5]; for i in 0..5 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[i]; } @@ -208,13 +223,15 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let src = [[0; 5]; 5]; let mut dst = [0; 5]; for i in 0..5 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[0][i]; } let src = [[[0; 5]; 5]; 5]; for i in 0..5 { - //~^ ERROR: it looks like you're manually copying between slices + //~^ manual_memcpy + dst[i] = src[0][1][i]; } } @@ -222,7 +239,8 @@ 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 + //~^ manual_memcpy + 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 c881e3fac769..2599bc02c3ca 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -2,9 +2,7 @@ error: it looks like you're manually copying between slices --> tests/ui/manual_memcpy/without_loop_counters.rs:14: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[..]);` | @@ -12,46 +10,51 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:21:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:22:5 | LL | / for i in 0..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:27:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:29:5 | LL | / for i in 0..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:33:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:36:5 | LL | / for i in 11..src.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:39:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:43:5 | LL | / for i in 0..dst.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:53:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:58:5 | LL | / for i in 10..256 { LL | | +LL | | LL | | dst[i] = src[i - 5]; LL | | dst2[i + 500] = src[i] LL | | } @@ -64,109 +67,121 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:66:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:72:5 | LL | / for i in 10..LOOP_OFFSET { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:80:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:87:5 | LL | / for i in 0..src_vec.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:110:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:118:5 | LL | / for i in from..from + src.len() { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:115:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:124:5 | LL | / for i in from..from + 3 { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:121:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:131:5 | LL | / for i in 0..5 { LL | | +LL | | LL | | dst[i - 0] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:127:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:138:5 | LL | / for i in 0..0 { LL | | +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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:151:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:163:5 | LL | / for i in 0..4 { LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..4]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:157:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:170:5 | LL | / for i in 0..5 { LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:163:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:177:5 | LL | / for i in 0..5 { LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:210:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:225:5 | LL | / for i in 0..5 { LL | | +LL | | LL | | dst[i] = src[0][i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:216:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:232:5 | LL | / for i in 0..5 { LL | | +LL | | LL | | dst[i] = src[0][1][i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0][1]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:224:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:241:5 | LL | / for i in 0..src.len() { LL | | +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_next_back.fixed b/tests/ui/manual_next_back.fixed index 75828f355d90..153fbc6fd071 100644 --- a/tests/ui/manual_next_back.fixed +++ b/tests/ui/manual_next_back.fixed @@ -30,5 +30,7 @@ fn main() { // should lint let _ = (0..10).next_back().unwrap(); + //~^ manual_next_back let _ = "something".bytes().next_back(); + //~^ manual_next_back } diff --git a/tests/ui/manual_next_back.rs b/tests/ui/manual_next_back.rs index b980e90e1144..ca71d6a24773 100644 --- a/tests/ui/manual_next_back.rs +++ b/tests/ui/manual_next_back.rs @@ -30,5 +30,7 @@ fn main() { // should lint let _ = (0..10).rev().next().unwrap(); + //~^ manual_next_back let _ = "something".bytes().rev().next(); + //~^ manual_next_back } diff --git a/tests/ui/manual_next_back.stderr b/tests/ui/manual_next_back.stderr index c7e1ceca437c..4ac7b0d21244 100644 --- a/tests/ui/manual_next_back.stderr +++ b/tests/ui/manual_next_back.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..10).rev().next().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::manual_next_back)]` error: manual backwards iteration - --> tests/ui/manual_next_back.rs:33:32 + --> tests/ui/manual_next_back.rs:34: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 ffe2bb924673..aaa5b549e734 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -2,7 +2,7 @@ #![allow(unused)] //@no-rustfix pub enum E { - //~^ manual_non_exhaustive +//~^ manual_non_exhaustive A, B, #[doc(hidden)] @@ -27,6 +27,7 @@ pub enum NoDocHidden { // name of variant with doc hidden does not start with underscore pub enum NoUnderscore { +//~^ manual_non_exhaustive A, B, #[doc(hidden)] diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index 0a9ac157f850..0f91f24b4a34 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -27,6 +27,7 @@ error: this seems like a manual implementation of the non-exhaustive pattern --> tests/ui/manual_non_exhaustive_enum.rs:29:1 | LL | / pub enum NoUnderscore { +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -35,7 +36,7 @@ LL | | } | |_^ | help: remove this variant - --> tests/ui/manual_non_exhaustive_enum.rs:33:5 + --> tests/ui/manual_non_exhaustive_enum.rs:34:5 | LL | C, | ^ diff --git a/tests/ui/manual_ok_err.rs b/tests/ui/manual_ok_err.rs index 03ad773f47cf..976311604a38 100644 --- a/tests/ui/manual_ok_err.rs +++ b/tests/ui/manual_ok_err.rs @@ -6,38 +6,44 @@ fn funcall() -> Result { fn main() { let _ = match funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Ok(v) => Some(v), Err(_) => None, }; let _ = match funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Ok(v) => Some(v), _v => None, }; let _ = match funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Err(v) => Some(v), Ok(_) => None, }; let _ = match funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Err(v) => Some(v), _v => None, }; let _ = if let Ok(v) = funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Some(v) } else { None }; let _ = if let Err(v) = funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Some(v) } else { None @@ -45,7 +51,8 @@ fn main() { #[allow(clippy::redundant_pattern)] let _ = match funcall() { - //~^ manual_ok_err + //~^ manual_ok_err + Ok(v) => Some(v), _v @ _ => None, }; @@ -62,7 +69,8 @@ fn main() { // Suggestion should be properly parenthesized let _ = match -S { - //~^ manual_ok_err + //~^ manual_ok_err + Ok(v) => Some(v), _ => None, }; diff --git a/tests/ui/manual_ok_err.stderr b/tests/ui/manual_ok_err.stderr index d0d5e2c81e96..ea430dd3eb45 100644 --- a/tests/ui/manual_ok_err.stderr +++ b/tests/ui/manual_ok_err.stderr @@ -4,6 +4,7 @@ error: manual implementation of `ok` LL | let _ = match funcall() { | _____________^ LL | | +LL | | LL | | Ok(v) => Some(v), LL | | Err(_) => None, LL | | }; @@ -13,44 +14,48 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_ok_err)]` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:14:13 + --> tests/ui/manual_ok_err.rs:15:13 | LL | let _ = match funcall() { | _____________^ LL | | +LL | | LL | | Ok(v) => Some(v), LL | | _v => None, LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:20:13 + --> tests/ui/manual_ok_err.rs:22:13 | LL | let _ = match funcall() { | _____________^ LL | | +LL | | LL | | Err(v) => Some(v), LL | | Ok(_) => None, LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:26:13 + --> tests/ui/manual_ok_err.rs:29:13 | LL | let _ = match funcall() { | _____________^ LL | | +LL | | LL | | Err(v) => Some(v), LL | | _v => None, LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:32:13 + --> tests/ui/manual_ok_err.rs:36:13 | LL | let _ = if let Ok(v) = funcall() { | _____________^ LL | | +LL | | LL | | Some(v) LL | | } else { LL | | None @@ -58,11 +63,12 @@ LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:39:13 + --> tests/ui/manual_ok_err.rs:44:13 | LL | let _ = if let Err(v) = funcall() { | _____________^ LL | | +LL | | LL | | Some(v) LL | | } else { LL | | None @@ -70,22 +76,24 @@ LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:47:13 + --> tests/ui/manual_ok_err.rs:53:13 | LL | let _ = match funcall() { | _____________^ LL | | +LL | | LL | | Ok(v) => Some(v), LL | | _v @ _ => None, LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:64:13 + --> tests/ui/manual_ok_err.rs:71:13 | LL | let _ = match -S { | _____________^ LL | | +LL | | LL | | Ok(v) => Some(v), LL | | _ => None, LL | | }; diff --git a/tests/ui/manual_ok_or.fixed b/tests/ui/manual_ok_or.fixed index cc53cb416a22..f326822149cd 100644 --- a/tests/ui/manual_ok_or.fixed +++ b/tests/ui/manual_ok_or.fixed @@ -9,12 +9,15 @@ fn main() { // basic case let foo: Option = None; foo.ok_or("error"); + //~^ manual_ok_or // eta expansion case foo.ok_or("error"); + //~^ manual_ok_or // turbo fish syntax None::.ok_or("error"); + //~^ manual_ok_or // multiline case #[rustfmt::skip] diff --git a/tests/ui/manual_ok_or.rs b/tests/ui/manual_ok_or.rs index 39c61a1e490f..7d065eda0ea1 100644 --- a/tests/ui/manual_ok_or.rs +++ b/tests/ui/manual_ok_or.rs @@ -9,16 +9,20 @@ fn main() { // basic case let foo: Option = None; foo.map_or(Err("error"), |v| Ok(v)); + //~^ manual_ok_or // eta expansion case foo.map_or(Err("error"), Ok); + //~^ manual_ok_or // turbo fish syntax None::.map_or(Err("error"), |v| Ok(v)); + //~^ manual_ok_or // multiline case #[rustfmt::skip] foo.map_or(Err::( + //~^ manual_ok_or &format!( "{}{}{}{}{}{}{}", "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer") diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index 4722f53580f1..e8176f4c31fa 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -8,25 +8,25 @@ LL | foo.map_or(Err("error"), |v| Ok(v)); = help: to override `-D warnings` add `#[allow(clippy::manual_ok_or)]` error: this pattern reimplements `Option::ok_or` - --> tests/ui/manual_ok_or.rs:14:5 + --> tests/ui/manual_ok_or.rs:15:5 | LL | foo.map_or(Err("error"), Ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> tests/ui/manual_ok_or.rs:17:5 + --> tests/ui/manual_ok_or.rs:19:5 | LL | None::.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `None::.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> tests/ui/manual_ok_or.rs:21:5 + --> tests/ui/manual_ok_or.rs:24:5 | LL | / foo.map_or(Err::( +LL | | LL | | &format!( LL | | "{}{}{}{}{}{}{}", -LL | | "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer") -LL | | ), +... | LL | | |v| Ok(v), LL | | ); | |_____^ diff --git a/tests/ui/manual_option_as_slice.fixed b/tests/ui/manual_option_as_slice.fixed index 48337d7654de..17a412017a43 100644 --- a/tests/ui/manual_option_as_slice.fixed +++ b/tests/ui/manual_option_as_slice.fixed @@ -9,19 +9,24 @@ fn check(x: Option) { _ = x.as_slice(); //~^ manual_option_as_slice - _ = x.as_slice(); - //~^ manual_option_as_slice _ = x.as_slice(); //~^ manual_option_as_slice + _ = x.as_slice(); //~^ manual_option_as_slice + + _ = x.as_slice(); + //~^ manual_option_as_slice + + { use std::slice::from_ref; _ = x.as_slice(); //~^ manual_option_as_slice + } // possible false positives diff --git a/tests/ui/manual_option_as_slice.rs b/tests/ui/manual_option_as_slice.rs index 561a8b534014..71166399cbea 100644 --- a/tests/ui/manual_option_as_slice.rs +++ b/tests/ui/manual_option_as_slice.rs @@ -3,13 +3,15 @@ fn check(x: Option) { _ = match x.as_ref() { - //~^ manual_option_as_slice + //~^ manual_option_as_slice + Some(f) => std::slice::from_ref(f), None => &[], }; _ = if let Some(f) = x.as_ref() { - //~^ manual_option_as_slice + //~^ manual_option_as_slice + std::slice::from_ref(f) } else { &[] @@ -18,19 +20,24 @@ fn check(x: Option) { _ = x.as_ref().map_or(&[][..], std::slice::from_ref); //~^ manual_option_as_slice + _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); //~^ manual_option_as_slice + _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); //~^ manual_option_as_slice + _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); //~^ manual_option_as_slice + { use std::slice::from_ref; _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); //~^ manual_option_as_slice + } // possible false positives diff --git a/tests/ui/manual_option_as_slice.stderr b/tests/ui/manual_option_as_slice.stderr index 569269d3e2b7..3a07c6a02dae 100644 --- a/tests/ui/manual_option_as_slice.stderr +++ b/tests/ui/manual_option_as_slice.stderr @@ -4,6 +4,7 @@ error: use `Option::as_slice` LL | _ = match x.as_ref() { | _________^ LL | | +LL | | LL | | Some(f) => std::slice::from_ref(f), LL | | None => &[], LL | | }; @@ -13,11 +14,12 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_option_as_slice)]` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:11:9 + --> tests/ui/manual_option_as_slice.rs:12:9 | LL | _ = if let Some(f) = x.as_ref() { | _________^ LL | | +LL | | LL | | std::slice::from_ref(f) LL | | } else { LL | | &[] @@ -25,31 +27,31 @@ LL | | }; | |_____^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:18:9 + --> tests/ui/manual_option_as_slice.rs:20:9 | LL | _ = x.as_ref().map_or(&[][..], std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:21:9 + --> tests/ui/manual_option_as_slice.rs:24:9 | LL | _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:24:9 + --> tests/ui/manual_option_as_slice.rs:28:9 | LL | _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:27:9 + --> tests/ui/manual_option_as_slice.rs:32:9 | LL | _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:32:13 + --> tests/ui/manual_option_as_slice.rs:38:13 | LL | _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` diff --git a/tests/ui/manual_pattern_char_comparison.fixed b/tests/ui/manual_pattern_char_comparison.fixed index 03e621d95ba1..b03e83e6b99d 100644 --- a/tests/ui/manual_pattern_char_comparison.fixed +++ b/tests/ui/manual_pattern_char_comparison.fixed @@ -9,16 +9,25 @@ impl NotStr { fn main() { let sentence = "Hello, world!"; sentence.trim_end_matches(['.', ',', '!', '?']); + //~^ manual_pattern_char_comparison sentence.split(['\n', 'X']); + //~^ manual_pattern_char_comparison sentence.split(['\n', 'X']); + //~^ manual_pattern_char_comparison sentence.splitn(3, 'X'); + //~^ manual_pattern_char_comparison sentence.splitn(3, |c: char| c.is_whitespace() || c == 'X'); let char_compare = 'X'; sentence.splitn(3, char_compare); + //~^ manual_pattern_char_comparison sentence.split(['\n', 'X', 'Y']); + //~^ manual_pattern_char_comparison sentence.splitn(3, 'X'); + //~^ manual_pattern_char_comparison sentence.splitn(3, ['X', 'W']); + //~^ manual_pattern_char_comparison sentence.find('🎈'); + //~^ manual_pattern_char_comparison let not_str = NotStr; not_str.find(|c: char| c == 'X'); @@ -58,4 +67,5 @@ fn msrv_1_57() { fn msrv_1_58() { let sentence = "Hello, world!"; sentence.trim_end_matches(['.', ',', '!', '?']); + //~^ manual_pattern_char_comparison } diff --git a/tests/ui/manual_pattern_char_comparison.rs b/tests/ui/manual_pattern_char_comparison.rs index 43e883cd325a..451480df4225 100644 --- a/tests/ui/manual_pattern_char_comparison.rs +++ b/tests/ui/manual_pattern_char_comparison.rs @@ -9,16 +9,25 @@ impl NotStr { fn main() { let sentence = "Hello, world!"; sentence.trim_end_matches(|c: char| c == '.' || c == ',' || c == '!' || c == '?'); + //~^ manual_pattern_char_comparison sentence.split(|c: char| c == '\n' || c == 'X'); + //~^ manual_pattern_char_comparison sentence.split(|c| c == '\n' || c == 'X'); + //~^ manual_pattern_char_comparison sentence.splitn(3, |c: char| c == 'X'); + //~^ manual_pattern_char_comparison sentence.splitn(3, |c: char| c.is_whitespace() || c == 'X'); let char_compare = 'X'; sentence.splitn(3, |c: char| c == char_compare); + //~^ manual_pattern_char_comparison sentence.split(|c: char| matches!(c, '\n' | 'X' | 'Y')); + //~^ manual_pattern_char_comparison sentence.splitn(3, |c: char| matches!(c, 'X')); + //~^ manual_pattern_char_comparison sentence.splitn(3, |c: char| matches!(c, 'X' | 'W')); + //~^ manual_pattern_char_comparison sentence.find(|c| c == '🎈'); + //~^ manual_pattern_char_comparison let not_str = NotStr; not_str.find(|c: char| c == 'X'); @@ -58,4 +67,5 @@ fn msrv_1_57() { fn msrv_1_58() { let sentence = "Hello, world!"; sentence.trim_end_matches(|c: char| c == '.' || c == ',' || c == '!' || c == '?'); + //~^ manual_pattern_char_comparison } diff --git a/tests/ui/manual_pattern_char_comparison.stderr b/tests/ui/manual_pattern_char_comparison.stderr index f185d7c8f676..d4fc3faa066f 100644 --- a/tests/ui/manual_pattern_char_comparison.stderr +++ b/tests/ui/manual_pattern_char_comparison.stderr @@ -8,55 +8,55 @@ LL | sentence.trim_end_matches(|c: char| c == '.' || c == ',' || c == '!' || = help: to override `-D warnings` add `#[allow(clippy::manual_pattern_char_comparison)]` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:12:20 + --> tests/ui/manual_pattern_char_comparison.rs:13:20 | LL | sentence.split(|c: char| c == '\n' || c == 'X'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['\n', 'X']` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:13:20 + --> tests/ui/manual_pattern_char_comparison.rs:15:20 | LL | sentence.split(|c| c == '\n' || c == 'X'); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['\n', 'X']` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:14:24 + --> tests/ui/manual_pattern_char_comparison.rs:17:24 | LL | sentence.splitn(3, |c: char| c == 'X'); | ^^^^^^^^^^^^^^^^^^ help: consider using a `char`: `'X'` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:17:24 + --> tests/ui/manual_pattern_char_comparison.rs:21:24 | LL | sentence.splitn(3, |c: char| c == char_compare); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a `char`: `char_compare` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:18:20 + --> tests/ui/manual_pattern_char_comparison.rs:23:20 | LL | sentence.split(|c: char| matches!(c, '\n' | 'X' | 'Y')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['\n', 'X', 'Y']` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:19:24 + --> tests/ui/manual_pattern_char_comparison.rs:25:24 | LL | sentence.splitn(3, |c: char| matches!(c, 'X')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a `char`: `'X'` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:20:24 + --> tests/ui/manual_pattern_char_comparison.rs:27:24 | LL | sentence.splitn(3, |c: char| matches!(c, 'X' | 'W')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['X', 'W']` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:21:19 + --> tests/ui/manual_pattern_char_comparison.rs:29:19 | LL | sentence.find(|c| c == '🎈'); | ^^^^^^^^^^^^^ help: consider using a `char`: `'🎈'` error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:60:31 + --> tests/ui/manual_pattern_char_comparison.rs:69:31 | LL | sentence.trim_end_matches(|c: char| c == '.' || c == ',' || c == '!' || c == '?'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['.', ',', '!', '?']` diff --git a/tests/ui/manual_range_patterns.fixed b/tests/ui/manual_range_patterns.fixed index 60467bf9e884..c05e1fb27b03 100644 --- a/tests/ui/manual_range_patterns.fixed +++ b/tests/ui/manual_range_patterns.fixed @@ -6,7 +6,9 @@ fn main() { let f = 6; let _ = matches!(f, 1..=10); + //~^ manual_range_patterns let _ = matches!(f, 1..=10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing let _ = matches!(f, | 4); let _ = matches!(f, 4 | 5); @@ -14,34 +16,51 @@ fn main() { let _ = matches!(f, 0 | 2147483647); let _ = matches!(f, -2147483647 | 2147483647); let _ = matches!(f, 1..=4); + //~^ manual_range_patterns let _ = matches!(f, 1..4); + //~^ manual_range_patterns let _ = matches!(f, 1..=48324729); + //~^ manual_range_patterns let _ = matches!(f, 0..=48324730); + //~^ manual_range_patterns let _ = matches!(f, 0..=3); + //~^ manual_range_patterns #[allow(clippy::match_like_matches_macro)] let _ = match f { 1..=10 => true, + //~^ manual_range_patterns _ => false, }; let _ = matches!(f, -5..=3); + //~^ manual_range_patterns let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing let _ = matches!(f, -1_000_001..=1_000_001); + //~^ manual_range_patterns let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); matches!(f, 0x00..=0x03); + //~^ manual_range_patterns matches!(f, 0x00..=0x07); + //~^ manual_range_patterns matches!(f, -0x09..=0x00); + //~^ manual_range_patterns matches!(f, 0..=5); + //~^ manual_range_patterns matches!(f, 0..5); + //~^ manual_range_patterns matches!(f, 0..10); + //~^ manual_range_patterns matches!(f, 0..=10); + //~^ manual_range_patterns matches!(f, 0..=10); + //~^ manual_range_patterns macro_rules! mac { ($e:expr) => { matches!($e, 1..=10) + //~^ manual_range_patterns }; } mac!(f); diff --git a/tests/ui/manual_range_patterns.rs b/tests/ui/manual_range_patterns.rs index 9cd803334499..e5c403dc5f2e 100644 --- a/tests/ui/manual_range_patterns.rs +++ b/tests/ui/manual_range_patterns.rs @@ -6,7 +6,9 @@ fn main() { let f = 6; let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); + //~^ manual_range_patterns let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing let _ = matches!(f, | 4); let _ = matches!(f, 4 | 5); @@ -14,34 +16,51 @@ fn main() { let _ = matches!(f, 0 | 2147483647); let _ = matches!(f, -2147483647 | 2147483647); let _ = matches!(f, 1 | (2..=4)); + //~^ manual_range_patterns let _ = matches!(f, 1 | (2..4)); + //~^ manual_range_patterns let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); + //~^ manual_range_patterns let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); + //~^ manual_range_patterns let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); + //~^ manual_range_patterns #[allow(clippy::match_like_matches_macro)] let _ = match f { 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, + //~^ manual_range_patterns _ => false, }; let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); + //~^ manual_range_patterns let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); + //~^ manual_range_patterns let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); matches!(f, 0x00 | 0x01 | 0x02 | 0x03); + //~^ manual_range_patterns matches!(f, 0x00..=0x05 | 0x06 | 0x07); + //~^ manual_range_patterns matches!(f, -0x09 | -0x08 | -0x07..=0x00); + //~^ manual_range_patterns matches!(f, 0..5 | 5); + //~^ manual_range_patterns matches!(f, 0 | 1..5); + //~^ manual_range_patterns matches!(f, 0..=5 | 6..10); + //~^ manual_range_patterns matches!(f, 0..5 | 5..=10); + //~^ manual_range_patterns matches!(f, 5..=10 | 0..5); + //~^ manual_range_patterns macro_rules! mac { ($e:expr) => { matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) + //~^ manual_range_patterns }; } mac!(f); diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index 7c19fdd475f1..e494e7234d68 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -8,109 +8,109 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); = help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:9:25 + --> tests/ui/manual_range_patterns.rs:10: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 - --> tests/ui/manual_range_patterns.rs:16:25 + --> tests/ui/manual_range_patterns.rs:18:25 | LL | let _ = matches!(f, 1 | (2..=4)); | ^^^^^^^^^^^ help: try: `1..=4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:17:25 + --> tests/ui/manual_range_patterns.rs:20:25 | LL | let _ = matches!(f, 1 | (2..4)); | ^^^^^^^^^^ help: try: `1..4` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:18:25 + --> tests/ui/manual_range_patterns.rs:22: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 - --> tests/ui/manual_range_patterns.rs:19:25 + --> tests/ui/manual_range_patterns.rs:24: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 - --> tests/ui/manual_range_patterns.rs:20:25 + --> tests/ui/manual_range_patterns.rs:26: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 - --> tests/ui/manual_range_patterns.rs:23:9 + --> tests/ui/manual_range_patterns.rs:30: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 - --> tests/ui/manual_range_patterns.rs:26:25 + --> tests/ui/manual_range_patterns.rs:34: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 - --> tests/ui/manual_range_patterns.rs:28:25 + --> tests/ui/manual_range_patterns.rs:37:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:31:17 + --> tests/ui/manual_range_patterns.rs:41:17 | LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:32:17 + --> tests/ui/manual_range_patterns.rs:43:17 | LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:33:17 + --> tests/ui/manual_range_patterns.rs:45:17 | LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:35:17 + --> tests/ui/manual_range_patterns.rs:48:17 | LL | matches!(f, 0..5 | 5); | ^^^^^^^^ help: try: `0..=5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:36:17 + --> tests/ui/manual_range_patterns.rs:50:17 | LL | matches!(f, 0 | 1..5); | ^^^^^^^^ help: try: `0..5` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:38:17 + --> tests/ui/manual_range_patterns.rs:53:17 | LL | matches!(f, 0..=5 | 6..10); | ^^^^^^^^^^^^^ help: try: `0..10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:39:17 + --> tests/ui/manual_range_patterns.rs:55:17 | LL | matches!(f, 0..5 | 5..=10); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:40:17 + --> tests/ui/manual_range_patterns.rs:57:17 | LL | matches!(f, 5..=10 | 0..5); | ^^^^^^^^^^^^^ help: try: `0..=10` error: this OR pattern can be rewritten using a range - --> tests/ui/manual_range_patterns.rs:44:26 + --> tests/ui/manual_range_patterns.rs:62: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 2d50865586d1..e64654bb6866 100644 --- a/tests/ui/manual_rem_euclid.fixed +++ b/tests/ui/manual_rem_euclid.fixed @@ -11,10 +11,15 @@ fn main() { let value: i32 = 5; let _: i32 = value.rem_euclid(4); + //~^ manual_rem_euclid let _: i32 = value.rem_euclid(4); + //~^ manual_rem_euclid let _: i32 = value.rem_euclid(4); + //~^ manual_rem_euclid let _: i32 = value.rem_euclid(4); + //~^ manual_rem_euclid let _: i32 = 1 + value.rem_euclid(4); + //~^ manual_rem_euclid let _: i32 = (3 + value % 4) % 4; let _: i32 = (-4 + value % -4) % -4; @@ -35,6 +40,7 @@ fn main() { inline!( let value: i32 = 5; let _: i32 = value.rem_euclid(4); + //~^ manual_rem_euclid ); // Do not lint in external macros @@ -47,11 +53,13 @@ fn main() { // Should lint for params too pub fn rem_euclid_4(num: i32) -> i32 { num.rem_euclid(4) + //~^ manual_rem_euclid } // Constant version came later, should still lint pub const fn const_rem_euclid_4(num: i32) -> i32 { num.rem_euclid(4) + //~^ manual_rem_euclid } #[clippy::msrv = "1.37"] @@ -64,6 +72,7 @@ pub fn msrv_1_37() { pub fn msrv_1_38() { let x: i32 = 10; let _: i32 = x.rem_euclid(4); + //~^ manual_rem_euclid } // For const fns: @@ -77,4 +86,5 @@ pub const fn msrv_1_51() { pub const fn msrv_1_52() { let x: i32 = 10; let _: i32 = x.rem_euclid(4); + //~^ manual_rem_euclid } diff --git a/tests/ui/manual_rem_euclid.rs b/tests/ui/manual_rem_euclid.rs index e405a2db4765..4561a7ee9ea4 100644 --- a/tests/ui/manual_rem_euclid.rs +++ b/tests/ui/manual_rem_euclid.rs @@ -11,10 +11,15 @@ fn main() { let value: i32 = 5; let _: i32 = ((value % 4) + 4) % 4; + //~^ manual_rem_euclid let _: i32 = (4 + (value % 4)) % 4; + //~^ manual_rem_euclid let _: i32 = (value % 4 + 4) % 4; + //~^ manual_rem_euclid let _: i32 = (4 + value % 4) % 4; + //~^ manual_rem_euclid let _: i32 = 1 + (4 + value % 4) % 4; + //~^ manual_rem_euclid let _: i32 = (3 + value % 4) % 4; let _: i32 = (-4 + value % -4) % -4; @@ -35,6 +40,7 @@ fn main() { inline!( let value: i32 = 5; let _: i32 = ((value % 4) + 4) % 4; + //~^ manual_rem_euclid ); // Do not lint in external macros @@ -47,11 +53,13 @@ fn main() { // Should lint for params too pub fn rem_euclid_4(num: i32) -> i32 { ((num % 4) + 4) % 4 + //~^ manual_rem_euclid } // Constant version came later, should still lint pub const fn const_rem_euclid_4(num: i32) -> i32 { ((num % 4) + 4) % 4 + //~^ manual_rem_euclid } #[clippy::msrv = "1.37"] @@ -64,6 +72,7 @@ pub fn msrv_1_37() { pub fn msrv_1_38() { let x: i32 = 10; let _: i32 = ((x % 4) + 4) % 4; + //~^ manual_rem_euclid } // For const fns: @@ -77,4 +86,5 @@ pub const fn msrv_1_51() { pub const fn msrv_1_52() { let x: i32 = 10; let _: i32 = ((x % 4) + 4) % 4; + //~^ manual_rem_euclid } diff --git a/tests/ui/manual_rem_euclid.stderr b/tests/ui/manual_rem_euclid.stderr index a19fdadb1c9b..386815b23b68 100644 --- a/tests/ui/manual_rem_euclid.stderr +++ b/tests/ui/manual_rem_euclid.stderr @@ -8,31 +8,31 @@ LL | let _: i32 = ((value % 4) + 4) % 4; = help: to override `-D warnings` add `#[allow(clippy::manual_rem_euclid)]` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:14:18 + --> tests/ui/manual_rem_euclid.rs:15:18 | LL | let _: i32 = (4 + (value % 4)) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:15:18 + --> tests/ui/manual_rem_euclid.rs:17:18 | LL | let _: i32 = (value % 4 + 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:16:18 + --> tests/ui/manual_rem_euclid.rs:19:18 | LL | let _: i32 = (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:17:22 + --> tests/ui/manual_rem_euclid.rs:21:22 | LL | let _: i32 = 1 + (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:37:22 + --> tests/ui/manual_rem_euclid.rs:42:22 | LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` @@ -40,25 +40,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 - --> tests/ui/manual_rem_euclid.rs:49:5 + --> tests/ui/manual_rem_euclid.rs:55:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:54:5 + --> tests/ui/manual_rem_euclid.rs:61:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:66:18 + --> tests/ui/manual_rem_euclid.rs:74:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` error: manual `rem_euclid` implementation - --> tests/ui/manual_rem_euclid.rs:79:18 + --> tests/ui/manual_rem_euclid.rs:88:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` diff --git a/tests/ui/manual_repeat_n.fixed b/tests/ui/manual_repeat_n.fixed index 4235b02a89e3..44ad3c02d3b8 100644 --- a/tests/ui/manual_repeat_n.fixed +++ b/tests/ui/manual_repeat_n.fixed @@ -4,14 +4,19 @@ use std::iter::repeat; fn main() { let _ = std::iter::repeat_n(10, 3); + //~^ manual_repeat_n let _ = std::iter::repeat_n(String::from("foo"), 4); + //~^ manual_repeat_n for value in std::iter::repeat_n(5, 3) {} + //~^ manual_repeat_n let _: Vec<_> = std::iter::repeat_n(String::from("bar"), 10).collect(); + //~^ manual_repeat_n let _ = std::iter::repeat_n(vec![1, 2], 2); + //~^ manual_repeat_n } mod foo_lib { diff --git a/tests/ui/manual_repeat_n.rs b/tests/ui/manual_repeat_n.rs index dbf9ac6a14af..ef6d6827d573 100644 --- a/tests/ui/manual_repeat_n.rs +++ b/tests/ui/manual_repeat_n.rs @@ -4,14 +4,19 @@ use std::iter::repeat; fn main() { let _ = repeat(10).take(3); + //~^ manual_repeat_n let _ = repeat(String::from("foo")).take(4); + //~^ manual_repeat_n for value in std::iter::repeat(5).take(3) {} + //~^ manual_repeat_n let _: Vec<_> = std::iter::repeat(String::from("bar")).take(10).collect(); + //~^ manual_repeat_n let _ = repeat(vec![1, 2]).take(2); + //~^ manual_repeat_n } mod foo_lib { diff --git a/tests/ui/manual_repeat_n.stderr b/tests/ui/manual_repeat_n.stderr index 87395b3f8bf1..de968b3ff791 100644 --- a/tests/ui/manual_repeat_n.stderr +++ b/tests/ui/manual_repeat_n.stderr @@ -8,25 +8,25 @@ LL | let _ = repeat(10).take(3); = help: to override `-D warnings` add `#[allow(clippy::manual_repeat_n)]` error: this `repeat().take()` can be written more concisely - --> tests/ui/manual_repeat_n.rs:8:13 + --> tests/ui/manual_repeat_n.rs:9:13 | LL | let _ = repeat(String::from("foo")).take(4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(String::from("foo"), 4)` error: this `repeat().take()` can be written more concisely - --> tests/ui/manual_repeat_n.rs:10:18 + --> tests/ui/manual_repeat_n.rs:12:18 | LL | for value in std::iter::repeat(5).take(3) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(5, 3)` error: this `repeat().take()` can be written more concisely - --> tests/ui/manual_repeat_n.rs:12:21 + --> tests/ui/manual_repeat_n.rs:15:21 | LL | let _: Vec<_> = std::iter::repeat(String::from("bar")).take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(String::from("bar"), 10)` error: this `repeat().take()` can be written more concisely - --> tests/ui/manual_repeat_n.rs:14:13 + --> tests/ui/manual_repeat_n.rs:18:13 | LL | let _ = repeat(vec![1, 2]).take(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(vec![1, 2], 2)` diff --git a/tests/ui/manual_retain.fixed b/tests/ui/manual_retain.fixed index 5540029bf6b1..ca8491131c06 100644 --- a/tests/ui/manual_retain.fixed +++ b/tests/ui/manual_retain.fixed @@ -23,13 +23,18 @@ fn binary_heap_retain() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); // Do lint. binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain binary_heap.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed binary_heap = binary_heap @@ -60,7 +65,9 @@ fn btree_map_retain() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. btree_map.retain(|k, _| k % 2 == 0); + //~^ manual_retain btree_map.retain(|_, &mut v| v % 2 == 0); + //~^ manual_retain btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0)); // Do not lint, because the parameters are not matched in tuple pattern @@ -84,13 +91,18 @@ fn btree_set_retain() { // Do lint. btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain btree_set.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed btree_set = btree_set @@ -121,7 +133,9 @@ fn hash_map_retain() { let mut hash_map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. hash_map.retain(|k, _| k % 2 == 0); + //~^ manual_retain hash_map.retain(|_, &mut v| v % 2 == 0); + //~^ manual_retain hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0)); // Do not lint, because the parameters are not matched in tuple pattern @@ -144,13 +158,18 @@ fn hash_set_retain() { let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]); // Do lint. hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain hash_set.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]); tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -180,6 +199,7 @@ fn string_retain() { let mut s = String::from("foobar"); // Do lint. s.retain(|c| c != 'o'); + //~^ manual_retain // Do not lint, because this expression is not assign. let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect(); @@ -192,13 +212,18 @@ fn vec_retain() { let mut vec = vec![0, 1, 2]; // Do lint. vec.retain(|x| x % 2 == 0); + //~^ manual_retain vec.retain(|x| x % 2 == 0); + //~^ manual_retain vec.retain(|x| x % 2 == 0); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = vec![(0, 1), (1, 2), (2, 3)]; tuples.retain(|(ref x, ref y)| *x == 0); + //~^ manual_retain tuples.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do not lint, because type conversion is performed vec = vec.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -221,8 +246,11 @@ fn vec_deque_retain() { // Do lint. vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain vec_deque.retain(|x| x % 2 == 0); + //~^ manual_retain // Do not lint, because type conversion is performed vec_deque = vec_deque @@ -280,10 +308,12 @@ fn issue_10393() { // Do lint let mut vec = vec![(0, 1), (1, 2), (2, 3)]; vec.retain(|(x, y)| *x == 0); + //~^ manual_retain // Do lint let mut tuples = vec![(true, -2), (false, 3)]; tuples.retain(|(_, n)| *n > 0); + //~^ manual_retain } fn issue_11457() { @@ -301,11 +331,17 @@ fn issue_12081() { // Do lint vec.retain(|&x| x == 0); + //~^ manual_retain vec.retain(|&x| x == 0); + //~^ manual_retain vec.retain(|&x| x == 0); + //~^ manual_retain // Do lint vec.retain(|x| *x == 0); + //~^ manual_retain vec.retain(|x| *x == 0); + //~^ manual_retain vec.retain(|x| *x == 0); + //~^ manual_retain } diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index cee641d9d65f..61e2d73b544f 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -23,13 +23,18 @@ fn binary_heap_retain() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); // Do lint. binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed binary_heap = binary_heap @@ -60,8 +65,11 @@ fn btree_map_retain() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); + //~^ manual_retain btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); + //~^ manual_retain btree_map = btree_map + //~^ manual_retain .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) .collect(); @@ -87,13 +95,18 @@ fn btree_set_retain() { // Do lint. btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed btree_set = btree_set @@ -124,8 +137,11 @@ fn hash_map_retain() { let mut hash_map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); // Do lint. hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); + //~^ manual_retain hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); + //~^ manual_retain hash_map = hash_map + //~^ manual_retain .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) .collect(); @@ -150,13 +166,18 @@ fn hash_set_retain() { let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]); // Do lint. hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]); tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -186,6 +207,7 @@ fn string_retain() { let mut s = String::from("foobar"); // Do lint. s = s.chars().filter(|&c| c != 'o').to_owned().collect(); + //~^ manual_retain // Do not lint, because this expression is not assign. let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect(); @@ -198,13 +220,18 @@ fn vec_retain() { let mut vec = vec![0, 1, 2]; // Do lint. vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do lint, because we use pattern matching let mut tuples = vec![(0, 1), (1, 2), (2, 3)]; tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); + //~^ manual_retain tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); + //~^ manual_retain // Do not lint, because type conversion is performed vec = vec.into_iter().filter(|x| x % 2 == 0).collect::>(); @@ -227,8 +254,11 @@ fn vec_deque_retain() { // Do lint. vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); + //~^ manual_retain vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); + //~^ manual_retain vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); + //~^ manual_retain // Do not lint, because type conversion is performed vec_deque = vec_deque @@ -286,10 +316,12 @@ fn issue_10393() { // Do lint let mut vec = vec![(0, 1), (1, 2), (2, 3)]; vec = vec.into_iter().filter(|(x, y)| *x == 0).collect(); + //~^ manual_retain // Do lint let mut tuples = vec![(true, -2), (false, 3)]; tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect(); + //~^ manual_retain } fn issue_11457() { @@ -307,11 +339,17 @@ fn issue_12081() { // Do lint vec = vec.iter().filter(|&&x| x == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&&x| x == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|&x| x == 0).collect(); + //~^ manual_retain // Do lint vec = vec.iter().filter(|&x| *x == 0).copied().collect(); + //~^ manual_retain vec = vec.iter().filter(|&x| *x == 0).cloned().collect(); + //~^ manual_retain vec = vec.into_iter().filter(|x| *x == 0).collect(); + //~^ manual_retain } diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index c25c804df758..2f81647dd8b7 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -8,229 +8,231 @@ LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_retain)]` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:26:5 + --> tests/ui/manual_retain.rs:27: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()` - --> tests/ui/manual_retain.rs:27:5 + --> tests/ui/manual_retain.rs:29: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()` - --> tests/ui/manual_retain.rs:31:5 + --> tests/ui/manual_retain.rs:34:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:32:5 + --> tests/ui/manual_retain.rs:36:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:62:5 + --> tests/ui/manual_retain.rs:67: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()` - --> tests/ui/manual_retain.rs:63:5 + --> tests/ui/manual_retain.rs:69: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()` - --> tests/ui/manual_retain.rs:64:5 + --> tests/ui/manual_retain.rs:71:5 | LL | / btree_map = btree_map +LL | | LL | | .into_iter() LL | | .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) 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()` - --> tests/ui/manual_retain.rs:89:5 + --> tests/ui/manual_retain.rs:97: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()` - --> tests/ui/manual_retain.rs:90:5 + --> tests/ui/manual_retain.rs:99: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()` - --> tests/ui/manual_retain.rs:91:5 + --> tests/ui/manual_retain.rs:101: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()` - --> tests/ui/manual_retain.rs:95:5 + --> tests/ui/manual_retain.rs:106:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:96:5 + --> tests/ui/manual_retain.rs:108:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:126:5 + --> tests/ui/manual_retain.rs:139: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()` - --> tests/ui/manual_retain.rs:127:5 + --> tests/ui/manual_retain.rs:141: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()` - --> tests/ui/manual_retain.rs:128:5 + --> tests/ui/manual_retain.rs:143:5 | LL | / hash_map = hash_map +LL | | LL | | .into_iter() LL | | .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) 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()` - --> tests/ui/manual_retain.rs:152:5 + --> tests/ui/manual_retain.rs:168: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()` - --> tests/ui/manual_retain.rs:153:5 + --> tests/ui/manual_retain.rs:170: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()` - --> tests/ui/manual_retain.rs:154:5 + --> tests/ui/manual_retain.rs:172: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()` - --> tests/ui/manual_retain.rs:158:5 + --> tests/ui/manual_retain.rs:177:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:159:5 + --> tests/ui/manual_retain.rs:179:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:188:5 + --> tests/ui/manual_retain.rs:209: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()` - --> tests/ui/manual_retain.rs:200:5 + --> tests/ui/manual_retain.rs:222: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()` - --> tests/ui/manual_retain.rs:201:5 + --> tests/ui/manual_retain.rs:224: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()` - --> tests/ui/manual_retain.rs:202:5 + --> tests/ui/manual_retain.rs:226: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()` - --> tests/ui/manual_retain.rs:206:5 + --> tests/ui/manual_retain.rs:231:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:207:5 + --> tests/ui/manual_retain.rs:233:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:229:5 + --> tests/ui/manual_retain.rs:256: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()` - --> tests/ui/manual_retain.rs:230:5 + --> tests/ui/manual_retain.rs:258: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()` - --> tests/ui/manual_retain.rs:231:5 + --> tests/ui/manual_retain.rs:260: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: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:288:5 + --> tests/ui/manual_retain.rs:318:5 | LL | vec = vec.into_iter().filter(|(x, y)| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:292:5 + --> tests/ui/manual_retain.rs:323:5 | LL | tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(_, n)| *n > 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:309:5 + --> tests/ui/manual_retain.rs:341:5 | LL | vec = vec.iter().filter(|&&x| x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:310:5 + --> tests/ui/manual_retain.rs:343:5 | LL | vec = vec.iter().filter(|&&x| x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:311:5 + --> tests/ui/manual_retain.rs:345:5 | LL | vec = vec.into_iter().filter(|&x| x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:314:5 + --> tests/ui/manual_retain.rs:349:5 | LL | vec = vec.iter().filter(|&x| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:315:5 + --> tests/ui/manual_retain.rs:351:5 | LL | vec = vec.iter().filter(|&x| *x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:316:5 + --> tests/ui/manual_retain.rs:353:5 | LL | vec = vec.into_iter().filter(|x| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` diff --git a/tests/ui/manual_rotate.fixed b/tests/ui/manual_rotate.fixed index 5d33838a3187..49db8661369e 100644 --- a/tests/ui/manual_rotate.fixed +++ b/tests/ui/manual_rotate.fixed @@ -6,18 +6,29 @@ fn main() { let a_u32 = 1u32; // True positives let y_u8 = x_u8.rotate_right(3); + //~^ manual_rotate let y_u16 = x_u16.rotate_right(7); + //~^ manual_rotate let y_u32 = x_u32.rotate_right(8); + //~^ manual_rotate let y_u64 = x_u64.rotate_right(9); + //~^ manual_rotate let y_i8 = x_i8.rotate_right(3); + //~^ manual_rotate let y_i16 = x_i16.rotate_right(7); + //~^ manual_rotate let y_i32 = x_i32.rotate_right(8); + //~^ manual_rotate let y_i64 = x_i64.rotate_right(9); + //~^ manual_rotate // Plus also works instead of | let y_u32_plus = x_u32.rotate_right(8); + //~^ manual_rotate // Complex expression let y_u32_complex = (x_u32 | 3256).rotate_right(8); + //~^ manual_rotate let y_u64_as = (x_u32 as u64).rotate_right(8); + //~^ manual_rotate // False positives - can't be replaced with a rotation let y_u8_false = (x_u8 >> 6) | (x_u8 << 3); diff --git a/tests/ui/manual_rotate.rs b/tests/ui/manual_rotate.rs index 5377491fb1a3..6445e60aa25d 100644 --- a/tests/ui/manual_rotate.rs +++ b/tests/ui/manual_rotate.rs @@ -6,18 +6,29 @@ fn main() { let a_u32 = 1u32; // True positives let y_u8 = (x_u8 >> 3) | (x_u8 << 5); + //~^ manual_rotate let y_u16 = (x_u16 >> 7) | (x_u16 << 9); + //~^ manual_rotate let y_u32 = (x_u32 >> 8) | (x_u32 << 24); + //~^ manual_rotate let y_u64 = (x_u64 >> 9) | (x_u64 << 55); + //~^ manual_rotate let y_i8 = (x_i8 >> 3) | (x_i8 << 5); + //~^ manual_rotate let y_i16 = (x_i16 >> 7) | (x_i16 << 9); + //~^ manual_rotate let y_i32 = (x_i32 >> 8) | (x_i32 << 24); + //~^ manual_rotate let y_i64 = (x_i64 >> 9) | (x_i64 << 55); + //~^ manual_rotate // Plus also works instead of | let y_u32_plus = (x_u32 >> 8) + (x_u32 << 24); + //~^ manual_rotate // Complex expression let y_u32_complex = ((x_u32 | 3256) >> 8) | ((x_u32 | 3256) << 24); + //~^ manual_rotate let y_u64_as = (x_u32 as u64 >> 8) | ((x_u32 as u64) << 56); + //~^ manual_rotate // False positives - can't be replaced with a rotation let y_u8_false = (x_u8 >> 6) | (x_u8 << 3); diff --git a/tests/ui/manual_rotate.stderr b/tests/ui/manual_rotate.stderr index 52da0861f700..a28721fbb94c 100644 --- a/tests/ui/manual_rotate.stderr +++ b/tests/ui/manual_rotate.stderr @@ -8,61 +8,61 @@ LL | let y_u8 = (x_u8 >> 3) | (x_u8 << 5); = help: to override `-D warnings` add `#[allow(clippy::manual_rotate)]` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:9:17 + --> tests/ui/manual_rotate.rs:10:17 | LL | let y_u16 = (x_u16 >> 7) | (x_u16 << 9); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_u16.rotate_right(7)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:10:17 + --> tests/ui/manual_rotate.rs:12:17 | LL | let y_u32 = (x_u32 >> 8) | (x_u32 << 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_u32.rotate_right(8)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:11:17 + --> tests/ui/manual_rotate.rs:14:17 | LL | let y_u64 = (x_u64 >> 9) | (x_u64 << 55); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_u64.rotate_right(9)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:12:16 + --> tests/ui/manual_rotate.rs:16:16 | LL | let y_i8 = (x_i8 >> 3) | (x_i8 << 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_i8.rotate_right(3)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:13:17 + --> tests/ui/manual_rotate.rs:18:17 | LL | let y_i16 = (x_i16 >> 7) | (x_i16 << 9); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_i16.rotate_right(7)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:14:17 + --> tests/ui/manual_rotate.rs:20:17 | LL | let y_i32 = (x_i32 >> 8) | (x_i32 << 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_i32.rotate_right(8)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:15:17 + --> tests/ui/manual_rotate.rs:22:17 | LL | let y_i64 = (x_i64 >> 9) | (x_i64 << 55); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_i64.rotate_right(9)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:17:22 + --> tests/ui/manual_rotate.rs:25:22 | LL | let y_u32_plus = (x_u32 >> 8) + (x_u32 << 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `x_u32.rotate_right(8)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:19:25 + --> tests/ui/manual_rotate.rs:28:25 | LL | let y_u32_complex = ((x_u32 | 3256) >> 8) | ((x_u32 | 3256) << 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `(x_u32 | 3256).rotate_right(8)` error: there is no need to manually implement bit rotation - --> tests/ui/manual_rotate.rs:20:20 + --> tests/ui/manual_rotate.rs:30:20 | LL | let y_u64_as = (x_u32 as u64 >> 8) | ((x_u32 as u64) << 56); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: this expression can be rewritten as: `(x_u32 as u64).rotate_right(8)` diff --git a/tests/ui/manual_saturating_arithmetic.fixed b/tests/ui/manual_saturating_arithmetic.fixed index 528a65790c4c..3f73d6e5a1a6 100644 --- a/tests/ui/manual_saturating_arithmetic.fixed +++ b/tests/ui/manual_saturating_arithmetic.fixed @@ -4,38 +4,57 @@ use std::{i32, i128, u32, u128}; fn main() { let _ = 1u32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1u8.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1u128.saturating_add(1); let _ = 1u32.checked_add(1).unwrap_or(1234); // ok let _ = 1u8.checked_add(1).unwrap_or(0); // ok let _ = 1u32.saturating_mul(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u8.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok let _ = 1u8.checked_sub(1).unwrap_or(255); // ok let _ = 1i32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_add(1); + //~^ manual_saturating_arithmetic let _ = 1i128.saturating_add(1); let _ = 1i32.saturating_add(-1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_add(-1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_add(-1); + //~^ manual_saturating_arithmetic let _ = 1i128.saturating_add(-1); let _ = 1i32.checked_add(1).unwrap_or(1234); // ok let _ = 1i8.checked_add(1).unwrap_or(-128); // ok let _ = 1i8.checked_add(-1).unwrap_or(127); // ok let _ = 1i32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_sub(1); + //~^ manual_saturating_arithmetic let _ = 1i128.saturating_sub(1); let _ = 1i32.saturating_sub(-1); + //~^ manual_saturating_arithmetic let _ = 1i32.saturating_sub(-1); + //~^ manual_saturating_arithmetic let _ = 1i8.saturating_sub(-1); + //~^ manual_saturating_arithmetic let _ = 1i128.saturating_sub(-1); let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok let _ = 1i8.checked_sub(1).unwrap_or(127); // ok diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs index 55f3720dfcc0..c0d7f26916ee 100644 --- a/tests/ui/manual_saturating_arithmetic.rs +++ b/tests/ui/manual_saturating_arithmetic.rs @@ -4,31 +4,47 @@ use std::{i32, i128, u32, u128}; fn main() { let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); + //~^ manual_saturating_arithmetic let _ = 1u8.checked_add(1).unwrap_or(255); + //~^ manual_saturating_arithmetic let _ = 1u128 + //~^ manual_saturating_arithmetic .checked_add(1) .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); let _ = 1u32.checked_add(1).unwrap_or(1234); // ok let _ = 1u8.checked_add(1).unwrap_or(0); // ok let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); + //~^ manual_saturating_arithmetic let _ = 1u8.checked_sub(1).unwrap_or(0); + //~^ manual_saturating_arithmetic let _ = 1u32.checked_sub(1).unwrap_or(1234); // ok let _ = 1u8.checked_sub(1).unwrap_or(255); // ok let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_add(1).unwrap_or(127); + //~^ manual_saturating_arithmetic let _ = 1i128 + //~^ manual_saturating_arithmetic .checked_add(1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_add(-1).unwrap_or(-128); + //~^ manual_saturating_arithmetic let _ = 1i128 + //~^ manual_saturating_arithmetic .checked_add(-1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); let _ = 1i32.checked_add(1).unwrap_or(1234); // ok @@ -36,15 +52,23 @@ fn main() { let _ = 1i8.checked_add(-1).unwrap_or(127); // ok let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_sub(1).unwrap_or(-128); + //~^ manual_saturating_arithmetic let _ = 1i128 + //~^ manual_saturating_arithmetic .checked_sub(1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); + //~^ manual_saturating_arithmetic let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); + //~^ manual_saturating_arithmetic let _ = 1i8.checked_sub(-1).unwrap_or(127); + //~^ manual_saturating_arithmetic let _ = 1i128 + //~^ manual_saturating_arithmetic .checked_sub(-1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok diff --git a/tests/ui/manual_saturating_arithmetic.stderr b/tests/ui/manual_saturating_arithmetic.stderr index b6a8df0f84e1..9d133d8a073b 100644 --- a/tests/ui/manual_saturating_arithmetic.stderr +++ b/tests/ui/manual_saturating_arithmetic.stderr @@ -8,154 +8,159 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); = help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:7:13 + --> tests/ui/manual_saturating_arithmetic.rs:8:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:8:13 + --> tests/ui/manual_saturating_arithmetic.rs:10:13 | LL | let _ = 1u8.checked_add(1).unwrap_or(255); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u8.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:9:13 + --> tests/ui/manual_saturating_arithmetic.rs:12:13 | LL | let _ = 1u128 | _____________^ +LL | | LL | | .checked_add(1) LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); | |_______________________________________________________________________^ help: consider using `saturating_add`: `1u128.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:14:13 + --> tests/ui/manual_saturating_arithmetic.rs:18:13 | LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `1u32.saturating_mul(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:16:13 + --> tests/ui/manual_saturating_arithmetic.rs:21:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:17:13 + --> tests/ui/manual_saturating_arithmetic.rs:23:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:18:13 + --> tests/ui/manual_saturating_arithmetic.rs:25:13 | LL | let _ = 1u8.checked_sub(1).unwrap_or(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u8.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:22:13 + --> tests/ui/manual_saturating_arithmetic.rs:30:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:23:13 + --> tests/ui/manual_saturating_arithmetic.rs:32:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:24:13 + --> tests/ui/manual_saturating_arithmetic.rs:34:13 | LL | let _ = 1i8.checked_add(1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:25:13 + --> tests/ui/manual_saturating_arithmetic.rs:36:13 | LL | let _ = 1i128 | _____________^ +LL | | LL | | .checked_add(1) LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); | |_______________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:28:13 + --> tests/ui/manual_saturating_arithmetic.rs:40:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:29:13 + --> tests/ui/manual_saturating_arithmetic.rs:42:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:30:13 + --> tests/ui/manual_saturating_arithmetic.rs:44:13 | LL | let _ = 1i8.checked_add(-1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:31:13 + --> tests/ui/manual_saturating_arithmetic.rs:46:13 | LL | let _ = 1i128 | _____________^ +LL | | LL | | .checked_add(-1) LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:38:13 + --> tests/ui/manual_saturating_arithmetic.rs:54:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:39:13 + --> tests/ui/manual_saturating_arithmetic.rs:56:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:40:13 + --> tests/ui/manual_saturating_arithmetic.rs:58:13 | LL | let _ = 1i8.checked_sub(1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:41:13 + --> tests/ui/manual_saturating_arithmetic.rs:60:13 | LL | let _ = 1i128 | _____________^ +LL | | LL | | .checked_sub(1) LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:44:13 + --> tests/ui/manual_saturating_arithmetic.rs:64:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:45:13 + --> tests/ui/manual_saturating_arithmetic.rs:66:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:46:13 + --> tests/ui/manual_saturating_arithmetic.rs:68:13 | LL | let _ = 1i8.checked_sub(-1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(-1)` error: manual saturating arithmetic - --> tests/ui/manual_saturating_arithmetic.rs:47:13 + --> tests/ui/manual_saturating_arithmetic.rs:70:13 | LL | let _ = 1i128 | _____________^ +LL | | LL | | .checked_sub(-1) LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); | |_______________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(-1)` diff --git a/tests/ui/manual_slice_fill.rs b/tests/ui/manual_slice_fill.rs index 75a391f4243c..cd62a476d174 100644 --- a/tests/ui/manual_slice_fill.rs +++ b/tests/ui/manual_slice_fill.rs @@ -23,21 +23,25 @@ fn should_lint() { let mut some_slice = [1, 2, 3, 4, 5]; for i in 0..some_slice.len() { + //~^ manual_slice_fill some_slice[i] = 0; } let x = 5; for i in 0..some_slice.len() { + //~^ manual_slice_fill some_slice[i] = x; } for i in &mut some_slice { + //~^ manual_slice_fill *i = 0; } // This should trigger `manual_slice_fill`, but the applicability is `MaybeIncorrect` since comments // within the loop might be purely informational. for i in 0..some_slice.len() { + //~^ manual_slice_fill some_slice[i] = 0; // foo } diff --git a/tests/ui/manual_slice_fill.stderr b/tests/ui/manual_slice_fill.stderr index 3aa980f69191..38e43d5b4e06 100644 --- a/tests/ui/manual_slice_fill.stderr +++ b/tests/ui/manual_slice_fill.stderr @@ -2,6 +2,7 @@ error: manually filling a slice --> tests/ui/manual_slice_fill.rs:25:5 | LL | / for i in 0..some_slice.len() { +LL | | LL | | some_slice[i] = 0; LL | | } | |_____^ help: try: `some_slice.fill(0);` @@ -10,25 +11,28 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_slice_fill)]` error: manually filling a slice - --> tests/ui/manual_slice_fill.rs:30:5 + --> tests/ui/manual_slice_fill.rs:31:5 | LL | / for i in 0..some_slice.len() { +LL | | LL | | some_slice[i] = x; LL | | } | |_____^ help: try: `some_slice.fill(x);` error: manually filling a slice - --> tests/ui/manual_slice_fill.rs:34:5 + --> tests/ui/manual_slice_fill.rs:36:5 | LL | / for i in &mut some_slice { +LL | | LL | | *i = 0; LL | | } | |_____^ help: try: `some_slice.fill(0);` error: manually filling a slice - --> tests/ui/manual_slice_fill.rs:40:5 + --> tests/ui/manual_slice_fill.rs:43:5 | LL | / for i in 0..some_slice.len() { +LL | | LL | | some_slice[i] = 0; LL | | // foo LL | | } diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 0603b30e3465..91ada0b75d5c 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -15,18 +15,27 @@ fn main() { // True positives: let _ = std::mem::size_of_val(s_i32); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32) * 5; // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(*s_i32_ref); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(**s_i32_ref_ref); // WARNING + //~^ manual_slice_size_calculation let len = s_i32.len(); let size = size_of::(); let _ = std::mem::size_of_val(s_i32); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING + //~^ manual_slice_size_calculation let _ = std::mem::size_of_val(external!(&[1u64][..])); + //~^ manual_slice_size_calculation // True negatives: let _ = size_of::() + s_i32.len(); // Ok, not a multiplication diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index 14093e653c09..0ef3793619c4 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -15,18 +15,27 @@ fn main() { // True positives: let _ = s_i32.len() * size_of::(); // WARNING + //~^ manual_slice_size_calculation let _ = size_of::() * s_i32.len(); // WARNING + //~^ manual_slice_size_calculation let _ = size_of::() * s_i32.len() * 5; // WARNING + //~^ manual_slice_size_calculation let _ = size_of::() * s_i32_ref.len(); // WARNING + //~^ manual_slice_size_calculation let _ = size_of::() * s_i32_ref_ref.len(); // WARNING + //~^ manual_slice_size_calculation let len = s_i32.len(); let size = size_of::(); let _ = len * size_of::(); // WARNING + //~^ manual_slice_size_calculation let _ = s_i32.len() * size; // WARNING + //~^ manual_slice_size_calculation let _ = len * size; // WARNING + //~^ manual_slice_size_calculation let _ = external!(&[1u64][..]).len() * size_of::(); + //~^ manual_slice_size_calculation // True negatives: let _ = size_of::() + s_i32.len(); // Ok, not a multiplication diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index 0397f3a4969a..d752e8356aa8 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -8,49 +8,49 @@ LL | let _ = s_i32.len() * size_of::(); // WARNING = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:18:13 + --> tests/ui/manual_slice_size_calculation.rs:19:13 | LL | let _ = size_of::() * s_i32.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:19:13 + --> tests/ui/manual_slice_size_calculation.rs:21:13 | LL | let _ = size_of::() * s_i32.len() * 5; // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:20:13 + --> tests/ui/manual_slice_size_calculation.rs:23:13 | LL | let _ = size_of::() * s_i32_ref.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(*s_i32_ref)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:21:13 + --> tests/ui/manual_slice_size_calculation.rs:25:13 | LL | let _ = size_of::() * s_i32_ref_ref.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(**s_i32_ref_ref)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:25:13 + --> tests/ui/manual_slice_size_calculation.rs:30:13 | LL | let _ = len * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:26:13 + --> tests/ui/manual_slice_size_calculation.rs:32:13 | LL | let _ = s_i32.len() * size; // WARNING | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:27:13 + --> tests/ui/manual_slice_size_calculation.rs:34:13 | LL | let _ = len * size; // WARNING | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:29:13 + --> tests/ui/manual_slice_size_calculation.rs:37: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 aaac6a048e1d..76dfb99b787d 100644 --- a/tests/ui/manual_split_once.fixed +++ b/tests/ui/manual_split_once.fixed @@ -9,23 +9,33 @@ use itertools::Itertools; fn main() { let _ = "key=value".splitn(2, '=').nth(2); let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once let (_, _) = "key=value".split_once('=').unwrap(); + //~^ manual_split_once let s = String::from("key=value"); let _ = s.split_once('=').unwrap().1; + //~^ manual_split_once let s = Box::::from("key=value"); let _ = s.split_once('=').unwrap().1; + //~^ manual_split_once let s = &"key=value"; let _ = s.split_once('=').unwrap().1; + //~^ manual_split_once fn _f(s: &str) -> Option<&str> { let _ = s.split_once('=')?.1; + //~^ manual_split_once let _ = s.split_once('=')?.1; + //~^ manual_split_once let _ = s.rsplit_once('=')?.0; + //~^ manual_split_once let _ = s.rsplit_once('=')?.0; + //~^ manual_split_once None } @@ -34,24 +44,31 @@ fn main() { // `rsplitn` gives the results in the reverse order of `rsplit_once` let _ = "key=value".rsplit_once('=').unwrap().0; + //~^ manual_split_once let (_, _) = "key=value".rsplit_once('=').map(|(x, y)| (y, x)).unwrap(); + //~^ manual_split_once let _ = s.rsplit_once('=').map(|x| x.0); + //~^ manual_split_once } fn indirect() -> Option<()> { let (l, r) = "a.b.c".split_once('.').unwrap(); + //~^ manual_split_once let (l, r) = "a.b.c".split_once('.')?; + //~^ manual_split_once let (l, r) = "a.b.c".rsplit_once('.').unwrap(); + //~^ manual_split_once let (l, r) = "a.b.c".rsplit_once('.')?; + //~^ manual_split_once @@ -137,8 +154,10 @@ fn _msrv_1_51() { #[clippy::msrv = "1.52"] fn _msrv_1_52() { let _ = "key=value".split_once('=').unwrap().1; + //~^ manual_split_once let (a, b) = "a.b.c".split_once('.').unwrap(); + //~^ manual_split_once } diff --git a/tests/ui/manual_split_once.rs b/tests/ui/manual_split_once.rs index 113e1737c97d..73602fae3d82 100644 --- a/tests/ui/manual_split_once.rs +++ b/tests/ui/manual_split_once.rs @@ -9,23 +9,33 @@ use itertools::Itertools; fn main() { let _ = "key=value".splitn(2, '=').nth(2); let _ = "key=value".splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let _ = "key=value".splitn(2, '=').skip(1).next().unwrap(); + //~^ manual_split_once let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap(); + //~^ manual_split_once let s = String::from("key=value"); let _ = s.splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let s = Box::::from("key=value"); let _ = s.splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let s = &"key=value"; let _ = s.splitn(2, '=').skip(1).next().unwrap(); + //~^ manual_split_once fn _f(s: &str) -> Option<&str> { let _ = s.splitn(2, '=').nth(1)?; + //~^ manual_split_once let _ = s.splitn(2, '=').skip(1).next()?; + //~^ manual_split_once let _ = s.rsplitn(2, '=').nth(1)?; + //~^ manual_split_once let _ = s.rsplitn(2, '=').skip(1).next()?; + //~^ manual_split_once None } @@ -34,24 +44,31 @@ fn main() { // `rsplitn` gives the results in the reverse order of `rsplit_once` let _ = "key=value".rsplitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap(); + //~^ manual_split_once let _ = s.rsplitn(2, '=').nth(1); + //~^ manual_split_once } fn indirect() -> Option<()> { let mut iter = "a.b.c".splitn(2, '.'); + //~^ manual_split_once let l = iter.next().unwrap(); let r = iter.next().unwrap(); let mut iter = "a.b.c".splitn(2, '.'); + //~^ manual_split_once let l = iter.next()?; let r = iter.next()?; let mut iter = "a.b.c".rsplitn(2, '.'); + //~^ manual_split_once let r = iter.next().unwrap(); let l = iter.next().unwrap(); let mut iter = "a.b.c".rsplitn(2, '.'); + //~^ manual_split_once let r = iter.next()?; let l = iter.next()?; @@ -137,8 +154,10 @@ fn _msrv_1_51() { #[clippy::msrv = "1.52"] fn _msrv_1_52() { let _ = "key=value".splitn(2, '=').nth(1).unwrap(); + //~^ manual_split_once let mut iter = "a.b.c".splitn(2, '.'); + //~^ manual_split_once let a = iter.next().unwrap(); let b = iter.next().unwrap(); } diff --git a/tests/ui/manual_split_once.stderr b/tests/ui/manual_split_once.stderr index 366d860f25ef..2a44f6e7438c 100644 --- a/tests/ui/manual_split_once.stderr +++ b/tests/ui/manual_split_once.stderr @@ -8,23 +8,17 @@ LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::manual_split_once)]` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:12:13 + --> tests/ui/manual_split_once.rs:13: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` - --> tests/ui/manual_split_once.rs:13:18 + --> tests/ui/manual_split_once.rs:15:18 | LL | let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=')` -error: manual implementation of `split_once` - --> tests/ui/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` --> tests/ui/manual_split_once.rs:19:13 | @@ -32,58 +26,65 @@ LL | let _ = s.splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:22:13 + --> tests/ui/manual_split_once.rs:23:13 + | +LL | let _ = s.splitn(2, '=').nth(1).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` + +error: manual implementation of `split_once` + --> tests/ui/manual_split_once.rs:27:13 | LL | let _ = s.splitn(2, '=').skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:25:17 + --> tests/ui/manual_split_once.rs:31:17 | LL | let _ = s.splitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:26:17 + --> tests/ui/manual_split_once.rs:33:17 | LL | let _ = s.splitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:27:17 + --> tests/ui/manual_split_once.rs:35:17 | LL | let _ = s.rsplitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:28:17 + --> tests/ui/manual_split_once.rs:37:17 | LL | let _ = s.rsplitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:36:13 + --> tests/ui/manual_split_once.rs:46:13 | LL | let _ = "key=value".rsplitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').unwrap().0` error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:37:18 + --> tests/ui/manual_split_once.rs:48: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` - --> tests/ui/manual_split_once.rs:38:13 + --> tests/ui/manual_split_once.rs:50:13 | LL | let _ = s.rsplitn(2, '=').nth(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=').map(|x| x.0)` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:42:5 + --> tests/ui/manual_split_once.rs:55:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | let l = iter.next().unwrap(); | ----------------------------- first usage here LL | let r = iter.next().unwrap(); @@ -92,15 +93,17 @@ LL | let r = iter.next().unwrap(); help: replace with `split_once` | LL ~ let (l, r) = "a.b.c".split_once('.').unwrap(); +LL | LL ~ LL ~ | error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:46:5 + --> tests/ui/manual_split_once.rs:60:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | let l = iter.next()?; | --------------------- first usage here LL | let r = iter.next()?; @@ -109,15 +112,17 @@ LL | let r = iter.next()?; help: replace with `split_once` | LL ~ let (l, r) = "a.b.c".split_once('.')?; +LL | LL ~ LL ~ | error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:50:5 + --> tests/ui/manual_split_once.rs:65:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | let r = iter.next().unwrap(); | ----------------------------- first usage here LL | let l = iter.next().unwrap(); @@ -126,15 +131,17 @@ LL | let l = iter.next().unwrap(); help: replace with `rsplit_once` | LL ~ let (l, r) = "a.b.c".rsplit_once('.').unwrap(); +LL | LL ~ LL ~ | error: manual implementation of `rsplit_once` - --> tests/ui/manual_split_once.rs:54:5 + --> tests/ui/manual_split_once.rs:70:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | let r = iter.next()?; | --------------------- first usage here LL | let l = iter.next()?; @@ -143,21 +150,23 @@ LL | let l = iter.next()?; help: replace with `rsplit_once` | LL ~ let (l, r) = "a.b.c".rsplit_once('.')?; +LL | LL ~ LL ~ | error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:139:13 + --> tests/ui/manual_split_once.rs:156:13 | LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` error: manual implementation of `split_once` - --> tests/ui/manual_split_once.rs:141:5 + --> tests/ui/manual_split_once.rs:159:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | let a = iter.next().unwrap(); | ----------------------------- first usage here LL | let b = iter.next().unwrap(); @@ -166,6 +175,7 @@ LL | let b = iter.next().unwrap(); help: replace with `split_once` | LL ~ let (a, b) = "a.b.c".split_once('.').unwrap(); +LL | LL ~ LL ~ | diff --git a/tests/ui/manual_str_repeat.fixed b/tests/ui/manual_str_repeat.fixed index da6f36f53b0d..bbe4260f6bc8 100644 --- a/tests/ui/manual_str_repeat.fixed +++ b/tests/ui/manual_str_repeat.fixed @@ -6,13 +6,18 @@ use std::iter::repeat; fn main() { let _: String = "test".repeat(10); + //~^ manual_str_repeat let _: String = "x".repeat(10); + //~^ manual_str_repeat let _: String = "'".repeat(10); + //~^ manual_str_repeat let _: String = "\"".repeat(10); + //~^ manual_str_repeat let x = "test"; let count = 10; let _ = x.repeat(count + 2); + //~^ manual_str_repeat macro_rules! m { ($e:expr) => {{ $e }}; @@ -22,6 +27,7 @@ fn main() { let x = &x; let _: String = (*x).repeat(count); + //~^ manual_str_repeat macro_rules! repeat_m { ($e:expr) => {{ repeat($e) }}; @@ -31,6 +37,7 @@ fn main() { let x: Box = Box::from("test"); let _: String = x.repeat(count); + //~^ manual_str_repeat #[derive(Clone)] struct S; @@ -43,9 +50,11 @@ fn main() { let _: String = repeat(Box::new(S)).take(count).collect(); let _: String = Cow::Borrowed("test").repeat(count); + //~^ manual_str_repeat let x = "x".to_owned(); let _: String = x.repeat(count); + //~^ manual_str_repeat let x = 'x'; // Don't lint, not char literal @@ -61,4 +70,5 @@ fn _msrv_1_15() { #[clippy::msrv = "1.16"] fn _msrv_1_16() { let _: String = "test".repeat(10); + //~^ manual_str_repeat } diff --git a/tests/ui/manual_str_repeat.rs b/tests/ui/manual_str_repeat.rs index 686ed4fee7d1..38d2eb4fcad8 100644 --- a/tests/ui/manual_str_repeat.rs +++ b/tests/ui/manual_str_repeat.rs @@ -6,13 +6,18 @@ use std::iter::repeat; fn main() { let _: String = std::iter::repeat("test").take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('x').take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('\'').take(10).collect(); + //~^ manual_str_repeat let _: String = std::iter::repeat('"').take(10).collect(); + //~^ manual_str_repeat let x = "test"; let count = 10; let _ = repeat(x).take(count + 2).collect::(); + //~^ manual_str_repeat macro_rules! m { ($e:expr) => {{ $e }}; @@ -22,6 +27,7 @@ fn main() { let x = &x; let _: String = repeat(*x).take(count).collect(); + //~^ manual_str_repeat macro_rules! repeat_m { ($e:expr) => {{ repeat($e) }}; @@ -31,6 +37,7 @@ fn main() { let x: Box = Box::from("test"); let _: String = repeat(x).take(count).collect(); + //~^ manual_str_repeat #[derive(Clone)] struct S; @@ -43,9 +50,11 @@ fn main() { let _: String = repeat(Box::new(S)).take(count).collect(); let _: String = repeat(Cow::Borrowed("test")).take(count).collect(); + //~^ manual_str_repeat let x = "x".to_owned(); let _: String = repeat(x).take(count).collect(); + //~^ manual_str_repeat let x = 'x'; // Don't lint, not char literal @@ -61,4 +70,5 @@ fn _msrv_1_15() { #[clippy::msrv = "1.16"] fn _msrv_1_16() { let _: String = std::iter::repeat("test").take(10).collect(); + //~^ manual_str_repeat } diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index d4f8786fb5f1..7998c3f6d97c 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -8,55 +8,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:9:21 + --> tests/ui/manual_str_repeat.rs:10:21 | LL | let _: String = std::iter::repeat('x').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:10:21 + --> tests/ui/manual_str_repeat.rs:12:21 | LL | let _: String = std::iter::repeat('\'').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:11:21 + --> tests/ui/manual_str_repeat.rs:14:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:15:13 + --> tests/ui/manual_str_repeat.rs:19:13 | LL | let _ = repeat(x).take(count + 2).collect::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:24:21 + --> tests/ui/manual_str_repeat.rs:29:21 | LL | let _: String = repeat(*x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:33:21 + --> tests/ui/manual_str_repeat.rs:39:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:45:21 + --> tests/ui/manual_str_repeat.rs:52: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 - --> tests/ui/manual_str_repeat.rs:48:21 + --> tests/ui/manual_str_repeat.rs:56:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> tests/ui/manual_str_repeat.rs:63:21 + --> tests/ui/manual_str_repeat.rs:72: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 2d4c5a029153..02eeb603891a 100644 --- a/tests/ui/manual_string_new.fixed +++ b/tests/ui/manual_string_new.fixed @@ -12,12 +12,15 @@ macro_rules! create_strings_from_macro { fn main() { // Method calls let _ = String::new(); + //~^ manual_string_new let _ = "no warning".to_string(); let _ = String::new(); + //~^ manual_string_new let _ = "no warning".to_owned(); let _: String = String::new(); + //~^ manual_string_new let _: String = "no warning".into(); let _: SomeOtherStruct = "no warning".into(); @@ -25,26 +28,32 @@ fn main() { // Calls let _ = String::new(); + //~^ manual_string_new let _ = String::new(); + //~^ manual_string_new let _ = String::from("no warning"); let _ = SomeOtherStruct::from("no warning"); let _ = SomeOtherStruct::from(""); // Again: no warning. let _ = String::new(); + //~^ manual_string_new let _ = String::try_from("no warning").unwrap(); let _ = String::try_from("no warning").expect("this should not warn"); let _ = SomeOtherStruct::try_from("no warning").unwrap(); let _ = SomeOtherStruct::try_from("").unwrap(); // Again: no warning. let _: String = String::new(); + //~^ manual_string_new let _: String = From::from("no warning"); let _: SomeOtherStruct = From::from("no warning"); let _: SomeOtherStruct = From::from(""); // Again: no warning. let _: String = String::new(); + //~^ manual_string_new let _: String = TryFrom::try_from("no warning").unwrap(); let _: String = TryFrom::try_from("no warning").expect("this should not warn"); let _: String = String::new(); + //~^ manual_string_new let _: SomeOtherStruct = TryFrom::try_from("no_warning").unwrap(); let _: SomeOtherStruct = TryFrom::try_from("").unwrap(); // Again: no warning. diff --git a/tests/ui/manual_string_new.rs b/tests/ui/manual_string_new.rs index 20f0be6aaf97..fb4f58abad26 100644 --- a/tests/ui/manual_string_new.rs +++ b/tests/ui/manual_string_new.rs @@ -12,12 +12,15 @@ macro_rules! create_strings_from_macro { fn main() { // Method calls let _ = "".to_string(); + //~^ manual_string_new let _ = "no warning".to_string(); let _ = "".to_owned(); + //~^ manual_string_new let _ = "no warning".to_owned(); let _: String = "".into(); + //~^ manual_string_new let _: String = "no warning".into(); let _: SomeOtherStruct = "no warning".into(); @@ -25,26 +28,32 @@ fn main() { // Calls let _ = String::from(""); + //~^ manual_string_new let _ = ::from(""); + //~^ manual_string_new let _ = String::from("no warning"); let _ = SomeOtherStruct::from("no warning"); let _ = SomeOtherStruct::from(""); // Again: no warning. let _ = String::try_from("").unwrap(); + //~^ manual_string_new let _ = String::try_from("no warning").unwrap(); let _ = String::try_from("no warning").expect("this should not warn"); let _ = SomeOtherStruct::try_from("no warning").unwrap(); let _ = SomeOtherStruct::try_from("").unwrap(); // Again: no warning. let _: String = From::from(""); + //~^ manual_string_new let _: String = From::from("no warning"); let _: SomeOtherStruct = From::from("no warning"); let _: SomeOtherStruct = From::from(""); // Again: no warning. let _: String = TryFrom::try_from("").unwrap(); + //~^ manual_string_new let _: String = TryFrom::try_from("no warning").unwrap(); let _: String = TryFrom::try_from("no warning").expect("this should not warn"); let _: String = TryFrom::try_from("").expect("this should warn"); + //~^ manual_string_new let _: SomeOtherStruct = TryFrom::try_from("no_warning").unwrap(); let _: SomeOtherStruct = TryFrom::try_from("").unwrap(); // Again: no warning. diff --git a/tests/ui/manual_string_new.stderr b/tests/ui/manual_string_new.stderr index 6b434f405d31..2d98501f62d4 100644 --- a/tests/ui/manual_string_new.stderr +++ b/tests/ui/manual_string_new.stderr @@ -8,49 +8,49 @@ LL | let _ = "".to_string(); = help: to override `-D warnings` add `#[allow(clippy::manual_string_new)]` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:17:13 + --> tests/ui/manual_string_new.rs:18:13 | LL | let _ = "".to_owned(); | ^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:20:21 + --> tests/ui/manual_string_new.rs:22:21 | LL | let _: String = "".into(); | ^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:27:13 + --> tests/ui/manual_string_new.rs:30:13 | LL | let _ = String::from(""); | ^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:28:13 + --> tests/ui/manual_string_new.rs:32:13 | LL | let _ = ::from(""); | ^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:33:13 + --> tests/ui/manual_string_new.rs:38:13 | LL | let _ = String::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:39:21 + --> tests/ui/manual_string_new.rs:45:21 | LL | let _: String = From::from(""); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:44:21 + --> tests/ui/manual_string_new.rs:51:21 | LL | let _: String = TryFrom::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> tests/ui/manual_string_new.rs:47:21 + --> tests/ui/manual_string_new.rs:55: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 8bd0300e6bcc..d3dbf301d9c0 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -5,7 +5,8 @@ fn main() { if s.starts_with("ab") { str::to_string(&s["ab".len()..]); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + s["ab".len()..].to_string(); str::to_string(&s[2..]); @@ -14,7 +15,8 @@ fn main() { if s.ends_with("bc") { str::to_string(&s[..s.len() - "bc".len()]); - //~^ ERROR: stripping a suffix manually + //~^ manual_strip + s[..s.len() - "bc".len()].to_string(); str::to_string(&s[..s.len() - 2]); @@ -24,7 +26,8 @@ fn main() { // Character patterns if s.starts_with('a') { str::to_string(&s[1..]); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + s[1..].to_string(); } @@ -32,14 +35,16 @@ fn main() { let prefix = "ab"; if s.starts_with(prefix) { str::to_string(&s[prefix.len()..]); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + } // Constant prefix const PREFIX: &str = "ab"; if s.starts_with(PREFIX) { str::to_string(&s[PREFIX.len()..]); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + str::to_string(&s[2..]); } @@ -47,14 +52,16 @@ fn main() { const TARGET: &str = "abc"; if TARGET.starts_with(prefix) { str::to_string(&TARGET[prefix.len()..]); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + } // String target - not mutated. let s1: String = "abc".into(); if s1.starts_with("ab") { s1[2..].to_uppercase(); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + } // String target - mutated. (Don't lint.) @@ -85,6 +92,7 @@ fn msrv_1_45() { let s = "abc"; if s.starts_with('a') { s[1..].to_string(); - //~^ ERROR: stripping a prefix manually + //~^ manual_strip + } } diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index a70c988a0549..78967e521baa 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -16,6 +16,7 @@ help: try using the `strip_prefix` method LL ~ if let Some() = s.strip_prefix("ab") { LL ~ str::to_string(); LL | +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -23,13 +24,13 @@ LL ~ .to_string(); | error: stripping a suffix manually - --> tests/ui/manual_strip.rs:16:24 + --> tests/ui/manual_strip.rs:17:24 | LL | str::to_string(&s[..s.len() - "bc".len()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the suffix was tested here - --> tests/ui/manual_strip.rs:15:5 + --> tests/ui/manual_strip.rs:16:5 | LL | if s.ends_with("bc") { | ^^^^^^^^^^^^^^^^^^^^^ @@ -38,6 +39,7 @@ help: try using the `strip_suffix` method LL ~ if let Some() = s.strip_suffix("bc") { LL ~ str::to_string(); LL | +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -45,13 +47,13 @@ LL ~ .to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:26:24 + --> tests/ui/manual_strip.rs:28:24 | LL | str::to_string(&s[1..]); | ^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:25:5 + --> tests/ui/manual_strip.rs:27:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -60,17 +62,18 @@ help: try using the `strip_prefix` method LL ~ if let Some() = s.strip_prefix('a') { LL ~ str::to_string(); LL | +LL | LL ~ .to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:34:24 + --> tests/ui/manual_strip.rs:37:24 | LL | str::to_string(&s[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:33:5 + --> tests/ui/manual_strip.rs:36:5 | LL | if s.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,13 +84,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:41:24 + --> tests/ui/manual_strip.rs:45:24 | LL | str::to_string(&s[PREFIX.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:40:5 + --> tests/ui/manual_strip.rs:44:5 | LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,17 +99,18 @@ help: try using the `strip_prefix` method LL ~ if let Some() = s.strip_prefix(PREFIX) { LL ~ str::to_string(); LL | +LL | LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:49:24 + --> tests/ui/manual_strip.rs:54:24 | LL | str::to_string(&TARGET[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:48:5 + --> tests/ui/manual_strip.rs:53:5 | LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -117,13 +121,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:56:9 + --> tests/ui/manual_strip.rs:62:9 | LL | s1[2..].to_uppercase(); | ^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:55:5 + --> tests/ui/manual_strip.rs:61:5 | LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -134,13 +138,13 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:87:9 + --> tests/ui/manual_strip.rs:94:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:86:5 + --> tests/ui/manual_strip.rs:93:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_swap_auto_fix.rs b/tests/ui/manual_swap_auto_fix.rs index 702a9e67d3d5..c9880e651cd7 100644 --- a/tests/ui/manual_swap_auto_fix.rs +++ b/tests/ui/manual_swap_auto_fix.rs @@ -4,7 +4,8 @@ fn swap1() { let mut v = [3, 2, 1, 0]; let index = v[0]; - //~^ ERROR: this looks like you are swapping elements of `v` manually + //~^ manual_swap + v[0] = v[index]; v[index] = index; } @@ -12,6 +13,7 @@ fn swap1() { fn swap2() { let mut v = [3, 2, 1, 0]; let tmp = v[0]; + //~^ manual_swap v[0] = v[1]; v[1] = tmp; // check not found in this scope. @@ -23,6 +25,7 @@ fn swap3() { let i1 = 0; let i2 = 1; let temp = v[i1]; + //~^ manual_swap v[i1] = v[i2]; v[i2] = temp; } @@ -32,6 +35,7 @@ fn swap4() { let i1 = 0; let i2 = 1; let temp = v[i1]; + //~^ manual_swap v[i1] = v[i2 + 1]; v[i2 + 1] = temp; } @@ -41,6 +45,7 @@ fn swap5() { let i1 = 0; let i2 = 1; let temp = v[i1]; + //~^ manual_swap v[i1] = v[i2 + 1]; v[i2 + 1] = temp; } @@ -48,7 +53,8 @@ fn swap5() { fn swap6() { let mut v = [0, 1, 2, 3]; let index = v[0]; - //~^ ERROR: this looks like you are swapping elements of `v` manually + //~^ manual_swap + v[0] = v[index + 1]; v[index + 1] = index; } @@ -58,6 +64,7 @@ fn swap7() { let i1 = 0; let i2 = 6; let tmp = v[i1 * 3]; + //~^ manual_swap v[i1 * 3] = v[i2 / 2]; v[i2 / 2] = tmp; } @@ -67,6 +74,7 @@ fn swap8() { let i1 = 1; let i2 = 1; let tmp = v[i1 + i2]; + //~^ manual_swap v[i1 + i2] = v[i2]; v[i2] = tmp; } diff --git a/tests/ui/manual_swap_auto_fix.stderr b/tests/ui/manual_swap_auto_fix.stderr index eecfcd3977be..7ab898fcc726 100644 --- a/tests/ui/manual_swap_auto_fix.stderr +++ b/tests/ui/manual_swap_auto_fix.stderr @@ -3,6 +3,7 @@ error: this looks like you are swapping elements of `v` manually | LL | / let index = v[0]; LL | | +LL | | LL | | v[0] = v[index]; LL | | v[index] = index; | |_____________________^ @@ -16,9 +17,10 @@ LL + v.swap(0, index); | error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:14:5 + --> tests/ui/manual_swap_auto_fix.rs:15:5 | LL | / let tmp = v[0]; +LL | | LL | | v[0] = v[1]; LL | | v[1] = tmp; | |_______________^ @@ -30,34 +32,38 @@ LL + v.swap(0, 1); | error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:25:5 + --> tests/ui/manual_swap_auto_fix.rs:27:5 | LL | / let temp = v[i1]; +LL | | LL | | v[i1] = v[i2]; LL | | v[i2] = temp; | |_________________^ help: try: `v.swap(i1, i2);` error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:34:5 + --> tests/ui/manual_swap_auto_fix.rs:37:5 | LL | / let temp = v[i1]; +LL | | LL | | v[i1] = v[i2 + 1]; LL | | v[i2 + 1] = temp; | |_____________________^ help: try: `v.swap(i1, i2 + 1);` error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:43:5 + --> tests/ui/manual_swap_auto_fix.rs:47:5 | LL | / let temp = v[i1]; +LL | | LL | | v[i1] = v[i2 + 1]; LL | | v[i2 + 1] = temp; | |_____________________^ help: try: `v.swap(i1, i2 + 1);` error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:50:5 + --> tests/ui/manual_swap_auto_fix.rs:55:5 | LL | / let index = v[0]; LL | | +LL | | LL | | v[0] = v[index + 1]; LL | | v[index + 1] = index; | |_________________________^ @@ -69,17 +75,19 @@ LL + v.swap(0, index + 1); | error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:60:5 + --> tests/ui/manual_swap_auto_fix.rs:66:5 | LL | / let tmp = v[i1 * 3]; +LL | | LL | | v[i1 * 3] = v[i2 / 2]; LL | | v[i2 / 2] = tmp; | |____________________^ help: try: `v.swap(i1 * 3, i2 / 2);` error: this looks like you are swapping elements of `v` manually - --> tests/ui/manual_swap_auto_fix.rs:69:5 + --> tests/ui/manual_swap_auto_fix.rs:76:5 | LL | / let tmp = v[i1 + i2]; +LL | | LL | | v[i1 + i2] = v[i2]; LL | | v[i2] = tmp; | |________________^ help: try: `v.swap(i1 + i2, i2);` diff --git a/tests/ui/manual_try_fold.rs b/tests/ui/manual_try_fold.rs index 7299d7cf9862..749fc7c7b683 100644 --- a/tests/ui/manual_try_fold.rs +++ b/tests/ui/manual_try_fold.rs @@ -57,13 +57,16 @@ fn main() { [1, 2, 3] .iter() .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) + //~^ manual_try_fold .unwrap(); [1, 2, 3] .iter() .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); + //~^ manual_try_fold [1, 2, 3] .iter() .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); + //~^ manual_try_fold // Do not lint [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap(); [1, 2, 3].iter().fold(0i32, |sum, i| sum + i); @@ -94,6 +97,7 @@ fn msrv_juust_right() { [1, 2, 3] .iter() .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) + //~^ manual_try_fold .unwrap(); } diff --git a/tests/ui/manual_try_fold.stderr b/tests/ui/manual_try_fold.stderr index bc075e87d71f..f2740187878f 100644 --- a/tests/ui/manual_try_fold.stderr +++ b/tests/ui/manual_try_fold.stderr @@ -8,19 +8,19 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) = help: to override `-D warnings` add `#[allow(clippy::manual_try_fold)]` error: usage of `Iterator::fold` on a type that implements `Try` - --> tests/ui/manual_try_fold.rs:63:10 + --> tests/ui/manual_try_fold.rs:64:10 | LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(..., |sum, i| ...)` error: usage of `Iterator::fold` on a type that implements `Try` - --> tests/ui/manual_try_fold.rs:66:10 + --> tests/ui/manual_try_fold.rs:68:10 | LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` error: usage of `Iterator::fold` on a type that implements `Try` - --> tests/ui/manual_try_fold.rs:96:10 + --> tests/ui/manual_try_fold.rs:99:10 | LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index cdbe51a41212..80a677d726ef 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -9,18 +9,21 @@ fn option_unwrap_or() { // int case match Some(1) { + //~^ manual_unwrap_or Some(i) => i, None => 42, }; // int case reversed match Some(1) { + //~^ manual_unwrap_or None => 42, Some(i) => i, }; // richer none expr match Some(1) { + //~^ manual_unwrap_or Some(i) => i, None => 1 + 42, }; @@ -28,6 +31,7 @@ fn option_unwrap_or() { // multiline case #[rustfmt::skip] match Some(1) { + //~^ manual_unwrap_or Some(i) => i, None => { 42 + 42 @@ -38,6 +42,7 @@ fn option_unwrap_or() { // string case match Some("Bob") { + //~^ manual_unwrap_or Some(i) => i, None => "Alice", }; @@ -85,6 +90,7 @@ fn option_unwrap_or() { }; if let Some(x) = Some(1) { + //~^ manual_unwrap_or x } else { 42 @@ -118,6 +124,7 @@ fn option_unwrap_or() { fn result_unwrap_or() { // int case match Ok::(1) { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; @@ -125,12 +132,14 @@ fn result_unwrap_or() { // int case, scrutinee is a binding let a = Ok::(1); match a { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; // int case, suggestion must surround Result expr with parentheses match Ok(1) as Result { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; @@ -144,18 +153,21 @@ fn result_unwrap_or() { } let s = S {}; match s.method() { + //~^ manual_unwrap_or Some(i) => i, None => 42, }; // int case reversed match Ok::(1) { + //~^ manual_unwrap_or Err(_) => 42, Ok(i) => i, }; // richer none expr match Ok::(1) { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 1 + 42, }; @@ -163,6 +175,7 @@ fn result_unwrap_or() { // multiline case #[rustfmt::skip] match Ok::(1) { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => { 42 + 42 @@ -173,6 +186,7 @@ fn result_unwrap_or() { // string case match Ok::<&str, &str>("Bob") { + //~^ manual_unwrap_or Ok(i) => i, Err(_) => "Alice", }; @@ -209,6 +223,7 @@ fn result_unwrap_or() { }; if let Ok(x) = Ok::(1) { + //~^ manual_unwrap_or x } else { 42 @@ -263,6 +278,7 @@ mod issue6965 { fn test() { let _ = match some_macro!() { + //~^ manual_unwrap_or Some(val) => val, None => 0, }; diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index a5a64ecb9a3e..a5deb55786e9 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -2,6 +2,7 @@ error: this pattern reimplements `Option::unwrap_or` --> tests/ui/manual_unwrap_or.rs:11:5 | LL | / match Some(1) { +LL | | LL | | Some(i) => i, LL | | None => 42, LL | | }; @@ -11,30 +12,32 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:17:5 + --> tests/ui/manual_unwrap_or.rs:18:5 | LL | / match Some(1) { +LL | | LL | | None => 42, LL | | Some(i) => i, LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:23:5 + --> tests/ui/manual_unwrap_or.rs:25:5 | LL | / match Some(1) { +LL | | LL | | Some(i) => i, LL | | None => 1 + 42, LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:30:5 + --> tests/ui/manual_unwrap_or.rs:33:5 | LL | / match Some(1) { +LL | | LL | | Some(i) => i, LL | | None => { -LL | | 42 + 42 ... | LL | | }; | |_____^ @@ -49,18 +52,20 @@ LL ~ }); | error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:40:5 + --> tests/ui/manual_unwrap_or.rs:44:5 | LL | / match Some("Bob") { +LL | | LL | | Some(i) => i, LL | | None => "Alice", LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:87:5 + --> tests/ui/manual_unwrap_or.rs:92:5 | LL | / if let Some(x) = Some(1) { +LL | | LL | | x LL | | } else { LL | | 42 @@ -68,66 +73,72 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:120:5 + --> tests/ui/manual_unwrap_or.rs:126:5 | LL | / match Ok::(1) { +LL | | LL | | Ok(i) => i, LL | | Err(_) => 42, LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:127:5 + --> tests/ui/manual_unwrap_or.rs:134:5 | LL | / match a { +LL | | LL | | Ok(i) => i, LL | | Err(_) => 42, LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:133:5 + --> tests/ui/manual_unwrap_or.rs:141:5 | LL | / match Ok(1) as Result { +LL | | LL | | Ok(i) => i, LL | | Err(_) => 42, LL | | }; | |_____^ help: replace with: `(Ok(1) as Result).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:146:5 + --> tests/ui/manual_unwrap_or.rs:155:5 | LL | / match s.method() { +LL | | LL | | Some(i) => i, LL | | None => 42, LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:152:5 + --> tests/ui/manual_unwrap_or.rs:162:5 | LL | / match Ok::(1) { +LL | | LL | | Err(_) => 42, LL | | Ok(i) => i, LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:158:5 + --> tests/ui/manual_unwrap_or.rs:169:5 | LL | / match Ok::(1) { +LL | | LL | | Ok(i) => i, LL | | Err(_) => 1 + 42, LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(1 + 42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:165:5 + --> tests/ui/manual_unwrap_or.rs:177:5 | LL | / match Ok::(1) { +LL | | LL | | Ok(i) => i, LL | | Err(_) => { -LL | | 42 + 42 ... | LL | | }; | |_____^ @@ -142,18 +153,20 @@ LL ~ }); | error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:175:5 + --> tests/ui/manual_unwrap_or.rs:188:5 | LL | / match Ok::<&str, &str>("Bob") { +LL | | LL | | Ok(i) => i, LL | | Err(_) => "Alice", LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:211:5 + --> tests/ui/manual_unwrap_or.rs:225:5 | LL | / if let Ok(x) = Ok::(1) { +LL | | LL | | x LL | | } else { LL | | 42 @@ -161,10 +174,11 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:265:17 + --> tests/ui/manual_unwrap_or.rs:280:17 | LL | let _ = match some_macro!() { | _________________^ +LL | | LL | | Some(val) => val, LL | | None => 0, LL | | }; diff --git a/tests/ui/manual_unwrap_or_default.rs b/tests/ui/manual_unwrap_or_default.rs index 649f65c89fb0..1ef07cf84bde 100644 --- a/tests/ui/manual_unwrap_or_default.rs +++ b/tests/ui/manual_unwrap_or_default.rs @@ -4,35 +4,40 @@ fn main() { let x: Option> = None; match x { - //~^ ERROR: match can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + Some(v) => v, None => Vec::default(), }; let x: Option> = None; match x { - //~^ ERROR: match can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + Some(v) => v, _ => Vec::default(), }; let x: Option = None; match x { - //~^ ERROR: match can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + Some(v) => v, None => String::new(), }; let x: Option> = None; match x { - //~^ ERROR: match can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + None => Vec::default(), Some(v) => v, }; let x: Option> = None; if let Some(v) = x { - //~^ ERROR: if let can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + v } else { Vec::default() @@ -50,14 +55,16 @@ fn main() { let x: Result = Ok(String::new()); match x { - //~^ ERROR: match can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + Ok(v) => v, Err(_) => String::new(), }; let x: Result = Ok(String::new()); if let Ok(v) = x { - //~^ ERROR: if let can be simplified with `.unwrap_or_default()` + //~^ manual_unwrap_or_default + v } else { String::new() @@ -69,6 +76,7 @@ unsafe fn no_deref_ptr(a: Option, b: *const Option) -> i32 { match a { // `*b` being correct depends on `a == Some(_)` Some(_) => match *b { + //~^ manual_unwrap_or_default Some(v) => v, _ => 0, }, diff --git a/tests/ui/manual_unwrap_or_default.stderr b/tests/ui/manual_unwrap_or_default.stderr index 9e3b1be5cb9b..ff388ba85d51 100644 --- a/tests/ui/manual_unwrap_or_default.stderr +++ b/tests/ui/manual_unwrap_or_default.stderr @@ -3,6 +3,7 @@ error: match can be simplified with `.unwrap_or_default()` | LL | / match x { LL | | +LL | | LL | | Some(v) => v, LL | | None => Vec::default(), LL | | }; @@ -12,40 +13,44 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:13:5 + --> tests/ui/manual_unwrap_or_default.rs:14:5 | LL | / match x { LL | | +LL | | LL | | Some(v) => v, LL | | _ => Vec::default(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:20:5 + --> tests/ui/manual_unwrap_or_default.rs:22:5 | LL | / match x { LL | | +LL | | LL | | Some(v) => v, LL | | None => String::new(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:27:5 + --> tests/ui/manual_unwrap_or_default.rs:30:5 | LL | / match x { LL | | +LL | | LL | | None => Vec::default(), LL | | Some(v) => v, LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:34:5 + --> tests/ui/manual_unwrap_or_default.rs:38:5 | LL | / if let Some(v) = x { LL | | +LL | | LL | | v LL | | } else { LL | | Vec::default() @@ -53,20 +58,22 @@ LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:52:5 + --> tests/ui/manual_unwrap_or_default.rs:57:5 | LL | / match x { LL | | +LL | | LL | | Ok(v) => v, LL | | Err(_) => String::new(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:59:5 + --> tests/ui/manual_unwrap_or_default.rs:65:5 | LL | / if let Ok(v) = x { LL | | +LL | | LL | | v LL | | } else { LL | | String::new() @@ -74,10 +81,11 @@ LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:71:20 + --> tests/ui/manual_unwrap_or_default.rs:78:20 | LL | Some(_) => match *b { | ____________________^ +LL | | LL | | Some(v) => v, LL | | _ => 0, LL | | }, diff --git a/tests/ui/manual_unwrap_or_default_unfixable.rs b/tests/ui/manual_unwrap_or_default_unfixable.rs index acc54b52816c..fb61d639f9c0 100644 --- a/tests/ui/manual_unwrap_or_default_unfixable.rs +++ b/tests/ui/manual_unwrap_or_default_unfixable.rs @@ -3,13 +3,17 @@ fn issue_12670() { // no auto: type not found #[allow(clippy::match_result_ok)] let _ = if let Some(x) = "1".parse().ok() { + //~^ manual_unwrap_or_default x } else { i32::default() }; let _ = if let Some(x) = None { x } else { i32::default() }; + //~^ manual_unwrap_or_default // auto fix with unwrap_or_default let a: Option = None; let _ = if let Some(x) = a { x } else { i32::default() }; + //~^ manual_unwrap_or_default let _ = if let Some(x) = Some(99) { x } else { i32::default() }; + //~^ manual_unwrap_or_default } diff --git a/tests/ui/manual_unwrap_or_default_unfixable.stderr b/tests/ui/manual_unwrap_or_default_unfixable.stderr index 3849d33cf254..94a7c2f5d2c3 100644 --- a/tests/ui/manual_unwrap_or_default_unfixable.stderr +++ b/tests/ui/manual_unwrap_or_default_unfixable.stderr @@ -3,6 +3,7 @@ error: if let can be simplified with `.unwrap_or_default()` | LL | let _ = if let Some(x) = "1".parse().ok() { | _____________^ +LL | | LL | | x LL | | } else { LL | | i32::default() @@ -13,19 +14,19 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default_unfixable.rs:10:13 + --> tests/ui/manual_unwrap_or_default_unfixable.rs:11:13 | LL | let _ = if let Some(x) = None { x } else { i32::default() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `None::.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default_unfixable.rs:13:13 + --> tests/ui/manual_unwrap_or_default_unfixable.rs:15:13 | LL | let _ = if let Some(x) = a { x } else { i32::default() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default_unfixable.rs:14:13 + --> tests/ui/manual_unwrap_or_default_unfixable.rs:17:13 | LL | let _ = if let Some(x) = Some(99) { x } else { i32::default() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(99).unwrap_or_default()` diff --git a/tests/ui/manual_while_let_some.fixed b/tests/ui/manual_while_let_some.fixed index c70d258dfe6e..c0f6522d5fb8 100644 --- a/tests/ui/manual_while_let_some.fixed +++ b/tests/ui/manual_while_let_some.fixed @@ -19,6 +19,7 @@ fn main() { let mut numbers = vec![1, 2, 3, 4, 5]; while let Some(number) = numbers.pop() { + //~^ manual_while_let_some } let mut val = VecInStruct { @@ -27,14 +28,17 @@ fn main() { }; while let Some(number) = val.numbers.pop() { + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32(element); + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32(element); + //~^ manual_while_let_some } // This should not warn. It "conditionally" pops elements. @@ -78,14 +82,17 @@ fn main() { let mut numbers = vec![(0, 0), (1, 1), (2, 2)]; while let Some((a, b)) = numbers.pop() { + //~^ manual_while_let_some } while let Some(element) = numbers.pop() { accept_i32_tuple(element); + //~^ manual_while_let_some } let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }]; while let Some(Foo { a, b }) = results.pop() { + //~^ manual_while_let_some } } diff --git a/tests/ui/manual_while_let_some.rs b/tests/ui/manual_while_let_some.rs index 415bb5798667..f69eb66af1d7 100644 --- a/tests/ui/manual_while_let_some.rs +++ b/tests/ui/manual_while_let_some.rs @@ -19,6 +19,7 @@ fn main() { let mut numbers = vec![1, 2, 3, 4, 5]; while !numbers.is_empty() { let number = numbers.pop().unwrap(); + //~^ manual_while_let_some } let mut val = VecInStruct { @@ -27,14 +28,17 @@ fn main() { }; while !val.numbers.is_empty() { let number = val.numbers.pop().unwrap(); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32(numbers.pop().unwrap()); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32(numbers.pop().expect("")); + //~^ manual_while_let_some } // This should not warn. It "conditionally" pops elements. @@ -78,14 +82,17 @@ fn main() { let mut numbers = vec![(0, 0), (1, 1), (2, 2)]; while !numbers.is_empty() { let (a, b) = numbers.pop().unwrap(); + //~^ manual_while_let_some } while !numbers.is_empty() { accept_i32_tuple(numbers.pop().unwrap()); + //~^ manual_while_let_some } let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }]; while !results.is_empty() { let Foo { a, b } = results.pop().unwrap(); + //~^ manual_while_let_some } } diff --git a/tests/ui/manual_while_let_some.stderr b/tests/ui/manual_while_let_some.stderr index 8d444b80aaff..5f2fecb7a0b9 100644 --- a/tests/ui/manual_while_let_some.stderr +++ b/tests/ui/manual_while_let_some.stderr @@ -13,7 +13,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:29:9 + --> tests/ui/manual_while_let_some.rs:30:9 | LL | let number = val.numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:33:20 + --> tests/ui/manual_while_let_some.rs:35:20 | LL | accept_i32(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:37:20 + --> tests/ui/manual_while_let_some.rs:40:20 | LL | accept_i32(numbers.pop().expect("")); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:80:9 + --> tests/ui/manual_while_let_some.rs:84:9 | LL | let (a, b) = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:84:26 + --> tests/ui/manual_while_let_some.rs:89:26 | LL | accept_i32_tuple(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL ~ accept_i32_tuple(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> tests/ui/manual_while_let_some.rs:89:9 + --> tests/ui/manual_while_let_some.rs:95:9 | LL | let Foo { a, b } = results.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs index 68578340d90e..6e662e246061 100644 --- a/tests/ui/many_single_char_names.rs +++ b/tests/ui/many_single_char_names.rs @@ -3,10 +3,13 @@ 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 + //~^ many_single_char_names + //~| many_single_char_names + //~| many_single_char_names + + + + let (b, c, d): (i32, i64, i16); { { @@ -32,11 +35,13 @@ 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 +//~^ many_single_char_names + 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 + //~^ many_single_char_names + } fn shadowing() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index 131836ef7c88..ad45f9a34fd4 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -40,13 +40,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> tests/ui/many_single_char_names.rs:34:13 + --> tests/ui/many_single_char_names.rs:37: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 - --> tests/ui/many_single_char_names.rs:38:10 + --> tests/ui/many_single_char_names.rs:42: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_all_any_identity.fixed b/tests/ui/map_all_any_identity.fixed index c92462ab9c27..436b94bde0fc 100644 --- a/tests/ui/map_all_any_identity.fixed +++ b/tests/ui/map_all_any_identity.fixed @@ -3,9 +3,11 @@ fn main() { let _ = ["foo"].into_iter().any(|s| s == "foo"); //~^ map_all_any_identity + let _ = ["foo"].into_iter().all(|s| s == "foo"); //~^ map_all_any_identity + // // Do not lint // diff --git a/tests/ui/map_all_any_identity.rs b/tests/ui/map_all_any_identity.rs index 0e4a564ca046..68fe7b77f5c6 100644 --- a/tests/ui/map_all_any_identity.rs +++ b/tests/ui/map_all_any_identity.rs @@ -3,9 +3,11 @@ fn main() { let _ = ["foo"].into_iter().map(|s| s == "foo").any(|a| a); //~^ map_all_any_identity + let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::identity); //~^ map_all_any_identity + // // Do not lint // diff --git a/tests/ui/map_all_any_identity.stderr b/tests/ui/map_all_any_identity.stderr index 98fdcc2a9393..869d81a73d65 100644 --- a/tests/ui/map_all_any_identity.stderr +++ b/tests/ui/map_all_any_identity.stderr @@ -12,7 +12,7 @@ LL | let _ = ["foo"].into_iter().any(|s| s == "foo"); | ~~~~~~~~~~~~~~~~~~~ error: usage of `.map(...).all(identity)` - --> tests/ui/map_all_any_identity.rs:6:33 + --> tests/ui/map_all_any_identity.rs:7:33 | LL | let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index f9f8dc1a5123..5e2c31bb31df 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -12,11 +12,16 @@ fn main() { let _: Vec = vec![5_i8; 6].iter().copied().collect(); + //~^ map_clone let _: Vec = vec![String::new()].iter().cloned().collect(); + //~^ map_clone let _: Vec = vec![42, 43].iter().copied().collect(); + //~^ map_clone let _: Option = Some(Box::new(16)).map(|b| *b); let _: Option = Some(&16).copied(); + //~^ map_clone let _: Option = Some(&1).copied(); + //~^ map_clone // Don't lint these let v = vec![5_i8; 6]; @@ -28,6 +33,7 @@ fn main() { // Issue #498 let _ = std::env::args(); + //~^ map_clone // Issue #4824 item types that aren't references { @@ -67,22 +73,27 @@ fn main() { let x = Some(String::new()); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.cloned(); - //~^ ERROR: you are explicitly cloning with `.map()` + //~^ map_clone + let y = x.cloned(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let y = x.cloned(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let x: Option = Some(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.copied(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + let y = x.copied(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Option = Some(0); @@ -93,20 +104,24 @@ fn main() { let x: Result = Ok(String::new()); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.cloned(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let y = x.cloned(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let x: Result = Ok(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.copied(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + let y = x.copied(); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Result = Ok(0); diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index a5c19ce06319..f15889d64c52 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -12,11 +12,16 @@ fn main() { let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); + //~^ map_clone let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); + //~^ map_clone let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); + //~^ map_clone let _: Option = Some(Box::new(16)).map(|b| *b); let _: Option = Some(&16).map(|b| *b); + //~^ map_clone let _: Option = Some(&1).map(|x| x.clone()); + //~^ map_clone // Don't lint these let v = vec![5_i8; 6]; @@ -28,6 +33,7 @@ fn main() { // Issue #498 let _ = std::env::args().map(|v| v.clone()); + //~^ map_clone // Issue #4824 item types that aren't references { @@ -67,22 +73,27 @@ fn main() { let x = Some(String::new()); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| String::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` + //~^ map_clone + let y = x.map(Clone::clone); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let y = x.map(String::clone); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let x: Option = Some(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| u32::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + let y = x.map(|x| Clone::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Option = Some(0); @@ -93,20 +104,24 @@ fn main() { let x: Result = Ok(String::new()); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| String::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let y = x.map(|x| Clone::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `cloned` method + //~^ map_clone + + let x: Result = Ok(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| u32::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + let y = x.map(|x| Clone::clone(x)); - //~^ ERROR: you are explicitly cloning with `.map()` - //~| HELP: consider calling the dedicated `copied` method + //~^ map_clone + + // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Result = Ok(0); diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index d9e025de4abe..5c88ec579328 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -8,85 +8,85 @@ LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: you are using an explicit closure for cloning elements - --> tests/ui/map_clone.rs:15:26 + --> tests/ui/map_clone.rs:16: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 - --> tests/ui/map_clone.rs:16:23 + --> tests/ui/map_clone.rs:18: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 - --> tests/ui/map_clone.rs:18:26 + --> tests/ui/map_clone.rs:21: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 - --> tests/ui/map_clone.rs:19:25 + --> tests/ui/map_clone.rs:23: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 - --> tests/ui/map_clone.rs:30:29 + --> tests/ui/map_clone.rs:35:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:69:13 + --> tests/ui/map_clone.rs:75:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:71:13 + --> tests/ui/map_clone.rs:78:13 | LL | let y = x.map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:74:13 + --> tests/ui/map_clone.rs:82:13 | LL | let y = x.map(String::clone); | ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:80:13 + --> tests/ui/map_clone.rs:89:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:83:13 + --> tests/ui/map_clone.rs:93:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:95:13 + --> tests/ui/map_clone.rs:106:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:98:13 + --> tests/ui/map_clone.rs:110:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:104:13 + --> tests/ui/map_clone.rs:117:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:107:13 + --> tests/ui/map_clone.rs:121:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` diff --git a/tests/ui/map_collect_result_unit.fixed b/tests/ui/map_collect_result_unit.fixed index 374af105f889..26957e59f14a 100644 --- a/tests/ui/map_collect_result_unit.fixed +++ b/tests/ui/map_collect_result_unit.fixed @@ -3,7 +3,9 @@ fn main() { { let _ = (0..3).try_for_each(|t| Err(t + 1)); + //~^ map_collect_result_unit let _: Result<(), _> = (0..3).try_for_each(|t| Err(t + 1)); + //~^ map_collect_result_unit let _ = (0..3).try_for_each(|t| Err(t + 1)); } diff --git a/tests/ui/map_collect_result_unit.rs b/tests/ui/map_collect_result_unit.rs index 5c6fb23e2372..cdd73bfe6544 100644 --- a/tests/ui/map_collect_result_unit.rs +++ b/tests/ui/map_collect_result_unit.rs @@ -3,7 +3,9 @@ fn main() { { let _ = (0..3).map(|t| Err(t + 1)).collect::>(); + //~^ map_collect_result_unit let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); + //~^ map_collect_result_unit let _ = (0..3).try_for_each(|t| Err(t + 1)); } diff --git a/tests/ui/map_collect_result_unit.stderr b/tests/ui/map_collect_result_unit.stderr index 8d147340e16a..93293be855bb 100644 --- a/tests/ui/map_collect_result_unit.stderr +++ b/tests/ui/map_collect_result_unit.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); = help: to override `-D warnings` add `#[allow(clippy::map_collect_result_unit)]` error: `.map().collect()` can be replaced with `.try_for_each()` - --> tests/ui/map_collect_result_unit.rs:6:32 + --> tests/ui/map_collect_result_unit.rs:7: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_err.rs b/tests/ui/map_err.rs index 07c51784407a..43f6ea0b3ae0 100644 --- a/tests/ui/map_err.rs +++ b/tests/ui/map_err.rs @@ -20,7 +20,8 @@ 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 + //~^ map_err_ignore + // 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 eafc8b6e81ca..e16a11f83ed5 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -6,8 +6,9 @@ fn long_span() { let _: Option = Some(1) .map(|x| { - //~^ ERROR: called `map(..).flatten()` on `Option` - //~| NOTE: `-D clippy::map-flatten` implied by `-D warnings` + //~^ map_flatten + + if x <= 5 { Some(x) } else { @@ -18,7 +19,8 @@ fn long_span() { let _: Result = Ok(1) .map(|x| { - //~^ ERROR: called `map(..).flatten()` on `Result` + //~^ map_flatten + if x == 1 { Ok(x) } else { @@ -31,7 +33,8 @@ fn long_span() { fn do_something() { } let _: Result = result .map(|res| { - //~^ ERROR: called `map(..).flatten()` on `Result` + //~^ map_flatten + if res > 0 { do_something(); Ok(res) @@ -44,7 +47,8 @@ fn long_span() { let _: Vec<_> = vec![5_i8; 6] .into_iter() .map(|some_value| { - //~^ ERROR: called `map(..).flatten()` on `Iterator` + //~^ map_flatten + if some_value > 3 { Some(some_value) } else { @@ -62,7 +66,8 @@ fn no_suggestion_if_comments_present() { .iter() // a lovely comment explaining the code in very detail .map(|x| x.iter()) - //~^ ERROR: called `map(..).flatten()` on `Iterator` + //~^ map_flatten + // the answer to life, the universe and everything could be here .flatten(); } diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index 34bd174d7dde..704267fea3cf 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -3,9 +3,6 @@ error: called `map(..).flatten()` on `Option` | LL | .map(|x| { | __________^ -LL | | -LL | | -LL | | if x <= 5 { ... | LL | | }) LL | | .flatten(); @@ -17,7 +14,8 @@ help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { LL + -LL + +LL + +LL + LL + if x <= 5 { LL + Some(x) LL + } else { @@ -27,13 +25,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> tests/ui/map_flatten.rs:20:10 + --> tests/ui/map_flatten.rs:21:10 | LL | .map(|x| { | __________^ LL | | +LL | | LL | | if x == 1 { -LL | | Ok(x) ... | LL | | }) LL | | .flatten(); @@ -43,6 +41,7 @@ help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { LL + +LL + LL + if x == 1 { LL + Ok(x) LL + } else { @@ -52,13 +51,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> tests/ui/map_flatten.rs:33:10 + --> tests/ui/map_flatten.rs:35:10 | LL | .map(|res| { | __________^ LL | | +LL | | LL | | if res > 0 { -LL | | do_something(); ... | LL | | }) LL | | .flatten(); @@ -68,6 +67,7 @@ help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|res| { LL + +LL + LL + if res > 0 { LL + do_something(); LL + Ok(res) @@ -78,13 +78,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Iterator` - --> tests/ui/map_flatten.rs:46:10 + --> tests/ui/map_flatten.rs:49:10 | LL | .map(|some_value| { | __________^ LL | | +LL | | LL | | if some_value > 3 { -LL | | Some(some_value) ... | LL | | }) LL | | .flatten() @@ -94,6 +94,7 @@ help: try replacing `map` with `filter_map` and remove the `.flatten()` | LL ~ .filter_map(|some_value| { LL + +LL + LL + if some_value > 3 { LL + Some(some_value) LL + } else { @@ -103,7 +104,7 @@ LL + }) | error: called `map(..).flatten()` on `Iterator` - --> tests/ui/map_flatten.rs:64:10 + --> tests/ui/map_flatten.rs:68:10 | LL | .map(|x| x.iter()) | __________^ diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index 1932f412d2ca..a5dc17cc06ca 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -14,18 +14,25 @@ fn main() { let option_id_ref: fn(i8) -> Option = option_id; let option_id_closure = |x| Some(x); let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect(); + //~^ map_flatten // mapping to Iterator on Iterator let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect(); + //~^ map_flatten // mapping to Option on Option let _: Option<_> = (Some(Some(1))).and_then(|x| x); + //~^ map_flatten // mapping to Result on Result let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x); + //~^ map_flatten issue8734(); issue8878(); @@ -35,6 +42,7 @@ fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() .flat_map(|n| match n { + //~^ map_flatten 1 => [n .saturating_add(1) .saturating_add(1) @@ -54,6 +62,7 @@ fn issue8878() { std::collections::HashMap::::new() .get(&0) .and_then(|_| { + //~^ map_flatten // we need some newlines // so that the span is big enough // for a split output of the diagnostic diff --git a/tests/ui/map_flatten_fixable.rs b/tests/ui/map_flatten_fixable.rs index 093fd9b6cae2..57b8e7943f41 100644 --- a/tests/ui/map_flatten_fixable.rs +++ b/tests/ui/map_flatten_fixable.rs @@ -14,18 +14,25 @@ fn main() { let option_id_ref: fn(i8) -> Option = option_id; let option_id_closure = |x| Some(x); let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); + //~^ map_flatten let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); + //~^ map_flatten // mapping to Iterator on Iterator let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); + //~^ map_flatten // mapping to Option on Option let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); + //~^ map_flatten // mapping to Result on Result let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten(); + //~^ map_flatten issue8734(); issue8878(); @@ -35,6 +42,7 @@ fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() .map(|n| match n { + //~^ map_flatten 1 => [n .saturating_add(1) .saturating_add(1) @@ -55,6 +63,7 @@ fn issue8878() { std::collections::HashMap::::new() .get(&0) .map(|_| { + //~^ map_flatten // we need some newlines // so that the span is big enough // for a split output of the diagnostic diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index 095bee52d6d7..05d4d9a6ad85 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -8,49 +8,49 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` error: called `map(..).flatten()` on `Iterator` - --> tests/ui/map_flatten_fixable.rs:17:47 + --> tests/ui/map_flatten_fixable.rs:18: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` - --> tests/ui/map_flatten_fixable.rs:18:47 + --> tests/ui/map_flatten_fixable.rs:20: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` - --> tests/ui/map_flatten_fixable.rs:19:47 + --> tests/ui/map_flatten_fixable.rs:22: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` - --> tests/ui/map_flatten_fixable.rs:22:47 + --> tests/ui/map_flatten_fixable.rs:26: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` - --> tests/ui/map_flatten_fixable.rs:25:40 + --> tests/ui/map_flatten_fixable.rs:30: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` - --> tests/ui/map_flatten_fixable.rs:28:42 + --> tests/ui/map_flatten_fixable.rs:34: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` - --> tests/ui/map_flatten_fixable.rs:37:10 + --> tests/ui/map_flatten_fixable.rs:44:10 | LL | .map(|n| match n { | __________^ +LL | | LL | | 1 => [n LL | | .saturating_add(1) -LL | | .saturating_add(1) ... | LL | | }) LL | | .flatten(); @@ -59,6 +59,7 @@ LL | | .flatten(); help: try replacing `map` with `flat_map` and remove the `.flatten()` | LL ~ .flat_map(|n| match n { +LL + LL + 1 => [n LL + .saturating_add(1) LL + .saturating_add(1) @@ -73,7 +74,7 @@ LL ~ }); | error: called `map(..).flatten()` on `Option` - --> tests/ui/map_flatten_fixable.rs:57:10 + --> tests/ui/map_flatten_fixable.rs:65:10 | LL | .map(|_| { | __________^ @@ -85,6 +86,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|_| { +LL + LL + // we need some newlines LL + // so that the span is big enough LL + // for a split output of the diagnostic diff --git a/tests/ui/map_identity.fixed b/tests/ui/map_identity.fixed index 3257ddc6f72b..83b2dac5fc51 100644 --- a/tests/ui/map_identity.fixed +++ b/tests/ui/map_identity.fixed @@ -5,8 +5,12 @@ fn main() { let x: [u16; 3] = [1, 2, 3]; // should lint let _: Vec<_> = x.iter().map(not_identity).collect(); + //~^ map_identity let _: Vec<_> = x.iter().collect(); + //~^ map_identity + //~| map_identity let _: Option = Some(3); + //~^ map_identity let _: Result = Ok(-3); // should not lint let _: Vec<_> = x.iter().map(|x| 2 * x).collect(); @@ -16,6 +20,7 @@ fn main() { return x + 3; }); let _: Result = Ok(1); + //~^ map_identity let _: Result = Ok(1).map_err(|a: u32| a * 42); // : u32 guides type inference let _ = Ok(1).map_err(|a: u32| a); @@ -26,11 +31,14 @@ fn issue7189() { // should lint let x = [(1, 2), (3, 4)].iter().copied(); let _ = x.clone(); + //~^ map_identity let _ = x.clone(); let _ = x.clone(); + //~^ map_identity let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))].iter().copied(); let _ = y.clone(); + //~^ map_identity // should not lint let _ = x.clone().map(|(x, y)| (x, y, y)); @@ -60,6 +68,7 @@ fn issue11764() { // no match ergonomics for `(i32, i32)` let _ = x.iter().copied(); + //~^ map_identity } fn issue13904() { @@ -71,8 +80,10 @@ fn issue13904() { #[allow(unused_mut)] let mut it = [1, 2, 3].into_iter(); let _ = it.next(); + //~^ map_identity // lint let it = [1, 2, 3].into_iter(); let _ = { it }.next(); + //~^ map_identity } diff --git a/tests/ui/map_identity.rs b/tests/ui/map_identity.rs index be3bb9a4f106..7c891dda79ce 100644 --- a/tests/ui/map_identity.rs +++ b/tests/ui/map_identity.rs @@ -5,9 +5,14 @@ fn main() { let x: [u16; 3] = [1, 2, 3]; // should lint let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); + //~^ map_identity let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); + //~^ map_identity + //~| map_identity let _: Option = Some(3).map(|x| x); + //~^ map_identity let _: Result = Ok(-3).map(|x| { + //~^ map_identity return x; }); // should not lint @@ -18,6 +23,7 @@ fn main() { return x + 3; }); let _: Result = Ok(1).map_err(|a| a); + //~^ map_identity let _: Result = Ok(1).map_err(|a: u32| a * 42); // : u32 guides type inference let _ = Ok(1).map_err(|a: u32| a); @@ -28,13 +34,17 @@ fn issue7189() { // should lint let x = [(1, 2), (3, 4)].iter().copied(); let _ = x.clone().map(|(x, y)| (x, y)); + //~^ map_identity let _ = x.clone().map(|(x, y)| { + //~^ map_identity return (x, y); }); let _ = x.clone().map(|(x, y)| return (x, y)); + //~^ map_identity let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))].iter().copied(); let _ = y.clone().map(|(x, y, (z, (w,)))| (x, y, (z, (w,)))); + //~^ map_identity // should not lint let _ = x.clone().map(|(x, y)| (x, y, y)); @@ -64,6 +74,7 @@ fn issue11764() { // no match ergonomics for `(i32, i32)` let _ = x.iter().copied().map(|(x, y)| (x, y)); + //~^ map_identity } fn issue13904() { @@ -75,8 +86,10 @@ fn issue13904() { #[allow(unused_mut)] let mut it = [1, 2, 3].into_iter(); let _ = it.map(|x| x).next(); + //~^ map_identity // lint let it = [1, 2, 3].into_iter(); let _ = { it }.map(|x| x).next(); + //~^ map_identity } diff --git a/tests/ui/map_identity.stderr b/tests/ui/map_identity.stderr index aa3fc4ae0b5c..9836f3b4cc5f 100644 --- a/tests/ui/map_identity.stderr +++ b/tests/ui/map_identity.stderr @@ -8,79 +8,81 @@ LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_identity)]` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:8:57 + --> tests/ui/map_identity.rs:9: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 - --> tests/ui/map_identity.rs:8:29 + --> tests/ui/map_identity.rs:9: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 - --> tests/ui/map_identity.rs:9:32 + --> tests/ui/map_identity.rs:12:32 | LL | let _: Option = Some(3).map(|x| x); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:10:36 + --> tests/ui/map_identity.rs:14:36 | LL | let _: Result = Ok(-3).map(|x| { | ____________________________________^ +LL | | LL | | return x; LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:20:36 + --> tests/ui/map_identity.rs:25:36 | LL | let _: Result = Ok(1).map_err(|a| a); | ^^^^^^^^^^^^^^^ help: remove the call to `map_err` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:30:22 + --> tests/ui/map_identity.rs:36:22 | LL | let _ = x.clone().map(|(x, y)| (x, y)); | ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:31:22 + --> tests/ui/map_identity.rs:38:22 | LL | let _ = x.clone().map(|(x, y)| { | ______________________^ +LL | | LL | | return (x, y); LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:34:22 + --> tests/ui/map_identity.rs:42:22 | LL | let _ = x.clone().map(|(x, y)| return (x, y)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:37:22 + --> tests/ui/map_identity.rs:46:22 | LL | let _ = y.clone().map(|(x, y, (z, (w,)))| (x, y, (z, (w,)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:66:30 + --> tests/ui/map_identity.rs:76:30 | LL | let _ = x.iter().copied().map(|(x, y)| (x, y)); | ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:77:15 + --> tests/ui/map_identity.rs:88:15 | LL | let _ = it.map(|x| x).next(); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> tests/ui/map_identity.rs:81:19 + --> tests/ui/map_identity.rs:93:19 | LL | let _ = { it }.map(|x| x).next(); | ^^^^^^^^^^^ help: remove the call to `map` diff --git a/tests/ui/map_unit_fn.rs b/tests/ui/map_unit_fn.rs index e7f07b50f3ab..3a810196a44d 100644 --- a/tests/ui/map_unit_fn.rs +++ b/tests/ui/map_unit_fn.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![allow(unused)] struct Mappable; diff --git a/tests/ui/map_unwrap_or.rs b/tests/ui/map_unwrap_or.rs index dfaa8f24f987..fba81cb493cd 100644 --- a/tests/ui/map_unwrap_or.rs +++ b/tests/ui/map_unwrap_or.rs @@ -15,25 +15,31 @@ fn option_methods() { // Check for `option.map(_).unwrap_or(_)` use. // Single line case. let _ = opt.map(|x| x + 1) + //~^ map_unwrap_or // Should lint even though this call is on a separate line. .unwrap_or(0); // Multi-line cases. let _ = opt.map(|x| { + //~^ map_unwrap_or x + 1 } ).unwrap_or(0); let _ = opt.map(|x| x + 1) + //~^ map_unwrap_or .unwrap_or({ 0 }); // Single line `map(f).unwrap_or(None)` case. let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); + //~^ map_unwrap_or // Multi-line `map(f).unwrap_or(None)` cases. let _ = opt.map(|x| { + //~^ map_unwrap_or Some(x + 1) } ).unwrap_or(None); let _ = opt + //~^ map_unwrap_or .map(|x| Some(x + 1)) .unwrap_or(None); // macro case @@ -45,20 +51,24 @@ fn option_methods() { // ...but DO lint if the `unwrap_or` argument is not used in the `map` let id: String = "identifier".to_string(); let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); + //~^ map_unwrap_or // Check for `option.map(_).unwrap_or_else(_)` use. // Multi-line cases. let _ = opt.map(|x| { + //~^ map_unwrap_or x + 1 } ).unwrap_or_else(|| 0); let _ = opt.map(|x| x + 1) + //~^ map_unwrap_or .unwrap_or_else(|| 0 ); // Check for `map(f).unwrap_or(false)` use. let _ = opt.map(|x| x > 5).unwrap_or(false); + //~^ map_unwrap_or } @@ -69,10 +79,12 @@ fn result_methods() { // Check for `result.map(_).unwrap_or_else(_)` use. // multi line cases let _ = res.map(|x| { + //~^ map_unwrap_or x + 1 } ).unwrap_or_else(|_e| 0); let _ = res.map(|x| x + 1) + //~^ map_unwrap_or .unwrap_or_else(|_e| { 0 }); @@ -97,6 +109,7 @@ fn msrv_1_41() { let res: Result = Ok(1); let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); + //~^ map_unwrap_or } #[clippy::msrv = "1.69"] @@ -104,6 +117,7 @@ fn msrv_1_69() { let opt: Option = Some(1); let _ = opt.map(|x| x > 5).unwrap_or(false); + //~^ map_unwrap_or } #[clippy::msrv = "1.70"] @@ -111,6 +125,7 @@ fn msrv_1_70() { let opt: Option = Some(1); let _ = opt.map(|x| x > 5).unwrap_or(false); + //~^ map_unwrap_or } mod issue_10579 { diff --git a/tests/ui/map_unwrap_or.stderr b/tests/ui/map_unwrap_or.stderr index d6ddd09c188c..0b6c9b7fcf19 100644 --- a/tests/ui/map_unwrap_or.stderr +++ b/tests/ui/map_unwrap_or.stderr @@ -3,7 +3,7 @@ error: called `map().unwrap_or()` on an `Option` value | LL | let _ = opt.map(|x| x + 1) | _____________^ -LL | | // Should lint even though this call is on a separate line. +... | LL | | .unwrap_or(0); | |_____________________^ | @@ -16,10 +16,11 @@ LL + let _ = opt.map_or(0, |x| x + 1); | error: called `map().unwrap_or()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:21:13 + --> tests/ui/map_unwrap_or.rs:22:13 | LL | let _ = opt.map(|x| { | _____________^ +LL | | LL | | x + 1 LL | | } LL | | ).unwrap_or(0); @@ -28,16 +29,18 @@ LL | | ).unwrap_or(0); help: use `map_or(, )` instead | LL ~ let _ = opt.map_or(0, |x| { +LL | LL | x + 1 LL | } LL ~ ); | error: called `map().unwrap_or()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:25:13 + --> tests/ui/map_unwrap_or.rs:27:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ +LL | | LL | | .unwrap_or({ LL | | 0 LL | | }); @@ -51,7 +54,7 @@ LL ~ }, |x| x + 1); | error: called `map().unwrap_or(None)` on an `Option` value - --> tests/ui/map_unwrap_or.rs:30:13 + --> tests/ui/map_unwrap_or.rs:33:13 | LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,10 +66,11 @@ LL + let _ = opt.and_then(|x| Some(x + 1)); | error: called `map().unwrap_or(None)` on an `Option` value - --> tests/ui/map_unwrap_or.rs:32:13 + --> tests/ui/map_unwrap_or.rs:36:13 | LL | let _ = opt.map(|x| { | _____________^ +LL | | LL | | Some(x + 1) LL | | } LL | | ).unwrap_or(None); @@ -75,16 +79,18 @@ LL | | ).unwrap_or(None); help: use `and_then()` instead | LL ~ let _ = opt.and_then(|x| { +LL | LL | Some(x + 1) LL | } LL ~ ); | error: called `map().unwrap_or(None)` on an `Option` value - --> tests/ui/map_unwrap_or.rs:36:13 + --> tests/ui/map_unwrap_or.rs:41:13 | LL | let _ = opt | _____________^ +LL | | LL | | .map(|x| Some(x + 1)) LL | | .unwrap_or(None); | |________________________^ @@ -96,7 +102,7 @@ LL + .and_then(|x| Some(x + 1)); | error: called `map().unwrap_or()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:47:13 + --> tests/ui/map_unwrap_or.rs:53:13 | LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,27 +114,29 @@ LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p)); | error: called `map().unwrap_or_else()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:51:13 + --> tests/ui/map_unwrap_or.rs:58:13 | LL | let _ = opt.map(|x| { | _____________^ +LL | | LL | | x + 1 LL | | } LL | | ).unwrap_or_else(|| 0); | |__________________________^ error: called `map().unwrap_or_else()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:55:13 + --> tests/ui/map_unwrap_or.rs:63:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ +LL | | LL | | .unwrap_or_else(|| LL | | 0 LL | | ); | |_________^ error: called `map().unwrap_or(false)` on an `Option` value - --> tests/ui/map_unwrap_or.rs:61:13 + --> tests/ui/map_unwrap_or.rs:70:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -140,33 +148,35 @@ LL + let _ = opt.is_some_and(|x| x > 5); | error: called `map().unwrap_or_else()` on a `Result` value - --> tests/ui/map_unwrap_or.rs:71:13 + --> tests/ui/map_unwrap_or.rs:81:13 | LL | let _ = res.map(|x| { | _____________^ +LL | | LL | | x + 1 LL | | } LL | | ).unwrap_or_else(|_e| 0); | |____________________________^ error: called `map().unwrap_or_else()` on a `Result` value - --> tests/ui/map_unwrap_or.rs:75:13 + --> tests/ui/map_unwrap_or.rs:86:13 | LL | let _ = res.map(|x| x + 1) | _____________^ +LL | | LL | | .unwrap_or_else(|_e| { LL | | 0 LL | | }); | |__________^ error: called `map().unwrap_or_else()` on a `Result` value - --> tests/ui/map_unwrap_or.rs:99:13 + --> tests/ui/map_unwrap_or.rs:111:13 | LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)` error: called `map().unwrap_or()` on an `Option` value - --> tests/ui/map_unwrap_or.rs:106:13 + --> tests/ui/map_unwrap_or.rs:119:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +188,7 @@ LL + let _ = opt.map_or(false, |x| x > 5); | error: called `map().unwrap_or(false)` on an `Option` value - --> tests/ui/map_unwrap_or.rs:113:13 + --> tests/ui/map_unwrap_or.rs:127:13 | LL | let _ = opt.map(|x| x > 5).unwrap_or(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_unwrap_or_fixable.rs b/tests/ui/map_unwrap_or_fixable.rs index d3d0ae0154c1..1078c7a3cf34 100644 --- a/tests/ui/map_unwrap_or_fixable.rs +++ b/tests/ui/map_unwrap_or_fixable.rs @@ -14,6 +14,7 @@ fn option_methods() { // Check for `option.map(_).unwrap_or_else(_)` use. // single line case let _ = opt.map(|x| x + 1) + //~^ map_unwrap_or // Should lint even though this call is on a separate line. .unwrap_or_else(|| 0); @@ -44,6 +45,7 @@ fn result_methods() { // Check for `result.map(_).unwrap_or_else(_)` use. // single line case let _ = res.map(|x| x + 1) + //~^ map_unwrap_or // should lint even though this call is on a separate line .unwrap_or_else(|_e| 0); diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr index 89a7c979f6e9..99e660f8dbd1 100644 --- a/tests/ui/map_unwrap_or_fixable.stderr +++ b/tests/ui/map_unwrap_or_fixable.stderr @@ -3,7 +3,7 @@ error: called `map().unwrap_or_else()` on an `Option` value | LL | let _ = opt.map(|x| x + 1) | _____________^ -LL | | // Should lint even though this call is on a separate line. +... | LL | | .unwrap_or_else(|| 0); | |_____________________________^ help: try: `opt.map_or_else(|| 0, |x| x + 1)` | @@ -11,11 +11,11 @@ LL | | .unwrap_or_else(|| 0); = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` error: called `map().unwrap_or_else()` on a `Result` value - --> tests/ui/map_unwrap_or_fixable.rs:46:13 + --> tests/ui/map_unwrap_or_fixable.rs:47:13 | LL | let _ = res.map(|x| x + 1) | _____________^ -LL | | // should lint even though this call is on a separate line +... | LL | | .unwrap_or_else(|_e| 0); | |_______________________________^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)` diff --git a/tests/ui/map_with_unused_argument_over_ranges.fixed b/tests/ui/map_with_unused_argument_over_ranges.fixed index 18716e93d1e9..08bc1c7a6283 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.fixed +++ b/tests/ui/map_with_unused_argument_over_ranges.fixed @@ -23,27 +23,43 @@ macro_rules! r#gen { fn main() { // These should be raised std::iter::repeat_with(|| do_something()).take(10); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(10); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(11); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(7); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(8); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_n(3, 10); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| { + //~^ map_with_unused_argument_over_ranges let x = 3; x + 2 }).take(10); std::iter::repeat_with(|| do_something()).take(10).collect::>(); + //~^ map_with_unused_argument_over_ranges let upper = 4; std::iter::repeat_with(|| do_something()).take(upper); + //~^ map_with_unused_argument_over_ranges let upper_fn = || 4; std::iter::repeat_with(|| do_something()).take(upper_fn()); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(upper_fn() + 1); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(upper_fn() - 2); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(upper_fn() - 1); + //~^ map_with_unused_argument_over_ranges (-3..9).map(|_| do_something()); std::iter::repeat_with(|| do_something()).take(0); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take(1); + //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| do_something()).take((1 << 4) - 0); + //~^ map_with_unused_argument_over_ranges // These should not be raised r#gen!(); let lower = 2; @@ -65,9 +81,11 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { std::iter::repeat_with(|| do_something()).take(10); + //~^ map_with_unused_argument_over_ranges } #[clippy::msrv = "1.81"] fn msrv_1_82() { std::iter::repeat(3).take(10); + //~^ map_with_unused_argument_over_ranges } diff --git a/tests/ui/map_with_unused_argument_over_ranges.rs b/tests/ui/map_with_unused_argument_over_ranges.rs index 596afd51e61f..151ebdf97e5d 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.rs +++ b/tests/ui/map_with_unused_argument_over_ranges.rs @@ -23,27 +23,43 @@ macro_rules! r#gen { fn main() { // These should be raised (0..10).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (0..10).map(|_foo| do_something()); + //~^ map_with_unused_argument_over_ranges (0..=10).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (3..10).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (3..=10).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (0..10).map(|_| 3); + //~^ map_with_unused_argument_over_ranges (0..10).map(|_| { + //~^ map_with_unused_argument_over_ranges let x = 3; x + 2 }); (0..10).map(|_| do_something()).collect::>(); + //~^ map_with_unused_argument_over_ranges let upper = 4; (0..upper).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges let upper_fn = || 4; (0..upper_fn()).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (0..=upper_fn()).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (2..upper_fn()).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (2..=upper_fn()).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (-3..9).map(|_| do_something()); (9..3).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (9..=9).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges (1..=1 << 4).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges // These should not be raised r#gen!(); let lower = 2; @@ -65,9 +81,11 @@ fn msrv_1_27() { #[clippy::msrv = "1.28"] fn msrv_1_28() { (0..10).map(|_| do_something()); + //~^ map_with_unused_argument_over_ranges } #[clippy::msrv = "1.81"] fn msrv_1_82() { (0..10).map(|_| 3); + //~^ map_with_unused_argument_over_ranges } diff --git a/tests/ui/map_with_unused_argument_over_ranges.stderr b/tests/ui/map_with_unused_argument_over_ranges.stderr index 0b56c6d95219..ed905b6591c7 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.stderr +++ b/tests/ui/map_with_unused_argument_over_ranges.stderr @@ -13,7 +13,7 @@ LL + std::iter::repeat_with(|| do_something()).take(10); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:26:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:27:5 | LL | (0..10).map(|_foo| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + std::iter::repeat_with(|| do_something()).take(10); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:27:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:29:5 | LL | (0..=10).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + std::iter::repeat_with(|| do_something()).take(11); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:28:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:31:5 | LL | (3..10).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + std::iter::repeat_with(|| do_something()).take(7); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:29:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:33:5 | LL | (3..=10).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + std::iter::repeat_with(|| do_something()).take(8); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:30:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:35:5 | LL | (0..10).map(|_| 3); | ^^^^^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL | std::iter::repeat_n(3, 10); | ~~~~~~~~~~~~~~~~~~~ ~~~~~ error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:31:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:37:5 | LL | / (0..10).map(|_| { +LL | | LL | | let x = 3; LL | | x + 2 LL | | }); @@ -83,13 +84,14 @@ LL | | }); help: remove the explicit range and use `repeat_with` and `take` | LL ~ std::iter::repeat_with(|| { +LL | LL | let x = 3; LL | x + 2 LL ~ }).take(10); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:35:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:42:5 | LL | (0..10).map(|_| do_something()).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +103,7 @@ LL + std::iter::repeat_with(|| do_something()).take(10).collect::>(); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:37:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:45:5 | LL | (0..upper).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -113,7 +115,7 @@ LL + std::iter::repeat_with(|| do_something()).take(upper); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:39:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:48:5 | LL | (0..upper_fn()).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -125,7 +127,7 @@ LL + std::iter::repeat_with(|| do_something()).take(upper_fn()); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:40:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:50:5 | LL | (0..=upper_fn()).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,7 +139,7 @@ LL + std::iter::repeat_with(|| do_something()).take(upper_fn() + 1); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:41:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:52:5 | LL | (2..upper_fn()).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +151,7 @@ LL + std::iter::repeat_with(|| do_something()).take(upper_fn() - 2); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:42:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:54:5 | LL | (2..=upper_fn()).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -161,7 +163,7 @@ LL + std::iter::repeat_with(|| do_something()).take(upper_fn() - 1); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:44:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:57:5 | LL | (9..3).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -173,7 +175,7 @@ LL + std::iter::repeat_with(|| do_something()).take(0); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:45:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:59:5 | LL | (9..=9).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,7 +187,7 @@ LL + std::iter::repeat_with(|| do_something()).take(1); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:46:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:61:5 | LL | (1..=1 << 4).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +199,7 @@ LL + std::iter::repeat_with(|| do_something()).take((1 << 4) - 0); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:67:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:83:5 | LL | (0..10).map(|_| do_something()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +211,7 @@ LL + std::iter::repeat_with(|| do_something()).take(10); | error: map of a closure that does not depend on its parameter over a range - --> tests/ui/map_with_unused_argument_over_ranges.rs:72:5 + --> tests/ui/map_with_unused_argument_over_ranges.rs:89:5 | LL | (0..10).map(|_| 3); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_with_unused_argument_over_ranges_nostd.fixed b/tests/ui/map_with_unused_argument_over_ranges_nostd.fixed index 65e59774905c..15a2780da440 100644 --- a/tests/ui/map_with_unused_argument_over_ranges_nostd.fixed +++ b/tests/ui/map_with_unused_argument_over_ranges_nostd.fixed @@ -5,4 +5,5 @@ use alloc::vec::Vec; fn nostd(v: &mut [i32]) { let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); + //~^ map_with_unused_argument_over_ranges } diff --git a/tests/ui/map_with_unused_argument_over_ranges_nostd.rs b/tests/ui/map_with_unused_argument_over_ranges_nostd.rs index dda7a69b33f9..58de71facebb 100644 --- a/tests/ui/map_with_unused_argument_over_ranges_nostd.rs +++ b/tests/ui/map_with_unused_argument_over_ranges_nostd.rs @@ -5,4 +5,5 @@ use alloc::vec::Vec; fn nostd(v: &mut [i32]) { let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); + //~^ map_with_unused_argument_over_ranges } diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs index 655e16623697..7eaabcdc3d0e 100644 --- a/tests/ui/match_as_ref.rs +++ b/tests/ui/match_as_ref.rs @@ -4,12 +4,14 @@ fn match_as_ref() { let owned: Option<()> = None; let borrowed: Option<&()> = match owned { + //~^ match_as_ref None => None, Some(ref v) => Some(v), }; let mut mut_owned: Option<()> = None; let borrow_mut: Option<&mut ()> = match mut_owned { + //~^ match_as_ref None => None, Some(ref mut v) => Some(v), }; @@ -28,6 +30,7 @@ mod issue4437 { impl Error for E { fn source(&self) -> Option<&(dyn Error + 'static)> { match self.source { + //~^ match_as_ref Some(ref s) => Some(s), None => None, } diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr index 97b121424d93..7b40cb80dc6e 100644 --- a/tests/ui/match_as_ref.stderr +++ b/tests/ui/match_as_ref.stderr @@ -3,6 +3,7 @@ error: use `as_ref()` instead | LL | let borrowed: Option<&()> = match owned { | _________________________________^ +LL | | LL | | None => None, LL | | Some(ref v) => Some(v), LL | | }; @@ -12,19 +13,21 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::match_as_ref)]` error: use `as_mut()` instead - --> tests/ui/match_as_ref.rs:12:39 + --> tests/ui/match_as_ref.rs:13:39 | LL | let borrow_mut: Option<&mut ()> = match mut_owned { | _______________________________________^ +LL | | LL | | None => None, LL | | Some(ref mut v) => Some(v), LL | | }; | |_____^ help: try: `mut_owned.as_mut()` error: use `as_ref()` instead - --> tests/ui/match_as_ref.rs:30:13 + --> tests/ui/match_as_ref.rs:32:13 | LL | / match self.source { +LL | | LL | | Some(ref s) => Some(s), LL | | None => None, LL | | } diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index e77f0304feda..7d4afd3f2890 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -5,20 +5,23 @@ fn match_bool() { let test: bool = true; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true => 0, false => 42, }; let option = 1; match option == 1 { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true => 1, false => 0, }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true => (), false => { println!("Noooo!"); @@ -26,7 +29,8 @@ fn match_bool() { }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false => { println!("Noooo!"); }, @@ -34,7 +38,8 @@ fn match_bool() { }; match test && test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false => { println!("Noooo!"); }, @@ -42,7 +47,8 @@ fn match_bool() { }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false => { println!("Noooo!"); }, @@ -67,37 +73,43 @@ fn match_bool() { }; let _ = match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true if option == 5 => 10, _ => 1, }; let _ = match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false if option == 5 => 10, _ => 1, }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true if option == 5 => println!("Hello"), _ => (), }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true if option == 5 => (), _ => println!("Hello"), }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false if option == 5 => println!("Hello"), _ => (), }; match test { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + false if option == 5 => (), _ => println!("Hello"), }; @@ -105,7 +117,8 @@ fn match_bool() { fn issue14099() { match true { - //~^ ERROR: `match` on a boolean expression + //~^ match_bool + true => 'a: { break 'a; }, diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index c05742e56339..c25aad27cef2 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -3,6 +3,7 @@ error: `match` on a boolean expression | LL | / match test { LL | | +LL | | LL | | true => 0, LL | | false => 42, LL | | }; @@ -15,23 +16,24 @@ LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: `match` on a boolean expression - --> tests/ui/match_bool.rs:14:5 + --> tests/ui/match_bool.rs:15:5 | LL | / match option == 1 { LL | | +LL | | LL | | true => 1, LL | | false => 0, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:20:5 + --> tests/ui/match_bool.rs:22:5 | LL | / match test { LL | | +LL | | LL | | true => (), -LL | | false => { -LL | | println!("Noooo!"); +... | LL | | }, LL | | }; | |_____^ @@ -44,13 +46,13 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:28:5 + --> tests/ui/match_bool.rs:31:5 | LL | / match test { LL | | +LL | | LL | | false => { -LL | | println!("Noooo!"); -LL | | }, +... | LL | | _ => (), LL | | }; | |_____^ @@ -63,13 +65,13 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:36:5 + --> tests/ui/match_bool.rs:40:5 | LL | / match test && test { LL | | +LL | | LL | | false => { -LL | | println!("Noooo!"); -LL | | }, +... | LL | | _ => (), LL | | }; | |_____^ @@ -82,12 +84,12 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:44:5 + --> tests/ui/match_bool.rs:49:5 | LL | / match test { LL | | +LL | | LL | | false => { -LL | | println!("Noooo!"); ... | LL | | }, LL | | }; @@ -103,75 +105,81 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:69:13 + --> tests/ui/match_bool.rs:75:13 | LL | let _ = match test { | _____________^ LL | | +LL | | LL | | true if option == 5 => 10, LL | | _ => 1, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test && option == 5 { 10 } else { 1 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:75:13 + --> tests/ui/match_bool.rs:82:13 | LL | let _ = match test { | _____________^ LL | | +LL | | LL | | false if option == 5 => 10, LL | | _ => 1, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !test && option == 5 { 10 } else { 1 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:81:5 + --> tests/ui/match_bool.rs:89:5 | LL | / match test { LL | | +LL | | LL | | true if option == 5 => println!("Hello"), LL | | _ => (), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test && option == 5 { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:87:5 + --> tests/ui/match_bool.rs:96:5 | LL | / match test { LL | | +LL | | LL | | true if option == 5 => (), LL | | _ => println!("Hello"), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !(test && option == 5) { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:93:5 + --> tests/ui/match_bool.rs:103:5 | LL | / match test { LL | | +LL | | LL | | false if option == 5 => println!("Hello"), LL | | _ => (), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !test && option == 5 { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:99:5 + --> tests/ui/match_bool.rs:110:5 | LL | / match test { LL | | +LL | | LL | | false if option == 5 => (), LL | | _ => println!("Hello"), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !(!test && option == 5) { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:107:5 + --> tests/ui/match_bool.rs:119:5 | LL | / match true { LL | | +LL | | LL | | true => 'a: { -LL | | break 'a; -LL | | }, +... | LL | | _ => (), LL | | } | |_____^ diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed index 05edc024ba9f..8530ab16bfd7 100644 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ b/tests/ui/match_expr_like_matches_macro.fixed @@ -12,18 +12,23 @@ fn main() { // Lint let _y = matches!(x, Some(0)); + //~^^^^ match_like_matches_macro // Lint let _w = x.is_some(); + //~^^^^ redundant_pattern_matching // Turn into is_none let _z = x.is_none(); + //~^^^^ redundant_pattern_matching // Lint let _zz = !matches!(x, Some(r) if r == 0); + //~^^^^ match_like_matches_macro // Lint let _zzz = matches!(x, Some(5)); + //~^ match_like_matches_macro // No lint let _a = match x { @@ -48,16 +53,19 @@ fn main() { { // lint let _ans = matches!(x, E::A(_) | E::B(_)); + //~^^^^^ match_like_matches_macro } { // lint // skip rustfmt to prevent removing block for first pattern #[rustfmt::skip] let _ans = matches!(x, E::A(_) | E::B(_)); + //~^^^^^^^ match_like_matches_macro } { // lint let _ans = !matches!(x, E::B(_) | E::C); + //~^^^^^ match_like_matches_macro } { // no lint @@ -114,12 +122,14 @@ fn main() { // should print "z" in suggestion (#6503) let z = &Some(3); let _z = matches!(z, Some(3)); + //~^^^^ match_like_matches_macro } { // this could also print "z" in suggestion..? let z = Some(3); let _z = matches!(&z, Some(3)); + //~^^^^ match_like_matches_macro } { @@ -134,6 +144,7 @@ fn main() { let z = AnEnum::X; // we can't remove the reference here! let _ = matches!(&z, AnEnum::X); + //~^^^^ match_like_matches_macro foo(z); } } @@ -145,6 +156,7 @@ fn main() { let val = Some(S(42)); // we need the reference here because later val is consumed by fun() let _res = matches!(&val, &Some(ref _a)); + //~^^^^ match_like_matches_macro fun(val); } @@ -154,6 +166,7 @@ fn main() { fn fun(_val: Option) {} let val = Some(S(42)); let _res = matches!(&val, &Some(ref _a)); + //~^^^^ match_like_matches_macro fun(val); } @@ -209,4 +222,5 @@ fn msrv_1_41() { #[clippy::msrv = "1.42"] fn msrv_1_42() { let _y = matches!(Some(5), Some(0)); + //~^^^^ match_like_matches_macro } diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index d6a0313cde43..81017936889e 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -15,27 +15,32 @@ fn main() { Some(0) => true, _ => false, }; + //~^^^^ match_like_matches_macro // Lint let _w = match x { Some(_) => true, _ => false, }; + //~^^^^ redundant_pattern_matching // Turn into is_none let _z = match x { Some(_) => false, None => true, }; + //~^^^^ redundant_pattern_matching // Lint let _zz = match x { Some(r) if r == 0 => false, _ => true, }; + //~^^^^ match_like_matches_macro // Lint let _zzz = if let Some(5) = x { true } else { false }; + //~^ match_like_matches_macro // No lint let _a = match x { @@ -64,6 +69,7 @@ fn main() { E::B(_) => true, _ => false, }; + //~^^^^^ match_like_matches_macro } { // lint @@ -76,6 +82,7 @@ fn main() { E::B(_) => true, _ => false, }; + //~^^^^^^^ match_like_matches_macro } { // lint @@ -84,6 +91,7 @@ fn main() { E::C => false, _ => true, }; + //~^^^^^ match_like_matches_macro } { // no lint @@ -143,6 +151,7 @@ fn main() { Some(3) => true, _ => false, }; + //~^^^^ match_like_matches_macro } { @@ -152,6 +161,7 @@ fn main() { Some(3) => true, _ => false, }; + //~^^^^ match_like_matches_macro } { @@ -169,6 +179,7 @@ fn main() { AnEnum::X => true, _ => false, }; + //~^^^^ match_like_matches_macro foo(z); } } @@ -183,6 +194,7 @@ fn main() { &Some(ref _a) => true, _ => false, }; + //~^^^^ match_like_matches_macro fun(val); } @@ -195,6 +207,7 @@ fn main() { &Some(ref _a) => true, _ => false, }; + //~^^^^ match_like_matches_macro fun(val); } @@ -253,4 +266,5 @@ fn msrv_1_42() { Some(0) => true, _ => false, }; + //~^^^^ match_like_matches_macro } diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr index ffe5772ece90..8fceb05bc6e8 100644 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ b/tests/ui/match_expr_like_matches_macro.stderr @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/match_expr_like_matches_macro.rs:20:14 + --> tests/ui/match_expr_like_matches_macro.rs:21:14 | LL | let _w = match x { | ______________^ @@ -25,7 +25,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/match_expr_like_matches_macro.rs:26:14 + --> tests/ui/match_expr_like_matches_macro.rs:28:14 | LL | let _z = match x { | ______________^ @@ -35,7 +35,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:32:15 + --> tests/ui/match_expr_like_matches_macro.rs:35:15 | LL | let _zz = match x { | _______________^ @@ -45,13 +45,13 @@ LL | | }; | |_____^ help: try: `!matches!(x, Some(r) if r == 0)` error: if let .. else expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:38:16 + --> tests/ui/match_expr_like_matches_macro.rs:42: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 - --> tests/ui/match_expr_like_matches_macro.rs:62:20 + --> tests/ui/match_expr_like_matches_macro.rs:67:20 | LL | let _ans = match x { | ____________________^ @@ -62,7 +62,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:72:20 + --> tests/ui/match_expr_like_matches_macro.rs:78:20 | LL | let _ans = match x { | ____________________^ @@ -74,7 +74,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:82:20 + --> tests/ui/match_expr_like_matches_macro.rs:89:20 | LL | let _ans = match x { | ____________________^ @@ -85,7 +85,7 @@ LL | | }; | |_________^ help: try: `!matches!(x, E::B(_) | E::C)` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:142:18 + --> tests/ui/match_expr_like_matches_macro.rs:150:18 | LL | let _z = match &z { | __________________^ @@ -95,7 +95,7 @@ LL | | }; | |_________^ help: try: `matches!(z, Some(3))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:151:18 + --> tests/ui/match_expr_like_matches_macro.rs:160:18 | LL | let _z = match &z { | __________________^ @@ -105,7 +105,7 @@ LL | | }; | |_________^ help: try: `matches!(&z, Some(3))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:168:21 + --> tests/ui/match_expr_like_matches_macro.rs:178:21 | LL | let _ = match &z { | _____________________^ @@ -115,7 +115,7 @@ LL | | }; | |_____________^ help: try: `matches!(&z, AnEnum::X)` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:182:20 + --> tests/ui/match_expr_like_matches_macro.rs:193:20 | LL | let _res = match &val { | ____________________^ @@ -125,7 +125,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:194:20 + --> tests/ui/match_expr_like_matches_macro.rs:206:20 | LL | let _res = match &val { | ____________________^ @@ -135,7 +135,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> tests/ui/match_expr_like_matches_macro.rs:252:14 + --> tests/ui/match_expr_like_matches_macro.rs:265: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 f7b8500faa4a..1b7ce69f3ae7 100644 --- a/tests/ui/match_on_vec_items.rs +++ b/tests/ui/match_on_vec_items.rs @@ -8,8 +8,9 @@ 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` + //~^ match_on_vec_items + + 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -17,7 +18,8 @@ fn match_with_wildcard() { // Lint, may panic match arr[range] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, @@ -31,7 +33,8 @@ fn match_without_wildcard() { // Lint, may panic match arr[idx] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + 0 => println!("0"), 1 => println!("1"), num => {}, @@ -39,7 +42,8 @@ fn match_without_wildcard() { // Lint, may panic match arr[range] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), [ref sub @ ..] => {}, @@ -53,7 +57,8 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[idx] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + 0 => println!("0"), 1 => println!("1"), _ => println!("Hello, World!"), @@ -61,7 +66,8 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[range] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => println!("Hello, World!"), @@ -75,7 +81,8 @@ fn match_vec_ref() { // Lint, may panic match arr[idx] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -83,7 +90,8 @@ fn match_vec_ref() { // Lint, may panic match arr[range] { - //~^ ERROR: indexing into a vector may panic + //~^ match_on_vec_items + [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 e31db3784137..b00b2cb662a0 100644 --- a/tests/ui/match_on_vec_items.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -8,43 +8,43 @@ LL | match arr[idx] { = help: to override `-D warnings` add `#[allow(clippy::match_on_vec_items)]` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:19:11 + --> tests/ui/match_on_vec_items.rs:20:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:33:11 + --> tests/ui/match_on_vec_items.rs:35:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:41:11 + --> tests/ui/match_on_vec_items.rs:44:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:55:11 + --> tests/ui/match_on_vec_items.rs:59:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:63:11 + --> tests/ui/match_on_vec_items.rs:68:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:77:11 + --> tests/ui/match_on_vec_items.rs:83:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:85:11 + --> tests/ui/match_on_vec_items.rs:92: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 a056fdeaa5d0..3885731264f7 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -7,14 +7,16 @@ fn overlapping() { match 42 { 0..=10 => println!("0..=10"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 0..=11 => println!("0..=11"), _ => (), } match 42 { 0..=5 => println!("0..=5"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 6..=7 => println!("6..=7"), FOO..=11 => println!("FOO..=11"), _ => (), @@ -52,7 +54,8 @@ fn overlapping() { match 42 { 0..11 => println!("0..11"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 0..=11 => println!("0..=11"), _ => (), } @@ -78,13 +81,15 @@ fn overlapping() { match 42 { 5..14 => println!("5..14"), 0..=10 => println!("0..=10"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + _ => (), } match 42 { 0..7 => println!("0..7"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 0..=10 => println!("0..=10"), _ => (), } @@ -97,7 +102,8 @@ fn overlapping() { match 42 { ..=23 => println!("..=23"), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + ..26 => println!("..26"), _ => (), } @@ -107,7 +113,8 @@ fn overlapping() { 5..=10 => (), 0..=20 => (), 21..=30 => (), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 21..=40 => (), _ => (), } @@ -122,7 +129,8 @@ fn overlapping() { // Only warn about the first if there are multiple overlaps match 42u128 { 0..=0x0000_0000_0000_00ff => (), - //~^ ERROR: some ranges overlap + //~^ match_overlapping_arm + 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 a60a09a07990..cc928b4066a9 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -5,7 +5,7 @@ LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:11:9 + --> tests/ui/match_overlapping_arm.rs:12:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ @@ -13,85 +13,85 @@ LL | 0..=11 => println!("0..=11"), = help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]` error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:16:9 + --> tests/ui/match_overlapping_arm.rs:17:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:19:9 + --> tests/ui/match_overlapping_arm.rs:21:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:54:9 + --> tests/ui/match_overlapping_arm.rs:56:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:56:9 + --> tests/ui/match_overlapping_arm.rs:59:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:80:9 + --> tests/ui/match_overlapping_arm.rs:83:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:79:9 + --> tests/ui/match_overlapping_arm.rs:82:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:86:9 + --> tests/ui/match_overlapping_arm.rs:90:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:88:9 + --> tests/ui/match_overlapping_arm.rs:93:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:99:9 + --> tests/ui/match_overlapping_arm.rs:104:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:101:9 + --> tests/ui/match_overlapping_arm.rs:107:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:109:9 + --> tests/ui/match_overlapping_arm.rs:115:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:111:9 + --> tests/ui/match_overlapping_arm.rs:118:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:124:9 + --> tests/ui/match_overlapping_arm.rs:131:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:126:9 + --> tests/ui/match_overlapping_arm.rs:134:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_ref_pats.fixed b/tests/ui/match_ref_pats.fixed index f8d47b0fdc7d..8ada28985198 100644 --- a/tests/ui/match_ref_pats.fixed +++ b/tests/ui/match_ref_pats.fixed @@ -6,6 +6,7 @@ fn ref_pats() { { let v = &Some(0); match *v { + //~^ match_ref_pats Some(v) => println!("{:?}", v), None => println!("none"), } @@ -23,6 +24,7 @@ fn ref_pats() { // Special case: using `&` both in expr and pats. let w = Some(0); match w { + //~^ match_ref_pats Some(v) => println!("{:?}", v), None => println!("none"), } @@ -35,11 +37,13 @@ fn ref_pats() { let a = &Some(0); if a.is_none() { + //~^ redundant_pattern_matching println!("none"); } let b = Some(0); if b.is_none() { + //~^ redundant_pattern_matching println!("none"); } } @@ -100,6 +104,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 match *foobar_variant!(0) { + //~^ match_ref_pats FooBar::Foo => println!("Foo"), FooBar::Bar => println!("Bar"), FooBar::FooBar => println!("FooBar"), diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs index bcd7bf7ab51b..cac6240bde31 100644 --- a/tests/ui/match_ref_pats.rs +++ b/tests/ui/match_ref_pats.rs @@ -6,6 +6,7 @@ fn ref_pats() { { let v = &Some(0); match v { + //~^ match_ref_pats &Some(v) => println!("{:?}", v), &None => println!("none"), } @@ -23,6 +24,7 @@ fn ref_pats() { // Special case: using `&` both in expr and pats. let w = Some(0); match &w { + //~^ match_ref_pats &Some(v) => println!("{:?}", v), &None => println!("none"), } @@ -35,11 +37,13 @@ fn ref_pats() { let a = &Some(0); if let &None = a { + //~^ redundant_pattern_matching println!("none"); } let b = Some(0); if let &None = &b { + //~^ redundant_pattern_matching println!("none"); } } @@ -100,6 +104,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 match foobar_variant!(0) { + //~^ match_ref_pats &FooBar::Foo => println!("Foo"), &FooBar::Bar => println!("Bar"), &FooBar::FooBar => println!("FooBar"), diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index fc01ab0a919a..f81b290b32cb 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -2,6 +2,7 @@ error: you don't need to add `&` to all patterns --> tests/ui/match_ref_pats.rs:8:9 | LL | / match v { +LL | | LL | | &Some(v) => println!("{:?}", v), LL | | &None => println!("none"), LL | | } @@ -12,14 +13,16 @@ LL | | } help: instead of prefixing all patterns with `&`, you can dereference the expression | LL ~ match *v { +LL | LL ~ Some(v) => println!("{:?}", v), LL ~ None => println!("none"), | error: you don't need to add `&` to both the expression and the patterns - --> tests/ui/match_ref_pats.rs:25:5 + --> tests/ui/match_ref_pats.rs:26:5 | LL | / match &w { +LL | | LL | | &Some(v) => println!("{:?}", v), LL | | &None => println!("none"), LL | | } @@ -28,12 +31,13 @@ LL | | } help: try | LL ~ match w { +LL | LL ~ Some(v) => println!("{:?}", v), LL ~ None => println!("none"), | error: redundant pattern matching, consider using `is_none()` - --> tests/ui/match_ref_pats.rs:37:12 + --> tests/ui/match_ref_pats.rs:39:12 | LL | if let &None = a { | -------^^^^^---- help: try: `if a.is_none()` @@ -42,15 +46,16 @@ LL | if let &None = a { = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/match_ref_pats.rs:42:12 + --> tests/ui/match_ref_pats.rs:45:12 | LL | if let &None = &b { | -------^^^^^----- help: try: `if b.is_none()` error: you don't need to add `&` to all patterns - --> tests/ui/match_ref_pats.rs:102:9 + --> tests/ui/match_ref_pats.rs:106:9 | LL | / match foobar_variant!(0) { +LL | | LL | | &FooBar::Foo => println!("Foo"), LL | | &FooBar::Bar => println!("Bar"), LL | | &FooBar::FooBar => println!("FooBar"), @@ -61,6 +66,7 @@ LL | | } help: instead of prefixing all patterns with `&`, you can dereference the expression | LL ~ match *foobar_variant!(0) { +LL | LL ~ FooBar::Foo => println!("Foo"), LL ~ FooBar::Bar => println!("Bar"), LL ~ FooBar::FooBar => println!("FooBar"), diff --git a/tests/ui/match_result_ok.fixed b/tests/ui/match_result_ok.fixed index 117e0bc68ccc..2032394f0e92 100644 --- a/tests/ui/match_result_ok.fixed +++ b/tests/ui/match_result_ok.fixed @@ -11,6 +11,7 @@ fn str_to_int(x: &str) -> i32 { if let Ok(y) = x.parse() { y } else { 0 } + //~^ match_result_ok } fn str_to_int_ok(x: &str) -> i32 { @@ -21,6 +22,7 @@ fn str_to_int_ok(x: &str) -> i32 { fn strange_some_no_else(x: &str) -> i32 { { if let Ok(y) = x . parse() { + //~^ match_result_ok return y; }; 0 @@ -47,6 +49,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; while let Ok(a) = wat.next() { + //~^ match_result_ok println!("{}", a); } } diff --git a/tests/ui/match_result_ok.rs b/tests/ui/match_result_ok.rs index f8a5269024da..c15e32d112d4 100644 --- a/tests/ui/match_result_ok.rs +++ b/tests/ui/match_result_ok.rs @@ -11,6 +11,7 @@ fn str_to_int(x: &str) -> i32 { if let Some(y) = x.parse().ok() { y } else { 0 } + //~^ match_result_ok } fn str_to_int_ok(x: &str) -> i32 { @@ -21,6 +22,7 @@ fn str_to_int_ok(x: &str) -> i32 { fn strange_some_no_else(x: &str) -> i32 { { if let Some(y) = x . parse() . ok () { + //~^ match_result_ok return y; }; 0 @@ -47,6 +49,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; while let Some(a) = wat.next().ok() { + //~^ match_result_ok println!("{}", a); } } diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index b5b91cbe5534..ccdf53230757 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -12,7 +12,7 @@ LL | if let Ok(y) = x.parse() { y } else { 0 } | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> tests/ui/match_result_ok.rs:23:9 + --> tests/ui/match_result_ok.rs:24:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if let Ok(y) = x . parse() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> tests/ui/match_result_ok.rs:49:5 + --> tests/ui/match_result_ok.rs:51: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 2f4652dcf32b..073c66930357 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -9,30 +9,37 @@ pub enum Abc { fn match_same_arms() { let _ = match Abc::A { - Abc::A => 0, //~ ERROR: this match arm has an identical body to the `_` wildcard arm +Abc::A => 0, +//~^ match_same_arms Abc::B => 1, _ => 0, }; match (1, 2, 3) { - (1, .., 3) => 42, //~ ERROR: this match arm has an identical body to another arm +(1, .., 3) => 42, +//~^ match_same_arms (.., 3) => 42, _ => 0, }; let _ = match 42 { 42 => 1, - 51 => 1, //~ ERROR: this match arm has an identical body to another arm - 41 => 2, //~ ERROR: this match arm has an identical body to another arm +51 => 1, +//~^ match_same_arms +41 => 2, +//~^ match_same_arms 52 => 2, _ => 0, }; let _ = match 42 { 1 => 2, - 2 => 2, //~ ERROR: this match arm has an identical body to another arm - //~^ ERROR: this match arm has an identical body to another arm - 3 => 2, //~ ERROR: this match arm has an identical body to another arm +2 => 2, +//~^ match_same_arms +//~| match_same_arms + +3 => 2, +//~^ match_same_arms 4 => 3, _ => 0, }; @@ -50,7 +57,8 @@ mod issue4244 { match self { CommandInfo::BuiltIn { name, .. } => name.to_string(), CommandInfo::External { name, .. } => name.to_string(), - //~^ ERROR: this match arm has an identical body to another arm + //~^ match_same_arms + } } } diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 4a4772da143a..a269c4f39267 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -1,12 +1,13 @@ error: this match arm has an identical body to the `_` wildcard arm - --> tests/ui/match_same_arms.rs:12:9 + --> tests/ui/match_same_arms.rs:12:1 | -LL | Abc::A => 0, - | ^^^^^^^^^^^^^ help: try removing the arm +LL | / Abc::A => 0, +LL | | + | |_^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms.rs:14:9 + --> tests/ui/match_same_arms.rs:15:9 | LL | _ => 0, | ^^^^^^ @@ -14,89 +15,91 @@ LL | _ => 0, = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:18:9 + --> tests/ui/match_same_arms.rs:19:1 | -LL | (1, .., 3) => 42, - | ^^^^^^^^^^^^^^^^ +LL | (1, .., 3) => 42, + | ^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (1, .., 3) | (.., 3) => 42, +LL ~ (1, .., 3) | (.., 3) => 42, +LL | LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:25:9 + --> tests/ui/match_same_arms.rs:27:1 | -LL | 51 => 1, - | ^^^^^^^ +LL | 51 => 1, + | ^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 42 => 1, -LL - 51 => 1, +LL - 51 => 1, LL + 51 | 42 => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:26:9 + --> tests/ui/match_same_arms.rs:29:1 | -LL | 41 => 2, - | ^^^^^^^ +LL | 41 => 2, + | ^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ 41 | 52 => 2, +LL ~ 41 | 52 => 2, +LL | LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:33:9 + --> tests/ui/match_same_arms.rs:37:1 | -LL | 2 => 2, - | ^^^^^^ +LL | 2 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 1 => 2, -LL - 2 => 2, +LL - 2 => 2, LL + 2 | 1 => 2, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:35:9 + --> tests/ui/match_same_arms.rs:41:1 | -LL | 3 => 2, - | ^^^^^^ +LL | 3 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL ~ 2 => 2, LL | -LL ~ 3 | 1 => 2, +LL | +LL | +LL ~ 3 | 1 => 2, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:33:9 + --> tests/ui/match_same_arms.rs:37:1 | -LL | 2 => 2, - | ^^^^^^ +LL | 2 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ 2 | 3 => 2, -LL | -LL ~ +LL ~ 2 | 3 => 2, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:52:17 + --> tests/ui/match_same_arms.rs:59:17 | LL | CommandInfo::External { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms2.fixed b/tests/ui/match_same_arms2.fixed index b7d377f1ebff..855c3287532c 100644 --- a/tests/ui/match_same_arms2.fixed +++ b/tests/ui/match_same_arms2.fixed @@ -14,6 +14,7 @@ fn foo() -> bool { fn match_same_arms() { let _ = match 42 { + //~^^^^^^^^^ match_same_arms _ => { foo(); let mut a = 42 + [23].len() as i32; @@ -24,15 +25,17 @@ fn match_same_arms() { a }, }; - //~^^^^^^^^^^^^^^^^^^^ ERROR: this match arm has an identical body to the `_` wildcard arm + let _ = match 42 { - 51 | 42 => foo(), //~ ERROR: this match arm has an identical body to another arm + 51 | 42 => foo(), +//~^ match_same_arms _ => true, }; let _ = match Some(42) { - None | Some(_) => 24, //~ ERROR: this match arm has an identical body to another arm + None | Some(_) => 24, +//~^ match_same_arms }; let _ = match Some(42) { @@ -53,7 +56,8 @@ fn match_same_arms() { }; match (Some(42), Some(42)) { - (None, Some(a)) | (Some(a), None) => bar(a), //~ ERROR: this match arm has an identical body to another arm + (None, Some(a)) | (Some(a), None) => bar(a), +//~^ match_same_arms _ => (), } @@ -66,12 +70,14 @@ fn match_same_arms() { }; let _ = match (Some(42), Some(42)) { - (None, Some(a)) | (Some(a), None) if a == 42 => a, //~ ERROR: this match arm has an identical body to another arm + (None, Some(a)) | (Some(a), None) if a == 42 => a, +//~^ match_same_arms _ => 0, }; match (Some(42), Some(42)) { - (Some(a), ..) | (.., Some(a)) => bar(a), //~ ERROR: this match arm has an identical body to another arm +(Some(a), ..) | (.., Some(a)) => bar(a), +//~^ match_same_arms _ => (), } @@ -104,7 +110,8 @@ fn match_same_arms() { } match (x, Some(1i32)) { - (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), //~ ERROR: this match arm has an identical body to another arm +(Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), +//~^ match_same_arms _ => println!("err"), } @@ -118,7 +125,8 @@ fn match_same_arms() { // False negative #2251. match x { Ok(_tmp) => println!("ok"), - Ok(_) | Ok(3) => println!("ok"), //~ ERROR: this match arm has an identical body to another arm + Ok(_) | Ok(3) => println!("ok"), +//~^ match_same_arms Err(_) => { unreachable!(); }, @@ -145,11 +153,12 @@ fn match_same_arms() { 1 | 0 => { empty!(0); }, + //~^^^ match_same_arms x => { empty!(x); }, } - //~^^^^^^^ ERROR: this match arm has an identical body to another arm + match_expr_like_matches_macro_priority(); } @@ -193,7 +202,8 @@ fn main() { // Suggest moving `Foo::Z(_)` up. let _ = match Foo::X(0) { - Foo::X(0) | Foo::Z(_) => 1, //~ ERROR: this match arm has an identical body to another arm +Foo::X(0) | Foo::Z(_) => 1, +//~^ match_same_arms Foo::X(_) | Foo::Y(_) => 2, _ => 0, }; @@ -201,7 +211,8 @@ fn main() { // Suggest moving `Foo::X(0)` down. let _ = match Foo::X(0) { Foo::Y(_) | Foo::Z(0) => 2, - Foo::Z(_) | Foo::X(0) => 1, //~ ERROR: this match arm has an identical body to another arm +Foo::Z(_) | Foo::X(0) => 1, +//~^ match_same_arms _ => 0, }; @@ -223,7 +234,8 @@ fn main() { let _ = match None { Some(Bar { y: 10, z: 0, .. }) => 2, None => 50, - Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, //~ ERROR: this match arm has an identical body to another arm +Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, +//~^ match_same_arms _ => 200, }; @@ -237,6 +249,7 @@ fn main() { let _ = match 0 { 1 | 0 => cfg!(not_enable), + //~^ match_same_arms _ => false, }; } @@ -252,7 +265,8 @@ mod with_lifetime { fn get(&self) -> &'a str { match *self { MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s, - //~^ ERROR: this match arm has an identical body to another arm + //~^ match_same_arms + } } } diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs index dfd15d10c3d3..73a4fd432551 100644 --- a/tests/ui/match_same_arms2.rs +++ b/tests/ui/match_same_arms2.rs @@ -23,6 +23,7 @@ fn match_same_arms() { a = -31 - a; a }, + //~^^^^^^^^^ match_same_arms _ => { foo(); let mut a = 42 + [23].len() as i32; @@ -33,17 +34,19 @@ fn match_same_arms() { a }, }; - //~^^^^^^^^^^^^^^^^^^^ ERROR: this match arm has an identical body to the `_` wildcard arm + let _ = match 42 { 42 => foo(), - 51 => foo(), //~ ERROR: this match arm has an identical body to another arm +51 => foo(), +//~^ match_same_arms _ => true, }; let _ = match Some(42) { Some(_) => 24, - None => 24, //~ ERROR: this match arm has an identical body to another arm +None => 24, +//~^ match_same_arms }; let _ = match Some(42) { @@ -65,7 +68,8 @@ fn match_same_arms() { match (Some(42), Some(42)) { (Some(a), None) => bar(a), - (None, Some(a)) => bar(a), //~ ERROR: this match arm has an identical body to another arm +(None, Some(a)) => bar(a), +//~^ match_same_arms _ => (), } @@ -79,12 +83,14 @@ fn match_same_arms() { let _ = match (Some(42), Some(42)) { (Some(a), None) if a == 42 => a, - (None, Some(a)) if a == 42 => a, //~ ERROR: this match arm has an identical body to another arm +(None, Some(a)) if a == 42 => a, +//~^ match_same_arms _ => 0, }; match (Some(42), Some(42)) { - (Some(a), ..) => bar(a), //~ ERROR: this match arm has an identical body to another arm +(Some(a), ..) => bar(a), +//~^ match_same_arms (.., Some(a)) => bar(a), _ => (), } @@ -118,7 +124,8 @@ fn match_same_arms() { } match (x, Some(1i32)) { - (Ok(x), Some(_)) => println!("ok {}", x), //~ ERROR: this match arm has an identical body to another arm +(Ok(x), Some(_)) => println!("ok {}", x), +//~^ match_same_arms (Ok(_), Some(x)) => println!("ok {}", x), _ => println!("err"), } @@ -134,7 +141,8 @@ fn match_same_arms() { match x { Ok(_tmp) => println!("ok"), Ok(3) => println!("ok"), - Ok(_) => println!("ok"), //~ ERROR: this match arm has an identical body to another arm +Ok(_) => println!("ok"), +//~^ match_same_arms Err(_) => { unreachable!(); }, @@ -164,11 +172,12 @@ fn match_same_arms() { 1 => { empty!(0); }, + //~^^^ match_same_arms x => { empty!(x); }, } - //~^^^^^^^ ERROR: this match arm has an identical body to another arm + match_expr_like_matches_macro_priority(); } @@ -212,7 +221,8 @@ fn main() { // Suggest moving `Foo::Z(_)` up. let _ = match Foo::X(0) { - Foo::X(0) => 1, //~ ERROR: this match arm has an identical body to another arm +Foo::X(0) => 1, +//~^ match_same_arms Foo::X(_) | Foo::Y(_) => 2, Foo::Z(_) => 1, _ => 0, @@ -222,7 +232,8 @@ fn main() { let _ = match Foo::X(0) { Foo::X(0) => 1, Foo::Y(_) | Foo::Z(0) => 2, - Foo::Z(_) => 1, //~ ERROR: this match arm has an identical body to another arm +Foo::Z(_) => 1, +//~^ match_same_arms _ => 0, }; @@ -245,7 +256,8 @@ fn main() { Some(Bar { x: 0, y: 5, .. }) => 1, Some(Bar { y: 10, z: 0, .. }) => 2, None => 50, - Some(Bar { y: 0, x: 5, .. }) => 1, //~ ERROR: this match arm has an identical body to another arm +Some(Bar { y: 0, x: 5, .. }) => 1, +//~^ match_same_arms _ => 200, }; @@ -260,6 +272,7 @@ fn main() { let _ = match 0 { 0 => cfg!(not_enable), 1 => cfg!(not_enable), + //~^ match_same_arms _ => false, }; } @@ -276,7 +289,8 @@ mod with_lifetime { match *self { MaybeStaticStr::Static(s) => s, MaybeStaticStr::Borrowed(s) => s, - //~^ ERROR: this match arm has an identical body to another arm + //~^ match_same_arms + } } } diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index 525a25e9287b..c67ac5475aae 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -7,12 +7,12 @@ LL | | let mut a = 42 + [23].len() as i32; LL | | if true { ... | LL | | }, -LL | | _ => { +LL | | | |________^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms2.rs:26:9 + --> tests/ui/match_same_arms2.rs:27:9 | LL | / _ => { LL | | foo(); @@ -26,103 +26,105 @@ LL | | }, = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:40:9 + --> tests/ui/match_same_arms2.rs:41:1 | -LL | 51 => foo(), - | ^^^^^^^^^^^ +LL | 51 => foo(), + | ^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 42 => foo(), -LL - 51 => foo(), +LL - 51 => foo(), LL + 51 | 42 => foo(), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:46:9 + --> tests/ui/match_same_arms2.rs:48:1 | -LL | None => 24, - | ^^^^^^^^^^ +LL | None => 24, + | ^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - Some(_) => 24, -LL - None => 24, +LL - None => 24, LL + None | Some(_) => 24, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:68:9 + --> tests/ui/match_same_arms2.rs:71:1 | -LL | (None, Some(a)) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (None, Some(a)) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - (Some(a), None) => bar(a), -LL - (None, Some(a)) => bar(a), +LL - (None, Some(a)) => bar(a), LL + (None, Some(a)) | (Some(a), None) => bar(a), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:82:9 + --> tests/ui/match_same_arms2.rs:86:1 | -LL | (None, Some(a)) if a == 42 => a, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (None, Some(a)) if a == 42 => a, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - (Some(a), None) if a == 42 => a, -LL - (None, Some(a)) if a == 42 => a, +LL - (None, Some(a)) if a == 42 => a, LL + (None, Some(a)) | (Some(a), None) if a == 42 => a, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:87:9 + --> tests/ui/match_same_arms2.rs:92:1 | -LL | (Some(a), ..) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Some(a), ..) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (Some(a), ..) | (.., Some(a)) => bar(a), +LL ~ (Some(a), ..) | (.., Some(a)) => bar(a), +LL | LL ~ _ => (), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:121:9 + --> tests/ui/match_same_arms2.rs:127:1 | -LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Ok(x), Some(_)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), +LL ~ (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), +LL | LL ~ _ => println!("err"), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:137:9 + --> tests/ui/match_same_arms2.rs:144:1 | -LL | Ok(_) => println!("ok"), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | Ok(_) => println!("ok"), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - Ok(3) => println!("ok"), -LL - Ok(_) => println!("ok"), +LL - Ok(_) => println!("ok"), LL + Ok(_) | Ok(3) => println!("ok"), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:164:9 + --> tests/ui/match_same_arms2.rs:172:9 | LL | / 1 => { LL | | empty!(0); @@ -140,48 +142,49 @@ LL + 1 | 0 => { | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:215:9 + --> tests/ui/match_same_arms2.rs:224:1 | -LL | Foo::X(0) => 1, - | ^^^^^^^^^^^^^^ +LL | Foo::X(0) => 1, + | ^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ Foo::X(0) | Foo::Z(_) => 1, +LL ~ Foo::X(0) | Foo::Z(_) => 1, +LL | LL | Foo::X(_) | Foo::Y(_) => 2, LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:225:9 + --> tests/ui/match_same_arms2.rs:235:1 | -LL | Foo::Z(_) => 1, - | ^^^^^^^^^^^^^^ +LL | Foo::Z(_) => 1, + | ^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL ~ Foo::Y(_) | Foo::Z(0) => 2, -LL ~ Foo::Z(_) | Foo::X(0) => 1, +LL ~ Foo::Z(_) | Foo::X(0) => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:248:9 + --> tests/ui/match_same_arms2.rs:259:1 | -LL | Some(Bar { y: 0, x: 5, .. }) => 1, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Some(Bar { y: 0, x: 5, .. }) => 1, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL ~ Some(Bar { y: 10, z: 0, .. }) => 2, LL | None => 50, -LL ~ Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, +LL ~ Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:262:9 + --> tests/ui/match_same_arms2.rs:274:9 | LL | 1 => cfg!(not_enable), | ^^^^^^^^^^^^^^^^^^^^^ @@ -195,7 +198,7 @@ LL + 1 | 0 => cfg!(not_enable), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:278:17 + --> tests/ui/match_same_arms2.rs:291:17 | LL | MaybeStaticStr::Borrowed(s) => s, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms_non_exhaustive.fixed b/tests/ui/match_same_arms_non_exhaustive.fixed index 804c0a869a9f..71041cff8d0a 100644 --- a/tests/ui/match_same_arms_non_exhaustive.fixed +++ b/tests/ui/match_same_arms_non_exhaustive.fixed @@ -41,7 +41,8 @@ pub fn g(x: Ordering) { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - //~^ ERROR: this match arm has an identical body to the `_` wildcard arm + //~^ match_same_arms + _ => repeat(), } } @@ -54,7 +55,8 @@ mod g { Ordering::Relaxed => println!("relaxed"), Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), - //~^ ERROR: this match arm has an identical body to the `_` wildcard arm + //~^ match_same_arms + _ => repeat(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index e50663932a1a..45dc5d78883b 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -42,7 +42,8 @@ pub fn g(x: Ordering) { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => repeat(), - //~^ ERROR: this match arm has an identical body to the `_` wildcard arm + //~^ match_same_arms + _ => repeat(), } } @@ -56,7 +57,8 @@ mod g { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => repeat(), - //~^ ERROR: this match arm has an identical body to the `_` wildcard arm + //~^ match_same_arms + _ => repeat(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index aa7f8c95dce8..1033203c7237 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -7,7 +7,7 @@ LL | | | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms_non_exhaustive.rs:46:9 + --> tests/ui/match_same_arms_non_exhaustive.rs:47:9 | LL | _ => repeat(), | ^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | _ => repeat(), = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to the `_` wildcard arm - --> tests/ui/match_same_arms_non_exhaustive.rs:58:13 + --> tests/ui/match_same_arms_non_exhaustive.rs:59:13 | LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), LL | | @@ -23,7 +23,7 @@ LL | | | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms_non_exhaustive.rs:60:13 + --> tests/ui/match_same_arms_non_exhaustive.rs:62:13 | LL | _ => repeat(), | ^^^^^^^^^^^^^ diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs index ff2f842ac39e..27fd7d601abf 100644 --- a/tests/ui/match_single_binding.rs +++ b/tests/ui/match_single_binding.rs @@ -31,12 +31,14 @@ fn main() { let c = 3; // Lint match (a, b, c) { + //~^ match_single_binding (x, y, z) => { println!("{} {} {}", x, y, z); }, } // Lint match (a, b, c) { + //~^ match_single_binding (x, y, z) => println!("{} {} {}", x, y, z), } // Ok @@ -54,10 +56,12 @@ fn main() { } // Lint match a { + //~^ match_single_binding _ => println!("whatever"), } // Lint match a { + //~^ match_single_binding _ => { let x = 29; println!("x has a value of {}", x); @@ -65,6 +69,7 @@ fn main() { } // Lint match a { + //~^ match_single_binding _ => { let e = 5 * a; if e >= 5 { @@ -75,24 +80,29 @@ fn main() { // Lint let p = Point { x: 0, y: 7 }; match p { + //~^ match_single_binding Point { x, y } => println!("Coords: ({}, {})", x, y), } // Lint match p { + //~^ match_single_binding Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), } // Lint let x = 5; match x { + //~^ match_single_binding ref r => println!("Got a reference to {}", r), } // Lint let mut x = 5; match x { + //~^ match_single_binding ref mut mr => println!("Got a mutable reference to {}", mr), } // Lint let product = match coords() { + //~^ match_single_binding Point { x, y } => x * y, }; // Lint @@ -101,6 +111,7 @@ fn main() { let _ = v .iter() .map(|i| match i.unwrap() { + //~^ match_single_binding unwrapped => unwrapped, }) .collect::>(); @@ -127,6 +138,7 @@ fn main() { // Lint let x = 1; match x { + //~^ match_single_binding // => _ => println!("Not an array index start"), } @@ -136,6 +148,7 @@ fn issue_8723() { let (mut val, idx) = ("a b", 1); val = match val.split_at(idx) { + //~^ match_single_binding (pre, suf) => { println!("{}", pre); suf @@ -149,12 +162,14 @@ fn side_effects() {} fn issue_9575() { let _ = || match side_effects() { + //~^ match_single_binding _ => println!("Needs curlies"), }; } fn issue_9725(r: Option) { match r { + //~^ match_single_binding x => match x { Some(_) => { println!("Some"); @@ -168,37 +183,46 @@ fn issue_9725(r: Option) { fn issue_10447() -> usize { match 1 { + //~^ match_single_binding _ => (), } let a = match 1 { + //~^ match_single_binding _ => (), }; match 1 { + //~^ match_single_binding _ => side_effects(), } let b = match 1 { + //~^ match_single_binding _ => side_effects(), }; match 1 { + //~^ match_single_binding _ => println!("1"), } let c = match 1 { + //~^ match_single_binding _ => println!("1"), }; let in_expr = [ match 1 { + //~^ match_single_binding _ => (), }, match 1 { + //~^ match_single_binding _ => side_effects(), }, match 1 { + //~^ match_single_binding _ => println!("1"), }, ]; diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 19ab85180ad2..7e1ec32dac2f 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -2,6 +2,7 @@ error: this match could be written as a `let` statement --> tests/ui/match_single_binding.rs:33:5 | LL | / match (a, b, c) { +LL | | LL | | (x, y, z) => { LL | | println!("{} {} {}", x, y, z); LL | | }, @@ -19,9 +20,10 @@ LL + } | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:39:5 + --> tests/ui/match_single_binding.rs:40:5 | LL | / match (a, b, c) { +LL | | LL | | (x, y, z) => println!("{} {} {}", x, y, z), LL | | } | |_____^ @@ -33,17 +35,19 @@ LL + println!("{} {} {}", x, y, z); | error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:56:5 + --> tests/ui/match_single_binding.rs:58:5 | LL | / match a { +LL | | LL | | _ => println!("whatever"), LL | | } | |_____^ help: consider using the match body instead: `println!("whatever");` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:60:5 + --> tests/ui/match_single_binding.rs:63:5 | LL | / match a { +LL | | LL | | _ => { LL | | let x = 29; LL | | println!("x has a value of {}", x); @@ -60,12 +64,12 @@ LL + } | error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:67:5 + --> tests/ui/match_single_binding.rs:71:5 | LL | / match a { +LL | | LL | | _ => { LL | | let e = 5 * a; -LL | | if e >= 5 { ... | LL | | }, LL | | } @@ -82,9 +86,10 @@ LL + } | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:77:5 + --> tests/ui/match_single_binding.rs:82:5 | LL | / match p { +LL | | LL | | Point { x, y } => println!("Coords: ({}, {})", x, y), LL | | } | |_____^ @@ -96,9 +101,10 @@ LL + println!("Coords: ({}, {})", x, y); | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:81:5 + --> tests/ui/match_single_binding.rs:87:5 | LL | / match p { +LL | | LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), LL | | } | |_____^ @@ -110,9 +116,10 @@ LL + println!("Coords: ({}, {})", x1, y1); | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:86:5 + --> tests/ui/match_single_binding.rs:93:5 | LL | / match x { +LL | | LL | | ref r => println!("Got a reference to {}", r), LL | | } | |_____^ @@ -124,9 +131,10 @@ LL + println!("Got a reference to {}", r); | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:91:5 + --> tests/ui/match_single_binding.rs:99:5 | LL | / match x { +LL | | LL | | ref mut mr => println!("Got a mutable reference to {}", mr), LL | | } | |_____^ @@ -138,9 +146,10 @@ LL + println!("Got a mutable reference to {}", mr); | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:95:5 + --> tests/ui/match_single_binding.rs:104:5 | LL | / let product = match coords() { +LL | | LL | | Point { x, y } => x * y, LL | | }; | |______^ @@ -152,10 +161,11 @@ LL + let product = x * y; | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:103:18 + --> tests/ui/match_single_binding.rs:113:18 | LL | .map(|i| match i.unwrap() { | __________________^ +LL | | LL | | unwrapped => unwrapped, LL | | }) | |_________^ @@ -169,18 +179,20 @@ LL ~ }) | error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:129:5 + --> tests/ui/match_single_binding.rs:140:5 | LL | / match x { +LL | | LL | | // => LL | | _ => println!("Not an array index start"), LL | | } | |_____^ help: consider using the match body instead: `println!("Not an array index start")` error: this assignment could be simplified - --> tests/ui/match_single_binding.rs:138:5 + --> tests/ui/match_single_binding.rs:150:5 | LL | / val = match val.split_at(idx) { +LL | | LL | | (pre, suf) => { LL | | println!("{}", pre); LL | | suf @@ -198,10 +210,11 @@ LL ~ }; | error: this match could be replaced by its scrutinee and body - --> tests/ui/match_single_binding.rs:151:16 + --> tests/ui/match_single_binding.rs:164:16 | LL | let _ = || match side_effects() { | ________________^ +LL | | LL | | _ => println!("Needs curlies"), LL | | }; | |_____^ @@ -215,12 +228,12 @@ LL ~ }; | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding.rs:157:5 + --> tests/ui/match_single_binding.rs:171:5 | LL | / match r { +LL | | LL | | x => match x { LL | | Some(_) => { -LL | | println!("Some"); ... | LL | | }, LL | | }; @@ -240,76 +253,85 @@ LL ~ }; | error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:170:5 + --> tests/ui/match_single_binding.rs:185:5 | LL | / match 1 { +LL | | LL | | _ => (), LL | | } | |_____^ help: consider using the match body instead: `();` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:174:13 + --> tests/ui/match_single_binding.rs:190:13 | LL | let a = match 1 { | _____________^ +LL | | LL | | _ => (), LL | | }; | |_____^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:178:5 + --> tests/ui/match_single_binding.rs:195:5 | LL | / match 1 { +LL | | LL | | _ => side_effects(), LL | | } | |_____^ help: consider using the match body instead: `side_effects();` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:182:13 + --> tests/ui/match_single_binding.rs:200:13 | LL | let b = match 1 { | _____________^ +LL | | LL | | _ => side_effects(), LL | | }; | |_____^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:186:5 + --> tests/ui/match_single_binding.rs:205:5 | LL | / match 1 { +LL | | LL | | _ => println!("1"), LL | | } | |_____^ help: consider using the match body instead: `println!("1");` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:190:13 + --> tests/ui/match_single_binding.rs:210:13 | LL | let c = match 1 { | _____________^ +LL | | LL | | _ => println!("1"), LL | | }; | |_____^ help: consider using the match body instead: `println!("1")` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:195:9 + --> tests/ui/match_single_binding.rs:216:9 | LL | / match 1 { +LL | | LL | | _ => (), LL | | }, | |_________^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:198:9 + --> tests/ui/match_single_binding.rs:220:9 | LL | / match 1 { +LL | | LL | | _ => side_effects(), LL | | }, | |_________^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> tests/ui/match_single_binding.rs:201:9 + --> tests/ui/match_single_binding.rs:224:9 | LL | / match 1 { +LL | | LL | | _ => println!("1"), LL | | }, | |_________^ help: consider using the match body instead: `println!("1")` diff --git a/tests/ui/match_single_binding2.fixed b/tests/ui/match_single_binding2.fixed index 5673aa78c76a..1d34f179ea4a 100644 --- a/tests/ui/match_single_binding2.fixed +++ b/tests/ui/match_single_binding2.fixed @@ -45,6 +45,7 @@ fn main() { // issue #7094 let x = 1; match x { + //~^ match_single_binding 0 => 1, _ => 2, }; diff --git a/tests/ui/match_single_binding2.rs b/tests/ui/match_single_binding2.rs index 575e7f5816b8..8c18d7c133c1 100644 --- a/tests/ui/match_single_binding2.rs +++ b/tests/ui/match_single_binding2.rs @@ -15,6 +15,7 @@ fn main() { fn size_hint(iter: &AppendIter) -> (usize, Option) { match &iter.inner { Some((iter, _item)) => match iter.size_hint() { + //~^ match_single_binding (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), }, None => (0, Some(0)), @@ -28,6 +29,7 @@ fn main() { #[rustfmt::skip] Some((first, _second)) => { match get_tup() { + //~^ match_single_binding (a, b) => println!("a {:?} and b {:?}", a, b), } }, @@ -39,6 +41,7 @@ fn main() { // Lint (scrutinee has side effects) // issue #7094 match side_effects() { + //~^ match_single_binding _ => println!("Side effects"), } @@ -46,6 +49,7 @@ fn main() { // issue #7094 let x = 1; match match x { + //~^ match_single_binding 0 => 1, _ => 2, } { diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr index 38659596af1f..a24cbe3eed76 100644 --- a/tests/ui/match_single_binding2.stderr +++ b/tests/ui/match_single_binding2.stderr @@ -3,6 +3,7 @@ error: this match could be written as a `let` statement | LL | Some((iter, _item)) => match iter.size_hint() { | ____________________________________^ +LL | | LL | | (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), LL | | }, | |_____________^ @@ -18,9 +19,10 @@ LL ~ }, | error: this match could be written as a `let` statement - --> tests/ui/match_single_binding2.rs:30:13 + --> tests/ui/match_single_binding2.rs:31:13 | LL | / match get_tup() { +LL | | LL | | (a, b) => println!("a {:?} and b {:?}", a, b), LL | | } | |_____________^ @@ -32,9 +34,10 @@ LL + println!("a {:?} and b {:?}", a, b) | error: this match could be replaced by its scrutinee and body - --> tests/ui/match_single_binding2.rs:41:5 + --> tests/ui/match_single_binding2.rs:43:5 | LL | / match side_effects() { +LL | | LL | | _ => println!("Side effects"), LL | | } | |_____^ @@ -46,9 +49,10 @@ LL + println!("Side effects"); | error: this match could be replaced by its scrutinee and body - --> tests/ui/match_single_binding2.rs:48:5 + --> tests/ui/match_single_binding2.rs:51:5 | LL | / match match x { +LL | | LL | | 0 => 1, LL | | _ => 2, LL | | } { @@ -59,6 +63,7 @@ LL | | } help: consider using the scrutinee and body instead | LL ~ match x { +LL + LL + 0 => 1, LL + _ => 2, LL + }; diff --git a/tests/ui/match_str_case_mismatch.fixed b/tests/ui/match_str_case_mismatch.fixed index a608ab0c0cb0..5f41f29f8a46 100644 --- a/tests/ui/match_str_case_mismatch.fixed +++ b/tests/ui/match_str_case_mismatch.fixed @@ -110,6 +110,7 @@ fn as_str_match_mismatch() { match var.to_ascii_lowercase().as_str() { "foo" => {}, "bar" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -120,6 +121,7 @@ fn non_alphabetic_mismatch() { match var.to_ascii_lowercase().as_str() { "1234567890" => {}, "~!@#$%^&*()-_=+foo" => {}, + //~^ match_str_case_mismatch "\n\r\t\x7F" => {}, _ => {}, } @@ -132,6 +134,7 @@ fn unicode_cased_mismatch() { "水" => {}, "νερό" => {}, "воды" => {}, + //~^ match_str_case_mismatch "물" => {}, _ => {}, } @@ -143,6 +146,7 @@ fn titlecase_mismatch() { match var.to_lowercase().as_str() { "foolj" => {}, "bardz" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -153,6 +157,7 @@ fn no_case_equivalent_mismatch() { match var.to_uppercase().as_str() { "FOOɕ" => {}, "BARʁ" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -163,6 +168,7 @@ fn addrof_unary_match_mismatch() { match &*var.to_ascii_lowercase() { "foo" => {}, "bar" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -178,6 +184,7 @@ fn alternating_chain_mismatch() { { "FOO" => {}, "BAR" => {}, + //~^ match_str_case_mismatch _ => {}, } } diff --git a/tests/ui/match_str_case_mismatch.rs b/tests/ui/match_str_case_mismatch.rs index 1e4269d1db5d..fa5d5a8ebc31 100644 --- a/tests/ui/match_str_case_mismatch.rs +++ b/tests/ui/match_str_case_mismatch.rs @@ -110,6 +110,7 @@ fn as_str_match_mismatch() { match var.to_ascii_lowercase().as_str() { "foo" => {}, "Bar" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -120,6 +121,7 @@ fn non_alphabetic_mismatch() { match var.to_ascii_lowercase().as_str() { "1234567890" => {}, "~!@#$%^&*()-_=+Foo" => {}, + //~^ match_str_case_mismatch "\n\r\t\x7F" => {}, _ => {}, } @@ -132,6 +134,7 @@ fn unicode_cased_mismatch() { "水" => {}, "νερό" => {}, "Воды" => {}, + //~^ match_str_case_mismatch "물" => {}, _ => {}, } @@ -143,6 +146,7 @@ fn titlecase_mismatch() { match var.to_lowercase().as_str() { "foolj" => {}, "barDz" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -153,6 +157,7 @@ fn no_case_equivalent_mismatch() { match var.to_uppercase().as_str() { "FOOɕ" => {}, "bARʁ" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -163,6 +168,7 @@ fn addrof_unary_match_mismatch() { match &*var.to_ascii_lowercase() { "foo" => {}, "Bar" => {}, + //~^ match_str_case_mismatch _ => {}, } } @@ -178,6 +184,7 @@ fn alternating_chain_mismatch() { { "FOO" => {}, "bAR" => {}, + //~^ match_str_case_mismatch _ => {}, } } diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index 67e9ccaf6d2f..ea461eb510ff 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -12,7 +12,7 @@ LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:122:9 + --> tests/ui/match_str_case_mismatch.rs:123:9 | LL | "~!@#$%^&*()-_=+Foo" => {}, | ^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | "~!@#$%^&*()-_=+foo" => {}, | ~~~~~~~~~~~~~~~~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:134:9 + --> tests/ui/match_str_case_mismatch.rs:136:9 | LL | "Воды" => {}, | ^^^^^^ @@ -34,7 +34,7 @@ LL | "воды" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:145:9 + --> tests/ui/match_str_case_mismatch.rs:148:9 | LL | "barDz" => {}, | ^^^^^^ @@ -45,7 +45,7 @@ LL | "bardz" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:155:9 + --> tests/ui/match_str_case_mismatch.rs:159:9 | LL | "bARʁ" => {}, | ^^^^^^ @@ -56,7 +56,7 @@ LL | "BARʁ" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:165:9 + --> tests/ui/match_str_case_mismatch.rs:170:9 | LL | "Bar" => {}, | ^^^^^ @@ -67,7 +67,7 @@ LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> tests/ui/match_str_case_mismatch.rs:180:9 + --> tests/ui/match_str_case_mismatch.rs:186:9 | LL | "bAR" => {}, | ^^^^^ diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs index 8e670ce5bda2..f7f7c398d647 100644 --- a/tests/ui/match_wild_err_arm.rs +++ b/tests/ui/match_wild_err_arm.rs @@ -21,24 +21,27 @@ 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_wild_err_arm + + } 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_wild_err_arm + + } 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 + //~^ match_wild_err_arm + + panic!(); }, } @@ -47,8 +50,9 @@ 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 + //~^ match_wild_err_arm + + } // Allowed when used in `panic!`. diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index f98065d9a591..ec0ca602f5f9 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -9,7 +9,7 @@ LL | Err(_) => panic!("err"), = help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]` error: `Err(_)` matches all errors - --> tests/ui/match_wild_err_arm.rs:31:9 + --> tests/ui/match_wild_err_arm.rs:32:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -17,7 +17,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 - --> tests/ui/match_wild_err_arm.rs:39:9 + --> tests/ui/match_wild_err_arm.rs:41:9 | LL | Err(_) => { | ^^^^^^ @@ -25,7 +25,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 - --> tests/ui/match_wild_err_arm.rs:49:9 + --> tests/ui/match_wild_err_arm.rs:52:9 | LL | Err(_e) => panic!(), | ^^^^^^^ diff --git a/tests/ui/match_wildcard_for_single_variants.fixed b/tests/ui/match_wildcard_for_single_variants.fixed index e5ea2fdde82f..c34f49df6549 100644 --- a/tests/ui/match_wildcard_for_single_variants.fixed +++ b/tests/ui/match_wildcard_for_single_variants.fixed @@ -20,6 +20,7 @@ impl Color { Self::Green => (), Self::Blue => (), Self::Rgb(..) => (), + //~^ match_wildcard_for_single_variants }; } } @@ -30,6 +31,7 @@ fn main() { Foo::A => {}, Foo::B => {}, Foo::C => {}, + //~^ match_wildcard_for_single_variants } let color = Color::Red; @@ -40,6 +42,7 @@ fn main() { Color::Green => {}, Color::Rgb(_r, _g, _b) => {}, Color::Blue => {}, + //~^ match_wildcard_for_single_variants } // check exhaustive wild @@ -48,12 +51,14 @@ fn main() { Color::Green => {}, Color::Rgb(..) => {}, Color::Blue => {}, + //~^ match_wildcard_for_single_variants } match color { Color::Red => {}, Color::Green => {}, Color::Rgb(_, _, _) => {}, Color::Blue => {}, + //~^ match_wildcard_for_single_variants } // shouldn't lint as there is one missing variant @@ -71,6 +76,7 @@ fn main() { Color::Green => (), &Color::Rgb(..) => (), Color::Blue => (), + //~^ match_wildcard_for_single_variants } use self::Color as C; @@ -80,6 +86,7 @@ fn main() { C::Green => (), C::Rgb(..) => (), C::Blue => (), + //~^ match_wildcard_for_single_variants } match color { @@ -87,6 +94,7 @@ fn main() { Color::Green => (), Color::Rgb(..) => (), Color::Blue => (), + //~^ match_wildcard_for_single_variants } match Some(0) { @@ -122,6 +130,7 @@ fn main() { Enum::B => (), Enum::C => (), Enum::__Private => (), + //~^ match_wildcard_for_single_variants } match Enum::A { Enum::A => (), @@ -149,6 +158,7 @@ mod issue9993 { _ if false => 0, Foo::A(_) => 1, Foo::B => 2, + //~^ match_wildcard_for_single_variants }; } } diff --git a/tests/ui/match_wildcard_for_single_variants.rs b/tests/ui/match_wildcard_for_single_variants.rs index dbd7fbe160f0..ecdb7d2fa3af 100644 --- a/tests/ui/match_wildcard_for_single_variants.rs +++ b/tests/ui/match_wildcard_for_single_variants.rs @@ -20,6 +20,7 @@ impl Color { Self::Green => (), Self::Blue => (), _ => (), + //~^ match_wildcard_for_single_variants }; } } @@ -30,6 +31,7 @@ fn main() { Foo::A => {}, Foo::B => {}, _ => {}, + //~^ match_wildcard_for_single_variants } let color = Color::Red; @@ -40,6 +42,7 @@ fn main() { Color::Green => {}, Color::Rgb(_r, _g, _b) => {}, _ => {}, + //~^ match_wildcard_for_single_variants } // check exhaustive wild @@ -48,12 +51,14 @@ fn main() { Color::Green => {}, Color::Rgb(..) => {}, _ => {}, + //~^ match_wildcard_for_single_variants } match color { Color::Red => {}, Color::Green => {}, Color::Rgb(_, _, _) => {}, _ => {}, + //~^ match_wildcard_for_single_variants } // shouldn't lint as there is one missing variant @@ -71,6 +76,7 @@ fn main() { Color::Green => (), &Color::Rgb(..) => (), &_ => (), + //~^ match_wildcard_for_single_variants } use self::Color as C; @@ -80,6 +86,7 @@ fn main() { C::Green => (), C::Rgb(..) => (), _ => (), + //~^ match_wildcard_for_single_variants } match color { @@ -87,6 +94,7 @@ fn main() { Color::Green => (), Color::Rgb(..) => (), _ => (), + //~^ match_wildcard_for_single_variants } match Some(0) { @@ -122,6 +130,7 @@ fn main() { Enum::B => (), Enum::C => (), _ => (), + //~^ match_wildcard_for_single_variants } match Enum::A { Enum::A => (), @@ -149,6 +158,7 @@ mod issue9993 { _ if false => 0, Foo::A(_) => 1, _ => 2, + //~^ match_wildcard_for_single_variants }; } } diff --git a/tests/ui/match_wildcard_for_single_variants.stderr b/tests/ui/match_wildcard_for_single_variants.stderr index 5cc50c823b2c..3c0cc53b1bf2 100644 --- a/tests/ui/match_wildcard_for_single_variants.stderr +++ b/tests/ui/match_wildcard_for_single_variants.stderr @@ -8,55 +8,55 @@ LL | _ => (), = help: to override `-D warnings` add `#[allow(clippy::match_wildcard_for_single_variants)]` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:32:9 + --> tests/ui/match_wildcard_for_single_variants.rs:33:9 | LL | _ => {}, | ^ help: try: `Foo::C` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:42:9 + --> tests/ui/match_wildcard_for_single_variants.rs:44:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:50:9 + --> tests/ui/match_wildcard_for_single_variants.rs:53:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:56:9 + --> tests/ui/match_wildcard_for_single_variants.rs:60:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:73:9 + --> tests/ui/match_wildcard_for_single_variants.rs:78:9 | LL | &_ => (), | ^^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:82:9 + --> tests/ui/match_wildcard_for_single_variants.rs:88:9 | LL | _ => (), | ^ help: try: `C::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:89:9 + --> tests/ui/match_wildcard_for_single_variants.rs:96:9 | LL | _ => (), | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:124:13 + --> tests/ui/match_wildcard_for_single_variants.rs:132:13 | LL | _ => (), | ^ help: try: `Enum::__Private` error: wildcard matches only a single variant and will also match any future added variants - --> tests/ui/match_wildcard_for_single_variants.rs:151:13 + --> tests/ui/match_wildcard_for_single_variants.rs:160:13 | LL | _ => 2, | ^ help: try: `Foo::B` diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index 1f508b3bca28..ad9bd079b98d 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -12,23 +12,27 @@ 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` + //~^ mem_forget + + 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` + //~^ mem_forget + + let eight: Vec = vec![8]; forgetSomething(eight); - //~^ ERROR: usage of `mem::forget` on `Drop` type - //~| NOTE: argument has type `std::vec::Vec` + //~^ mem_forget + + 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` + //~^ mem_forget + + std::mem::forget(7); } diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 3b0e839e0871..4dd1efc1a240 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -9,7 +9,7 @@ LL | memstuff::forget(six); = help: to override `-D warnings` add `#[allow(clippy::mem_forget)]` error: usage of `mem::forget` on `Drop` type - --> tests/ui/mem_forget.rs:19:5 + --> tests/ui/mem_forget.rs:20:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | std::mem::forget(seven); = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type - --> tests/ui/mem_forget.rs:24:5 + --> tests/ui/mem_forget.rs:26:5 | LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | forgetSomething(eight); = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields - --> tests/ui/mem_forget.rs:29:5 + --> tests/ui/mem_forget.rs:32:5 | LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 02b0d9c7045f..870ef23113a2 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -11,55 +11,76 @@ use std::mem; fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::take(&mut s); + //~^ mem_replace_with_default let _ = std::mem::take(&mut s); + //~^ mem_replace_with_default let s = &mut String::from("foo"); let _ = std::mem::take(s); + //~^ mem_replace_with_default let _ = std::mem::take(s); + //~^ mem_replace_with_default let _ = std::mem::take(s); + //~^ mem_replace_with_default let mut v = vec![123]; let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let _ = std::mem::take(&mut v); + //~^ mem_replace_with_default let mut hash_map: HashMap = HashMap::new(); let _ = std::mem::take(&mut hash_map); + //~^ mem_replace_with_default let mut btree_map: BTreeMap = BTreeMap::new(); let _ = std::mem::take(&mut btree_map); + //~^ mem_replace_with_default let mut vd: VecDeque = VecDeque::new(); let _ = std::mem::take(&mut vd); + //~^ mem_replace_with_default let mut hash_set: HashSet<&str> = HashSet::new(); let _ = std::mem::take(&mut hash_set); + //~^ mem_replace_with_default let mut btree_set: BTreeSet<&str> = BTreeSet::new(); let _ = std::mem::take(&mut btree_set); + //~^ mem_replace_with_default let mut list: LinkedList = LinkedList::new(); let _ = std::mem::take(&mut list); + //~^ mem_replace_with_default let mut binary_heap: BinaryHeap = BinaryHeap::new(); let _ = std::mem::take(&mut binary_heap); + //~^ mem_replace_with_default let mut tuple = (vec![1, 2], BinaryHeap::::new()); let _ = std::mem::take(&mut tuple); + //~^ mem_replace_with_default let mut refstr = "hello"; let _ = std::mem::take(&mut refstr); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = std::mem::take(&mut slice); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -96,6 +117,7 @@ fn msrv_1_39() { fn msrv_1_40() { let mut s = String::from("foo"); let _ = std::mem::take(&mut s); + //~^ mem_replace_with_default } fn issue9824() { @@ -126,10 +148,14 @@ fn issue9824() { // replace option with none let _ = f.0.take(); + //~^ mem_replace_option_with_none let _ = (*f).take(); + //~^ mem_replace_option_with_none let _ = b.opt.take(); + //~^ mem_replace_option_with_none // replace with default let _ = std::mem::take(&mut b.val); + //~^ mem_replace_with_default } #[clippy::msrv = "1.31"] diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 1bb72b5de239..b4ed5eafea95 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -11,55 +11,76 @@ use std::mem; fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = mem::replace(an_option, None); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut s = String::from("foo"); let _ = std::mem::replace(&mut s, String::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut s, String::new()); + //~^ mem_replace_with_default let s = &mut String::from("foo"); let _ = std::mem::replace(s, String::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(s, String::new()); + //~^ mem_replace_with_default let _ = std::mem::replace(s, Default::default()); + //~^ mem_replace_with_default let mut v = vec![123]; let _ = std::mem::replace(&mut v, Vec::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, Default::default()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, Vec::new()); + //~^ mem_replace_with_default let _ = std::mem::replace(&mut v, vec![]); + //~^ mem_replace_with_default let mut hash_map: HashMap = HashMap::new(); let _ = std::mem::replace(&mut hash_map, HashMap::new()); + //~^ mem_replace_with_default let mut btree_map: BTreeMap = BTreeMap::new(); let _ = std::mem::replace(&mut btree_map, BTreeMap::new()); + //~^ mem_replace_with_default let mut vd: VecDeque = VecDeque::new(); let _ = std::mem::replace(&mut vd, VecDeque::new()); + //~^ mem_replace_with_default let mut hash_set: HashSet<&str> = HashSet::new(); let _ = std::mem::replace(&mut hash_set, HashSet::new()); + //~^ mem_replace_with_default let mut btree_set: BTreeSet<&str> = BTreeSet::new(); let _ = std::mem::replace(&mut btree_set, BTreeSet::new()); + //~^ mem_replace_with_default let mut list: LinkedList = LinkedList::new(); let _ = std::mem::replace(&mut list, LinkedList::new()); + //~^ mem_replace_with_default let mut binary_heap: BinaryHeap = BinaryHeap::new(); let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); + //~^ mem_replace_with_default let mut tuple = (vec![1, 2], BinaryHeap::::new()); let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); + //~^ mem_replace_with_default let mut refstr = "hello"; let _ = std::mem::replace(&mut refstr, ""); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = std::mem::replace(&mut slice, &[]); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -96,6 +117,7 @@ fn msrv_1_39() { fn msrv_1_40() { let mut s = String::from("foo"); let _ = std::mem::replace(&mut s, String::default()); + //~^ mem_replace_with_default } fn issue9824() { @@ -126,10 +148,14 @@ fn issue9824() { // replace option with none let _ = std::mem::replace(&mut f.0, None); + //~^ mem_replace_option_with_none let _ = std::mem::replace(&mut *f, None); + //~^ mem_replace_option_with_none let _ = std::mem::replace(&mut b.opt, None); + //~^ mem_replace_option_with_none // replace with default let _ = std::mem::replace(&mut b.val, String::default()); + //~^ mem_replace_with_default } #[clippy::msrv = "1.31"] diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 42ab546a5d77..98417df8c84b 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:15:13 + --> tests/ui/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` - --> tests/ui/mem_replace.rs:20:13 + --> tests/ui/mem_replace.rs:22:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -23,139 +23,139 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:21:13 + --> tests/ui/mem_replace.rs:24:13 | LL | let _ = std::mem::replace(&mut s, String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:24:13 + --> tests/ui/mem_replace.rs:28: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` - --> tests/ui/mem_replace.rs:25:13 + --> tests/ui/mem_replace.rs:30:13 | LL | let _ = std::mem::replace(s, String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:26:13 + --> tests/ui/mem_replace.rs:32: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` - --> tests/ui/mem_replace.rs:29:13 + --> tests/ui/mem_replace.rs:36: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` - --> tests/ui/mem_replace.rs:30:13 + --> tests/ui/mem_replace.rs:38: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` - --> tests/ui/mem_replace.rs:31:13 + --> tests/ui/mem_replace.rs:40: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` - --> tests/ui/mem_replace.rs:32:13 + --> tests/ui/mem_replace.rs:42:13 | LL | let _ = std::mem::replace(&mut v, vec![]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:35:13 + --> tests/ui/mem_replace.rs:46: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` - --> tests/ui/mem_replace.rs:38:13 + --> tests/ui/mem_replace.rs:50: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` - --> tests/ui/mem_replace.rs:41:13 + --> tests/ui/mem_replace.rs:54: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` - --> tests/ui/mem_replace.rs:44:13 + --> tests/ui/mem_replace.rs:58: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` - --> tests/ui/mem_replace.rs:47:13 + --> tests/ui/mem_replace.rs:62: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` - --> tests/ui/mem_replace.rs:50:13 + --> tests/ui/mem_replace.rs:66: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` - --> tests/ui/mem_replace.rs:53:13 + --> tests/ui/mem_replace.rs:70: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` - --> tests/ui/mem_replace.rs:56:13 + --> tests/ui/mem_replace.rs:74:13 | LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:59:13 + --> tests/ui/mem_replace.rs:78: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` - --> tests/ui/mem_replace.rs:62:13 + --> tests/ui/mem_replace.rs:82: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` - --> tests/ui/mem_replace.rs:98:13 + --> tests/ui/mem_replace.rs:119:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:128:13 + --> tests/ui/mem_replace.rs:150:13 | LL | let _ = std::mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:129:13 + --> tests/ui/mem_replace.rs:152:13 | LL | let _ = std::mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:130:13 + --> tests/ui/mem_replace.rs:154: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` - --> tests/ui/mem_replace.rs:132:13 + --> tests/ui/mem_replace.rs:157: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/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs index c14ea2942f3e..9458dade3a9c 100644 --- a/tests/ui/mem_replace_macro.rs +++ b/tests/ui/mem_replace_macro.rs @@ -8,5 +8,6 @@ use proc_macros::{external, inline_macros}; fn main() { let s = &mut String::from("foo"); let _ = inline!(std::mem::replace($s, Default::default())); + //~^ mem_replace_with_default let _ = external!(std::mem::replace($s, Default::default())); } diff --git a/tests/ui/mem_replace_no_std.fixed b/tests/ui/mem_replace_no_std.fixed index 60f523c8ef1e..669450e59d8b 100644 --- a/tests/ui/mem_replace_no_std.fixed +++ b/tests/ui/mem_replace_no_std.fixed @@ -21,16 +21,20 @@ fn panic(info: &PanicInfo) -> ! { fn replace_option_with_none() { let mut an_option = Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = an_option.take(); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut refstr = "hello"; let _ = core::mem::take(&mut refstr); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = core::mem::take(&mut slice); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -74,8 +78,11 @@ fn issue9824() { // replace option with none let _ = f.0.take(); + //~^ mem_replace_option_with_none let _ = (*f).take(); + //~^ mem_replace_option_with_none let _ = b.opt.take(); + //~^ mem_replace_option_with_none // replace with default let _ = mem::replace(&mut b.val, u8::default()); } diff --git a/tests/ui/mem_replace_no_std.rs b/tests/ui/mem_replace_no_std.rs index d1cb9a5817ba..2cdf1df5196a 100644 --- a/tests/ui/mem_replace_no_std.rs +++ b/tests/ui/mem_replace_no_std.rs @@ -21,16 +21,20 @@ fn panic(info: &PanicInfo) -> ! { fn replace_option_with_none() { let mut an_option = Some(1); let _ = mem::replace(&mut an_option, None); + //~^ mem_replace_option_with_none let an_option = &mut Some(1); let _ = mem::replace(an_option, None); + //~^ mem_replace_option_with_none } fn replace_with_default() { let mut refstr = "hello"; let _ = mem::replace(&mut refstr, ""); + //~^ mem_replace_with_default let mut slice: &[i32] = &[1, 2, 3]; let _ = mem::replace(&mut slice, &[]); + //~^ mem_replace_with_default } // lint is disabled for primitives because in this case `take` @@ -74,8 +78,11 @@ fn issue9824() { // replace option with none let _ = mem::replace(&mut f.0, None); + //~^ mem_replace_option_with_none let _ = mem::replace(&mut *f, None); + //~^ mem_replace_option_with_none let _ = mem::replace(&mut b.opt, None); + //~^ mem_replace_option_with_none // replace with default let _ = mem::replace(&mut b.val, u8::default()); } diff --git a/tests/ui/mem_replace_no_std.stderr b/tests/ui/mem_replace_no_std.stderr index 6ba6d2162a74..926a8288fd31 100644 --- a/tests/ui/mem_replace_no_std.stderr +++ b/tests/ui/mem_replace_no_std.stderr @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:25:13 + --> tests/ui/mem_replace_no_std.rs:26: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 `core::mem::take` - --> tests/ui/mem_replace_no_std.rs:30:13 + --> tests/ui/mem_replace_no_std.rs:32:13 | LL | let _ = mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut refstr)` @@ -23,25 +23,25 @@ LL | let _ = mem::replace(&mut refstr, ""); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take` - --> tests/ui/mem_replace_no_std.rs:33:13 + --> tests/ui/mem_replace_no_std.rs:36:13 | LL | let _ = mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut slice)` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:76:13 + --> tests/ui/mem_replace_no_std.rs:80:13 | LL | let _ = mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:77:13 + --> tests/ui/mem_replace_no_std.rs:82:13 | LL | let _ = mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:78:13 + --> tests/ui/mem_replace_no_std.rs:84:13 | LL | let _ = mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index cb1f695c651c..a7e37b2e8d23 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -101,6 +101,7 @@ struct BadNew; impl BadNew { fn new() -> i32 { + //~^ new_ret_no_self 0 } } @@ -122,6 +123,7 @@ fn filter_next() { // Multi-line case. let _ = v.iter().filter(|&x| { + //~^ filter_next *x < 0 } ).next(); diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 2e2bd3d874f5..30e8d0794f71 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -2,6 +2,7 @@ error: methods called `new` usually return `Self` --> tests/ui/methods.rs:103:5 | LL | / fn new() -> i32 { +LL | | LL | | 0 LL | | } | |_____^ @@ -10,10 +11,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead - --> tests/ui/methods.rs:124:13 + --> tests/ui/methods.rs:125:13 | LL | let _ = v.iter().filter(|&x| { | _____________^ +LL | | LL | | *x < 0 LL | | } LL | | ).next(); diff --git a/tests/ui/methods_fixable.fixed b/tests/ui/methods_fixable.fixed index bb06b5a480ff..49730d811558 100644 --- a/tests/ui/methods_fixable.fixed +++ b/tests/ui/methods_fixable.fixed @@ -7,4 +7,5 @@ fn main() { // Single-line case. let _ = v.iter().find(|&x| *x < 0); + //~^ filter_next } diff --git a/tests/ui/methods_fixable.rs b/tests/ui/methods_fixable.rs index 11de924593ed..a499b63b6f5b 100644 --- a/tests/ui/methods_fixable.rs +++ b/tests/ui/methods_fixable.rs @@ -7,4 +7,5 @@ fn main() { // Single-line case. let _ = v.iter().filter(|&x| *x < 0).next(); + //~^ filter_next } diff --git a/tests/ui/methods_unfixable.rs b/tests/ui/methods_unfixable.rs index ee59983a7573..a9881080d6f4 100644 --- a/tests/ui/methods_unfixable.rs +++ b/tests/ui/methods_unfixable.rs @@ -7,5 +7,6 @@ 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 + //~^ filter_next + } diff --git a/tests/ui/min_ident_chars.rs b/tests/ui/min_ident_chars.rs index 1d89f26b6ee4..5eae52d5c25c 100644 --- a/tests/ui/min_ident_chars.rs +++ b/tests/ui/min_ident_chars.rs @@ -7,24 +7,35 @@ extern crate proc_macros; use proc_macros::{external, with_span}; struct A { +//~^ min_ident_chars a: u32, + //~^ min_ident_chars i: u32, A: u32, + //~^ min_ident_chars I: u32, + //~^ min_ident_chars } struct B(u32); +//~^ min_ident_chars struct O { +//~^ min_ident_chars o: u32, + //~^ min_ident_chars } struct i; enum C { +//~^ min_ident_chars D, + //~^ min_ident_chars E, + //~^ min_ident_chars F, + //~^ min_ident_chars j, } @@ -39,8 +50,11 @@ struct AA(T, E); trait Trait { const A: u32 = 0; + //~^ min_ident_chars type A; + //~^ min_ident_chars fn a() {} + //~^ min_ident_chars } fn main() { @@ -55,22 +69,37 @@ fn main() { let z = 1; // Implicitly disallowed idents let h = 1; + //~^ min_ident_chars let e = 2; + //~^ min_ident_chars let l = 3; + //~^ min_ident_chars let l = 4; + //~^ min_ident_chars let o = 6; + //~^ min_ident_chars // 2 len does not lint let hi = 0; // Lint let (h, o, w) = (1, 2, 3); + //~^ min_ident_chars + //~| min_ident_chars for (a, (r, e)) in (0..1000).enumerate().enumerate() {} + //~^ min_ident_chars + //~| min_ident_chars + //~| min_ident_chars let you = Vec4 { x: 1, y: 2, z: 3, w: 4 }; while let (d, o, _i, n, g) = (true, true, false, false, true) {} + //~^ min_ident_chars + //~| min_ident_chars + //~| min_ident_chars let today = true; // Ideally this wouldn't lint, but this would (likely) require global analysis, outta scope // of this lint regardless let o = 1; + //~^ min_ident_chars let o = O { o }; + //~^ min_ident_chars for j in 0..1000 {} for _ in 0..10 {} @@ -85,7 +114,10 @@ fn main() { } fn b() {} +//~^ min_ident_chars fn wrong_pythagoras(a: f32, b: f32) -> f32 { +//~^ min_ident_chars +//~| min_ident_chars a * a + a * b } diff --git a/tests/ui/min_ident_chars.stderr b/tests/ui/min_ident_chars.stderr index 3dd5c9561fd0..bd6c45cf648e 100644 --- a/tests/ui/min_ident_chars.stderr +++ b/tests/ui/min_ident_chars.stderr @@ -8,187 +8,187 @@ LL | struct A { = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:10:5 + --> tests/ui/min_ident_chars.rs:11:5 | LL | a: u32, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:12:5 + --> tests/ui/min_ident_chars.rs:14:5 | LL | A: u32, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:13:5 + --> tests/ui/min_ident_chars.rs:16:5 | LL | I: u32, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:16:8 + --> tests/ui/min_ident_chars.rs:20:8 | LL | struct B(u32); | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:18:8 + --> tests/ui/min_ident_chars.rs:23:8 | LL | struct O { | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:19:5 + --> tests/ui/min_ident_chars.rs:25:5 | LL | o: u32, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:24:6 + --> tests/ui/min_ident_chars.rs:31:6 | LL | enum C { | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:25:5 + --> tests/ui/min_ident_chars.rs:33:5 | LL | D, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:26:5 + --> tests/ui/min_ident_chars.rs:35:5 | LL | E, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:27:5 + --> tests/ui/min_ident_chars.rs:37:5 | LL | F, | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:41:11 + --> tests/ui/min_ident_chars.rs:52:11 | LL | const A: u32 = 0; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:42:10 + --> tests/ui/min_ident_chars.rs:54:10 | LL | type A; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:43:8 + --> tests/ui/min_ident_chars.rs:56:8 | LL | fn a() {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:57:9 + --> tests/ui/min_ident_chars.rs:71:9 | LL | let h = 1; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:58:9 + --> tests/ui/min_ident_chars.rs:73:9 | LL | let e = 2; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:59:9 + --> tests/ui/min_ident_chars.rs:75:9 | LL | let l = 3; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:60:9 + --> tests/ui/min_ident_chars.rs:77:9 | LL | let l = 4; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:61:9 + --> tests/ui/min_ident_chars.rs:79:9 | LL | let o = 6; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:65:10 + --> tests/ui/min_ident_chars.rs:84:10 | LL | let (h, o, w) = (1, 2, 3); | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:65:13 + --> tests/ui/min_ident_chars.rs:84:13 | LL | let (h, o, w) = (1, 2, 3); | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:66:10 + --> tests/ui/min_ident_chars.rs:87:10 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:66:14 + --> tests/ui/min_ident_chars.rs:87:14 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:66:17 + --> tests/ui/min_ident_chars.rs:87:17 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:68:16 + --> tests/ui/min_ident_chars.rs:92:16 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:68:19 + --> tests/ui/min_ident_chars.rs:92:19 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:68:29 + --> tests/ui/min_ident_chars.rs:92:29 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:72:9 + --> tests/ui/min_ident_chars.rs:99:9 | LL | let o = 1; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:73:9 + --> tests/ui/min_ident_chars.rs:101:9 | LL | let o = O { o }; | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:87:4 + --> tests/ui/min_ident_chars.rs:116:4 | LL | fn b() {} | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:88:21 + --> tests/ui/min_ident_chars.rs:118:21 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ error: this ident consists of a single char - --> tests/ui/min_ident_chars.rs:88:29 + --> tests/ui/min_ident_chars.rs:118:29 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index cf64f85f9bb5..1b1a6a0eb10b 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -20,17 +20,22 @@ 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 + + min(max(3, x), 1); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + max(min(x, 1), 3); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + max(3, min(x, 1)); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + my_max(3, my_min(x, 1)); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x @@ -41,32 +46,40 @@ fn main() { let s = "Hello"; min("Apple", max("Zoo", s)); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + max(min(s, "Apple"), "Zoo"); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + max("Apple", min(s, "Zoo")); // ok let f = 3f32; x.min(1).max(3); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + x.max(3).min(1); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + f.max(3f32).min(1f32); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + 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_max + min(x.max(1), 3); // ok s.max("Zoo").min("Apple"); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + s.min("Apple").max("Zoo"); - //~^ ERROR: this `min`/`max` combination leads to constant result + //~^ min_max + s.min("Zoo").max("Apple"); // ok diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index bb1a82e320d9..91b3d722b3c6 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -8,73 +8,73 @@ LL | min(1, max(3, x)); = help: to override `-D warnings` add `#[allow(clippy::min_max)]` error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:25:5 + --> tests/ui/min_max.rs:26:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:27:5 + --> tests/ui/min_max.rs:29:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:29:5 + --> tests/ui/min_max.rs:32:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:32:5 + --> tests/ui/min_max.rs:36:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:43:5 + --> tests/ui/min_max.rs:48:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:45:5 + --> tests/ui/min_max.rs:51:5 | LL | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:51:5 + --> tests/ui/min_max.rs:58:5 | LL | x.min(1).max(3); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:53:5 + --> tests/ui/min_max.rs:61:5 | LL | x.max(3).min(1); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:55:5 + --> tests/ui/min_max.rs:64:5 | LL | f.max(3f32).min(1f32); | ^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:62:5 + --> tests/ui/min_max.rs:72:5 | LL | max(x.min(1), 3); | ^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:66:5 + --> tests/ui/min_max.rs:77:5 | LL | s.max("Zoo").min("Apple"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:68:5 + --> tests/ui/min_max.rs:80: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 5fe3306d6fc8..4793eb9726d6 100644 --- a/tests/ui/min_rust_version_attr.rs +++ b/tests/ui/min_rust_version_attr.rs @@ -11,13 +11,15 @@ 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 + //~^ approx_constant + } #[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 + //~^ approx_constant + } #[clippy::msrv = "1.42"] @@ -28,7 +30,8 @@ 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 + //~^ approx_constant + } fn inner_attr_under() { @@ -39,7 +42,8 @@ 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 + //~^ approx_constant + } // https://github.com/rust-lang/rust-clippy/issues/6920 @@ -50,7 +54,8 @@ fn scoping() { // Should warn let log2_10 = 3.321928094887362; - //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found + //~^ approx_constant + mod a { #![clippy::msrv = "1.42.0"] @@ -58,7 +63,8 @@ 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 + //~^ approx_constant + } fn should_not_warn() { diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index 809b1cfe73bf..6d4a8d9bd86e 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 - --> tests/ui/min_rust_version_attr.rs:19:19 + --> tests/ui/min_rust_version_attr.rs:20: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 - --> tests/ui/min_rust_version_attr.rs:30:19 + --> tests/ui/min_rust_version_attr.rs:32: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 - --> tests/ui/min_rust_version_attr.rs:41:19 + --> tests/ui/min_rust_version_attr.rs:44: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 - --> tests/ui/min_rust_version_attr.rs:52:19 + --> tests/ui/min_rust_version_attr.rs:56: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 - --> tests/ui/min_rust_version_attr.rs:60:27 + --> tests/ui/min_rust_version_attr.rs:65:27 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mismatching_type_param_order.rs b/tests/ui/mismatching_type_param_order.rs index a4560f9e9a99..7e6044d0f5ff 100644 --- a/tests/ui/mismatching_type_param_order.rs +++ b/tests/ui/mismatching_type_param_order.rs @@ -9,12 +9,15 @@ 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, + //~^ mismatching_type_param_order + //~| mismatching_type_param_order + + // lint on the 2nd param impl Foo {} - //~^ ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, + //~^ mismatching_type_param_order + // should not lint impl Foo {} @@ -26,8 +29,10 @@ 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 + //~^ mismatching_type_param_order + //~| mismatching_type_param_order + + struct Bar { x: i32, @@ -44,9 +49,12 @@ 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 + //~^ mismatching_type_param_order + //~| mismatching_type_param_order + //~| mismatching_type_param_order + + + // also works for unions union FooUnion @@ -58,8 +66,10 @@ 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 + //~^ mismatching_type_param_order + //~| mismatching_type_param_order + + impl FooUnion where diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index 214d9d734d1b..817ab8c99796 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -17,7 +17,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 - --> tests/ui/mismatching_type_param_order.rs:16:23 + --> tests/ui/mismatching_type_param_order.rs:18:23 | LL | impl Foo {} | ^ @@ -25,7 +25,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 - --> tests/ui/mismatching_type_param_order.rs:28:44 + --> tests/ui/mismatching_type_param_order.rs:31:44 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -33,7 +33,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 - --> tests/ui/mismatching_type_param_order.rs:28:47 + --> tests/ui/mismatching_type_param_order.rs:31:47 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -41,7 +41,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 - --> tests/ui/mismatching_type_param_order.rs:46:27 + --> tests/ui/mismatching_type_param_order.rs:51:27 | LL | impl FooEnum {} | ^ @@ -49,7 +49,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 - --> tests/ui/mismatching_type_param_order.rs:46:30 + --> tests/ui/mismatching_type_param_order.rs:51:30 | LL | impl FooEnum {} | ^ @@ -57,7 +57,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 - --> tests/ui/mismatching_type_param_order.rs:46:33 + --> tests/ui/mismatching_type_param_order.rs:51:33 | LL | impl FooEnum {} | ^ @@ -65,7 +65,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 - --> tests/ui/mismatching_type_param_order.rs:60:31 + --> tests/ui/mismatching_type_param_order.rs:68:31 | LL | impl FooUnion where A: Copy {} | ^ @@ -73,7 +73,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 - --> tests/ui/mismatching_type_param_order.rs:60:34 + --> tests/ui/mismatching_type_param_order.rs:68:34 | LL | impl FooUnion where A: Copy {} | ^ diff --git a/tests/ui/misnamed_getters.fixed b/tests/ui/misnamed_getters.fixed index 70af604b2144..81af604e2e63 100644 --- a/tests/ui/misnamed_getters.fixed +++ b/tests/ui/misnamed_getters.fixed @@ -10,32 +10,38 @@ 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` + //~^ misnamed_getters + + &self.a } fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } fn b(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.b } fn b_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } fn c(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.c } fn c_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.c } } @@ -47,21 +53,25 @@ union B { impl B { unsafe fn a(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.a } unsafe fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } unsafe fn b(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.b } unsafe fn b_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } @@ -74,21 +84,25 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.a } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } unsafe fn b_unchecked(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.b } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } @@ -121,20 +135,24 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.a } fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } fn d(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.d } fn d_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.d } } diff --git a/tests/ui/misnamed_getters.rs b/tests/ui/misnamed_getters.rs index 23c3e7bc5cf7..cb83ae02ccf1 100644 --- a/tests/ui/misnamed_getters.rs +++ b/tests/ui/misnamed_getters.rs @@ -10,32 +10,38 @@ 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` + //~^ misnamed_getters + + &self.b } fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } fn b(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.a } fn b_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } fn c(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.b } fn c_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } } @@ -47,21 +53,25 @@ union B { impl B { unsafe fn a(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.b } unsafe fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } unsafe fn b(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.a } unsafe fn b_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } @@ -74,21 +84,25 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.b } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } unsafe fn b_unchecked(self) -> u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + self.a } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.a } @@ -121,20 +135,24 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.b } fn a_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } fn d(&self) -> &u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &self.b } fn d_mut(&mut self) -> &mut u8 { - //~^ ERROR: getter function appears to return the wrong field + //~^ misnamed_getters + &mut self.b } } diff --git a/tests/ui/misnamed_getters.stderr b/tests/ui/misnamed_getters.stderr index 056fa2be9215..e3ea40b7a94e 100644 --- a/tests/ui/misnamed_getters.stderr +++ b/tests/ui/misnamed_getters.stderr @@ -2,8 +2,7 @@ error: getter function appears to return the wrong field --> tests/ui/misnamed_getters.rs:12:5 | LL | / fn a(&self) -> &u8 { -LL | | -LL | | +... | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } @@ -13,170 +12,187 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::misnamed_getters)]` error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:17:5 + --> tests/ui/misnamed_getters.rs:18:5 | LL | / fn a_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:22:5 + --> tests/ui/misnamed_getters.rs:24:5 | LL | / fn b(self) -> u8 { LL | | +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:27:5 + --> tests/ui/misnamed_getters.rs:30:5 | LL | / fn b_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:32:5 + --> tests/ui/misnamed_getters.rs:36:5 | LL | / fn c(&self) -> &u8 { LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:37:5 + --> tests/ui/misnamed_getters.rs:42:5 | LL | / fn c_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:49:5 + --> tests/ui/misnamed_getters.rs:55:5 | LL | / unsafe fn a(&self) -> &u8 { LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:53:5 + --> tests/ui/misnamed_getters.rs:60:5 | LL | / unsafe fn a_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:58:5 + --> tests/ui/misnamed_getters.rs:66:5 | LL | / unsafe fn b(self) -> u8 { LL | | +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:63:5 + --> tests/ui/misnamed_getters.rs:72:5 | LL | / unsafe fn b_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:76:5 + --> tests/ui/misnamed_getters.rs:86:5 | LL | / unsafe fn a_unchecked(&self) -> &u8 { LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:80:5 + --> tests/ui/misnamed_getters.rs:91:5 | LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:85:5 + --> tests/ui/misnamed_getters.rs:97:5 | LL | / unsafe fn b_unchecked(self) -> u8 { LL | | +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:90:5 + --> tests/ui/misnamed_getters.rs:103:5 | LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:123:5 + --> tests/ui/misnamed_getters.rs:137:5 | LL | / fn a(&self) -> &u8 { LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:127:5 + --> tests/ui/misnamed_getters.rs:142:5 | LL | / fn a_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:132:5 + --> tests/ui/misnamed_getters.rs:148:5 | LL | / fn d(&self) -> &u8 { LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.d` LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:136:5 + --> tests/ui/misnamed_getters.rs:153:5 | LL | / fn d_mut(&mut self) -> &mut u8 { LL | | +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.d` LL | | } diff --git a/tests/ui/missing_asserts_for_indexing.fixed b/tests/ui/missing_asserts_for_indexing.fixed index ac44a6f3fdb2..ce23c45b5214 100644 --- a/tests/ui/missing_asserts_for_indexing.fixed +++ b/tests/ui/missing_asserts_for_indexing.fixed @@ -28,25 +28,29 @@ fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } // ok, don't lint for single array access @@ -64,7 +68,8 @@ fn subslice_ok(v: &[u8]) { fn subslice_bad(v: &[u8]) { assert!(v.len() > 3); let _ = v[0]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v[1..4]; } @@ -78,7 +83,8 @@ fn subslice_inclusive_ok(v: &[u8]) { fn subslice_inclusive_bad(v: &[u8]) { assert!(v.len() > 4); let _ = v[0]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v[1..=4]; } @@ -93,15 +99,18 @@ fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); assert!(v2.len() > 15); let _ = v1[0] + v1[12]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[5] + v2[15]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); assert!(v2.len() > 15); let _ = v1[0] + v1[12]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[5] + v2[15]; } @@ -125,11 +134,13 @@ fn issue11835(v1: &[u8], v2: &[u8], v3: &[u8], v4: &[u8]) { assert!(4 == v4.len()); let _ = v1[0] + v1[1] + v1[2]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[0] + v2[1] + v2[2]; let _ = v3[0] + v3[1] + v3[2]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v4[0] + v4[1] + v4[2]; } diff --git a/tests/ui/missing_asserts_for_indexing.rs b/tests/ui/missing_asserts_for_indexing.rs index f05d5fea57dc..2d129c6b7e2c 100644 --- a/tests/ui/missing_asserts_for_indexing.rs +++ b/tests/ui/missing_asserts_for_indexing.rs @@ -28,25 +28,29 @@ fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() < 5); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() <= 5); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 3); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() >= 4); v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } // ok, don't lint for single array access @@ -64,7 +68,8 @@ fn subslice_ok(v: &[u8]) { fn subslice_bad(v: &[u8]) { assert!(v.len() >= 3); let _ = v[0]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v[1..4]; } @@ -78,7 +83,8 @@ fn subslice_inclusive_ok(v: &[u8]) { fn subslice_inclusive_bad(v: &[u8]) { assert!(v.len() >= 4); let _ = v[0]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v[1..=4]; } @@ -93,15 +99,18 @@ fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() >= 12); assert!(v2.len() >= 15); let _ = v1[0] + v1[12]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[5] + v2[15]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() >= 12); assert!(v2.len() > 15); let _ = v1[0] + v1[12]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[5] + v2[15]; } @@ -125,11 +134,13 @@ fn issue11835(v1: &[u8], v2: &[u8], v3: &[u8], v4: &[u8]) { assert!(4 == v4.len()); let _ = v1[0] + v1[1] + v1[2]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v2[0] + v2[1] + v2[2]; let _ = v3[0] + v3[1] + v3[2]; - //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + //~^ missing_asserts_for_indexing + let _ = v4[0] + v4[1] + v4[2]; } diff --git a/tests/ui/missing_asserts_for_indexing.stderr b/tests/ui/missing_asserts_for_indexing.stderr index 2e63cd4a0e50..a1559d21150b 100644 --- a/tests/ui/missing_asserts_for_indexing.stderr +++ b/tests/ui/missing_asserts_for_indexing.stderr @@ -36,7 +36,7 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:36:5 + --> tests/ui/missing_asserts_for_indexing.rs:37:5 | LL | assert!(v.len() <= 5); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -44,34 +44,34 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:36:5 + --> tests/ui/missing_asserts_for_indexing.rs:37:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:36:12 + --> tests/ui/missing_asserts_for_indexing.rs:37:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:36:19 + --> tests/ui/missing_asserts_for_indexing.rs:37:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:36:26 + --> tests/ui/missing_asserts_for_indexing.rs:37:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:36:33 + --> tests/ui/missing_asserts_for_indexing.rs:37:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:42:5 + --> tests/ui/missing_asserts_for_indexing.rs:44:5 | LL | assert!(v.len() > 3); | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -79,34 +79,34 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:42:5 + --> tests/ui/missing_asserts_for_indexing.rs:44:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:42:12 + --> tests/ui/missing_asserts_for_indexing.rs:44:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:42:19 + --> tests/ui/missing_asserts_for_indexing.rs:44:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:42:26 + --> tests/ui/missing_asserts_for_indexing.rs:44:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:42:33 + --> tests/ui/missing_asserts_for_indexing.rs:44:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:48:5 + --> tests/ui/missing_asserts_for_indexing.rs:51:5 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -114,80 +114,80 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:48:5 + --> tests/ui/missing_asserts_for_indexing.rs:51:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:48:12 + --> tests/ui/missing_asserts_for_indexing.rs:51:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:48:19 + --> tests/ui/missing_asserts_for_indexing.rs:51:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:48:26 + --> tests/ui/missing_asserts_for_indexing.rs:51:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:48:33 + --> tests/ui/missing_asserts_for_indexing.rs:51:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:66:13 + --> tests/ui/missing_asserts_for_indexing.rs:70:13 | LL | assert!(v.len() >= 3); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)` LL | let _ = v[0]; | _____________^ -LL | | +... | LL | | let _ = v[1..4]; | |___________________^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:66:13 + --> tests/ui/missing_asserts_for_indexing.rs:70:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:68:13 + --> tests/ui/missing_asserts_for_indexing.rs:73:13 | LL | let _ = v[1..4]; | ^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:80:13 + --> tests/ui/missing_asserts_for_indexing.rs:85:13 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` LL | let _ = v[0]; | _____________^ -LL | | +... | LL | | let _ = v[1..=4]; | |____________________^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:80:13 + --> tests/ui/missing_asserts_for_indexing.rs:85:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:82:13 + --> tests/ui/missing_asserts_for_indexing.rs:88:13 | LL | let _ = v[1..=4]; | ^^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:95:13 + --> tests/ui/missing_asserts_for_indexing.rs:101:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` @@ -196,19 +196,19 @@ LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:95:13 + --> tests/ui/missing_asserts_for_indexing.rs:101:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:95:21 + --> tests/ui/missing_asserts_for_indexing.rs:101:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:97:13 + --> tests/ui/missing_asserts_for_indexing.rs:104:13 | LL | assert!(v2.len() >= 15); | ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)` @@ -217,19 +217,19 @@ LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:97:13 + --> tests/ui/missing_asserts_for_indexing.rs:104:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:97:21 + --> tests/ui/missing_asserts_for_indexing.rs:104:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:103:13 + --> tests/ui/missing_asserts_for_indexing.rs:111:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` @@ -238,19 +238,19 @@ LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:103:13 + --> tests/ui/missing_asserts_for_indexing.rs:111:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:103:21 + --> tests/ui/missing_asserts_for_indexing.rs:111:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:127:13 + --> tests/ui/missing_asserts_for_indexing.rs:136:13 | LL | assert!(v1.len() == 2); | ---------------------- help: provide the highest index that is indexed with: `assert!(v1.len() == 3)` @@ -259,24 +259,24 @@ LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:127:13 + --> tests/ui/missing_asserts_for_indexing.rs:136:13 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:127:21 + --> tests/ui/missing_asserts_for_indexing.rs:136:21 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:127:29 + --> tests/ui/missing_asserts_for_indexing.rs:136:29 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:131:13 + --> tests/ui/missing_asserts_for_indexing.rs:141:13 | LL | assert!(2 == v3.len()); | ---------------------- help: provide the highest index that is indexed with: `assert!(v3.len() == 3)` @@ -285,17 +285,17 @@ LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:131:13 + --> tests/ui/missing_asserts_for_indexing.rs:141:13 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:131:21 + --> tests/ui/missing_asserts_for_indexing.rs:141:21 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:131:29 + --> tests/ui/missing_asserts_for_indexing.rs:141:29 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.rs b/tests/ui/missing_asserts_for_indexing_unfixable.rs index de53079a4760..c2083a90a19a 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.rs +++ b/tests/ui/missing_asserts_for_indexing_unfixable.rs @@ -3,18 +3,21 @@ fn sum(v: &[u8]) -> u8 { v[0] + v[1] + v[2] + v[3] + v[4] - //~^ ERROR: indexing into a slice multiple times without an `assert` + //~^ missing_asserts_for_indexing + } fn subslice(v: &[u8]) { let _ = v[0]; - //~^ ERROR: indexing into a slice multiple times without an `assert` + //~^ missing_asserts_for_indexing + let _ = v[1..4]; } fn variables(v: &[u8]) -> u8 { let a = v[0]; - //~^ ERROR: indexing into a slice multiple times without an `assert` + //~^ missing_asserts_for_indexing + let b = v[1]; let c = v[2]; a + b + c @@ -22,13 +25,16 @@ fn variables(v: &[u8]) -> u8 { fn index_different_slices(v1: &[u8], v2: &[u8]) { let _ = v1[0] + v1[12]; + //~^ missing_asserts_for_indexing let _ = v2[5] + v2[15]; + //~^ missing_asserts_for_indexing } fn index_different_slices2(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); let _ = v1[0] + v1[12]; let _ = v2[5] + v2[15]; + //~^ missing_asserts_for_indexing } struct Foo<'a> { @@ -38,7 +44,8 @@ struct Foo<'a> { fn index_struct_field(f: &Foo<'_>) { let _ = f.v[0] + f.v[1]; - //~^ ERROR: indexing into a slice multiple times without an `assert` + //~^ missing_asserts_for_indexing + } fn index_struct_different_fields(f: &Foo<'_>) { @@ -52,7 +59,8 @@ fn shadowing() { let x: &[i32] = &[1]; let _ = x[0] + x[1]; - //~^ ERROR: indexing into a slice multiple times without an `assert` + //~^ missing_asserts_for_indexing + } pub fn issue11856(values: &[i32]) -> usize { diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.stderr b/tests/ui/missing_asserts_for_indexing_unfixable.stderr index b575e09966ce..f6557fb2e50f 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.stderr +++ b/tests/ui/missing_asserts_for_indexing_unfixable.stderr @@ -35,145 +35,146 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:10:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:11:13 | LL | let _ = v[0]; | _____________^ -LL | | +... | LL | | let _ = v[1..4]; | |___________________^ | = help: consider asserting the length before indexing: `assert!(v.len() > 3);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:10:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:11:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:12:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:14:13 | LL | let _ = v[1..4]; | ^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:16:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:18:13 | LL | let a = v[0]; | _____________^ LL | | +LL | | LL | | let b = v[1]; LL | | let c = v[2]; | |________________^ | = help: consider asserting the length before indexing: `assert!(v.len() > 2);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:16:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:18:13 | LL | let a = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:18:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:21:13 | LL | let b = v[1]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:19:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:22:13 | LL | let c = v[2]; | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:24:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v1.len() > 12);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:24:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:24:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:25:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:25:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:25:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:31:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:31:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:31:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:40:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:13 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(f.v.len() > 1);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:40:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:13 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:40:22 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:22 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:54:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:13 | LL | let _ = x[0] + x[1]; | ^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(x.len() > 1);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:54:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:13 | LL | let _ = x[0] + x[1]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:54:20 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:20 | LL | let _ = x[0] + x[1]; | ^^^^ 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 cdfdcd5007a8..aef5eb5b890a 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -1,3 +1,4 @@ +//@ check-pass //! False-positive tests to ensure we don't suggest `const` for things where it would cause a //! compilation error. //! The .stderr output of this test should be empty. Otherwise it's a bug somewhere. diff --git a/tests/ui/missing_const_for_fn/could_be_const.fixed b/tests/ui/missing_const_for_fn/could_be_const.fixed index 689060468c57..592302c34ae6 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.fixed +++ b/tests/ui/missing_const_for_fn/could_be_const.fixed @@ -11,45 +11,44 @@ struct Game { impl Game { // Could be const pub const fn new() -> Self { - //~^ ERROR: this could be a `const fn` - //~| NOTE: `-D clippy::missing-const-for-fn` implied by `-D warnings` + //~^ missing_const_for_fn Self { guess: 42 } } const fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn b } } // Could be const const fn one() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 1 } // Could also be const const fn two() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn let abc = 2; abc } // Could be const (since Rust 1.39) const fn string() -> String { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn String::new() } // Could be const const unsafe fn four() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 4 } // Could also be const const fn generic(t: T) -> T { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn t } @@ -58,7 +57,7 @@ fn sub(x: u32) -> usize { } const fn generic_arr(t: [T; 1]) -> T { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn t[0] } @@ -72,7 +71,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub const fn b(self, a: &A) -> B { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn B } } @@ -82,7 +81,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. const fn const_fn_stabilized_before_msrv(byte: u8) { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn byte.is_ascii_digit(); } } @@ -94,7 +93,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] const fn msrv_1_46() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 46 } @@ -114,7 +113,7 @@ impl const Drop for D { // Lint this, since it can be dropped in const contexts // FIXME(const_trait_impl) const fn d(this: D) {} -//~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn mod msrv { struct Foo(*const u8, &'static u8); @@ -122,12 +121,12 @@ mod msrv { impl Foo { #[clippy::msrv = "1.58"] const fn deref_ptr_can_be_const(self) -> usize { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn unsafe { *self.0 as usize } } const fn deref_copied_val(self) -> usize { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn *self.1 as usize } } @@ -138,7 +137,7 @@ mod msrv { #[clippy::msrv = "1.56"] const fn union_access_can_be_const() { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn let bar = Bar { val: 1 }; let _ = unsafe { bar.val }; } @@ -146,12 +145,12 @@ mod msrv { #[clippy::msrv = "1.62"] mod with_extern { const extern "C" fn c() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn #[rustfmt::skip] #[allow(missing_abi)] const extern fn implicit_c() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn // any item functions in extern block won't trigger this lint extern "C" { @@ -168,11 +167,13 @@ mod issue12677 { impl Wrapper { #[must_use] pub const fn new(strings: Vec) -> Self { + //~^ missing_const_for_fn Self { strings } } #[must_use] pub const fn empty() -> Self { + //~^ missing_const_for_fn Self { strings: Vec::new() } } } @@ -184,6 +185,7 @@ mod issue12677 { impl Other { pub const fn new(text: String) -> Self { + //~^ missing_const_for_fn let vec = Vec::new(); Self { text, vec } } @@ -203,18 +205,19 @@ mod with_ty_alias { // is. Because the associate ty could have no default, therefore would cause ICE, as demonstrated // in this test. const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {} + //~^ missing_const_for_fn } mod extern_fn { const extern "C-unwind" fn c_unwind() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn const extern "system" fn system() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn const extern "system-unwind" fn system_unwind() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn } const fn mut_add(x: &mut i32) { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn *x += 1; } 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 492c47d7e49b..f689f9bb7f92 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -11,45 +11,44 @@ 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` + //~^ missing_const_for_fn 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` + //~^ missing_const_for_fn b } } // Could be const fn one() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 1 } // Could also be const fn two() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn let abc = 2; abc } // Could be const (since Rust 1.39) fn string() -> String { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn String::new() } // Could be const unsafe fn four() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 4 } // Could also be const fn generic(t: T) -> T { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn t } @@ -58,7 +57,7 @@ fn sub(x: u32) -> usize { } fn generic_arr(t: [T; 1]) -> T { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn t[0] } @@ -72,7 +71,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` + //~^ missing_const_for_fn B } } @@ -82,7 +81,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` + //~^ missing_const_for_fn byte.is_ascii_digit(); } } @@ -94,7 +93,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] fn msrv_1_46() -> i32 { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn 46 } @@ -114,7 +113,7 @@ impl const Drop for D { // Lint this, since it can be dropped in const contexts // FIXME(const_trait_impl) fn d(this: D) {} -//~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn mod msrv { struct Foo(*const u8, &'static u8); @@ -122,12 +121,12 @@ mod msrv { impl Foo { #[clippy::msrv = "1.58"] fn deref_ptr_can_be_const(self) -> usize { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn unsafe { *self.0 as usize } } fn deref_copied_val(self) -> usize { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn *self.1 as usize } } @@ -138,7 +137,7 @@ mod msrv { #[clippy::msrv = "1.56"] fn union_access_can_be_const() { - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn let bar = Bar { val: 1 }; let _ = unsafe { bar.val }; } @@ -146,12 +145,12 @@ mod msrv { #[clippy::msrv = "1.62"] mod with_extern { extern "C" fn c() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn #[rustfmt::skip] #[allow(missing_abi)] extern fn implicit_c() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn // any item functions in extern block won't trigger this lint extern "C" { @@ -168,11 +167,13 @@ mod issue12677 { impl Wrapper { #[must_use] pub fn new(strings: Vec) -> Self { + //~^ missing_const_for_fn Self { strings } } #[must_use] pub fn empty() -> Self { + //~^ missing_const_for_fn Self { strings: Vec::new() } } } @@ -184,6 +185,7 @@ mod issue12677 { impl Other { pub fn new(text: String) -> Self { + //~^ missing_const_for_fn let vec = Vec::new(); Self { text, vec } } @@ -203,18 +205,19 @@ mod with_ty_alias { // is. Because the associate ty could have no default, therefore would cause ICE, as demonstrated // in this test. fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {} + //~^ missing_const_for_fn } mod extern_fn { extern "C-unwind" fn c_unwind() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn extern "system" fn system() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn extern "system-unwind" fn system_unwind() {} - //~^ ERROR: this could be a `const fn` + //~^ missing_const_for_fn } fn mut_add(x: &mut i32) { - //~^ ERROR: this could be a `const fn` +//~^ missing_const_for_fn *x += 1; } 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 a06703e2ebf2..5df5a54ff521 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -3,7 +3,6 @@ error: this could be a `const fn` | LL | / pub fn new() -> Self { LL | | -LL | | LL | | Self { guess: 42 } LL | | } | |_____^ @@ -16,7 +15,7 @@ LL | pub const fn new() -> Self { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:19:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:18:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { LL | | @@ -30,7 +29,7 @@ LL | const fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:26:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:25:1 | LL | / fn one() -> i32 { LL | | @@ -44,7 +43,7 @@ LL | const fn one() -> i32 { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:32:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:31:1 | LL | / fn two() -> i32 { LL | | @@ -59,7 +58,7 @@ LL | const fn two() -> i32 { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:39:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:38:1 | LL | / fn string() -> String { LL | | @@ -73,7 +72,7 @@ LL | const fn string() -> String { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:45:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:44:1 | LL | / unsafe fn four() -> i32 { LL | | @@ -87,7 +86,7 @@ LL | const unsafe fn four() -> i32 { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:51:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:50:1 | LL | / fn generic(t: T) -> T { LL | | @@ -101,7 +100,7 @@ LL | const fn generic(t: T) -> T { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:60:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:59:1 | LL | / fn generic_arr(t: [T; 1]) -> T { LL | | @@ -115,7 +114,7 @@ LL | const fn generic_arr(t: [T; 1]) -> T { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:74:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:73:9 | LL | / pub fn b(self, a: &A) -> B { LL | | @@ -129,7 +128,7 @@ LL | pub const fn b(self, a: &A) -> B { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:84:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:83:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { LL | | @@ -143,7 +142,7 @@ LL | const fn const_fn_stabilized_before_msrv(byte: u8) { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:96:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:95:1 | LL | / fn msrv_1_46() -> i32 { LL | | @@ -157,7 +156,7 @@ LL | const fn msrv_1_46() -> i32 { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:116:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:115:1 | LL | fn d(this: D) {} | ^^^^^^^^^^^^^^^^ @@ -168,7 +167,7 @@ LL | const fn d(this: D) {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:124:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:123:9 | LL | / fn deref_ptr_can_be_const(self) -> usize { LL | | @@ -182,7 +181,7 @@ LL | const fn deref_ptr_can_be_const(self) -> usize { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:129:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:128:9 | LL | / fn deref_copied_val(self) -> usize { LL | | @@ -196,7 +195,7 @@ LL | const fn deref_copied_val(self) -> usize { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:140:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:139:5 | LL | / fn union_access_can_be_const() { LL | | @@ -211,7 +210,7 @@ LL | const fn union_access_can_be_const() { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:148:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:147:9 | LL | extern "C" fn c() {} | ^^^^^^^^^^^^^^^^^^^^ @@ -222,7 +221,7 @@ LL | const extern "C" fn c() {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:153:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:152:9 | LL | extern fn implicit_c() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,9 +232,10 @@ LL | const extern fn implicit_c() {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:170:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:169:9 | LL | / pub fn new(strings: Vec) -> Self { +LL | | LL | | Self { strings } LL | | } | |_________^ @@ -249,6 +249,7 @@ error: this could be a `const fn` --> tests/ui/missing_const_for_fn/could_be_const.rs:175:9 | LL | / pub fn empty() -> Self { +LL | | LL | | Self { strings: Vec::new() } LL | | } | |_________^ @@ -259,9 +260,10 @@ LL | pub const fn empty() -> Self { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:186:9 + --> tests/ui/missing_const_for_fn/could_be_const.rs:187:9 | LL | / pub fn new(text: String) -> Self { +LL | | LL | | let vec = Vec::new(); LL | | Self { text, vec } LL | | } @@ -273,7 +275,7 @@ LL | pub const fn new(text: String) -> Self { | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:205:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:207:5 | LL | fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -284,7 +286,7 @@ LL | const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:209:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:212:5 | LL | extern "C-unwind" fn c_unwind() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -295,7 +297,7 @@ LL | const extern "C-unwind" fn c_unwind() {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:211:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:214:5 | LL | extern "system" fn system() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -306,7 +308,7 @@ LL | const extern "system" fn system() {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:213:5 + --> tests/ui/missing_const_for_fn/could_be_const.rs:216:5 | LL | extern "system-unwind" fn system_unwind() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -317,7 +319,7 @@ LL | const extern "system-unwind" fn system_unwind() {} | +++++ error: this could be a `const fn` - --> tests/ui/missing_const_for_fn/could_be_const.rs:217:1 + --> tests/ui/missing_const_for_fn/could_be_const.rs:220:1 | LL | / fn mut_add(x: &mut i32) { LL | | diff --git a/tests/ui/missing_const_for_thread_local.fixed b/tests/ui/missing_const_for_thread_local.fixed index 90b31b9b5d21..281d7a6c9da3 100644 --- a/tests/ui/missing_const_for_thread_local.fixed +++ b/tests/ui/missing_const_for_thread_local.fixed @@ -6,8 +6,9 @@ fn main() { // lint and suggest const thread_local! { static BUF_1: RefCell = const { RefCell::new(String::new()) }; + //~^ missing_const_for_thread_local } - //~^^ ERROR: initializer for `thread_local` value can be made `const` + // don't lint thread_local! { @@ -16,23 +17,28 @@ fn main() { thread_local! { static SIMPLE:i32 = const { 1 }; + //~^ missing_const_for_thread_local } - //~^^ ERROR: initializer for `thread_local` value can be made `const` + // lint and suggest const for all non const items thread_local! { static BUF_3_CAN_BE_MADE_CONST: RefCell = const { RefCell::new(String::new()) }; + //~^ missing_const_for_thread_local static CONST_MIXED_WITH:i32 = const { 1 }; static BUF_4_CAN_BE_MADE_CONST: RefCell = const { RefCell::new(String::new()) }; + //~^ missing_const_for_thread_local } - //~^^^^ ERROR: initializer for `thread_local` value can be made `const` - //~^^^ ERROR: initializer for `thread_local` value can be made `const` + + thread_local! { static PEEL_ME: i32 = const { 1 }; - //~^ ERROR: initializer for `thread_local` value can be made `const` + //~^ missing_const_for_thread_local + static PEEL_ME_MANY: i32 = const { { let x = 1; x * x } }; - //~^ ERROR: initializer for `thread_local` value can be made `const` + //~^ missing_const_for_thread_local + } } diff --git a/tests/ui/missing_const_for_thread_local.rs b/tests/ui/missing_const_for_thread_local.rs index f97e4848fd7a..07239e5fa617 100644 --- a/tests/ui/missing_const_for_thread_local.rs +++ b/tests/ui/missing_const_for_thread_local.rs @@ -6,8 +6,9 @@ fn main() { // lint and suggest const thread_local! { static BUF_1: RefCell = RefCell::new(String::new()); + //~^ missing_const_for_thread_local } - //~^^ ERROR: initializer for `thread_local` value can be made `const` + // don't lint thread_local! { @@ -16,23 +17,28 @@ fn main() { thread_local! { static SIMPLE:i32 = 1; + //~^ missing_const_for_thread_local } - //~^^ ERROR: initializer for `thread_local` value can be made `const` + // lint and suggest const for all non const items thread_local! { static BUF_3_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); + //~^ missing_const_for_thread_local static CONST_MIXED_WITH:i32 = const { 1 }; static BUF_4_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); + //~^ missing_const_for_thread_local } - //~^^^^ ERROR: initializer for `thread_local` value can be made `const` - //~^^^ ERROR: initializer for `thread_local` value can be made `const` + + thread_local! { static PEEL_ME: i32 = { 1 }; - //~^ ERROR: initializer for `thread_local` value can be made `const` + //~^ missing_const_for_thread_local + static PEEL_ME_MANY: i32 = { let x = 1; x * x }; - //~^ ERROR: initializer for `thread_local` value can be made `const` + //~^ missing_const_for_thread_local + } } diff --git a/tests/ui/missing_const_for_thread_local.stderr b/tests/ui/missing_const_for_thread_local.stderr index c143a37454f5..76104a3761eb 100644 --- a/tests/ui/missing_const_for_thread_local.stderr +++ b/tests/ui/missing_const_for_thread_local.stderr @@ -8,31 +8,31 @@ LL | static BUF_1: RefCell = RefCell::new(String::new()); = help: to override `-D warnings` add `#[allow(clippy::missing_const_for_thread_local)]` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:18:29 + --> tests/ui/missing_const_for_thread_local.rs:19:29 | LL | static SIMPLE:i32 = 1; | ^ help: replace with: `const { 1 }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:24:59 + --> tests/ui/missing_const_for_thread_local.rs:26:59 | LL | static BUF_3_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { RefCell::new(String::new()) }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:26:59 + --> tests/ui/missing_const_for_thread_local.rs:29:59 | LL | static BUF_4_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { RefCell::new(String::new()) }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:32:31 + --> tests/ui/missing_const_for_thread_local.rs:36:31 | LL | static PEEL_ME: i32 = { 1 }; | ^^^^^ help: replace with: `const { 1 }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:34:36 + --> tests/ui/missing_const_for_thread_local.rs:39:36 | LL | static PEEL_ME_MANY: i32 = { let x = 1; x * x }; | ^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { { let x = 1; x * x } }` diff --git a/tests/ui/missing_doc.rs b/tests/ui/missing_doc.rs index 31bc4309582e..301c46e0f1b9 100644 --- a/tests/ui/missing_doc.rs +++ b/tests/ui/missing_doc.rs @@ -17,15 +17,18 @@ use proc_macros::with_span; use std::arch::global_asm; type Typedef = String; +//~^ missing_docs_in_private_items pub type PubTypedef = String; mod module_no_dox {} +//~^ missing_docs_in_private_items pub mod pub_module_no_dox {} /// dox pub fn foo() {} pub fn foo2() {} fn foo3() {} +//~^ missing_docs_in_private_items #[allow(clippy::missing_docs_in_private_items)] pub fn foo4() {} @@ -40,8 +43,13 @@ mod a { } enum Baz { +//~^ missing_docs_in_private_items BazA { a: isize, b: isize }, + //~^ missing_docs_in_private_items + //~| missing_docs_in_private_items + //~| missing_docs_in_private_items BarB, + //~^ missing_docs_in_private_items } pub enum PubBaz { @@ -66,6 +74,7 @@ pub enum PubBaz3 { pub fn baz() {} const FOO: u32 = 0; +//~^ missing_docs_in_private_items /// dox pub const FOO1: u32 = 0; #[allow(clippy::missing_docs_in_private_items)] @@ -75,6 +84,7 @@ pub const FOO3: u32 = 0; pub const FOO4: u32 = 0; static BAR: u32 = 0; +//~^ missing_docs_in_private_items /// dox pub static BAR1: u32 = 0; #[allow(clippy::missing_docs_in_private_items)] @@ -84,17 +94,20 @@ pub static BAR3: u32 = 0; pub static BAR4: u32 = 0; mod internal_impl { +//~^ missing_docs_in_private_items /// dox pub fn documented() {} pub fn undocumented1() {} pub fn undocumented2() {} fn undocumented3() {} + //~^ missing_docs_in_private_items /// dox pub mod globbed { /// dox pub fn also_documented() {} pub fn also_undocumented1() {} fn also_undocumented2() {} + //~^ missing_docs_in_private_items } } /// dox @@ -120,6 +133,7 @@ with_span!(span pub const FOO2_PM: u32 = 0;); const _: () = (); fn issue13298() { +//~^ missing_docs_in_private_items // Rustdoc doesn't generate documentation for items within other items like fns or consts const MSG: &str = "Hello, world!"; } diff --git a/tests/ui/missing_doc.stderr b/tests/ui/missing_doc.stderr index 6554eed16106..63e440b82d14 100644 --- a/tests/ui/missing_doc.stderr +++ b/tests/ui/missing_doc.stderr @@ -8,89 +8,91 @@ LL | type Typedef = String; = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a module - --> tests/ui/missing_doc.rs:22:1 + --> tests/ui/missing_doc.rs:23:1 | LL | mod module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:28:1 + --> tests/ui/missing_doc.rs:30:1 | LL | fn foo3() {} | ^^^^^^^^^^^^ error: missing documentation for an enum - --> tests/ui/missing_doc.rs:42:1 + --> tests/ui/missing_doc.rs:45:1 | LL | / enum Baz { +LL | | LL | | BazA { a: isize, b: isize }, -LL | | BarB, +... | LL | | } | |_^ error: missing documentation for a variant - --> tests/ui/missing_doc.rs:43:5 + --> tests/ui/missing_doc.rs:47:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc.rs:43:12 + --> tests/ui/missing_doc.rs:47:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc.rs:43:22 + --> tests/ui/missing_doc.rs:47:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> tests/ui/missing_doc.rs:44:5 + --> tests/ui/missing_doc.rs:51:5 | LL | BarB, | ^^^^ error: missing documentation for a constant - --> tests/ui/missing_doc.rs:68:1 + --> tests/ui/missing_doc.rs:76:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> tests/ui/missing_doc.rs:77:1 + --> tests/ui/missing_doc.rs:86:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> tests/ui/missing_doc.rs:86:1 + --> tests/ui/missing_doc.rs:96:1 | LL | / mod internal_impl { +LL | | LL | | /// dox LL | | pub fn documented() {} -LL | | pub fn undocumented1() {} ... | LL | | } | |_^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:91:5 + --> tests/ui/missing_doc.rs:102:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:97:9 + --> tests/ui/missing_doc.rs:109:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:122:1 + --> tests/ui/missing_doc.rs:135:1 | LL | / fn issue13298() { +LL | | LL | | // Rustdoc doesn't generate documentation for items within other items like fns or consts LL | | const MSG: &str = "Hello, world!"; LL | | } diff --git a/tests/ui/missing_doc_crate.rs b/tests/ui/missing_doc_crate.rs index fdb23af279df..e6e783a2bb40 100644 --- a/tests/ui/missing_doc_crate.rs +++ b/tests/ui/missing_doc_crate.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::missing_docs_in_private_items)] #![allow(clippy::doc_include_without_cfg)] #![doc = include_str!("../../README.md")] diff --git a/tests/ui/missing_doc_crate_missing.rs b/tests/ui/missing_doc_crate_missing.rs index 73584ac8c67d..70e96f4dd547 100644 --- a/tests/ui/missing_doc_crate_missing.rs +++ b/tests/ui/missing_doc_crate_missing.rs @@ -1,5 +1,6 @@ #![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` +//~^ missing_docs_in_private_items + + fn main() {} diff --git a/tests/ui/missing_doc_impl.rs b/tests/ui/missing_doc_impl.rs index 520ddbe16b82..e2d268c4e3bd 100644 --- a/tests/ui/missing_doc_impl.rs +++ b/tests/ui/missing_doc_impl.rs @@ -11,13 +11,17 @@ extern crate proc_macros; use proc_macros::with_span; struct Foo { +//~^ missing_docs_in_private_items a: isize, + //~^ missing_docs_in_private_items b: isize, + //~^ missing_docs_in_private_items } pub struct PubFoo { pub a: isize, b: isize, + //~^ missing_docs_in_private_items } #[allow(clippy::missing_docs_in_private_items)] @@ -65,9 +69,11 @@ pub trait E: Sized { impl Foo { pub fn new() -> Self { + //~^ missing_docs_in_private_items Foo { a: 0, b: 0 } } fn bar() {} + //~^ missing_docs_in_private_items } impl PubFoo { @@ -76,6 +82,7 @@ impl PubFoo { pub fn foo1() {} #[must_use = "yep"] fn foo2() -> u32 { + //~^ missing_docs_in_private_items 1 } #[allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/missing_doc_impl.stderr b/tests/ui/missing_doc_impl.stderr index e2052c346df8..999ff06f593e 100644 --- a/tests/ui/missing_doc_impl.stderr +++ b/tests/ui/missing_doc_impl.stderr @@ -2,8 +2,9 @@ error: missing documentation for a struct --> tests/ui/missing_doc_impl.rs:13:1 | LL | / struct Foo { +LL | | LL | | a: isize, -LL | | b: isize, +... | LL | | } | |_^ | @@ -11,41 +12,43 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a struct field - --> tests/ui/missing_doc_impl.rs:14:5 + --> tests/ui/missing_doc_impl.rs:15:5 | LL | a: isize, | ^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc_impl.rs:15:5 + --> tests/ui/missing_doc_impl.rs:17:5 | LL | b: isize, | ^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc_impl.rs:20:5 + --> tests/ui/missing_doc_impl.rs:23:5 | LL | b: isize, | ^^^^^^^^ error: missing documentation for an associated function - --> tests/ui/missing_doc_impl.rs:67:5 + --> tests/ui/missing_doc_impl.rs:71:5 | LL | / pub fn new() -> Self { +LL | | LL | | Foo { a: 0, b: 0 } LL | | } | |_____^ error: missing documentation for an associated function - --> tests/ui/missing_doc_impl.rs:70:5 + --> tests/ui/missing_doc_impl.rs:75:5 | LL | fn bar() {} | ^^^^^^^^^^^ error: missing documentation for an associated function - --> tests/ui/missing_doc_impl.rs:78:5 + --> tests/ui/missing_doc_impl.rs:84:5 | LL | / fn foo2() -> u32 { +LL | | LL | | 1 LL | | } | |_____^ diff --git a/tests/ui/missing_fields_in_debug.rs b/tests/ui/missing_fields_in_debug.rs index 68867ec819d1..bf69eae05169 100644 --- a/tests/ui/missing_fields_in_debug.rs +++ b/tests/ui/missing_fields_in_debug.rs @@ -12,7 +12,8 @@ struct NamedStruct1Ignored { } impl fmt::Debug for NamedStruct1Ignored { - //~^ ERROR: manual `Debug` impl does not include all fields +//~^ missing_fields_in_debug + // unused field: hidden fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -31,7 +32,8 @@ struct NamedStructMultipleIgnored { } impl fmt::Debug for NamedStructMultipleIgnored { - //~^ ERROR: manual `Debug` impl does not include all fields +//~^ missing_fields_in_debug + // unused fields: hidden, hidden2, hidden4 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -93,7 +95,8 @@ struct MultiExprDebugImpl { // ok impl fmt::Debug for MultiExprDebugImpl { - //~^ ERROR: manual `Debug` impl does not include all fields +//~^ missing_fields_in_debug + 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 5e51194c4b37..75b551e1f5c7 100644 --- a/tests/ui/missing_fields_in_debug.stderr +++ b/tests/ui/missing_fields_in_debug.stderr @@ -2,9 +2,6 @@ error: manual `Debug` impl does not include all fields --> tests/ui/missing_fields_in_debug.rs:14:1 | LL | / impl fmt::Debug for NamedStruct1Ignored { -LL | | -LL | | // unused field: hidden -LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { ... | LL | | } | |_^ @@ -20,28 +17,25 @@ LL | hidden: u32, = help: to override `-D warnings` add `#[allow(clippy::missing_fields_in_debug)]` error: manual `Debug` impl does not include all fields - --> tests/ui/missing_fields_in_debug.rs:33:1 + --> tests/ui/missing_fields_in_debug.rs:34: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 | | } | |_^ | note: this field is unused - --> tests/ui/missing_fields_in_debug.rs:27:5 + --> tests/ui/missing_fields_in_debug.rs:28:5 | LL | hidden: u32, | ^^^^^^^^^^^ note: this field is unused - --> tests/ui/missing_fields_in_debug.rs:28:5 + --> tests/ui/missing_fields_in_debug.rs:29:5 | LL | hidden2: String, | ^^^^^^^^^^^^^^^ note: this field is unused - --> tests/ui/missing_fields_in_debug.rs:30:5 + --> tests/ui/missing_fields_in_debug.rs:31:5 | LL | hidden4: ((((u8), u16), u32), u64), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,18 +43,18 @@ 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 - --> tests/ui/missing_fields_in_debug.rs:95:1 + --> tests/ui/missing_fields_in_debug.rs:97:1 | LL | / impl fmt::Debug for MultiExprDebugImpl { LL | | +LL | | LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | let mut f = formatter.debug_struct("MultiExprDebugImpl"); ... | LL | | } | |_^ | note: this field is unused - --> tests/ui/missing_fields_in_debug.rs:91:5 + --> tests/ui/missing_fields_in_debug.rs:93:5 | LL | b: String, | ^^^^^^^^^ diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index dca85b94d5ee..ec21de4ca41c 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -18,8 +18,9 @@ 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` +//~^ missing_inline_in_public_items + + #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -37,7 +38,8 @@ pub trait PubBar { fn PubBar_a(); // ok // missing #[inline] fn PubBar_b() {} - //~^ ERROR: missing `#[inline]` for a default trait method + //~^ missing_inline_in_public_items + #[inline] fn PubBar_c() {} // ok } @@ -53,13 +55,16 @@ impl PubBar for Foo { impl PubBar for PubFoo { // missing #[inline] fn PubBar_a() {} - //~^ ERROR: missing `#[inline]` for a method + //~^ missing_inline_in_public_items + // missing #[inline] fn PubBar_b() {} - //~^ ERROR: missing `#[inline]` for a method + //~^ missing_inline_in_public_items + // missing #[inline] fn PubBar_c() {} - //~^ ERROR: missing `#[inline]` for a method + //~^ missing_inline_in_public_items + } // do not need inline because Foo is not exported @@ -71,7 +76,8 @@ impl Foo { impl PubFoo { // missing #[inline] pub fn PubFooImpl() {} - //~^ ERROR: missing `#[inline]` for a method + //~^ missing_inline_in_public_items + } // 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 c2bb37141a02..2ce335a696ce 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -8,31 +8,31 @@ LL | pub fn pub_foo() {} = help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]` error: missing `#[inline]` for a default trait method - --> tests/ui/missing_inline.rs:39:5 + --> tests/ui/missing_inline.rs:40:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:55:5 + --> tests/ui/missing_inline.rs:57:5 | LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:58:5 + --> tests/ui/missing_inline.rs:61:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:61:5 + --> tests/ui/missing_inline.rs:65:5 | LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:73:5 + --> tests/ui/missing_inline.rs:78:5 | LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_inline_executable.rs b/tests/ui/missing_inline_executable.rs index 6e0400ac935b..444a7f1c964f 100644 --- a/tests/ui/missing_inline_executable.rs +++ b/tests/ui/missing_inline_executable.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::missing_inline_in_public_items)] pub fn foo() {} diff --git a/tests/ui/missing_inline_proc_macro.rs b/tests/ui/missing_inline_proc_macro.rs index e47a198c6aea..ce368304f725 100644 --- a/tests/ui/missing_inline_proc_macro.rs +++ b/tests/ui/missing_inline_proc_macro.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::missing_inline_in_public_items)] extern crate proc_macro; diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index b0fa8e988598..f8aeffb3d041 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -11,17 +11,20 @@ fn main() {} /// This needs to be documented pub fn unwrap() { +//~^ missing_panics_doc let result = Err("Hi"); result.unwrap() } /// This needs to be documented pub fn panic() { +//~^ missing_panics_doc panic!("This function panics") } /// This needs to be documented pub fn inner_body(opt: Option) { +//~^ missing_panics_doc opt.map(|x| { if x == 10 { panic!() @@ -31,17 +34,20 @@ pub fn inner_body(opt: Option) { /// This needs to be documented pub fn unreachable_and_panic() { +//~^ missing_panics_doc if true { unreachable!() } else { panic!() } } /// This needs to be documented pub fn assert_eq() { +//~^ missing_panics_doc let x = 0; assert_eq!(x, 0); } /// This needs to be documented pub fn assert_ne() { +//~^ missing_panics_doc let x = 0; assert_ne!(x, 0); } @@ -149,30 +155,36 @@ pub fn debug_assertions() { // `pub` is required, because the lint does not consider unreachable items pub mod issue10240 { pub fn option_unwrap(v: &[T]) -> &T { + //~^ missing_panics_doc let o: Option<&T> = v.last(); o.unwrap() } pub fn option_expect(v: &[T]) -> &T { + //~^ missing_panics_doc let o: Option<&T> = v.last(); o.expect("passed an empty thing") } pub fn result_unwrap(v: &[T]) -> &T { + //~^ missing_panics_doc let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.unwrap() } pub fn result_expect(v: &[T]) -> &T { + //~^ missing_panics_doc let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.expect("passed an empty thing") } pub fn last_unwrap(v: &[u32]) -> u32 { + //~^ missing_panics_doc *v.last().unwrap() } pub fn last_expect(v: &[u32]) -> u32 { + //~^ missing_panics_doc *v.last().expect("passed an empty thing") } } diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index c6a939d86f7c..a83e2fa367dd 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -5,7 +5,7 @@ LL | pub fn unwrap() { | ^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:15:5 + --> tests/ui/missing_panics_doc.rs:16:5 | LL | result.unwrap() | ^^^^^^^^^^^^^^^ @@ -13,133 +13,133 @@ LL | result.unwrap() = help: to override `-D warnings` add `#[allow(clippy::missing_panics_doc)]` error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:19:1 + --> tests/ui/missing_panics_doc.rs:20:1 | LL | pub fn panic() { | ^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:20:5 + --> tests/ui/missing_panics_doc.rs:22:5 | LL | panic!("This function panics") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:24:1 + --> tests/ui/missing_panics_doc.rs:26:1 | LL | pub fn inner_body(opt: Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:27:13 + --> tests/ui/missing_panics_doc.rs:30:13 | LL | panic!() | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:33:1 + --> tests/ui/missing_panics_doc.rs:36:1 | LL | pub fn unreachable_and_panic() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:34:39 + --> tests/ui/missing_panics_doc.rs:38:39 | LL | if true { unreachable!() } else { panic!() } | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:38:1 + --> tests/ui/missing_panics_doc.rs:42:1 | LL | pub fn assert_eq() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:40:5 + --> tests/ui/missing_panics_doc.rs:45:5 | LL | assert_eq!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:44:1 + --> tests/ui/missing_panics_doc.rs:49:1 | LL | pub fn assert_ne() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:46:5 + --> tests/ui/missing_panics_doc.rs:52:5 | LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:151:5 + --> tests/ui/missing_panics_doc.rs:157:5 | LL | pub fn option_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:153:9 + --> tests/ui/missing_panics_doc.rs:160:9 | LL | o.unwrap() | ^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:156:5 + --> tests/ui/missing_panics_doc.rs:163:5 | LL | pub fn option_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:158:9 + --> tests/ui/missing_panics_doc.rs:166:9 | LL | o.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:161:5 + --> tests/ui/missing_panics_doc.rs:169:5 | LL | pub fn result_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:163:9 + --> tests/ui/missing_panics_doc.rs:172:9 | LL | res.unwrap() | ^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:166:5 + --> tests/ui/missing_panics_doc.rs:175:5 | LL | pub fn result_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:168:9 + --> tests/ui/missing_panics_doc.rs:178:9 | LL | res.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:171:5 + --> tests/ui/missing_panics_doc.rs:181:5 | LL | pub fn last_unwrap(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:172:10 + --> tests/ui/missing_panics_doc.rs:183:10 | LL | *v.last().unwrap() | ^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:175:5 + --> tests/ui/missing_panics_doc.rs:186:5 | LL | pub fn last_expect(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:176:10 + --> tests/ui/missing_panics_doc.rs:188:10 | LL | *v.last().expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_spin_loop.fixed b/tests/ui/missing_spin_loop.fixed index b6520d478be8..03fbf8ccc8a3 100644 --- a/tests/ui/missing_spin_loop.fixed +++ b/tests/ui/missing_spin_loop.fixed @@ -8,16 +8,22 @@ fn main() { let b = AtomicBool::new(true); // Those should lint while b.load(Ordering::Acquire) { std::hint::spin_loop() } + //~^ missing_spin_loop while !b.load(Ordering::SeqCst) { std::hint::spin_loop() } + //~^ missing_spin_loop while b.load(Ordering::Acquire) == false { std::hint::spin_loop() } + //~^ missing_spin_loop while { true == b.load(Ordering::Acquire) } { std::hint::spin_loop() } + //~^ missing_spin_loop while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) { std::hint::spin_loop() } + //~^ missing_spin_loop while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) { std::hint::spin_loop() } + //~^ missing_spin_loop // This is OK, as the body is not empty while b.load(Ordering::Acquire) { diff --git a/tests/ui/missing_spin_loop.rs b/tests/ui/missing_spin_loop.rs index 7b115c66ade6..bf18590b9408 100644 --- a/tests/ui/missing_spin_loop.rs +++ b/tests/ui/missing_spin_loop.rs @@ -8,16 +8,22 @@ fn main() { let b = AtomicBool::new(true); // Those should lint while b.load(Ordering::Acquire) {} + //~^ missing_spin_loop while !b.load(Ordering::SeqCst) {} + //~^ missing_spin_loop while b.load(Ordering::Acquire) == false {} + //~^ missing_spin_loop while { true == b.load(Ordering::Acquire) } {} + //~^ missing_spin_loop while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) {} + //~^ missing_spin_loop while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {} + //~^ missing_spin_loop // This is OK, as the body is not empty while b.load(Ordering::Acquire) { diff --git a/tests/ui/missing_spin_loop.stderr b/tests/ui/missing_spin_loop.stderr index 12f4b53a3d18..98c32d042346 100644 --- a/tests/ui/missing_spin_loop.stderr +++ b/tests/ui/missing_spin_loop.stderr @@ -8,31 +8,31 @@ LL | while b.load(Ordering::Acquire) {} = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` error: busy-waiting loop should at least have a spin loop hint - --> tests/ui/missing_spin_loop.rs:12:37 + --> tests/ui/missing_spin_loop.rs:13: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 - --> tests/ui/missing_spin_loop.rs:14:46 + --> tests/ui/missing_spin_loop.rs:16: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 - --> tests/ui/missing_spin_loop.rs:16:49 + --> tests/ui/missing_spin_loop.rs:19: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 - --> tests/ui/missing_spin_loop.rs:18:93 + --> tests/ui/missing_spin_loop.rs:22: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 - --> tests/ui/missing_spin_loop.rs:20:94 + --> tests/ui/missing_spin_loop.rs:25: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 771ab1ab21a8..a525d414670e 100644 --- a/tests/ui/missing_spin_loop_no_std.fixed +++ b/tests/ui/missing_spin_loop_no_std.fixed @@ -9,5 +9,6 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let b = AtomicBool::new(true); // This should lint with `core::hint::spin_loop()` while b.load(Ordering::Acquire) { core::hint::spin_loop() } + //~^ missing_spin_loop 0 } diff --git a/tests/ui/missing_spin_loop_no_std.rs b/tests/ui/missing_spin_loop_no_std.rs index bf890fc4066b..3b421f32c34f 100644 --- a/tests/ui/missing_spin_loop_no_std.rs +++ b/tests/ui/missing_spin_loop_no_std.rs @@ -9,5 +9,6 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let b = AtomicBool::new(true); // This should lint with `core::hint::spin_loop()` while b.load(Ordering::Acquire) {} + //~^ missing_spin_loop 0 } diff --git a/tests/ui/missing_trait_methods.rs b/tests/ui/missing_trait_methods.rs index 55b904bde59a..bcca5e1ae5bd 100644 --- a/tests/ui/missing_trait_methods.rs +++ b/tests/ui/missing_trait_methods.rs @@ -20,10 +20,12 @@ trait B { struct Partial; impl A for Partial {} -//~^ ERROR: missing trait method provided by default: `provided` +//~^ missing_trait_methods + impl B for Partial { - //~^ ERROR: missing trait method provided by default: `b` +//~^ missing_trait_methods + fn required() {} fn a(_: usize) -> usize { @@ -56,5 +58,8 @@ trait MissingMultiple { } impl MissingMultiple for Partial {} +//~^ missing_trait_methods +//~| missing_trait_methods +//~| missing_trait_methods fn main() {} diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index 9c4968b022d7..4af7b9ae1ea9 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -13,7 +13,7 @@ LL | fn provided() {} = help: to override `-D warnings` add `#[allow(clippy::missing_trait_methods)]` error: missing trait method provided by default: `b` - --> tests/ui/missing_trait_methods.rs:25:1 + --> tests/ui/missing_trait_methods.rs:26:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ @@ -25,31 +25,7 @@ LL | fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing trait method provided by default: `one` - --> tests/ui/missing_trait_methods.rs:58:1 - | -LL | impl MissingMultiple for Partial {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: implement the method - --> tests/ui/missing_trait_methods.rs:53:5 - | -LL | fn one() {} - | ^^^^^^^^ - -error: missing trait method provided by default: `two` - --> tests/ui/missing_trait_methods.rs:58:1 - | -LL | impl MissingMultiple for Partial {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: implement the method - --> tests/ui/missing_trait_methods.rs:54:5 - | -LL | fn two() {} - | ^^^^^^^^ - -error: missing trait method provided by default: `three` - --> tests/ui/missing_trait_methods.rs:58:1 + --> tests/ui/missing_trait_methods.rs:60:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,6 +33,30 @@ LL | impl MissingMultiple for Partial {} help: implement the method --> tests/ui/missing_trait_methods.rs:55:5 | +LL | fn one() {} + | ^^^^^^^^ + +error: missing trait method provided by default: `two` + --> tests/ui/missing_trait_methods.rs:60:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:56:5 + | +LL | fn two() {} + | ^^^^^^^^ + +error: missing trait method provided by default: `three` + --> tests/ui/missing_trait_methods.rs:60:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:57:5 + | LL | fn three() {} | ^^^^^^^^^^ diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index b84b3dc349ec..50ef32e47c03 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -14,35 +14,51 @@ use proc_macros::with_span; fn main() { let fail14 = 2_i32; + //~^ mistyped_literal_suffixes let fail15 = 4_i64; + //~^ mistyped_literal_suffixes let fail16 = 7_i8; // + //~^ mistyped_literal_suffixes let fail17 = 23_i16; // + //~^ mistyped_literal_suffixes let ok18 = 23_128; let fail20 = 2_i8; // + //~^ mistyped_literal_suffixes let fail21 = 4_i16; // + //~^ mistyped_literal_suffixes let ok24 = 12.34_64; let fail25 = 1E2_f32; + //~^ mistyped_literal_suffixes let fail26 = 43E7_f64; + //~^ mistyped_literal_suffixes let fail27 = 243E17_f32; + //~^ mistyped_literal_suffixes let fail28 = 241_251_235E723_f64; + //~^ mistyped_literal_suffixes let ok29 = 42279.911_32; // testing that the suggestion actually fits in its type let fail30 = 127_i8; // should be i8 + //~^ mistyped_literal_suffixes let fail31 = 240_u8; // should be u8 + //~^ mistyped_literal_suffixes let ok32 = 360_8; // doesn't fit in either, should be ignored let fail33 = 0x1234_i16; + //~^ mistyped_literal_suffixes let fail34 = 0xABCD_u16; + //~^ mistyped_literal_suffixes let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_u64; // u64 + //~^ mistyped_literal_suffixes // issue #6129 let ok37 = 123_32.123; let ok38 = 124_64.0; let _ = 1.123_45E1_f32; + //~^ mistyped_literal_suffixes let _ = with_span!(1 2_u32); } diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index a47a736067a8..92f827608b10 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -14,35 +14,51 @@ use proc_macros::with_span; fn main() { let fail14 = 2_32; + //~^ mistyped_literal_suffixes let fail15 = 4_64; + //~^ mistyped_literal_suffixes let fail16 = 7_8; // + //~^ mistyped_literal_suffixes let fail17 = 23_16; // + //~^ mistyped_literal_suffixes let ok18 = 23_128; let fail20 = 2__8; // + //~^ mistyped_literal_suffixes let fail21 = 4___16; // + //~^ mistyped_literal_suffixes let ok24 = 12.34_64; let fail25 = 1E2_32; + //~^ mistyped_literal_suffixes let fail26 = 43E7_64; + //~^ mistyped_literal_suffixes let fail27 = 243E17_32; + //~^ mistyped_literal_suffixes let fail28 = 241251235E723_64; + //~^ mistyped_literal_suffixes let ok29 = 42279.911_32; // testing that the suggestion actually fits in its type let fail30 = 127_8; // should be i8 + //~^ mistyped_literal_suffixes let fail31 = 240_8; // should be u8 + //~^ mistyped_literal_suffixes let ok32 = 360_8; // doesn't fit in either, should be ignored let fail33 = 0x1234_16; + //~^ mistyped_literal_suffixes let fail34 = 0xABCD_16; + //~^ mistyped_literal_suffixes let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 + //~^ mistyped_literal_suffixes // issue #6129 let ok37 = 123_32.123; let ok38 = 124_64.0; let _ = 1.12345E1_32; + //~^ mistyped_literal_suffixes let _ = with_span!(1 2_u32); } diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index 56bfb06d8e66..2fb3012b84f6 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -7,91 +7,91 @@ LL | let fail14 = 2_32; = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:17:18 + --> tests/ui/mistyped_literal_suffix.rs:18:18 | LL | let fail15 = 4_64; | ^^^^ help: did you mean to write: `4_i64` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:18:18 + --> tests/ui/mistyped_literal_suffix.rs:20:18 | LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:19:18 + --> tests/ui/mistyped_literal_suffix.rs:22:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:22:18 + --> tests/ui/mistyped_literal_suffix.rs:26:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:23:18 + --> tests/ui/mistyped_literal_suffix.rs:28:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:26:18 + --> tests/ui/mistyped_literal_suffix.rs:32:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:27:18 + --> tests/ui/mistyped_literal_suffix.rs:34:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:28:18 + --> tests/ui/mistyped_literal_suffix.rs:36:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:29:18 + --> tests/ui/mistyped_literal_suffix.rs:38:18 | LL | let fail28 = 241251235E723_64; | ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:33:18 + --> tests/ui/mistyped_literal_suffix.rs:43:18 | LL | let fail30 = 127_8; // should be i8 | ^^^^^ help: did you mean to write: `127_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:34:18 + --> tests/ui/mistyped_literal_suffix.rs:45:18 | LL | let fail31 = 240_8; // should be u8 | ^^^^^ help: did you mean to write: `240_u8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:36:18 + --> tests/ui/mistyped_literal_suffix.rs:48:18 | LL | let fail33 = 0x1234_16; | ^^^^^^^^^ help: did you mean to write: `0x1234_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:37:18 + --> tests/ui/mistyped_literal_suffix.rs:50:18 | LL | let fail34 = 0xABCD_16; | ^^^^^^^^^ help: did you mean to write: `0xABCD_u16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:39:18 + --> tests/ui/mistyped_literal_suffix.rs:53: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 - --> tests/ui/mistyped_literal_suffix.rs:45:13 + --> tests/ui/mistyped_literal_suffix.rs:60:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` diff --git a/tests/ui/mixed_attributes_style/auxiliary/submodule.rs b/tests/ui/mixed_attributes_style/auxiliary/submodule.rs index df44b07a6941..61615c5d3a64 100644 --- a/tests/ui/mixed_attributes_style/auxiliary/submodule.rs +++ b/tests/ui/mixed_attributes_style/auxiliary/submodule.rs @@ -3,7 +3,8 @@ #![allow(dead_code)] #[allow(unused)] -//~^ ERROR: item has both inner and outer attributes +//~^ mixed_attributes_style + mod foo { #![allow(dead_code)] } diff --git a/tests/ui/mixed_attributes_style/global_allow.rs b/tests/ui/mixed_attributes_style/global_allow.rs index 153262e65570..c68a5462afea 100644 --- a/tests/ui/mixed_attributes_style/global_allow.rs +++ b/tests/ui/mixed_attributes_style/global_allow.rs @@ -1,3 +1,5 @@ +//@error-in-other-file: +//@no-rustfix // issue 12436 #![allow(clippy::mixed_attributes_style)] diff --git a/tests/ui/mixed_attributes_style/mod_declaration.rs b/tests/ui/mixed_attributes_style/mod_declaration.rs index b0f1f0bda9e6..f2aad9a21e99 100644 --- a/tests/ui/mixed_attributes_style/mod_declaration.rs +++ b/tests/ui/mixed_attributes_style/mod_declaration.rs @@ -1,3 +1,6 @@ +//@error-in-other-file: empty line after outer attribute +//@error-in-other-file: item has both inner and outer attributes +//@no-rustfix #[path = "auxiliary/submodule.rs"] // don't lint. /// This doc comment should not lint, it could be used to add context to the original module doc mod submodule; diff --git a/tests/ui/mixed_attributes_style/mod_declaration.stderr b/tests/ui/mixed_attributes_style/mod_declaration.stderr index 968c537c7e44..13ec97fbc1af 100644 --- a/tests/ui/mixed_attributes_style/mod_declaration.stderr +++ b/tests/ui/mixed_attributes_style/mod_declaration.stderr @@ -3,6 +3,7 @@ error: item has both inner and outer attributes | LL | / #[allow(unused)] LL | | +LL | | LL | | mod foo { LL | | #![allow(dead_code)] | |________________________^ @@ -10,5 +11,23 @@ LL | | #![allow(dead_code)] = note: `-D clippy::mixed-attributes-style` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]` -error: aborting due to 1 previous error +error: empty line after outer attribute + --> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1 + | +LL | / #[allow(unused)] +LL | | +LL | | + | |_^ +LL | mod foo { + | ------- the attribute applies to this module + | + = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` + = help: if the empty line is unintentional remove it +help: if the attribute should apply to the parent module use an inner attribute + | +LL | #![allow(unused)] + | + + +error: aborting due to 2 previous errors diff --git a/tests/ui/mixed_read_write_in_expression.rs b/tests/ui/mixed_read_write_in_expression.rs index 241536abdfbd..cff7996243bb 100644 --- a/tests/ui/mixed_read_write_in_expression.rs +++ b/tests/ui/mixed_read_write_in_expression.rs @@ -12,11 +12,13 @@ fn main() { x = 1; 1 } + x; - //~^ ERROR: unsequenced read of `x` + //~^ mixed_read_write_in_expression + // Example from iss#277 x += { - //~^ ERROR: unsequenced read of `x` + //~^ mixed_read_write_in_expression + x = 20; 2 }; @@ -30,7 +32,8 @@ fn main() { let base = Foo { a: 4, b: 5 }; let foo = Foo { a: x, - //~^ ERROR: unsequenced read of `x` + //~^ mixed_read_write_in_expression + ..{ x = 6; base @@ -40,7 +43,8 @@ fn main() { let closure = || { let mut x = 0; x += { - //~^ ERROR: unsequenced read of `x` + //~^ mixed_read_write_in_expression + x = 20; 2 }; diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index 796d4ccd26b7..ebb3e691e6b7 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -13,37 +13,37 @@ LL | x = 1; = help: to override `-D warnings` add `#[allow(clippy::mixed_read_write_in_expression)]` error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:18:5 + --> tests/ui/mixed_read_write_in_expression.rs:19:5 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:20:9 + --> tests/ui/mixed_read_write_in_expression.rs:22:9 | LL | x = 20; | ^^^^^^ error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:32:12 + --> tests/ui/mixed_read_write_in_expression.rs:34:12 | LL | a: x, | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:35:13 + --> tests/ui/mixed_read_write_in_expression.rs:38:13 | LL | x = 6; | ^^^^^ error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:42:9 + --> tests/ui/mixed_read_write_in_expression.rs:45:9 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:44:13 + --> tests/ui/mixed_read_write_in_expression.rs:48:13 | LL | x = 20; | ^^^^^^ diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index ad46e0c29aee..f04f0c5eeeba 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -3,14 +3,16 @@ 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` + //~^ module_inception + + pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { - //~^ ERROR: module has the same name as its containing module + //~^ module_inception + pub mod bar2 {} } } @@ -18,13 +20,15 @@ pub mod foo2 { mod foo { mod bar { mod bar { - //~^ ERROR: module has the same name as its containing module + //~^ module_inception + mod foo {} } mod foo {} } mod foo { - //~^ ERROR: module has the same name as its containing module + //~^ module_inception + mod bar {} } } diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index 455f5372747a..3aaf304ac0e5 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -2,9 +2,7 @@ error: module has the same name as its containing module --> tests/ui/module_inception.rs:5:9 | LL | / pub mod bar2 { -LL | | -LL | | -LL | | pub mod foo2 {} +... | LL | | } | |_________^ | @@ -12,28 +10,31 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module - --> tests/ui/module_inception.rs:12:5 + --> tests/ui/module_inception.rs:13:5 | LL | / pub mod foo2 { LL | | +LL | | LL | | pub mod bar2 {} LL | | } | |_____^ error: module has the same name as its containing module - --> tests/ui/module_inception.rs:20:9 + --> tests/ui/module_inception.rs:22:9 | LL | / mod bar { LL | | +LL | | LL | | mod foo {} LL | | } | |_________^ error: module has the same name as its containing module - --> tests/ui/module_inception.rs:26:5 + --> tests/ui/module_inception.rs:29:5 | LL | / mod foo { LL | | +LL | | LL | | mod bar {} LL | | } | |_____^ diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index 71d8ac7a1f0e..b45120a8d10c 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -6,16 +6,21 @@ pub 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` + //~^ module_name_repetitions + + pub fn bar_foo() {} - //~^ ERROR: item name ends with its containing module's name + //~^ module_name_repetitions + pub struct FooCake; - //~^ ERROR: item name starts with its containing module's name + //~^ module_name_repetitions + pub enum CakeFoo {} - //~^ ERROR: item name ends with its containing module's name + //~^ module_name_repetitions + pub struct Foo7Bar; - //~^ ERROR: item name starts with its containing module's name + //~^ module_name_repetitions + // Should not warn pub struct Foobar; @@ -28,7 +33,8 @@ pub mod foo { pub use error::Error; // ... but should still warn when the item is reexported to create a *public* path with repetition. pub use error::FooError; - //~^ ERROR: item name starts with its containing module's name + //~^ module_name_repetitions + // FIXME: This should also warn because it creates the public path `foo::FooIter`. mod iter { diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index 8fd8b3948753..664a816ae5d1 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -8,31 +8,31 @@ LL | pub fn foo_bar() {} = help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` error: item name ends with its containing module's name - --> tests/ui/module_name_repetitions.rs:11:12 + --> tests/ui/module_name_repetitions.rs:12:12 | LL | pub fn bar_foo() {} | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:13:16 + --> tests/ui/module_name_repetitions.rs:15:16 | LL | pub struct FooCake; | ^^^^^^^ error: item name ends with its containing module's name - --> tests/ui/module_name_repetitions.rs:15:14 + --> tests/ui/module_name_repetitions.rs:18:14 | LL | pub enum CakeFoo {} | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:17:16 + --> tests/ui/module_name_repetitions.rs:21:16 | LL | pub struct Foo7Bar; | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:30:20 + --> tests/ui/module_name_repetitions.rs:35:20 | LL | pub use error::FooError; | ^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs index a5b63bed531b..1b622151bcc2 100644 --- a/tests/ui/modulo_arithmetic_float.rs +++ b/tests/ui/modulo_arithmetic_float.rs @@ -6,67 +6,83 @@ 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + (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 + //~^ modulo_arithmetic + + (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 + //~^ modulo_arithmetic + + // Lint on floating point numbers let a_f16: f16 = -1.6; let mut b_f16: f16 = 2.1; a_f16 % b_f16; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + b_f16 % a_f16; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + b_f16 %= a_f16; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + // 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + let a_f128: f128 = -1.6; let mut b_f128: f128 = 2.1; a_f128 % b_f128; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + b_f128 % a_f128; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + b_f128 %= a_f128; - //~^ ERROR: you are using modulo operator on types that might have different signs - //~| NOTE: double check for expected result especially when interoperating with differ + //~^ modulo_arithmetic + + // 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 2b4937552bda..9eb9a328664b 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -9,7 +9,7 @@ LL | -1.6 % 2.1; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> tests/ui/modulo_arithmetic_float.rs:11:5 + --> tests/ui/modulo_arithmetic_float.rs:12:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -17,7 +17,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` - --> tests/ui/modulo_arithmetic_float.rs:14:5 + --> tests/ui/modulo_arithmetic_float.rs:16:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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` - --> tests/ui/modulo_arithmetic_float.rs:17:5 + --> tests/ui/modulo_arithmetic_float.rs:20:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/modulo_arithmetic_float.rs:24:5 + --> tests/ui/modulo_arithmetic_float.rs:28:5 | LL | a_f16 % b_f16; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | a_f16 % b_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:27:5 + --> tests/ui/modulo_arithmetic_float.rs:32:5 | LL | b_f16 % a_f16; | ^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | b_f16 % a_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:30:5 + --> tests/ui/modulo_arithmetic_float.rs:36:5 | LL | b_f16 %= a_f16; | ^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | b_f16 %= a_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:37:5 + --> tests/ui/modulo_arithmetic_float.rs:44:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/modulo_arithmetic_float.rs:40:5 + --> tests/ui/modulo_arithmetic_float.rs:48:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/modulo_arithmetic_float.rs:43:5 + --> tests/ui/modulo_arithmetic_float.rs:52:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -81,7 +81,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 - --> tests/ui/modulo_arithmetic_float.rs:49:5 + --> tests/ui/modulo_arithmetic_float.rs:59:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -89,7 +89,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 - --> tests/ui/modulo_arithmetic_float.rs:52:5 + --> tests/ui/modulo_arithmetic_float.rs:63:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -97,7 +97,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 - --> tests/ui/modulo_arithmetic_float.rs:55:5 + --> tests/ui/modulo_arithmetic_float.rs:67:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/modulo_arithmetic_float.rs:61:5 + --> tests/ui/modulo_arithmetic_float.rs:74:5 | LL | a_f128 % b_f128; | ^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ LL | a_f128 % b_f128; = 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 - --> tests/ui/modulo_arithmetic_float.rs:64:5 + --> tests/ui/modulo_arithmetic_float.rs:78:5 | LL | b_f128 % a_f128; | ^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | b_f128 % a_f128; = 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 - --> tests/ui/modulo_arithmetic_float.rs:67:5 + --> tests/ui/modulo_arithmetic_float.rs:82:5 | LL | b_f128 %= a_f128; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral.rs b/tests/ui/modulo_arithmetic_integral.rs index c427b8580e17..e3a6df7c88f3 100644 --- a/tests/ui/modulo_arithmetic_integral.rs +++ b/tests/ui/modulo_arithmetic_integral.rs @@ -6,77 +6,94 @@ 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + // 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 f1cfe791a03b..32cf45240c1b 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -10,7 +10,7 @@ LL | a % b; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_integral.rs:11:5 + --> tests/ui/modulo_arithmetic_integral.rs:12:5 | LL | b % a; | ^^^^^ @@ -19,7 +19,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 - --> tests/ui/modulo_arithmetic_integral.rs:14:5 + --> tests/ui/modulo_arithmetic_integral.rs:16:5 | LL | b %= a; | ^^^^^^ @@ -28,7 +28,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 - --> tests/ui/modulo_arithmetic_integral.rs:20:5 + --> tests/ui/modulo_arithmetic_integral.rs:23:5 | LL | a_i8 % b_i8; | ^^^^^^^^^^^ @@ -37,7 +37,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 - --> tests/ui/modulo_arithmetic_integral.rs:23:5 + --> tests/ui/modulo_arithmetic_integral.rs:27:5 | LL | b_i8 %= a_i8; | ^^^^^^^^^^^^ @@ -46,7 +46,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 - --> tests/ui/modulo_arithmetic_integral.rs:29:5 + --> tests/ui/modulo_arithmetic_integral.rs:34:5 | LL | a_i16 % b_i16; | ^^^^^^^^^^^^^ @@ -55,7 +55,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 - --> tests/ui/modulo_arithmetic_integral.rs:32:5 + --> tests/ui/modulo_arithmetic_integral.rs:38:5 | LL | b_i16 %= a_i16; | ^^^^^^^^^^^^^^ @@ -64,7 +64,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 - --> tests/ui/modulo_arithmetic_integral.rs:38:5 + --> tests/ui/modulo_arithmetic_integral.rs:45:5 | LL | a_i32 % b_i32; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/modulo_arithmetic_integral.rs:41:5 + --> tests/ui/modulo_arithmetic_integral.rs:49:5 | LL | b_i32 %= a_i32; | ^^^^^^^^^^^^^^ @@ -82,7 +82,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 - --> tests/ui/modulo_arithmetic_integral.rs:47:5 + --> tests/ui/modulo_arithmetic_integral.rs:56:5 | LL | a_i64 % b_i64; | ^^^^^^^^^^^^^ @@ -91,7 +91,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 - --> tests/ui/modulo_arithmetic_integral.rs:50:5 + --> tests/ui/modulo_arithmetic_integral.rs:60:5 | LL | b_i64 %= a_i64; | ^^^^^^^^^^^^^^ @@ -100,7 +100,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 - --> tests/ui/modulo_arithmetic_integral.rs:56:5 + --> tests/ui/modulo_arithmetic_integral.rs:67:5 | LL | a_i128 % b_i128; | ^^^^^^^^^^^^^^^ @@ -109,7 +109,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 - --> tests/ui/modulo_arithmetic_integral.rs:59:5 + --> tests/ui/modulo_arithmetic_integral.rs:71:5 | LL | b_i128 %= a_i128; | ^^^^^^^^^^^^^^^^ @@ -118,7 +118,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 - --> tests/ui/modulo_arithmetic_integral.rs:65:5 + --> tests/ui/modulo_arithmetic_integral.rs:78:5 | LL | a_isize % b_isize; | ^^^^^^^^^^^^^^^^^ @@ -127,7 +127,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 - --> tests/ui/modulo_arithmetic_integral.rs:68:5 + --> tests/ui/modulo_arithmetic_integral.rs:82:5 | LL | b_isize %= a_isize; | ^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,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 - --> tests/ui/modulo_arithmetic_integral.rs:74:5 + --> tests/ui/modulo_arithmetic_integral.rs:89:5 | LL | a % b; | ^^^^^ @@ -145,7 +145,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 - --> tests/ui/modulo_arithmetic_integral.rs:77:5 + --> tests/ui/modulo_arithmetic_integral.rs:93:5 | LL | b %= a; | ^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral_const.rs b/tests/ui/modulo_arithmetic_integral_const.rs index dbc679a69825..ddcf4b219073 100644 --- a/tests/ui/modulo_arithmetic_integral_const.rs +++ b/tests/ui/modulo_arithmetic_integral_const.rs @@ -9,57 +9,74 @@ 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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + (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 + //~^ modulo_arithmetic + + (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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + -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 + //~^ modulo_arithmetic + + 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 + //~^ modulo_arithmetic + + // 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 722d9b83660e..49a5a2c6433a 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -10,7 +10,7 @@ LL | -1 % 2; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1 % -2` - --> tests/ui/modulo_arithmetic_integral_const.rs:14:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:15:5 | LL | 1 % -2; | ^^^^^^ @@ -19,7 +19,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:17:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:19:5 | LL | (1 - 2) % (1 + 2); | ^^^^^^^^^^^^^^^^^ @@ -28,7 +28,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:20:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:23:5 | LL | (1 + 2) % (1 - 2); | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:23:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:27:5 | LL | 35 * (7 - 4 * 2) % (-500 * -600); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:27:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:32:5 | LL | -1i8 % 2i8; | ^^^^^^^^^^ @@ -55,7 +55,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:30:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:36:5 | LL | 1i8 % -2i8; | ^^^^^^^^^^ @@ -64,7 +64,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:33:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:40:5 | LL | -1i16 % 2i16; | ^^^^^^^^^^^^ @@ -73,7 +73,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:36:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:44:5 | LL | 1i16 % -2i16; | ^^^^^^^^^^^^ @@ -82,7 +82,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:39:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:48:5 | LL | -1i32 % 2i32; | ^^^^^^^^^^^^ @@ -91,7 +91,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:42:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:52:5 | LL | 1i32 % -2i32; | ^^^^^^^^^^^^ @@ -100,7 +100,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:45:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:56:5 | LL | -1i64 % 2i64; | ^^^^^^^^^^^^ @@ -109,7 +109,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:48:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:60:5 | LL | 1i64 % -2i64; | ^^^^^^^^^^^^ @@ -118,7 +118,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:51:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:64:5 | LL | -1i128 % 2i128; | ^^^^^^^^^^^^^^ @@ -127,7 +127,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:54:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:68:5 | LL | 1i128 % -2i128; | ^^^^^^^^^^^^^^ @@ -136,7 +136,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:57:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:72:5 | LL | -1isize % 2isize; | ^^^^^^^^^^^^^^^^ @@ -145,7 +145,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:60:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:76:5 | LL | 1isize % -2isize; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index c332a15f1577..6ad038e60744 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -1,4 +1,5 @@ #![warn(clippy::modulo_one)] +#![allow(unconditional_panic)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::identity_op)] static STATIC_ONE: usize = 2 - 1; @@ -6,33 +7,35 @@ 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` + //~^ modulo_one + + 10 % -1; - //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 + //~^ modulo_one + 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 + //~^ modulo_one 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 + //~^ modulo_one + // NOT caught by lint 5 % STATIC_ONE; 2 % NEG_ONE; - //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 + //~^ modulo_one + // 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 + //~^ modulo_one + // Not caught by lint, we don't look into static items, even if entirely immutable. INT_MIN % STATIC_NEG_ONE; } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index aedcf24eae71..1eb886123d85 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,19 +1,5 @@ -error: this operation will panic at runtime - --> tests/ui/modulo_one.rs:15:5 - | -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 - --> tests/ui/modulo_one.rs:33:5 - | -LL | INT_MIN % NEG_ONE; - | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow - error: any number modulo 1 will be 0 - --> tests/ui/modulo_one.rs:8:5 + --> tests/ui/modulo_one.rs:9:5 | LL | 10 % 1; | ^^^^^^ @@ -22,34 +8,34 @@ LL | 10 % 1; = help: to override `-D warnings` add `#[allow(clippy::modulo_one)]` error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:11:5 + --> tests/ui/modulo_one.rs:13:5 | LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:15:5 + --> tests/ui/modulo_one.rs:18:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> tests/ui/modulo_one.rs:24:5 + --> tests/ui/modulo_one.rs:25:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:28:5 + --> tests/ui/modulo_one.rs:30:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:33:5 + --> tests/ui/modulo_one.rs:36:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/multi_assignments.rs b/tests/ui/multi_assignments.rs index cdbf13b68889..651cdc5773de 100644 --- a/tests/ui/multi_assignments.rs +++ b/tests/ui/multi_assignments.rs @@ -2,15 +2,21 @@ 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` + //~^ multi_assignments + + a = b = c = d; - //~^ ERROR: assignments don't nest intuitively - //~| ERROR: assignments don't nest intuitively + //~^ multi_assignments + //~| multi_assignments + + a = b = { c }; - //~^ ERROR: assignments don't nest intuitively + //~^ multi_assignments + a = { b = c }; - //~^ ERROR: assignments don't nest intuitively + //~^ multi_assignments + a = (b = c); - //~^ ERROR: assignments don't nest intuitively + //~^ multi_assignments + } diff --git a/tests/ui/multi_assignments.stderr b/tests/ui/multi_assignments.stderr index 53c22fcdb4c0..3c5bbcdea5f3 100644 --- a/tests/ui/multi_assignments.stderr +++ b/tests/ui/multi_assignments.stderr @@ -8,31 +8,31 @@ LL | a = b = c; = help: to override `-D warnings` add `#[allow(clippy::multi_assignments)]` error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:7:5 + --> tests/ui/multi_assignments.rs:8:5 | LL | a = b = c = d; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:7:9 + --> tests/ui/multi_assignments.rs:8:9 | LL | a = b = c = d; | ^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:10:5 + --> tests/ui/multi_assignments.rs:13:5 | LL | a = b = { c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:12:5 + --> tests/ui/multi_assignments.rs:16:5 | LL | a = { b = c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:14:5 + --> tests/ui/multi_assignments.rs:19:5 | LL | a = (b = c); | ^^^^^^^^^^^ diff --git a/tests/ui/multiple_bound_locations.rs b/tests/ui/multiple_bound_locations.rs index de9d994782ec..45524c90b7f2 100644 --- a/tests/ui/multiple_bound_locations.rs +++ b/tests/ui/multiple_bound_locations.rs @@ -1,21 +1,24 @@ #![warn(clippy::multiple_bound_locations)] fn ty(a: F) -//~^ ERROR: bound is defined in more than one place +//~^ multiple_bound_locations + where F: Sized, { } fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) -//~^ ERROR: bound is defined in more than one place +//~^ multiple_bound_locations + where 'b: 'c, { } fn ty_pred() -//~^ ERROR: bound is defined in more than one place +//~^ multiple_bound_locations + where for<'a> F: Send + 'a, { @@ -25,21 +28,24 @@ struct B; impl B { fn ty(a: F) - //~^ ERROR: bound is defined in more than one place + //~^ multiple_bound_locations + where F: Sized, { } fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) - //~^ ERROR: bound is defined in more than one place + //~^ multiple_bound_locations + where 'b: 'c, { } fn ty_pred() - //~^ ERROR: bound is defined in more than one place + //~^ multiple_bound_locations + where for<'a> F: Send + 'a, { diff --git a/tests/ui/multiple_bound_locations.stderr b/tests/ui/multiple_bound_locations.stderr index 22dd2e0a5524..bccc57fe7054 100644 --- a/tests/ui/multiple_bound_locations.stderr +++ b/tests/ui/multiple_bound_locations.stderr @@ -11,7 +11,7 @@ LL | F: Sized, = help: to override `-D warnings` add `#[allow(clippy::multiple_bound_locations)]` error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:10:17 + --> tests/ui/multiple_bound_locations.rs:11:17 | LL | fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) | ^^ @@ -20,7 +20,7 @@ LL | 'b: 'c, | ^^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:17:12 + --> tests/ui/multiple_bound_locations.rs:19:12 | LL | fn ty_pred() | ^ @@ -29,7 +29,7 @@ LL | for<'a> F: Send + 'a, | ^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:27:11 + --> tests/ui/multiple_bound_locations.rs:30:11 | LL | fn ty(a: F) | ^ @@ -38,7 +38,7 @@ LL | F: Sized, | ^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:34:21 + --> tests/ui/multiple_bound_locations.rs:38:21 | LL | fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) | ^^ @@ -47,7 +47,7 @@ LL | 'b: 'c, | ^^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:41:16 + --> tests/ui/multiple_bound_locations.rs:46:16 | LL | fn ty_pred() | ^ diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index 87d3517cd5f2..cc5d455f78cf 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -36,6 +36,7 @@ static mut STATIC: i32 = 0; fn test1() { unsafe { + //~^ multiple_unsafe_ops_per_block STATIC += 1; not_very_safe(); } @@ -45,6 +46,7 @@ fn test2() { let u = U { i: 0 }; unsafe { + //~^ multiple_unsafe_ops_per_block drop(u.u); *raw_ptr(); } @@ -52,6 +54,7 @@ fn test2() { fn test3() { unsafe { + //~^ multiple_unsafe_ops_per_block asm!("nop"); sample.not_very_safe(); STATIC = 0; @@ -61,6 +64,7 @@ fn test3() { fn test_all() { let u = U { i: 0 }; unsafe { + //~^ multiple_unsafe_ops_per_block drop(u.u); drop(STATIC); sample.not_very_safe(); @@ -105,6 +109,7 @@ fn correct3() { unsafe fn read_char_bad(ptr: *const u8) -> char { unsafe { char::from_u32_unchecked(*ptr.cast::()) } + //~^ multiple_unsafe_ops_per_block } // no lint @@ -123,6 +128,7 @@ fn issue10259() { fn _fn_ptr(x: unsafe fn()) { unsafe { + //~^ multiple_unsafe_ops_per_block x(); x(); } @@ -134,6 +140,7 @@ fn _assoc_const() { } fn _f() { unsafe { + //~^ multiple_unsafe_ops_per_block T::X(); T::X(); } @@ -144,6 +151,7 @@ fn _field_fn_ptr(x: unsafe fn()) { struct X(unsafe fn()); let x = X(x); unsafe { + //~^ multiple_unsafe_ops_per_block x.0(); x.0(); } diff --git a/tests/ui/multiple_unsafe_ops_per_block.stderr b/tests/ui/multiple_unsafe_ops_per_block.stderr index a9417a9ef91c..3130cecc2525 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.stderr +++ b/tests/ui/multiple_unsafe_ops_per_block.stderr @@ -2,18 +2,19 @@ error: this `unsafe` block contains 2 unsafe operations, expected only one --> tests/ui/multiple_unsafe_ops_per_block.rs:38:5 | LL | / unsafe { +LL | | LL | | STATIC += 1; LL | | not_very_safe(); LL | | } | |_____^ | note: modification of a mutable static occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:39:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:40:9 | LL | STATIC += 1; | ^^^^^^^^^^^ note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:40:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:41:9 | LL | not_very_safe(); | ^^^^^^^^^^^^^^^ @@ -21,29 +22,31 @@ LL | not_very_safe(); = help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]` error: this `unsafe` block contains 2 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:47:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:48:5 | LL | / unsafe { +LL | | LL | | drop(u.u); LL | | *raw_ptr(); LL | | } | |_____^ | note: union field access occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:48:14 + --> tests/ui/multiple_unsafe_ops_per_block.rs:50:14 | LL | drop(u.u); | ^^^ note: raw pointer dereference occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:49:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:51:9 | LL | *raw_ptr(); | ^^^^^^^^^^ error: this `unsafe` block contains 3 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:54:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:56:5 | LL | / unsafe { +LL | | LL | | asm!("nop"); LL | | sample.not_very_safe(); LL | | STATIC = 0; @@ -51,137 +54,140 @@ LL | | } | |_____^ | note: inline assembly used here - --> tests/ui/multiple_unsafe_ops_per_block.rs:55:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:58:9 | LL | asm!("nop"); | ^^^^^^^^^^^ note: unsafe method call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:56:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:59:9 | LL | sample.not_very_safe(); | ^^^^^^^^^^^^^^^^^^^^^^ note: modification of a mutable static occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:57:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:60:9 | LL | STATIC = 0; | ^^^^^^^^^^ error: this `unsafe` block contains 6 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:63:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:66:5 | LL | / unsafe { +LL | | LL | | drop(u.u); LL | | drop(STATIC); -LL | | sample.not_very_safe(); ... | LL | | asm!("nop"); LL | | } | |_____^ | note: union field access occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:64:14 + --> tests/ui/multiple_unsafe_ops_per_block.rs:68:14 | LL | drop(u.u); | ^^^ note: access of a mutable static occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:65:14 + --> tests/ui/multiple_unsafe_ops_per_block.rs:69:14 | LL | drop(STATIC); | ^^^^^^ note: unsafe method call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:66:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:70:9 | LL | sample.not_very_safe(); | ^^^^^^^^^^^^^^^^^^^^^^ note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:67:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:71:9 | LL | not_very_safe(); | ^^^^^^^^^^^^^^^ note: raw pointer dereference occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:68:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:72:9 | LL | *raw_ptr(); | ^^^^^^^^^^ note: inline assembly used here - --> tests/ui/multiple_unsafe_ops_per_block.rs:69:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:73:9 | LL | asm!("nop"); | ^^^^^^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:107:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:111:5 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:107:14 + --> tests/ui/multiple_unsafe_ops_per_block.rs:111:14 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: raw pointer dereference occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:107:39 + --> tests/ui/multiple_unsafe_ops_per_block.rs:111:39 | LL | unsafe { char::from_u32_unchecked(*ptr.cast::()) } | ^^^^^^^^^^^^^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:125:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:130:5 | LL | / unsafe { +LL | | LL | | x(); LL | | x(); LL | | } | |_____^ | note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:126:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:132:9 | LL | x(); | ^^^ note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:127:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:133:9 | LL | x(); | ^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:136:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:142:9 | LL | / unsafe { +LL | | LL | | T::X(); LL | | T::X(); LL | | } | |_________^ | note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:137:13 + --> tests/ui/multiple_unsafe_ops_per_block.rs:144:13 | LL | T::X(); | ^^^^^^ note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:138:13 + --> tests/ui/multiple_unsafe_ops_per_block.rs:145:13 | LL | T::X(); | ^^^^^^ error: this `unsafe` block contains 2 unsafe operations, expected only one - --> tests/ui/multiple_unsafe_ops_per_block.rs:146:5 + --> tests/ui/multiple_unsafe_ops_per_block.rs:153:5 | LL | / unsafe { +LL | | LL | | x.0(); LL | | x.0(); LL | | } | |_____^ | note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:147:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:155:9 | LL | x.0(); | ^^^^^ note: unsafe function call occurs here - --> tests/ui/multiple_unsafe_ops_per_block.rs:148:9 + --> tests/ui/multiple_unsafe_ops_per_block.rs:156:9 | LL | x.0(); | ^^^^^ diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 2459af606884..7c70c7f6399f 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -14,11 +14,13 @@ pub struct MyAtomic(AtomicBool); pub struct MyPure; #[must_use] pub fn pure(i: u8) -> u8 { +//~^ must_use_candidate i } impl MyPure { #[must_use] pub fn inherent_pure(&self) -> u8 { + //~^ must_use_candidate 0 } } @@ -50,6 +52,7 @@ pub fn with_callback bool>(f: &F) -> bool { } #[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { +//~^ must_use_candidate true } @@ -62,6 +65,7 @@ pub fn atomics(b: &AtomicBool) -> bool { } #[must_use] pub fn rcd(_x: Rc) -> bool { +//~^ must_use_candidate true } @@ -70,6 +74,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { } #[must_use] pub fn arcd(_x: Arc) -> bool { +//~^ must_use_candidate false } diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index 5f9b2449552a..a422e952dbcd 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -14,11 +14,13 @@ pub struct MyAtomic(AtomicBool); pub struct MyPure; pub fn pure(i: u8) -> u8 { +//~^ must_use_candidate i } impl MyPure { pub fn inherent_pure(&self) -> u8 { + //~^ must_use_candidate 0 } } @@ -50,6 +52,7 @@ pub fn with_callback bool>(f: &F) -> bool { } pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { +//~^ must_use_candidate true } @@ -62,6 +65,7 @@ pub fn atomics(b: &AtomicBool) -> bool { } pub fn rcd(_x: Rc) -> bool { +//~^ must_use_candidate true } @@ -70,6 +74,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { } pub fn arcd(_x: Arc) -> bool { +//~^ must_use_candidate false } diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 2117e37866e2..590253d95f9e 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 { = help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]` error: this method could have a `#[must_use]` attribute - --> tests/ui/must_use_candidates.rs:21:5 + --> tests/ui/must_use_candidates.rs:22: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 - --> tests/ui/must_use_candidates.rs:52:1 + --> tests/ui/must_use_candidates.rs:54: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 - --> tests/ui/must_use_candidates.rs:64:1 + --> tests/ui/must_use_candidates.rs:67: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 - --> tests/ui/must_use_candidates.rs:72:1 + --> tests/ui/must_use_candidates.rs:76: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 b92d9379c904..5a8603ceb562 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -7,10 +7,13 @@ extern crate proc_macros; use proc_macros::external; pub fn must_use_default() {} +//~^ must_use_unit pub fn must_use_unit() -> () {} +//~^ must_use_unit pub fn must_use_with_note() {} +//~^ must_use_unit fn main() { must_use_default(); @@ -26,6 +29,8 @@ fn main() { #[cfg_attr(all(), deprecated)] fn issue_12320() {} +//~^ must_use_unit #[cfg_attr(all(), deprecated, doc = "foo")] fn issue_12320_2() {} +//~^ must_use_unit diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index c77e72827504..ab2764841cb4 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -8,12 +8,15 @@ use proc_macros::external; #[must_use] pub fn must_use_default() {} +//~^ must_use_unit #[must_use] pub fn must_use_unit() -> () {} +//~^ must_use_unit #[must_use = "With note"] pub fn must_use_with_note() {} +//~^ must_use_unit fn main() { must_use_default(); @@ -29,6 +32,8 @@ fn main() { #[cfg_attr(all(), must_use, deprecated)] fn issue_12320() {} +//~^ must_use_unit #[cfg_attr(all(), deprecated, doc = "foo", must_use)] fn issue_12320_2() {} +//~^ must_use_unit diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index b435568deeab..3df9738a9693 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -10,7 +10,7 @@ LL | pub fn must_use_default() {} = help: to override `-D warnings` add `#[allow(clippy::must_use_unit)]` error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:13:1 + --> tests/ui/must_use_unit.rs:14:1 | LL | #[must_use] | ----------- help: remove the attribute @@ -18,7 +18,7 @@ LL | pub fn must_use_unit() -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:16:1 + --> tests/ui/must_use_unit.rs:18:1 | LL | #[must_use = "With note"] | ------------------------- help: remove the attribute @@ -26,7 +26,7 @@ LL | pub fn must_use_with_note() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:31:1 + --> tests/ui/must_use_unit.rs:34:1 | LL | #[cfg_attr(all(), must_use, deprecated)] | -------------------- help: change these attributes to: `deprecated` @@ -34,7 +34,7 @@ LL | fn issue_12320() {} | ^^^^^^^^^^^^^^^^ error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:34:1 + --> tests/ui/must_use_unit.rs:38:1 | LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] | --------------------------------- help: change these attributes to: `deprecated, doc = "foo"` diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index 0ab6d77de1e1..d2d82135d641 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -5,14 +5,16 @@ struct Foo; impl Foo { fn this_wont_hurt_a_bit(&self) -> &mut Foo { - //~^ ERROR: mutable borrow from immutable input(s) + //~^ mut_from_ref + unsafe { unimplemented!() } } } trait Ouch { fn ouch(x: &Foo) -> &mut Foo; - //~^ ERROR: mutable borrow from immutable input(s) + //~^ mut_from_ref + } impl Ouch for Foo { @@ -22,17 +24,20 @@ impl Ouch for Foo { } fn fail(x: &u32) -> &mut u16 { - //~^ ERROR: mutable borrow from immutable input(s) +//~^ mut_from_ref + unsafe { unimplemented!() } } fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { - //~^ ERROR: mutable borrow from immutable input(s) +//~^ mut_from_ref + 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) +//~^ mut_from_ref + unsafe { unimplemented!() } } @@ -47,7 +52,8 @@ 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) +//~^ mut_from_ref + unimplemented!() } diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index 34fe91b5b3ac..593e7acdaed8 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -13,61 +13,61 @@ LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { = help: to override `-D warnings` add `#[allow(clippy::mut_from_ref)]` error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:14:25 + --> tests/ui/mut_from_ref.rs:15:25 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:14:16 + --> tests/ui/mut_from_ref.rs:15:16 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:24:21 + --> tests/ui/mut_from_ref.rs:26:21 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:24:12 + --> tests/ui/mut_from_ref.rs:26:12 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:29:50 + --> tests/ui/mut_from_ref.rs:32:50 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:29:25 + --> tests/ui/mut_from_ref.rs:32:25 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:34:67 + --> tests/ui/mut_from_ref.rs:38:67 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:34:27 + --> tests/ui/mut_from_ref.rs:38: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) - --> tests/ui/mut_from_ref.rs:49:35 + --> tests/ui/mut_from_ref.rs:54:35 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:49:26 + --> tests/ui/mut_from_ref.rs:54: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 43ff705c4775..55b7fe2bcca0 100644 --- a/tests/ui/mut_key.rs +++ b/tests/ui/mut_key.rs @@ -29,11 +29,14 @@ 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 +//~^ mutable_key_type +//~| mutable_key_type + + + let _other: HashMap = HashMap::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + m.keys().cloned().collect() } @@ -61,7 +64,8 @@ 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 +//~^ mutable_key_type + fn main() { let _ = should_not_take_this_arg(&mut HashMap::new(), 1); @@ -74,29 +78,40 @@ fn main() { raw_mut_ptr_is_ok(&mut HashMap::new()); let _map = HashMap::, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::<&mut Cell, usize>::new(); - //~^ ERROR: mutable key type + //~^ 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 + //~^ mutable_key_type + let _map = HashMap::, ()>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::>>, usize>::new(); - //~^ ERROR: mutable key type + //~^ 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 + //~^ mutable_key_type + let _map = HashMap::>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + let _map = HashMap::>, usize>::new(); - //~^ ERROR: mutable key type + //~^ mutable_key_type + // Not interior mutability let _map = HashMap::<&mut usize, usize>::new(); diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index 8698ed4fd678..1887604b080a 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -21,7 +21,7 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:35:5 + --> tests/ui/mut_key.rs:37:5 | LL | let _other: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | let _other: HashMap = HashMap::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:63:22 + --> tests/ui/mut_key.rs:66:22 | LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:76:5 + --> tests/ui/mut_key.rs:80:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL | let _map = HashMap::, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:78:5 + --> tests/ui/mut_key.rs:83:5 | LL | let _map = HashMap::<&mut Cell, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _map = HashMap::<&mut Cell, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:81:5 + --> tests/ui/mut_key.rs:87:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:83:5 + --> tests/ui/mut_key.rs:90:5 | LL | let _map = HashMap::, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _map = HashMap::, ()>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:85:5 + --> tests/ui/mut_key.rs:93:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:87:5 + --> tests/ui/mut_key.rs:96:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:89:5 + --> tests/ui/mut_key.rs:99:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:91:5 + --> tests/ui/mut_key.rs:102:5 | LL | let _map = HashMap::>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _map = HashMap::>>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:94:5 + --> tests/ui/mut_key.rs:106:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:96:5 + --> tests/ui/mut_key.rs:109:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -142,7 +142,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:98:5 + --> tests/ui/mut_key.rs:112:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index 4c45bc980265..47f52621794b 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -13,6 +13,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; fn fun(x: &mut &mut u32) -> bool { +//~^ mut_mut **x > 0 } @@ -30,21 +31,29 @@ macro_rules! mut_ptr { #[inline_macros] fn main() { let mut x = &mut &mut 1u32; + //~^ mut_mut { let mut y = &mut x; + //~^ mut_mut } if fun(x) { let y: &mut &mut u32 = &mut &mut 2; + //~^ mut_mut + //~| mut_mut **y + **x; } if fun(x) { let y: &mut &mut &mut u32 = &mut &mut &mut 2; + //~^ mut_mut + //~| mut_mut + //~| mut_mut ***y + **x; } let mut z = inline!(&mut $(&mut 3u32)); + //~^ mut_mut } fn issue939() { diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 42853fdc008c..74b0c9ba145a 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -8,13 +8,13 @@ LL | fn fun(x: &mut &mut u32) -> bool { = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:32:17 + --> tests/ui/mut_mut.rs:33:17 | LL | let mut x = &mut &mut 1u32; | ^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:47:25 + --> tests/ui/mut_mut.rs:55:25 | LL | let mut z = inline!(&mut $(&mut 3u32)); | ^ @@ -22,37 +22,37 @@ LL | let mut z = inline!(&mut $(&mut 3u32)); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this expression mutably borrows a mutable reference. Consider reborrowing - --> tests/ui/mut_mut.rs:34:21 + --> tests/ui/mut_mut.rs:36:21 | LL | let mut y = &mut x; | ^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:38:32 + --> tests/ui/mut_mut.rs:41:32 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:38:16 + --> tests/ui/mut_mut.rs:41:16 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:43:37 + --> tests/ui/mut_mut.rs:48:37 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:43:16 + --> tests/ui/mut_mut.rs:48:16 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:43:21 + --> tests/ui/mut_mut.rs:48:21 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ diff --git a/tests/ui/mut_mutex_lock.fixed b/tests/ui/mut_mutex_lock.fixed index 29c5a27cb624..5790ee8c1b02 100644 --- a/tests/ui/mut_mutex_lock.fixed +++ b/tests/ui/mut_mutex_lock.fixed @@ -8,11 +8,13 @@ fn mut_mutex_lock() { let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); let mut value = value_mutex.get_mut().unwrap(); + //~^ mut_mutex_lock *value += 1; let mut value_mutex = Mutex::new(42_u8); let mut_ref_mut_ref_mutex = &mut &mut value_mutex; let mut value = mut_ref_mut_ref_mutex.get_mut().unwrap(); + //~^ mut_mutex_lock *value += 1; } diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs index fcdb3ff97dbc..7286afac823b 100644 --- a/tests/ui/mut_mutex_lock.rs +++ b/tests/ui/mut_mutex_lock.rs @@ -8,11 +8,13 @@ fn mut_mutex_lock() { let value_mutex = Arc::get_mut(&mut value_rc).unwrap(); let mut value = value_mutex.lock().unwrap(); + //~^ mut_mutex_lock *value += 1; let mut value_mutex = Mutex::new(42_u8); let mut_ref_mut_ref_mutex = &mut &mut value_mutex; let mut value = mut_ref_mut_ref_mutex.lock().unwrap(); + //~^ mut_mutex_lock *value += 1; } diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr index 92601c4c6121..67543c73c6ee 100644 --- a/tests/ui/mut_mutex_lock.stderr +++ b/tests/ui/mut_mutex_lock.stderr @@ -8,7 +8,7 @@ LL | let mut value = value_mutex.lock().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]` error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference - --> tests/ui/mut_mutex_lock.rs:15:43 + --> tests/ui/mut_mutex_lock.rs:16:43 | LL | let mut value = mut_ref_mut_ref_mutex.lock().unwrap(); | ^^^^ help: change this to: `get_mut` diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 7aebbf4981ee..326afb42ccb2 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -6,8 +6,9 @@ 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 + //~^ mut_range_bound + + } } @@ -15,8 +16,9 @@ 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 + //~^ mut_range_bound + + } } @@ -25,11 +27,13 @@ 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 + //~^ mut_range_bound + + n = 7; - //~^ ERROR: attempt to mutate range bound within loop - //~| NOTE: the range of the loop is unchanged + //~^ mut_range_bound + + } } @@ -44,8 +48,9 @@ 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 + //~^ mut_range_bound + + *n += 1; } } @@ -79,8 +84,9 @@ 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 + //~^ mut_range_bound + + if m == 4 { break; } @@ -91,8 +97,9 @@ 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 + //~^ mut_range_bound + + let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index 6f93b0ebe6fc..3dbc70f87f0f 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -9,7 +9,7 @@ LL | m = 5; = help: to override `-D warnings` add `#[allow(clippy::mut_range_bound)]` error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:17:9 + --> tests/ui/mut_range_bound.rs:18:9 | LL | m *= 2; | ^ @@ -17,7 +17,7 @@ LL | m *= 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:27:9 + --> tests/ui/mut_range_bound.rs:29:9 | LL | m = 5; | ^ @@ -25,7 +25,7 @@ LL | m = 5; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:30:9 + --> tests/ui/mut_range_bound.rs:33:9 | LL | n = 7; | ^ @@ -33,7 +33,7 @@ LL | n = 7; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:46:22 + --> tests/ui/mut_range_bound.rs:50:22 | LL | let n = &mut m; | ^ @@ -41,7 +41,7 @@ LL | let n = &mut m; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:81:9 + --> tests/ui/mut_range_bound.rs:86:9 | LL | m = 2; | ^ @@ -49,7 +49,7 @@ LL | m = 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:93:13 + --> tests/ui/mut_range_bound.rs:99:13 | LL | n = 1; | ^ diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 1d7faaa5e75e..4ae57940cf2d 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -28,16 +28,19 @@ impl MyStruct { 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` + //~^ unnecessary_mut_passed + + let as_ptr: fn(&i32) = takes_an_immutable_reference; as_ptr(&mut 42); - //~^ ERROR: the function `as_ptr` doesn't need a mutable reference + //~^ unnecessary_mut_passed + // 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 + //~^ unnecessary_mut_passed + // No error diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index 474221329c25..fb489360a1a3 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -8,13 +8,13 @@ LL | takes_an_immutable_reference(&mut 42); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]` error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/mut_reference.rs:34:12 + --> tests/ui/mut_reference.rs:35:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> tests/ui/mut_reference.rs:39:44 + --> tests/ui/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 3a51538b7424..993ea880d66b 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -6,32 +6,43 @@ 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_atomic + + Mutex::new(5usize); - //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan + //~^ mutex_atomic + Mutex::new(9isize); - //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan + //~^ mutex_atomic + 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_atomic + Mutex::new(&mut x as *mut u32); - //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want + //~^ mutex_atomic + Mutex::new(0u32); - //~^ ERROR: consider using an `AtomicU32` instead of a `Mutex` here; if you just wan - //~| NOTE: `-D clippy::mutex-integer` implied by `-D warnings` + //~^ mutex_integer + + Mutex::new(0i32); - //~^ ERROR: consider using an `AtomicI32` instead of a `Mutex` here; if you just wan + //~^ mutex_integer + Mutex::new(0f32); // there are no float atomics, so this should not lint Mutex::new(0u8); - //~^ ERROR: consider using an `AtomicU8` instead of a `Mutex` here; if you just wan + //~^ mutex_integer + Mutex::new(0i16); - //~^ ERROR: consider using an `AtomicI16` instead of a `Mutex` here; if you just wan + //~^ mutex_integer + let _x: Mutex = Mutex::new(0); - //~^ ERROR: consider using an `AtomicI8` instead of a `Mutex` here; if you just wan + //~^ mutex_integer + const X: i64 = 0; Mutex::new(X); - //~^ ERROR: consider using an `AtomicI64` instead of a `Mutex` here; if you just wan + //~^ mutex_integer + // there are no 128 atomics, so these two should not lint { diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 683a7b939db3..83be2ef995ce 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -8,31 +8,31 @@ LL | Mutex::new(true); = help: to override `-D warnings` add `#[allow(clippy::mutex_atomic)]` 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<()>` - --> tests/ui/mutex_atomic.rs:11:5 + --> tests/ui/mutex_atomic.rs:12: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<()>` - --> tests/ui/mutex_atomic.rs:13:5 + --> tests/ui/mutex_atomic.rs:15: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<()>` - --> tests/ui/mutex_atomic.rs:16:5 + --> tests/ui/mutex_atomic.rs:19: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<()>` - --> tests/ui/mutex_atomic.rs:18:5 + --> tests/ui/mutex_atomic.rs:22:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicU32` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:20:5 + --> tests/ui/mutex_atomic.rs:25:5 | LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ @@ -41,31 +41,31 @@ LL | Mutex::new(0u32); = help: to override `-D warnings` add `#[allow(clippy::mutex_integer)]` error: consider using an `AtomicI32` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:23:5 + --> tests/ui/mutex_atomic.rs:29:5 | LL | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ error: consider using an `AtomicU8` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:26:5 + --> tests/ui/mutex_atomic.rs:33:5 | LL | Mutex::new(0u8); | ^^^^^^^^^^^^^^^ error: consider using an `AtomicI16` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:28:5 + --> tests/ui/mutex_atomic.rs:36:5 | LL | Mutex::new(0i16); | ^^^^^^^^^^^^^^^^ error: consider using an `AtomicI8` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:30:25 + --> tests/ui/mutex_atomic.rs:39:25 | LL | let _x: Mutex = Mutex::new(0); | ^^^^^^^^^^^^^ error: consider using an `AtomicI64` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:33:5 + --> tests/ui/mutex_atomic.rs:43:5 | LL | Mutex::new(X); | ^^^^^^^^^^^^^ diff --git a/tests/ui/needless_arbitrary_self_type.fixed b/tests/ui/needless_arbitrary_self_type.fixed index 530eb77d83d2..22dd127f01f3 100644 --- a/tests/ui/needless_arbitrary_self_type.fixed +++ b/tests/ui/needless_arbitrary_self_type.fixed @@ -8,6 +8,7 @@ pub enum ValType { impl ValType { pub fn bad(self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -16,6 +17,7 @@ impl ValType { } pub fn mut_bad(mut self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -24,6 +26,7 @@ impl ValType { } pub fn ref_bad(&self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -32,6 +35,7 @@ impl ValType { } pub fn ref_bad_with_lifetime<'a>(&'a self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -40,6 +44,7 @@ impl ValType { } pub fn mut_ref_bad(&mut self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -48,6 +53,7 @@ impl ValType { } pub fn mut_ref_bad_with_lifetime<'a>(&'a mut self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -66,7 +72,9 @@ impl ValType { trait Foo<'r#struct> { fn f1(&'r#struct self) {} + //~^ needless_arbitrary_self_type fn f2(&'r#struct mut self) {} + //~^ needless_arbitrary_self_type } fn main() {} diff --git a/tests/ui/needless_arbitrary_self_type.rs b/tests/ui/needless_arbitrary_self_type.rs index 5a1ff96a11cc..5b1702bfdf96 100644 --- a/tests/ui/needless_arbitrary_self_type.rs +++ b/tests/ui/needless_arbitrary_self_type.rs @@ -8,6 +8,7 @@ pub enum ValType { impl ValType { pub fn bad(self: Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -16,6 +17,7 @@ impl ValType { } pub fn mut_bad(mut self: Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -24,6 +26,7 @@ impl ValType { } pub fn ref_bad(self: &Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -32,6 +35,7 @@ impl ValType { } pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -40,6 +44,7 @@ impl ValType { } pub fn mut_ref_bad(self: &mut Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -48,6 +53,7 @@ impl ValType { } pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -66,7 +72,9 @@ impl ValType { trait Foo<'r#struct> { fn f1(self: &'r#struct Self) {} + //~^ needless_arbitrary_self_type fn f2(self: &'r#struct mut Self) {} + //~^ needless_arbitrary_self_type } fn main() {} diff --git a/tests/ui/needless_arbitrary_self_type.stderr b/tests/ui/needless_arbitrary_self_type.stderr index 7ebbbaa122f5..b5c0aae8310f 100644 --- a/tests/ui/needless_arbitrary_self_type.stderr +++ b/tests/ui/needless_arbitrary_self_type.stderr @@ -8,43 +8,43 @@ LL | pub fn bad(self: Self) { = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` error: the type of the `self` parameter does not need to be arbitrary - --> tests/ui/needless_arbitrary_self_type.rs:18:20 + --> tests/ui/needless_arbitrary_self_type.rs:19: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 - --> tests/ui/needless_arbitrary_self_type.rs:26:20 + --> tests/ui/needless_arbitrary_self_type.rs:28: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 - --> tests/ui/needless_arbitrary_self_type.rs:34:38 + --> tests/ui/needless_arbitrary_self_type.rs:37: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 - --> tests/ui/needless_arbitrary_self_type.rs:42:24 + --> tests/ui/needless_arbitrary_self_type.rs:46: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 - --> tests/ui/needless_arbitrary_self_type.rs:50:42 + --> tests/ui/needless_arbitrary_self_type.rs:55:42 | LL | pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { | ^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a mut self` error: the type of the `self` parameter does not need to be arbitrary - --> tests/ui/needless_arbitrary_self_type.rs:68:11 + --> tests/ui/needless_arbitrary_self_type.rs:74:11 | LL | fn f1(self: &'r#struct Self) {} | ^^^^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'r#struct self` error: the type of the `self` parameter does not need to be arbitrary - --> tests/ui/needless_arbitrary_self_type.rs:69:11 + --> tests/ui/needless_arbitrary_self_type.rs:76:11 | LL | fn f2(self: &'r#struct mut Self) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'r#struct mut self` diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.fixed b/tests/ui/needless_arbitrary_self_type_unfixable.fixed index 62a6e5932435..f4ee0a8bd072 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.fixed +++ b/tests/ui/needless_arbitrary_self_type_unfixable.fixed @@ -40,6 +40,7 @@ mod issue_6089 { impl T2 for S2 { #[allow(clippy::needless_lifetimes)] fn call_with_mut_self(&mut self) {} + //~^ 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 00871f9f450c..3f29025c1362 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -40,6 +40,7 @@ mod issue_6089 { impl T2 for S2 { #[allow(clippy::needless_lifetimes)] fn call_with_mut_self(self: &mut Self) {} + //~^ needless_arbitrary_self_type } } diff --git a/tests/ui/needless_as_bytes.fixed b/tests/ui/needless_as_bytes.fixed index 74b4ba5be798..2f9e82218889 100644 --- a/tests/ui/needless_as_bytes.fixed +++ b/tests/ui/needless_as_bytes.fixed @@ -15,26 +15,34 @@ impl S { fn main() { if "some string".is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", "some string".len()); //~^ needless_as_bytes + } if "some string".is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", "some string".len()); //~^ needless_as_bytes + } let s = String::from("yet another string"); if s.is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", s.len()); //~^ needless_as_bytes + } if s.is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", s.len()); //~^ needless_as_bytes + } // Do not lint diff --git a/tests/ui/needless_as_bytes.rs b/tests/ui/needless_as_bytes.rs index ffcce60bbbef..2f0fc352d192 100644 --- a/tests/ui/needless_as_bytes.rs +++ b/tests/ui/needless_as_bytes.rs @@ -15,26 +15,34 @@ impl S { fn main() { if "some string".as_bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", "some string".as_bytes().len()); //~^ needless_as_bytes + } if "some string".bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", "some string".bytes().len()); //~^ needless_as_bytes + } let s = String::from("yet another string"); if s.as_bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", s.as_bytes().len()); //~^ needless_as_bytes + } if s.bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes + println!("len = {}", s.bytes().len()); //~^ needless_as_bytes + } // Do not lint diff --git a/tests/ui/needless_as_bytes.stderr b/tests/ui/needless_as_bytes.stderr index 138c6630ae7d..72746c05b8e2 100644 --- a/tests/ui/needless_as_bytes.stderr +++ b/tests/ui/needless_as_bytes.stderr @@ -8,43 +8,43 @@ LL | if "some string".as_bytes().is_empty() { = help: to override `-D warnings` add `#[allow(clippy::needless_as_bytes)]` error: needless call to `as_bytes` - --> tests/ui/needless_as_bytes.rs:19:30 + --> tests/ui/needless_as_bytes.rs:20:30 | LL | println!("len = {}", "some string".as_bytes().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:22:8 + --> tests/ui/needless_as_bytes.rs:24:8 | LL | if "some string".bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `"some string".is_empty()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:24:30 + --> tests/ui/needless_as_bytes.rs:27:30 | LL | println!("len = {}", "some string".bytes().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` error: needless call to `as_bytes` - --> tests/ui/needless_as_bytes.rs:29:8 + --> tests/ui/needless_as_bytes.rs:33:8 | LL | if s.as_bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` error: needless call to `as_bytes` - --> tests/ui/needless_as_bytes.rs:31:30 + --> tests/ui/needless_as_bytes.rs:36:30 | LL | println!("len = {}", s.as_bytes().len()); | ^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:34:8 + --> tests/ui/needless_as_bytes.rs:40:8 | LL | if s.bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:36:30 + --> tests/ui/needless_as_bytes.rs:43:30 | LL | println!("len = {}", s.bytes().len()); | ^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` diff --git a/tests/ui/needless_bitwise_bool.fixed b/tests/ui/needless_bitwise_bool.fixed index a8176618c1f2..7fc36e0f94b4 100644 --- a/tests/ui/needless_bitwise_bool.fixed +++ b/tests/ui/needless_bitwise_bool.fixed @@ -21,6 +21,7 @@ fn main() { println!("true") } if y && !x { + //~^ needless_bitwise_bool println!("true") } diff --git a/tests/ui/needless_bitwise_bool.rs b/tests/ui/needless_bitwise_bool.rs index f190eb2b76e7..dcbc08334a77 100644 --- a/tests/ui/needless_bitwise_bool.rs +++ b/tests/ui/needless_bitwise_bool.rs @@ -21,6 +21,7 @@ fn main() { println!("true") } if y & !x { + //~^ needless_bitwise_bool println!("true") } diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed index ec63c4fd6a26..0664abf0944d 100644 --- a/tests/ui/needless_bool/fixable.fixed +++ b/tests/ui/needless_bool/fixable.fixed @@ -39,17 +39,26 @@ fn main() { let x = true; let y = false; x; + //~^^^^^ needless_bool !x; + //~^^^^^ needless_bool !(x && y); + //~^^^^^ needless_bool let a = 0; let b = 1; a != b; + //~^^^^^ needless_bool a == b; + //~^^^^^ needless_bool a >= b; + //~^^^^^ needless_bool a > b; + //~^^^^^ needless_bool a <= b; + //~^^^^^ needless_bool a < b; + //~^^^^^ needless_bool if x { x } else { @@ -74,26 +83,32 @@ fn main() { fn bool_ret3(x: bool) -> bool { return x; + //~^^^^^ needless_bool } fn bool_ret4(x: bool) -> bool { return !x; + //~^^^^^ needless_bool } fn bool_ret5(x: bool, y: bool) -> bool { return x && y; + //~^^^^^ needless_bool } fn bool_ret6(x: bool, y: bool) -> bool { return !(x && y); + //~^^^^^ needless_bool } fn needless_bool(x: bool) { if x {}; + //~^ bool_comparison } fn needless_bool2(x: bool) { if !x {}; + //~^ bool_comparison } fn needless_bool3(x: bool) { @@ -104,7 +119,9 @@ fn needless_bool3(x: bool) { } if x {}; + //~^ bool_comparison if !x {}; + //~^ bool_comparison } fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { @@ -114,6 +131,7 @@ fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_b let x = if b { true } else { !returns_bool() }; + //~^^^^^ needless_bool } unsafe fn no(v: u8) -> u8 { @@ -123,10 +141,13 @@ unsafe fn no(v: u8) -> u8 { #[allow(clippy::unnecessary_operation)] fn needless_bool_condition() -> bool { (unsafe { no(4) } & 1 != 0); + //~^^^^^ needless_bool let _brackets_unneeded = unsafe { no(4) } & 1 != 0; + //~^ needless_bool fn foo() -> bool { // parentheses are needed here (unsafe { no(4) } & 1 != 0) + //~^ needless_bool } foo() @@ -138,8 +159,11 @@ fn issue12846() { // parentheses are needed here let _x = (a && b).then(|| todo!()); + //~^ needless_bool let _x = (a && b) as u8; + //~^ needless_bool // parentheses are not needed here let _x = a.then(|| todo!()); + //~^ needless_bool } diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs index 8694aa715908..7507a6af408b 100644 --- a/tests/ui/needless_bool/fixable.rs +++ b/tests/ui/needless_bool/fixable.rs @@ -43,16 +43,19 @@ fn main() { } else { false }; + //~^^^^^ needless_bool if x { false } else { true }; + //~^^^^^ needless_bool if x && y { false } else { true }; + //~^^^^^ needless_bool let a = 0; let b = 1; @@ -61,31 +64,37 @@ fn main() { } else { true }; + //~^^^^^ needless_bool if a != b { false } else { true }; + //~^^^^^ needless_bool if a < b { false } else { true }; + //~^^^^^ needless_bool if a <= b { false } else { true }; + //~^^^^^ needless_bool if a > b { false } else { true }; + //~^^^^^ needless_bool if a >= b { false } else { true }; + //~^^^^^ needless_bool if x { x } else { @@ -114,6 +123,7 @@ fn bool_ret3(x: bool) -> bool { } else { return false; }; + //~^^^^^ needless_bool } fn bool_ret4(x: bool) -> bool { @@ -122,6 +132,7 @@ fn bool_ret4(x: bool) -> bool { } else { return true; }; + //~^^^^^ needless_bool } fn bool_ret5(x: bool, y: bool) -> bool { @@ -130,6 +141,7 @@ fn bool_ret5(x: bool, y: bool) -> bool { } else { return false; }; + //~^^^^^ needless_bool } fn bool_ret6(x: bool, y: bool) -> bool { @@ -138,14 +150,17 @@ fn bool_ret6(x: bool, y: bool) -> bool { } else { return true; }; + //~^^^^^ needless_bool } fn needless_bool(x: bool) { if x == true {}; + //~^ bool_comparison } fn needless_bool2(x: bool) { if x == false {}; + //~^ bool_comparison } fn needless_bool3(x: bool) { @@ -156,7 +171,9 @@ fn needless_bool3(x: bool) { } if x == true {}; + //~^ bool_comparison if x == false {}; + //~^ bool_comparison } fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_brackets() { @@ -170,6 +187,7 @@ fn needless_bool_in_the_suggestion_wraps_the_predicate_of_if_else_statement_in_b } else { true }; + //~^^^^^ needless_bool } unsafe fn no(v: u8) -> u8 { @@ -183,10 +201,13 @@ fn needless_bool_condition() -> bool { } else { false }; + //~^^^^^ needless_bool let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false }; + //~^ needless_bool fn foo() -> bool { // parentheses are needed here if unsafe { no(4) } & 1 != 0 { true } else { false } + //~^ needless_bool } foo() @@ -198,8 +219,11 @@ fn issue12846() { // parentheses are needed here let _x = if a && b { true } else { false }.then(|| todo!()); + //~^ needless_bool let _x = if a && b { true } else { false } as u8; + //~^ needless_bool // parentheses are not needed here let _x = if a { true } else { false }.then(|| todo!()); + //~^ needless_bool } diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr index 99b5b9983448..3f117ee5a502 100644 --- a/tests/ui/needless_bool/fixable.stderr +++ b/tests/ui/needless_bool/fixable.stderr @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:46:5 + --> tests/ui/needless_bool/fixable.rs:47:5 | LL | / if x { LL | | false @@ -22,7 +22,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!x` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:51:5 + --> tests/ui/needless_bool/fixable.rs:53:5 | LL | / if x && y { LL | | false @@ -32,7 +32,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!(x && y)` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:59:5 + --> tests/ui/needless_bool/fixable.rs:62:5 | LL | / if a == b { LL | | false @@ -42,7 +42,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a != b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:64:5 + --> tests/ui/needless_bool/fixable.rs:68:5 | LL | / if a != b { LL | | false @@ -52,7 +52,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a == b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:69:5 + --> tests/ui/needless_bool/fixable.rs:74:5 | LL | / if a < b { LL | | false @@ -62,7 +62,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a >= b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:74:5 + --> tests/ui/needless_bool/fixable.rs:80:5 | LL | / if a <= b { LL | | false @@ -72,7 +72,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a > b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:79:5 + --> tests/ui/needless_bool/fixable.rs:86:5 | LL | / if a > b { LL | | false @@ -82,7 +82,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a <= b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:84:5 + --> tests/ui/needless_bool/fixable.rs:92:5 | LL | / if a >= b { LL | | false @@ -92,7 +92,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a < b` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:112:5 + --> tests/ui/needless_bool/fixable.rs:121:5 | LL | / if x { LL | | return true; @@ -102,7 +102,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:120:5 + --> tests/ui/needless_bool/fixable.rs:130:5 | LL | / if x { LL | | return false; @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !x` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:128:5 + --> tests/ui/needless_bool/fixable.rs:139:5 | LL | / if x && y { LL | | return true; @@ -122,7 +122,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x && y` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:136:5 + --> tests/ui/needless_bool/fixable.rs:148:5 | LL | / if x && y { LL | | return false; @@ -132,7 +132,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !(x && y)` error: equality checks against true are unnecessary - --> tests/ui/needless_bool/fixable.rs:144:8 + --> tests/ui/needless_bool/fixable.rs:157:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` @@ -141,25 +141,25 @@ LL | if x == true {}; = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation - --> tests/ui/needless_bool/fixable.rs:148:8 + --> tests/ui/needless_bool/fixable.rs:162:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> tests/ui/needless_bool/fixable.rs:158:8 + --> tests/ui/needless_bool/fixable.rs:173:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> tests/ui/needless_bool/fixable.rs:159:8 + --> tests/ui/needless_bool/fixable.rs:175:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:168:12 + --> tests/ui/needless_bool/fixable.rs:185:12 | LL | } else if returns_bool() { | ____________^ @@ -170,7 +170,7 @@ LL | | }; | |_____^ help: you can reduce it to: `{ !returns_bool() }` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:181:5 + --> tests/ui/needless_bool/fixable.rs:199:5 | LL | / if unsafe { no(4) } & 1 != 0 { LL | | true @@ -180,31 +180,31 @@ LL | | }; | |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:186:30 + --> tests/ui/needless_bool/fixable.rs:205: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 - --> tests/ui/needless_bool/fixable.rs:189:9 + --> tests/ui/needless_bool/fixable.rs:209:9 | LL | 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 - --> tests/ui/needless_bool/fixable.rs:200:14 + --> tests/ui/needless_bool/fixable.rs:221:14 | LL | let _x = if a && b { true } else { false }.then(|| todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a && b)` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:201:14 + --> tests/ui/needless_bool/fixable.rs:223:14 | LL | let _x = if a && b { true } else { false } as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a && b)` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:204:14 + --> tests/ui/needless_bool/fixable.rs:227:14 | LL | let _x = if a { true } else { false }.then(|| todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `a` diff --git a/tests/ui/needless_bool/simple.rs b/tests/ui/needless_bool/simple.rs index 588bb88f4461..40ffeae6c56f 100644 --- a/tests/ui/needless_bool/simple.rs +++ b/tests/ui/needless_bool/simple.rs @@ -16,11 +16,13 @@ fn main() { } else { true }; + //~^^^^^ needless_bool if x { false } else { false }; + //~^^^^^ needless_bool if x { x } else { @@ -36,6 +38,7 @@ fn bool_ret(x: bool) -> bool { } else { return true; }; + //~^^^^^ needless_bool } fn bool_ret2(x: bool) -> bool { @@ -44,4 +47,5 @@ fn bool_ret2(x: bool) -> bool { } else { return false; }; + //~^^^^^ needless_bool } diff --git a/tests/ui/needless_bool/simple.stderr b/tests/ui/needless_bool/simple.stderr deleted file mode 100644 index bf30a56f43e7..000000000000 --- a/tests/ui/needless_bool/simple.stderr +++ /dev/null @@ -1,45 +0,0 @@ -error: this if-then-else expression will always return true - --> tests/ui/needless_bool/simple.rs:14:5 - | -LL | / if x { -LL | | true -LL | | } else { -LL | | true -LL | | }; - | |_____^ - | - = note: `-D clippy::needless-bool` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` - -error: this if-then-else expression will always return false - --> tests/ui/needless_bool/simple.rs:19:5 - | -LL | / if x { -LL | | false -LL | | } else { -LL | | false -LL | | }; - | |_____^ - -error: this if-then-else expression will always return true - --> tests/ui/needless_bool/simple.rs:34:5 - | -LL | / if x { -LL | | return true; -LL | | } else { -LL | | return true; -LL | | }; - | |_____^ - -error: this if-then-else expression will always return false - --> tests/ui/needless_bool/simple.rs:42:5 - | -LL | / if x { -LL | | return false; -LL | | } else { -LL | | return false; -LL | | }; - | |_____^ - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_bool_assign.fixed b/tests/ui/needless_bool_assign.fixed index 7b10fe78c681..e0c717ecda21 100644 --- a/tests/ui/needless_bool_assign.fixed +++ b/tests/ui/needless_bool_assign.fixed @@ -11,7 +11,9 @@ fn main() { }; let mut a = Data { field: false }; a.field = random() && random(); + //~^^^^^ needless_bool_assign a.field = !(random() && random()); + //~^^^^^ needless_bool_assign // Do not lint… if random() { a.field = false; @@ -22,6 +24,8 @@ fn main() { // This one also triggers lint `clippy::if_same_then_else` // which does not suggest a rewrite. random(); a.field = true; + //~^^^^^ if_same_then_else + //~| needless_bool_assign let mut b = false; if random() { a.field = false; diff --git a/tests/ui/needless_bool_assign.rs b/tests/ui/needless_bool_assign.rs index 85c0a5777fee..3e4fecefa785 100644 --- a/tests/ui/needless_bool_assign.rs +++ b/tests/ui/needless_bool_assign.rs @@ -15,11 +15,13 @@ fn main() { } else { a.field = false } + //~^^^^^ needless_bool_assign if random() && random() { a.field = false; } else { a.field = true } + //~^^^^^ needless_bool_assign // Do not lint… if random() { a.field = false; @@ -34,6 +36,8 @@ fn main() { } else { a.field = true; } + //~^^^^^ if_same_then_else + //~| needless_bool_assign let mut b = false; if random() { a.field = false; diff --git a/tests/ui/needless_bool_assign.stderr b/tests/ui/needless_bool_assign.stderr deleted file mode 100644 index 2d80dded39c3..000000000000 --- a/tests/ui/needless_bool_assign.stderr +++ /dev/null @@ -1,55 +0,0 @@ -error: this if-then-else expression assigns a bool literal - --> tests/ui/needless_bool_assign.rs:13:5 - | -LL | / if random() && random() { -LL | | a.field = true; -LL | | } else { -LL | | a.field = false -LL | | } - | |_____^ help: you can reduce it to: `a.field = random() && random();` - | - = note: `-D clippy::needless-bool-assign` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::needless_bool_assign)]` - -error: this if-then-else expression assigns a bool literal - --> tests/ui/needless_bool_assign.rs:18:5 - | -LL | / if random() && random() { -LL | | a.field = false; -LL | | } else { -LL | | a.field = true -LL | | } - | |_____^ help: you can reduce it to: `a.field = !(random() && random());` - -error: this if-then-else expression assigns a bool literal - --> tests/ui/needless_bool_assign.rs:32:5 - | -LL | / if random() { -LL | | a.field = true; -LL | | } else { -LL | | a.field = true; -LL | | } - | |_____^ help: you can reduce it to: `random(); a.field = true;` - -error: this `if` has identical blocks - --> tests/ui/needless_bool_assign.rs:32:17 - | -LL | if random() { - | _________________^ -LL | | a.field = true; -LL | | } else { - | |_____^ - | -note: same as this - --> tests/ui/needless_bool_assign.rs:34:12 - | -LL | } else { - | ____________^ -LL | | a.field = true; -LL | | } - | |_____^ - = note: `-D clippy::if-same-then-else` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 2763830e09c9..7bd42d17f3a4 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -14,10 +14,12 @@ fn main() { let ref_a = &a; let _ = x(&a); // no warning let _ = x(&a); // warn + //~^ needless_borrow let mut b = 5; mut_ref(&mut b); // no warning mut_ref(&mut b); // warn + //~^ needless_borrow let s = &String::from("hi"); let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not @@ -30,14 +32,17 @@ fn main() { 45 => { println!("foo"); &a + //~^ needless_borrow }, 46 => &a, + //~^ needless_borrow 47 => { println!("foo"); loop { println!("{}", a); if a == 25 { break ref_a; + //~^ needless_borrow } } }, @@ -45,12 +50,17 @@ fn main() { }; let _ = x(&a); + //~^ needless_borrow let _ = x(&a); + //~^ needless_borrow let _ = x(&mut b); + //~^ needless_borrow let _ = x(ref_a); + //~^ needless_borrow { let b = &mut b; x(b); + //~^ needless_borrow } // Issue #8191 @@ -58,9 +68,13 @@ fn main() { let mut x = &mut x; mut_ref(x); + //~^ needless_borrow mut_ref(x); + //~^ needless_borrow let y: &mut i32 = x; + //~^ needless_borrow let y: &mut i32 = x; + //~^ needless_borrow let y = match 0 { // Don't lint. Removing the borrow would move 'x' @@ -70,12 +84,14 @@ fn main() { let y: &mut i32 = match 0 { // Lint here. The type given above triggers auto-borrow. 0 => x, + //~^ needless_borrow _ => &mut *x, }; fn ref_mut_i32(_: &mut i32) {} ref_mut_i32(match 0 { // Lint here. The type given above triggers auto-borrow. 0 => x, + //~^ needless_borrow _ => &mut *x, }); // use 'x' after to make sure it's still usable in the fixed code. @@ -88,8 +104,10 @@ fn main() { let x = (1, 2); let _ = x.0; + //~^ needless_borrow let x = &x as *const (i32, i32); let _ = unsafe { (*x).0 }; + //~^ needless_borrow // Issue #8367 trait Foo { @@ -100,6 +118,7 @@ fn main() { } (&()).foo(); // Don't lint. `()` doesn't implement `Foo` (&()).foo(); + //~^ needless_borrow impl Foo for i32 { fn foo(self) {} @@ -109,6 +128,7 @@ fn main() { } (&5).foo(); // Don't lint. `5` will call `::foo` (&5).foo(); + //~^ needless_borrow trait FooRef { fn foo_ref(&self); @@ -135,6 +155,7 @@ fn main() { // issue #11786 let x: (&str,) = ("",); + //~^ needless_borrow } #[allow(clippy::needless_borrowed_reference)] @@ -177,6 +198,7 @@ mod issue9160 { { fn calls_field(&self) -> T { (self.f)() + //~^ needless_borrow } } @@ -186,6 +208,7 @@ mod issue9160 { { fn calls_mut_field(&mut self) -> T { (self.f)() + //~^ needless_borrow } } } @@ -223,6 +246,7 @@ fn issue9383() { }; let _ = &mut (&mut x.u).x; let _ = &mut { x.u }.x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { @@ -230,11 +254,14 @@ fn issue9383() { }; let _ = &mut (&mut x.u).x; let _ = &mut { x.u }.x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(Foo { x: 0 }) }; let _ = &mut x.u.x; + //~^ needless_borrow let _ = &mut { x.u }.x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; } } @@ -256,6 +283,7 @@ fn issue_12268() { let option = Some((&1,)); let x = (&1,); option.unwrap_or((x.0,)); - //~^ ERROR: this expression creates a reference which is immediately dereferenced by the + //~^ needless_borrow + // compiler } diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index b46f82b18c64..a5b337140b5b 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -14,10 +14,12 @@ fn main() { let ref_a = &a; let _ = x(&a); // no warning let _ = x(&&a); // warn + //~^ needless_borrow let mut b = 5; mut_ref(&mut b); // no warning mut_ref(&mut &mut b); // warn + //~^ needless_borrow let s = &String::from("hi"); let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not @@ -30,14 +32,17 @@ fn main() { 45 => { println!("foo"); &&a + //~^ needless_borrow }, 46 => &&a, + //~^ needless_borrow 47 => { println!("foo"); loop { println!("{}", a); if a == 25 { break &ref_a; + //~^ needless_borrow } } }, @@ -45,12 +50,17 @@ fn main() { }; let _ = x(&&&a); + //~^ needless_borrow let _ = x(&mut &&a); + //~^ needless_borrow let _ = x(&&&mut b); + //~^ needless_borrow let _ = x(&&ref_a); + //~^ needless_borrow { let b = &mut b; x(&b); + //~^ needless_borrow } // Issue #8191 @@ -58,9 +68,13 @@ fn main() { let mut x = &mut x; mut_ref(&mut x); + //~^ needless_borrow mut_ref(&mut &mut x); + //~^ needless_borrow let y: &mut i32 = &mut x; + //~^ needless_borrow let y: &mut i32 = &mut &mut x; + //~^ needless_borrow let y = match 0 { // Don't lint. Removing the borrow would move 'x' @@ -70,12 +84,14 @@ fn main() { let y: &mut i32 = match 0 { // Lint here. The type given above triggers auto-borrow. 0 => &mut x, + //~^ needless_borrow _ => &mut *x, }; fn ref_mut_i32(_: &mut i32) {} ref_mut_i32(match 0 { // Lint here. The type given above triggers auto-borrow. 0 => &mut x, + //~^ needless_borrow _ => &mut *x, }); // use 'x' after to make sure it's still usable in the fixed code. @@ -88,8 +104,10 @@ fn main() { let x = (1, 2); let _ = (&x).0; + //~^ needless_borrow let x = &x as *const (i32, i32); let _ = unsafe { (&*x).0 }; + //~^ needless_borrow // Issue #8367 trait Foo { @@ -100,6 +118,7 @@ fn main() { } (&()).foo(); // Don't lint. `()` doesn't implement `Foo` (&&()).foo(); + //~^ needless_borrow impl Foo for i32 { fn foo(self) {} @@ -109,6 +128,7 @@ fn main() { } (&5).foo(); // Don't lint. `5` will call `::foo` (&&5).foo(); + //~^ needless_borrow trait FooRef { fn foo_ref(&self); @@ -135,6 +155,7 @@ fn main() { // issue #11786 let x: (&str,) = (&"",); + //~^ needless_borrow } #[allow(clippy::needless_borrowed_reference)] @@ -177,6 +198,7 @@ mod issue9160 { { fn calls_field(&self) -> T { (&self.f)() + //~^ needless_borrow } } @@ -186,6 +208,7 @@ mod issue9160 { { fn calls_mut_field(&mut self) -> T { (&mut self.f)() + //~^ needless_borrow } } } @@ -223,6 +246,7 @@ fn issue9383() { }; let _ = &mut (&mut x.u).x; let _ = &mut (&mut { x.u }).x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { @@ -230,11 +254,14 @@ fn issue9383() { }; let _ = &mut (&mut x.u).x; let _ = &mut (&mut { x.u }).x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; let mut x = U { u: Wrap(Foo { x: 0 }) }; let _ = &mut (&mut x.u).x; + //~^ needless_borrow let _ = &mut (&mut { x.u }).x; + //~^ needless_borrow let _ = &mut ({ &mut x.u }).x; } } @@ -256,6 +283,7 @@ fn issue_12268() { let option = Some((&1,)); let x = (&1,); option.unwrap_or((&x.0,)); - //~^ ERROR: this expression creates a reference which is immediately dereferenced by the + //~^ needless_borrow + // compiler } diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index 4b2b17e7e570..b574948962de 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:20:13 + --> tests/ui/needless_borrow.rs:21:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:32:13 + --> tests/ui/needless_borrow.rs:34:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:34:15 + --> tests/ui/needless_borrow.rs:37:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:40:27 + --> tests/ui/needless_borrow.rs:44:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:47:15 + --> tests/ui/needless_borrow.rs:52:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:48:15 + --> tests/ui/needless_borrow.rs:54:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:49:15 + --> tests/ui/needless_borrow.rs:56:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:50:15 + --> tests/ui/needless_borrow.rs:58:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:53:11 + --> tests/ui/needless_borrow.rs:62:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:60:13 + --> tests/ui/needless_borrow.rs:70:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:61:13 + --> tests/ui/needless_borrow.rs:72:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:62:23 + --> tests/ui/needless_borrow.rs:74:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:63:23 + --> tests/ui/needless_borrow.rs:76:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:72:14 + --> tests/ui/needless_borrow.rs:86:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:78:14 + --> tests/ui/needless_borrow.rs:93:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:90:13 + --> tests/ui/needless_borrow.rs:106:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:92:22 + --> tests/ui/needless_borrow.rs:109:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:102:5 + --> tests/ui/needless_borrow.rs:120:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:111:5 + --> tests/ui/needless_borrow.rs:130:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:137:23 + --> tests/ui/needless_borrow.rs:157:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:179:13 + --> tests/ui/needless_borrow.rs:200:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:188:13 + --> tests/ui/needless_borrow.rs:210:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:225:22 + --> tests/ui/needless_borrow.rs:248:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:232:22 + --> tests/ui/needless_borrow.rs:256:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:236:22 + --> tests/ui/needless_borrow.rs:261:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:237:22 + --> tests/ui/needless_borrow.rs:263:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:258:23 + --> tests/ui/needless_borrow.rs:285:23 | LL | option.unwrap_or((&x.0,)); | ^^^^ help: change this to: `x.0` diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed index 8f8887f08a27..d067f1c6016b 100644 --- a/tests/ui/needless_borrow_pat.fixed +++ b/tests/ui/needless_borrow_pat.fixed @@ -57,22 +57,25 @@ 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` + //~^ needless_borrow + + None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(x) => x, - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => { - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + f1(x); f1(x); x @@ -83,19 +86,22 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(x) => m1!(x), - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + None => return, }; // Err, reference to a &String let _ = |&x: &&String| { - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + let _: &String = x; }; // Err, reference to a &String let (y,) = (&x,); - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + let _: &String = y; let y = &&x; @@ -106,7 +112,8 @@ 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 + //~^ needless_borrow + None => return, }; @@ -117,14 +124,16 @@ 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 + //~^ needless_borrow + }; // Err, reference to &String. if_chain! { if true; if let Some(x) = Some(&String::new()); - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + then { f1(x); } @@ -133,7 +142,8 @@ fn main() { // Err, reference to a &String fn f2<'a>(&x: &&'a String) -> &'a String { - //~^ ERROR: this pattern creates a reference to a reference +//~^ needless_borrow + let _: &String = x; x } @@ -141,7 +151,8 @@ 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 + //~^ needless_borrow + let _: &String = x; } } @@ -150,7 +161,8 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&x: &&String) { - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + let _: &String = x; } } diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index 56dbd923f256..7c39183d7916 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -57,22 +57,25 @@ 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` + //~^ needless_borrow + + 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 + //~^ needless_borrow + None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => { - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + f1(x); f1(*x); x @@ -83,19 +86,22 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m1!(x), - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + None => return, }; // Err, reference to a &String let _ = |&ref x: &&String| { - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + let _: &String = x; }; // Err, reference to a &String let (ref y,) = (&x,); - //~^ ERROR: this pattern creates a reference to a reference + //~^ needless_borrow + let _: &String = *y; let y = &&x; @@ -106,7 +112,8 @@ 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 + //~^ needless_borrow + None => return, }; @@ -117,14 +124,16 @@ 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 + //~^ needless_borrow + }; // 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 + //~^ needless_borrow + then { f1(x); } @@ -133,7 +142,8 @@ 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 +//~^ needless_borrow + let _: &String = x; *x } @@ -141,7 +151,8 @@ 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 + //~^ needless_borrow + let _: &String = x; } } @@ -150,7 +161,8 @@ 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 + //~^ needless_borrow + let _: &String = *x; } } diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 2ad694490396..7e1b3694e30f 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -8,7 +8,7 @@ LL | Some(ref x) => x, = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:67:14 + --> tests/ui/needless_borrow_pat.rs:68:14 | LL | Some(ref x) => *x, | ^^^^^ @@ -19,7 +19,7 @@ LL | Some(x) => x, | ~ ~ error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:74:14 + --> tests/ui/needless_borrow_pat.rs:76:14 | LL | Some(ref x) => { | ^^^^^ @@ -28,24 +28,25 @@ help: try | LL ~ Some(x) => { LL | +LL | LL | f1(x); LL ~ f1(x); | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:85:14 + --> tests/ui/needless_borrow_pat.rs:88:14 | LL | Some(ref x) => m1!(x), | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:91:15 + --> tests/ui/needless_borrow_pat.rs:95:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:97:10 + --> tests/ui/needless_borrow_pat.rs:102:10 | LL | let (ref y,) = (&x,); | ^^^^^ @@ -54,17 +55,18 @@ help: try | LL ~ let (y,) = (&x,); LL | +LL | LL ~ let _: &String = y; | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:108:14 + --> tests/ui/needless_borrow_pat.rs:114:14 | LL | Some(ref x) => x.0, | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:119:14 + --> tests/ui/needless_borrow_pat.rs:126:14 | LL | E::A(ref x) | E::B(ref x) => *x, | ^^^^^ ^^^^^ @@ -75,13 +77,13 @@ LL | E::A(x) | E::B(x) => x, | ~ ~ ~ error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:126:21 + --> tests/ui/needless_borrow_pat.rs:134:21 | LL | if let Some(ref x) = Some(&String::new()); | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:135:12 + --> tests/ui/needless_borrow_pat.rs:144:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -90,18 +92,19 @@ help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { LL | +LL | LL | let _: &String = x; LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:143:11 + --> tests/ui/needless_borrow_pat.rs:153:11 | LL | fn f(&ref x: &&String) { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:152:11 + --> tests/ui/needless_borrow_pat.rs:163:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -110,6 +113,7 @@ help: try | LL ~ fn f(&x: &&String) { LL | +LL | LL ~ let _: &String = x; | diff --git a/tests/ui/needless_borrowed_ref.fixed b/tests/ui/needless_borrowed_ref.fixed index 5d2fd0950ee4..1cad115e96d1 100644 --- a/tests/ui/needless_borrowed_ref.fixed +++ b/tests/ui/needless_borrowed_ref.fixed @@ -28,32 +28,48 @@ fn should_lint( ) { let mut v = Vec::::new(); let _ = v.iter_mut().filter(|a| a.is_empty()); + //~^ needless_borrowed_reference let var = 3; let thingy = Some(&var); if let Some(v) = thingy {} + //~^ needless_borrowed_reference if let &[a, ref b] = slice_of_refs {} + //~^ needless_borrowed_reference let [a, ..] = &array; + //~^ needless_borrowed_reference let [a, b, ..] = &array; + //~^ needless_borrowed_reference if let [a, b] = slice {} + //~^ needless_borrowed_reference if let [a, b] = &vec[..] {} + //~^ needless_borrowed_reference if let [a, b, ..] = slice {} + //~^ needless_borrowed_reference if let [a, .., b] = slice {} + //~^ needless_borrowed_reference if let [.., a, b] = slice {} + //~^ needless_borrowed_reference if let [a, _] = slice {} + //~^ needless_borrowed_reference if let (a, b, c) = &tuple {} + //~^ needless_borrowed_reference if let (a, _, c) = &tuple {} + //~^ needless_borrowed_reference if let (a, ..) = &tuple {} + //~^ needless_borrowed_reference if let TupleStruct(a, ..) = &tuple_struct {} + //~^ needless_borrowed_reference if let Struct { + //~^ needless_borrowed_reference a, b: b, c: renamed, @@ -61,6 +77,7 @@ fn should_lint( {} if let Struct { a, b: _, .. } = &s {} + //~^ needless_borrowed_reference } fn should_not_lint( diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index 556fd3a35427..ae6377fd4421 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -28,32 +28,48 @@ fn should_lint( ) { let mut v = Vec::::new(); let _ = v.iter_mut().filter(|&ref a| a.is_empty()); + //~^ needless_borrowed_reference let var = 3; let thingy = Some(&var); if let Some(&ref v) = thingy {} + //~^ needless_borrowed_reference if let &[&ref a, ref b] = slice_of_refs {} + //~^ needless_borrowed_reference let &[ref a, ..] = &array; + //~^ needless_borrowed_reference let &[ref a, ref b, ..] = &array; + //~^ needless_borrowed_reference if let &[ref a, ref b] = slice {} + //~^ needless_borrowed_reference if let &[ref a, ref b] = &vec[..] {} + //~^ needless_borrowed_reference if let &[ref a, ref b, ..] = slice {} + //~^ needless_borrowed_reference if let &[ref a, .., ref b] = slice {} + //~^ needless_borrowed_reference if let &[.., ref a, ref b] = slice {} + //~^ needless_borrowed_reference if let &[ref a, _] = slice {} + //~^ needless_borrowed_reference if let &(ref a, ref b, ref c) = &tuple {} + //~^ needless_borrowed_reference if let &(ref a, _, ref c) = &tuple {} + //~^ needless_borrowed_reference if let &(ref a, ..) = &tuple {} + //~^ needless_borrowed_reference if let &TupleStruct(ref a, ..) = &tuple_struct {} + //~^ needless_borrowed_reference if let &Struct { + //~^ needless_borrowed_reference ref a, b: ref b, c: ref renamed, @@ -61,6 +77,7 @@ fn should_lint( {} if let &Struct { ref a, b: _, .. } = &s {} + //~^ needless_borrowed_reference } fn should_not_lint( diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index b8181e2805c9..bfa3cafdedeb 100644 --- a/tests/ui/needless_borrowed_ref.stderr +++ b/tests/ui/needless_borrowed_ref.stderr @@ -13,7 +13,7 @@ LL + let _ = v.iter_mut().filter(|a| a.is_empty()); | error: this pattern takes a reference on something that is being dereferenced - --> tests/ui/needless_borrowed_ref.rs:34:17 + --> tests/ui/needless_borrowed_ref.rs:35:17 | LL | if let Some(&ref v) = thingy {} | ^^^^^^ @@ -25,7 +25,7 @@ LL + if let Some(v) = thingy {} | error: this pattern takes a reference on something that is being dereferenced - --> tests/ui/needless_borrowed_ref.rs:36:14 + --> tests/ui/needless_borrowed_ref.rs:38:14 | LL | if let &[&ref a, ref b] = slice_of_refs {} | ^^^^^^ @@ -37,7 +37,7 @@ LL + if let &[a, ref b] = slice_of_refs {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:38:9 + --> tests/ui/needless_borrowed_ref.rs:41:9 | LL | let &[ref a, ..] = &array; | ^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let [a, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:39:9 + --> tests/ui/needless_borrowed_ref.rs:43:9 | LL | let &[ref a, ref b, ..] = &array; | ^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let [a, b, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:41:12 + --> tests/ui/needless_borrowed_ref.rs:46:12 | LL | if let &[ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + if let [a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:42:12 + --> tests/ui/needless_borrowed_ref.rs:48:12 | LL | if let &[ref a, ref b] = &vec[..] {} | ^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + if let [a, b] = &vec[..] {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:44:12 + --> tests/ui/needless_borrowed_ref.rs:51:12 | LL | if let &[ref a, ref b, ..] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + if let [a, b, ..] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:45:12 + --> tests/ui/needless_borrowed_ref.rs:53:12 | LL | if let &[ref a, .., ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + if let [a, .., b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:46:12 + --> tests/ui/needless_borrowed_ref.rs:55:12 | LL | if let &[.., ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + if let [.., a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:48:12 + --> tests/ui/needless_borrowed_ref.rs:58:12 | LL | if let &[ref a, _] = slice {} | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + if let [a, _] = slice {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:50:12 + --> tests/ui/needless_borrowed_ref.rs:61:12 | LL | if let &(ref a, ref b, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + if let (a, b, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:51:12 + --> tests/ui/needless_borrowed_ref.rs:63:12 | LL | if let &(ref a, _, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + if let (a, _, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:52:12 + --> tests/ui/needless_borrowed_ref.rs:65:12 | LL | if let &(ref a, ..) = &tuple {} | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + if let (a, ..) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:54:12 + --> tests/ui/needless_borrowed_ref.rs:68:12 | LL | if let &TupleStruct(ref a, ..) = &tuple_struct {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,10 +181,11 @@ LL + if let TupleStruct(a, ..) = &tuple_struct {} | error: dereferencing a struct pattern where every field's pattern takes a reference - --> tests/ui/needless_borrowed_ref.rs:56:12 + --> tests/ui/needless_borrowed_ref.rs:71:12 | LL | if let &Struct { | ____________^ +LL | | LL | | ref a, LL | | b: ref b, LL | | c: ref renamed, @@ -194,13 +195,14 @@ LL | | } = &s help: try removing the `&` and `ref` parts | LL ~ if let Struct { +LL | LL ~ a, LL ~ b: b, LL ~ c: renamed, | error: dereferencing a struct pattern where every field's pattern takes a reference - --> tests/ui/needless_borrowed_ref.rs:63:12 + --> tests/ui/needless_borrowed_ref.rs:79:12 | LL | if let &Struct { ref a, b: _, .. } = &s {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_borrows_for_generic_args.fixed b/tests/ui/needless_borrows_for_generic_args.fixed index c1dc8b5e8d09..374caeacfd28 100644 --- a/tests/ui/needless_borrows_for_generic_args.fixed +++ b/tests/ui/needless_borrows_for_generic_args.fixed @@ -14,11 +14,14 @@ use std::process::Command; fn main() { let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args let _ = Path::new(".").join("."); + //~^ needless_borrows_for_generic_args let _ = Any::type_id(&""); // Don't lint. `Any` is only bound let _ = Box::new(&""); // Don't lint. Type parameter appears in return type let _ = Some("").unwrap_or(&""); let _ = std::fs::write("x", "".to_string()); + //~^ needless_borrows_for_generic_args { #[derive(Clone, Copy)] @@ -34,6 +37,7 @@ fn main() { fn deref_target_is_x>(_: T) {} deref_target_is_x(X); + //~^ needless_borrows_for_generic_args } { fn multiple_constraints(_: T) @@ -47,6 +51,7 @@ fn main() { } multiple_constraints([[""]]); + //~^ needless_borrows_for_generic_args } { #[derive(Clone, Copy)] @@ -67,6 +72,7 @@ fn main() { } multiple_constraints_normalizes_to_same(X, X); + //~^ needless_borrows_for_generic_args } { fn only_sized(_: T) {} @@ -125,6 +131,7 @@ fn main() { #[allow(unused_mut)] fn warn(mut x: &mut Iter) { takes_iter(x) + //~^ needless_borrows_for_generic_args } } #[clippy::msrv = "1.52.0"] @@ -134,6 +141,7 @@ fn main() { #[clippy::msrv = "1.53.0"] { let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args }; { let env = "env".to_owned(); @@ -245,6 +253,7 @@ fn main() { // 8 foo::<&[u8; 100]>(&a); foo(a); + //~^ needless_borrows_for_generic_args } { struct S; @@ -329,9 +338,11 @@ fn main() { let x = String::new(); f(&x); // Don't lint, not a copy, makes it unavailable later f(String::new()); // Lint, makes no difference + //~^ needless_borrows_for_generic_args let y = "".to_owned(); f(&y); // Don't lint f("".to_owned()); // Lint + //~^ needless_borrows_for_generic_args } { fn takes_writer(_: T) {} diff --git a/tests/ui/needless_borrows_for_generic_args.rs b/tests/ui/needless_borrows_for_generic_args.rs index c7f66824d581..06e2a4505211 100644 --- a/tests/ui/needless_borrows_for_generic_args.rs +++ b/tests/ui/needless_borrows_for_generic_args.rs @@ -14,11 +14,14 @@ use std::process::Command; fn main() { let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args let _ = Path::new(".").join(&&"."); + //~^ needless_borrows_for_generic_args let _ = Any::type_id(&""); // Don't lint. `Any` is only bound let _ = Box::new(&""); // Don't lint. Type parameter appears in return type let _ = Some("").unwrap_or(&""); let _ = std::fs::write("x", &"".to_string()); + //~^ needless_borrows_for_generic_args { #[derive(Clone, Copy)] @@ -34,6 +37,7 @@ fn main() { fn deref_target_is_x>(_: T) {} deref_target_is_x(&X); + //~^ needless_borrows_for_generic_args } { fn multiple_constraints(_: T) @@ -47,6 +51,7 @@ fn main() { } multiple_constraints(&[[""]]); + //~^ needless_borrows_for_generic_args } { #[derive(Clone, Copy)] @@ -67,6 +72,7 @@ fn main() { } multiple_constraints_normalizes_to_same(&X, X); + //~^ needless_borrows_for_generic_args } { fn only_sized(_: T) {} @@ -125,6 +131,7 @@ fn main() { #[allow(unused_mut)] fn warn(mut x: &mut Iter) { takes_iter(&mut x) + //~^ needless_borrows_for_generic_args } } #[clippy::msrv = "1.52.0"] @@ -134,6 +141,7 @@ fn main() { #[clippy::msrv = "1.53.0"] { let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + //~^ needless_borrows_for_generic_args }; { let env = "env".to_owned(); @@ -245,6 +253,7 @@ fn main() { // 8 foo::<&[u8; 100]>(&a); foo(&a); + //~^ needless_borrows_for_generic_args } { struct S; @@ -329,9 +338,11 @@ fn main() { let x = String::new(); f(&x); // Don't lint, not a copy, makes it unavailable later f(&String::new()); // Lint, makes no difference + //~^ needless_borrows_for_generic_args let y = "".to_owned(); f(&y); // Don't lint f(&"".to_owned()); // Lint + //~^ needless_borrows_for_generic_args } { fn takes_writer(_: T) {} diff --git a/tests/ui/needless_borrows_for_generic_args.stderr b/tests/ui/needless_borrows_for_generic_args.stderr index fba0755d14b5..6b5a0b4b1b67 100644 --- a/tests/ui/needless_borrows_for_generic_args.stderr +++ b/tests/ui/needless_borrows_for_generic_args.stderr @@ -8,61 +8,61 @@ LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:17:33 + --> tests/ui/needless_borrows_for_generic_args.rs:18:33 | LL | let _ = Path::new(".").join(&&"."); | ^^^^^ help: change this to: `"."` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:21:33 + --> tests/ui/needless_borrows_for_generic_args.rs:23:33 | LL | let _ = std::fs::write("x", &"".to_string()); | ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:36:27 + --> tests/ui/needless_borrows_for_generic_args.rs:39:27 | LL | deref_target_is_x(&X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:49:30 + --> tests/ui/needless_borrows_for_generic_args.rs:53:30 | LL | multiple_constraints(&[[""]]); | ^^^^^^^ help: change this to: `[[""]]` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:69:49 + --> tests/ui/needless_borrows_for_generic_args.rs:74:49 | LL | multiple_constraints_normalizes_to_same(&X, X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:127:24 + --> tests/ui/needless_borrows_for_generic_args.rs:133:24 | LL | takes_iter(&mut x) | ^^^^^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:136:41 + --> tests/ui/needless_borrows_for_generic_args.rs:143:41 | LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:247:13 + --> tests/ui/needless_borrows_for_generic_args.rs:255:13 | LL | foo(&a); | ^^ help: change this to: `a` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:331:11 + --> tests/ui/needless_borrows_for_generic_args.rs:340:11 | LL | f(&String::new()); // Lint, makes no difference | ^^^^^^^^^^^^^^ help: change this to: `String::new()` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:334:11 + --> tests/ui/needless_borrows_for_generic_args.rs:344:11 | LL | f(&"".to_owned()); // Lint | ^^^^^^^^^^^^^^ help: change this to: `"".to_owned()` diff --git a/tests/ui/needless_character_iteration.fixed b/tests/ui/needless_character_iteration.fixed index f0bf84a41d7e..584b578fa8be 100644 --- a/tests/ui/needless_character_iteration.fixed +++ b/tests/ui/needless_character_iteration.fixed @@ -16,25 +16,32 @@ fn magic(_: char) {} fn main() { "foo".is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + !"foo".is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + !"foo".is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + let s = String::new(); s.is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + !"foo".to_string().is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".is_ascii(); !"foo".is_ascii(); S::default().field().is_ascii(); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + // Should not lint! "foo".chars().all(|c| { diff --git a/tests/ui/needless_character_iteration.rs b/tests/ui/needless_character_iteration.rs index 2805d2438b4a..1ef5c3a79a3e 100644 --- a/tests/ui/needless_character_iteration.rs +++ b/tests/ui/needless_character_iteration.rs @@ -16,33 +16,42 @@ fn magic(_: char) {} fn main() { "foo".chars().all(|c| c.is_ascii()); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".chars().any(|c| !c.is_ascii()); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".chars().all(|c| char::is_ascii(&c)); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".chars().any(|c| !char::is_ascii(&c)); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + let s = String::new(); s.chars().all(|c| c.is_ascii()); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".to_string().chars().any(|c| !c.is_ascii()); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + "foo".chars().all(|c| { - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + let x = c; x.is_ascii() }); "foo".chars().any(|c| { - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + let x = c; !x.is_ascii() }); S::default().field().chars().all(|x| x.is_ascii()); - //~^ ERROR: checking if a string is ascii using iterators + //~^ needless_character_iteration + // Should not lint! "foo".chars().all(|c| { diff --git a/tests/ui/needless_character_iteration.stderr b/tests/ui/needless_character_iteration.stderr index 7966033555f5..29e5a674e0c5 100644 --- a/tests/ui/needless_character_iteration.stderr +++ b/tests/ui/needless_character_iteration.stderr @@ -8,57 +8,59 @@ LL | "foo".chars().all(|c| c.is_ascii()); = help: to override `-D warnings` add `#[allow(clippy::needless_character_iteration)]` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:20:5 + --> tests/ui/needless_character_iteration.rs:21:5 | LL | "foo".chars().any(|c| !c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:22:5 + --> tests/ui/needless_character_iteration.rs:24:5 | LL | "foo".chars().all(|c| char::is_ascii(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:24:5 + --> tests/ui/needless_character_iteration.rs:27:5 | LL | "foo".chars().any(|c| !char::is_ascii(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:28:5 + --> tests/ui/needless_character_iteration.rs:32:5 | LL | s.chars().all(|c| c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:30:5 + --> tests/ui/needless_character_iteration.rs:35:5 | LL | "foo".to_string().chars().any(|c| !c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".to_string().is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:33:5 + --> tests/ui/needless_character_iteration.rs:39:5 | LL | / "foo".chars().all(|c| { LL | | +LL | | LL | | let x = c; LL | | x.is_ascii() LL | | }); | |______^ help: try: `"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:38:5 + --> tests/ui/needless_character_iteration.rs:45:5 | LL | / "foo".chars().any(|c| { LL | | +LL | | LL | | let x = c; LL | | !x.is_ascii() LL | | }); | |______^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:44:5 + --> tests/ui/needless_character_iteration.rs:52:5 | LL | S::default().field().chars().all(|x| x.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `S::default().field().is_ascii()` diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index bd83581bdd97..c2267b84de42 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -7,16 +7,21 @@ use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedL fn main() { let sample = [1; 5]; let len = sample.iter().count(); + //~^ needless_collect if sample.iter().next().is_none() { + //~^ needless_collect // Empty } sample.iter().cloned().any(|x| x == 1); + //~^ needless_collect // #7164 HashMap's and BTreeMap's `len` usage should not be linted sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).next().is_none(); + //~^ needless_collect sample.iter().map(|x| (x, x)).next().is_none(); + //~^ needless_collect // Notice the `HashSet`--this should not be linted sample.iter().collect::>().len(); @@ -24,19 +29,27 @@ fn main() { sample.iter().collect::>().len(); sample.iter().count(); + //~^ needless_collect sample.iter().next().is_none(); + //~^ needless_collect sample.iter().cloned().any(|x| x == 1); + //~^ needless_collect sample.iter().any(|x| x == &1); + //~^ needless_collect // `BinaryHeap` doesn't have `contains` method sample.iter().count(); + //~^ needless_collect sample.iter().next().is_none(); + //~^ needless_collect // Don't lint string from str let _ = ["", ""].into_iter().collect::().is_empty(); let _ = sample.iter().next().is_none(); + //~^ needless_collect let _ = sample.iter().any(|x| x == &0); + //~^ needless_collect struct VecWrapper(Vec); impl core::ops::Deref for VecWrapper { @@ -59,14 +72,20 @@ fn main() { } let _ = sample.iter().next().is_none(); + //~^ needless_collect let _ = sample.iter().any(|x| x == &0); + //~^ needless_collect #[allow(clippy::double_parens)] { Vec::::new().extend((0..10)); + //~^ needless_collect foo((0..10)); + //~^ needless_collect bar((0..10).collect::>(), (0..10)); + //~^ needless_collect baz((0..10), (), ('a'..='z')) + //~^ needless_collect } let values = [1, 2, 3, 4]; diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 6a81a767bbb6..854bc3fff19d 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -7,16 +7,21 @@ use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedL fn main() { let sample = [1; 5]; let len = sample.iter().collect::>().len(); + //~^ needless_collect if sample.iter().collect::>().is_empty() { + //~^ needless_collect // Empty } sample.iter().cloned().collect::>().contains(&1); + //~^ needless_collect // #7164 HashMap's and BTreeMap's `len` usage should not be linted sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().len(); sample.iter().map(|x| (x, x)).collect::>().is_empty(); + //~^ needless_collect sample.iter().map(|x| (x, x)).collect::>().is_empty(); + //~^ needless_collect // Notice the `HashSet`--this should not be linted sample.iter().collect::>().len(); @@ -24,19 +29,27 @@ fn main() { sample.iter().collect::>().len(); sample.iter().collect::>().len(); + //~^ needless_collect sample.iter().collect::>().is_empty(); + //~^ needless_collect sample.iter().cloned().collect::>().contains(&1); + //~^ needless_collect sample.iter().collect::>().contains(&&1); + //~^ needless_collect // `BinaryHeap` doesn't have `contains` method sample.iter().collect::>().len(); + //~^ needless_collect sample.iter().collect::>().is_empty(); + //~^ needless_collect // Don't lint string from str let _ = ["", ""].into_iter().collect::().is_empty(); let _ = sample.iter().collect::>().is_empty(); + //~^ needless_collect let _ = sample.iter().collect::>().contains(&&0); + //~^ needless_collect struct VecWrapper(Vec); impl core::ops::Deref for VecWrapper { @@ -59,14 +72,20 @@ fn main() { } let _ = sample.iter().collect::>().is_empty(); + //~^ needless_collect let _ = sample.iter().collect::>().contains(&&0); + //~^ needless_collect #[allow(clippy::double_parens)] { Vec::::new().extend((0..10).collect::>()); + //~^ needless_collect foo((0..10).collect::>()); + //~^ needless_collect bar((0..10).collect::>(), (0..10).collect::>()); + //~^ needless_collect baz((0..10), (), ('a'..='z').collect::>()) + //~^ needless_collect } let values = [1, 2, 3, 4]; diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index ea317896d368..cba54f0af6bf 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -8,109 +8,109 @@ LL | let len = sample.iter().collect::>().len(); = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:10:22 + --> tests/ui/needless_collect.rs:11:22 | LL | if sample.iter().collect::>().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:13:28 + --> tests/ui/needless_collect.rs:15:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:18:35 + --> tests/ui/needless_collect.rs:21:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:19:35 + --> tests/ui/needless_collect.rs:23:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:26:19 + --> tests/ui/needless_collect.rs:31:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:27:19 + --> tests/ui/needless_collect.rs:33:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:28:28 + --> tests/ui/needless_collect.rs:35:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:29:19 + --> tests/ui/needless_collect.rs:37:19 | LL | sample.iter().collect::>().contains(&&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:32:19 + --> tests/ui/needless_collect.rs:41:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:33:19 + --> tests/ui/needless_collect.rs:43:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:38:27 + --> tests/ui/needless_collect.rs:49:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:39:27 + --> tests/ui/needless_collect.rs:51:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:61:27 + --> tests/ui/needless_collect.rs:74:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:62:27 + --> tests/ui/needless_collect.rs:76:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:66:40 + --> tests/ui/needless_collect.rs:81:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:67:20 + --> tests/ui/needless_collect.rs:83:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:68:49 + --> tests/ui/needless_collect.rs:85:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:69:37 + --> tests/ui/needless_collect.rs:87: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 9d66c5f255fe..57d0f2b99480 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -7,17 +7,20 @@ 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` + //~^ needless_collect + indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); let indirect_len = sample.iter().collect::>(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + indirect_len.len(); let indirect_empty = sample.iter().collect::>(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + indirect_empty.is_empty(); let indirect_contains = sample.iter().collect::>(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + indirect_contains.contains(&&5); let indirect_negative = sample.iter().collect::>(); indirect_negative.len(); @@ -30,7 +33,8 @@ 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 + //~^ needless_collect + non_copy_contains.contains(&a); // Fix #5991 @@ -60,25 +64,29 @@ mod issue7110 { fn lint_vec(string: &str) -> usize { let buffer: Vec<&str> = string.split('/').collect(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + 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 + //~^ needless_collect + 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 + //~^ needless_collect + 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 + //~^ needless_collect + indirect_len.len() } fn dont_lint(string: &str) -> usize { @@ -139,7 +147,8 @@ 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 + //~^ needless_collect + let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&i); @@ -165,7 +174,8 @@ mod issue_8553 { while n > 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -195,7 +205,8 @@ mod issue_8553 { loop { if n < 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); - //~^ ERROR: avoid using `collect()` when not needed + //~^ needless_collect + let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -232,7 +243,8 @@ 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 + //~^ needless_collect + let z: Vec = vec.iter().map(|k| k * k).collect(); if n < 2 { // Do lint @@ -258,7 +270,8 @@ 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 + //~^ needless_collect + // Do lint for _ in 0..w.len() { todo!(); @@ -281,7 +294,8 @@ 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 + //~^ needless_collect + // Do lint while 1 == w.len() { todo!(); @@ -304,7 +318,8 @@ 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 + //~^ needless_collect + // 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 f25c02937545..c7bf1b14df80 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -22,7 +22,7 @@ error: avoid using `collect()` when not needed | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ -LL | +... LL | indirect_len.len(); | ------------------ the iterator could be used here instead | @@ -30,15 +30,16 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | +LL | LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:16:40 + --> tests/ui/needless_collect_indirect.rs:17:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ -LL | +... LL | indirect_empty.is_empty(); | ------------------------- the iterator could be used here instead | @@ -46,15 +47,16 @@ help: check if the original Iterator has anything instead of collecting it and s | LL ~ LL | +LL | LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:19:43 + --> tests/ui/needless_collect_indirect.rs:21:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ -LL | +... LL | indirect_contains.contains(&&5); | ------------------------------- the iterator could be used here instead | @@ -62,15 +64,16 @@ help: check if the original Iterator contains an element instead of collecting t | LL ~ LL | +LL | LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:32:48 + --> tests/ui/needless_collect_indirect.rs:35:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ -LL | +... LL | non_copy_contains.contains(&a); | ------------------------------ the iterator could be used here instead | @@ -78,15 +81,16 @@ help: check if the original Iterator contains an element instead of collecting t | LL ~ LL | +LL | LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:62:51 + --> tests/ui/needless_collect_indirect.rs:66:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ -LL | +... LL | buffer.len() | ------------ the iterator could be used here instead | @@ -94,15 +98,16 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | +LL | LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:68:55 + --> tests/ui/needless_collect_indirect.rs:73:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ -LL | +... LL | indirect_len.len() | ------------------ the iterator could be used here instead | @@ -110,21 +115,6 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | -LL ~ sample.iter().count() - | - -error: avoid using `collect()` when not needed - --> tests/ui/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() | @@ -132,9 +122,9 @@ LL ~ sample.iter().count() error: avoid using `collect()` when not needed --> tests/ui/needless_collect_indirect.rs:80:57 | -LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); +LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ -LL | +... LL | indirect_len.len() | ------------------ the iterator could be used here instead | @@ -142,11 +132,29 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:141:59 + --> tests/ui/needless_collect_indirect.rs:87:57 + | +LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); + | ^^^^^^^ +... +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 | +LL ~ sample.iter().count() + | + +error: avoid using `collect()` when not needed + --> tests/ui/needless_collect_indirect.rs:149:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -158,13 +166,13 @@ help: check if the original Iterator contains an element instead of collecting t | 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 - --> tests/ui/needless_collect_indirect.rs:167:59 + --> tests/ui/needless_collect_indirect.rs:176:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -176,13 +184,13 @@ help: check if the original Iterator contains an element instead of collecting t | 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 - --> tests/ui/needless_collect_indirect.rs:197:63 + --> tests/ui/needless_collect_indirect.rs:207:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -194,13 +202,13 @@ help: check if the original Iterator contains an element instead of collecting t | 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 - --> tests/ui/needless_collect_indirect.rs:234:59 + --> tests/ui/needless_collect_indirect.rs:245:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -218,7 +226,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:260:26 + --> tests/ui/needless_collect_indirect.rs:272:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ @@ -230,12 +238,13 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | +LL | LL | // Do lint LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:283:30 + --> tests/ui/needless_collect_indirect.rs:296:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ @@ -247,12 +256,13 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ LL | +LL | LL | // Do lint LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:306:30 + --> tests/ui/needless_collect_indirect.rs:320:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ @@ -264,6 +274,7 @@ help: take the original Iterator's count instead of collecting it and finding th | LL ~ 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 334a2b32775f..0adef7e72ee4 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -28,7 +28,8 @@ fn main() { let i = 0; println!("bar {} ", i); } else { - //~^ ERROR: this `else` block is redundant + //~^ needless_continue + continue; } @@ -44,7 +45,8 @@ 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 + //~^ needless_continue + continue; } else { println!("Blabber"); @@ -58,7 +60,8 @@ fn main() { fn simple_loop() { loop { continue; - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } @@ -66,7 +69,8 @@ fn simple_loop2() { loop { println!("bleh"); continue; - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } @@ -74,7 +78,8 @@ fn simple_loop2() { fn simple_loop3() { loop { continue - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } @@ -83,7 +88,8 @@ fn simple_loop4() { loop { println!("bleh"); continue - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } @@ -91,7 +97,8 @@ fn simple_loop5() { loop { println!("bleh"); { continue } - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } @@ -142,14 +149,16 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { - //~^ ERROR: this `else` block is redundant + //~^ needless_continue + continue 'inner; } println!("bar-4"); update_condition(); if condition() { - //~^ ERROR: there is no need for an explicit `else` block for this `if` ex + //~^ needless_continue + continue; } else { println!("bar-5"); @@ -172,7 +181,8 @@ fn issue_13641() { while std::hint::black_box(true) { 'b: loop { continue 'b; - //~^ ERROR: this `continue` expression is redundant + //~^ needless_continue + } } } @@ -188,9 +198,11 @@ mod issue_4077 { } else if !some_expr() { println!("bar-8"); continue 'inner; + //~^ needless_continue } else { println!("bar-9"); continue 'inner; + //~^ needless_continue } } } @@ -201,6 +213,7 @@ mod issue_4077 { Err(_) => { println!("bar-10"); continue; + //~^ needless_continue }, } } @@ -208,6 +221,7 @@ mod issue_4077 { loop { if true { } else { + //~^ needless_continue // redundant `else` continue; // redundant `continue` } @@ -215,6 +229,7 @@ mod issue_4077 { loop { if some_expr() { + //~^ needless_continue continue; } else { do_something(); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index ec39d6234195..947e61cac12e 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -4,6 +4,7 @@ error: this `else` block is redundant LL | } else { | ________________^ LL | | +LL | | LL | | continue; LL | | } | |_________^ @@ -27,6 +28,7 @@ LL | | } } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } else { println!("Blabber"); @@ -38,13 +40,13 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::needless_continue)]` error: there is no need for an explicit `else` block for this `if` expression - --> tests/ui/needless_continue.rs:46:9 + --> tests/ui/needless_continue.rs:47:9 | LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { LL | | +LL | | LL | | continue; -LL | | } else { -LL | | println!("Blabber"); +... | LL | | println!("Jabber"); LL | | } | |_________^ @@ -52,6 +54,7 @@ LL | | } = help: consider dropping the `else` clause if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } { @@ -60,7 +63,7 @@ LL | | } } error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:60:9 + --> tests/ui/needless_continue.rs:62:9 | LL | continue; | ^^^^^^^^ @@ -68,7 +71,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:68:9 + --> tests/ui/needless_continue.rs:71:9 | LL | continue; | ^^^^^^^^ @@ -76,7 +79,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:76:9 + --> tests/ui/needless_continue.rs:80:9 | LL | continue | ^^^^^^^^ @@ -84,7 +87,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:85:9 + --> tests/ui/needless_continue.rs:90:9 | LL | continue | ^^^^^^^^ @@ -92,7 +95,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:93:11 + --> tests/ui/needless_continue.rs:99:11 | LL | { continue } | ^^^^^^^^ @@ -100,11 +103,12 @@ LL | { continue } = help: consider dropping the `continue` expression error: this `else` block is redundant - --> tests/ui/needless_continue.rs:144:24 + --> tests/ui/needless_continue.rs:151:24 | LL | } else { | ________________________^ LL | | +LL | | LL | | continue 'inner; LL | | } | |_________________^ @@ -117,6 +121,7 @@ LL | | } update_condition(); if condition() { + continue; } else { println!("bar-5"); @@ -125,10 +130,11 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> tests/ui/needless_continue.rs:151:17 + --> tests/ui/needless_continue.rs:159:17 | LL | / if condition() { LL | | +LL | | LL | | continue; LL | | } else { LL | | println!("bar-5"); @@ -138,6 +144,7 @@ LL | | } = help: consider dropping the `else` clause if condition() { + continue; } { @@ -145,7 +152,7 @@ LL | | } } error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:174:13 + --> tests/ui/needless_continue.rs:183:13 | LL | continue 'b; | ^^^^^^^^^^^ @@ -153,7 +160,7 @@ LL | continue 'b; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:190:21 + --> tests/ui/needless_continue.rs:200:21 | LL | continue 'inner; | ^^^^^^^^^^^^^^^ @@ -161,7 +168,7 @@ LL | continue 'inner; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:193:21 + --> tests/ui/needless_continue.rs:204:21 | LL | continue 'inner; | ^^^^^^^^^^^^^^^ @@ -169,7 +176,7 @@ LL | continue 'inner; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:203:21 + --> tests/ui/needless_continue.rs:215:21 | LL | continue; | ^^^^^^^^ @@ -177,10 +184,11 @@ LL | continue; = help: consider dropping the `continue` expression error: this `else` block is redundant - --> tests/ui/needless_continue.rs:210:20 + --> tests/ui/needless_continue.rs:223:20 | LL | } else { | ____________________^ +LL | | LL | | // redundant `else` LL | | continue; // redundant `continue` LL | | } @@ -193,9 +201,10 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> tests/ui/needless_continue.rs:217:13 + --> tests/ui/needless_continue.rs:231:13 | LL | / if some_expr() { +LL | | LL | | continue; LL | | } else { LL | | do_something(); @@ -204,6 +213,7 @@ LL | | } | = help: consider dropping the `else` clause if some_expr() { + continue; } { diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs index 18adfff8beba..8894ab0285d4 100644 --- a/tests/ui/needless_doc_main.rs +++ b/tests/ui/needless_doc_main.rs @@ -6,7 +6,6 @@ /// ``` /// fn main() { //~^ ERROR: needless `fn main` in doctest -//~| NOTE: `-D clippy::needless-doctest-main` implied by `-D warnings` /// unimplemented!(); /// } /// ``` diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr index 7e362cf377ce..9ba2ad306dac 100644 --- a/tests/ui/needless_doc_main.stderr +++ b/tests/ui/needless_doc_main.stderr @@ -4,7 +4,6 @@ error: needless `fn main` in doctest LL | /// fn main() { | _____^ LL | | -LL | | LL | | /// unimplemented!(); LL | | /// } | |_____^ @@ -13,7 +12,7 @@ LL | | /// } = help: to override `-D warnings` add `#[allow(clippy::needless_doctest_main)]` error: needless `fn main` in doctest - --> tests/ui/needless_doc_main.rs:16:5 + --> tests/ui/needless_doc_main.rs:15:5 | LL | /// fn main() -> () { | _____^ @@ -23,7 +22,7 @@ LL | | /// } | |_____^ error: needless `fn main` in doctest - --> tests/ui/needless_doc_main.rs:24:5 + --> tests/ui/needless_doc_main.rs:23:5 | LL | /// fn main() { | _____^ @@ -33,7 +32,7 @@ LL | | /// } | |_____^ error: needless `fn main` in doctest - --> tests/ui/needless_doc_main.rs:32:5 + --> tests/ui/needless_doc_main.rs:31:5 | LL | /// // the fn is not always the first line | _____^ diff --git a/tests/ui/needless_else.fixed b/tests/ui/needless_else.fixed index 240b79bae13c..0455910c3ee8 100644 --- a/tests/ui/needless_else.fixed +++ b/tests/ui/needless_else.fixed @@ -21,6 +21,7 @@ fn main() { if b { println!("Foobar"); } + //~^^ needless_else if b { println!("Foobar"); diff --git a/tests/ui/needless_else.rs b/tests/ui/needless_else.rs index ad84da170535..236ac631a49e 100644 --- a/tests/ui/needless_else.rs +++ b/tests/ui/needless_else.rs @@ -22,6 +22,7 @@ fn main() { println!("Foobar"); } else { } + //~^^ needless_else if b { println!("Foobar"); diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr deleted file mode 100644 index 77ead31b31cc..000000000000 --- a/tests/ui/needless_else.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: this `else` branch is empty - --> tests/ui/needless_else.rs:23:7 - | -LL | } else { - | _______^ -LL | | } - | |_____^ help: you can remove it - | - = note: `-D clippy::needless-else` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::needless_else)]` - -error: aborting due to 1 previous error - diff --git a/tests/ui/needless_for_each_fixable.fixed b/tests/ui/needless_for_each_fixable.fixed index 2362314290e6..873bad552af1 100644 --- a/tests/ui/needless_for_each_fixable.fixed +++ b/tests/ui/needless_for_each_fixable.fixed @@ -13,27 +13,34 @@ fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; for elem in v.iter() { + //~^ needless_for_each acc += elem; } for elem in v.into_iter() { + //~^ needless_for_each acc += elem; } for elem in [1, 2, 3].iter() { + //~^ needless_for_each acc += elem; } let mut hash_map: HashMap = HashMap::new(); for (k, v) in hash_map.iter() { + //~^ needless_for_each acc += k + v; } for (k, v) in hash_map.iter_mut() { + //~^ needless_for_each acc += *k + *v; } for k in hash_map.keys() { + //~^ needless_for_each acc += k; } for v in hash_map.values() { + //~^ needless_for_each acc += v; } @@ -41,6 +48,7 @@ fn should_lint() { Vec::new() } for elem in my_vec().iter() { + //~^ needless_for_each acc += elem; } } diff --git a/tests/ui/needless_for_each_fixable.rs b/tests/ui/needless_for_each_fixable.rs index 5b1186daa229..5e650dfc06c1 100644 --- a/tests/ui/needless_for_each_fixable.rs +++ b/tests/ui/needless_for_each_fixable.rs @@ -13,27 +13,34 @@ fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; v.iter().for_each(|elem| { + //~^ needless_for_each acc += elem; }); v.into_iter().for_each(|elem| { + //~^ needless_for_each acc += elem; }); [1, 2, 3].iter().for_each(|elem| { + //~^ needless_for_each acc += elem; }); let mut hash_map: HashMap = HashMap::new(); hash_map.iter().for_each(|(k, v)| { + //~^ needless_for_each acc += k + v; }); hash_map.iter_mut().for_each(|(k, v)| { + //~^ needless_for_each acc += *k + *v; }); hash_map.keys().for_each(|k| { + //~^ needless_for_each acc += k; }); hash_map.values().for_each(|v| { + //~^ needless_for_each acc += v; }); @@ -41,6 +48,7 @@ fn should_lint() { Vec::new() } my_vec().iter().for_each(|elem| { + //~^ needless_for_each acc += elem; }); } diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index 21342d052561..013a3fa3e36d 100644 --- a/tests/ui/needless_for_each_fixable.stderr +++ b/tests/ui/needless_for_each_fixable.stderr @@ -2,6 +2,7 @@ error: needless use of `for_each` --> tests/ui/needless_for_each_fixable.rs:15:5 | LL | / v.iter().for_each(|elem| { +LL | | LL | | acc += elem; LL | | }); | |_______^ @@ -11,14 +12,16 @@ LL | | }); help: try | LL ~ for elem in v.iter() { +LL + LL + acc += elem; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:18:5 + --> tests/ui/needless_for_each_fixable.rs:19:5 | LL | / v.into_iter().for_each(|elem| { +LL | | LL | | acc += elem; LL | | }); | |_______^ @@ -26,14 +29,16 @@ LL | | }); help: try | LL ~ for elem in v.into_iter() { +LL + LL + acc += elem; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:22:5 + --> tests/ui/needless_for_each_fixable.rs:24:5 | LL | / [1, 2, 3].iter().for_each(|elem| { +LL | | LL | | acc += elem; LL | | }); | |_______^ @@ -41,14 +46,16 @@ LL | | }); help: try | LL ~ for elem in [1, 2, 3].iter() { +LL + LL + acc += elem; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:27:5 + --> tests/ui/needless_for_each_fixable.rs:30:5 | LL | / hash_map.iter().for_each(|(k, v)| { +LL | | LL | | acc += k + v; LL | | }); | |_______^ @@ -56,14 +63,16 @@ LL | | }); help: try | LL ~ for (k, v) in hash_map.iter() { +LL + LL + acc += k + v; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:30:5 + --> tests/ui/needless_for_each_fixable.rs:34:5 | LL | / hash_map.iter_mut().for_each(|(k, v)| { +LL | | LL | | acc += *k + *v; LL | | }); | |_______^ @@ -71,14 +80,16 @@ LL | | }); help: try | LL ~ for (k, v) in hash_map.iter_mut() { +LL + LL + acc += *k + *v; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:33:5 + --> tests/ui/needless_for_each_fixable.rs:38:5 | LL | / hash_map.keys().for_each(|k| { +LL | | LL | | acc += k; LL | | }); | |_______^ @@ -86,14 +97,16 @@ LL | | }); help: try | LL ~ for k in hash_map.keys() { +LL + LL + acc += k; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:36:5 + --> tests/ui/needless_for_each_fixable.rs:42:5 | LL | / hash_map.values().for_each(|v| { +LL | | LL | | acc += v; LL | | }); | |_______^ @@ -101,14 +114,16 @@ LL | | }); help: try | LL ~ for v in hash_map.values() { +LL + LL + acc += v; LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:43:5 + --> tests/ui/needless_for_each_fixable.rs:50:5 | LL | / my_vec().iter().for_each(|elem| { +LL | | LL | | acc += elem; LL | | }); | |_______^ @@ -116,6 +131,7 @@ LL | | }); help: try | LL ~ for elem in my_vec().iter() { +LL + LL + acc += elem; LL + } | diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 2220cf9e11ee..56faa471ed8c 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -6,8 +6,9 @@ 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` + //~^ needless_for_each + + if *v == 10 { return; } else { diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 682140a1dfda..37470a8a622e 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -2,9 +2,6 @@ error: needless use of `for_each` --> tests/ui/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { -LL | | -LL | | -LL | | if *v == 10 { ... | LL | | }); | |_______^ @@ -15,7 +12,8 @@ help: try | LL ~ for v in v.iter() { LL + -LL + +LL + +LL + LL + if *v == 10 { LL + return; LL + } else { diff --git a/tests/ui/needless_if.fixed b/tests/ui/needless_if.fixed index 79e33a7218b7..1e2842a27aa6 100644 --- a/tests/ui/needless_if.fixed +++ b/tests/ui/needless_if.fixed @@ -25,13 +25,16 @@ fn maybe_side_effect() -> bool { fn main() { // Lint + //~^ needless_if // Do not remove the condition maybe_side_effect(); + //~^ needless_if // Do not lint if (true) { } else { } ({ + //~^ needless_if return; }); // Do not lint if `else if` is present @@ -48,6 +51,7 @@ fn main() { {} // Can lint nested `if let`s ({ + //~^ needless_if if let true = true && true { @@ -91,12 +95,15 @@ fn main() { // Must be placed into an expression context to not be interpreted as a block ({ maybe_side_effect() }); + //~^ needless_if // Would be a block followed by `&&true` - a double reference to `true` ({ maybe_side_effect() } && true); + //~^ needless_if // Don't leave trailing attributes #[allow(unused)] true; + //~^ needless_if let () = if maybe_side_effect() {}; } diff --git a/tests/ui/needless_if.rs b/tests/ui/needless_if.rs index 2c135fb22bf8..a753c66da5a5 100644 --- a/tests/ui/needless_if.rs +++ b/tests/ui/needless_if.rs @@ -25,13 +25,16 @@ fn maybe_side_effect() -> bool { fn main() { // Lint if (true) {} + //~^ needless_if // Do not remove the condition if maybe_side_effect() {} + //~^ needless_if // Do not lint if (true) { } else { } if { + //~^ needless_if return; } {} // Do not lint if `else if` is present @@ -48,6 +51,7 @@ fn main() { {} // Can lint nested `if let`s if { + //~^ needless_if if let true = true && true { @@ -92,12 +96,15 @@ fn main() { // Must be placed into an expression context to not be interpreted as a block if { maybe_side_effect() } {} + //~^ needless_if // Would be a block followed by `&&true` - a double reference to `true` if { maybe_side_effect() } && true {} + //~^ needless_if // Don't leave trailing attributes #[allow(unused)] if true {} + //~^ needless_if let () = if maybe_side_effect() {}; } diff --git a/tests/ui/needless_if.stderr b/tests/ui/needless_if.stderr index cbfeb979d2f2..eeb8d044526d 100644 --- a/tests/ui/needless_if.stderr +++ b/tests/ui/needless_if.stderr @@ -8,15 +8,16 @@ LL | if (true) {} = help: to override `-D warnings` add `#[allow(clippy::needless_if)]` error: this `if` branch is empty - --> tests/ui/needless_if.rs:29:5 + --> tests/ui/needless_if.rs:30:5 | LL | if maybe_side_effect() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();` error: this `if` branch is empty - --> tests/ui/needless_if.rs:34:5 + --> tests/ui/needless_if.rs:36:5 | LL | / if { +LL | | LL | | return; LL | | } {} | |________^ @@ -24,14 +25,16 @@ LL | | } {} help: you can remove it | LL ~ ({ +LL + LL + return; LL + }); | error: this `if` branch is empty - --> tests/ui/needless_if.rs:50:5 + --> tests/ui/needless_if.rs:53:5 | LL | / if { +LL | | LL | | if let true = true LL | | && true ... | @@ -42,6 +45,7 @@ LL | | {} help: you can remove it | LL ~ ({ +LL + LL + if let true = true LL + && true LL + { @@ -53,19 +57,19 @@ LL + } && true); | error: this `if` branch is empty - --> tests/ui/needless_if.rs:94:5 + --> tests/ui/needless_if.rs:98:5 | LL | if { maybe_side_effect() } {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });` error: this `if` branch is empty - --> tests/ui/needless_if.rs:96:5 + --> tests/ui/needless_if.rs:101:5 | LL | if { maybe_side_effect() } && true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() } && true);` error: this `if` branch is empty - --> tests/ui/needless_if.rs:100:5 + --> tests/ui/needless_if.rs:106: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 b4bd53ce7bf7..eb67e6cc8282 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -25,22 +25,28 @@ impl std::ops::Drop for SignificantDrop { fn simple() { + //~^ needless_late_init let a = "zero"; + //~^ needless_late_init + //~^ needless_late_init let b = 1; let c = 2; + //~^ needless_late_init let d: usize = 1; + //~^ needless_late_init let e = format!("{}", d); } fn main() { + //~^ needless_late_init let n = 1; let a = match n { 1 => "one", @@ -50,6 +56,7 @@ fn main() { }; + //~^ needless_late_init let b = if n == 3 { "four" } else { @@ -57,6 +64,7 @@ fn main() { }; + //~^ needless_late_init let d = if true { let temp = 5; temp @@ -65,6 +73,7 @@ fn main() { }; + //~^ needless_late_init let e = if true { format!("{} {}", a, b) } else { @@ -72,12 +81,14 @@ fn main() { }; + //~^ needless_late_init let f = match 1 { 1 => "three", _ => return, }; // has semi + //~^ needless_late_init let g: usize = if true { 5 } else { @@ -86,14 +97,17 @@ fn main() { // Drop order only matters if both are significant + //~^ needless_late_init let y = SignificantDrop; let x = 1; + //~^ needless_late_init let y = 1; let x = SignificantDrop; + //~^ needless_late_init // types that should be considered insignificant let y = 1; let y = "2"; @@ -113,6 +127,7 @@ async fn in_async() -> &'static str { } + //~^ needless_late_init let n = 1; let a = match n { 1 => f().await, @@ -130,6 +145,7 @@ const fn in_const() -> &'static str { } + //~^ needless_late_init let n = 1; let a = match n { 1 => f(), diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index e25483625a68..7de2202dc323 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -25,22 +25,28 @@ impl std::ops::Drop for SignificantDrop { fn simple() { let a; + //~^ needless_late_init a = "zero"; let b; + //~^ needless_late_init let c; + //~^ needless_late_init b = 1; c = 2; let d: usize; + //~^ needless_late_init d = 1; let e; + //~^ needless_late_init e = format!("{}", d); } fn main() { let a; + //~^ needless_late_init let n = 1; match n { 1 => a = "one", @@ -50,6 +56,7 @@ fn main() { } let b; + //~^ needless_late_init if n == 3 { b = "four"; } else { @@ -57,6 +64,7 @@ fn main() { } let d; + //~^ needless_late_init if true { let temp = 5; d = temp; @@ -65,6 +73,7 @@ fn main() { } let e; + //~^ needless_late_init if true { e = format!("{} {}", a, b); } else { @@ -72,12 +81,14 @@ fn main() { } let f; + //~^ needless_late_init match 1 { 1 => f = "three", _ => return, }; // has semi let g: usize; + //~^ needless_late_init if true { g = 5; } else { @@ -86,14 +97,17 @@ fn main() { // Drop order only matters if both are significant let x; + //~^ needless_late_init let y = SignificantDrop; x = 1; let x; + //~^ needless_late_init let y = 1; x = SignificantDrop; let x; + //~^ needless_late_init // types that should be considered insignificant let y = 1; let y = "2"; @@ -113,6 +127,7 @@ async fn in_async() -> &'static str { } let a; + //~^ needless_late_init let n = 1; match n { 1 => a = f().await, @@ -130,6 +145,7 @@ const fn in_const() -> &'static str { } let a; + //~^ needless_late_init let n = 1; match n { 1 => a = f(), diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index de048091cfbe..02fd2811da58 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -3,6 +3,7 @@ error: unneeded late initialization | LL | let a; | ^^^^^^ created here +LL | LL | a = "zero"; | ^^^^^^^^^^ initialised here | @@ -11,71 +12,79 @@ LL | a = "zero"; help: move the declaration `a` here | LL ~ +LL | LL ~ let a = "zero"; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:30:5 + --> tests/ui/needless_late_init.rs:31:5 | LL | let b; | ^^^^^^ created here -LL | let c; +... LL | b = 1; | ^^^^^ initialised here | help: move the declaration `b` here | LL ~ +LL | LL | let c; +LL | LL ~ let b = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:31:5 + --> tests/ui/needless_late_init.rs:33:5 | LL | let c; | ^^^^^^ created here -LL | b = 1; +... LL | c = 2; | ^^^^^ initialised here | help: move the declaration `c` here | LL ~ +LL | LL | b = 1; LL ~ let c = 2; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:35:5 + --> tests/ui/needless_late_init.rs:38:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here +LL | LL | d = 1; | ^^^^^ initialised here | help: move the declaration `d` here | LL ~ +LL | LL ~ let d: usize = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:38:5 + --> tests/ui/needless_late_init.rs:42:5 | LL | let e; | ^^^^^^ created here +LL | LL | e = format!("{}", d); | ^^^^^^^^^^^^^^^^^^^^ initialised here | help: move the declaration `e` here | LL ~ +LL | LL ~ let e = format!("{}", d); | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:43:5 + --> tests/ui/needless_late_init.rs:48:5 | LL | let a; | ^^^^^^ @@ -83,6 +92,7 @@ LL | let a; help: move the declaration `a` here and remove the assignments from the `match` arms | LL ~ +LL | LL | let n = 1; LL ~ let a = match n { LL ~ 1 => "one", @@ -93,7 +103,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:52:5 + --> tests/ui/needless_late_init.rs:58:5 | LL | let b; | ^^^^^^ @@ -101,6 +111,7 @@ LL | let b; help: move the declaration `b` here and remove the assignments from the branches | LL ~ +LL | LL ~ let b = if n == 3 { LL ~ "four" LL | } else { @@ -109,7 +120,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:59:5 + --> tests/ui/needless_late_init.rs:66:5 | LL | let d; | ^^^^^^ @@ -117,6 +128,7 @@ LL | let d; help: move the declaration `d` here and remove the assignments from the branches | LL ~ +LL | LL ~ let d = if true { LL | let temp = 5; LL ~ temp @@ -126,7 +138,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:67:5 + --> tests/ui/needless_late_init.rs:75:5 | LL | let e; | ^^^^^^ @@ -134,6 +146,7 @@ LL | let e; help: move the declaration `e` here and remove the assignments from the branches | LL ~ +LL | LL ~ let e = if true { LL ~ format!("{} {}", a, b) LL | } else { @@ -142,7 +155,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:74:5 + --> tests/ui/needless_late_init.rs:83:5 | LL | let f; | ^^^^^^ @@ -150,12 +163,13 @@ LL | let f; help: move the declaration `f` here and remove the assignments from the `match` arms | LL ~ +LL | LL ~ let f = match 1 { LL ~ 1 => "three", | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:80:5 + --> tests/ui/needless_late_init.rs:90:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -163,6 +177,7 @@ LL | let g: usize; help: move the declaration `g` here and remove the assignments from the branches | LL ~ +LL | LL ~ let g: usize = if true { LL ~ 5 LL | } else { @@ -171,39 +186,24 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:88:5 + --> tests/ui/needless_late_init.rs:99:5 | LL | let x; | ^^^^^^ created here -LL | let y = SignificantDrop; +... LL | x = 1; | ^^^^^ initialised here | help: move the declaration `x` here | LL ~ +LL | LL | let y = SignificantDrop; LL ~ let x = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:92:5 - | -LL | let x; - | ^^^^^^ created here -LL | let y = 1; -LL | x = SignificantDrop; - | ^^^^^^^^^^^^^^^^^^^ initialised here - | -help: move the declaration `x` here - | -LL ~ -LL | let y = 1; -LL ~ let x = SignificantDrop; - | - -error: unneeded late initialization - --> tests/ui/needless_late_init.rs:96:5 + --> tests/ui/needless_late_init.rs:104:5 | LL | let x; | ^^^^^^ created here @@ -214,14 +214,31 @@ LL | x = SignificantDrop; help: move the declaration `x` here | LL ~ -LL | // types that should be considered insignificant +LL | +LL | let y = 1; +LL ~ let x = SignificantDrop; + | + +error: unneeded late initialization + --> tests/ui/needless_late_init.rs:109:5 + | +LL | let x; + | ^^^^^^ created here +... +LL | x = SignificantDrop; + | ^^^^^^^^^^^^^^^^^^^ initialised here + | +help: move the declaration `x` here + | +LL ~ +LL | ... LL | let y = Box::new(4); LL ~ let x = SignificantDrop; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:115:5 + --> tests/ui/needless_late_init.rs:129:5 | LL | let a; | ^^^^^^ @@ -229,6 +246,7 @@ LL | let a; help: move the declaration `a` here and remove the assignments from the `match` arms | LL ~ +LL | LL | let n = 1; LL ~ let a = match n { LL ~ 1 => f().await, @@ -239,7 +257,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:132:5 + --> tests/ui/needless_late_init.rs:147:5 | LL | let a; | ^^^^^^ @@ -247,6 +265,7 @@ LL | let a; help: move the declaration `a` here and remove the assignments from the `match` arms | LL ~ +LL | LL | let n = 1; LL ~ let a = match n { LL ~ 1 => f(), diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index 86cf9a9cdb63..3cfbce84cd9b 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -9,15 +9,18 @@ clippy::redundant_allocation, clippy::unnecessary_wraps, dyn_drop, - clippy::get_first + clippy::get_first, + elided_named_lifetimes )] extern crate proc_macros; use proc_macros::inline_macros; fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} +//~^ needless_lifetimes fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} +//~^ needless_lifetimes // No error; same lifetime on two params. fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} @@ -28,6 +31,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} fn in_and_out(x: &u8, _y: u8) -> &u8 { +//~^ needless_lifetimes x } @@ -40,6 +44,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { +//~^ needless_lifetimes x } @@ -47,6 +52,7 @@ fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { +//~^ needless_lifetimes y } @@ -64,6 +70,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { +//~^ needless_lifetimes Ok(x) } @@ -71,6 +78,7 @@ fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { +//~^ needless_lifetimes Ok(y) } @@ -80,11 +88,13 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { } fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { +//~^ needless_lifetimes Ok(x) } // Where-clause, but without lifetimes. fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> +//~^ needless_lifetimes where T: Copy, { @@ -97,6 +107,7 @@ type Ref<'r> = &'r u8; fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} +//~^ needless_lifetimes // No error; bounded lifetime. fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} @@ -121,6 +132,7 @@ where } fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> +//~^ needless_lifetimes where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, { @@ -151,6 +163,7 @@ struct X { impl X { fn self_and_out(&self) -> &u8 { + //~^ needless_lifetimes &self.x } @@ -158,6 +171,7 @@ impl X { // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { + //~^ needless_lifetimes &self.x } @@ -165,10 +179,12 @@ impl X { // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { + //~^ needless_lifetimes x } fn distinct_self_and_in(&self, _x: &u8) {} + //~^ needless_lifetimes // No error; same lifetimes on two params. fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} @@ -188,6 +204,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { } fn struct_with_lt(_foo: Foo<'_>) -> &str { +//~^ needless_lifetimes unimplemented!() } @@ -206,6 +223,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -214,6 +232,7 @@ fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { +//~^ needless_lifetimes unimplemented!() } @@ -229,12 +248,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. fn trait_obj_elided2(_arg: &dyn Drop) -> &str { +//~^ needless_lifetimes unimplemented!() } type FooAlias<'a> = Foo<'a>; fn alias_with_lt(_foo: FooAlias<'_>) -> &str { +//~^ needless_lifetimes unimplemented!() } @@ -253,6 +274,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -261,10 +283,12 @@ fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { +//~^ needless_lifetimes unimplemented!() } fn named_input_elided_output(_arg: &str) -> &str { +//~^ needless_lifetimes unimplemented!() } @@ -273,6 +297,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { } fn trait_bound_ok>(_: &u8, _: T) { +//~^ needless_lifetimes unimplemented!() } fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { @@ -309,6 +334,7 @@ struct Cow<'a> { x: &'a str, } fn out_return_type_lts(e: &str) -> Cow<'_> { +//~^ needless_lifetimes unimplemented!() } @@ -316,10 +342,12 @@ fn out_return_type_lts(e: &str) -> Cow<'_> { mod issue4291 { trait BadTrait { fn needless_lt(x: &u8) {} + //~^ needless_lifetimes } impl BadTrait for () { fn needless_lt(_x: &u8) {} + //~^ needless_lifetimes } } @@ -331,8 +359,10 @@ mod issue2944 { } impl Foo for Baz<'_> {} + //~^ needless_lifetimes impl Bar { fn baz(&self) -> impl Foo + '_ { + //~^ needless_lifetimes Baz { bar: self } } } @@ -365,6 +395,7 @@ mod nested_elision_sites { f(i) } fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(&i32) -> &i32) -> &i32 { + //~^ needless_lifetimes f(i) } @@ -374,6 +405,7 @@ mod nested_elision_sites { } // lint fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { + //~^ needless_lifetimes f(i) } @@ -386,6 +418,7 @@ mod nested_elision_sites { } // lint fn where_clause_elidable(i: &i32, f: T) -> &i32 + //~^ needless_lifetimes where T: Fn(&i32) -> &i32, { @@ -401,6 +434,7 @@ mod nested_elision_sites { } // lint fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { + //~^ needless_lifetimes f(i) } @@ -414,9 +448,11 @@ mod nested_elision_sites { // lint fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { + //~^ needless_lifetimes |f| 42 } fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { + //~^ needless_lifetimes |f| () } } @@ -439,17 +475,21 @@ mod issue7296 { struct Foo; impl Foo { fn implicit(&self) -> &() { + //~^ needless_lifetimes &() } fn implicit_mut(&mut self) -> &() { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit(self: &Arc) -> &() { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit_mut(self: &mut Rc) -> &() { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -462,20 +502,25 @@ mod issue7296 { } fn lifetime_elsewhere(self: Box, here: &()) -> &() { + //~^ needless_lifetimes &() } } trait Bar { fn implicit(&self) -> &(); + //~^ needless_lifetimes fn implicit_provided(&self) -> &() { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit(self: &Arc) -> &(); + //~^ needless_lifetimes #[clippy::msrv = "1.81"] fn explicit_provided(self: &Arc) -> &() { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -486,7 +531,9 @@ mod issue7296 { } fn lifetime_elsewhere(self: Box, here: &()) -> &(); + //~^ needless_lifetimes fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { + //~^ needless_lifetimes &() } } @@ -496,8 +543,10 @@ mod pr_9743_false_negative_fix { #![allow(unused)] fn foo(x: &u8, y: &'_ u8) {} + //~^ needless_lifetimes fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} + //~^ needless_lifetimes } mod pr_9743_output_lifetime_checks { @@ -505,11 +554,13 @@ mod pr_9743_output_lifetime_checks { // lint: only one input fn one_input(x: &u8) -> &u8 { + //~^ needless_lifetimes unimplemented!() } // lint: multiple inputs, output would not be elided fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) -> &'b u8 { + //~^ needless_lifetimes unimplemented!() } @@ -526,6 +577,7 @@ mod in_macro { // lint local macro expands to function with needless lifetimes inline! { fn one_input(x: &u8) -> &u8 { + //~^ needless_lifetimes unimplemented!() } } @@ -621,6 +673,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&self` fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { match self { @@ -631,6 +684,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&'_ self` fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { match self { @@ -651,6 +705,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&Self` fn map_content5( self: std::pin::Pin<&Self>, @@ -672,6 +727,7 @@ mod issue13923 { // `'c` cannot be elided because we have several input lifetimes fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { x.b + //~^ needless_borrow } } diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 1ee0f4c6092a..612e7546d962 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -9,15 +9,18 @@ clippy::redundant_allocation, clippy::unnecessary_wraps, dyn_drop, - clippy::get_first + clippy::get_first, + elided_named_lifetimes )] extern crate proc_macros; use proc_macros::inline_macros; fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} +//~^ needless_lifetimes fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} +//~^ needless_lifetimes // No error; same lifetime on two params. fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) {} @@ -28,6 +31,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { +//~^ needless_lifetimes x } @@ -40,6 +44,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { +//~^ needless_lifetimes x } @@ -47,6 +52,7 @@ fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { +//~^ needless_lifetimes y } @@ -64,6 +70,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { +//~^ needless_lifetimes Ok(x) } @@ -71,6 +78,7 @@ fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { +//~^ needless_lifetimes Ok(y) } @@ -80,11 +88,13 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { } fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { +//~^ needless_lifetimes Ok(x) } // Where-clause, but without lifetimes. fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> +//~^ needless_lifetimes where T: Copy, { @@ -97,6 +107,7 @@ type Ref<'r> = &'r u8; fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} +//~^ needless_lifetimes // No error; bounded lifetime. fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} @@ -121,6 +132,7 @@ where } fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +//~^ needless_lifetimes where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, { @@ -151,6 +163,7 @@ struct X { impl X { fn self_and_out<'s>(&'s self) -> &'s u8 { + //~^ needless_lifetimes &self.x } @@ -158,6 +171,7 @@ impl X { // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { + //~^ needless_lifetimes &self.x } @@ -165,10 +179,12 @@ impl X { // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { + //~^ needless_lifetimes x } fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} + //~^ needless_lifetimes // No error; same lifetimes on two params. fn self_and_same_in<'s>(&'s self, _x: &'s u8) {} @@ -188,6 +204,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { } fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -206,6 +223,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -214,6 +232,7 @@ fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { +//~^ needless_lifetimes unimplemented!() } @@ -229,12 +248,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { +//~^ needless_lifetimes unimplemented!() } type FooAlias<'a> = Foo<'a>; fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -253,6 +274,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { +//~^ needless_lifetimes unimplemented!() } @@ -261,10 +283,12 @@ fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { +//~^ needless_lifetimes unimplemented!() } fn named_input_elided_output<'a>(_arg: &'a str) -> &str { +//~^ needless_lifetimes unimplemented!() } @@ -273,6 +297,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { } fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { +//~^ needless_lifetimes unimplemented!() } fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { @@ -309,6 +334,7 @@ struct Cow<'a> { x: &'a str, } fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { +//~^ needless_lifetimes unimplemented!() } @@ -316,10 +342,12 @@ fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { mod issue4291 { trait BadTrait { fn needless_lt<'a>(x: &'a u8) {} + //~^ needless_lifetimes } impl BadTrait for () { fn needless_lt<'a>(_x: &'a u8) {} + //~^ needless_lifetimes } } @@ -331,8 +359,10 @@ mod issue2944 { } impl<'a> Foo for Baz<'a> {} + //~^ needless_lifetimes impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { + //~^ needless_lifetimes Baz { bar: self } } } @@ -365,6 +395,7 @@ mod nested_elision_sites { f(i) } fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { + //~^ needless_lifetimes f(i) } @@ -374,6 +405,7 @@ mod nested_elision_sites { } // lint fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { + //~^ needless_lifetimes f(i) } @@ -386,6 +418,7 @@ mod nested_elision_sites { } // lint fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 + //~^ needless_lifetimes where T: Fn(&i32) -> &i32, { @@ -401,6 +434,7 @@ mod nested_elision_sites { } // lint fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { + //~^ needless_lifetimes f(i) } @@ -414,9 +448,11 @@ mod nested_elision_sites { // lint fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { + //~^ needless_lifetimes |f| 42 } fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { + //~^ needless_lifetimes |f| () } } @@ -439,17 +475,21 @@ mod issue7296 { struct Foo; impl Foo { fn implicit<'a>(&'a self) -> &'a () { + //~^ needless_lifetimes &() } fn implicit_mut<'a>(&'a mut self) -> &'a () { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit<'a>(self: &'a Arc) -> &'a () { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit_mut<'a>(self: &'a mut Rc) -> &'a () { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -462,20 +502,25 @@ mod issue7296 { } fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { + //~^ needless_lifetimes &() } } trait Bar { fn implicit<'a>(&'a self) -> &'a (); + //~^ needless_lifetimes fn implicit_provided<'a>(&'a self) -> &'a () { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit<'a>(self: &'a Arc) -> &'a (); + //~^ needless_lifetimes #[clippy::msrv = "1.81"] fn explicit_provided<'a>(self: &'a Arc) -> &'a () { + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -486,7 +531,9 @@ mod issue7296 { } fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); + //~^ needless_lifetimes fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { + //~^ needless_lifetimes &() } } @@ -496,8 +543,10 @@ mod pr_9743_false_negative_fix { #![allow(unused)] fn foo<'a>(x: &'a u8, y: &'_ u8) {} + //~^ needless_lifetimes fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} + //~^ needless_lifetimes } mod pr_9743_output_lifetime_checks { @@ -505,11 +554,13 @@ mod pr_9743_output_lifetime_checks { // lint: only one input fn one_input<'a>(x: &'a u8) -> &'a u8 { + //~^ needless_lifetimes unimplemented!() } // lint: multiple inputs, output would not be elided fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { + //~^ needless_lifetimes unimplemented!() } @@ -526,6 +577,7 @@ mod in_macro { // lint local macro expands to function with needless lifetimes inline! { fn one_input<'a>(x: &'a u8) -> &'a u8 { + //~^ needless_lifetimes unimplemented!() } } @@ -621,6 +673,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&self` fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { match self { @@ -631,6 +684,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&'_ self` fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { match self { @@ -651,6 +705,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { + //~^ needless_lifetimes // `'py` can be elided because of `&Self` fn map_content5( self: std::pin::Pin<&Self>, @@ -672,6 +727,7 @@ mod issue13923 { // `'c` cannot be elided because we have several input lifetimes fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { &x.b + //~^ needless_borrow } } diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 465d529bf16c..b1d1c88a2968 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -1,16 +1,5 @@ -error: elided lifetime has a name - --> tests/ui/needless_lifetimes.rs:267:52 - | -LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { - | -- ^ this elided lifetime gets resolved as `'a` - | | - | lifetime `'a` declared here - | - = note: `-D elided-named-lifetimes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(elided_named_lifetimes)]` - error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:18:23 + --> tests/ui/needless_lifetimes.rs:19:23 | LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} | ^^ ^^ ^^ ^^ @@ -24,7 +13,7 @@ LL + fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} | error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:20:24 + --> tests/ui/needless_lifetimes.rs:22:24 | LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} | ^^ ^^ ^^ ^^ @@ -36,7 +25,7 @@ LL + fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:30:15 + --> tests/ui/needless_lifetimes.rs:33:15 | LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^ ^^ ^^ @@ -48,7 +37,7 @@ LL + fn in_and_out(x: &u8, _y: u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:42:31 + --> tests/ui/needless_lifetimes.rs:46:31 | LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { | ^^ ^^ @@ -60,7 +49,7 @@ LL + fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:49:27 + --> tests/ui/needless_lifetimes.rs:54:27 | LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { | ^^ ^^ @@ -72,7 +61,7 @@ LL + fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:66:26 + --> tests/ui/needless_lifetimes.rs:72:26 | LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { | ^^ ^^ @@ -84,7 +73,7 @@ LL + fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:73:22 + --> tests/ui/needless_lifetimes.rs:80:22 | LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { | ^^ ^^ @@ -96,7 +85,7 @@ LL + fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:82:21 + --> tests/ui/needless_lifetimes.rs:90:21 | LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { | ^^ ^^ ^^ @@ -108,7 +97,7 @@ LL + fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:87:28 + --> tests/ui/needless_lifetimes.rs:96:28 | LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> | ^^ ^^ ^^ @@ -120,7 +109,7 @@ LL + fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> | error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:99:21 + --> tests/ui/needless_lifetimes.rs:109:21 | LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} | ^^ ^^ ^^ ^^ @@ -132,7 +121,7 @@ LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:123:15 + --> tests/ui/needless_lifetimes.rs:134:15 | LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ^^ ^^ ^^ @@ -144,7 +133,7 @@ LL + fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> | error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:153:21 + --> tests/ui/needless_lifetimes.rs:165:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -156,7 +145,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> tests/ui/needless_lifetimes.rs:160:30 + --> tests/ui/needless_lifetimes.rs:173:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -168,7 +157,7 @@ LL + fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { | error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:167:26 + --> tests/ui/needless_lifetimes.rs:181:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -180,7 +169,7 @@ LL + fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { | error: the following explicit lifetimes could be elided: 's, 't - --> tests/ui/needless_lifetimes.rs:171:29 + --> tests/ui/needless_lifetimes.rs:186:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -192,7 +181,7 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:190:19 + --> tests/ui/needless_lifetimes.rs:206:19 | LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { | ^^ ^^ ^^ @@ -204,7 +193,7 @@ LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:208:25 + --> tests/ui/needless_lifetimes.rs:225:25 | LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { | ^^ ^^ @@ -216,7 +205,7 @@ LL + fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:216:21 + --> tests/ui/needless_lifetimes.rs:234:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -228,7 +217,7 @@ LL + fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:231:22 + --> tests/ui/needless_lifetimes.rs:250:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -240,7 +229,7 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:237:18 + --> tests/ui/needless_lifetimes.rs:257:18 | LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { | ^^ ^^ ^^ @@ -252,7 +241,7 @@ LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:255:24 + --> tests/ui/needless_lifetimes.rs:276:24 | LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ^^ ^^ @@ -264,7 +253,7 @@ LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:263:20 + --> tests/ui/needless_lifetimes.rs:285:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -276,7 +265,7 @@ LL + fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:267:30 + --> tests/ui/needless_lifetimes.rs:290:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -288,7 +277,7 @@ LL + fn named_input_elided_output(_arg: &str) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:275:19 + --> tests/ui/needless_lifetimes.rs:299:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -300,7 +289,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:311:24 + --> tests/ui/needless_lifetimes.rs:336:24 | LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { | ^^ ^^ ^^ @@ -312,7 +301,7 @@ LL + fn out_return_type_lts(e: &str) -> Cow<'_> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:318:24 + --> tests/ui/needless_lifetimes.rs:344:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -324,7 +313,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:322:24 + --> tests/ui/needless_lifetimes.rs:349:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -336,7 +325,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:333:10 + --> tests/ui/needless_lifetimes.rs:361:10 | LL | impl<'a> Foo for Baz<'a> {} | ^^ ^^ @@ -348,7 +337,7 @@ LL + impl Foo for Baz<'_> {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:335:16 + --> tests/ui/needless_lifetimes.rs:364:16 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ @@ -360,7 +349,7 @@ LL + fn baz(&self) -> impl Foo + '_ { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:367:55 + --> tests/ui/needless_lifetimes.rs:397:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -372,7 +361,7 @@ LL + fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(& | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:376:26 + --> tests/ui/needless_lifetimes.rs:407:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -384,7 +373,7 @@ LL + fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:388:30 + --> tests/ui/needless_lifetimes.rs:420:30 | LL | fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -396,7 +385,7 @@ LL + fn where_clause_elidable(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:403:28 + --> tests/ui/needless_lifetimes.rs:436:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -408,7 +397,7 @@ LL + fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:416:28 + --> tests/ui/needless_lifetimes.rs:450:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -420,7 +409,7 @@ LL + fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:419:28 + --> tests/ui/needless_lifetimes.rs:454:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -432,7 +421,7 @@ LL + fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:441:21 + --> tests/ui/needless_lifetimes.rs:477:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -444,7 +433,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:444:25 + --> tests/ui/needless_lifetimes.rs:481:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -456,7 +445,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:448:21 + --> tests/ui/needless_lifetimes.rs:486:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -468,7 +457,7 @@ LL + fn explicit(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:452:25 + --> tests/ui/needless_lifetimes.rs:491:25 | LL | fn explicit_mut<'a>(self: &'a mut Rc) -> &'a () { | ^^ ^^ ^^ @@ -480,7 +469,7 @@ LL + fn explicit_mut(self: &mut Rc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:464:31 + --> tests/ui/needless_lifetimes.rs:504:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -492,7 +481,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:470:21 + --> tests/ui/needless_lifetimes.rs:511:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -504,7 +493,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:471:30 + --> tests/ui/needless_lifetimes.rs:513:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -516,7 +505,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:476:21 + --> tests/ui/needless_lifetimes.rs:519:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a (); | ^^ ^^ ^^ @@ -528,7 +517,7 @@ LL + fn explicit(self: &Arc) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:478:30 + --> tests/ui/needless_lifetimes.rs:522:30 | LL | fn explicit_provided<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -540,7 +529,7 @@ LL + fn explicit_provided(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:488:31 + --> tests/ui/needless_lifetimes.rs:533:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -552,7 +541,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:489:40 + --> tests/ui/needless_lifetimes.rs:535:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -564,7 +553,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:498:12 + --> tests/ui/needless_lifetimes.rs:545:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -576,7 +565,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:500:12 + --> tests/ui/needless_lifetimes.rs:548:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -588,7 +577,7 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:507:18 + --> tests/ui/needless_lifetimes.rs:556:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -600,7 +589,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:512:42 + --> tests/ui/needless_lifetimes.rs:562:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -612,7 +601,7 @@ LL + fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:528:22 + --> tests/ui/needless_lifetimes.rs:579:22 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -625,39 +614,41 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:623:14 + --> tests/ui/needless_lifetimes.rs:675:14 | LL | impl<'t, 'py> ContentString<'t> { | ^^^ -LL | // `'py` can be elided because of `&self` +... LL | fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { | ^^^ | help: elide the lifetimes | LL ~ impl<'t> ContentString<'t> { +LL | LL | // `'py` can be elided because of `&self` LL ~ fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { | error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:633:14 + --> tests/ui/needless_lifetimes.rs:686:14 | LL | impl<'t, 'py> ContentString<'t> { | ^^^ -LL | // `'py` can be elided because of `&'_ self` +... LL | fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { | ^^^ | help: elide the lifetimes | LL ~ impl<'t> ContentString<'t> { +LL | LL | // `'py` can be elided because of `&'_ self` LL ~ fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { | error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:653:14 + --> tests/ui/needless_lifetimes.rs:707:14 | LL | impl<'t, 'py> ContentString<'t> { | ^^^ @@ -668,14 +659,14 @@ LL | ) -> Content<'t, 'py> { help: elide the lifetimes | LL ~ impl<'t> ContentString<'t> { -LL | // `'py` can be elided because of `&Self` +LL | ... LL | o: &'t str, LL ~ ) -> Content<'t, '_> { | error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_lifetimes.rs:674:9 + --> tests/ui/needless_lifetimes.rs:729:9 | LL | &x.b | ^^^^ help: change this to: `x.b` @@ -683,5 +674,5 @@ LL | &x.b = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` -error: aborting due to 56 previous errors +error: aborting due to 55 previous errors diff --git a/tests/ui/needless_match.fixed b/tests/ui/needless_match.fixed index 06c6169d0da0..b2c2bbfaa361 100644 --- a/tests/ui/needless_match.fixed +++ b/tests/ui/needless_match.fixed @@ -61,6 +61,7 @@ fn result_match() { fn if_let_option() { let _ = Some(1); + //~^ needless_match fn do_something() {} @@ -96,7 +97,9 @@ fn if_let_option_result() -> Result<(), ()> { fn if_let_result() { let x: Result = Ok(1); let _: Result = x; + //~^ needless_match let _: Result = x; + //~^ needless_match // Input type mismatch, don't trigger #[allow(clippy::question_mark)] let _: Result = if let Err(e) = Ok(1) { Err(e) } else { x }; diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs index 6b71de68e1be..848490d9b35e 100644 --- a/tests/ui/needless_match.rs +++ b/tests/ui/needless_match.rs @@ -13,6 +13,7 @@ enum Simple { fn useless_match() { let i = 10; let _: i32 = match i { + //~^ needless_match 0 => 0, 1 => 1, 2 => 2, @@ -20,6 +21,7 @@ fn useless_match() { }; let s = "test"; let _: &str = match s { + //~^ needless_match "a" => "a", "b" => "b", s => s, @@ -29,6 +31,7 @@ fn useless_match() { fn custom_type_match() { let se = Simple::A; let _: Simple = match se { + //~^ needless_match Simple::A => Simple::A, Simple::B => Simple::B, Simple::C => Simple::C, @@ -51,6 +54,7 @@ fn custom_type_match() { fn option_match(x: Option) { let _: Option = match x { + //~^ needless_match Some(a) => Some(a), None => None, }; @@ -67,10 +71,12 @@ fn func_ret_err(err: T) -> Result { fn result_match() { let _: Result = match Ok(1) { + //~^ needless_match Ok(a) => Ok(a), Err(err) => Err(err), }; let _: Result = match func_ret_err(0_i32) { + //~^ needless_match Err(err) => Err(err), Ok(a) => Ok(a), }; @@ -84,6 +90,7 @@ fn result_match() { fn if_let_option() { let _ = if let Some(a) = Some(1) { Some(a) } else { None }; + //~^ needless_match fn do_something() {} @@ -119,7 +126,9 @@ fn if_let_option_result() -> Result<(), ()> { fn if_let_result() { let x: Result = Ok(1); let _: Result = if let Err(e) = x { Err(e) } else { x }; + //~^ needless_match let _: Result = if let Ok(val) = x { Ok(val) } else { x }; + //~^ needless_match // Input type mismatch, don't trigger #[allow(clippy::question_mark)] let _: Result = if let Err(e) = Ok(1) { Err(e) } else { x }; @@ -127,6 +136,7 @@ fn if_let_result() { fn if_let_custom_enum(x: Simple) { let _: Simple = if let Simple::A = x { + //~^ needless_match Simple::A } else if let Simple::B = x { Simple::B @@ -166,6 +176,7 @@ mod issue8542 { let bb = false; let _: Complex = match ce { + //~^ needless_match Complex::A(a) => Complex::A(a), Complex::B(a, b) => Complex::B(a, b), Complex::C(a, b, c) => Complex::C(a, b, c), @@ -250,12 +261,14 @@ mod issue9084 { // should lint let _ = match e { + //~^ needless_match _ if some_bool => e, _ => e, }; // should lint let _ = match e { + //~^ needless_match Some(i) => Some(i), _ if some_bool => e, _ => e, @@ -337,6 +350,7 @@ pub fn issue13574() -> Option<()> { // Same const, should lint let _ = { if let Some(num) = A { + //~^ needless_match Some(num) } else if let Some(num) = A { Some(num) diff --git a/tests/ui/needless_match.stderr b/tests/ui/needless_match.stderr index 1410585cb2e3..719b0ef88469 100644 --- a/tests/ui/needless_match.stderr +++ b/tests/ui/needless_match.stderr @@ -3,6 +3,7 @@ error: this match expression is unnecessary | LL | let _: i32 = match i { | __________________^ +LL | | LL | | 0 => 0, LL | | 1 => 1, LL | | 2 => 2, @@ -14,10 +15,11 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_match)]` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:22:19 + --> tests/ui/needless_match.rs:23:19 | LL | let _: &str = match s { | ___________________^ +LL | | LL | | "a" => "a", LL | | "b" => "b", LL | | s => s, @@ -25,10 +27,11 @@ LL | | }; | |_____^ help: replace it with: `s` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:31:21 + --> tests/ui/needless_match.rs:33:21 | LL | let _: Simple = match se { | _____________________^ +LL | | LL | | Simple::A => Simple::A, LL | | Simple::B => Simple::B, LL | | Simple::C => Simple::C, @@ -37,94 +40,99 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:53:26 + --> tests/ui/needless_match.rs:56:26 | LL | let _: Option = match x { | __________________________^ +LL | | LL | | Some(a) => Some(a), LL | | None => None, LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:69:31 + --> tests/ui/needless_match.rs:73:31 | LL | let _: Result = match Ok(1) { | _______________________________^ +LL | | LL | | Ok(a) => Ok(a), LL | | Err(err) => Err(err), LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:73:31 + --> tests/ui/needless_match.rs:78:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ +LL | | LL | | Err(err) => Err(err), LL | | Ok(a) => Ok(a), LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:86:13 + --> tests/ui/needless_match.rs:92:13 | LL | let _ = if let Some(a) = Some(1) { Some(a) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(1)` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:121:31 + --> tests/ui/needless_match.rs:128:31 | LL | let _: Result = if let Err(e) = x { Err(e) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:122:31 + --> tests/ui/needless_match.rs:130:31 | LL | let _: Result = if let Ok(val) = x { Ok(val) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:129:21 + --> tests/ui/needless_match.rs:138:21 | LL | let _: Simple = if let Simple::A = x { | _____________________^ +LL | | LL | | Simple::A LL | | } else if let Simple::B = x { -LL | | Simple::B ... | LL | | x LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:168:26 + --> tests/ui/needless_match.rs:178:26 | LL | let _: Complex = match ce { | __________________________^ +LL | | LL | | Complex::A(a) => Complex::A(a), LL | | Complex::B(a, b) => Complex::B(a, b), -LL | | Complex::C(a, b, c) => Complex::C(a, b, c), -LL | | Complex::D(E::VariantA(ea, eb), b) => Complex::D(E::VariantA(ea, eb), b), +... | LL | | Complex::D(E::VariantB(ea, eb), b) => Complex::D(E::VariantB(ea, eb), b), LL | | }; | |_________^ help: replace it with: `ce` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:252:17 + --> tests/ui/needless_match.rs:263:17 | LL | let _ = match e { | _________________^ +LL | | LL | | _ if some_bool => e, LL | | _ => e, LL | | }; | |_________^ help: replace it with: `e` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:258:17 + --> tests/ui/needless_match.rs:270:17 | LL | let _ = match e { | _________________^ +LL | | LL | | Some(i) => Some(i), LL | | _ if some_bool => e, LL | | _ => e, @@ -132,12 +140,12 @@ LL | | }; | |_________^ help: replace it with: `e` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:339:9 + --> tests/ui/needless_match.rs:352:9 | LL | / if let Some(num) = A { +LL | | LL | | Some(num) LL | | } else if let Some(num) = A { -LL | | Some(num) ... | LL | | None LL | | } diff --git a/tests/ui/needless_maybe_sized.fixed b/tests/ui/needless_maybe_sized.fixed index 4d24a7cee619..68252ba54fd4 100644 --- a/tests/ui/needless_maybe_sized.fixed +++ b/tests/ui/needless_maybe_sized.fixed @@ -7,27 +7,34 @@ extern crate proc_macros; use proc_macros::external; fn directly(t: &T) {} +//~^ needless_maybe_sized trait A: Sized {} trait B: A {} fn depth_1(t: &T) {} +//~^ needless_maybe_sized fn depth_2(t: &T) {} +//~^ needless_maybe_sized // We only need to show one fn multiple_paths(t: &T) {} +//~^ needless_maybe_sized fn in_where(t: &T) where T: Sized, + //~^ needless_maybe_sized { } fn mixed_1(t: &T) + //~^ needless_maybe_sized { } fn mixed_2(t: &T) +//~^ needless_maybe_sized where T: Sized, { @@ -36,38 +43,50 @@ where fn mixed_3(t: &T) where T: Sized, + //~^ needless_maybe_sized { } struct Struct(T); +//~^ needless_maybe_sized impl Struct { +//~^ needless_maybe_sized fn method(&self) {} + //~^ needless_maybe_sized } enum Enum { +//~^ needless_maybe_sized Variant(&'static T), } union Union<'a, T: Sized> { +//~^ needless_maybe_sized a: &'a T, } trait Trait { +//~^ needless_maybe_sized fn trait_method() {} + //~^ needless_maybe_sized type GAT; + //~^ needless_maybe_sized type Assoc: Sized + ?Sized; // False negative } trait SecondInTrait: Send + Sized {} fn second_in_trait() {} +//~^ needless_maybe_sized fn impl_trait(_: &(impl Sized)) {} +//~^ needless_maybe_sized trait GenericTrait: Sized {} fn in_generic_trait, U>() {} +//~^ needless_maybe_sized mod larger_graph { // C1 C2 Sized @@ -83,6 +102,7 @@ mod larger_graph { trait A1: B1 + B2 {} fn larger_graph() {} + //~^ needless_maybe_sized } // Should not lint diff --git a/tests/ui/needless_maybe_sized.rs b/tests/ui/needless_maybe_sized.rs index ef66f9a4f2ae..0cafc0d9ff6e 100644 --- a/tests/ui/needless_maybe_sized.rs +++ b/tests/ui/needless_maybe_sized.rs @@ -7,29 +7,36 @@ extern crate proc_macros; use proc_macros::external; fn directly(t: &T) {} +//~^ needless_maybe_sized trait A: Sized {} trait B: A {} fn depth_1(t: &T) {} +//~^ needless_maybe_sized fn depth_2(t: &T) {} +//~^ needless_maybe_sized // We only need to show one fn multiple_paths(t: &T) {} +//~^ needless_maybe_sized fn in_where(t: &T) where T: Sized + ?Sized, + //~^ needless_maybe_sized { } fn mixed_1(t: &T) where T: ?Sized, + //~^ needless_maybe_sized { } fn mixed_2(t: &T) +//~^ needless_maybe_sized where T: Sized, { @@ -39,38 +46,50 @@ fn mixed_3(t: &T) where T: Sized, T: ?Sized, + //~^ needless_maybe_sized { } struct Struct(T); +//~^ needless_maybe_sized impl Struct { +//~^ needless_maybe_sized fn method(&self) {} + //~^ needless_maybe_sized } enum Enum { +//~^ needless_maybe_sized Variant(&'static T), } union Union<'a, T: Sized + ?Sized> { +//~^ needless_maybe_sized a: &'a T, } trait Trait { +//~^ needless_maybe_sized fn trait_method() {} + //~^ needless_maybe_sized type GAT; + //~^ needless_maybe_sized type Assoc: Sized + ?Sized; // False negative } trait SecondInTrait: Send + Sized {} fn second_in_trait() {} +//~^ needless_maybe_sized fn impl_trait(_: &(impl Sized + ?Sized)) {} +//~^ needless_maybe_sized trait GenericTrait: Sized {} fn in_generic_trait + ?Sized, U>() {} +//~^ needless_maybe_sized mod larger_graph { // C1 C2 Sized @@ -86,6 +105,7 @@ mod larger_graph { trait A1: B1 + B2 {} fn larger_graph() {} + //~^ needless_maybe_sized } // Should not lint diff --git a/tests/ui/needless_maybe_sized.stderr b/tests/ui/needless_maybe_sized.stderr index 3b1d2b49b062..30dcaa48e429 100644 --- a/tests/ui/needless_maybe_sized.stderr +++ b/tests/ui/needless_maybe_sized.stderr @@ -18,13 +18,13 @@ LL + fn directly(t: &T) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:14:19 + --> tests/ui/needless_maybe_sized.rs:15:19 | LL | fn depth_1(t: &T) {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:14:15 + --> tests/ui/needless_maybe_sized.rs:15:15 | LL | fn depth_1(t: &T) {} | ^ @@ -36,13 +36,13 @@ LL + fn depth_1(t: &T) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:15:19 + --> tests/ui/needless_maybe_sized.rs:17:19 | LL | fn depth_2(t: &T) {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:15:15 + --> tests/ui/needless_maybe_sized.rs:17:15 | LL | fn depth_2(t: &T) {} | ^ @@ -55,13 +55,13 @@ LL + fn depth_2(t: &T) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:18:30 + --> tests/ui/needless_maybe_sized.rs:21:30 | LL | fn multiple_paths(t: &T) {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:18:22 + --> tests/ui/needless_maybe_sized.rs:21:22 | LL | fn multiple_paths(t: &T) {} | ^ @@ -73,13 +73,13 @@ LL + fn multiple_paths(t: &T) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:22:16 + --> tests/ui/needless_maybe_sized.rs:26:16 | LL | T: Sized + ?Sized, | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:22:8 + --> tests/ui/needless_maybe_sized.rs:26:8 | LL | T: Sized + ?Sized, | ^^^^^ @@ -90,13 +90,13 @@ LL + T: Sized, | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:28:8 + --> tests/ui/needless_maybe_sized.rs:33:8 | LL | T: ?Sized, | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:26:15 + --> tests/ui/needless_maybe_sized.rs:31:15 | LL | fn mixed_1(t: &T) | ^^^^^ @@ -107,13 +107,13 @@ LL - T: ?Sized, | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:32:15 + --> tests/ui/needless_maybe_sized.rs:38:15 | LL | fn mixed_2(t: &T) | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:34:8 + --> tests/ui/needless_maybe_sized.rs:41:8 | LL | T: Sized, | ^^^^^ @@ -124,13 +124,13 @@ LL + fn mixed_2(t: &T) | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:41:8 + --> tests/ui/needless_maybe_sized.rs:48:8 | LL | T: ?Sized, | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:40:8 + --> tests/ui/needless_maybe_sized.rs:47:8 | LL | T: Sized, | ^^^^^ @@ -142,13 +142,13 @@ LL + T: Sized, | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:45:26 + --> tests/ui/needless_maybe_sized.rs:53:26 | LL | struct Struct(T); | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:45:18 + --> tests/ui/needless_maybe_sized.rs:53:18 | LL | struct Struct(T); | ^^^^^ @@ -159,13 +159,13 @@ LL + struct Struct(T); | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:47:17 + --> tests/ui/needless_maybe_sized.rs:56:17 | LL | impl Struct { | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:47:9 + --> tests/ui/needless_maybe_sized.rs:56:9 | LL | impl Struct { | ^^^^^ @@ -176,13 +176,13 @@ LL + impl Struct { | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:48:26 + --> tests/ui/needless_maybe_sized.rs:58:26 | LL | fn method(&self) {} | ^^^^^^ | note: `U` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:48:18 + --> tests/ui/needless_maybe_sized.rs:58:18 | LL | fn method(&self) {} | ^^^^^ @@ -193,13 +193,13 @@ LL + fn method(&self) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:51:22 + --> tests/ui/needless_maybe_sized.rs:62:22 | LL | enum Enum { | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:51:14 + --> tests/ui/needless_maybe_sized.rs:62:14 | LL | enum Enum { | ^^^^^ @@ -210,13 +210,13 @@ LL + enum Enum { | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:55:28 + --> tests/ui/needless_maybe_sized.rs:67:28 | LL | union Union<'a, T: Sized + ?Sized> { | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:55:20 + --> tests/ui/needless_maybe_sized.rs:67:20 | LL | union Union<'a, T: Sized + ?Sized> { | ^^^^^ @@ -227,13 +227,13 @@ LL + union Union<'a, T: Sized> { | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:59:24 + --> tests/ui/needless_maybe_sized.rs:72:24 | LL | trait Trait { | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:59:16 + --> tests/ui/needless_maybe_sized.rs:72:16 | LL | trait Trait { | ^^^^^ @@ -244,13 +244,13 @@ LL + trait Trait { | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:60:32 + --> tests/ui/needless_maybe_sized.rs:74:32 | LL | fn trait_method() {} | ^^^^^^ | note: `U` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:60:24 + --> tests/ui/needless_maybe_sized.rs:74:24 | LL | fn trait_method() {} | ^^^^^ @@ -261,13 +261,13 @@ LL + fn trait_method() {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:62:25 + --> tests/ui/needless_maybe_sized.rs:77:25 | LL | type GAT; | ^^^^^^ | note: `U` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:62:17 + --> tests/ui/needless_maybe_sized.rs:77:17 | LL | type GAT; | ^^^^^ @@ -278,13 +278,13 @@ LL + type GAT; | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:68:23 + --> tests/ui/needless_maybe_sized.rs:84:23 | LL | fn second_in_trait() {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:68:32 + --> tests/ui/needless_maybe_sized.rs:84:32 | LL | fn second_in_trait() {} | ^^^^^^^^^^^^^ @@ -296,13 +296,13 @@ LL + fn second_in_trait() {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:70:33 + --> tests/ui/needless_maybe_sized.rs:87:33 | LL | fn impl_trait(_: &(impl Sized + ?Sized)) {} | ^^^^^^ | note: `impl Sized + ?Sized` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:70:25 + --> tests/ui/needless_maybe_sized.rs:87:25 | LL | fn impl_trait(_: &(impl Sized + ?Sized)) {} | ^^^^^ @@ -313,13 +313,13 @@ LL + fn impl_trait(_: &(impl Sized)) {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:73:42 + --> tests/ui/needless_maybe_sized.rs:91:42 | LL | fn in_generic_trait + ?Sized, U>() {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:73:24 + --> tests/ui/needless_maybe_sized.rs:91:24 | LL | fn in_generic_trait + ?Sized, U>() {} | ^^^^^^^^^^^^^^^ @@ -331,13 +331,13 @@ LL + fn in_generic_trait, U>() {} | error: `?Sized` bound is ignored because of a `Sized` requirement - --> tests/ui/needless_maybe_sized.rs:88:29 + --> tests/ui/needless_maybe_sized.rs:107:29 | LL | fn larger_graph() {} | ^^^^^^ | note: `T` cannot be unsized because of the bound - --> tests/ui/needless_maybe_sized.rs:88:24 + --> tests/ui/needless_maybe_sized.rs:107:24 | LL | fn larger_graph() {} | ^^ diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index 84eaf12fc139..5bb0244ee091 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -5,11 +5,14 @@ fn main() { // should lint let _: Option<&usize> = Some(&1); + //~^ needless_option_as_deref let _: Option<&mut usize> = Some(&mut 1); + //~^ needless_option_as_deref let mut y = 0; let mut x = Some(&mut y); let _ = x; + //~^ needless_option_as_deref // should not lint let _ = Some(Box::new(1)).as_deref(); diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index fff1e45d846f..9cd8afe0bc72 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -5,11 +5,14 @@ fn main() { // should lint let _: Option<&usize> = Some(&1).as_deref(); + //~^ needless_option_as_deref let _: Option<&mut usize> = Some(&mut 1).as_deref_mut(); + //~^ needless_option_as_deref let mut y = 0; let mut x = Some(&mut y); let _ = x.as_deref_mut(); + //~^ needless_option_as_deref // should not lint let _ = Some(Box::new(1)).as_deref(); diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index a05d0aa9276a..bd19dc75eed6 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -8,13 +8,13 @@ LL | let _: Option<&usize> = Some(&1).as_deref(); = help: to override `-D warnings` add `#[allow(clippy::needless_option_as_deref)]` error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:8:33 + --> tests/ui/needless_option_as_deref.rs:9:33 | LL | let _: Option<&mut usize> = Some(&mut 1).as_deref_mut(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&mut 1)` error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:12:13 + --> tests/ui/needless_option_as_deref.rs:14: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 6514b67ef7a7..ae2bfab0e06d 100644 --- a/tests/ui/needless_option_take.fixed +++ b/tests/ui/needless_option_take.fixed @@ -21,7 +21,8 @@ fn main() { let x = Some(3); x.as_ref(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + println!("Testing non erroneous option_take_on_temporary"); let mut x = Some(3); @@ -29,30 +30,38 @@ fn main() { let mut x = Some(3); let y = x.as_mut(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = x.replace(289); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = Some(3).as_mut(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = Option::as_mut(&mut x); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let x = return_option(); let x = return_option(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let x = MyStruct::get_option(); let x = MyStruct::get_option(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let mut my_vec = vec![1, 2, 3]; my_vec.push(4); let y = my_vec.first(); let y = my_vec.first(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = my_vec.first(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + } diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index c6807718a758..723930f59a11 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -21,7 +21,8 @@ fn main() { let x = Some(3); x.as_ref().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + println!("Testing non erroneous option_take_on_temporary"); let mut x = Some(3); @@ -29,30 +30,38 @@ fn main() { let mut x = Some(3); let y = x.as_mut().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = x.replace(289).take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = Some(3).as_mut().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = Option::as_mut(&mut x).take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let x = return_option(); let x = return_option().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let x = MyStruct::get_option(); let x = MyStruct::get_option().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let mut my_vec = vec![1, 2, 3]; my_vec.push(4); let y = my_vec.first(); let y = my_vec.first().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + let y = my_vec.first().take(); - //~^ ERROR: called `Option::take()` on a temporary value + //~^ needless_option_take + } diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index 3fc339ed79e2..271e1a0c7915 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -11,7 +11,7 @@ LL | x.as_ref().take(); = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:31:13 + --> tests/ui/needless_option_take.rs:32:13 | LL | let y = x.as_mut().take(); | ^^^^^^^^^^------- @@ -21,7 +21,7 @@ LL | let y = x.as_mut().take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:33:13 + --> tests/ui/needless_option_take.rs:35:13 | LL | let y = x.replace(289).take(); | ^^^^^^^^^^^^^^------- @@ -31,7 +31,7 @@ LL | let y = x.replace(289).take(); = note: `replace` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:36:13 + --> tests/ui/needless_option_take.rs:39:13 | LL | let y = Some(3).as_mut().take(); | ^^^^^^^^^^^^^^^^------- @@ -41,7 +41,7 @@ LL | let y = Some(3).as_mut().take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:39:13 + --> tests/ui/needless_option_take.rs:43:13 | LL | let y = Option::as_mut(&mut x).take(); | ^^^^^^^^^^^^^^^^^^^^^^------- @@ -51,7 +51,7 @@ LL | let y = Option::as_mut(&mut x).take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:43:13 + --> tests/ui/needless_option_take.rs:48:13 | LL | let x = return_option().take(); | ^^^^^^^^^^^^^^^------- @@ -61,7 +61,7 @@ LL | let x = return_option().take(); = note: `return_option` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:47:13 + --> tests/ui/needless_option_take.rs:53:13 | LL | let x = MyStruct::get_option().take(); | ^^^^^^^^^^^^^^^^^^^^^^------- @@ -71,7 +71,7 @@ LL | let x = MyStruct::get_option().take(); = note: `get_option` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:53:13 + --> tests/ui/needless_option_take.rs:60:13 | LL | let y = my_vec.first().take(); | ^^^^^^^^^^^^^^------- @@ -81,7 +81,7 @@ LL | let y = my_vec.first().take(); = note: `first` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:56:13 + --> tests/ui/needless_option_take.rs:64:13 | LL | let y = my_vec.first().take(); | ^^^^^^^^^^^^^^------- diff --git a/tests/ui/needless_parens_on_range_literals.fixed b/tests/ui/needless_parens_on_range_literals.fixed index b4d9e3297c49..7abcbc0c6e32 100644 --- a/tests/ui/needless_parens_on_range_literals.fixed +++ b/tests/ui/needless_parens_on_range_literals.fixed @@ -5,9 +5,15 @@ fn main() { let _ = 'a'..='z'; + //~^ needless_parens_on_range_literals + //~| needless_parens_on_range_literals let _ = 'a'..'z'; + //~^ needless_parens_on_range_literals let _ = (1.)..2.; let _ = (1.)..2.; + //~^ needless_parens_on_range_literals let _ = 'a'..; + //~^ needless_parens_on_range_literals let _ = ..'z'; + //~^ 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 2f0e54f80d85..2a6f9305883b 100644 --- a/tests/ui/needless_parens_on_range_literals.rs +++ b/tests/ui/needless_parens_on_range_literals.rs @@ -5,9 +5,15 @@ fn main() { let _ = ('a')..=('z'); + //~^ needless_parens_on_range_literals + //~| needless_parens_on_range_literals let _ = 'a'..('z'); + //~^ needless_parens_on_range_literals let _ = (1.)..2.; let _ = (1.)..(2.); + //~^ needless_parens_on_range_literals let _ = ('a')..; + //~^ needless_parens_on_range_literals let _ = ..('z'); + //~^ 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 d293ecce69fb..082b2cd8cade 100644 --- a/tests/ui/needless_parens_on_range_literals.stderr +++ b/tests/ui/needless_parens_on_range_literals.stderr @@ -14,25 +14,25 @@ LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> tests/ui/needless_parens_on_range_literals.rs:8:18 + --> tests/ui/needless_parens_on_range_literals.rs:10:18 | LL | let _ = 'a'..('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> tests/ui/needless_parens_on_range_literals.rs:10:19 + --> tests/ui/needless_parens_on_range_literals.rs:13:19 | LL | let _ = (1.)..(2.); | ^^^^ help: try: `2.` error: needless parenthesis on range literals can be removed - --> tests/ui/needless_parens_on_range_literals.rs:11:13 + --> tests/ui/needless_parens_on_range_literals.rs:15:13 | LL | let _ = ('a')..; | ^^^^^ help: try: `'a'` error: needless parenthesis on range literals can be removed - --> tests/ui/needless_parens_on_range_literals.rs:12:15 + --> tests/ui/needless_parens_on_range_literals.rs:17: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 162ec82aeded..415a13163805 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -9,7 +9,8 @@ use std::ptr::NonNull; fn foo(s: &mut Vec, b: &u32, x: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + *x += *b + s.len() as u32; } @@ -34,7 +35,8 @@ fn foo5(s: &mut Vec) { } fn foo6(s: &mut Vec) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + non_mut_ref(s); } @@ -44,10 +46,12 @@ struct Bar; impl Bar { fn bar(&mut self) {} - //~^ ERROR: this argument is a mutable reference, but not used mutably + //~^ needless_pass_by_ref_mut + fn mushroom(&self, vec: &mut Vec) -> usize { - //~^ ERROR: this argument is a mutable reference, but not used mutably + //~^ needless_pass_by_ref_mut + vec.len() } } @@ -124,35 +128,44 @@ async fn f7(x: &mut i32, y: i32, z: &mut i32, a: i32) { } async fn a1(x: &mut i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a2(x: &mut i32, y: String) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a3(x: &mut i32, y: String, z: String) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a4(x: &mut i32, y: i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a5(x: i32, y: &mut i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a6(x: i32, y: &mut i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", x); } async fn a7(x: i32, y: i32, z: &mut i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + println!("{:?}", z); } async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut +//~| needless_pass_by_ref_mut + println!("{:?}", z); } @@ -186,14 +199,16 @@ fn lint_attr(s: &mut u32) {} #[cfg(not(feature = "a"))] fn cfg_warn(s: &mut u32) {} -//~^ ERROR: this argument is a mutable reference, but not used mutably -//~| NOTE: this is cfg-gated and may require further changes +//~^ needless_pass_by_ref_mut + + #[cfg(not(feature = "a"))] mod foo { fn cfg_warn(s: &mut u32) {} - //~^ ERROR: this argument is a mutable reference, but not used mutably - //~| NOTE: this is cfg-gated and may require further changes + //~^ needless_pass_by_ref_mut + + } // Should not warn. @@ -206,7 +221,8 @@ async fn inner_async(x: &mut i32, y: &mut u32) { } async fn inner_async2(x: &mut i32, y: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *x += 1; } @@ -214,7 +230,8 @@ async fn inner_async2(x: &mut i32, y: &mut u32) { } async fn inner_async3(x: &mut i32, y: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *y += 1; } @@ -233,6 +250,7 @@ async fn async_vec2(b: &mut Vec) { fn non_mut(n: &str) {} //Should warn async fn call_in_closure1(n: &mut str) { +//~^ needless_pass_by_ref_mut (|| non_mut(n))() } fn str_mut(str: &mut String) -> bool { @@ -252,7 +270,8 @@ async fn closure(n: &mut usize) -> impl '_ + FnMut() { // Should warn. fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + || *n + 1 } @@ -263,7 +282,8 @@ async fn closure3(n: &mut usize) { // Should warn. async fn closure4(n: &mut usize) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + (|| { let _x = *n + 1; })(); @@ -317,17 +337,21 @@ struct MutSelf { impl MutSelf { fn bar(&mut self) {} - //~^ ERROR: this argument is a mutable reference, but not used mutably + //~^ needless_pass_by_ref_mut + async fn foo(&mut self, u: &mut i32, v: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably - //~| ERROR: this argument is a mutable reference, but not used mutably + //~^ needless_pass_by_ref_mut + //~| needless_pass_by_ref_mut + + async { *u += 1; } .await; } async fn foo2(&mut self, u: &mut i32, v: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably + //~^ needless_pass_by_ref_mut + async { self.a += 1; *u += 1; @@ -343,16 +367,26 @@ impl MutSelfTrait for MutSelf { // `is_from_proc_macro` stress tests fn _empty_tup(x: &mut (())) {} +//~^ needless_pass_by_ref_mut fn _single_tup(x: &mut ((i32,))) {} +//~^ needless_pass_by_ref_mut fn _multi_tup(x: &mut ((i32, u32))) {} +//~^ needless_pass_by_ref_mut fn _fn(x: &mut (fn())) {} +//~^ needless_pass_by_ref_mut #[rustfmt::skip] fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} +//~^ needless_pass_by_ref_mut fn _extern_c_fn(x: &mut extern "C" fn()) {} +//~^ needless_pass_by_ref_mut fn _unsafe_fn(x: &mut unsafe fn()) {} +//~^ needless_pass_by_ref_mut fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} +//~^ needless_pass_by_ref_mut fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} +//~^ needless_pass_by_ref_mut fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} +//~^ needless_pass_by_ref_mut fn main() { let mut u = 0; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index f462fa9099ed..0492acf7cc08 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -8,79 +8,79 @@ LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:36:12 + --> tests/ui/needless_pass_by_ref_mut.rs:37:12 | LL | fn foo6(s: &mut Vec) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:46:12 + --> tests/ui/needless_pass_by_ref_mut.rs:48:12 | LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:49:29 + --> tests/ui/needless_pass_by_ref_mut.rs:52:29 | LL | fn mushroom(&self, vec: &mut Vec) -> usize { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:126:16 + --> tests/ui/needless_pass_by_ref_mut.rs:130:16 | LL | async fn a1(x: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:130:16 + --> tests/ui/needless_pass_by_ref_mut.rs:135:16 | LL | async fn a2(x: &mut i32, y: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:134:16 + --> tests/ui/needless_pass_by_ref_mut.rs:140:16 | LL | async fn a3(x: &mut i32, y: String, z: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:138:16 + --> tests/ui/needless_pass_by_ref_mut.rs:145:16 | LL | async fn a4(x: &mut i32, y: i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:142:24 + --> tests/ui/needless_pass_by_ref_mut.rs:150:24 | LL | async fn a5(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:146:24 + --> tests/ui/needless_pass_by_ref_mut.rs:155:24 | LL | async fn a6(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:150:32 + --> tests/ui/needless_pass_by_ref_mut.rs:160:32 | LL | async fn a7(x: i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:154:24 + --> tests/ui/needless_pass_by_ref_mut.rs:165:24 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:154:45 + --> tests/ui/needless_pass_by_ref_mut.rs:165:45 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:188:16 + --> tests/ui/needless_pass_by_ref_mut.rs:201:16 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -88,7 +88,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:194:20 + --> tests/ui/needless_pass_by_ref_mut.rs:208:20 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -96,115 +96,115 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:208:39 + --> tests/ui/needless_pass_by_ref_mut.rs:223: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 - --> tests/ui/needless_pass_by_ref_mut.rs:216:26 + --> tests/ui/needless_pass_by_ref_mut.rs:232:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:235:30 + --> tests/ui/needless_pass_by_ref_mut.rs:252:30 | LL | async fn call_in_closure1(n: &mut str) { | ^^^^^^^^ help: consider changing to: `&str` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:254:16 + --> tests/ui/needless_pass_by_ref_mut.rs:272:16 | LL | fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | ^^^^^^^^^^ help: consider changing to: `&usize` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:265:22 + --> tests/ui/needless_pass_by_ref_mut.rs:284:22 | LL | async fn closure4(n: &mut usize) { | ^^^^^^^^^^ help: consider changing to: `&usize` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:319:12 + --> tests/ui/needless_pass_by_ref_mut.rs:339:12 | LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:321:18 + --> tests/ui/needless_pass_by_ref_mut.rs:342:18 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:321:45 + --> tests/ui/needless_pass_by_ref_mut.rs:342:45 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:329:46 + --> tests/ui/needless_pass_by_ref_mut.rs:352:46 | LL | async fn foo2(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:345:18 + --> tests/ui/needless_pass_by_ref_mut.rs:369:18 | LL | fn _empty_tup(x: &mut (())) {} | ^^^^^^^^^ help: consider changing to: `&()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:346:19 + --> tests/ui/needless_pass_by_ref_mut.rs:371:19 | LL | fn _single_tup(x: &mut ((i32,))) {} | ^^^^^^^^^^^^^ help: consider changing to: `&(i32,)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:347:18 + --> tests/ui/needless_pass_by_ref_mut.rs:373:18 | LL | fn _multi_tup(x: &mut ((i32, u32))) {} | ^^^^^^^^^^^^^^^^^ help: consider changing to: `&(i32, u32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:348:11 + --> tests/ui/needless_pass_by_ref_mut.rs:375:11 | LL | fn _fn(x: &mut (fn())) {} | ^^^^^^^^^^^ help: consider changing to: `&fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:350:23 + --> tests/ui/needless_pass_by_ref_mut.rs:378:23 | LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "Rust" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:351:20 + --> tests/ui/needless_pass_by_ref_mut.rs:380:20 | LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:352:18 + --> tests/ui/needless_pass_by_ref_mut.rs:382:18 | LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | ^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:353:25 + --> tests/ui/needless_pass_by_ref_mut.rs:384:25 | LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:354:20 + --> tests/ui/needless_pass_by_ref_mut.rs:386:20 | LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn(i32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:355:20 + --> tests/ui/needless_pass_by_ref_mut.rs:388:20 | LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn() -> (i32)` diff --git a/tests/ui/needless_pass_by_ref_mut2.fixed b/tests/ui/needless_pass_by_ref_mut2.fixed index f26b39ea6a16..fc40f8c8ca30 100644 --- a/tests/ui/needless_pass_by_ref_mut2.fixed +++ b/tests/ui/needless_pass_by_ref_mut2.fixed @@ -6,7 +6,8 @@ #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &i32, y: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *y += 1; } @@ -14,7 +15,8 @@ async fn inner_async3(x: &i32, y: &mut u32) { } async fn inner_async4(u: &mut i32, v: &u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *u += 1; } diff --git a/tests/ui/needless_pass_by_ref_mut2.rs b/tests/ui/needless_pass_by_ref_mut2.rs index 4220215b1fe9..f921a7684236 100644 --- a/tests/ui/needless_pass_by_ref_mut2.rs +++ b/tests/ui/needless_pass_by_ref_mut2.rs @@ -6,7 +6,8 @@ #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &mut i32, y: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *y += 1; } @@ -14,7 +15,8 @@ async fn inner_async3(x: &mut i32, y: &mut u32) { } async fn inner_async4(u: &mut i32, v: &mut u32) { - //~^ ERROR: this argument is a mutable reference, but not used mutably +//~^ needless_pass_by_ref_mut + async { *u += 1; } diff --git a/tests/ui/needless_pass_by_ref_mut2.stderr b/tests/ui/needless_pass_by_ref_mut2.stderr index 1c0136cf5d59..9876a6b50718 100644 --- a/tests/ui/needless_pass_by_ref_mut2.stderr +++ b/tests/ui/needless_pass_by_ref_mut2.stderr @@ -8,7 +8,7 @@ LL | async fn inner_async3(x: &mut i32, y: &mut u32) { = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut2.rs:16:39 + --> tests/ui/needless_pass_by_ref_mut2.rs:17:39 | LL | async fn inner_async4(u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index a8d9db95dcc7..faa68c8140cb 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -17,8 +17,9 @@ 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` +//~^ needless_pass_by_value + + assert_eq!(v.len(), 42); consume(w); @@ -33,15 +34,18 @@ 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 +//~^ needless_pass_by_value +//~| needless_pass_by_value + + 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 +//~^ needless_pass_by_value + println!("{}", t.borrow()); println!("{}", u.as_ref()); consume(&v); @@ -54,7 +58,8 @@ 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 +//~^ needless_pass_by_value + match x { Some(Some(_)) => 1, // not moved _ => 0, @@ -68,8 +73,10 @@ 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 +//~^ needless_pass_by_value +//~| needless_pass_by_value + + let Wrapper(s) = z; // moved let Wrapper(ref t) = y; // not moved let Wrapper(_) = y; // still not moved @@ -86,13 +93,18 @@ impl<'a, T> Serialize for &'a T where T: Serialize {} impl Serialize for i32 {} fn test_blanket_ref(vals: T, serializable: S) {} -//~^ ERROR: this argument is passed by value, but not consumed in the function body +//~^ needless_pass_by_value + 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 +//~^ needless_pass_by_value +//~| needless_pass_by_value +//~| needless_pass_by_value +//~| needless_pass_by_value + + + + s.capacity(); let _ = t.clone(); u.capacity(); @@ -106,9 +118,11 @@ 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 + //~^ needless_pass_by_value + t: String, - //~^ ERROR: this argument is passed by value, but not consumed in the function bod + //~^ needless_pass_by_value + ) -> usize { s.len() + t.capacity() } @@ -118,8 +132,10 @@ impl S { } fn baz(&self, uu: U, ss: 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 + //~^ needless_pass_by_value + //~| needless_pass_by_value + + } trait FalsePositive { @@ -142,16 +158,20 @@ 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 +//~^ needless_pass_by_value + 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 +//~^ needless_pass_by_value +//~| needless_pass_by_value +//~| needless_pass_by_value + + + let CopyWrapper(s) = z; // moved let CopyWrapper(ref t) = y; // not moved let CopyWrapper(_) = y; // still not moved @@ -164,13 +184,15 @@ 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, ()>>(items: S) {} -//~^ ERROR: this argument is passed by value, but not consumed in the function body +//~^ needless_pass_by_value + // Also this should not cause an ICE. See #2831 trait Club<'a, A> {} impl Club<'static, T> for T {} fn more_fun(items: impl Club<'static, i32>) {} -//~^ ERROR: this argument is passed by value, but not consumed in the function body +//~^ needless_pass_by_value + fn is_sync(_: T) where diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 2587d3f8c52f..414ce347403a 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -8,55 +8,55 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec tests/ui/needless_pass_by_value.rs:35:11 + --> tests/ui/needless_pass_by_value.rs:36:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:35:22 + --> tests/ui/needless_pass_by_value.rs:36: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 - --> tests/ui/needless_pass_by_value.rs:43:71 + --> tests/ui/needless_pass_by_value.rs:46: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 - --> tests/ui/needless_pass_by_value.rs:56:18 + --> tests/ui/needless_pass_by_value.rs:60: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 - --> tests/ui/needless_pass_by_value.rs:70:24 + --> tests/ui/needless_pass_by_value.rs:75: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 - --> tests/ui/needless_pass_by_value.rs:70:36 + --> tests/ui/needless_pass_by_value.rs:75: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 - --> tests/ui/needless_pass_by_value.rs:88:49 + --> tests/ui/needless_pass_by_value.rs:95:49 | LL | fn test_blanket_ref(vals: T, serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:91:18 + --> tests/ui/needless_pass_by_value.rs:99: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 - --> tests/ui/needless_pass_by_value.rs:91:29 + --> tests/ui/needless_pass_by_value.rs:99:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -71,13 +71,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:91:40 + --> tests/ui/needless_pass_by_value.rs:99: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 - --> tests/ui/needless_pass_by_value.rs:91:53 + --> tests/ui/needless_pass_by_value.rs:99:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -92,85 +92,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:108:12 + --> tests/ui/needless_pass_by_value.rs:120:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:110:12 + --> tests/ui/needless_pass_by_value.rs:123: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 - --> tests/ui/needless_pass_by_value.rs:120:23 + --> tests/ui/needless_pass_by_value.rs:134:23 | LL | fn baz(&self, uu: U, ss: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:120:30 + --> tests/ui/needless_pass_by_value.rs:134:30 | LL | fn baz(&self, uu: U, ss: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:144:24 + --> tests/ui/needless_pass_by_value.rs:160:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:142:1 + --> tests/ui/needless_pass_by_value.rs:158:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:151:29 + --> tests/ui/needless_pass_by_value.rs:168:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:142:1 + --> tests/ui/needless_pass_by_value.rs:158:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:151:45 + --> tests/ui/needless_pass_by_value.rs:168:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:142:1 + --> tests/ui/needless_pass_by_value.rs:158:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:151:61 + --> tests/ui/needless_pass_by_value.rs:168:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:142:1 + --> tests/ui/needless_pass_by_value.rs:158:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:166:40 + --> tests/ui/needless_pass_by_value.rs:186:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:172:20 + --> tests/ui/needless_pass_by_value.rs:193:20 | LL | fn more_fun(items: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` diff --git a/tests/ui/needless_pass_by_value_proc_macro.rs b/tests/ui/needless_pass_by_value_proc_macro.rs index c603163c145f..67516a962e75 100644 --- a/tests/ui/needless_pass_by_value_proc_macro.rs +++ b/tests/ui/needless_pass_by_value_proc_macro.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::needless_pass_by_value)] extern crate proc_macro; diff --git a/tests/ui/needless_pub_self.fixed b/tests/ui/needless_pub_self.fixed index d9f7b92d0901..7b4601ba8a37 100644 --- a/tests/ui/needless_pub_self.fixed +++ b/tests/ui/needless_pub_self.fixed @@ -11,13 +11,16 @@ extern crate proc_macros; fn a() {} +//~^ needless_pub_self fn b() {} +//~^ needless_pub_self pub fn c() {} mod a { pub(in super) fn d() {} pub(super) fn e() {} fn f() {} + //~^ needless_pub_self } external! { diff --git a/tests/ui/needless_pub_self.rs b/tests/ui/needless_pub_self.rs index 9f0ec76477e6..f64a56c37989 100644 --- a/tests/ui/needless_pub_self.rs +++ b/tests/ui/needless_pub_self.rs @@ -11,13 +11,16 @@ extern crate proc_macros; pub(self) fn a() {} +//~^ needless_pub_self pub(in self) fn b() {} +//~^ needless_pub_self pub fn c() {} mod a { pub(in super) fn d() {} pub(super) fn e() {} pub(self) fn f() {} + //~^ needless_pub_self } external! { diff --git a/tests/ui/needless_pub_self.stderr b/tests/ui/needless_pub_self.stderr index 1fdd84165659..c362d11804ec 100644 --- a/tests/ui/needless_pub_self.stderr +++ b/tests/ui/needless_pub_self.stderr @@ -9,7 +9,7 @@ LL | pub(self) fn a() {} = help: remove it error: unnecessary `pub(in self)` - --> tests/ui/needless_pub_self.rs:14:1 + --> tests/ui/needless_pub_self.rs:15:1 | LL | pub(in self) fn b() {} | ^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub(in self) fn b() {} = help: remove it error: unnecessary `pub(self)` - --> tests/ui/needless_pub_self.rs:20:5 + --> tests/ui/needless_pub_self.rs:22:5 | LL | pub(self) fn f() {} | ^^^^^^^^^ diff --git a/tests/ui/needless_question_mark.fixed b/tests/ui/needless_question_mark.fixed index 92f01c217c1c..375c38771eb6 100644 --- a/tests/ui/needless_question_mark.fixed +++ b/tests/ui/needless_question_mark.fixed @@ -18,6 +18,7 @@ struct TR { fn simple_option_bad1(to: TO) -> Option { // return as a statement return to.magic; + //~^ needless_question_mark } // formatting will add a semi-colon, which would make @@ -26,16 +27,19 @@ fn simple_option_bad1(to: TO) -> Option { fn simple_option_bad2(to: TO) -> Option { // return as an expression return to.magic + //~^ needless_question_mark } fn simple_option_bad3(to: TO) -> Option { // block value "return" to.magic + //~^ needless_question_mark } fn simple_option_bad4(to: Option) -> Option { // single line closure to.and_then(|t| t.magic) + //~^ needless_question_mark } // formatting this will remove the block brackets, making @@ -45,11 +49,13 @@ fn simple_option_bad5(to: Option) -> Option { // closure with body to.and_then(|t| { t.magic + //~^ needless_question_mark }) } fn simple_result_bad1(tr: TR) -> Result { return tr.magic; + //~^ needless_question_mark } // formatting will add a semi-colon, which would make @@ -57,14 +63,17 @@ fn simple_result_bad1(tr: TR) -> Result { #[rustfmt::skip] fn simple_result_bad2(tr: TR) -> Result { return tr.magic + //~^ needless_question_mark } fn simple_result_bad3(tr: TR) -> Result { tr.magic + //~^ needless_question_mark } fn simple_result_bad4(tr: Result) -> Result { tr.and_then(|t| t.magic) + //~^ needless_question_mark } // formatting this will remove the block brackets, making @@ -73,6 +82,7 @@ fn simple_result_bad4(tr: Result) -> Result { fn simple_result_bad5(tr: Result) -> Result { tr.and_then(|t| { t.magic + //~^ needless_question_mark }) } @@ -80,6 +90,7 @@ fn also_bad(tr: Result) -> Result { if tr.is_ok() { let t = tr.unwrap(); return t.magic; + //~^ needless_question_mark } Err(false) } @@ -115,6 +126,7 @@ pub fn test1() { macro_rules! some_and_qmark_in_macro { ($expr:expr) => { || -> Option<_> { Some($expr) }() + //~^ needless_question_mark }; } @@ -126,6 +138,7 @@ pub fn test2() { async fn async_option_bad(to: TO) -> Option { let _ = Some(3); to.magic + //~^ needless_question_mark } async fn async_deref_ref(s: Option<&String>) -> Option<&str> { @@ -134,8 +147,10 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { async fn async_result_bad(s: TR) -> Result { s.magic + //~^ needless_question_mark } async fn async_wrapped(a: Option) -> Option { { a } + //~^ needless_question_mark } diff --git a/tests/ui/needless_question_mark.rs b/tests/ui/needless_question_mark.rs index 21c858c291ff..5f6bd0c0f166 100644 --- a/tests/ui/needless_question_mark.rs +++ b/tests/ui/needless_question_mark.rs @@ -18,6 +18,7 @@ struct TR { fn simple_option_bad1(to: TO) -> Option { // return as a statement return Some(to.magic?); + //~^ needless_question_mark } // formatting will add a semi-colon, which would make @@ -26,16 +27,19 @@ fn simple_option_bad1(to: TO) -> Option { fn simple_option_bad2(to: TO) -> Option { // return as an expression return Some(to.magic?) + //~^ needless_question_mark } fn simple_option_bad3(to: TO) -> Option { // block value "return" Some(to.magic?) + //~^ needless_question_mark } fn simple_option_bad4(to: Option) -> Option { // single line closure to.and_then(|t| Some(t.magic?)) + //~^ needless_question_mark } // formatting this will remove the block brackets, making @@ -45,11 +49,13 @@ fn simple_option_bad5(to: Option) -> Option { // closure with body to.and_then(|t| { Some(t.magic?) + //~^ needless_question_mark }) } fn simple_result_bad1(tr: TR) -> Result { return Ok(tr.magic?); + //~^ needless_question_mark } // formatting will add a semi-colon, which would make @@ -57,14 +63,17 @@ fn simple_result_bad1(tr: TR) -> Result { #[rustfmt::skip] fn simple_result_bad2(tr: TR) -> Result { return Ok(tr.magic?) + //~^ needless_question_mark } fn simple_result_bad3(tr: TR) -> Result { Ok(tr.magic?) + //~^ needless_question_mark } fn simple_result_bad4(tr: Result) -> Result { tr.and_then(|t| Ok(t.magic?)) + //~^ needless_question_mark } // formatting this will remove the block brackets, making @@ -73,6 +82,7 @@ fn simple_result_bad4(tr: Result) -> Result { fn simple_result_bad5(tr: Result) -> Result { tr.and_then(|t| { Ok(t.magic?) + //~^ needless_question_mark }) } @@ -80,6 +90,7 @@ fn also_bad(tr: Result) -> Result { if tr.is_ok() { let t = tr.unwrap(); return Ok(t.magic?); + //~^ needless_question_mark } Err(false) } @@ -115,6 +126,7 @@ pub fn test1() { macro_rules! some_and_qmark_in_macro { ($expr:expr) => { || -> Option<_> { Some(Some($expr)?) }() + //~^ needless_question_mark }; } @@ -126,6 +138,7 @@ pub fn test2() { async fn async_option_bad(to: TO) -> Option { let _ = Some(3); Some(to.magic?) + //~^ needless_question_mark } async fn async_deref_ref(s: Option<&String>) -> Option<&str> { @@ -134,8 +147,10 @@ async fn async_deref_ref(s: Option<&String>) -> Option<&str> { async fn async_result_bad(s: TR) -> Result { Ok(s.magic?) + //~^ needless_question_mark } async fn async_wrapped(a: Option) -> Option { { Some(a?) } + //~^ needless_question_mark } diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index 0a1cb5979708..55da4f28976c 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -8,67 +8,67 @@ LL | return Some(to.magic?); = help: to override `-D warnings` add `#[allow(clippy::needless_question_mark)]` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:28:12 + --> tests/ui/needless_question_mark.rs:29:12 | LL | return Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:33:5 + --> tests/ui/needless_question_mark.rs:35:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:38:21 + --> tests/ui/needless_question_mark.rs:41: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 - --> tests/ui/needless_question_mark.rs:47:9 + --> tests/ui/needless_question_mark.rs:51:9 | LL | Some(t.magic?) | ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:52:12 + --> tests/ui/needless_question_mark.rs:57:12 | LL | return Ok(tr.magic?); | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:59:12 + --> tests/ui/needless_question_mark.rs:65:12 | LL | return Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:63:5 + --> tests/ui/needless_question_mark.rs:70:5 | LL | Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:67:21 + --> tests/ui/needless_question_mark.rs:75: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 - --> tests/ui/needless_question_mark.rs:75:9 + --> tests/ui/needless_question_mark.rs:84:9 | LL | Ok(t.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:82:16 + --> tests/ui/needless_question_mark.rs:92:16 | LL | return Ok(t.magic?); | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:117:27 + --> tests/ui/needless_question_mark.rs:128:27 | LL | || -> Option<_> { Some(Some($expr)?) }() | ^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `Some($expr)` @@ -79,19 +79,19 @@ 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 - --> tests/ui/needless_question_mark.rs:128:5 + --> tests/ui/needless_question_mark.rs:140:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:136:5 + --> tests/ui/needless_question_mark.rs:149:5 | LL | Ok(s.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic` error: question mark operator is useless here - --> tests/ui/needless_question_mark.rs:140:7 + --> tests/ui/needless_question_mark.rs:154:7 | LL | { Some(a?) } | ^^^^^^^^ help: try removing question mark and `Some()`: `a` diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index 75f1896eded1..ff9699e35691 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -14,8 +14,9 @@ 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` + //~^ needless_range_loop + + println!("{}", vec[i]); } @@ -25,23 +26,27 @@ fn main() { } for i in 0..vec.len() { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + let _ = vec[i]; } // ICE #746 for j in 0..4 { - //~^ ERROR: the loop variable `j` is only used to index `STATIC` + //~^ needless_range_loop + println!("{:?}", STATIC[j]); } for j in 0..4 { - //~^ ERROR: the loop variable `j` is only used to index `CONST` + //~^ needless_range_loop + println!("{:?}", CONST[j]); } for i in 0..vec.len() { - //~^ ERROR: the loop variable `i` is used to index `vec` + //~^ needless_range_loop + println!("{} {}", vec[i], i); } for i in 0..vec.len() { @@ -50,48 +55,57 @@ fn main() { } for i in 0..vec.len() { - //~^ ERROR: the loop variable `i` is only used to index `vec2` + //~^ needless_range_loop + println!("{}", vec2[i]); } for i in 5..vec.len() { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + println!("{}", vec[i]); } for i in 0..MAX_LEN { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + println!("{}", vec[i]); } for i in 0..=MAX_LEN { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + println!("{}", vec[i]); } for i in 5..10 { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + println!("{}", vec[i]); } for i in 5..=10 { - //~^ ERROR: the loop variable `i` is only used to index `vec` + //~^ needless_range_loop + println!("{}", vec[i]); } for i in 5..vec.len() { - //~^ ERROR: the loop variable `i` is used to index `vec` + //~^ needless_range_loop + println!("{} {}", vec[i], i); } for i in 5..10 { - //~^ ERROR: the loop variable `i` is used to index `vec` + //~^ needless_range_loop + println!("{} {}", vec[i], i); } // #2542 for i in 0..vec.len() { - //~^ ERROR: the loop variable `i` is used to index `vec` + //~^ needless_range_loop + 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 503d796e5e8d..a15830d721b6 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -12,7 +12,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:27:14 + --> tests/ui/needless_range_loop.rs:28:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> tests/ui/needless_range_loop.rs:33:14 + --> tests/ui/needless_range_loop.rs:35:14 | LL | for j in 0..4 { | ^^^^ @@ -34,7 +34,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> tests/ui/needless_range_loop.rs:38:14 + --> tests/ui/needless_range_loop.rs:41:14 | LL | for j in 0..4 { | ^^^^ @@ -45,7 +45,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:43:14 + --> tests/ui/needless_range_loop.rs:47:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> tests/ui/needless_range_loop.rs:52:14 + --> tests/ui/needless_range_loop.rs:57:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:57:14 + --> tests/ui/needless_range_loop.rs:63:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:62:14 + --> tests/ui/needless_range_loop.rs:69:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:67:14 + --> tests/ui/needless_range_loop.rs:75:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:72:14 + --> tests/ui/needless_range_loop.rs:81:14 | LL | for i in 5..10 { | ^^^^^ @@ -111,7 +111,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:77:14 + --> tests/ui/needless_range_loop.rs:87:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -122,7 +122,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:82:14 + --> tests/ui/needless_range_loop.rs:93:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:87:14 + --> tests/ui/needless_range_loop.rs:99:14 | LL | for i in 5..10 { | ^^^^^ @@ -144,7 +144,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:93:14 + --> tests/ui/needless_range_loop.rs:106: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 787ff18f338d..8a591a4bddae 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -9,8 +9,9 @@ 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` + //~^ needless_range_loop + + println!("{}", ns[i]); } @@ -32,14 +33,16 @@ 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` + //~^ needless_range_loop + 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` + //~^ needless_range_loop + let x = &mut ms[i]; *x *= 2; } @@ -64,7 +67,8 @@ 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` + //~^ needless_range_loop + vec[i] += 1; } @@ -72,24 +76,28 @@ 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` + //~^ needless_range_loop + vec[i] += 1; } let arr = [1, 2, 3]; for i in 0..3 { - //~^ ERROR: the loop variable `i` is only used to index `arr` + //~^ needless_range_loop + println!("{}", arr[i]); } for i in 0..2 { - //~^ ERROR: the loop variable `i` is only used to index `arr` + //~^ needless_range_loop + println!("{}", arr[i]); } for i in 1..3 { - //~^ ERROR: the loop variable `i` is only used to index `arr` + //~^ needless_range_loop + println!("{}", arr[i]); } diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 353f30b1b26d..34357c3db02f 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -12,7 +12,7 @@ LL | for in ns.iter().take(10).skip(3) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> tests/ui/needless_range_loop2.rs:34:14 + --> tests/ui/needless_range_loop2.rs:35:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> tests/ui/needless_range_loop2.rs:41:14 + --> tests/ui/needless_range_loop2.rs:43:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop2.rs:66:14 + --> tests/ui/needless_range_loop2.rs:69:14 | LL | for i in x..x + 4 { | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | for in vec.iter_mut().skip(x).take(4) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop2.rs:74:14 + --> tests/ui/needless_range_loop2.rs:78:14 | LL | for i in x..=x + 4 { | ^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for in vec.iter_mut().skip(x).take(4 + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:81:14 + --> tests/ui/needless_range_loop2.rs:86:14 | LL | for i in 0..3 { | ^^^^ @@ -67,7 +67,7 @@ LL | for in &arr { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:86:14 + --> tests/ui/needless_range_loop2.rs:92:14 | LL | for i in 0..2 { | ^^^^ @@ -78,7 +78,7 @@ LL | for in arr.iter().take(2) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:91:14 + --> tests/ui/needless_range_loop2.rs:98:14 | LL | for i in 1..3 { | ^^^^ diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index ab061467488a..88f9096db03c 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -3,31 +3,41 @@ fn main() { "aaa"; + //~^ needless_raw_strings r#""aaa""#; r#"\s"#; b"aaa"; + //~^ needless_raw_strings br#""aaa""#; br#"\s"#; c"aaa"; + //~^ needless_raw_strings cr#""aaa""#; cr#"\s"#; " + //~^ needless_raw_strings a multiline string "; "no hashes"; + //~^ needless_raw_strings b"no hashes"; + //~^ needless_raw_strings c"no hashes"; + //~^ needless_raw_strings } fn issue_13503() { println!("SELECT * FROM posts"); + //~^ needless_raw_strings println!("SELECT * FROM posts"); + //~^ needless_raw_strings println!(r##"SELECT * FROM "posts""##); // Test arguments as well println!("{}", "foobar".len()); + //~^ needless_raw_strings } diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index 5be8bdeb4ad0..6913b8b75546 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -3,31 +3,41 @@ fn main() { r#"aaa"#; + //~^ needless_raw_strings r#""aaa""#; r#"\s"#; br#"aaa"#; + //~^ needless_raw_strings br#""aaa""#; br#"\s"#; cr#"aaa"#; + //~^ needless_raw_strings cr#""aaa""#; cr#"\s"#; r#" + //~^ needless_raw_strings a multiline string "#; r"no hashes"; + //~^ needless_raw_strings br"no hashes"; + //~^ needless_raw_strings cr"no hashes"; + //~^ needless_raw_strings } fn issue_13503() { println!(r"SELECT * FROM posts"); + //~^ needless_raw_strings println!(r#"SELECT * FROM posts"#); + //~^ needless_raw_strings println!(r##"SELECT * FROM "posts""##); // Test arguments as well println!("{}", r"foobar".len()); + //~^ needless_raw_strings } diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index 5169f0855738..99c60b10b21b 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -13,7 +13,7 @@ LL + "aaa"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:8:5 + --> tests/ui/needless_raw_string.rs:9:5 | LL | br#"aaa"#; | ^^^^^^^^^ @@ -25,7 +25,7 @@ LL + b"aaa"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:11:5 + --> tests/ui/needless_raw_string.rs:13:5 | LL | cr#"aaa"#; | ^^^^^^^^^ @@ -37,9 +37,10 @@ LL + c"aaa"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:15:5 + --> tests/ui/needless_raw_string.rs:18:5 | LL | / r#" +LL | | LL | | a LL | | multiline LL | | string @@ -49,14 +50,14 @@ LL | | "#; help: use a plain string literal instead | LL ~ " -LL | a -LL | multiline +LL | +... LL | string LL ~ "; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:21:5 + --> tests/ui/needless_raw_string.rs:25:5 | LL | r"no hashes"; | ^^^^^^^^^^^^ @@ -68,7 +69,7 @@ LL + "no hashes"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:22:5 + --> tests/ui/needless_raw_string.rs:27:5 | LL | br"no hashes"; | ^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL + b"no hashes"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:23:5 + --> tests/ui/needless_raw_string.rs:29:5 | LL | cr"no hashes"; | ^^^^^^^^^^^^^ @@ -92,7 +93,7 @@ LL + c"no hashes"; | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:27:14 + --> tests/ui/needless_raw_string.rs:34:14 | LL | println!(r"SELECT * FROM posts"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL + println!("SELECT * FROM posts"); | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:28:14 + --> tests/ui/needless_raw_string.rs:36:14 | LL | println!(r#"SELECT * FROM posts"#); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -116,7 +117,7 @@ LL + println!("SELECT * FROM posts"); | error: unnecessary raw string literal - --> tests/ui/needless_raw_string.rs:32:20 + --> tests/ui/needless_raw_string.rs:41:20 | LL | println!("{}", r"foobar".len()); | ^^^^^^^^^ diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index 4c1137091071..bc7da202df4a 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -3,33 +3,51 @@ fn main() { r"\aaa"; + //~^ needless_raw_string_hashes r#"Hello "world"!"#; + //~^ needless_raw_string_hashes r####" "### "## "# "####; + //~^ needless_raw_string_hashes r###" "aa" "# "## "###; + //~^ needless_raw_string_hashes br"\aaa"; + //~^ needless_raw_string_hashes br#"Hello "world"!"#; + //~^ needless_raw_string_hashes br####" "### "## "# "####; + //~^ needless_raw_string_hashes br###" "aa" "# "## "###; + //~^ needless_raw_string_hashes cr"\aaa"; + //~^ needless_raw_string_hashes cr#"Hello "world"!"#; + //~^ needless_raw_string_hashes cr####" "### "## "# "####; + //~^ needless_raw_string_hashes cr###" "aa" "# "## "###; + //~^ needless_raw_string_hashes r" + //~^ needless_raw_string_hashes \a multiline string "; r"rust"; + //~^ needless_raw_string_hashes r"hello world"; + //~^ needless_raw_string_hashes } fn issue_13503() { println!(r"SELECT * FROM posts"); println!(r"SELECT * FROM posts"); + //~^ needless_raw_string_hashes println!(r#"SELECT * FROM "posts""#); + //~^ needless_raw_string_hashes println!(r#"SELECT * FROM "posts""#); + //~^ needless_raw_string_hashes // Test arguments as well println!("{}", r"foobar".len()); diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index 7b6b4e784eea..3f2f92a4097c 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -3,33 +3,51 @@ fn main() { r#"\aaa"#; + //~^ needless_raw_string_hashes r##"Hello "world"!"##; + //~^ needless_raw_string_hashes r######" "### "## "# "######; + //~^ needless_raw_string_hashes r######" "aa" "# "## "######; + //~^ needless_raw_string_hashes br#"\aaa"#; + //~^ needless_raw_string_hashes br##"Hello "world"!"##; + //~^ needless_raw_string_hashes br######" "### "## "# "######; + //~^ needless_raw_string_hashes br######" "aa" "# "## "######; + //~^ needless_raw_string_hashes cr#"\aaa"#; + //~^ needless_raw_string_hashes cr##"Hello "world"!"##; + //~^ needless_raw_string_hashes cr######" "### "## "# "######; + //~^ needless_raw_string_hashes cr######" "aa" "# "## "######; + //~^ needless_raw_string_hashes r#" + //~^ needless_raw_string_hashes \a multiline string "#; r###"rust"###; + //~^ needless_raw_string_hashes r#"hello world"#; + //~^ needless_raw_string_hashes } fn issue_13503() { println!(r"SELECT * FROM posts"); println!(r#"SELECT * FROM posts"#); + //~^ needless_raw_string_hashes println!(r##"SELECT * FROM "posts""##); + //~^ needless_raw_string_hashes println!(r##"SELECT * FROM "posts""##); + //~^ needless_raw_string_hashes // Test arguments as well println!("{}", r"foobar".len()); diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index a213ba3e7438..853ee7092528 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -13,7 +13,7 @@ LL + r"\aaa"; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:6:5 + --> tests/ui/needless_raw_string_hashes.rs:7:5 | LL | r##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + r#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:7:5 + --> tests/ui/needless_raw_string_hashes.rs:9:5 | LL | r######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + r####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:8:5 + --> tests/ui/needless_raw_string_hashes.rs:11:5 | LL | r######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + r###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:9:5 + --> tests/ui/needless_raw_string_hashes.rs:13:5 | LL | br#"\aaa"#; | ^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + br"\aaa"; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:10:5 + --> tests/ui/needless_raw_string_hashes.rs:15:5 | LL | br##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + br#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:11:5 + --> tests/ui/needless_raw_string_hashes.rs:17:5 | LL | br######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + br####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:12:5 + --> tests/ui/needless_raw_string_hashes.rs:19:5 | LL | br######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + br###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:13:5 + --> tests/ui/needless_raw_string_hashes.rs:21:5 | LL | cr#"\aaa"#; | ^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + cr"\aaa"; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:14:5 + --> tests/ui/needless_raw_string_hashes.rs:23:5 | LL | cr##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + cr#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:15:5 + --> tests/ui/needless_raw_string_hashes.rs:25:5 | LL | cr######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + cr####" "### "## "# "####; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:16:5 + --> tests/ui/needless_raw_string_hashes.rs:27:5 | LL | cr######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,9 +145,10 @@ LL + cr###" "aa" "# "## "###; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:18:5 + --> tests/ui/needless_raw_string_hashes.rs:30:5 | LL | / r#" +LL | | LL | | \a LL | | multiline LL | | string @@ -157,14 +158,14 @@ LL | | "#; help: remove all the hashes around the string literal | LL ~ r" -LL | \a -LL | multiline +LL | +... LL | string LL ~ "; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:24:5 + --> tests/ui/needless_raw_string_hashes.rs:37:5 | LL | r###"rust"###; | ^^^^^^^^^^^^^ @@ -176,7 +177,7 @@ LL + r"rust"; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:25:5 + --> tests/ui/needless_raw_string_hashes.rs:39:5 | LL | r#"hello world"#; | ^^^^^^^^^^^^^^^^ @@ -188,7 +189,7 @@ LL + r"hello world"; | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:30:14 + --> tests/ui/needless_raw_string_hashes.rs:45:14 | LL | println!(r#"SELECT * FROM posts"#); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +201,7 @@ LL + println!(r"SELECT * FROM posts"); | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:31:14 + --> tests/ui/needless_raw_string_hashes.rs:47:14 | LL | println!(r##"SELECT * FROM "posts""##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -212,7 +213,7 @@ LL + println!(r#"SELECT * FROM "posts""#); | error: unnecessary hashes around raw string literal - --> tests/ui/needless_raw_string_hashes.rs:32:14 + --> tests/ui/needless_raw_string_hashes.rs:49:14 | LL | println!(r##"SELECT * FROM "posts""##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index aa2a274525bc..efc073ebe874 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -27,35 +27,43 @@ fn test_end_of_fn() -> bool { return true; } true + //~^ needless_return } fn test_no_semicolon() -> bool { true + //~^ needless_return } #[rustfmt::skip] fn test_multiple_semicolon() -> bool { true + //~^ needless_return } #[rustfmt::skip] fn test_multiple_semicolon_with_spaces() -> bool { true + //~^ needless_return } fn test_if_block() -> bool { if true { true + //~^ needless_return } else { false + //~^ needless_return } } fn test_match(x: bool) -> bool { match x { true => false, + //~^ needless_return false => { true + //~^ needless_return }, } } @@ -63,20 +71,26 @@ fn test_match(x: bool) -> bool { fn test_closure() { let _ = || { true + //~^ needless_return }; let _ = || true; + //~^ needless_return } fn test_macro_call() -> i32 { the_answer!() + //~^ needless_return } fn test_void_fun() { + //~^^ needless_return } fn test_void_if_fun(b: bool) { if b { + //~^^ needless_return } else { + //~^^ needless_return } } @@ -84,6 +98,7 @@ fn test_void_match(x: u32) { match x { 0 => (), _ => (), + //~^ needless_return } } @@ -92,8 +107,10 @@ fn test_nested_match(x: u32) { 0 => (), 1 => { let _ = 42; + //~^^ needless_return }, _ => (), + //~^ needless_return } } @@ -107,8 +124,10 @@ fn borrows_but_not_last(value: bool) -> String { let x = RefCell::::default(); let _a = x.borrow().clone(); String::from("test") + //~^ needless_return } else { String::new() + //~^ needless_return } } @@ -131,18 +150,22 @@ mod issue6501 { #[allow(clippy::unnecessary_lazy_evaluations)] fn foo(bar: Result<(), ()>) { bar.unwrap_or_else(|_| {}) + //~^ needless_return } fn test_closure() { let _ = || { + //~^^ needless_return }; let _ = || {}; + //~^ needless_return } struct Foo; #[allow(clippy::unnecessary_lazy_evaluations)] fn bar(res: Result) -> Foo { res.unwrap_or_else(|_| Foo) + //~^ needless_return } } @@ -152,25 +175,31 @@ async fn async_test_end_of_fn() -> bool { return true; } true + //~^ needless_return } async fn async_test_no_semicolon() -> bool { true + //~^ needless_return } async fn async_test_if_block() -> bool { if true { true + //~^ needless_return } else { false + //~^ needless_return } } async fn async_test_match(x: bool) -> bool { match x { true => false, + //~^ needless_return false => { true + //~^ needless_return }, } } @@ -178,20 +207,26 @@ async fn async_test_match(x: bool) -> bool { async fn async_test_closure() { let _ = || { true + //~^ needless_return }; let _ = || true; + //~^ needless_return } async fn async_test_macro_call() -> i32 { the_answer!() + //~^ needless_return } async fn async_test_void_fun() { + //~^^ needless_return } async fn async_test_void_if_fun(b: bool) { if b { + //~^^ needless_return } else { + //~^^ needless_return } } @@ -199,6 +234,7 @@ async fn async_test_void_match(x: u32) { match x { 0 => (), _ => (), + //~^ needless_return } } @@ -212,8 +248,10 @@ async fn async_borrows_but_not_last(value: bool) -> String { let x = RefCell::::default(); let _a = x.borrow().clone(); String::from("test") + //~^ needless_return } else { String::new() + //~^ needless_return } } @@ -230,6 +268,7 @@ fn needless_return_macro() -> String { let _ = "foo"; let _ = "bar"; format!("Hello {}", "world!") + //~^ needless_return } fn issue_9361(n: i32) -> i32 { @@ -271,8 +310,10 @@ fn issue8336(x: i32) -> bool { if x > 0 { println!("something"); true + //~^ needless_return } else { false + //~^ needless_return } } @@ -280,9 +321,11 @@ fn issue8156(x: u8) -> u64 { match x { 80 => { 10 + //~^ needless_return }, _ => { 100 + //~^ needless_return }, } } @@ -291,6 +334,7 @@ fn issue8156(x: u8) -> u64 { fn issue9192() -> i32 { { 0 + //~^ needless_return } } @@ -298,8 +342,10 @@ fn issue9503(x: usize) -> isize { unsafe { if x > 12 { *(x as *const isize) + //~^ needless_return } else { !*(x as *const isize) + //~^ needless_return } } } @@ -307,11 +353,13 @@ fn issue9503(x: usize) -> isize { mod issue9416 { pub fn with_newline() { let _ = 42; + //~^^ needless_return } #[rustfmt::skip] pub fn oneline() { let _ = 42; + //~^ needless_return } } @@ -324,18 +372,22 @@ fn issue9947() -> Result<(), String> { fn issue10051() -> Result { if true { Ok(format!("ok!")) + //~^ needless_return } else { Err(format!("err!")) + //~^ needless_return } } mod issue10049 { fn single() -> u32 { if true { 1 } else { 2 } + //~^ needless_return } fn multiple(b1: bool, b2: bool, b3: bool) -> u32 { (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }) + //~^ needless_return } } @@ -357,10 +409,12 @@ fn allow_works() -> i32 { fn conjunctive_blocks() -> String { ({ "a".to_string() } + "b" + { "c" }) + //~^ needless_return } fn issue12907() -> String { "".split("").next().unwrap().to_string() + //~^ needless_return } fn issue13458() { diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index bf67cfd3698a..283d86f25fe5 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -27,35 +27,43 @@ fn test_end_of_fn() -> bool { return true; } return true; + //~^ needless_return } fn test_no_semicolon() -> bool { return true; + //~^ needless_return } #[rustfmt::skip] fn test_multiple_semicolon() -> bool { return true;;; + //~^ needless_return } #[rustfmt::skip] fn test_multiple_semicolon_with_spaces() -> bool { return true;; ; ; + //~^ needless_return } fn test_if_block() -> bool { if true { return true; + //~^ needless_return } else { return false; + //~^ needless_return } } fn test_match(x: bool) -> bool { match x { true => return false, + //~^ needless_return false => { return true; + //~^ needless_return }, } } @@ -63,23 +71,29 @@ fn test_match(x: bool) -> bool { fn test_closure() { let _ = || { return true; + //~^ needless_return }; let _ = || return true; + //~^ needless_return } fn test_macro_call() -> i32 { return the_answer!(); + //~^ needless_return } fn test_void_fun() { return; + //~^^ needless_return } fn test_void_if_fun(b: bool) { if b { return; + //~^^ needless_return } else { return; + //~^^ needless_return } } @@ -87,6 +101,7 @@ fn test_void_match(x: u32) { match x { 0 => (), _ => return, + //~^ needless_return } } @@ -96,8 +111,10 @@ fn test_nested_match(x: u32) { 1 => { let _ = 42; return; + //~^^ needless_return }, _ => return, + //~^ needless_return } } @@ -111,8 +128,10 @@ fn borrows_but_not_last(value: bool) -> String { let x = RefCell::::default(); let _a = x.borrow().clone(); return String::from("test"); + //~^ needless_return } else { return String::new(); + //~^ needless_return } } @@ -135,19 +154,23 @@ mod issue6501 { #[allow(clippy::unnecessary_lazy_evaluations)] fn foo(bar: Result<(), ()>) { bar.unwrap_or_else(|_| return) + //~^ needless_return } fn test_closure() { let _ = || { return; + //~^^ needless_return }; let _ = || return; + //~^ needless_return } struct Foo; #[allow(clippy::unnecessary_lazy_evaluations)] fn bar(res: Result) -> Foo { res.unwrap_or_else(|_| return Foo) + //~^ needless_return } } @@ -157,25 +180,31 @@ async fn async_test_end_of_fn() -> bool { return true; } return true; + //~^ needless_return } async fn async_test_no_semicolon() -> bool { return true; + //~^ needless_return } async fn async_test_if_block() -> bool { if true { return true; + //~^ needless_return } else { return false; + //~^ needless_return } } async fn async_test_match(x: bool) -> bool { match x { true => return false, + //~^ needless_return false => { return true; + //~^ needless_return }, } } @@ -183,23 +212,29 @@ async fn async_test_match(x: bool) -> bool { async fn async_test_closure() { let _ = || { return true; + //~^ needless_return }; let _ = || return true; + //~^ needless_return } async fn async_test_macro_call() -> i32 { return the_answer!(); + //~^ needless_return } async fn async_test_void_fun() { return; + //~^^ needless_return } async fn async_test_void_if_fun(b: bool) { if b { return; + //~^^ needless_return } else { return; + //~^^ needless_return } } @@ -207,6 +242,7 @@ async fn async_test_void_match(x: u32) { match x { 0 => (), _ => return, + //~^ needless_return } } @@ -220,8 +256,10 @@ async fn async_borrows_but_not_last(value: bool) -> String { let x = RefCell::::default(); let _a = x.borrow().clone(); return String::from("test"); + //~^ needless_return } else { return String::new(); + //~^ needless_return } } @@ -238,6 +276,7 @@ fn needless_return_macro() -> String { let _ = "foo"; let _ = "bar"; return format!("Hello {}", "world!"); + //~^ needless_return } fn issue_9361(n: i32) -> i32 { @@ -279,8 +318,10 @@ fn issue8336(x: i32) -> bool { if x > 0 { println!("something"); return true; + //~^ needless_return } else { return false; + //~^ needless_return }; } @@ -288,9 +329,11 @@ fn issue8156(x: u8) -> u64 { match x { 80 => { return 10; + //~^ needless_return }, _ => { return 100; + //~^ needless_return }, }; } @@ -299,6 +342,7 @@ fn issue8156(x: u8) -> u64 { fn issue9192() -> i32 { { return 0; + //~^ needless_return }; } @@ -306,8 +350,10 @@ fn issue9503(x: usize) -> isize { unsafe { if x > 12 { return *(x as *const isize); + //~^ needless_return } else { return !*(x as *const isize); + //~^ needless_return }; }; } @@ -315,13 +361,14 @@ fn issue9503(x: usize) -> isize { mod issue9416 { pub fn with_newline() { let _ = 42; - return; + //~^^ needless_return } #[rustfmt::skip] pub fn oneline() { let _ = 42; return; + //~^ needless_return } } @@ -334,18 +381,22 @@ fn issue9947() -> Result<(), String> { fn issue10051() -> Result { if true { return Ok(format!("ok!")); + //~^ needless_return } else { return Err(format!("err!")); + //~^ needless_return } } mod issue10049 { fn single() -> u32 { return if true { 1 } else { 2 }; + //~^ needless_return } fn multiple(b1: bool, b2: bool, b3: bool) -> u32 { return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; + //~^ needless_return } } @@ -367,10 +418,12 @@ fn allow_works() -> i32 { fn conjunctive_blocks() -> String { return { "a".to_string() } + "b" + { "c" }; + //~^ needless_return } fn issue12907() -> String { return "".split("").next().unwrap().to_string(); + //~^ needless_return } fn issue13458() { diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index d3c2a6badc0f..3865a7fea6bf 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -13,7 +13,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:33:5 + --> tests/ui/needless_return.rs:34:5 | LL | return true; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:38:5 + --> tests/ui/needless_return.rs:40:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:43:5 + --> tests/ui/needless_return.rs:46:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:48:9 + --> tests/ui/needless_return.rs:52:9 | LL | return true; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:50:9 + --> tests/ui/needless_return.rs:55:9 | LL | return false; | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:56:17 + --> tests/ui/needless_return.rs:62:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:58:13 + --> tests/ui/needless_return.rs:65:13 | LL | return true; | ^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:65:9 + --> tests/ui/needless_return.rs:73:9 | LL | return true; | ^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:67:16 + --> tests/ui/needless_return.rs:76:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:71:5 + --> tests/ui/needless_return.rs:81:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:74:21 + --> tests/ui/needless_return.rs:85:21 | LL | fn test_void_fun() { | _____________________^ @@ -146,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:79:11 + --> tests/ui/needless_return.rs:91:11 | LL | if b { | ___________^ @@ -161,7 +161,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:81:13 + --> tests/ui/needless_return.rs:94:13 | LL | } else { | _____________^ @@ -176,7 +176,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:89:14 + --> tests/ui/needless_return.rs:103:14 | LL | _ => return, | ^^^^^^ @@ -187,7 +187,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:97:24 + --> tests/ui/needless_return.rs:112:24 | LL | let _ = 42; | ________________________^ @@ -202,7 +202,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:100:14 + --> tests/ui/needless_return.rs:116:14 | LL | _ => return, | ^^^^^^ @@ -213,7 +213,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:113:9 + --> tests/ui/needless_return.rs:130:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:115:9 + --> tests/ui/needless_return.rs:133:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:137:32 + --> tests/ui/needless_return.rs:156:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -248,7 +248,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:141:21 + --> tests/ui/needless_return.rs:161:21 | LL | let _ = || { | _____________________^ @@ -263,7 +263,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:144:20 + --> tests/ui/needless_return.rs:165:20 | LL | let _ = || return; | ^^^^^^ @@ -274,7 +274,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:150:32 + --> tests/ui/needless_return.rs:172:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -285,7 +285,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:159:5 + --> tests/ui/needless_return.rs:182:5 | LL | return true; | ^^^^^^^^^^^ @@ -297,7 +297,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:163:5 + --> tests/ui/needless_return.rs:187:5 | LL | return true; | ^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:168:9 + --> tests/ui/needless_return.rs:193:9 | LL | return true; | ^^^^^^^^^^^ @@ -321,7 +321,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:170:9 + --> tests/ui/needless_return.rs:196:9 | LL | return false; | ^^^^^^^^^^^^ @@ -333,7 +333,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:176:17 + --> tests/ui/needless_return.rs:203:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -344,7 +344,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:178:13 + --> tests/ui/needless_return.rs:206:13 | LL | return true; | ^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:185:9 + --> tests/ui/needless_return.rs:214:9 | LL | return true; | ^^^^^^^^^^^ @@ -368,7 +368,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:187:16 + --> tests/ui/needless_return.rs:217:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:191:5 + --> tests/ui/needless_return.rs:222:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -391,7 +391,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:194:33 + --> tests/ui/needless_return.rs:226:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -406,7 +406,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:199:11 + --> tests/ui/needless_return.rs:232:11 | LL | if b { | ___________^ @@ -421,7 +421,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:201:13 + --> tests/ui/needless_return.rs:235:13 | LL | } else { | _____________^ @@ -436,7 +436,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:209:14 + --> tests/ui/needless_return.rs:244:14 | LL | _ => return, | ^^^^^^ @@ -447,7 +447,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:222:9 + --> tests/ui/needless_return.rs:258:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:224:9 + --> tests/ui/needless_return.rs:261:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:240:5 + --> tests/ui/needless_return.rs:278:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:281:9 + --> tests/ui/needless_return.rs:320:9 | LL | return true; | ^^^^^^^^^^^ @@ -491,13 +491,14 @@ LL | return true; help: remove `return` | LL ~ true -LL | } else { -LL | return false; +LL | +... +LL | LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:283:9 + --> tests/ui/needless_return.rs:323:9 | LL | return false; | ^^^^^^^^^^^^ @@ -505,11 +506,12 @@ LL | return false; help: remove `return` | LL ~ false +LL | LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:290:13 + --> tests/ui/needless_return.rs:331:13 | LL | return 10; | ^^^^^^^^^ @@ -517,14 +519,14 @@ LL | return 10; help: remove `return` | LL ~ 10 -LL | }, +LL | ... LL | }, LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:293:13 + --> tests/ui/needless_return.rs:335:13 | LL | return 100; | ^^^^^^^^^^ @@ -532,12 +534,13 @@ LL | return 100; help: remove `return` | LL ~ 100 +LL | LL | }, LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:301:9 + --> tests/ui/needless_return.rs:344:9 | LL | return 0; | ^^^^^^^^ @@ -545,11 +548,12 @@ LL | return 0; help: remove `return` | LL ~ 0 +LL | LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:308:13 + --> tests/ui/needless_return.rs:352:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -557,14 +561,15 @@ LL | return *(x as *const isize); help: remove `return` | LL ~ *(x as *const isize) -LL | } else { -LL | return !*(x as *const isize); +LL | +... +LL | LL ~ } LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:310:13 + --> tests/ui/needless_return.rs:355:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -572,29 +577,28 @@ LL | return !*(x as *const isize); help: remove `return` | LL ~ !*(x as *const isize) +LL | LL ~ } LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:317:20 + --> tests/ui/needless_return.rs:363:20 | LL | let _ = 42; | ____________________^ -LL | | LL | | return; | |______________^ | help: remove `return` | LL - let _ = 42; -LL - LL - return; LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:324:20 + --> tests/ui/needless_return.rs:370:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -606,7 +610,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:336:9 + --> tests/ui/needless_return.rs:383:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -618,7 +622,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:338:9 + --> tests/ui/needless_return.rs:386:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -630,7 +634,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:344:9 + --> tests/ui/needless_return.rs:393:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -642,7 +646,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:348:9 + --> tests/ui/needless_return.rs:398:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -654,7 +658,7 @@ LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else | error: unneeded `return` statement - --> tests/ui/needless_return.rs:369:5 + --> tests/ui/needless_return.rs:420:5 | LL | return { "a".to_string() } + "b" + { "c" }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -666,7 +670,7 @@ LL + ({ "a".to_string() } + "b" + { "c" }) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:373:5 + --> tests/ui/needless_return.rs:425:5 | LL | return "".split("").next().unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_return_with_question_mark.fixed b/tests/ui/needless_return_with_question_mark.fixed index 9b7da8526631..2c6faf37717d 100644 --- a/tests/ui/needless_return_with_question_mark.fixed +++ b/tests/ui/needless_return_with_question_mark.fixed @@ -27,6 +27,7 @@ fn c() -> Option<()> { fn main() -> Result<(), ()> { Err(())?; + //~^ needless_return_with_question_mark return Ok::<(), ()>(()); Err(())?; Ok::<(), ()>(()); diff --git a/tests/ui/needless_return_with_question_mark.rs b/tests/ui/needless_return_with_question_mark.rs index 68e76d2b6402..b4411fa19561 100644 --- a/tests/ui/needless_return_with_question_mark.rs +++ b/tests/ui/needless_return_with_question_mark.rs @@ -27,6 +27,7 @@ fn c() -> Option<()> { fn main() -> Result<(), ()> { return Err(())?; + //~^ needless_return_with_question_mark return Ok::<(), ()>(()); Err(())?; Ok::<(), ()>(()); diff --git a/tests/ui/needless_return_with_question_mark.stderr b/tests/ui/needless_return_with_question_mark.stderr index 76dd5f953bc6..2af0f46a1ad0 100644 --- a/tests/ui/needless_return_with_question_mark.stderr +++ b/tests/ui/needless_return_with_question_mark.stderr @@ -8,7 +8,7 @@ LL | return Err(())?; = help: to override `-D warnings` add `#[allow(clippy::needless_return_with_question_mark)]` error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:69:9 + --> tests/ui/needless_return_with_question_mark.rs:70:9 | LL | return Err(())?; | ^^^^^^^ help: remove it diff --git a/tests/ui/needless_splitn.fixed b/tests/ui/needless_splitn.fixed index efc47533e233..bf5c1717ae53 100644 --- a/tests/ui/needless_splitn.fixed +++ b/tests/ui/needless_splitn.fixed @@ -11,29 +11,41 @@ use itertools::Itertools; fn main() { let str = "key=value=end"; let _ = str.split('=').next(); + //~^ needless_splitn let _ = str.split('=').nth(0); + //~^ needless_splitn let _ = str.splitn(2, '=').nth(1); let (_, _) = str.splitn(2, '=').next_tuple().unwrap(); let (_, _) = str.split('=').next_tuple().unwrap(); + //~^ needless_splitn let _: Vec<&str> = str.splitn(3, '=').collect(); let _ = str.rsplit('=').next(); + //~^ needless_splitn let _ = str.rsplit('=').nth(0); + //~^ needless_splitn let _ = str.rsplitn(2, '=').nth(1); let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap(); let (_, _) = str.rsplit('=').next_tuple().unwrap(); + //~^ needless_splitn let _ = str.split('=').next(); + //~^ needless_splitn let _ = str.split('=').nth(3); + //~^ needless_splitn let _ = str.splitn(5, '=').nth(4); let _ = str.splitn(5, '=').nth(5); } fn _question_mark(s: &str) -> Option<()> { let _ = s.split('=').next()?; + //~^ needless_splitn let _ = s.split('=').nth(0)?; + //~^ needless_splitn let _ = s.rsplit('=').next()?; + //~^ needless_splitn let _ = s.rsplit('=').nth(0)?; + //~^ needless_splitn Some(()) } @@ -42,4 +54,5 @@ fn _question_mark(s: &str) -> Option<()> { fn _test_msrv() { // `manual_split_once` MSRV shouldn't apply to `needless_splitn` let _ = "key=value".split('=').nth(0).unwrap(); + //~^ needless_splitn } diff --git a/tests/ui/needless_splitn.rs b/tests/ui/needless_splitn.rs index a4a3736eea2f..fdfdcb9d5ca8 100644 --- a/tests/ui/needless_splitn.rs +++ b/tests/ui/needless_splitn.rs @@ -11,29 +11,41 @@ use itertools::Itertools; fn main() { let str = "key=value=end"; let _ = str.splitn(2, '=').next(); + //~^ needless_splitn let _ = str.splitn(2, '=').nth(0); + //~^ needless_splitn let _ = str.splitn(2, '=').nth(1); let (_, _) = str.splitn(2, '=').next_tuple().unwrap(); let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); + //~^ needless_splitn let _: Vec<&str> = str.splitn(3, '=').collect(); let _ = str.rsplitn(2, '=').next(); + //~^ needless_splitn let _ = str.rsplitn(2, '=').nth(0); + //~^ needless_splitn let _ = str.rsplitn(2, '=').nth(1); let (_, _) = str.rsplitn(2, '=').next_tuple().unwrap(); let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); + //~^ needless_splitn let _ = str.splitn(5, '=').next(); + //~^ needless_splitn let _ = str.splitn(5, '=').nth(3); + //~^ needless_splitn let _ = str.splitn(5, '=').nth(4); let _ = str.splitn(5, '=').nth(5); } fn _question_mark(s: &str) -> Option<()> { let _ = s.splitn(2, '=').next()?; + //~^ needless_splitn let _ = s.splitn(2, '=').nth(0)?; + //~^ needless_splitn let _ = s.rsplitn(2, '=').next()?; + //~^ needless_splitn let _ = s.rsplitn(2, '=').nth(0)?; + //~^ needless_splitn Some(()) } @@ -42,4 +54,5 @@ fn _question_mark(s: &str) -> Option<()> { fn _test_msrv() { // `manual_split_once` MSRV shouldn't apply to `needless_splitn` let _ = "key=value".splitn(2, '=').nth(0).unwrap(); + //~^ needless_splitn } diff --git a/tests/ui/needless_splitn.stderr b/tests/ui/needless_splitn.stderr index ffd82c3fcb13..49387793a122 100644 --- a/tests/ui/needless_splitn.stderr +++ b/tests/ui/needless_splitn.stderr @@ -8,73 +8,73 @@ LL | let _ = str.splitn(2, '=').next(); = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:14:13 + --> tests/ui/needless_splitn.rs:15:13 | LL | let _ = str.splitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:17:18 + --> tests/ui/needless_splitn.rs:19:18 | LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:20:13 + --> tests/ui/needless_splitn.rs:23:13 | LL | let _ = str.rsplitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:21:13 + --> tests/ui/needless_splitn.rs:25:13 | LL | let _ = str.rsplitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:24:18 + --> tests/ui/needless_splitn.rs:29:18 | LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:26:13 + --> tests/ui/needless_splitn.rs:32:13 | LL | let _ = str.splitn(5, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:27:13 + --> tests/ui/needless_splitn.rs:34:13 | LL | let _ = str.splitn(5, '=').nth(3); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:33:13 + --> tests/ui/needless_splitn.rs:41:13 | LL | let _ = s.splitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:34:13 + --> tests/ui/needless_splitn.rs:43:13 | LL | let _ = s.splitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:35:13 + --> tests/ui/needless_splitn.rs:45:13 | LL | let _ = s.rsplitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:36:13 + --> tests/ui/needless_splitn.rs:47:13 | LL | let _ = s.rsplitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:44:13 + --> tests/ui/needless_splitn.rs:56:13 | LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')` diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 7c59abf07aba..6e91c957e811 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -17,8 +17,9 @@ 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` + //~^ needless_update + + 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 c79fd2665260..7d24429b5867 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -14,20 +14,24 @@ 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` + //~^ neg_cmp_op_on_partial_ord + + // 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 + //~^ neg_cmp_op_on_partial_ord + // 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 + //~^ neg_cmp_op_on_partial_ord + // 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 + //~^ neg_cmp_op_on_partial_ord + // --- Good --- diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr index d4f7f14f59a3..f6347b7d56cd 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -8,19 +8,19 @@ LL | let _not_less = !(a_value < another_value); = help: to override `-D warnings` add `#[allow(clippy::neg_cmp_op_on_partial_ord)]` 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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:21:30 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:22: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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:25:24 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:27: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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:29:33 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:32:33 | LL | let _not_greater_or_equal = !(a_value >= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/neg_multiply.fixed b/tests/ui/neg_multiply.fixed index 52edea73afbb..995470493bfb 100644 --- a/tests/ui/neg_multiply.fixed +++ b/tests/ui/neg_multiply.fixed @@ -26,19 +26,27 @@ fn main() { let x = 0; -x; + //~^ neg_multiply -x; + //~^ neg_multiply 100 + -x; + //~^ neg_multiply -(100 + x); + //~^ neg_multiply -17; + //~^ neg_multiply 0xcafe | -0xff00; + //~^ neg_multiply -(3_usize as i32); + //~^ neg_multiply -(3_usize as i32); + //~^ neg_multiply -1 * -1; // should be ok diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 23092a35e606..95b94e29517f 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -26,19 +26,27 @@ fn main() { let x = 0; x * -1; + //~^ neg_multiply -1 * x; + //~^ neg_multiply 100 + x * -1; + //~^ neg_multiply (100 + x) * -1; + //~^ neg_multiply -1 * 17; + //~^ neg_multiply 0xcafe | 0xff00 * -1; + //~^ neg_multiply 3_usize as i32 * -1; + //~^ neg_multiply (3_usize as i32) * -1; + //~^ neg_multiply -1 * -1; // should be ok diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index 13226c7c37b3..9efa5d3ba1f1 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -8,43 +8,43 @@ LL | x * -1; = help: to override `-D warnings` add `#[allow(clippy::neg_multiply)]` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:30:5 + --> tests/ui/neg_multiply.rs:31:5 | LL | -1 * x; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:32:11 + --> tests/ui/neg_multiply.rs:34:11 | LL | 100 + x * -1; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:34:5 + --> tests/ui/neg_multiply.rs:37:5 | LL | (100 + x) * -1; | ^^^^^^^^^^^^^^ help: consider using: `-(100 + x)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:36:5 + --> tests/ui/neg_multiply.rs:40:5 | LL | -1 * 17; | ^^^^^^^ help: consider using: `-17` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:38:14 + --> tests/ui/neg_multiply.rs:43:14 | LL | 0xcafe | 0xff00 * -1; | ^^^^^^^^^^^ help: consider using: `-0xff00` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:40:5 + --> tests/ui/neg_multiply.rs:46:5 | LL | 3_usize as i32 * -1; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:41:5 + --> tests/ui/neg_multiply.rs:48: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 93c69209c698..c366e7d86310 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -10,8 +10,9 @@ fn test1() { let mut x = 0; loop { - //~^ ERROR: this loop never actually loops - //~| NOTE: `#[deny(clippy::never_loop)]` on by default + //~^ never_loop + + // clippy::never_loop x += 1; if x == 1 { @@ -34,7 +35,8 @@ fn test2() { fn test3() { let mut x = 0; loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops x += 1; break; @@ -55,10 +57,12 @@ fn test4() { fn test5() { let i = 0; loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops while i == 0 { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops break; } @@ -71,7 +75,8 @@ fn test6() { 'outer: loop { x += 1; loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops if x == 5 { break; @@ -108,7 +113,8 @@ fn test8() { fn test9() { let x = Some(1); while let Some(y) = x { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops return; } @@ -116,7 +122,8 @@ fn test9() { fn test10() { for x in 0..10 { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops match x { 1 => break, @@ -165,7 +172,8 @@ pub fn test13() { pub fn test14() { let mut a = true; 'outer: while a { - //~^ ERROR: this loop never actually loops + //~^ never_loop + // never loops while a { if a { @@ -181,7 +189,8 @@ pub fn test14() { pub fn test15() { 'label: loop { while false { - //~^ ERROR: this loop never actually loops + //~^ never_loop + break 'label; } } @@ -233,7 +242,8 @@ pub fn test18() { }; // never loops let _ = loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + let Some(x) = x else { return; }; @@ -255,12 +265,14 @@ pub fn test19() { pub fn test20() { 'a: loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + 'b: { break 'b 'c: { break 'a; - //~^ ERROR: sub-expression diverges - //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` + //~^ diverging_sub_expression + + }; } } @@ -292,7 +304,8 @@ pub fn test23() { for _ in 0..10 { 'block: { for _ in 0..20 { - //~^ ERROR: this loop never actually loops + //~^ never_loop + break 'block; } } @@ -376,7 +389,8 @@ pub fn test31(b: bool) { 'a: loop { 'b: { 'c: loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + if b { break 'c } else { break 'b } } continue 'a; @@ -387,11 +401,13 @@ pub fn test31(b: bool) { pub fn test32() { loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + panic!("oh no"); } loop { - //~^ ERROR: this loop never actually loops + //~^ never_loop + unimplemented!("not yet"); } loop { diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index dab3488af106..6d492f8eb9da 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -10,67 +10,52 @@ LL | | } = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops - --> tests/ui/never_loop.rs:36:5 + --> tests/ui/never_loop.rs:37:5 | LL | / loop { -LL | | -LL | | // never loops -LL | | x += 1; +... | LL | | break; LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:57:5 + --> tests/ui/never_loop.rs:59:5 | LL | / loop { -LL | | -LL | | // never loops -LL | | while i == 0 { ... | LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:60:9 + --> tests/ui/never_loop.rs:63:9 | LL | / while i == 0 { -LL | | -LL | | // never loops -LL | | break; +... | LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:73:9 + --> tests/ui/never_loop.rs:77:9 | LL | / loop { -LL | | -LL | | // never loops -LL | | if x == 5 { ... | LL | | continue 'outer; LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:110:5 + --> tests/ui/never_loop.rs:115:5 | LL | / while let Some(y) = x { -LL | | -LL | | // never loops -LL | | return; +... | LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:118:5 + --> tests/ui/never_loop.rs:124:5 | LL | / for x in 0..10 { -LL | | -LL | | // never loops -LL | | match x { ... | LL | | } | |_____^ @@ -81,52 +66,50 @@ LL | if let Some(x) = (0..10).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> tests/ui/never_loop.rs:167:5 + --> tests/ui/never_loop.rs:174:5 | LL | / 'outer: while a { -LL | | -LL | | // never loops -LL | | while a { ... | LL | | break 'outer; LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:183:9 + --> tests/ui/never_loop.rs:191:9 | LL | / while false { LL | | +LL | | LL | | break 'label; LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:235:13 + --> tests/ui/never_loop.rs:244:13 | LL | let _ = loop { | _____________^ LL | | +LL | | LL | | let Some(x) = x else { -LL | | return; ... | LL | | break x; LL | | }; | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:257:5 + --> tests/ui/never_loop.rs:267:5 | LL | / 'a: loop { LL | | +LL | | LL | | 'b: { -LL | | break 'b 'c: { ... | LL | | } | |_____^ error: sub-expression diverges - --> tests/ui/never_loop.rs:261:17 + --> tests/ui/never_loop.rs:272:17 | LL | break 'a; | ^^^^^^^^ @@ -135,10 +118,11 @@ LL | break 'a; = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: this loop never actually loops - --> tests/ui/never_loop.rs:294:13 + --> tests/ui/never_loop.rs:306:13 | LL | / for _ in 0..20 { LL | | +LL | | LL | | break 'block; LL | | } | |_____________^ @@ -149,28 +133,31 @@ LL | if let Some(_) = (0..20).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> tests/ui/never_loop.rs:378:13 + --> tests/ui/never_loop.rs:391:13 | LL | / 'c: loop { LL | | +LL | | LL | | if b { break 'c } else { break 'b } LL | | } | |_____________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:389:5 + --> tests/ui/never_loop.rs:403:5 | LL | / loop { LL | | +LL | | LL | | panic!("oh no"); LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:393:5 + --> tests/ui/never_loop.rs:408:5 | LL | / loop { LL | | +LL | | LL | | unimplemented!("not yet"); LL | | } | |_____^ diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 175b14d815a2..fc7dea97e48a 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -48,8 +48,9 @@ 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` + //~^ new_ret_no_self + + S3 } } @@ -82,7 +83,8 @@ struct U; impl U { // should trigger lint pub fn new() -> u32 { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -92,7 +94,8 @@ struct V; impl V { // should trigger lint pub fn new(_: String) -> u32 { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -129,7 +132,8 @@ struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint pub fn new() -> (u32, u32) { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -157,7 +161,8 @@ struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -176,7 +181,8 @@ struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint pub fn new() -> Option { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -230,7 +236,8 @@ mod issue5435 { pub trait TraitRet { // should trigger lint as we are in trait definition fn new() -> String; - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + } pub struct StructRet; impl TraitRet for StructRet { @@ -243,7 +250,8 @@ mod issue5435 { pub trait TraitRet2 { // should trigger lint fn new(_: String) -> String; - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + } trait TupleReturnerOk { @@ -279,7 +287,8 @@ mod issue5435 { trait TupleReturnerBad { // should trigger lint fn new() -> (u32, u32) { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -307,7 +316,8 @@ mod issue5435 { trait MutPointerReturnerBad { // should trigger lint fn new() -> *mut V { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + unimplemented!(); } } @@ -378,7 +388,8 @@ mod issue7344 { impl RetImplTraitNoSelf { // should trigger lint fn new(t: T) -> impl Into { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + 1 } } @@ -398,7 +409,8 @@ mod issue7344 { impl RetImplTraitNoSelf2 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { - //~^ ERROR: methods called `new` usually return `Self` + //~^ new_ret_no_self + } } diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 3597ad65838f..e31282c3fb7e 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -2,9 +2,7 @@ error: methods called `new` usually return `Self` --> tests/ui/new_ret_no_self.rs:50:5 | LL | / pub fn new(_: String) -> impl R { -LL | | -LL | | -LL | | S3 +... | LL | | } | |_____^ | @@ -12,94 +10,102 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:84:5 + --> tests/ui/new_ret_no_self.rs:85:5 | LL | / pub fn new() -> u32 { LL | | +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:94:5 + --> tests/ui/new_ret_no_self.rs:96:5 | LL | / pub fn new(_: String) -> u32 { LL | | +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:131:5 + --> tests/ui/new_ret_no_self.rs:134:5 | LL | / pub fn new() -> (u32, u32) { LL | | +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:159:5 + --> tests/ui/new_ret_no_self.rs:163:5 | LL | / pub fn new() -> *mut V { LL | | -LL | | unimplemented!(); -LL | | } - | |_____^ - -error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:178:5 - | -LL | / pub fn new() -> Option { LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:232:9 + --> tests/ui/new_ret_no_self.rs:183:5 + | +LL | / pub fn new() -> Option { +LL | | +LL | | +LL | | unimplemented!(); +LL | | } + | |_____^ + +error: methods called `new` usually return `Self` + --> tests/ui/new_ret_no_self.rs:238:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:245:9 + --> tests/ui/new_ret_no_self.rs:252:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:281:9 + --> tests/ui/new_ret_no_self.rs:289:9 | LL | / fn new() -> (u32, u32) { LL | | -LL | | unimplemented!(); -LL | | } - | |_________^ - -error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:309:9 - | -LL | / fn new() -> *mut V { LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:380:9 + --> tests/ui/new_ret_no_self.rs:318:9 + | +LL | / fn new() -> *mut V { +LL | | +LL | | +LL | | unimplemented!(); +LL | | } + | |_________^ + +error: methods called `new` usually return `Self` + --> tests/ui/new_ret_no_self.rs:390:9 | LL | / fn new(t: T) -> impl Into { LL | | +LL | | LL | | 1 LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:400:9 + --> tests/ui/new_ret_no_self.rs:411:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { -LL | | +... | LL | | } | |_________^ diff --git a/tests/ui/new_ret_no_self_overflow.rs b/tests/ui/new_ret_no_self_overflow.rs index 7bc6fec10ba6..db7ce9c4054e 100644 --- a/tests/ui/new_ret_no_self_overflow.rs +++ b/tests/ui/new_ret_no_self_overflow.rs @@ -18,6 +18,7 @@ mod issue10041 { impl Bomb2 { pub fn new() -> X { + //~^ ERROR: overflow evaluating the requirement 0i32 } } diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 5a6a92394a7f..8fd703200835 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -17,8 +17,9 @@ 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` + //~^ new_without_default + + Foo } } @@ -33,7 +34,8 @@ impl Default for Bar { impl Bar { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `Bar` + //~^ new_without_default + Bar } } @@ -104,7 +106,8 @@ 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>` + //~^ new_without_default + unimplemented!() } } @@ -143,6 +146,7 @@ impl Default for Const { impl Const { pub const fn new() -> Const { + //~^ new_without_default Const } // While Default is not const, it can still call const functions, so we should lint this } @@ -209,7 +213,8 @@ 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 + //~^ new_without_default + NewNotEqualToDerive { foo: 1 } } } @@ -224,7 +229,8 @@ impl Default for FooGenerics { impl FooGenerics { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` + //~^ new_without_default + Self(Default::default()) } } @@ -238,7 +244,8 @@ impl Default for BarGenerics { impl BarGenerics { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` + //~^ new_without_default + Self(Default::default()) } } @@ -256,7 +263,8 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~^ new_without_default + todo!() } } @@ -311,6 +319,7 @@ where K: std::hash::Hash + Eq + PartialEq, { pub fn new() -> Self { + //~^ new_without_default Self { _kv: None } } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 12ea729253ac..856f515e4aba 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -11,8 +11,9 @@ 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` + //~^ new_without_default + + Foo } } @@ -21,7 +22,8 @@ pub struct Bar; impl Bar { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `Bar` + //~^ new_without_default + Bar } } @@ -86,7 +88,8 @@ pub struct LtKo<'a> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { - //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` + //~^ new_without_default + unimplemented!() } } @@ -119,6 +122,7 @@ pub struct Const; impl Const { pub const fn new() -> Const { + //~^ new_without_default Const } // While Default is not const, it can still call const functions, so we should lint this } @@ -179,7 +183,8 @@ 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 + //~^ new_without_default + NewNotEqualToDerive { foo: 1 } } } @@ -188,7 +193,8 @@ impl NewNotEqualToDerive { pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` + //~^ new_without_default + Self(Default::default()) } } @@ -196,7 +202,8 @@ impl FooGenerics { pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` + //~^ new_without_default + Self(Default::default()) } } @@ -208,7 +215,8 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { - //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~^ new_without_default + todo!() } } @@ -254,6 +262,7 @@ where K: std::hash::Hash + Eq + PartialEq, { pub fn new() -> Self { + //~^ new_without_default Self { _kv: None } } } diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 57bf4bd847cc..1a122d341a08 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -2,9 +2,7 @@ error: you should consider adding a `Default` implementation for `Foo` --> tests/ui/new_without_default.rs:13:5 | LL | / pub fn new() -> Foo { -LL | | -LL | | -LL | | Foo +... | LL | | } | |_____^ | @@ -20,10 +18,11 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> tests/ui/new_without_default.rs:23:5 + --> tests/ui/new_without_default.rs:24:5 | LL | / pub fn new() -> Self { LL | | +LL | | LL | | Bar LL | | } | |_____^ @@ -38,10 +37,11 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> tests/ui/new_without_default.rs:88:5 + --> tests/ui/new_without_default.rs:90:5 | LL | / pub fn new() -> LtKo<'c> { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -56,9 +56,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Const` - --> tests/ui/new_without_default.rs:121:5 + --> tests/ui/new_without_default.rs:124:5 | LL | / pub const fn new() -> Const { +LL | | LL | | Const LL | | } // While Default is not const, it can still call const functions, so we should lint this | |_____^ @@ -73,10 +74,11 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> tests/ui/new_without_default.rs:181:5 + --> tests/ui/new_without_default.rs:185:5 | LL | / pub fn new() -> Self { LL | | +LL | | LL | | NewNotEqualToDerive { foo: 1 } LL | | } | |_____^ @@ -91,10 +93,11 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> tests/ui/new_without_default.rs:190:5 + --> tests/ui/new_without_default.rs:195:5 | LL | / pub fn new() -> Self { LL | | +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -109,10 +112,11 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> tests/ui/new_without_default.rs:198:5 + --> tests/ui/new_without_default.rs:204:5 | LL | / pub fn new() -> Self { LL | | +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -127,10 +131,11 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:210:9 + --> tests/ui/new_without_default.rs:217:9 | LL | / pub fn new() -> Self { LL | | +LL | | LL | | todo!() LL | | } | |_________^ @@ -147,9 +152,10 @@ LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> tests/ui/new_without_default.rs:256:5 + --> tests/ui/new_without_default.rs:264:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self { _kv: None } LL | | } | |_____^ diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 0ea911c34348..cd992aed15e2 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -113,62 +113,89 @@ fn main() { let s = get_struct(); 0; - //~^ ERROR: statement with no effect + //~^ no_effect + Tuple(0); - //~^ ERROR: statement with no effect + //~^ no_effect + Struct { field: 0 }; - //~^ ERROR: statement with no effect + //~^ no_effect + Struct { ..s }; - //~^ ERROR: statement with no effect + //~^ no_effect + Union { a: 0 }; - //~^ ERROR: statement with no effect + //~^ no_effect + Enum::Tuple(0); - //~^ ERROR: statement with no effect + //~^ no_effect + Enum::Struct { field: 0 }; - //~^ ERROR: statement with no effect + //~^ no_effect + 5 + 6; - //~^ ERROR: statement with no effect + //~^ no_effect + *&42; - //~^ ERROR: statement with no effect + //~^ no_effect + &6; - //~^ ERROR: statement with no effect + //~^ no_effect + (5, 6, 7); - //~^ ERROR: statement with no effect + //~^ no_effect + ..; - //~^ ERROR: statement with no effect + //~^ no_effect + 5..; - //~^ ERROR: statement with no effect + //~^ no_effect + ..5; - //~^ ERROR: statement with no effect + //~^ no_effect + 5..6; - //~^ ERROR: statement with no effect + //~^ no_effect + 5..=6; - //~^ ERROR: statement with no effect + //~^ no_effect + [42, 55]; - //~^ ERROR: statement with no effect + //~^ no_effect + [42, 55][1]; - //~^ ERROR: statement with no effect + //~^ no_effect + (42, 55).1; - //~^ ERROR: statement with no effect + //~^ no_effect + [42; 55]; - //~^ ERROR: statement with no effect + //~^ no_effect + [42; 55][13]; - //~^ ERROR: statement with no effect + //~^ no_effect + let mut x = 0; || x += 5; - //~^ ERROR: statement with no effect + //~^ no_effect + let s: String = "foo".into(); FooString { s: s }; - //~^ ERROR: statement with no effect + //~^ 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` + //~^ no_effect_underscore_binding + + let _penguin = || println!("Some helpful closure"); - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + let _duck = Struct { field: 0 }; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + let _cat = [2, 4, 6, 8][2]; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + let _issue_12166 = 42; let underscore_variable_above_can_be_used_dont_lint = _issue_12166; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 48ec997d938c..617a43aaf60d 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -8,139 +8,139 @@ LL | 0; = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> tests/ui/no_effect.rs:117:5 + --> tests/ui/no_effect.rs:118:5 | LL | Tuple(0); | ^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:119:5 + --> tests/ui/no_effect.rs:121:5 | LL | Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:121:5 + --> tests/ui/no_effect.rs:124:5 | LL | Struct { ..s }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:123:5 + --> tests/ui/no_effect.rs:127:5 | LL | Union { a: 0 }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:125:5 + --> tests/ui/no_effect.rs:130:5 | LL | Enum::Tuple(0); | ^^^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:127:5 + --> tests/ui/no_effect.rs:133:5 | LL | Enum::Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:129:5 + --> tests/ui/no_effect.rs:136:5 | LL | 5 + 6; | ^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:131:5 + --> tests/ui/no_effect.rs:139:5 | LL | *&42; | ^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:133:5 + --> tests/ui/no_effect.rs:142:5 | LL | &6; | ^^^ error: statement with no effect - --> tests/ui/no_effect.rs:135:5 + --> tests/ui/no_effect.rs:145:5 | LL | (5, 6, 7); | ^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:137:5 + --> tests/ui/no_effect.rs:148:5 | LL | ..; | ^^^ error: statement with no effect - --> tests/ui/no_effect.rs:139:5 + --> tests/ui/no_effect.rs:151:5 | LL | 5..; | ^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:141:5 + --> tests/ui/no_effect.rs:154:5 | LL | ..5; | ^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:143:5 + --> tests/ui/no_effect.rs:157:5 | LL | 5..6; | ^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:145:5 + --> tests/ui/no_effect.rs:160:5 | LL | 5..=6; | ^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:147:5 + --> tests/ui/no_effect.rs:163:5 | LL | [42, 55]; | ^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:149:5 + --> tests/ui/no_effect.rs:166:5 | LL | [42, 55][1]; | ^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:151:5 + --> tests/ui/no_effect.rs:169:5 | LL | (42, 55).1; | ^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:153:5 + --> tests/ui/no_effect.rs:172:5 | LL | [42; 55]; | ^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:155:5 + --> tests/ui/no_effect.rs:175:5 | LL | [42; 55][13]; | ^^^^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:158:5 + --> tests/ui/no_effect.rs:179:5 | LL | || x += 5; | ^^^^^^^^^^ error: statement with no effect - --> tests/ui/no_effect.rs:161:5 + --> tests/ui/no_effect.rs:183:5 | LL | FooString { s: s }; | ^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:163:9 + --> tests/ui/no_effect.rs:186:9 | LL | let _unused = 1; | ^^^^^^^ @@ -149,19 +149,19 @@ LL | let _unused = 1; = help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]` error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:166:9 + --> tests/ui/no_effect.rs:190:9 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:168:9 + --> tests/ui/no_effect.rs:193:9 | LL | let _duck = Struct { field: 0 }; | ^^^^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:170:9 + --> tests/ui/no_effect.rs:196:9 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^ diff --git a/tests/ui/no_effect_async_fn.rs b/tests/ui/no_effect_async_fn.rs index ef0f3d1df1ac..6fb3ccab8a08 100644 --- a/tests/ui/no_effect_async_fn.rs +++ b/tests/ui/no_effect_async_fn.rs @@ -11,14 +11,16 @@ impl AsyncTrait for Bar { // Shouldn't lint `binding to `_` prefixed variable with no side-effect` async fn bar(_i: u64) { let _a = 0; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _b = num(); let _ = async { let _c = 0; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _d = num(); @@ -30,14 +32,16 @@ impl AsyncTrait for Bar { // Shouldn't lint `binding to `_` prefixed variable with no side-effect` async fn foo(_i: u64) { let _a = 0; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _b = num(); let _ = async { let _c = 0; - //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~^ no_effect_underscore_binding + // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _d = num(); diff --git a/tests/ui/no_effect_async_fn.stderr b/tests/ui/no_effect_async_fn.stderr index 2325eb9aae59..96ad7b9d6075 100644 --- a/tests/ui/no_effect_async_fn.stderr +++ b/tests/ui/no_effect_async_fn.stderr @@ -1,5 +1,5 @@ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:20:17 + --> tests/ui/no_effect_async_fn.rs:21:17 | LL | let _c = 0; | ^^ @@ -14,13 +14,13 @@ LL | let _a = 0; | ^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:39:13 + --> tests/ui/no_effect_async_fn.rs:42:13 | LL | let _c = 0; | ^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:32:9 + --> tests/ui/no_effect_async_fn.rs:34:9 | LL | let _a = 0; | ^^ diff --git a/tests/ui/no_effect_replace.rs b/tests/ui/no_effect_replace.rs index e4fd5caae2a5..dc8e66f69ff5 100644 --- a/tests/ui/no_effect_replace.rs +++ b/tests/ui/no_effect_replace.rs @@ -2,30 +2,38 @@ fn main() { let _ = "12345".replace('1', "1"); - //~^ ERROR: replacing text with itself - //~| NOTE: `-D clippy::no-effect-replace` implied by `-D warnings` + //~^ no_effect_replace + + let _ = "12345".replace("12", "12"); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + let _ = String::new().replace("12", "12"); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + let _ = "12345".replacen('1', "1", 1); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + let _ = "12345".replacen("12", "12", 1); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + let _ = String::new().replacen("12", "12", 1); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + 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 + //~^ no_effect_replace + let _ = "hello".replace(&x.f(), &x.ff()); let _ = "hello".replace(&y(), &y()); - //~^ ERROR: replacing text with itself + //~^ no_effect_replace + 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 ded86c5c5b8d..3861d042e6f5 100644 --- a/tests/ui/no_effect_replace.stderr +++ b/tests/ui/no_effect_replace.stderr @@ -8,43 +8,43 @@ LL | let _ = "12345".replace('1', "1"); = help: to override `-D warnings` add `#[allow(clippy::no_effect_replace)]` error: replacing text with itself - --> tests/ui/no_effect_replace.rs:7:13 + --> tests/ui/no_effect_replace.rs:8:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:9:13 + --> tests/ui/no_effect_replace.rs:11:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:12:13 + --> tests/ui/no_effect_replace.rs:15:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:14:13 + --> tests/ui/no_effect_replace.rs:18:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:16:13 + --> tests/ui/no_effect_replace.rs:21:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:23:13 + --> tests/ui/no_effect_replace.rs:29:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:27:13 + --> tests/ui/no_effect_replace.rs:34:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index e46c0d73518b..8bfd8367f104 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -7,8 +7,9 @@ use std::ops::ControlFlow; fn a() -> u32 { { 0u32; - //~^ ERROR: statement with no effect - //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` + //~^ no_effect + + } 0 } @@ -16,7 +17,8 @@ fn a() -> u32 { async fn b() -> u32 { { 0u32; - //~^ ERROR: statement with no effect + //~^ no_effect + } 0 } @@ -25,7 +27,8 @@ type C = i32; async fn c() -> C { { 0i32 as C; - //~^ ERROR: statement with no effect + //~^ no_effect + } 0 } @@ -34,7 +37,8 @@ fn d() -> u128 { { // not last stmt 0u128; - //~^ ERROR: statement with no effect + //~^ no_effect + println!("lol"); } 0 @@ -44,7 +48,8 @@ fn e() -> u32 { { // mismatched types 0u16; - //~^ ERROR: statement with no effect + //~^ no_effect + } 0 } @@ -52,7 +57,8 @@ fn e() -> u32 { fn f() -> [u16; 1] { { [1u16]; - //~^ ERROR: statement with no effect + //~^ no_effect + } [1] } @@ -60,7 +66,8 @@ fn f() -> [u16; 1] { fn g() -> ControlFlow<()> { { ControlFlow::Break::<()>(()); - //~^ ERROR: statement with no effect + //~^ no_effect + } ControlFlow::Continue(()) } @@ -78,7 +85,8 @@ fn i() -> () { { // does not suggest on function with explicit unit return type (); - //~^ ERROR: statement with no effect + //~^ no_effect + } () } @@ -87,7 +95,8 @@ fn j() { { // does not suggest on function without explicit return type (); - //~^ ERROR: statement with no effect + //~^ no_effect + } () } diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index 3cfe375d034a..f6ff2ded33e0 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -10,7 +10,7 @@ LL | 0u32; = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> tests/ui/no_effect_return.rs:18:9 + --> tests/ui/no_effect_return.rs:19:9 | LL | 0u32; | -^^^^ @@ -18,7 +18,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:27:9 + --> tests/ui/no_effect_return.rs:29:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -26,19 +26,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:36:9 + --> tests/ui/no_effect_return.rs:39:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:46:9 + --> tests/ui/no_effect_return.rs:50:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:54:9 + --> tests/ui/no_effect_return.rs:59:9 | LL | [1u16]; | -^^^^^^ @@ -46,7 +46,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:62:9 + --> tests/ui/no_effect_return.rs:68:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:80:9 + --> tests/ui/no_effect_return.rs:87:9 | LL | (); | ^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:89:9 + --> tests/ui/no_effect_return.rs:97:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index 8be149d18637..99b731d4a597 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -4,28 +4,27 @@ #[unsafe(no_mangle)] fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} -//~^ ERROR: `#[unsafe(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_with_rust_abi #[unsafe(no_mangle)] pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} -//~^ ERROR: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI +//~^ no_mangle_with_rust_abi /// # Safety /// This function shouldn't be called unless the horsemen are ready #[unsafe(no_mangle)] pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} -//~^ ERROR: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI +//~^ no_mangle_with_rust_abi /// # Safety /// This function shouldn't be called unless the horsemen are ready #[unsafe(no_mangle)] unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} -//~^ ERROR: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI +//~^ no_mangle_with_rust_abi #[unsafe(no_mangle)] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( - //~^ ERROR: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI +//~^ no_mangle_with_rust_abi arg_one: u32, arg_two: usize, ) -> u32 { @@ -51,6 +50,7 @@ extern "C" { mod r#fn { #[unsafe(no_mangle)] pub(in super::r#fn) fn with_some_fn_around() {} + //~^ no_mangle_with_rust_abi } fn main() { diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index a00ebe5e1ac7..871f38e94b63 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -16,7 +16,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:11:1 + --> tests/ui/no_mangle_with_rust_abi.rs:10:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:17:1 + --> tests/ui/no_mangle_with_rust_abi.rs:16:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:23:1 + --> tests/ui/no_mangle_with_rust_abi.rs:22:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:27:1 + --> tests/ui/no_mangle_with_rust_abi.rs:26:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( LL | | @@ -80,7 +80,7 @@ LL | extern "Rust" fn rust_abi_multiline_function_really_long_name_to_overflow_a | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:53:5 + --> tests/ui/no_mangle_with_rust_abi.rs:52:5 | LL | pub(in super::r#fn) fn with_some_fn_around() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_mangle_with_rust_abi_2021.rs b/tests/ui/no_mangle_with_rust_abi_2021.rs index c7c973353480..eba653889064 100644 --- a/tests/ui/no_mangle_with_rust_abi_2021.rs +++ b/tests/ui/no_mangle_with_rust_abi_2021.rs @@ -8,28 +8,27 @@ #[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_with_rust_abi #[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 +//~^ no_mangle_with_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 +//~^ no_mangle_with_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_with_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 +//~^ no_mangle_with_rust_abi arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/tests/ui/no_mangle_with_rust_abi_2021.stderr b/tests/ui/no_mangle_with_rust_abi_2021.stderr index 15075be72d0b..abae8fafbeee 100644 --- a/tests/ui/no_mangle_with_rust_abi_2021.stderr +++ b/tests/ui/no_mangle_with_rust_abi_2021.stderr @@ -16,7 +16,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:15:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:14:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:21:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:20:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:27:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:26:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:31:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:30:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( LL | | diff --git a/tests/ui/non_canonical_clone_impl.rs b/tests/ui/non_canonical_clone_impl.rs index a36c7ed44c24..d735122e1845 100644 --- a/tests/ui/non_canonical_clone_impl.rs +++ b/tests/ui/non_canonical_clone_impl.rs @@ -12,10 +12,12 @@ struct A(u32); impl Clone for A { fn clone(&self) -> Self { + //~^ non_canonical_clone_impl Self(self.0) } fn clone_from(&mut self, source: &Self) { + //~^ non_canonical_clone_impl source.clone(); *self = source.clone(); } @@ -83,10 +85,12 @@ struct F(u32); impl Clone for F { fn clone(&self) -> Self { + //~^ non_canonical_clone_impl Self(self.0) } fn clone_from(&mut self, source: &Self) { + //~^ non_canonical_clone_impl source.clone(); *self = source.clone(); } diff --git a/tests/ui/non_canonical_clone_impl.stderr b/tests/ui/non_canonical_clone_impl.stderr index f7cad58150f7..550098452717 100644 --- a/tests/ui/non_canonical_clone_impl.stderr +++ b/tests/ui/non_canonical_clone_impl.stderr @@ -3,6 +3,7 @@ error: non-canonical implementation of `clone` on a `Copy` type | LL | fn clone(&self) -> Self { | _____________________________^ +LL | | LL | | Self(self.0) LL | | } | |_____^ help: change this to: `{ *self }` @@ -11,27 +12,30 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_clone_impl)]` error: unnecessary implementation of `clone_from` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:18:5 + --> tests/ui/non_canonical_clone_impl.rs:19:5 | LL | / fn clone_from(&mut self, source: &Self) { +LL | | LL | | source.clone(); LL | | *self = source.clone(); LL | | } | |_____^ help: remove it error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:85:29 + --> tests/ui/non_canonical_clone_impl.rs:87:29 | LL | fn clone(&self) -> Self { | _____________________________^ +LL | | LL | | Self(self.0) LL | | } | |_____^ help: change this to: `{ *self }` error: unnecessary implementation of `clone_from` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:89:5 + --> tests/ui/non_canonical_clone_impl.rs:92:5 | LL | / fn clone_from(&mut self, source: &Self) { +LL | | LL | | source.clone(); LL | | *self = source.clone(); LL | | } diff --git a/tests/ui/non_canonical_partial_ord_impl.fixed b/tests/ui/non_canonical_partial_ord_impl.fixed index d444a753697f..7d1211522f18 100644 --- a/tests/ui/non_canonical_partial_ord_impl.fixed +++ b/tests/ui/non_canonical_partial_ord_impl.fixed @@ -14,6 +14,7 @@ impl Ord for A { } impl PartialOrd for A { +//~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } @@ -46,6 +47,7 @@ impl Ord for C { } impl PartialOrd for C { +//~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } diff --git a/tests/ui/non_canonical_partial_ord_impl.rs b/tests/ui/non_canonical_partial_ord_impl.rs index dc6c4354604d..4f3310557992 100644 --- a/tests/ui/non_canonical_partial_ord_impl.rs +++ b/tests/ui/non_canonical_partial_ord_impl.rs @@ -14,6 +14,7 @@ impl Ord for A { } impl PartialOrd for A { +//~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { todo!(); } @@ -48,6 +49,7 @@ impl Ord for C { } impl PartialOrd for C { +//~^ non_canonical_partial_ord_impl fn partial_cmp(&self, _: &Self) -> Option { todo!(); } diff --git a/tests/ui/non_canonical_partial_ord_impl.stderr b/tests/ui/non_canonical_partial_ord_impl.stderr index a15379c5b1a5..12e6bdc7addc 100644 --- a/tests/ui/non_canonical_partial_ord_impl.stderr +++ b/tests/ui/non_canonical_partial_ord_impl.stderr @@ -2,6 +2,7 @@ error: non-canonical implementation of `partial_cmp` on an `Ord` type --> tests/ui/non_canonical_partial_ord_impl.rs:16:1 | LL | / impl PartialOrd for A { +LL | | LL | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- LL | || todo!(); @@ -14,9 +15,10 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]` error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:50:1 + --> tests/ui/non_canonical_partial_ord_impl.rs:51:1 | LL | / impl PartialOrd for C { +LL | | LL | | fn partial_cmp(&self, _: &Self) -> Option { LL | | todo!(); LL | | } diff --git a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs index 2f8d5cf30c77..cbd1ae57be4a 100644 --- a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs +++ b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs @@ -21,6 +21,7 @@ impl cmp::Ord for A { } impl PartialOrd for A { +//~^ non_canonical_partial_ord_impl 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 +45,7 @@ impl cmp::Ord for B { } impl PartialOrd for B { +//~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { // This calls `B.cmp`, not `Ord::cmp`! Some(self.cmp(other)) diff --git a/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr b/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr index 8dd7face6ef4..392b81dc8d74 100644 --- a/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr +++ b/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr @@ -2,6 +2,7 @@ error: non-canonical implementation of `partial_cmp` on an `Ord` type --> tests/ui/non_canonical_partial_ord_impl_fully_qual.rs:23:1 | LL | / impl PartialOrd for A { +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 @@ -16,9 +17,10 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_partial_ord_impl)]` error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl_fully_qual.rs:46:1 + --> tests/ui/non_canonical_partial_ord_impl_fully_qual.rs:47: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/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index 987a4775ef07..69e90c3d670b 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -25,9 +25,12 @@ impl MaybeInst { } fn underscores_and_numbers() { - let _1 = 1; //~ERROR: consider choosing a more descriptive name - let ____1 = 1; //~ERROR: consider choosing a more descriptive name - let __1___2 = 12; //~ERROR: consider choosing a more descriptive name +let _1 = 1; +//~^ just_underscores_and_digits +let ____1 = 1; +//~^ just_underscores_and_digits +let __1___2 = 12; +//~^ just_underscores_and_digits let _1_ok = 1; } @@ -48,9 +51,12 @@ struct Bar; impl Bar { fn bar() { - let _1 = 1; //~ERROR: consider choosing a more descriptive name - let ____1 = 1; //~ERROR: consider choosing a more descriptive name - let __1___2 = 12; //~ERROR: consider choosing a more descriptive name +let _1 = 1; +//~^ just_underscores_and_digits +let ____1 = 1; +//~^ just_underscores_and_digits +let __1___2 = 12; +//~^ just_underscores_and_digits let _1_ok = 1; } } diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index d9c745f466b7..7aa67e1ca415 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -1,41 +1,41 @@ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:28:9 + --> tests/ui/non_expressive_names.rs:28:5 | -LL | let _1 = 1; - | ^^ +LL | let _1 = 1; + | ^^ | = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::just_underscores_and_digits)]` error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:29:9 + --> tests/ui/non_expressive_names.rs:30:5 | -LL | let ____1 = 1; - | ^^^^^ +LL | let ____1 = 1; + | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:30:9 + --> tests/ui/non_expressive_names.rs:32:5 | -LL | let __1___2 = 12; - | ^^^^^^^ +LL | let __1___2 = 12; + | ^^^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:51:13 + --> tests/ui/non_expressive_names.rs:54:5 | -LL | let _1 = 1; - | ^^ +LL | let _1 = 1; + | ^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:52:13 + --> tests/ui/non_expressive_names.rs:56:5 | -LL | let ____1 = 1; - | ^^^^^ +LL | let ____1 = 1; + | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:53:13 + --> tests/ui/non_expressive_names.rs:58:5 | -LL | let __1___2 = 12; - | ^^^^^^^ +LL | let __1___2 = 12; + | ^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/non_minimal_cfg.fixed b/tests/ui/non_minimal_cfg.fixed index 2fcecab452b8..a2b69d0662ee 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -1,12 +1,16 @@ #![allow(unused)] #[cfg(windows)] +//~^ non_minimal_cfg fn hermit() {} #[cfg(windows)] +//~^ non_minimal_cfg fn wasi() {} #[cfg(all(unix, not(windows)))] +//~^ non_minimal_cfg +//~| non_minimal_cfg fn the_end() {} #[cfg(any())] diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index e3ce11b73336..7178cd189c08 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -1,12 +1,16 @@ #![allow(unused)] #[cfg(all(windows))] +//~^ non_minimal_cfg fn hermit() {} #[cfg(any(windows))] +//~^ non_minimal_cfg fn wasi() {} #[cfg(all(any(unix), all(not(windows))))] +//~^ non_minimal_cfg +//~| non_minimal_cfg fn the_end() {} #[cfg(any())] diff --git a/tests/ui/non_minimal_cfg.stderr b/tests/ui/non_minimal_cfg.stderr index 707ff51d430c..3bf306dd89c2 100644 --- a/tests/ui/non_minimal_cfg.stderr +++ b/tests/ui/non_minimal_cfg.stderr @@ -8,19 +8,19 @@ LL | #[cfg(all(windows))] = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:6:7 + --> tests/ui/non_minimal_cfg.rs:7:7 | LL | #[cfg(any(windows))] | ^^^^^^^^^^^^ help: try: `windows` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:9:11 + --> tests/ui/non_minimal_cfg.rs:11:11 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^ help: try: `unix` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:9:22 + --> tests/ui/non_minimal_cfg.rs:11:22 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)` diff --git a/tests/ui/non_minimal_cfg2.rs b/tests/ui/non_minimal_cfg2.rs index f9e3ba4dacda..d073feedb1da 100644 --- a/tests/ui/non_minimal_cfg2.rs +++ b/tests/ui/non_minimal_cfg2.rs @@ -1,3 +1,4 @@ +//@require-annotations-for-level: WARN #![allow(unused)] #[cfg(all())] diff --git a/tests/ui/non_minimal_cfg2.stderr b/tests/ui/non_minimal_cfg2.stderr index 6d86e931edce..169d2989aa13 100644 --- a/tests/ui/non_minimal_cfg2.stderr +++ b/tests/ui/non_minimal_cfg2.stderr @@ -1,5 +1,5 @@ error: unneeded sub `cfg` when there is no condition - --> tests/ui/non_minimal_cfg2.rs:3:7 + --> tests/ui/non_minimal_cfg2.rs:4:7 | LL | #[cfg(all())] | ^^^^^ diff --git a/tests/ui/non_octal_unix_permissions.fixed b/tests/ui/non_octal_unix_permissions.fixed index f68d5e30d27e..83f8991c94f8 100644 --- a/tests/ui/non_octal_unix_permissions.fixed +++ b/tests/ui/non_octal_unix_permissions.fixed @@ -10,11 +10,13 @@ fn main() { // OpenOptionsExt::mode let mut options = OpenOptions::new(); options.mode(0o440); + //~^ non_octal_unix_permissions options.mode(0o400); options.mode(permissions); // PermissionsExt::from_mode let _permissions = Permissions::from_mode(0o647); + //~^ non_octal_unix_permissions let _permissions = Permissions::from_mode(0o000); let _permissions = Permissions::from_mode(permissions); @@ -24,6 +26,7 @@ fn main() { let mut permissions = metadata.permissions(); permissions.set_mode(0o644); + //~^ non_octal_unix_permissions permissions.set_mode(0o704); // no error permissions.set_mode(0b111_000_100); @@ -31,6 +34,7 @@ fn main() { // DirBuilderExt::mode let mut builder = DirBuilder::new(); builder.mode(0o755); + //~^ non_octal_unix_permissions builder.mode(0o406); // no error permissions.set_mode(0b111000100); diff --git a/tests/ui/non_octal_unix_permissions.rs b/tests/ui/non_octal_unix_permissions.rs index 647c3769d2c3..ba1ee10a2787 100644 --- a/tests/ui/non_octal_unix_permissions.rs +++ b/tests/ui/non_octal_unix_permissions.rs @@ -10,11 +10,13 @@ fn main() { // OpenOptionsExt::mode let mut options = OpenOptions::new(); options.mode(440); + //~^ non_octal_unix_permissions options.mode(0o400); options.mode(permissions); // PermissionsExt::from_mode let _permissions = Permissions::from_mode(647); + //~^ non_octal_unix_permissions let _permissions = Permissions::from_mode(0o000); let _permissions = Permissions::from_mode(permissions); @@ -24,6 +26,7 @@ fn main() { let mut permissions = metadata.permissions(); permissions.set_mode(644); + //~^ non_octal_unix_permissions permissions.set_mode(0o704); // no error permissions.set_mode(0b111_000_100); @@ -31,6 +34,7 @@ fn main() { // DirBuilderExt::mode let mut builder = DirBuilder::new(); builder.mode(755); + //~^ non_octal_unix_permissions builder.mode(0o406); // no error permissions.set_mode(0b111000100); diff --git a/tests/ui/non_octal_unix_permissions.stderr b/tests/ui/non_octal_unix_permissions.stderr index 890b308a1dc5..9027617c813a 100644 --- a/tests/ui/non_octal_unix_permissions.stderr +++ b/tests/ui/non_octal_unix_permissions.stderr @@ -8,19 +8,19 @@ LL | options.mode(440); = help: to override `-D warnings` add `#[allow(clippy::non_octal_unix_permissions)]` error: using a non-octal value to set unix file permissions - --> tests/ui/non_octal_unix_permissions.rs:17:47 + --> tests/ui/non_octal_unix_permissions.rs:18:47 | LL | let _permissions = Permissions::from_mode(647); | ^^^ help: consider using an octal literal instead: `0o647` error: using a non-octal value to set unix file permissions - --> tests/ui/non_octal_unix_permissions.rs:26:26 + --> tests/ui/non_octal_unix_permissions.rs:28:26 | LL | permissions.set_mode(644); | ^^^ help: consider using an octal literal instead: `0o644` error: using a non-octal value to set unix file permissions - --> tests/ui/non_octal_unix_permissions.rs:33:18 + --> tests/ui/non_octal_unix_permissions.rs:36:18 | LL | builder.mode(755); | ^^^ help: consider using an octal literal instead: `0o755` diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_no_std.rs b/tests/ui/non_std_lazy_static/non_std_lazy_static_no_std.rs index 6208612c6983..1170696b2030 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_no_std.rs +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_no_std.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:once_cell.rs //@aux-build:lazy_static.rs diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs b/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs index 8701a4b7729a..f6d4f7250915 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs @@ -1,3 +1,4 @@ +//@ check-pass //@aux-build:once_cell.rs #![warn(clippy::non_std_lazy_statics)] diff --git a/tests/ui/non_zero_suggestions.fixed b/tests/ui/non_zero_suggestions.fixed index e67c992fdde0..1459832be75e 100644 --- a/tests/ui/non_zero_suggestions.fixed +++ b/tests/ui/non_zero_suggestions.fixed @@ -7,19 +7,23 @@ fn main() { let x: u64 = 100; let y = NonZeroU32::new(10).unwrap(); let r1 = x / NonZeroU64::from(y); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + let r2 = x % NonZeroU64::from(y); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + // U16 -> U32 let a: u32 = 50; let b = NonZeroU16::new(5).unwrap(); let r3 = a / NonZeroU32::from(b); - //~^ ERROR: consider using `NonZeroU32::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + let x = NonZeroU64::from(NonZeroU32::new(5).unwrap()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + /// Negative test cases (lint should not trigger) // Left hand side expressions should not be triggered @@ -50,7 +54,8 @@ fn main() { // Additional function to test the lint in a different context fn divide_numbers(x: u64, y: NonZeroU32) -> u64 { x / NonZeroU64::from(y) - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + } struct Calculator { @@ -60,6 +65,7 @@ struct Calculator { impl Calculator { fn divide(&self, divisor: NonZeroU32) -> u64 { self.value / NonZeroU64::from(divisor) - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + } } diff --git a/tests/ui/non_zero_suggestions.rs b/tests/ui/non_zero_suggestions.rs index de82371a8f29..72a38131a132 100644 --- a/tests/ui/non_zero_suggestions.rs +++ b/tests/ui/non_zero_suggestions.rs @@ -7,19 +7,23 @@ fn main() { let x: u64 = 100; let y = NonZeroU32::new(10).unwrap(); let r1 = x / u64::from(y.get()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + let r2 = x % u64::from(y.get()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + // U16 -> U32 let a: u32 = 50; let b = NonZeroU16::new(5).unwrap(); let r3 = a / u32::from(b.get()); - //~^ ERROR: consider using `NonZeroU32::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + let x = u64::from(NonZeroU32::new(5).unwrap().get()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + /// Negative test cases (lint should not trigger) // Left hand side expressions should not be triggered @@ -50,7 +54,8 @@ fn main() { // Additional function to test the lint in a different context fn divide_numbers(x: u64, y: NonZeroU32) -> u64 { x / u64::from(y.get()) - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + } struct Calculator { @@ -60,6 +65,7 @@ struct Calculator { impl Calculator { fn divide(&self, divisor: NonZeroU32) -> u64 { self.value / u64::from(divisor.get()) - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + } } diff --git a/tests/ui/non_zero_suggestions.stderr b/tests/ui/non_zero_suggestions.stderr index 7a57f7983be7..f7ed71dcf56c 100644 --- a/tests/ui/non_zero_suggestions.stderr +++ b/tests/ui/non_zero_suggestions.stderr @@ -8,31 +8,31 @@ LL | let r1 = x / u64::from(y.get()); = help: to override `-D warnings` add `#[allow(clippy::non_zero_suggestions)]` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:12:18 + --> tests/ui/non_zero_suggestions.rs:13:18 | LL | let r2 = x % u64::from(y.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` error: consider using `NonZeroU32::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:18:18 + --> tests/ui/non_zero_suggestions.rs:20:18 | LL | let r3 = a / u32::from(b.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU32::from(b)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:21:13 + --> tests/ui/non_zero_suggestions.rs:24:13 | LL | let x = u64::from(NonZeroU32::new(5).unwrap().get()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(NonZeroU32::new(5).unwrap())` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:52:9 + --> tests/ui/non_zero_suggestions.rs:56:9 | LL | x / u64::from(y.get()) | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:62:22 + --> tests/ui/non_zero_suggestions.rs:67:22 | LL | self.value / u64::from(divisor.get()) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(divisor)` diff --git a/tests/ui/non_zero_suggestions_unfixable.rs b/tests/ui/non_zero_suggestions_unfixable.rs index 193c710e589f..4adbdf7bcc74 100644 --- a/tests/ui/non_zero_suggestions_unfixable.rs +++ b/tests/ui/non_zero_suggestions_unfixable.rs @@ -4,11 +4,13 @@ use std::num::{NonZeroI8, NonZeroI16, NonZeroU8, NonZeroU16, NonZeroU32, NonZero fn main() { let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + let n = NonZeroU32::new(20).unwrap(); let y = u64::from(n.get()); - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + some_fn_that_only_takes_u64(y); let m = NonZeroU32::try_from(1).unwrap(); @@ -17,7 +19,8 @@ fn main() { fn return_non_zero(x: u64, y: NonZeroU32) -> u64 { u64::from(y.get()) - //~^ ERROR: consider using `NonZeroU64::from()` for more efficient and type-safe conversion + //~^ non_zero_suggestions + } fn some_fn_that_only_takes_u64(_: u64) {} diff --git a/tests/ui/non_zero_suggestions_unfixable.stderr b/tests/ui/non_zero_suggestions_unfixable.stderr index 787179f2a2d6..dff70dada26d 100644 --- a/tests/ui/non_zero_suggestions_unfixable.stderr +++ b/tests/ui/non_zero_suggestions_unfixable.stderr @@ -8,13 +8,13 @@ LL | let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); = help: to override `-D warnings` add `#[allow(clippy::non_zero_suggestions)]` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions_unfixable.rs:10:13 + --> tests/ui/non_zero_suggestions_unfixable.rs:11:13 | LL | let y = u64::from(n.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(n)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions_unfixable.rs:19:5 + --> tests/ui/non_zero_suggestions_unfixable.rs:21:5 | LL | u64::from(y.get()) | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 9d0a475064ed..1d41b2b9a84c 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -15,23 +15,30 @@ 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` + //~^ nonminimal_bool + + let _ = !false; - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = !!a; - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = false || a; - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + // 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 + //~^ nonminimal_bool + let _ = !(!a || b); - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = !a && !(b && c); - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + } fn equality_stuff() { @@ -40,15 +47,20 @@ 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 + //~^ nonminimal_bool + let _ = a == b || c == 5 || a == b; - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = a == b && c == 5 && b == a; - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = a != b || !(a != b || c == d); - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + let _ = a != b && !(a != b && c == d); - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + } fn issue3847(a: u32, b: u32) -> bool { @@ -79,7 +91,8 @@ fn check_expect() { fn issue9428() { if matches!(true, true) && true { - //~^ ERROR: this boolean expression can be simplified + //~^ nonminimal_bool + println!("foo"); } } @@ -158,19 +171,35 @@ fn issue11932() { fn issue_5794() { let a = 0; - if !(12 == a) {} //~ ERROR: this boolean expression can be simplified - if !(a == 12) {} //~ ERROR: this boolean expression can be simplified - if !(12 != a) {} //~ ERROR: this boolean expression can be simplified - if !(a != 12) {} //~ ERROR: this boolean expression can be simplified +if !(12 == a) {} +//~^ nonminimal_bool +if !(a == 12) {} +//~^ nonminimal_bool +if !(12 != a) {} +//~^ nonminimal_bool +if !(a != 12) {} +//~^ nonminimal_bool let b = true; let c = false; - if !b == true {} //~ ERROR: this boolean expression can be simplified - if !b != true {} //~ ERROR: this boolean expression can be simplified - if true == !b {} //~ ERROR: this boolean expression can be simplified - if true != !b {} //~ ERROR: this boolean expression can be simplified - if !b == !c {} //~ ERROR: this boolean expression can be simplified - if !b != !c {} //~ ERROR: this boolean expression can be simplified +if !b == true {} +//~^ nonminimal_bool +//~| bool_comparison +//~| bool_comparison +if !b != true {} +//~^ nonminimal_bool +//~| bool_comparison +if true == !b {} +//~^ nonminimal_bool +//~| bool_comparison +//~| bool_comparison +if true != !b {} +//~^ nonminimal_bool +//~| bool_comparison +if !b == !c {} +//~^ nonminimal_bool +if !b != !c {} +//~^ nonminimal_bool } fn issue_12371(x: usize) -> bool { @@ -186,6 +215,7 @@ fn many_ops(a: bool, b: bool, c: bool, d: bool, e: bool, f: bool) -> bool { fn issue14184(a: f32, b: bool) { if !(a < 2.0 && !b) { + //~^ nonminimal_bool println!("Hi"); } } diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 129dadf315e4..ca2c7ab8232a 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -8,43 +8,43 @@ LL | let _ = !true; = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:20:13 + --> tests/ui/nonminimal_bool.rs:21:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:22:13 + --> tests/ui/nonminimal_bool.rs:24:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:24:13 + --> tests/ui/nonminimal_bool.rs:27:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:29:13 + --> tests/ui/nonminimal_bool.rs:33:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:31:13 + --> tests/ui/nonminimal_bool.rs:36:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:33:13 + --> tests/ui/nonminimal_bool.rs:39:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:42:13 + --> tests/ui/nonminimal_bool.rs:49:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:44:13 + --> tests/ui/nonminimal_bool.rs:52:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:46:13 + --> tests/ui/nonminimal_bool.rs:55:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:48:13 + --> tests/ui/nonminimal_bool.rs:58:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:50:13 + --> tests/ui/nonminimal_bool.rs:61:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,112 +109,112 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:81:8 + --> tests/ui/nonminimal_bool.rs:93:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:161:8 + --> tests/ui/nonminimal_bool.rs:174:4 | -LL | if !(12 == a) {} - | ^^^^^^^^^^ help: try: `(12 != a)` +LL | if !(12 == a) {} + | ^^^^^^^^^^ help: try: `(12 != a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:162:8 + --> tests/ui/nonminimal_bool.rs:176:4 | -LL | if !(a == 12) {} - | ^^^^^^^^^^ help: try: `(a != 12)` +LL | if !(a == 12) {} + | ^^^^^^^^^^ help: try: `(a != 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:163:8 + --> tests/ui/nonminimal_bool.rs:178:4 | -LL | if !(12 != a) {} - | ^^^^^^^^^^ help: try: `(12 == a)` +LL | if !(12 != a) {} + | ^^^^^^^^^^ help: try: `(12 == a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:164:8 + --> tests/ui/nonminimal_bool.rs:180:4 | -LL | if !(a != 12) {} - | ^^^^^^^^^^ help: try: `(a == 12)` +LL | if !(a != 12) {} + | ^^^^^^^^^^ help: try: `(a == 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:168:8 + --> tests/ui/nonminimal_bool.rs:185:4 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try: `b != true` +LL | if !b == true {} + | ^^^^^^^^^^ help: try: `b != true` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:168:8 + --> tests/ui/nonminimal_bool.rs:185:4 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` +LL | if !b == true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` | = note: `-D clippy::bool-comparison` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:168:8 + --> tests/ui/nonminimal_bool.rs:185:4 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!b` +LL | if !b == true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:169:8 + --> tests/ui/nonminimal_bool.rs:189:4 | -LL | if !b != true {} - | ^^^^^^^^^^ help: try: `b == true` +LL | if !b != true {} + | ^^^^^^^^^^ help: try: `b == true` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:169:8 + --> tests/ui/nonminimal_bool.rs:189:4 | -LL | if !b != true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` +LL | if !b != true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:192:4 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try: `true != b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try: `true != b` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:192:4 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:170:8 + --> tests/ui/nonminimal_bool.rs:192:4 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:171:8 + --> tests/ui/nonminimal_bool.rs:196:4 | -LL | if true != !b {} - | ^^^^^^^^^^ help: try: `true == b` +LL | if true != !b {} + | ^^^^^^^^^^ help: try: `true == b` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:171:8 + --> tests/ui/nonminimal_bool.rs:196:4 | -LL | if true != !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` +LL | if true != !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:172:8 + --> tests/ui/nonminimal_bool.rs:199:4 | -LL | if !b == !c {} - | ^^^^^^^^ help: try: `b == c` +LL | if !b == !c {} + | ^^^^^^^^ help: try: `b == c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:173:8 + --> tests/ui/nonminimal_bool.rs:201:4 | -LL | if !b != !c {} - | ^^^^^^^^ help: try: `b != c` +LL | if !b != !c {} + | ^^^^^^^^ help: try: `b != c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:188:8 + --> tests/ui/nonminimal_bool.rs:217:8 | LL | if !(a < 2.0 && !b) { | ^^^^^^^^^^^^^^^^ help: try: `!(a < 2.0) || b` diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index 65ccaaca8918..4b11dc2b5dda 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -6,18 +6,27 @@ fn methods_with_negation() { let b: Result = unimplemented!(); let _ = a.is_some(); let _ = a.is_none(); + //~^ nonminimal_bool let _ = a.is_none(); let _ = a.is_some(); + //~^ nonminimal_bool let _ = b.is_err(); let _ = b.is_ok(); + //~^ nonminimal_bool let _ = b.is_ok(); let _ = b.is_err(); + //~^ nonminimal_bool let c = false; let _ = a.is_none() || c; + //~^ nonminimal_bool let _ = a.is_none() && c; + //~^ nonminimal_bool let _ = !(!c ^ c) || a.is_none(); + //~^ nonminimal_bool let _ = (!c ^ c) || a.is_none(); + //~^ nonminimal_bool let _ = !c ^ c || a.is_none(); + //~^ nonminimal_bool } // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 @@ -90,11 +99,15 @@ fn dont_warn_for_custom_methods_with_negation() { fn warn_for_built_in_methods_with_negation() { let res: Result = Ok(1); if res.is_err() {} + //~^ nonminimal_bool if res.is_ok() {} + //~^ nonminimal_bool let res = Some(1); if res.is_none() {} + //~^ nonminimal_bool if res.is_some() {} + //~^ nonminimal_bool } #[allow(clippy::neg_cmp_op_on_partial_ord)] @@ -110,24 +123,34 @@ fn dont_warn_for_negated_partial_ord_comparison() { fn issue_12625() { let a = 0; let b = 0; - if ((a as u64) < b) {} //~ ERROR: this boolean expression can be simplified - if ((a as u64) < b) {} //~ ERROR: this boolean expression can be simplified - if (a as u64 > b) {} //~ ERROR: this boolean expression can be simplified +if ((a as u64) < b) {} +//~^ nonminimal_bool +if ((a as u64) < b) {} +//~^ nonminimal_bool +if (a as u64 > b) {} +//~^ nonminimal_bool } fn issue_12761() { let a = 0; let b = 0; let c = 0; - if (a < b) as i32 == c {} //~ ERROR: this boolean expression can be simplified - if (a < b) | (a > c) {} //~ ERROR: this boolean expression can be simplified +if (a < b) as i32 == c {} +//~^ nonminimal_bool +if (a < b) | (a > c) {} +//~^ nonminimal_bool +//~| nonminimal_bool let opt: Option = Some(1); let res: Result = Ok(1); - if res.is_err() as i32 == c {} //~ ERROR: this boolean expression can be simplified - if res.is_err() | opt.is_some() {} //~ ERROR: this boolean expression can be simplified +if res.is_err() as i32 == c {} +//~^ nonminimal_bool +if res.is_err() | opt.is_some() {} +//~^ nonminimal_bool +//~| nonminimal_bool fn a(a: bool) -> bool { - (4 <= 3).b() //~ ERROR: this boolean expression can be simplified +(4 <= 3).b() +//~^ nonminimal_bool } trait B { @@ -152,12 +175,18 @@ fn issue_13436() { _ = opt.is_some_and(|x| x == 1000); _ = opt.is_some_and(|x| x != 1000); _ = opt.is_some_and(not_zero); - _ = opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified +_ = opt.is_none_or(|x| x >= 1000); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x > 1000); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x <= 1000); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x < 1000); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x != 1000); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x == 1000); +//~^ nonminimal_bool _ = !opt.is_some_and(not_zero); _ = opt.is_none_or(|x| x < 1000); _ = opt.is_none_or(|x| x <= 1000); @@ -166,33 +195,45 @@ fn issue_13436() { _ = opt.is_none_or(|x| x == 1000); _ = opt.is_none_or(|x| x != 1000); _ = opt.is_none_or(not_zero); - _ = opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified +_ = opt.is_some_and(|x| x >= 1000); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x > 1000); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x <= 1000); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x < 1000); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x != 1000); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x == 1000); +//~^ nonminimal_bool _ = !opt.is_none_or(not_zero); let opt = Some(true); _ = opt.is_some_and(|x| x); _ = opt.is_some_and(|x| !x); _ = !opt.is_some_and(|x| x); - _ = opt.is_none_or(|x| x); //~ ERROR: this boolean expression can be simplified +_ = opt.is_none_or(|x| x); +//~^ nonminimal_bool _ = opt.is_none_or(|x| x); _ = opt.is_none_or(|x| !x); _ = !opt.is_none_or(|x| x); - _ = opt.is_some_and(|x| x); //~ ERROR: this boolean expression can be simplified +_ = opt.is_some_and(|x| x); +//~^ nonminimal_bool let opt: Option> = Some(Ok(123)); _ = opt.is_some_and(|x| x.is_ok()); _ = opt.is_some_and(|x| x.is_err()); _ = opt.is_none_or(|x| x.is_ok()); _ = opt.is_none_or(|x| x.is_err()); - _ = opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified - _ = opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified - _ = opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified +_ = opt.is_none_or(|x| x.is_err()); +//~^ nonminimal_bool +_ = opt.is_none_or(|x| x.is_ok()); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x.is_err()); +//~^ nonminimal_bool +_ = opt.is_some_and(|x| x.is_ok()); +//~^ nonminimal_bool #[clippy::msrv = "1.81"] fn before_stabilization() { diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index 06db3a1d4a5c..3e574de2d156 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -6,18 +6,27 @@ fn methods_with_negation() { let b: Result = unimplemented!(); let _ = a.is_some(); let _ = !a.is_some(); + //~^ nonminimal_bool let _ = a.is_none(); let _ = !a.is_none(); + //~^ nonminimal_bool let _ = b.is_err(); let _ = !b.is_err(); + //~^ nonminimal_bool let _ = b.is_ok(); let _ = !b.is_ok(); + //~^ nonminimal_bool let c = false; let _ = !(a.is_some() && !c); + //~^ nonminimal_bool let _ = !(a.is_some() || !c); + //~^ nonminimal_bool let _ = !(!c ^ c) || !a.is_some(); + //~^ nonminimal_bool let _ = (!c ^ c) || !a.is_some(); + //~^ nonminimal_bool let _ = !c ^ c || !a.is_some(); + //~^ nonminimal_bool } // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638 @@ -90,11 +99,15 @@ fn dont_warn_for_custom_methods_with_negation() { fn warn_for_built_in_methods_with_negation() { let res: Result = Ok(1); if !res.is_ok() {} + //~^ nonminimal_bool if !res.is_err() {} + //~^ nonminimal_bool let res = Some(1); if !res.is_some() {} + //~^ nonminimal_bool if !res.is_none() {} + //~^ nonminimal_bool } #[allow(clippy::neg_cmp_op_on_partial_ord)] @@ -110,24 +123,34 @@ fn dont_warn_for_negated_partial_ord_comparison() { fn issue_12625() { let a = 0; let b = 0; - if !(a as u64 >= b) {} //~ ERROR: this boolean expression can be simplified - if !((a as u64) >= b) {} //~ ERROR: this boolean expression can be simplified - if !(a as u64 <= b) {} //~ ERROR: this boolean expression can be simplified +if !(a as u64 >= b) {} +//~^ nonminimal_bool +if !((a as u64) >= b) {} +//~^ nonminimal_bool +if !(a as u64 <= b) {} +//~^ nonminimal_bool } fn issue_12761() { let a = 0; let b = 0; let c = 0; - if !(a >= b) as i32 == c {} //~ ERROR: this boolean expression can be simplified - if !(a >= b) | !(a <= c) {} //~ ERROR: this boolean expression can be simplified +if !(a >= b) as i32 == c {} +//~^ nonminimal_bool +if !(a >= b) | !(a <= c) {} +//~^ nonminimal_bool +//~| nonminimal_bool let opt: Option = Some(1); let res: Result = Ok(1); - if !res.is_ok() as i32 == c {} //~ ERROR: this boolean expression can be simplified - if !res.is_ok() | !opt.is_none() {} //~ ERROR: this boolean expression can be simplified +if !res.is_ok() as i32 == c {} +//~^ nonminimal_bool +if !res.is_ok() | !opt.is_none() {} +//~^ nonminimal_bool +//~| nonminimal_bool fn a(a: bool) -> bool { - (!(4 > 3)).b() //~ ERROR: this boolean expression can be simplified +(!(4 > 3)).b() +//~^ nonminimal_bool } trait B { @@ -152,12 +175,18 @@ fn issue_13436() { _ = opt.is_some_and(|x| x == 1000); _ = opt.is_some_and(|x| x != 1000); _ = opt.is_some_and(not_zero); - _ = !opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified +_ = !opt.is_some_and(|x| x < 1000); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x <= 1000); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x > 1000); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x >= 1000); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x == 1000); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x != 1000); +//~^ nonminimal_bool _ = !opt.is_some_and(not_zero); _ = opt.is_none_or(|x| x < 1000); _ = opt.is_none_or(|x| x <= 1000); @@ -166,33 +195,45 @@ fn issue_13436() { _ = opt.is_none_or(|x| x == 1000); _ = opt.is_none_or(|x| x != 1000); _ = opt.is_none_or(not_zero); - _ = !opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified +_ = !opt.is_none_or(|x| x < 1000); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x <= 1000); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x > 1000); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x >= 1000); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x == 1000); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x != 1000); +//~^ nonminimal_bool _ = !opt.is_none_or(not_zero); let opt = Some(true); _ = opt.is_some_and(|x| x); _ = opt.is_some_and(|x| !x); _ = !opt.is_some_and(|x| x); - _ = !opt.is_some_and(|x| !x); //~ ERROR: this boolean expression can be simplified +_ = !opt.is_some_and(|x| !x); +//~^ nonminimal_bool _ = opt.is_none_or(|x| x); _ = opt.is_none_or(|x| !x); _ = !opt.is_none_or(|x| x); - _ = !opt.is_none_or(|x| !x); //~ ERROR: this boolean expression can be simplified +_ = !opt.is_none_or(|x| !x); +//~^ nonminimal_bool let opt: Option> = Some(Ok(123)); _ = opt.is_some_and(|x| x.is_ok()); _ = opt.is_some_and(|x| x.is_err()); _ = opt.is_none_or(|x| x.is_ok()); _ = opt.is_none_or(|x| x.is_err()); - _ = !opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified - _ = !opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified +_ = !opt.is_some_and(|x| x.is_ok()); +//~^ nonminimal_bool +_ = !opt.is_some_and(|x| x.is_err()); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x.is_ok()); +//~^ nonminimal_bool +_ = !opt.is_none_or(|x| x.is_err()); +//~^ nonminimal_bool #[clippy::msrv = "1.81"] fn before_stabilization() { diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index 66c50f9ff1e1..3f03b8613596 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -8,244 +8,244 @@ LL | let _ = !a.is_some(); = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:10:13 + --> tests/ui/nonminimal_bool_methods.rs:11:13 | LL | let _ = !a.is_none(); | ^^^^^^^^^^^^ help: try: `a.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:12:13 + --> tests/ui/nonminimal_bool_methods.rs:14:13 | LL | let _ = !b.is_err(); | ^^^^^^^^^^^ help: try: `b.is_ok()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:14:13 + --> tests/ui/nonminimal_bool_methods.rs:17:13 | LL | let _ = !b.is_ok(); | ^^^^^^^^^^ help: try: `b.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:16:13 + --> tests/ui/nonminimal_bool_methods.rs:20:13 | LL | let _ = !(a.is_some() && !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:17:13 + --> tests/ui/nonminimal_bool_methods.rs:22:13 | LL | let _ = !(a.is_some() || !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:18:26 + --> tests/ui/nonminimal_bool_methods.rs:24:26 | LL | let _ = !(!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:19:25 + --> tests/ui/nonminimal_bool_methods.rs:26:25 | LL | let _ = (!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:20:23 + --> tests/ui/nonminimal_bool_methods.rs:28:23 | LL | let _ = !c ^ c || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:92:8 + --> tests/ui/nonminimal_bool_methods.rs:101:8 | LL | if !res.is_ok() {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:93:8 + --> tests/ui/nonminimal_bool_methods.rs:103:8 | LL | if !res.is_err() {} | ^^^^^^^^^^^^^ help: try: `res.is_ok()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:96:8 + --> tests/ui/nonminimal_bool_methods.rs:107:8 | LL | if !res.is_some() {} | ^^^^^^^^^^^^^^ help: try: `res.is_none()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:97:8 + --> tests/ui/nonminimal_bool_methods.rs:109:8 | LL | if !res.is_none() {} | ^^^^^^^^^^^^^^ help: try: `res.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:113:8 + --> tests/ui/nonminimal_bool_methods.rs:126:4 | -LL | if !(a as u64 >= b) {} - | ^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` +LL | if !(a as u64 >= b) {} + | ^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:114:8 + --> tests/ui/nonminimal_bool_methods.rs:128:4 | -LL | if !((a as u64) >= b) {} - | ^^^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` +LL | if !((a as u64) >= b) {} + | ^^^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:115:8 + --> tests/ui/nonminimal_bool_methods.rs:130:4 | -LL | if !(a as u64 <= b) {} - | ^^^^^^^^^^^^^^^^ help: try: `(a as u64 > b)` +LL | if !(a as u64 <= b) {} + | ^^^^^^^^^^^^^^^^ help: try: `(a as u64 > b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:122:8 + --> tests/ui/nonminimal_bool_methods.rs:138:4 | -LL | if !(a >= b) as i32 == c {} - | ^^^^^^^^^ help: try: `(a < b)` +LL | if !(a >= b) as i32 == c {} + | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:123:8 + --> tests/ui/nonminimal_bool_methods.rs:140:4 | -LL | if !(a >= b) | !(a <= c) {} - | ^^^^^^^^^ help: try: `(a < b)` +LL | if !(a >= b) | !(a <= c) {} + | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:123:20 + --> tests/ui/nonminimal_bool_methods.rs:140:16 | -LL | if !(a >= b) | !(a <= c) {} - | ^^^^^^^^^ help: try: `(a > c)` +LL | if !(a >= b) | !(a <= c) {} + | ^^^^^^^^^ help: try: `(a > c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:126:8 + --> tests/ui/nonminimal_bool_methods.rs:145:4 | -LL | if !res.is_ok() as i32 == c {} - | ^^^^^^^^^^^^ help: try: `res.is_err()` +LL | if !res.is_ok() as i32 == c {} + | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:127:8 + --> tests/ui/nonminimal_bool_methods.rs:147:4 | -LL | if !res.is_ok() | !opt.is_none() {} - | ^^^^^^^^^^^^ help: try: `res.is_err()` +LL | if !res.is_ok() | !opt.is_none() {} + | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:127:23 + --> tests/ui/nonminimal_bool_methods.rs:147:19 | -LL | if !res.is_ok() | !opt.is_none() {} - | ^^^^^^^^^^^^^^ help: try: `opt.is_some()` +LL | if !res.is_ok() | !opt.is_none() {} + | ^^^^^^^^^^^^^^ help: try: `opt.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:130:9 + --> tests/ui/nonminimal_bool_methods.rs:152:1 | -LL | (!(4 > 3)).b() - | ^^^^^^^^^^ help: try: `(4 <= 3)` +LL | (!(4 > 3)).b() + | ^^^^^^^^^^ help: try: `(4 <= 3)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:155:9 + --> tests/ui/nonminimal_bool_methods.rs:178:5 | -LL | _ = !opt.is_some_and(|x| x < 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` +LL | _ = !opt.is_some_and(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:156:9 + --> tests/ui/nonminimal_bool_methods.rs:180:5 | -LL | _ = !opt.is_some_and(|x| x <= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` +LL | _ = !opt.is_some_and(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:157:9 + --> tests/ui/nonminimal_bool_methods.rs:182:5 | -LL | _ = !opt.is_some_and(|x| x > 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` +LL | _ = !opt.is_some_and(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:158:9 + --> tests/ui/nonminimal_bool_methods.rs:184:5 | -LL | _ = !opt.is_some_and(|x| x >= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` +LL | _ = !opt.is_some_and(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:159:9 + --> tests/ui/nonminimal_bool_methods.rs:186:5 | -LL | _ = !opt.is_some_and(|x| x == 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` +LL | _ = !opt.is_some_and(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:160:9 + --> tests/ui/nonminimal_bool_methods.rs:188:5 | -LL | _ = !opt.is_some_and(|x| x != 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` +LL | _ = !opt.is_some_and(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:169:9 + --> tests/ui/nonminimal_bool_methods.rs:198:5 | -LL | _ = !opt.is_none_or(|x| x < 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` +LL | _ = !opt.is_none_or(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:170:9 + --> tests/ui/nonminimal_bool_methods.rs:200:5 | -LL | _ = !opt.is_none_or(|x| x <= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` +LL | _ = !opt.is_none_or(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:171:9 + --> tests/ui/nonminimal_bool_methods.rs:202:5 | -LL | _ = !opt.is_none_or(|x| x > 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` +LL | _ = !opt.is_none_or(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:172:9 + --> tests/ui/nonminimal_bool_methods.rs:204:5 | -LL | _ = !opt.is_none_or(|x| x >= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` +LL | _ = !opt.is_none_or(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:173:9 + --> tests/ui/nonminimal_bool_methods.rs:206:5 | -LL | _ = !opt.is_none_or(|x| x == 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` +LL | _ = !opt.is_none_or(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:174:9 + --> tests/ui/nonminimal_bool_methods.rs:208:5 | -LL | _ = !opt.is_none_or(|x| x != 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` +LL | _ = !opt.is_none_or(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:181:9 + --> tests/ui/nonminimal_bool_methods.rs:216:5 | -LL | _ = !opt.is_some_and(|x| !x); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` +LL | _ = !opt.is_some_and(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:185:9 + --> tests/ui/nonminimal_bool_methods.rs:221:5 | -LL | _ = !opt.is_none_or(|x| !x); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` +LL | _ = !opt.is_none_or(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:192:9 + --> tests/ui/nonminimal_bool_methods.rs:229:5 | -LL | _ = !opt.is_some_and(|x| x.is_ok()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` +LL | _ = !opt.is_some_and(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:193:9 + --> tests/ui/nonminimal_bool_methods.rs:231:5 | -LL | _ = !opt.is_some_and(|x| x.is_err()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` +LL | _ = !opt.is_some_and(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:194:9 + --> tests/ui/nonminimal_bool_methods.rs:233:5 | -LL | _ = !opt.is_none_or(|x| x.is_ok()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` +LL | _ = !opt.is_none_or(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:195:9 + --> tests/ui/nonminimal_bool_methods.rs:235:5 | -LL | _ = !opt.is_none_or(|x| x.is_err()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` +LL | _ = !opt.is_none_or(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` error: aborting due to 41 previous errors diff --git a/tests/ui/nonminimal_bool_methods_unfixable.rs b/tests/ui/nonminimal_bool_methods_unfixable.rs index 60b8da30a2f1..aba156ac8ea9 100644 --- a/tests/ui/nonminimal_bool_methods_unfixable.rs +++ b/tests/ui/nonminimal_bool_methods_unfixable.rs @@ -3,7 +3,9 @@ fn issue_13436() { let opt_opt = Some(Some(500)); - _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); //~ ERROR: this boolean expression can be simplified +_ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); +//~^ nonminimal_bool +//~| nonminimal_bool } fn main() {} diff --git a/tests/ui/nonminimal_bool_methods_unfixable.stderr b/tests/ui/nonminimal_bool_methods_unfixable.stderr index 5a90155844cd..c228bafad325 100644 --- a/tests/ui/nonminimal_bool_methods_unfixable.stderr +++ b/tests/ui/nonminimal_bool_methods_unfixable.stderr @@ -1,17 +1,17 @@ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:9 + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:5 | -LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))` +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:34 + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:30 | -LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)` +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)` error: aborting due to 2 previous errors diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 2cdbee90d52d..61a8fdddcd7d 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -3,48 +3,62 @@ fn main() { if true { "a" } else { "b" }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + if true { "a" } else { "b" }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + let a = 1; if a == 1 { "a" } else { "b" }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + if a == 1 { "a" } else { "b" }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint let mut a = 0; if true { a += 1 } else { () }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + if true { () } else { a += 2 }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + } fn issue11141() { // Parentheses are required around the left side of a binary expression let _ = (if true { 40 } else { 17 }) | 2; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are required only for the leftmost expression let _ = (if true { 30 } else { 17 }) | if true { 2 } else { 3 } | if true { 10 } else { 1 }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + //~| obfuscated_if_else + //~| obfuscated_if_else + // Parentheses are not required around the right side of a binary expression let _ = 2 | if true { 40 } else { 17 }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a cast let _ = if true { 42 } else { 17 } as u8; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a deref let _ = *if true { &42 } else { &17 }; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a deref followed by a cast let _ = *if true { &42 } else { &17 } as u8; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + } diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index 20c67e729926..0eaafe8b66ad 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -3,48 +3,62 @@ fn main() { true.then_some("a").unwrap_or("b"); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + true.then(|| "a").unwrap_or("b"); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + let a = 1; (a == 1).then_some("a").unwrap_or("b"); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + (a == 1).then(|| "a").unwrap_or("b"); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint let mut a = 0; true.then_some(a += 1).unwrap_or(()); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + true.then_some(()).unwrap_or(a += 2); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + } fn issue11141() { // Parentheses are required around the left side of a binary expression let _ = true.then_some(40).unwrap_or(17) | 2; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are required only for the leftmost expression let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + //~| obfuscated_if_else + //~| obfuscated_if_else + // Parentheses are not required around the right side of a binary expression let _ = 2 | true.then_some(40).unwrap_or(17); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a cast let _ = true.then_some(42).unwrap_or(17) as u8; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a deref let _ = *true.then_some(&42).unwrap_or(&17); - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + // Parentheses are not required for a deref followed by a cast let _ = *true.then_some(&42).unwrap_or(&17) as u8; - //~^ ERROR: this method chain can be written more clearly with `if .. else ..` + //~^ obfuscated_if_else + } diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 9b1aebb58940..2d635871950f 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -8,79 +8,79 @@ LL | true.then_some("a").unwrap_or("b"); = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:7:5 + --> tests/ui/obfuscated_if_else.rs:8:5 | LL | true.then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:11:5 + --> tests/ui/obfuscated_if_else.rs:13:5 | LL | (a == 1).then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:13:5 + --> tests/ui/obfuscated_if_else.rs:16:5 | LL | (a == 1).then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:20:5 + --> tests/ui/obfuscated_if_else.rs:24:5 | LL | true.then_some(a += 1).unwrap_or(()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:22:5 + --> tests/ui/obfuscated_if_else.rs:27:5 | LL | true.then_some(()).unwrap_or(a += 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:28:13 + --> tests/ui/obfuscated_if_else.rs:34:13 | LL | let _ = true.then_some(40).unwrap_or(17) | 2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 40 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:32:13 + --> tests/ui/obfuscated_if_else.rs:39:13 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 30 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:32:48 + --> tests/ui/obfuscated_if_else.rs:39:48 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 2 } else { 3 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:32:81 + --> tests/ui/obfuscated_if_else.rs:39:81 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 10 } else { 1 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:36:17 + --> tests/ui/obfuscated_if_else.rs:46:17 | LL | let _ = 2 | true.then_some(40).unwrap_or(17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 40 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:40:13 + --> tests/ui/obfuscated_if_else.rs:51:13 | LL | let _ = true.then_some(42).unwrap_or(17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 42 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:44:14 + --> tests/ui/obfuscated_if_else.rs:56:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:48:14 + --> tests/ui/obfuscated_if_else.rs:61:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` diff --git a/tests/ui/octal_escapes.rs b/tests/ui/octal_escapes.rs index f2664e2fa67f..08e0316d1124 100644 --- a/tests/ui/octal_escapes.rs +++ b/tests/ui/octal_escapes.rs @@ -2,20 +2,31 @@ #![warn(clippy::octal_escapes)] fn main() { - let _bad1 = "\033[0m"; //~ octal_escapes - let _bad2 = b"\033[0m"; //~ octal_escapes - let _bad3 = "\\\033[0m"; //~ octal_escapes +let _bad1 = "\033[0m"; +//~^ octal_escapes +let _bad2 = b"\033[0m"; +//~^ octal_escapes +let _bad3 = "\\\033[0m"; +//~^ octal_escapes // maximum 3 digits (\012 is the escape) - let _bad4 = "\01234567"; //~ octal_escapes - let _bad5 = "\0\03"; //~ octal_escapes +let _bad4 = "\01234567"; +//~^ octal_escapes +let _bad5 = "\0\03"; +//~^ octal_escapes let _bad6 = "Text-\055\077-MoreText"; //~^ octal_escapes //~| octal_escapes + + let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; //~^ octal_escapes //~| octal_escapes - let _bad8 = "锈\01锈"; //~ octal_escapes - let _bad9 = "锈\011锈"; //~ octal_escapes + + +let _bad8 = "锈\01锈"; +//~^ octal_escapes +let _bad9 = "锈\011锈"; +//~^ octal_escapes let _good1 = "\\033[0m"; let _good2 = "\0\\0"; diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 9343ba64a30b..2f838a84dd48 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -1,83 +1,83 @@ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:5:18 + --> tests/ui/octal_escapes.rs:5:14 | -LL | let _bad1 = "\033[0m"; - | ^^^^ +LL | let _bad1 = "\033[0m"; + | ^^^^ | = help: octal escapes are not supported, `\0` is always null = note: `-D clippy::octal-escapes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape is intended, use a hex escape instead | -LL | let _bad1 = "\x1b[0m"; - | ~~~~ +LL | let _bad1 = "\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad1 = "\x0033[0m"; - | ~~~~~~ +LL | let _bad1 = "\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:6:19 + --> tests/ui/octal_escapes.rs:7:15 | -LL | let _bad2 = b"\033[0m"; - | ^^^^ +LL | let _bad2 = b"\033[0m"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad2 = b"\x1b[0m"; - | ~~~~ +LL | let _bad2 = b"\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad2 = b"\x0033[0m"; - | ~~~~~~ +LL | let _bad2 = b"\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:7:20 + --> tests/ui/octal_escapes.rs:9:16 | -LL | let _bad3 = "\\\033[0m"; - | ^^^^ +LL | let _bad3 = "\\\033[0m"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad3 = "\\\x1b[0m"; - | ~~~~ +LL | let _bad3 = "\\\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad3 = "\\\x0033[0m"; - | ~~~~~~ +LL | let _bad3 = "\\\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:9:18 + --> tests/ui/octal_escapes.rs:12:14 | -LL | let _bad4 = "\01234567"; - | ^^^^ +LL | let _bad4 = "\01234567"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad4 = "\x0a34567"; - | ~~~~ +LL | let _bad4 = "\x0a34567"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad4 = "\x001234567"; - | ~~~~~~ +LL | let _bad4 = "\x001234567"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:10:20 + --> tests/ui/octal_escapes.rs:14:16 | -LL | let _bad5 = "\0\03"; - | ^^^ +LL | let _bad5 = "\0\03"; + | ^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad5 = "\0\x03"; - | ~~~~ +LL | let _bad5 = "\0\x03"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad5 = "\0\x0003"; - | ~~~~~~ +LL | let _bad5 = "\0\x0003"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:11:23 + --> tests/ui/octal_escapes.rs:16:23 | LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^ @@ -92,7 +92,7 @@ LL | let _bad6 = "Text-\x0055\077-MoreText"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:11:27 + --> tests/ui/octal_escapes.rs:16:27 | LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^ @@ -107,7 +107,7 @@ LL | let _bad6 = "Text-\055\x0077-MoreText"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:14:31 + --> tests/ui/octal_escapes.rs:21:31 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^ @@ -122,7 +122,7 @@ LL | let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:14:34 + --> tests/ui/octal_escapes.rs:21:34 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^ @@ -137,34 +137,34 @@ LL | let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:17:19 + --> tests/ui/octal_escapes.rs:26:15 | -LL | let _bad8 = "锈\01锈"; - | ^^^ +LL | let _bad8 = "锈\01锈"; + | ^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad8 = "锈\x01锈"; - | ~~~~ +LL | let _bad8 = "锈\x01锈"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad8 = "锈\x0001锈"; - | ~~~~~~ +LL | let _bad8 = "锈\x0001锈"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:18:19 + --> tests/ui/octal_escapes.rs:28:15 | -LL | let _bad9 = "锈\011锈"; - | ^^^^ +LL | let _bad9 = "锈\011锈"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad9 = "锈\x09锈"; - | ~~~~ +LL | let _bad9 = "锈\x09锈"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad9 = "锈\x0011锈"; - | ~~~~~~ +LL | let _bad9 = "锈\x0011锈"; + | ~~~~~~ error: aborting due to 11 previous errors diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index c2ad21e22ff8..33702878ddb7 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -14,21 +14,26 @@ fn main() { let _ = res.unwrap(); res.ok().expect("disaster!"); - //~^ ERROR: called `ok().expect()` on a `Result` value + //~^ ok_expect + // 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 + //~^ ok_expect + let res4: Result = Ok(0); res4.ok().expect("argh"); - //~^ ERROR: called `ok().expect()` on a `Result` value + //~^ ok_expect + let res5: io::Result = Ok(0); res5.ok().expect("oops"); - //~^ ERROR: called `ok().expect()` on a `Result` value + //~^ ok_expect + let res6: Result = Ok(0); res6.ok().expect("meh"); - //~^ ERROR: called `ok().expect()` on a `Result` value + //~^ ok_expect + } diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index 2fd4f007d06d..a9e3533d8ca1 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -9,7 +9,7 @@ LL | res.ok().expect("disaster!"); = help: to override `-D warnings` add `#[allow(clippy::ok_expect)]` error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:23:5 + --> tests/ui/ok_expect.rs:24:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | res3.ok().expect("whoof"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:26:5 + --> tests/ui/ok_expect.rs:28:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | res4.ok().expect("argh"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:29:5 + --> tests/ui/ok_expect.rs:32:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | res5.ok().expect("oops"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:32:5 + --> tests/ui/ok_expect.rs:36: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 169fb790f8c5..cf872920a6e2 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -9,18 +9,22 @@ fn _simple2(x: u32) -> u32 { } fn _one_unused(flag: u32, a: usize) -> usize { - //~^ ERROR: parameter is only used in recursion +//~^ 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 +//~^ only_used_in_recursion +//~| 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 +//~^ only_used_in_recursion + if flag == 0 { 0 } else { @@ -34,8 +38,10 @@ 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 +//~^ only_used_in_recursion +//~| only_used_in_recursion + + if flag == 0 { 0 } else { @@ -44,8 +50,10 @@ 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 +//~^ only_used_in_recursion +//~| only_used_in_recursion + + if flag == 0 { 0 } else { @@ -54,7 +62,8 @@ 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 +//~^ only_used_in_recursion + if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } } @@ -62,13 +71,16 @@ struct A; impl A { fn _method(flag: usize, a: usize) -> usize { - //~^ ERROR: parameter is only used in recursion + //~^ 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 + //~^ only_used_in_recursion + //~| only_used_in_recursion + + if flag == 0 { 0 } else { self._method_self(flag - 1, a) } } } @@ -80,12 +92,14 @@ trait B { impl B for A { fn method(flag: u32, a: usize) -> usize { - //~^ ERROR: parameter is only used in recursion + //~^ 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 + //~^ only_used_in_recursion + if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } @@ -112,12 +126,14 @@ impl B for u32 { trait C { fn method(flag: u32, a: usize) -> usize { - //~^ ERROR: parameter is only used in recursion + //~^ 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 + //~^ 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 a3aee2697f38..1f1aa75be662 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -5,7 +5,7 @@ LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:13:53 + --> tests/ui/only_used_in_recursion.rs:14:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ @@ -13,181 +13,181 @@ LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:16:27 + --> tests/ui/only_used_in_recursion.rs:17:27 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:19:53 + --> tests/ui/only_used_in_recursion.rs:22:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:16:35 + --> tests/ui/only_used_in_recursion.rs:17:35 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:19:56 + --> tests/ui/only_used_in_recursion.rs:22:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:22:26 + --> tests/ui/only_used_in_recursion.rs:25:26 | LL | fn _with_calc(flag: u32, a: i64) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:27:32 + --> tests/ui/only_used_in_recursion.rs:31:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:36:33 + --> tests/ui/only_used_in_recursion.rs:40:33 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:42:38 + --> tests/ui/only_used_in_recursion.rs:48:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:36:41 + --> tests/ui/only_used_in_recursion.rs:40:41 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:42:45 + --> tests/ui/only_used_in_recursion.rs:48:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:46:35 + --> tests/ui/only_used_in_recursion.rs:52:35 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:52:39 + --> tests/ui/only_used_in_recursion.rs:60:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:46:43 + --> tests/ui/only_used_in_recursion.rs:52:43 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:52:43 + --> tests/ui/only_used_in_recursion.rs:60:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:56:30 + --> tests/ui/only_used_in_recursion.rs:64:30 | LL | fn _not_primitive(flag: u32, b: String) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:58:56 + --> tests/ui/only_used_in_recursion.rs:67:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:64:29 + --> tests/ui/only_used_in_recursion.rs:73:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:66:59 + --> tests/ui/only_used_in_recursion.rs:76:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:69:22 + --> tests/ui/only_used_in_recursion.rs:79:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:72:35 + --> tests/ui/only_used_in_recursion.rs:84:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:69:41 + --> tests/ui/only_used_in_recursion.rs:79:41 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:72:63 + --> tests/ui/only_used_in_recursion.rs:84:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:82:26 + --> tests/ui/only_used_in_recursion.rs:94:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:84:58 + --> tests/ui/only_used_in_recursion.rs:97:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:87:38 + --> tests/ui/only_used_in_recursion.rs:100:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:89:62 + --> tests/ui/only_used_in_recursion.rs:103:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:114:26 + --> tests/ui/only_used_in_recursion.rs:128:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:116:58 + --> tests/ui/only_used_in_recursion.rs:131:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:119:38 + --> tests/ui/only_used_in_recursion.rs:134:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:121:62 + --> tests/ui/only_used_in_recursion.rs:137: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 1353ff8816ad..e4639c8b8a45 100644 --- a/tests/ui/only_used_in_recursion2.rs +++ b/tests/ui/only_used_in_recursion2.rs @@ -1,9 +1,11 @@ #![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 +//~^ only_used_in_recursion + fn inner(flag: u32, a: u32) -> u32 { - //~^ ERROR: parameter is only used in recursion + //~^ only_used_in_recursion + if flag == 0 { 0 } else { inner(flag, a) } } @@ -12,7 +14,8 @@ 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 +//~^ only_used_in_recursion + if let Some(x) = a.and_then(|x| f(x, x)) { _with_closure(Some(x), b, f) } else { @@ -63,7 +66,8 @@ impl E<()> for () { } fn overwritten_param(flag: u32, mut a: usize) -> usize { - //~^ ERROR: parameter is only used in recursion +//~^ only_used_in_recursion + if flag == 0 { return 0; } else if flag > 5 { @@ -75,7 +79,8 @@ 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 +//~^ 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 e39460c7e8f3..a7cd8713cf7a 100644 --- a/tests/ui/only_used_in_recursion2.stderr +++ b/tests/ui/only_used_in_recursion2.stderr @@ -5,7 +5,7 @@ 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 - --> tests/ui/only_used_in_recursion2.rs:11:52 + --> tests/ui/only_used_in_recursion2.rs:13:52 | LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ @@ -13,49 +13,49 @@ LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion2.rs:5:25 + --> tests/ui/only_used_in_recursion2.rs:6:25 | LL | fn inner(flag: u32, a: u32) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion2.rs:7:47 + --> tests/ui/only_used_in_recursion2.rs:9:47 | LL | if flag == 0 { 0 } else { inner(flag, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion2.rs:14:34 + --> tests/ui/only_used_in_recursion2.rs:16: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 - --> tests/ui/only_used_in_recursion2.rs:17:32 + --> tests/ui/only_used_in_recursion2.rs:20:32 | LL | _with_closure(Some(x), b, f) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion2.rs:65:37 + --> tests/ui/only_used_in_recursion2.rs:68: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 - --> tests/ui/only_used_in_recursion2.rs:74:29 + --> tests/ui/only_used_in_recursion2.rs:78:29 | LL | overwritten_param(flag, a) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion2.rs:77:32 + --> tests/ui/only_used_in_recursion2.rs:81: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 - --> tests/ui/only_used_in_recursion2.rs:83:32 + --> tests/ui/only_used_in_recursion2.rs:88:32 | LL | field_direct(flag - 1, a) | ^ diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index 183dcf4f0863..a67f883fe2e2 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -9,8 +9,9 @@ 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` + //~^ op_ref + + let bar = String::new(); let bar = "foo" == &bar; @@ -56,7 +57,8 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & y; - //~^ ERROR: taken reference of right operand + //~^ op_ref + } #[derive(Clone, Copy)] @@ -90,9 +92,11 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * self; - //~^ ERROR: taken reference of right operand + //~^ op_ref + let _ = two + three; - //~^ ERROR: taken reference of right operand + //~^ op_ref + // 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 6ed4f23d2bd7..798484c9fe9e 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -9,8 +9,9 @@ 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` + //~^ op_ref + + let bar = String::new(); let bar = "foo" == &bar; @@ -56,7 +57,8 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & &y; - //~^ ERROR: taken reference of right operand + //~^ op_ref + } #[derive(Clone, Copy)] @@ -90,9 +92,11 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * &self; - //~^ ERROR: taken reference of right operand + //~^ op_ref + let _ = two + &three; - //~^ ERROR: taken reference of right operand + //~^ op_ref + // 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 c5b68730a8f2..86d0be4272c6 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -12,7 +12,7 @@ LL | let foo = 5 - 6; | ~ ~ error: taken reference of right operand - --> tests/ui/op_ref.rs:58:13 + --> tests/ui/op_ref.rs:59:13 | LL | let z = x & &y; | ^^^^-- @@ -20,7 +20,7 @@ LL | let z = x & &y; | help: use the right value directly: `y` error: taken reference of right operand - --> tests/ui/op_ref.rs:92:17 + --> tests/ui/op_ref.rs:94:17 | LL | let _ = one * &self; | ^^^^^^----- @@ -28,7 +28,7 @@ LL | let _ = one * &self; | help: use the right value directly: `self` error: taken reference of right operand - --> tests/ui/op_ref.rs:94:17 + --> tests/ui/op_ref.rs:97:17 | LL | let _ = two + &three; | ^^^^^^------ diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index 4acb3780df43..acc2a5f86164 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -15,28 +15,36 @@ impl OpenOptionsExt for OpenOptions { 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` + //~^ nonsensical_open_options + + OpenOptions::new().append(true).truncate(true).open("foo.txt"); - //~^ ERROR: file opened with `append` and `truncate` + //~^ nonsensical_open_options + OpenOptions::new().read(true).read(false).open("foo.txt"); - //~^ ERROR: the method `read` is called more than once + //~^ nonsensical_open_options + OpenOptions::new() .create(true) .truncate(true) // Ensure we don't trigger suspicious open options by having create without truncate .create(false) - //~^ ERROR: the method `create` is called more than once + //~^ nonsensical_open_options + .open("foo.txt"); OpenOptions::new().write(true).write(false).open("foo.txt"); - //~^ ERROR: the method `write` is called more than once + //~^ nonsensical_open_options + OpenOptions::new().append(true).append(false).open("foo.txt"); - //~^ ERROR: the method `append` is called more than once + //~^ nonsensical_open_options + OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); - //~^ ERROR: the method `truncate` is called more than once + //~^ nonsensical_open_options + std::fs::File::options().read(true).read(false).open("foo.txt"); - //~^ ERROR: the method `read` is called more than once + //~^ nonsensical_open_options + let mut options = std::fs::OpenOptions::new(); options.read(true); diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index 19755bce46c8..27d8d01f3b5f 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -8,43 +8,43 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); = help: to override `-D warnings` add `#[allow(clippy::nonsensical_open_options)]` error: file opened with `append` and `truncate` - --> tests/ui/open_options.rs:20:5 + --> tests/ui/open_options.rs:21:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:23:35 + --> tests/ui/open_options.rs:25:35 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ error: the method `create` is called more than once - --> tests/ui/open_options.rs:28:10 + --> tests/ui/open_options.rs:31:10 | LL | .create(false) | ^^^^^^^^^^^^^ error: the method `write` is called more than once - --> tests/ui/open_options.rs:31:36 + --> tests/ui/open_options.rs:35:36 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^ error: the method `append` is called more than once - --> tests/ui/open_options.rs:33:37 + --> tests/ui/open_options.rs:38:37 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> tests/ui/open_options.rs:35:39 + --> tests/ui/open_options.rs:41:39 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:38:41 + --> tests/ui/open_options.rs:45:41 | LL | std::fs::File::options().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ diff --git a/tests/ui/open_options_fixable.fixed b/tests/ui/open_options_fixable.fixed index 90a129a9bdff..7ba5a8782bef 100644 --- a/tests/ui/open_options_fixable.fixed +++ b/tests/ui/open_options_fixable.fixed @@ -3,5 +3,6 @@ use std::fs::OpenOptions; #[warn(clippy::suspicious_open_options)] fn main() { OpenOptions::new().create(true).truncate(true).open("foo.txt"); - //~^ ERROR: file opened with `create`, but `truncate` behavior not defined + //~^ suspicious_open_options + } diff --git a/tests/ui/open_options_fixable.rs b/tests/ui/open_options_fixable.rs index 3a9e522ba150..230d6d782074 100644 --- a/tests/ui/open_options_fixable.rs +++ b/tests/ui/open_options_fixable.rs @@ -3,5 +3,6 @@ use std::fs::OpenOptions; #[warn(clippy::suspicious_open_options)] fn main() { OpenOptions::new().create(true).open("foo.txt"); - //~^ ERROR: file opened with `create`, but `truncate` behavior not defined + //~^ suspicious_open_options + } diff --git a/tests/ui/option_as_ref_cloned.fixed b/tests/ui/option_as_ref_cloned.fixed index 394dad219f77..cf21d1c0176e 100644 --- a/tests/ui/option_as_ref_cloned.fixed +++ b/tests/ui/option_as_ref_cloned.fixed @@ -5,10 +5,13 @@ fn main() { let mut x = Some(String::new()); let _: Option = x.clone(); + //~^ option_as_ref_cloned let _: Option = x.clone(); + //~^ option_as_ref_cloned let y = x.as_ref(); let _: Option<&String> = y.clone(); + //~^ option_as_ref_cloned macro_rules! cloned_recv { () => { diff --git a/tests/ui/option_as_ref_cloned.rs b/tests/ui/option_as_ref_cloned.rs index 7243957927b2..354638c4c380 100644 --- a/tests/ui/option_as_ref_cloned.rs +++ b/tests/ui/option_as_ref_cloned.rs @@ -5,10 +5,13 @@ fn main() { let mut x = Some(String::new()); let _: Option = x.as_ref().cloned(); + //~^ option_as_ref_cloned let _: Option = x.as_mut().cloned(); + //~^ option_as_ref_cloned let y = x.as_ref(); let _: Option<&String> = y.as_ref().cloned(); + //~^ option_as_ref_cloned macro_rules! cloned_recv { () => { diff --git a/tests/ui/option_as_ref_cloned.stderr b/tests/ui/option_as_ref_cloned.stderr index 5892f2bdec56..d0f5747420bc 100644 --- a/tests/ui/option_as_ref_cloned.stderr +++ b/tests/ui/option_as_ref_cloned.stderr @@ -12,7 +12,7 @@ LL | let _: Option = x.clone(); | ~~~~~ error: cloning an `Option<_>` using `.as_mut().cloned()` - --> tests/ui/option_as_ref_cloned.rs:8:31 + --> tests/ui/option_as_ref_cloned.rs:9:31 | LL | let _: Option = x.as_mut().cloned(); | ^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _: Option = x.clone(); | ~~~~~ error: cloning an `Option<_>` using `.as_ref().cloned()` - --> tests/ui/option_as_ref_cloned.rs:11:32 + --> tests/ui/option_as_ref_cloned.rs:13:32 | LL | let _: Option<&String> = y.as_ref().cloned(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_as_ref_deref.fixed b/tests/ui/option_as_ref_deref.fixed index c5a959ba566d..9be89b5d484f 100644 --- a/tests/ui/option_as_ref_deref.fixed +++ b/tests/ui/option_as_ref_deref.fixed @@ -9,25 +9,38 @@ fn main() { let mut opt = Some(String::from("123")); let _ = opt.clone().as_deref().map(str::len); + //~^ option_as_ref_deref #[rustfmt::skip] let _ = opt.clone().as_deref() .map(str::len); let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref let _ = Some(CString::new(vec![]).unwrap()).as_deref(); + //~^ option_as_ref_deref let _ = Some(OsString::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(PathBuf::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_deref(); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_deref_mut(); + //~^ option_as_ref_deref let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.clone().as_deref_mut().map(|x| x.len()); + //~^ option_as_ref_deref let vc = vec![String::new()]; let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted @@ -35,10 +48,13 @@ fn main() { let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted let _ = opt.as_deref(); + //~^ option_as_ref_deref let _ = opt.as_deref_mut(); + //~^ option_as_ref_deref // Issue #5927 let _ = opt.as_deref(); + //~^ option_as_ref_deref } #[clippy::msrv = "1.39"] @@ -51,4 +67,5 @@ fn msrv_1_39() { fn msrv_1_40() { let opt = Some(String::from("123")); let _ = opt.as_deref(); + //~^ option_as_ref_deref } diff --git a/tests/ui/option_as_ref_deref.rs b/tests/ui/option_as_ref_deref.rs index 1aeedf211fe2..d6b29e5e61b1 100644 --- a/tests/ui/option_as_ref_deref.rs +++ b/tests/ui/option_as_ref_deref.rs @@ -9,28 +9,42 @@ fn main() { let mut opt = Some(String::from("123")); let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); + //~^ option_as_ref_deref #[rustfmt::skip] let _ = opt.clone() + //~^ option_as_ref_deref .as_ref().map( Deref::deref ) .map(str::len); let _ = opt.as_mut().map(DerefMut::deref_mut); + //~^ option_as_ref_deref let _ = opt.as_ref().map(String::as_str); + //~^ option_as_ref_deref let _ = opt.as_ref().map(|x| x.as_str()); + //~^ option_as_ref_deref let _ = opt.as_mut().map(String::as_mut_str); + //~^ option_as_ref_deref let _ = opt.as_mut().map(|x| x.as_mut_str()); + //~^ option_as_ref_deref let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); + //~^ option_as_ref_deref let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); + //~^ option_as_ref_deref let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); + //~^ option_as_ref_deref let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); + //~^ option_as_ref_deref let _ = opt.as_ref().map(|x| x.deref()); + //~^ option_as_ref_deref let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); + //~^ option_as_ref_deref let vc = vec![String::new()]; let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted @@ -38,10 +52,13 @@ fn main() { let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted let _ = opt.as_ref().map(|x| &**x); + //~^ option_as_ref_deref let _ = opt.as_mut().map(|x| &mut **x); + //~^ option_as_ref_deref // Issue #5927 let _ = opt.as_ref().map(std::ops::Deref::deref); + //~^ option_as_ref_deref } #[clippy::msrv = "1.39"] @@ -54,4 +71,5 @@ fn msrv_1_39() { fn msrv_1_40() { let opt = Some(String::from("123")); let _ = opt.as_ref().map(String::as_str); + //~^ option_as_ref_deref } diff --git a/tests/ui/option_as_ref_deref.stderr b/tests/ui/option_as_ref_deref.stderr index 8b7f47a1b9af..ca924aec66dd 100644 --- a/tests/ui/option_as_ref_deref.stderr +++ b/tests/ui/option_as_ref_deref.stderr @@ -8,107 +8,108 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]` error: called `.as_ref().map(Deref::deref)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:14:13 + --> tests/ui/option_as_ref_deref.rs:15:13 | LL | let _ = opt.clone() | _____________^ +LL | | LL | | .as_ref().map( LL | | Deref::deref LL | | ) | |_________^ help: consider using as_deref: `opt.clone().as_deref()` error: called `.as_mut().map(DerefMut::deref_mut)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:20:13 + --> tests/ui/option_as_ref_deref.rs:22:13 | LL | let _ = opt.as_mut().map(DerefMut::deref_mut); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(String::as_str)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:22:13 + --> tests/ui/option_as_ref_deref.rs:25:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_ref().map(|x| x.as_str())` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:23:13 + --> tests/ui/option_as_ref_deref.rs:27:13 | LL | let _ = opt.as_ref().map(|x| x.as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(String::as_mut_str)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:24:13 + --> tests/ui/option_as_ref_deref.rs:29:13 | LL | let _ = opt.as_mut().map(String::as_mut_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_mut().map(|x| x.as_mut_str())` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:25:13 + --> tests/ui/option_as_ref_deref.rs:31:13 | LL | let _ = opt.as_mut().map(|x| x.as_mut_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(CString::as_c_str)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:26:13 + --> tests/ui/option_as_ref_deref.rs:33:13 | LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(CString::new(vec![]).unwrap()).as_deref()` error: called `.as_ref().map(OsString::as_os_str)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:27:13 + --> tests/ui/option_as_ref_deref.rs:35:13 | LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(OsString::new()).as_deref()` error: called `.as_ref().map(PathBuf::as_path)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:28:13 + --> tests/ui/option_as_ref_deref.rs:37:13 | LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(PathBuf::new()).as_deref()` error: called `.as_ref().map(Vec::as_slice)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:29:13 + --> tests/ui/option_as_ref_deref.rs:39:13 | LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `Some(Vec::<()>::new()).as_deref()` error: called `.as_mut().map(Vec::as_mut_slice)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:30:13 + --> tests/ui/option_as_ref_deref.rs:41:13 | LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `Some(Vec::<()>::new()).as_deref_mut()` error: called `.as_ref().map(|x| x.deref())` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:32:13 + --> tests/ui/option_as_ref_deref.rs:44:13 | LL | let _ = opt.as_ref().map(|x| x.deref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(|x| x.deref_mut())` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:33:13 + --> tests/ui/option_as_ref_deref.rs:46:13 | LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.clone().as_deref_mut()` error: called `.as_ref().map(|x| &**x)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:40:13 + --> tests/ui/option_as_ref_deref.rs:54:13 | LL | let _ = opt.as_ref().map(|x| &**x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_mut().map(|x| &mut **x)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:41:13 + --> tests/ui/option_as_ref_deref.rs:56:13 | LL | let _ = opt.as_mut().map(|x| &mut **x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref_mut: `opt.as_deref_mut()` error: called `.as_ref().map(std::ops::Deref::deref)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:44:13 + --> tests/ui/option_as_ref_deref.rs:60:13 | LL | let _ = opt.as_ref().map(std::ops::Deref::deref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` error: called `.as_ref().map(String::as_str)` on an `Option` value - --> tests/ui/option_as_ref_deref.rs:56:13 + --> tests/ui/option_as_ref_deref.rs:73:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using as_deref: `opt.as_deref()` diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index f8d382340f2f..f5e57284df49 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -8,10 +8,17 @@ use proc_macros::{external, inline_macros}; #[inline_macros] fn main() { let _ = option_env!("PATH").unwrap(); + //~^ option_env_unwrap let _ = option_env!("PATH").expect("environment variable PATH isn't set"); + //~^ option_env_unwrap let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment. + //~^ option_env_unwrap let _ = inline!(option_env!($"PATH").unwrap()); + //~^ option_env_unwrap let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); + //~^ option_env_unwrap let _ = external!(option_env!($"PATH").unwrap()); + //~^ option_env_unwrap let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); + //~^ option_env_unwrap } diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index 169523269fbb..cee0fe6bf9ae 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -9,7 +9,7 @@ LL | let _ = option_env!("PATH").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::option_env_unwrap)]` error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:11:13 + --> tests/ui/option_env_unwrap.rs:12:13 | LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:12:13 + --> tests/ui/option_env_unwrap.rs:14:13 | LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your env... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only work = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:13:21 + --> tests/ui/option_env_unwrap.rs:16:21 | LL | let _ = inline!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = inline!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:14:21 + --> tests/ui/option_env_unwrap.rs:18:21 | LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:15:13 + --> tests/ui/option_env_unwrap.rs:20:13 | LL | let _ = external!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = external!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:16:13 + --> tests/ui/option_env_unwrap.rs:22:13 | LL | let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_filter_map.fixed b/tests/ui/option_filter_map.fixed index b1c3cfa48a44..d8d3ba7edd28 100644 --- a/tests/ui/option_filter_map.fixed +++ b/tests/ui/option_filter_map.fixed @@ -3,18 +3,24 @@ fn main() { let _ = Some(Some(1)).flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(Some(1)).flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(1).map(odds_out).flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(1).map(odds_out).flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![Some(1)].into_iter().flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![Some(1)].into_iter().flatten(); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![1] .into_iter() .map(odds_out) diff --git a/tests/ui/option_filter_map.rs b/tests/ui/option_filter_map.rs index 2550b9cd2b36..68abaff01b44 100644 --- a/tests/ui/option_filter_map.rs +++ b/tests/ui/option_filter_map.rs @@ -3,29 +3,37 @@ fn main() { let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap()); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + let _ = vec![1] .into_iter() .map(odds_out) .filter(Option::is_some) - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + .map(Option::unwrap); let _ = vec![1] .into_iter() .map(odds_out) .filter(|o| o.is_some()) - //~^ ERROR: `filter` for `Some` followed by `unwrap` + //~^ option_filter_map + .map(|o| o.unwrap()); } diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index 401ac2b2296d..24a3a2d7605c 100644 --- a/tests/ui/option_filter_map.stderr +++ b/tests/ui/option_filter_map.stderr @@ -8,50 +8,50 @@ LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); = help: to override `-D warnings` add `#[allow(clippy::option_filter_map)]` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:7:27 + --> tests/ui/option_filter_map.rs:8:27 | LL | let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:9:35 + --> tests/ui/option_filter_map.rs:11:35 | LL | let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:11:35 + --> tests/ui/option_filter_map.rs:14:35 | LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:14:39 + --> tests/ui/option_filter_map.rs:18:39 | LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:16:39 + --> tests/ui/option_filter_map.rs:21:39 | LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:21:10 + --> tests/ui/option_filter_map.rs:27:10 | LL | .filter(Option::is_some) | __________^ -LL | | +... | LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:27:10 + --> tests/ui/option_filter_map.rs:34:10 | LL | .filter(|o| o.is_some()) | __________^ -LL | | +... | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 0ac89bf0d8ea..eb1aabe63e75 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -24,17 +24,23 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = string.map_or(0, |s| s.len()); + //~^ option_if_let_else let _ = num.as_ref().map_or(&0, |s| s); + //~^ option_if_let_else let _ = num.as_mut().map_or(&0, |s| { + //~^ option_if_let_else *s += 1; s }); let _ = num.as_ref().map_or(&0, |s| s); + //~^ option_if_let_else let _ = num.map_or(0, |mut s| { + //~^ option_if_let_else s += 1; s }); let _ = num.as_mut().map_or(&0, |s| { + //~^ option_if_let_else *s += 1; s }); @@ -42,6 +48,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { fn longer_body(arg: Option) -> u32 { arg.map_or(13, |x| { + //~^ option_if_let_else let y = x * x; y * y }) @@ -98,6 +105,7 @@ fn test_result_impure_else(variable: Result) -> bool { println!("Err"); false }, |binding| { + //~^ option_if_let_else println!("Ok {binding}"); true }) @@ -119,6 +127,7 @@ fn complex_subpat() -> DummyEnum { fn main() { let optional = Some(5); let _ = optional.map_or(5, |x| x + 2); + //~^ option_if_let_else let _ = bad1(None); let _ = else_if_option(None); unop_bad(&None, None); @@ -153,10 +162,12 @@ fn main() { let s = String::new(); // Lint, both branches immutably borrow `s`. let _ = Some(0).map_or(s.len(), |x| s.len() + x); + //~^ option_if_let_else let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. let _ = Some(0).map_or(1, |x| { + //~^ option_if_let_else let s = s; s.len() + x }); @@ -200,6 +211,7 @@ fn main() { let _ = res.map_or(1, |a| a + 1); let _ = res.map_or(1, |a| a + 1); let _ = res.map_or(5, |a| a + 1); + //~^ option_if_let_else } #[allow(dead_code)] @@ -243,6 +255,7 @@ fn issue11429() { let mut _hashmap = opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone()); let mut _hm = opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone()); + //~^ option_if_let_else } fn issue11893() { diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index b4f1b2cd1f7f..f2e2de02a93d 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -10,6 +10,7 @@ fn bad1(string: Option<&str>) -> (bool, &str) { if let Some(x) = string { + //~^ option_if_let_else (true, x) } else { (false, "hello") @@ -28,21 +29,27 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> { fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = if let Some(s) = *string { s.len() } else { 0 }; + //~^ option_if_let_else let _ = if let Some(s) = &num { s } else { &0 }; + //~^ option_if_let_else let _ = if let Some(s) = &mut num { + //~^ option_if_let_else *s += 1; s } else { &0 }; let _ = if let Some(ref s) = num { s } else { &0 }; + //~^ option_if_let_else let _ = if let Some(mut s) = num { + //~^ option_if_let_else s += 1; s } else { 0 }; let _ = if let Some(ref mut s) = num { + //~^ option_if_let_else *s += 1; s } else { @@ -52,6 +59,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { fn longer_body(arg: Option) -> u32 { if let Some(x) = arg { + //~^ option_if_let_else let y = x * x; y * y } else { @@ -65,6 +73,7 @@ fn impure_else(arg: Option) { 1 }; let _ = if let Some(x) = arg { + //~^ option_if_let_else x } else { // map_or_else must be suggested @@ -74,6 +83,7 @@ fn impure_else(arg: Option) { fn test_map_or_else(arg: Option) { let _ = if let Some(x) = arg { + //~^ option_if_let_else x * x * x * x } else { let mut y = 1; @@ -107,6 +117,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { .split('/') .flat_map(|s| { if let Some(idx) = s.find('.') { + //~^ option_if_let_else vec![s[..idx].to_string(), s[idx..].to_string()] } else { vec![s.to_string()] @@ -118,6 +129,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { // #10335 fn test_result_impure_else(variable: Result) -> bool { if let Ok(binding) = variable { + //~^ option_if_let_else println!("Ok {binding}"); true } else { @@ -142,6 +154,7 @@ fn complex_subpat() -> DummyEnum { fn main() { let optional = Some(5); let _ = if let Some(x) = optional { x + 2 } else { 5 }; + //~^ option_if_let_else let _ = bad1(None); let _ = else_if_option(None); unop_bad(&None, None); @@ -152,6 +165,7 @@ fn main() { let _ = impure_else(None); let _ = if let Some(x) = Some(0) { + //~^ option_if_let_else loop { if x == 0 { break x; @@ -180,10 +194,12 @@ fn main() { let s = String::new(); // Lint, both branches immutably borrow `s`. let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; + //~^ option_if_let_else let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. let _ = if let Some(x) = Some(0) { + //~^ option_if_let_else let s = s; s.len() + x } else { @@ -223,24 +239,29 @@ fn main() { // issue #8492 let _ = match s { + //~^ option_if_let_else Some(string) => string.len(), None => 1, }; let _ = match Some(10) { + //~^ option_if_let_else Some(a) => a + 1, None => 5, }; let res: Result = Ok(5); let _ = match res { + //~^ option_if_let_else Ok(a) => a + 1, _ => 1, }; let _ = match res { + //~^ option_if_let_else Err(_) => 1, Ok(a) => a + 1, }; let _ = if let Ok(a) = res { a + 1 } else { 5 }; + //~^ option_if_let_else } #[allow(dead_code)] @@ -258,6 +279,7 @@ mod issue10729 { pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` let _ = match initial { + //~^ option_if_let_else Some(value) => do_something(value), None => 42, }; @@ -265,6 +287,7 @@ mod issue10729 { pub fn reproduce2(initial: &mut Option) { let _ = match initial { + //~^ option_if_let_else Some(value) => do_something2(value), None => 42, }; @@ -288,12 +311,14 @@ fn issue11429() { let opt: Option> = None; let mut _hashmap = if let Some(hm) = &opt { + //~^ option_if_let_else hm.clone() } else { HashMap::new() }; let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; + //~^ option_if_let_else } fn issue11893() { diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 32ff22763234..f872ac991840 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -2,6 +2,7 @@ error: use Option::map_or instead of an if let/else --> tests/ui/option_if_let_else.rs:12:5 | LL | / if let Some(x) = string { +LL | | LL | | (true, x) LL | | } else { LL | | (false, "hello") @@ -12,22 +13,23 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:30:13 + --> tests/ui/option_if_let_else.rs:31:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:31:13 + --> tests/ui/option_if_let_else.rs:33:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:32:13 + --> tests/ui/option_if_let_else.rs:35:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ +LL | | LL | | *s += 1; LL | | s LL | | } else { @@ -38,22 +40,24 @@ LL | | }; help: try | LL ~ let _ = num.as_mut().map_or(&0, |s| { +LL + LL + *s += 1; LL + s LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:38:13 + --> tests/ui/option_if_let_else.rs:42:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:39:13 + --> tests/ui/option_if_let_else.rs:44:13 | LL | let _ = if let Some(mut s) = num { | _____________^ +LL | | LL | | s += 1; LL | | s LL | | } else { @@ -64,16 +68,18 @@ LL | | }; help: try | LL ~ let _ = num.map_or(0, |mut s| { +LL + LL + s += 1; LL + s LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:45:13 + --> tests/ui/option_if_let_else.rs:51:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ +LL | | LL | | *s += 1; LL | | s LL | | } else { @@ -84,15 +90,17 @@ LL | | }; help: try | LL ~ let _ = num.as_mut().map_or(&0, |s| { +LL + LL + *s += 1; LL + s LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:54:5 + --> tests/ui/option_if_let_else.rs:61:5 | LL | / if let Some(x) = arg { +LL | | LL | | let y = x * x; LL | | y * y LL | | } else { @@ -103,30 +111,33 @@ LL | | } help: try | LL ~ arg.map_or(13, |x| { +LL + LL + let y = x * x; LL + y * y LL + }) | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:67:13 + --> tests/ui/option_if_let_else.rs:75:13 | LL | let _ = if let Some(x) = arg { | _____________^ +LL | | LL | | x LL | | } else { -... | +LL | | // map_or_else must be suggested +LL | | side_effect() LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:76:13 + --> tests/ui/option_if_let_else.rs:85:13 | LL | let _ = if let Some(x) = arg { | _____________^ +LL | | LL | | x * x * x * x LL | | } else { -LL | | let mut y = 1; ... | LL | | y LL | | }; @@ -143,9 +154,10 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:109:13 + --> tests/ui/option_if_let_else.rs:119:13 | LL | / if let Some(idx) = s.find('.') { +LL | | LL | | vec![s[..idx].to_string(), s[idx..].to_string()] LL | | } else { LL | | vec![s.to_string()] @@ -153,13 +165,13 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:120:5 + --> tests/ui/option_if_let_else.rs:131:5 | LL | / if let Ok(binding) = variable { +LL | | LL | | println!("Ok {binding}"); LL | | true -LL | | } else { -LL | | println!("Err"); +... | LL | | false LL | | } | |_____^ @@ -170,25 +182,26 @@ LL ~ variable.map_or_else(|_| { LL + println!("Err"); LL + false LL + }, |binding| { +LL + LL + println!("Ok {binding}"); LL + true LL + }) | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:144:13 + --> tests/ui/option_if_let_else.rs:156:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:154:13 + --> tests/ui/option_if_let_else.rs:167:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ +LL | | LL | | loop { LL | | if x == 0 { -LL | | break x; ... | LL | | 0 LL | | }; @@ -204,16 +217,17 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:182:13 + --> tests/ui/option_if_let_else.rs:196:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:186:13 + --> tests/ui/option_if_let_else.rs:201:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ +LL | | LL | | let s = s; LL | | s.len() + x LL | | } else { @@ -224,82 +238,90 @@ LL | | }; help: try | LL ~ let _ = Some(0).map_or(1, |x| { +LL + LL + let s = s; LL + s.len() + x LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:225:13 + --> tests/ui/option_if_let_else.rs:241:13 | LL | let _ = match s { | _____________^ +LL | | LL | | Some(string) => string.len(), LL | | None => 1, LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:229:13 + --> tests/ui/option_if_let_else.rs:246:13 | LL | let _ = match Some(10) { | _____________^ +LL | | LL | | Some(a) => a + 1, LL | | None => 5, LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:235:13 + --> tests/ui/option_if_let_else.rs:253:13 | LL | let _ = match res { | _____________^ +LL | | LL | | Ok(a) => a + 1, LL | | _ => 1, LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:239:13 + --> tests/ui/option_if_let_else.rs:258:13 | LL | let _ = match res { | _____________^ +LL | | LL | | Err(_) => 1, LL | | Ok(a) => a + 1, LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:243:13 + --> tests/ui/option_if_let_else.rs:263:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:260:17 + --> tests/ui/option_if_let_else.rs:281:17 | LL | let _ = match initial { | _________________^ +LL | | LL | | Some(value) => do_something(value), LL | | None => 42, LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:267:17 + --> tests/ui/option_if_let_else.rs:289:17 | LL | let _ = match initial { | _________________^ +LL | | LL | | Some(value) => do_something2(value), LL | | None => 42, LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:290:24 + --> tests/ui/option_if_let_else.rs:313:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ +LL | | LL | | hm.clone() LL | | } else { LL | | HashMap::new() @@ -307,7 +329,7 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:296:19 + --> tests/ui/option_if_let_else.rs:320:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed index 5f0ef34d231c..c4d9f25bd28c 100644 --- a/tests/ui/option_map_or_none.fixed +++ b/tests/ui/option_map_or_none.fixed @@ -8,12 +8,15 @@ fn main() { // Check `OPTION_MAP_OR_NONE`. // Single line case. let _: Option = opt.map(|x| x + 1); + //~^ option_map_or_none // Multi-line case. #[rustfmt::skip] let _: Option = opt.map(|x| x + 1); // function returning `Option` let _: Option = opt.and_then(bar); + //~^ option_map_or_none let _: Option = opt.and_then(|x| { + //~^ option_map_or_none let offset = 0; let height = x; Some(offset + height) @@ -21,4 +24,5 @@ fn main() { // Check `RESULT_MAP_OR_INTO_OPTION`. let _: Option = r.ok(); + //~^ result_map_or_into_option } diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs index 56b1f61212d0..c3143f50cb6c 100644 --- a/tests/ui/option_map_or_none.rs +++ b/tests/ui/option_map_or_none.rs @@ -8,14 +8,18 @@ fn main() { // Check `OPTION_MAP_OR_NONE`. // Single line case. let _: Option = opt.map_or(None, |x| Some(x + 1)); + //~^ option_map_or_none // Multi-line case. #[rustfmt::skip] let _: Option = opt.map_or(None, |x| { + //~^ option_map_or_none Some(x + 1) }); // function returning `Option` let _: Option = opt.map_or(None, bar); + //~^ option_map_or_none let _: Option = opt.map_or(None, |x| { + //~^ option_map_or_none let offset = 0; let height = x; Some(offset + height) @@ -23,4 +27,5 @@ fn main() { // Check `RESULT_MAP_OR_INTO_OPTION`. let _: Option = r.map_or(None, Some); + //~^ result_map_or_into_option } diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index cba29861296f..f9290fb99bc1 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -8,25 +8,27 @@ LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); = help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]` error: called `map_or(None, ..)` on an `Option` value - --> tests/ui/option_map_or_none.rs:13:26 + --> tests/ui/option_map_or_none.rs:14:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ +LL | | LL | | Some(x + 1) LL | | }); | |_________________________^ help: consider using `map`: `opt.map(|x| x + 1)` error: called `map_or(None, ..)` on an `Option` value - --> tests/ui/option_map_or_none.rs:17:26 + --> tests/ui/option_map_or_none.rs:19:26 | LL | let _: Option = opt.map_or(None, bar); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `and_then`: `opt.and_then(bar)` error: called `map_or(None, ..)` on an `Option` value - --> tests/ui/option_map_or_none.rs:18:26 + --> tests/ui/option_map_or_none.rs:21:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ +LL | | LL | | let offset = 0; LL | | let height = x; LL | | Some(offset + height) @@ -36,6 +38,7 @@ LL | | }); help: consider using `and_then` | LL ~ let _: Option = opt.and_then(|x| { +LL + LL + let offset = 0; LL + let height = x; LL + Some(offset + height) @@ -43,7 +46,7 @@ LL ~ }); | error: called `map_or(None, Some)` on a `Result` value - --> tests/ui/option_map_or_none.rs:25:26 + --> tests/ui/option_map_or_none.rs:29:26 | LL | let _: Option = r.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `ok`: `r.ok()` diff --git a/tests/ui/option_map_unit_fn_fixable.fixed b/tests/ui/option_map_unit_fn_fixable.fixed index 5dcc6464ff5f..55c1b8f110ce 100644 --- a/tests/ui/option_map_unit_fn_fixable.fixed +++ b/tests/ui/option_map_unit_fn_fixable.fixed @@ -35,52 +35,71 @@ fn option_map_unit_fn() { let _ : Option<()> = x.field.map(do_nothing); if let Some(x_field) = x.field { do_nothing(x_field) } + //~^ option_map_unit_fn if let Some(x_field) = x.field { do_nothing(x_field) } + //~^ option_map_unit_fn if let Some(x_field) = x.field { diverge(x_field) } + //~^ option_map_unit_fn let captured = 10; if let Some(value) = x.field { do_nothing(value + captured) }; let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); if let Some(value) = x.field { x.do_option_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { x.do_option_plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { do_nothing(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured) } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { diverge(value + captured); } + //~^ option_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); if let Some(value) = x.field { let y = plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(value) = x.field { plus_one(value + captured); } + //~^ option_map_unit_fn if let Some(ref value) = x.field { do_nothing(value + captured) } + //~^ option_map_unit_fn if let Some(a) = option() { do_nothing(a) } + //~^ option_map_unit_fn if let Some(value) = option() { println!("{:?}", value) } + //~^ option_map_unit_fn } fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.rs b/tests/ui/option_map_unit_fn_fixable.rs index 5489545fe3d9..5ed47e4c60b5 100644 --- a/tests/ui/option_map_unit_fn_fixable.rs +++ b/tests/ui/option_map_unit_fn_fixable.rs @@ -35,52 +35,71 @@ fn option_map_unit_fn() { let _ : Option<()> = x.field.map(do_nothing); x.field.map(do_nothing); + //~^ option_map_unit_fn x.field.map(do_nothing); + //~^ option_map_unit_fn x.field.map(diverge); + //~^ option_map_unit_fn let captured = 10; if let Some(value) = x.field { do_nothing(value + captured) }; let _ : Option<()> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_option_nothing(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { x.do_option_plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| do_nothing(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { do_nothing(value + captured) }); + //~^ option_map_unit_fn x.field.map(|value| { do_nothing(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { do_nothing(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|value| diverge(value + captured)); + //~^ option_map_unit_fn x.field.map(|value| { diverge(value + captured) }); + //~^ option_map_unit_fn x.field.map(|value| { diverge(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { diverge(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); x.field.map(|value| { let y = plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { plus_one(value + captured); }); + //~^ option_map_unit_fn x.field.map(|value| { { plus_one(value + captured); } }); + //~^ option_map_unit_fn x.field.map(|ref value| { do_nothing(value + captured) }); + //~^ option_map_unit_fn option().map(do_nothing); + //~^ option_map_unit_fn option().map(|value| println!("{:?}", value)); + //~^ option_map_unit_fn } fn main() {} diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 5fd3dfd071c2..3f7abae34eea 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -10,7 +10,7 @@ LL | x.field.map(do_nothing); = help: to override `-D warnings` add `#[allow(clippy::option_map_unit_fn)]` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> tests/ui/option_map_unit_fn_fixable.rs:39:5 + --> tests/ui/option_map_unit_fn_fixable.rs:40:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -18,7 +18,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:41:5 + --> tests/ui/option_map_unit_fn_fixable.rs:43:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -26,7 +26,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:47:5 + --> tests/ui/option_map_unit_fn_fixable.rs:50:5 | LL | x.field.map(|value| x.do_option_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -34,7 +34,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:49:5 + --> tests/ui/option_map_unit_fn_fixable.rs:53:5 | LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -42,7 +42,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:52:5 + --> tests/ui/option_map_unit_fn_fixable.rs:57:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -50,7 +50,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:54:5 + --> tests/ui/option_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -58,7 +58,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:56:5 + --> tests/ui/option_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -66,7 +66,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:58:5 + --> tests/ui/option_map_unit_fn_fixable.rs:66:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -74,7 +74,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:61:5 + --> tests/ui/option_map_unit_fn_fixable.rs:70:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -82,7 +82,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:63:5 + --> tests/ui/option_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -90,7 +90,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:65:5 + --> tests/ui/option_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -98,7 +98,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:67:5 + --> tests/ui/option_map_unit_fn_fixable.rs:79:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -106,7 +106,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:72:5 + --> tests/ui/option_map_unit_fn_fixable.rs:85:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -114,7 +114,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:74:5 + --> tests/ui/option_map_unit_fn_fixable.rs:88:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -122,7 +122,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:76:5 + --> tests/ui/option_map_unit_fn_fixable.rs:91:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -130,7 +130,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:79:5 + --> tests/ui/option_map_unit_fn_fixable.rs:95:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -138,7 +138,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:81:5 + --> tests/ui/option_map_unit_fn_fixable.rs:98:5 | LL | option().map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^^- @@ -146,7 +146,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 `()` - --> tests/ui/option_map_unit_fn_fixable.rs:83:5 + --> tests/ui/option_map_unit_fn_fixable.rs:101:5 | LL | option().map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/option_map_unit_fn_unfixable.rs b/tests/ui/option_map_unit_fn_unfixable.rs index 20e6c15b18d5..dd2f80fefbee 100644 --- a/tests/ui/option_map_unit_fn_unfixable.rs +++ b/tests/ui/option_map_unit_fn_unfixable.rs @@ -15,8 +15,10 @@ fn plus_one(value: usize) -> usize { fn option_map_unit_fn() { x.field.map(|value| { do_nothing(value); do_nothing(value) }); + //~^ ERROR: cannot find value x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + //~^ ERROR: cannot find value // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases @@ -24,7 +26,9 @@ fn option_map_unit_fn() { do_nothing(value); do_nothing(value) }); + //~^^^^ ERROR: cannot find value x.field.map(|value| { do_nothing(value); do_nothing(value); }); + //~^ ERROR: cannot find value // The following should suggest `if let Some(_X) ...` as it's difficult to generate a proper let variable name for them Some(42).map(diverge); diff --git a/tests/ui/option_map_unit_fn_unfixable.stderr b/tests/ui/option_map_unit_fn_unfixable.stderr index 66271036113c..852785014329 100644 --- a/tests/ui/option_map_unit_fn_unfixable.stderr +++ b/tests/ui/option_map_unit_fn_unfixable.stderr @@ -5,19 +5,19 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); | ^ not found in this scope error[E0425]: cannot find value `x` in this scope - --> tests/ui/option_map_unit_fn_unfixable.rs:19:5 + --> tests/ui/option_map_unit_fn_unfixable.rs:20:5 | LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); | ^ not found in this scope error[E0425]: cannot find value `x` in this scope - --> tests/ui/option_map_unit_fn_unfixable.rs:23:5 + --> tests/ui/option_map_unit_fn_unfixable.rs:25:5 | LL | x.field.map(|value| { | ^ not found in this scope error[E0425]: cannot find value `x` in this scope - --> tests/ui/option_map_unit_fn_unfixable.rs:27:5 + --> tests/ui/option_map_unit_fn_unfixable.rs:30:5 | LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | ^ not found in this scope diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 625d654dd396..73ba4394e983 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -50,61 +50,80 @@ fn or_fun_call() { let with_constructor = Some(vec![1]); with_constructor.unwrap_or_else(make); + //~^ or_fun_call let with_new = Some(vec![1]); with_new.unwrap_or_default(); + //~^ unwrap_or_default let with_const_args = Some(vec![1]); with_const_args.unwrap_or_else(|| Vec::with_capacity(12)); + //~^ or_fun_call let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(|_| make()); + //~^ or_fun_call let with_err_args: Result<_, ()> = Ok(vec![1]); with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); + //~^ or_fun_call let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let self_default = None::; self_default.unwrap_or_else(::default); + //~^ or_fun_call let real_default = None::; real_default.unwrap_or_default(); + //~^ unwrap_or_default let with_vec = Some(vec![1]); with_vec.unwrap_or_default(); + //~^ unwrap_or_default let without_default = Some(Foo); without_default.unwrap_or_else(Foo::new); + //~^ or_fun_call let mut map = HashMap::::new(); map.entry(42).or_default(); + //~^ unwrap_or_default let mut map_vec = HashMap::>::new(); map_vec.entry(42).or_default(); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_default(); + //~^ unwrap_or_default let mut btree_vec = BTreeMap::>::new(); btree_vec.entry(42).or_default(); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or_default(); + //~^ unwrap_or_default let opt = Some(1); let hello = "Hello"; let _ = opt.ok_or_else(|| format!("{} world.", hello)); + //~^ or_fun_call // index let map = HashMap::::new(); let _ = Some(1).unwrap_or_else(|| map[&1]); + //~^ or_fun_call let map = BTreeMap::::new(); let _ = Some(1).unwrap_or_else(|| map[&1]); + //~^ or_fun_call // don't lint index vec let vec = vec![1]; let _ = Some(1).unwrap_or(vec[1]); @@ -129,6 +148,7 @@ fn test_or_with_ctors() { let _ = opt.or(Some(two)); let _ = Some("a".to_string()).or_else(|| Some("b".to_string())); + //~^ or_fun_call let b = "b".to_string(); let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) @@ -168,14 +188,17 @@ mod issue6675 { let s = "test".to_owned(); let s = &s as *const _; None.unwrap_or_else(|| ptr_to_ref(s)); + //~^ or_fun_call } fn bar() { let s = "test".to_owned(); let s = &s as *const _; None.unwrap_or_else(|| unsafe { ptr_to_ref(s) }); + //~^ or_fun_call #[rustfmt::skip] None.unwrap_or_else(|| unsafe { ptr_to_ref(s) }); + //~^ or_fun_call } } @@ -251,7 +274,9 @@ mod issue8993 { fn test_map_or() { let _ = Some(4).map_or_else(g, |v| v); + //~^ or_fun_call let _ = Some(4).map_or_else(g, f); + //~^ or_fun_call let _ = Some(4).map_or(0, f); } } @@ -283,24 +308,31 @@ mod lazy { let with_new = Some(vec![1]); with_new.unwrap_or_default(); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let real_default = None::; real_default.unwrap_or_default(); + //~^ unwrap_or_default let mut map = HashMap::::new(); map.entry(42).or_default(); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_default(); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or_default(); + //~^ unwrap_or_default // negative tests let self_default = None::; @@ -341,28 +373,34 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or_else(f); // suggest `.unwrap_or_else(f)` + //~^ or_fun_call // - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or_else(|| f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` + //~^ or_fun_call // - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or_else(|| { + //~^ or_fun_call let x = f(); x + 1 }); - //~v ERROR: function call inside of `map_or` + let _ = opt.map_or_else(|| f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` + //~^ or_fun_call // - //~v ERROR: use of `unwrap_or` to construct default value + let _ = opt.unwrap_or_default(); + //~^ unwrap_or_default let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: function call inside of `unwrap_or` + let _ = opt_foo.unwrap_or_else(|| Foo { val: String::default() }); + //~^ or_fun_call } fn main() {} diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 5b7d8faec7bf..ed3469178196 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -50,61 +50,80 @@ fn or_fun_call() { let with_constructor = Some(vec![1]); with_constructor.unwrap_or(make()); + //~^ or_fun_call let with_new = Some(vec![1]); with_new.unwrap_or(Vec::new()); + //~^ unwrap_or_default let with_const_args = Some(vec![1]); with_const_args.unwrap_or(Vec::with_capacity(12)); + //~^ or_fun_call let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or(make()); + //~^ or_fun_call let with_err_args: Result<_, ()> = Ok(vec![1]); with_err_args.unwrap_or(Vec::with_capacity(12)); + //~^ or_fun_call let with_default_trait = Some(1); with_default_trait.unwrap_or(Default::default()); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or(u64::default()); + //~^ unwrap_or_default let self_default = None::; self_default.unwrap_or(::default()); + //~^ or_fun_call let real_default = None::; real_default.unwrap_or(::default()); + //~^ unwrap_or_default let with_vec = Some(vec![1]); with_vec.unwrap_or(vec![]); + //~^ unwrap_or_default let without_default = Some(Foo); without_default.unwrap_or(Foo::new()); + //~^ or_fun_call let mut map = HashMap::::new(); map.entry(42).or_insert(String::new()); + //~^ unwrap_or_default let mut map_vec = HashMap::>::new(); map_vec.entry(42).or_insert(vec![]); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_insert(String::new()); + //~^ unwrap_or_default let mut btree_vec = BTreeMap::>::new(); btree_vec.entry(42).or_insert(vec![]); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or(String::new()); + //~^ unwrap_or_default let opt = Some(1); let hello = "Hello"; let _ = opt.ok_or(format!("{} world.", hello)); + //~^ or_fun_call // index let map = HashMap::::new(); let _ = Some(1).unwrap_or(map[&1]); + //~^ or_fun_call let map = BTreeMap::::new(); let _ = Some(1).unwrap_or(map[&1]); + //~^ or_fun_call // don't lint index vec let vec = vec![1]; let _ = Some(1).unwrap_or(vec[1]); @@ -129,6 +148,7 @@ fn test_or_with_ctors() { let _ = opt.or(Some(two)); let _ = Some("a".to_string()).or(Some("b".to_string())); + //~^ or_fun_call let b = "b".to_string(); let _ = Some(Bar("a".to_string(), Duration::from_secs(1))) @@ -168,14 +188,17 @@ mod issue6675 { let s = "test".to_owned(); let s = &s as *const _; None.unwrap_or(ptr_to_ref(s)); + //~^ or_fun_call } fn bar() { let s = "test".to_owned(); let s = &s as *const _; None.unwrap_or(unsafe { ptr_to_ref(s) }); + //~^ or_fun_call #[rustfmt::skip] None.unwrap_or( unsafe { ptr_to_ref(s) } ); + //~^ or_fun_call } } @@ -251,7 +274,9 @@ mod issue8993 { fn test_map_or() { let _ = Some(4).map_or(g(), |v| v); + //~^ or_fun_call let _ = Some(4).map_or(g(), f); + //~^ or_fun_call let _ = Some(4).map_or(0, f); } } @@ -283,24 +308,31 @@ mod lazy { let with_new = Some(vec![1]); with_new.unwrap_or_else(Vec::new); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_else(Default::default); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_else(u64::default); + //~^ unwrap_or_default let real_default = None::; real_default.unwrap_or_else(::default); + //~^ unwrap_or_default let mut map = HashMap::::new(); map.entry(42).or_insert_with(String::new); + //~^ unwrap_or_default let mut btree = BTreeMap::::new(); btree.entry(42).or_insert_with(String::new); + //~^ unwrap_or_default let stringy = Some(String::new()); let _ = stringy.unwrap_or_else(String::new); + //~^ unwrap_or_default // negative tests let self_default = None::; @@ -341,28 +373,34 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` + //~^ or_fun_call // - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` + //~^ or_fun_call // - //~v ERROR: function call inside of `unwrap_or` + let _ = opt.unwrap_or({ + //~^ or_fun_call let x = f(); x + 1 }); - //~v ERROR: function call inside of `map_or` + let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` + //~^ or_fun_call // - //~v ERROR: use of `unwrap_or` to construct default value + let _ = opt.unwrap_or({ i32::default() }); + //~^ unwrap_or_default let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: function call inside of `unwrap_or` + let _ = opt_foo.unwrap_or(Foo { val: String::default() }); + //~^ or_fun_call } fn main() {} diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 9f90a830a211..a1eaf08e4458 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -8,7 +8,7 @@ LL | with_constructor.unwrap_or(make()); = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:55:14 + --> tests/ui/or_fun_call.rs:56:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -17,202 +17,203 @@ LL | with_new.unwrap_or(Vec::new()); = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:58:21 + --> tests/ui/or_fun_call.rs:60:21 | LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:61:14 + --> tests/ui/or_fun_call.rs:64:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:64:19 + --> tests/ui/or_fun_call.rs:68:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Vec::with_capacity(12))` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:67:24 + --> tests/ui/or_fun_call.rs:72:24 | LL | with_default_trait.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:70:23 + --> tests/ui/or_fun_call.rs:76:23 | LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:73:18 + --> tests/ui/or_fun_call.rs:80:18 | LL | self_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(::default)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:76:18 + --> tests/ui/or_fun_call.rs:84:18 | LL | real_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:79:14 + --> tests/ui/or_fun_call.rs:88:14 | LL | with_vec.unwrap_or(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:82:21 + --> tests/ui/or_fun_call.rs:92:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:85:19 + --> tests/ui/or_fun_call.rs:96:19 | LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:88:23 + --> tests/ui/or_fun_call.rs:100:23 | LL | map_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:91:21 + --> tests/ui/or_fun_call.rs:104:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:94:25 + --> tests/ui/or_fun_call.rs:108:25 | LL | btree_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:97:21 + --> tests/ui/or_fun_call.rs:112:21 | LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `ok_or` - --> tests/ui/or_fun_call.rs:101:17 + --> tests/ui/or_fun_call.rs:117:17 | LL | let _ = opt.ok_or(format!("{} world.", hello)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ok_or_else(|| format!("{} world.", hello))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:105:21 + --> tests/ui/or_fun_call.rs:122:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:107:21 + --> tests/ui/or_fun_call.rs:125:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `or` - --> tests/ui/or_fun_call.rs:131:35 + --> tests/ui/or_fun_call.rs:150:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:170:14 + --> tests/ui/or_fun_call.rs:190:14 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:176:14 + --> tests/ui/or_fun_call.rs:197:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:178:14 + --> tests/ui/or_fun_call.rs:200:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:253:25 + --> tests/ui/or_fun_call.rs:276:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:254:25 + --> tests/ui/or_fun_call.rs:278: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 - --> tests/ui/or_fun_call.rs:285:18 + --> tests/ui/or_fun_call.rs:310:18 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:288:28 + --> tests/ui/or_fun_call.rs:314:28 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:291:27 + --> tests/ui/or_fun_call.rs:318:27 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:294:22 + --> tests/ui/or_fun_call.rs:322:22 | LL | real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:297:23 + --> tests/ui/or_fun_call.rs:326:23 | LL | map.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:300:25 + --> tests/ui/or_fun_call.rs:330:25 | LL | btree.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:303:25 + --> tests/ui/or_fun_call.rs:334:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:345:17 + --> tests/ui/or_fun_call.rs:377:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:348:17 + --> tests/ui/or_fun_call.rs:381:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:351:17 + --> tests/ui/or_fun_call.rs:385:17 | LL | let _ = opt.unwrap_or({ | _________________^ +LL | | LL | | let x = f(); LL | | x + 1 LL | | }); @@ -221,25 +222,26 @@ LL | | }); help: try | LL ~ let _ = opt.unwrap_or_else(|| { +LL + LL + let x = f(); LL + x + 1 LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:356:17 + --> tests/ui/or_fun_call.rs:391:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| f() + 1, |v| v)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:359:17 + --> tests/ui/or_fun_call.rs:395:17 | LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:365:21 + --> tests/ui/or_fun_call.rs:402:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index c94478614352..19db0e47279c 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -20,13 +20,16 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; let _ = option.unwrap_or("fallback"); // should trigger lint + //~^ or_then_unwrap let result: Result<&str, &str> = Err("Error"); let _ = result.unwrap_or("fallback"); // should trigger lint + //~^ or_then_unwrap // as part of a method chain let option: Option<&str> = None; let _ = option.map(|v| v).unwrap_or("fallback").to_string().chars(); // should trigger lint + //~^ or_then_unwrap // Not Option/Result let instance = SomeStruct {}; diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index 10e43e1d1896..7af03b523f73 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -20,13 +20,16 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; let _ = option.or(Some("fallback")).unwrap(); // should trigger lint + //~^ or_then_unwrap let result: Result<&str, &str> = Err("Error"); let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint + //~^ or_then_unwrap // as part of a method chain let option: Option<&str> = None; let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint + //~^ or_then_unwrap // Not Option/Result let instance = SomeStruct {}; diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index f454316068f2..d64cc58a790b 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -8,13 +8,13 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:25:20 + --> tests/ui/or_then_unwrap.rs:26:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` error: found `.or(Some(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:29:31 + --> tests/ui/or_then_unwrap.rs:31:31 | LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index 81674653bdd3..3ba35482780d 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -7,8 +7,10 @@ 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` + //~^ out_of_bounds_indexing + + &x[10..num]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 8bf0152601df..304adcfdc2d3 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -8,7 +8,7 @@ LL | &x[num..10]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/issue-3102.rs:12:8 + --> tests/ui/out_of_bounds_indexing/issue-3102.rs:13: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 c38ca5123816..86f29f9ee408 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -5,18 +5,24 @@ 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` + //~^ out_of_bounds_indexing + + &x[1..5]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + &x[5..]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + &x[..5]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + &x[5..].iter().map(|x| 2 * x).collect::>(); - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + &x[0..=4]; - //~^ ERROR: range is out of bounds + //~^ out_of_bounds_indexing + &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 87d1d574dcb8..47f36e51bffa 100644 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -8,31 +8,31 @@ LL | &x[..=4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:10:11 + --> tests/ui/out_of_bounds_indexing/simple.rs:11:11 | LL | &x[1..5]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:12:8 + --> tests/ui/out_of_bounds_indexing/simple.rs:14:8 | LL | &x[5..]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:14:10 + --> tests/ui/out_of_bounds_indexing/simple.rs:17:10 | LL | &x[..5]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:16:8 + --> tests/ui/out_of_bounds_indexing/simple.rs:20:8 | LL | &x[5..].iter().map(|x| 2 * x).collect::>(); | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:18:12 + --> tests/ui/out_of_bounds_indexing/simple.rs:23:12 | LL | &x[0..=4]; | ^ diff --git a/tests/ui/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed index b21e91aa3ad4..6818f96725e7 100644 --- a/tests/ui/overly_complex_bool_expr.fixed +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -8,10 +8,12 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = !(a && b); let _ = false; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -22,11 +24,14 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = false; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = false; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = false; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.rs b/tests/ui/overly_complex_bool_expr.rs index 35ef0a1240a5..f1cd9562a855 100644 --- a/tests/ui/overly_complex_bool_expr.rs +++ b/tests/ui/overly_complex_bool_expr.rs @@ -8,10 +8,12 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a && b || a; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = !(a && b); let _ = false && a; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -22,11 +24,14 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = a == b && a != b; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = a < b && a >= b; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = a > b && a <= b; - //~^ ERROR: this boolean expression contains a logic bug + //~^ overly_complex_bool_expr + let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index 5a754236fe4b..42a48a3b5be8 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -13,49 +13,49 @@ LL | let _ = a && b || a; = help: to override `-D warnings` add `#[allow(clippy::overly_complex_bool_expr)]` error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:13:13 + --> tests/ui/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 - --> tests/ui/overly_complex_bool_expr.rs:13:22 + --> tests/ui/overly_complex_bool_expr.rs:14:22 | LL | let _ = false && a; | ^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:24:13 + --> tests/ui/overly_complex_bool_expr.rs:26: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 - --> tests/ui/overly_complex_bool_expr.rs:24:13 + --> tests/ui/overly_complex_bool_expr.rs:26:13 | LL | let _ = a == b && a != b; | ^^^^^^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:26:13 + --> tests/ui/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 - --> tests/ui/overly_complex_bool_expr.rs:26:13 + --> tests/ui/overly_complex_bool_expr.rs:29:13 | LL | let _ = a < b && a >= b; | ^^^^^ error: this boolean expression contains a logic bug - --> tests/ui/overly_complex_bool_expr.rs:28:13 + --> tests/ui/overly_complex_bool_expr.rs:32: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 - --> tests/ui/overly_complex_bool_expr.rs:28:13 + --> tests/ui/overly_complex_bool_expr.rs:32: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 e2375aa996f7..dc0fc65fd777 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -4,7 +4,8 @@ struct A; impl A { fn result_with_panic() -> Result // should emit lint - //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` + //~^ panic_in_result_fn + { panic!("error"); } @@ -51,12 +52,14 @@ impl A { } fn function_result_with_panic() -> Result // should emit lint -//~^ ERROR: used `panic!()` or assertion in a function that returns `Result` +//~^ panic_in_result_fn + { panic!("error"); } fn in_closure() -> Result { +//~^ panic_in_result_fn let c = || panic!(); c() } diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 2d49b5ab1b8f..17fd03733abc 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -2,15 +2,13 @@ error: used `panic!()` or assertion in a function that returns `Result` --> tests/ui/panic_in_result_fn.rs:6:5 | LL | / fn result_with_panic() -> Result // should emit lint -LL | | -LL | | { -LL | | panic!("error"); +... | 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 - --> tests/ui/panic_in_result_fn.rs:9:9 + --> tests/ui/panic_in_result_fn.rs:10:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ @@ -18,26 +16,25 @@ LL | panic!("error"); = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn.rs:53:1 + --> tests/ui/panic_in_result_fn.rs:54:1 | LL | / fn function_result_with_panic() -> Result // should emit lint -LL | | -LL | | { -LL | | panic!("error"); +... | 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 - --> tests/ui/panic_in_result_fn.rs:56:5 + --> tests/ui/panic_in_result_fn.rs:58:5 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn.rs:59:1 + --> tests/ui/panic_in_result_fn.rs:61:1 | LL | / fn in_closure() -> Result { +LL | | LL | | let c = || panic!(); LL | | c() LL | | } @@ -45,7 +42,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 - --> tests/ui/panic_in_result_fn.rs:60:16 + --> tests/ui/panic_in_result_fn.rs:63:16 | LL | let c = || panic!(); | ^^^^^^^^ diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs index 672c4c738339..894e63f8ff1e 100644 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ b/tests/ui/panic_in_result_fn_assertions.rs @@ -5,21 +5,24 @@ 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` + //~^ panic_in_result_fn + { 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` + //~^ panic_in_result_fn + { 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` + //~^ panic_in_result_fn + { 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 cdb7762510d9..46bc16fe8e16 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -2,16 +2,14 @@ error: used `panic!()` or assertion in a function that returns `Result` --> tests/ui/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) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:10:9 + --> tests/ui/panic_in_result_fn_assertions.rs:11:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,37 +17,33 @@ LL | assert!(x == 5, "wrong argument"); = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn_assertions.rs:14:5 + --> tests/ui/panic_in_result_fn_assertions.rs:15:5 | LL | / fn result_with_assert_eq(x: i32) -> Result // should emit lint -LL | | -LL | | { -LL | | assert_eq!(x, 5); +... | LL | | Ok(true) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:17:9 + --> tests/ui/panic_in_result_fn_assertions.rs:19:9 | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn_assertions.rs:21:5 + --> tests/ui/panic_in_result_fn_assertions.rs:23:5 | LL | / fn result_with_assert_ne(x: i32) -> Result // should emit lint -LL | | -LL | | { -LL | | assert_ne!(x, 1); +... | LL | | Ok(true) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:24:9 + --> tests/ui/panic_in_result_fn_assertions.rs:27:9 | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/panic_in_result_fn_debug_assertions.rs b/tests/ui/panic_in_result_fn_debug_assertions.rs index df89d8c50246..c4549c6b8412 100644 --- a/tests/ui/panic_in_result_fn_debug_assertions.rs +++ b/tests/ui/panic_in_result_fn_debug_assertions.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::panic_in_result_fn)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index 2bbf5792ec4c..a718dd925216 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -20,61 +20,77 @@ 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 + + panic!("message"); - //~^ ERROR: `panic` should not be present in production code + //~^ panic + panic!("{} {}", "panic with", "multiple arguments"); - //~^ ERROR: `panic` should not be present in production code + //~^ panic + 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 + + todo!("message"); - //~^ ERROR: `todo` should not be present in production code + //~^ todo + todo!("{} {}", "panic with", "multiple arguments"); - //~^ ERROR: `todo` should not be present in production code + //~^ todo + 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 + + unimplemented!("message"); - //~^ ERROR: `unimplemented` should not be present in production code + //~^ unimplemented + unimplemented!("{} {}", "panic with", "multiple arguments"); - //~^ ERROR: `unimplemented` should not be present in production code + //~^ unimplemented + 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 + + unreachable!("message"); - //~^ ERROR: usage of the `unreachable!` macro + //~^ unreachable + unreachable!("{} {}", "panic with", "multiple arguments"); - //~^ ERROR: usage of the `unreachable!` macro + //~^ unreachable + let b = a + 2; } fn core_versions() { use core::{panic, todo, unimplemented, unreachable}; panic!(); - //~^ ERROR: `panic` should not be present in production code + //~^ panic + todo!(); - //~^ ERROR: `todo` should not be present in production code + //~^ todo + unimplemented!(); - //~^ ERROR: `unimplemented` should not be present in production code + //~^ unimplemented + unreachable!(); - //~^ ERROR: usage of the `unreachable!` macro + //~^ unreachable + } fn assert() { diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 7c0f0a7d3764..0c2b4508a803 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -8,19 +8,19 @@ LL | panic!(); = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:25:5 + --> tests/ui/panicking_macros.rs:26:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:27:5 + --> tests/ui/panicking_macros.rs:29:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:34:5 + --> tests/ui/panicking_macros.rs:37:5 | LL | todo!(); | ^^^^^^^ @@ -29,19 +29,19 @@ LL | todo!(); = help: to override `-D warnings` add `#[allow(clippy::todo)]` error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:37:5 + --> tests/ui/panicking_macros.rs:41:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:39:5 + --> tests/ui/panicking_macros.rs:44:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:46:5 + --> tests/ui/panicking_macros.rs:52:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ @@ -50,19 +50,19 @@ LL | unimplemented!(); = help: to override `-D warnings` add `#[allow(clippy::unimplemented)]` error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:49:5 + --> tests/ui/panicking_macros.rs:56:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:51:5 + --> tests/ui/panicking_macros.rs:59:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:58:5 + --> tests/ui/panicking_macros.rs:67:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ @@ -71,37 +71,37 @@ LL | unreachable!(); = help: to override `-D warnings` add `#[allow(clippy::unreachable)]` error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:61:5 + --> tests/ui/panicking_macros.rs:71:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:63:5 + --> tests/ui/panicking_macros.rs:74:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:70:5 + --> tests/ui/panicking_macros.rs:82:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:72:5 + --> tests/ui/panicking_macros.rs:85:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:74:5 + --> tests/ui/panicking_macros.rs:88:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:76:5 + --> tests/ui/panicking_macros.rs:91:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/panicking_overflow_checks.rs b/tests/ui/panicking_overflow_checks.rs index dc2ddeada1e9..57a829d50d2c 100644 --- a/tests/ui/panicking_overflow_checks.rs +++ b/tests/ui/panicking_overflow_checks.rs @@ -2,14 +2,20 @@ #![allow(clippy::needless_if)] fn test(a: u32, b: u32, c: u32) { - if a + b < a {} //~ panicking_overflow_checks - if a > a + b {} //~ panicking_overflow_checks - if a + b < b {} //~ panicking_overflow_checks - if b > a + b {} //~ panicking_overflow_checks +if a + b < a {} +//~^ panicking_overflow_checks +if a > a + b {} +//~^ panicking_overflow_checks +if a + b < b {} +//~^ panicking_overflow_checks +if b > a + b {} +//~^ panicking_overflow_checks if a - b > b {} if b < a - b {} - if a - b > a {} //~ panicking_overflow_checks - if a < a - b {} //~ panicking_overflow_checks +if a - b > a {} +//~^ panicking_overflow_checks +if a < a - b {} +//~^ panicking_overflow_checks if a + b < c {} if c > a + b {} if a - b < c {} diff --git a/tests/ui/panicking_overflow_checks.stderr b/tests/ui/panicking_overflow_checks.stderr index 1fae04578899..3bb209ccfa7e 100644 --- a/tests/ui/panicking_overflow_checks.stderr +++ b/tests/ui/panicking_overflow_checks.stderr @@ -1,41 +1,41 @@ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:5:8 + --> tests/ui/panicking_overflow_checks.rs:5:4 | -LL | if a + b < a {} - | ^^^^^^^^^ +LL | if a + b < a {} + | ^^^^^^^^^ | = note: `-D clippy::panicking-overflow-checks` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::panicking_overflow_checks)]` error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:6:8 + --> tests/ui/panicking_overflow_checks.rs:7:4 | -LL | if a > a + b {} - | ^^^^^^^^^ +LL | if a > a + b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:7:8 + --> tests/ui/panicking_overflow_checks.rs:9:4 | -LL | if a + b < b {} - | ^^^^^^^^^ +LL | if a + b < b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:8:8 + --> tests/ui/panicking_overflow_checks.rs:11:4 | -LL | if b > a + b {} - | ^^^^^^^^^ +LL | if b > a + b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:11:8 + --> tests/ui/panicking_overflow_checks.rs:15:4 | -LL | if a - b > a {} - | ^^^^^^^^^ +LL | if a - b > a {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:12:8 + --> tests/ui/panicking_overflow_checks.rs:17:4 | -LL | if a < a - b {} - | ^^^^^^^^^ +LL | if a < a - b {} + | ^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs index 316b36c25eac..a0ee4f2b0496 100644 --- a/tests/ui/partial_pub_fields.rs +++ b/tests/ui/partial_pub_fields.rs @@ -8,23 +8,27 @@ fn main() { pub struct FileSet { files: HashMap, pub paths: HashMap, - //~^ ERROR: mixed usage of pub and non-pub fields + //~^ partial_pub_fields + } pub struct Color { pub r: u8, pub g: u8, b: u8, - //~^ ERROR: mixed usage of pub and non-pub fields + //~^ partial_pub_fields + } pub struct Point(i32, pub i32); - //~^ ERROR: mixed usage of pub and non-pub fields + //~^ partial_pub_fields + pub struct Visibility { r#pub: bool, pub pos: u32, - //~^ ERROR: mixed usage of pub and non-pub fields + //~^ partial_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 af3b2f758757..4232f3e82e45 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -9,7 +9,7 @@ LL | pub paths: HashMap, = help: to override `-D warnings` add `#[allow(clippy::partial_pub_fields)]` error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:17:9 + --> tests/ui/partial_pub_fields.rs:18:9 | LL | b: u8, | ^ @@ -17,7 +17,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:21:27 + --> tests/ui/partial_pub_fields.rs:23:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -25,7 +25,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:26:9 + --> tests/ui/partial_pub_fields.rs:29:9 | LL | pub pos: u32, | ^^^ diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 555eeebe1c78..42c235b381ef 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -7,8 +7,9 @@ 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` + //~^ partialeq_ne_impl + + false } } diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index dc01a375060b..ffc26afa075d 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -2,9 +2,7 @@ error: re-implementing `PartialEq::ne` is unnecessary --> tests/ui/partialeq_ne_impl.rs:9:5 | LL | / fn ne(&self, _: &Foo) -> bool { -LL | | -LL | | -LL | | false +... | LL | | } | |_____^ | diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index 87adbca39484..d650e28f2b68 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -12,6 +12,7 @@ impl PartialEq> for Foobar { #[allow(dead_code)] fn foo(f: Option) -> &'static str { if f.is_some() { "yay" } else { "nay" } + //~^ partialeq_to_none } fn foobar() -> Option<()> { @@ -42,19 +43,28 @@ fn main() { let x = Some(0); let _ = x.is_none(); + //~^ partialeq_to_none let _ = x.is_some(); + //~^ partialeq_to_none let _ = x.is_none(); + //~^ partialeq_to_none let _ = x.is_some(); + //~^ partialeq_to_none if foobar().is_none() {} + //~^ partialeq_to_none if bar().ok().is_some() {} + //~^ partialeq_to_none let _ = Some(1 + 2).is_some(); + //~^ partialeq_to_none let _ = { Some(0) }.is_none(); + //~^ partialeq_to_none let _ = { + //~^ partialeq_to_none /* This comment runs long */ @@ -65,10 +75,15 @@ fn main() { let _ = Foobar == None; let _ = optref().is_none(); + //~^ partialeq_to_none let _ = optref().is_some(); + //~^ partialeq_to_none let _ = optref().is_none(); + //~^ partialeq_to_none let _ = optref().is_some(); + //~^ partialeq_to_none let x = Box::new(Option::<()>::None); let _ = (*x).is_some(); + //~^ partialeq_to_none } diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index b623e6a66268..77804b0765f1 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -12,6 +12,7 @@ impl PartialEq> for Foobar { #[allow(dead_code)] fn foo(f: Option) -> &'static str { if f != None { "yay" } else { "nay" } + //~^ partialeq_to_none } fn foobar() -> Option<()> { @@ -42,19 +43,28 @@ fn main() { let x = Some(0); let _ = x == None; + //~^ partialeq_to_none let _ = x != None; + //~^ partialeq_to_none let _ = None == x; + //~^ partialeq_to_none let _ = None != x; + //~^ partialeq_to_none if foobar() == None {} + //~^ partialeq_to_none if bar().ok() != None {} + //~^ partialeq_to_none let _ = Some(1 + 2) != None; + //~^ partialeq_to_none let _ = { Some(0) } == None; + //~^ partialeq_to_none let _ = { + //~^ partialeq_to_none /* This comment runs long */ @@ -65,10 +75,15 @@ fn main() { let _ = Foobar == None; let _ = optref() == &&None; + //~^ partialeq_to_none let _ = &&None != optref(); + //~^ partialeq_to_none let _ = **optref() == None; + //~^ partialeq_to_none let _ = &None != *optref(); + //~^ partialeq_to_none let x = Box::new(Option::<()>::None); let _ = None != *x; + //~^ partialeq_to_none } diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index b588fbf32b60..b09bd7fa0f42 100644 --- a/tests/ui/partialeq_to_none.stderr +++ b/tests/ui/partialeq_to_none.stderr @@ -8,58 +8,59 @@ LL | if f != None { "yay" } else { "nay" } = help: to override `-D warnings` add `#[allow(clippy::partialeq_to_none)]` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:44:13 + --> tests/ui/partialeq_to_none.rs:45:13 | LL | let _ = x == None; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:45:13 + --> tests/ui/partialeq_to_none.rs:47:13 | LL | let _ = x != None; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:46:13 + --> tests/ui/partialeq_to_none.rs:49:13 | LL | let _ = None == x; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:47:13 + --> tests/ui/partialeq_to_none.rs:51:13 | LL | let _ = None != x; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:49:8 + --> tests/ui/partialeq_to_none.rs:54:8 | LL | if foobar() == None {} | ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:51:8 + --> tests/ui/partialeq_to_none.rs:57:8 | LL | if bar().ok() != None {} | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:53:13 + --> tests/ui/partialeq_to_none.rs:60:13 | LL | let _ = Some(1 + 2) != None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `Some(1 + 2).is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:55:13 + --> tests/ui/partialeq_to_none.rs:63:13 | LL | let _ = { Some(0) } == None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:57:13 + --> tests/ui/partialeq_to_none.rs:66:13 | LL | let _ = { | _____________^ +LL | | LL | | /* LL | | This comment runs long LL | | */ @@ -70,6 +71,7 @@ LL | | } != None; help: use `Option::is_some()` instead | LL ~ let _ = { +LL + LL + /* LL + This comment runs long LL + */ @@ -78,31 +80,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:67:13 + --> tests/ui/partialeq_to_none.rs:77:13 | LL | let _ = optref() == &&None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:68:13 + --> tests/ui/partialeq_to_none.rs:79:13 | LL | let _ = &&None != optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:69:13 + --> tests/ui/partialeq_to_none.rs:81:13 | LL | let _ = **optref() == None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:70:13 + --> tests/ui/partialeq_to_none.rs:83:13 | LL | let _ = &None != *optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:73:13 + --> tests/ui/partialeq_to_none.rs:87: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 1a46d72378f8..5c818bad3d53 100644 --- a/tests/ui/path_buf_push_overwrite.fixed +++ b/tests/ui/path_buf_push_overwrite.fixed @@ -5,4 +5,5 @@ use std::path::PathBuf; fn main() { let mut x = PathBuf::from("/foo"); x.push("bar"); + //~^ path_buf_push_overwrite } diff --git a/tests/ui/path_buf_push_overwrite.rs b/tests/ui/path_buf_push_overwrite.rs index 3e3f84b17a4b..650ae3286a0c 100644 --- a/tests/ui/path_buf_push_overwrite.rs +++ b/tests/ui/path_buf_push_overwrite.rs @@ -5,4 +5,5 @@ use std::path::PathBuf; fn main() { let mut x = PathBuf::from("/foo"); x.push("/bar"); + //~^ path_buf_push_overwrite } diff --git a/tests/ui/path_ends_with_ext.fixed b/tests/ui/path_ends_with_ext.fixed index 49767e242cee..a20925f9ba67 100644 --- a/tests/ui/path_ends_with_ext.fixed +++ b/tests/ui/path_ends_with_ext.fixed @@ -9,7 +9,8 @@ macro_rules! arg { fn test(path: &Path) { path.extension().is_some_and(|ext| ext == "md"); - //~^ ERROR: this looks like a failed attempt at checking for the file extension + //~^ path_ends_with_ext + // some "extensions" are allowed by default path.ends_with(".git"); @@ -30,7 +31,8 @@ fn test(path: &Path) { #[clippy::msrv = "1.69"] fn under_msv(path: &Path) -> bool { path.extension().map_or(false, |ext| ext == "md") - //~^ ERROR: this looks like a failed attempt at checking for the file extension + //~^ path_ends_with_ext + } fn main() {} diff --git a/tests/ui/path_ends_with_ext.rs b/tests/ui/path_ends_with_ext.rs index 2dfd046218af..e20620e983d0 100644 --- a/tests/ui/path_ends_with_ext.rs +++ b/tests/ui/path_ends_with_ext.rs @@ -9,7 +9,8 @@ macro_rules! arg { fn test(path: &Path) { path.ends_with(".md"); - //~^ ERROR: this looks like a failed attempt at checking for the file extension + //~^ path_ends_with_ext + // some "extensions" are allowed by default path.ends_with(".git"); @@ -30,7 +31,8 @@ fn test(path: &Path) { #[clippy::msrv = "1.69"] fn under_msv(path: &Path) -> bool { path.ends_with(".md") - //~^ ERROR: this looks like a failed attempt at checking for the file extension + //~^ path_ends_with_ext + } fn main() {} diff --git a/tests/ui/path_ends_with_ext.stderr b/tests/ui/path_ends_with_ext.stderr index deab71ff7626..7016b8e5b8fb 100644 --- a/tests/ui/path_ends_with_ext.stderr +++ b/tests/ui/path_ends_with_ext.stderr @@ -8,7 +8,7 @@ LL | path.ends_with(".md"); = help: to override `-D warnings` add `#[allow(clippy::path_ends_with_ext)]` error: this looks like a failed attempt at checking for the file extension - --> tests/ui/path_ends_with_ext.rs:32:5 + --> tests/ui/path_ends_with_ext.rs:33:5 | LL | path.ends_with(".md") | ^^^^^^^^^^^^^^^^^^^^^ help: try: `path.extension().map_or(false, |ext| ext == "md")` diff --git a/tests/ui/pathbuf_init_then_push.fixed b/tests/ui/pathbuf_init_then_push.fixed index 2a90b8ce2814..43cc65f8dfbf 100644 --- a/tests/ui/pathbuf_init_then_push.fixed +++ b/tests/ui/pathbuf_init_then_push.fixed @@ -3,14 +3,14 @@ use std::path::PathBuf; fn main() { - let mut path_buf = PathBuf::from("foo"); +let mut path_buf = PathBuf::from("foo"); - path_buf = PathBuf::from("foo").join("bar"); +path_buf = PathBuf::from("foo").join("bar"); let bar = "bar"; - path_buf = PathBuf::from("foo").join(bar); +path_buf = PathBuf::from("foo").join(bar); - let mut path_buf = PathBuf::from("foo").join("bar").join("buz"); +let mut path_buf = PathBuf::from("foo").join("bar").join("buz"); let mut x = PathBuf::new(); println!("{}", x.display()); diff --git a/tests/ui/pathbuf_init_then_push.rs b/tests/ui/pathbuf_init_then_push.rs index 4a7ae00a7352..f3adb6d27abf 100644 --- a/tests/ui/pathbuf_init_then_push.rs +++ b/tests/ui/pathbuf_init_then_push.rs @@ -3,17 +3,21 @@ use std::path::PathBuf; fn main() { - let mut path_buf = PathBuf::new(); //~ ERROR: calls to `push` immediately after creation +let mut path_buf = PathBuf::new(); +//~^ pathbuf_init_then_push path_buf.push("foo"); - path_buf = PathBuf::from("foo"); //~ ERROR: calls to `push` immediately after creation +path_buf = PathBuf::from("foo"); +//~^ pathbuf_init_then_push path_buf.push("bar"); let bar = "bar"; - path_buf = PathBuf::from("foo"); //~ ERROR: calls to `push` immediately after creation +path_buf = PathBuf::from("foo"); +//~^ pathbuf_init_then_push path_buf.push(bar); - let mut path_buf = PathBuf::from("foo").join("bar"); //~ ERROR: calls to `push` immediately after creation +let mut path_buf = PathBuf::from("foo").join("bar"); +//~^ pathbuf_init_then_push path_buf.push("buz"); let mut x = PathBuf::new(); diff --git a/tests/ui/pathbuf_init_then_push.stderr b/tests/ui/pathbuf_init_then_push.stderr index e7aa291035d2..80e7b836fce3 100644 --- a/tests/ui/pathbuf_init_then_push.stderr +++ b/tests/ui/pathbuf_init_then_push.stderr @@ -1,7 +1,8 @@ error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:6:5 + --> tests/ui/pathbuf_init_then_push.rs:6:1 | -LL | / let mut path_buf = PathBuf::new(); +LL | / let mut path_buf = PathBuf::new(); +LL | | LL | | path_buf.push("foo"); | |_________________________^ help: consider using the `.join()`: `let mut path_buf = PathBuf::from("foo");` | @@ -9,23 +10,26 @@ LL | | path_buf.push("foo"); = help: to override `-D warnings` add `#[allow(clippy::pathbuf_init_then_push)]` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:9:5 + --> tests/ui/pathbuf_init_then_push.rs:10:1 | -LL | / path_buf = PathBuf::from("foo"); +LL | / path_buf = PathBuf::from("foo"); +LL | | LL | | path_buf.push("bar"); | |_________________________^ help: consider using the `.join()`: `path_buf = PathBuf::from("foo").join("bar");` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:13:5 + --> tests/ui/pathbuf_init_then_push.rs:15:1 | -LL | / path_buf = PathBuf::from("foo"); +LL | / path_buf = PathBuf::from("foo"); +LL | | LL | | path_buf.push(bar); | |_______________________^ help: consider using the `.join()`: `path_buf = PathBuf::from("foo").join(bar);` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:16:5 + --> tests/ui/pathbuf_init_then_push.rs:19:1 | -LL | / let mut path_buf = PathBuf::from("foo").join("bar"); +LL | / let mut path_buf = PathBuf::from("foo").join("bar"); +LL | | LL | | path_buf.push("buz"); | |_________________________^ help: consider using the `.join()`: `let mut path_buf = PathBuf::from("foo").join("bar").join("buz");` diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs index 61dee47cb192..c62b33681439 100644 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ b/tests/ui/pattern_type_mismatch/mutability.rs @@ -7,14 +7,16 @@ fn should_lint() { let value = &Some(23); match value { Some(_) => (), - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + _ => (), } let value = &mut Some(23); match value { Some(_) => (), - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + _ => (), } } diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index e795ded7386d..805fc99ea212 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -9,7 +9,7 @@ LL | Some(_) => (), = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/mutability.rs:16:9 + --> tests/ui/pattern_type_mismatch/mutability.rs:17:9 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs index 558d496ae2c0..9df08bfe7246 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs @@ -13,11 +13,14 @@ fn alternatives() { // not ok if let Value::B | Value::A(_) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &Value::B | &Value::A(Some(_)) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let Value::B | Value::A(Some(_)) = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // 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 e1aec2497cd1..763f688ea897 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -9,7 +9,7 @@ LL | if let Value::B | Value::A(_) = ref_value {} = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/pattern_alternatives.rs:17:34 + --> tests/ui/pattern_type_mismatch/pattern_alternatives.rs:18:34 | LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} | ^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/pattern_type_mismatch/pattern_alternatives.rs:19:32 + --> tests/ui/pattern_type_mismatch/pattern_alternatives.rs:21: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 d9b22693f297..862953120b4c 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ b/tests/ui/pattern_type_mismatch/pattern_structs.rs @@ -11,11 +11,14 @@ fn struct_types() { // not ok let Struct { .. } = ref_value; - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &Struct { ref_inner: Some(_) } = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let Struct { ref_inner: Some(_) } = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok let &Struct { .. } = ref_value; @@ -33,15 +36,20 @@ fn struct_enum_variants() { // not ok if let StructEnum::Var { .. } = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let StructEnum::Empty = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // 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 e5d6e9ed6f81..bdb11c73a457 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -9,7 +9,7 @@ LL | let Struct { .. } = ref_value; = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:15:33 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:16:33 | LL | if let &Struct { ref_inner: Some(_) } = ref_value {} | ^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:17:32 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:19:32 | LL | if let Struct { ref_inner: Some(_) } = *ref_value {} | ^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:35:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:38:12 | LL | if let StructEnum::Var { .. } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:37:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:41:12 | LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:39:42 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:44:42 | LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:41:41 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:47:41 | LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} | ^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:43:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:50: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 f44e3543c96a..4847e1a30a20 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.rs @@ -9,11 +9,14 @@ fn tuple_types() { // not ok let TupleStruct(_) = ref_value; - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &TupleStruct(Some(_)) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let TupleStruct(Some(_)) = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok let &TupleStruct(_) = ref_value; @@ -31,13 +34,17 @@ fn tuple_enum_variants() { // not ok if let TupleEnum::Var(_) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &TupleEnum::Var(Some(_)) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let TupleEnum::Var(Some(_)) = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let TupleEnum::Empty = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok if let &TupleEnum::Var(_) = ref_value {} @@ -53,11 +60,14 @@ fn plain_tuples() { // not ok let (_a, _b) = ref_value; - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let &(_a, Some(_)) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + if let (_a, Some(_)) = *ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // 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 9ecf12a1d639..8a80a888f775 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -9,7 +9,7 @@ LL | let TupleStruct(_) = ref_value; = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:13:25 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:14:25 | LL | if let &TupleStruct(Some(_)) = ref_value {} | ^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:15:24 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:17:24 | LL | if let TupleStruct(Some(_)) = *ref_value {} | ^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:33:12 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:36:12 | LL | if let TupleEnum::Var(_) = ref_value {} | ^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:35:28 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:39:28 | LL | if let &TupleEnum::Var(Some(_)) = ref_value {} | ^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:37:27 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:42:27 | LL | if let TupleEnum::Var(Some(_)) = *ref_value {} | ^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:39:12 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:45:12 | LL | if let TupleEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:55:9 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:62:9 | LL | let (_a, _b) = ref_value; | ^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:57:18 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:65:18 | LL | if let &(_a, Some(_)) = ref_value {} | ^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:59:17 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:68: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 dbc7c3f31061..77e9ec772aa8 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -9,7 +9,8 @@ fn syntax_match() { // not ok match ref_value { Some(_) => (), - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + None => (), } @@ -29,7 +30,8 @@ fn syntax_if_let() { // not ok if let Some(_) = ref_value {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok if let &Some(_) = ref_value {} @@ -41,7 +43,8 @@ fn syntax_while_let() { // not ok while let Some(_) = ref_value { - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + break; } @@ -60,7 +63,8 @@ fn syntax_for() { // not ok for (_a, _b) in slice.iter() {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok for &(_a, _b) in slice.iter() {} @@ -71,7 +75,8 @@ fn syntax_let() { // not ok let (_n, _m) = ref_value; - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok let &(_n, _m) = ref_value; @@ -81,7 +86,8 @@ fn syntax_let() { fn syntax_fn() { // not ok fn foo((_a, _b): &(i32, i32)) {} - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok fn foo_ok_1(&(_a, _b): &(i32, i32)) {} @@ -96,7 +102,8 @@ fn syntax_closure() { // not ok foo(|(_a, _b)| ()); - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + // ok foo(|&(_a, _b)| ()); @@ -113,7 +120,8 @@ fn macro_with_expression() { // not ok matching_macro!(match value { Some(_) => (), - //~^ ERROR: type of pattern does not match the expression type + //~^ pattern_type_mismatch + _ => (), }); @@ -134,6 +142,7 @@ fn macro_expansion() { // not ok match $e { Some(_) => (), + //~^ pattern_type_mismatch _ => (), } diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index 9186a01b9c75..eec9ea70c69d 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -9,7 +9,7 @@ LL | Some(_) => (), = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/syntax.rs:31:12 + --> tests/ui/pattern_type_mismatch/syntax.rs:32:12 | LL | if let Some(_) = ref_value {} | ^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:43:15 + --> tests/ui/pattern_type_mismatch/syntax.rs:45:15 | LL | while let Some(_) = ref_value { | ^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:62:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:65:9 | LL | for (_a, _b) in slice.iter() {} | ^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:73:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:77:9 | LL | let (_n, _m) = ref_value; | ^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:83:12 + --> tests/ui/pattern_type_mismatch/syntax.rs:88:12 | LL | fn foo((_a, _b): &(i32, i32)) {} | ^^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:98:10 + --> tests/ui/pattern_type_mismatch/syntax.rs:104:10 | LL | foo(|(_a, _b)| ()); | ^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:115:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:122:9 | LL | Some(_) => (), | ^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:136:17 + --> tests/ui/pattern_type_mismatch/syntax.rs:144:17 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index feaec33ac15a..a119096865a0 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -12,6 +12,7 @@ fn main() { match v { Some(x) => (), y => (), + //~^ redundant_pattern } match v { Some(x) => (), @@ -27,6 +28,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { ref mut x => { + //~^ redundant_pattern x.push(4); println!("vec: {:?}", x); }, @@ -35,6 +37,7 @@ fn main() { match mutv { ref x => println!("vec: {:?}", x), + //~^ redundant_pattern ref y if y == &vec![0] => (), } external! { diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 53812c7deec3..4ba6ac319af9 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -12,6 +12,7 @@ fn main() { match v { Some(x) => (), y @ _ => (), + //~^ redundant_pattern } match v { Some(x) => (), @@ -27,6 +28,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { ref mut x @ _ => { + //~^ redundant_pattern x.push(4); println!("vec: {:?}", x); }, @@ -35,6 +37,7 @@ fn main() { match mutv { ref x @ _ => println!("vec: {:?}", x), + //~^ redundant_pattern ref y if y == &vec![0] => (), } external! { diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index fa4cf7f83562..b9950fe181cc 100644 --- a/tests/ui/patterns.stderr +++ b/tests/ui/patterns.stderr @@ -8,13 +8,13 @@ LL | y @ _ => (), = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern)]` error: the `x @ _` pattern can be written as just `x` - --> tests/ui/patterns.rs:29:9 + --> tests/ui/patterns.rs:30:9 | LL | ref mut x @ _ => { | ^^^^^^^^^^^^^ help: try: `ref mut x` error: the `x @ _` pattern can be written as just `x` - --> tests/ui/patterns.rs:37:9 + --> tests/ui/patterns.rs:39:9 | LL | ref x @ _ => println!("vec: {:?}", x), | ^^^^^^^^^ help: try: `ref x` diff --git a/tests/ui/permissions_set_readonly_false.rs b/tests/ui/permissions_set_readonly_false.rs index 5a84a64fd2d1..652ffd724d95 100644 --- a/tests/ui/permissions_set_readonly_false.rs +++ b/tests/ui/permissions_set_readonly_false.rs @@ -17,8 +17,9 @@ 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 + //~^ permissions_set_readonly_false + + // no lint permissions.set_readonly(true); diff --git a/tests/ui/pointers_in_nomem_asm_block.rs b/tests/ui/pointers_in_nomem_asm_block.rs index b5abcbb3474c..6d23bd78e919 100644 --- a/tests/ui/pointers_in_nomem_asm_block.rs +++ b/tests/ui/pointers_in_nomem_asm_block.rs @@ -9,7 +9,8 @@ unsafe fn nomem_bad(p: &i32) { asm!( "asdf {p1}, {p2}, {p3}", p1 = in(reg) p, - //~^ ERROR: passing pointers to nomem asm block + //~^ pointers_in_nomem_asm_block + p2 = in(reg) p as *const _ as usize, p3 = in(reg) p, options(nomem, nostack, preserves_flags) @@ -24,10 +25,12 @@ unsafe fn nomem_good(p: &i32) { unsafe fn nomem_bad2(p: &mut i32) { asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags)); - //~^ ERROR: passing pointers to nomem asm block + //~^ pointers_in_nomem_asm_block + } unsafe fn nomem_fn(p: extern "C" fn()) { asm!("call {p}", p = in(reg) p, options(nomem)); - //~^ ERROR: passing pointers to nomem asm block + //~^ pointers_in_nomem_asm_block + } diff --git a/tests/ui/pointers_in_nomem_asm_block.stderr b/tests/ui/pointers_in_nomem_asm_block.stderr index cabeb37344f2..6de9c476312a 100644 --- a/tests/ui/pointers_in_nomem_asm_block.stderr +++ b/tests/ui/pointers_in_nomem_asm_block.stderr @@ -13,7 +13,7 @@ LL | p3 = in(reg) p, = help: to override `-D warnings` add `#[allow(clippy::pointers_in_nomem_asm_block)]` error: passing pointers to nomem asm block - --> tests/ui/pointers_in_nomem_asm_block.rs:26:22 + --> tests/ui/pointers_in_nomem_asm_block.rs:27:22 | LL | asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags)); | ^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags = note: if this is intentional and no pointers are read or written to, consider allowing the lint error: passing pointers to nomem asm block - --> tests/ui/pointers_in_nomem_asm_block.rs:31:22 + --> tests/ui/pointers_in_nomem_asm_block.rs:33:22 | LL | asm!("call {p}", p = in(reg) p, options(nomem)); | ^^^^^^^^^^^^^ diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed index 52144a18bac0..cbb78bff68bf 100644 --- a/tests/ui/precedence.fixed +++ b/tests/ui/precedence.fixed @@ -14,12 +14,19 @@ macro_rules! trip { fn main() { 1 << (2 + 3); + //~^ precedence (1 + 2) << 3; + //~^ precedence 4 >> (1 + 1); + //~^ precedence (1 + 3) >> 2; + //~^ precedence 1 ^ (1 - 1); + //~^ precedence 3 | (2 - 1); + //~^ precedence 3 & (5 - 2); + //~^ precedence 0x0F00 & 0x00F0 << 4; 0x0F00 & 0xF000 >> 4; 0x0F00 << 1 ^ 3; diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index 9ef5c43833f8..c73a4020e2e5 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -14,12 +14,19 @@ macro_rules! trip { fn main() { 1 << 2 + 3; + //~^ precedence 1 + 2 << 3; + //~^ precedence 4 >> 1 + 1; + //~^ precedence 1 + 3 >> 2; + //~^ precedence 1 ^ 1 - 1; + //~^ precedence 3 | 2 - 1; + //~^ precedence 3 & 5 - 2; + //~^ precedence 0x0F00 & 0x00F0 << 4; 0x0F00 & 0xF000 >> 4; 0x0F00 << 1 ^ 3; diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index 68ad5cb4829a..50cd8f4b8146 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -8,37 +8,37 @@ LL | 1 << 2 + 3; = help: to override `-D warnings` add `#[allow(clippy::precedence)]` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:17:5 + --> tests/ui/precedence.rs:18:5 | LL | 1 + 2 << 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:18:5 + --> tests/ui/precedence.rs:20:5 | LL | 4 >> 1 + 1; | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:19:5 + --> tests/ui/precedence.rs:22:5 | LL | 1 + 3 >> 2; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:20:5 + --> tests/ui/precedence.rs:24:5 | LL | 1 ^ 1 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:21:5 + --> tests/ui/precedence.rs:26:5 | LL | 3 | 2 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:22:5 + --> tests/ui/precedence.rs:28:5 | LL | 3 & 5 - 2; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` diff --git a/tests/ui/precedence_bits.fixed b/tests/ui/precedence_bits.fixed index 82fea0d14e43..e0ce4a992bb1 100644 --- a/tests/ui/precedence_bits.fixed +++ b/tests/ui/precedence_bits.fixed @@ -26,9 +26,13 @@ fn main() { 3 | 2 - 1; 3 & 5 - 2; 0x0F00 & (0x00F0 << 4); + //~^ precedence_bits 0x0F00 & (0xF000 >> 4); + //~^ precedence_bits (0x0F00 << 1) ^ 3; + //~^ precedence_bits (0x0F00 << 1) | 2; + //~^ precedence_bits let b = 3; trip!(b * 8); diff --git a/tests/ui/precedence_bits.rs b/tests/ui/precedence_bits.rs index 9b353308b6ee..20d17e26c355 100644 --- a/tests/ui/precedence_bits.rs +++ b/tests/ui/precedence_bits.rs @@ -26,9 +26,13 @@ fn main() { 3 | 2 - 1; 3 & 5 - 2; 0x0F00 & 0x00F0 << 4; + //~^ precedence_bits 0x0F00 & 0xF000 >> 4; + //~^ precedence_bits 0x0F00 << 1 ^ 3; + //~^ precedence_bits 0x0F00 << 1 | 2; + //~^ precedence_bits let b = 3; trip!(b * 8); diff --git a/tests/ui/precedence_bits.stderr b/tests/ui/precedence_bits.stderr index f468186b363c..9cbdca8956d6 100644 --- a/tests/ui/precedence_bits.stderr +++ b/tests/ui/precedence_bits.stderr @@ -8,19 +8,19 @@ LL | 0x0F00 & 0x00F0 << 4; = help: to override `-D warnings` add `#[allow(clippy::precedence_bits)]` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:29:5 + --> tests/ui/precedence_bits.rs:30:5 | LL | 0x0F00 & 0xF000 >> 4; | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0xF000 >> 4)` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:30:5 + --> tests/ui/precedence_bits.rs:32:5 | LL | 0x0F00 << 1 ^ 3; | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) ^ 3` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:31:5 + --> tests/ui/precedence_bits.rs:34:5 | LL | 0x0F00 << 1 | 2; | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) | 2` diff --git a/tests/ui/print.rs b/tests/ui/print.rs index 9ac4b51e1afd..7f7b8eb15b5d 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -9,8 +9,9 @@ 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` + //~^ use_debug + + } } @@ -23,21 +24,28 @@ impl Debug for Foo { fn main() { println!("Hello"); - //~^ ERROR: use of `println!` - //~| NOTE: `-D clippy::print-stdout` implied by `-D warnings` + //~^ print_stdout + + print!("Hello"); - //~^ ERROR: use of `print!` + //~^ print_stdout + print!("Hello {}", "World"); - //~^ ERROR: use of `print!` + //~^ print_stdout + print!("Hello {:?}", "World"); - //~^ ERROR: use of `print!` - //~| ERROR: use of `Debug`-based formatting + //~^ print_stdout + //~| use_debug + + print!("Hello {:#?}", "#orld"); - //~^ ERROR: use of `print!` - //~| ERROR: use of `Debug`-based formatting + //~^ print_stdout + //~| use_debug + + assert_eq!(42, 1337); diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index a8374241c831..4e9d4135486c 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -8,7 +8,7 @@ LL | write!(f, "{:?}", 43.1415) = help: to override `-D warnings` add `#[allow(clippy::use_debug)]` error: use of `println!` - --> tests/ui/print.rs:25:5 + --> tests/ui/print.rs:26:5 | LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ @@ -17,37 +17,37 @@ LL | println!("Hello"); = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `print!` - --> tests/ui/print.rs:28:5 + --> tests/ui/print.rs:30:5 | LL | print!("Hello"); | ^^^^^^^^^^^^^^^ error: use of `print!` - --> tests/ui/print.rs:31:5 + --> tests/ui/print.rs:34:5 | LL | print!("Hello {}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `print!` - --> tests/ui/print.rs:34:5 + --> tests/ui/print.rs:38:5 | LL | print!("Hello {:?}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> tests/ui/print.rs:34:19 + --> tests/ui/print.rs:38:19 | LL | print!("Hello {:?}", "World"); | ^^^^ error: use of `print!` - --> tests/ui/print.rs:38:5 + --> tests/ui/print.rs:44:5 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> tests/ui/print.rs:38:19 + --> tests/ui/print.rs:44:19 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^ diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index 261f50832199..fdf630355044 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -18,17 +18,22 @@ 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` + //~^ print_in_format_impl + + println!("{}", 2); - //~^ ERROR: use of `println!` in `Debug` impl + //~^ print_in_format_impl + eprint!("{}", 3); - //~^ ERROR: use of `eprint!` in `Debug` impl + //~^ print_in_format_impl + eprintln!("{}", 4); - //~^ ERROR: use of `eprintln!` in `Debug` impl + //~^ print_in_format_impl + nested! { println!("nested"); - //~^ ERROR: use of `println!` in `Debug` impl + //~^ print_in_format_impl + }; write!(f, "{}", 5); @@ -42,7 +47,8 @@ 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 + //~^ print_in_format_impl + write!(f, "Display"); Ok(()) @@ -53,7 +59,8 @@ struct UnnamedFormatter; impl Debug for UnnamedFormatter { fn fmt(&self, _: &mut Formatter) -> Result<(), Error> { println!("UnnamedFormatter"); - //~^ ERROR: use of `println!` in `Debug` impl + //~^ print_in_format_impl + Ok(()) } } diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 3fb6b3f9c911..1a9c62d39e03 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -8,37 +8,37 @@ LL | print!("{}", 1); = help: to override `-D warnings` add `#[allow(clippy::print_in_format_impl)]` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:23:9 + --> tests/ui/print_in_format_impl.rs:24:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:25:9 + --> tests/ui/print_in_format_impl.rs:27:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:27:9 + --> tests/ui/print_in_format_impl.rs:30:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:30:13 + --> tests/ui/print_in_format_impl.rs:34:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> tests/ui/print_in_format_impl.rs:44:9 + --> tests/ui/print_in_format_impl.rs:49:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:55:9 + --> tests/ui/print_in_format_impl.rs:61:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index 328e9a9b999f..bcf022badc6e 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -25,28 +25,36 @@ 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` + //~^ print_literal + + println!("Hello {} world", world); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("Hello world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("a literal {:.4}", 5); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // 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 + //~^ print_literal + println!("world hello"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // named args shouldn't change anything either println!("hello world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("world hello"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion @@ -54,23 +62,33 @@ fn main() { // Braces in unicode escapes should not be escaped println!("{{}} \x00 \u{ab123} \\\u{ab123} {{:?}}"); + //~^ print_literal println!("\\\u{1234}"); + //~^ print_literal // This does not lint because it would have to suggest unescaping the character println!(r"{}", "\u{ab123}"); // These are not unicode escapes println!("\\u{{ab123}} \\u{{{{"); + //~^ print_literal println!(r"\u{{ab123}} \u{{{{"); + //~^ print_literal println!("\\{{ab123}} \\u{{{{"); + //~^ print_literal println!("\\u{{ab123}}"); + //~^ print_literal println!("\\\\u{{1234}}"); + //~^ print_literal println!("mixed: {{hello}} {world}"); + //~^ print_literal } fn issue_13959() { println!("\""); + //~^ print_literal println!( " + //~^ print_literal foo \\ \\\\ diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 3130d0b6998e..96c150ae4810 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -25,28 +25,36 @@ 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` + //~^ print_literal + + println!("Hello {} {}", world, "world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("Hello {}", "world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("{} {:.4}", "a literal", 5); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // 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 + //~^ print_literal + println!("{1} {0}", "hello", "world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // named args shouldn't change anything either println!("{foo} {bar}", foo = "hello", bar = "world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + println!("{bar} {foo}", foo = "hello", bar = "world"); - //~^ ERROR: literal with an empty format string + //~^ print_literal + // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion @@ -54,24 +62,34 @@ fn main() { // Braces in unicode escapes should not be escaped println!("{}", "{} \x00 \u{ab123} \\\u{ab123} {:?}"); + //~^ print_literal println!("{}", "\\\u{1234}"); + //~^ print_literal // This does not lint because it would have to suggest unescaping the character println!(r"{}", "\u{ab123}"); // These are not unicode escapes println!("{}", r"\u{ab123} \u{{"); + //~^ print_literal println!(r"{}", r"\u{ab123} \u{{"); + //~^ print_literal println!("{}", r"\{ab123} \u{{"); + //~^ print_literal println!("{}", "\\u{ab123}"); + //~^ print_literal println!("{}", "\\\\u{1234}"); + //~^ print_literal println!("mixed: {} {world}", "{hello}"); + //~^ print_literal } fn issue_13959() { println!("{}", r#"""#); + //~^ print_literal println!( "{}", r#" + //~^ print_literal foo \ \\ diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index d967b7c24070..c2bc7d495f27 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -13,7 +13,7 @@ LL + print!("Hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:30:36 + --> tests/ui/print_literal.rs:31:36 | LL | println!("Hello {} {}", world, "world"); | ^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {} world", world); | error: literal with an empty format string - --> tests/ui/print_literal.rs:32:26 + --> tests/ui/print_literal.rs:34:26 | LL | println!("Hello {}", "world"); | ^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("Hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:34:26 + --> tests/ui/print_literal.rs:37:26 | LL | println!("{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("a literal {:.4}", 5); | error: literal with an empty format string - --> tests/ui/print_literal.rs:40:25 + --> tests/ui/print_literal.rs:44:25 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:42:25 + --> tests/ui/print_literal.rs:47:25 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + println!("world hello"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:46:35 + --> tests/ui/print_literal.rs:52:35 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + println!("hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:48:35 + --> tests/ui/print_literal.rs:55:35 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + println!("world hello"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:56:20 + --> tests/ui/print_literal.rs:64:20 | LL | println!("{}", "{} \x00 \u{ab123} \\\u{ab123} {:?}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + println!("{{}} \x00 \u{ab123} \\\u{ab123} {{:?}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:57:20 + --> tests/ui/print_literal.rs:66:20 | LL | println!("{}", "\\\u{1234}"); | ^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + println!("\\\u{1234}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:61:20 + --> tests/ui/print_literal.rs:71:20 | LL | println!("{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + println!("\\u{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:62:21 + --> tests/ui/print_literal.rs:73:21 | LL | println!(r"{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + println!(r"\u{{ab123}} \u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:63:20 + --> tests/ui/print_literal.rs:75:20 | LL | println!("{}", r"\{ab123} \u{{"); | ^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + println!("\\{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:64:20 + --> tests/ui/print_literal.rs:77:20 | LL | println!("{}", "\\u{ab123}"); | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + println!("\\u{{ab123}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:65:20 + --> tests/ui/print_literal.rs:79:20 | LL | println!("{}", "\\\\u{1234}"); | ^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + println!("\\\\u{{1234}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:67:35 + --> tests/ui/print_literal.rs:82:35 | LL | println!("mixed: {} {world}", "{hello}"); | ^^^^^^^^^ @@ -193,7 +193,7 @@ LL + println!("mixed: {{hello}} {world}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:71:20 + --> tests/ui/print_literal.rs:87:20 | LL | println!("{}", r#"""#); | ^^^^^^ @@ -205,12 +205,12 @@ LL + println!("\""); | error: literal with an empty format string - --> tests/ui/print_literal.rs:74:9 + --> tests/ui/print_literal.rs:91:9 | LL | / r#" +LL | | LL | | foo LL | | \ -LL | | \\ ... | LL | | bar LL | | "# @@ -219,6 +219,7 @@ LL | | "# help: try | LL ~ " +LL + LL + foo LL + \\ LL + \\\\ diff --git a/tests/ui/print_stderr.rs b/tests/ui/print_stderr.rs index 109f43ffe25d..2ad2c97b7cc1 100644 --- a/tests/ui/print_stderr.rs +++ b/tests/ui/print_stderr.rs @@ -2,10 +2,12 @@ fn main() { eprintln!("Hello"); - //~^ ERROR: use of `eprintln!` - //~| NOTE: `-D clippy::print-stderr` implied by `-D warnings` + //~^ print_stderr + + println!("This should not do anything"); eprint!("World"); - //~^ ERROR: use of `eprint!` + //~^ print_stderr + print!("Nor should this"); } diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr index 17019b886905..7dfe72934c64 100644 --- a/tests/ui/print_stderr.stderr +++ b/tests/ui/print_stderr.stderr @@ -8,7 +8,7 @@ LL | eprintln!("Hello"); = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: use of `eprint!` - --> tests/ui/print_stderr.rs:8:5 + --> tests/ui/print_stderr.rs:9:5 | LL | eprint!("World"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/print_stdout_build_script.rs b/tests/ui/print_stdout_build_script.rs index 91448cb0faf8..f01b8538ef49 100644 --- a/tests/ui/print_stdout_build_script.rs +++ b/tests/ui/print_stdout_build_script.rs @@ -1,4 +1,5 @@ //@compile-flags: --crate-name=build_script_build +//@ check-pass #![warn(clippy::print_stdout)] diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index 7ac6d2870c12..79bd8a2c8d36 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -5,16 +5,21 @@ 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` + //~^ print_with_newline + + println!("Hello {}", "world"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + println!("Hello {} {}", "world", "#2"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + println!("{}", 1265); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + println!(); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + // these are all fine print!(""); @@ -37,7 +42,8 @@ fn main() { // #3514 print!("\\n"); println!("\\"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + print!("\\\\n"); // Raw strings @@ -46,11 +52,13 @@ fn main() { // Literal newlines should also fail println!( - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + ); println!( - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + ); @@ -59,7 +67,8 @@ fn main() { print!("foo\r\n"); // should fail println!("\\r"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_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 602d1ea3ec0e..a9cbd214fc61 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -5,16 +5,21 @@ 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_with_newline + + print!("Hello {}\n", "world"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + print!("Hello {} {}\n", "world", "#2"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + print!("{}\n", 1265); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + print!("\n"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + // these are all fine print!(""); @@ -37,7 +42,8 @@ fn main() { // #3514 print!("\\n"); print!("\\\n"); - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + print!("\\\\n"); // Raw strings @@ -46,12 +52,14 @@ fn main() { // Literal newlines should also fail print!( - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + " " ); print!( - //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~^ print_with_newline + r" " ); @@ -61,7 +69,8 @@ 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_with_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 9b07299e61d3..45f858d68966 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -13,7 +13,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:10:5 + --> tests/ui/print_with_newline.rs:11:5 | LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:12:5 + --> tests/ui/print_with_newline.rs:14:5 | LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:14:5 + --> tests/ui/print_with_newline.rs:17:5 | LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:16:5 + --> tests/ui/print_with_newline.rs:20:5 | LL | print!("\n"); | ^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:39:5 + --> tests/ui/print_with_newline.rs:44:5 | LL | print!("\\\n"); | ^^^^^^^^^^^^^^ @@ -73,10 +73,11 @@ LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:48:5 + --> tests/ui/print_with_newline.rs:54:5 | LL | / print!( LL | | +LL | | LL | | " LL | | " LL | | ); @@ -86,14 +87,16 @@ help: use `println!` instead | LL ~ println!( LL | +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:53:5 + --> tests/ui/print_with_newline.rs:60:5 | LL | / print!( LL | | +LL | | LL | | r" LL | | " LL | | ); @@ -103,11 +106,12 @@ help: use `println!` instead | LL ~ println!( LL | +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:63:5 + --> tests/ui/print_with_newline.rs:71:5 | LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed index 20811fc75323..05e262ec7786 100644 --- a/tests/ui/println_empty_string.fixed +++ b/tests/ui/println_empty_string.fixed @@ -3,15 +3,19 @@ fn main() { println!(); println!(); + //~^ println_empty_string match "a" { _ => println!(), + //~^ println_empty_string } eprintln!(); eprintln!(); + //~^ println_empty_string match "a" { _ => eprintln!(), + //~^ println_empty_string } } diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index 47f7277dce79..028ddb60dbce 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -3,15 +3,19 @@ fn main() { println!(); println!(""); + //~^ println_empty_string match "a" { _ => println!(""), + //~^ println_empty_string } eprintln!(); eprintln!(""); + //~^ println_empty_string match "a" { _ => eprintln!(""), + //~^ println_empty_string } } diff --git a/tests/ui/println_empty_string.stderr b/tests/ui/println_empty_string.stderr index 17de05fa25a4..8b997aef9069 100644 --- a/tests/ui/println_empty_string.stderr +++ b/tests/ui/println_empty_string.stderr @@ -10,7 +10,7 @@ LL | println!(""); = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:8:14 + --> tests/ui/println_empty_string.rs:9:14 | LL | _ => println!(""), | ^^^^^^^^^--^ @@ -18,7 +18,7 @@ LL | _ => println!(""), | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:12:5 + --> tests/ui/println_empty_string.rs:14:5 | LL | eprintln!(""); | ^^^^^^^^^^--^ @@ -26,7 +26,7 @@ LL | eprintln!(""); | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:15:14 + --> tests/ui/println_empty_string.rs:18:14 | LL | _ => eprintln!(""), | ^^^^^^^^^^--^ diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index e8b42d3b913b..e8332cb97e1b 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -11,39 +11,46 @@ 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` +//~^ ptr_arg + + //Nothing here } fn do_vec_mut(x: &mut Vec) { - //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w +//~^ ptr_arg + //Nothing here } fn do_vec_mut2(x: &mut Vec) { - //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w +//~^ ptr_arg + x.len(); x.is_empty(); } fn do_str(x: &String) { - //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d +//~^ ptr_arg + //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 +//~^ ptr_arg + //Nothing here either } fn do_path(x: &PathBuf) { - //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will +//~^ ptr_arg + //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 +//~^ ptr_arg + //Nothing here either } @@ -52,7 +59,8 @@ fn main() {} trait Foo { type Item; fn do_vec(x: &Vec); - //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will + //~^ ptr_arg + fn do_item(x: &Self::Item); } @@ -66,7 +74,8 @@ impl Foo for Bar { } fn cloned(x: &Vec) -> Vec { - //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do +//~^ ptr_arg + let e = x.clone(); let f = e.clone(); // OK let g = x; @@ -76,7 +85,8 @@ 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 +//~^ ptr_arg + let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -85,7 +95,8 @@ 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 +//~^ ptr_arg + let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -94,7 +105,8 @@ 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 +//~^ ptr_arg + let a = x.capacity(); let b = y.clone(); let c = y.as_str(); @@ -109,7 +121,8 @@ 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 +//~^ ptr_arg + fn test_cow(c: Cow<[i32]>) { let _c = c; @@ -139,7 +152,8 @@ 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 + //~^ ptr_arg + struct S; impl S { @@ -169,26 +183,30 @@ mod issue6509 { use std::path::PathBuf; fn foo_vec(vec: &Vec) { - //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will + //~^ ptr_arg + 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 + //~^ ptr_arg + 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 + //~^ ptr_arg + 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 +//~^ ptr_arg + v.copy_within(1..5, 10); } @@ -251,9 +269,10 @@ 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 +//~^ ptr_arg +//~| ptr_arg +//~| ptr_arg + trait T {} impl T for Vec {} impl T for [U] {} @@ -277,22 +296,26 @@ 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 + //~^ ptr_arg + todo!() } // These two's return types don't 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 + //~^ ptr_arg + 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 + //~^ ptr_arg + todo!() } // Inferred to be `&'a str`, afaik. fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str { + //~^ ERROR: elided lifetime has a name todo!() } } @@ -325,8 +348,9 @@ mod issue_13308 { // Other cases that are still ok to lint and ideally shouldn't regress fn good(v1: &String, v2: &String) { - //~^ ERROR: writing `&String` instead of `&str` - //~^^ ERROR: writing `&String` instead of `&str` + //~^ ptr_arg + //~| ptr_arg + h1(v1); h2(String::new(), v2); } diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 1a6b3aa1f8d4..94fa2184fd64 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -1,5 +1,5 @@ error: elided lifetime has a name - --> tests/ui/ptr_arg.rs:295:56 + --> tests/ui/ptr_arg.rs:317:56 | LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str { | -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a` @@ -17,49 +17,49 @@ LL | fn do_vec(x: &Vec) { = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:19:18 + --> tests/ui/ptr_arg.rs:20:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:24:19 + --> tests/ui/ptr_arg.rs:26:19 | LL | fn do_vec_mut2(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:30:14 + --> tests/ui/ptr_arg.rs:33: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 - --> tests/ui/ptr_arg.rs:35:18 + --> tests/ui/ptr_arg.rs:39: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 - --> tests/ui/ptr_arg.rs:40:15 + --> tests/ui/ptr_arg.rs:45: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 - --> tests/ui/ptr_arg.rs:45:19 + --> tests/ui/ptr_arg.rs:51: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 - --> tests/ui/ptr_arg.rs:54:18 + --> tests/ui/ptr_arg.rs:61:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:68:14 + --> tests/ui/ptr_arg.rs:76:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -68,6 +68,7 @@ help: change this to | LL ~ fn cloned(x: &[u8]) -> Vec { LL | +LL | LL ~ let e = x.to_owned(); LL | let f = e.clone(); // OK LL | let g = x; @@ -77,7 +78,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:78:18 + --> tests/ui/ptr_arg.rs:87:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -86,6 +87,7 @@ help: change this to | LL ~ fn str_cloned(x: &str) -> String { LL | +LL | LL ~ let a = x.to_owned(); LL ~ let b = x.to_owned(); LL | let c = b.clone(); @@ -94,7 +96,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:87:19 + --> tests/ui/ptr_arg.rs:97:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -103,6 +105,7 @@ help: change this to | LL ~ fn path_cloned(x: &Path) -> PathBuf { LL | +LL | LL ~ let a = x.to_path_buf(); LL ~ let b = x.to_path_buf(); LL | let c = b.clone(); @@ -111,7 +114,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:96:44 + --> tests/ui/ptr_arg.rs:107:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -120,25 +123,26 @@ help: change this to | LL ~ fn false_positive_capacity(x: &Vec, y: &str) { LL | +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 - --> tests/ui/ptr_arg.rs:111:25 + --> tests/ui/ptr_arg.rs:123:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:141:66 + --> tests/ui/ptr_arg.rs:154: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 - --> tests/ui/ptr_arg.rs:171:21 + --> tests/ui/ptr_arg.rs:185:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -147,12 +151,13 @@ help: change this to | LL ~ fn foo_vec(vec: &[u8]) { LL | +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 - --> tests/ui/ptr_arg.rs:177:23 + --> tests/ui/ptr_arg.rs:192:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -161,12 +166,13 @@ help: change this to | LL ~ fn foo_path(path: &Path) { LL | +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 - --> tests/ui/ptr_arg.rs:183:21 + --> tests/ui/ptr_arg.rs:199:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -175,60 +181,61 @@ help: change this to | LL ~ fn foo_str(str: &Path) { LL | +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 - --> tests/ui/ptr_arg.rs:190:29 + --> tests/ui/ptr_arg.rs:207: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 - --> tests/ui/ptr_arg.rs:253:17 + --> tests/ui/ptr_arg.rs:271: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 - --> tests/ui/ptr_arg.rs:253:35 + --> tests/ui/ptr_arg.rs:271: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 - --> tests/ui/ptr_arg.rs:253:51 + --> tests/ui/ptr_arg.rs:271: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 - --> tests/ui/ptr_arg.rs:279:39 + --> tests/ui/ptr_arg.rs:298:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:285:36 + --> tests/ui/ptr_arg.rs:305:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:289:40 + --> tests/ui/ptr_arg.rs:310:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:327:17 + --> tests/ui/ptr_arg.rs:350:17 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:327:30 + --> tests/ui/ptr_arg.rs:350:30 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ help: change this to: `&str` diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index fa15c323540f..2033f31c1eec 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -16,6 +16,7 @@ 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::>()) } + //~^ ptr_as_ptr } } @@ -25,12 +26,15 @@ fn main() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr.cast::(); + //~^ ptr_as_ptr let _ = mut_ptr.cast::(); + //~^ ptr_as_ptr // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; let _ = (*ptr_ptr).cast::(); + //~^ ptr_as_ptr } // Changes in mutability. Do not lint this. @@ -44,10 +48,13 @@ fn main() { // Ensure the lint doesn't produce unnecessary turbofish for inferred types. let _: *const i32 = ptr.cast(); + //~^ ptr_as_ptr let _: *mut i32 = mut_ptr.cast(); + //~^ ptr_as_ptr // Make sure the lint is triggered inside a macro let _ = inline!($ptr.cast::()); + //~^ ptr_as_ptr // Do not lint inside macros from external crates let _ = external!($ptr as *const i32); @@ -69,7 +76,9 @@ fn _msrv_1_38() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr.cast::(); + //~^ ptr_as_ptr let _ = mut_ptr.cast::(); + //~^ ptr_as_ptr } #[allow(clippy::unnecessary_cast)] @@ -77,37 +86,45 @@ mod null { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut::() + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut::() + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut::() + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut::() + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null::() + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null::() + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null::() + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null::() + //~^ ptr_as_ptr } } @@ -115,37 +132,45 @@ mod null_ptr_infer { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut() + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut() + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut() + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut() + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null() + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null() + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null() + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null() + //~^ ptr_as_ptr } } @@ -153,36 +178,44 @@ mod null_entire_infer { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut() + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut() + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut() + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut() + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null() + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null() + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null() + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null() + //~^ ptr_as_ptr } } diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index 7ab52e63da55..224d09b0eb6e 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -16,6 +16,7 @@ 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) } + //~^ ptr_as_ptr } } @@ -25,12 +26,15 @@ fn main() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr as *const i32; + //~^ ptr_as_ptr let _ = mut_ptr as *mut i32; + //~^ ptr_as_ptr // Make sure the lint can handle the difference in their operator precedences. unsafe { let ptr_ptr: *const *const u32 = &ptr; let _ = *ptr_ptr as *const i32; + //~^ ptr_as_ptr } // Changes in mutability. Do not lint this. @@ -44,10 +48,13 @@ fn main() { // Ensure the lint doesn't produce unnecessary turbofish for inferred types. let _: *const i32 = ptr as *const _; + //~^ ptr_as_ptr let _: *mut i32 = mut_ptr as _; + //~^ ptr_as_ptr // Make sure the lint is triggered inside a macro let _ = inline!($ptr as *const i32); + //~^ ptr_as_ptr // Do not lint inside macros from external crates let _ = external!($ptr as *const i32); @@ -69,7 +76,9 @@ fn _msrv_1_38() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr as *const i32; + //~^ ptr_as_ptr let _ = mut_ptr as *mut i32; + //~^ ptr_as_ptr } #[allow(clippy::unnecessary_cast)] @@ -77,37 +86,45 @@ mod null { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut() as *mut u32 + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut() as *mut u32 + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut() as *mut u32 + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut() as *mut u32 + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null() as *const u32 + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null() as *const u32 + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null() as *const u32 + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null() as *const u32 + //~^ ptr_as_ptr } } @@ -115,37 +132,45 @@ mod null_ptr_infer { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut() as *mut _ + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut() as *mut _ + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut() as *mut _ + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut() as *mut _ + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null() as *const _ + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null() as *const _ + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null() as *const _ + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null() as *const _ + //~^ ptr_as_ptr } } @@ -153,36 +178,44 @@ mod null_entire_infer { fn use_path_mut() -> *mut u32 { use std::ptr; ptr::null_mut() as _ + //~^ ptr_as_ptr } fn full_path_mut() -> *mut u32 { std::ptr::null_mut() as _ + //~^ ptr_as_ptr } fn core_path_mut() -> *mut u32 { use core::ptr; ptr::null_mut() as _ + //~^ ptr_as_ptr } fn full_core_path_mut() -> *mut u32 { core::ptr::null_mut() as _ + //~^ ptr_as_ptr } fn use_path() -> *const u32 { use std::ptr; ptr::null() as _ + //~^ ptr_as_ptr } fn full_path() -> *const u32 { std::ptr::null() as _ + //~^ ptr_as_ptr } fn core_path() -> *const u32 { use core::ptr; ptr::null() as _ + //~^ ptr_as_ptr } fn full_core_path() -> *const u32 { core::ptr::null() as _ + //~^ ptr_as_ptr } } diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index 18462620b0a3..66dae8e0135e 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -8,37 +8,37 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i = help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:27:13 + --> tests/ui/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 their constness - --> tests/ui/ptr_as_ptr.rs:28:13 + --> tests/ui/ptr_as_ptr.rs:30: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 their constness - --> tests/ui/ptr_as_ptr.rs:33:17 + --> tests/ui/ptr_as_ptr.rs:36: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 their constness - --> tests/ui/ptr_as_ptr.rs:46:25 + --> tests/ui/ptr_as_ptr.rs:50: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 their constness - --> tests/ui/ptr_as_ptr.rs:47:23 + --> tests/ui/ptr_as_ptr.rs:52: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 their constness - --> tests/ui/ptr_as_ptr.rs:50:21 + --> tests/ui/ptr_as_ptr.rs:56:21 | LL | let _ = inline!($ptr as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::()` @@ -46,29 +46,17 @@ 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 their constness - --> tests/ui/ptr_as_ptr.rs:71:13 + --> tests/ui/ptr_as_ptr.rs:78:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:72:13 + --> tests/ui/ptr_as_ptr.rs:80: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 their constness - --> tests/ui/ptr_as_ptr.rs:79:9 - | -LL | ptr::null_mut() as *mut u32 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::()` - -error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:83:9 - | -LL | std::ptr::null_mut() as *mut u32 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::()` - error: `as` casting between raw pointers without changing their constness --> tests/ui/ptr_as_ptr.rs:88:9 | @@ -76,127 +64,139 @@ LL | ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:92:9 + --> tests/ui/ptr_as_ptr.rs:93:9 + | +LL | std::ptr::null_mut() as *mut u32 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut::()` + +error: `as` casting between raw pointers without changing their constness + --> tests/ui/ptr_as_ptr.rs:99:9 + | +LL | ptr::null_mut() as *mut u32 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut::()` + +error: `as` casting between raw pointers without changing their constness + --> tests/ui/ptr_as_ptr.rs:104:9 | LL | core::ptr::null_mut() as *mut u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:97:9 + --> tests/ui/ptr_as_ptr.rs:110:9 | LL | ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:101:9 + --> tests/ui/ptr_as_ptr.rs:115:9 | LL | std::ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:106:9 + --> tests/ui/ptr_as_ptr.rs:121:9 | LL | ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:110:9 + --> tests/ui/ptr_as_ptr.rs:126:9 | LL | core::ptr::null() as *const u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null::()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:117:9 + --> tests/ui/ptr_as_ptr.rs:134:9 | LL | ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:121:9 + --> tests/ui/ptr_as_ptr.rs:139:9 | LL | std::ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:126:9 + --> tests/ui/ptr_as_ptr.rs:145:9 | LL | ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:130:9 + --> tests/ui/ptr_as_ptr.rs:150:9 | LL | core::ptr::null_mut() as *mut _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:135:9 + --> tests/ui/ptr_as_ptr.rs:156:9 | LL | ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:139:9 + --> tests/ui/ptr_as_ptr.rs:161:9 | LL | std::ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:144:9 + --> tests/ui/ptr_as_ptr.rs:167:9 | LL | ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:148:9 + --> tests/ui/ptr_as_ptr.rs:172:9 | LL | core::ptr::null() as *const _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:155:9 + --> tests/ui/ptr_as_ptr.rs:180:9 | LL | ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:159:9 + --> tests/ui/ptr_as_ptr.rs:185:9 | LL | std::ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:164:9 + --> tests/ui/ptr_as_ptr.rs:191:9 | LL | ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:168:9 + --> tests/ui/ptr_as_ptr.rs:196:9 | LL | core::ptr::null_mut() as _ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null_mut()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:173:9 + --> tests/ui/ptr_as_ptr.rs:202:9 | LL | ptr::null() as _ | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:177:9 + --> tests/ui/ptr_as_ptr.rs:207:9 | LL | std::ptr::null() as _ | ^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `std::ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:182:9 + --> tests/ui/ptr_as_ptr.rs:213:9 | LL | ptr::null() as _ | ^^^^^^^^^^^^^^^^ help: try call directly: `ptr::null()` error: `as` casting between raw pointers without changing their constness - --> tests/ui/ptr_as_ptr.rs:186:9 + --> tests/ui/ptr_as_ptr.rs:218:9 | LL | core::ptr::null() as _ | ^^^^^^^^^^^^^^^^^^^^^^ help: try call directly: `core::ptr::null()` diff --git a/tests/ui/ptr_cast_constness.fixed b/tests/ui/ptr_cast_constness.fixed index 9a5272c7adc3..6dded72d3e19 100644 --- a/tests/ui/ptr_cast_constness.fixed +++ b/tests/ui/ptr_cast_constness.fixed @@ -13,7 +13,9 @@ use proc_macros::{external, inline_macros}; unsafe fn ptr_to_ref(p: *const T, om: *mut U) { let _: &mut T = std::mem::transmute(p.cast_mut()); + //~^ ptr_cast_constness let _ = &mut *p.cast_mut(); + //~^ ptr_cast_constness let _: &T = &*(om as *const T); } @@ -29,10 +31,13 @@ fn main() { unsafe { let ptr_ptr: *const *const u32 = &ptr; let _ = (*ptr_ptr).cast_mut(); + //~^ ptr_cast_constness } let _ = ptr.cast_mut(); + //~^ ptr_cast_constness let _ = mut_ptr.cast_const(); + //~^ ptr_cast_constness // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4]; @@ -66,20 +71,28 @@ fn _msrv_1_65() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr.cast_mut(); + //~^ ptr_cast_constness let _ = mut_ptr.cast_const(); + //~^ ptr_cast_constness } #[inline_macros] fn null_pointers() { use std::ptr; let _ = std::ptr::null_mut::(); + //~^ ptr_cast_constness let _ = std::ptr::null::(); + //~^ ptr_cast_constness let _ = std::ptr::null_mut::(); + //~^ ptr_cast_constness let _ = std::ptr::null::(); + //~^ ptr_cast_constness // Make sure the lint is triggered inside a macro let _ = inline!(std::ptr::null_mut::()); + //~^ ptr_cast_constness let _ = inline!(std::ptr::null_mut::()); + //~^ ptr_cast_constness // Do not lint inside macros from external crates let _ = external!(ptr::null::() as *mut u32); diff --git a/tests/ui/ptr_cast_constness.rs b/tests/ui/ptr_cast_constness.rs index 43ab5f5ba7cc..e9629f5290ec 100644 --- a/tests/ui/ptr_cast_constness.rs +++ b/tests/ui/ptr_cast_constness.rs @@ -13,7 +13,9 @@ use proc_macros::{external, inline_macros}; unsafe fn ptr_to_ref(p: *const T, om: *mut U) { let _: &mut T = std::mem::transmute(p as *mut T); + //~^ ptr_cast_constness let _ = &mut *(p as *mut T); + //~^ ptr_cast_constness let _: &T = &*(om as *const T); } @@ -29,10 +31,13 @@ fn main() { unsafe { let ptr_ptr: *const *const u32 = &ptr; let _ = *ptr_ptr as *mut u32; + //~^ ptr_cast_constness } let _ = ptr as *mut u32; + //~^ ptr_cast_constness let _ = mut_ptr as *const u32; + //~^ ptr_cast_constness // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4]; @@ -66,20 +71,28 @@ fn _msrv_1_65() { let mut_ptr: *mut u32 = &mut 42_u32; let _ = ptr as *mut u32; + //~^ ptr_cast_constness let _ = mut_ptr as *const u32; + //~^ ptr_cast_constness } #[inline_macros] fn null_pointers() { use std::ptr; let _ = ptr::null::() as *mut String; + //~^ ptr_cast_constness let _ = ptr::null_mut::() as *const u32; + //~^ ptr_cast_constness let _ = ptr::null::().cast_mut(); + //~^ ptr_cast_constness let _ = ptr::null_mut::().cast_const(); + //~^ ptr_cast_constness // Make sure the lint is triggered inside a macro let _ = inline!(ptr::null::() as *mut u32); + //~^ ptr_cast_constness let _ = inline!(ptr::null::().cast_mut()); + //~^ ptr_cast_constness // Do not lint inside macros from external crates let _ = external!(ptr::null::() as *mut u32); diff --git a/tests/ui/ptr_cast_constness.stderr b/tests/ui/ptr_cast_constness.stderr index a693793a4ae9..1eeeef747013 100644 --- a/tests/ui/ptr_cast_constness.stderr +++ b/tests/ui/ptr_cast_constness.stderr @@ -8,67 +8,67 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); = help: to override `-D warnings` add `#[allow(clippy::ptr_cast_constness)]` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:16:19 + --> tests/ui/ptr_cast_constness.rs:17: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 - --> tests/ui/ptr_cast_constness.rs:31:17 + --> tests/ui/ptr_cast_constness.rs:33:17 | LL | let _ = *ptr_ptr as *mut u32; | ^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(*ptr_ptr).cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:34:13 + --> tests/ui/ptr_cast_constness.rs:37:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:35:13 + --> tests/ui/ptr_cast_constness.rs:39:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:68:13 + --> tests/ui/ptr_cast_constness.rs:73:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:69:13 + --> tests/ui/ptr_cast_constness.rs:75:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` error: `as` casting to make a const null pointer into a mutable null pointer - --> tests/ui/ptr_cast_constness.rs:75:13 + --> tests/ui/ptr_cast_constness.rs:82:13 | LL | let _ = ptr::null::() as *mut String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` error: `as` casting to make a mutable null pointer into a const null pointer - --> tests/ui/ptr_cast_constness.rs:76:13 + --> tests/ui/ptr_cast_constness.rs:84:13 | LL | let _ = ptr::null_mut::() as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null()` directly instead: `std::ptr::null::()` error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:77:13 + --> tests/ui/ptr_cast_constness.rs:86:13 | LL | let _ = ptr::null::().cast_mut(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:78:13 + --> tests/ui/ptr_cast_constness.rs:88:13 | LL | let _ = ptr::null_mut::().cast_const(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null()` directly instead: `std::ptr::null::()` error: `as` casting to make a const null pointer into a mutable null pointer - --> tests/ui/ptr_cast_constness.rs:81:21 + --> tests/ui/ptr_cast_constness.rs:92:21 | LL | let _ = inline!(ptr::null::() as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` @@ -76,7 +76,7 @@ LL | let _ = inline!(ptr::null::() as *mut u32); = note: this error originates in the macro `__inline_mac_fn_null_pointers` (in Nightly builds, run with -Z macro-backtrace for more info) error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:82:21 + --> tests/ui/ptr_cast_constness.rs:94:21 | LL | let _ = inline!(ptr::null::().cast_mut()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` diff --git a/tests/ui/ptr_eq.fixed b/tests/ui/ptr_eq.fixed index 3ae6df18c0a0..1ccd2c2237de 100644 --- a/tests/ui/ptr_eq.fixed +++ b/tests/ui/ptr_eq.fixed @@ -17,7 +17,9 @@ fn main() { let b = &[1, 2, 3]; let _ = std::ptr::eq(a, b); + //~^ ptr_eq let _ = std::ptr::eq(a, b); + //~^ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq.rs b/tests/ui/ptr_eq.rs index 440d5d94a831..0bc58a57fa53 100644 --- a/tests/ui/ptr_eq.rs +++ b/tests/ui/ptr_eq.rs @@ -17,7 +17,9 @@ fn main() { let b = &[1, 2, 3]; let _ = a as *const _ as usize == b as *const _ as usize; + //~^ ptr_eq let _ = a as *const _ == b as *const _; + //~^ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr index bf8c2b5c08fb..8e8b34f26ff7 100644 --- a/tests/ui/ptr_eq.stderr +++ b/tests/ui/ptr_eq.stderr @@ -8,7 +8,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:20:13 + --> tests/ui/ptr_eq.rs:21:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` diff --git a/tests/ui/ptr_eq_no_std.fixed b/tests/ui/ptr_eq_no_std.fixed index 97c8c394c03d..b3e82fae38f3 100644 --- a/tests/ui/ptr_eq_no_std.fixed +++ b/tests/ui/ptr_eq_no_std.fixed @@ -29,7 +29,9 @@ fn main() { let b = &[1, 2, 3]; let _ = core::ptr::eq(a, b); + //~^ ptr_eq let _ = core::ptr::eq(a, b); + //~^ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq_no_std.rs b/tests/ui/ptr_eq_no_std.rs index a7ba9b4d8174..ba78f5ee5f84 100644 --- a/tests/ui/ptr_eq_no_std.rs +++ b/tests/ui/ptr_eq_no_std.rs @@ -29,7 +29,9 @@ fn main() { let b = &[1, 2, 3]; let _ = a as *const _ as usize == b as *const _ as usize; + //~^ ptr_eq let _ = a as *const _ == b as *const _; + //~^ ptr_eq let _ = a.as_ptr() == b as *const _; let _ = a.as_ptr() == b.as_ptr(); diff --git a/tests/ui/ptr_eq_no_std.stderr b/tests/ui/ptr_eq_no_std.stderr index 0463b75b720b..8c7b1ff76661 100644 --- a/tests/ui/ptr_eq_no_std.stderr +++ b/tests/ui/ptr_eq_no_std.stderr @@ -8,7 +8,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `core::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq_no_std.rs:32:13 + --> tests/ui/ptr_eq_no_std.rs:33:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::eq(a, b)` diff --git a/tests/ui/ptr_offset_with_cast.fixed b/tests/ui/ptr_offset_with_cast.fixed index 929512be63d4..4fe9dcf46c35 100644 --- a/tests/ui/ptr_offset_with_cast.fixed +++ b/tests/ui/ptr_offset_with_cast.fixed @@ -10,10 +10,12 @@ fn main() { unsafe { let _ = ptr.add(offset_usize); + //~^ ptr_offset_with_cast let _ = ptr.offset(offset_isize as isize); let _ = ptr.offset(offset_u8 as isize); let _ = ptr.wrapping_add(offset_usize); + //~^ ptr_offset_with_cast let _ = ptr.wrapping_offset(offset_isize as isize); let _ = ptr.wrapping_offset(offset_u8 as isize); } diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs index 146bc27765ad..a1fb892733d3 100644 --- a/tests/ui/ptr_offset_with_cast.rs +++ b/tests/ui/ptr_offset_with_cast.rs @@ -10,10 +10,12 @@ fn main() { unsafe { let _ = ptr.offset(offset_usize as isize); + //~^ ptr_offset_with_cast let _ = ptr.offset(offset_isize as isize); let _ = ptr.offset(offset_u8 as isize); let _ = ptr.wrapping_offset(offset_usize as isize); + //~^ ptr_offset_with_cast let _ = ptr.wrapping_offset(offset_isize as isize); let _ = ptr.wrapping_offset(offset_u8 as isize); } diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr index 87ff10adc946..dcd5e027d182 100644 --- a/tests/ui/ptr_offset_with_cast.stderr +++ b/tests/ui/ptr_offset_with_cast.stderr @@ -8,7 +8,7 @@ LL | let _ = ptr.offset(offset_usize as isize); = help: to override `-D warnings` add `#[allow(clippy::ptr_offset_with_cast)]` error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> tests/ui/ptr_offset_with_cast.rs:16:17 + --> tests/ui/ptr_offset_with_cast.rs:17:17 | LL | let _ = ptr.wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)` diff --git a/tests/ui/pub_use.rs b/tests/ui/pub_use.rs index aef947e406a6..4c2c3dfb30cb 100644 --- a/tests/ui/pub_use.rs +++ b/tests/ui/pub_use.rs @@ -8,7 +8,8 @@ pub mod outer { } // should be linted pub use inner::Test; - //~^ ERROR: using `pub use` + //~^ pub_use + } // should not be linted diff --git a/tests/ui/pub_with_shorthand.fixed b/tests/ui/pub_with_shorthand.fixed index 028209de0666..4036de8bbc0a 100644 --- a/tests/ui/pub_with_shorthand.fixed +++ b/tests/ui/pub_with_shorthand.fixed @@ -11,14 +11,18 @@ extern crate proc_macros; pub(in self) fn a() {} +//~^ pub_with_shorthand pub(in self) fn b() {} pub fn c() {} mod a { pub(in super) fn d() {} pub(in super) fn e() {} + //~^ pub_with_shorthand pub(in self) fn f() {} + //~^ pub_with_shorthand pub(in crate) fn k() {} + //~^ pub_with_shorthand pub(in crate) fn m() {} mod b { pub(in crate::a) fn l() {} diff --git a/tests/ui/pub_with_shorthand.rs b/tests/ui/pub_with_shorthand.rs index 8578e3e0c434..fac4ba990447 100644 --- a/tests/ui/pub_with_shorthand.rs +++ b/tests/ui/pub_with_shorthand.rs @@ -11,14 +11,18 @@ extern crate proc_macros; pub(self) fn a() {} +//~^ pub_with_shorthand pub(in self) fn b() {} pub fn c() {} mod a { pub(in super) fn d() {} pub(super) fn e() {} + //~^ pub_with_shorthand pub(self) fn f() {} + //~^ pub_with_shorthand pub(crate) fn k() {} + //~^ pub_with_shorthand pub(in crate) fn m() {} mod b { pub(in crate::a) fn l() {} diff --git a/tests/ui/pub_with_shorthand.stderr b/tests/ui/pub_with_shorthand.stderr index 8978244c4c04..00a3fc28ecb6 100644 --- a/tests/ui/pub_with_shorthand.stderr +++ b/tests/ui/pub_with_shorthand.stderr @@ -8,19 +8,19 @@ LL | pub(self) fn a() {} = help: to override `-D warnings` add `#[allow(clippy::pub_with_shorthand)]` error: usage of `pub` without `in` - --> tests/ui/pub_with_shorthand.rs:19:5 + --> tests/ui/pub_with_shorthand.rs:20:5 | LL | pub(super) fn e() {} | ^^^^^^^^^^ help: add it: `pub(in super)` error: usage of `pub` without `in` - --> tests/ui/pub_with_shorthand.rs:20:5 + --> tests/ui/pub_with_shorthand.rs:22:5 | LL | pub(self) fn f() {} | ^^^^^^^^^ help: add it: `pub(in self)` error: usage of `pub` without `in` - --> tests/ui/pub_with_shorthand.rs:21:5 + --> tests/ui/pub_with_shorthand.rs:24:5 | LL | pub(crate) fn k() {} | ^^^^^^^^^^ help: add it: `pub(in crate)` diff --git a/tests/ui/pub_without_shorthand.fixed b/tests/ui/pub_without_shorthand.fixed index 715e86c17645..fbe3326400cb 100644 --- a/tests/ui/pub_without_shorthand.fixed +++ b/tests/ui/pub_without_shorthand.fixed @@ -12,14 +12,17 @@ extern crate proc_macros; pub(self) fn a() {} pub(self) fn b() {} +//~^ pub_without_shorthand pub fn c() {} mod a { pub(super) fn d() {} + //~^ pub_without_shorthand pub(super) fn e() {} pub(self) fn f() {} pub(crate) fn k() {} pub(crate) fn m() {} + //~^ pub_without_shorthand mod b { pub(in crate::a) fn l() {} } diff --git a/tests/ui/pub_without_shorthand.rs b/tests/ui/pub_without_shorthand.rs index ed2fd6f0f617..fb756096c9d9 100644 --- a/tests/ui/pub_without_shorthand.rs +++ b/tests/ui/pub_without_shorthand.rs @@ -12,14 +12,17 @@ extern crate proc_macros; pub(self) fn a() {} pub(in self) fn b() {} +//~^ pub_without_shorthand pub fn c() {} mod a { pub(in super) fn d() {} + //~^ pub_without_shorthand pub(super) fn e() {} pub(self) fn f() {} pub(crate) fn k() {} pub(in crate) fn m() {} + //~^ pub_without_shorthand mod b { pub(in crate::a) fn l() {} } diff --git a/tests/ui/pub_without_shorthand.stderr b/tests/ui/pub_without_shorthand.stderr index e37c731732ba..c823af6432de 100644 --- a/tests/ui/pub_without_shorthand.stderr +++ b/tests/ui/pub_without_shorthand.stderr @@ -8,13 +8,13 @@ LL | pub(in self) fn b() {} = help: to override `-D warnings` add `#[allow(clippy::pub_without_shorthand)]` error: usage of `pub` with `in` - --> tests/ui/pub_without_shorthand.rs:18:5 + --> tests/ui/pub_without_shorthand.rs:19:5 | LL | pub(in super) fn d() {} | ^^^^^^^^^^^^^ help: remove it: `pub(super)` error: usage of `pub` with `in` - --> tests/ui/pub_without_shorthand.rs:22:5 + --> tests/ui/pub_without_shorthand.rs:24:5 | LL | pub(in crate) fn m() {} | ^^^^^^^^^^^^^ help: remove it: `pub(crate)` diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index b6e148e9f772..8dfef3202be9 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -141,6 +141,7 @@ fn func_returning_result() -> Result { fn result_func(x: Result) -> Result { let _ = x?; + //~^ question_mark x?; @@ -371,5 +372,6 @@ fn issue12412(foo: &Foo, bar: &Bar) -> Option<()> { }; // lint let v = bar.foo.owned.clone()?; + //~^^^ question_mark Some(()) } diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index 48dc9eb0a626..609a4d3251e7 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -5,6 +5,7 @@ fn some_func(a: Option) -> Option { if a.is_none() { + //~^ question_mark return None; } @@ -50,20 +51,24 @@ impl CopyStruct { #[rustfmt::skip] pub fn func(&self) -> Option { if (self.opt).is_none() { + //~^ question_mark return None; } if self.opt.is_none() { + //~^ question_mark return None } let _ = if self.opt.is_none() { + //~^ question_mark return None; } else { self.opt }; let _ = if let Some(x) = self.opt { + //~^ question_mark x } else { return None; @@ -81,6 +86,7 @@ pub struct MoveStruct { impl MoveStruct { pub fn ref_func(&self) -> Option> { if self.opt.is_none() { + //~^ question_mark return None; } @@ -89,6 +95,7 @@ impl MoveStruct { pub fn mov_func_reuse(self) -> Option> { if self.opt.is_none() { + //~^ question_mark return None; } @@ -97,6 +104,7 @@ impl MoveStruct { pub fn mov_func_no_use(self) -> Option> { if self.opt.is_none() { + //~^ question_mark return None; } Some(Vec::new()) @@ -104,6 +112,7 @@ impl MoveStruct { pub fn if_let_ref_func(self) -> Option> { let v: &Vec<_> = if let Some(ref v) = self.opt { + //~^ question_mark v } else { return None; @@ -114,6 +123,7 @@ impl MoveStruct { pub fn if_let_mov_func(self) -> Option> { let v = if let Some(v) = self.opt { + //~^ question_mark v } else { return None; @@ -135,10 +145,12 @@ fn func() -> Option { } if f().is_none() { + //~^ question_mark return None; } let _val = match f() { + //~^ question_mark Some(val) => val, None => return None, }; @@ -149,11 +161,13 @@ fn func() -> Option { }; match f() { + //~^ question_mark Some(val) => val, None => return None, }; match opt_none!() { + //~^ question_mark Some(x) => x, None => return None, }; @@ -180,17 +194,21 @@ fn func_returning_result() -> Result { fn result_func(x: Result) -> Result { let _ = if let Ok(x) = x { x } else { return x }; + //~^ question_mark if x.is_err() { + //~^ question_mark return x; } let _val = match func_returning_result() { + //~^ question_mark Ok(val) => val, Err(err) => return Err(err), }; match func_returning_result() { + //~^ question_mark Ok(val) => val, Err(err) => return Err(err), }; @@ -282,6 +300,7 @@ fn do_something() {} fn err_immediate_return() -> Result { if let Err(err) = func_returning_result() { + //~^ question_mark return Err(err); } Ok(1) @@ -289,6 +308,7 @@ fn err_immediate_return() -> Result { fn err_immediate_return_and_do_something() -> Result { if let Err(err) = func_returning_result() { + //~^ question_mark return Err(err); } do_something(); @@ -366,6 +386,7 @@ fn issue6828_nested_body() -> Option { try { fn f2(a: Option) -> Option { if a.is_none() { + //~^ question_mark return None; // do lint here, the outer `try` is not relevant here // https://github.com/rust-lang/rust-clippy/pull/11001#issuecomment-1610636867 @@ -428,5 +449,6 @@ fn issue12412(foo: &Foo, bar: &Bar) -> Option<()> { let Some(v) = bar.foo.owned.clone() else { return None; }; + //~^^^ question_mark Some(()) } diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 06a8bd0de349..c4db0fbc3022 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -2,6 +2,7 @@ error: this block may be rewritten with the `?` operator --> tests/ui/question_mark.rs:7:5 | LL | / if a.is_none() { +LL | | LL | | return None; LL | | } | |_____^ help: replace it with: `a?;` @@ -10,26 +11,29 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:52:9 + --> tests/ui/question_mark.rs:53:9 | LL | / if (self.opt).is_none() { +LL | | LL | | return None; LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:56:9 + --> tests/ui/question_mark.rs:58:9 | LL | / if self.opt.is_none() { +LL | | LL | | return None LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:60:17 + --> tests/ui/question_mark.rs:63:17 | LL | let _ = if self.opt.is_none() { | _________________^ +LL | | LL | | return None; LL | | } else { LL | | self.opt @@ -37,10 +41,11 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:66:17 + --> tests/ui/question_mark.rs:70:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ +LL | | LL | | x LL | | } else { LL | | return None; @@ -48,34 +53,38 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:83:9 + --> tests/ui/question_mark.rs:88:9 | LL | / if self.opt.is_none() { +LL | | LL | | return None; LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:91:9 + --> tests/ui/question_mark.rs:97:9 | LL | / if self.opt.is_none() { +LL | | LL | | return None; LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:99:9 + --> tests/ui/question_mark.rs:106:9 | LL | / if self.opt.is_none() { +LL | | LL | | return None; LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:106:26 + --> tests/ui/question_mark.rs:114:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ +LL | | LL | | v LL | | } else { LL | | return None; @@ -83,10 +92,11 @@ LL | | }; | |_________^ help: replace it with: `self.opt.as_ref()?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:116:17 + --> tests/ui/question_mark.rs:125:17 | LL | let v = if let Some(v) = self.opt { | _________________^ +LL | | LL | | v LL | | } else { LL | | return None; @@ -94,101 +104,111 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:137:5 + --> tests/ui/question_mark.rs:147:5 | LL | / if f().is_none() { +LL | | LL | | return None; LL | | } | |_____^ help: replace it with: `f()?;` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:141:16 + --> tests/ui/question_mark.rs:152:16 | LL | let _val = match f() { | ________________^ +LL | | LL | | Some(val) => val, LL | | None => return None, LL | | }; | |_____^ help: try instead: `f()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:151:5 + --> tests/ui/question_mark.rs:163:5 | LL | / match f() { +LL | | LL | | Some(val) => val, LL | | None => return None, LL | | }; | |_____^ help: try instead: `f()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:156:5 + --> tests/ui/question_mark.rs:169:5 | LL | / match opt_none!() { +LL | | LL | | Some(x) => x, LL | | None => return None, LL | | }; | |_____^ help: try instead: `opt_none!()?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:182:13 + --> tests/ui/question_mark.rs:196:13 | LL | let _ = if let Ok(x) = x { x } else { return x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:184:5 + --> tests/ui/question_mark.rs:199:5 | LL | / if x.is_err() { +LL | | LL | | return x; LL | | } | |_____^ help: replace it with: `x?;` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:188:16 + --> tests/ui/question_mark.rs:204:16 | LL | let _val = match func_returning_result() { | ________________^ +LL | | LL | | Ok(val) => val, LL | | Err(err) => return Err(err), LL | | }; | |_____^ help: try instead: `func_returning_result()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:193:5 + --> tests/ui/question_mark.rs:210:5 | LL | / match func_returning_result() { +LL | | LL | | Ok(val) => val, LL | | Err(err) => return Err(err), LL | | }; | |_____^ help: try instead: `func_returning_result()?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:284:5 + --> tests/ui/question_mark.rs:302:5 | LL | / if let Err(err) = func_returning_result() { +LL | | LL | | return Err(err); LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:291:5 + --> tests/ui/question_mark.rs:310:5 | LL | / if let Err(err) = func_returning_result() { +LL | | LL | | return Err(err); LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:368:13 + --> tests/ui/question_mark.rs:388:13 | LL | / if a.is_none() { +LL | | LL | | return None; ... | LL | | } | |_____________^ help: replace it with: `a?;` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:428:5 + --> tests/ui/question_mark.rs:449:5 | LL | / let Some(v) = bar.foo.owned.clone() else { LL | | return None; diff --git a/tests/ui/question_mark_used.rs b/tests/ui/question_mark_used.rs index 715d7fab8eed..9e204d1e9f3c 100644 --- a/tests/ui/question_mark_used.rs +++ b/tests/ui/question_mark_used.rs @@ -9,7 +9,8 @@ fn other_function() -> Option { fn my_function() -> Option { other_function()?; - //~^ ERROR: question mark operator was used + //~^ question_mark_used + None } diff --git a/tests/ui/range.fixed b/tests/ui/range.fixed index 82aa1b5f94fd..0e951d88091b 100644 --- a/tests/ui/range.fixed +++ b/tests/ui/range.fixed @@ -4,7 +4,8 @@ fn main() { let v1 = vec![1, 2, 3]; let v2 = vec![4, 5]; let _x = v1.iter().enumerate(); - //~^ ERROR: using `.zip()` with a range and `.len()` + //~^ range_zip_with_len + let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/tests/ui/range.rs b/tests/ui/range.rs index a7d5cf38dfb5..534380164743 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -4,7 +4,8 @@ fn main() { let v1 = vec![1, 2, 3]; let v2 = vec![4, 5]; let _x = v1.iter().zip(0..v1.len()); - //~^ ERROR: using `.zip()` with a range and `.len()` + //~^ range_zip_with_len + let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed index ed248df374d1..19d6165e9820 100644 --- a/tests/ui/range_contains.fixed +++ b/tests/ui/range_contains.fixed @@ -11,23 +11,35 @@ fn main() { // order shouldn't matter (8..12).contains(&x); + //~^ manual_range_contains (21..42).contains(&x); + //~^ manual_range_contains (1..100).contains(&x); + //~^ manual_range_contains // also with inclusive ranges (9..=99).contains(&x); + //~^ manual_range_contains (1..=33).contains(&x); + //~^ manual_range_contains (1..=999).contains(&x); + //~^ manual_range_contains // and the outside !(8..12).contains(&x); + //~^ manual_range_contains !(21..42).contains(&x); + //~^ manual_range_contains !(1..100).contains(&x); + //~^ manual_range_contains // also with the outside of inclusive ranges !(9..=99).contains(&x); + //~^ manual_range_contains !(1..=33).contains(&x); + //~^ manual_range_contains !(1..=999).contains(&x); + //~^ manual_range_contains // not a range.contains x > 8 && x < 12; // lower bound not inclusive @@ -43,18 +55,26 @@ fn main() { // Fix #6315 let y = 3.; (0. ..1.).contains(&y); + //~^ manual_range_contains !(0. ..=1.).contains(&y); + //~^ manual_range_contains // handle negatives #8721 (-10..=10).contains(&x); + //~^ manual_range_contains x >= 10 && x <= -10; (-3. ..=3.).contains(&y); + //~^ manual_range_contains y >= 3. && y <= -3.; // Fix #8745 let z = 42; (0..=10).contains(&x) && (0..=10).contains(&z); + //~^ manual_range_contains + //~| manual_range_contains !(0..10).contains(&x) || !(0..10).contains(&z); + //~^ manual_range_contains + //~| manual_range_contains // Make sure operators in parens don't give a breaking suggestion ((x % 2 == 0) || (x < 0)) || (x >= 10); } @@ -74,4 +94,5 @@ fn msrv_1_34() { fn msrv_1_35() { let x = 5; (8..35).contains(&x); + //~^ manual_range_contains } diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs index c3188ec6d92b..80bf40806697 100644 --- a/tests/ui/range_contains.rs +++ b/tests/ui/range_contains.rs @@ -11,23 +11,35 @@ fn main() { // order shouldn't matter x >= 8 && x < 12; + //~^ manual_range_contains x < 42 && x >= 21; + //~^ manual_range_contains 100 > x && 1 <= x; + //~^ manual_range_contains // also with inclusive ranges x >= 9 && x <= 99; + //~^ manual_range_contains x <= 33 && x >= 1; + //~^ manual_range_contains 999 >= x && 1 <= x; + //~^ manual_range_contains // and the outside x < 8 || x >= 12; + //~^ manual_range_contains x >= 42 || x < 21; + //~^ manual_range_contains 100 <= x || 1 > x; + //~^ manual_range_contains // also with the outside of inclusive ranges x < 9 || x > 99; + //~^ manual_range_contains x > 33 || x < 1; + //~^ manual_range_contains 999 < x || 1 > x; + //~^ manual_range_contains // not a range.contains x > 8 && x < 12; // lower bound not inclusive @@ -43,18 +55,26 @@ fn main() { // Fix #6315 let y = 3.; y >= 0. && y < 1.; + //~^ manual_range_contains y < 0. || y > 1.; + //~^ manual_range_contains // handle negatives #8721 x >= -10 && x <= 10; + //~^ manual_range_contains x >= 10 && x <= -10; y >= -3. && y <= 3.; + //~^ manual_range_contains y >= 3. && y <= -3.; // Fix #8745 let z = 42; (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); + //~^ manual_range_contains + //~| manual_range_contains (x < 0) || (x >= 10) || (z < 0) || (z >= 10); + //~^ manual_range_contains + //~| manual_range_contains // Make sure operators in parens don't give a breaking suggestion ((x % 2 == 0) || (x < 0)) || (x >= 10); } @@ -74,4 +94,5 @@ fn msrv_1_34() { fn msrv_1_35() { let x = 5; x >= 8 && x < 35; + //~^ manual_range_contains } diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr index 58ed1292ac7c..67bd5aad093d 100644 --- a/tests/ui/range_contains.stderr +++ b/tests/ui/range_contains.stderr @@ -8,121 +8,121 @@ LL | x >= 8 && x < 12; = help: to override `-D warnings` add `#[allow(clippy::manual_range_contains)]` error: manual `Range::contains` implementation - --> tests/ui/range_contains.rs:14:5 + --> tests/ui/range_contains.rs:15:5 | LL | x < 42 && x >= 21; | ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)` error: manual `Range::contains` implementation - --> tests/ui/range_contains.rs:15:5 + --> tests/ui/range_contains.rs:17:5 | LL | 100 > x && 1 <= x; | ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:18:5 + --> tests/ui/range_contains.rs:21:5 | LL | x >= 9 && x <= 99; | ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:19:5 + --> tests/ui/range_contains.rs:23:5 | LL | x <= 33 && x >= 1; | ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:20:5 + --> tests/ui/range_contains.rs:25:5 | LL | 999 >= x && 1 <= x; | ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)` error: manual `!Range::contains` implementation - --> tests/ui/range_contains.rs:23:5 + --> tests/ui/range_contains.rs:29:5 | LL | x < 8 || x >= 12; | ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)` error: manual `!Range::contains` implementation - --> tests/ui/range_contains.rs:24:5 + --> tests/ui/range_contains.rs:31:5 | LL | x >= 42 || x < 21; | ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)` error: manual `!Range::contains` implementation - --> tests/ui/range_contains.rs:25:5 + --> tests/ui/range_contains.rs:33:5 | LL | 100 <= x || 1 > x; | ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:28:5 + --> tests/ui/range_contains.rs:37:5 | LL | x < 9 || x > 99; | ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:29:5 + --> tests/ui/range_contains.rs:39:5 | LL | x > 33 || x < 1; | ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:30:5 + --> tests/ui/range_contains.rs:41:5 | LL | 999 < x || 1 > x; | ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)` error: manual `Range::contains` implementation - --> tests/ui/range_contains.rs:45:5 + --> tests/ui/range_contains.rs:57:5 | LL | y >= 0. && y < 1.; | ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)` error: manual `!RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:46:5 + --> tests/ui/range_contains.rs:59:5 | LL | y < 0. || y > 1.; | ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:49:5 + --> tests/ui/range_contains.rs:63:5 | LL | x >= -10 && x <= 10; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:51:5 + --> tests/ui/range_contains.rs:66:5 | LL | y >= -3. && y <= 3.; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:56:30 + --> tests/ui/range_contains.rs:72:30 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)` error: manual `RangeInclusive::contains` implementation - --> tests/ui/range_contains.rs:56:5 + --> tests/ui/range_contains.rs:72:5 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)` error: manual `!Range::contains` implementation - --> tests/ui/range_contains.rs:57:29 + --> tests/ui/range_contains.rs:75:29 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)` error: manual `!Range::contains` implementation - --> tests/ui/range_contains.rs:57:5 + --> tests/ui/range_contains.rs:75:5 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)` error: manual `Range::contains` implementation - --> tests/ui/range_contains.rs:76:5 + --> tests/ui/range_contains.rs:96: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 e701dde86933..ee716ef3a6a0 100644 --- a/tests/ui/range_plus_minus_one.fixed +++ b/tests/ui/range_plus_minus_one.fixed @@ -27,29 +27,38 @@ fn main() { for _ in 0..=2 {} for _ in 0..=3 {} + //~^ range_plus_one for _ in 0..=3 + 1 {} for _ in 0..=5 {} + //~^ range_plus_one for _ in 0..=1 + 5 {} for _ in 1..=1 {} + //~^ range_plus_one for _ in 1..=1 + 1 {} for _ in 0..13 + 13 {} for _ in 0..=13 - 7 {} for _ in 0..=f() {} + //~^ range_plus_one for _ in 0..=(1 + f()) {} let _ = ..11 - 1; let _ = ..11; + //~^ range_minus_one let _ = ..11; + //~^ range_minus_one let _ = (1..=11); + //~^ range_plus_one let _ = ((f() + 1)..=f()); + //~^ range_plus_one const ONE: usize = 1; // integer consts are linted, too for _ in 1..=ONE {} + //~^ range_plus_one let mut vec: Vec<()> = std::vec::Vec::new(); vec.drain(..); diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs index 7057fa8e3f0d..f2d5ae2c1506 100644 --- a/tests/ui/range_plus_minus_one.rs +++ b/tests/ui/range_plus_minus_one.rs @@ -27,29 +27,38 @@ fn main() { for _ in 0..=2 {} for _ in 0..3 + 1 {} + //~^ range_plus_one for _ in 0..=3 + 1 {} for _ in 0..1 + 5 {} + //~^ range_plus_one for _ in 0..=1 + 5 {} for _ in 1..1 + 1 {} + //~^ range_plus_one for _ in 1..=1 + 1 {} for _ in 0..13 + 13 {} for _ in 0..=13 - 7 {} for _ in 0..(1 + f()) {} + //~^ range_plus_one for _ in 0..=(1 + f()) {} let _ = ..11 - 1; let _ = ..=11 - 1; + //~^ range_minus_one let _ = ..=(11 - 1); + //~^ range_minus_one let _ = (1..11 + 1); + //~^ range_plus_one let _ = (f() + 1)..(f() + 1); + //~^ range_plus_one const ONE: usize = 1; // integer consts are linted, too for _ in 1..ONE + ONE {} + //~^ range_plus_one let mut vec: Vec<()> = std::vec::Vec::new(); vec.drain(..); diff --git a/tests/ui/range_plus_minus_one.stderr b/tests/ui/range_plus_minus_one.stderr index 0b1883bc5ff2..9b23a8b8c0b4 100644 --- a/tests/ui/range_plus_minus_one.stderr +++ b/tests/ui/range_plus_minus_one.stderr @@ -8,25 +8,25 @@ LL | for _ in 0..3 + 1 {} = help: to override `-D warnings` add `#[allow(clippy::range_plus_one)]` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:32:14 + --> tests/ui/range_plus_minus_one.rs:33:14 | LL | for _ in 0..1 + 5 {} | ^^^^^^^^ help: use: `0..=5` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:35:14 + --> tests/ui/range_plus_minus_one.rs:37:14 | LL | for _ in 1..1 + 1 {} | ^^^^^^^^ help: use: `1..=1` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:41:14 + --> tests/ui/range_plus_minus_one.rs:44:14 | LL | for _ in 0..(1 + f()) {} | ^^^^^^^^^^^^ help: use: `0..=f()` error: an exclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:45:13 + --> tests/ui/range_plus_minus_one.rs:49:13 | LL | let _ = ..=11 - 1; | ^^^^^^^^^ help: use: `..11` @@ -35,25 +35,25 @@ LL | let _ = ..=11 - 1; = help: to override `-D warnings` add `#[allow(clippy::range_minus_one)]` error: an exclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:46:13 + --> tests/ui/range_plus_minus_one.rs:51:13 | LL | let _ = ..=(11 - 1); | ^^^^^^^^^^^ help: use: `..11` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:47:13 + --> tests/ui/range_plus_minus_one.rs:53:13 | LL | let _ = (1..11 + 1); | ^^^^^^^^^^^ help: use: `(1..=11)` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:48:13 + --> tests/ui/range_plus_minus_one.rs:55:13 | LL | let _ = (f() + 1)..(f() + 1); | ^^^^^^^^^^^^^^^^^^^^ help: use: `((f() + 1)..=f())` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:52:14 + --> tests/ui/range_plus_minus_one.rs:60: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 35ac95a76a91..c71a4072b962 100644 --- a/tests/ui/rc_buffer.fixed +++ b/tests/ui/rc_buffer.fixed @@ -9,18 +9,26 @@ use std::rc::Rc; struct S { // triggers lint bad1: Rc, + //~^ rc_buffer bad2: Rc, + //~^ rc_buffer bad3: Rc<[u8]>, + //~^ rc_buffer bad4: Rc, + //~^ rc_buffer // does not trigger lint good1: Rc>, } // triggers lint fn func_bad1(_: Rc) {} +//~^ rc_buffer fn func_bad2(_: Rc) {} +//~^ rc_buffer fn func_bad3(_: Rc<[u8]>) {} +//~^ rc_buffer fn func_bad4(_: Rc) {} +//~^ rc_buffer // does not trigger lint fn func_good1(_: Rc>) {} diff --git a/tests/ui/rc_buffer.rs b/tests/ui/rc_buffer.rs index e78fb5a6d9d8..686c2644da17 100644 --- a/tests/ui/rc_buffer.rs +++ b/tests/ui/rc_buffer.rs @@ -9,18 +9,26 @@ use std::rc::Rc; struct S { // triggers lint bad1: Rc, + //~^ rc_buffer bad2: Rc, + //~^ rc_buffer bad3: Rc>, + //~^ rc_buffer bad4: Rc, + //~^ rc_buffer // does not trigger lint good1: Rc>, } // triggers lint fn func_bad1(_: Rc) {} +//~^ rc_buffer fn func_bad2(_: Rc) {} +//~^ rc_buffer fn func_bad3(_: Rc>) {} +//~^ rc_buffer fn func_bad4(_: Rc) {} +//~^ rc_buffer // does not trigger lint fn func_good1(_: Rc>) {} diff --git a/tests/ui/rc_buffer.stderr b/tests/ui/rc_buffer.stderr index 922f09288bf3..7500523ab4ac 100644 --- a/tests/ui/rc_buffer.stderr +++ b/tests/ui/rc_buffer.stderr @@ -8,43 +8,43 @@ LL | bad1: Rc, = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:12:11 + --> tests/ui/rc_buffer.rs:13:11 | LL | bad2: Rc, | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:13:11 + --> tests/ui/rc_buffer.rs:15:11 | LL | bad3: Rc>, | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:14:11 + --> tests/ui/rc_buffer.rs:17:11 | LL | bad4: Rc, | ^^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:20:17 + --> tests/ui/rc_buffer.rs:24:17 | LL | fn func_bad1(_: Rc) {} | ^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:21:17 + --> tests/ui/rc_buffer.rs:26:17 | LL | fn func_bad2(_: Rc) {} | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:22:17 + --> tests/ui/rc_buffer.rs:28:17 | LL | fn func_bad3(_: Rc>) {} | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> tests/ui/rc_buffer.rs:23:17 + --> tests/ui/rc_buffer.rs:30: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 0d01c7c476f7..27059e3f2e1f 100644 --- a/tests/ui/rc_buffer_arc.fixed +++ b/tests/ui/rc_buffer_arc.fixed @@ -8,18 +8,26 @@ use std::sync::{Arc, Mutex}; struct S { // triggers lint bad1: Arc, + //~^ rc_buffer bad2: Arc, + //~^ rc_buffer bad3: Arc<[u8]>, + //~^ rc_buffer bad4: Arc, + //~^ rc_buffer // does not trigger lint good1: Arc>, } // triggers lint fn func_bad1(_: Arc) {} +//~^ rc_buffer fn func_bad2(_: Arc) {} +//~^ rc_buffer fn func_bad3(_: Arc<[u8]>) {} +//~^ rc_buffer fn func_bad4(_: Arc) {} +//~^ rc_buffer // does not trigger lint fn func_good1(_: Arc>) {} diff --git a/tests/ui/rc_buffer_arc.rs b/tests/ui/rc_buffer_arc.rs index 61ab16dc1829..5261eae2f26a 100644 --- a/tests/ui/rc_buffer_arc.rs +++ b/tests/ui/rc_buffer_arc.rs @@ -8,18 +8,26 @@ use std::sync::{Arc, Mutex}; struct S { // triggers lint bad1: Arc, + //~^ rc_buffer bad2: Arc, + //~^ rc_buffer bad3: Arc>, + //~^ rc_buffer bad4: Arc, + //~^ rc_buffer // does not trigger lint good1: Arc>, } // triggers lint fn func_bad1(_: Arc) {} +//~^ rc_buffer fn func_bad2(_: Arc) {} +//~^ rc_buffer fn func_bad3(_: Arc>) {} +//~^ rc_buffer fn func_bad4(_: Arc) {} +//~^ rc_buffer // does not trigger lint fn func_good1(_: Arc>) {} diff --git a/tests/ui/rc_buffer_arc.stderr b/tests/ui/rc_buffer_arc.stderr index 5ef5da2f67f8..786715463232 100644 --- a/tests/ui/rc_buffer_arc.stderr +++ b/tests/ui/rc_buffer_arc.stderr @@ -8,43 +8,43 @@ LL | bad1: Arc, = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:11:11 + --> tests/ui/rc_buffer_arc.rs:12:11 | LL | bad2: Arc, | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:12:11 + --> tests/ui/rc_buffer_arc.rs:14:11 | LL | bad3: Arc>, | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:13:11 + --> tests/ui/rc_buffer_arc.rs:16:11 | LL | bad4: Arc, | ^^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:19:17 + --> tests/ui/rc_buffer_arc.rs:23:17 | LL | fn func_bad1(_: Arc) {} | ^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:20:17 + --> tests/ui/rc_buffer_arc.rs:25:17 | LL | fn func_bad2(_: Arc) {} | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:21:17 + --> tests/ui/rc_buffer_arc.rs:27:17 | LL | fn func_bad3(_: Arc>) {} | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> tests/ui/rc_buffer_arc.rs:22:17 + --> tests/ui/rc_buffer_arc.rs:29:17 | LL | fn func_bad4(_: Arc) {} | ^^^^^^^^^^^^^ help: try: `Arc` diff --git a/tests/ui/rc_buffer_redefined_string.rs b/tests/ui/rc_buffer_redefined_string.rs index 5d31a848cf72..49a8ba3e2efb 100644 --- a/tests/ui/rc_buffer_redefined_string.rs +++ b/tests/ui/rc_buffer_redefined_string.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::rc_buffer)] use std::rc::Rc; diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index 1c9e9aa7ef47..3b3e5dc643e1 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -7,8 +7,9 @@ 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 + //~^ rc_clone_in_vec_init + + } fn should_warn_simple_case_with_big_indentation() { @@ -17,16 +18,18 @@ 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 + //~^ rc_clone_in_vec_init + + } } } 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 + //~^ rc_clone_in_vec_init + + std::sync::Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -36,8 +39,9 @@ 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 + //~^ rc_clone_in_vec_init + + 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 1078a97542f2..5d70bfc85363 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:19:21 + --> tests/ui/rc_clone_in_vec_init/arc.rs:20:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,13 +47,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:27:13 + --> tests/ui/rc_clone_in_vec_init/arc.rs:29:13 | LL | let v = vec![ | _____________^ -LL | | -LL | | -LL | | std::sync::Arc::new(Mutex::new({ ... | LL | | 2 LL | | ]; @@ -77,13 +74,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:38:14 + --> tests/ui/rc_clone_in_vec_init/arc.rs:41:14 | LL | let v1 = vec![ | ______________^ -LL | | -LL | | -LL | | Arc::new(Mutex::new({ ... | 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 01cc433cbdae..e93408798585 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -8,8 +8,9 @@ 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 + //~^ rc_clone_in_vec_init + + } fn should_warn_simple_case_with_big_indentation() { @@ -18,16 +19,18 @@ 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 + //~^ rc_clone_in_vec_init + + } } } 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 + //~^ rc_clone_in_vec_init + + std::rc::Rc::new(Mutex::new({ let x = 1; dbg!(x); @@ -37,8 +40,9 @@ 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_clone_in_vec_init + + 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 702266d62d2c..57ea31f9ff89 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:20:21 + --> tests/ui/rc_clone_in_vec_init/rc.rs:21:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,13 +47,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:28:13 + --> tests/ui/rc_clone_in_vec_init/rc.rs:30:13 | LL | let v = vec![ | _____________^ -LL | | -LL | | -LL | | std::rc::Rc::new(Mutex::new({ ... | LL | | 2 LL | | ]; @@ -77,13 +74,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:39:14 + --> tests/ui/rc_clone_in_vec_init/rc.rs:42:14 | LL | let v1 = vec![ | ______________^ -LL | | -LL | | -LL | | Rc::new(Mutex::new({ ... | 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 fd2895d40458..af1ec1601dcf 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -8,18 +8,22 @@ 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 + //~^ rc_clone_in_vec_init + + 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 + //~^ rc_clone_in_vec_init + + 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 + //~^ rc_clone_in_vec_init + + 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 + //~^ rc_clone_in_vec_init + + } fn should_warn_simple_case_with_big_indentation() { @@ -28,19 +32,22 @@ 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 + //~^ rc_clone_in_vec_init + + 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 + //~^ rc_clone_in_vec_init + + } } } 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 + //~^ rc_clone_in_vec_init + + Arc::downgrade(&Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -50,8 +57,9 @@ 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_clone_in_vec_init + + 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 68ca2a7eb848..26974dd7446c 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:13:14 + --> tests/ui/rc_clone_in_vec_init/weak.rs:14:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:17:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:19:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:20:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:23:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -93,7 +93,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:30:21 + --> tests/ui/rc_clone_in_vec_init/weak.rs:34:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -116,7 +116,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:33:22 + --> tests/ui/rc_clone_in_vec_init/weak.rs:38:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,13 +139,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:41:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:47:13 | LL | let v = vec![ | _____________^ -LL | | -LL | | -LL | | Arc::downgrade(&Arc::new(Mutex::new({ ... | LL | | 2 LL | | ]; @@ -169,13 +166,10 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:52:14 + --> tests/ui/rc_clone_in_vec_init/weak.rs:59:14 | LL | let v1 = vec![ | ______________^ -LL | | -LL | | -LL | | Rc::downgrade(&Rc::new(Mutex::new({ ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index 40adb3ddce95..cccbc751f417 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -6,7 +6,7 @@ use std::sync::Mutex; pub struct MyStructWithPrivItem { foo: Rc>, - //~^ ERROR: usage of `Rc>` + //~^ rc_mutex } pub struct MyStructWithPubItem { @@ -25,11 +25,14 @@ 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>` +//~^ rc_mutex + fn test2(foo: Rc>) {} -//~^ ERROR: usage of `Rc>` +//~^ rc_mutex + fn test3(foo: Rc>>) {} -//~^ ERROR: usage of `Rc>` +//~^ rc_mutex + // 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 9aa18336df00..5b589cfa309a 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -17,7 +17,7 @@ LL | fn test1(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> tests/ui/rc_mutex.rs:29:15 + --> tests/ui/rc_mutex.rs:30:15 | LL | fn test2(foo: Rc>) {} | ^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn test2(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> tests/ui/rc_mutex.rs:31:15 + --> tests/ui/rc_mutex.rs:33:15 | LL | fn test3(foo: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/read_line_without_trim.fixed b/tests/ui/read_line_without_trim.fixed index 523ad5552747..9263a398ad85 100644 --- a/tests/ui/read_line_without_trim.fixed +++ b/tests/ui/read_line_without_trim.fixed @@ -10,22 +10,27 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x: i32 = input.trim_end().parse().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.trim_end().parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); @@ -36,12 +41,14 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.trim_end() == "foo" { + //~^ read_line_without_trim println!("This will never ever execute!"); } let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.trim_end().ends_with("foo") { + //~^ read_line_without_trim println!("Neither will this"); } } diff --git a/tests/ui/read_line_without_trim.rs b/tests/ui/read_line_without_trim.rs index e31ff0cde61d..ba5196bb51ba 100644 --- a/tests/ui/read_line_without_trim.rs +++ b/tests/ui/read_line_without_trim.rs @@ -10,22 +10,27 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x: i32 = input.parse().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let _x = input.parse::().unwrap(); + //~^ read_line_without_trim let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); @@ -36,12 +41,14 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input == "foo" { + //~^ read_line_without_trim println!("This will never ever execute!"); } let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.ends_with("foo") { + //~^ read_line_without_trim println!("Neither will this"); } } diff --git a/tests/ui/read_line_without_trim.stderr b/tests/ui/read_line_without_trim.stderr index b54229f762a3..5e5618111432 100644 --- a/tests/ui/read_line_without_trim.stderr +++ b/tests/ui/read_line_without_trim.stderr @@ -15,7 +15,7 @@ LL | std::io::stdin().read_line(&mut input).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::read_line_without_trim)]` error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:16:20 + --> tests/ui/read_line_without_trim.rs:17:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -23,13 +23,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:15:5 + --> tests/ui/read_line_without_trim.rs:16:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:20:20 + --> tests/ui/read_line_without_trim.rs:22:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -37,13 +37,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:19:5 + --> tests/ui/read_line_without_trim.rs:21:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:24:20 + --> tests/ui/read_line_without_trim.rs:27:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -51,13 +51,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:23:5 + --> tests/ui/read_line_without_trim.rs:26:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:28:20 + --> tests/ui/read_line_without_trim.rs:32:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^^ @@ -65,13 +65,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:27:5 + --> tests/ui/read_line_without_trim.rs:31:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: comparing a string literal without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:38:8 + --> tests/ui/read_line_without_trim.rs:43:8 | LL | if input == "foo" { | -----^^^^^^^^^ @@ -79,13 +79,13 @@ LL | if input == "foo" { | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the comparison to always fail - --> tests/ui/read_line_without_trim.rs:37:5 + --> tests/ui/read_line_without_trim.rs:42:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: checking the end of a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:44:8 + --> tests/ui/read_line_without_trim.rs:50:8 | LL | if input.ends_with("foo") { | -----^^^^^^^^^^^^^^^^^ @@ -93,7 +93,7 @@ LL | if input.ends_with("foo") { | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the parsing to always fail - --> tests/ui/read_line_without_trim.rs:43:5 + --> tests/ui/read_line_without_trim.rs:49: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 68acf4334699..938d61b68607 100644 --- a/tests/ui/read_zero_byte_vec.rs +++ b/tests/ui/read_zero_byte_vec.rs @@ -8,6 +8,7 @@ use std::fs::File; use std::io; use std::io::prelude::*; //@no-rustfix +//@require-annotations-for-level: WARN 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/read_zero_byte_vec.stderr b/tests/ui/read_zero_byte_vec.stderr index e2356f1cb56b..8f255bc87ab8 100644 --- a/tests/ui/read_zero_byte_vec.stderr +++ b/tests/ui/read_zero_byte_vec.stderr @@ -1,5 +1,5 @@ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:21:5 + --> tests/ui/read_zero_byte_vec.rs:22:5 | LL | f.read_exact(&mut data).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data.resize(20, 0); f.read_exact(&mut data)` @@ -8,61 +8,61 @@ LL | f.read_exact(&mut data).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::read_zero_byte_vec)]` error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:27:5 + --> tests/ui/read_zero_byte_vec.rs:28: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` - --> tests/ui/read_zero_byte_vec.rs:32:5 + --> tests/ui/read_zero_byte_vec.rs:33:5 | LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:37:13 + --> tests/ui/read_zero_byte_vec.rs:38:13 | LL | let _ = f.read(&mut data4)?; | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:43:9 + --> tests/ui/read_zero_byte_vec.rs:44:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:50:9 + --> tests/ui/read_zero_byte_vec.rs:51:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:84:9 + --> tests/ui/read_zero_byte_vec.rs:85:9 | LL | f.read(&mut v)?; | ^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:94:5 + --> tests/ui/read_zero_byte_vec.rs:95:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:99:5 + --> tests/ui/read_zero_byte_vec.rs:100:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:106:5 + --> tests/ui/read_zero_byte_vec.rs:107:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:111:5 + --> tests/ui/read_zero_byte_vec.rs:112: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 4db13482ac78..21822444f35f 100644 --- a/tests/ui/readonly_write_lock.fixed +++ b/tests/ui/readonly_write_lock.fixed @@ -14,14 +14,16 @@ 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` + //~^ readonly_write_lock + + dbg!(&writer); } { let writer = lock.read().unwrap(); - //~^ ERROR: this write lock is used only for reading + //~^ readonly_write_lock + accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.rs b/tests/ui/readonly_write_lock.rs index 66ba1b2d6969..b3fd1a611cc8 100644 --- a/tests/ui/readonly_write_lock.rs +++ b/tests/ui/readonly_write_lock.rs @@ -14,14 +14,16 @@ 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` + //~^ readonly_write_lock + + dbg!(&writer); } { let writer = lock.write().unwrap(); - //~^ ERROR: this write lock is used only for reading + //~^ readonly_write_lock + accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.stderr b/tests/ui/readonly_write_lock.stderr index 6b1ef3c4720f..a3f88e92bfae 100644 --- a/tests/ui/readonly_write_lock.stderr +++ b/tests/ui/readonly_write_lock.stderr @@ -8,7 +8,7 @@ LL | let writer = lock.write().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::readonly_write_lock)]` error: this write lock is used only for reading - --> tests/ui/readonly_write_lock.rs:23:22 + --> tests/ui/readonly_write_lock.rs:24: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 b3eafc6dad7a..d9b3a15eb9b1 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -29,8 +29,9 @@ 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` + //~^ recursive_format_impl + + } } @@ -75,7 +76,8 @@ 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 + //~^ recursive_format_impl + } } @@ -85,14 +87,16 @@ 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 + //~^ recursive_format_impl + } } 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 + //~^ recursive_format_impl + } } @@ -102,7 +106,8 @@ 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 + //~^ recursive_format_impl + } } @@ -177,14 +182,16 @@ 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 + //~^ recursive_format_impl + } } 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 + //~^ recursive_format_impl + } } @@ -201,7 +208,8 @@ 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 + //~^ recursive_format_impl + } } @@ -218,7 +226,8 @@ 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 + //~^ recursive_format_impl + } } @@ -235,7 +244,8 @@ 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 + //~^ recursive_format_impl + } } diff --git a/tests/ui/recursive_format_impl.stderr b/tests/ui/recursive_format_impl.stderr index f80aff01eb53..515f18d5b477 100644 --- a/tests/ui/recursive_format_impl.stderr +++ b/tests/ui/recursive_format_impl.stderr @@ -8,7 +8,7 @@ LL | write!(f, "{}", self.to_string()) = help: to override `-D warnings` add `#[allow(clippy::recursive_format_impl)]` error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> tests/ui/recursive_format_impl.rs:77:9 + --> tests/ui/recursive_format_impl.rs:78:9 | LL | write!(f, "{}", self) | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,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 - --> tests/ui/recursive_format_impl.rs:87:9 + --> tests/ui/recursive_format_impl.rs:89:9 | LL | write!(f, "{}", &self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,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 - --> tests/ui/recursive_format_impl.rs:94:9 + --> tests/ui/recursive_format_impl.rs:97:9 | LL | write!(f, "{:?}", &self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,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 - --> tests/ui/recursive_format_impl.rs:104:9 + --> tests/ui/recursive_format_impl.rs:108:9 | LL | write!(f, "{}", &&&self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,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 - --> tests/ui/recursive_format_impl.rs:179:9 + --> tests/ui/recursive_format_impl.rs:184:9 | LL | write!(f, "{}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,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 - --> tests/ui/recursive_format_impl.rs:186:9 + --> tests/ui/recursive_format_impl.rs:192:9 | LL | write!(f, "{:?}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,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 - --> tests/ui/recursive_format_impl.rs:203:9 + --> tests/ui/recursive_format_impl.rs:210:9 | LL | write!(f, "{}", *self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,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 - --> tests/ui/recursive_format_impl.rs:220:9 + --> tests/ui/recursive_format_impl.rs:228:9 | LL | write!(f, "{}", **&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,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 - --> tests/ui/recursive_format_impl.rs:237:9 + --> tests/ui/recursive_format_impl.rs:246:9 | LL | write!(f, "{}", &&**&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index e70f8e71fae8..e3bf6c58b153 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -14,24 +14,29 @@ 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 + //~^ redundant_allocation + + pub fn box_test7(foo: Box>) {} - //~^ ERROR: usage of `Box>` - //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation + //~^ redundant_allocation + + pub fn box_test8() -> Box>> { - //~^ ERROR: usage of `Box>>` - //~| NOTE: `Rc>` is already on the heap, `Box>>` makes an e + //~^ redundant_allocation + + 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 + //~^ redundant_allocation + //~| redundant_allocation + + + + unimplemented!(); } } @@ -43,24 +48,29 @@ 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 + //~^ redundant_allocation + + pub fn rc_test7(a: Rc>) {} - //~^ ERROR: usage of `Rc>` - //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocati + //~^ redundant_allocation + + pub fn rc_test8() -> Rc>> { - //~^ ERROR: usage of `Rc>>` - //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an + //~^ redundant_allocation + + 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 + //~^ redundant_allocation + //~| redundant_allocation + + + + unimplemented!(); } } @@ -72,24 +82,29 @@ 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 + //~^ redundant_allocation + + pub fn arc_test6(a: Arc>) {} - //~^ ERROR: usage of `Arc>` - //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocatio + //~^ redundant_allocation + + pub fn arc_test8() -> Arc>> { - //~^ ERROR: usage of `Arc>>` - //~| NOTE: `Box>` is already on the heap, `Arc>>` makes an + //~^ redundant_allocation + + 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 + //~^ redundant_allocation + //~| redundant_allocation + + + + unimplemented!(); } } @@ -112,8 +127,9 @@ 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 + //~^ redundant_allocation + + } // https://github.com/rust-lang/rust-clippy/issues/8604 @@ -146,17 +162,21 @@ 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 + //~^ redundant_allocation + + pub fn test_rc_box_slice(_: Rc>>) {} - //~^ ERROR: usage of `Rc>>` - //~| NOTE: `Box>` is already on the heap, `Rc>>` makes a + //~^ redundant_allocation + + pub fn test_rc_box_path(_: Rc>>) {} - //~^ ERROR: usage of `Rc>>` - //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extr + //~^ redundant_allocation + + pub fn test_rc_box_custom(_: Rc>>) {} - //~^ ERROR: usage of `Rc>>` - //~| NOTE: `Box>` is already on the heap, `Rc>>` makes + //~^ redundant_allocation + + } // https://github.com/rust-lang/rust-clippy/issues/11417 diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index 8a043013e07a..407cdef1c20d 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -10,7 +10,7 @@ LL | pub fn box_test6(foo: Box>) {} = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:20:30 + --> tests/ui/redundant_allocation.rs:21:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:24:27 + --> tests/ui/redundant_allocation.rs:26:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:30:30 + --> tests/ui/redundant_allocation.rs:33:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:30:46 + --> tests/ui/redundant_allocation.rs:33:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:45:24 + --> tests/ui/redundant_allocation.rs:50:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:49:24 + --> tests/ui/redundant_allocation.rs:55:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:53:26 + --> tests/ui/redundant_allocation.rs:60:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:59:29 + --> tests/ui/redundant_allocation.rs:67:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:59:44 + --> tests/ui/redundant_allocation.rs:67:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:74:25 + --> tests/ui/redundant_allocation.rs:84:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:78:25 + --> tests/ui/redundant_allocation.rs:89:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:82:27 + --> tests/ui/redundant_allocation.rs:94:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:88:30 + --> tests/ui/redundant_allocation.rs:101:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -127,7 +127,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:88:45 + --> tests/ui/redundant_allocation.rs:101:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:114:27 + --> tests/ui/redundant_allocation.rs:129:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:148:31 + --> tests/ui/redundant_allocation.rs:164:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:151:33 + --> tests/ui/redundant_allocation.rs:168:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:154:32 + --> tests/ui/redundant_allocation.rs:172:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -172,7 +172,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:157:34 + --> tests/ui/redundant_allocation.rs:176:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation_fixable.fixed b/tests/ui/redundant_allocation_fixable.fixed index 61c989c67a1a..7773ba11f973 100644 --- a/tests/ui/redundant_allocation_fixable.fixed +++ b/tests/ui/redundant_allocation_fixable.fixed @@ -21,14 +21,18 @@ mod outer_box { use std::sync::Arc; pub fn box_test1(foo: &T) {} + //~^ redundant_allocation pub fn box_test2(foo: &MyStruct) {} + //~^ redundant_allocation pub fn box_test3(foo: &MyEnum) {} + //~^ redundant_allocation pub fn box_test4_neg(foo: Box>) {} pub fn box_test5(foo: Box) {} + //~^ redundant_allocation } mod outer_rc { @@ -38,14 +42,18 @@ mod outer_rc { use std::sync::Arc; pub fn rc_test1(foo: &T) {} + //~^ redundant_allocation pub fn rc_test2(foo: &MyStruct) {} + //~^ redundant_allocation pub fn rc_test3(foo: &MyEnum) {} + //~^ redundant_allocation pub fn rc_test4_neg(foo: Rc>) {} pub fn rc_test6(a: Rc) {} + //~^ redundant_allocation } mod outer_arc { @@ -55,14 +63,18 @@ mod outer_arc { use std::sync::Arc; pub fn arc_test1(foo: &T) {} + //~^ redundant_allocation pub fn arc_test2(foo: &MyStruct) {} + //~^ redundant_allocation pub fn arc_test3(foo: &MyEnum) {} + //~^ redundant_allocation pub fn arc_test4_neg(foo: Arc>) {} pub fn arc_test7(a: Arc) {} + //~^ redundant_allocation } fn main() {} diff --git a/tests/ui/redundant_allocation_fixable.rs b/tests/ui/redundant_allocation_fixable.rs index 3ad1e9a978df..fb86ed2b3cfd 100644 --- a/tests/ui/redundant_allocation_fixable.rs +++ b/tests/ui/redundant_allocation_fixable.rs @@ -21,14 +21,18 @@ mod outer_box { use std::sync::Arc; pub fn box_test1(foo: Box<&T>) {} + //~^ redundant_allocation pub fn box_test2(foo: Box<&MyStruct>) {} + //~^ redundant_allocation pub fn box_test3(foo: Box<&MyEnum>) {} + //~^ redundant_allocation pub fn box_test4_neg(foo: Box>) {} pub fn box_test5(foo: Box>) {} + //~^ redundant_allocation } mod outer_rc { @@ -38,14 +42,18 @@ mod outer_rc { use std::sync::Arc; pub fn rc_test1(foo: Rc<&T>) {} + //~^ redundant_allocation pub fn rc_test2(foo: Rc<&MyStruct>) {} + //~^ redundant_allocation pub fn rc_test3(foo: Rc<&MyEnum>) {} + //~^ redundant_allocation pub fn rc_test4_neg(foo: Rc>) {} pub fn rc_test6(a: Rc>) {} + //~^ redundant_allocation } mod outer_arc { @@ -55,14 +63,18 @@ mod outer_arc { use std::sync::Arc; pub fn arc_test1(foo: Arc<&T>) {} + //~^ redundant_allocation pub fn arc_test2(foo: Arc<&MyStruct>) {} + //~^ redundant_allocation pub fn arc_test3(foo: Arc<&MyEnum>) {} + //~^ redundant_allocation pub fn arc_test4_neg(foo: Arc>) {} pub fn arc_test7(a: Arc>) {} + //~^ redundant_allocation } fn main() {} diff --git a/tests/ui/redundant_allocation_fixable.stderr b/tests/ui/redundant_allocation_fixable.stderr index 34a1a21bdadc..ed8282cc82ce 100644 --- a/tests/ui/redundant_allocation_fixable.stderr +++ b/tests/ui/redundant_allocation_fixable.stderr @@ -9,7 +9,7 @@ LL | pub fn box_test1(foo: Box<&T>) {} = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box<&MyStruct>` - --> tests/ui/redundant_allocation_fixable.rs:25:27 + --> tests/ui/redundant_allocation_fixable.rs:26:27 | LL | pub fn box_test2(foo: Box<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -17,7 +17,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>` - --> tests/ui/redundant_allocation_fixable.rs:27:27 + --> tests/ui/redundant_allocation_fixable.rs:29:27 | LL | pub fn box_test3(foo: Box<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -25,7 +25,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>` - --> tests/ui/redundant_allocation_fixable.rs:31:30 + --> tests/ui/redundant_allocation_fixable.rs:34:30 | LL | pub fn box_test5(foo: Box>) {} | ^^^^^^^^^^^ help: try: `Box` @@ -33,7 +33,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>` - --> tests/ui/redundant_allocation_fixable.rs:40:29 + --> tests/ui/redundant_allocation_fixable.rs:44:29 | LL | pub fn rc_test1(foo: Rc<&T>) {} | ^^^^^^ help: try: `&T` @@ -41,7 +41,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>` - --> tests/ui/redundant_allocation_fixable.rs:42:26 + --> tests/ui/redundant_allocation_fixable.rs:47:26 | LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} | ^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -49,7 +49,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>` - --> tests/ui/redundant_allocation_fixable.rs:44:26 + --> tests/ui/redundant_allocation_fixable.rs:50:26 | LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} | ^^^^^^^^^^^ help: try: `&MyEnum` @@ -57,7 +57,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>` - --> tests/ui/redundant_allocation_fixable.rs:48:24 + --> tests/ui/redundant_allocation_fixable.rs:55:24 | LL | pub fn rc_test6(a: Rc>) {} | ^^^^^^^^^^^^ help: try: `Rc` @@ -65,7 +65,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>` - --> tests/ui/redundant_allocation_fixable.rs:57:30 + --> tests/ui/redundant_allocation_fixable.rs:65:30 | LL | pub fn arc_test1(foo: Arc<&T>) {} | ^^^^^^^ help: try: `&T` @@ -73,7 +73,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>` - --> tests/ui/redundant_allocation_fixable.rs:59:27 + --> tests/ui/redundant_allocation_fixable.rs:68:27 | LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -81,7 +81,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>` - --> tests/ui/redundant_allocation_fixable.rs:61:27 + --> tests/ui/redundant_allocation_fixable.rs:71:27 | LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -89,7 +89,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>` - --> tests/ui/redundant_allocation_fixable.rs:65:25 + --> tests/ui/redundant_allocation_fixable.rs:76:25 | LL | pub fn arc_test7(a: Arc>) {} | ^^^^^^^^^^^^^^ help: try: `Arc` diff --git a/tests/ui/redundant_as_str.fixed b/tests/ui/redundant_as_str.fixed index 708a1cc91506..4c5f7893d42e 100644 --- a/tests/ui/redundant_as_str.fixed +++ b/tests/ui/redundant_as_str.fixed @@ -6,7 +6,9 @@ fn main() { // These methods are redundant and the `as_str` can be removed let _redundant = string.as_bytes(); + //~^ redundant_as_str let _redundant = string.is_empty(); + //~^ redundant_as_str // These methods don't use `as_str` when they are redundant let _no_as_str = string.as_bytes(); diff --git a/tests/ui/redundant_as_str.rs b/tests/ui/redundant_as_str.rs index 257af591ceff..e3baec754595 100644 --- a/tests/ui/redundant_as_str.rs +++ b/tests/ui/redundant_as_str.rs @@ -6,7 +6,9 @@ fn main() { // These methods are redundant and the `as_str` can be removed let _redundant = string.as_str().as_bytes(); + //~^ redundant_as_str let _redundant = string.as_str().is_empty(); + //~^ redundant_as_str // These methods don't use `as_str` when they are redundant let _no_as_str = string.as_bytes(); diff --git a/tests/ui/redundant_as_str.stderr b/tests/ui/redundant_as_str.stderr index f5379d701db8..fc99c008220e 100644 --- a/tests/ui/redundant_as_str.stderr +++ b/tests/ui/redundant_as_str.stderr @@ -8,7 +8,7 @@ LL | let _redundant = string.as_str().as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::redundant_as_str)]` error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too - --> tests/ui/redundant_as_str.rs:9:29 + --> tests/ui/redundant_as_str.rs:10:29 | LL | let _redundant = string.as_str().is_empty(); | ^^^^^^^^^^^^^^^^^ help: try: `is_empty` diff --git a/tests/ui/redundant_async_block.fixed b/tests/ui/redundant_async_block.fixed index a1875c1c06e1..2f14f27e7056 100644 --- a/tests/ui/redundant_async_block.fixed +++ b/tests/ui/redundant_async_block.fixed @@ -11,6 +11,7 @@ async fn func2() -> String { let s = String::from("some string"); let f = async { (*s).to_owned() }; let x = f; + //~^ redundant_async_block x.await } @@ -18,13 +19,16 @@ fn main() { let fut1 = async { 17 }; // Lint let fut2 = fut1; + //~^ redundant_async_block let fut1 = async { 25 }; // Lint let fut2 = fut1; + //~^ redundant_async_block // Lint let fut = async { 42 }; + //~^ redundant_async_block // Do not lint: not a single expression let fut = async { @@ -41,6 +45,7 @@ fn capture_local() -> impl Future { let fut = async { 17 }; // Lint fut + //~^ redundant_async_block } fn capture_local_closure(s: &str) -> impl Future { @@ -54,11 +59,13 @@ fn capture_arg(s: &str) -> impl Future { let fut = async move { s }; // Lint fut + //~^ redundant_async_block } fn capture_future_arg(f: impl Future) -> impl Future { // Lint f + //~^ redundant_async_block } fn capture_func_result(f: FN) -> impl Future @@ -82,6 +89,7 @@ where { // Lint async { f().await + 1 } + //~^ redundant_async_block } #[derive(Debug, Clone)] @@ -145,6 +153,7 @@ fn all_from_macro() -> impl Future { () => { // Lint async { 42 } + //~^ redundant_async_block }; } mac!() @@ -165,6 +174,7 @@ fn safe_parts_from_macro() -> impl Future { ($e: expr) => { // Lint async { $e } + //~^ redundant_async_block }; } mac!(42) diff --git a/tests/ui/redundant_async_block.rs b/tests/ui/redundant_async_block.rs index bb43403a043e..f5fe26b19cc8 100644 --- a/tests/ui/redundant_async_block.rs +++ b/tests/ui/redundant_async_block.rs @@ -11,6 +11,7 @@ async fn func2() -> String { let s = String::from("some string"); let f = async { (*s).to_owned() }; let x = async { f.await }; + //~^ redundant_async_block x.await } @@ -18,13 +19,16 @@ fn main() { let fut1 = async { 17 }; // Lint let fut2 = async { fut1.await }; + //~^ redundant_async_block let fut1 = async { 25 }; // Lint let fut2 = async move { fut1.await }; + //~^ redundant_async_block // Lint let fut = async { async { 42 }.await }; + //~^ redundant_async_block // Do not lint: not a single expression let fut = async { @@ -41,6 +45,7 @@ fn capture_local() -> impl Future { let fut = async { 17 }; // Lint async move { fut.await } + //~^ redundant_async_block } fn capture_local_closure(s: &str) -> impl Future { @@ -54,11 +59,13 @@ fn capture_arg(s: &str) -> impl Future { let fut = async move { s }; // Lint async move { fut.await } + //~^ redundant_async_block } fn capture_future_arg(f: impl Future) -> impl Future { // Lint async { f.await } + //~^ redundant_async_block } fn capture_func_result(f: FN) -> impl Future @@ -82,6 +89,7 @@ where { // Lint async { async { f().await + 1 }.await } + //~^ redundant_async_block } #[derive(Debug, Clone)] @@ -145,6 +153,7 @@ fn all_from_macro() -> impl Future { () => { // Lint async { async { 42 }.await } + //~^ redundant_async_block }; } mac!() @@ -165,6 +174,7 @@ fn safe_parts_from_macro() -> impl Future { ($e: expr) => { // Lint async { async { $e }.await } + //~^ redundant_async_block }; } mac!(42) diff --git a/tests/ui/redundant_async_block.stderr b/tests/ui/redundant_async_block.stderr index c6a5e2f28ada..386f00a25c2f 100644 --- a/tests/ui/redundant_async_block.stderr +++ b/tests/ui/redundant_async_block.stderr @@ -8,31 +8,25 @@ LL | let x = async { f.await }; = help: to override `-D warnings` add `#[allow(clippy::redundant_async_block)]` error: this async expression only awaits a single future - --> tests/ui/redundant_async_block.rs:20:16 + --> tests/ui/redundant_async_block.rs:21:16 | LL | let fut2 = async { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> tests/ui/redundant_async_block.rs:24:16 + --> tests/ui/redundant_async_block.rs:26:16 | LL | let fut2 = async move { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> tests/ui/redundant_async_block.rs:27:15 + --> tests/ui/redundant_async_block.rs:30: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 - --> tests/ui/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 - --> tests/ui/redundant_async_block.rs:56:5 + --> tests/ui/redundant_async_block.rs:47:5 | LL | async move { fut.await } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` @@ -40,17 +34,23 @@ LL | async move { fut.await } error: this async expression only awaits a single future --> tests/ui/redundant_async_block.rs:61:5 | +LL | async move { fut.await } + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` + +error: this async expression only awaits a single future + --> tests/ui/redundant_async_block.rs:67:5 + | LL | async { f.await } | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` error: this async expression only awaits a single future - --> tests/ui/redundant_async_block.rs:84:5 + --> tests/ui/redundant_async_block.rs:91: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 - --> tests/ui/redundant_async_block.rs:147:13 + --> tests/ui/redundant_async_block.rs:155:13 | LL | async { async { 42 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` @@ -61,7 +61,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 - --> tests/ui/redundant_async_block.rs:167:13 + --> tests/ui/redundant_async_block.rs:176: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 a7997637372e..908b9051b7ef 100644 --- a/tests/ui/redundant_at_rest_pattern.fixed +++ b/tests/ui/redundant_at_rest_pattern.fixed @@ -7,13 +7,19 @@ extern crate proc_macros; fn main() { if let a = [()] {} + //~^ redundant_at_rest_pattern if let ref a = [()] {} + //~^ redundant_at_rest_pattern if let mut a = [()] {} + //~^ redundant_at_rest_pattern if let ref mut a = [()] {} + //~^ redundant_at_rest_pattern let v = vec![()]; if let a = &*v {} + //~^ redundant_at_rest_pattern let s = &[()]; if let a = s {} + //~^ redundant_at_rest_pattern // Don't lint if let [..] = &*v {} if let [a] = &*v {} diff --git a/tests/ui/redundant_at_rest_pattern.rs b/tests/ui/redundant_at_rest_pattern.rs index f103d1f1a179..0f19459773a9 100644 --- a/tests/ui/redundant_at_rest_pattern.rs +++ b/tests/ui/redundant_at_rest_pattern.rs @@ -7,13 +7,19 @@ extern crate proc_macros; fn main() { if let [a @ ..] = [()] {} + //~^ redundant_at_rest_pattern if let [ref a @ ..] = [()] {} + //~^ redundant_at_rest_pattern if let [mut a @ ..] = [()] {} + //~^ redundant_at_rest_pattern if let [ref mut a @ ..] = [()] {} + //~^ redundant_at_rest_pattern let v = vec![()]; if let [a @ ..] = &*v {} + //~^ redundant_at_rest_pattern let s = &[()]; if let [a @ ..] = s {} + //~^ redundant_at_rest_pattern // Don't lint if let [..] = &*v {} if let [a] = &*v {} diff --git a/tests/ui/redundant_at_rest_pattern.stderr b/tests/ui/redundant_at_rest_pattern.stderr index 012ba550ca11..3a6f6cf6500a 100644 --- a/tests/ui/redundant_at_rest_pattern.stderr +++ b/tests/ui/redundant_at_rest_pattern.stderr @@ -8,31 +8,31 @@ LL | if let [a @ ..] = [()] {} = help: to override `-D warnings` add `#[allow(clippy::redundant_at_rest_pattern)]` error: using a rest pattern to bind an entire slice to a local - --> tests/ui/redundant_at_rest_pattern.rs:10:12 + --> tests/ui/redundant_at_rest_pattern.rs:11: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 - --> tests/ui/redundant_at_rest_pattern.rs:11:12 + --> tests/ui/redundant_at_rest_pattern.rs:13: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 - --> tests/ui/redundant_at_rest_pattern.rs:12:12 + --> tests/ui/redundant_at_rest_pattern.rs:15: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 - --> tests/ui/redundant_at_rest_pattern.rs:14:12 + --> tests/ui/redundant_at_rest_pattern.rs:18: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 - --> tests/ui/redundant_at_rest_pattern.rs:16:12 + --> tests/ui/redundant_at_rest_pattern.rs:21: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 1d04cca9b9ed..e0657246bd00 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -13,23 +13,31 @@ use std::path::Path; fn main() { let _s = ["lorem", "ipsum"].join(" "); + //~^ redundant_clone let s = String::from("foo"); let _s = s; + //~^ redundant_clone let s = String::from("foo"); let _s = s; + //~^ redundant_clone let s = String::from("foo"); let _s = s; + //~^ redundant_clone let _s = Path::new("/a/b/").join("c"); + //~^ redundant_clone let _s = Path::new("/a/b/").join("c"); + //~^ redundant_clone let _s = OsString::new(); + //~^ redundant_clone let _s = OsString::new(); + //~^ redundant_clone // Check that lint level works #[allow(clippy::redundant_clone)] @@ -41,6 +49,7 @@ fn main() { let tup = (String::from("foo"),); let _t = tup.0; + //~^ redundant_clone let tup_ref = &(String::from("foo"),); let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed @@ -73,6 +82,7 @@ fn main() { struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { if b { (a.clone(), a) } else { (Alpha, a) } + //~^ redundant_clone } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { @@ -130,7 +140,9 @@ fn borrower_propagation() { } let _s = s; + //~^ redundant_clone let _t = t; + //~^ redundant_clone #[derive(Clone)] struct Foo { @@ -141,6 +153,7 @@ fn borrower_propagation() { let f = Foo { x: 123 }; let _x = Some(f.x); let _f = f; + //~^ redundant_clone } { @@ -153,6 +166,7 @@ fn borrower_propagation() { fn not_consumed() { let x = std::path::PathBuf::from("home"); let y = x.join("matthias"); + //~^ redundant_clone // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is // redundant. (It also does not consume the PathBuf) @@ -207,6 +221,7 @@ fn clone_then_move_cloned() { let x = Alpha; // ok, data is moved while the clone is in use. foo(&x, move || { + //~^ redundant_clone let _ = x; }); diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index 738744fec98f..53e60a44d7df 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -13,23 +13,31 @@ use std::path::Path; fn main() { let _s = ["lorem", "ipsum"].join(" ").to_string(); + //~^ redundant_clone let s = String::from("foo"); let _s = s.clone(); + //~^ redundant_clone let s = String::from("foo"); let _s = s.to_string(); + //~^ redundant_clone let s = String::from("foo"); let _s = s.to_owned(); + //~^ redundant_clone let _s = Path::new("/a/b/").join("c").to_owned(); + //~^ redundant_clone let _s = Path::new("/a/b/").join("c").to_path_buf(); + //~^ redundant_clone let _s = OsString::new().to_owned(); + //~^ redundant_clone let _s = OsString::new().to_os_string(); + //~^ redundant_clone // Check that lint level works #[allow(clippy::redundant_clone)] @@ -41,6 +49,7 @@ fn main() { let tup = (String::from("foo"),); let _t = tup.0.clone(); + //~^ redundant_clone let tup_ref = &(String::from("foo"),); let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed @@ -73,6 +82,7 @@ fn main() { struct Alpha; fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { if b { (a.clone(), a.clone()) } else { (Alpha, a) } + //~^ redundant_clone } fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { @@ -130,7 +140,9 @@ fn borrower_propagation() { } let _s = s.clone(); + //~^ redundant_clone let _t = t.clone(); + //~^ redundant_clone #[derive(Clone)] struct Foo { @@ -141,6 +153,7 @@ fn borrower_propagation() { let f = Foo { x: 123 }; let _x = Some(f.x); let _f = f.clone(); + //~^ redundant_clone } { @@ -153,6 +166,7 @@ fn borrower_propagation() { fn not_consumed() { let x = std::path::PathBuf::from("home"); let y = x.clone().join("matthias"); + //~^ redundant_clone // join() creates a new owned PathBuf, does not take a &mut to x variable, thus the .clone() is // redundant. (It also does not consume the PathBuf) @@ -207,6 +221,7 @@ fn clone_then_move_cloned() { let x = Alpha; // ok, data is moved while the clone is in use. foo(&x.clone(), move || { + //~^ redundant_clone let _ = x; }); diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 3c37288f5507..5be081f0f2f8 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -13,169 +13,169 @@ LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> tests/ui/redundant_clone.rs:18:15 + --> tests/ui/redundant_clone.rs:19:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:18:14 + --> tests/ui/redundant_clone.rs:19:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:21:15 + --> tests/ui/redundant_clone.rs:23:15 | LL | let _s = s.to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:21:14 + --> tests/ui/redundant_clone.rs:23:14 | LL | let _s = s.to_string(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:24:15 + --> tests/ui/redundant_clone.rs:27:15 | LL | let _s = s.to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:24:14 + --> tests/ui/redundant_clone.rs:27:14 | LL | let _s = s.to_owned(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:26:42 + --> tests/ui/redundant_clone.rs:30:42 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:26:14 + --> tests/ui/redundant_clone.rs:30:14 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:28:42 + --> tests/ui/redundant_clone.rs:33:42 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:28:14 + --> tests/ui/redundant_clone.rs:33:14 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:30:29 + --> tests/ui/redundant_clone.rs:36:29 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:30:14 + --> tests/ui/redundant_clone.rs:36:14 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:32:29 + --> tests/ui/redundant_clone.rs:39:29 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:32:14 + --> tests/ui/redundant_clone.rs:39:14 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:43:19 + --> tests/ui/redundant_clone.rs:51:19 | LL | let _t = tup.0.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:43:14 + --> tests/ui/redundant_clone.rs:51:14 | LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:75:25 + --> tests/ui/redundant_clone.rs:84:25 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:75:24 + --> tests/ui/redundant_clone.rs:84:24 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:132:15 + --> tests/ui/redundant_clone.rs:142:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:132:14 + --> tests/ui/redundant_clone.rs:142:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:133:15 + --> tests/ui/redundant_clone.rs:144:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:133:14 + --> tests/ui/redundant_clone.rs:144:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:143:19 + --> tests/ui/redundant_clone.rs:155:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:143:18 + --> tests/ui/redundant_clone.rs:155:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> tests/ui/redundant_clone.rs:155:14 + --> tests/ui/redundant_clone.rs:168:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> tests/ui/redundant_clone.rs:155:13 + --> tests/ui/redundant_clone.rs:168:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ error: redundant clone - --> tests/ui/redundant_clone.rs:209:11 + --> tests/ui/redundant_clone.rs:223:11 | LL | foo(&x.clone(), move || { | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/redundant_clone.rs:209:10 + --> tests/ui/redundant_clone.rs:223:10 | LL | foo(&x.clone(), move || { | ^ diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs index 6f9c9fd52224..2f4feeed9ae6 100644 --- a/tests/ui/redundant_closure_call_early.rs +++ b/tests/ui/redundant_closure_call_early.rs @@ -7,12 +7,14 @@ 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` + //~^ redundant_closure_call + + // lint here k = (|a, b| a * b)(1, 5); - //~^ ERROR: try not to call a closure in the expression where it is declared + //~^ redundant_closure_call + // 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 038144a5d613..4cfde9a64b57 100644 --- a/tests/ui/redundant_closure_call_early.stderr +++ b/tests/ui/redundant_closure_call_early.stderr @@ -8,7 +8,7 @@ LL | let mut k = (|m| m + 1)(i); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_early.rs:14:9 + --> tests/ui/redundant_closure_call_early.rs:15:9 | LL | k = (|a, b| a * b)(1, 5); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed index 9138a8bacfe1..528a2000693e 100644 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ b/tests/ui/redundant_closure_call_fixable.fixed @@ -13,17 +13,21 @@ async fn something_else() -> u32 { fn main() { let a = 42; + //~^ redundant_closure_call let b = async { + //~^ redundant_closure_call let x = something().await; let y = something_else().await; x * y }; let c = { + //~^ redundant_closure_call let x = 21; let y = 2; x * y }; let d = async { something().await }; + //~^ redundant_closure_call macro_rules! m { () => { @@ -33,14 +37,17 @@ fn main() { macro_rules! m2 { () => { m!() + //~^ redundant_closure_call }; } m2!(); + //~^ redundant_closure_call issue9956(); } fn issue9956() { assert_eq!(43, 42); + //~^ redundant_closure_call // ... and some more interesting cases I've found while implementing the fix @@ -50,13 +57,16 @@ fn issue9956() { // immediately calling it inside of a macro dbg!(42); + //~^ redundant_closure_call // immediately calling only one closure, so we can't remove the other ones let a = (|| || 123); + //~^ redundant_closure_call dbg!(a()()); // nested async closures let a = async { 1 }; + //~^ redundant_closure_call let h = async { a.await }; // macro expansion tests @@ -66,8 +76,10 @@ fn issue9956() { }; } let a = 1; + //~^ redundant_closure_call assert_eq!(a, 1); let a = 123; + //~^ redundant_closure_call assert_eq!(a, 123); // chaining calls, but not closures @@ -81,11 +93,14 @@ fn issue9956() { } fn foo(_: i32, _: i32) {} bar()(42, 5); + //~^ redundant_closure_call foo(42, 5); + //~^ redundant_closure_call } async fn issue11357() { async {}.await; + //~^ redundant_closure_call } mod issue11707 { @@ -95,11 +110,13 @@ mod issue11707 { fn demo() { spawn_on(async move {}); + //~^ redundant_closure_call } } fn avoid_double_parens() { std::convert::identity(13_i32 + 36_i32).leading_zeros(); + //~^ redundant_closure_call } fn fp_11274() { diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs index ede6fa27778b..c3cbd8d61ada 100644 --- a/tests/ui/redundant_closure_call_fixable.rs +++ b/tests/ui/redundant_closure_call_fixable.rs @@ -13,17 +13,21 @@ async fn something_else() -> u32 { fn main() { let a = (|| 42)(); + //~^ redundant_closure_call let b = (async || { + //~^ redundant_closure_call let x = something().await; let y = something_else().await; x * y })(); let c = (|| { + //~^ redundant_closure_call let x = 21; let y = 2; x * y })(); let d = (async || something().await)(); + //~^ redundant_closure_call macro_rules! m { () => { @@ -33,14 +37,17 @@ fn main() { macro_rules! m2 { () => { (|| m!())() + //~^ redundant_closure_call }; } m2!(); + //~^ redundant_closure_call issue9956(); } fn issue9956() { assert_eq!((|| || 43)()(), 42); + //~^ redundant_closure_call // ... and some more interesting cases I've found while implementing the fix @@ -50,13 +57,16 @@ fn issue9956() { // immediately calling it inside of a macro dbg!((|| 42)()); + //~^ redundant_closure_call // immediately calling only one closure, so we can't remove the other ones let a = (|| || || 123)(); + //~^ redundant_closure_call dbg!(a()()); // nested async closures let a = (|| || || || async || 1)()()()()(); + //~^ redundant_closure_call let h = async { a.await }; // macro expansion tests @@ -66,8 +76,10 @@ fn issue9956() { }; } let a = (|| echo!(|| echo!(|| 1)))()()(); + //~^ redundant_closure_call assert_eq!(a, 1); let a = (|| echo!((|| 123)))()(); + //~^ redundant_closure_call assert_eq!(a, 123); // chaining calls, but not closures @@ -81,11 +93,14 @@ fn issue9956() { } fn foo(_: i32, _: i32) {} bar()((|| || 42)()(), 5); + //~^ redundant_closure_call foo((|| || 42)()(), 5); + //~^ redundant_closure_call } async fn issue11357() { (|| async {})().await; + //~^ redundant_closure_call } mod issue11707 { @@ -95,11 +110,13 @@ mod issue11707 { fn demo() { spawn_on((|| async move {})()); + //~^ redundant_closure_call } } fn avoid_double_parens() { std::convert::identity((|| 13_i32 + 36_i32)()).leading_zeros(); + //~^ redundant_closure_call } fn fp_11274() { diff --git a/tests/ui/redundant_closure_call_fixable.stderr b/tests/ui/redundant_closure_call_fixable.stderr index 8e0d37df96b8..2c35aafbe310 100644 --- a/tests/ui/redundant_closure_call_fixable.stderr +++ b/tests/ui/redundant_closure_call_fixable.stderr @@ -8,10 +8,11 @@ LL | let a = (|| 42)(); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:16:13 + --> tests/ui/redundant_closure_call_fixable.rs:17:13 | LL | let b = (async || { | _____________^ +LL | | LL | | let x = something().await; LL | | let y = something_else().await; LL | | x * y @@ -21,6 +22,7 @@ LL | | })(); help: try doing something like | LL ~ let b = async { +LL + LL + let x = something().await; LL + let y = something_else().await; LL + x * y @@ -28,10 +30,11 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:21:13 + --> tests/ui/redundant_closure_call_fixable.rs:23:13 | LL | let c = (|| { | _____________^ +LL | | LL | | let x = 21; LL | | let y = 2; LL | | x * y @@ -41,6 +44,7 @@ LL | | })(); help: try doing something like | LL ~ let c = { +LL + LL + let x = 21; LL + let y = 2; LL + x * y @@ -48,13 +52,13 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:26:13 + --> tests/ui/redundant_closure_call_fixable.rs:29: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 - --> tests/ui/redundant_closure_call_fixable.rs:35:13 + --> tests/ui/redundant_closure_call_fixable.rs:39:13 | LL | (|| m!())() | ^^^^^^^^^^^ help: try doing something like: `m!()` @@ -65,7 +69,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 - --> tests/ui/redundant_closure_call_fixable.rs:30:13 + --> tests/ui/redundant_closure_call_fixable.rs:34:13 | LL | (|| 0)() | ^^^^^^^^ help: try doing something like: `0` @@ -76,67 +80,67 @@ 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 - --> tests/ui/redundant_closure_call_fixable.rs:43:16 + --> tests/ui/redundant_closure_call_fixable.rs:49: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 - --> tests/ui/redundant_closure_call_fixable.rs:52:10 + --> tests/ui/redundant_closure_call_fixable.rs:59:10 | LL | dbg!((|| 42)()); | ^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:55:13 + --> tests/ui/redundant_closure_call_fixable.rs:63: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 - --> tests/ui/redundant_closure_call_fixable.rs:59:13 + --> tests/ui/redundant_closure_call_fixable.rs:68: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 - --> tests/ui/redundant_closure_call_fixable.rs:68:13 + --> tests/ui/redundant_closure_call_fixable.rs:78: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 - --> tests/ui/redundant_closure_call_fixable.rs:70:13 + --> tests/ui/redundant_closure_call_fixable.rs:81: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 - --> tests/ui/redundant_closure_call_fixable.rs:83:11 + --> tests/ui/redundant_closure_call_fixable.rs:95: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 - --> tests/ui/redundant_closure_call_fixable.rs:84:9 + --> tests/ui/redundant_closure_call_fixable.rs:97:9 | LL | foo((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:88:5 + --> tests/ui/redundant_closure_call_fixable.rs:102:5 | LL | (|| async {})().await; | ^^^^^^^^^^^^^^^ help: try doing something like: `async {}` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:97:18 + --> tests/ui/redundant_closure_call_fixable.rs:112:18 | LL | spawn_on((|| async move {})()); | ^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async move {}` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_fixable.rs:102:28 + --> tests/ui/redundant_closure_call_fixable.rs:118:28 | LL | std::convert::identity((|| 13_i32 + 36_i32)()).leading_zeros(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `13_i32 + 36_i32` diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs index dc369c3bc092..c697fedb871e 100644 --- a/tests/ui/redundant_closure_call_late.rs +++ b/tests/ui/redundant_closure_call_late.rs @@ -14,16 +14,19 @@ 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` + //~^ redundant_closure_call + + // shadowed closures are supported, lint here let shadowed_closure = || 1; i = shadowed_closure(); - //~^ ERROR: closure called just once immediately after it was declared + //~^ redundant_closure_call + let shadowed_closure = || 2; i = shadowed_closure(); - //~^ ERROR: closure called just once immediately after it was declared + //~^ redundant_closure_call + // 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 023e766a5d2b..abe7ac7b6595 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -8,13 +8,13 @@ LL | i = redun_closure(); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:22:5 + --> tests/ui/redundant_closure_call_late.rs:23:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:25:5 + --> tests/ui/redundant_closure_call_late.rs:27:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_else.fixed b/tests/ui/redundant_else.fixed index 47aa79302d2c..4dc325330249 100644 --- a/tests/ui/redundant_else.fixed +++ b/tests/ui/redundant_else.fixed @@ -8,15 +8,17 @@ fn main() { println!("Love your neighbor;"); break; } - //~^ ERROR: redundant else block - println!("yet don't pull down your hedge."); + //~^ redundant_else + + println!("yet don't pull down your hedge."); // continue if foo() { println!("He that lies down with Dogs,"); continue; } - //~^ ERROR: redundant else block - println!("shall rise up with fleas."); + //~^ redundant_else + + println!("shall rise up with fleas."); // match block if foo() { match foo() { @@ -24,8 +26,9 @@ fn main() { _ => return, } } - //~^ ERROR: redundant else block - println!("You may delay, but time will not."); + //~^ redundant_else + + println!("You may delay, but time will not."); } // else if if foo() { @@ -33,15 +36,17 @@ fn main() { } else if foo() { return; } - //~^ ERROR: redundant else block - println!("A fat kitchen makes a lean will."); + //~^ redundant_else + + println!("A fat kitchen makes a lean will."); // let binding outside of block let _ = { if foo() { return; } - //~^ ERROR: redundant else block - 1 + //~^ redundant_else + + 1 }; // else if with let binding outside of block let _ = { @@ -50,8 +55,9 @@ fn main() { } else if foo() { return; } - //~^ ERROR: redundant else block - 2 + //~^ redundant_else + + 2 }; // inside if let let _ = if let Some(1) = foo() { @@ -59,8 +65,9 @@ fn main() { if foo() { return; } - //~^ ERROR: redundant else block - 1 + //~^ redundant_else + + 1 } else { 1 }; diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 8bcf2ce5233d..842cb4bc9411 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -8,7 +8,8 @@ fn main() { println!("Love your neighbor;"); break; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + println!("yet don't pull down your hedge."); } // continue @@ -16,7 +17,8 @@ fn main() { println!("He that lies down with Dogs,"); continue; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + println!("shall rise up with fleas."); } // match block @@ -26,7 +28,8 @@ fn main() { _ => return, } } else { - //~^ ERROR: redundant else block + //~^ redundant_else + println!("You may delay, but time will not."); } } @@ -36,7 +39,8 @@ fn main() { } else if foo() { return; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + println!("A fat kitchen makes a lean will."); } // let binding outside of block @@ -44,7 +48,8 @@ fn main() { if foo() { return; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + 1 } }; @@ -55,7 +60,8 @@ fn main() { } else if foo() { return; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + 2 } }; @@ -65,7 +71,8 @@ fn main() { if foo() { return; } else { - //~^ ERROR: redundant else block + //~^ redundant_else + 1 } } else { diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index ecc16f7cda5e..2cb0fd6f127f 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -4,6 +4,7 @@ error: redundant else block LL | } else { | __________^ LL | | +LL | | LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ @@ -14,15 +15,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + println!("yet don't pull down your hedge."); +LL + +LL + println!("yet don't pull down your hedge."); | error: redundant else block - --> tests/ui/redundant_else.rs:18:10 + --> tests/ui/redundant_else.rs:19:10 | LL | } else { | __________^ LL | | +LL | | LL | | println!("shall rise up with fleas."); LL | | } | |_________^ @@ -31,15 +34,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + println!("shall rise up with fleas."); +LL + +LL + println!("shall rise up with fleas."); | error: redundant else block - --> tests/ui/redundant_else.rs:28:10 + --> tests/ui/redundant_else.rs:30:10 | LL | } else { | __________^ LL | | +LL | | LL | | println!("You may delay, but time will not."); LL | | } | |_________^ @@ -48,15 +53,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + println!("You may delay, but time will not."); +LL + +LL + println!("You may delay, but time will not."); | error: redundant else block - --> tests/ui/redundant_else.rs:38:6 + --> tests/ui/redundant_else.rs:41:6 | LL | } else { | ______^ LL | | +LL | | LL | | println!("A fat kitchen makes a lean will."); LL | | } | |_____^ @@ -65,15 +72,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + println!("A fat kitchen makes a lean will."); +LL + +LL + println!("A fat kitchen makes a lean will."); | error: redundant else block - --> tests/ui/redundant_else.rs:46:10 + --> tests/ui/redundant_else.rs:50:10 | LL | } else { | __________^ LL | | +LL | | LL | | 1 LL | | } | |_________^ @@ -82,15 +91,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + 1 +LL + +LL + 1 | error: redundant else block - --> tests/ui/redundant_else.rs:57:10 + --> tests/ui/redundant_else.rs:62:10 | LL | } else { | __________^ LL | | +LL | | LL | | 2 LL | | } | |_________^ @@ -99,15 +110,17 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + 2 +LL + +LL + 2 | error: redundant else block - --> tests/ui/redundant_else.rs:67:10 + --> tests/ui/redundant_else.rs:73:10 | LL | } else { | __________^ LL | | +LL | | LL | | 1 LL | | } | |_________^ @@ -116,7 +129,8 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + 1 +LL + +LL + 1 | error: aborting due to 7 previous errors diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed index 72fc4cb7333e..142828a2b2d8 100644 --- a/tests/ui/redundant_field_names.fixed +++ b/tests/ui/redundant_field_names.fixed @@ -31,7 +31,9 @@ fn main() { let me = Person { gender, + //~^ redundant_field_names age, + //~^ redundant_field_names name, //should be ok buzz: fizz, //should be ok @@ -53,10 +55,15 @@ fn main() { // hand-written Range family structs are linted let _ = RangeFrom { start }; + //~^ redundant_field_names let _ = RangeTo { end }; + //~^ redundant_field_names let _ = Range { start, end }; + //~^ redundant_field_names + //~| redundant_field_names let _ = RangeInclusive::new(start, end); let _ = RangeToInclusive { end }; + //~^ redundant_field_names external! { let v = 1; @@ -69,6 +76,7 @@ fn main() { macro_rules! internal { ($i:ident) => { let _ = S { v }; + //~^ redundant_field_names let _ = S { $i: v }; let _ = S { v: $i }; let _ = S { $i: $i }; @@ -97,4 +105,5 @@ fn msrv_1_16() { fn msrv_1_17() { let start = 0; let _ = RangeFrom { start }; + //~^ redundant_field_names } diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index 2617d7e72837..15fef11a0408 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -31,7 +31,9 @@ fn main() { let me = Person { gender: gender, + //~^ redundant_field_names age: age, + //~^ redundant_field_names name, //should be ok buzz: fizz, //should be ok @@ -53,10 +55,15 @@ fn main() { // hand-written Range family structs are linted let _ = RangeFrom { start: start }; + //~^ redundant_field_names let _ = RangeTo { end: end }; + //~^ redundant_field_names let _ = Range { start: start, end: end }; + //~^ redundant_field_names + //~| redundant_field_names let _ = RangeInclusive::new(start, end); let _ = RangeToInclusive { end: end }; + //~^ redundant_field_names external! { let v = 1; @@ -69,6 +76,7 @@ fn main() { macro_rules! internal { ($i:ident) => { let _ = S { v: v }; + //~^ redundant_field_names let _ = S { $i: v }; let _ = S { v: $i }; let _ = S { $i: $i }; @@ -97,4 +105,5 @@ fn msrv_1_16() { fn msrv_1_17() { let start = 0; let _ = RangeFrom { start: start }; + //~^ redundant_field_names } diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 38c021fdba37..78b8a4f1118e 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -8,43 +8,43 @@ LL | gender: gender, = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:34:9 + --> tests/ui/redundant_field_names.rs:35:9 | LL | age: age, | ^^^^^^^^ help: replace it with: `age` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:55:25 + --> tests/ui/redundant_field_names.rs:57:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:56:23 + --> tests/ui/redundant_field_names.rs:59:23 | LL | let _ = RangeTo { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:57:21 + --> tests/ui/redundant_field_names.rs:61:21 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:57:35 + --> tests/ui/redundant_field_names.rs:61:35 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:59:32 + --> tests/ui/redundant_field_names.rs:65:32 | LL | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:71:25 + --> tests/ui/redundant_field_names.rs:78:25 | LL | let _ = S { v: v }; | ^^^^ help: replace it with: `v` @@ -55,7 +55,7 @@ LL | internal!(v); = note: this error originates in the macro `internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:99:25 + --> tests/ui/redundant_field_names.rs:107: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 ff7b233f004e..c7e6f44ad83e 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -20,12 +20,14 @@ struct FloatWrapper(f32); fn issue11304() { match 0.1 { 0.0 => todo!(), + //~^ redundant_guards // Pattern matching NAN is illegal x if x == f64::NAN => todo!(), _ => todo!(), } match FloatWrapper(0.1) { FloatWrapper(0.0) => todo!(), + //~^ redundant_guards _ => todo!(), } } @@ -41,19 +43,25 @@ fn main() { let c = C(1, 2); match c { C(x, 1) => .., + //~^ redundant_guards _ => todo!(), }; let x = Some(Some(1)); match x { Some(Some(1)) if true => .., + //~^ redundant_guards Some(Some(1)) => { + //~^ redundant_guards println!("a"); .. }, Some(Some(1)) => .., + //~^ redundant_guards Some(Some(2)) => .., + //~^ redundant_guards Some(Some(2)) => .., + //~^ redundant_guards // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -79,6 +87,7 @@ fn main() { let b = B { e: Some(A(0)) }; match b { B { e: Some(A(2)) } => .., + //~^ redundant_guards _ => todo!(), }; // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) @@ -116,6 +125,7 @@ fn i() { // Do not lint E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {}, E::A("not from an or pattern") => {}, + //~^ redundant_guards _ => {}, }; } @@ -123,6 +133,7 @@ fn i() { fn h(v: Option) { match v { Some(0) => .., + //~^ redundant_guards _ => .., }; } @@ -130,7 +141,9 @@ fn h(v: Option) { fn negative_literal(i: i32) { match i { -1 => {}, + //~^ redundant_guards 1 => {}, + //~^ redundant_guards _ => {}, } } @@ -193,9 +206,13 @@ mod issue11465 { let c = Some(1); match c { Some(1) => {}, + //~^ redundant_guards Some(1) => {}, + //~^ redundant_guards Some(2) => {}, + //~^ redundant_guards Some(3) => {}, + //~^ redundant_guards _ => {}, }; @@ -216,9 +233,13 @@ mod issue11465 { B { ref b, .. } if b == "bar" => {}, B { ref b, .. } if "bar" == b => {}, B { c: 1, .. } => {}, + //~^ redundant_guards B { c: 1, .. } => {}, + //~^ redundant_guards B { c: 1, .. } => {}, + //~^ redundant_guards B { c: 1, .. } => {}, + //~^ redundant_guards _ => {}, } } @@ -229,6 +250,7 @@ fn issue11807() { match Some(Some("")) { Some(Some("")) => {}, + //~^ redundant_guards _ => {}, } @@ -240,11 +262,13 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some([])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some([] as [i32; 0])) { Some(Some([])) => {}, + //~^ redundant_guards _ => {}, } @@ -256,21 +280,25 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some([..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([1, ..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([1, 2, ..])) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some([.., 1, 2])) => {}, + //~^ redundant_guards _ => {}, } diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index b4d4ef5b170d..d3c55c18884d 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -20,12 +20,14 @@ struct FloatWrapper(f32); fn issue11304() { match 0.1 { x if x == 0.0 => todo!(), + //~^ redundant_guards // Pattern matching NAN is illegal x if x == f64::NAN => todo!(), _ => todo!(), } match FloatWrapper(0.1) { x if x == FloatWrapper(0.0) => todo!(), + //~^ redundant_guards _ => todo!(), } } @@ -41,19 +43,25 @@ fn main() { let c = C(1, 2); match c { C(x, y) if let 1 = y => .., + //~^ redundant_guards _ => todo!(), }; let x = Some(Some(1)); match x { Some(x) if matches!(x, Some(1) if true) => .., + //~^ redundant_guards Some(x) if matches!(x, Some(1)) => { + //~^ redundant_guards println!("a"); .. }, Some(x) if let Some(1) = x => .., + //~^ redundant_guards Some(x) if x == Some(2) => .., + //~^ redundant_guards Some(x) if Some(2) == x => .., + //~^ redundant_guards // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -79,6 +87,7 @@ fn main() { let b = B { e: Some(A(0)) }; match b { B { e } if matches!(e, Some(A(2))) => .., + //~^ redundant_guards _ => todo!(), }; // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) @@ -116,6 +125,7 @@ fn i() { // Do not lint E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {}, E::A(y) if y == "not from an or pattern" => {}, + //~^ redundant_guards _ => {}, }; } @@ -123,6 +133,7 @@ fn i() { fn h(v: Option) { match v { x if matches!(x, Some(0)) => .., + //~^ redundant_guards _ => .., }; } @@ -130,7 +141,9 @@ fn h(v: Option) { fn negative_literal(i: i32) { match i { i if i == -1 => {}, + //~^ redundant_guards i if i == 1 => {}, + //~^ redundant_guards _ => {}, } } @@ -193,9 +206,13 @@ mod issue11465 { let c = Some(1); match c { Some(ref x) if x == &1 => {}, + //~^ redundant_guards Some(ref x) if &1 == x => {}, + //~^ redundant_guards Some(ref x) if let &2 = x => {}, + //~^ redundant_guards Some(ref x) if matches!(x, &3) => {}, + //~^ redundant_guards _ => {}, }; @@ -216,9 +233,13 @@ mod issue11465 { B { ref b, .. } if b == "bar" => {}, B { ref b, .. } if "bar" == b => {}, B { ref c, .. } if c == &1 => {}, + //~^ redundant_guards B { ref c, .. } if &1 == c => {}, + //~^ redundant_guards B { ref c, .. } if let &1 = c => {}, + //~^ redundant_guards B { ref c, .. } if matches!(c, &1) => {}, + //~^ redundant_guards _ => {}, } } @@ -229,6 +250,7 @@ fn issue11807() { match Some(Some("")) { Some(Some(x)) if x.is_empty() => {}, + //~^ redundant_guards _ => {}, } @@ -240,11 +262,13 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.is_empty() => {}, + //~^ redundant_guards _ => {}, } match Some(Some([] as [i32; 0])) { Some(Some(x)) if x.is_empty() => {}, + //~^ redundant_guards _ => {}, } @@ -256,21 +280,25 @@ fn issue11807() { match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[1]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.starts_with(&[1, 2]) => {}, + //~^ redundant_guards _ => {}, } match Some(Some(&[] as &[i32])) { Some(Some(x)) if x.ends_with(&[1, 2]) => {}, + //~^ redundant_guards _ => {}, } diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 7512546450b2..2a3d8901066d 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -13,7 +13,7 @@ LL + 0.0 => todo!(), | error: redundant guard - --> tests/ui/redundant_guards.rs:28:14 + --> tests/ui/redundant_guards.rs:29:14 | LL | x if x == FloatWrapper(0.0) => todo!(), | ^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + FloatWrapper(0.0) => todo!(), | error: redundant guard - --> tests/ui/redundant_guards.rs:43:20 + --> tests/ui/redundant_guards.rs:45:20 | LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL + C(x, 1) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:49:20 + --> tests/ui/redundant_guards.rs:52:20 | LL | Some(x) if matches!(x, Some(1) if true) => .., | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | Some(Some(1)) if true => .., | ~~~~~~~ ~~~~~~~ error: redundant guard - --> tests/ui/redundant_guards.rs:50:20 + --> tests/ui/redundant_guards.rs:54:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> tests/ui/redundant_guards.rs:54:20 + --> tests/ui/redundant_guards.rs:59:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:55:20 + --> tests/ui/redundant_guards.rs:61:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:56:20 + --> tests/ui/redundant_guards.rs:63:20 | LL | Some(x) if Some(2) == x => .., | ^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:81:20 + --> tests/ui/redundant_guards.rs:89:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:118:20 + --> tests/ui/redundant_guards.rs:127:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:125:14 + --> tests/ui/redundant_guards.rs:135:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + Some(0) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:132:14 + --> tests/ui/redundant_guards.rs:143:14 | LL | i if i == -1 => {}, | ^^^^^^^ @@ -144,7 +144,7 @@ LL + -1 => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:133:14 + --> tests/ui/redundant_guards.rs:145:14 | LL | i if i == 1 => {}, | ^^^^^^ @@ -156,7 +156,7 @@ LL + 1 => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:195:28 + --> tests/ui/redundant_guards.rs:208:28 | LL | Some(ref x) if x == &1 => {}, | ^^^^^^^ @@ -168,7 +168,7 @@ LL + Some(1) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:196:28 + --> tests/ui/redundant_guards.rs:210:28 | LL | Some(ref x) if &1 == x => {}, | ^^^^^^^ @@ -180,7 +180,7 @@ LL + Some(1) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:197:28 + --> tests/ui/redundant_guards.rs:212:28 | LL | Some(ref x) if let &2 = x => {}, | ^^^^^^^^^^ @@ -192,7 +192,7 @@ LL + Some(2) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:198:28 + --> tests/ui/redundant_guards.rs:214:28 | LL | Some(ref x) if matches!(x, &3) => {}, | ^^^^^^^^^^^^^^^ @@ -204,7 +204,7 @@ LL + Some(3) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:218:32 + --> tests/ui/redundant_guards.rs:235:32 | LL | B { ref c, .. } if c == &1 => {}, | ^^^^^^^ @@ -216,7 +216,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:219:32 + --> tests/ui/redundant_guards.rs:237:32 | LL | B { ref c, .. } if &1 == c => {}, | ^^^^^^^ @@ -228,7 +228,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:220:32 + --> tests/ui/redundant_guards.rs:239:32 | LL | B { ref c, .. } if let &1 = c => {}, | ^^^^^^^^^^ @@ -240,7 +240,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:221:32 + --> tests/ui/redundant_guards.rs:241:32 | LL | B { ref c, .. } if matches!(c, &1) => {}, | ^^^^^^^^^^^^^^^ @@ -252,7 +252,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:231:26 + --> tests/ui/redundant_guards.rs:252:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -264,7 +264,7 @@ LL + Some(Some("")) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:242:26 + --> tests/ui/redundant_guards.rs:264:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:247:26 + --> tests/ui/redundant_guards.rs:270:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:258:26 + --> tests/ui/redundant_guards.rs:282:26 | LL | Some(Some(x)) if x.starts_with(&[]) => {}, | ^^^^^^^^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + Some(Some([..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:263:26 + --> tests/ui/redundant_guards.rs:288:26 | LL | Some(Some(x)) if x.starts_with(&[1]) => {}, | ^^^^^^^^^^^^^^^^^^^ @@ -312,7 +312,7 @@ LL + Some(Some([1, ..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:268:26 + --> tests/ui/redundant_guards.rs:294:26 | LL | Some(Some(x)) if x.starts_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^^^ @@ -324,7 +324,7 @@ LL + Some(Some([1, 2, ..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:273:26 + --> tests/ui/redundant_guards.rs:300:26 | LL | Some(Some(x)) if x.ends_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +336,7 @@ LL + Some(Some([.., 1, 2])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:295:18 + --> tests/ui/redundant_guards.rs:323:18 | LL | y if y.is_empty() => {}, | ^^^^^^^^^^^^ @@ -348,7 +348,7 @@ LL + "" => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:314:22 + --> tests/ui/redundant_guards.rs:342:22 | LL | y if y.is_empty() => {}, | ^^^^^^^^^^^^ diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index 3e7695106a7f..b66532dd22ee 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -11,11 +11,13 @@ fn main() {} fn immutable() { let x = 1; let x = x; + //~^ redundant_locals } fn mutable() { let mut x = 1; let mut x = x; + //~^ redundant_locals } fn upgraded_mutability() { @@ -46,27 +48,35 @@ fn coercion(par: &mut i32) { fn parameter(x: i32) { let x = x; + //~^ redundant_locals } fn many() { let x = 1; let x = x; + //~^ redundant_locals let x = x; + //~^ redundant_locals let x = x; + //~^ redundant_locals let x = x; + //~^ redundant_locals } fn interleaved() { let a = 1; let b = 2; let a = a; + //~^ redundant_locals let b = b; + //~^ redundant_locals } fn block() { { let x = 1; let x = x; + //~^ redundant_locals } } @@ -74,9 +84,11 @@ fn closure() { || { let x = 1; let x = x; + //~^ redundant_locals }; |x: i32| { let x = x; + //~^ redundant_locals }; } @@ -96,6 +108,7 @@ fn inconsequential_drop_order() { { let x = x; + //~^ redundant_locals } } @@ -151,6 +164,7 @@ fn without_drop() { let a = WithoutDrop(1); let b = WithoutDrop(2); let a = a; + //~^ redundant_locals } fn drop_inner() { diff --git a/tests/ui/redundant_locals.stderr b/tests/ui/redundant_locals.stderr index 541b988eefe9..ae3631cdf15f 100644 --- a/tests/ui/redundant_locals.stderr +++ b/tests/ui/redundant_locals.stderr @@ -13,65 +13,29 @@ LL | let x = 1; = help: to override `-D warnings` add `#[allow(clippy::redundant_locals)]` error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:18:5 + --> tests/ui/redundant_locals.rs:19:5 | LL | let mut x = x; | ^^^^^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:17:9 + --> tests/ui/redundant_locals.rs:18:9 | LL | let mut x = 1; | ^^^^^ error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:48:5 + --> tests/ui/redundant_locals.rs:50:5 | LL | let x = x; | ^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:47:14 + --> tests/ui/redundant_locals.rs:49:14 | LL | fn parameter(x: i32) { | ^ -error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:53:5 - | -LL | let x = x; - | ^^^^^^^^^^ - | -help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:52:9 - | -LL | let x = 1; - | ^ - -error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:54:5 - | -LL | let x = x; - | ^^^^^^^^^^ - | -help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:53:9 - | -LL | let x = x; - | ^ - -error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:55:5 - | -LL | let x = x; - | ^^^^^^^^^^ - | -help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:54:9 - | -LL | let x = x; - | ^ - error: redundant redefinition of a binding `x` --> tests/ui/redundant_locals.rs:56:5 | @@ -81,89 +45,125 @@ LL | let x = x; help: `x` is initially defined here --> tests/ui/redundant_locals.rs:55:9 | +LL | let x = 1; + | ^ + +error: redundant redefinition of a binding `x` + --> tests/ui/redundant_locals.rs:58:5 + | +LL | let x = x; + | ^^^^^^^^^^ + | +help: `x` is initially defined here + --> tests/ui/redundant_locals.rs:56:9 + | +LL | let x = x; + | ^ + +error: redundant redefinition of a binding `x` + --> tests/ui/redundant_locals.rs:60:5 + | +LL | let x = x; + | ^^^^^^^^^^ + | +help: `x` is initially defined here + --> tests/ui/redundant_locals.rs:58:9 + | +LL | let x = x; + | ^ + +error: redundant redefinition of a binding `x` + --> tests/ui/redundant_locals.rs:62:5 + | +LL | let x = x; + | ^^^^^^^^^^ + | +help: `x` is initially defined here + --> tests/ui/redundant_locals.rs:60:9 + | LL | let x = x; | ^ error: redundant redefinition of a binding `a` - --> tests/ui/redundant_locals.rs:62:5 + --> tests/ui/redundant_locals.rs:69:5 | LL | let a = a; | ^^^^^^^^^^ | help: `a` is initially defined here - --> tests/ui/redundant_locals.rs:60:9 + --> tests/ui/redundant_locals.rs:67:9 | LL | let a = 1; | ^ error: redundant redefinition of a binding `b` - --> tests/ui/redundant_locals.rs:63:5 + --> tests/ui/redundant_locals.rs:71:5 | LL | let b = b; | ^^^^^^^^^^ | help: `b` is initially defined here - --> tests/ui/redundant_locals.rs:61:9 + --> tests/ui/redundant_locals.rs:68:9 | LL | let b = 2; | ^ error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:69:9 + --> tests/ui/redundant_locals.rs:78:9 | LL | let x = x; | ^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:68:13 + --> tests/ui/redundant_locals.rs:77:13 | LL | let x = 1; | ^ error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:76:9 + --> tests/ui/redundant_locals.rs:86:9 | LL | let x = x; | ^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:75:13 + --> tests/ui/redundant_locals.rs:85:13 | LL | let x = 1; | ^ error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:79:9 + --> tests/ui/redundant_locals.rs:90:9 | LL | let x = x; | ^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:78:6 + --> tests/ui/redundant_locals.rs:89:6 | LL | |x: i32| { | ^ error: redundant redefinition of a binding `x` - --> tests/ui/redundant_locals.rs:98:9 + --> tests/ui/redundant_locals.rs:110:9 | LL | let x = x; | ^^^^^^^^^^ | help: `x` is initially defined here - --> tests/ui/redundant_locals.rs:95:9 + --> tests/ui/redundant_locals.rs:107:9 | LL | let x = 1; | ^ error: redundant redefinition of a binding `a` - --> tests/ui/redundant_locals.rs:153:5 + --> tests/ui/redundant_locals.rs:166:5 | LL | let a = a; | ^^^^^^^^^^ | help: `a` is initially defined here - --> tests/ui/redundant_locals.rs:151:9 + --> tests/ui/redundant_locals.rs:164:9 | LL | let a = WithoutDrop(1); | ^ diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index 148eaa4b33a6..4de47a1ad3ee 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -13,49 +13,71 @@ fn main() { // Result if m.lock().is_ok() {} + //~^ redundant_pattern_matching if Err::<(), _>(m.lock().unwrap().0).is_err() {} + //~^ redundant_pattern_matching { if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} + //~^ redundant_pattern_matching } if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() { + //~^ redundant_pattern_matching } else { } if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} + //~^ redundant_pattern_matching if Err::, _>(()).is_err() {} + //~^ redundant_pattern_matching if Ok::<_, ()>(String::new()).is_ok() {} + //~^ redundant_pattern_matching if Err::<(), _>((String::new(), ())).is_err() {} + //~^ redundant_pattern_matching // Option if Some(m.lock()).is_some() {} + //~^ redundant_pattern_matching if Some(m.lock().unwrap().0).is_some() {} + //~^ redundant_pattern_matching { if None::>.is_none() {} + //~^ redundant_pattern_matching } if None::>.is_none() { + //~^ redundant_pattern_matching } else { } if None::>.is_none() {} + //~^ redundant_pattern_matching if Some(String::new()).is_some() {} + //~^ redundant_pattern_matching if Some((String::new(), ())).is_some() {} + //~^ redundant_pattern_matching // Poll if Ready(m.lock()).is_ready() {} + //~^ redundant_pattern_matching if Ready(m.lock().unwrap().0).is_ready() {} + //~^ redundant_pattern_matching { if Pending::>.is_pending() {} + //~^ redundant_pattern_matching } if Pending::>.is_pending() { + //~^ redundant_pattern_matching } else { } if Pending::>.is_pending() {} + //~^ redundant_pattern_matching if Ready(String::new()).is_ready() {} + //~^ redundant_pattern_matching if Ready((String::new(), ())).is_ready() {} + //~^ redundant_pattern_matching } diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index 5bc06f3cc529..4e37837c1fe6 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -13,49 +13,71 @@ fn main() { // Result if let Ok(_) = m.lock() {} + //~^ redundant_pattern_matching if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} + //~^ redundant_pattern_matching } if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { + //~^ redundant_pattern_matching } else { } if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} + //~^ redundant_pattern_matching if let Err(_) = Err::, _>(()) {} + //~^ redundant_pattern_matching if let Ok(_) = Ok::<_, ()>(String::new()) {} + //~^ redundant_pattern_matching if let Err(_) = Err::<(), _>((String::new(), ())) {} + //~^ redundant_pattern_matching // Option if let Some(_) = Some(m.lock()) {} + //~^ redundant_pattern_matching if let Some(_) = Some(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let None = None::> {} + //~^ redundant_pattern_matching } if let None = None::> { + //~^ redundant_pattern_matching } else { } if let None = None::> {} + //~^ redundant_pattern_matching if let Some(_) = Some(String::new()) {} + //~^ redundant_pattern_matching if let Some(_) = Some((String::new(), ())) {} + //~^ redundant_pattern_matching // Poll if let Ready(_) = Ready(m.lock()) {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(m.lock().unwrap().0) {} + //~^ redundant_pattern_matching { if let Pending = Pending::> {} + //~^ redundant_pattern_matching } if let Pending = Pending::> { + //~^ redundant_pattern_matching } else { } if let Pending = Pending::> {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(String::new()) {} + //~^ redundant_pattern_matching if let Ready(_) = Ready((String::new(), ())) {} + //~^ redundant_pattern_matching } diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index 1a99cb9fc32b..74462f022f70 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -10,7 +10,7 @@ LL | if let Ok(_) = m.lock() {} = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:16:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:17:12 | LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>(m.lock().unwrap().0).is_err()` @@ -19,7 +19,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:19:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:21:16 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -28,7 +28,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:21:12 + --> tests/ui/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()` @@ -37,31 +37,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:24:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:28: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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:25:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:30:12 | LL | if let Err(_) = Err::, _>(()) {} | -------^^^^^^------------------------------------------ help: try: `if Err::, _>(()).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:27:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:33:12 | LL | if let Ok(_) = Ok::<_, ()>(String::new()) {} | -------^^^^^----------------------------- help: try: `if Ok::<_, ()>(String::new()).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:28:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:35:12 | LL | if let Err(_) = Err::<(), _>((String::new(), ())) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>((String::new(), ())).is_err()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:31:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:39:12 | LL | if let Some(_) = Some(m.lock()) {} | -------^^^^^^^----------------- help: try: `if Some(m.lock()).is_some()` @@ -70,7 +70,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:32:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:41:12 | LL | if let Some(_) = Some(m.lock().unwrap().0) {} | -------^^^^^^^---------------------------- help: try: `if Some(m.lock().unwrap().0).is_some()` @@ -79,7 +79,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:35:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:45:16 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -88,7 +88,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:37:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:48:12 | LL | if let None = None::> { | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -97,25 +97,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:41:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:53:12 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:43:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:56:12 | LL | if let Some(_) = Some(String::new()) {} | -------^^^^^^^---------------------- help: try: `if Some(String::new()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:44:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:58:12 | LL | if let Some(_) = Some((String::new(), ())) {} | -------^^^^^^^---------------------------- help: try: `if Some((String::new(), ())).is_some()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:47:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:62:12 | LL | if let Ready(_) = Ready(m.lock()) {} | -------^^^^^^^^------------------ help: try: `if Ready(m.lock()).is_ready()` @@ -124,7 +124,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:48:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:64:12 | LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} | -------^^^^^^^^----------------------------- help: try: `if Ready(m.lock().unwrap().0).is_ready()` @@ -133,7 +133,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:51:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:68:16 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -142,7 +142,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:53:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:71:12 | LL | if let Pending = Pending::> { | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -151,19 +151,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()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:57:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:76:12 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:59:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:79:12 | LL | if let Ready(_) = Ready(String::new()) {} | -------^^^^^^^^----------------------- help: try: `if Ready(String::new()).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_drop_order.rs:60:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:81:12 | LL | if let Ready(_) = Ready((String::new(), ())) {} | -------^^^^^^^^----------------------------- help: try: `if Ready((String::new(), ())).is_ready()` diff --git a/tests/ui/redundant_pattern_matching_if_let_true.fixed b/tests/ui/redundant_pattern_matching_if_let_true.fixed index 6d9106789340..f40cd01d16cb 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.fixed +++ b/tests/ui/redundant_pattern_matching_if_let_true.fixed @@ -20,18 +20,25 @@ fn main() { let mut k = 5; if k > 1 {} + //~^ redundant_pattern_matching if !(k > 5) {} + //~^ redundant_pattern_matching if k > 1 {} + //~^ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} while k > 1 { + //~^ redundant_pattern_matching k += 1; } while condition!() { + //~^ redundant_pattern_matching k += 1; } k > 5; + //~^ redundant_pattern_matching !(k > 5); + //~^ redundant_pattern_matching // Whole loop is from a macro expansion, don't lint: lettrue!(if); lettrue!(while); diff --git a/tests/ui/redundant_pattern_matching_if_let_true.rs b/tests/ui/redundant_pattern_matching_if_let_true.rs index a82e673982a3..143c279e41c1 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.rs +++ b/tests/ui/redundant_pattern_matching_if_let_true.rs @@ -20,18 +20,25 @@ fn main() { let mut k = 5; if let true = k > 1 {} + //~^ redundant_pattern_matching if let false = k > 5 {} + //~^ redundant_pattern_matching if let (true) = k > 1 {} + //~^ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} while let true = k > 1 { + //~^ redundant_pattern_matching k += 1; } while let true = condition!() { + //~^ redundant_pattern_matching k += 1; } matches!(k > 5, true); + //~^ redundant_pattern_matching matches!(k > 5, false); + //~^ redundant_pattern_matching // Whole loop is from a macro expansion, don't lint: lettrue!(if); lettrue!(while); diff --git a/tests/ui/redundant_pattern_matching_if_let_true.stderr b/tests/ui/redundant_pattern_matching_if_let_true.stderr index 43d5cd07cec7..db8646270609 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.stderr +++ b/tests/ui/redundant_pattern_matching_if_let_true.stderr @@ -8,37 +8,37 @@ LL | if let true = k > 1 {} = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: using `if let` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:23:8 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:24:8 | LL | if let false = k > 5 {} | ^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `!(k > 5)` error: using `if let` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:24:8 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:26:8 | LL | if let (true) = k > 1 {} | ^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 1` error: using `if let` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:26:11 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:29:11 | LL | while let true = k > 1 { | ^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 1` error: using `if let` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:29:11 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:33:11 | LL | while let true = condition!() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `condition!()` error: using `matches!` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:33:5 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:38:5 | LL | matches!(k > 5, true); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `k > 5` error: using `matches!` to pattern match a bool - --> tests/ui/redundant_pattern_matching_if_let_true.rs:34:5 + --> tests/ui/redundant_pattern_matching_if_let_true.rs:40:5 | LL | matches!(k > 5, false); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using the condition directly: `!(k > 5)` diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed index 429d33118a58..05ea8f75dc89 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -13,20 +13,27 @@ use std::net::{Ipv4Addr, Ipv6Addr}; fn main() { let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); if ipaddr.is_ipv4() {} + //~^ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching // Issue 6459 if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching // Issue 6459 if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} @@ -45,6 +52,7 @@ fn main() { V6(Ipv6Addr::LOCALHOST).is_ipv4(); let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() { + //~^ redundant_pattern_matching true } else { false @@ -53,8 +61,10 @@ fn main() { ipaddr_const(); let _ = if gen_ipaddr().is_ipv4() { + //~^ redundant_pattern_matching 1 } else if gen_ipaddr().is_ipv6() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -67,12 +77,16 @@ fn gen_ipaddr() -> IpAddr { const fn ipaddr_const() { if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} + //~^ redundant_pattern_matching while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} + //~^ redundant_pattern_matching V4(Ipv4Addr::LOCALHOST).is_ipv4(); diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs index e7136b72c20c..4ff9b2204e8a 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -13,20 +13,27 @@ use std::net::{Ipv4Addr, Ipv6Addr}; fn main() { let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST); if let V4(_) = &ipaddr {} + //~^ redundant_pattern_matching if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(V4(Ipv4Addr::LOCALHOST), V4(_)) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(V6(Ipv6Addr::LOCALHOST), V6(_)) {} + //~^ redundant_pattern_matching while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} @@ -37,26 +44,31 @@ fn main() { } match V4(Ipv4Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; match V4(Ipv4Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; match V6(Ipv6Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; match V6(Ipv6Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { + //~^ redundant_pattern_matching true } else { false @@ -65,8 +77,10 @@ fn main() { ipaddr_const(); let _ = if let V4(_) = gen_ipaddr() { + //~^ redundant_pattern_matching 1 } else if let V6(_) = gen_ipaddr() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -79,19 +93,25 @@ fn gen_ipaddr() -> IpAddr { const fn ipaddr_const() { if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} + //~^ redundant_pattern_matching while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} + //~^ redundant_pattern_matching match V4(Ipv4Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; match V6(Ipv6Addr::LOCALHOST) { + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr index a4930ad839f9..66d2cecdc0c9 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ b/tests/ui/redundant_pattern_matching_ipaddr.stderr @@ -8,132 +8,138 @@ LL | if let V4(_) = &ipaddr {} = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:17:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:18:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:19:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:21:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:22:8 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:25:8 | LL | if matches!(V4(Ipv4Addr::LOCALHOST), V4(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:25:8 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:29:8 | LL | if matches!(V6(Ipv6Addr::LOCALHOST), V6(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:27:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:32:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:29:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:35:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:39:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:46:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { +LL | | LL | | V4(_) => true, LL | | V6(_) => false, LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:44:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:52:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { +LL | | LL | | V4(_) => false, LL | | V6(_) => true, LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:49:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:58:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { +LL | | LL | | V4(_) => false, LL | | V6(_) => true, LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:54:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:64:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { +LL | | LL | | V4(_) => true, LL | | V6(_) => false, LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:59:20 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:70: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()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:67:20 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:79:20 | LL | let _ = if let V4(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:69:19 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:82:19 | LL | } else if let V6(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:81:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:95:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:83:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:98:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:85:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:101:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:87:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:104:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:89:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:107:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { +LL | | LL | | V4(_) => true, LL | | V6(_) => false, LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> tests/ui/redundant_pattern_matching_ipaddr.rs:94:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:113:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { +LL | | LL | | V4(_) => false, LL | | V6(_) => true, LL | | }; diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index c7e0cd2610f0..7d45bb63a395 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -12,10 +12,12 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { maybe_some.is_none() && (!boolean) + //~^ redundant_pattern_matching } fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs parentheses + //~^ redundant_pattern_matching let _ = match maybe_some { // can't use `matches!` here // because `expr` metavars in macros don't allow let exprs @@ -30,23 +32,30 @@ fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option.is_none() {} + //~^ redundant_pattern_matching if Some(42).is_some() {} + //~^ redundant_pattern_matching if Some(42).is_some() { + //~^ redundant_pattern_matching foo(); } else { bar(); } while Some(42).is_some() {} + //~^ redundant_pattern_matching while Some(42).is_none() {} + //~^ redundant_pattern_matching while None::<()>.is_none() {} + //~^ redundant_pattern_matching let mut v = vec![1, 2, 3]; while v.pop().is_some() { + //~^ redundant_pattern_matching foo(); } @@ -62,20 +71,24 @@ fn main() { let opt = Some(false); let _ = if opt.is_some() { true } else { false }; + //~^ redundant_pattern_matching issue6067(); issue10726(); issue10803(); let _ = if gen_opt().is_some() { + //~^ redundant_pattern_matching 1 } else if gen_opt().is_none() { + //~^ redundant_pattern_matching 2 } else { 3 }; if gen_opt().is_some() {} + //~^ redundant_pattern_matching } fn gen_opt() -> Option<()> { @@ -91,12 +104,16 @@ fn bar() {} // so the following should be linted. const fn issue6067() { if Some(42).is_some() {} + //~^ redundant_pattern_matching if None::<()>.is_none() {} + //~^ redundant_pattern_matching while Some(42).is_some() {} + //~^ redundant_pattern_matching while None::<()>.is_none() {} + //~^ redundant_pattern_matching Some(42).is_some(); @@ -106,7 +123,9 @@ const fn issue6067() { #[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] fn issue7921() { if (&None::<()>).is_none() {} + //~^ redundant_pattern_matching if (&None::<()>).is_none() {} + //~^ redundant_pattern_matching } fn issue10726() { @@ -131,8 +150,10 @@ fn issue10803() { let x = Some(42); let _ = x.is_some(); + //~^ redundant_pattern_matching let _ = x.is_none(); + //~^ redundant_pattern_matching // Don't lint let _ = matches!(x, Some(16)); @@ -143,5 +164,6 @@ fn issue13902() { let p = &raw const x; unsafe { let _ = (*p).is_none(); + //~^ redundant_pattern_matching } } diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index 6d9a9f7f9428..3d02bade4409 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -12,10 +12,12 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { matches!(maybe_some, None if !boolean) + //~^ redundant_pattern_matching } fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses + //~^ redundant_pattern_matching let _ = match maybe_some { // can't use `matches!` here // because `expr` metavars in macros don't allow let exprs @@ -30,23 +32,30 @@ fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option {} + //~^ redundant_pattern_matching if let Some(_) = Some(42) {} + //~^ redundant_pattern_matching if let Some(_) = Some(42) { + //~^ redundant_pattern_matching foo(); } else { bar(); } while let Some(_) = Some(42) {} + //~^ redundant_pattern_matching while let None = Some(42) {} + //~^ redundant_pattern_matching while let None = None::<()> {} + //~^ redundant_pattern_matching let mut v = vec![1, 2, 3]; while let Some(_) = v.pop() { + //~^ redundant_pattern_matching foo(); } @@ -55,36 +64,43 @@ fn main() { if Some(42).is_some() {} match Some(42) { + //~^ redundant_pattern_matching Some(_) => true, None => false, }; match None::<()> { + //~^ redundant_pattern_matching Some(_) => false, None => true, }; let _ = match None::<()> { + //~^ redundant_pattern_matching Some(_) => false, None => true, }; let opt = Some(false); let _ = if let Some(_) = opt { true } else { false }; + //~^ redundant_pattern_matching issue6067(); issue10726(); issue10803(); let _ = if let Some(_) = gen_opt() { + //~^ redundant_pattern_matching 1 } else if let None = gen_opt() { + //~^ redundant_pattern_matching 2 } else { 3 }; if let Some(..) = gen_opt() {} + //~^ redundant_pattern_matching } fn gen_opt() -> Option<()> { @@ -100,19 +116,25 @@ fn bar() {} // so the following should be linted. const fn issue6067() { if let Some(_) = Some(42) {} + //~^ redundant_pattern_matching if let None = None::<()> {} + //~^ redundant_pattern_matching while let Some(_) = Some(42) {} + //~^ redundant_pattern_matching while let None = None::<()> {} + //~^ redundant_pattern_matching match Some(42) { + //~^ redundant_pattern_matching Some(_) => true, None => false, }; match None::<()> { + //~^ redundant_pattern_matching Some(_) => false, None => true, }; @@ -121,28 +143,34 @@ const fn issue6067() { #[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] fn issue7921() { if let None = *(&None::<()>) {} + //~^ redundant_pattern_matching if let None = *&None::<()> {} + //~^ redundant_pattern_matching } fn issue10726() { let x = Some(42); match x { + //~^ redundant_pattern_matching Some(_) => true, _ => false, }; match x { + //~^ redundant_pattern_matching None => true, _ => false, }; match x { + //~^ redundant_pattern_matching Some(_) => false, _ => true, }; match x { + //~^ redundant_pattern_matching None => false, _ => true, }; @@ -158,8 +186,10 @@ fn issue10803() { let x = Some(42); let _ = matches!(x, Some(_)); + //~^ redundant_pattern_matching let _ = matches!(x, None); + //~^ redundant_pattern_matching // Don't lint let _ = matches!(x, Some(16)); @@ -170,5 +200,6 @@ fn issue13902() { let p = &raw const x; unsafe { let _ = matches!(*p, None); + //~^ redundant_pattern_matching } } diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index 34d80f5ca782..0dfa05970ce3 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -8,209 +8,218 @@ LL | matches!(maybe_some, None if !boolean) = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:18:13 + --> tests/ui/redundant_pattern_matching_option.rs:19: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()` - --> tests/ui/redundant_pattern_matching_option.rs:32:12 + --> tests/ui/redundant_pattern_matching_option.rs:34:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:34:12 + --> tests/ui/redundant_pattern_matching_option.rs:37:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:36:12 + --> tests/ui/redundant_pattern_matching_option.rs:40:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:42:15 + --> tests/ui/redundant_pattern_matching_option.rs:47:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:44:15 + --> tests/ui/redundant_pattern_matching_option.rs:50:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:46:15 + --> tests/ui/redundant_pattern_matching_option.rs:53:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:49:15 + --> tests/ui/redundant_pattern_matching_option.rs:57:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:57:5 + --> tests/ui/redundant_pattern_matching_option.rs:66:5 | LL | / match Some(42) { +LL | | LL | | Some(_) => true, LL | | None => false, LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:62:5 + --> tests/ui/redundant_pattern_matching_option.rs:72:5 | LL | / match None::<()> { +LL | | LL | | Some(_) => false, LL | | None => true, LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:67:13 + --> tests/ui/redundant_pattern_matching_option.rs:78:13 | LL | let _ = match None::<()> { | _____________^ +LL | | LL | | Some(_) => false, LL | | None => true, LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:73:20 + --> tests/ui/redundant_pattern_matching_option.rs:85:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:79:20 + --> tests/ui/redundant_pattern_matching_option.rs:92:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:81:19 + --> tests/ui/redundant_pattern_matching_option.rs:95:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:87:12 + --> tests/ui/redundant_pattern_matching_option.rs:102:12 | LL | if let Some(..) = gen_opt() {} | -------^^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:102:12 + --> tests/ui/redundant_pattern_matching_option.rs:118:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:104:12 + --> tests/ui/redundant_pattern_matching_option.rs:121:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:106:15 + --> tests/ui/redundant_pattern_matching_option.rs:124:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:108:15 + --> tests/ui/redundant_pattern_matching_option.rs:127:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:110:5 + --> tests/ui/redundant_pattern_matching_option.rs:130:5 | LL | / match Some(42) { +LL | | LL | | Some(_) => true, LL | | None => false, LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:115:5 + --> tests/ui/redundant_pattern_matching_option.rs:136:5 | LL | / match None::<()> { +LL | | LL | | Some(_) => false, LL | | None => true, LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:123:12 + --> tests/ui/redundant_pattern_matching_option.rs:145:12 | LL | if let None = *(&None::<()>) {} | -------^^^^----------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:124:12 + --> tests/ui/redundant_pattern_matching_option.rs:147:12 | LL | if let None = *&None::<()> {} | -------^^^^--------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:130:5 + --> tests/ui/redundant_pattern_matching_option.rs:154:5 | LL | / match x { +LL | | LL | | Some(_) => true, LL | | _ => false, LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:135:5 + --> tests/ui/redundant_pattern_matching_option.rs:160:5 | LL | / match x { +LL | | LL | | None => true, LL | | _ => false, LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:140:5 + --> tests/ui/redundant_pattern_matching_option.rs:166:5 | LL | / match x { +LL | | LL | | Some(_) => false, LL | | _ => true, LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:145:5 + --> tests/ui/redundant_pattern_matching_option.rs:172:5 | LL | / match x { +LL | | LL | | None => false, LL | | _ => true, LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:160:13 + --> tests/ui/redundant_pattern_matching_option.rs:188:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:162:13 + --> tests/ui/redundant_pattern_matching_option.rs:191:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:172:17 + --> tests/ui/redundant_pattern_matching_option.rs:202:17 | LL | let _ = matches!(*p, None); | ^^^^^^^^^^^^^^^^^^ help: try: `(*p).is_none()` diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed index 08d83f87e4c3..f3ffb6b3c755 100644 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ b/tests/ui/redundant_pattern_matching_poll.fixed @@ -13,10 +13,13 @@ use std::task::Poll::{self, Pending, Ready}; fn main() { if Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching if Ready(42).is_ready() {} + //~^ redundant_pattern_matching if Ready(42).is_ready() { + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -24,15 +27,20 @@ fn main() { // Issue 6459 if Ready(42).is_ready() {} + //~^ redundant_pattern_matching // Issue 6459 if Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching while Ready(42).is_ready() {} + //~^ redundant_pattern_matching while Ready(42).is_pending() {} + //~^ redundant_pattern_matching while Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching if Pending::.is_pending() {} @@ -46,12 +54,15 @@ fn main() { let poll = Ready(false); let _ = if poll.is_ready() { true } else { false }; + //~^ redundant_pattern_matching poll_const(); let _ = if gen_poll().is_ready() { + //~^ redundant_pattern_matching 1 } else if gen_poll().is_pending() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -68,12 +79,16 @@ fn bar() {} const fn poll_const() { if Ready(42).is_ready() {} + //~^ redundant_pattern_matching if Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching while Ready(42).is_ready() {} + //~^ redundant_pattern_matching while Pending::<()>.is_pending() {} + //~^ redundant_pattern_matching Ready(42).is_ready(); diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs index 7bc2b3be4d34..30e80b24521d 100644 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ b/tests/ui/redundant_pattern_matching_poll.rs @@ -13,10 +13,13 @@ use std::task::Poll::{self, Pending, Ready}; fn main() { if let Pending = Pending::<()> {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(42) {} + //~^ redundant_pattern_matching if let Ready(_) = Ready(42) { + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -24,43 +27,54 @@ fn main() { // Issue 6459 if matches!(Ready(42), Ready(_)) {} + //~^ redundant_pattern_matching // Issue 6459 if matches!(Pending::<()>, Pending) {} + //~^ redundant_pattern_matching while let Ready(_) = Ready(42) {} + //~^ redundant_pattern_matching while let Pending = Ready(42) {} + //~^ redundant_pattern_matching while let Pending = Pending::<()> {} + //~^ redundant_pattern_matching if Pending::.is_pending() {} if Ready(42).is_ready() {} match Ready(42) { + //~^ redundant_pattern_matching Ready(_) => true, Pending => false, }; match Pending::<()> { + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; let _ = match Pending::<()> { + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; let poll = Ready(false); let _ = if let Ready(_) = poll { true } else { false }; + //~^ redundant_pattern_matching poll_const(); let _ = if let Ready(_) = gen_poll() { + //~^ redundant_pattern_matching 1 } else if let Pending = gen_poll() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -77,19 +91,25 @@ fn bar() {} const fn poll_const() { if let Ready(_) = Ready(42) {} + //~^ redundant_pattern_matching if let Pending = Pending::<()> {} + //~^ redundant_pattern_matching while let Ready(_) = Ready(42) {} + //~^ redundant_pattern_matching while let Pending = Pending::<()> {} + //~^ redundant_pattern_matching match Ready(42) { + //~^ redundant_pattern_matching Ready(_) => true, Pending => false, }; match Pending::<()> { + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr index 2b0f087fb993..5f659184f7b3 100644 --- a/tests/ui/redundant_pattern_matching_poll.stderr +++ b/tests/ui/redundant_pattern_matching_poll.stderr @@ -8,130 +8,135 @@ LL | if let Pending = Pending::<()> {} = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:17:12 + --> tests/ui/redundant_pattern_matching_poll.rs:18:12 | LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:19:12 + --> tests/ui/redundant_pattern_matching_poll.rs:21:12 | LL | if let Ready(_) = Ready(42) { | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:26:8 + --> tests/ui/redundant_pattern_matching_poll.rs:29:8 | LL | if matches!(Ready(42), Ready(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:29:8 + --> tests/ui/redundant_pattern_matching_poll.rs:33:8 | LL | if matches!(Pending::<()>, Pending) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:31:15 + --> tests/ui/redundant_pattern_matching_poll.rs:36:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:33:15 + --> tests/ui/redundant_pattern_matching_poll.rs:39:15 | LL | while let Pending = Ready(42) {} | ----------^^^^^^^------------ help: try: `while Ready(42).is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:35:15 + --> tests/ui/redundant_pattern_matching_poll.rs:42:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:41:5 + --> tests/ui/redundant_pattern_matching_poll.rs:49:5 | LL | / match Ready(42) { +LL | | LL | | Ready(_) => true, LL | | Pending => false, LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:46:5 + --> tests/ui/redundant_pattern_matching_poll.rs:55:5 | LL | / match Pending::<()> { +LL | | LL | | Ready(_) => false, LL | | Pending => true, LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:51:13 + --> tests/ui/redundant_pattern_matching_poll.rs:61:13 | LL | let _ = match Pending::<()> { | _____________^ +LL | | LL | | Ready(_) => false, LL | | Pending => true, LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:57:20 + --> tests/ui/redundant_pattern_matching_poll.rs:68:20 | LL | let _ = if let Ready(_) = poll { true } else { false }; | -------^^^^^^^^------- help: try: `if poll.is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:61:20 + --> tests/ui/redundant_pattern_matching_poll.rs:73:20 | LL | let _ = if let Ready(_) = gen_poll() { | -------^^^^^^^^------------- help: try: `if gen_poll().is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:63:19 + --> tests/ui/redundant_pattern_matching_poll.rs:76:19 | LL | } else if let Pending = gen_poll() { | -------^^^^^^^------------- help: try: `if gen_poll().is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:79:12 + --> tests/ui/redundant_pattern_matching_poll.rs:93:12 | LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:81:12 + --> tests/ui/redundant_pattern_matching_poll.rs:96:12 | LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:83:15 + --> tests/ui/redundant_pattern_matching_poll.rs:99:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:85:15 + --> tests/ui/redundant_pattern_matching_poll.rs:102:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> tests/ui/redundant_pattern_matching_poll.rs:87:5 + --> tests/ui/redundant_pattern_matching_poll.rs:105:5 | LL | / match Ready(42) { +LL | | LL | | Ready(_) => true, LL | | Pending => false, LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> tests/ui/redundant_pattern_matching_poll.rs:92:5 + --> tests/ui/redundant_pattern_matching_poll.rs:111:5 | LL | / match Pending::<()> { +LL | | LL | | Ready(_) => false, LL | | Pending => true, LL | | }; diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index 9571aaee7424..3bb9dacf4618 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -13,14 +13,19 @@ fn main() { let result: Result = Err(5); if result.is_ok() {} + //~^ redundant_pattern_matching if Ok::(42).is_ok() {} + //~^ redundant_pattern_matching if Err::(42).is_err() {} + //~^ redundant_pattern_matching while Ok::(10).is_ok() {} + //~^ redundant_pattern_matching while Ok::(10).is_err() {} + //~^ redundant_pattern_matching if Ok::(42).is_ok() {} @@ -39,6 +44,7 @@ fn main() { Err::(42).is_ok(); let _ = if Ok::(4).is_ok() { true } else { false }; + //~^ redundant_pattern_matching issue5504(); issue6067(); @@ -47,8 +53,10 @@ fn main() { issue10803(); let _ = if gen_res().is_ok() { + //~^ redundant_pattern_matching 1 } else if gen_res().is_err() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -72,14 +80,18 @@ fn issue5504() { fn try_result_opt() -> Result { while r#try!(result_opt()).is_some() {} + //~^ redundant_pattern_matching if r#try!(result_opt()).is_some() {} + //~^ redundant_pattern_matching Ok(42) } try_result_opt(); if m!().is_some() {} + //~^ redundant_pattern_matching while m!().is_some() {} + //~^ redundant_pattern_matching } fn issue6065() { @@ -98,12 +110,16 @@ fn issue6065() { // so the following should be linted. const fn issue6067() { if Ok::(42).is_ok() {} + //~^ redundant_pattern_matching if Err::(42).is_err() {} + //~^ redundant_pattern_matching while Ok::(10).is_ok() {} + //~^ redundant_pattern_matching while Ok::(10).is_err() {} + //~^ redundant_pattern_matching Ok::(42).is_ok(); @@ -139,8 +155,10 @@ fn issue10803() { let x: Result = Ok(42); let _ = x.is_ok(); + //~^ redundant_pattern_matching let _ = x.is_err(); + //~^ redundant_pattern_matching // Don't lint let _ = matches!(x, Ok(16)); diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index 4fc65aa70b54..f2632286ea3c 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -13,14 +13,19 @@ fn main() { let result: Result = Err(5); if let Ok(_) = &result {} + //~^ redundant_pattern_matching if let Ok(_) = Ok::(42) {} + //~^ redundant_pattern_matching if let Err(_) = Err::(42) {} + //~^ redundant_pattern_matching while let Ok(_) = Ok::(10) {} + //~^ redundant_pattern_matching while let Err(_) = Ok::(10) {} + //~^ redundant_pattern_matching if Ok::(42).is_ok() {} @@ -31,26 +36,31 @@ fn main() { } match Ok::(42) { + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; match Ok::(42) { + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; match Err::(42) { + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; match Err::(42) { + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; let _ = if let Ok(_) = Ok::(4) { true } else { false }; + //~^ redundant_pattern_matching issue5504(); issue6067(); @@ -59,8 +69,10 @@ fn main() { issue10803(); let _ = if let Ok(_) = gen_res() { + //~^ redundant_pattern_matching 1 } else if let Err(_) = gen_res() { + //~^ redundant_pattern_matching 2 } else { 3 @@ -84,14 +96,18 @@ fn issue5504() { fn try_result_opt() -> Result { while let Some(_) = r#try!(result_opt()) {} + //~^ redundant_pattern_matching if let Some(_) = r#try!(result_opt()) {} + //~^ redundant_pattern_matching Ok(42) } try_result_opt(); if let Some(_) = m!() {} + //~^ redundant_pattern_matching while let Some(_) = m!() {} + //~^ redundant_pattern_matching } fn issue6065() { @@ -110,19 +126,25 @@ fn issue6065() { // so the following should be linted. const fn issue6067() { if let Ok(_) = Ok::(42) {} + //~^ redundant_pattern_matching if let Err(_) = Err::(42) {} + //~^ redundant_pattern_matching while let Ok(_) = Ok::(10) {} + //~^ redundant_pattern_matching while let Err(_) = Ok::(10) {} + //~^ redundant_pattern_matching match Ok::(42) { + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; match Err::(42) { + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; @@ -133,21 +155,25 @@ fn issue10726() { let x: Result = Ok(42); match x { + //~^ redundant_pattern_matching Ok(_) => true, _ => false, }; match x { + //~^ redundant_pattern_matching Ok(_) => false, _ => true, }; match x { + //~^ redundant_pattern_matching Err(_) => true, _ => false, }; match x { + //~^ redundant_pattern_matching Err(_) => false, _ => true, }; @@ -169,8 +195,10 @@ fn issue10803() { let x: Result = Ok(42); let _ = matches!(x, Ok(_)); + //~^ redundant_pattern_matching let _ = matches!(x, Err(_)); + //~^ redundant_pattern_matching // Don't lint let _ = matches!(x, Ok(16)); diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr index 991e6225ecb6..4f78b95356c2 100644 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ b/tests/ui/redundant_pattern_matching_result.stderr @@ -8,193 +8,203 @@ LL | if let Ok(_) = &result {} = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:17:12 + --> tests/ui/redundant_pattern_matching_result.rs:18:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:19:12 + --> tests/ui/redundant_pattern_matching_result.rs:21:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:21:15 + --> tests/ui/redundant_pattern_matching_result.rs:24:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:23:15 + --> tests/ui/redundant_pattern_matching_result.rs:27:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:33:5 + --> tests/ui/redundant_pattern_matching_result.rs:38:5 | LL | / match Ok::(42) { +LL | | LL | | Ok(_) => true, LL | | Err(_) => false, LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:38:5 + --> tests/ui/redundant_pattern_matching_result.rs:44:5 | LL | / match Ok::(42) { +LL | | LL | | Ok(_) => false, LL | | Err(_) => true, LL | | }; | |_____^ help: try: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:43:5 + --> tests/ui/redundant_pattern_matching_result.rs:50:5 | LL | / match Err::(42) { +LL | | LL | | Ok(_) => false, LL | | Err(_) => true, LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:48:5 + --> tests/ui/redundant_pattern_matching_result.rs:56:5 | LL | / match Err::(42) { +LL | | LL | | Ok(_) => true, LL | | Err(_) => false, LL | | }; | |_____^ help: try: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:53:20 + --> tests/ui/redundant_pattern_matching_result.rs:62: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()` - --> tests/ui/redundant_pattern_matching_result.rs:61:20 + --> tests/ui/redundant_pattern_matching_result.rs:71:20 | LL | let _ = if let Ok(_) = gen_res() { | -------^^^^^------------ help: try: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:63:19 + --> tests/ui/redundant_pattern_matching_result.rs:74:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_result.rs:86:19 + --> tests/ui/redundant_pattern_matching_result.rs:98: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()` - --> tests/ui/redundant_pattern_matching_result.rs:87:16 + --> tests/ui/redundant_pattern_matching_result.rs:100: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()` - --> tests/ui/redundant_pattern_matching_result.rs:93:12 + --> tests/ui/redundant_pattern_matching_result.rs:107:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_result.rs:94:15 + --> tests/ui/redundant_pattern_matching_result.rs:109:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try: `while m!().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:112:12 + --> tests/ui/redundant_pattern_matching_result.rs:128:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:114:12 + --> tests/ui/redundant_pattern_matching_result.rs:131:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:116:15 + --> tests/ui/redundant_pattern_matching_result.rs:134:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:118:15 + --> tests/ui/redundant_pattern_matching_result.rs:137:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:120:5 + --> tests/ui/redundant_pattern_matching_result.rs:140:5 | LL | / match Ok::(42) { +LL | | LL | | Ok(_) => true, LL | | Err(_) => false, LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:125:5 + --> tests/ui/redundant_pattern_matching_result.rs:146:5 | LL | / match Err::(42) { +LL | | LL | | Ok(_) => false, LL | | Err(_) => true, LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:135:5 + --> tests/ui/redundant_pattern_matching_result.rs:157:5 | LL | / match x { +LL | | LL | | Ok(_) => true, LL | | _ => false, LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:140:5 + --> tests/ui/redundant_pattern_matching_result.rs:163:5 | LL | / match x { +LL | | LL | | Ok(_) => false, LL | | _ => true, LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:145:5 + --> tests/ui/redundant_pattern_matching_result.rs:169:5 | LL | / match x { +LL | | LL | | Err(_) => true, LL | | _ => false, LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:150:5 + --> tests/ui/redundant_pattern_matching_result.rs:175:5 | LL | / match x { +LL | | LL | | Err(_) => false, LL | | _ => true, LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> tests/ui/redundant_pattern_matching_result.rs:171:13 + --> tests/ui/redundant_pattern_matching_result.rs:197:13 | LL | let _ = matches!(x, Ok(_)); | ^^^^^^^^^^^^^^^^^^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> tests/ui/redundant_pattern_matching_result.rs:173:13 + --> tests/ui/redundant_pattern_matching_result.rs:200: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 8882a4d50a5f..2072282bd2c3 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -5,24 +5,29 @@ mod m1 { fn f() {} pub fn g() {} // private due to m1 + //~^ redundant_pub_crate pub fn h() {} mod m1_1 { fn f() {} pub fn g() {} // private due to m1_1 and m1 + //~^ redundant_pub_crate pub fn h() {} } pub mod m1_2 { + //~^ redundant_pub_crate //:^ private due to m1 fn f() {} pub fn g() {} // private due to m1_2 and m1 + //~^ redundant_pub_crate pub fn h() {} } pub mod m1_3 { fn f() {} pub fn g() {} // private due to m1 + //~^ redundant_pub_crate pub fn h() {} } } @@ -30,24 +35,29 @@ mod m1 { pub(crate) mod m2 { fn f() {} pub fn g() {} // already crate visible due to m2 + //~^ redundant_pub_crate pub fn h() {} mod m2_1 { fn f() {} pub fn g() {} // private due to m2_1 + //~^ redundant_pub_crate pub fn h() {} } pub mod m2_2 { + //~^ redundant_pub_crate //:^ already crate visible due to m2 fn f() {} pub fn g() {} // already crate visible due to m2_2 and m2 + //~^ redundant_pub_crate pub fn h() {} } pub mod m2_3 { fn f() {} pub fn g() {} // already crate visible due to m2 + //~^ redundant_pub_crate pub fn h() {} } } @@ -60,6 +70,7 @@ pub mod m3 { mod m3_1 { fn f() {} pub fn g() {} // private due to m3_1 + //~^ redundant_pub_crate pub fn h() {} } @@ -67,6 +78,7 @@ pub mod m3 { //:^ ok fn f() {} pub fn g() {} // already crate visible due to m3_2 + //~^ redundant_pub_crate pub fn h() {} } @@ -80,18 +92,22 @@ pub mod m3 { mod m4 { fn f() {} pub fn g() {} // private: not re-exported by `pub use m4::*` + //~^ redundant_pub_crate pub fn h() {} mod m4_1 { fn f() {} pub fn g() {} // private due to m4_1 + //~^ redundant_pub_crate pub fn h() {} } pub mod m4_2 { + //~^ redundant_pub_crate //:^ private: not re-exported by `pub use m4::*` fn f() {} pub fn g() {} // private due to m4_2 + //~^ redundant_pub_crate pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index 5c8cab9be161..d8eaa8cdbc69 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -5,24 +5,29 @@ mod m1 { fn f() {} pub(crate) fn g() {} // private due to m1 + //~^ redundant_pub_crate pub fn h() {} mod m1_1 { fn f() {} pub(crate) fn g() {} // private due to m1_1 and m1 + //~^ redundant_pub_crate pub fn h() {} } pub(crate) mod m1_2 { + //~^ redundant_pub_crate //:^ private due to m1 fn f() {} pub(crate) fn g() {} // private due to m1_2 and m1 + //~^ redundant_pub_crate pub fn h() {} } pub mod m1_3 { fn f() {} pub(crate) fn g() {} // private due to m1 + //~^ redundant_pub_crate pub fn h() {} } } @@ -30,24 +35,29 @@ mod m1 { pub(crate) mod m2 { fn f() {} pub(crate) fn g() {} // already crate visible due to m2 + //~^ redundant_pub_crate pub fn h() {} mod m2_1 { fn f() {} pub(crate) fn g() {} // private due to m2_1 + //~^ redundant_pub_crate pub fn h() {} } pub(crate) mod m2_2 { + //~^ redundant_pub_crate //:^ already crate visible due to m2 fn f() {} pub(crate) fn g() {} // already crate visible due to m2_2 and m2 + //~^ redundant_pub_crate pub fn h() {} } pub mod m2_3 { fn f() {} pub(crate) fn g() {} // already crate visible due to m2 + //~^ redundant_pub_crate pub fn h() {} } } @@ -60,6 +70,7 @@ pub mod m3 { mod m3_1 { fn f() {} pub(crate) fn g() {} // private due to m3_1 + //~^ redundant_pub_crate pub fn h() {} } @@ -67,6 +78,7 @@ pub mod m3 { //:^ ok fn f() {} pub(crate) fn g() {} // already crate visible due to m3_2 + //~^ redundant_pub_crate pub fn h() {} } @@ -80,18 +92,22 @@ pub mod m3 { mod m4 { fn f() {} pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` + //~^ redundant_pub_crate pub fn h() {} mod m4_1 { fn f() {} pub(crate) fn g() {} // private due to m4_1 + //~^ redundant_pub_crate pub fn h() {} } pub(crate) mod m4_2 { + //~^ redundant_pub_crate //:^ private: not re-exported by `pub use m4::*` fn f() {} pub(crate) fn g() {} // private due to m4_2 + //~^ redundant_pub_crate pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index 699e19b1abcf..90be83d948bd 100644 --- a/tests/ui/redundant_pub_crate.stderr +++ b/tests/ui/redundant_pub_crate.stderr @@ -10,7 +10,7 @@ LL | pub(crate) fn g() {} // private due to m1 = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:12:9 + --> tests/ui/redundant_pub_crate.rs:13:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -18,7 +18,7 @@ LL | pub(crate) fn g() {} // private due to m1_1 and m1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:16:5 + --> tests/ui/redundant_pub_crate.rs:18:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -26,7 +26,7 @@ LL | pub(crate) mod m1_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:19:9 + --> tests/ui/redundant_pub_crate.rs:22:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -34,7 +34,7 @@ LL | pub(crate) fn g() {} // private due to m1_2 and m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:25:9 + --> tests/ui/redundant_pub_crate.rs:29:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -42,7 +42,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:32:5 + --> tests/ui/redundant_pub_crate.rs:37:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -50,7 +50,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:37:9 + --> tests/ui/redundant_pub_crate.rs:43:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -58,7 +58,7 @@ LL | pub(crate) fn g() {} // private due to m2_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:41:5 + --> tests/ui/redundant_pub_crate.rs:48:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -66,7 +66,7 @@ LL | pub(crate) mod m2_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:44:9 + --> tests/ui/redundant_pub_crate.rs:52:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -74,7 +74,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:50:9 + --> tests/ui/redundant_pub_crate.rs:59:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -82,7 +82,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:62:9 + --> tests/ui/redundant_pub_crate.rs:72:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -90,7 +90,7 @@ LL | pub(crate) fn g() {} // private due to m3_1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:69:9 + --> tests/ui/redundant_pub_crate.rs:80:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -98,7 +98,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m3_2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:82:5 + --> tests/ui/redundant_pub_crate.rs:94:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -106,7 +106,7 @@ LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:87:9 + --> tests/ui/redundant_pub_crate.rs:100:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -114,7 +114,7 @@ LL | pub(crate) fn g() {} // private due to m4_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:91:5 + --> tests/ui/redundant_pub_crate.rs:105:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -122,7 +122,7 @@ LL | pub(crate) mod m4_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:94:9 + --> tests/ui/redundant_pub_crate.rs:109: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 a4c035ba8407..d640de71e446 100644 --- a/tests/ui/redundant_slicing.fixed +++ b/tests/ui/redundant_slicing.fixed @@ -6,10 +6,12 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; let _ = slice; // Redundant slice + //~^ redundant_slicing let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` let _ = (&*v); // Outer borrow is redundant + //~^ redundant_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Ok, re-borrows slice @@ -27,6 +29,7 @@ fn main() { }; } let _ = slice; + //~^ redundant_slicing macro_rules! m2 { ($e:expr) => { diff --git a/tests/ui/redundant_slicing.rs b/tests/ui/redundant_slicing.rs index 67fe702acf54..34596cf84799 100644 --- a/tests/ui/redundant_slicing.rs +++ b/tests/ui/redundant_slicing.rs @@ -6,10 +6,12 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; let _ = &slice[..]; // Redundant slice + //~^ redundant_slicing let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` let _ = &(&*v)[..]; // Outer borrow is redundant + //~^ redundant_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Ok, re-borrows slice @@ -27,6 +29,7 @@ fn main() { }; } let _ = &m!(slice)[..]; + //~^ redundant_slicing macro_rules! m2 { ($e:expr) => { diff --git a/tests/ui/redundant_slicing.stderr b/tests/ui/redundant_slicing.stderr index 269a597b3226..47a61b41e978 100644 --- a/tests/ui/redundant_slicing.stderr +++ b/tests/ui/redundant_slicing.stderr @@ -8,13 +8,13 @@ LL | let _ = &slice[..]; // Redundant slice = help: to override `-D warnings` add `#[allow(clippy::redundant_slicing)]` error: redundant slicing of the whole range - --> tests/ui/redundant_slicing.rs:12:13 + --> tests/ui/redundant_slicing.rs:13:13 | LL | let _ = &(&*v)[..]; // Outer borrow is redundant | ^^^^^^^^^^ help: use the original value instead: `(&*v)` error: redundant slicing of the whole range - --> tests/ui/redundant_slicing.rs:29:13 + --> tests/ui/redundant_slicing.rs:31: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 3d1c78bd12d9..86c6ca17eb20 100644 --- a/tests/ui/redundant_static_lifetimes.fixed +++ b/tests/ui/redundant_static_lifetimes.fixed @@ -6,40 +6,57 @@ struct Foo; const VAR_ONE: &str = "Test constant #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. const VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes const VAR_SIX: &u8 = &5; +//~^ redundant_static_lifetimes const VAR_HEIGHT: &Foo = &Foo {}; +//~^ redundant_static_lifetimes const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes static STATIC_VAR_SIX: &u8 = &5; +//~^ redundant_static_lifetimes static STATIC_VAR_HEIGHT: &Foo = &Foo {}; +//~^ redundant_static_lifetimes static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0]; +//~^ redundant_static_lifetimes fn main() { let false_positive: &'static str = "test"; @@ -69,4 +86,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { static V: &u8 = &17; + //~^ redundant_static_lifetimes } diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs index 5932f14b8d9a..6fefe6c232d2 100644 --- a/tests/ui/redundant_static_lifetimes.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -6,40 +6,57 @@ struct Foo; const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes const VAR_SIX: &'static u8 = &5; +//~^ redundant_static_lifetimes const VAR_HEIGHT: &'static Foo = &Foo {}; +//~^ redundant_static_lifetimes const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static +//~^ redundant_static_lifetimes static STATIC_VAR_SIX: &'static u8 = &5; +//~^ redundant_static_lifetimes static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; +//~^ redundant_static_lifetimes static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. +//~^ redundant_static_lifetimes static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0]; +//~^ redundant_static_lifetimes fn main() { let false_positive: &'static str = "test"; @@ -69,4 +86,5 @@ fn msrv_1_16() { #[clippy::msrv = "1.17"] fn msrv_1_17() { static V: &'static u8 = &17; + //~^ redundant_static_lifetimes } diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr index 48871eba2dc7..955882703955 100644 --- a/tests/ui/redundant_static_lifetimes.stderr +++ b/tests/ui/redundant_static_lifetimes.stderr @@ -8,103 +8,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes.rs:12:21 + --> tests/ui/redundant_static_lifetimes.rs:13: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 - --> tests/ui/redundant_static_lifetimes.rs:14:32 + --> tests/ui/redundant_static_lifetimes.rs:16: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 - --> tests/ui/redundant_static_lifetimes.rs:14:47 + --> tests/ui/redundant_static_lifetimes.rs:16: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 - --> tests/ui/redundant_static_lifetimes.rs:16:17 + --> tests/ui/redundant_static_lifetimes.rs:20:17 | LL | const VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: constants have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes.rs:18:20 + --> tests/ui/redundant_static_lifetimes.rs:23:20 | LL | const VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: constants have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes.rs:20:19 + --> tests/ui/redundant_static_lifetimes.rs:26: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 - --> tests/ui/redundant_static_lifetimes.rs:22:19 + --> tests/ui/redundant_static_lifetimes.rs:29: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 - --> tests/ui/redundant_static_lifetimes.rs:24:19 + --> tests/ui/redundant_static_lifetimes.rs:32: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 - --> tests/ui/redundant_static_lifetimes.rs:26:25 + --> tests/ui/redundant_static_lifetimes.rs:35: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 - --> tests/ui/redundant_static_lifetimes.rs:30:29 + --> tests/ui/redundant_static_lifetimes.rs:40: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 - --> tests/ui/redundant_static_lifetimes.rs:32:25 + --> tests/ui/redundant_static_lifetimes.rs:43:25 | LL | static STATIC_VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: statics have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes.rs:34:28 + --> tests/ui/redundant_static_lifetimes.rs:46:28 | LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: statics have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes.rs:36:27 + --> tests/ui/redundant_static_lifetimes.rs:49: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 - --> tests/ui/redundant_static_lifetimes.rs:38:27 + --> tests/ui/redundant_static_lifetimes.rs:52: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 - --> tests/ui/redundant_static_lifetimes.rs:40:27 + --> tests/ui/redundant_static_lifetimes.rs:55: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 - --> tests/ui/redundant_static_lifetimes.rs:42:31 + --> tests/ui/redundant_static_lifetimes.rs:58: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 - --> tests/ui/redundant_static_lifetimes.rs:71:16 + --> tests/ui/redundant_static_lifetimes.rs:88: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 bfcab420b1f4..02f3829d8c03 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/tests/ui/redundant_static_lifetimes_multiple.rs @@ -2,24 +2,34 @@ // 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 +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes + + + 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 +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes + + 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 +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes + + 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 +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes + + 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 +//~^ redundant_static_lifetimes +//~| redundant_static_lifetimes + + fn main() {} diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 330703d9eff1..486a23b06089 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -14,49 +14,49 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes_multiple.rs:9:29 + --> tests/ui/redundant_static_lifetimes_multiple.rs:11: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:9:39 + --> tests/ui/redundant_static_lifetimes_multiple.rs:11: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:13:40 + --> tests/ui/redundant_static_lifetimes_multiple.rs:17: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:13:55 + --> tests/ui/redundant_static_lifetimes_multiple.rs:17: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:17:26 + --> tests/ui/redundant_static_lifetimes_multiple.rs:23: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:17:38 + --> tests/ui/redundant_static_lifetimes_multiple.rs:23: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:21:37 + --> tests/ui/redundant_static_lifetimes_multiple.rs:29: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:21:47 + --> tests/ui/redundant_static_lifetimes_multiple.rs:29: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 dc9b073ffba8..5023ec7ee576 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -79,12 +79,15 @@ 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` + //~^ redundant_type_annotations + + let v: &u32 = self.return_a_ref(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let v: &Slice = self.return_a_ref_to_struct(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + } } @@ -157,50 +160,64 @@ fn test_functions() { // Everything here should be lint let _return: String = return_a_string(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: Pie = return_a_struct(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: Pizza = return_an_enum(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: u32 = return_an_int(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: String = String::new(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let new_pie: Pie = Pie::new(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: u32 = new_pie.return_an_int(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: u32 = Pie::associated_return_an_int(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _return: String = Pie::associated_return_a_string(); - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + } fn test_simple_types() { // Everything here should be lint let _var: u32 = u32::MAX; - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _var: u32 = 5_u32; - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _var: &str = "test"; - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _var: &[u8; 4] = b"test"; - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + let _var: bool = false; - //~^ ERROR: redundant type annotation + //~^ redundant_type_annotations + } fn issue12212() { diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index 4768f4d3c57c..de78ad5e4b48 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -8,97 +8,97 @@ LL | let v: u32 = self.return_an_int(); = help: to override `-D warnings` add `#[allow(clippy::redundant_type_annotations)]` error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:84:9 + --> tests/ui/redundant_type_annotations.rs:85:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:86:9 + --> tests/ui/redundant_type_annotations.rs:88:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:159:5 + --> tests/ui/redundant_type_annotations.rs:162:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:162:5 + --> tests/ui/redundant_type_annotations.rs:166:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:165:5 + --> tests/ui/redundant_type_annotations.rs:170:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:168:5 + --> tests/ui/redundant_type_annotations.rs:174:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:171:5 + --> tests/ui/redundant_type_annotations.rs:178:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:174:5 + --> tests/ui/redundant_type_annotations.rs:182:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:177:5 + --> tests/ui/redundant_type_annotations.rs:186:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:180:5 + --> tests/ui/redundant_type_annotations.rs:190:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:183:5 + --> tests/ui/redundant_type_annotations.rs:194:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:190:5 + --> tests/ui/redundant_type_annotations.rs:202:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:193:5 + --> tests/ui/redundant_type_annotations.rs:206:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:196:5 + --> tests/ui/redundant_type_annotations.rs:210:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:199:5 + --> tests/ui/redundant_type_annotations.rs:214:5 | LL | let _var: &[u8; 4] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:202:5 + --> tests/ui/redundant_type_annotations.rs:218:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index 6048267092f1..ce144508581e 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -5,53 +5,86 @@ fn f(_: T) {} fn main() { f(std::ptr::from_ref(&1u8)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&2u32)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&3.0f64)); + //~^ ref_as_ptr f(std::ptr::from_ref(&4) as *const f32); + //~^ ref_as_ptr f(std::ptr::from_ref::(&5.0f32) as *const u32); + //~^ ref_as_ptr f(std::ptr::from_ref(&mut 6u8)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&mut 7u32)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&mut 8.0f64)); + //~^ ref_as_ptr f(std::ptr::from_ref(&mut 9) as *const f32); + //~^ ref_as_ptr f(std::ptr::from_ref::(&mut 10.0f32) as *const u32); + //~^ ref_as_ptr f(std::ptr::from_mut(&mut 11u8)); + //~^ ref_as_ptr f(std::ptr::from_mut::(&mut 12u32)); + //~^ ref_as_ptr f(std::ptr::from_mut::(&mut 13.0f64)); + //~^ ref_as_ptr f(std::ptr::from_mut(&mut 14) as *const f32); + //~^ ref_as_ptr f(std::ptr::from_mut::(&mut 15.0f32) as *const u32); + //~^ ref_as_ptr f(std::ptr::from_ref(&1u8)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&2u32)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&3.0f64)); + //~^ ref_as_ptr f(std::ptr::from_ref(&4) as *const f32); + //~^ ref_as_ptr f(std::ptr::from_ref::(&5.0f32) as *const u32); + //~^ ref_as_ptr let val = 1; f(std::ptr::from_ref(&val)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&val)); + //~^ ref_as_ptr f(std::ptr::from_ref(&val) as *const f32); + //~^ ref_as_ptr f(std::ptr::from_ref::(&val) as *const f64); + //~^ ref_as_ptr let mut val: u8 = 2; f(std::ptr::from_mut::(&mut val)); + //~^ ref_as_ptr f(std::ptr::from_mut(&mut val)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&mut val)); + //~^ ref_as_ptr f(std::ptr::from_ref(&mut val)); + //~^ ref_as_ptr f(std::ptr::from_ref::(&mut val) as *const f64); + //~^ ref_as_ptr f::<*const Option>(std::ptr::from_ref(&mut val) as *const _); + //~^ ref_as_ptr f(std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))); + //~^ ref_as_ptr f(std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))); + //~^ ref_as_ptr f(std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))); + //~^ ref_as_ptr let _ = &String::new() as *const _; let _ = &mut String::new() as *mut _; @@ -74,17 +107,23 @@ fn _msrv_1_76() { let mut_val = &mut 42_i32; f(std::ptr::from_ref::(val)); + //~^ ref_as_ptr f(std::ptr::from_mut::(mut_val)); + //~^ ref_as_ptr } fn foo(val: &[u8]) { f(std::ptr::from_ref(val)); + //~^ ref_as_ptr f(std::ptr::from_ref::<[u8]>(val)); + //~^ ref_as_ptr } fn bar(val: &mut str) { f(std::ptr::from_mut(val)); + //~^ ref_as_ptr f(std::ptr::from_mut::(val)); + //~^ ref_as_ptr } struct X<'a>(&'a i32); @@ -92,10 +131,12 @@ struct X<'a>(&'a i32); impl<'a> X<'a> { fn foo(&self) -> *const i64 { std::ptr::from_ref(self.0) as *const _ + //~^ ref_as_ptr } fn bar(&mut self) -> *const i64 { std::ptr::from_ref(self.0) as *const _ + //~^ ref_as_ptr } } @@ -104,13 +145,16 @@ struct Y<'a>(&'a mut i32); impl<'a> Y<'a> { fn foo(&self) -> *const i64 { std::ptr::from_ref(self.0) as *const _ + //~^ ref_as_ptr } fn bar(&mut self) -> *const i64 { std::ptr::from_ref(self.0) as *const _ + //~^ ref_as_ptr } fn baz(&mut self) -> *const i64 { std::ptr::from_mut(self.0) as *mut _ + //~^ ref_as_ptr } } diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index 7f1d59b856e4..acdff2c2ba29 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -5,53 +5,86 @@ fn f(_: T) {} fn main() { f(&1u8 as *const _); + //~^ ref_as_ptr f(&2u32 as *const u32); + //~^ ref_as_ptr f(&3.0f64 as *const f64); + //~^ ref_as_ptr f(&4 as *const _ as *const f32); + //~^ ref_as_ptr f(&5.0f32 as *const f32 as *const u32); + //~^ ref_as_ptr f(&mut 6u8 as *const _); + //~^ ref_as_ptr f(&mut 7u32 as *const u32); + //~^ ref_as_ptr f(&mut 8.0f64 as *const f64); + //~^ ref_as_ptr f(&mut 9 as *const _ as *const f32); + //~^ ref_as_ptr f(&mut 10.0f32 as *const f32 as *const u32); + //~^ ref_as_ptr f(&mut 11u8 as *mut _); + //~^ ref_as_ptr f(&mut 12u32 as *mut u32); + //~^ ref_as_ptr f(&mut 13.0f64 as *mut f64); + //~^ ref_as_ptr f(&mut 14 as *mut _ as *const f32); + //~^ ref_as_ptr f(&mut 15.0f32 as *mut f32 as *const u32); + //~^ ref_as_ptr f(&1u8 as *const _); + //~^ ref_as_ptr f(&2u32 as *const u32); + //~^ ref_as_ptr f(&3.0f64 as *const f64); + //~^ ref_as_ptr f(&4 as *const _ as *const f32); + //~^ ref_as_ptr f(&5.0f32 as *const f32 as *const u32); + //~^ ref_as_ptr let val = 1; f(&val as *const _); + //~^ ref_as_ptr f(&val as *const i32); + //~^ ref_as_ptr f(&val as *const _ as *const f32); + //~^ ref_as_ptr f(&val as *const i32 as *const f64); + //~^ ref_as_ptr let mut val: u8 = 2; f(&mut val as *mut u8); + //~^ ref_as_ptr f(&mut val as *mut _); + //~^ ref_as_ptr f(&mut val as *const u8); + //~^ ref_as_ptr f(&mut val as *const _); + //~^ ref_as_ptr f(&mut val as *const u8 as *const f64); + //~^ ref_as_ptr f::<*const Option>(&mut val as *const _ as *const _); + //~^ ref_as_ptr f(&std::array::from_fn(|i| i * i) as *const [usize; 7]); + //~^ ref_as_ptr f(&mut std::array::from_fn(|i| i * i) as *const [usize; 8]); + //~^ ref_as_ptr f(&mut std::array::from_fn(|i| i * i) as *mut [usize; 9]); + //~^ ref_as_ptr let _ = &String::new() as *const _; let _ = &mut String::new() as *mut _; @@ -74,17 +107,23 @@ fn _msrv_1_76() { let mut_val = &mut 42_i32; f(val as *const i32); + //~^ ref_as_ptr f(mut_val as *mut i32); + //~^ ref_as_ptr } fn foo(val: &[u8]) { f(val as *const _); + //~^ ref_as_ptr f(val as *const [u8]); + //~^ ref_as_ptr } fn bar(val: &mut str) { f(val as *mut _); + //~^ ref_as_ptr f(val as *mut str); + //~^ ref_as_ptr } struct X<'a>(&'a i32); @@ -92,10 +131,12 @@ struct X<'a>(&'a i32); impl<'a> X<'a> { fn foo(&self) -> *const i64 { self.0 as *const _ as *const _ + //~^ ref_as_ptr } fn bar(&mut self) -> *const i64 { self.0 as *const _ as *const _ + //~^ ref_as_ptr } } @@ -104,13 +145,16 @@ struct Y<'a>(&'a mut i32); impl<'a> Y<'a> { fn foo(&self) -> *const i64 { self.0 as *const _ as *const _ + //~^ ref_as_ptr } fn bar(&mut self) -> *const i64 { self.0 as *const _ as *const _ + //~^ ref_as_ptr } fn baz(&mut self) -> *const i64 { self.0 as *mut _ as *mut _ + //~^ ref_as_ptr } } diff --git a/tests/ui/ref_as_ptr.stderr b/tests/ui/ref_as_ptr.stderr index c5e9af38aea0..79db29e596bd 100644 --- a/tests/ui/ref_as_ptr.stderr +++ b/tests/ui/ref_as_ptr.stderr @@ -8,259 +8,259 @@ LL | f(&1u8 as *const _); = help: to override `-D warnings` add `#[allow(clippy::ref_as_ptr)]` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:8:7 + --> tests/ui/ref_as_ptr.rs:9:7 | LL | f(&2u32 as *const u32); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:9:7 + --> tests/ui/ref_as_ptr.rs:11:7 | LL | f(&3.0f64 as *const f64); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:11:7 + --> tests/ui/ref_as_ptr.rs:14:7 | LL | f(&4 as *const _ as *const f32); | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:12:7 + --> tests/ui/ref_as_ptr.rs:16:7 | LL | f(&5.0f32 as *const f32 as *const u32); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:14:7 + --> tests/ui/ref_as_ptr.rs:19:7 | LL | f(&mut 6u8 as *const _); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 6u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:15:7 + --> tests/ui/ref_as_ptr.rs:21:7 | LL | f(&mut 7u32 as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 7u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:16:7 + --> tests/ui/ref_as_ptr.rs:23:7 | LL | f(&mut 8.0f64 as *const f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 8.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:18:7 + --> tests/ui/ref_as_ptr.rs:26:7 | LL | f(&mut 9 as *const _ as *const f32); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 9)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:19:7 + --> tests/ui/ref_as_ptr.rs:28:7 | LL | f(&mut 10.0f32 as *const f32 as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 10.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:21:7 + --> tests/ui/ref_as_ptr.rs:31:7 | LL | f(&mut 11u8 as *mut _); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 11u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:22:7 + --> tests/ui/ref_as_ptr.rs:33:7 | LL | f(&mut 12u32 as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 12u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:23:7 + --> tests/ui/ref_as_ptr.rs:35:7 | LL | f(&mut 13.0f64 as *mut f64); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 13.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:25:7 + --> tests/ui/ref_as_ptr.rs:38:7 | LL | f(&mut 14 as *mut _ as *const f32); | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 14)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:26:7 + --> tests/ui/ref_as_ptr.rs:40:7 | LL | f(&mut 15.0f32 as *mut f32 as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 15.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:28:7 + --> tests/ui/ref_as_ptr.rs:43:7 | LL | f(&1u8 as *const _); | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:29:7 + --> tests/ui/ref_as_ptr.rs:45:7 | LL | f(&2u32 as *const u32); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:30:7 + --> tests/ui/ref_as_ptr.rs:47:7 | LL | f(&3.0f64 as *const f64); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:32:7 + --> tests/ui/ref_as_ptr.rs:50:7 | LL | f(&4 as *const _ as *const f32); | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:33:7 + --> tests/ui/ref_as_ptr.rs:52:7 | LL | f(&5.0f32 as *const f32 as *const u32); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:36:7 + --> tests/ui/ref_as_ptr.rs:56:7 | LL | f(&val as *const _); | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:37:7 + --> tests/ui/ref_as_ptr.rs:58:7 | LL | f(&val as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:39:7 + --> tests/ui/ref_as_ptr.rs:61:7 | LL | f(&val as *const _ as *const f32); | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:40:7 + --> tests/ui/ref_as_ptr.rs:63:7 | LL | f(&val as *const i32 as *const f64); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:43:7 + --> tests/ui/ref_as_ptr.rs:67:7 | LL | f(&mut val as *mut u8); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:44:7 + --> tests/ui/ref_as_ptr.rs:69:7 | LL | f(&mut val as *mut _); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:46:7 + --> tests/ui/ref_as_ptr.rs:72:7 | LL | f(&mut val as *const u8); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:47:7 + --> tests/ui/ref_as_ptr.rs:74:7 | LL | f(&mut val as *const _); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:49:7 + --> tests/ui/ref_as_ptr.rs:77:7 | LL | f(&mut val as *const u8 as *const f64); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:50:28 + --> tests/ui/ref_as_ptr.rs:79:28 | LL | f::<*const Option>(&mut val as *const _ as *const _); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:52:7 + --> tests/ui/ref_as_ptr.rs:82:7 | LL | f(&std::array::from_fn(|i| i * i) as *const [usize; 7]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:53:7 + --> tests/ui/ref_as_ptr.rs:84:7 | LL | f(&mut std::array::from_fn(|i| i * i) as *const [usize; 8]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:54:7 + --> tests/ui/ref_as_ptr.rs:86:7 | LL | f(&mut std::array::from_fn(|i| i * i) as *mut [usize; 9]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:76:7 + --> tests/ui/ref_as_ptr.rs:109:7 | LL | f(val as *const i32); | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:77:7 + --> tests/ui/ref_as_ptr.rs:111:7 | LL | f(mut_val as *mut i32); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(mut_val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:81:7 + --> tests/ui/ref_as_ptr.rs:116:7 | LL | f(val as *const _); | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:82:7 + --> tests/ui/ref_as_ptr.rs:118:7 | LL | f(val as *const [u8]); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:86:7 + --> tests/ui/ref_as_ptr.rs:123:7 | LL | f(val as *mut _); | ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:87:7 + --> tests/ui/ref_as_ptr.rs:125:7 | LL | f(val as *mut str); | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:94:9 + --> tests/ui/ref_as_ptr.rs:133:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:98:9 + --> tests/ui/ref_as_ptr.rs:138:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:106:9 + --> tests/ui/ref_as_ptr.rs:147:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:110:9 + --> tests/ui/ref_as_ptr.rs:152:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:114:9 + --> tests/ui/ref_as_ptr.rs:157:9 | LL | self.0 as *mut _ as *mut _ | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)` diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index 001ed3119490..55df796c41dc 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -28,15 +28,17 @@ 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` + //~^ ref_binding_to_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 + //~^ ref_binding_to_reference + f1(x); f1(*x); x @@ -47,20 +49,23 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m2!(x), - //~^ ERROR: this pattern creates a reference to a reference + //~^ ref_binding_to_reference + None => return, } // Err, reference to a &String let _ = |&ref x: &&String| { - //~^ ERROR: this pattern creates a reference to a reference + //~^ ref_binding_to_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 +//~^ ref_binding_to_reference + let _: &&String = x; *x } @@ -68,7 +73,8 @@ 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 + //~^ ref_binding_to_reference + let _: &&String = x; } } @@ -77,7 +83,8 @@ 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 + //~^ ref_binding_to_reference + let _: &&String = x; } } diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 25ab98223827..66e769ec61b3 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -12,7 +12,7 @@ LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:38:14 + --> tests/ui/ref_binding_to_reference.rs:39:14 | LL | Some(ref x) => { | ^^^^^ @@ -21,13 +21,14 @@ help: try | LL ~ Some(x) => { LL | +LL | LL | f1(x); LL ~ f1(x); LL ~ &x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:49:14 + --> tests/ui/ref_binding_to_reference.rs:51:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -38,7 +39,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:55:15 + --> tests/ui/ref_binding_to_reference.rs:58:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -47,11 +48,12 @@ help: try | LL ~ let _ = |&x: &&String| { LL | +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:62:12 + --> tests/ui/ref_binding_to_reference.rs:66:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -60,12 +62,13 @@ help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { LL | +LL | LL ~ let _: &&String = &x; LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:70:11 + --> tests/ui/ref_binding_to_reference.rs:75:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -74,11 +77,12 @@ help: try | LL ~ fn f(&x: &&String) { LL | +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:79:11 + --> tests/ui/ref_binding_to_reference.rs:85:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -87,6 +91,7 @@ help: try | LL ~ fn f(&x: &&String) { LL | +LL | LL ~ let _: &&String = &x; | diff --git a/tests/ui/ref_option/ref_option.all.fixed b/tests/ui/ref_option/ref_option.all.fixed index 47781a97c983..d7b0e13e5bb9 100644 --- a/tests/ui/ref_option/ref_option.all.fixed +++ b/tests/ui/ref_option/ref_option.all.fixed @@ -6,42 +6,59 @@ #![warn(clippy::ref_option)] fn opt_u8(a: Option<&u8>) {} +//~^ ref_option fn opt_gen(a: Option<&T>) {} +//~^ ref_option fn opt_string(a: std::option::Option<&String>) {} +//~^ ref_option fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { +//~^ ref_option panic!() } fn ret_string_static() -> Option<&'static u8> { +//~^ ref_option panic!() } fn mult_string(a: Option<&String>, b: Option<&Vec>) {} +//~^ ref_option fn ret_box<'a>() -> Option<&'a Box> { +//~^ ref_option panic!() } pub fn pub_opt_string(a: Option<&String>) {} +//~[all]^ ref_option pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} +//~[all]^ ref_option pub trait PubTrait { fn pub_trait_opt(&self, a: Option<&Vec>); + //~[all]^ ref_option fn pub_trait_ret(&self) -> Option<&Vec>; + //~[all]^ ref_option } trait PrivateTrait { fn trait_opt(&self, a: Option<&String>); + //~^ ref_option fn trait_ret(&self) -> Option<&String>; + //~^ ref_option } pub struct PubStruct; impl PubStruct { pub fn pub_opt_params(&self, a: Option<&()>) {} + //~[all]^ ref_option pub fn pub_opt_ret(&self) -> Option<&String> { + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: Option<&()>) {} + //~^ ref_option fn private_opt_ret(&self) -> Option<&String> { + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option/ref_option.all.stderr b/tests/ui/ref_option/ref_option.all.stderr index b4c69ac62962..7eb425548745 100644 --- a/tests/ui/ref_option/ref_option.all.stderr +++ b/tests/ui/ref_option/ref_option.all.stderr @@ -10,7 +10,7 @@ LL | fn opt_u8(a: &Option) {} = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:9:1 + --> tests/ui/ref_option/ref_option.rs:10:1 | LL | fn opt_gen(a: &Option) {} | ^^^^^^^^^^^^^^^^^----------^^^^ @@ -18,7 +18,7 @@ LL | fn opt_gen(a: &Option) {} | help: change this to: `Option<&T>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:10:1 + --> tests/ui/ref_option/ref_option.rs:12:1 | LL | fn opt_string(a: &std::option::Option) {} | ^^^^^^^^^^^^^^^^^----------------------------^^^^ @@ -26,29 +26,31 @@ LL | fn opt_string(a: &std::option::Option) {} | help: change this to: `std::option::Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:11:1 + --> tests/ui/ref_option/ref_option.rs:14:1 | LL | fn ret_string<'a>(p: &'a str) -> &'a Option { | ^ -------------- help: change this to: `Option<&'a u8>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:14:1 + --> tests/ui/ref_option/ref_option.rs:18:1 | LL | fn ret_string_static() -> &'static Option { | ^ ------------------- help: change this to: `Option<&'static u8>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:17:1 + --> tests/ui/ref_option/ref_option.rs:22:1 | LL | fn mult_string(a: &Option, b: &Option>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,18 +61,19 @@ LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:18:1 + --> tests/ui/ref_option/ref_option.rs:24:1 | LL | fn ret_box<'a>() -> &'a Option> { | ^ ------------------- help: change this to: `Option<&'a Box>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:22:1 + --> tests/ui/ref_option/ref_option.rs:29:1 | LL | pub fn pub_opt_string(a: &Option) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^ @@ -78,7 +81,7 @@ LL | pub fn pub_opt_string(a: &Option) {} | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:23:1 + --> tests/ui/ref_option/ref_option.rs:31:1 | LL | pub fn pub_mult_string(a: &Option, b: &Option>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +92,7 @@ LL | pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec>) {} | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:26:5 + --> tests/ui/ref_option/ref_option.rs:35:5 | LL | fn pub_trait_opt(&self, a: &Option>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^ @@ -97,7 +100,7 @@ LL | fn pub_trait_opt(&self, a: &Option>); | help: change this to: `Option<&Vec>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:27:5 + --> tests/ui/ref_option/ref_option.rs:37:5 | LL | fn pub_trait_ret(&self) -> &Option>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^ @@ -105,7 +108,7 @@ LL | fn pub_trait_ret(&self) -> &Option>; | help: change this to: `Option<&Vec>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:31:5 + --> tests/ui/ref_option/ref_option.rs:42:5 | LL | fn trait_opt(&self, a: &Option); | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ @@ -113,7 +116,7 @@ LL | fn trait_opt(&self, a: &Option); | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:32:5 + --> tests/ui/ref_option/ref_option.rs:44:5 | LL | fn trait_ret(&self) -> &Option; | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ @@ -121,7 +124,7 @@ LL | fn trait_ret(&self) -> &Option; | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:38:5 + --> tests/ui/ref_option/ref_option.rs:51:5 | LL | pub fn pub_opt_params(&self, a: &Option<()>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ @@ -129,18 +132,19 @@ LL | pub fn pub_opt_params(&self, a: &Option<()>) {} | help: change this to: `Option<&()>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:39:5 + --> tests/ui/ref_option/ref_option.rs:53:5 | LL | pub fn pub_opt_ret(&self) -> &Option { | ^ --------------- help: change this to: `Option<&String>` | _____| | | +LL | | LL | | panic!() LL | | } | |_____^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:43:5 + --> tests/ui/ref_option/ref_option.rs:58:5 | LL | fn private_opt_params(&self, a: &Option<()>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ @@ -148,12 +152,13 @@ LL | fn private_opt_params(&self, a: &Option<()>) {} | help: change this to: `Option<&()>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:44:5 + --> tests/ui/ref_option/ref_option.rs:60:5 | LL | fn private_opt_ret(&self) -> &Option { | ^ --------------- help: change this to: `Option<&String>` | _____| | | +LL | | LL | | panic!() LL | | } | |_____^ diff --git a/tests/ui/ref_option/ref_option.private.fixed b/tests/ui/ref_option/ref_option.private.fixed index 8c42556e9b0d..4036c6a08dca 100644 --- a/tests/ui/ref_option/ref_option.private.fixed +++ b/tests/ui/ref_option/ref_option.private.fixed @@ -6,42 +6,59 @@ #![warn(clippy::ref_option)] fn opt_u8(a: Option<&u8>) {} +//~^ ref_option fn opt_gen(a: Option<&T>) {} +//~^ ref_option fn opt_string(a: std::option::Option<&String>) {} +//~^ ref_option fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { +//~^ ref_option panic!() } fn ret_string_static() -> Option<&'static u8> { +//~^ ref_option panic!() } fn mult_string(a: Option<&String>, b: Option<&Vec>) {} +//~^ ref_option fn ret_box<'a>() -> Option<&'a Box> { +//~^ ref_option panic!() } pub fn pub_opt_string(a: &Option) {} +//~[all]^ ref_option pub fn pub_mult_string(a: &Option, b: &Option>) {} +//~[all]^ ref_option pub trait PubTrait { fn pub_trait_opt(&self, a: &Option>); + //~[all]^ ref_option fn pub_trait_ret(&self) -> &Option>; + //~[all]^ ref_option } trait PrivateTrait { fn trait_opt(&self, a: Option<&String>); + //~^ ref_option fn trait_ret(&self) -> Option<&String>; + //~^ ref_option } pub struct PubStruct; impl PubStruct { pub fn pub_opt_params(&self, a: &Option<()>) {} + //~[all]^ ref_option pub fn pub_opt_ret(&self) -> &Option { + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: Option<&()>) {} + //~^ ref_option fn private_opt_ret(&self) -> Option<&String> { + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option/ref_option.private.stderr b/tests/ui/ref_option/ref_option.private.stderr index 17c90536da34..f608092161bb 100644 --- a/tests/ui/ref_option/ref_option.private.stderr +++ b/tests/ui/ref_option/ref_option.private.stderr @@ -10,7 +10,7 @@ LL | fn opt_u8(a: &Option) {} = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:9:1 + --> tests/ui/ref_option/ref_option.rs:10:1 | LL | fn opt_gen(a: &Option) {} | ^^^^^^^^^^^^^^^^^----------^^^^ @@ -18,7 +18,7 @@ LL | fn opt_gen(a: &Option) {} | help: change this to: `Option<&T>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:10:1 + --> tests/ui/ref_option/ref_option.rs:12:1 | LL | fn opt_string(a: &std::option::Option) {} | ^^^^^^^^^^^^^^^^^----------------------------^^^^ @@ -26,29 +26,31 @@ LL | fn opt_string(a: &std::option::Option) {} | help: change this to: `std::option::Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:11:1 + --> tests/ui/ref_option/ref_option.rs:14:1 | LL | fn ret_string<'a>(p: &'a str) -> &'a Option { | ^ -------------- help: change this to: `Option<&'a u8>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:14:1 + --> tests/ui/ref_option/ref_option.rs:18:1 | LL | fn ret_string_static() -> &'static Option { | ^ ------------------- help: change this to: `Option<&'static u8>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:17:1 + --> tests/ui/ref_option/ref_option.rs:22:1 | LL | fn mult_string(a: &Option, b: &Option>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,18 +61,19 @@ LL | fn mult_string(a: Option<&String>, b: Option<&Vec>) {} | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:18:1 + --> tests/ui/ref_option/ref_option.rs:24:1 | LL | fn ret_box<'a>() -> &'a Option> { | ^ ------------------- help: change this to: `Option<&'a Box>` | _| | | +LL | | LL | | panic!() LL | | } | |_^ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:31:5 + --> tests/ui/ref_option/ref_option.rs:42:5 | LL | fn trait_opt(&self, a: &Option); | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ @@ -78,7 +81,7 @@ LL | fn trait_opt(&self, a: &Option); | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:32:5 + --> tests/ui/ref_option/ref_option.rs:44:5 | LL | fn trait_ret(&self) -> &Option; | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ @@ -86,7 +89,7 @@ LL | fn trait_ret(&self) -> &Option; | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:43:5 + --> tests/ui/ref_option/ref_option.rs:58:5 | LL | fn private_opt_params(&self, a: &Option<()>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ @@ -94,12 +97,13 @@ LL | fn private_opt_params(&self, a: &Option<()>) {} | help: change this to: `Option<&()>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option.rs:44:5 + --> tests/ui/ref_option/ref_option.rs:60:5 | LL | fn private_opt_ret(&self) -> &Option { | ^ --------------- help: change this to: `Option<&String>` | _____| | | +LL | | LL | | panic!() LL | | } | |_____^ diff --git a/tests/ui/ref_option/ref_option.rs b/tests/ui/ref_option/ref_option.rs index 05251bcf12cd..86b5c6fe896b 100644 --- a/tests/ui/ref_option/ref_option.rs +++ b/tests/ui/ref_option/ref_option.rs @@ -6,42 +6,59 @@ #![warn(clippy::ref_option)] fn opt_u8(a: &Option) {} +//~^ ref_option fn opt_gen(a: &Option) {} +//~^ ref_option fn opt_string(a: &std::option::Option) {} +//~^ ref_option fn ret_string<'a>(p: &'a str) -> &'a Option { +//~^ ref_option panic!() } fn ret_string_static() -> &'static Option { +//~^ ref_option panic!() } fn mult_string(a: &Option, b: &Option>) {} +//~^ ref_option fn ret_box<'a>() -> &'a Option> { +//~^ ref_option panic!() } pub fn pub_opt_string(a: &Option) {} +//~[all]^ ref_option pub fn pub_mult_string(a: &Option, b: &Option>) {} +//~[all]^ ref_option pub trait PubTrait { fn pub_trait_opt(&self, a: &Option>); + //~[all]^ ref_option fn pub_trait_ret(&self) -> &Option>; + //~[all]^ ref_option } trait PrivateTrait { fn trait_opt(&self, a: &Option); + //~^ ref_option fn trait_ret(&self) -> &Option; + //~^ ref_option } pub struct PubStruct; impl PubStruct { pub fn pub_opt_params(&self, a: &Option<()>) {} + //~[all]^ ref_option pub fn pub_opt_ret(&self) -> &Option { + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: &Option<()>) {} + //~^ ref_option fn private_opt_ret(&self) -> &Option { + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option/ref_option_traits.all.stderr b/tests/ui/ref_option/ref_option_traits.all.stderr index a9967168c12e..030a9a28ec68 100644 --- a/tests/ui/ref_option/ref_option_traits.all.stderr +++ b/tests/ui/ref_option/ref_option_traits.all.stderr @@ -10,7 +10,7 @@ LL | fn pub_trait_opt(&self, a: &Option>); = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option_traits.rs:11:5 + --> tests/ui/ref_option/ref_option_traits.rs:12:5 | LL | fn pub_trait_ret(&self) -> &Option>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^ @@ -18,7 +18,7 @@ LL | fn pub_trait_ret(&self) -> &Option>; | help: change this to: `Option<&Vec>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option_traits.rs:15:5 + --> tests/ui/ref_option/ref_option_traits.rs:17:5 | LL | fn trait_opt(&self, a: &Option); | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ @@ -26,7 +26,7 @@ LL | fn trait_opt(&self, a: &Option); | help: change this to: `Option<&String>` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option_traits.rs:16:5 + --> tests/ui/ref_option/ref_option_traits.rs:19:5 | LL | fn trait_ret(&self) -> &Option; | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ diff --git a/tests/ui/ref_option/ref_option_traits.private.stderr b/tests/ui/ref_option/ref_option_traits.private.stderr index 36d0833af8a2..2837ee80fb2e 100644 --- a/tests/ui/ref_option/ref_option_traits.private.stderr +++ b/tests/ui/ref_option/ref_option_traits.private.stderr @@ -1,5 +1,5 @@ error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option_traits.rs:15:5 + --> tests/ui/ref_option/ref_option_traits.rs:17:5 | LL | fn trait_opt(&self, a: &Option); | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ @@ -10,7 +10,7 @@ LL | fn trait_opt(&self, a: &Option); = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` error: it is more idiomatic to use `Option<&T>` instead of `&Option` - --> tests/ui/ref_option/ref_option_traits.rs:16:5 + --> tests/ui/ref_option/ref_option_traits.rs:19:5 | LL | fn trait_ret(&self) -> &Option; | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ diff --git a/tests/ui/ref_option/ref_option_traits.rs b/tests/ui/ref_option/ref_option_traits.rs index 5d5f113c83db..811da2eb4d50 100644 --- a/tests/ui/ref_option/ref_option_traits.rs +++ b/tests/ui/ref_option/ref_option_traits.rs @@ -8,12 +8,16 @@ pub trait PubTrait { fn pub_trait_opt(&self, a: &Option>); + //~[all]^ ref_option fn pub_trait_ret(&self) -> &Option>; + //~[all]^ ref_option } trait PrivateTrait { fn trait_opt(&self, a: &Option); + //~^ ref_option fn trait_ret(&self) -> &Option; + //~^ ref_option } pub struct PubStruct; diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index 44001c45e99a..de936cb08108 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -8,37 +8,46 @@ 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` +//~^ ref_option_ref + + 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 +//~^ ref_option_ref + type RefOptRefU32<'a> = &'a Option<&'a u32>; -//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~^ ref_option_ref + type RefOptRef<'a, T> = &'a Option<&'a T>; -//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~^ ref_option_ref + fn foo(data: &Option<&u32>) {} -//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~^ ref_option_ref + fn bar(data: &u32) -> &Option<&u32> { - //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~^ ref_option_ref + &None } struct StructRef<'a> { data: &'a Option<&'a u32>, - //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to + //~^ ref_option_ref + } struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); -//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~^ ref_option_ref + enum EnumRef<'a> { Variant1(u32), Variant2(&'a Option<&'a u32>), - //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to + //~^ ref_option_ref + } trait RefOptTrait { @@ -48,14 +57,16 @@ trait RefOptTrait { impl RefOptTrait for u32 { type A = &'static Option<&'static Self>; - //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to + //~^ ref_option_ref + fn foo(&self, _: Self::A) {} } fn main() { let x: &Option<&u32> = &None; - //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to + //~^ ref_option_ref + } fn issue9682(arg: &Option<&mut String>) { diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index 1cb64e1182a5..fcafbc5ea18e 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -8,61 +8,61 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); = help: to override `-D warnings` add `#[allow(clippy::ref_option_ref)]` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:14:18 + --> tests/ui/ref_option_ref.rs:15:18 | LL | const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:17:25 + --> tests/ui/ref_option_ref.rs:19:25 | LL | type RefOptRefU32<'a> = &'a Option<&'a u32>; | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:19:25 + --> tests/ui/ref_option_ref.rs:22:25 | LL | type RefOptRef<'a, T> = &'a Option<&'a T>; | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:22:14 + --> tests/ui/ref_option_ref.rs:26:14 | LL | fn foo(data: &Option<&u32>) {} | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:25:23 + --> tests/ui/ref_option_ref.rs:30:23 | LL | fn bar(data: &u32) -> &Option<&u32> { | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:31:11 + --> tests/ui/ref_option_ref.rs:37:11 | LL | data: &'a Option<&'a u32>, | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:35:32 + --> tests/ui/ref_option_ref.rs:42:32 | LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:40:14 + --> tests/ui/ref_option_ref.rs:48:14 | LL | Variant2(&'a Option<&'a u32>), | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:50:14 + --> tests/ui/ref_option_ref.rs:59:14 | LL | type A = &'static Option<&'static Self>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:57:12 + --> tests/ui/ref_option_ref.rs:67: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 acd42ec89b62..214778b78b5b 100644 --- a/tests/ui/ref_patterns.rs +++ b/tests/ui/ref_patterns.rs @@ -6,17 +6,20 @@ fn use_in_pattern() { match opt { None => {}, Some(ref opt) => {}, - //~^ ERROR: usage of ref pattern + //~^ ref_patterns + } } fn use_in_binding() { let x = 5; let ref y = x; - //~^ ERROR: usage of ref pattern + //~^ ref_patterns + } fn use_in_parameter(ref x: i32) {} -//~^ ERROR: usage of ref pattern +//~^ ref_patterns + fn main() {} diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index 9e2d036e3483..bf63189a15b0 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -9,7 +9,7 @@ LL | Some(ref opt) => {}, = help: to override `-D warnings` add `#[allow(clippy::ref_patterns)]` error: usage of ref pattern - --> tests/ui/ref_patterns.rs:15:9 + --> tests/ui/ref_patterns.rs:16:9 | LL | let ref y = x; | ^^^^^ @@ -17,7 +17,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> tests/ui/ref_patterns.rs:19:21 + --> tests/ui/ref_patterns.rs:21:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index f607a2d50c6d..c63d549b7553 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -1,3 +1,4 @@ +//@require-annotations-for-level: WARN #![allow( unused, clippy::needless_raw_strings, @@ -27,11 +28,14 @@ fn syntax_error() { //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th let some_regex = Regex::new(OPENING_PAREN); + //~^ invalid_regex let binary_pipe_in_wrong_position = BRegex::new("|"); //~^ ERROR: trivial regex let some_binary_regex = BRegex::new(OPENING_PAREN); + //~^ invalid_regex let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); + //~^ invalid_regex let closing_paren = ")"; let not_linted = Regex::new(closing_paren); @@ -44,7 +48,9 @@ fn syntax_error() { ]); let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); + //~^ invalid_regex let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); + //~^ invalid_regex // These following three cases are considering valid since regex-1.8.0 let raw_string_error = Regex::new(r"[...\/...]"); @@ -52,6 +58,7 @@ fn syntax_error() { let _ = Regex::new(r"(?hi)").unwrap(); let escaped_string_span = Regex::new("\\b\\c"); + //~^ invalid_regex let aux_span = Regex::new("(?ixi)"); //~^ ERROR: regex syntax error: duplicate flag diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 18dd538c68b4..aaec3bc14200 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -1,5 +1,5 @@ error: trivial regex - --> tests/ui/regex.rs:19:45 + --> tests/ui/regex.rs:20:45 | LL | let pipe_in_wrong_position = Regex::new("|"); | ^^^ @@ -9,7 +9,7 @@ LL | let pipe_in_wrong_position = Regex::new("|"); = help: to override `-D warnings` add `#[allow(clippy::trivial_regex)]` error: trivial regex - --> tests/ui/regex.rs:21:60 + --> tests/ui/regex.rs:22:60 | LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); | ^^^ @@ -17,7 +17,7 @@ LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); = help: the regex is unlikely to be useful as it is error: regex syntax error: invalid character class range, the start must be <= the end - --> tests/ui/regex.rs:23:42 + --> tests/ui/regex.rs:24:42 | LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ @@ -26,7 +26,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]"); = help: to override `-D warnings` add `#[allow(clippy::invalid_regex)]` error: regex syntax error: invalid character class range, the start must be <= the end - --> tests/ui/regex.rs:26:37 + --> tests/ui/regex.rs:27:37 | LL | let some_unicode = Regex::new("[é-è]"); | ^^^ @@ -35,13 +35,13 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:29:33 + --> tests/ui/regex.rs:30:33 | LL | let some_regex = Regex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ error: trivial regex - --> tests/ui/regex.rs:31:53 + --> tests/ui/regex.rs:33:53 | LL | let binary_pipe_in_wrong_position = BRegex::new("|"); | ^^^ @@ -52,7 +52,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:33:41 + --> tests/ui/regex.rs:35:41 | LL | let some_binary_regex = BRegex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:34:56 + --> tests/ui/regex.rs:37:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:46:37 + --> tests/ui/regex.rs:50:37 | LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:47:39 + --> tests/ui/regex.rs:52:39 | LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ error: regex parse error: \b\c ^^ error: unrecognized escape sequence - --> tests/ui/regex.rs:54:42 + --> tests/ui/regex.rs:60:42 | LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ @@ -96,19 +96,19 @@ LL | let escaped_string_span = Regex::new("\\b\\c"); = help: consider using a raw string literal: `r".."` error: regex syntax error: duplicate flag - --> tests/ui/regex.rs:56:34 + --> tests/ui/regex.rs:63:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> tests/ui/regex.rs:62:53 + --> tests/ui/regex.rs:69:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> tests/ui/regex.rs:67:33 + --> tests/ui/regex.rs:74:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -116,7 +116,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> tests/ui/regex.rs:70:48 + --> tests/ui/regex.rs:77:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -124,7 +124,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> tests/ui/regex.rs:73:42 + --> tests/ui/regex.rs:80:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -132,7 +132,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> tests/ui/regex.rs:76:40 + --> tests/ui/regex.rs:83:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -140,7 +140,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> tests/ui/regex.rs:79:39 + --> tests/ui/regex.rs:86:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -148,7 +148,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:82:39 + --> tests/ui/regex.rs:89:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:85:40 + --> tests/ui/regex.rs:92:40 | LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ @@ -164,7 +164,7 @@ LL | let trivial_backslash = Regex::new("a\\.b"); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:89:36 + --> tests/ui/regex.rs:96:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -172,7 +172,7 @@ LL | let trivial_empty = Regex::new(""); = help: the regex is unlikely to be useful as it is error: trivial regex - --> tests/ui/regex.rs:92:36 + --> tests/ui/regex.rs:99:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -180,7 +180,7 @@ LL | let trivial_empty = Regex::new("^"); = help: the regex is unlikely to be useful as it is error: trivial regex - --> tests/ui/regex.rs:95:36 + --> tests/ui/regex.rs:102:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -188,7 +188,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> tests/ui/regex.rs:98:44 + --> tests/ui/regex.rs:105:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ @@ -196,13 +196,13 @@ LL | let binary_trivial_empty = BRegex::new("^$"); = help: consider using `str::is_empty` error: compiling a regex in a loop - --> tests/ui/regex.rs:125:21 + --> tests/ui/regex.rs:132:21 | LL | let regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:122:5 + --> tests/ui/regex.rs:129:5 | LL | loop { | ^^^^ @@ -210,37 +210,37 @@ LL | loop { = help: to override `-D warnings` add `#[allow(clippy::regex_creation_in_loops)]` error: compiling a regex in a loop - --> tests/ui/regex.rs:127:21 + --> tests/ui/regex.rs:134:21 | LL | let regex = BRegex::new("a.b"); | ^^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:122:5 + --> tests/ui/regex.rs:129:5 | LL | loop { | ^^^^ error: compiling a regex in a loop - --> tests/ui/regex.rs:133:25 + --> tests/ui/regex.rs:140:25 | LL | let regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:122:5 + --> tests/ui/regex.rs:129:5 | LL | loop { | ^^^^ error: compiling a regex in a loop - --> tests/ui/regex.rs:138:32 + --> tests/ui/regex.rs:145:32 | LL | let nested_regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:137:9 + --> tests/ui/regex.rs:144:9 | LL | for _ in 0..10 { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/renamed_builtin_attr.fixed b/tests/ui/renamed_builtin_attr.fixed index aebf8712dd92..1ad7d8702bc0 100644 --- a/tests/ui/renamed_builtin_attr.fixed +++ b/tests/ui/renamed_builtin_attr.fixed @@ -1,4 +1,5 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #[clippy::cognitive_complexity = "1"] +//~^ ERROR: usage of deprecated attribute fn main() {} diff --git a/tests/ui/renamed_builtin_attr.rs b/tests/ui/renamed_builtin_attr.rs index 6c18151195f5..0fb43b7f4901 100644 --- a/tests/ui/renamed_builtin_attr.rs +++ b/tests/ui/renamed_builtin_attr.rs @@ -1,4 +1,5 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #[clippy::cyclomatic_complexity = "1"] +//~^ ERROR: usage of deprecated attribute fn main() {} diff --git a/tests/ui/repeat_once.fixed b/tests/ui/repeat_once.fixed index 72e97350a0c8..e739e176f0ac 100644 --- a/tests/ui/repeat_once.fixed +++ b/tests/ui/repeat_once.fixed @@ -7,9 +7,15 @@ fn main() { let slice = [1; 5]; let a = [1; 5].to_vec(); + //~^ repeat_once let b = slice.to_vec(); + //~^ repeat_once let c = "hello".to_string(); + //~^ repeat_once let d = "hi".to_string(); + //~^ repeat_once let e = s.to_string(); + //~^ repeat_once let f = string.clone(); + //~^ repeat_once } diff --git a/tests/ui/repeat_once.rs b/tests/ui/repeat_once.rs index 7557c4d0bd41..89ab94bbaee8 100644 --- a/tests/ui/repeat_once.rs +++ b/tests/ui/repeat_once.rs @@ -7,9 +7,15 @@ fn main() { let slice = [1; 5]; let a = [1; 5].repeat(1); + //~^ repeat_once let b = slice.repeat(1); + //~^ repeat_once let c = "hello".repeat(N); + //~^ repeat_once let d = "hi".repeat(1); + //~^ repeat_once let e = s.repeat(1); + //~^ repeat_once let f = string.repeat(1); + //~^ repeat_once } diff --git a/tests/ui/repeat_once.stderr b/tests/ui/repeat_once.stderr index 6996dc5eee7d..3db7a3568f8e 100644 --- a/tests/ui/repeat_once.stderr +++ b/tests/ui/repeat_once.stderr @@ -8,31 +8,31 @@ LL | let a = [1; 5].repeat(1); = help: to override `-D warnings` add `#[allow(clippy::repeat_once)]` error: calling `repeat(1)` on slice - --> tests/ui/repeat_once.rs:10:13 + --> tests/ui/repeat_once.rs:11:13 | LL | let b = slice.repeat(1); | ^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `slice.to_vec()` error: calling `repeat(1)` on str - --> tests/ui/repeat_once.rs:11:13 + --> tests/ui/repeat_once.rs:13:13 | LL | let c = "hello".repeat(N); | ^^^^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hello".to_string()` error: calling `repeat(1)` on str - --> tests/ui/repeat_once.rs:12:13 + --> tests/ui/repeat_once.rs:15:13 | LL | let d = "hi".repeat(1); | ^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hi".to_string()` error: calling `repeat(1)` on str - --> tests/ui/repeat_once.rs:13:13 + --> tests/ui/repeat_once.rs:17:13 | LL | let e = s.repeat(1); | ^^^^^^^^^^^ help: consider using `.to_string()` instead: `s.to_string()` error: calling `repeat(1)` on a string literal - --> tests/ui/repeat_once.rs:14:13 + --> tests/ui/repeat_once.rs:19:13 | LL | let f = string.repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.clone()` instead: `string.clone()` diff --git a/tests/ui/repeat_vec_with_capacity.fixed b/tests/ui/repeat_vec_with_capacity.fixed index f72b61b5f6cd..318839db221e 100644 --- a/tests/ui/repeat_vec_with_capacity.fixed +++ b/tests/ui/repeat_vec_with_capacity.fixed @@ -4,13 +4,15 @@ fn main() { { (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - //~^ ERROR: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { let n = 123; (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); - //~^ ERROR: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { @@ -25,7 +27,8 @@ fn main() { { std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); - //~^ ERROR: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { diff --git a/tests/ui/repeat_vec_with_capacity.rs b/tests/ui/repeat_vec_with_capacity.rs index c0cc81f78436..0ce4658c1089 100644 --- a/tests/ui/repeat_vec_with_capacity.rs +++ b/tests/ui/repeat_vec_with_capacity.rs @@ -4,13 +4,15 @@ fn main() { { vec![Vec::<()>::with_capacity(42); 123]; - //~^ ERROR: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { let n = 123; vec![Vec::<()>::with_capacity(42); n]; - //~^ ERROR: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { @@ -25,7 +27,8 @@ fn main() { { std::iter::repeat(Vec::<()>::with_capacity(42)); - //~^ ERROR: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity + //~^ repeat_vec_with_capacity + } { diff --git a/tests/ui/repeat_vec_with_capacity.stderr b/tests/ui/repeat_vec_with_capacity.stderr index 43027c9cb892..bdfd58137b0b 100644 --- a/tests/ui/repeat_vec_with_capacity.stderr +++ b/tests/ui/repeat_vec_with_capacity.stderr @@ -13,7 +13,7 @@ LL | (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:12:9 + --> tests/ui/repeat_vec_with_capacity.rs:13:9 | LL | vec![Vec::<()>::with_capacity(42); n]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:27:9 + --> tests/ui/repeat_vec_with_capacity.rs:29:9 | LL | std::iter::repeat(Vec::<()>::with_capacity(42)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/repeat_vec_with_capacity_nostd.fixed b/tests/ui/repeat_vec_with_capacity_nostd.fixed index ef316f1def41..dcff18723b6c 100644 --- a/tests/ui/repeat_vec_with_capacity_nostd.fixed +++ b/tests/ui/repeat_vec_with_capacity_nostd.fixed @@ -7,4 +7,5 @@ use alloc::vec::Vec; fn nostd() { let _: Vec> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); + //~^ repeat_vec_with_capacity } diff --git a/tests/ui/repeat_vec_with_capacity_nostd.rs b/tests/ui/repeat_vec_with_capacity_nostd.rs index 83b418a56674..84cc78de35ec 100644 --- a/tests/ui/repeat_vec_with_capacity_nostd.rs +++ b/tests/ui/repeat_vec_with_capacity_nostd.rs @@ -7,4 +7,5 @@ use alloc::vec::Vec; fn nostd() { let _: Vec> = iter::repeat(Vec::with_capacity(42)).take(123).collect(); + //~^ repeat_vec_with_capacity } diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs index 01bdf79e6422..f9887eedcf46 100644 --- a/tests/ui/repl_uninit.rs +++ b/tests/ui/repl_uninit.rs @@ -13,22 +13,25 @@ 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` + //~^ mem_replace_with_uninit + + 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()` + //~^ mem_replace_with_uninit + 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()` + //~^ mem_replace_with_uninit + let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } @@ -41,6 +44,7 @@ fn main() { // this is still not OK, because uninit let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; - //~^ ERROR: replacing with `mem::uninitialized()` + //~^ mem_replace_with_uninit + *uref = taken_u + 1; } diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr index 645c4a16a07e..6e314d0dd166 100644 --- a/tests/ui/repl_uninit.stderr +++ b/tests/ui/repl_uninit.stderr @@ -8,13 +8,13 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_uninit)]` error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> tests/ui/repl_uninit.rs:23:23 + --> tests/ui/repl_uninit.rs:24: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()` - --> tests/ui/repl_uninit.rs:30:23 + --> tests/ui/repl_uninit.rs:32:23 | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,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()` - --> tests/ui/repl_uninit.rs:43:28 + --> tests/ui/repl_uninit.rs:46:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` diff --git a/tests/ui/repr_packed_without_abi.rs b/tests/ui/repr_packed_without_abi.rs index 16b5ededee99..4f51d4b9aec6 100644 --- a/tests/ui/repr_packed_without_abi.rs +++ b/tests/ui/repr_packed_without_abi.rs @@ -2,12 +2,14 @@ #[repr(packed)] struct NetworkPacketHeader { +//~^ repr_packed_without_abi header_length: u8, header_version: u16, } #[repr(packed)] union Foo { +//~^ repr_packed_without_abi a: u8, b: u16, } diff --git a/tests/ui/repr_packed_without_abi.stderr b/tests/ui/repr_packed_without_abi.stderr index 4f7acd00db3d..d1078b3e8e48 100644 --- a/tests/ui/repr_packed_without_abi.stderr +++ b/tests/ui/repr_packed_without_abi.stderr @@ -4,6 +4,7 @@ error: item uses `packed` representation without ABI-qualification LL | #[repr(packed)] | ------ `packed` representation set here LL | / struct NetworkPacketHeader { +LL | | LL | | header_length: u8, LL | | header_version: u16, LL | | } @@ -18,11 +19,12 @@ LL | #![deny(clippy::repr_packed_without_abi)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: item uses `packed` representation without ABI-qualification - --> tests/ui/repr_packed_without_abi.rs:10:1 + --> tests/ui/repr_packed_without_abi.rs:11:1 | LL | #[repr(packed)] | ------ `packed` representation set here LL | / union Foo { +LL | | LL | | a: u8, LL | | b: u16, LL | | } diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs index b57a8e162c53..7f79dac46536 100644 --- a/tests/ui/reserve_after_initialization.rs +++ b/tests/ui/reserve_after_initialization.rs @@ -8,6 +8,7 @@ use proc_macros::{external, with_span}; // Should lint fn standard() { let mut v1: Vec = vec![]; + //~^ reserve_after_initialization v1.reserve(10); } @@ -15,6 +16,7 @@ fn standard() { fn capacity_as_expr() { let capacity = 10; let mut v2: Vec = vec![]; + //~^ reserve_after_initialization v2.reserve(capacity); } @@ -33,6 +35,7 @@ fn called_with_capacity() { fn assign_expression() { let mut v5: Vec = Vec::new(); v5 = Vec::new(); + //~^ reserve_after_initialization v5.reserve(10); } diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index b6dbebb3f14c..e79b59a35d41 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -2,6 +2,7 @@ error: call to `reserve` immediately after creation --> tests/ui/reserve_after_initialization.rs:10:5 | LL | / let mut v1: Vec = vec![]; +LL | | LL | | v1.reserve(10); | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v1: Vec = Vec::with_capacity(10);` | @@ -9,16 +10,18 @@ LL | | v1.reserve(10); = help: to override `-D warnings` add `#[allow(clippy::reserve_after_initialization)]` error: call to `reserve` immediately after creation - --> tests/ui/reserve_after_initialization.rs:17:5 + --> tests/ui/reserve_after_initialization.rs:18:5 | LL | / let mut v2: Vec = vec![]; +LL | | LL | | v2.reserve(capacity); | |_________________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v2: Vec = Vec::with_capacity(capacity);` error: call to `reserve` immediately after creation - --> tests/ui/reserve_after_initialization.rs:35:5 + --> tests/ui/reserve_after_initialization.rs:37:5 | LL | / v5 = Vec::new(); +LL | | LL | | v5.reserve(10); | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `v5 = Vec::with_capacity(10);` diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs index 51fe346d0926..fd6cf0d1ce1f 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -21,16 +21,19 @@ fn main() { match a_struct { A { a: 5, b: 42, c: "", .. } => {}, // Lint - //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr + //~^ rest_pat_in_fully_bound_structs + A { a: 0, b: 0, c: "", .. } => {}, // Lint - //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr + //~^ rest_pat_in_fully_bound_structs + _ => {}, } 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 + //~^ rest_pat_in_fully_bound_structs + _ => {}, } diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index d048933ddb7b..72cf778ca64c 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -9,7 +9,7 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint = help: to override `-D warnings` add `#[allow(clippy::rest_pat_in_fully_bound_structs)]` error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> tests/ui/rest_pat_in_fully_bound_structs.rs:25:9 + --> tests/ui/rest_pat_in_fully_bound_structs.rs:26:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ 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 - --> tests/ui/rest_pat_in_fully_bound_structs.rs:32:9 + --> tests/ui/rest_pat_in_fully_bound_structs.rs:34:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_filter_map.rs b/tests/ui/result_filter_map.rs index bfe47ffcf380..f5e0a9da9ea5 100644 --- a/tests/ui/result_filter_map.rs +++ b/tests/ui/result_filter_map.rs @@ -11,25 +11,29 @@ fn main() { let _ = vec![Ok(1) as Result] .into_iter() .filter(Result::is_ok) - //~^ ERROR: `filter` for `Ok` followed by `unwrap` + //~^ result_filter_map + .map(Result::unwrap); let _ = vec![Ok(1) as Result] .into_iter() .filter(|o| o.is_ok()) - //~^ ERROR: `filter` for `Ok` followed by `unwrap` + //~^ result_filter_map + .map(|o| o.unwrap()); let _ = vec![1] .into_iter() .map(odds_out) .filter(Result::is_ok) - //~^ ERROR: `filter` for `Ok` followed by `unwrap` + //~^ result_filter_map + .map(Result::unwrap); let _ = vec![1] .into_iter() .map(odds_out) .filter(|o| o.is_ok()) - //~^ ERROR: `filter` for `Ok` followed by `unwrap` + //~^ result_filter_map + .map(|o| o.unwrap()); } diff --git a/tests/ui/result_filter_map.stderr b/tests/ui/result_filter_map.stderr index 12eb7083b5a8..f3ff5173c171 100644 --- a/tests/ui/result_filter_map.stderr +++ b/tests/ui/result_filter_map.stderr @@ -3,7 +3,7 @@ error: `filter` for `Ok` followed by `unwrap` | LL | .filter(Result::is_ok) | __________^ -LL | | +... | LL | | .map(Result::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` | @@ -11,29 +11,29 @@ LL | | .map(Result::unwrap); = help: to override `-D warnings` add `#[allow(clippy::result_filter_map)]` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:19:10 + --> tests/ui/result_filter_map.rs:20:10 | LL | .filter(|o| o.is_ok()) | __________^ -LL | | +... | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:26:10 + --> tests/ui/result_filter_map.rs:28:10 | LL | .filter(Result::is_ok) | __________^ -LL | | +... | LL | | .map(Result::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:32:10 + --> tests/ui/result_filter_map.rs:35:10 | LL | .filter(|o| o.is_ok()) | __________^ -LL | | +... | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index 9c39f023da2d..bdcf40a99ab9 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -8,7 +8,8 @@ pub fn small_err() -> Result<(), u128> { } pub fn large_err() -> Result<(), [u8; 512]> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + Ok(()) } @@ -20,19 +21,22 @@ pub struct FullyDefinedLargeError { impl FullyDefinedLargeError { pub fn ret() -> Result<(), Self> { - //~^ ERROR: the `Err`-variant returned from this function is very large + //~^ result_large_err + Ok(()) } } pub fn struct_error() -> Result<(), FullyDefinedLargeError> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + 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 +//~^ result_large_err + Ok(x) } @@ -41,7 +45,8 @@ 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 +//~^ result_large_err + Ok(()) } @@ -53,7 +58,8 @@ pub enum LargeErrorVariants { impl LargeErrorVariants<()> { pub fn large_enum_error() -> Result<(), Self> { - //~^ ERROR: the `Err`-variant returned from this function is very large + //~^ result_large_err + Ok(()) } } @@ -66,14 +72,16 @@ enum MultipleLargeVariants { impl MultipleLargeVariants { fn large_enum_error() -> Result<(), Self> { - //~^ ERROR: the `Err`-variant returned from this function is very large + //~^ result_large_err + Ok(()) } } trait TraitForcesLargeError { fn large_error() -> Result<(), [u8; 512]> { - //~^ ERROR: the `Err`-variant returned from this function is very large + //~^ result_large_err + Ok(()) } } @@ -93,7 +101,8 @@ pub union FullyDefinedUnionError { } pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + Ok(()) } @@ -103,7 +112,8 @@ pub union UnionError { } pub fn param_large_union() -> Result<(), UnionError> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + Ok(()) } @@ -113,12 +123,14 @@ pub struct ArrayError { } pub fn array_error_subst() -> Result<(), ArrayError> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + Ok(()) } pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { - //~^ ERROR: the `Err`-variant returned from this function is very large +//~^ result_large_err + Ok(()) } diff --git a/tests/ui/result_large_err.stderr b/tests/ui/result_large_err.stderr index 1dff3f9efe81..72fbc3f58961 100644 --- a/tests/ui/result_large_err.stderr +++ b/tests/ui/result_large_err.stderr @@ -9,7 +9,7 @@ LL | pub fn large_err() -> Result<(), [u8; 512]> { = help: to override `-D warnings` add `#[allow(clippy::result_large_err)]` error: the `Err`-variant returned from this function is very large - --> tests/ui/result_large_err.rs:22:21 + --> tests/ui/result_large_err.rs:23:21 | LL | pub fn ret() -> Result<(), Self> { | ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -17,7 +17,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 - --> tests/ui/result_large_err.rs:28:26 + --> tests/ui/result_large_err.rs:30:26 | LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -25,7 +25,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 - --> tests/ui/result_large_err.rs:34:45 + --> tests/ui/result_large_err.rs:37:45 | LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { | ^^^^^^^ the `Err`-variant is at least 240 bytes @@ -33,7 +33,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 - --> tests/ui/result_large_err.rs:43:34 + --> tests/ui/result_large_err.rs:47:34 | LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 256 bytes @@ -41,7 +41,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 - --> tests/ui/result_large_err.rs:55:34 + --> tests/ui/result_large_err.rs:60:34 | LL | _Omg([u8; 512]), | --------------- the largest variant contains at least 512 bytes @@ -52,7 +52,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 - --> tests/ui/result_large_err.rs:68:30 + --> tests/ui/result_large_err.rs:74:30 | LL | _Biggest([u8; 1024]), | -------------------- the largest variant contains at least 1024 bytes @@ -65,7 +65,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 - --> tests/ui/result_large_err.rs:75:25 + --> tests/ui/result_large_err.rs:82:25 | LL | fn large_error() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -73,7 +73,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 - --> tests/ui/result_large_err.rs:95:29 + --> tests/ui/result_large_err.rs:103:29 | LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -81,7 +81,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 - --> tests/ui/result_large_err.rs:105:40 + --> tests/ui/result_large_err.rs:114:40 | LL | pub fn param_large_union() -> Result<(), UnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -89,7 +89,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 - --> tests/ui/result_large_err.rs:115:34 + --> tests/ui/result_large_err.rs:125:34 | LL | pub fn array_error_subst() -> Result<(), ArrayError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes @@ -97,7 +97,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 - --> tests/ui/result_large_err.rs:120:31 + --> tests/ui/result_large_err.rs:131: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_or_into_option.fixed b/tests/ui/result_map_or_into_option.fixed index cf42b24b2dda..47ba2b03bfc4 100644 --- a/tests/ui/result_map_or_into_option.fixed +++ b/tests/ui/result_map_or_into_option.fixed @@ -3,12 +3,15 @@ fn main() { let opt: Result = Ok(1); let _ = opt.ok(); - //~^ ERROR: called `map_or(None, Some)` on a `Result` value + //~^ result_map_or_into_option + let _ = opt.ok(); - //~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value + //~^ result_map_or_into_option + #[rustfmt::skip] let _ = opt.ok(); - //~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value + //~^ result_map_or_into_option + let rewrap = |s: u32| -> Option { Some(s) }; diff --git a/tests/ui/result_map_or_into_option.rs b/tests/ui/result_map_or_into_option.rs index cdb45d6b82a0..3c6b2f0e836f 100644 --- a/tests/ui/result_map_or_into_option.rs +++ b/tests/ui/result_map_or_into_option.rs @@ -3,12 +3,15 @@ fn main() { let opt: Result = Ok(1); let _ = opt.map_or(None, Some); - //~^ ERROR: called `map_or(None, Some)` on a `Result` value + //~^ result_map_or_into_option + let _ = opt.map_or_else(|_| None, Some); - //~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value + //~^ result_map_or_into_option + #[rustfmt::skip] let _ = opt.map_or_else(|_| { None }, Some); - //~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value + //~^ result_map_or_into_option + let rewrap = |s: u32| -> Option { Some(s) }; diff --git a/tests/ui/result_map_or_into_option.stderr b/tests/ui/result_map_or_into_option.stderr index 4cb510d77a06..f9058d35e6c6 100644 --- a/tests/ui/result_map_or_into_option.stderr +++ b/tests/ui/result_map_or_into_option.stderr @@ -8,13 +8,13 @@ LL | let _ = opt.map_or(None, Some); = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` error: called `map_or_else(|_| None, Some)` on a `Result` value - --> tests/ui/result_map_or_into_option.rs:7:13 + --> tests/ui/result_map_or_into_option.rs:8:13 | LL | let _ = opt.map_or_else(|_| None, Some); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok`: `opt.ok()` error: called `map_or_else(|_| None, Some)` on a `Result` value - --> tests/ui/result_map_or_into_option.rs:10:13 + --> tests/ui/result_map_or_into_option.rs:12:13 | LL | let _ = opt.map_or_else(|_| { None }, Some); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok`: `opt.ok()` diff --git a/tests/ui/result_map_unit_fn_fixable.fixed b/tests/ui/result_map_unit_fn_fixable.fixed index 3890f916b606..6bee013c3f47 100644 --- a/tests/ui/result_map_unit_fn_fixable.fixed +++ b/tests/ui/result_map_unit_fn_fixable.fixed @@ -32,50 +32,68 @@ fn result_map_unit_fn() { let _: Result<(), usize> = x.field.map(do_nothing); if let Ok(x_field) = x.field { do_nothing(x_field) } + //~^ result_map_unit_fn if let Ok(x_field) = x.field { do_nothing(x_field) } + //~^ result_map_unit_fn if let Ok(x_field) = x.field { diverge(x_field) } + //~^ result_map_unit_fn let captured = 10; if let Ok(value) = x.field { do_nothing(value + captured) }; let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); if let Ok(value) = x.field { x.do_result_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { x.do_result_plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { do_nothing(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { diverge(value + captured); } + //~^ result_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); if let Ok(value) = x.field { let y = plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(value) = x.field { plus_one(value + captured); } + //~^ result_map_unit_fn if let Ok(ref value) = x.field { do_nothing(value + captured) } + //~^ result_map_unit_fn if let Ok(value) = x.field { println!("{:?}", value) } + //~^ result_map_unit_fn } fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.rs b/tests/ui/result_map_unit_fn_fixable.rs index c3f5aca7bfbe..a206cfe6842f 100644 --- a/tests/ui/result_map_unit_fn_fixable.rs +++ b/tests/ui/result_map_unit_fn_fixable.rs @@ -32,50 +32,68 @@ fn result_map_unit_fn() { let _: Result<(), usize> = x.field.map(do_nothing); x.field.map(do_nothing); + //~^ result_map_unit_fn x.field.map(do_nothing); + //~^ result_map_unit_fn x.field.map(diverge); + //~^ result_map_unit_fn let captured = 10; if let Ok(value) = x.field { do_nothing(value + captured) }; let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured)); x.field.map(|value| x.do_result_nothing(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { x.do_result_plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| do_nothing(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { do_nothing(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| { do_nothing(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { do_nothing(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|value| diverge(value + captured)); + //~^ result_map_unit_fn x.field.map(|value| { diverge(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| { diverge(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { diverge(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|value| plus_one(value + captured)); x.field.map(|value| { plus_one(value + captured) }); x.field.map(|value| { let y = plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { plus_one(value + captured); }); + //~^ result_map_unit_fn x.field.map(|value| { { plus_one(value + captured); } }); + //~^ result_map_unit_fn x.field.map(|ref value| { do_nothing(value + captured) }); + //~^ result_map_unit_fn x.field.map(|value| println!("{:?}", value)); + //~^ result_map_unit_fn } fn main() {} diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index 4f3bc2e95449..eca844e06cc0 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -10,7 +10,7 @@ LL | x.field.map(do_nothing); = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> tests/ui/result_map_unit_fn_fixable.rs:36:5 + --> tests/ui/result_map_unit_fn_fixable.rs:37:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -18,7 +18,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:38:5 + --> tests/ui/result_map_unit_fn_fixable.rs:40:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -26,7 +26,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:44:5 + --> tests/ui/result_map_unit_fn_fixable.rs:47:5 | LL | x.field.map(|value| x.do_result_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -34,7 +34,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:46:5 + --> tests/ui/result_map_unit_fn_fixable.rs:50:5 | LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -42,7 +42,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:49:5 + --> tests/ui/result_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -50,7 +50,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:51:5 + --> tests/ui/result_map_unit_fn_fixable.rs:57:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -58,7 +58,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:53:5 + --> tests/ui/result_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -66,7 +66,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:55:5 + --> tests/ui/result_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -74,7 +74,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:58:5 + --> tests/ui/result_map_unit_fn_fixable.rs:67:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -82,7 +82,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:60:5 + --> tests/ui/result_map_unit_fn_fixable.rs:70:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -90,7 +90,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:62:5 + --> tests/ui/result_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -98,7 +98,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:64:5 + --> tests/ui/result_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -106,7 +106,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:69:5 + --> tests/ui/result_map_unit_fn_fixable.rs:82:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -114,7 +114,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:71:5 + --> tests/ui/result_map_unit_fn_fixable.rs:85:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -122,7 +122,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:73:5 + --> tests/ui/result_map_unit_fn_fixable.rs:88:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -130,7 +130,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:76:5 + --> tests/ui/result_map_unit_fn_fixable.rs:92:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -138,7 +138,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 `()` - --> tests/ui/result_map_unit_fn_fixable.rs:78:5 + --> tests/ui/result_map_unit_fn_fixable.rs:95: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 62798b6d3d6f..fe3d8ece39f4 100644 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ b/tests/ui/result_map_unit_fn_unfixable.rs @@ -21,33 +21,39 @@ 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` + //~^ result_map_unit_fn + + 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 + //~^ result_map_unit_fn + // 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 + //~^ result_map_unit_fn + 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 + //~^ result_map_unit_fn + // 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 + //~^ result_map_unit_fn + 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 + //~^ result_map_unit_fn + } fn main() {} diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index d69c86c70e29..a6e38d808afa 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -10,7 +10,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> tests/ui/result_map_unit_fn_unfixable.rs:27:5 + --> tests/ui/result_map_unit_fn_unfixable.rs:28:5 | LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -18,10 +18,11 @@ 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 `()` - --> tests/ui/result_map_unit_fn_unfixable.rs:32:5 + --> tests/ui/result_map_unit_fn_unfixable.rs:34:5 | LL | // x.field.map(|value| { LL | || +LL | || LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); @@ -30,7 +31,7 @@ LL | || }); | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> tests/ui/result_map_unit_fn_unfixable.rs:37:5 + --> tests/ui/result_map_unit_fn_unfixable.rs:40:5 | LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -38,7 +39,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 `()` - --> tests/ui/result_map_unit_fn_unfixable.rs:42:5 + --> tests/ui/result_map_unit_fn_unfixable.rs:46:5 | LL | "12".parse::().map(diverge); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -46,7 +47,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 `()` - --> tests/ui/result_map_unit_fn_unfixable.rs:49:5 + --> tests/ui/result_map_unit_fn_unfixable.rs:54:5 | LL | y.map(do_nothing); | ^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/result_unit_error.rs b/tests/ui/result_unit_error.rs index f3159f2e9515..a6cf36bff913 100644 --- a/tests/ui/result_unit_error.rs +++ b/tests/ui/result_unit_error.rs @@ -1,7 +1,8 @@ #![warn(clippy::result_unit_err)] pub fn returns_unit_error() -> Result { - //~^ ERROR: this returns a `Result<_, ()>` +//~^ result_unit_err + Err(()) } @@ -11,10 +12,12 @@ fn private_unit_errors() -> Result { pub trait HasUnitError { fn get_that_error(&self) -> Result; - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + fn get_this_one_too(&self) -> Result { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Err(()) } } @@ -33,7 +36,8 @@ pub struct UnitErrorHolder; impl UnitErrorHolder { pub fn unit_error(&self) -> Result { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Ok(0) } } @@ -43,7 +47,8 @@ pub mod issue_6546 { type ResInv = Result; pub fn should_lint() -> ResInv<(), usize> { - //~^ ERROR: this returns a `Result<_, ()>` + //~^ result_unit_err + Ok(0) } diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index e869a3159775..a59271f8f72e 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -9,7 +9,7 @@ LL | pub fn returns_unit_error() -> Result { = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:13:5 + --> tests/ui/result_unit_error.rs:14:5 | LL | fn get_that_error(&self) -> Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | fn get_that_error(&self) -> Result; = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:16:5 + --> tests/ui/result_unit_error.rs:18:5 | LL | fn get_this_one_too(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn get_this_one_too(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:35:5 + --> tests/ui/result_unit_error.rs:38:5 | LL | pub fn unit_error(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | pub fn unit_error(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:45:5 + --> tests/ui/result_unit_error.rs:49:5 | LL | pub fn should_lint() -> ResInv<(), usize> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_unit_error_no_std.rs b/tests/ui/result_unit_error_no_std.rs index c9f4996c3689..cd2b17a52234 100644 --- a/tests/ui/result_unit_error_no_std.rs +++ b/tests/ui/result_unit_error_no_std.rs @@ -10,6 +10,7 @@ pub fn returns_unit_error_no_lint() -> Result { #[clippy::msrv = "1.81"] pub fn returns_unit_error_lint() -> Result { +//~^ result_unit_err Err(()) } diff --git a/tests/ui/return_and_then.fixed b/tests/ui/return_and_then.fixed index 9736a51ac868..732854d2b969 100644 --- a/tests/ui/return_and_then.fixed +++ b/tests/ui/return_and_then.fixed @@ -3,40 +3,47 @@ fn main() { fn test_opt_block(opt: Option) -> Option { let n = opt?; - let mut ret = n + 1; - ret += n; - if n > 1 { Some(ret) } else { None } + //~^ return_and_then + let mut ret = n + 1; + ret += n; + if n > 1 { Some(ret) } else { None } } fn test_opt_func(opt: Option) -> Option { let n = opt?; test_opt_block(Some(n)) + //~^ return_and_then } fn test_call_chain() -> Option { let n = gen_option(1)?; test_opt_block(Some(n)) + //~^ return_and_then } fn test_res_block(opt: Result) -> Result { let n = opt?; if n > 1 { Ok(n + 1) } else { Err(n) } + //~^ return_and_then } fn test_res_func(opt: Result) -> Result { let n = opt?; test_res_block(Ok(n)) + //~^ return_and_then } fn test_ref_only() -> Option { // ref: empty string let x = Some("")?; if x.len() > 2 { Some(3) } else { None } + //~^ return_and_then } fn test_tmp_only() -> Option { // unused temporary: vec![1, 2, 4] let x = Some(match (vec![1, 2, 3], vec![1, 2, 4]) { + //~^ return_and_then (a, _) if a.len() > 1 => a, (_, b) => b, })?; diff --git a/tests/ui/return_and_then.rs b/tests/ui/return_and_then.rs index 8bcbdfc3a632..cfefee373c78 100644 --- a/tests/ui/return_and_then.rs +++ b/tests/ui/return_and_then.rs @@ -3,6 +3,7 @@ fn main() { fn test_opt_block(opt: Option) -> Option { opt.and_then(|n| { + //~^ return_and_then let mut ret = n + 1; ret += n; if n > 1 { Some(ret) } else { None } @@ -11,28 +12,34 @@ fn main() { fn test_opt_func(opt: Option) -> Option { opt.and_then(|n| test_opt_block(Some(n))) + //~^ return_and_then } fn test_call_chain() -> Option { gen_option(1).and_then(|n| test_opt_block(Some(n))) + //~^ return_and_then } fn test_res_block(opt: Result) -> Result { opt.and_then(|n| if n > 1 { Ok(n + 1) } else { Err(n) }) + //~^ return_and_then } fn test_res_func(opt: Result) -> Result { opt.and_then(|n| test_res_block(Ok(n))) + //~^ return_and_then } fn test_ref_only() -> Option { // ref: empty string Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None }) + //~^ return_and_then } fn test_tmp_only() -> Option { // unused temporary: vec![1, 2, 4] Some(match (vec![1, 2, 3], vec![1, 2, 4]) { + //~^ return_and_then (a, _) if a.len() > 1 => a, (_, b) => b, }) diff --git a/tests/ui/return_and_then.stderr b/tests/ui/return_and_then.stderr index b2e8bf2ca45a..ef5f7417de78 100644 --- a/tests/ui/return_and_then.stderr +++ b/tests/ui/return_and_then.stderr @@ -2,6 +2,7 @@ error: use the question mark operator instead of an `and_then` call --> tests/ui/return_and_then.rs:5:9 | LL | / opt.and_then(|n| { +LL | | LL | | let mut ret = n + 1; LL | | ret += n; LL | | if n > 1 { Some(ret) } else { None } @@ -13,13 +14,14 @@ LL | | }) help: try | LL ~ let n = opt?; -LL + let mut ret = n + 1; -LL + ret += n; -LL + if n > 1 { Some(ret) } else { None } +LL + +LL + let mut ret = n + 1; +LL + ret += n; +LL + if n > 1 { Some(ret) } else { None } | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:13:9 + --> tests/ui/return_and_then.rs:14:9 | LL | opt.and_then(|n| test_opt_block(Some(n))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +33,7 @@ LL + test_opt_block(Some(n)) | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:17:9 + --> tests/ui/return_and_then.rs:19:9 | LL | gen_option(1).and_then(|n| test_opt_block(Some(n))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +45,7 @@ LL + test_opt_block(Some(n)) | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:21:9 + --> tests/ui/return_and_then.rs:24:9 | LL | opt.and_then(|n| if n > 1 { Ok(n + 1) } else { Err(n) }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +57,7 @@ LL + if n > 1 { Ok(n + 1) } else { Err(n) } | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:25:9 + --> tests/ui/return_and_then.rs:29:9 | LL | opt.and_then(|n| test_res_block(Ok(n))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +69,7 @@ LL + test_res_block(Ok(n)) | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:30:9 + --> tests/ui/return_and_then.rs:35:9 | LL | Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,9 +81,10 @@ LL + if x.len() > 2 { Some(3) } else { None } | error: use the question mark operator instead of an `and_then` call - --> tests/ui/return_and_then.rs:35:9 + --> tests/ui/return_and_then.rs:41:9 | LL | / Some(match (vec![1, 2, 3], vec![1, 2, 4]) { +LL | | LL | | (a, _) if a.len() > 1 => a, LL | | (_, b) => b, LL | | }) @@ -91,6 +94,7 @@ LL | | .and_then(|x| if x.len() > 2 { Some(3) } else { None }) help: try | LL ~ let x = Some(match (vec![1, 2, 3], vec![1, 2, 4]) { +LL + LL + (a, _) if a.len() > 1 => a, LL + (_, b) => b, LL + })?; diff --git a/tests/ui/return_self_not_must_use.rs b/tests/ui/return_self_not_must_use.rs index ec6f0feb8e65..2e9a29aea0d7 100644 --- a/tests/ui/return_self_not_must_use.rs +++ b/tests/ui/return_self_not_must_use.rs @@ -6,7 +6,8 @@ pub struct Bar; pub trait Whatever { fn what(&self) -> Self; - //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` + //~^ return_self_not_must_use + // There should be no warning here! (returns a reference) fn what2(&self) -> &Self; } @@ -17,11 +18,13 @@ impl Bar { Self } pub fn foo(&self) -> Self { - //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` + //~^ return_self_not_must_use + Self } pub fn bar(self) -> Self { - //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` + //~^ return_self_not_must_use + 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 01f826b94a80..3e6a28f32920 100644 --- a/tests/ui/return_self_not_must_use.stderr +++ b/tests/ui/return_self_not_must_use.stderr @@ -9,10 +9,11 @@ LL | fn what(&self) -> Self; = help: to override `-D warnings` add `#[allow(clippy::return_self_not_must_use)]` error: missing `#[must_use]` attribute on a method returning `Self` - --> tests/ui/return_self_not_must_use.rs:19:5 + --> tests/ui/return_self_not_must_use.rs:20:5 | LL | / pub fn foo(&self) -> Self { LL | | +LL | | LL | | Self LL | | } | |_____^ @@ -20,10 +21,11 @@ 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` - --> tests/ui/return_self_not_must_use.rs:23:5 + --> tests/ui/return_self_not_must_use.rs:25:5 | LL | / pub fn bar(self) -> Self { LL | | +LL | | LL | | self LL | | } | |_____^ diff --git a/tests/ui/reversed_empty_ranges_fixable.fixed b/tests/ui/reversed_empty_ranges_fixable.fixed index c8bf1b35085d..ba5059bbaa37 100644 --- a/tests/ui/reversed_empty_ranges_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_fixable.fixed @@ -7,10 +7,14 @@ fn main() { // These should be linted: (21..=42).rev().for_each(|x| println!("{}", x)); + //~^ reversed_empty_ranges let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::>(); + //~^ reversed_empty_ranges for _ in (-42..=-21).rev() {} + //~^ reversed_empty_ranges for _ in (21u32..42u32).rev() {} + //~^ reversed_empty_ranges // These should be ignored as they are not empty ranges: diff --git a/tests/ui/reversed_empty_ranges_fixable.rs b/tests/ui/reversed_empty_ranges_fixable.rs index 6733c096420b..4068bc393066 100644 --- a/tests/ui/reversed_empty_ranges_fixable.rs +++ b/tests/ui/reversed_empty_ranges_fixable.rs @@ -7,10 +7,14 @@ fn main() { // These should be linted: (42..=21).for_each(|x| println!("{}", x)); + //~^ reversed_empty_ranges let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); + //~^ reversed_empty_ranges for _ in -21..=-42 {} + //~^ reversed_empty_ranges for _ in 42u32..21u32 {} + //~^ reversed_empty_ranges // These should be ignored as they are not empty ranges: diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index 3747eb9deebc..706413726a12 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -12,7 +12,7 @@ LL | (21..=42).rev().for_each(|x| println!("{}", x)); | ~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_fixable.rs:10:13 + --> tests/ui/reversed_empty_ranges_fixable.rs:11:13 | LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect:: tests/ui/reversed_empty_ranges_fixable.rs:12:14 + --> tests/ui/reversed_empty_ranges_fixable.rs:14:14 | LL | for _ in -21..=-42 {} | ^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for _ in (-42..=-21).rev() {} | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_fixable.rs:13:14 + --> tests/ui/reversed_empty_ranges_fixable.rs:16: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 df5f2c441f41..5d7f852e4e53 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -5,14 +5,17 @@ fn main() { const MAX_LEN: usize = 42; for i in (0..10).rev() { + //~^ reversed_empty_ranges println!("{}", i); } for i in (0..=10).rev() { + //~^ reversed_empty_ranges println!("{}", i); } for i in (0..MAX_LEN).rev() { + //~^ reversed_empty_ranges println!("{}", i); } @@ -32,15 +35,18 @@ fn main() { } for i in (0..10).rev().map(|x| x * 2) { + //~^ reversed_empty_ranges println!("{}", i); } // testing that the empty range lint folds constants for i in (5 + 4..10).rev() { + //~^ reversed_empty_ranges println!("{}", i); } for i in ((3 - 1)..(5 + 2)).rev() { + //~^ reversed_empty_ranges println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs index 92481be6cfc9..b65d4adb090a 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -5,14 +5,17 @@ fn main() { const MAX_LEN: usize = 42; for i in 10..0 { + //~^ reversed_empty_ranges println!("{}", i); } for i in 10..=0 { + //~^ reversed_empty_ranges println!("{}", i); } for i in MAX_LEN..0 { + //~^ reversed_empty_ranges println!("{}", i); } @@ -32,15 +35,18 @@ fn main() { } for i in (10..0).map(|x| x * 2) { + //~^ reversed_empty_ranges println!("{}", i); } // testing that the empty range lint folds constants for i in 10..5 + 4 { + //~^ reversed_empty_ranges println!("{}", i); } for i in (5 + 2)..(3 - 1) { + //~^ reversed_empty_ranges println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index d5df34c42f4f..0c05f351b46f 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -12,7 +12,7 @@ LL | for i in (0..10).rev() { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_fixable.rs:11:14 + --> tests/ui/reversed_empty_ranges_loops_fixable.rs:12:14 | LL | for i in 10..=0 { | ^^^^^^ @@ -23,7 +23,7 @@ LL | for i in (0..=10).rev() { | ~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_fixable.rs:15:14 + --> tests/ui/reversed_empty_ranges_loops_fixable.rs:17:14 | LL | for i in MAX_LEN..0 { | ^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for i in (0..MAX_LEN).rev() { | ~~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_fixable.rs:34:14 + --> tests/ui/reversed_empty_ranges_loops_fixable.rs:37:14 | LL | for i in (10..0).map(|x| x * 2) { | ^^^^^^^ @@ -45,7 +45,7 @@ LL | for i in (0..10).rev().map(|x| x * 2) { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_fixable.rs:39:14 + --> tests/ui/reversed_empty_ranges_loops_fixable.rs:43:14 | LL | for i in 10..5 + 4 { | ^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for i in (5 + 4..10).rev() { | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_fixable.rs:43:14 + --> tests/ui/reversed_empty_ranges_loops_fixable.rs:48:14 | LL | for i in (5 + 2)..(3 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs index cd1701dd4bf2..4fc7fb50a9ec 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -3,13 +3,15 @@ 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` + //~^ reversed_empty_ranges + + println!("{}", i); } for i in (5 + 2)..(8 - 1) { - //~^ ERROR: this range is empty so it will yield no values + //~^ reversed_empty_ranges + println!("{}", i); } } diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index b9e6fa04a34c..b5c17aad46bc 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -8,7 +8,7 @@ LL | for i in 5..5 { = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_unfixable.rs:11:14 + --> tests/ui/reversed_empty_ranges_loops_unfixable.rs:12: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 16c1121ae069..1ed35786a0da 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_unfixable.rs @@ -6,13 +6,16 @@ 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` + //~^ reversed_empty_ranges + + let _ = &arr[SOME_NUM..1]; - //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim + //~^ reversed_empty_ranges + for _ in ANSWER..ANSWER {} - //~^ ERROR: this range is empty so it will yield no values + //~^ reversed_empty_ranges + // 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 bc2b9576c41d..770d916bad66 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -8,13 +8,13 @@ LL | let _ = &arr[3usize..=1usize]; = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is reversed and using it to index a slice will panic at run-time - --> tests/ui/reversed_empty_ranges_unfixable.rs:11:18 + --> tests/ui/reversed_empty_ranges_unfixable.rs:12:18 | LL | let _ = &arr[SOME_NUM..1]; | ^^^^^^^^^^^ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_unfixable.rs:14:14 + --> tests/ui/reversed_empty_ranges_unfixable.rs:16:14 | LL | for _ in ANSWER..ANSWER {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs index a207e4221355..47954392178a 100644 --- a/tests/ui/same_functions_in_if_condition.rs +++ b/tests/ui/same_functions_in_if_condition.rs @@ -37,33 +37,39 @@ fn ifs_same_cond_fn() { if function() { } else if function() { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } if fn_arg(a) { } else if fn_arg(a) { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } if obj.method() { } else if obj.method() { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } if obj.method_arg(a) { } else if obj.method_arg(a) { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } let mut v = vec![1]; if v.pop().is_none() { } else if v.pop().is_none() { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } if v.len() == 42 { } else if v.len() == 42 { - //~^ ERROR: `if` has the same function call as a previous `if` + //~^ same_functions_in_if_condition + } if v.len() == 1 { diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index 6cd4f96c13e3..0d40c8359557 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -16,61 +16,61 @@ LL | #![deny(clippy::same_functions_in_if_condition)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:44:15 + --> tests/ui/same_functions_in_if_condition.rs:45:15 | LL | } else if fn_arg(a) { | ^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:43:8 + --> tests/ui/same_functions_in_if_condition.rs:44:8 | LL | if fn_arg(a) { | ^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:49:15 + --> tests/ui/same_functions_in_if_condition.rs:51:15 | LL | } else if obj.method() { | ^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:48:8 + --> tests/ui/same_functions_in_if_condition.rs:50:8 | LL | if obj.method() { | ^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:54:15 + --> tests/ui/same_functions_in_if_condition.rs:57:15 | LL | } else if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:53:8 + --> tests/ui/same_functions_in_if_condition.rs:56:8 | LL | if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:60:15 + --> tests/ui/same_functions_in_if_condition.rs:64:15 | LL | } else if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:59:8 + --> tests/ui/same_functions_in_if_condition.rs:63:8 | LL | if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:65:15 + --> tests/ui/same_functions_in_if_condition.rs:70:15 | LL | } else if v.len() == 42 { | ^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:64:8 + --> tests/ui/same_functions_in_if_condition.rs:69:8 | LL | if v.len() == 42 { | ^^^^^^^^^^^^^ diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs index 87fd59ad3179..dbe9c729bc56 100644 --- a/tests/ui/same_item_push.rs +++ b/tests/ui/same_item_push.rs @@ -21,33 +21,38 @@ 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` + //~^ same_item_push + } 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` + //~^ same_item_push + } 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` + //~^ same_item_push + } 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` + //~^ same_item_push + } 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` + //~^ same_item_push + } #[clippy::msrv = "1.81"] @@ -56,7 +61,8 @@ fn main() { let item = VALUE; for _ in 0..20 { vec.push(item); - //~^ ERROR: it looks like the same item is being pushed into this `Vec` + //~^ same_item_push + } } diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index e3fa4f9cbcec..d2bf5069a846 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -10,7 +10,7 @@ LL | vec.push(item); = help: to override `-D warnings` add `#[allow(clippy::same_item_push)]` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:30:9 + --> tests/ui/same_item_push.rs:31:9 | LL | vec.push(item); | ^^^ @@ -19,7 +19,7 @@ LL | vec.push(item); = help: or `vec.extend(std::iter::repeat_n(item, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:36:9 + --> tests/ui/same_item_push.rs:38:9 | LL | vec.push(13); | ^^^ @@ -28,7 +28,7 @@ LL | vec.push(13); = help: or `vec.extend(std::iter::repeat_n(13, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:42:9 + --> tests/ui/same_item_push.rs:45:9 | LL | vec.push(VALUE); | ^^^ @@ -37,7 +37,7 @@ LL | vec.push(VALUE); = help: or `vec.extend(std::iter::repeat_n(VALUE, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:49:9 + --> tests/ui/same_item_push.rs:53:9 | LL | vec.push(item); | ^^^ @@ -46,7 +46,7 @@ LL | vec.push(item); = help: or `vec.extend(std::iter::repeat_n(item, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:58:13 + --> tests/ui/same_item_push.rs:63:13 | LL | vec.push(item); | ^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index ba876c2b5a3f..398f3a7d5f91 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -18,7 +18,8 @@ mod should_lint { impl S { fn foo() {} - //~^ ERROR: method's name is the same as an existing method in a trait + //~^ same_name_method + } impl T1 for S { @@ -33,7 +34,8 @@ mod should_lint { impl S { fn clone() {} - //~^ ERROR: method's name is the same as an existing method in a trait + //~^ same_name_method + } } @@ -44,7 +46,8 @@ mod should_lint { impl S { fn foo() {} - //~^ ERROR: method's name is the same as an existing method in a trait + //~^ same_name_method + } impl T1 for S { @@ -59,7 +62,8 @@ mod should_lint { impl S { fn foo() {} - //~^ ERROR: method's name is the same as an existing method in a trait + //~^ same_name_method + } impl T1 for S {} @@ -72,8 +76,10 @@ mod should_lint { impl S { fn foo() {} - //~^ ERROR: method's name is the same as an existing method in a trait - //~| ERROR: method's name is the same as an existing method in a trait + //~^ same_name_method + //~| same_name_method + + } impl T1 for S {} diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index fefdb5c9c23d..d3bf386ea545 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -5,7 +5,7 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:25:13 + --> tests/ui/same_name_method.rs:26:13 | LL | fn foo() {} | ^^^^^^^^^^^ @@ -13,62 +13,62 @@ LL | fn foo() {} = help: to override `-D warnings` add `#[allow(clippy::same_name_method)]` error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:35:13 + --> tests/ui/same_name_method.rs:36:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> tests/ui/same_name_method.rs:31:18 + --> tests/ui/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 - --> tests/ui/same_name_method.rs:46:13 + --> tests/ui/same_name_method.rs:48:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:51:13 + --> tests/ui/same_name_method.rs:54:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:61:13 + --> tests/ui/same_name_method.rs:64:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:65:9 + --> tests/ui/same_name_method.rs:69:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:74:13 + --> tests/ui/same_name_method.rs:78:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:79:9 + --> tests/ui/same_name_method.rs:85:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:74:13 + --> tests/ui/same_name_method.rs:78:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:81:9 + --> tests/ui/same_name_method.rs:87:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/search_is_some.rs b/tests/ui/search_is_some.rs index 9a9aaba56adc..4143b8bfba58 100644 --- a/tests/ui/search_is_some.rs +++ b/tests/ui/search_is_some.rs @@ -14,18 +14,21 @@ fn main() { // Check `find().is_some()`, multi-line case. let _ = v.iter().find(|&x| { + //~^ search_is_some *x < 0 } ).is_some(); // Check `position().is_some()`, multi-line case. let _ = v.iter().position(|&x| { + //~^ search_is_some x < 0 } ).is_some(); // Check `rposition().is_some()`, multi-line case. let _ = v.iter().rposition(|&x| { + //~^ search_is_some x < 0 } ).is_some(); @@ -41,6 +44,7 @@ fn main() { let some_closure = |x: &u32| *x == 0; let _ = (0..1).find(some_closure).is_some(); + //~^ search_is_some } #[rustfmt::skip] @@ -51,18 +55,21 @@ fn is_none() { // Check `find().is_none()`, multi-line case. let _ = v.iter().find(|&x| { + //~^ search_is_some *x < 0 } ).is_none(); // Check `position().is_none()`, multi-line case. let _ = v.iter().position(|&x| { + //~^ search_is_some x < 0 } ).is_none(); // Check `rposition().is_none()`, multi-line case. let _ = v.iter().rposition(|&x| { + //~^ search_is_some x < 0 } ).is_none(); @@ -78,4 +85,5 @@ fn is_none() { let some_closure = |x: &u32| *x == 0; let _ = (0..1).find(some_closure).is_none(); + //~^ search_is_some } diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr index b5ef55341770..d9a43c8915e8 100644 --- a/tests/ui/search_is_some.stderr +++ b/tests/ui/search_is_some.stderr @@ -3,6 +3,7 @@ error: called `is_some()` after searching an `Iterator` with `find` | LL | let _ = v.iter().find(|&x| { | _____________^ +LL | | LL | | *x < 0 LL | | } LL | | ).is_some(); @@ -13,10 +14,11 @@ LL | | ).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some.rs:22:13 + --> tests/ui/search_is_some.rs:23:13 | LL | let _ = v.iter().position(|&x| { | _____________^ +LL | | LL | | x < 0 LL | | } LL | | ).is_some(); @@ -25,10 +27,11 @@ LL | | ).is_some(); = help: this is more succinctly expressed by calling `any()` error: called `is_some()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some.rs:28:13 + --> tests/ui/search_is_some.rs:30:13 | LL | let _ = v.iter().rposition(|&x| { | _____________^ +LL | | LL | | x < 0 LL | | } LL | | ).is_some(); @@ -37,16 +40,17 @@ LL | | ).is_some(); = help: this is more succinctly expressed by calling `any()` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some.rs:43:20 + --> tests/ui/search_is_some.rs:46:20 | LL | let _ = (0..1).find(some_closure).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(some_closure)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some.rs:53:13 + --> tests/ui/search_is_some.rs:57:13 | LL | let _ = v.iter().find(|&x| { | _____________^ +LL | | LL | | *x < 0 LL | | } LL | | ).is_none(); @@ -55,10 +59,11 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some.rs:59:13 + --> tests/ui/search_is_some.rs:64:13 | LL | let _ = v.iter().position(|&x| { | _____________^ +LL | | LL | | x < 0 LL | | } LL | | ).is_none(); @@ -67,10 +72,11 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some.rs:65:13 + --> tests/ui/search_is_some.rs:71:13 | LL | let _ = v.iter().rposition(|&x| { | _____________^ +LL | | LL | | x < 0 LL | | } LL | | ).is_none(); @@ -79,7 +85,7 @@ LL | | ).is_none(); = help: this is more succinctly expressed by calling `any()` with negation error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some.rs:80:13 + --> tests/ui/search_is_some.rs:87:13 | LL | let _ = (0..1).find(some_closure).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(some_closure)` diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 86a937b4dae1..e33f32d5bdb8 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -7,36 +7,55 @@ fn main() { // Check `find().is_none()`, single-line case. let _ = !v.iter().any(|x| *x < 0); + //~^ search_is_some let _ = !(0..1).any(|x| **y == x); // one dereference less + //~^ search_is_some let _ = !(0..1).any(|x| x == 0); + //~^ search_is_some let _ = !v.iter().any(|x| *x == 0); + //~^ search_is_some let _ = !(4..5).any(|x| x == 1 || x == 3 || x == 5); + //~^ search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = !(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0); + //~^ search_is_some let _ = !(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1); // Check `position().is_none()`, single-line case. let _ = !v.iter().any(|&x| x < 0); + //~^ search_is_some // Check `rposition().is_none()`, single-line case. let _ = !v.iter().any(|&x| x < 0); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = !"hello world".contains("world"); + //~^ search_is_some let _ = !"hello world".contains(&s2); + //~^ search_is_some let _ = !"hello world".contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is a `String` let _ = !s1.contains("world"); + //~^ search_is_some let _ = !s1.contains(&s2); + //~^ search_is_some let _ = !s1.contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is slice of `String` let _ = !s1[2..].contains("world"); + //~^ search_is_some let _ = !s1[2..].contains(&s2); + //~^ search_is_some let _ = !s1[2..].contains(&s2[2..]); + //~^ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -53,6 +72,7 @@ mod issue7392 { .hand .iter() .filter(|c| !filter_hand.iter().any(|cc| c == &cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -69,6 +89,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| !filter_hand.iter().any(|cc| c == cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -80,21 +101,25 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = !vfoo.iter().any(|v| v.foo == 1 && v.bar == 2); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = !vfoo + //~^ search_is_some .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); } fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = !vfoo.iter().any(|a| a[0] == 42); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = !vfoo.iter().any(|sub| sub[1..4].len() == 3); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -113,16 +138,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = ![ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); + //~^ search_is_some let _ = ![String::from("Hey hey")].iter().any(|s| s.len() == 2); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = !v.iter().any(|x| deref_enough(*x)); + //~^ search_is_some let _ = !v.iter().any(|x: &u32| deref_enough(*x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = !v.iter().any(|x| arg_no_deref(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = !v.iter().any(|x: &u32| arg_no_deref(&x)); + //~^ search_is_some } fn field_index_projection() { @@ -143,6 +174,7 @@ mod issue7392 { }, }]; let _ = !vfoo + //~^ search_is_some .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2); } @@ -157,11 +189,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = !vfoo.iter().any(|v| v.inner[0].bar == 2); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = !vfoo.iter().any(|x| (**x)[0] == 9); + //~^ search_is_some } fn method_call_by_ref() { @@ -175,11 +209,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = !vfoo.iter().any(|v| v.by_ref(&v.bar)); + //~^ search_is_some } fn ref_bindings() { let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some let _ = ![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -199,7 +236,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = !v.iter().any(|s| s[0].is_empty()); + //~^ search_is_some let _ = !v.iter().any(|s| test_string_1(&s[0])); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -209,8 +248,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = !v.iter().any(|fp| fp.field.is_power_of_two()); + //~^ search_is_some let _ = !v.iter().any(|fp| test_u32_1(fp.field)); + //~^ search_is_some let _ = !v.iter().any(|fp| test_u32_2(*fp.field)); + //~^ search_is_some } } @@ -227,39 +269,51 @@ mod issue_11910 { fn test_normal_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; let _ = !v.iter().any(|x| *x == 42); + //~^ search_is_some Foo.bar(!v.iter().any(|x| *x == 42)); + //~^ search_is_some } fn test_then_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; (!v.iter().any(|x| *x == 42)).then(computations); + //~^ search_is_some } fn test_then_some_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; (!v.iter().any(|x| *x == 42)).then_some(0); + //~^ search_is_some } fn test_normal_for_str() { let s = "hello"; let _ = !s.contains("world"); + //~^ search_is_some Foo.bar(!s.contains("world")); + //~^ search_is_some let s = String::from("hello"); let _ = !s.contains("world"); + //~^ search_is_some Foo.bar(!s.contains("world")); + //~^ search_is_some } fn test_then_for_str() { let s = "hello"; let _ = (!s.contains("world")).then(computations); + //~^ search_is_some let s = String::from("hello"); let _ = (!s.contains("world")).then(computations); + //~^ search_is_some } fn test_then_some_for_str() { let s = "hello"; let _ = (!s.contains("world")).then_some(0); + //~^ search_is_some let s = String::from("hello"); let _ = (!s.contains("world")).then_some(0); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index c0103a015097..86885c7d3be3 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -7,38 +7,58 @@ fn main() { // Check `find().is_none()`, single-line case. let _ = v.iter().find(|&x| *x < 0).is_none(); + //~^ search_is_some let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less + //~^ search_is_some let _ = (0..1).find(|x| *x == 0).is_none(); + //~^ search_is_some let _ = v.iter().find(|x| **x == 0).is_none(); + //~^ search_is_some let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); + //~^ search_is_some let _ = (1..3) + //~^ search_is_some .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) .is_none(); // Check `position().is_none()`, single-line case. let _ = v.iter().position(|&x| x < 0).is_none(); + //~^ search_is_some // Check `rposition().is_none()`, single-line case. let _ = v.iter().rposition(|&x| x < 0).is_none(); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".find("world").is_none(); + //~^ search_is_some let _ = "hello world".find(&s2).is_none(); + //~^ search_is_some let _ = "hello world".find(&s2[2..]).is_none(); + //~^ search_is_some // caller of `find()` is a `String` let _ = s1.find("world").is_none(); + //~^ search_is_some let _ = s1.find(&s2).is_none(); + //~^ search_is_some let _ = s1.find(&s2[2..]).is_none(); + //~^ search_is_some // caller of `find()` is slice of `String` let _ = s1[2..].find("world").is_none(); + //~^ search_is_some let _ = s1[2..].find(&s2).is_none(); + //~^ search_is_some let _ = s1[2..].find(&s2[2..]).is_none(); + //~^ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -55,6 +75,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -71,6 +92,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -82,9 +104,11 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo + //~^ search_is_some .iter() .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) .is_none(); @@ -93,12 +117,14 @@ mod issue7392 { fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -117,16 +143,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().find(|x| deref_enough(**x)).is_none(); + //~^ search_is_some let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); + //~^ search_is_some } fn field_index_projection() { @@ -147,6 +179,7 @@ mod issue7392 { }, }]; let _ = vfoo + //~^ search_is_some .iter() .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) .is_none(); @@ -163,11 +196,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); + //~^ search_is_some } fn method_call_by_ref() { @@ -181,11 +216,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -205,7 +243,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().find(|s| s[0].is_empty()).is_none(); + //~^ search_is_some let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -215,8 +255,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); + //~^ search_is_some } } @@ -233,39 +276,51 @@ mod issue_11910 { fn test_normal_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; let _ = v.iter().find(|x| **x == 42).is_none(); + //~^ search_is_some Foo.bar(v.iter().find(|x| **x == 42).is_none()); + //~^ search_is_some } fn test_then_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; v.iter().find(|x| **x == 42).is_none().then(computations); + //~^ search_is_some } fn test_then_some_for_iter() { let v = vec![3, 2, 1, 0, -1, -2, -3]; v.iter().find(|x| **x == 42).is_none().then_some(0); + //~^ search_is_some } fn test_normal_for_str() { let s = "hello"; let _ = s.find("world").is_none(); + //~^ search_is_some Foo.bar(s.find("world").is_none()); + //~^ search_is_some let s = String::from("hello"); let _ = s.find("world").is_none(); + //~^ search_is_some Foo.bar(s.find("world").is_none()); + //~^ search_is_some } fn test_then_for_str() { let s = "hello"; let _ = s.find("world").is_none().then(computations); + //~^ search_is_some let s = String::from("hello"); let _ = s.find("world").is_none().then(computations); + //~^ search_is_some } fn test_then_some_for_str() { let s = "hello"; let _ = s.find("world").is_none().then_some(0); + //~^ search_is_some let s = String::from("hello"); let _ = s.find("world").is_none().then_some(0); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index 2c858b9fb10e..e134df9f63c9 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -8,145 +8,147 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_none(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:10:13 + --> tests/ui/search_is_some_fixable_none.rs:11:13 | LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| **y == x)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:11:13 + --> tests/ui/search_is_some_fixable_none.rs:13:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:12:13 + --> tests/ui/search_is_some_fixable_none.rs:15:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:13:13 + --> tests/ui/search_is_some_fixable_none.rs:17:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:14:13 + --> tests/ui/search_is_some_fixable_none.rs:19:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:15:13 + --> tests/ui/search_is_some_fixable_none.rs:21:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:16:13 + --> tests/ui/search_is_some_fixable_none.rs:23:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:17:13 + --> tests/ui/search_is_some_fixable_none.rs:25:13 | LL | let _ = (1..3) | _____________^ +LL | | LL | | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) LL | | .is_none(); | |__________________^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_none()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_none.rs:22:13 + --> tests/ui/search_is_some_fixable_none.rs:31:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_none.rs:25:13 + --> tests/ui/search_is_some_fixable_none.rs:35:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:31:13 + --> tests/ui/search_is_some_fixable_none.rs:42:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:32:13 + --> tests/ui/search_is_some_fixable_none.rs:44:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:33:13 + --> tests/ui/search_is_some_fixable_none.rs:46:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:35:13 + --> tests/ui/search_is_some_fixable_none.rs:49:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:36:13 + --> tests/ui/search_is_some_fixable_none.rs:51:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:37:13 + --> tests/ui/search_is_some_fixable_none.rs:53:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:39:13 + --> tests/ui/search_is_some_fixable_none.rs:56:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:40:13 + --> tests/ui/search_is_some_fixable_none.rs:58:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:41:13 + --> tests/ui/search_is_some_fixable_none.rs:60:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:57:25 + --> tests/ui/search_is_some_fixable_none.rs:77:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:73:30 + --> tests/ui/search_is_some_fixable_none.rs:94:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:84:17 + --> tests/ui/search_is_some_fixable_none.rs:106:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.foo == 1 && v.bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:87:17 + --> tests/ui/search_is_some_fixable_none.rs:110:17 | LL | let _ = vfoo | _________________^ +LL | | LL | | .iter() LL | | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) LL | | .is_none(); @@ -155,62 +157,64 @@ LL | | .is_none(); help: consider using | LL ~ let _ = !vfoo +LL + LL ~ .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:95:17 + --> tests/ui/search_is_some_fixable_none.rs:119:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:101:17 + --> tests/ui/search_is_some_fixable_none.rs:126:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:119:17 + --> tests/ui/search_is_some_fixable_none.rs:145:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:120:17 + --> tests/ui/search_is_some_fixable_none.rs:147:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:123:17 + --> tests/ui/search_is_some_fixable_none.rs:151:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:124:17 + --> tests/ui/search_is_some_fixable_none.rs:153:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:127:17 + --> tests/ui/search_is_some_fixable_none.rs:157:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:129:17 + --> tests/ui/search_is_some_fixable_none.rs:160:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:149:17 + --> tests/ui/search_is_some_fixable_none.rs:181:17 | LL | let _ = vfoo | _________________^ +LL | | LL | | .iter() LL | | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) LL | | .is_none(); @@ -219,137 +223,138 @@ LL | | .is_none(); help: consider using | LL ~ let _ = !vfoo +LL + LL ~ .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:165:17 + --> tests/ui/search_is_some_fixable_none.rs:198:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.inner[0].bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:170:17 + --> tests/ui/search_is_some_fixable_none.rs:204:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:183:17 + --> tests/ui/search_is_some_fixable_none.rs:218:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.by_ref(&v.bar))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:187:17 + --> tests/ui/search_is_some_fixable_none.rs:223:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:188:17 + --> tests/ui/search_is_some_fixable_none.rs:225:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:207:17 + --> tests/ui/search_is_some_fixable_none.rs:245:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| s[0].is_empty())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:208:17 + --> tests/ui/search_is_some_fixable_none.rs:247:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| test_string_1(&s[0]))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:217:17 + --> tests/ui/search_is_some_fixable_none.rs:257:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| fp.field.is_power_of_two())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:218:17 + --> tests/ui/search_is_some_fixable_none.rs:259:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_1(fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:219:17 + --> tests/ui/search_is_some_fixable_none.rs:261:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_2(*fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:235:17 + --> tests/ui/search_is_some_fixable_none.rs:278:17 | LL | let _ = v.iter().find(|x| **x == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:236:17 + --> tests/ui/search_is_some_fixable_none.rs:280:17 | LL | Foo.bar(v.iter().find(|x| **x == 42).is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:241:9 + --> tests/ui/search_is_some_fixable_none.rs:286:9 | LL | v.iter().find(|x| **x == 42).is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:246:9 + --> tests/ui/search_is_some_fixable_none.rs:292:9 | LL | v.iter().find(|x| **x == 42).is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:251:17 + --> tests/ui/search_is_some_fixable_none.rs:298:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:252:17 + --> tests/ui/search_is_some_fixable_none.rs:300:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:254:17 + --> tests/ui/search_is_some_fixable_none.rs:303:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:255:17 + --> tests/ui/search_is_some_fixable_none.rs:305:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:260:17 + --> tests/ui/search_is_some_fixable_none.rs:311:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:262:17 + --> tests/ui/search_is_some_fixable_none.rs:314:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:267:17 + --> tests/ui/search_is_some_fixable_none.rs:320:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:269:17 + --> tests/ui/search_is_some_fixable_none.rs:323:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index ae3cbc3c4da2..69467796e0c9 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -7,36 +7,55 @@ fn main() { // Check `find().is_some()`, single-line case. let _ = v.iter().any(|x| *x < 0); + //~^ search_is_some let _ = (0..1).any(|x| **y == x); // one dereference less + //~^ search_is_some let _ = (0..1).any(|x| x == 0); + //~^ search_is_some let _ = v.iter().any(|x| *x == 0); + //~^ search_is_some let _ = (4..5).any(|x| x == 1 || x == 3 || x == 5); + //~^ search_is_some let _ = (1..3).any(|x| [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = (1..3).any(|x| x == 0 || [1, 2, 3].contains(&x)); + //~^ search_is_some let _ = (1..3).any(|x| [1, 2, 3].contains(&x) || x == 0); + //~^ search_is_some let _ = (1..3) .any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1); // Check `position().is_some()`, single-line case. let _ = v.iter().any(|&x| x < 0); + //~^ search_is_some // Check `rposition().is_some()`, single-line case. let _ = v.iter().any(|&x| x < 0); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".contains("world"); + //~^ search_is_some let _ = "hello world".contains(&s2); + //~^ search_is_some let _ = "hello world".contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is a `String` let _ = s1.contains("world"); + //~^ search_is_some let _ = s1.contains(&s2); + //~^ search_is_some let _ = s1.contains(&s2[2..]); + //~^ search_is_some // caller of `find()` is slice of `String` let _ = s1[2..].contains("world"); + //~^ search_is_some let _ = s1[2..].contains(&s2); + //~^ search_is_some let _ = s1[2..].contains(&s2[2..]); + //~^ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -53,6 +72,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().any(|cc| c == &cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -69,6 +89,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().any(|cc| c == cc)) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -80,6 +101,7 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().any(|v| v.foo == 1 && v.bar == 2); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo @@ -90,12 +112,14 @@ mod issue7392 { fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().any(|a| a[0] == 42); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().any(|sub| sub[1..4].len() == 3); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -114,16 +138,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().any(|ppp_x: &&u32| please(ppp_x)); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().any(|s| s.len() == 2); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().any(|x| deref_enough(*x)); + //~^ search_is_some let _ = v.iter().any(|x: &u32| deref_enough(*x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x| arg_no_deref(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref(&x)); + //~^ search_is_some } fn field_index_projection() { @@ -159,11 +189,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().any(|v| v.inner[0].bar == 2); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().any(|x| (**x)[0] == 9); + //~^ search_is_some } fn method_call_by_ref() { @@ -177,11 +209,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().any(|v| v.by_ref(&v.bar)); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -201,7 +236,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().any(|s| s[0].is_empty()); + //~^ search_is_some let _ = v.iter().any(|s| test_string_1(&s[0])); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -211,8 +248,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().any(|fp| fp.field.is_power_of_two()); + //~^ search_is_some let _ = v.iter().any(|fp| test_u32_1(fp.field)); + //~^ search_is_some let _ = v.iter().any(|fp| test_u32_2(*fp.field)); + //~^ search_is_some } } @@ -228,6 +268,7 @@ mod issue9120 { fn wrapper bool>(v: Vec, func: T) -> bool { #[allow(clippy::redundant_closure)] v.iter().any(|x: &u32| func(&x)) + //~^ search_is_some } fn do_tests() { @@ -237,11 +278,14 @@ mod issue9120 { #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref_impl(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| arg_no_deref_dyn(&x)); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().any(|x: &u32| (*arg_no_deref_dyn)(&x)); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index 19a44803fd54..0ca80a563e28 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -7,37 +7,57 @@ fn main() { // Check `find().is_some()`, single-line case. let _ = v.iter().find(|&x| *x < 0).is_some(); + //~^ search_is_some let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less + //~^ search_is_some let _ = (0..1).find(|x| *x == 0).is_some(); + //~^ search_is_some let _ = v.iter().find(|x| **x == 0).is_some(); + //~^ search_is_some let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); + //~^ search_is_some let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); + //~^ search_is_some let _ = (1..3) .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) + //~^ search_is_some .is_some(); // Check `position().is_some()`, single-line case. let _ = v.iter().position(|&x| x < 0).is_some(); + //~^ search_is_some // Check `rposition().is_some()`, single-line case. let _ = v.iter().rposition(|&x| x < 0).is_some(); + //~^ search_is_some let s1 = String::from("hello world"); let s2 = String::from("world"); // caller of `find()` is a `&`static str` let _ = "hello world".find("world").is_some(); + //~^ search_is_some let _ = "hello world".find(&s2).is_some(); + //~^ search_is_some let _ = "hello world".find(&s2[2..]).is_some(); + //~^ search_is_some // caller of `find()` is a `String` let _ = s1.find("world").is_some(); + //~^ search_is_some let _ = s1.find(&s2).is_some(); + //~^ search_is_some let _ = s1.find(&s2[2..]).is_some(); + //~^ search_is_some // caller of `find()` is slice of `String` let _ = s1[2..].find("world").is_some(); + //~^ search_is_some let _ = s1[2..].find(&s2).is_some(); + //~^ search_is_some let _ = s1[2..].find(&s2[2..]).is_some(); + //~^ search_is_some } #[allow(clippy::clone_on_copy, clippy::map_clone)] @@ -54,6 +74,7 @@ mod issue7392 { .hand .iter() .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -70,6 +91,7 @@ mod issue7392 { .hand .iter() .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) + //~^ search_is_some .map(|c| c.clone()) .collect::>(); } @@ -81,23 +103,27 @@ mod issue7392 { } let vfoo = vec![Foo { foo: 1, bar: 2 }]; let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); + //~^ search_is_some let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo .iter() .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) + //~^ search_is_some .is_some(); } fn index_projection() { let vfoo = vec![[0, 1, 2, 3]]; let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); + //~^ search_is_some } #[allow(clippy::match_like_matches_macro)] fn slice_projection() { let vfoo = vec![[0, 1, 2, 3, 0, 1, 2, 3]]; let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); + //~^ search_is_some } fn please(x: &u32) -> bool { @@ -116,16 +142,22 @@ mod issue7392 { let x = 19; let ppx: &u32 = &x; let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); + //~^ search_is_some let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); + //~^ search_is_some let v = vec![3, 2, 1, 0]; let _ = v.iter().find(|x| deref_enough(**x)).is_some(); + //~^ search_is_some let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); + //~^ search_is_some } fn field_index_projection() { @@ -148,6 +180,7 @@ mod issue7392 { let _ = vfoo .iter() .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) + //~^ search_is_some .is_some(); } @@ -162,11 +195,13 @@ mod issue7392 { inner: vec![Foo { bar: 0 }], }]; let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); + //~^ search_is_some } fn double_deref_index_projection() { let vfoo = vec![&&[0, 1, 2, 3]]; let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); + //~^ search_is_some } fn method_call_by_ref() { @@ -180,11 +215,14 @@ mod issue7392 { } let vfoo = vec![Foo { bar: 1 }]; let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); + //~^ search_is_some } fn ref_bindings() { let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); + //~^ search_is_some let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); + //~^ search_is_some } fn test_string_1(s: &str) -> bool { @@ -204,7 +242,9 @@ mod issue7392 { let lst = &[String::from("Hello"), String::from("world")]; let v: Vec<&[String]> = vec![lst]; let _ = v.iter().find(|s| s[0].is_empty()).is_some(); + //~^ search_is_some let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); + //~^ search_is_some // Field projections struct FieldProjection<'a> { @@ -214,8 +254,11 @@ mod issue7392 { let instance = FieldProjection { field: &field }; let v = vec![instance]; let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); + //~^ search_is_some let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); + //~^ search_is_some } } @@ -231,6 +274,7 @@ mod issue9120 { fn wrapper bool>(v: Vec, func: T) -> bool { #[allow(clippy::redundant_closure)] v.iter().find(|x: &&u32| func(x)).is_some() + //~^ search_is_some } fn do_tests() { @@ -240,11 +284,14 @@ mod issue9120 { #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); + //~^ search_is_some #[allow(clippy::redundant_closure)] let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); + //~^ search_is_some } } diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index af1de7f82f80..3f18b0fdd3c3 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -8,283 +8,286 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:10:20 + --> tests/ui/search_is_some_fixable_some.rs:11:20 | LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:11:20 + --> tests/ui/search_is_some_fixable_some.rs:13:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:12:22 + --> tests/ui/search_is_some_fixable_some.rs:15:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| *x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:13:20 + --> tests/ui/search_is_some_fixable_some.rs:17:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 1 || x == 3 || x == 5)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:14:20 + --> tests/ui/search_is_some_fixable_some.rs:19:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:15:20 + --> tests/ui/search_is_some_fixable_some.rs:21:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:16:20 + --> tests/ui/search_is_some_fixable_some.rs:23:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:18:10 + --> tests/ui/search_is_some_fixable_some.rs:26:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ +LL | | LL | | .is_some(); | |__________________^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_some()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_some.rs:22:22 + --> tests/ui/search_is_some_fixable_some.rs:31:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_some.rs:25:22 + --> tests/ui/search_is_some_fixable_some.rs:35:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:30:27 + --> tests/ui/search_is_some_fixable_some.rs:41:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:31:27 + --> tests/ui/search_is_some_fixable_some.rs:43:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:32:27 + --> tests/ui/search_is_some_fixable_some.rs:45:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:34:16 + --> tests/ui/search_is_some_fixable_some.rs:48:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:35:16 + --> tests/ui/search_is_some_fixable_some.rs:50:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:36:16 + --> tests/ui/search_is_some_fixable_some.rs:52:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:38:21 + --> tests/ui/search_is_some_fixable_some.rs:55:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:39:21 + --> tests/ui/search_is_some_fixable_some.rs:57:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:40:21 + --> tests/ui/search_is_some_fixable_some.rs:59:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:56:44 + --> tests/ui/search_is_some_fixable_some.rs:76:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:72:49 + --> tests/ui/search_is_some_fixable_some.rs:93:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:83:29 + --> tests/ui/search_is_some_fixable_some.rs:105:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:88:14 + --> tests/ui/search_is_some_fixable_some.rs:111:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ +LL | | LL | | .is_some(); | |______________________^ help: consider using: `any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:94:29 + --> tests/ui/search_is_some_fixable_some.rs:118:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:100:29 + --> tests/ui/search_is_some_fixable_some.rs:125:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:118:30 + --> tests/ui/search_is_some_fixable_some.rs:144:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:119:50 + --> tests/ui/search_is_some_fixable_some.rs:146:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s.len() == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:122:26 + --> tests/ui/search_is_some_fixable_some.rs:150:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:123:26 + --> tests/ui/search_is_some_fixable_some.rs:152:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:126:26 + --> tests/ui/search_is_some_fixable_some.rs:156:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:128:26 + --> tests/ui/search_is_some_fixable_some.rs:159:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:150:14 + --> tests/ui/search_is_some_fixable_some.rs:182:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ +LL | | LL | | .is_some(); | |______________________^ help: consider using: `any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:164:29 + --> tests/ui/search_is_some_fixable_some.rs:197:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:169:29 + --> tests/ui/search_is_some_fixable_some.rs:203:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:182:29 + --> tests/ui/search_is_some_fixable_some.rs:217:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.by_ref(&v.bar))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:186:55 + --> tests/ui/search_is_some_fixable_some.rs:222:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:187:55 + --> tests/ui/search_is_some_fixable_some.rs:224:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:206:26 + --> tests/ui/search_is_some_fixable_some.rs:244:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:207:26 + --> tests/ui/search_is_some_fixable_some.rs:246:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| test_string_1(&s[0]))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:216:26 + --> tests/ui/search_is_some_fixable_some.rs:256:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| fp.field.is_power_of_two())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:217:26 + --> tests/ui/search_is_some_fixable_some.rs:258:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:218:26 + --> tests/ui/search_is_some_fixable_some.rs:260:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:233:18 + --> tests/ui/search_is_some_fixable_some.rs:276:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:242:26 + --> tests/ui/search_is_some_fixable_some.rs:286:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_impl(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:245:26 + --> tests/ui/search_is_some_fixable_some.rs:290:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_dyn(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:248:26 + --> tests/ui/search_is_some_fixable_some.rs:294:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/tests/ui/seek_from_current.fixed b/tests/ui/seek_from_current.fixed index 543f0c681393..08eb15fe4e78 100644 --- a/tests/ui/seek_from_current.fixed +++ b/tests/ui/seek_from_current.fixed @@ -17,6 +17,7 @@ fn _msrv_1_51() -> io::Result<()> { let mut f = File::create("foo.txt")?; f.write_all(b"Hi!")?; f.stream_position()?; + //~^ seek_from_current f.seek(SeekFrom::Current(1))?; Ok(()) } diff --git a/tests/ui/seek_from_current.rs b/tests/ui/seek_from_current.rs index 4ed877f8ec21..1974fd60dec7 100644 --- a/tests/ui/seek_from_current.rs +++ b/tests/ui/seek_from_current.rs @@ -17,6 +17,7 @@ fn _msrv_1_51() -> io::Result<()> { let mut f = File::create("foo.txt")?; f.write_all(b"Hi!")?; f.seek(SeekFrom::Current(0))?; + //~^ seek_from_current f.seek(SeekFrom::Current(1))?; Ok(()) } diff --git a/tests/ui/seek_to_start_instead_of_rewind.fixed b/tests/ui/seek_to_start_instead_of_rewind.fixed index 8859a68320f0..87747eafc443 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.fixed +++ b/tests/ui/seek_to_start_instead_of_rewind.fixed @@ -50,11 +50,13 @@ fn seek_to_start_false_trait_bound(t: &mut T) { // This should trigger clippy warning fn seek_to_start(t: &mut T) { t.rewind(); + //~^ seek_to_start_instead_of_rewind } // This should trigger clippy warning fn owned_seek_to_start(mut t: T) { t.rewind(); + //~^ seek_to_start_instead_of_rewind } // This should NOT trigger clippy warning because @@ -134,6 +136,7 @@ fn msrv_1_55() { write!(f, "{hello}").unwrap(); f.rewind(); + //~^ seek_to_start_instead_of_rewind let mut buf = String::new(); f.read_to_string(&mut buf).unwrap(); diff --git a/tests/ui/seek_to_start_instead_of_rewind.rs b/tests/ui/seek_to_start_instead_of_rewind.rs index 7b72efb34ff8..e824a9b1ec31 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.rs +++ b/tests/ui/seek_to_start_instead_of_rewind.rs @@ -50,11 +50,13 @@ fn seek_to_start_false_trait_bound(t: &mut T) { // This should trigger clippy warning fn seek_to_start(t: &mut T) { t.seek(SeekFrom::Start(0)); + //~^ seek_to_start_instead_of_rewind } // This should trigger clippy warning fn owned_seek_to_start(mut t: T) { t.seek(SeekFrom::Start(0)); + //~^ seek_to_start_instead_of_rewind } // This should NOT trigger clippy warning because @@ -134,6 +136,7 @@ fn msrv_1_55() { write!(f, "{hello}").unwrap(); f.seek(SeekFrom::Start(0)); + //~^ seek_to_start_instead_of_rewind let mut buf = String::new(); f.read_to_string(&mut buf).unwrap(); diff --git a/tests/ui/seek_to_start_instead_of_rewind.stderr b/tests/ui/seek_to_start_instead_of_rewind.stderr index 2c3c45820e10..6c6575cc02f5 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.stderr +++ b/tests/ui/seek_to_start_instead_of_rewind.stderr @@ -8,13 +8,13 @@ LL | t.seek(SeekFrom::Start(0)); = help: to override `-D warnings` add `#[allow(clippy::seek_to_start_instead_of_rewind)]` error: used `seek` to go to the start of the stream - --> tests/ui/seek_to_start_instead_of_rewind.rs:57:7 + --> tests/ui/seek_to_start_instead_of_rewind.rs:58:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` error: used `seek` to go to the start of the stream - --> tests/ui/seek_to_start_instead_of_rewind.rs:136:7 + --> tests/ui/seek_to_start_instead_of_rewind.rs:138:7 | LL | f.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index 213bca6c4515..a12a2829ba1a 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -11,30 +11,41 @@ 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` + //~^ self_assignment + + *b = *b; - //~^ ERROR: self-assignment of `*b` to `*b` + //~^ self_assignment + s = s; - //~^ ERROR: self-assignment of `s` to `s` + //~^ self_assignment + s.a = s.a; - //~^ ERROR: self-assignment of `s.a` to `s.a` + //~^ self_assignment + s.b[9] = s.b[5 + 4]; - //~^ ERROR: self-assignment of `s.b[5 + 4]` to `s.b[9]` + //~^ self_assignment + s.c[0][1] = s.c[0][1]; - //~^ ERROR: self-assignment of `s.c[0][1]` to `s.c[0][1]` + //~^ self_assignment + s.b[a] = s.b[a]; - //~^ ERROR: self-assignment of `s.b[a]` to `s.b[a]` + //~^ self_assignment + *s.e = *s.e; - //~^ ERROR: self-assignment of `*s.e` to `*s.e` + //~^ self_assignment + s.b[a + 10] = s.b[10 + a]; - //~^ ERROR: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` + //~^ self_assignment + let mut t = (0, 1); t.1 = t.1; - //~^ ERROR: self-assignment of `t.1` to `t.1` + //~^ self_assignment + t.0 = (t.0); - //~^ ERROR: self-assignment of `(t.0)` to `t.0` + //~^ self_assignment + } 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 e92414163d4c..02c5b4195e9c 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -8,61 +8,61 @@ LL | a = a; = help: to override `-D warnings` add `#[allow(clippy::self_assignment)]` error: self-assignment of `*b` to `*b` - --> tests/ui/self_assignment.rs:16:5 + --> tests/ui/self_assignment.rs:17:5 | LL | *b = *b; | ^^^^^^^ error: self-assignment of `s` to `s` - --> tests/ui/self_assignment.rs:18:5 + --> tests/ui/self_assignment.rs:20:5 | LL | s = s; | ^^^^^ error: self-assignment of `s.a` to `s.a` - --> tests/ui/self_assignment.rs:20:5 + --> tests/ui/self_assignment.rs:23:5 | LL | s.a = s.a; | ^^^^^^^^^ error: self-assignment of `s.b[5 + 4]` to `s.b[9]` - --> tests/ui/self_assignment.rs:22:5 + --> tests/ui/self_assignment.rs:26:5 | LL | s.b[9] = s.b[5 + 4]; | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> tests/ui/self_assignment.rs:24:5 + --> tests/ui/self_assignment.rs:29:5 | LL | s.c[0][1] = s.c[0][1]; | ^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.b[a]` to `s.b[a]` - --> tests/ui/self_assignment.rs:26:5 + --> tests/ui/self_assignment.rs:32:5 | LL | s.b[a] = s.b[a]; | ^^^^^^^^^^^^^^^ error: self-assignment of `*s.e` to `*s.e` - --> tests/ui/self_assignment.rs:28:5 + --> tests/ui/self_assignment.rs:35:5 | LL | *s.e = *s.e; | ^^^^^^^^^^^ error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> tests/ui/self_assignment.rs:30:5 + --> tests/ui/self_assignment.rs:38:5 | LL | s.b[a + 10] = s.b[10 + a]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `t.1` to `t.1` - --> tests/ui/self_assignment.rs:34:5 + --> tests/ui/self_assignment.rs:43:5 | LL | t.1 = t.1; | ^^^^^^^^^ error: self-assignment of `(t.0)` to `t.0` - --> tests/ui/self_assignment.rs:36:5 + --> tests/ui/self_assignment.rs:46:5 | LL | t.0 = (t.0); | ^^^^^^^^^^^ diff --git a/tests/ui/self_named_constructors.rs b/tests/ui/self_named_constructors.rs index dc326b399481..3dcd20b58c9d 100644 --- a/tests/ui/self_named_constructors.rs +++ b/tests/ui/self_named_constructors.rs @@ -5,8 +5,9 @@ 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` + //~^ self_named_constructors + + ShouldSpawn } diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index 1d8b44f6bc2b..54d7fb939796 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -2,9 +2,7 @@ error: constructor `should_spawn` has the same name as the type --> tests/ui/self_named_constructors.rs:7:5 | LL | / pub fn should_spawn() -> ShouldSpawn { -LL | | -LL | | -LL | | ShouldSpawn +... | LL | | } | |_____^ | diff --git a/tests/ui/semicolon_if_nothing_returned.fixed b/tests/ui/semicolon_if_nothing_returned.fixed index 6c8c835d0e0e..3de14e9d2595 100644 --- a/tests/ui/semicolon_if_nothing_returned.fixed +++ b/tests/ui/semicolon_if_nothing_returned.fixed @@ -16,21 +16,25 @@ fn get_unit() {} // the functions below trigger the lint fn main() { println!("Hello"); + //~^ semicolon_if_nothing_returned } fn hello() { get_unit(); + //~^ semicolon_if_nothing_returned } fn basic101(x: i32) { let y: i32; y = x + 1; + //~^ semicolon_if_nothing_returned } #[rustfmt::skip] fn closure_error() { let _d = || { hello(); + //~^ semicolon_if_nothing_returned }; } @@ -42,6 +46,7 @@ fn unsafe_checks_error() { let mut s = MaybeUninit::::uninit(); let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()); + //~^ semicolon_if_nothing_returned }; } diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 2c2e4c024190..304f43fb457c 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -16,21 +16,25 @@ fn get_unit() {} // the functions below trigger the lint fn main() { println!("Hello") + //~^ semicolon_if_nothing_returned } fn hello() { get_unit() + //~^ semicolon_if_nothing_returned } fn basic101(x: i32) { let y: i32; y = x + 1 + //~^ semicolon_if_nothing_returned } #[rustfmt::skip] fn closure_error() { let _d = || { hello() + //~^ semicolon_if_nothing_returned }; } @@ -42,6 +46,7 @@ fn unsafe_checks_error() { let mut s = MaybeUninit::::uninit(); let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) + //~^ semicolon_if_nothing_returned }; } diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 69e434b142cf..d7d117e05bdf 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -8,25 +8,25 @@ LL | println!("Hello") = help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:22:5 + --> tests/ui/semicolon_if_nothing_returned.rs:23:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:27:5 + --> tests/ui/semicolon_if_nothing_returned.rs:29:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:33:9 + --> tests/ui/semicolon_if_nothing_returned.rs:36:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:44:9 + --> tests/ui/semicolon_if_nothing_returned.rs:48: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 21681e71589e..7eb53e733ad5 100644 --- a/tests/ui/semicolon_inside_block.fixed +++ b/tests/ui/semicolon_inside_block.fixed @@ -36,7 +36,9 @@ fn main() { } { unit_fn_block(); } + //~^ semicolon_inside_block unsafe { unit_fn_block(); } + //~^ semicolon_inside_block { unit_fn_block(); } unsafe { unit_fn_block(); } @@ -45,6 +47,7 @@ fn main() { unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block(); } @@ -58,6 +61,7 @@ fn main() { }; { m!(()); } + //~^ semicolon_inside_block { m!(()); } { m!(()); }; m!(0); diff --git a/tests/ui/semicolon_inside_block.rs b/tests/ui/semicolon_inside_block.rs index 3a81661cd16f..9fa5b117194d 100644 --- a/tests/ui/semicolon_inside_block.rs +++ b/tests/ui/semicolon_inside_block.rs @@ -36,7 +36,9 @@ fn main() { } { unit_fn_block() }; + //~^ semicolon_inside_block unsafe { unit_fn_block() }; + //~^ semicolon_inside_block { unit_fn_block(); } unsafe { unit_fn_block(); } @@ -45,6 +47,7 @@ fn main() { unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block() }; @@ -58,6 +61,7 @@ fn main() { }; { m!(()) }; + //~^ semicolon_inside_block { m!(()); } { m!(()); }; m!(0); diff --git a/tests/ui/semicolon_inside_block.stderr b/tests/ui/semicolon_inside_block.stderr index d32fb681d3b9..23433f4e7ef9 100644 --- a/tests/ui/semicolon_inside_block.stderr +++ b/tests/ui/semicolon_inside_block.stderr @@ -13,7 +13,7 @@ LL + { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:39:5 + --> tests/ui/semicolon_inside_block.rs:40:5 | LL | unsafe { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,9 +25,10 @@ LL + unsafe { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:47:5 + --> tests/ui/semicolon_inside_block.rs:49:5 | LL | / { +LL | | LL | | unit_fn_block(); LL | | unit_fn_block() LL | | }; @@ -40,7 +41,7 @@ LL ~ } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:60:5 + --> tests/ui/semicolon_inside_block.rs:63:5 | LL | { m!(()) }; | ^^^^^^^^^^^ diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index ac7e86631cae..52fae9a3aff1 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -39,7 +39,9 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block() }; + //~^ semicolon_outside_block unsafe { unit_fn_block() }; + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -49,6 +51,7 @@ fn main() { unit_fn_block() }; { + //~^ semicolon_outside_block unit_fn_block(); unit_fn_block() }; @@ -59,6 +62,7 @@ fn main() { { m!(()) }; { m!(()) }; + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); @@ -81,10 +85,12 @@ fn main() { { unit_fn_block(); }; unsafe { + //~^ semicolon_outside_block std::arch::asm!("") }; { + //~^ semicolon_outside_block line!() }; diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index 68f25339e322..5975e66fbb81 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -39,7 +39,9 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block(); } + //~^ semicolon_outside_block unsafe { unit_fn_block(); } + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -49,6 +51,7 @@ fn main() { unit_fn_block() }; { + //~^ semicolon_outside_block unit_fn_block(); unit_fn_block(); } @@ -59,6 +62,7 @@ fn main() { { m!(()) }; { m!(()); } + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); @@ -81,10 +85,12 @@ fn main() { { unit_fn_block(); }; unsafe { + //~^ semicolon_outside_block std::arch::asm!(""); } { + //~^ semicolon_outside_block line!(); } diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index ff8c00048f63..18d6dc697f2e 100644 --- a/tests/ui/semicolon_outside_block.stderr +++ b/tests/ui/semicolon_outside_block.stderr @@ -13,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:42:5 + --> tests/ui/semicolon_outside_block.rs:43:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,9 +25,10 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:51:5 + --> tests/ui/semicolon_outside_block.rs:53:5 | LL | / { +LL | | LL | | unit_fn_block(); LL | | unit_fn_block(); LL | | } @@ -40,7 +41,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:61:5 + --> tests/ui/semicolon_outside_block.rs:64:5 | LL | { m!(()); } | ^^^^^^^^^^^ @@ -52,9 +53,10 @@ LL + { m!(()) }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:83:5 + --> tests/ui/semicolon_outside_block.rs:87:5 | LL | / unsafe { +LL | | LL | | std::arch::asm!(""); LL | | } | |_____^ @@ -66,9 +68,10 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:87:5 + --> tests/ui/semicolon_outside_block.rs:92:5 | LL | / { +LL | | LL | | line!(); LL | | } | |_____^ diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index af8b10f3e6ae..8ab1144e5700 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -37,8 +37,7 @@ 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` + //~^ serde_api_misuse where E: serde::de::Error, { diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index f71d41d58aae..eb6b7c6b0c36 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -3,9 +3,9 @@ error: you should not implement `visit_string` without also implementing `visit_ | 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/set_contains_or_insert.rs b/tests/ui/set_contains_or_insert.rs index d3a3e1c878b3..0e54afe91a80 100644 --- a/tests/ui/set_contains_or_insert.rs +++ b/tests/ui/set_contains_or_insert.rs @@ -10,35 +10,42 @@ fn should_warn_hashset() { let value = 5; if !set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if !set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); } if !!set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if (&set).contains(&value) { + //~^ set_contains_or_insert set.insert(value); } let borrow_value = &6; if !set.contains(borrow_value) { + //~^ set_contains_or_insert set.insert(*borrow_value); } let borrow_set = &mut set; if !borrow_set.contains(&value) { + //~^ set_contains_or_insert borrow_set.insert(value); } } @@ -77,35 +84,42 @@ fn should_warn_btreeset() { let value = 5; if !set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if !set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); } if !!set.contains(&value) { + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if (&set).contains(&value) { + //~^ set_contains_or_insert set.insert(value); } let borrow_value = &6; if !set.contains(borrow_value) { + //~^ set_contains_or_insert set.insert(*borrow_value); } let borrow_set = &mut set; if !borrow_set.contains(&value) { + //~^ set_contains_or_insert borrow_set.insert(value); } } diff --git a/tests/ui/set_contains_or_insert.stderr b/tests/ui/set_contains_or_insert.stderr index 14ad63005448..3152b1136458 100644 --- a/tests/ui/set_contains_or_insert.stderr +++ b/tests/ui/set_contains_or_insert.stderr @@ -3,6 +3,7 @@ error: usage of `HashSet::insert` after `HashSet::contains` | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ | @@ -10,106 +11,119 @@ LL | set.insert(value); = help: to override `-D warnings` add `#[allow(clippy::set_contains_or_insert)]` error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:17:12 + --> tests/ui/set_contains_or_insert.rs:18:12 | LL | if set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:22:13 + --> tests/ui/set_contains_or_insert.rs:24:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:26:14 + --> tests/ui/set_contains_or_insert.rs:29:14 | LL | if !!set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:31:15 + --> tests/ui/set_contains_or_insert.rs:35:15 | LL | if (&set).contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:36:13 + --> tests/ui/set_contains_or_insert.rs:41:13 | LL | if !set.contains(borrow_value) { | ^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | set.insert(*borrow_value); | ^^^^^^^^^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:41:20 + --> tests/ui/set_contains_or_insert.rs:47:20 | LL | if !borrow_set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | borrow_set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:79:13 + --> tests/ui/set_contains_or_insert.rs:86:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:84:12 + --> tests/ui/set_contains_or_insert.rs:92:12 | LL | if set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:89:13 + --> tests/ui/set_contains_or_insert.rs:98:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:93:14 + --> tests/ui/set_contains_or_insert.rs:103:14 | LL | if !!set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:98:15 + --> tests/ui/set_contains_or_insert.rs:109:15 | LL | if (&set).contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:103:13 + --> tests/ui/set_contains_or_insert.rs:115:13 | LL | if !set.contains(borrow_value) { | ^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | set.insert(*borrow_value); | ^^^^^^^^^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:108:20 + --> tests/ui/set_contains_or_insert.rs:121:20 | LL | if !borrow_set.contains(&value) { | ^^^^^^^^^^^^^^^^ +LL | LL | borrow_set.insert(value); | ^^^^^^^^^^^^^ diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index 31944f5ef1b1..b44705dfc7d6 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -22,22 +22,34 @@ macro_rules! reuse { fn shadow_same() { let x = 1; let x = x; + //~^ shadow_same let mut x = &x; + //~^ shadow_same let x = &mut x; + //~^ shadow_same let x = *x; + //~^ shadow_same } fn shadow_reuse() -> Option<()> { let x = ([[0]], ()); let x = x.0; + //~^ shadow_reuse let x = x[0]; + //~^ shadow_reuse let [x] = x; + //~^ shadow_reuse let x = Some(x); + //~^ shadow_reuse let x = foo(x); + //~^ shadow_reuse let x = || x; + //~^ shadow_reuse let x = Some(1).map(|_| x)?; + //~^ shadow_reuse let y = 1; let y = match y { + //~^ shadow_reuse 1 => 2, _ => 3, }; @@ -53,27 +65,36 @@ fn shadow_reuse_macro() { fn shadow_unrelated() { let x = 1; let x = 2; + //~^ shadow_unrelated } fn syntax() { fn f(x: u32) { let x = 1; + //~^ shadow_unrelated } let x = 1; match Some(1) { Some(1) => {}, Some(x) => { + //~^ shadow_unrelated let x = 1; + //~^ shadow_unrelated }, _ => {}, } if let Some(x) = Some(1) {} + //~^ shadow_unrelated while let Some(x) = Some(1) {} + //~^ shadow_unrelated let _ = |[x]: [u32; 1]| { + //~^ shadow_unrelated let x = 1; + //~^ shadow_unrelated }; let y = Some(1); if let Some(y) = y {} + //~^ shadow_reuse } fn negative() { @@ -110,12 +131,14 @@ pub async fn foo1(_a: i32) {} pub async fn foo2(_a: i32, _b: i64) { let _b = _a; + //~^ shadow_unrelated } fn ice_8748() { let _ = [0; { let x = 1; if let Some(x) = Some(1) { x } else { 1 } + //~^ shadow_unrelated }]; } @@ -126,10 +149,12 @@ fn shadow_closure() { #[allow(clippy::shadow_reuse)] let y = x.map(|x| x + 1); let z = x.map(|x| x + 1); + //~^ shadow_reuse let a: Vec> = [100u8, 120, 140] .iter() .map(|i| i.checked_mul(2)) .map(|i| i.map(|i| i - 10)) + //~^ shadow_reuse .collect(); } @@ -139,6 +164,7 @@ struct Issue13795 { fn issue13795(value: Issue13795) { let Issue13795 { value, .. } = value; + //~^ shadow_same } fn main() {} diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index c8c524b3a2f5..649f843575a7 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -13,7 +13,7 @@ LL | let x = 1; = help: to override `-D warnings` add `#[allow(clippy::shadow_same)]` error: `mut x` is shadowed by itself in `&x` - --> tests/ui/shadow.rs:25:13 + --> tests/ui/shadow.rs:26:13 | LL | let mut x = &x; | ^ @@ -25,37 +25,37 @@ LL | let x = x; | ^ error: `x` is shadowed by itself in `&mut x` - --> tests/ui/shadow.rs:26:9 + --> tests/ui/shadow.rs:28:9 | LL | let x = &mut x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:25:9 + --> tests/ui/shadow.rs:26:9 | LL | let mut x = &x; | ^^^^^ error: `x` is shadowed by itself in `*x` - --> tests/ui/shadow.rs:27:9 + --> tests/ui/shadow.rs:30:9 | LL | let x = *x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:26:9 + --> tests/ui/shadow.rs:28:9 | LL | let x = &mut x; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:32:9 + --> tests/ui/shadow.rs:36:9 | LL | let x = x.0; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:31:9 + --> tests/ui/shadow.rs:35:9 | LL | let x = ([[0]], ()); | ^ @@ -63,175 +63,103 @@ LL | let x = ([[0]], ()); = help: to override `-D warnings` add `#[allow(clippy::shadow_reuse)]` error: `x` is shadowed - --> tests/ui/shadow.rs:33:9 + --> tests/ui/shadow.rs:38:9 | LL | let x = x[0]; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:32:9 + --> tests/ui/shadow.rs:36:9 | LL | let x = x.0; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:34:10 + --> tests/ui/shadow.rs:40:10 | LL | let [x] = x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:33:9 + --> tests/ui/shadow.rs:38:9 | LL | let x = x[0]; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:35:9 + --> tests/ui/shadow.rs:42:9 | LL | let x = Some(x); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:34:10 + --> tests/ui/shadow.rs:40:10 | LL | let [x] = x; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:36:9 + --> tests/ui/shadow.rs:44:9 | LL | let x = foo(x); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:35:9 + --> tests/ui/shadow.rs:42:9 | LL | let x = Some(x); | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:37:9 + --> tests/ui/shadow.rs:46:9 | LL | let x = || x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:36:9 + --> tests/ui/shadow.rs:44:9 | LL | let x = foo(x); | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:38:9 + --> tests/ui/shadow.rs:48:9 | LL | let x = Some(1).map(|_| x)?; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:37:9 + --> tests/ui/shadow.rs:46:9 | LL | let x = || x; | ^ error: `y` is shadowed - --> tests/ui/shadow.rs:40:9 + --> tests/ui/shadow.rs:51:9 | LL | let y = match y { | ^ | note: previous binding is here - --> tests/ui/shadow.rs:39:9 + --> tests/ui/shadow.rs:50:9 | LL | let y = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:55:9 + --> tests/ui/shadow.rs:67:9 | LL | let x = 2; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:54:9 + --> tests/ui/shadow.rs:66:9 | LL | let x = 1; | ^ = note: `-D clippy::shadow-unrelated` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::shadow_unrelated)]` -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:60:13 - | -LL | let x = 1; - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:59:10 - | -LL | fn f(x: u32) { - | ^ - -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:65:14 - | -LL | Some(x) => { - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:62:9 - | -LL | let x = 1; - | ^ - -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:66:17 - | -LL | let x = 1; - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:65:14 - | -LL | Some(x) => { - | ^ - -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:70:17 - | -LL | if let Some(x) = Some(1) {} - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:62:9 - | -LL | let x = 1; - | ^ - -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:71:20 - | -LL | while let Some(x) = Some(1) {} - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:62:9 - | -LL | let x = 1; - | ^ - -error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:72:15 - | -LL | let _ = |[x]: [u32; 1]| { - | ^ - | -note: previous binding is here - --> tests/ui/shadow.rs:62:9 - | -LL | let x = 1; - | ^ - error: `x` shadows a previous, unrelated binding --> tests/ui/shadow.rs:73:13 | @@ -239,79 +167,151 @@ LL | let x = 1; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:72:15 + --> tests/ui/shadow.rs:72:10 + | +LL | fn f(x: u32) { + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:79:14 + | +LL | Some(x) => { + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:76:9 + | +LL | let x = 1; + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:81:17 + | +LL | let x = 1; + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:79:14 + | +LL | Some(x) => { + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:86:17 + | +LL | if let Some(x) = Some(1) {} + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:76:9 + | +LL | let x = 1; + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:88:20 + | +LL | while let Some(x) = Some(1) {} + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:76:9 + | +LL | let x = 1; + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:90:15 + | +LL | let _ = |[x]: [u32; 1]| { + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:76:9 + | +LL | let x = 1; + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:92:13 + | +LL | let x = 1; + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:90:15 | LL | let _ = |[x]: [u32; 1]| { | ^ error: `y` is shadowed - --> tests/ui/shadow.rs:76:17 + --> tests/ui/shadow.rs:96:17 | LL | if let Some(y) = y {} | ^ | note: previous binding is here - --> tests/ui/shadow.rs:75:9 + --> tests/ui/shadow.rs:95:9 | LL | let y = Some(1); | ^ error: `_b` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:112:9 + --> tests/ui/shadow.rs:133:9 | LL | let _b = _a; | ^^ | note: previous binding is here - --> tests/ui/shadow.rs:111:28 + --> tests/ui/shadow.rs:132:28 | LL | pub async fn foo2(_a: i32, _b: i64) { | ^^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:118:21 + --> tests/ui/shadow.rs:140:21 | LL | if let Some(x) = Some(1) { x } else { 1 } | ^ | note: previous binding is here - --> tests/ui/shadow.rs:117:13 + --> tests/ui/shadow.rs:139:13 | LL | let x = 1; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:128:20 + --> tests/ui/shadow.rs:151:20 | LL | let z = x.map(|x| x + 1); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:125:9 + --> tests/ui/shadow.rs:148:9 | LL | let x = Some(1); | ^ error: `i` is shadowed - --> tests/ui/shadow.rs:132:25 + --> tests/ui/shadow.rs:156:25 | LL | .map(|i| i.map(|i| i - 10)) | ^ | note: previous binding is here - --> tests/ui/shadow.rs:132:15 + --> tests/ui/shadow.rs:156:15 | LL | .map(|i| i.map(|i| i - 10)) | ^ error: `value` is shadowed by itself in `value` - --> tests/ui/shadow.rs:141:22 + --> tests/ui/shadow.rs:166:22 | LL | let Issue13795 { value, .. } = value; | ^^^^^ | note: previous binding is here - --> tests/ui/shadow.rs:140:15 + --> tests/ui/shadow.rs:165:15 | LL | fn issue13795(value: Issue13795) { | ^^^^^ diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed index a2bf07ac6052..672f692db51e 100644 --- a/tests/ui/short_circuit_statement.fixed +++ b/tests/ui/short_circuit_statement.fixed @@ -3,15 +3,20 @@ fn main() { if f() { g(); } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + if !f() { g(); } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + if 1 != 2 { g(); } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + if f() || g() { H * 2; } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + if !(f() || g()) { H * 2; } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + macro_rules! mac { ($f:ident or $g:ident) => { @@ -26,9 +31,11 @@ fn main() { } if mac!() { mac!(); } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + if !mac!() { mac!(); } - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + // Do not lint if the expression comes from a macro mac!(); diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index bdba546ad8f6..ca8913c8e637 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -3,15 +3,20 @@ fn main() { f() && g(); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + f() || g(); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + 1 == 2 || g(); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + (f() || g()) && (H * 2); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + (f() || g()) || (H * 2); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + macro_rules! mac { ($f:ident or $g:ident) => { @@ -26,9 +31,11 @@ fn main() { } mac!() && mac!(); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + mac!() || mac!(); - //~^ ERROR: boolean short circuit operator in statement + //~^ short_circuit_statement + // Do not lint if the expression comes from a macro mac!(); diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index ecf6676405b4..f69f411b4885 100644 --- a/tests/ui/short_circuit_statement.stderr +++ b/tests/ui/short_circuit_statement.stderr @@ -8,37 +8,37 @@ LL | f() && g(); = help: to override `-D warnings` add `#[allow(clippy::short_circuit_statement)]` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:7:5 + --> tests/ui/short_circuit_statement.rs:8:5 | LL | f() || g(); | ^^^^^^^^^^^ help: replace it with: `if !f() { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:9:5 + --> tests/ui/short_circuit_statement.rs:11:5 | LL | 1 == 2 || g(); | ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:11:5 + --> tests/ui/short_circuit_statement.rs:14:5 | LL | (f() || g()) && (H * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `if f() || g() { H * 2; }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:13:5 + --> tests/ui/short_circuit_statement.rs:17:5 | LL | (f() || g()) || (H * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `if !(f() || g()) { H * 2; }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:28:5 + --> tests/ui/short_circuit_statement.rs:33:5 | LL | mac!() && mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if mac!() { mac!(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:30:5 + --> tests/ui/short_circuit_statement.rs:36:5 | LL | mac!() || mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if !mac!() { mac!(); }` diff --git a/tests/ui/should_impl_trait/corner_cases.rs b/tests/ui/should_impl_trait/corner_cases.rs index 50999c6f2198..4ec0f02d6645 100644 --- a/tests/ui/should_impl_trait/corner_cases.rs +++ b/tests/ui/should_impl_trait/corner_cases.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::all, clippy::pedantic)] #![allow( clippy::missing_errors_doc, diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs index 85eed3f06f64..664d8aab7568 100644 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ b/tests/ui/should_impl_trait/method_list_1.rs @@ -23,77 +23,92 @@ 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: + //~^ should_implement_trait + unimplemented!() } pub fn as_mut(&mut self) -> &mut T { - //~^ ERROR: method `as_mut` can be confused for the standard trait method `std::conver + //~^ should_implement_trait + unimplemented!() } pub fn as_ref(&self) -> &T { - //~^ ERROR: method `as_ref` can be confused for the standard trait method `std::conver + //~^ should_implement_trait + unimplemented!() } pub fn bitand(self, rhs: T) -> T { - //~^ ERROR: method `bitand` can be confused for the standard trait method `std::ops::B + //~^ should_implement_trait + unimplemented!() } pub fn bitor(self, rhs: Self) -> Self { - //~^ ERROR: method `bitor` can be confused for the standard trait method `std::ops::Bi + //~^ should_implement_trait + unimplemented!() } pub fn bitxor(self, rhs: Self) -> Self { - //~^ ERROR: method `bitxor` can be confused for the standard trait method `std::ops::B + //~^ should_implement_trait + unimplemented!() } pub fn borrow(&self) -> &str { - //~^ ERROR: method `borrow` can be confused for the standard trait method `std::borrow + //~^ should_implement_trait + unimplemented!() } pub fn borrow_mut(&mut self) -> &mut str { - //~^ ERROR: method `borrow_mut` can be confused for the standard trait method `std::bo + //~^ should_implement_trait + unimplemented!() } pub fn clone(&self) -> Self { - //~^ ERROR: method `clone` can be confused for the standard trait method `std::clone:: + //~^ should_implement_trait + unimplemented!() } pub fn cmp(&self, other: &Self) -> Self { - //~^ ERROR: method `cmp` can be confused for the standard trait method `std::cmp::Ord: + //~^ should_implement_trait + unimplemented!() } pub fn default() -> Self { - //~^ ERROR: method `default` can be confused for the standard trait method `std::defau + //~^ should_implement_trait + unimplemented!() } pub fn deref(&self) -> &Self { - //~^ ERROR: method `deref` can be confused for the standard trait method `std::ops::De + //~^ should_implement_trait + unimplemented!() } pub fn deref_mut(&mut self) -> &mut Self { - //~^ ERROR: method `deref_mut` can be confused for the standard trait method `std::ops + //~^ should_implement_trait + unimplemented!() } pub fn div(self, rhs: Self) -> Self { - //~^ ERROR: method `div` can be confused for the standard trait method `std::ops::Div: + //~^ should_implement_trait + unimplemented!() } pub fn drop(&mut self) { - //~^ ERROR: method `drop` can be confused for the standard trait method `std::ops::Dro + //~^ should_implement_trait + unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr index dfa55ace40f0..8738b61192a3 100644 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ b/tests/ui/should_impl_trait/method_list_1.stderr @@ -3,6 +3,7 @@ error: method `add` can be confused for the standard trait method `std::ops::Add | LL | / pub fn add(self, other: T) -> T { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -12,10 +13,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:30:5 + --> tests/ui/should_impl_trait/method_list_1.rs:31:5 | LL | / pub fn as_mut(&mut self) -> &mut T { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -23,10 +25,11 @@ LL | | } = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> tests/ui/should_impl_trait/method_list_1.rs:35:5 + --> tests/ui/should_impl_trait/method_list_1.rs:37:5 | LL | / pub fn as_ref(&self) -> &T { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -34,10 +37,11 @@ LL | | } = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> tests/ui/should_impl_trait/method_list_1.rs:40:5 + --> tests/ui/should_impl_trait/method_list_1.rs:43:5 | LL | / pub fn bitand(self, rhs: T) -> T { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -45,10 +49,11 @@ LL | | } = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> tests/ui/should_impl_trait/method_list_1.rs:45:5 + --> tests/ui/should_impl_trait/method_list_1.rs:49:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -56,10 +61,11 @@ LL | | } = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> tests/ui/should_impl_trait/method_list_1.rs:50:5 + --> tests/ui/should_impl_trait/method_list_1.rs:55:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -67,10 +73,11 @@ LL | | } = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> tests/ui/should_impl_trait/method_list_1.rs:55:5 + --> tests/ui/should_impl_trait/method_list_1.rs:61:5 | LL | / pub fn borrow(&self) -> &str { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -78,10 +85,11 @@ LL | | } = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:60:5 + --> tests/ui/should_impl_trait/method_list_1.rs:67:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -89,10 +97,11 @@ LL | | } = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> tests/ui/should_impl_trait/method_list_1.rs:65:5 + --> tests/ui/should_impl_trait/method_list_1.rs:73:5 | LL | / pub fn clone(&self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,10 +109,11 @@ LL | | } = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> tests/ui/should_impl_trait/method_list_1.rs:70:5 + --> tests/ui/should_impl_trait/method_list_1.rs:79:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -111,10 +121,11 @@ LL | | } = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name error: method `default` can be confused for the standard trait method `std::default::Default::default` - --> tests/ui/should_impl_trait/method_list_1.rs:75:5 + --> tests/ui/should_impl_trait/method_list_1.rs:85:5 | LL | / pub fn default() -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -122,10 +133,11 @@ LL | | } = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> tests/ui/should_impl_trait/method_list_1.rs:80:5 + --> tests/ui/should_impl_trait/method_list_1.rs:91:5 | LL | / pub fn deref(&self) -> &Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -133,10 +145,11 @@ LL | | } = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:85:5 + --> tests/ui/should_impl_trait/method_list_1.rs:97:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -144,10 +157,11 @@ LL | | } = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> tests/ui/should_impl_trait/method_list_1.rs:90:5 + --> tests/ui/should_impl_trait/method_list_1.rs:103:5 | LL | / pub fn div(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -155,10 +169,11 @@ LL | | } = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> tests/ui/should_impl_trait/method_list_1.rs:95:5 + --> tests/ui/should_impl_trait/method_list_1.rs:109:5 | LL | / pub fn drop(&mut self) { LL | | +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 33211b32d74b..29b96c33ce9c 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -24,77 +24,92 @@ impl T { // ***************************************** pub fn eq(&self, other: &Self) -> bool { - //~^ ERROR: method `eq` can be confused for the standard trait method `std::cmp::Parti + //~^ should_implement_trait + unimplemented!() } pub fn from_iter(iter: T) -> Self { - //~^ ERROR: method `from_iter` can be confused for the standard trait method `std::ite + //~^ should_implement_trait + unimplemented!() } pub fn from_str(s: &str) -> Result { - //~^ ERROR: method `from_str` can be confused for the standard trait method `std::str: + //~^ should_implement_trait + unimplemented!() } pub fn hash(&self, state: &mut T) { - //~^ ERROR: method `hash` can be confused for the standard trait method `std::hash::Ha + //~^ should_implement_trait + unimplemented!() } pub fn index(&self, index: usize) -> &Self { - //~^ ERROR: method `index` can be confused for the standard trait method `std::ops::In + //~^ should_implement_trait + 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 + //~^ should_implement_trait + unimplemented!() } pub fn into_iter(self) -> Self { - //~^ ERROR: method `into_iter` can be confused for the standard trait method `std::ite + //~^ should_implement_trait + unimplemented!() } pub fn mul(self, rhs: Self) -> Self { - //~^ ERROR: method `mul` can be confused for the standard trait method `std::ops::Mul: + //~^ should_implement_trait + unimplemented!() } pub fn neg(self) -> Self { - //~^ ERROR: method `neg` can be confused for the standard trait method `std::ops::Neg: + //~^ should_implement_trait + unimplemented!() } pub fn next(&mut self) -> Option { - //~^ ERROR: method `next` can be confused for the standard trait method `std::iter::It + //~^ should_implement_trait + unimplemented!() } pub fn not(self) -> Self { - //~^ ERROR: method `not` can be confused for the standard trait method `std::ops::Not: + //~^ should_implement_trait + unimplemented!() } pub fn rem(self, rhs: Self) -> Self { - //~^ ERROR: method `rem` can be confused for the standard trait method `std::ops::Rem: + //~^ should_implement_trait + unimplemented!() } pub fn shl(self, rhs: Self) -> Self { - //~^ ERROR: method `shl` can be confused for the standard trait method `std::ops::Shl: + //~^ should_implement_trait + unimplemented!() } pub fn shr(self, rhs: Self) -> Self { - //~^ ERROR: method `shr` can be confused for the standard trait method `std::ops::Shr: + //~^ should_implement_trait + unimplemented!() } pub fn sub(self, rhs: Self) -> Self { - //~^ ERROR: method `sub` can be confused for the standard trait method `std::ops::Sub: + //~^ should_implement_trait + unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr index b1e5bbbfa4c5..85de74337020 100644 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ b/tests/ui/should_impl_trait/method_list_2.stderr @@ -3,6 +3,7 @@ error: method `eq` can be confused for the standard trait method `std::cmp::Part | LL | / pub fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -12,10 +13,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> tests/ui/should_impl_trait/method_list_2.rs:31:5 + --> tests/ui/should_impl_trait/method_list_2.rs:32:5 | LL | / pub fn from_iter(iter: T) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -23,10 +25,11 @@ LL | | } = help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> tests/ui/should_impl_trait/method_list_2.rs:36:5 + --> tests/ui/should_impl_trait/method_list_2.rs:38:5 | LL | / pub fn from_str(s: &str) -> Result { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -34,10 +37,11 @@ LL | | } = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> tests/ui/should_impl_trait/method_list_2.rs:41:5 + --> tests/ui/should_impl_trait/method_list_2.rs:44:5 | LL | / pub fn hash(&self, state: &mut T) { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -45,10 +49,11 @@ LL | | } = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> tests/ui/should_impl_trait/method_list_2.rs:46:5 + --> tests/ui/should_impl_trait/method_list_2.rs:50:5 | LL | / pub fn index(&self, index: usize) -> &Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -56,10 +61,11 @@ LL | | } = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> tests/ui/should_impl_trait/method_list_2.rs:51:5 + --> tests/ui/should_impl_trait/method_list_2.rs:56:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -67,10 +73,11 @@ LL | | } = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> tests/ui/should_impl_trait/method_list_2.rs:56:5 + --> tests/ui/should_impl_trait/method_list_2.rs:62:5 | LL | / pub fn into_iter(self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -78,10 +85,11 @@ LL | | } = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> tests/ui/should_impl_trait/method_list_2.rs:61:5 + --> tests/ui/should_impl_trait/method_list_2.rs:68:5 | LL | / pub fn mul(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -89,10 +97,11 @@ LL | | } = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> tests/ui/should_impl_trait/method_list_2.rs:66:5 + --> tests/ui/should_impl_trait/method_list_2.rs:74:5 | LL | / pub fn neg(self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,10 +109,11 @@ LL | | } = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> tests/ui/should_impl_trait/method_list_2.rs:71:5 + --> tests/ui/should_impl_trait/method_list_2.rs:80:5 | LL | / pub fn next(&mut self) -> Option { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -111,10 +121,11 @@ LL | | } = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> tests/ui/should_impl_trait/method_list_2.rs:76:5 + --> tests/ui/should_impl_trait/method_list_2.rs:86:5 | LL | / pub fn not(self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -122,10 +133,11 @@ LL | | } = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> tests/ui/should_impl_trait/method_list_2.rs:81:5 + --> tests/ui/should_impl_trait/method_list_2.rs:92:5 | LL | / pub fn rem(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -133,10 +145,11 @@ LL | | } = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> tests/ui/should_impl_trait/method_list_2.rs:86:5 + --> tests/ui/should_impl_trait/method_list_2.rs:98:5 | LL | / pub fn shl(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -144,10 +157,11 @@ LL | | } = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> tests/ui/should_impl_trait/method_list_2.rs:91:5 + --> tests/ui/should_impl_trait/method_list_2.rs:104:5 | LL | / pub fn shr(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -155,10 +169,11 @@ LL | | } = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> tests/ui/should_impl_trait/method_list_2.rs:96:5 + --> tests/ui/should_impl_trait/method_list_2.rs:110:5 | LL | / pub fn sub(self, rhs: Self) -> Self { LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ diff --git a/tests/ui/should_panic_without_expect.rs b/tests/ui/should_panic_without_expect.rs index b554fdaf2249..a209f794b105 100644 --- a/tests/ui/should_panic_without_expect.rs +++ b/tests/ui/should_panic_without_expect.rs @@ -3,6 +3,7 @@ #[test] #[should_panic] +//~^ should_panic_without_expect fn no_message() {} #[test] diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 39d550398d70..db4f8867fa41 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -58,8 +58,7 @@ 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 + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().bar(); }, @@ -146,8 +145,7 @@ 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 + //~^ significant_drop_in_scrutinee 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -169,8 +167,7 @@ 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 + //~^ significant_drop_in_scrutinee 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -219,8 +216,7 @@ 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 + //~^ significant_drop_in_scrutinee 2 => { let current_count = counter.i.load(Ordering::Relaxed); println!("Current count {}", current_count); @@ -244,8 +240,7 @@ 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 + //~^ significant_drop_in_scrutinee (3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -255,8 +250,7 @@ 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 + //~^ significant_drop_in_scrutinee (_, 3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -267,10 +261,8 @@ 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 + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee (3, _, 3) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -322,8 +314,7 @@ 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 + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().s.len(); }, @@ -331,8 +322,7 @@ 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 + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().s.len(); }, @@ -351,8 +341,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 + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee true => { println!( "{} < {}", @@ -364,8 +354,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 + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee true => { println!( "{} >= {}", @@ -401,8 +391,7 @@ 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 + //~^ significant_drop_in_scrutinee true => { mutex1.lock().unwrap().s.len(); }, @@ -420,8 +409,7 @@ 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 + //~^ significant_drop_in_scrutinee 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap(), } @@ -448,8 +436,7 @@ 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 + //~^ significant_drop_in_scrutinee mutex1.lock().unwrap() } else { mutex2.lock().unwrap() @@ -504,8 +491,7 @@ 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 + //~^ significant_drop_in_scrutinee 0 | 1 => println!("Value was less than 2"), _ => println!("Value is {}", s.lock().deref()), }; @@ -554,32 +540,28 @@ 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 + //~^ significant_drop_in_scrutinee _ => { 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 + //~^ significant_drop_in_scrutinee _ => { 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 + //~^ significant_drop_in_scrutinee _ => { 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 + //~^ significant_drop_in_scrutinee _ => { println!("{}", mutex.lock().unwrap().i); }, @@ -643,8 +625,7 @@ 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 + //~^ significant_drop_in_scrutinee Ok(n) => println!("Converted to number: {}", n), Err(e) => println!("Could not convert {} to number", e), }; @@ -671,8 +652,7 @@ 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 + //~^ significant_drop_in_scrutinee true => do_bar(&mutex), false => {}, }; @@ -734,8 +714,7 @@ fn should_not_trigger_for_significant_drop_ref() { } match guard.take().len() { - //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the - //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~^ significant_drop_in_scrutinee 0 => println!("empty"), _ => println!("not empty"), }; @@ -760,8 +739,7 @@ fn should_trigger_lint_if_and_only_if_lifetime_is_irrelevant() { // Should trigger lint even if `copy_old_lifetime()` has a lifetime, as the lifetime of // `&vec` is unrelated to the temporary with significant drop (i.e., the `MutexGuard`). for val in mutex.lock().unwrap().copy_old_lifetime() { - //~^ ERROR: temporary with significant `Drop` in `for` loop condition will live until the - //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~^ significant_drop_in_scrutinee println!("{}", val); } @@ -800,8 +778,7 @@ fn should_not_trigger_lint_with_explicit_drop() { // Should trigger lint if there is no explicit drop. for val in [mutex.lock().unwrap()[0], 2] { - //~^ ERROR: temporary with significant `Drop` in `for` loop condition will live until the - //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~^ significant_drop_in_scrutinee println!("{:?}", val); } } @@ -810,8 +787,7 @@ fn should_trigger_lint_in_if_let() { let mutex = Mutex::new(vec![1]); if let Some(val) = mutex.lock().unwrap().first().copied() { - //~^ ERROR: temporary with significant `Drop` in `if let` scrutinee will live until the - //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~^ significant_drop_in_scrutinee println!("{}", val); } @@ -826,8 +802,7 @@ fn should_trigger_lint_in_while_let() { let mutex = Mutex::new(vec![1]); while let Some(val) = mutex.lock().unwrap().pop() { - //~^ ERROR: temporary with significant `Drop` in `while let` scrutinee will live until the - //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~^ significant_drop_in_scrutinee println!("{}", val); } } @@ -838,6 +813,7 @@ async fn foo_async(mutex: &Mutex) -> Option> { async fn should_trigger_lint_for_async(mutex: Mutex) -> i32 { match *foo_async(&mutex).await.unwrap() { + //~^ significant_drop_in_scrutinee n if n < 10 => n, _ => 10, } @@ -857,8 +833,7 @@ fn should_trigger_lint_in_match_expr() { // is preserved until the end of the match, but there is no clear indication that this is the // case. let _ = 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 + //~^ significant_drop_in_scrutinee true => 0, false => 1, }; diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index f99d862aa6b2..b32b249fd429 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -20,7 +20,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:148:11 + --> tests/ui/significant_drop_in_scrutinee.rs:147:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:171:11 + --> tests/ui/significant_drop_in_scrutinee.rs:169:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:221:11 + --> tests/ui/significant_drop_in_scrutinee.rs:218:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:246:16 + --> tests/ui/significant_drop_in_scrutinee.rs:242:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:257:22 + --> tests/ui/significant_drop_in_scrutinee.rs:252:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:269:16 + --> tests/ui/significant_drop_in_scrutinee.rs:263:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,7 +139,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:269:54 + --> tests/ui/significant_drop_in_scrutinee.rs:263:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:324:11 + --> tests/ui/significant_drop_in_scrutinee.rs:316:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:333:15 + --> tests/ui/significant_drop_in_scrutinee.rs:324:15 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -198,7 +198,7 @@ LL ~ match 1 < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:353:11 + --> tests/ui/significant_drop_in_scrutinee.rs:343:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,7 @@ LL ~ match value < mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:353:44 + --> tests/ui/significant_drop_in_scrutinee.rs:343:44 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL ~ match mutex1.lock().unwrap().s.len() < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:366:11 + --> tests/ui/significant_drop_in_scrutinee.rs:356:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL ~ match value >= mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:366:45 + --> tests/ui/significant_drop_in_scrutinee.rs:356:45 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -282,7 +282,7 @@ LL ~ match mutex1.lock().unwrap().s.len() >= value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:403:11 + --> tests/ui/significant_drop_in_scrutinee.rs:393:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,14 +301,14 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:422:11 + --> tests/ui/significant_drop_in_scrutinee.rs:411:11 | LL | match match i { | ___________^ LL | | -LL | | LL | | 100 => mutex1.lock().unwrap(), -... | +LL | | _ => mutex2.lock().unwrap(), +LL | | } LL | | .s LL | | .len() | |__________^ @@ -324,7 +324,6 @@ 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 + } @@ -334,13 +333,13 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:450:11 + --> tests/ui/significant_drop_in_scrutinee.rs:438:11 | LL | match if i > 1 { | ___________^ LL | | -LL | | LL | | mutex1.lock().unwrap() +LL | | } else { ... | LL | | .s LL | | .len() @@ -357,7 +356,6 @@ 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() @@ -368,7 +366,7 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:506:11 + --> tests/ui/significant_drop_in_scrutinee.rs:493:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -386,7 +384,7 @@ LL ~ match (&value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:556:11 + --> tests/ui/significant_drop_in_scrutinee.rs:542:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -405,7 +403,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:564:15 + --> tests/ui/significant_drop_in_scrutinee.rs:549:15 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -424,7 +422,7 @@ LL ~ match i = value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:572:11 + --> tests/ui/significant_drop_in_scrutinee.rs:556:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -443,7 +441,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:580:16 + --> tests/ui/significant_drop_in_scrutinee.rs:563:16 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -462,7 +460,7 @@ LL ~ match i += value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:645:11 + --> tests/ui/significant_drop_in_scrutinee.rs:627:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -478,7 +476,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:673:11 + --> tests/ui/significant_drop_in_scrutinee.rs:654:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -494,7 +492,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:736:11 + --> tests/ui/significant_drop_in_scrutinee.rs:716:11 | LL | match guard.take().len() { | ^^^^^^^^^^^^^^^^^^ @@ -510,7 +508,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:762:16 + --> tests/ui/significant_drop_in_scrutinee.rs:741:16 | LL | for val in mutex.lock().unwrap().copy_old_lifetime() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -526,7 +524,7 @@ LL ~ for val in value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:802:17 + --> tests/ui/significant_drop_in_scrutinee.rs:780:17 | LL | for val in [mutex.lock().unwrap()[0], 2] { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -542,7 +540,7 @@ LL ~ for val in [value, 2] { | error: temporary with significant `Drop` in `if let` scrutinee will live until the end of the `if let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:812:24 + --> tests/ui/significant_drop_in_scrutinee.rs:789:24 | LL | if let Some(val) = mutex.lock().unwrap().first().copied() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -558,7 +556,7 @@ LL ~ if let Some(val) = value { | error: temporary with significant `Drop` in `while let` scrutinee will live until the end of the `while let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:828:27 + --> tests/ui/significant_drop_in_scrutinee.rs:804:27 | LL | while let Some(val) = mutex.lock().unwrap().pop() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -569,7 +567,7 @@ LL | } = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:840:11 + --> tests/ui/significant_drop_in_scrutinee.rs:815:11 | LL | match *foo_async(&mutex).await.unwrap() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -585,7 +583,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:859:19 + --> tests/ui/significant_drop_in_scrutinee.rs:835:19 | LL | let _ = match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/significant_drop_tightening.fixed b/tests/ui/significant_drop_tightening.fixed index ed05f6e0c8d3..3d416056226c 100644 --- a/tests/ui/significant_drop_tightening.fixed +++ b/tests/ui/significant_drop_tightening.fixed @@ -8,6 +8,7 @@ pub fn complex_return_triggers_the_lint() -> i32 { } let mutex = Mutex::new(1); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let _ = *lock; let _ = *lock; drop(lock); @@ -103,6 +104,7 @@ pub fn unnecessary_contention_with_multiple_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); let rslt1 = lock.is_positive(); drop(lock); @@ -126,6 +128,7 @@ pub fn unnecessary_contention_with_single_owned_results() { let mutex = Mutex::new(1i32); let rslt0 = mutex.lock().unwrap().abs(); + //~^ significant_drop_tightening do_heavy_computation_that_takes_time(rslt0); } @@ -133,6 +136,7 @@ pub fn unnecessary_contention_with_single_owned_results() { let mutex = Mutex::new(vec![1i32]); mutex.lock().unwrap().clear(); + //~^ significant_drop_tightening do_heavy_computation_that_takes_time(()); } diff --git a/tests/ui/significant_drop_tightening.rs b/tests/ui/significant_drop_tightening.rs index e5f17278f0f6..d9c4ad543593 100644 --- a/tests/ui/significant_drop_tightening.rs +++ b/tests/ui/significant_drop_tightening.rs @@ -8,6 +8,7 @@ pub fn complex_return_triggers_the_lint() -> i32 { } let mutex = Mutex::new(1); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let _ = *lock; let _ = *lock; foo() @@ -102,6 +103,7 @@ pub fn unnecessary_contention_with_multiple_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); let rslt1 = lock.is_positive(); do_heavy_computation_that_takes_time((rslt0, rslt1)); @@ -123,12 +125,14 @@ pub fn unnecessary_contention_with_single_owned_results() { { let mutex = Mutex::new(1i32); let lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening let rslt0 = lock.abs(); do_heavy_computation_that_takes_time(rslt0); } { let mutex = Mutex::new(vec![1i32]); let mut lock = mutex.lock().unwrap(); + //~^ significant_drop_tightening lock.clear(); do_heavy_computation_that_takes_time(()); } diff --git a/tests/ui/significant_drop_tightening.stderr b/tests/ui/significant_drop_tightening.stderr index aef774a3d360..25cd9da73a10 100644 --- a/tests/ui/significant_drop_tightening.stderr +++ b/tests/ui/significant_drop_tightening.stderr @@ -23,14 +23,13 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:104:13 + --> tests/ui/significant_drop_tightening.rs:105:13 | LL | / { LL | | let mutex = Mutex::new(1i32); LL | | let lock = mutex.lock().unwrap(); | | ^^^^ -LL | | let rslt0 = lock.abs(); -LL | | let rslt1 = lock.is_positive(); +... | LL | | do_heavy_computation_that_takes_time((rslt0, rslt1)); LL | | } | |_____- temporary `lock` is currently being dropped at the end of its contained scope @@ -43,13 +42,13 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:125:13 + --> tests/ui/significant_drop_tightening.rs:127:13 | LL | / { LL | | let mutex = Mutex::new(1i32); LL | | let lock = mutex.lock().unwrap(); | | ^^^^ -LL | | let rslt0 = lock.abs(); +... | LL | | do_heavy_computation_that_takes_time(rslt0); LL | | } | |_____- temporary `lock` is currently being dropped at the end of its contained scope @@ -59,17 +58,18 @@ help: merge the temporary construction with its single usage | LL ~ LL + let rslt0 = mutex.lock().unwrap().abs(); +LL | LL ~ | error: temporary with significant `Drop` can be early dropped - --> tests/ui/significant_drop_tightening.rs:131:17 + --> tests/ui/significant_drop_tightening.rs:134:17 | LL | / { LL | | let mutex = Mutex::new(vec![1i32]); LL | | let mut lock = mutex.lock().unwrap(); | | ^^^^ -LL | | lock.clear(); +... | LL | | do_heavy_computation_that_takes_time(()); LL | | } | |_____- temporary `lock` is currently being dropped at the end of its contained scope @@ -79,6 +79,7 @@ help: merge the temporary construction with its single usage | LL ~ LL + mutex.lock().unwrap().clear(); +LL | LL ~ | diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index f09693344915..a6b20b94a4a7 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -45,12 +45,14 @@ fn main() { let blubx: i32; let bluby: i32; - //~^ ERROR: binding's name is too similar to existing binding + //~^ similar_names + let cake: i32; let cakes: i32; let coke: i32; - //~^ ERROR: binding's name is too similar to existing binding + //~^ similar_names + match 5 { cheese @ 1 => {}, @@ -69,12 +71,14 @@ fn main() { let xyz1abc: i32; let xyz2abc: i32; let xyzeabc: i32; - //~^ ERROR: binding's name is too similar to existing binding + //~^ similar_names + let parser: i32; let parsed: i32; let parsee: i32; - //~^ ERROR: binding's name is too similar to existing binding + //~^ similar_names + let setter: i32; let getter: i32; @@ -96,7 +100,8 @@ fn foo() { let Foo { apple: spring, bpple: sprang, - //~^ ERROR: binding's name is too similar to existing binding + //~^ similar_names + } = unimplemented!(); } diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 8d722fb8b564..36255f52e825 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -13,49 +13,49 @@ LL | let blubx: i32; = help: to override `-D warnings` add `#[allow(clippy::similar_names)]` error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:52:9 + --> tests/ui/similar_names.rs:53:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:50:9 + --> tests/ui/similar_names.rs:51:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:71:9 + --> tests/ui/similar_names.rs:73:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:69:9 + --> tests/ui/similar_names.rs:71:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:76:9 + --> tests/ui/similar_names.rs:79:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:74:9 + --> tests/ui/similar_names.rs:77:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:98:16 + --> tests/ui/similar_names.rs:102:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:97:16 + --> tests/ui/similar_names.rs:101:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index a0597664da55..0894509b73ea 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -11,7 +11,9 @@ extern crate proc_macros; pub fn f() {} fn i() {} +//~^ single_call_fn fn j() {} +//~^ single_call_fn fn h() { // Linted @@ -32,6 +34,7 @@ fn g() { } fn c() { +//~^ single_call_fn println!("really"); println!("long"); println!("function..."); @@ -42,6 +45,7 @@ fn d() { } fn a() {} +//~^ single_call_fn fn b() { a(); @@ -87,6 +91,7 @@ fn l() { trait Trait { fn default() {} + //~^ single_call_fn fn foo(&self); } extern "C" { @@ -100,6 +105,7 @@ fn m(v: T) { struct S; impl S { fn foo() {} + //~^ single_call_fn } T::default(); S::foo(); diff --git a/tests/ui/single_call_fn.stderr b/tests/ui/single_call_fn.stderr index 14529beac616..8dd90a123852 100644 --- a/tests/ui/single_call_fn.stderr +++ b/tests/ui/single_call_fn.stderr @@ -5,7 +5,7 @@ LL | fn i() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:18:13 + --> tests/ui/single_call_fn.rs:20:13 | LL | let a = i; | ^ @@ -13,21 +13,22 @@ LL | let a = i; = help: to override `-D warnings` add `#[allow(clippy::single_call_fn)]` error: this function is only used once - --> tests/ui/single_call_fn.rs:14:1 + --> tests/ui/single_call_fn.rs:15:1 | LL | fn j() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:25:9 + --> tests/ui/single_call_fn.rs:27:9 | LL | j(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:34:1 + --> tests/ui/single_call_fn.rs:36:1 | LL | / fn c() { +LL | | LL | | println!("really"); LL | | println!("long"); LL | | println!("function..."); @@ -35,43 +36,43 @@ LL | | } | |_^ | note: used here - --> tests/ui/single_call_fn.rs:41:5 + --> tests/ui/single_call_fn.rs:44:5 | LL | c(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:44:1 + --> tests/ui/single_call_fn.rs:47:1 | LL | fn a() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:47:5 + --> tests/ui/single_call_fn.rs:51:5 | LL | a(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:89:5 + --> tests/ui/single_call_fn.rs:93:5 | LL | fn default() {} | ^^^^^^^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:104:5 + --> tests/ui/single_call_fn.rs:110:5 | LL | T::default(); | ^^^^^^^^^^ error: this function is only used once - --> tests/ui/single_call_fn.rs:102:9 + --> tests/ui/single_call_fn.rs:107:9 | LL | fn foo() {} | ^^^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:105:5 + --> tests/ui/single_call_fn.rs:111:5 | LL | S::foo(); | ^^^^^^ diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed index aef15252b1bc..b729cf8b2ca1 100644 --- a/tests/ui/single_char_add_str.fixed +++ b/tests/ui/single_char_add_str.fixed @@ -12,44 +12,65 @@ fn main() { let mut string = String::new(); string.push('R'); + //~^ single_char_add_str string.push('\''); + //~^ single_char_add_str string.push('u'); string.push_str("st"); string.push_str(""); string.push('\x52'); + //~^ single_char_add_str string.push('\u{0052}'); + //~^ single_char_add_str string.push('a'); + //~^ single_char_add_str let c_ref = &'a'; string.push(*c_ref); + //~^ single_char_add_str let c = 'a'; string.push(c); + //~^ single_char_add_str string.push('a'); + //~^ single_char_add_str get_string!().push('ö'); + //~^ single_char_add_str // `insert_str` tests let mut string = String::new(); string.insert(0, 'R'); + //~^ single_char_add_str string.insert(1, '\''); + //~^ single_char_add_str string.insert(0, 'u'); string.insert_str(2, "st"); string.insert_str(0, ""); string.insert(0, '\x52'); + //~^ single_char_add_str string.insert(0, '\u{0052}'); + //~^ single_char_add_str let x: usize = 2; string.insert(x, 'a'); + //~^ single_char_add_str const Y: usize = 1; string.insert(Y, 'a'); + //~^ single_char_add_str string.insert(Y, '"'); + //~^ single_char_add_str string.insert(Y, '\''); + //~^ single_char_add_str string.insert(0, *c_ref); + //~^ single_char_add_str string.insert(0, c); + //~^ single_char_add_str string.insert(0, 'a'); + //~^ single_char_add_str get_string!().insert(1, '?'); + //~^ single_char_add_str } diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs index 7f97250dacd4..a768c47db391 100644 --- a/tests/ui/single_char_add_str.rs +++ b/tests/ui/single_char_add_str.rs @@ -12,44 +12,65 @@ fn main() { let mut string = String::new(); string.push_str("R"); + //~^ single_char_add_str string.push_str("'"); + //~^ single_char_add_str string.push('u'); string.push_str("st"); string.push_str(""); string.push_str("\x52"); + //~^ single_char_add_str string.push_str("\u{0052}"); + //~^ single_char_add_str string.push_str(r##"a"##); + //~^ single_char_add_str let c_ref = &'a'; string.push_str(&c_ref.to_string()); + //~^ single_char_add_str let c = 'a'; string.push_str(&c.to_string()); + //~^ single_char_add_str string.push_str(&'a'.to_string()); + //~^ single_char_add_str get_string!().push_str("ö"); + //~^ single_char_add_str // `insert_str` tests let mut string = String::new(); string.insert_str(0, "R"); + //~^ single_char_add_str string.insert_str(1, "'"); + //~^ single_char_add_str string.insert(0, 'u'); string.insert_str(2, "st"); string.insert_str(0, ""); string.insert_str(0, "\x52"); + //~^ single_char_add_str string.insert_str(0, "\u{0052}"); + //~^ single_char_add_str let x: usize = 2; string.insert_str(x, r##"a"##); + //~^ single_char_add_str const Y: usize = 1; string.insert_str(Y, r##"a"##); + //~^ single_char_add_str string.insert_str(Y, r##"""##); + //~^ single_char_add_str string.insert_str(Y, r##"'"##); + //~^ single_char_add_str string.insert_str(0, &c_ref.to_string()); + //~^ single_char_add_str string.insert_str(0, &c.to_string()); + //~^ single_char_add_str string.insert_str(0, &'a'.to_string()); + //~^ single_char_add_str get_string!().insert_str(1, "?"); + //~^ single_char_add_str } diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr index 7791c67578aa..a1fae93462c9 100644 --- a/tests/ui/single_char_add_str.stderr +++ b/tests/ui/single_char_add_str.stderr @@ -8,121 +8,121 @@ LL | string.push_str("R"); = help: to override `-D warnings` add `#[allow(clippy::single_char_add_str)]` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:15:5 + --> tests/ui/single_char_add_str.rs:16:5 | LL | string.push_str("'"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\'')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:20:5 + --> tests/ui/single_char_add_str.rs:22:5 | LL | string.push_str("\x52"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\x52')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:21:5 + --> tests/ui/single_char_add_str.rs:24:5 | LL | string.push_str("\u{0052}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\u{0052}')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:22:5 + --> tests/ui/single_char_add_str.rs:26:5 | LL | string.push_str(r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:25:5 + --> tests/ui/single_char_add_str.rs:30:5 | LL | string.push_str(&c_ref.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push(*c_ref)` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:27:5 + --> tests/ui/single_char_add_str.rs:33:5 | LL | string.push_str(&c.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push(c)` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:28:5 + --> tests/ui/single_char_add_str.rs:35:5 | LL | string.push_str(&'a'.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push('a')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:30:5 + --> tests/ui/single_char_add_str.rs:38:5 | LL | get_string!().push_str("ö"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:35:5 + --> tests/ui/single_char_add_str.rs:44:5 | LL | string.insert_str(0, "R"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:36:5 + --> tests/ui/single_char_add_str.rs:46:5 | LL | string.insert_str(1, "'"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '\'')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:41:5 + --> tests/ui/single_char_add_str.rs:52:5 | LL | string.insert_str(0, "\x52"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\x52')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:42:5 + --> tests/ui/single_char_add_str.rs:54:5 | LL | string.insert_str(0, "\u{0052}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\u{0052}')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:44:5 + --> tests/ui/single_char_add_str.rs:57:5 | LL | string.insert_str(x, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:46:5 + --> tests/ui/single_char_add_str.rs:60:5 | LL | string.insert_str(Y, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:47:5 + --> tests/ui/single_char_add_str.rs:62:5 | LL | string.insert_str(Y, r##"""##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '"')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:48:5 + --> tests/ui/single_char_add_str.rs:64:5 | LL | string.insert_str(Y, r##"'"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '\'')` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:50:5 + --> tests/ui/single_char_add_str.rs:67:5 | LL | string.insert_str(0, &c_ref.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, *c_ref)` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:51:5 + --> tests/ui/single_char_add_str.rs:69:5 | LL | string.insert_str(0, &c.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, c)` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:52:5 + --> tests/ui/single_char_add_str.rs:71:5 | LL | string.insert_str(0, &'a'.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:54:5 + --> tests/ui/single_char_add_str.rs:74:5 | LL | get_string!().insert_str(1, "?"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')` diff --git a/tests/ui/single_char_lifetime_names.rs b/tests/ui/single_char_lifetime_names.rs index 6731b5b13564..e6a35cfe1642 100644 --- a/tests/ui/single_char_lifetime_names.rs +++ b/tests/ui/single_char_lifetime_names.rs @@ -3,8 +3,10 @@ // 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 +//~^ single_char_lifetime_names +//~| single_char_lifetime_names + + where 'a: 'b, { @@ -14,8 +16,10 @@ 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 +//~^ single_char_lifetime_names +//~| single_char_lifetime_names + + fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> { Self { _source: source, @@ -36,7 +40,8 @@ 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 +//~^ single_char_lifetime_names + 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 005c897b19ba..010390ce15cc 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -17,7 +17,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:16:6 + --> tests/ui/single_char_lifetime_names.rs:18:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -25,7 +25,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:16:10 + --> tests/ui/single_char_lifetime_names.rs:18:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -33,7 +33,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:38:15 + --> tests/ui/single_char_lifetime_names.rs:42:15 | LL | fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { | ^^ diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed index a18d6319f89d..717779f03ab2 100644 --- a/tests/ui/single_char_pattern.fixed +++ b/tests/ui/single_char_pattern.fixed @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() { let x = "foo"; x.split('x'); + //~^ single_char_pattern x.split("xx"); x.split('x'); @@ -16,38 +17,65 @@ fn main() { // Can't use this lint for unicode code points which don't fit in a char x.split("❤️"); x.split_inclusive('x'); + //~^ single_char_pattern x.contains('x'); + //~^ single_char_pattern x.starts_with('x'); + //~^ single_char_pattern x.ends_with('x'); + //~^ single_char_pattern x.find('x'); + //~^ single_char_pattern x.rfind('x'); + //~^ single_char_pattern x.rsplit('x'); + //~^ single_char_pattern x.split_terminator('x'); + //~^ single_char_pattern x.rsplit_terminator('x'); + //~^ single_char_pattern x.splitn(2, 'x'); + //~^ single_char_pattern x.rsplitn(2, 'x'); + //~^ single_char_pattern x.split_once('x'); + //~^ single_char_pattern x.rsplit_once('x'); + //~^ single_char_pattern x.matches('x'); + //~^ single_char_pattern x.rmatches('x'); + //~^ single_char_pattern x.match_indices('x'); + //~^ single_char_pattern x.rmatch_indices('x'); + //~^ single_char_pattern x.trim_start_matches('x'); + //~^ single_char_pattern x.trim_end_matches('x'); + //~^ single_char_pattern x.replace('x', "y"); + //~^ single_char_pattern x.replacen('x', "y", 3); + //~^ single_char_pattern // Make sure we escape characters correctly. x.split('\n'); + //~^ single_char_pattern x.split('\''); + //~^ single_char_pattern x.split('\''); + //~^ single_char_pattern // Issue #11973: Don't escape `"` in `'"'` x.split('"'); + //~^ single_char_pattern let h = HashSet::::new(); h.contains("X"); // should not warn x.replace(';', ",").split(','); // issue #2978 + //~^ single_char_pattern x.starts_with('\x03'); // issue #2996 + //~^ single_char_pattern // Issue #3204 const S: &str = "#"; @@ -55,13 +83,20 @@ fn main() { // Raw string x.split('a'); + //~^ single_char_pattern x.split('a'); + //~^ single_char_pattern x.split('a'); + //~^ single_char_pattern x.split('\''); + //~^ single_char_pattern x.split('#'); + //~^ single_char_pattern // Must escape backslash in raw strings when converting to char #8060 x.split('\\'); + //~^ single_char_pattern x.split('\\'); + //~^ single_char_pattern // should not warn, the char versions are actually slower in some cases x.strip_prefix("x"); diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index b52e6fb2fdfb..88f6b85f946f 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() { let x = "foo"; x.split("x"); + //~^ single_char_pattern x.split("xx"); x.split('x'); @@ -16,38 +17,65 @@ fn main() { // Can't use this lint for unicode code points which don't fit in a char x.split("❤️"); x.split_inclusive("x"); + //~^ single_char_pattern x.contains("x"); + //~^ single_char_pattern x.starts_with("x"); + //~^ single_char_pattern x.ends_with("x"); + //~^ single_char_pattern x.find("x"); + //~^ single_char_pattern x.rfind("x"); + //~^ single_char_pattern x.rsplit("x"); + //~^ single_char_pattern x.split_terminator("x"); + //~^ single_char_pattern x.rsplit_terminator("x"); + //~^ single_char_pattern x.splitn(2, "x"); + //~^ single_char_pattern x.rsplitn(2, "x"); + //~^ single_char_pattern x.split_once("x"); + //~^ single_char_pattern x.rsplit_once("x"); + //~^ single_char_pattern x.matches("x"); + //~^ single_char_pattern x.rmatches("x"); + //~^ single_char_pattern x.match_indices("x"); + //~^ single_char_pattern x.rmatch_indices("x"); + //~^ single_char_pattern x.trim_start_matches("x"); + //~^ single_char_pattern x.trim_end_matches("x"); + //~^ single_char_pattern x.replace("x", "y"); + //~^ single_char_pattern x.replacen("x", "y", 3); + //~^ single_char_pattern // Make sure we escape characters correctly. x.split("\n"); + //~^ single_char_pattern x.split("'"); + //~^ single_char_pattern x.split("\'"); + //~^ single_char_pattern // Issue #11973: Don't escape `"` in `'"'` x.split("\""); + //~^ single_char_pattern let h = HashSet::::new(); h.contains("X"); // should not warn x.replace(';', ",").split(","); // issue #2978 + //~^ single_char_pattern x.starts_with("\x03"); // issue #2996 + //~^ single_char_pattern // Issue #3204 const S: &str = "#"; @@ -55,13 +83,20 @@ fn main() { // Raw string x.split(r"a"); + //~^ single_char_pattern x.split(r#"a"#); + //~^ single_char_pattern x.split(r###"a"###); + //~^ single_char_pattern x.split(r###"'"###); + //~^ single_char_pattern x.split(r###"#"###); + //~^ single_char_pattern // Must escape backslash in raw strings when converting to char #8060 x.split(r#"\"#); + //~^ single_char_pattern x.split(r"\"); + //~^ single_char_pattern // should not warn, the char versions are actually slower in some cases x.strip_prefix("x"); diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index b2deed23cbd5..80d9c7b04637 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -8,205 +8,205 @@ LL | x.split("x"); = help: to override `-D warnings` add `#[allow(clippy::single_char_pattern)]` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:18:23 + --> tests/ui/single_char_pattern.rs:19:23 | LL | x.split_inclusive("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:19:16 + --> tests/ui/single_char_pattern.rs:21:16 | LL | x.contains("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:20:19 + --> tests/ui/single_char_pattern.rs:23:19 | LL | x.starts_with("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:21:17 + --> tests/ui/single_char_pattern.rs:25:17 | LL | x.ends_with("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:22:12 + --> tests/ui/single_char_pattern.rs:27:12 | LL | x.find("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:23:13 + --> tests/ui/single_char_pattern.rs:29:13 | LL | x.rfind("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:24:14 + --> tests/ui/single_char_pattern.rs:31:14 | LL | x.rsplit("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:25:24 + --> tests/ui/single_char_pattern.rs:33:24 | LL | x.split_terminator("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:26:25 + --> tests/ui/single_char_pattern.rs:35:25 | LL | x.rsplit_terminator("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:27:17 + --> tests/ui/single_char_pattern.rs:37:17 | LL | x.splitn(2, "x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:28:18 + --> tests/ui/single_char_pattern.rs:39:18 | LL | x.rsplitn(2, "x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:29:18 + --> tests/ui/single_char_pattern.rs:41:18 | LL | x.split_once("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:30:19 + --> tests/ui/single_char_pattern.rs:43:19 | LL | x.rsplit_once("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:31:15 + --> tests/ui/single_char_pattern.rs:45:15 | LL | x.matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:32:16 + --> tests/ui/single_char_pattern.rs:47:16 | LL | x.rmatches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:33:21 + --> tests/ui/single_char_pattern.rs:49:21 | LL | x.match_indices("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:34:22 + --> tests/ui/single_char_pattern.rs:51:22 | LL | x.rmatch_indices("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:35:26 + --> tests/ui/single_char_pattern.rs:53:26 | LL | x.trim_start_matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:36:24 + --> tests/ui/single_char_pattern.rs:55:24 | LL | x.trim_end_matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:37:15 + --> tests/ui/single_char_pattern.rs:57:15 | LL | x.replace("x", "y"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:38:16 + --> tests/ui/single_char_pattern.rs:59:16 | LL | x.replacen("x", "y", 3); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:40:13 + --> tests/ui/single_char_pattern.rs:62:13 | LL | x.split("\n"); | ^^^^ help: consider using a `char`: `'\n'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:41:13 + --> tests/ui/single_char_pattern.rs:64:13 | LL | x.split("'"); | ^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:42:13 + --> tests/ui/single_char_pattern.rs:66:13 | LL | x.split("\'"); | ^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:44:13 + --> tests/ui/single_char_pattern.rs:69:13 | LL | x.split("\""); | ^^^^ help: consider using a `char`: `'"'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:49:31 + --> tests/ui/single_char_pattern.rs:75:31 | LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: consider using a `char`: `','` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:50:19 + --> tests/ui/single_char_pattern.rs:77:19 | LL | x.starts_with("\x03"); // issue #2996 | ^^^^^^ help: consider using a `char`: `'\x03'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:57:13 + --> tests/ui/single_char_pattern.rs:85:13 | LL | x.split(r"a"); | ^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:58:13 + --> tests/ui/single_char_pattern.rs:87:13 | LL | x.split(r#"a"#); | ^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:59:13 + --> tests/ui/single_char_pattern.rs:89:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:60:13 + --> tests/ui/single_char_pattern.rs:91:13 | LL | x.split(r###"'"###); | ^^^^^^^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:61:13 + --> tests/ui/single_char_pattern.rs:93:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: consider using a `char`: `'#'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:63:13 + --> tests/ui/single_char_pattern.rs:96:13 | LL | x.split(r#"\"#); | ^^^^^^ help: consider using a `char`: `'\\'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:64:13 + --> tests/ui/single_char_pattern.rs:98:13 | LL | x.split(r"\"); | ^^^^ help: consider using a `char`: `'\\'` diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index 3e81bcd5e487..180a55813b19 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -3,6 +3,7 @@ use core; +//~^ single_component_path_imports use serde as edres; @@ -29,6 +30,7 @@ fn main() { mod hello_mod { + //~^ single_component_path_imports #[allow(dead_code)] fn hello_mod() {} } diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs index 2d72f122adf2..888c533c534c 100644 --- a/tests/ui/single_component_path_imports.rs +++ b/tests/ui/single_component_path_imports.rs @@ -4,6 +4,7 @@ use core; use regex; +//~^ single_component_path_imports use serde as edres; @@ -30,6 +31,7 @@ fn main() { mod hello_mod { use regex; + //~^ single_component_path_imports #[allow(dead_code)] fn hello_mod() {} } diff --git a/tests/ui/single_component_path_imports.stderr b/tests/ui/single_component_path_imports.stderr index 95d7e4d85b7c..f1c56b14358f 100644 --- a/tests/ui/single_component_path_imports.stderr +++ b/tests/ui/single_component_path_imports.stderr @@ -8,7 +8,7 @@ LL | use regex; = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> tests/ui/single_component_path_imports.rs:32:5 + --> tests/ui/single_component_path_imports.rs:33:5 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely diff --git a/tests/ui/single_component_path_imports_macro.rs b/tests/ui/single_component_path_imports_macro.rs index fda294a61546..f655ea482d1c 100644 --- a/tests/ui/single_component_path_imports_macro.rs +++ b/tests/ui/single_component_path_imports_macro.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/tests/ui/single_component_path_imports_nested_first.rs b/tests/ui/single_component_path_imports_nested_first.rs index b4a1ce1d6aec..b1c6e6f94e42 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -2,8 +2,9 @@ #![allow(unused_imports)] //@no-rustfix use regex; -//~^ ERROR: this import is redundant -//~| NOTE: `-D clippy::single-component-path-imports` implied by `-D warnings` +//~^ single_component_path_imports + + use serde as edres; @@ -15,8 +16,10 @@ fn main() { mod root_nested_use_mod { use {regex, serde}; - //~^ ERROR: this import is redundant - //~| ERROR: this import is redundant + //~^ single_component_path_imports + //~| single_component_path_imports + + #[allow(dead_code)] fn root_nested_use_mod() {} } diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index 8eec877860e7..8df4d8404eea 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -8,7 +8,7 @@ LL | use regex; = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:17:10 + --> tests/ui/single_component_path_imports_nested_first.rs:18:10 | LL | use {regex, serde}; | ^^^^^ @@ -16,7 +16,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:17:17 + --> tests/ui/single_component_path_imports_nested_first.rs:18:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/tests/ui/single_component_path_imports_self_after.rs b/tests/ui/single_component_path_imports_self_after.rs index 5723d480a2e1..a0f2cf690809 100644 --- a/tests/ui/single_component_path_imports_self_after.rs +++ b/tests/ui/single_component_path_imports_self_after.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/tests/ui/single_component_path_imports_self_before.rs b/tests/ui/single_component_path_imports_self_before.rs index 8a4fbf0dc5b6..b80580da10c3 100644 --- a/tests/ui/single_component_path_imports_self_before.rs +++ b/tests/ui/single_component_path_imports_self_before.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed index 64cbd5e9c905..eadf77f0fa50 100644 --- a/tests/ui/single_element_loop.fixed +++ b/tests/ui/single_element_loop.fixed @@ -7,27 +7,33 @@ fn main() { let item1 = 2; { let item = &item1; + //~^ single_element_loop dbg!(item); } { let item = &item1; + //~^ single_element_loop dbg!(item); } for item in 0..5 { + //~^ single_element_loop dbg!(item); } for item in 0..5 { + //~^ single_element_loop dbg!(item); } for item in 0..5 { + //~^ single_element_loop dbg!(item); } for item in 0..5 { + //~^ single_element_loop dbg!(item); } @@ -48,6 +54,7 @@ fn main() { // should lint (issue #10018) { let _ = 42; + //~^ single_element_loop let _f = |n: u32| { for i in 0..n { if i > 10 { @@ -63,6 +70,7 @@ fn main() { { let (Ok(mut _x) | Err(mut _x)) = res_void; + //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } } diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs index 92406f1c1cac..6aa9269e56c0 100644 --- a/tests/ui/single_element_loop.rs +++ b/tests/ui/single_element_loop.rs @@ -6,26 +6,32 @@ fn main() { let item1 = 2; for item in &[item1] { + //~^ single_element_loop dbg!(item); } for item in [item1].iter() { + //~^ single_element_loop dbg!(item); } for item in &[0..5] { + //~^ single_element_loop dbg!(item); } for item in [0..5].iter_mut() { + //~^ single_element_loop dbg!(item); } for item in [0..5] { + //~^ single_element_loop dbg!(item); } for item in [0..5].into_iter() { + //~^ single_element_loop dbg!(item); } @@ -45,6 +51,7 @@ fn main() { // should lint (issue #10018) for _ in [42] { + //~^ single_element_loop let _f = |n: u32| { for i in 0..n { if i > 10 { @@ -59,6 +66,7 @@ fn main() { let res_void: Result = Ok(true); for (Ok(mut _x) | Err(mut _x)) in [res_void] { + //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } } diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index 73453dd2dfd8..639f8d2d1b98 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -2,6 +2,7 @@ error: for loop over a single element --> tests/ui/single_element_loop.rs:8:5 | LL | / for item in &[item1] { +LL | | LL | | dbg!(item); LL | | } | |_____^ @@ -12,14 +13,16 @@ help: try | LL ~ { LL + let item = &item1; +LL + LL + dbg!(item); LL + } | error: for loop over a single element - --> tests/ui/single_element_loop.rs:12:5 + --> tests/ui/single_element_loop.rs:13:5 | LL | / for item in [item1].iter() { +LL | | LL | | dbg!(item); LL | | } | |_____^ @@ -28,41 +31,42 @@ help: try | LL ~ { LL + let item = &item1; +LL + LL + dbg!(item); LL + } | error: this loops only once with `item` being `0..5` - --> tests/ui/single_element_loop.rs:16:17 + --> tests/ui/single_element_loop.rs:18:17 | LL | for item in &[0..5] { | ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> tests/ui/single_element_loop.rs:20:17 + --> tests/ui/single_element_loop.rs:23:17 | LL | for item in [0..5].iter_mut() { | ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> tests/ui/single_element_loop.rs:24:17 + --> tests/ui/single_element_loop.rs:28:17 | LL | for item in [0..5] { | ^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: this loops only once with `item` being `0..5` - --> tests/ui/single_element_loop.rs:28:17 + --> tests/ui/single_element_loop.rs:33:17 | LL | for item in [0..5].into_iter() { | ^^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` error: for loop over a single element - --> tests/ui/single_element_loop.rs:47:5 + --> tests/ui/single_element_loop.rs:53:5 | LL | / for _ in [42] { +LL | | LL | | let _f = |n: u32| { LL | | for i in 0..n { -LL | | if i > 10 { ... | LL | | }; LL | | } @@ -72,6 +76,7 @@ help: try | LL ~ { LL + let _ = 42; +LL + LL + let _f = |n: u32| { LL + for i in 0..n { LL + if i > 10 { @@ -84,9 +89,10 @@ LL + } | error: for loop over a single element - --> tests/ui/single_element_loop.rs:61:5 + --> tests/ui/single_element_loop.rs:68:5 | LL | / for (Ok(mut _x) | Err(mut _x)) in [res_void] { +LL | | LL | | let ptr: *const bool = std::ptr::null(); LL | | } | |_____^ @@ -95,6 +101,7 @@ help: try | LL ~ { LL + let (Ok(mut _x) | Err(mut _x)) = res_void; +LL + LL + let ptr: *const bool = std::ptr::null(); LL + } | diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed index d3d5fd8b35c8..c6ffe93eb7ab 100644 --- a/tests/ui/single_match.fixed +++ b/tests/ui/single_match.fixed @@ -15,6 +15,7 @@ fn single_match() { if let Some(y) = x { println!("{:?}", y); }; + //~^^^^^^ single_match let x = Some(1u8); match x { @@ -27,6 +28,7 @@ fn single_match() { let z = (1u8, 1u8); if let (2..=3, 7..=9) = z { dummy() }; + //~^^^^ single_match // Not linted (pattern guards used) match x { @@ -53,12 +55,15 @@ fn single_match_know_enum() { let y: Result<_, i8> = Ok(1i8); if let Some(y) = x { dummy() }; + //~^^^^ single_match if let Ok(y) = y { dummy() }; + //~^^^^ single_match let c = Cow::Borrowed(""); if let Cow::Borrowed(..) = c { dummy() }; + //~^^^^ single_match let z = Foo::Bar; // no warning @@ -77,6 +82,7 @@ fn single_match_know_enum() { fn if_suggestion() { let x = "test"; if x == "test" { println!() } + //~^^^^ single_match #[derive(PartialEq, Eq)] enum Foo { @@ -87,14 +93,18 @@ fn if_suggestion() { let x = Foo::A; if x == Foo::A { println!() } + //~^^^^ single_match const FOO_C: Foo = Foo::C(0); if x == FOO_C { println!() } + //~^^^^ single_match if x == Foo::A { println!() } + //~^^^^ single_match let x = &x; if x == &Foo::A { println!() } + //~^^^^ single_match enum Bar { A, @@ -109,11 +119,13 @@ fn if_suggestion() { let x = Bar::A; if let Bar::A = x { println!() } + //~^^^^ single_match // issue #7038 struct X; let x = Some(X); if let None = x { println!() }; + //~^^^^ single_match } // See: issue #8282 @@ -133,12 +145,15 @@ fn ranges() { // lint if let (Some(_), _) = x {} + //~^^^^ single_match // lint if let (Some(E::V), _) = x { todo!() } + //~^^^^ single_match // lint if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {} + //~^^^^ single_match // Don't lint, see above. match (Some(E::V), Some(E::V), Some(E::V)) { @@ -211,6 +226,7 @@ fn issue_10808(bar: Option) { let r = &v as *const i32; println!("{}", *r); } } + //~^^^^^^^ single_match if let Some(v) = bar { unsafe { @@ -218,6 +234,7 @@ fn issue_10808(bar: Option) { println!("{}", *r); } } + //~^^^^^^^^^^ single_match } mod issue8634 { @@ -289,6 +306,7 @@ fn issue11365() { } if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() } + //~^^^^ single_match match &Some(A) { Some(A | B | C) => println!(), @@ -301,10 +319,12 @@ fn issue11365() { } if let Some(A | B) = &Some(A) { println!() } + //~^^^^ single_match } fn issue12758(s: &[u8]) { if &s[0..3] == b"foo" { println!() } + //~^^^^ single_match } #[derive(Eq, PartialEq)] @@ -315,20 +335,26 @@ const CONST_I32: i32 = 1; fn irrefutable_match() { println!(); + //~^^^^ single_match println!(); + //~^^^^ single_match let i = 0; { let a = 1; let b = 2; } + //~^^^^^^^ single_match + //~^^^^ single_match + //~^^^^ single_match println!(); + //~^^^^ single_match let mut x = vec![1i8]; diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index 2f3547c50639..dc758fa4281c 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -18,6 +18,7 @@ fn single_match() { }, _ => (), }; + //~^^^^^^ single_match let x = Some(1u8); match x { @@ -33,6 +34,7 @@ fn single_match() { (2..=3, 7..=9) => dummy(), _ => {}, }; + //~^^^^ single_match // Not linted (pattern guards used) match x { @@ -62,11 +64,13 @@ fn single_match_know_enum() { Some(y) => dummy(), None => (), }; + //~^^^^ single_match match y { Ok(y) => dummy(), Err(..) => (), }; + //~^^^^ single_match let c = Cow::Borrowed(""); @@ -74,6 +78,7 @@ fn single_match_know_enum() { Cow::Borrowed(..) => dummy(), Cow::Owned(..) => (), }; + //~^^^^ single_match let z = Foo::Bar; // no warning @@ -95,6 +100,7 @@ fn if_suggestion() { "test" => println!(), _ => (), } + //~^^^^ single_match #[derive(PartialEq, Eq)] enum Foo { @@ -108,23 +114,27 @@ fn if_suggestion() { Foo::A => println!(), _ => (), } + //~^^^^ single_match const FOO_C: Foo = Foo::C(0); match x { FOO_C => println!(), _ => (), } + //~^^^^ single_match match &&x { Foo::A => println!(), _ => (), } + //~^^^^ single_match let x = &x; match &x { Foo::A => println!(), _ => (), } + //~^^^^ single_match enum Bar { A, @@ -142,6 +152,7 @@ fn if_suggestion() { Bar::A => println!(), _ => (), } + //~^^^^ single_match // issue #7038 struct X; @@ -150,6 +161,7 @@ fn if_suggestion() { None => println!(), _ => (), }; + //~^^^^ single_match } // See: issue #8282 @@ -172,18 +184,21 @@ fn ranges() { (Some(_), _) => {}, (None, _) => {}, } + //~^^^^ single_match // lint match x { (Some(E::V), _) => todo!(), (_, _) => {}, } + //~^^^^ single_match // lint match (Some(42), Some(E::V), Some(42)) { (.., Some(E::V), _) => {}, (..) => {}, } + //~^^^^ single_match // Don't lint, see above. match (Some(E::V), Some(E::V), Some(E::V)) { @@ -259,6 +274,7 @@ fn issue_10808(bar: Option) { }, _ => {}, } + //~^^^^^^^ single_match match bar { #[rustfmt::skip] @@ -270,6 +286,7 @@ fn issue_10808(bar: Option) { }, _ => {}, } + //~^^^^^^^^^^ single_match } mod issue8634 { @@ -344,6 +361,7 @@ fn issue11365() { Ok(Some(A)) => println!(), Err(_) | Ok(None | Some(_)) => {}, } + //~^^^^ single_match match &Some(A) { Some(A | B | C) => println!(), @@ -359,6 +377,7 @@ fn issue11365() { Some(A | B) => println!(), None | Some(_) => {}, } + //~^^^^ single_match } fn issue12758(s: &[u8]) { @@ -366,6 +385,7 @@ fn issue12758(s: &[u8]) { b"foo" => println!(), _ => {}, } + //~^^^^ single_match } #[derive(Eq, PartialEq)] @@ -379,11 +399,13 @@ fn irrefutable_match() { DATA => println!(), _ => {}, } + //~^^^^ single_match match CONST_I32 { CONST_I32 => println!(), _ => {}, } + //~^^^^ single_match let i = 0; match i { @@ -393,21 +415,25 @@ fn irrefutable_match() { }, _ => {}, } + //~^^^^^^^ single_match match i { i => {}, _ => {}, } + //~^^^^ single_match match i { i => (), _ => (), } + //~^^^^ single_match match CONST_I32 { CONST_I32 => println!(), _ => {}, } + //~^^^^ single_match let mut x = vec![1i8]; diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr deleted file mode 100644 index 54bbfbac093c..000000000000 --- a/tests/ui/single_match.stderr +++ /dev/null @@ -1,282 +0,0 @@ -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:15:5 - | -LL | / match x { -LL | | Some(y) => { -LL | | println!("{:?}", y); -LL | | }, -LL | | _ => (), -LL | | }; - | |_____^ - | - = note: `-D clippy::single-match` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::single_match)]` -help: try - | -LL ~ if let Some(y) = x { -LL + println!("{:?}", y); -LL ~ }; - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:32:5 - | -LL | / match z { -LL | | (2..=3, 7..=9) => dummy(), -LL | | _ => {}, -LL | | }; - | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:61:5 - | -LL | / match x { -LL | | Some(y) => dummy(), -LL | | None => (), -LL | | }; - | |_____^ help: try: `if let Some(y) = x { dummy() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:66:5 - | -LL | / match y { -LL | | Ok(y) => dummy(), -LL | | Err(..) => (), -LL | | }; - | |_____^ help: try: `if let Ok(y) = y { dummy() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:73:5 - | -LL | / match c { -LL | | Cow::Borrowed(..) => dummy(), -LL | | Cow::Owned(..) => (), -LL | | }; - | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:94:5 - | -LL | / match x { -LL | | "test" => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if x == "test" { println!() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:107:5 - | -LL | / match x { -LL | | Foo::A => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if x == Foo::A { println!() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:113:5 - | -LL | / match x { -LL | | FOO_C => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if x == FOO_C { println!() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:118:5 - | -LL | / match &&x { -LL | | Foo::A => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if x == Foo::A { println!() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:124:5 - | -LL | / match &x { -LL | | Foo::A => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if x == &Foo::A { println!() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:141:5 - | -LL | / match x { -LL | | Bar::A => println!(), -LL | | _ => (), -LL | | } - | |_____^ help: try: `if let Bar::A = x { println!() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:149:5 - | -LL | / match x { -LL | | None => println!(), -LL | | _ => (), -LL | | }; - | |_____^ help: try: `if let None = x { println!() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:171:5 - | -LL | / match x { -LL | | (Some(_), _) => {}, -LL | | (None, _) => {}, -LL | | } - | |_____^ help: try: `if let (Some(_), _) = x {}` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:177:5 - | -LL | / match x { -LL | | (Some(E::V), _) => todo!(), -LL | | (_, _) => {}, -LL | | } - | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:183:5 - | -LL | / match (Some(42), Some(E::V), Some(42)) { -LL | | (.., Some(E::V), _) => {}, -LL | | (..) => {}, -LL | | } - | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:255:5 - | -LL | / match bar { -LL | | Some(v) => unsafe { -LL | | let r = &v as *const i32; -LL | | println!("{}", *r); -LL | | }, -LL | | _ => {}, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { unsafe { -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:263:5 - | -LL | / match bar { -LL | | #[rustfmt::skip] -LL | | Some(v) => { -LL | | unsafe { -... | -LL | | _ => {}, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { -LL + unsafe { -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:343:5 - | -LL | / match Ok::<_, u32>(Some(A)) { -LL | | Ok(Some(A)) => println!(), -LL | | Err(_) | Ok(None | Some(_)) => {}, -LL | | } - | |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }` - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:358:5 - | -LL | / match &Some(A) { -LL | | Some(A | B) => println!(), -LL | | None | Some(_) => {}, -LL | | } - | |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }` - -error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:365:5 - | -LL | / match &s[0..3] { -LL | | b"foo" => println!(), -LL | | _ => {}, -LL | | } - | |_____^ help: try: `if &s[0..3] == b"foo" { println!() }` - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:378:5 - | -LL | / match DATA { -LL | | DATA => println!(), -LL | | _ => {}, -LL | | } - | |_____^ help: try: `println!();` - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:383:5 - | -LL | / match CONST_I32 { -LL | | CONST_I32 => println!(), -LL | | _ => {}, -LL | | } - | |_____^ help: try: `println!();` - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:389:5 - | -LL | / match i { -LL | | i => { -LL | | let a = 1; -LL | | let b = 2; -LL | | }, -LL | | _ => {}, -LL | | } - | |_____^ - | -help: try - | -LL ~ { -LL + let a = 1; -LL + let b = 2; -LL + } - | - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:397:5 - | -LL | / match i { -LL | | i => {}, -LL | | _ => {}, -LL | | } - | |_____^ help: `match` expression can be removed - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:402:5 - | -LL | / match i { -LL | | i => (), -LL | | _ => (), -LL | | } - | |_____^ help: `match` expression can be removed - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:407:5 - | -LL | / match CONST_I32 { -LL | | CONST_I32 => println!(), -LL | | _ => {}, -LL | | } - | |_____^ help: try: `println!();` - -error: aborting due to 26 previous errors - diff --git a/tests/ui/single_match_else.fixed b/tests/ui/single_match_else.fixed index c2ca746976bd..64782bf62a78 100644 --- a/tests/ui/single_match_else.fixed +++ b/tests/ui/single_match_else.fixed @@ -18,6 +18,7 @@ fn unwrap_addr() -> Option<&'static ExprNode> { let x = 5; None }; + //~^^^^^^^ single_match_else // Don't lint with_span!(span match ExprNode::Butterflies { @@ -80,12 +81,14 @@ fn main() { println!("else block"); return } + //~^^^^^^^ single_match_else // lint here if let Some(a) = Some(1) { println!("${:?}", a) } else { println!("else block"); return; } + //~^^^^^^^ single_match_else // lint here use std::convert::Infallible; @@ -93,12 +96,14 @@ fn main() { println!("else block"); return; } + //~^^^^^^^ single_match_else use std::borrow::Cow; if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else { println!("else block"); return; } + //~^^^^^^^ single_match_else } fn issue_10808(bar: Option) { @@ -109,6 +114,7 @@ fn issue_10808(bar: Option) { println!("None1"); println!("None2"); } + //~^^^^^^^^^^ single_match_else if let Some(v) = bar { println!("Some"); @@ -118,6 +124,7 @@ fn issue_10808(bar: Option) { let r = &v as *const i32; println!("{}", *r); } } + //~^^^^^^^^^^^ single_match_else if let Some(v) = bar { unsafe { let r = &v as *const i32; @@ -127,6 +134,7 @@ fn issue_10808(bar: Option) { let r = &v as *const i32; println!("{}", *r); } } + //~^^^^^^^^^^^ single_match_else if let Some(v) = bar { unsafe { @@ -137,6 +145,7 @@ fn issue_10808(bar: Option) { println!("None"); println!("None"); } + //~^^^^^^^^^^^^^ single_match_else match bar { Some(v) => { @@ -174,4 +183,5 @@ fn issue_10808(bar: Option) { fn irrefutable_match() -> Option<&'static ExprNode> { Some(&NODE) + //~^^^^^^^ single_match_else } diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index 2d9e877ee0fe..3f86f4d51803 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -21,6 +21,7 @@ fn unwrap_addr() -> Option<&'static ExprNode> { None }, }; + //~^^^^^^^ single_match_else // Don't lint with_span!(span match ExprNode::Butterflies { @@ -86,6 +87,7 @@ fn main() { return }, } + //~^^^^^^^ single_match_else // lint here match Some(1) { @@ -95,6 +97,7 @@ fn main() { return; }, } + //~^^^^^^^ single_match_else // lint here use std::convert::Infallible; @@ -105,6 +108,7 @@ fn main() { return; } } + //~^^^^^^^ single_match_else use std::borrow::Cow; match Cow::from("moo") { @@ -114,6 +118,7 @@ fn main() { return; } } + //~^^^^^^^ single_match_else } fn issue_10808(bar: Option) { @@ -127,6 +132,7 @@ fn issue_10808(bar: Option) { println!("None2"); }, } + //~^^^^^^^^^^ single_match_else match bar { Some(v) => { @@ -139,6 +145,7 @@ fn issue_10808(bar: Option) { println!("{}", *r); }, } + //~^^^^^^^^^^^ single_match_else match bar { Some(v) => unsafe { @@ -151,6 +158,7 @@ fn issue_10808(bar: Option) { println!("{}", *r); }, } + //~^^^^^^^^^^^ single_match_else match bar { #[rustfmt::skip] @@ -165,6 +173,7 @@ fn issue_10808(bar: Option) { println!("None"); }, } + //~^^^^^^^^^^^^^ single_match_else match bar { Some(v) => { @@ -208,4 +217,5 @@ fn irrefutable_match() -> Option<&'static ExprNode> { None }, } + //~^^^^^^^ single_match_else } diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr deleted file mode 100644 index aa494520b841..000000000000 --- a/tests/ui/single_match_else.stderr +++ /dev/null @@ -1,211 +0,0 @@ -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:17:13 - | -LL | let _ = match ExprNode::Butterflies { - | _____________^ -LL | | ExprNode::ExprAddrOf => Some(&NODE), -LL | | _ => { -LL | | let x = 5; -LL | | None -LL | | }, -LL | | }; - | |_____^ - | - = note: `-D clippy::single-match-else` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::single_match_else)]` -help: try - | -LL ~ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { -LL + let x = 5; -LL + None -LL ~ }; - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:82:5 - | -LL | / match Some(1) { -LL | | Some(a) => println!("${:?}", a), -LL | | None => { -LL | | println!("else block"); -LL | | return -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL + println!("else block"); -LL + return -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:91:5 - | -LL | / match Some(1) { -LL | | Some(a) => println!("${:?}", a), -LL | | None => { -LL | | println!("else block"); -LL | | return; -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { -LL + println!("else block"); -LL + return; -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:101:5 - | -LL | / match Result::::Ok(1) { -LL | | Ok(a) => println!("${:?}", a), -LL | | Err(_) => { -LL | | println!("else block"); -... | -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Ok(a) = Result::::Ok(1) { println!("${:?}", a) } else { -LL + println!("else block"); -LL + return; -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:110:5 - | -LL | / match Cow::from("moo") { -LL | | Cow::Owned(a) => println!("${:?}", a), -LL | | Cow::Borrowed(_) => { -LL | | println!("else block"); -... | -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else { -LL + println!("else block"); -LL + return; -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:120:5 - | -LL | / match bar { -LL | | Some(v) => unsafe { -LL | | let r = &v as *const i32; -LL | | println!("{}", *r); -... | -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { unsafe { -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } } else { -LL + println!("None1"); -LL + println!("None2"); -LL + } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:131:5 - | -LL | / match bar { -LL | | Some(v) => { -LL | | println!("Some"); -LL | | println!("{v}"); -... | -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { -LL + println!("Some"); -LL + println!("{v}"); -LL + } else { unsafe { -LL + let v = 0; -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:143:5 - | -LL | / match bar { -LL | | Some(v) => unsafe { -LL | | let r = &v as *const i32; -LL | | println!("{}", *r); -... | -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { unsafe { -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } } else { unsafe { -LL + let v = 0; -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } } - | - -error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:155:5 - | -LL | / match bar { -LL | | #[rustfmt::skip] -LL | | Some(v) => { -LL | | unsafe { -... | -LL | | }, -LL | | } - | |_____^ - | -help: try - | -LL ~ if let Some(v) = bar { -LL + unsafe { -LL + let r = &v as *const i32; -LL + println!("{}", *r); -LL + } -LL + } else { -LL + println!("None"); -LL + println!("None"); -LL + } - | - -error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match_else.rs:204:5 - | -LL | / match ExprNode::Butterflies { -LL | | ExprNode::Butterflies => Some(&NODE), -LL | | _ => { -LL | | let x = 5; -LL | | None -LL | | }, -LL | | } - | |_____^ help: try: `Some(&NODE)` - -error: aborting due to 10 previous errors - diff --git a/tests/ui/single_option_map.rs b/tests/ui/single_option_map.rs index 571beec54799..fd9db9165bdc 100644 --- a/tests/ui/single_option_map.rs +++ b/tests/ui/single_option_map.rs @@ -6,12 +6,14 @@ static ATOM: AtomicUsize = AtomicUsize::new(42); static MAYBE_ATOMIC: Option<&AtomicUsize> = Some(&ATOM); fn h(arg: Option) -> Option { - //~^ ERROR: `fn` that only maps over argument +//~^ single_option_map + arg.map(|x| x * 2) } fn j(arg: Option) -> Option { - //~^ ERROR: `fn` that only maps over argument +//~^ single_option_map + arg.map(|x| x * 2) } @@ -20,7 +22,8 @@ fn mul_args(a: String, b: u64) -> String { } fn mul_args_opt(a: Option, b: u64) -> Option { - //~^ ERROR: `fn` that only maps over argument +//~^ single_option_map + a.map(|val| mul_args(val, b + 1)) } diff --git a/tests/ui/single_option_map.stderr b/tests/ui/single_option_map.stderr index f7d48eba71e8..11865c5b569f 100644 --- a/tests/ui/single_option_map.stderr +++ b/tests/ui/single_option_map.stderr @@ -3,6 +3,7 @@ error: `fn` that only maps over argument | LL | / fn h(arg: Option) -> Option { LL | | +LL | | LL | | arg.map(|x| x * 2) LL | | } | |_^ @@ -12,10 +13,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::single_option_map)]` error: `fn` that only maps over argument - --> tests/ui/single_option_map.rs:13:1 + --> tests/ui/single_option_map.rs:14:1 | LL | / fn j(arg: Option) -> Option { LL | | +LL | | LL | | arg.map(|x| x * 2) LL | | } | |_^ @@ -23,10 +25,11 @@ LL | | } = help: move the `.map` to the caller or to an `_opt` function error: `fn` that only maps over argument - --> tests/ui/single_option_map.rs:22:1 + --> tests/ui/single_option_map.rs:24:1 | LL | / fn mul_args_opt(a: Option, b: u64) -> Option { LL | | +LL | | LL | | a.map(|val| mul_args(val, b + 1)) LL | | } | |_^ diff --git a/tests/ui/single_range_in_vec_init.rs b/tests/ui/single_range_in_vec_init.rs index 7887cfc61750..c6c0cb347dc6 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -24,16 +24,26 @@ fn awa_vec(start: T, end: T) { fn main() { // Lint [0..200]; + //~^ single_range_in_vec_init vec![0..200]; + //~^ single_range_in_vec_init [0u8..200]; + //~^ single_range_in_vec_init [0usize..200]; + //~^ single_range_in_vec_init [0..200usize]; + //~^ single_range_in_vec_init vec![0u8..200]; + //~^ single_range_in_vec_init vec![0usize..200]; + //~^ single_range_in_vec_init vec![0..200usize]; + //~^ single_range_in_vec_init // Only suggest collect [0..200isize]; + //~^ single_range_in_vec_init vec![0..200isize]; + //~^ single_range_in_vec_init // Do not lint [0..200, 0..100]; vec![0..200, 0..100]; diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.stderr index 9c125adb51a7..48f5a94826c6 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.stderr @@ -16,7 +16,7 @@ LL | [0; 200]; | ~~~~~~ error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:27:5 + --> tests/ui/single_range_in_vec_init.rs:28:5 | LL | vec![0..200]; | ^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | vec![0; 200]; | ~~~~~~ error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:28:5 + --> tests/ui/single_range_in_vec_init.rs:30:5 | LL | [0u8..200]; | ^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | [0u8; 200]; | ~~~~~~~~ error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:29:5 + --> tests/ui/single_range_in_vec_init.rs:32:5 | LL | [0usize..200]; | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | [0usize; 200]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:30:5 + --> tests/ui/single_range_in_vec_init.rs:34:5 | LL | [0..200usize]; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | [0; 200usize]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:31:5 + --> tests/ui/single_range_in_vec_init.rs:36:5 | LL | vec![0u8..200]; | ^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | vec![0u8; 200]; | ~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:32:5 + --> tests/ui/single_range_in_vec_init.rs:38:5 | LL | vec![0usize..200]; | ^^^^^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | vec![0usize; 200]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:33:5 + --> tests/ui/single_range_in_vec_init.rs:40:5 | LL | vec![0..200usize]; | ^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | vec![0; 200usize]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:35:5 + --> tests/ui/single_range_in_vec_init.rs:43:5 | LL | [0..200isize]; | ^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | (0..200isize).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:36:5 + --> tests/ui/single_range_in_vec_init.rs:45:5 | LL | vec![0..200isize]; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index f405ba200acd..39c482af78c0 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -13,15 +13,18 @@ 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` + //~^ size_of_in_element_count + // 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` + //~^ size_of_in_element_count + // 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` + //~^ size_of_in_element_count + // 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::()) }; @@ -31,7 +34,8 @@ 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` + //~^ size_of_in_element_count + // 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 74be0d7773df..8af8867e04dd 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -9,7 +9,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of:: = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:19:62 + --> tests/ui/size_of_in_element_count/expressions.rs:20:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:23:47 + --> tests/ui/size_of_in_element_count/expressions.rs:25:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::( = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:33:47 + --> tests/ui/size_of_in_element_count/expressions.rs:36: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 af18136a1dbe..c8bb603d8165 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -16,47 +16,66 @@ 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + 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` + //~^ size_of_in_element_count + unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + unsafe { y.as_mut_ptr().sub(size_of::()) }; - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + y.as_ptr().wrapping_sub(size_of::()); - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + unsafe { y.as_ptr().add(size_of::()) }; - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + y.as_mut_ptr().wrapping_add(size_of::()); - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + unsafe { y.as_ptr().offset(size_of::() as isize) }; - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + y.as_mut_ptr().wrapping_offset(size_of::() as isize); - //~^ ERROR: found a count of bytes instead of a count of elements of `T` + //~^ size_of_in_element_count + } diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index de54789b2251..a05f88436a6a 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -9,7 +9,7 @@ LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/functions.rs:20:62 + --> tests/ui/size_of_in_element_count/functions.rs:21:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,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` - --> tests/ui/size_of_in_element_count/functions.rs:23:49 + --> tests/ui/size_of_in_element_count/functions.rs:25:49 | LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -25,7 +25,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` - --> tests/ui/size_of_in_element_count/functions.rs:25:64 + --> tests/ui/size_of_in_element_count/functions.rs:28:64 | LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of:: tests/ui/size_of_in_element_count/functions.rs:27:51 + --> tests/ui/size_of_in_element_count/functions.rs:31:51 | LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -41,7 +41,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` - --> tests/ui/size_of_in_element_count/functions.rs:29:66 + --> tests/ui/size_of_in_element_count/functions.rs:34:66 | LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,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` - --> tests/ui/size_of_in_element_count/functions.rs:32:47 + --> tests/ui/size_of_in_element_count/functions.rs:38:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -57,7 +57,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` - --> tests/ui/size_of_in_element_count/functions.rs:34:47 + --> tests/ui/size_of_in_element_count/functions.rs:41:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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` - --> tests/ui/size_of_in_element_count/functions.rs:37:66 + --> tests/ui/size_of_in_element_count/functions.rs:45:66 | LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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` - --> tests/ui/size_of_in_element_count/functions.rs:40:46 + --> tests/ui/size_of_in_element_count/functions.rs:49:46 | LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,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` - --> tests/ui/size_of_in_element_count/functions.rs:42:38 + --> tests/ui/size_of_in_element_count/functions.rs:52:38 | LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,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` - --> tests/ui/size_of_in_element_count/functions.rs:45:49 + --> tests/ui/size_of_in_element_count/functions.rs:56:49 | LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,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` - --> tests/ui/size_of_in_element_count/functions.rs:47:41 + --> tests/ui/size_of_in_element_count/functions.rs:59:41 | LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,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` - --> tests/ui/size_of_in_element_count/functions.rs:50:33 + --> tests/ui/size_of_in_element_count/functions.rs:63:33 | LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -113,7 +113,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` - --> tests/ui/size_of_in_element_count/functions.rs:52:29 + --> tests/ui/size_of_in_element_count/functions.rs:66:29 | LL | y.as_ptr().wrapping_sub(size_of::()); | ^^^^^^^^^^^^^^^^ @@ -121,7 +121,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` - --> tests/ui/size_of_in_element_count/functions.rs:54:29 + --> tests/ui/size_of_in_element_count/functions.rs:69:29 | LL | unsafe { y.as_ptr().add(size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -129,7 +129,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` - --> tests/ui/size_of_in_element_count/functions.rs:56:33 + --> tests/ui/size_of_in_element_count/functions.rs:72:33 | LL | y.as_mut_ptr().wrapping_add(size_of::()); | ^^^^^^^^^^^^^^^^ @@ -137,7 +137,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` - --> tests/ui/size_of_in_element_count/functions.rs:58:32 + --> tests/ui/size_of_in_element_count/functions.rs:75:32 | LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,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` - --> tests/ui/size_of_in_element_count/functions.rs:60:36 + --> tests/ui/size_of_in_element_count/functions.rs:78: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 670c6c080eca..06ed216b3422 100644 --- a/tests/ui/size_of_ref.rs +++ b/tests/ui/size_of_ref.rs @@ -11,9 +11,11 @@ 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_ref + size_of_val(&y); - //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference + //~^ size_of_ref + } struct S { @@ -25,6 +27,7 @@ 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 + //~^ size_of_ref + } } diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index bb8f08de531c..0dc64673940e 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -9,7 +9,7 @@ LL | size_of_val(&&x); = help: to override `-D warnings` add `#[allow(clippy::size_of_ref)]` error: argument to `std::mem::size_of_val()` is a reference to a reference - --> tests/ui/size_of_ref.rs:15:5 + --> tests/ui/size_of_ref.rs:16:5 | LL | size_of_val(&y); | ^^^^^^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/size_of_ref.rs:27:9 + --> tests/ui/size_of_ref.rs:29:9 | LL | std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/skip_while_next.rs b/tests/ui/skip_while_next.rs index 8e4cd82cec30..96f4604ad42d 100644 --- a/tests/ui/skip_while_next.rs +++ b/tests/ui/skip_while_next.rs @@ -12,9 +12,11 @@ fn skip_while_next() { // Single-line case. let _ = v.iter().skip_while(|&x| *x < 0).next(); + //~^ skip_while_next // Multi-line case. let _ = v.iter().skip_while(|&x| { + //~^ skip_while_next *x < 0 } ).next(); diff --git a/tests/ui/skip_while_next.stderr b/tests/ui/skip_while_next.stderr index 2c1b9eeba3b6..5db8b4bcb522 100644 --- a/tests/ui/skip_while_next.stderr +++ b/tests/ui/skip_while_next.stderr @@ -9,10 +9,11 @@ LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); = help: to override `-D warnings` add `#[allow(clippy::skip_while_next)]` error: called `skip_while(

).next()` on an `Iterator` - --> tests/ui/skip_while_next.rs:17:13 + --> tests/ui/skip_while_next.rs:18:13 | LL | let _ = v.iter().skip_while(|&x| { | _____________^ +LL | | LL | | *x < 0 LL | | } LL | | ).next(); diff --git a/tests/ui/sliced_string_as_bytes.fixed b/tests/ui/sliced_string_as_bytes.fixed index 469ad27a99b9..16c0daff78fd 100644 --- a/tests/ui/sliced_string_as_bytes.fixed +++ b/tests/ui/sliced_string_as_bytes.fixed @@ -26,8 +26,11 @@ fn main() { let string: String = "dolor sit amet".to_owned(); let bytes = &s.as_bytes()[1..5]; + //~^ sliced_string_as_bytes let bytes = &string.as_bytes()[1..]; + //~^ sliced_string_as_bytes let bytes = &"consectetur adipiscing".as_bytes()[..=5]; + //~^ sliced_string_as_bytes let f = Foo; let bytes = f[0..4].as_bytes(); diff --git a/tests/ui/sliced_string_as_bytes.rs b/tests/ui/sliced_string_as_bytes.rs index 4a4605e5a1ae..67985ae5b984 100644 --- a/tests/ui/sliced_string_as_bytes.rs +++ b/tests/ui/sliced_string_as_bytes.rs @@ -26,8 +26,11 @@ fn main() { let string: String = "dolor sit amet".to_owned(); let bytes = s[1..5].as_bytes(); + //~^ sliced_string_as_bytes let bytes = string[1..].as_bytes(); + //~^ sliced_string_as_bytes let bytes = "consectetur adipiscing"[..=5].as_bytes(); + //~^ sliced_string_as_bytes let f = Foo; let bytes = f[0..4].as_bytes(); diff --git a/tests/ui/sliced_string_as_bytes.stderr b/tests/ui/sliced_string_as_bytes.stderr index 1342f4c01a48..ae7f02781f4b 100644 --- a/tests/ui/sliced_string_as_bytes.stderr +++ b/tests/ui/sliced_string_as_bytes.stderr @@ -8,13 +8,13 @@ LL | let bytes = s[1..5].as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::sliced_string_as_bytes)]` error: calling `as_bytes` after slicing a string - --> tests/ui/sliced_string_as_bytes.rs:29:17 + --> tests/ui/sliced_string_as_bytes.rs:30:17 | LL | let bytes = string[1..].as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&string.as_bytes()[1..]` error: calling `as_bytes` after slicing a string - --> tests/ui/sliced_string_as_bytes.rs:30:17 + --> tests/ui/sliced_string_as_bytes.rs:32:17 | LL | let bytes = "consectetur adipiscing"[..=5].as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&"consectetur adipiscing".as_bytes()[..=5]` diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index 4b30fad409e3..6a09d1f36a66 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -12,13 +12,15 @@ fn extend_vector() { // Extend with constant expression let len = 300; let mut vec1 = Vec::with_capacity(len); - //~^ ERROR: slow zero-filling initialization - //~| NOTE: `-D clippy::slow-vector-initialization` implied by `-D warnings` + //~^ slow_vector_initialization + + vec1.extend(repeat(0).take(len)); // Extend with len expression let mut vec2 = Vec::with_capacity(len - 10); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec2.extend(repeat(0).take(len - 10)); // Extend with mismatching expression should not be warned @@ -26,7 +28,8 @@ fn extend_vector() { vec3.extend(repeat(0).take(2)); let mut vec4 = Vec::with_capacity(len); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec4.extend(repeat(0).take(vec4.capacity())); } @@ -37,11 +40,13 @@ fn mixed_extend_resize_vector() { // Slow initialization let mut resized_vec = Vec::with_capacity(30); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + resized_vec.resize(30, 0); let mut extend_vec = Vec::with_capacity(30); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + extend_vec.extend(repeat(0).take(30)); } @@ -49,7 +54,8 @@ fn resize_vector() { // Resize with constant expression let len = 300; let mut vec1 = Vec::with_capacity(len); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec1.resize(len, 0); // Resize mismatch len @@ -58,16 +64,19 @@ fn resize_vector() { // Resize with len expression let mut vec3 = Vec::with_capacity(len - 10); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec3.resize(len - 10, 0); let mut vec4 = Vec::with_capacity(len); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec4.resize(vec4.capacity(), 0); // Reinitialization should be warned vec1 = Vec::with_capacity(10); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec1.resize(10, 0); } @@ -75,21 +84,25 @@ fn from_empty_vec() { // Resize with constant expression let len = 300; let mut vec1 = Vec::new(); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec1.resize(len, 0); // Resize with len expression let mut vec3 = Vec::new(); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec3.resize(len - 10, 0); // Reinitialization should be warned vec1 = Vec::new(); - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec1.resize(10, 0); vec1 = vec![]; - //~^ ERROR: slow zero-filling initialization + //~^ slow_vector_initialization + vec1.resize(10, 0); macro_rules! x { diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 4a25cafcddf2..67a0b928618a 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -11,110 +11,110 @@ LL | | vec1.extend(repeat(0).take(len)); = help: to override `-D warnings` add `#[allow(clippy::slow_vector_initialization)]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:20:20 + --> tests/ui/slow_vector_initialization.rs:21:20 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ____________________^ -LL | | +... | LL | | vec2.extend(repeat(0).take(len - 10)); | |_________________________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:28:20 + --> tests/ui/slow_vector_initialization.rs:30:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ -LL | | +... | LL | | vec4.extend(repeat(0).take(vec4.capacity())); | |________________________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:39:27 + --> tests/ui/slow_vector_initialization.rs:42:27 | LL | let mut resized_vec = Vec::with_capacity(30); | ___________________________^ -LL | | +... | LL | | resized_vec.resize(30, 0); | |_____________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:43:26 + --> tests/ui/slow_vector_initialization.rs:47:26 | LL | let mut extend_vec = Vec::with_capacity(30); | __________________________^ -LL | | +... | LL | | extend_vec.extend(repeat(0).take(30)); | |_________________________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:51:20 + --> tests/ui/slow_vector_initialization.rs:56:20 | LL | let mut vec1 = Vec::with_capacity(len); | ____________________^ -LL | | +... | LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:60:20 + --> tests/ui/slow_vector_initialization.rs:66:20 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ____________________^ -LL | | +... | LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:64:20 + --> tests/ui/slow_vector_initialization.rs:71:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ -LL | | +... | LL | | vec4.resize(vec4.capacity(), 0); | |___________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:69:12 + --> tests/ui/slow_vector_initialization.rs:77:12 | LL | vec1 = Vec::with_capacity(10); | ____________^ -LL | | +... | LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:77:20 + --> tests/ui/slow_vector_initialization.rs:86:20 | LL | let mut vec1 = Vec::new(); | ____________________^ -LL | | +... | LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:82:20 + --> tests/ui/slow_vector_initialization.rs:92:20 | LL | let mut vec3 = Vec::new(); | ____________________^ -LL | | +... | LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:87:12 + --> tests/ui/slow_vector_initialization.rs:98:12 | LL | vec1 = Vec::new(); | ____________^ -LL | | +... | LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:91:12 + --> tests/ui/slow_vector_initialization.rs:103:12 | LL | vec1 = vec![]; | ____________^ -LL | | +... | LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` diff --git a/tests/ui/stable_sort_primitive.fixed b/tests/ui/stable_sort_primitive.fixed index 97f3a92238d2..b4870ebad2b3 100644 --- a/tests/ui/stable_sort_primitive.fixed +++ b/tests/ui/stable_sort_primitive.fixed @@ -5,18 +5,25 @@ fn main() { // positive examples let mut vec = vec![1, 3, 2]; vec.sort_unstable(); + //~^ stable_sort_primitive let mut vec = vec![false, false, true]; vec.sort_unstable(); + //~^ stable_sort_primitive let mut vec = vec!['a', 'A', 'c']; vec.sort_unstable(); + //~^ stable_sort_primitive let mut vec = vec!["ab", "cd", "ab", "bc"]; vec.sort_unstable(); + //~^ stable_sort_primitive let mut vec = vec![(2, 1), (1, 2), (2, 5)]; vec.sort_unstable(); + //~^ stable_sort_primitive let mut vec = vec![[2, 1], [1, 2], [2, 5]]; vec.sort_unstable(); + //~^ stable_sort_primitive let mut arr = [1, 3, 2]; arr.sort_unstable(); + //~^ stable_sort_primitive // Negative examples: behavior changes if made unstable let mut vec = vec![1, 3, 2]; vec.sort_by_key(|i| i / 2); diff --git a/tests/ui/stable_sort_primitive.rs b/tests/ui/stable_sort_primitive.rs index 26e3d8e74f71..b3fe64efd620 100644 --- a/tests/ui/stable_sort_primitive.rs +++ b/tests/ui/stable_sort_primitive.rs @@ -5,18 +5,25 @@ fn main() { // positive examples let mut vec = vec![1, 3, 2]; vec.sort(); + //~^ stable_sort_primitive let mut vec = vec![false, false, true]; vec.sort(); + //~^ stable_sort_primitive let mut vec = vec!['a', 'A', 'c']; vec.sort(); + //~^ stable_sort_primitive let mut vec = vec!["ab", "cd", "ab", "bc"]; vec.sort(); + //~^ stable_sort_primitive let mut vec = vec![(2, 1), (1, 2), (2, 5)]; vec.sort(); + //~^ stable_sort_primitive let mut vec = vec![[2, 1], [1, 2], [2, 5]]; vec.sort(); + //~^ stable_sort_primitive let mut arr = [1, 3, 2]; arr.sort(); + //~^ stable_sort_primitive // Negative examples: behavior changes if made unstable let mut vec = vec![1, 3, 2]; vec.sort_by_key(|i| i / 2); diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr index 66bd4c79bb28..00b45030139a 100644 --- a/tests/ui/stable_sort_primitive.stderr +++ b/tests/ui/stable_sort_primitive.stderr @@ -9,7 +9,7 @@ LL | vec.sort(); = help: to override `-D warnings` add `#[allow(clippy::stable_sort_primitive)]` error: used `sort` on primitive type `bool` - --> tests/ui/stable_sort_primitive.rs:9:5 + --> tests/ui/stable_sort_primitive.rs:10:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -17,14 +17,6 @@ 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` - --> tests/ui/stable_sort_primitive.rs:11:5 - | -LL | vec.sort(); - | ^^^^^^^^^^ help: try: `vec.sort_unstable()` - | - = note: an unstable sort typically performs faster without any observable difference for this data type - -error: used `sort` on primitive type `str` --> tests/ui/stable_sort_primitive.rs:13:5 | LL | vec.sort(); @@ -32,8 +24,16 @@ 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` + --> tests/ui/stable_sort_primitive.rs:16:5 + | +LL | vec.sort(); + | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort typically performs faster without any observable difference for this data type + error: used `sort` on primitive type `tuple` - --> tests/ui/stable_sort_primitive.rs:15:5 + --> tests/ui/stable_sort_primitive.rs:19:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -41,7 +41,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` - --> tests/ui/stable_sort_primitive.rs:17:5 + --> tests/ui/stable_sort_primitive.rs:22:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -49,7 +49,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` - --> tests/ui/stable_sort_primitive.rs:19:5 + --> tests/ui/stable_sort_primitive.rs:25: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 252b6e5a98c0..3e1ea00a341e 100644 --- a/tests/ui/starts_ends_with.fixed +++ b/tests/ui/starts_ends_with.fixed @@ -5,36 +5,46 @@ fn main() {} #[allow(clippy::unnecessary_operation)] fn starts_with() { "".starts_with(' '); + //~^ chars_next_cmp !"".starts_with(' '); + //~^ chars_next_cmp // Ensure that suggestion is escaped correctly "".starts_with('\n'); + //~^ chars_next_cmp !"".starts_with('\n'); + //~^ chars_next_cmp } fn chars_cmp_with_unwrap() { let s = String::from("foo"); if s.starts_with('f') { + //~^ chars_next_cmp // s.starts_with('f') // Nothing here } if s.ends_with('o') { + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.ends_with('o') { + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if !s.starts_with('f') { + //~^ chars_next_cmp // !s.starts_with('f') // Nothing here } if !s.ends_with('o') { + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } if !s.ends_with('\n') { + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } @@ -43,11 +53,17 @@ fn chars_cmp_with_unwrap() { #[allow(clippy::unnecessary_operation)] fn ends_with() { "".ends_with(' '); + //~^ chars_last_cmp !"".ends_with(' '); + //~^ chars_last_cmp "".ends_with(' '); + //~^ chars_last_cmp !"".ends_with(' '); + //~^ chars_last_cmp // Ensure that suggestion is escaped correctly "".ends_with('\n'); + //~^ chars_last_cmp !"".ends_with('\n'); + //~^ chars_last_cmp } diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index 6c5655f31782..ef7143a455f9 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -5,36 +5,46 @@ fn main() {} #[allow(clippy::unnecessary_operation)] fn starts_with() { "".chars().next() == Some(' '); + //~^ chars_next_cmp Some(' ') != "".chars().next(); + //~^ chars_next_cmp // Ensure that suggestion is escaped correctly "".chars().next() == Some('\n'); + //~^ chars_next_cmp Some('\n') != "".chars().next(); + //~^ chars_next_cmp } fn chars_cmp_with_unwrap() { let s = String::from("foo"); if s.chars().next().unwrap() == 'f' { + //~^ chars_next_cmp // s.starts_with('f') // Nothing here } if s.chars().next_back().unwrap() == 'o' { + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.chars().last().unwrap() == 'o' { + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.chars().next().unwrap() != 'f' { + //~^ chars_next_cmp // !s.starts_with('f') // Nothing here } if s.chars().next_back().unwrap() != 'o' { + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } if s.chars().last().unwrap() != '\n' { + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } @@ -43,11 +53,17 @@ fn chars_cmp_with_unwrap() { #[allow(clippy::unnecessary_operation)] fn ends_with() { "".chars().last() == Some(' '); + //~^ chars_last_cmp Some(' ') != "".chars().last(); + //~^ chars_last_cmp "".chars().next_back() == Some(' '); + //~^ chars_last_cmp Some(' ') != "".chars().next_back(); + //~^ chars_last_cmp // Ensure that suggestion is escaped correctly "".chars().last() == Some('\n'); + //~^ chars_last_cmp Some('\n') != "".chars().last(); + //~^ chars_last_cmp } diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr index cee31f1e4cdd..bcb38f2beb7b 100644 --- a/tests/ui/starts_ends_with.stderr +++ b/tests/ui/starts_ends_with.stderr @@ -8,31 +8,31 @@ LL | "".chars().next() == Some(' '); = help: to override `-D warnings` add `#[allow(clippy::chars_next_cmp)]` error: you should use the `starts_with` method - --> tests/ui/starts_ends_with.rs:8:5 + --> tests/ui/starts_ends_with.rs:9:5 | LL | Some(' ') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')` error: you should use the `starts_with` method - --> tests/ui/starts_ends_with.rs:11:5 + --> tests/ui/starts_ends_with.rs:13:5 | LL | "".chars().next() == Some('\n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('\n')` error: you should use the `starts_with` method - --> tests/ui/starts_ends_with.rs:12:5 + --> tests/ui/starts_ends_with.rs:15:5 | LL | Some('\n') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('\n')` error: you should use the `starts_with` method - --> tests/ui/starts_ends_with.rs:17:8 + --> tests/ui/starts_ends_with.rs:21:8 | LL | if s.chars().next().unwrap() == 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:21:8 + --> tests/ui/starts_ends_with.rs:26:8 | LL | if s.chars().next_back().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` @@ -41,61 +41,61 @@ LL | if s.chars().next_back().unwrap() == 'o' { = help: to override `-D warnings` add `#[allow(clippy::chars_last_cmp)]` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:25:8 + --> tests/ui/starts_ends_with.rs:31:8 | LL | if s.chars().last().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` error: you should use the `starts_with` method - --> tests/ui/starts_ends_with.rs:29:8 + --> tests/ui/starts_ends_with.rs:36:8 | LL | if s.chars().next().unwrap() != 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:33:8 + --> tests/ui/starts_ends_with.rs:41:8 | LL | if s.chars().next_back().unwrap() != 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:37:8 + --> tests/ui/starts_ends_with.rs:46:8 | LL | if s.chars().last().unwrap() != '\n' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('\n')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:45:5 + --> tests/ui/starts_ends_with.rs:55:5 | LL | "".chars().last() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:46:5 + --> tests/ui/starts_ends_with.rs:57:5 | LL | Some(' ') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:47:5 + --> tests/ui/starts_ends_with.rs:59:5 | LL | "".chars().next_back() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:48:5 + --> tests/ui/starts_ends_with.rs:61:5 | LL | Some(' ') != "".chars().next_back(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:51:5 + --> tests/ui/starts_ends_with.rs:65:5 | LL | "".chars().last() == Some('\n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('\n')` error: you should use the `ends_with` method - --> tests/ui/starts_ends_with.rs:52:5 + --> tests/ui/starts_ends_with.rs:67:5 | LL | Some('\n') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('\n')` diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed index ec158ee02de8..ab2e801eee25 100644 --- a/tests/ui/std_instead_of_core.fixed +++ b/tests/ui/std_instead_of_core.fixed @@ -89,3 +89,4 @@ fn msrv_1_76(_: std::net::IpAddr) {} #[clippy::msrv = "1.77"] fn msrv_1_77(_: core::net::IpAddr) {} +//~^ std_instead_of_core diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index 9c3c1658d8fe..f760b3561aed 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -89,3 +89,4 @@ fn msrv_1_76(_: std::net::IpAddr) {} #[clippy::msrv = "1.77"] fn msrv_1_77(_: std::net::IpAddr) {} +//~^ std_instead_of_core diff --git a/tests/ui/str_split.fixed b/tests/ui/str_split.fixed index 57a3c315a877..6aca5051c570 100644 --- a/tests/ui/str_split.fixed +++ b/tests/ui/str_split.fixed @@ -58,25 +58,35 @@ fn main() { // Splitting a `str` variable at "\n" or "\r\n" after trimming should warn let _ = s1.lines(); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s1.lines(); + //~^ str_split_at_newline let _ = s1.lines(); + //~^ str_split_at_newline // Splitting a `String` variable at "\n" or "\r\n" after trimming should warn let _ = s2.lines(); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s2.lines(); + //~^ str_split_at_newline let _ = s2.lines(); + //~^ str_split_at_newline // Splitting a variable that derefs into `str` at "\n" or "\r\n" after trimming should warn. let s3 = DerefsIntoStr { s: s1 }; let _ = s3.lines(); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s3.lines(); + //~^ str_split_at_newline let _ = s3.lines(); + //~^ str_split_at_newline // If the `&str` is generated by a macro then the macro should not be expanded in the suggested fix. let _ = make_str!(s1).lines(); + //~^ str_split_at_newline // CASES THAT SHOULD NOT EMIT A LINT diff --git a/tests/ui/str_split.rs b/tests/ui/str_split.rs index fcff036f2649..11e9862da14b 100644 --- a/tests/ui/str_split.rs +++ b/tests/ui/str_split.rs @@ -58,25 +58,35 @@ fn main() { // Splitting a `str` variable at "\n" or "\r\n" after trimming should warn let _ = s1.trim().split('\n'); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s1.trim().split("\n"); + //~^ str_split_at_newline let _ = s1.trim().split("\r\n"); + //~^ str_split_at_newline // Splitting a `String` variable at "\n" or "\r\n" after trimming should warn let _ = s2.trim().split('\n'); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s2.trim().split("\n"); + //~^ str_split_at_newline let _ = s2.trim().split("\r\n"); + //~^ str_split_at_newline // Splitting a variable that derefs into `str` at "\n" or "\r\n" after trimming should warn. let s3 = DerefsIntoStr { s: s1 }; let _ = s3.trim().split('\n'); + //~^ str_split_at_newline #[allow(clippy::single_char_pattern)] let _ = s3.trim().split("\n"); + //~^ str_split_at_newline let _ = s3.trim().split("\r\n"); + //~^ str_split_at_newline // If the `&str` is generated by a macro then the macro should not be expanded in the suggested fix. let _ = make_str!(s1).trim().split('\n'); + //~^ str_split_at_newline // CASES THAT SHOULD NOT EMIT A LINT diff --git a/tests/ui/str_split.stderr b/tests/ui/str_split.stderr index 7b560468f126..c4eca81004c5 100644 --- a/tests/ui/str_split.stderr +++ b/tests/ui/str_split.stderr @@ -8,55 +8,55 @@ LL | let _ = s1.trim().split('\n'); = help: to override `-D warnings` add `#[allow(clippy::str_split_at_newline)]` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:62:13 + --> tests/ui/str_split.rs:63:13 | LL | let _ = s1.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:63:13 + --> tests/ui/str_split.rs:65:13 | LL | let _ = s1.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:66:13 + --> tests/ui/str_split.rs:69:13 | LL | let _ = s2.trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:68:13 + --> tests/ui/str_split.rs:72:13 | LL | let _ = s2.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:69:13 + --> tests/ui/str_split.rs:74:13 | LL | let _ = s2.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:73:13 + --> tests/ui/str_split.rs:79:13 | LL | let _ = s3.trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:75:13 + --> tests/ui/str_split.rs:82:13 | LL | let _ = s3.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:76:13 + --> tests/ui/str_split.rs:84:13 | LL | let _ = s3.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:79:13 + --> tests/ui/str_split.rs:88:13 | LL | let _ = make_str!(s1).trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `make_str!(s1).lines()` diff --git a/tests/ui/str_to_string.fixed b/tests/ui/str_to_string.fixed index 52e40b45a8bd..4977e9c944d1 100644 --- a/tests/ui/str_to_string.fixed +++ b/tests/ui/str_to_string.fixed @@ -2,8 +2,10 @@ fn main() { let hello = "hello world".to_owned(); - //~^ ERROR: `to_string()` called on a `&str` + //~^ str_to_string + let msg = &hello[..]; msg.to_owned(); - //~^ ERROR: `to_string()` called on a `&str` + //~^ str_to_string + } diff --git a/tests/ui/str_to_string.rs b/tests/ui/str_to_string.rs index f93b289c29ab..f710761471b6 100644 --- a/tests/ui/str_to_string.rs +++ b/tests/ui/str_to_string.rs @@ -2,8 +2,10 @@ fn main() { let hello = "hello world".to_string(); - //~^ ERROR: `to_string()` called on a `&str` + //~^ str_to_string + let msg = &hello[..]; msg.to_string(); - //~^ ERROR: `to_string()` called on a `&str` + //~^ str_to_string + } diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr index a761d96cd6b1..cb7b6b48843a 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(); = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]` error: `to_string()` called on a `&str` - --> tests/ui/str_to_string.rs:7:5 + --> tests/ui/str_to_string.rs:8:5 | LL | msg.to_string(); | ^^^^^^^^^^^^^^^ help: try: `msg.to_owned()` diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index 61c812f16c8c..5c7d13ebcd58 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -11,10 +11,12 @@ fn main() { for _ in 1..3 { x = x + "."; + //~^ string_add } let y = String::new(); let z = y + "..."; + //~^ string_add assert_eq!(&x, &z); diff --git a/tests/ui/string_add.stderr b/tests/ui/string_add.stderr index 74ff7372e21a..084a439410f8 100644 --- a/tests/ui/string_add.stderr +++ b/tests/ui/string_add.stderr @@ -8,7 +8,7 @@ LL | x = x + "."; = help: to override `-D warnings` add `#[allow(clippy::string_add)]` error: you added something to a string. Consider using `String::push_str()` instead - --> tests/ui/string_add.rs:17:13 + --> tests/ui/string_add.rs:18:13 | LL | let z = y + "..."; | ^^^^^^^^^ diff --git a/tests/ui/string_add_assign.fixed b/tests/ui/string_add_assign.fixed index 31d84831d09a..a86a304684f2 100644 --- a/tests/ui/string_add_assign.fixed +++ b/tests/ui/string_add_assign.fixed @@ -6,6 +6,8 @@ fn main() { for _ in 1..3 { x += "."; + //~^ string_add_assign + //~| assign_op_pattern } let y = String::new(); @@ -15,5 +17,6 @@ fn main() { let mut x = 1; x += 1; + //~^ assign_op_pattern assert_eq!(2, x); } diff --git a/tests/ui/string_add_assign.rs b/tests/ui/string_add_assign.rs index cdea91573cc7..042e33cf8413 100644 --- a/tests/ui/string_add_assign.rs +++ b/tests/ui/string_add_assign.rs @@ -6,6 +6,8 @@ fn main() { for _ in 1..3 { x = x + "."; + //~^ string_add_assign + //~| assign_op_pattern } let y = String::new(); @@ -15,5 +17,6 @@ fn main() { let mut x = 1; x = x + 1; + //~^ assign_op_pattern assert_eq!(2, x); } diff --git a/tests/ui/string_add_assign.stderr b/tests/ui/string_add_assign.stderr index 50f970084e6b..198772747927 100644 --- a/tests/ui/string_add_assign.stderr +++ b/tests/ui/string_add_assign.stderr @@ -17,7 +17,7 @@ LL | x = x + "."; = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> tests/ui/string_add_assign.rs:17:5 + --> tests/ui/string_add_assign.rs:19: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 142cb6a34980..17d3d927830f 100644 --- a/tests/ui/string_extend.fixed +++ b/tests/ui/string_extend.fixed @@ -14,12 +14,15 @@ fn main() { s.push_str(abc); s.push_str(abc); + //~^ string_extend_chars s.push_str("abc"); s.push_str("abc"); + //~^ string_extend_chars s.push_str(&def); s.push_str(&def); + //~^ string_extend_chars s.extend(abc.chars().skip(1)); s.extend("abc".chars().skip(1)); @@ -30,4 +33,5 @@ fn main() { // issue #9735 s.push_str(&abc[0..2]); + //~^ string_extend_chars } diff --git a/tests/ui/string_extend.rs b/tests/ui/string_extend.rs index 41c0d29fae9c..e2d54f479439 100644 --- a/tests/ui/string_extend.rs +++ b/tests/ui/string_extend.rs @@ -14,12 +14,15 @@ fn main() { s.push_str(abc); s.extend(abc.chars()); + //~^ string_extend_chars s.push_str("abc"); s.extend("abc".chars()); + //~^ string_extend_chars s.push_str(&def); s.extend(def.chars()); + //~^ string_extend_chars s.extend(abc.chars().skip(1)); s.extend("abc".chars().skip(1)); @@ -30,4 +33,5 @@ fn main() { // issue #9735 s.extend(abc[0..2].chars()); + //~^ string_extend_chars } diff --git a/tests/ui/string_extend.stderr b/tests/ui/string_extend.stderr index fadda786aacb..52aad5a02f6d 100644 --- a/tests/ui/string_extend.stderr +++ b/tests/ui/string_extend.stderr @@ -8,19 +8,19 @@ LL | s.extend(abc.chars()); = help: to override `-D warnings` add `#[allow(clippy::string_extend_chars)]` error: calling `.extend(_.chars())` - --> tests/ui/string_extend.rs:19:5 + --> tests/ui/string_extend.rs:20:5 | LL | s.extend("abc".chars()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str("abc")` error: calling `.extend(_.chars())` - --> tests/ui/string_extend.rs:22:5 + --> tests/ui/string_extend.rs:24:5 | LL | s.extend(def.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&def)` error: calling `.extend(_.chars())` - --> tests/ui/string_extend.rs:32:5 + --> tests/ui/string_extend.rs:35: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 6aa5a95c6f40..193217114d88 100644 --- a/tests/ui/string_from_utf8_as_bytes.fixed +++ b/tests/ui/string_from_utf8_as_bytes.fixed @@ -2,4 +2,5 @@ fn main() { let _ = Some(&"Hello World!"[6..11]); + //~^ string_from_utf8_as_bytes } diff --git a/tests/ui/string_from_utf8_as_bytes.rs b/tests/ui/string_from_utf8_as_bytes.rs index c8717f7950bd..49beb19ee40f 100644 --- a/tests/ui/string_from_utf8_as_bytes.rs +++ b/tests/ui/string_from_utf8_as_bytes.rs @@ -2,4 +2,5 @@ fn main() { let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); + //~^ string_from_utf8_as_bytes } diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed index 225d4e90c4e2..2a86dffbc762 100644 --- a/tests/ui/string_lit_as_bytes.fixed +++ b/tests/ui/string_lit_as_bytes.fixed @@ -9,16 +9,21 @@ extern crate macro_rules; macro_rules! b { ($b:literal) => { const B: &[u8] = b"warning"; + //~^ string_lit_as_bytes }; } fn str_lit_as_bytes() { let bs = b"hello there"; + //~^ string_lit_as_bytes let bs = br###"raw string with 3# plus " ""###; + //~^ string_lit_as_bytes let bs = b"lit to string".to_vec(); + //~^ string_lit_as_bytes let bs = b"lit to owned".to_vec(); + //~^ string_lit_as_bytes b!("warning"); @@ -36,8 +41,10 @@ fn str_lit_as_bytes() { let current_version = env!("CARGO_PKG_VERSION").as_bytes(); let includestr = include_bytes!("string_lit_as_bytes.rs"); + //~^ string_lit_as_bytes let _ = b"string with newline\t\n"; + //~^ string_lit_as_bytes let _ = match "x".as_bytes() { b"xx" => 0, diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs index 3d116214ca42..785d8f1e0f6b 100644 --- a/tests/ui/string_lit_as_bytes.rs +++ b/tests/ui/string_lit_as_bytes.rs @@ -9,16 +9,21 @@ extern crate macro_rules; macro_rules! b { ($b:literal) => { const B: &[u8] = $b.as_bytes(); + //~^ string_lit_as_bytes }; } fn str_lit_as_bytes() { let bs = "hello there".as_bytes(); + //~^ string_lit_as_bytes let bs = r###"raw string with 3# plus " ""###.as_bytes(); + //~^ string_lit_as_bytes let bs = "lit to string".to_string().into_bytes(); + //~^ string_lit_as_bytes let bs = "lit to owned".to_owned().into_bytes(); + //~^ string_lit_as_bytes b!("warning"); @@ -36,8 +41,10 @@ fn str_lit_as_bytes() { let current_version = env!("CARGO_PKG_VERSION").as_bytes(); let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); + //~^ string_lit_as_bytes let _ = "string with newline\t\n".as_bytes(); + //~^ string_lit_as_bytes let _ = match "x".as_bytes() { b"xx" => 0, diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index 66b3e6f9462d..9388fbdc775d 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 - --> tests/ui/string_lit_as_bytes.rs:16:14 + --> tests/ui/string_lit_as_bytes.rs:17:14 | LL | let bs = "hello there".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` @@ -8,19 +8,19 @@ LL | let bs = "hello there".as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::string_lit_as_bytes)]` error: calling `as_bytes()` on a string literal - --> tests/ui/string_lit_as_bytes.rs:18:14 + --> tests/ui/string_lit_as_bytes.rs:20: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 - --> tests/ui/string_lit_as_bytes.rs:20:14 + --> tests/ui/string_lit_as_bytes.rs:23: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 - --> tests/ui/string_lit_as_bytes.rs:21:14 + --> tests/ui/string_lit_as_bytes.rs:25: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()` @@ -37,13 +37,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!(..)` - --> tests/ui/string_lit_as_bytes.rs:38:22 + --> tests/ui/string_lit_as_bytes.rs:43: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 - --> tests/ui/string_lit_as_bytes.rs:40:13 + --> tests/ui/string_lit_as_bytes.rs:46: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 03e20c16ee63..cf05a2c2e835 100644 --- a/tests/ui/string_lit_chars_any.fixed +++ b/tests/ui/string_lit_chars_any.fixed @@ -16,11 +16,16 @@ impl NotStringLit { fn main() { let c = 'c'; matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any #[rustfmt::skip] matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); + //~^ string_lit_chars_any // Do not lint NotStringLit.chars().any(|x| x == c); "\\.+*?()|[]{}^$#&-~".chars().any(|x| { diff --git a/tests/ui/string_lit_chars_any.rs b/tests/ui/string_lit_chars_any.rs index 12e6ffb6a9c4..22cfb784ed7d 100644 --- a/tests/ui/string_lit_chars_any.rs +++ b/tests/ui/string_lit_chars_any.rs @@ -16,11 +16,16 @@ impl NotStringLit { fn main() { let c = 'c'; "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); + //~^ string_lit_chars_any r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); + //~^ string_lit_chars_any "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); + //~^ string_lit_chars_any r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); + //~^ string_lit_chars_any #[rustfmt::skip] "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); + //~^ string_lit_chars_any // Do not lint NotStringLit.chars().any(|x| x == c); "\\.+*?()|[]{}^$#&-~".chars().any(|x| { diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index 4d3ca98e6237..b6bfb8d4b791 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -12,7 +12,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> tests/ui/string_lit_chars_any.rs:19:5 + --> tests/ui/string_lit_chars_any.rs:20:5 | LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> tests/ui/string_lit_chars_any.rs:20:5 + --> tests/ui/string_lit_chars_any.rs:22:5 | LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> tests/ui/string_lit_chars_any.rs:21:5 + --> tests/ui/string_lit_chars_any.rs:24:5 | LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> tests/ui/string_lit_chars_any.rs:23:5 + --> tests/ui/string_lit_chars_any.rs:27:5 | LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/string_slice.rs b/tests/ui/string_slice.rs index dc519493a4dd..9251b348af3f 100644 --- a/tests/ui/string_slice.rs +++ b/tests/ui/string_slice.rs @@ -5,15 +5,19 @@ use std::borrow::Cow; 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` + //~^ string_slice + + let m = "Mötörhead"; &m[2..5]; - //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~^ string_slice + let s = String::from(m); &s[0..2]; - //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~^ string_slice + let a = Cow::Borrowed("foo"); &a[0..3]; - //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~^ string_slice + } diff --git a/tests/ui/string_slice.stderr b/tests/ui/string_slice.stderr index bc0fcde34b82..4932152af6b6 100644 --- a/tests/ui/string_slice.stderr +++ b/tests/ui/string_slice.stderr @@ -8,19 +8,19 @@ LL | &"Ölkanne"[1..]; = help: to override `-D warnings` add `#[allow(clippy::string_slice)]` error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:11:6 + --> tests/ui/string_slice.rs:12:6 | LL | &m[2..5]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:14:6 + --> tests/ui/string_slice.rs:16:6 | LL | &s[0..2]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:17:6 + --> tests/ui/string_slice.rs:20:6 | LL | &a[0..3]; | ^^^^^^^ diff --git a/tests/ui/string_to_string.rs b/tests/ui/string_to_string.rs index 007685b60179..e3f5b6cf3bdc 100644 --- a/tests/ui/string_to_string.rs +++ b/tests/ui/string_to_string.rs @@ -4,5 +4,6 @@ fn main() { let mut message = String::from("Hello"); let mut v = message.to_string(); - //~^ ERROR: `to_string()` called on a `String` + //~^ string_to_string + } diff --git a/tests/ui/strlen_on_c_strings.fixed b/tests/ui/strlen_on_c_strings.fixed index 1e7d04ffb9df..31ed1cf03a2d 100644 --- a/tests/ui/strlen_on_c_strings.fixed +++ b/tests/ui/strlen_on_c_strings.fixed @@ -11,22 +11,29 @@ fn main() { // CString let cstring = CString::new("foo").expect("CString::new failed"); let _ = cstring.as_bytes().len(); + //~^ strlen_on_c_strings // CStr let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); let _ = cstr.to_bytes().len(); + //~^ strlen_on_c_strings let _ = cstr.to_bytes().len(); + //~^ strlen_on_c_strings let pcstr: *const &CStr = &cstr; let _ = unsafe { (*pcstr).to_bytes().len() }; + //~^ strlen_on_c_strings unsafe fn unsafe_identity(x: T) -> T { x } let _ = unsafe { unsafe_identity(cstr).to_bytes().len() }; + //~^ strlen_on_c_strings let _ = unsafe { unsafe_identity(cstr) }.to_bytes().len(); + //~^ strlen_on_c_strings let f: unsafe fn(_) -> _ = unsafe_identity; let _ = unsafe { f(cstr).to_bytes().len() }; + //~^ strlen_on_c_strings } diff --git a/tests/ui/strlen_on_c_strings.rs b/tests/ui/strlen_on_c_strings.rs index c3ad03591d4e..0f3798c9fd8a 100644 --- a/tests/ui/strlen_on_c_strings.rs +++ b/tests/ui/strlen_on_c_strings.rs @@ -11,22 +11,29 @@ fn main() { // CString let cstring = CString::new("foo").expect("CString::new failed"); let _ = unsafe { libc::strlen(cstring.as_ptr()) }; + //~^ strlen_on_c_strings // CStr let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"); let _ = unsafe { libc::strlen(cstr.as_ptr()) }; + //~^ strlen_on_c_strings let _ = unsafe { strlen(cstr.as_ptr()) }; + //~^ strlen_on_c_strings let pcstr: *const &CStr = &cstr; let _ = unsafe { strlen((*pcstr).as_ptr()) }; + //~^ strlen_on_c_strings unsafe fn unsafe_identity(x: T) -> T { x } let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; + //~^ strlen_on_c_strings let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; + //~^ strlen_on_c_strings let f: unsafe fn(_) -> _ = unsafe_identity; let _ = unsafe { strlen(f(cstr).as_ptr()) }; + //~^ strlen_on_c_strings } diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index 8c2a7692659c..b8619fa2df30 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -8,37 +8,37 @@ LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; = help: to override `-D warnings` add `#[allow(clippy::strlen_on_c_strings)]` error: using `libc::strlen` on a `CString` or `CStr` value - --> tests/ui/strlen_on_c_strings.rs:17:13 + --> tests/ui/strlen_on_c_strings.rs:18: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 - --> tests/ui/strlen_on_c_strings.rs:19:13 + --> tests/ui/strlen_on_c_strings.rs:21:13 | LL | let _ = unsafe { strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> tests/ui/strlen_on_c_strings.rs:22:22 + --> tests/ui/strlen_on_c_strings.rs:25:22 | LL | let _ = unsafe { strlen((*pcstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*pcstr).to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> tests/ui/strlen_on_c_strings.rs:27:22 + --> tests/ui/strlen_on_c_strings.rs:31: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 - --> tests/ui/strlen_on_c_strings.rs:28:13 + --> tests/ui/strlen_on_c_strings.rs:33: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 - --> tests/ui/strlen_on_c_strings.rs:31:22 + --> tests/ui/strlen_on_c_strings.rs:37:22 | LL | let _ = unsafe { strlen(f(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f(cstr).to_bytes().len()` diff --git a/tests/ui/struct_excessive_bools.rs b/tests/ui/struct_excessive_bools.rs index 8137ce7a81c5..f509c3143a86 100644 --- a/tests/ui/struct_excessive_bools.rs +++ b/tests/ui/struct_excessive_bools.rs @@ -20,7 +20,8 @@ struct Foo { } struct BadFoo { - //~^ ERROR: more than 3 bools in a struct +//~^ struct_excessive_bools + a: bool, b: bool, c: bool, @@ -37,7 +38,8 @@ struct Bar { fn main() { struct FooFoo { - //~^ ERROR: more than 3 bools in a struct + //~^ struct_excessive_bools + a: bool, b: bool, c: bool, diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index bdf6f0b7a1da..573af45355a6 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -3,9 +3,9 @@ error: more than 3 bools in a struct | LL | / struct BadFoo { LL | | +LL | | LL | | a: bool, -LL | | b: bool, -LL | | c: bool, +... | LL | | d: bool, LL | | } | |_^ @@ -15,13 +15,13 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: more than 3 bools in a struct - --> tests/ui/struct_excessive_bools.rs:39:5 + --> tests/ui/struct_excessive_bools.rs:40:5 | LL | / struct FooFoo { LL | | +LL | | LL | | a: bool, -LL | | b: bool, -LL | | c: bool, +... | LL | | d: bool, LL | | } | |_____^ diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs index 7c8867bd0fa3..3dce530efffa 100644 --- a/tests/ui/struct_fields.rs +++ b/tests/ui/struct_fields.rs @@ -339,7 +339,9 @@ struct Use { use_foo: bool, //~^ ERROR: field name starts with the struct's name use_bar: bool, + //~^ struct_field_names use_baz: bool, + //~^ struct_field_names } fn main() {} diff --git a/tests/ui/struct_fields.stderr b/tests/ui/struct_fields.stderr index cfda18c708c0..79186cc1cfd8 100644 --- a/tests/ui/struct_fields.stderr +++ b/tests/ui/struct_fields.stderr @@ -276,7 +276,7 @@ LL | use_bar: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:342:5 + --> tests/ui/struct_fields.rs:343:5 | LL | use_baz: bool, | ^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index 07280351e76c..b9207b1b3f91 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -12,16 +12,18 @@ 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` + //~^ suspicious_arithmetic_impl + + } } 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` + //~^ suspicious_op_assign_impl + + } } @@ -35,7 +37,8 @@ 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 + //~^ suspicious_op_assign_impl + } } @@ -74,7 +77,8 @@ impl Rem for Foo { fn rem(self, other: Self) -> Self { Foo(self.0 / other.0) - //~^ ERROR: suspicious use of `/` in `Rem` impl + //~^ suspicious_arithmetic_impl + } } @@ -83,7 +87,8 @@ impl BitAnd for Foo { fn bitand(self, other: Self) -> Self { Foo(self.0 | other.0) - //~^ ERROR: suspicious use of `|` in `BitAnd` impl + //~^ suspicious_arithmetic_impl + } } @@ -92,7 +97,8 @@ impl BitOr for Foo { fn bitor(self, other: Self) -> Self { Foo(self.0 ^ other.0) - //~^ ERROR: suspicious use of `^` in `BitOr` impl + //~^ suspicious_arithmetic_impl + } } @@ -101,7 +107,8 @@ impl BitXor for Foo { fn bitxor(self, other: Self) -> Self { Foo(self.0 & other.0) - //~^ ERROR: suspicious use of `&` in `BitXor` impl + //~^ suspicious_arithmetic_impl + } } @@ -110,7 +117,8 @@ impl Shl for Foo { fn shl(self, other: Self) -> Self { Foo(self.0 >> other.0) - //~^ ERROR: suspicious use of `>>` in `Shl` impl + //~^ suspicious_arithmetic_impl + } } @@ -119,7 +127,8 @@ impl Shr for Foo { fn shr(self, other: Self) -> Self { Foo(self.0 << other.0) - //~^ ERROR: suspicious use of `<<` in `Shr` impl + //~^ suspicious_arithmetic_impl + } } diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index 1bfca49a635d..a392aa16f1d4 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -8,7 +8,7 @@ LL | Foo(self.0 - other.0) = help: to override `-D warnings` add `#[allow(clippy::suspicious_arithmetic_impl)]` error: suspicious use of `-` in `AddAssign` impl - --> tests/ui/suspicious_arithmetic_impl.rs:22:23 + --> tests/ui/suspicious_arithmetic_impl.rs:23:23 | LL | *self = *self - other; | ^ @@ -17,43 +17,43 @@ LL | *self = *self - other; = help: to override `-D warnings` add `#[allow(clippy::suspicious_op_assign_impl)]` error: suspicious use of `/` in `MulAssign` impl - --> tests/ui/suspicious_arithmetic_impl.rs:37:16 + --> tests/ui/suspicious_arithmetic_impl.rs:39:16 | LL | self.0 /= other.0; | ^^ error: suspicious use of `/` in `Rem` impl - --> tests/ui/suspicious_arithmetic_impl.rs:76:20 + --> tests/ui/suspicious_arithmetic_impl.rs:79:20 | LL | Foo(self.0 / other.0) | ^ error: suspicious use of `|` in `BitAnd` impl - --> tests/ui/suspicious_arithmetic_impl.rs:85:20 + --> tests/ui/suspicious_arithmetic_impl.rs:89:20 | LL | Foo(self.0 | other.0) | ^ error: suspicious use of `^` in `BitOr` impl - --> tests/ui/suspicious_arithmetic_impl.rs:94:20 + --> tests/ui/suspicious_arithmetic_impl.rs:99:20 | LL | Foo(self.0 ^ other.0) | ^ error: suspicious use of `&` in `BitXor` impl - --> tests/ui/suspicious_arithmetic_impl.rs:103:20 + --> tests/ui/suspicious_arithmetic_impl.rs:109:20 | LL | Foo(self.0 & other.0) | ^ error: suspicious use of `>>` in `Shl` impl - --> tests/ui/suspicious_arithmetic_impl.rs:112:20 + --> tests/ui/suspicious_arithmetic_impl.rs:119:20 | LL | Foo(self.0 >> other.0) | ^^ error: suspicious use of `<<` in `Shr` impl - --> tests/ui/suspicious_arithmetic_impl.rs:121:20 + --> tests/ui/suspicious_arithmetic_impl.rs:129: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 704d6ea1bb83..5ab070f88dcf 100644 --- a/tests/ui/suspicious_command_arg_space.fixed +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -2,10 +2,12 @@ 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` + //~^ suspicious_command_arg_space + + std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); - //~^ ERROR: single argument that looks like it should be multiple arguments + //~^ suspicious_command_arg_space + // 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 2a2a7557381c..0017bd44dbfe 100644 --- a/tests/ui/suspicious_command_arg_space.rs +++ b/tests/ui/suspicious_command_arg_space.rs @@ -2,10 +2,12 @@ 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` + //~^ suspicious_command_arg_space + + std::process::Command::new("cat").arg("--number file").spawn().unwrap(); - //~^ ERROR: single argument that looks like it should be multiple arguments + //~^ suspicious_command_arg_space + // 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 6fd07d07d7be..f4d7d79def14 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -12,7 +12,7 @@ LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap | ~~~~ ~~~~~~~~~~~~~~~ error: single argument that looks like it should be multiple arguments - --> tests/ui/suspicious_command_arg_space.rs:7:43 + --> tests/ui/suspicious_command_arg_space.rs:8:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 614fc03571e5..58f6ebdb4c7c 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -3,10 +3,12 @@ //! Real module documentation. //! Fake module documentation. +//~^ suspicious_doc_comments fn baz() {} pub mod singleline_outer_doc { //! This module contains useful functions. + //~^ suspicious_doc_comments pub fn bar() {} } @@ -19,6 +21,7 @@ pub mod singleline_inner_doc { pub mod multiline_outer_doc { /*! This module contains useful functions. + //~^ suspicious_doc_comments */ pub fn bar() {} @@ -33,6 +36,7 @@ pub mod multiline_inner_doc { pub mod multiline_outer_doc2 { //! This module + //~^ suspicious_doc_comments //! contains //! useful functions. @@ -41,6 +45,7 @@ pub mod multiline_outer_doc2 { pub mod multiline_outer_doc3 { //! a + //~^ suspicious_doc_comments //! b /// c @@ -49,12 +54,14 @@ pub mod multiline_outer_doc3 { pub mod multiline_outer_doc4 { //! a + //~^ suspicious_doc_comments /// b pub fn bar() {} } pub mod multiline_outer_doc_gap { //! a + //~^ suspicious_doc_comments //! b pub fn bar() {} @@ -67,6 +74,7 @@ pub mod multiline_outer_doc_commented { pub mod outer_doc_macro { //! Very cool macro + //~^ suspicious_doc_comments macro_rules! x { () => {}; } @@ -74,6 +82,7 @@ pub mod outer_doc_macro { pub mod useless_outer_doc { //! Huh. + //~^ suspicious_doc_comments use std::mem; } diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index 7dcba0fefc98..26ee028b8c57 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -3,10 +3,12 @@ //! Real module documentation. ///! Fake module documentation. +//~^ suspicious_doc_comments fn baz() {} pub mod singleline_outer_doc { ///! This module contains useful functions. + //~^ suspicious_doc_comments pub fn bar() {} } @@ -19,6 +21,7 @@ pub mod singleline_inner_doc { pub mod multiline_outer_doc { /**! This module contains useful functions. + //~^ suspicious_doc_comments */ pub fn bar() {} @@ -33,6 +36,7 @@ pub mod multiline_inner_doc { pub mod multiline_outer_doc2 { ///! This module + //~^ suspicious_doc_comments ///! contains ///! useful functions. @@ -41,6 +45,7 @@ pub mod multiline_outer_doc2 { pub mod multiline_outer_doc3 { ///! a + //~^ suspicious_doc_comments ///! b /// c @@ -49,12 +54,14 @@ pub mod multiline_outer_doc3 { pub mod multiline_outer_doc4 { ///! a + //~^ suspicious_doc_comments /// b pub fn bar() {} } pub mod multiline_outer_doc_gap { ///! a + //~^ suspicious_doc_comments ///! b pub fn bar() {} @@ -67,6 +74,7 @@ pub mod multiline_outer_doc_commented { pub mod outer_doc_macro { ///! Very cool macro + //~^ suspicious_doc_comments macro_rules! x { () => {}; } @@ -74,6 +82,7 @@ pub mod outer_doc_macro { pub mod useless_outer_doc { ///! Huh. + //~^ suspicious_doc_comments use std::mem; } diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index f12053b1595a..8982e98b4daa 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -12,7 +12,7 @@ LL | //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:9:5 + --> tests/ui/suspicious_doc_comments.rs:10:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,22 +23,25 @@ LL | //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:21:5 + --> tests/ui/suspicious_doc_comments.rs:23:5 | LL | / /**! This module contains useful functions. +LL | | LL | | */ | |_______^ | help: use an inner doc comment to document the parent module or crate | LL ~ /*! This module contains useful functions. +LL + LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:35:5 + --> tests/ui/suspicious_doc_comments.rs:38:5 | LL | / ///! This module +LL | | LL | | ///! contains LL | | ///! useful functions. | |__________________________^ @@ -46,36 +49,13 @@ LL | | ///! useful functions. help: use an inner doc comment to document the parent module or crate | LL ~ //! This module +LL | LL ~ //! contains LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:43:5 - | -LL | / ///! a -LL | | ///! b - | |__________^ - | -help: use an inner doc comment to document the parent module or crate - | -LL ~ //! a -LL ~ //! b - | - -error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:51:5 - | -LL | ///! a - | ^^^^^^ - | -help: use an inner doc comment to document the parent module or crate - | -LL | //! a - | - -error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:57:5 + --> tests/ui/suspicious_doc_comments.rs:47:5 | LL | / ///! a LL | | @@ -90,7 +70,34 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:69:5 + --> tests/ui/suspicious_doc_comments.rs:56:5 + | +LL | ///! a + | ^^^^^^ + | +help: use an inner doc comment to document the parent module or crate + | +LL | //! a + | + +error: this is an outer doc comment and does not apply to the parent module or crate + --> tests/ui/suspicious_doc_comments.rs:63:5 + | +LL | / ///! a +... | +LL | | ///! b + | |__________^ + | +help: use an inner doc comment to document the parent module or crate + | +LL ~ //! a +LL | +LL | +LL ~ //! b + | + +error: this is an outer doc comment and does not apply to the parent module or crate + --> tests/ui/suspicious_doc_comments.rs:76:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +108,7 @@ LL | //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:76:5 + --> tests/ui/suspicious_doc_comments.rs:84:5 | LL | ///! Huh. | ^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 9e9c4775748c..255c6f7237df 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -2,15 +2,17 @@ #![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` +//~^ suspicious_doc_comments + + ///! b /// c ///! d pub fn foo() {} ///! a -//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate +//~^ suspicious_doc_comments + ///! b /// c ///! d diff --git a/tests/ui/suspicious_doc_comments_unfixable.stderr b/tests/ui/suspicious_doc_comments_unfixable.stderr index d15f16f7c503..ff4cb3358a81 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -2,9 +2,7 @@ error: this is an outer doc comment and does not apply to the parent module or c --> tests/ui/suspicious_doc_comments_unfixable.rs:4:1 | LL | / ///! a -LL | | -LL | | -LL | | ///! b +... | LL | | /// c LL | | ///! d | |______^ @@ -16,16 +14,18 @@ help: use an inner doc comment to document the parent module or crate LL + //! a LL | 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 - --> tests/ui/suspicious_doc_comments_unfixable.rs:12:1 + --> tests/ui/suspicious_doc_comments_unfixable.rs:13:1 | LL | / ///! a LL | | +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -35,6 +35,7 @@ help: use an inner doc comment to document the parent module or crate | LL + //! a LL | +LL | LL + //! b LL | /// c LL + //! d diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index 3d5c892eb606..7e57684bd437 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -20,10 +20,12 @@ fn main() { // weird `else` formatting: if foo() { } { + //~^ suspicious_else_formatting } if foo() { } if foo() { + //~^ suspicious_else_formatting } let _ = { // if as the last expression @@ -31,6 +33,7 @@ fn main() { if foo() { } if foo() { + //~^ suspicious_else_formatting } else { } @@ -39,6 +42,7 @@ fn main() { let _ = { // if in the middle of a block if foo() { } if foo() { + //~^ suspicious_else_formatting } else { } @@ -50,6 +54,7 @@ fn main() { } else { } + //~^^^ suspicious_else_formatting // This is fine, though weird. Allman style braces on the else. if foo() { @@ -62,12 +67,14 @@ fn main() { } else if foo() { // the span of the above error should continue here } + //~^^^ suspicious_else_formatting if foo() { } else if foo() { // the span of the above error should continue here } + //~^^^^ suspicious_else_formatting // those are ok: if foo() { @@ -92,7 +99,6 @@ fn main() { // Almost Allman style braces. Lint these. if foo() { } - else { @@ -105,6 +111,7 @@ fn main() { { } + //~^^^^^^ suspicious_else_formatting // #3864 - Allman style braces if foo() diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index 28c5a2d904ce..cf2788b67d07 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -9,7 +9,7 @@ LL | } { = help: to override `-D warnings` add `#[allow(clippy::suspicious_else_formatting)]` error: this looks like an `else if` but the `else` is missing - --> tests/ui/suspicious_else_formatting.rs:26:6 + --> tests/ui/suspicious_else_formatting.rs:27:6 | LL | } if foo() { | ^ @@ -17,7 +17,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> tests/ui/suspicious_else_formatting.rs:33:10 + --> tests/ui/suspicious_else_formatting.rs:35:10 | LL | } if foo() { | ^ @@ -25,7 +25,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this looks like an `else if` but the `else` is missing - --> tests/ui/suspicious_else_formatting.rs:41:10 + --> tests/ui/suspicious_else_formatting.rs:44:10 | LL | } if foo() { | ^ @@ -33,7 +33,7 @@ LL | } if foo() { = note: to remove this lint, add the missing `else` or add a new line before the second `if` error: this is an `else {..}` but the formatting might hide it - --> tests/ui/suspicious_else_formatting.rs:50:6 + --> tests/ui/suspicious_else_formatting.rs:54:6 | LL | } else | ______^ @@ -42,19 +42,19 @@ LL | | { | = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` -error: this is an `else if` but the formatting might hide it - --> tests/ui/suspicious_else_formatting.rs:62:6 - | -LL | } else - | ______^ -LL | | if foo() { // the span of the above error should continue here - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` - error: this is an `else if` but the formatting might hide it --> tests/ui/suspicious_else_formatting.rs:67:6 | +LL | } else + | ______^ +LL | | if foo() { // the span of the above error should continue here + | |____^ + | + = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` + +error: this is an `else if` but the formatting might hide it + --> tests/ui/suspicious_else_formatting.rs:73:6 + | LL | } | ______^ LL | | else @@ -64,19 +64,7 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else {..}` but the formatting might hide it - --> tests/ui/suspicious_else_formatting.rs:94:6 - | -LL | } - | ______^ -LL | | -LL | | else -LL | | { - | |____^ - | - = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` - -error: this is an `else {..}` but the formatting might hide it - --> tests/ui/suspicious_else_formatting.rs:102:6 + --> tests/ui/suspicious_else_formatting.rs:108:6 | LL | } | ______^ @@ -87,5 +75,5 @@ LL | | { | = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs index d4a52cb110fb..3e3035a68f49 100644 --- a/tests/ui/suspicious_map.rs +++ b/tests/ui/suspicious_map.rs @@ -3,11 +3,13 @@ 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()` + //~^ suspicious_map + 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()` + //~^ suspicious_map + } fn negative() { diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index 769adebaede7..7c08168f0c20 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -9,7 +9,7 @@ LL | let _ = (0..3).map(|x| x + 2).count(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]` error: this call to `map()` won't have an effect on the call to `count()` - --> tests/ui/suspicious_map.rs:9:13 + --> tests/ui/suspicious_map.rs:10:13 | LL | let _ = (0..3).map(f).count(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index 60fde6e22cb6..1da292130d05 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -15,6 +15,7 @@ impl PartialEq for Vec3 { fn eq(&self, other: &Self) -> bool { // This should trigger the lint because `self.x` is compared to `other.y` self.x == other.x && self.y == other.y && self.z == other.z + //~^ suspicious_operation_groupings } } @@ -28,6 +29,7 @@ struct S { fn buggy_ab_cmp(s1: &S, s2: &S) -> bool { // There's no `s1.b` s1.a < s2.a && s1.b < s2.b + //~^ suspicious_operation_groupings } struct SaOnly { @@ -76,31 +78,38 @@ fn permissable(s1: &S, s2: &S) -> bool { fn non_boolean_operators(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + s1.d * s2.d + //~^ suspicious_operation_groupings } fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { // There's no `s1.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_right(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_start(s1: &S, s2: &S) -> i32 { // There's no `s2.a` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_end(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { @@ -114,56 +123,68 @@ fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { fn outer_parens_simple(s1: &S, s2: &S) -> i32 { // There's no `s2.b` (s1.a * s2.a + s1.b * s2.b) + //~^ suspicious_operation_groupings } fn outer_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a + s1.b * s2.b + s1.c * s2.c + s1.d * s2.d) + //~^ suspicious_operation_groupings } fn inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d) + //~^ suspicious_operation_groupings } fn outer_and_some_inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.c) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.c)) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.c) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings } fn inside_other_binop_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` (s1.a * s2.a + s1.b * s2.b) / 2 + //~^ suspicious_operation_groupings } fn inside_function_call(s1: &S, s2: &S) -> i32 { // There's no `s1.b` i32::swap_bytes(s1.a * s2.a + s1.b * s2.b) + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.b > 0 && s1.c == s2.c && s1.d == s2.d + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression_with_unsorted_ops(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.c == s2.c && s1.b > 0 && s1.d == s2.d + //~^ suspicious_operation_groupings } struct Nested { @@ -173,6 +194,7 @@ struct Nested { fn changed_middle_ident(n1: &Nested, n2: &Nested) -> bool { // There's no `n2.inner.2.0` (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 + //~^ suspicious_operation_groupings } // `eq_op` should catch this one. @@ -187,12 +209,14 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { } else { // There's no `s1.b` in this subexpression s1.a <= s2.a && s1.b <= s2.b + //~^ suspicious_operation_groupings } } fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` if s1.a < s2.a && s1.b < s2.b { + //~^ suspicious_operation_groupings s1.c = s2.c; } } @@ -200,11 +224,13 @@ fn inside_an_if_statement(s1: &mut S, s2: &S) { fn maximum_unary_minus_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.c) + -(-s1.d * -s2.d))) + //~^ suspicious_operation_groupings } fn unary_minus_and_an_if_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` -(if -s1.a < -s2.a && -s1.b < -s2.b { s1.c } else { s2.a }) + //~^ suspicious_operation_groupings } fn main() {} diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index ce37148a853b..25ccba182fa5 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -15,6 +15,7 @@ impl PartialEq for Vec3 { fn eq(&self, other: &Self) -> bool { // This should trigger the lint because `self.x` is compared to `other.y` self.x == other.y && self.y == other.y && self.z == other.z + //~^ suspicious_operation_groupings } } @@ -28,6 +29,7 @@ struct S { fn buggy_ab_cmp(s1: &S, s2: &S) -> bool { // There's no `s1.b` s1.a < s2.a && s1.a < s2.b + //~^ suspicious_operation_groupings } struct SaOnly { @@ -76,31 +78,38 @@ fn permissable(s1: &S, s2: &S) -> bool { fn non_boolean_operators(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d + //~^ suspicious_operation_groupings } fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.c + s1.c * s2.c + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { // There's no `s1.b` s1.a * s2.a + s2.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_right(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s1.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_start(s1: &S, s2: &S) -> i32 { // There's no `s2.a` s1.a * s1.a + s1.b * s2.b + s1.c * s2.c + //~^ suspicious_operation_groupings } fn not_caught_by_eq_op_end(s1: &S, s2: &S) -> i32 { // There's no `s2.c` s1.a * s2.a + s1.b * s2.b + s1.c * s1.c + //~^ suspicious_operation_groupings } fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { @@ -114,56 +123,68 @@ fn the_cross_product_should_not_lint(s1: &S, s2: &S) -> (i32, i32, i32) { fn outer_parens_simple(s1: &S, s2: &S) -> i32 { // There's no `s2.b` (s1.a * s2.a + s1.b * s1.b) + //~^ suspicious_operation_groupings } fn outer_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) + //~^ suspicious_operation_groupings } fn inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) + //~^ suspicious_operation_groupings } fn outer_and_some_inner_parens(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings + //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) + //~^ suspicious_operation_groupings } fn all_parens_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) + //~^ suspicious_operation_groupings } fn inside_other_binop_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` (s1.a * s2.a + s2.b * s2.b) / 2 + //~^ suspicious_operation_groupings } fn inside_function_call(s1: &S, s2: &S) -> i32 { // There's no `s1.b` i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d + //~^ suspicious_operation_groupings } fn inside_larger_boolean_expression_with_unsorted_ops(s1: &S, s2: &S) -> bool { // There's no `s1.c` s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d + //~^ suspicious_operation_groupings } struct Nested { @@ -173,6 +194,7 @@ struct Nested { fn changed_middle_ident(n1: &Nested, n2: &Nested) -> bool { // There's no `n2.inner.2.0` (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 + //~^ suspicious_operation_groupings } // `eq_op` should catch this one. @@ -187,12 +209,14 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { } else { // There's no `s1.b` in this subexpression s1.a <= s2.a && s1.a <= s2.b + //~^ suspicious_operation_groupings } } fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` if s1.a < s2.a && s1.a < s2.b { + //~^ suspicious_operation_groupings s1.c = s2.c; } } @@ -200,11 +224,13 @@ fn inside_an_if_statement(s1: &mut S, s2: &S) { fn maximum_unary_minus_right_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) + //~^ suspicious_operation_groupings } fn unary_minus_and_an_if_expression(s1: &S, s2: &S) -> i32 { // There's no `s1.b` -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) + //~^ suspicious_operation_groupings } fn main() {} diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index 7cb066d57e75..b640b2041cd3 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -8,151 +8,151 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z = help: to override `-D warnings` add `#[allow(clippy::suspicious_operation_groupings)]` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:30:20 + --> tests/ui/suspicious_operation_groupings.rs:31:20 | LL | s1.a < s2.a && s1.a < s2.b | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:78:33 + --> tests/ui/suspicious_operation_groupings.rs:80:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:83:19 + --> tests/ui/suspicious_operation_groupings.rs:86:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:83:19 + --> tests/ui/suspicious_operation_groupings.rs:86:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` -error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:88:19 - | -LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c - | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` - error: this sequence of operators looks suspiciously like a bug --> tests/ui/suspicious_operation_groupings.rs:93:19 | +LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c + | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` + +error: this sequence of operators looks suspiciously like a bug + --> tests/ui/suspicious_operation_groupings.rs:99:19 + | LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:98:5 + --> tests/ui/suspicious_operation_groupings.rs:105:5 | LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.a * s2.a` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:103:33 + --> tests/ui/suspicious_operation_groupings.rs:111:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:116:20 + --> tests/ui/suspicious_operation_groupings.rs:125:20 | LL | (s1.a * s2.a + s1.b * s1.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:121:34 + --> tests/ui/suspicious_operation_groupings.rs:131:34 | LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:126:38 + --> tests/ui/suspicious_operation_groupings.rs:137:38 | LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:131:39 + --> tests/ui/suspicious_operation_groupings.rs:143:39 | LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:136:42 + --> tests/ui/suspicious_operation_groupings.rs:149:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:136:42 + --> tests/ui/suspicious_operation_groupings.rs:149:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:141:40 + --> tests/ui/suspicious_operation_groupings.rs:156:40 | LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:146:40 + --> tests/ui/suspicious_operation_groupings.rs:162:40 | LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:151:20 + --> tests/ui/suspicious_operation_groupings.rs:168:20 | LL | (s1.a * s2.a + s2.b * s2.b) / 2 | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:156:35 + --> tests/ui/suspicious_operation_groupings.rs:174:35 | LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:161:29 + --> tests/ui/suspicious_operation_groupings.rs:180:29 | LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:166:17 + --> tests/ui/suspicious_operation_groupings.rs:186:17 | LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:175:77 + --> tests/ui/suspicious_operation_groupings.rs:196:77 | LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `(n1.inner.2).0 == (n2.inner.2).0` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:189:25 + --> tests/ui/suspicious_operation_groupings.rs:211:25 | LL | s1.a <= s2.a && s1.a <= s2.b | ^^^^^^^^^^^^ help: did you mean: `s1.b <= s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:195:23 + --> tests/ui/suspicious_operation_groupings.rs:218:23 | LL | if s1.a < s2.a && s1.a < s2.b { | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:202:48 + --> tests/ui/suspicious_operation_groupings.rs:226:48 | LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) | ^^^^^^^^^^^^^ help: did you mean: `-s1.c * -s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:207:27 + --> tests/ui/suspicious_operation_groupings.rs:232: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_splitn.rs b/tests/ui/suspicious_splitn.rs index 7aa609706220..d7c1dd972450 100644 --- a/tests/ui/suspicious_splitn.rs +++ b/tests/ui/suspicious_splitn.rs @@ -8,32 +8,41 @@ 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` + //~^ suspicious_splitn + + let _ = "a,b".rsplitn(0, ','); - //~^ ERROR: `rsplitn` called with `0` splits - //~| NOTE: the resulting iterator will always return `None` + //~^ suspicious_splitn + + let _ = "a,b".splitn(1, ','); - //~^ ERROR: `splitn` called with `1` split - //~| NOTE: the resulting iterator will always return the entire string followed by `No + //~^ suspicious_splitn + + let _ = [0, 1, 2].splitn(0, |&x| x == 1); - //~^ ERROR: `splitn` called with `0` splits - //~| NOTE: the resulting iterator will always return `None` + //~^ suspicious_splitn + + 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` + //~^ suspicious_splitn + + 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 + //~^ suspicious_splitn + + 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 + //~^ suspicious_splitn + + 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 + //~^ suspicious_splitn + + let _ = "a,b".splitn(X, ','); - //~^ ERROR: `splitn` called with `0` splits - //~| NOTE: the resulting iterator will always return `None` + //~^ suspicious_splitn + + } diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 6e05bc28d130..1e1a9b22ffbd 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -9,7 +9,7 @@ LL | let _ = "a,b".splitn(0, ','); = help: to override `-D warnings` add `#[allow(clippy::suspicious_splitn)]` error: `rsplitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:13:13 + --> tests/ui/suspicious_splitn.rs:14:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:16:13 + --> tests/ui/suspicious_splitn.rs:18:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = "a,b".splitn(1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:19:13 + --> tests/ui/suspicious_splitn.rs:22:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn_mut` called with `0` splits - --> tests/ui/suspicious_splitn.rs:22:13 + --> tests/ui/suspicious_splitn.rs:26:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:25:13 + --> tests/ui/suspicious_splitn.rs:30:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `rsplitn_mut` called with `1` split - --> tests/ui/suspicious_splitn.rs:28:13 + --> tests/ui/suspicious_splitn.rs:34:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:33:13 + --> tests/ui/suspicious_splitn.rs:40:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = "a,b".splitn(X + 1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:36:13 + --> tests/ui/suspicious_splitn.rs:44:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index 794c2e7174af..bde20f4116c3 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -15,8 +15,9 @@ 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` + //~^ suspicious_to_owned + + // we expect no lints for this let cow = Cow::Borrowed(moo); let _ = cow.into_owned(); @@ -27,7 +28,8 @@ 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 + //~^ suspicious_to_owned + // we expect no lints for this let cow = Cow::Borrowed(&moos); let _ = cow.into_owned(); @@ -38,7 +40,8 @@ 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 + //~^ suspicious_to_owned + // we expect no lints for this let cow = Cow::Borrowed(&moos_vec); let _ = cow.into_owned(); @@ -49,7 +52,8 @@ 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 + //~^ suspicious_to_owned + // we expect no lints for this let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.into_owned(); @@ -64,8 +68,10 @@ 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` + //~^ implicit_clone + + let _ = moos_vec.to_owned(); - //~^ ERROR: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type + //~^ implicit_clone + } diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 255f211e6550..6c00819b4863 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -16,7 +16,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 - --> tests/ui/suspicious_to_owned.rs:29:13 + --> tests/ui/suspicious_to_owned.rs:30:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -31,7 +31,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 - --> tests/ui/suspicious_to_owned.rs:40:13 + --> tests/ui/suspicious_to_owned.rs:42:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -46,7 +46,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 - --> tests/ui/suspicious_to_owned.rs:51:13 + --> tests/ui/suspicious_to_owned.rs:54:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:66:13 + --> tests/ui/suspicious_to_owned.rs:70:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -70,7 +70,7 @@ LL | let _ = String::from(moo).to_owned(); = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:69:13 + --> tests/ui/suspicious_to_owned.rs:74: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 a7a62154ee0f..ab9bdde6cf90 100644 --- a/tests/ui/suspicious_unary_op_formatting.rs +++ b/tests/ui/suspicious_unary_op_formatting.rs @@ -7,18 +7,22 @@ fn main() { let a = 42; if a >- 30 {} - //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o + //~^ suspicious_unary_op_formatting + if a >=- 30 {} - //~^ ERROR: by not having a space between `>=` and `-` it looks like `>=-` is a single + //~^ suspicious_unary_op_formatting + let b = true; let c = false; if b &&! c {} - //~^ ERROR: by not having a space between `&&` and `!` it looks like `&&!` is a single + //~^ suspicious_unary_op_formatting + if a >- 30 {} - //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o + //~^ suspicious_unary_op_formatting + // 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 379fb17266a9..5fe18aa82435 100644 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ b/tests/ui/suspicious_unary_op_formatting.stderr @@ -9,7 +9,7 @@ LL | if a >- 30 {} = help: to override `-D warnings` add `#[allow(clippy::suspicious_unary_op_formatting)]` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator - --> tests/ui/suspicious_unary_op_formatting.rs:11:9 + --> tests/ui/suspicious_unary_op_formatting.rs:12:9 | LL | if a >=- 30 {} | ^^^^^ @@ -17,7 +17,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 - --> tests/ui/suspicious_unary_op_formatting.rs:17:9 + --> tests/ui/suspicious_unary_op_formatting.rs:19:9 | LL | if b &&! c {} | ^^^^^ @@ -25,7 +25,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 - --> tests/ui/suspicious_unary_op_formatting.rs:20:9 + --> tests/ui/suspicious_unary_op_formatting.rs:23: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 a5319e1b2308..229ed3383329 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -11,24 +11,31 @@ macro_rules! macro_test { macro_rules! macro_test_inside { () => { 1 ^ 2 // should warn even if inside macro + //~^ suspicious_xor_used_as_pow }; } 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` + //~^ suspicious_xor_used_as_pow + + let _ = 2i32 ^ 9i32; - //~^ ERROR: `^` is not the exponentiation operator + //~^ suspicious_xor_used_as_pow + let _ = 2i32 ^ 2i32; - //~^ ERROR: `^` is not the exponentiation operator + //~^ suspicious_xor_used_as_pow + let _ = 50i32 ^ 3i32; - //~^ ERROR: `^` is not the exponentiation operator + //~^ suspicious_xor_used_as_pow + let _ = 5i32 ^ 8i32; - //~^ ERROR: `^` is not the exponentiation operator + //~^ suspicious_xor_used_as_pow + let _ = 2i32 ^ 32i32; - //~^ ERROR: `^` is not the exponentiation operator + //~^ suspicious_xor_used_as_pow + 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 43b03676b1db..3fb3b4a34e53 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -1,5 +1,5 @@ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:19:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:20:13 | LL | let _ = 2 ^ 5; | ^^^^^ @@ -12,7 +12,7 @@ LL | let _ = 2.pow(5); | ~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:22:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = 2i32.pow(9i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:27:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = 2i32.pow(2i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = 50i32.pow(3i32); | ~~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:28:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:33:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = 5i32.pow(8i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:36:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index c9ad77629290..51af55ecd27c 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -26,6 +26,7 @@ fn field() { let mut bar = Bar { a: 1, b: 2 }; let temp = bar.a; + //~^ manual_swap bar.a = bar.b; bar.b = temp; @@ -38,6 +39,7 @@ fn field() { fn array() { let mut foo = [1, 2]; let temp = foo[0]; + //~^ manual_swap foo[0] = foo[1]; foo[1] = temp; @@ -47,6 +49,7 @@ fn array() { fn slice() { let foo = &mut [1, 2]; let temp = foo[0]; + //~^ manual_swap foo[0] = foo[1]; foo[1] = temp; @@ -66,6 +69,7 @@ fn unswappable_slice() { fn vec() { let mut foo = vec![1, 2]; let temp = foo[0]; + //~^ manual_swap foo[0] = foo[1]; foo[1] = temp; @@ -77,6 +81,7 @@ fn xor_swap_locals() { let mut a = 0; let mut b = 1; a ^= b; + //~^ manual_swap b ^= a; a ^= b; } @@ -85,6 +90,7 @@ fn xor_field_swap() { // This is an xor-based swap of fields in a struct. let mut bar = Bar { a: 0, b: 1 }; bar.a ^= bar.b; + //~^ manual_swap bar.b ^= bar.a; bar.a ^= bar.b; } @@ -93,6 +99,7 @@ fn xor_slice_swap() { // This is an xor-based swap of a slice let foo = &mut [1, 2]; foo[0] ^= foo[1]; + //~^ manual_swap foo[1] ^= foo[0]; foo[0] ^= foo[1]; } @@ -122,6 +129,7 @@ fn distinct_slice() { let foo = &mut [vec![1, 2], vec![3, 4]]; let bar = &mut [vec![1, 2], vec![3, 4]]; let temp = foo[0][1]; + //~^ manual_swap foo[0][1] = bar[1][0]; bar[1][0] = temp; } @@ -133,31 +141,38 @@ fn main() { let mut b = 1337; a = b; + //~^ almost_swapped b = a; ; let t = a; + //~^ manual_swap a = b; b = t; let mut c = Foo(42); c.0 = a; + //~^ almost_swapped a = c.0; ; let t = c.0; + //~^ manual_swap c.0 = a; a = t; let a = b; + //~^ almost_swapped let b = a; let mut c = 1; let mut d = 2; d = c; + //~^ almost_swapped c = d; let mut b = 1; let a = b; + //~^ almost_swapped b = a; let b = 1; @@ -171,6 +186,7 @@ fn main() { let mut a = 2; let t = b; + //~^ manual_swap b = a; a = t; } @@ -206,6 +222,7 @@ fn issue_8154() { let mut s = &mut s; let s = S3(&mut s); let t = s.0.x; + //~^ manual_swap s.0.x = s.0.y; s.0.y = t; } diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index fad356782479..15f7566d5896 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -2,6 +2,7 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually --> tests/ui/swap.rs:28:5 | LL | / let temp = bar.a; +LL | | LL | | bar.a = bar.b; LL | | bar.b = temp; | |_________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);` @@ -11,57 +12,64 @@ LL | | bar.b = temp; = help: to override `-D warnings` add `#[allow(clippy::manual_swap)]` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:40:5 + --> tests/ui/swap.rs:41:5 | LL | / let temp = foo[0]; +LL | | LL | | foo[0] = foo[1]; LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:49:5 + --> tests/ui/swap.rs:51:5 | LL | / let temp = foo[0]; +LL | | LL | | foo[0] = foo[1]; LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:68:5 + --> tests/ui/swap.rs:71:5 | LL | / let temp = foo[0]; +LL | | LL | | foo[0] = foo[1]; LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `a` and `b` manually - --> tests/ui/swap.rs:79:5 + --> tests/ui/swap.rs:83:5 | LL | / a ^= b; +LL | | LL | | b ^= a; LL | | a ^= b; | |___________^ help: try: `std::mem::swap(&mut a, &mut b);` error: this looks like you are swapping `bar.a` and `bar.b` manually - --> tests/ui/swap.rs:87:5 + --> tests/ui/swap.rs:92:5 | LL | / bar.a ^= bar.b; +LL | | LL | | bar.b ^= bar.a; LL | | bar.a ^= bar.b; | |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:95:5 + --> tests/ui/swap.rs:101:5 | LL | / foo[0] ^= foo[1]; +LL | | LL | | foo[1] ^= foo[0]; LL | | foo[0] ^= foo[1]; | |_____________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually - --> tests/ui/swap.rs:124:5 + --> tests/ui/swap.rs:131:5 | LL | / let temp = foo[0][1]; +LL | | LL | | foo[0][1] = bar[1][0]; LL | | bar[1][0] = temp; | |_____________________^ help: try: `std::mem::swap(&mut foo[0][1], &mut bar[1][0]);` @@ -69,10 +77,11 @@ LL | | bar[1][0] = temp; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `a` and `b` manually - --> tests/ui/swap.rs:138:7 + --> tests/ui/swap.rs:147:7 | LL | ; let t = a; | _______^ +LL | | LL | | a = b; LL | | b = t; | |__________^ help: try: `std::mem::swap(&mut a, &mut b);` @@ -80,10 +89,11 @@ LL | | b = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `c.0` and `a` manually - --> tests/ui/swap.rs:147:7 + --> tests/ui/swap.rs:158:7 | LL | ; let t = c.0; | _______^ +LL | | LL | | c.0 = a; LL | | a = t; | |__________^ help: try: `std::mem::swap(&mut c.0, &mut a);` @@ -91,9 +101,10 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `b` and `a` manually - --> tests/ui/swap.rs:173:5 + --> tests/ui/swap.rs:188:5 | LL | / let t = b; +LL | | LL | | b = a; LL | | a = t; | |__________^ help: try: `std::mem::swap(&mut b, &mut a);` @@ -101,9 +112,10 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:135:5 + --> tests/ui/swap.rs:143:5 | LL | / a = b; +LL | | LL | | b = a; | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | @@ -112,45 +124,50 @@ LL | | b = a; = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: this looks like you are trying to swap `c.0` and `a` - --> tests/ui/swap.rs:144:5 + --> tests/ui/swap.rs:154:5 | LL | / c.0 = a; +LL | | LL | | a = c.0; | |___________^ help: try: `std::mem::swap(&mut c.0, &mut a)` | = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:151:5 + --> tests/ui/swap.rs:163:5 | LL | / let a = b; +LL | | LL | | let b = a; | |_____________^ help: try: `std::mem::swap(&mut a, &mut b)` | = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `d` and `c` - --> tests/ui/swap.rs:156:5 + --> tests/ui/swap.rs:169:5 | LL | / d = c; +LL | | LL | | c = d; | |_________^ help: try: `std::mem::swap(&mut d, &mut c)` | = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:160:5 + --> tests/ui/swap.rs:174:5 | LL | / let a = b; +LL | | LL | | b = a; | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `s.0.x` and `s.0.y` manually - --> tests/ui/swap.rs:208:5 + --> tests/ui/swap.rs:224:5 | LL | / let t = s.0.x; +LL | | LL | | s.0.x = s.0.y; LL | | s.0.y = t; | |______________^ help: try: `std::mem::swap(&mut s.0.x, &mut s.0.y);` diff --git a/tests/ui/swap_ptr_to_ref.fixed b/tests/ui/swap_ptr_to_ref.fixed index 599bb0e80443..ec46368a95ae 100644 --- a/tests/ui/swap_ptr_to_ref.fixed +++ b/tests/ui/swap_ptr_to_ref.fixed @@ -9,9 +9,13 @@ fn main() { unsafe { core::ptr::swap(y, z); + //~^ swap_ptr_to_ref core::ptr::swap(y, &mut x); + //~^ swap_ptr_to_ref core::ptr::swap(&mut x, y); + //~^ swap_ptr_to_ref core::ptr::swap(addr_of_mut!(x), addr_of_mut!(x)); + //~^ swap_ptr_to_ref } let y = &mut x; diff --git a/tests/ui/swap_ptr_to_ref.rs b/tests/ui/swap_ptr_to_ref.rs index 3a8a8daefddc..6a903ddb006d 100644 --- a/tests/ui/swap_ptr_to_ref.rs +++ b/tests/ui/swap_ptr_to_ref.rs @@ -9,9 +9,13 @@ fn main() { unsafe { core::mem::swap(&mut *y, &mut *z); + //~^ swap_ptr_to_ref core::mem::swap(&mut *y, &mut x); + //~^ swap_ptr_to_ref core::mem::swap(&mut x, &mut *y); + //~^ swap_ptr_to_ref core::mem::swap(&mut *addr_of_mut!(x), &mut *addr_of_mut!(x)); + //~^ swap_ptr_to_ref } let y = &mut x; diff --git a/tests/ui/swap_ptr_to_ref.stderr b/tests/ui/swap_ptr_to_ref.stderr index 019c2f91f0e9..6b851901f82e 100644 --- a/tests/ui/swap_ptr_to_ref.stderr +++ b/tests/ui/swap_ptr_to_ref.stderr @@ -8,19 +8,19 @@ LL | core::mem::swap(&mut *y, &mut *z); = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> tests/ui/swap_ptr_to_ref.rs:12:9 + --> tests/ui/swap_ptr_to_ref.rs:13: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 - --> tests/ui/swap_ptr_to_ref.rs:13:9 + --> tests/ui/swap_ptr_to_ref.rs:15: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 - --> tests/ui/swap_ptr_to_ref.rs:14:9 + --> tests/ui/swap_ptr_to_ref.rs:17: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/swap_ptr_to_ref_unfixable.rs b/tests/ui/swap_ptr_to_ref_unfixable.rs index 08e56a5d01b2..9fe5925214a4 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.rs +++ b/tests/ui/swap_ptr_to_ref_unfixable.rs @@ -12,11 +12,14 @@ 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` + //~^ swap_ptr_to_ref + + 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 + //~^ swap_ptr_to_ref + 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 + //~^ swap_ptr_to_ref + } } diff --git a/tests/ui/swap_ptr_to_ref_unfixable.stderr b/tests/ui/swap_ptr_to_ref_unfixable.stderr index 8a0352049483..f4c7c8db15ac 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -8,13 +8,13 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> tests/ui/swap_ptr_to_ref_unfixable.rs:17:9 + --> tests/ui/swap_ptr_to_ref_unfixable.rs:18: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 - --> tests/ui/swap_ptr_to_ref_unfixable.rs:19:9 + --> tests/ui/swap_ptr_to_ref_unfixable.rs:21:9 | LL | core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/tabs_in_doc_comments.fixed b/tests/ui/tabs_in_doc_comments.fixed index 3536c1746df3..ed96cbaa6d3c 100644 --- a/tests/ui/tabs_in_doc_comments.fixed +++ b/tests/ui/tabs_in_doc_comments.fixed @@ -3,15 +3,23 @@ /// /// Struct to hold two strings: /// - first one +//~^ tabs_in_doc_comments +//~| tabs_in_doc_comments /// - second one +//~^ tabs_in_doc_comments +//~| tabs_in_doc_comments pub struct DoubleString { /// /// - First String: + //~^ tabs_in_doc_comments /// - needs to be inside here + //~^ tabs_in_doc_comments first_string: String, /// /// - Second String: + //~^ tabs_in_doc_comments /// - needs to be inside here + //~^ tabs_in_doc_comments second_string: String, } diff --git a/tests/ui/tabs_in_doc_comments.rs b/tests/ui/tabs_in_doc_comments.rs index 033a685066e1..73d4d92a862e 100644 --- a/tests/ui/tabs_in_doc_comments.rs +++ b/tests/ui/tabs_in_doc_comments.rs @@ -3,15 +3,23 @@ /// /// Struct to hold two strings: /// - first one +//~^ tabs_in_doc_comments +//~| tabs_in_doc_comments /// - second one +//~^ tabs_in_doc_comments +//~| tabs_in_doc_comments pub struct DoubleString { /// /// - First String: + //~^ tabs_in_doc_comments /// - needs to be inside here + //~^ tabs_in_doc_comments first_string: String, /// /// - Second String: + //~^ tabs_in_doc_comments /// - needs to be inside here + //~^ tabs_in_doc_comments second_string: String, } diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index f8d30b728e58..331bccaca92d 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -14,37 +14,37 @@ LL | /// - first one | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:5 + --> tests/ui/tabs_in_doc_comments.rs:8:5 | LL | /// - second one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:6:14 + --> tests/ui/tabs_in_doc_comments.rs:8:14 | LL | /// - second one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:9:9 + --> tests/ui/tabs_in_doc_comments.rs:13:9 | LL | /// - First String: | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:10:9 + --> tests/ui/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 - --> tests/ui/tabs_in_doc_comments.rs:13:9 + --> tests/ui/tabs_in_doc_comments.rs:19:9 | LL | /// - Second String: | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> tests/ui/tabs_in_doc_comments.rs:14:9 + --> tests/ui/tabs_in_doc_comments.rs:21:9 | LL | /// - needs to be inside here | ^^^^^^^^ help: consider using four spaces per tab diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index d269f91b9fa8..52a9de4ddffd 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -46,18 +46,22 @@ 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` + //~^ temporary_assignment + + MultiStruct { - //~^ ERROR: assignment to temporary + //~^ temporary_assignment + structure: Struct { field: 0 }, } .structure .field = 1; ArrayStruct { array: [0] }.array[0] = 1; - //~^ ERROR: assignment to temporary + //~^ temporary_assignment + (0, 0).0 = 1; - //~^ ERROR: assignment to temporary + //~^ temporary_assignment + // no error s.field = 1; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 7e6529cb2134..561f3d6f1ab9 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -8,23 +8,25 @@ LL | Struct { field: 0 }.field = 1; = help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]` error: assignment to temporary - --> tests/ui/temporary_assignment.rs:51:5 + --> tests/ui/temporary_assignment.rs:52:5 | LL | / MultiStruct { LL | | +LL | | LL | | structure: Struct { field: 0 }, -... | +LL | | } +LL | | .structure LL | | .field = 1; | |______________^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:57:5 + --> tests/ui/temporary_assignment.rs:59:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:59:5 + --> tests/ui/temporary_assignment.rs:62:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/tests/ui/test_attr_in_doctest.rs b/tests/ui/test_attr_in_doctest.rs index 4c904f7a09ac..8ca33c677f88 100644 --- a/tests/ui/test_attr_in_doctest.rs +++ b/tests/ui/test_attr_in_doctest.rs @@ -4,6 +4,7 @@ /// /// ``` /// #[test] +//~^ test_attr_in_doctest /// fn should_be_linted() { /// assert_eq!(1, 1); /// } @@ -14,12 +15,14 @@ /// /// ``` /// #[test] +//~^ test_attr_in_doctest /// fn should_also_be_linted() { /// #[cfg(test)] /// assert!(true); /// } /// /// #[test] +//~^ test_attr_in_doctest /// fn should_be_linted_too() { /// assert_eq!("#[test]", " /// #[test] diff --git a/tests/ui/test_attr_in_doctest.stderr b/tests/ui/test_attr_in_doctest.stderr index f950455f2908..b8de466e9698 100644 --- a/tests/ui/test_attr_in_doctest.stderr +++ b/tests/ui/test_attr_in_doctest.stderr @@ -3,6 +3,7 @@ error: unit tests in doctest are not executed | LL | /// #[test] | _____^ +LL | | LL | | /// fn should_be_linted() { | |_______________________^ | @@ -10,18 +11,20 @@ LL | | /// fn should_be_linted() { = help: to override `-D warnings` add `#[allow(clippy::test_attr_in_doctest)]` error: unit tests in doctest are not executed - --> tests/ui/test_attr_in_doctest.rs:16:5 + --> tests/ui/test_attr_in_doctest.rs:17:5 | LL | /// #[test] | _____^ +LL | | LL | | /// fn should_also_be_linted() { | |____________________________^ error: unit tests in doctest are not executed - --> tests/ui/test_attr_in_doctest.rs:22:5 + --> tests/ui/test_attr_in_doctest.rs:24:5 | LL | /// #[test] | _____^ +LL | | LL | | /// fn should_be_linted_too() { | |___________________________^ diff --git a/tests/ui/tests_outside_test_module.rs b/tests/ui/tests_outside_test_module.rs index 0abde4a57bf7..35126c46af08 100644 --- a/tests/ui/tests_outside_test_module.rs +++ b/tests/ui/tests_outside_test_module.rs @@ -1,3 +1,4 @@ +//@require-annotations-for-level: WARN #![allow(unused)] #![warn(clippy::tests_outside_test_module)] diff --git a/tests/ui/tests_outside_test_module.stderr b/tests/ui/tests_outside_test_module.stderr index 09feae6bf2aa..8602a63cc7a4 100644 --- a/tests/ui/tests_outside_test_module.stderr +++ b/tests/ui/tests_outside_test_module.stderr @@ -1,5 +1,5 @@ error: this function marked with #[test] is outside a #[cfg(test)] module - --> tests/ui/tests_outside_test_module.rs:10:1 + --> tests/ui/tests_outside_test_module.rs:11:1 | LL | fn my_test() {} | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/to_digit_is_some.fixed b/tests/ui/to_digit_is_some.fixed index 2ef4c05289fd..627d54c5f738 100644 --- a/tests/ui/to_digit_is_some.fixed +++ b/tests/ui/to_digit_is_some.fixed @@ -5,5 +5,7 @@ fn main() { let d = &c; let _ = d.is_digit(8); + //~^ to_digit_is_some let _ = char::is_digit(c, 8); + //~^ to_digit_is_some } diff --git a/tests/ui/to_digit_is_some.rs b/tests/ui/to_digit_is_some.rs index 54d9545809c5..d4eccc9931f1 100644 --- a/tests/ui/to_digit_is_some.rs +++ b/tests/ui/to_digit_is_some.rs @@ -5,5 +5,7 @@ fn main() { let d = &c; let _ = d.to_digit(8).is_some(); + //~^ to_digit_is_some let _ = char::to_digit(c, 8).is_some(); + //~^ to_digit_is_some } diff --git a/tests/ui/to_digit_is_some.stderr b/tests/ui/to_digit_is_some.stderr index e44106b2e188..f41382a60d53 100644 --- a/tests/ui/to_digit_is_some.stderr +++ b/tests/ui/to_digit_is_some.stderr @@ -8,7 +8,7 @@ LL | let _ = d.to_digit(8).is_some(); = help: to override `-D warnings` add `#[allow(clippy::to_digit_is_some)]` error: use of `.to_digit(..).is_some()` - --> tests/ui/to_digit_is_some.rs:8:13 + --> tests/ui/to_digit_is_some.rs:9: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 1f7895796366..2a29580e390c 100644 --- a/tests/ui/to_string_in_format_args_incremental.fixed +++ b/tests/ui/to_string_in_format_args_incremental.fixed @@ -5,4 +5,5 @@ fn main() { let s = "Hello, world!"; println!("{}", s); + //~^ to_string_in_format_args } diff --git a/tests/ui/to_string_in_format_args_incremental.rs b/tests/ui/to_string_in_format_args_incremental.rs index 514febe8c92d..18ca82976a40 100644 --- a/tests/ui/to_string_in_format_args_incremental.rs +++ b/tests/ui/to_string_in_format_args_incremental.rs @@ -5,4 +5,5 @@ fn main() { let s = "Hello, world!"; println!("{}", s.to_string()); + //~^ to_string_in_format_args } diff --git a/tests/ui/to_string_trait_impl.rs b/tests/ui/to_string_trait_impl.rs index 7be9f7994f08..f8195e55f9a8 100644 --- a/tests/ui/to_string_trait_impl.rs +++ b/tests/ui/to_string_trait_impl.rs @@ -9,6 +9,7 @@ struct Point { } impl ToString for Point { +//~^ to_string_trait_impl fn to_string(&self) -> String { format!("({}, {})", self.x, self.y) } diff --git a/tests/ui/to_string_trait_impl.stderr b/tests/ui/to_string_trait_impl.stderr index fe8afc215f0c..b24dfa39e011 100644 --- a/tests/ui/to_string_trait_impl.stderr +++ b/tests/ui/to_string_trait_impl.stderr @@ -2,6 +2,7 @@ error: direct implementation of `ToString` --> tests/ui/to_string_trait_impl.rs:11:1 | LL | / impl ToString for Point { +LL | | LL | | fn to_string(&self) -> String { LL | | format!("({}, {})", self.x, self.y) LL | | } diff --git a/tests/ui/too_long_first_doc_paragraph-fix.fixed b/tests/ui/too_long_first_doc_paragraph-fix.fixed index d4a0cdf3447f..7075aefd50b6 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.fixed +++ b/tests/ui/too_long_first_doc_paragraph-fix.fixed @@ -1,7 +1,9 @@ #![warn(clippy::too_long_first_doc_paragraph)] /// A very short summary. +//~^ too_long_first_doc_paragraph /// +//~^ too_long_first_doc_paragraph /// A much longer explanation that goes into a lot more detail about /// how the thing works, possibly with doclinks and so one, /// and probably spanning a many rows. Blablabla, it needs to be over diff --git a/tests/ui/too_long_first_doc_paragraph-fix.rs b/tests/ui/too_long_first_doc_paragraph-fix.rs index 5a3b6c42a328..844417d741ef 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.rs +++ b/tests/ui/too_long_first_doc_paragraph-fix.rs @@ -1,6 +1,7 @@ #![warn(clippy::too_long_first_doc_paragraph)] /// A very short summary. +//~^ too_long_first_doc_paragraph /// A much longer explanation that goes into a lot more detail about /// how the thing works, possibly with doclinks and so one, /// and probably spanning a many rows. Blablabla, it needs to be over diff --git a/tests/ui/too_long_first_doc_paragraph-fix.stderr b/tests/ui/too_long_first_doc_paragraph-fix.stderr index 6ef333f0cfd2..d6255ea2029b 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.stderr +++ b/tests/ui/too_long_first_doc_paragraph-fix.stderr @@ -2,6 +2,7 @@ error: first doc comment paragraph is too long --> tests/ui/too_long_first_doc_paragraph-fix.rs:3:1 | LL | / /// A very short summary. +LL | | LL | | /// A much longer explanation that goes into a lot more detail about LL | | /// how the thing works, possibly with doclinks and so one, LL | | /// and probably spanning a many rows. Blablabla, it needs to be over @@ -13,7 +14,9 @@ LL | | /// 200 characters so I needed to write something longeeeeeeer. help: add an empty line | LL ~ /// A very short summary. +LL + LL + /// +LL + | error: aborting due to 1 previous error diff --git a/tests/ui/too_long_first_doc_paragraph.rs b/tests/ui/too_long_first_doc_paragraph.rs index 7d0a37cde46d..2321e228866c 100644 --- a/tests/ui/too_long_first_doc_paragraph.rs +++ b/tests/ui/too_long_first_doc_paragraph.rs @@ -6,6 +6,7 @@ pub mod foo { // in foo.rs //! A very short summary. + //~^ too_long_first_doc_paragraph //! A much longer explanation that goes into a lot more detail about //! how the thing works, possibly with doclinks and so one, //! and probably spanning a many rows. Blablabla, it needs to be over @@ -13,6 +14,7 @@ pub mod foo { } /// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia +//~^ too_long_first_doc_paragraph /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, /// gravida non lacinia at, rhoncus eu lacus. pub struct Bar; @@ -34,6 +36,7 @@ pub enum Enum { } /// Lorem +//~^ too_long_first_doc_paragraph /// ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, /// gravida non lacinia at, rhoncus eu lacus. diff --git a/tests/ui/too_long_first_doc_paragraph.stderr b/tests/ui/too_long_first_doc_paragraph.stderr index 95f42349b9b3..2d4abaa9d63c 100644 --- a/tests/ui/too_long_first_doc_paragraph.stderr +++ b/tests/ui/too_long_first_doc_paragraph.stderr @@ -2,6 +2,7 @@ error: first doc comment paragraph is too long --> tests/ui/too_long_first_doc_paragraph.rs:8:5 | LL | / //! A very short summary. +LL | | LL | | //! A much longer explanation that goes into a lot more detail about LL | | //! how the thing works, possibly with doclinks and so one, LL | | //! and probably spanning a many rows. Blablabla, it needs to be over @@ -13,22 +14,26 @@ LL | | //! 200 characters so I needed to write something longeeeeeeer. help: add an empty line | LL ~ //! A very short summary. +LL + LL + //! +LL + LL ~ //! A much longer explanation that goes into a lot more detail about | error: first doc comment paragraph is too long - --> tests/ui/too_long_first_doc_paragraph.rs:15:1 + --> tests/ui/too_long_first_doc_paragraph.rs:16:1 | LL | / /// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia +LL | | LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, LL | | /// gravida non lacinia at, rhoncus eu lacus. | |_^ error: first doc comment paragraph is too long - --> tests/ui/too_long_first_doc_paragraph.rs:36:1 + --> tests/ui/too_long_first_doc_paragraph.rs:38:1 | LL | / /// Lorem +LL | | LL | | /// ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, LL | | /// gravida non lacinia at, rhoncus eu lacus. diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed index 3eb47a5b5fd6..11d4eaaefda0 100644 --- a/tests/ui/toplevel_ref_arg.fixed +++ b/tests/ui/toplevel_ref_arg.fixed @@ -12,17 +12,22 @@ fn main() { y(1u8); let _x = &1; + //~^ toplevel_ref_arg let _y: &(&_, u8) = &(&1, 2); + //~^ toplevel_ref_arg let _z = &(1 + 2); + //~^ toplevel_ref_arg let _z = &mut (1 + 2); + //~^ toplevel_ref_arg let (ref x, _) = (1, 2); // ok, not top level println!("The answer is {}.", x); let _x = &vec![1, 2, 3]; + //~^ toplevel_ref_arg // Make sure that allowing the lint works #[allow(clippy::toplevel_ref_arg)] @@ -33,6 +38,7 @@ fn main() { // lint in macro inline!(let _y = &42;); + //~^ toplevel_ref_arg // do not lint in external macro external!(let ref _y = 42;); diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index cd731387de97..957dd542f5a9 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -12,17 +12,22 @@ fn main() { y(1u8); let ref _x = 1; + //~^ toplevel_ref_arg let ref _y: (&_, u8) = (&1, 2); + //~^ toplevel_ref_arg let ref _z = 1 + 2; + //~^ toplevel_ref_arg let ref mut _z = 1 + 2; + //~^ toplevel_ref_arg let (ref x, _) = (1, 2); // ok, not top level println!("The answer is {}.", x); let ref _x = vec![1, 2, 3]; + //~^ toplevel_ref_arg // Make sure that allowing the lint works #[allow(clippy::toplevel_ref_arg)] @@ -33,6 +38,7 @@ fn main() { // lint in macro inline!(let ref _y = 42;); + //~^ toplevel_ref_arg // do not lint in external macro external!(let ref _y = 42;); diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 61f0fd4a6cd2..42e77f01495b 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -8,31 +8,31 @@ LL | let ref _x = 1; = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> tests/ui/toplevel_ref_arg.rs:16:9 + --> tests/ui/toplevel_ref_arg.rs:17: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 - --> tests/ui/toplevel_ref_arg.rs:18:9 + --> tests/ui/toplevel_ref_arg.rs:20: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 - --> tests/ui/toplevel_ref_arg.rs:20:9 + --> tests/ui/toplevel_ref_arg.rs:23: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 - --> tests/ui/toplevel_ref_arg.rs:25:9 + --> tests/ui/toplevel_ref_arg.rs:29: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 - --> tests/ui/toplevel_ref_arg.rs:35:17 + --> tests/ui/toplevel_ref_arg.rs:40:17 | LL | inline!(let ref _y = 42;); | ----^^^^^^------ help: try: `let _y = &42;` diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs index 8aaf47b1bd0c..729f528a8e59 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -7,6 +7,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; fn the_answer(ref mut x: u8) { +//~^ toplevel_ref_arg *x = 42; } @@ -18,6 +19,7 @@ fn main() { // lint in macro inline! { fn fun_example(ref _x: usize) {} + //~^ toplevel_ref_arg } // do not lint in external macro diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 26166e2fc8da..e17b2536874e 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -8,7 +8,7 @@ LL | fn the_answer(ref mut x: u8) { = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead - --> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24 + --> tests/ui/toplevel_ref_arg_non_rustfix.rs:21:24 | LL | fn fun_example(ref _x: usize) {} | ^^^^^^ diff --git a/tests/ui/track-diagnostics.rs b/tests/ui/track-diagnostics.rs index 6ab0bce770e2..723ea23e9a63 100644 --- a/tests/ui/track-diagnostics.rs +++ b/tests/ui/track-diagnostics.rs @@ -7,5 +7,6 @@ struct A; struct B; const S: A = B; +//~^ ERROR: mismatched types fn main() {} diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index ea3b8ff01afa..2297e645c9e6 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -4,39 +4,45 @@ // Do lint: struct RarelyUseful { - //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib +//~^ trailing_empty_array + field: i32, last: [usize; 0], } struct OnlyField { - //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib +//~^ trailing_empty_array + first_and_last: [usize; 0], } struct GenericArrayType { - //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib +//~^ trailing_empty_array + 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 +//~^ trailing_empty_array + 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 +//~^ trailing_empty_array + 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 +//~^ trailing_empty_array + field: i32, last: [usize; ZERO], } @@ -46,7 +52,8 @@ 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 +//~^ trailing_empty_array + field: i32, last: [usize; compute_zero()], } @@ -55,19 +62,23 @@ 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 +//~^ trailing_empty_array + 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 +//~^ trailing_empty_array + struct TupleStruct(i32, [usize; 0]); -//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib +//~^ trailing_empty_array + struct LotsOfFields { - //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib +//~^ trailing_empty_array + f1: u32, f2: u32, f3: u32, diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index 7ebff372cf75..424d23d07cdf 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -3,6 +3,7 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` a | LL | / struct RarelyUseful { LL | | +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -13,10 +14,11 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::trailing_empty_array)]` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> tests/ui/trailing_empty_array.rs:12:1 + --> tests/ui/trailing_empty_array.rs:13:1 | LL | / struct OnlyField { LL | | +LL | | LL | | first_and_last: [usize; 0], LL | | } | |_^ @@ -24,10 +26,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:17:1 + --> tests/ui/trailing_empty_array.rs:19:1 | LL | / struct GenericArrayType { LL | | +LL | | LL | | field: i32, LL | | last: [T; 0], LL | | } @@ -36,10 +39,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:24:1 + --> tests/ui/trailing_empty_array.rs:27:1 | LL | / struct OnlyAnotherAttribute { LL | | +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -48,10 +52,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:31:1 + --> tests/ui/trailing_empty_array.rs:35:1 | LL | / struct OnlyADeriveAttribute { LL | | +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -60,10 +65,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:38:1 + --> tests/ui/trailing_empty_array.rs:43:1 | LL | / struct ZeroSizedWithConst { LL | | +LL | | LL | | field: i32, LL | | last: [usize; ZERO], LL | | } @@ -72,10 +78,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:48:1 + --> tests/ui/trailing_empty_array.rs:54:1 | LL | / struct ZeroSizedWithConstFunction { LL | | +LL | | LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } @@ -84,10 +91,11 @@ 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 - --> tests/ui/trailing_empty_array.rs:57:1 + --> tests/ui/trailing_empty_array.rs:64:1 | LL | / struct ZeroSizedWithConstFunction2 { LL | | +LL | | LL | | field: i32, LL | | last: [usize; compute_zero_from_arg(1)], LL | | } @@ -96,7 +104,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 - --> tests/ui/trailing_empty_array.rs:63:1 + --> tests/ui/trailing_empty_array.rs:71:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +112,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 - --> tests/ui/trailing_empty_array.rs:66:1 + --> tests/ui/trailing_empty_array.rs:75:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,12 +120,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 - --> tests/ui/trailing_empty_array.rs:69:1 + --> tests/ui/trailing_empty_array.rs:79:1 | LL | / struct LotsOfFields { LL | | +LL | | LL | | f1: u32, -LL | | f2: u32, ... | LL | | last: [usize; 0], LL | | } diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index f7de976f1e00..273dd5d70646 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -4,10 +4,12 @@ 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` + //~^ verbose_bit_mask + + let _ = x.trailing_zeros() >= 5; - //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~^ verbose_bit_mask + 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 a05b09233e21..f3fffa7be840 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -4,10 +4,12 @@ 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` + //~^ verbose_bit_mask + + let _ = x & 0b1_1111 == 0; - //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~^ verbose_bit_mask + 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 6f3e7aa1d762..4b608e32a587 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -8,7 +8,7 @@ LL | let _ = (x & 0b1111 == 0); = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` error: bit mask could be simplified with a call to `trailing_zeros` - --> tests/ui/trailing_zeros.rs:9:13 + --> tests/ui/trailing_zeros.rs:10:13 | LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index 708512793d50..afd0f4d77d3e 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -5,12 +5,14 @@ use std::any::Any; fn bad_foo(arg0: T, argo1: U) { +//~^ trait_duplication_in_bounds unimplemented!(); } fn bad_bar(arg0: T, arg1: U) where T: Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy, { unimplemented!(); @@ -39,6 +41,7 @@ trait GoodSelfWhereClause { } trait BadSelfTraitBound: Clone { +//~^ trait_duplication_in_bounds fn f(); } @@ -46,6 +49,7 @@ trait BadSelfWhereClause { fn f() where Self: Clone; + //~^ trait_duplication_in_bounds } trait GoodTraitBound { @@ -60,6 +64,7 @@ trait GoodWhereClause { } trait BadTraitBound { +//~^ trait_duplication_in_bounds fn f(); } @@ -67,6 +72,7 @@ trait BadWhereClause { fn f() where T: Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy; } @@ -100,6 +106,7 @@ fn good_generic + GenericTrait>(arg0: T) { } fn bad_generic + GenericTrait>(arg0: T) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -108,6 +115,7 @@ mod foo { } fn qualified_path(arg0: T) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -116,6 +124,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { } fn bad_trait_object(arg0: &(dyn Any + Send)) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -165,12 +174,14 @@ const fn const_trait_bounds_good() {} const fn const_trait_bounds_bad() {} //~^ trait_duplication_in_bounds + fn projections() where U: ToOwned, V: ToOwned, T: IntoIterator, //~^ trait_duplication_in_bounds + V: IntoIterator + IntoIterator, { } @@ -193,5 +204,6 @@ fn assoc_const_args() where T: AssocConstTrait, //~^ trait_duplication_in_bounds + { } diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index 12db6b65a7ae..4d417e89bd82 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -5,12 +5,14 @@ use std::any::Any; fn bad_foo(arg0: T, argo1: U) { +//~^ trait_duplication_in_bounds unimplemented!(); } fn bad_bar(arg0: T, arg1: U) where T: Clone + Clone + Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy, { unimplemented!(); @@ -39,6 +41,7 @@ trait GoodSelfWhereClause { } trait BadSelfTraitBound: Clone + Clone + Clone { +//~^ trait_duplication_in_bounds fn f(); } @@ -46,6 +49,7 @@ trait BadSelfWhereClause { fn f() where Self: Clone + Clone + Clone; + //~^ trait_duplication_in_bounds } trait GoodTraitBound { @@ -60,6 +64,7 @@ trait GoodWhereClause { } trait BadTraitBound { +//~^ trait_duplication_in_bounds fn f(); } @@ -67,6 +72,7 @@ trait BadWhereClause { fn f() where T: Clone + Clone + Clone + Copy, + //~^ trait_duplication_in_bounds U: Clone + Copy; } @@ -100,6 +106,7 @@ fn good_generic + GenericTrait>(arg0: T) { } fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -108,6 +115,7 @@ mod foo { } fn qualified_path(arg0: T) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -116,6 +124,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { } fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { +//~^ trait_duplication_in_bounds unimplemented!(); } @@ -165,12 +174,14 @@ const fn const_trait_bounds_good() {} const fn const_trait_bounds_bad() {} //~^ trait_duplication_in_bounds + fn projections() where U: ToOwned, V: ToOwned, T: IntoIterator + IntoIterator, //~^ trait_duplication_in_bounds + V: IntoIterator + IntoIterator, { } @@ -193,5 +204,6 @@ fn assoc_const_args() where T: AssocConstTrait + AssocConstTrait, //~^ trait_duplication_in_bounds + { } diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 83c06eaccd4e..974dfe538799 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -11,67 +11,67 @@ LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:13:8 + --> tests/ui/trait_duplication_in_bounds.rs:14:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:41:26 + --> tests/ui/trait_duplication_in_bounds.rs:43:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:48:15 + --> tests/ui/trait_duplication_in_bounds.rs:51:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:62:24 + --> tests/ui/trait_duplication_in_bounds.rs:66:24 | LL | trait BadTraitBound { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:69:12 + --> tests/ui/trait_duplication_in_bounds.rs:74:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:102:19 + --> tests/ui/trait_duplication_in_bounds.rs:108:19 | LL | fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait + GenericTrait` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:110:22 + --> tests/ui/trait_duplication_in_bounds.rs:117:22 | LL | fn qualified_path(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone` error: this trait bound is already specified in trait declaration - --> tests/ui/trait_duplication_in_bounds.rs:118:33 + --> tests/ui/trait_duplication_in_bounds.rs:126:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:165:36 + --> tests/ui/trait_duplication_in_bounds.rs:174:36 | LL | const fn const_trait_bounds_bad() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `~const ConstTrait` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:172:8 + --> tests/ui/trait_duplication_in_bounds.rs:182:8 | LL | T: IntoIterator + IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:194:8 + --> tests/ui/trait_duplication_in_bounds.rs:205:8 | LL | T: AssocConstTrait + AssocConstTrait, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `AssocConstTrait` diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.rs b/tests/ui/trait_duplication_in_bounds_unfixable.rs index b0095bb77b5a..38a42c3bd365 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -5,8 +5,10 @@ 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 +//~^ trait_duplication_in_bounds +//~| trait_duplication_in_bounds + + where T: Clone, T: Default, @@ -36,7 +38,8 @@ trait T: Default { fn f() where Self: Default; - //~^ ERROR: this trait bound is already specified in trait declaration + //~^ trait_duplication_in_bounds + } trait U: Default { @@ -51,19 +54,23 @@ trait ZZ: Default { fn f() where Self: Default + Clone; - //~^ ERROR: this trait bound is already specified in trait declaration + //~^ trait_duplication_in_bounds + } 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 + //~^ trait_duplication_in_bounds + //~| trait_duplication_in_bounds + + fn g() where Self: Default; - //~^ ERROR: this trait bound is already specified in trait declaration + //~^ trait_duplication_in_bounds + fn h() where Self: Copy; @@ -99,7 +106,8 @@ trait FooIter: Iterator { fn bar() where Self: Iterator, - //~^ ERROR: this trait bound is already specified in trait declaration + //~^ trait_duplication_in_bounds + { } } diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index 41029007a98e..c7b8ba01c493 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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:38:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:40: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:53:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:56: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:60:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:64: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:60:25 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:64: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:65:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:71: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:101:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:108:15 | LL | Self: Iterator, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 7f5bdea4acf3..0fec14ffd975 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -29,41 +29,51 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { let _: &'a U = core::mem::transmute(t); let _: *const T = core::mem::transmute(t); - //~^ ERROR: transmute from a reference to a pointer - //~| NOTE: `-D clippy::useless-transmute` implied by `-D warnings` + //~^ useless_transmute + + let _: *mut T = core::mem::transmute(t); - //~^ ERROR: transmute from a reference to a pointer + //~^ useless_transmute + let _: *const U = core::mem::transmute(t); - //~^ ERROR: transmute from a reference to a pointer + //~^ useless_transmute + } #[warn(clippy::useless_transmute)] fn useless() { unsafe { let _: Vec = core::mem::transmute(my_vec()); - //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself + //~^ useless_transmute + let _: Vec = core::mem::transmute(my_vec()); - //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself + //~^ useless_transmute + let _: Vec = std::mem::transmute(my_vec()); - //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself + //~^ useless_transmute + let _: Vec = std::mem::transmute(my_vec()); - //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself + //~^ useless_transmute + let _: Vec = my_transmute(my_vec()); - //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself + //~^ useless_transmute + let _: *const usize = std::mem::transmute(5_isize); - //~^ ERROR: transmute from an integer to a pointer + //~^ useless_transmute + let _ = 5_isize as *const usize; let _: *const usize = std::mem::transmute(1 + 1usize); - //~^ ERROR: transmute from an integer to a pointer + //~^ useless_transmute + let _ = (1 + 1_usize) as *const usize; } @@ -95,77 +105,98 @@ fn crosspointer() { unsafe { let _: Usize = core::mem::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` + //~^ crosspointer_transmute + + let _: Usize = core::mem::transmute(int_mut_ptr); - //~^ ERROR: transmute from a type (`*mut Usize`) to the type that it points to (`U + //~^ crosspointer_transmute + let _: *const Usize = core::mem::transmute(my_int()); - //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*const Usi + //~^ crosspointer_transmute + let _: *mut Usize = core::mem::transmute(my_int()); - //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize + //~^ crosspointer_transmute + } } #[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` + //~^ transmute_int_to_bool + + } #[warn(clippy::transmute_int_to_float)] mod int_to_float { fn test() { let _: f16 = unsafe { std::mem::transmute(0_u16) }; - //~^ ERROR: transmute from a `u16` to a `f16` - //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` + //~^ transmute_int_to_float + + let _: f16 = unsafe { std::mem::transmute(0_i16) }; - //~^ ERROR: transmute from a `i16` to a `f16` + //~^ transmute_int_to_float + let _: f32 = unsafe { std::mem::transmute(0_u32) }; - //~^ ERROR: transmute from a `u32` to a `f32` + //~^ transmute_int_to_float + let _: f32 = unsafe { std::mem::transmute(0_i32) }; - //~^ ERROR: transmute from a `i32` to a `f32` + //~^ transmute_int_to_float + let _: f64 = unsafe { std::mem::transmute(0_u64) }; - //~^ ERROR: transmute from a `u64` to a `f64` + //~^ transmute_int_to_float + let _: f64 = unsafe { std::mem::transmute(0_i64) }; - //~^ ERROR: transmute from a `i64` to a `f64` + //~^ transmute_int_to_float + let _: f128 = unsafe { std::mem::transmute(0_u128) }; - //~^ ERROR: transmute from a `u128` to a `f128` + //~^ transmute_int_to_float + let _: f128 = unsafe { std::mem::transmute(0_i128) }; - //~^ ERROR: transmute from a `i128` to a `f128` + //~^ transmute_int_to_float + } mod issue_5747 { const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) }; - //~^ ERROR: transmute from a `u16` to a `f16` + //~^ transmute_int_to_float + const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) }; - //~^ ERROR: transmute from a `u32` to a `f32` + //~^ transmute_int_to_float + const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) }; - //~^ ERROR: transmute from a `i64` to a `f64` + //~^ transmute_int_to_float + const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) }; - //~^ ERROR: transmute from a `i128` to a `f128` + //~^ transmute_int_to_float + const fn from_bits_16(v: i16) -> f16 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `i16` to a `f16` + //~^ transmute_int_to_float + } const fn from_bits_32(v: i32) -> f32 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `i32` to a `f32` + //~^ transmute_int_to_float + } const fn from_bits_64(v: u64) -> f64 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `u64` to a `f64` + //~^ transmute_int_to_float + } const fn from_bits_128(v: u128) -> f128 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `u128` to a `f128` + //~^ transmute_int_to_float + } } } @@ -174,52 +205,72 @@ 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` + //~^ transmute_num_to_bytes + + let _: [u8; 4] = std::mem::transmute(0u32); - //~^ ERROR: transmute from a `u32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0u128); - //~^ ERROR: transmute from a `u128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + let _: [u8; 1] = std::mem::transmute(0i8); - //~^ ERROR: transmute from a `i8` to a `[u8; 1]` + //~^ transmute_num_to_bytes + let _: [u8; 4] = std::mem::transmute(0i32); - //~^ ERROR: transmute from a `i32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0i128); - //~^ ERROR: transmute from a `i128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + let _: [u8; 2] = std::mem::transmute(0.0f16); - //~^ ERROR: transmute from a `f16` to a `[u8; 2]` + //~^ transmute_num_to_bytes + let _: [u8; 4] = std::mem::transmute(0.0f32); - //~^ ERROR: transmute from a `f32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 8] = std::mem::transmute(0.0f64); - //~^ ERROR: transmute from a `f64` to a `[u8; 8]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0.0f128); - //~^ ERROR: transmute from a `f128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + } } const fn test_const() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); - //~^ ERROR: transmute from a `u8` to a `[u8; 1]` + //~^ transmute_num_to_bytes + let _: [u8; 4] = std::mem::transmute(0u32); - //~^ ERROR: transmute from a `u32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0u128); - //~^ ERROR: transmute from a `u128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + let _: [u8; 1] = std::mem::transmute(0i8); - //~^ ERROR: transmute from a `i8` to a `[u8; 1]` + //~^ transmute_num_to_bytes + let _: [u8; 4] = std::mem::transmute(0i32); - //~^ ERROR: transmute from a `i32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0i128); - //~^ ERROR: transmute from a `i128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + let _: [u8; 2] = std::mem::transmute(0.0f16); - //~^ ERROR: transmute from a `f16` to a `[u8; 2]` + //~^ transmute_num_to_bytes + let _: [u8; 4] = std::mem::transmute(0.0f32); - //~^ ERROR: transmute from a `f32` to a `[u8; 4]` + //~^ transmute_num_to_bytes + let _: [u8; 8] = std::mem::transmute(0.0f64); - //~^ ERROR: transmute from a `f64` to a `[u8; 8]` + //~^ transmute_num_to_bytes + let _: [u8; 16] = std::mem::transmute(0.0f128); - //~^ ERROR: transmute from a `f128` to a `[u8; 16]` + //~^ transmute_num_to_bytes + } } } @@ -228,12 +279,15 @@ 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` + //~^ transmute_bytes_to_str + + let _: &mut str = unsafe { std::mem::transmute(mb) }; - //~^ ERROR: transmute from a `&mut [u8]` to a `&mut str` + //~^ transmute_bytes_to_str + const _: &str = unsafe { std::mem::transmute(B) }; - //~^ ERROR: transmute from a `&[u8]` to a `&str` + //~^ transmute_bytes_to_str + } fn main() {} diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index b5032772856e..7db7fad28d80 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -8,23 +8,17 @@ LL | let _: *const T = core::mem::transmute(t); = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:35:21 + --> tests/ui/transmute.rs:36:21 | LL | let _: *mut T = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:38:23 + --> tests/ui/transmute.rs:40:23 | LL | let _: *const U = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` -error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:45:27 - | -LL | let _: Vec = core::mem::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: transmute from a type (`std::vec::Vec`) to itself --> tests/ui/transmute.rs:48:27 | @@ -32,37 +26,43 @@ LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:51:27 + --> tests/ui/transmute.rs:52:27 + | +LL | let _: Vec = core::mem::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> tests/ui/transmute.rs:56:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:54:27 + --> tests/ui/transmute.rs:60:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:57:27 + --> tests/ui/transmute.rs:64:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> tests/ui/transmute.rs:60:31 + --> tests/ui/transmute.rs:68: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 - --> tests/ui/transmute.rs:65:31 + --> tests/ui/transmute.rs:74: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`) - --> tests/ui/transmute.rs:97:24 + --> tests/ui/transmute.rs:107:24 | LL | let _: Usize = core::mem::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,25 +71,25 @@ LL | let _: Usize = core::mem::transmute(int_const_ptr); = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:101:24 + --> tests/ui/transmute.rs:112:24 | LL | let _: Usize = core::mem::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> tests/ui/transmute.rs:104:31 + --> tests/ui/transmute.rs:116:31 | LL | let _: *const Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> tests/ui/transmute.rs:107:29 + --> tests/ui/transmute.rs:120:29 | LL | let _: *mut Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u8` to a `bool` - --> tests/ui/transmute.rs:114:28 + --> tests/ui/transmute.rs:128:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -98,7 +98,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` error: transmute from a `u16` to a `f16` - --> tests/ui/transmute.rs:122:31 + --> tests/ui/transmute.rs:137:31 | LL | let _: f16 = unsafe { std::mem::transmute(0_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)` @@ -107,97 +107,97 @@ LL | let _: f16 = unsafe { std::mem::transmute(0_u16) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]` error: transmute from a `i16` to a `f16` - --> tests/ui/transmute.rs:125:31 + --> tests/ui/transmute.rs:141:31 | LL | let _: f16 = unsafe { std::mem::transmute(0_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_i16 as u16)` error: transmute from a `u32` to a `f32` - --> tests/ui/transmute.rs:127:31 + --> tests/ui/transmute.rs:144:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` error: transmute from a `i32` to a `f32` - --> tests/ui/transmute.rs:129:31 + --> tests/ui/transmute.rs:147: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` - --> tests/ui/transmute.rs:131:31 + --> tests/ui/transmute.rs:150: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` - --> tests/ui/transmute.rs:133:31 + --> tests/ui/transmute.rs:153:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `u128` to a `f128` - --> tests/ui/transmute.rs:135:32 + --> tests/ui/transmute.rs:156:32 | LL | let _: f128 = unsafe { std::mem::transmute(0_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_u128)` error: transmute from a `i128` to a `f128` - --> tests/ui/transmute.rs:137:32 + --> tests/ui/transmute.rs:159:32 | LL | let _: f128 = unsafe { std::mem::transmute(0_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)` error: transmute from a `u16` to a `f16` - --> tests/ui/transmute.rs:142:39 + --> tests/ui/transmute.rs:165:39 | LL | const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)` error: transmute from a `u32` to a `f32` - --> tests/ui/transmute.rs:144:39 + --> tests/ui/transmute.rs:168:39 | LL | const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` error: transmute from a `i64` to a `f64` - --> tests/ui/transmute.rs:146:39 + --> tests/ui/transmute.rs:171:39 | LL | const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `i128` to a `f128` - --> tests/ui/transmute.rs:148:41 + --> tests/ui/transmute.rs:174:41 | LL | const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)` error: transmute from a `i16` to a `f16` - --> tests/ui/transmute.rs:152:22 + --> tests/ui/transmute.rs:179:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(v as u16)` error: transmute from a `i32` to a `f32` - --> tests/ui/transmute.rs:157:22 + --> tests/ui/transmute.rs:185:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(v as u32)` error: transmute from a `u64` to a `f64` - --> tests/ui/transmute.rs:162:22 + --> tests/ui/transmute.rs:191:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(v)` error: transmute from a `u128` to a `f128` - --> tests/ui/transmute.rs:167:22 + --> tests/ui/transmute.rs:197:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(v)` error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:176:30 + --> tests/ui/transmute.rs:207:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` @@ -206,121 +206,121 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); = help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]` error: transmute from a `u32` to a `[u8; 4]` - --> tests/ui/transmute.rs:179:30 + --> tests/ui/transmute.rs:211: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]` - --> tests/ui/transmute.rs:181:31 + --> tests/ui/transmute.rs:214: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]` - --> tests/ui/transmute.rs:183:30 + --> tests/ui/transmute.rs:217: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]` - --> tests/ui/transmute.rs:185:30 + --> tests/ui/transmute.rs:220: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]` - --> tests/ui/transmute.rs:187:31 + --> tests/ui/transmute.rs:223:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f16` to a `[u8; 2]` - --> tests/ui/transmute.rs:190:30 + --> tests/ui/transmute.rs:227:30 | LL | let _: [u8; 2] = std::mem::transmute(0.0f16); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> tests/ui/transmute.rs:192:30 + --> tests/ui/transmute.rs:230: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]` - --> tests/ui/transmute.rs:194:30 + --> tests/ui/transmute.rs:233: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 `f128` to a `[u8; 16]` - --> tests/ui/transmute.rs:196:31 + --> tests/ui/transmute.rs:236:31 | LL | let _: [u8; 16] = std::mem::transmute(0.0f128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()` error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:202:30 + --> tests/ui/transmute.rs:243: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]` - --> tests/ui/transmute.rs:204:30 + --> tests/ui/transmute.rs:246: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]` - --> tests/ui/transmute.rs:206:31 + --> tests/ui/transmute.rs:249: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]` - --> tests/ui/transmute.rs:208:30 + --> tests/ui/transmute.rs:252: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]` - --> tests/ui/transmute.rs:210:30 + --> tests/ui/transmute.rs:255: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]` - --> tests/ui/transmute.rs:212:31 + --> tests/ui/transmute.rs:258:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f16` to a `[u8; 2]` - --> tests/ui/transmute.rs:215:30 + --> tests/ui/transmute.rs:262:30 | LL | let _: [u8; 2] = std::mem::transmute(0.0f16); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> tests/ui/transmute.rs:217:30 + --> tests/ui/transmute.rs:265: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]` - --> tests/ui/transmute.rs:219:30 + --> tests/ui/transmute.rs:268: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 `f128` to a `[u8; 16]` - --> tests/ui/transmute.rs:221:31 + --> tests/ui/transmute.rs:271:31 | LL | let _: [u8; 16] = std::mem::transmute(0.0f128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:230:28 + --> tests/ui/transmute.rs:281:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -329,13 +329,13 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` - --> tests/ui/transmute.rs:233:32 + --> tests/ui/transmute.rs:285:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:235:30 + --> tests/ui/transmute.rs:288: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 fd0ad74bcfa0..9570fa5ab093 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -4,10 +4,12 @@ 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` + //~^ wrong_transmute + + let _: *mut usize = std::mem::transmute(6.0f64); - //~^ ERROR: transmute from a `f64` to a pointer + //~^ wrong_transmute + } } diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index 65fff17f59fa..789eba5247fa 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -8,7 +8,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); = help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]` error: transmute from a `f64` to a pointer - --> tests/ui/transmute_64bit.rs:10:29 + --> tests/ui/transmute_64bit.rs:11: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 6748b66e0eb6..20952dfa2839 100644 --- a/tests/ui/transmute_collection.rs +++ b/tests/ui/transmute_collection.rs @@ -8,61 +8,79 @@ 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` + //~^ unsound_collection_transmute + + // wrong layout let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); - //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with m + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, VecDeque>(VecDeque::::new()); - //~^ ERROR: transmute from `std::collections::VecDeque` to `std::collections:: + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); - //~^ ERROR: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collecti + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); - //~^ ERROR: transmute from `std::collections::BinaryHeap` to `std::collections + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); - //~^ ERROR: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collec + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); - //~^ ERROR: transmute from `std::collections::BTreeSet` to `std::collections:: + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); - //~^ ERROR: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collecti + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, HashSet>(HashSet::::new()); - //~^ ERROR: transmute from `std::collections::HashSet` to `std::collections::H + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); - //~^ ERROR: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collectio + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collectio + //~^ unsound_collection_transmute + let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collect + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); - //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::coll + //~^ unsound_collection_transmute + let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); - //~^ ERROR: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::col + //~^ unsound_collection_transmute + // wrong size let _ = transmute::<_, HashMap>(HashMap::::new()); - //~^ ERROR: transmute from `std::collections::HashMap` to `std::collection + //~^ unsound_collection_transmute + let _ = transmute::<_, HashMap>(HashMap::::new()); - //~^ ERROR: transmute from `std::collections::HashMap` to `std::collecti + //~^ unsound_collection_transmute + // wrong layout let _ = transmute::<_, HashMap>(HashMap::::new()); - //~^ ERROR: transmute from `std::collections::HashMap` to `std::colle + //~^ unsound_collection_transmute + let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); - //~^ ERROR: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::coll + //~^ unsound_collection_transmute + 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 06db9321064b..f887afc9b676 100644 --- a/tests/ui/transmute_collection.stderr +++ b/tests/ui/transmute_collection.stderr @@ -8,103 +8,103 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); = help: to override `-D warnings` add `#[allow(clippy::unsound_collection_transmute)]` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:14:17 + --> tests/ui/transmute_collection.rs:15:17 | LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:18:17 + --> tests/ui/transmute_collection.rs:20:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:21:17 + --> tests/ui/transmute_collection.rs:24:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:25:17 + --> tests/ui/transmute_collection.rs:29:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:28:17 + --> tests/ui/transmute_collection.rs:33:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:32:17 + --> tests/ui/transmute_collection.rs:38:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:35:17 + --> tests/ui/transmute_collection.rs:42:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:39:17 + --> tests/ui/transmute_collection.rs:47:17 | LL | let _ = transmute::<_, HashSet>(HashSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:42:17 + --> tests/ui/transmute_collection.rs:51:17 | LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:46:17 + --> tests/ui/transmute_collection.rs:56:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:48:17 + --> tests/ui/transmute_collection.rs:59:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:51:17 + --> tests/ui/transmute_collection.rs:63: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 - --> tests/ui/transmute_collection.rs:53:17 + --> tests/ui/transmute_collection.rs:66: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 - --> tests/ui/transmute_collection.rs:57:17 + --> tests/ui/transmute_collection.rs:71:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:59:17 + --> tests/ui/transmute_collection.rs:74:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:62:17 + --> tests/ui/transmute_collection.rs:78: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 - --> tests/ui/transmute_collection.rs:64:17 + --> tests/ui/transmute_collection.rs:81: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 075a198918a0..e1feb57ae736 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -5,48 +5,62 @@ 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` + //~^ transmute_float_to_int + + let _: i32 = unsafe { 1f32.to_bits() as i32 }; - //~^ ERROR: transmute from a `f32` to a `i32` + //~^ transmute_float_to_int + let _: u64 = unsafe { 1f64.to_bits() }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + let _: i64 = unsafe { 1f64.to_bits() as i64 }; - //~^ ERROR: transmute from a `f64` to a `i64` + //~^ transmute_float_to_int + let _: u64 = unsafe { 1.0f64.to_bits() }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + let _: u64 = unsafe { (-1.0f64).to_bits() }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + } mod issue_5747 { const VALUE16: i16 = unsafe { 1f16.to_bits() as i16 }; - //~^ ERROR: transmute from a `f16` to a `i16` + //~^ transmute_float_to_int + const VALUE32: i32 = unsafe { 1f32.to_bits() as i32 }; - //~^ ERROR: transmute from a `f32` to a `i32` + //~^ transmute_float_to_int + const VALUE64: u64 = unsafe { 1f64.to_bits() }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + const VALUE128: u128 = unsafe { 1f128.to_bits() }; - //~^ ERROR: transmute from a `f128` to a `u128` + //~^ transmute_float_to_int + const fn to_bits_16(v: f16) -> u16 { unsafe { v.to_bits() } - //~^ ERROR: transmute from a `f16` to a `u16` + //~^ transmute_float_to_int + } const fn to_bits_32(v: f32) -> u32 { unsafe { v.to_bits() } - //~^ ERROR: transmute from a `f32` to a `u32` + //~^ transmute_float_to_int + } const fn to_bits_64(v: f64) -> i64 { unsafe { v.to_bits() as i64 } - //~^ ERROR: transmute from a `f64` to a `i64` + //~^ transmute_float_to_int + } const fn to_bits_128(v: f128) -> i128 { unsafe { v.to_bits() as i128 } - //~^ ERROR: transmute from a `f128` to a `i128` + //~^ transmute_float_to_int + } } diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 12541b2f7cf3..ac2a1a1ad05d 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -5,48 +5,62 @@ 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` + //~^ transmute_float_to_int + + let _: i32 = unsafe { std::mem::transmute(1f32) }; - //~^ ERROR: transmute from a `f32` to a `i32` + //~^ transmute_float_to_int + let _: u64 = unsafe { std::mem::transmute(1f64) }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + let _: i64 = unsafe { std::mem::transmute(1f64) }; - //~^ ERROR: transmute from a `f64` to a `i64` + //~^ transmute_float_to_int + let _: u64 = unsafe { std::mem::transmute(1.0) }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + let _: u64 = unsafe { std::mem::transmute(-1.0) }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + } mod issue_5747 { const VALUE16: i16 = unsafe { std::mem::transmute(1f16) }; - //~^ ERROR: transmute from a `f16` to a `i16` + //~^ transmute_float_to_int + const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; - //~^ ERROR: transmute from a `f32` to a `i32` + //~^ transmute_float_to_int + const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; - //~^ ERROR: transmute from a `f64` to a `u64` + //~^ transmute_float_to_int + const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; - //~^ ERROR: transmute from a `f128` to a `u128` + //~^ transmute_float_to_int + const fn to_bits_16(v: f16) -> u16 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `f16` to a `u16` + //~^ transmute_float_to_int + } const fn to_bits_32(v: f32) -> u32 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `f32` to a `u32` + //~^ transmute_float_to_int + } const fn to_bits_64(v: f64) -> i64 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `f64` to a `i64` + //~^ transmute_float_to_int + } const fn to_bits_128(v: f128) -> i128 { unsafe { std::mem::transmute(v) } - //~^ ERROR: transmute from a `f128` to a `i128` + //~^ transmute_float_to_int + } } diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index 0cabab58ab08..551fcb1f7d0d 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -8,79 +8,79 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]` error: transmute from a `f32` to a `i32` - --> tests/ui/transmute_float_to_int.rs:10:27 + --> tests/ui/transmute_float_to_int.rs:11: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` - --> tests/ui/transmute_float_to_int.rs:12:27 + --> tests/ui/transmute_float_to_int.rs:14:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> tests/ui/transmute_float_to_int.rs:14:27 + --> tests/ui/transmute_float_to_int.rs:17: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` - --> tests/ui/transmute_float_to_int.rs:16:27 + --> tests/ui/transmute_float_to_int.rs:20: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` - --> tests/ui/transmute_float_to_int.rs:18:27 + --> tests/ui/transmute_float_to_int.rs:23:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` error: transmute from a `f16` to a `i16` - --> tests/ui/transmute_float_to_int.rs:23:35 + --> tests/ui/transmute_float_to_int.rs:29:35 | LL | const VALUE16: i16 = unsafe { std::mem::transmute(1f16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f16.to_bits() as i16` error: transmute from a `f32` to a `i32` - --> tests/ui/transmute_float_to_int.rs:25:35 + --> tests/ui/transmute_float_to_int.rs:32:35 | LL | const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> tests/ui/transmute_float_to_int.rs:27:35 + --> tests/ui/transmute_float_to_int.rs:35:35 | LL | const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f128` to a `u128` - --> tests/ui/transmute_float_to_int.rs:29:37 + --> tests/ui/transmute_float_to_int.rs:38:37 | LL | const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f128.to_bits()` error: transmute from a `f16` to a `u16` - --> tests/ui/transmute_float_to_int.rs:33:18 + --> tests/ui/transmute_float_to_int.rs:43:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()` error: transmute from a `f32` to a `u32` - --> tests/ui/transmute_float_to_int.rs:38:18 + --> tests/ui/transmute_float_to_int.rs:49:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()` error: transmute from a `f64` to a `i64` - --> tests/ui/transmute_float_to_int.rs:43:18 + --> tests/ui/transmute_float_to_int.rs:55:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i64` error: transmute from a `f128` to a `i128` - --> tests/ui/transmute_float_to_int.rs:48:18 + --> tests/ui/transmute_float_to_int.rs:61:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i128` diff --git a/tests/ui/transmute_int_to_char.fixed b/tests/ui/transmute_int_to_char.fixed index d3277d1b8c73..e28467f00434 100644 --- a/tests/ui/transmute_int_to_char.fixed +++ b/tests/ui/transmute_int_to_char.fixed @@ -3,10 +3,12 @@ fn int_to_char() { let _: char = unsafe { std::char::from_u32(0_u32).unwrap() }; - //~^ ERROR: transmute from a `u32` to a `char` - //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` + //~^ transmute_int_to_char + + let _: char = unsafe { std::char::from_u32(0_i32 as u32).unwrap() }; - //~^ ERROR: transmute from a `i32` to a `char` + //~^ transmute_int_to_char + // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; diff --git a/tests/ui/transmute_int_to_char.rs b/tests/ui/transmute_int_to_char.rs index d21c4fd6fea3..decdaaa463a9 100644 --- a/tests/ui/transmute_int_to_char.rs +++ b/tests/ui/transmute_int_to_char.rs @@ -3,10 +3,12 @@ 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` + //~^ transmute_int_to_char + + let _: char = unsafe { std::mem::transmute(0_i32) }; - //~^ ERROR: transmute from a `i32` to a `char` + //~^ transmute_int_to_char + // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; diff --git a/tests/ui/transmute_int_to_char.stderr b/tests/ui/transmute_int_to_char.stderr index e3a3620f28b7..5dc58abb38ea 100644 --- a/tests/ui/transmute_int_to_char.stderr +++ b/tests/ui/transmute_int_to_char.stderr @@ -8,7 +8,7 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` - --> tests/ui/transmute_int_to_char.rs:8:28 + --> tests/ui/transmute_int_to_char.rs:9:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` diff --git a/tests/ui/transmute_int_to_char_no_std.fixed b/tests/ui/transmute_int_to_char_no_std.fixed index 32a57645b46f..09a353dc1ae9 100644 --- a/tests/ui/transmute_int_to_char_no_std.fixed +++ b/tests/ui/transmute_int_to_char_no_std.fixed @@ -15,10 +15,12 @@ fn panic(info: &PanicInfo) -> ! { fn int_to_char() { let _: char = unsafe { core::char::from_u32(0_u32).unwrap() }; - //~^ ERROR: transmute from a `u32` to a `char` - //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` + //~^ transmute_int_to_char + + let _: char = unsafe { core::char::from_u32(0_i32 as u32).unwrap() }; - //~^ ERROR: transmute from a `i32` to a `char` + //~^ transmute_int_to_char + // These shouldn't warn const _: char = unsafe { core::mem::transmute(0_u32) }; diff --git a/tests/ui/transmute_int_to_char_no_std.rs b/tests/ui/transmute_int_to_char_no_std.rs index 942794c32f81..fb47b3ce3ba9 100644 --- a/tests/ui/transmute_int_to_char_no_std.rs +++ b/tests/ui/transmute_int_to_char_no_std.rs @@ -15,10 +15,12 @@ fn panic(info: &PanicInfo) -> ! { fn int_to_char() { let _: char = unsafe { core::mem::transmute(0_u32) }; - //~^ ERROR: transmute from a `u32` to a `char` - //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` + //~^ transmute_int_to_char + + let _: char = unsafe { core::mem::transmute(0_i32) }; - //~^ ERROR: transmute from a `i32` to a `char` + //~^ transmute_int_to_char + // These shouldn't warn const _: char = unsafe { core::mem::transmute(0_u32) }; diff --git a/tests/ui/transmute_int_to_char_no_std.stderr b/tests/ui/transmute_int_to_char_no_std.stderr index d94580a84d7a..37f996e6277f 100644 --- a/tests/ui/transmute_int_to_char_no_std.stderr +++ b/tests/ui/transmute_int_to_char_no_std.stderr @@ -8,7 +8,7 @@ LL | let _: char = unsafe { core::mem::transmute(0_u32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` - --> tests/ui/transmute_int_to_char_no_std.rs:20:28 + --> tests/ui/transmute_int_to_char_no_std.rs:21:28 | LL | let _: char = unsafe { core::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::char::from_u32(0_i32 as u32).unwrap()` diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index 1a48051ec8c4..12d8d20f4d8f 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -17,27 +17,37 @@ fn main() { let int_i128: i128 = 1; let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; - //~^ ERROR: transmute from a `u8` to a `NonZero` - //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` + //~^ transmute_int_to_non_zero + + let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; - //~^ ERROR: transmute from a `u16` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; - //~^ ERROR: transmute from a `u32` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_u64) }; - //~^ ERROR: transmute from a `u64` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_u128) }; - //~^ ERROR: transmute from a `u128` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_i8) }; - //~^ ERROR: transmute from a `i8` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_i16) }; - //~^ ERROR: transmute from a `i16` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_i32) }; - //~^ ERROR: transmute from a `i32` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_i64) }; - //~^ ERROR: transmute from a `i64` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_i128) }; - //~^ ERROR: transmute from a `i128` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; let _: NonZero = unsafe { NonZero::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 d8e842fb99ce..a01b9aaa7f2e 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -17,27 +17,37 @@ fn main() { let int_i128: i128 = 1; let _: NonZero = unsafe { std::mem::transmute(int_u8) }; - //~^ ERROR: transmute from a `u8` to a `NonZero` - //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` + //~^ transmute_int_to_non_zero + + let _: NonZero = unsafe { std::mem::transmute(int_u16) }; - //~^ ERROR: transmute from a `u16` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_u32) }; - //~^ ERROR: transmute from a `u32` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_u64) }; - //~^ ERROR: transmute from a `u64` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_u128) }; - //~^ ERROR: transmute from a `u128` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_i8) }; - //~^ ERROR: transmute from a `i8` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_i16) }; - //~^ ERROR: transmute from a `i16` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_i32) }; - //~^ ERROR: transmute from a `i32` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_i64) }; - //~^ ERROR: transmute from a `i64` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { std::mem::transmute(int_i128) }; - //~^ ERROR: transmute from a `i128` to a `NonZero` + //~^ transmute_int_to_non_zero + let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; let _: NonZero = unsafe { NonZero::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 199b8ec59d09..1a1cd03248b4 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -8,55 +8,55 @@ LL | let _: NonZero = unsafe { std::mem::transmute(int_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` error: transmute from a `u16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:22:36 + --> tests/ui/transmute_int_to_non_zero.rs:23:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:24:36 + --> tests/ui/transmute_int_to_non_zero.rs:26:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:26:36 + --> tests/ui/transmute_int_to_non_zero.rs:29:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:28:37 + --> tests/ui/transmute_int_to_non_zero.rs:32:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:31:35 + --> tests/ui/transmute_int_to_non_zero.rs:36:35 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:33:36 + --> tests/ui/transmute_int_to_non_zero.rs:39:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:35:36 + --> tests/ui/transmute_int_to_non_zero.rs:42:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:37:36 + --> tests/ui/transmute_int_to_non_zero.rs:45:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:39:37 + --> tests/ui/transmute_int_to_non_zero.rs:48:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)` diff --git a/tests/ui/transmute_null_to_fn.rs b/tests/ui/transmute_null_to_fn.rs index c0196ad52d43..a9eaf16d05aa 100644 --- a/tests/ui/transmute_null_to_fn.rs +++ b/tests/ui/transmute_null_to_fn.rs @@ -6,9 +6,11 @@ fn one_liners() { unsafe { let _: fn() = std::mem::transmute(0 as *const ()); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + let _: fn() = std::mem::transmute(std::ptr::null::<()>()); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + } } @@ -19,7 +21,8 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: fn() = std::mem::transmute(ZPTR); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + // Should NOT raise a lint. let _: fn() = std::mem::transmute(NOT_ZPTR); } @@ -28,11 +31,14 @@ fn transmute_const() { fn issue_11485() { unsafe { let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + let _: fn() = std::mem::transmute(ZPTR as *const u8); - //~^ ERROR: transmuting a known null pointer into a function pointer + //~^ transmute_null_to_fn + } } diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index cea7b42cb801..9b2253c444f4 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -9,7 +9,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); = help: to override `-D warnings` add `#[allow(clippy::transmute_null_to_fn)]` error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:10:23 + --> tests/ui/transmute_null_to_fn.rs:11:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -17,7 +17,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:21:23 + --> tests/ui/transmute_null_to_fn.rs:23:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -25,7 +25,7 @@ LL | let _: fn() = std::mem::transmute(ZPTR); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:30:23 + --> tests/ui/transmute_null_to_fn.rs:33:23 | LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -33,7 +33,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:32:23 + --> tests/ui/transmute_null_to_fn.rs:36:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -41,7 +41,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:34:23 + --> tests/ui/transmute_null_to_fn.rs:39:23 | LL | let _: fn() = std::mem::transmute(ZPTR as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed index 39e67b250526..d595ecf32a1c 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -31,26 +31,35 @@ fn transmute_ptr_to_ptr() { // pointer-to-pointer transmutes; bad let _: *const f32 = ptr.cast::(); //~^ transmute_ptr_to_ptr + let _: *mut f32 = mut_ptr.cast::(); //~^ transmute_ptr_to_ptr + // ref-ref transmutes; bad let _: &f32 = &*(&1u32 as *const u32 as *const f32); //~^ transmute_ptr_to_ptr + let _: &f32 = &*(&1f64 as *const f64 as *const f32); //~^ transmute_ptr_to_ptr + //:^ 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); //~^ transmute_ptr_to_ptr + let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); //~^ transmute_ptr_to_ptr + let u64_ref: &u64 = &0u64; let u8_ref: &u8 = &*(u64_ref as *const u64 as *const u8); //~^ transmute_ptr_to_ptr + let _: *const u32 = mut_ptr.cast_const(); //~^ transmute_ptr_to_ptr + let _: *mut u32 = ptr.cast_mut(); //~^ transmute_ptr_to_ptr + } // transmute internal lifetimes, should not lint @@ -63,6 +72,7 @@ fn transmute_ptr_to_ptr() { fn lifetime_to_static(v: *mut &()) -> *const &'static () { unsafe { v as *const &() } //~^ transmute_ptr_to_ptr + } // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) @@ -77,6 +87,7 @@ const _: &() = { fn msrv_1_37(ptr: *const u8) { unsafe { let _: *const i8 = ptr as *const i8; + //~^ transmute_ptr_to_ptr } } @@ -84,6 +95,7 @@ fn msrv_1_37(ptr: *const u8) { fn msrv_1_38(ptr: *const u8) { unsafe { let _: *const i8 = ptr.cast::(); + //~^ transmute_ptr_to_ptr } } @@ -91,7 +103,9 @@ fn msrv_1_38(ptr: *const u8) { fn msrv_1_64(ptr: *const u8, mut_ptr: *mut u8) { unsafe { let _: *mut u8 = ptr as *mut u8; + //~^ transmute_ptr_to_ptr let _: *const u8 = mut_ptr as *const u8; + //~^ transmute_ptr_to_ptr } } @@ -99,7 +113,9 @@ fn msrv_1_64(ptr: *const u8, mut_ptr: *mut u8) { fn msrv_1_65(ptr: *const u8, mut_ptr: *mut u8) { unsafe { let _: *mut u8 = ptr.cast_mut(); + //~^ transmute_ptr_to_ptr let _: *const u8 = mut_ptr.cast_const(); + //~^ transmute_ptr_to_ptr } } diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 580b28551734..2e72f86dd3b3 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -31,26 +31,35 @@ fn transmute_ptr_to_ptr() { // pointer-to-pointer transmutes; bad let _: *const f32 = transmute(ptr); //~^ transmute_ptr_to_ptr + let _: *mut f32 = transmute(mut_ptr); //~^ transmute_ptr_to_ptr + // ref-ref transmutes; bad let _: &f32 = transmute(&1u32); //~^ transmute_ptr_to_ptr + let _: &f32 = transmute(&1f64); //~^ transmute_ptr_to_ptr + //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = transmute(&mut 1u32); //~^ transmute_ptr_to_ptr + let _: &GenericParam = transmute(&GenericParam { t: 1u32 }); //~^ transmute_ptr_to_ptr + let u64_ref: &u64 = &0u64; let u8_ref: &u8 = transmute(u64_ref); //~^ transmute_ptr_to_ptr + let _: *const u32 = transmute(mut_ptr); //~^ transmute_ptr_to_ptr + let _: *mut u32 = transmute(ptr); //~^ transmute_ptr_to_ptr + } // transmute internal lifetimes, should not lint @@ -63,6 +72,7 @@ fn transmute_ptr_to_ptr() { fn lifetime_to_static(v: *mut &()) -> *const &'static () { unsafe { transmute(v) } //~^ transmute_ptr_to_ptr + } // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) @@ -77,6 +87,7 @@ const _: &() = { fn msrv_1_37(ptr: *const u8) { unsafe { let _: *const i8 = transmute(ptr); + //~^ transmute_ptr_to_ptr } } @@ -84,6 +95,7 @@ fn msrv_1_37(ptr: *const u8) { fn msrv_1_38(ptr: *const u8) { unsafe { let _: *const i8 = transmute(ptr); + //~^ transmute_ptr_to_ptr } } @@ -91,7 +103,9 @@ fn msrv_1_38(ptr: *const u8) { fn msrv_1_64(ptr: *const u8, mut_ptr: *mut u8) { unsafe { let _: *mut u8 = transmute(ptr); + //~^ transmute_ptr_to_ptr let _: *const u8 = transmute(mut_ptr); + //~^ transmute_ptr_to_ptr } } @@ -99,7 +113,9 @@ fn msrv_1_64(ptr: *const u8, mut_ptr: *mut u8) { fn msrv_1_65(ptr: *const u8, mut_ptr: *mut u8) { unsafe { let _: *mut u8 = transmute(ptr); + //~^ transmute_ptr_to_ptr let _: *const u8 = transmute(mut_ptr); + //~^ transmute_ptr_to_ptr } } diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 8801eb943ce8..3e7e170eff7f 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -12,7 +12,7 @@ LL | let _: *const f32 = ptr.cast::(); | ~~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:34:27 + --> tests/ui/transmute_ptr_to_ptr.rs:35:27 | LL | let _: *mut f32 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -23,37 +23,37 @@ LL | let _: *mut f32 = mut_ptr.cast::(); | ~~~~~~~~~~~~~~~~~~~~~ error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:37:23 + --> tests/ui/transmute_ptr_to_ptr.rs:39:23 | LL | let _: &f32 = transmute(&1u32); | ^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:39:23 + --> tests/ui/transmute_ptr_to_ptr.rs:42:23 | LL | let _: &f32 = transmute(&1f64); | ^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:43:27 + --> tests/ui/transmute_ptr_to_ptr.rs:47:27 | LL | let _: &mut f32 = transmute(&mut 1u32); | ^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:45:37 + --> tests/ui/transmute_ptr_to_ptr.rs:50:37 | LL | let _: &GenericParam = transmute(&GenericParam { t: 1u32 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:48:27 + --> tests/ui/transmute_ptr_to_ptr.rs:54:27 | LL | let u8_ref: &u8 = transmute(u64_ref); | ^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)` error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:50:29 + --> tests/ui/transmute_ptr_to_ptr.rs:57:29 | LL | let _: *const u32 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _: *const u32 = mut_ptr.cast_const(); | ~~~~~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:52:27 + --> tests/ui/transmute_ptr_to_ptr.rs:60:27 | LL | let _: *mut u32 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | let _: *mut u32 = ptr.cast_mut(); | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:64:14 + --> tests/ui/transmute_ptr_to_ptr.rs:73:14 | LL | unsafe { transmute(v) } | ^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | unsafe { v as *const &() } | ~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:79:28 + --> tests/ui/transmute_ptr_to_ptr.rs:89:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: *const i8 = ptr as *const i8; | ~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:86:28 + --> tests/ui/transmute_ptr_to_ptr.rs:97:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | let _: *const i8 = ptr.cast::(); | ~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:93:26 + --> tests/ui/transmute_ptr_to_ptr.rs:105:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | let _: *mut u8 = ptr as *mut u8; | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:94:28 + --> tests/ui/transmute_ptr_to_ptr.rs:107:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -130,7 +130,7 @@ LL | let _: *const u8 = mut_ptr as *const u8; | ~~~~~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:101:26 + --> tests/ui/transmute_ptr_to_ptr.rs:115:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -141,7 +141,7 @@ LL | let _: *mut u8 = ptr.cast_mut(); | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:102:28 + --> tests/ui/transmute_ptr_to_ptr.rs:117:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_ptr_to_ref.fixed b/tests/ui/transmute_ptr_to_ref.fixed index 56330d719389..1bd45bc10a39 100644 --- a/tests/ui/transmute_ptr_to_ref.fixed +++ b/tests/ui/transmute_ptr_to_ref.fixed @@ -7,24 +7,31 @@ unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { let _: &T = &*p; + //~^ transmute_ptr_to_ref let _: &T = &*p; let _: &mut T = &mut *m; + //~^ transmute_ptr_to_ref let _: &mut T = &mut *m; let _: &T = &*m; + //~^ transmute_ptr_to_ref let _: &T = &*m; let _: &mut T = &mut *(p as *mut T); + //~^ transmute_ptr_to_ref let _ = &mut *(p as *mut T); let _: &T = &*(o as *const T); + //~^ transmute_ptr_to_ref let _: &T = &*(o as *const T); let _: &mut T = &mut *(om as *mut T); + //~^ transmute_ptr_to_ref let _: &mut T = &mut *(om as *mut T); let _: &T = &*(om as *const T); + //~^ transmute_ptr_to_ref let _: &T = &*(om as *const T); } @@ -35,20 +42,27 @@ fn _issue1231() { let raw = 42 as *const i32; let _: &Foo = unsafe { &*raw.cast::>() }; + //~^ transmute_ptr_to_ref let _: &Foo<&u8> = unsafe { &*raw.cast::>() }; + //~^ transmute_ptr_to_ref type Bar<'a> = &'a u8; let raw = 42 as *const i32; unsafe { &*(raw as *const u8) }; + //~^ transmute_ptr_to_ref } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { match 0 { 0 => &*x.cast::<&u32>(), + //~^ transmute_ptr_to_ref 1 => &*y.cast::<&u32>(), + //~^ transmute_ptr_to_ref 2 => &*x.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref _ => &*y.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref } } @@ -57,10 +71,14 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; let _: &u32 = &*a; + //~^ transmute_ptr_to_ref let _: &u32 = &*a.cast::(); + //~^ transmute_ptr_to_ref match 0 { 0 => &*x.cast::<&u32>(), + //~^ transmute_ptr_to_ref _ => &*x.cast::<&'b u32>(), + //~^ transmute_ptr_to_ref } } @@ -69,10 +87,14 @@ unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; let _: &u32 = &*a; + //~^ transmute_ptr_to_ref let _: &u32 = &*(a as *const u32); + //~^ transmute_ptr_to_ref match 0 { 0 => &*(x as *const () as *const &u32), + //~^ transmute_ptr_to_ref _ => &*(x as *const () as *const &'b u32), + //~^ transmute_ptr_to_ref } } diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs index ce1ee8bfbfae..cbe64bf1ea6b 100644 --- a/tests/ui/transmute_ptr_to_ref.rs +++ b/tests/ui/transmute_ptr_to_ref.rs @@ -7,24 +7,31 @@ unsafe fn _ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { let _: &T = std::mem::transmute(p); + //~^ transmute_ptr_to_ref let _: &T = &*p; let _: &mut T = std::mem::transmute(m); + //~^ transmute_ptr_to_ref let _: &mut T = &mut *m; let _: &T = std::mem::transmute(m); + //~^ transmute_ptr_to_ref let _: &T = &*m; let _: &mut T = std::mem::transmute(p as *mut T); + //~^ transmute_ptr_to_ref let _ = &mut *(p as *mut T); let _: &T = std::mem::transmute(o); + //~^ transmute_ptr_to_ref let _: &T = &*(o as *const T); let _: &mut T = std::mem::transmute(om); + //~^ transmute_ptr_to_ref let _: &mut T = &mut *(om as *mut T); let _: &T = std::mem::transmute(om); + //~^ transmute_ptr_to_ref let _: &T = &*(om as *const T); } @@ -35,20 +42,27 @@ fn _issue1231() { let raw = 42 as *const i32; let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; + //~^ transmute_ptr_to_ref let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; + //~^ transmute_ptr_to_ref type Bar<'a> = &'a u8; let raw = 42 as *const i32; unsafe { std::mem::transmute::<_, Bar>(raw) }; + //~^ transmute_ptr_to_ref } unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'b u32 { match 0 { 0 => std::mem::transmute(x), + //~^ transmute_ptr_to_ref 1 => std::mem::transmute(y), + //~^ transmute_ptr_to_ref 2 => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(y), + //~^ transmute_ptr_to_ref } } @@ -57,10 +71,14 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; let _: &u32 = std::mem::transmute(a); + //~^ transmute_ptr_to_ref let _: &u32 = std::mem::transmute::<_, &u32>(a); + //~^ transmute_ptr_to_ref match 0 { 0 => std::mem::transmute(x), + //~^ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref } } @@ -69,10 +87,14 @@ unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 { let a = 0u32; let a = &a as *const u32; let _: &u32 = std::mem::transmute(a); + //~^ transmute_ptr_to_ref let _: &u32 = std::mem::transmute::<_, &u32>(a); + //~^ transmute_ptr_to_ref match 0 { 0 => std::mem::transmute(x), + //~^ transmute_ptr_to_ref _ => std::mem::transmute::<_, &&'b u32>(x), + //~^ transmute_ptr_to_ref } } diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index 44cda254c3f7..7fad9b4065a5 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -8,127 +8,127 @@ LL | let _: &T = std::mem::transmute(p); = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ref)]` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> tests/ui/transmute_ptr_to_ref.rs:12:21 + --> tests/ui/transmute_ptr_to_ref.rs:13: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`) - --> tests/ui/transmute_ptr_to_ref.rs:15:17 + --> tests/ui/transmute_ptr_to_ref.rs:17: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`) - --> tests/ui/transmute_ptr_to_ref.rs:18:21 + --> tests/ui/transmute_ptr_to_ref.rs:21: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`) - --> tests/ui/transmute_ptr_to_ref.rs:21:17 + --> tests/ui/transmute_ptr_to_ref.rs:25: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`) - --> tests/ui/transmute_ptr_to_ref.rs:24:21 + --> tests/ui/transmute_ptr_to_ref.rs:29: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`) - --> tests/ui/transmute_ptr_to_ref.rs:27:17 + --> tests/ui/transmute_ptr_to_ref.rs:33: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>`) - --> tests/ui/transmute_ptr_to_ref.rs:37:32 + --> tests/ui/transmute_ptr_to_ref.rs:44:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`) - --> tests/ui/transmute_ptr_to_ref.rs:39:33 + --> tests/ui/transmute_ptr_to_ref.rs:47:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) - --> tests/ui/transmute_ptr_to_ref.rs:43:14 + --> tests/ui/transmute_ptr_to_ref.rs:52: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`) - --> tests/ui/transmute_ptr_to_ref.rs:48:14 + --> tests/ui/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`) - --> tests/ui/transmute_ptr_to_ref.rs:49:14 + --> tests/ui/transmute_ptr_to_ref.rs:60: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`) - --> tests/ui/transmute_ptr_to_ref.rs:50:14 + --> tests/ui/transmute_ptr_to_ref.rs:62: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`) - --> tests/ui/transmute_ptr_to_ref.rs:51:14 + --> tests/ui/transmute_ptr_to_ref.rs:64: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`) - --> tests/ui/transmute_ptr_to_ref.rs:59:19 + --> tests/ui/transmute_ptr_to_ref.rs:73:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:60:19 + --> tests/ui/transmute_ptr_to_ref.rs:75: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`) - --> tests/ui/transmute_ptr_to_ref.rs:62:14 + --> tests/ui/transmute_ptr_to_ref.rs:78: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`) - --> tests/ui/transmute_ptr_to_ref.rs:63:14 + --> tests/ui/transmute_ptr_to_ref.rs:80: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`) - --> tests/ui/transmute_ptr_to_ref.rs:71:19 + --> tests/ui/transmute_ptr_to_ref.rs:89:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:72:19 + --> tests/ui/transmute_ptr_to_ref.rs:91: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`) - --> tests/ui/transmute_ptr_to_ref.rs:74:14 + --> tests/ui/transmute_ptr_to_ref.rs:94: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`) - --> tests/ui/transmute_ptr_to_ref.rs:75:14 + --> tests/ui/transmute_ptr_to_ref.rs:96:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` diff --git a/tests/ui/transmute_ref_to_ref.rs b/tests/ui/transmute_ref_to_ref.rs index 44d7af44a805..c2094ab0cad6 100644 --- a/tests/ui/transmute_ref_to_ref.rs +++ b/tests/ui/transmute_ref_to_ref.rs @@ -7,12 +7,15 @@ fn main() { unsafe { let single_u64: &[u64] = &[0xDEAD_BEEF_DEAD_BEEF]; let bools: &[bool] = unsafe { std::mem::transmute(single_u64) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + let a: &[u32] = &[0x12345678, 0x90ABCDEF, 0xFEDCBA09, 0x87654321]; let b: &[u8] = unsafe { std::mem::transmute(a) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + let bytes = &[1u8, 2u8, 3u8, 4u8] as &[u8]; let alt_slice: &[u32] = unsafe { std::mem::transmute(bytes) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + } } diff --git a/tests/ui/transmute_ref_to_ref.stderr b/tests/ui/transmute_ref_to_ref.stderr index e2d04cea8959..e8d659f9c5d8 100644 --- a/tests/ui/transmute_ref_to_ref.stderr +++ b/tests/ui/transmute_ref_to_ref.stderr @@ -11,13 +11,13 @@ LL | #![deny(clippy::transmute_ptr_to_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a reference to a reference - --> tests/ui/transmute_ref_to_ref.rs:12:33 + --> tests/ui/transmute_ref_to_ref.rs:13:33 | LL | let b: &[u8] = unsafe { std::mem::transmute(a) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const [u32] as *const [u8])` error: transmute from a reference to a reference - --> tests/ui/transmute_ref_to_ref.rs:15:42 + --> tests/ui/transmute_ref_to_ref.rs:17:42 | LL | let alt_slice: &[u32] = unsafe { std::mem::transmute(bytes) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(bytes as *const [u8] as *const [u32])` diff --git a/tests/ui/transmute_ref_to_ref_no_std.rs b/tests/ui/transmute_ref_to_ref_no_std.rs index 591770587549..86c4189d87e4 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.rs +++ b/tests/ui/transmute_ref_to_ref_no_std.rs @@ -19,12 +19,15 @@ fn main() { unsafe { let single_u64: &[u64] = &[0xDEAD_BEEF_DEAD_BEEF]; let bools: &[bool] = unsafe { core::mem::transmute(single_u64) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + let a: &[u32] = &[0x12345678, 0x90ABCDEF, 0xFEDCBA09, 0x87654321]; let b: &[u8] = unsafe { core::mem::transmute(a) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + let bytes = &[1u8, 2u8, 3u8, 4u8] as &[u8]; let alt_slice: &[u32] = unsafe { core::mem::transmute(bytes) }; - //~^ ERROR: transmute from a reference to a reference + //~^ transmute_ptr_to_ptr + } } diff --git a/tests/ui/transmute_ref_to_ref_no_std.stderr b/tests/ui/transmute_ref_to_ref_no_std.stderr index 6a76d6729d05..9aa9ed928a4d 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.stderr +++ b/tests/ui/transmute_ref_to_ref_no_std.stderr @@ -11,13 +11,13 @@ LL | #![deny(clippy::transmute_ptr_to_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a reference to a reference - --> tests/ui/transmute_ref_to_ref_no_std.rs:24:33 + --> tests/ui/transmute_ref_to_ref_no_std.rs:25:33 | LL | let b: &[u8] = unsafe { core::mem::transmute(a) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const [u32] as *const [u8])` error: transmute from a reference to a reference - --> tests/ui/transmute_ref_to_ref_no_std.rs:27:42 + --> tests/ui/transmute_ref_to_ref_no_std.rs:29:42 | LL | let alt_slice: &[u32] = unsafe { core::mem::transmute(bytes) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(bytes as *const [u8] as *const [u32])` diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index 5b16d71f1142..db876150f406 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -32,11 +32,13 @@ 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` + //~^ transmute_undefined_repr + + // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>()); - //~^ ERROR: transmute into `Ty2` which has an undefined layout + //~^ transmute_undefined_repr + // Ok, Ty2 types are the same let _: Ty2 = transmute(value::>>()); @@ -45,24 +47,28 @@ 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 + //~^ transmute_undefined_repr + + // 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 + //~^ transmute_undefined_repr + + 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 + //~^ transmute_undefined_repr + + // 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 + //~^ transmute_undefined_repr + + // Ok, pointer to usize conversion let _: Ty = transmute(value::<&Ty2>()); @@ -91,12 +97,14 @@ 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 + //~^ transmute_undefined_repr + + // 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 + //~^ transmute_undefined_repr + + // Ok, type erasure let _: *const () = transmute(value::>>()); @@ -192,12 +200,14 @@ 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 + //~^ transmute_undefined_repr + + // 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 + //~^ transmute_undefined_repr + + // Ok let _: NonNull = transmute(value::>()); @@ -243,12 +253,14 @@ 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 b41d37a5cd13..a569309b2eb4 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -8,13 +8,13 @@ LL | let _: Ty2C = transmute(value::>()); = help: to override `-D warnings` add `#[allow(clippy::transmute_undefined_repr)]` error: transmute into `Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:38:32 + --> tests/ui/transmute_undefined_repr.rs:39:32 | LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:47:32 + --> tests/ui/transmute_undefined_repr.rs:49:32 | LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | let _: Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:51:36 + --> tests/ui/transmute_undefined_repr.rs:54:36 | LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _: Ty> = transmute(value::>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:59:33 + --> tests/ui/transmute_undefined_repr.rs:63:33 | LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | let _: &Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:63:37 + --> tests/ui/transmute_undefined_repr.rs:68:37 | LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:93:45 + --> tests/ui/transmute_undefined_repr.rs:99:45 | LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | let _: &'static mut Ty2 = transmute(value::` to `std::boxed::Box>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:97:37 + --> tests/ui/transmute_undefined_repr.rs:104:37 | LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | let _: Box> = transmute(value::<&'static mut Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:194:39 + --> tests/ui/transmute_undefined_repr.rs:202:39 | LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _: *const Ty2 = transmute(value::<*const Ty2C` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:198:50 + --> tests/ui/transmute_undefined_repr.rs:207:50 | LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: *const Ty2C> = transmute(value::<*const T = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:245:35 + --> tests/ui/transmute_undefined_repr.rs:255:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | let _: Vec> = transmute(value::>>()); = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:249:35 + --> tests/ui/transmute_undefined_repr.rs:260:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index a4a3ca82e76c..e7ad2a1cbbcb 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -15,28 +15,33 @@ fn main() { // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast let _ptr_i32_transmute = unsafe { usize::MAX as *const i32 }; + //~^ useless_transmute let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; + //~^ transmute_ptr_to_ptr let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0, 1, 2, 3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; + //~^ transmute_ptr_to_ptr let _ptr_to_unsized = slice_ptr as *const [u32]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast let _usize_from_int_ptr_transmute = unsafe { ptr_i32 as usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1, 2, 3, 4]; // e has type &[T; n] and U is *const T; array-ptr-cast let _array_ptr_transmute = unsafe { array_ref as *const [i32; 4] }; + //~^ useless_transmute let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { @@ -45,13 +50,16 @@ fn main() { // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast let _usize_ptr_transmute = unsafe { foo as *const usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast let _usize_from_fn_ptr_transmute = unsafe { foo as usize }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_fn_ptr = foo as *const usize; let _usize_from_ref = unsafe { &1u32 as *const u32 as usize }; + //~^ transmutes_expressible_as_ptr_casts } // If a ref-to-ptr cast of this form where the pointer type points to a type other @@ -63,6 +71,7 @@ fn main() { // fall through into `do_check`. fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { in_param as *const [i32; 1] as *const u8 } + //~^ useless_transmute } #[repr(C)] @@ -81,6 +90,7 @@ fn issue_10449() { fn f() {} let _x: u8 = unsafe { *(f as *const u8) }; + //~^ transmutes_expressible_as_ptr_casts } // Pointers cannot be cast to integers in const contexts diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 6aa8e384e268..42a81777a826 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -15,28 +15,33 @@ fn main() { // e is an integer and U is *U_0, while U_0: Sized; addr-ptr-cast let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; + //~^ useless_transmute let ptr_i32 = usize::MAX as *const i32; // e has type *T, U is *U_0, and either U_0: Sized ... let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; + //~^ transmute_ptr_to_ptr let _ptr_i8 = ptr_i32 as *const i8; let slice_ptr = &[0, 1, 2, 3] as *const [i32]; // ... or pointer_kind(T) = pointer_kind(U_0); ptr-ptr-cast let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; + //~^ transmute_ptr_to_ptr let _ptr_to_unsized = slice_ptr as *const [u32]; // TODO: We could try testing vtable casts here too, but maybe // we should wait until std::raw::TraitObject is stabilized? // e has type *T and U is a numeric type, while T: Sized; ptr-addr-cast let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_int_ptr = ptr_i32 as usize; let array_ref: &[i32; 4] = &[1, 2, 3, 4]; // e has type &[T; n] and U is *const T; array-ptr-cast let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; + //~^ useless_transmute let _array_ptr = array_ref as *const [i32; 4]; fn foo(_: usize) -> u8 { @@ -45,13 +50,16 @@ fn main() { // e is a function pointer type and U has type *T, while T: Sized; fptr-ptr-cast let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_ptr_transmute = foo as *const usize; // e is a function pointer type and U is an integer; fptr-addr-cast let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; + //~^ transmutes_expressible_as_ptr_casts let _usize_from_fn_ptr = foo as *const usize; let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; + //~^ transmutes_expressible_as_ptr_casts } // If a ref-to-ptr cast of this form where the pointer type points to a type other @@ -63,6 +71,7 @@ fn main() { // fall through into `do_check`. fn trigger_do_check_to_emit_error(in_param: &[i32; 1]) -> *const u8 { unsafe { transmute::<&[i32; 1], *const u8>(in_param) } + //~^ useless_transmute } #[repr(C)] @@ -81,6 +90,7 @@ fn issue_10449() { fn f() {} let _x: u8 = unsafe { *std::mem::transmute::(f) }; + //~^ transmutes_expressible_as_ptr_casts } // Pointers cannot be cast to integers in const contexts diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 2d74967ede56..1dab24a78d87 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -8,7 +8,7 @@ LL | let _ptr_i32_transmute = unsafe { transmute::(usize: = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:21:38 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:22:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; | ~~~~~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:27:46 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:29:46 | LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:33:50 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:36:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -41,37 +41,37 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us = help: to override `-D warnings` add `#[allow(clippy::transmutes_expressible_as_ptr_casts)]` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:39:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:43:41 | LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` error: transmute from `fn(usize) -> u8` to `*const usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:47:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:52:41 | LL | let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:51:49 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:57:49 | LL | let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from `*const u32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:54:36 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:61:36 | LL | let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&1u32 as *const u32 as usize` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:65:14 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:73:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` error: transmute from `fn()` to `*const u8` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:83:28 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:92:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs index c2deb6b6c460..91f32a725589 100644 --- a/tests/ui/transmuting_null.rs +++ b/tests/ui/transmuting_null.rs @@ -8,10 +8,12 @@ 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` + //~^ transmuting_null + + let _: &u64 = std::mem::transmute(std::ptr::null::()); - //~^ ERROR: transmuting a known null pointer into a reference + //~^ transmuting_null + } } @@ -22,7 +24,8 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: &u64 = std::mem::transmute(ZPTR); - //~^ ERROR: transmuting a known null pointer into a reference + //~^ transmuting_null + // 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 84e6e374d525..2e5fffd3ac28 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -8,13 +8,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); = help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]` error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:13:23 + --> tests/ui/transmuting_null.rs:14:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:24:23 + --> tests/ui/transmuting_null.rs:26:23 | LL | let _: &u64 = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/trim_split_whitespace.fixed b/tests/ui/trim_split_whitespace.fixed index 6d3daf798a67..c7c241e3075f 100644 --- a/tests/ui/trim_split_whitespace.fixed +++ b/tests/ui/trim_split_whitespace.fixed @@ -59,13 +59,19 @@ impl DerefStrAndCustomTrim { fn main() { // &str let _ = " A B C ".split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // String let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Custom let _ = Custom.trim().split_whitespace(); // should not trigger lint @@ -73,6 +79,7 @@ fn main() { // Deref let s = DerefStr(" A B C "); let _ = s.split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Deref + custom impl let s = DerefStrAndCustom(" A B C "); @@ -81,6 +88,7 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); let _ = s.split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.rs b/tests/ui/trim_split_whitespace.rs index b49d9e8b3fab..aa2cd92430ed 100644 --- a/tests/ui/trim_split_whitespace.rs +++ b/tests/ui/trim_split_whitespace.rs @@ -59,13 +59,19 @@ impl DerefStrAndCustomTrim { fn main() { // &str let _ = " A B C ".trim().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // String let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Custom let _ = Custom.trim().split_whitespace(); // should not trigger lint @@ -73,6 +79,7 @@ fn main() { // Deref let s = DerefStr(" A B C "); let _ = s.trim().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Deref + custom impl let s = DerefStrAndCustom(" A B C "); @@ -81,6 +88,7 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); let _ = s.trim().split_whitespace(); // should trigger lint + //~^ trim_split_whitespace // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index 6119d21a8e9a..deaec54d9363 100644 --- a/tests/ui/trim_split_whitespace.stderr +++ b/tests/ui/trim_split_whitespace.stderr @@ -8,43 +8,43 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::trim_split_whitespace)]` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:62:23 + --> tests/ui/trim_split_whitespace.rs:63:23 | LL | let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:63:23 + --> tests/ui/trim_split_whitespace.rs:65:23 | LL | let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:66:37 + --> tests/ui/trim_split_whitespace.rs:69:37 | LL | let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:67:37 + --> tests/ui/trim_split_whitespace.rs:71:37 | LL | let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:68:37 + --> tests/ui/trim_split_whitespace.rs:73:37 | LL | let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:75:15 + --> tests/ui/trim_split_whitespace.rs:81:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:83:15 + --> tests/ui/trim_split_whitespace.rs:90: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 043a7b63af3c..37bc6f89a20a 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -52,6 +52,7 @@ 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 +//~| 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) {} diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 4887fb00e742..e813fecf653a 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -23,91 +23,91 @@ 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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:61:12 + --> tests/ui/trivially_copy_pass_by_ref.rs:62: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:61:22 + --> tests/ui/trivially_copy_pass_by_ref.rs:62: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:61:31 + --> tests/ui/trivially_copy_pass_by_ref.rs:62: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:61:40 + --> tests/ui/trivially_copy_pass_by_ref.rs:62: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:67:16 + --> tests/ui/trivially_copy_pass_by_ref.rs:68: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:67:25 + --> tests/ui/trivially_copy_pass_by_ref.rs:68: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:67:34 + --> tests/ui/trivially_copy_pass_by_ref.rs:68: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:72:35 + --> tests/ui/trivially_copy_pass_by_ref.rs:73: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:85:16 + --> tests/ui/trivially_copy_pass_by_ref.rs:86: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:85:25 + --> tests/ui/trivially_copy_pass_by_ref.rs:86: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:85:34 + --> tests/ui/trivially_copy_pass_by_ref.rs:86: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:92:34 + --> tests/ui/trivially_copy_pass_by_ref.rs:93: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:125:21 + --> tests/ui/trivially_copy_pass_by_ref.rs:126: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:131:15 + --> tests/ui/trivially_copy_pass_by_ref.rs:132: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: 8 byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:159:37 + --> tests/ui/trivially_copy_pass_by_ref.rs:160:37 | LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { | ^^^^^^^ help: consider passing by value instead: `u32` diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index f149bfb77740..ea509f9a2da8 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -20,6 +20,7 @@ pub fn basic_test() -> Result { // To avoid warnings during rustfix if true { return Err(err); + //~^ try_err } Ok(0) } @@ -30,6 +31,7 @@ pub fn into_test() -> Result { // To avoid warnings during rustfix if true { return Err(err.into()); + //~^ try_err } Ok(0) } @@ -50,6 +52,7 @@ pub fn closure_matches_test() -> Result { // To avoid warnings during rustfix if true { return Err(err); + //~^ try_err } Ok(i) }) @@ -69,6 +72,7 @@ pub fn closure_into_test() -> Result { // To avoid warnings during rustfix if true { return Err(err.into()); + //~^ try_err } Ok(i) }) @@ -89,6 +93,7 @@ fn calling_macro() -> Result { match $(Ok::<_, i32>(5)) { Ok(_) => 0, Err(_) => return Err(1), + //~^ try_err } ); // `Err` arg is another macro @@ -96,6 +101,7 @@ fn calling_macro() -> Result { match $(Ok::<_, i32>(5)) { Ok(_) => 0, Err(_) => return Err(inline!(1)), + //~^ try_err } ); Ok(5) @@ -123,6 +129,7 @@ fn main() { pub fn macro_inside(fail: bool) -> Result { if fail { return Err(inline!(inline!(String::from("aasdfasdfasdfa")))); + //~^ try_err } Ok(0) } @@ -130,8 +137,10 @@ pub fn macro_inside(fail: bool) -> Result { pub fn poll_write(n: usize) -> Poll> { if n == 0 { return Poll::Ready(Err(io::ErrorKind::WriteZero.into())) + //~^ try_err } else if n == 1 { return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))) + //~^ try_err }; Poll::Ready(Ok(n)) @@ -140,6 +149,7 @@ pub fn poll_write(n: usize) -> Poll> { pub fn poll_next(ready: bool) -> Poll>> { if !ready { return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into()))) + //~^ try_err } Poll::Ready(None) @@ -149,6 +159,7 @@ pub fn poll_next(ready: bool) -> Poll>> { pub fn try_return(x: bool) -> Result { if x { return Err(42); + //~^ try_err } Ok(0) } diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index 841ec6b5d5c7..295f7bd7089b 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -20,6 +20,7 @@ pub fn basic_test() -> Result { // To avoid warnings during rustfix if true { Err(err)?; + //~^ try_err } Ok(0) } @@ -30,6 +31,7 @@ pub fn into_test() -> Result { // To avoid warnings during rustfix if true { Err(err)?; + //~^ try_err } Ok(0) } @@ -50,6 +52,7 @@ pub fn closure_matches_test() -> Result { // To avoid warnings during rustfix if true { Err(err)?; + //~^ try_err } Ok(i) }) @@ -69,6 +72,7 @@ pub fn closure_into_test() -> Result { // To avoid warnings during rustfix if true { Err(err)?; + //~^ try_err } Ok(i) }) @@ -89,6 +93,7 @@ fn calling_macro() -> Result { match $(Ok::<_, i32>(5)) { Ok(_) => 0, Err(_) => Err(1)?, + //~^ try_err } ); // `Err` arg is another macro @@ -96,6 +101,7 @@ fn calling_macro() -> Result { match $(Ok::<_, i32>(5)) { Ok(_) => 0, Err(_) => Err(inline!(1))?, + //~^ try_err } ); Ok(5) @@ -123,6 +129,7 @@ fn main() { pub fn macro_inside(fail: bool) -> Result { if fail { Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; + //~^ try_err } Ok(0) } @@ -130,8 +137,10 @@ pub fn macro_inside(fail: bool) -> Result { pub fn poll_write(n: usize) -> Poll> { if n == 0 { Err(io::ErrorKind::WriteZero)? + //~^ try_err } else if n == 1 { Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? + //~^ try_err }; Poll::Ready(Ok(n)) @@ -140,6 +149,7 @@ pub fn poll_write(n: usize) -> Poll> { pub fn poll_next(ready: bool) -> Poll>> { if !ready { Err(io::ErrorKind::NotFound)? + //~^ try_err } Poll::Ready(None) @@ -149,6 +159,7 @@ pub fn poll_next(ready: bool) -> Poll>> { pub fn try_return(x: bool) -> Result { if x { return Err(42)?; + //~^ try_err } Ok(0) } diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index fb563d407866..50c2b092d6c8 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -11,25 +11,25 @@ LL | #![deny(clippy::try_err)] | ^^^^^^^^^^^^^^^ error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:32:9 + --> tests/ui/try_err.rs:33:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:52:17 + --> tests/ui/try_err.rs:54:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:71:17 + --> tests/ui/try_err.rs:74:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:91:23 + --> tests/ui/try_err.rs:95: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 - --> tests/ui/try_err.rs:98:23 + --> tests/ui/try_err.rs:103: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 - --> tests/ui/try_err.rs:125:9 + --> tests/ui/try_err.rs:131:9 | LL | Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:132:9 + --> tests/ui/try_err.rs:139:9 | LL | Err(io::ErrorKind::WriteZero)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:134:9 + --> tests/ui/try_err.rs:142:9 | LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:142:9 + --> tests/ui/try_err.rs:151:9 | LL | Err(io::ErrorKind::NotFound)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:151:16 + --> tests/ui/try_err.rs:161:16 | LL | return Err(42)?; | ^^^^^^^^ help: try: `Err(42)` diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index ca79cc104f22..772c41df090e 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -8,15 +8,21 @@ extern crate proc_macros; fn main() { let x = [1, 2]; let x = (x[0], x[1]); + //~^ tuple_array_conversions let x = [x.0, x.1]; + //~^ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); let t1: &[(u32, u32)] = &[(1, 2), (3, 4)]; let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); + //~^ tuple_array_conversions t1.iter().for_each(|&(a, b)| _ = [a, b]); + //~^ tuple_array_conversions let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); + //~^ tuple_array_conversions t1.iter().for_each(|&(a, b)| _ = [a, b]); + //~^ tuple_array_conversions // Do not lint let v2: Vec<[u32; 2]> = t1.iter().map(|&t| t.into()).collect(); let t3: Vec<(u32, u32)> = v2.iter().map(|&v| v.into()).collect(); @@ -55,9 +61,11 @@ fn main() { // FP #11082; needs discussion let (a, b) = (1.0f64, 2.0f64); let _: &[f64] = &[a, b]; + //~^ tuple_array_conversions // FP #11085; impossible to fix let [src, dest]: [_; 2] = [1, 2]; (src, dest); + //~^ tuple_array_conversions // FP #11100 fn issue_11100_array_to_tuple(this: [&mut i32; 2]) -> (&i32, &mut i32) { let [input, output] = this; @@ -102,7 +110,9 @@ fn msrv_too_low() { fn msrv_juust_right() { let x = [1, 2]; let x = (x[0], x[1]); + //~^ tuple_array_conversions let x = [x.0, x.1]; + //~^ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); } diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index 9e022b3cfb25..6dafb8d285d4 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -9,7 +9,7 @@ LL | let x = (x[0], x[1]); = help: to override `-D warnings` add `#[allow(clippy::tuple_array_conversions)]` error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:11:13 + --> tests/ui/tuple_array_conversions.rs:12:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let x = [x.0, x.1]; = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:16:53 + --> tests/ui/tuple_array_conversions.rs:18:53 | LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); | ^^^^^^ @@ -25,7 +25,7 @@ LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:17:38 + --> tests/ui/tuple_array_conversions.rs:20:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -33,7 +33,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:18:55 + --> tests/ui/tuple_array_conversions.rs:22:55 | LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); | ^^^^^^ @@ -41,7 +41,7 @@ LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:19:38 + --> tests/ui/tuple_array_conversions.rs:24:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -49,7 +49,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:57:22 + --> tests/ui/tuple_array_conversions.rs:63:22 | LL | let _: &[f64] = &[a, b]; | ^^^^^^ @@ -57,7 +57,7 @@ LL | let _: &[f64] = &[a, b]; = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:60:5 + --> tests/ui/tuple_array_conversions.rs:67:5 | LL | (src, dest); | ^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | (src, dest); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:104:13 + --> tests/ui/tuple_array_conversions.rs:112:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let x = (x[0], x[1]); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:105:13 + --> tests/ui/tuple_array_conversions.rs:114:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ diff --git a/tests/ui/ty_fn_sig.rs b/tests/ui/ty_fn_sig.rs index 9e2753dcb18d..60767bfad135 100644 --- a/tests/ui/ty_fn_sig.rs +++ b/tests/ui/ty_fn_sig.rs @@ -1,3 +1,4 @@ +//@ check-pass // Regression test pub fn retry(f: F) { diff --git a/tests/ui/type_complexity.rs b/tests/ui/type_complexity.rs index be28ee2da0cd..09c7bcc68408 100644 --- a/tests/ui/type_complexity.rs +++ b/tests/ui/type_complexity.rs @@ -5,42 +5,54 @@ 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` +//~^ type_complexity + + static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); -//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~^ type_complexity + struct S { f: Vec>>, - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + } struct Ts(Vec>>); -//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~^ type_complexity + enum E { Tuple(Vec>>), - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + Struct { f: Vec>> }, - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + } 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 + //~^ type_complexity + fn impl_method(&self, p: Vec>>) {} - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + } trait T { const A: Vec>>; - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + type B = Vec>>; - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + fn method(&self, p: Vec>>); - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + fn def_method(&self, p: Vec>>) {} - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + } // Should not warn since there is likely no way to simplify this (#1013) @@ -53,16 +65,19 @@ impl T for () { } fn test1() -> Vec>> { - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~^ type_complexity + vec![] } fn test2(_x: Vec>>) {} -//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~^ type_complexity + fn test3() { let _y: Vec>> = vec![]; - //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions + //~^ type_complexity + } #[repr(C)] diff --git a/tests/ui/type_complexity.stderr b/tests/ui/type_complexity.stderr index 9e27899e4f90..4926432aab88 100644 --- a/tests/ui/type_complexity.stderr +++ b/tests/ui/type_complexity.stderr @@ -8,85 +8,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:10:12 + --> tests/ui/type_complexity.rs:11: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 - --> tests/ui/type_complexity.rs:14:8 + --> tests/ui/type_complexity.rs:16:8 | LL | f: Vec>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:18:11 + --> tests/ui/type_complexity.rs:21:11 | LL | struct Ts(Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:22:11 + --> tests/ui/type_complexity.rs:26:11 | LL | Tuple(Vec>>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:24:17 + --> tests/ui/type_complexity.rs:29:17 | LL | Struct { f: Vec>> }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:29:14 + --> tests/ui/type_complexity.rs:35: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 - --> tests/ui/type_complexity.rs:31:30 + --> tests/ui/type_complexity.rs:38:30 | LL | fn impl_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:36:14 + --> tests/ui/type_complexity.rs:44:14 | LL | const A: Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:38:14 + --> tests/ui/type_complexity.rs:47:14 | LL | type B = Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:40:25 + --> tests/ui/type_complexity.rs:50:25 | LL | fn method(&self, p: Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:42:29 + --> tests/ui/type_complexity.rs:53:29 | LL | fn def_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:55:15 + --> tests/ui/type_complexity.rs:67:15 | LL | fn test1() -> Vec>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:60:14 + --> tests/ui/type_complexity.rs:73:14 | LL | fn test2(_x: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:64:13 + --> tests/ui/type_complexity.rs:78:13 | LL | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_id_on_box.fixed b/tests/ui/type_id_on_box.fixed index 3656043700fa..f0d8a4acb2e3 100644 --- a/tests/ui/type_id_on_box.fixed +++ b/tests/ui/type_id_on_box.fixed @@ -29,7 +29,8 @@ fn main() { let any_box: Box = Box::new(0usize); let _ = (*any_box).type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + // Don't lint. We explicitly say "do this instead" if this is intentional let _ = TypeId::of::>(); @@ -38,18 +39,21 @@ fn main() { // 2 derefs are needed here to get to the `dyn Any` let any_box: &Box = &(Box::new(0usize) as Box); let _ = (**any_box).type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b = existential(); let _ = b.type_id(); // Don't let b: Box = Box::new(1); let _ = (*b).type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b: SomeBox = Box::new(0usize); let _ = (*b).type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! diff --git a/tests/ui/type_id_on_box.rs b/tests/ui/type_id_on_box.rs index 4bd9e73f2da0..b446ec287b67 100644 --- a/tests/ui/type_id_on_box.rs +++ b/tests/ui/type_id_on_box.rs @@ -29,7 +29,8 @@ fn main() { let any_box: Box = Box::new(0usize); let _ = any_box.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + // Don't lint. We explicitly say "do this instead" if this is intentional let _ = TypeId::of::>(); @@ -38,18 +39,21 @@ fn main() { // 2 derefs are needed here to get to the `dyn Any` let any_box: &Box = &(Box::new(0usize) as Box); let _ = any_box.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b = existential(); let _ = b.type_id(); // Don't let b: Box = Box::new(1); let _ = b.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b: SomeBox = Box::new(0usize); let _ = b.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! diff --git a/tests/ui/type_id_on_box.stderr b/tests/ui/type_id_on_box.stderr index 4528195607da..8004ef71287c 100644 --- a/tests/ui/type_id_on_box.stderr +++ b/tests/ui/type_id_on_box.stderr @@ -12,7 +12,7 @@ LL | let _ = any_box.type_id(); = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:40:13 + --> tests/ui/type_id_on_box.rs:41:13 | LL | let _ = any_box.type_id(); | -------^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = any_box.type_id(); = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:47:13 + --> tests/ui/type_id_on_box.rs:49:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = b.type_id(); = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:51:13 + --> tests/ui/type_id_on_box.rs:54:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ diff --git a/tests/ui/type_id_on_box_unfixable.rs b/tests/ui/type_id_on_box_unfixable.rs index 67e398e604b4..4df0ebb897a8 100644 --- a/tests/ui/type_id_on_box_unfixable.rs +++ b/tests/ui/type_id_on_box_unfixable.rs @@ -23,9 +23,11 @@ fn main() { // could) let b: Box = Box::new(1); let _ = b.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + let b: Box = Box::new(1); let _ = b.type_id(); - //~^ ERROR: calling `.type_id()` on + //~^ type_id_on_box + } diff --git a/tests/ui/type_id_on_box_unfixable.stderr b/tests/ui/type_id_on_box_unfixable.stderr index 539ed481ec10..c653fd7835ff 100644 --- a/tests/ui/type_id_on_box_unfixable.stderr +++ b/tests/ui/type_id_on_box_unfixable.stderr @@ -10,7 +10,7 @@ LL | let _ = b.type_id(); = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box_unfixable.rs:29:13 + --> tests/ui/type_id_on_box_unfixable.rs:30:13 | LL | let _ = b.type_id(); | ^^^^^^^^^^^ diff --git a/tests/ui/unchecked_duration_subtraction.fixed b/tests/ui/unchecked_duration_subtraction.fixed index a0c3330d1777..bddffe44ac4d 100644 --- a/tests/ui/unchecked_duration_subtraction.fixed +++ b/tests/ui/unchecked_duration_subtraction.fixed @@ -7,10 +7,14 @@ fn main() { let second = Duration::from_secs(3); let _ = _first.checked_sub(second).unwrap(); + //~^ unchecked_duration_subtraction let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap(); + //~^ unchecked_duration_subtraction let _ = _first.checked_sub(Duration::from_secs(5)).unwrap(); + //~^ unchecked_duration_subtraction let _ = Instant::now().checked_sub(second).unwrap(); + //~^ unchecked_duration_subtraction } diff --git a/tests/ui/unchecked_duration_subtraction.rs b/tests/ui/unchecked_duration_subtraction.rs index fff1d13720d9..bb0f71239642 100644 --- a/tests/ui/unchecked_duration_subtraction.rs +++ b/tests/ui/unchecked_duration_subtraction.rs @@ -7,10 +7,14 @@ fn main() { let second = Duration::from_secs(3); let _ = _first - second; + //~^ unchecked_duration_subtraction let _ = Instant::now() - Duration::from_secs(5); + //~^ unchecked_duration_subtraction let _ = _first - Duration::from_secs(5); + //~^ unchecked_duration_subtraction let _ = Instant::now() - second; + //~^ unchecked_duration_subtraction } diff --git a/tests/ui/unchecked_duration_subtraction.stderr b/tests/ui/unchecked_duration_subtraction.stderr index b5e9bab86b47..be291c320e68 100644 --- a/tests/ui/unchecked_duration_subtraction.stderr +++ b/tests/ui/unchecked_duration_subtraction.stderr @@ -8,19 +8,19 @@ LL | let _ = _first - second; = help: to override `-D warnings` add `#[allow(clippy::unchecked_duration_subtraction)]` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> tests/ui/unchecked_duration_subtraction.rs:11:13 + --> tests/ui/unchecked_duration_subtraction.rs:12: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' - --> tests/ui/unchecked_duration_subtraction.rs:13:13 + --> tests/ui/unchecked_duration_subtraction.rs:15: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' - --> tests/ui/unchecked_duration_subtraction.rs:15:13 + --> tests/ui/unchecked_duration_subtraction.rs:18:13 | LL | let _ = Instant::now() - second; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()` diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index b8476a7088a1..6cbd6bffb8db 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -15,11 +15,13 @@ enum Foo { impl PartialEq for Foo { fn ne(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + self != other } fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + self == other } } @@ -31,9 +33,11 @@ enum Foo2 { impl PartialEq for Foo2 { fn ne(&self, other: &Self) -> bool { + //~^ unconditional_recursion self != &Foo2::B // no error here } fn eq(&self, other: &Self) -> bool { + //~^ unconditional_recursion self == &Foo2::B // no error here } } @@ -45,11 +49,14 @@ enum Foo3 { impl PartialEq for Foo3 { fn ne(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + //~| ERROR: function cannot return without recursing self.ne(other) } fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + //~| ERROR: function cannot return without recursing + self.eq(other) } } @@ -93,11 +100,13 @@ struct S; // Check the order doesn't matter. impl PartialEq for S { fn ne(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + other != self } fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + other == self } } @@ -107,12 +116,16 @@ struct S2; // Check that if the same element is compared, it's also triggering the lint. impl PartialEq for S2 { fn ne(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + other != other + //~^ eq_op } fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + other == other + //~^ eq_op } } @@ -120,12 +133,16 @@ struct S3; impl PartialEq for S3 { fn ne(&self, _other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + self != self + //~^ eq_op } fn eq(&self, _other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + self == self + //~^ eq_op } } @@ -152,7 +169,8 @@ macro_rules! impl_partial_eq { ($ty:ident) => { impl PartialEq for $ty { fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + self == other } } @@ -181,7 +199,8 @@ struct S7<'a> { impl<'a> PartialEq for S7<'a> { fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + let mine = &self.field; let theirs = &other.field; mine == theirs @@ -250,7 +269,8 @@ impl std::default::Default for S12 { impl S12 { fn new() -> Self { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + Self::default() } @@ -289,7 +309,8 @@ struct S15<'a> { impl PartialEq for S15<'_> { fn eq(&self, other: &Self) -> bool { - //~^ ERROR: function cannot return without recursing + //~^ unconditional_recursion + let mine = &self.field; let theirs = &other.field; mine.eq(theirs) @@ -360,6 +381,7 @@ struct BadFromTy1<'a>(&'a ()); struct BadIntoTy1<'b>(&'b ()); impl<'a> From> for BadIntoTy1<'static> { fn from(f: BadFromTy1<'a>) -> Self { + //~^ unconditional_recursion f.into() } } @@ -369,6 +391,7 @@ struct BadFromTy2<'a>(&'a ()); struct BadIntoTy2<'b>(&'b ()); impl<'a> From> for BadIntoTy2<'static> { fn from(f: BadFromTy2<'a>) -> Self { + //~^ unconditional_recursion Into::into(f) } } diff --git a/tests/ui/unconditional_recursion.stderr b/tests/ui/unconditional_recursion.stderr index 6a0078ee0906..c6eaa6a0775c 100644 --- a/tests/ui/unconditional_recursion.stderr +++ b/tests/ui/unconditional_recursion.stderr @@ -1,9 +1,9 @@ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:47:5 + --> tests/ui/unconditional_recursion.rs:51:5 | LL | fn ne(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -LL | +... LL | self.ne(other) | -------------- recursive call site | @@ -12,18 +12,18 @@ LL | self.ne(other) = help: to override `-D warnings` add `#[allow(unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:51:5 + --> tests/ui/unconditional_recursion.rs:56:5 | LL | fn eq(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -LL | +... LL | self.eq(other) | -------------- recursive call site | = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:216:5 + --> tests/ui/unconditional_recursion.rs:235:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -34,7 +34,7 @@ LL | self.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:226:5 + --> tests/ui/unconditional_recursion.rs:245:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -45,7 +45,7 @@ LL | x.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:237:5 + --> tests/ui/unconditional_recursion.rs:256:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -60,12 +60,13 @@ error: function cannot return without recursing | LL | / fn ne(&self, other: &Self) -> bool { LL | | +LL | | LL | | self != other LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:19:9 + --> tests/ui/unconditional_recursion.rs:20:9 | LL | self != other | ^^^^^^^^^^^^^ @@ -73,125 +74,132 @@ LL | self != other = help: to override `-D warnings` add `#[allow(clippy::unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:21:5 + --> tests/ui/unconditional_recursion.rs:22:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | self == other LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:23:9 + --> tests/ui/unconditional_recursion.rs:25:9 | LL | self == other | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:33:5 + --> tests/ui/unconditional_recursion.rs:35:5 | LL | / fn ne(&self, other: &Self) -> bool { +LL | | LL | | self != &Foo2::B // no error here -LL | | } - | |_____^ - | -note: recursive call site - --> tests/ui/unconditional_recursion.rs:34:9 - | -LL | self != &Foo2::B // no error here - | ^^^^^^^^^^^^^^^^ - -error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:36:5 - | -LL | / fn eq(&self, other: &Self) -> bool { -LL | | self == &Foo2::B // no error here LL | | } | |_____^ | note: recursive call site --> tests/ui/unconditional_recursion.rs:37:9 | +LL | self != &Foo2::B // no error here + | ^^^^^^^^^^^^^^^^ + +error: function cannot return without recursing + --> tests/ui/unconditional_recursion.rs:39:5 + | +LL | / fn eq(&self, other: &Self) -> bool { +LL | | +LL | | self == &Foo2::B // no error here +LL | | } + | |_____^ + | +note: recursive call site + --> tests/ui/unconditional_recursion.rs:41:9 + | LL | self == &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:47:5 + --> tests/ui/unconditional_recursion.rs:51:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | +LL | | LL | | self.ne(other) LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:49:9 + --> tests/ui/unconditional_recursion.rs:54:9 | LL | self.ne(other) | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:51:5 + --> tests/ui/unconditional_recursion.rs:56:5 | LL | / fn eq(&self, other: &Self) -> bool { -LL | | -LL | | self.eq(other) +... | LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:53:9 + --> tests/ui/unconditional_recursion.rs:60:9 | LL | self.eq(other) | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:95:5 + --> tests/ui/unconditional_recursion.rs:102:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | +LL | | LL | | other != self LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:97:9 + --> tests/ui/unconditional_recursion.rs:105:9 | LL | other != self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:99:5 + --> tests/ui/unconditional_recursion.rs:107:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | other == self LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:101:9 + --> tests/ui/unconditional_recursion.rs:110:9 | LL | other == self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:109:5 + --> tests/ui/unconditional_recursion.rs:118:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | +LL | | LL | | other != other +LL | | LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:111:9 + --> tests/ui/unconditional_recursion.rs:121:9 | LL | other != other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:111:9 + --> tests/ui/unconditional_recursion.rs:121:9 | LL | other != other | ^^^^^^^^^^^^^^ @@ -199,73 +207,80 @@ LL | other != other = note: `#[deny(clippy::eq_op)]` on by default error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:113:5 + --> tests/ui/unconditional_recursion.rs:124:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | other == other +LL | | LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:115:9 + --> tests/ui/unconditional_recursion.rs:127:9 | LL | other == other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:115:9 + --> tests/ui/unconditional_recursion.rs:127:9 | LL | other == other | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:122:5 + --> tests/ui/unconditional_recursion.rs:135:5 | LL | / fn ne(&self, _other: &Self) -> bool { LL | | +LL | | LL | | self != self +LL | | LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:124:9 + --> tests/ui/unconditional_recursion.rs:138:9 | LL | self != self | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:124:9 + --> tests/ui/unconditional_recursion.rs:138:9 | LL | self != self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:126:5 + --> tests/ui/unconditional_recursion.rs:141:5 | LL | / fn eq(&self, _other: &Self) -> bool { LL | | +LL | | LL | | self == self +LL | | LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:128:9 + --> tests/ui/unconditional_recursion.rs:144:9 | LL | self == self | ^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:128:9 + --> tests/ui/unconditional_recursion.rs:144:9 | LL | self == self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:154:13 + --> tests/ui/unconditional_recursion.rs:171:13 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | self == other LL | | } | |_____________^ @@ -274,7 +289,7 @@ LL | impl_partial_eq!(S5); | -------------------- in this macro invocation | note: recursive call site - --> tests/ui/unconditional_recursion.rs:156:17 + --> tests/ui/unconditional_recursion.rs:174:17 | LL | self == other | ^^^^^^^^^^^^^ @@ -284,10 +299,11 @@ LL | impl_partial_eq!(S5); = note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:183:5 + --> tests/ui/unconditional_recursion.rs:201:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | let mine = &self.field; LL | | let theirs = &other.field; LL | | mine == theirs @@ -295,31 +311,33 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:187:9 + --> tests/ui/unconditional_recursion.rs:206:9 | LL | mine == theirs | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:252:5 + --> tests/ui/unconditional_recursion.rs:271:5 | LL | / fn new() -> Self { LL | | +LL | | LL | | Self::default() LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:254:9 + --> tests/ui/unconditional_recursion.rs:274:9 | LL | Self::default() | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:291:5 + --> tests/ui/unconditional_recursion.rs:311:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | +LL | | LL | | let mine = &self.field; LL | | let theirs = &other.field; LL | | mine.eq(theirs) @@ -327,35 +345,37 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:295:9 + --> tests/ui/unconditional_recursion.rs:316:9 | LL | mine.eq(theirs) | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:362:5 + --> tests/ui/unconditional_recursion.rs:383:5 | LL | / fn from(f: BadFromTy1<'a>) -> Self { +LL | | LL | | f.into() LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:363:9 + --> tests/ui/unconditional_recursion.rs:385:9 | LL | f.into() | ^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:371:5 + --> tests/ui/unconditional_recursion.rs:393:5 | LL | / fn from(f: BadFromTy2<'a>) -> Self { +LL | | LL | | Into::into(f) LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:372:9 + --> tests/ui/unconditional_recursion.rs:395:9 | LL | Into::into(f) | ^^^^^^^^^^^^^ diff --git a/tests/ui/unicode.fixed b/tests/ui/unicode.fixed index f9efb4ec34c6..9234b440d964 100644 --- a/tests/ui/unicode.fixed +++ b/tests/ui/unicode.fixed @@ -3,16 +3,20 @@ #[warn(clippy::invisible_characters)] fn zero() { print!("Here >\u{200B}< is a ZWS, and \u{200B}another"); + //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); print!("Here >\u{AD}< is a SHY, and \u{AD}another"); + //~^ invisible_characters print!("This\u{ad}is\u{ad}fine"); print!("Here >\u{2060}< is a WJ, and \u{2060}another"); + //~^ invisible_characters print!("This\u{2060}is\u{2060}fine"); } #[warn(clippy::unicode_not_nfc)] fn canon() { print!("̀àh?"); + //~^ unicode_not_nfc print!("a\u{0300}h?"); // also ok } @@ -21,13 +25,16 @@ mod non_ascii_literal { fn uni() { print!("\u{dc}ben!"); + //~^ non_ascii_literal print!("\u{DC}ben!"); // this is ok } // issue 8013 fn single_quote() { const _EMPTY_BLOCK: char = '\u{25b1}'; + //~^ non_ascii_literal const _FULL_BLOCK: char = '\u{25b0}'; + //~^ non_ascii_literal } #[test] @@ -48,6 +55,7 @@ mod non_ascii_literal { #[test] fn denied() { let _ = "\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}"; + //~^ non_ascii_literal } } } diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index bba613e228ed..ada8bac8e049 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -3,16 +3,20 @@ #[warn(clippy::invisible_characters)] fn zero() { print!("Here >​< is a ZWS, and ​another"); + //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); print!("Here >­< is a SHY, and ­another"); + //~^ invisible_characters print!("This\u{ad}is\u{ad}fine"); print!("Here >⁠< is a WJ, and ⁠another"); + //~^ invisible_characters print!("This\u{2060}is\u{2060}fine"); } #[warn(clippy::unicode_not_nfc)] fn canon() { print!("̀àh?"); + //~^ unicode_not_nfc print!("a\u{0300}h?"); // also ok } @@ -21,13 +25,16 @@ mod non_ascii_literal { fn uni() { print!("Üben!"); + //~^ non_ascii_literal print!("\u{DC}ben!"); // this is ok } // issue 8013 fn single_quote() { const _EMPTY_BLOCK: char = '▱'; + //~^ non_ascii_literal const _FULL_BLOCK: char = '▰'; + //~^ non_ascii_literal } #[test] @@ -48,6 +55,7 @@ mod non_ascii_literal { #[test] fn denied() { let _ = "悲しいかな、ここに日本語を書くことはできない。"; + //~^ non_ascii_literal } } } diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index b004493300ee..c761ec89602f 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -8,19 +8,19 @@ LL | print!("Here >​< is a ZWS, and ​another"); = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` error: invisible character detected - --> tests/ui/unicode.rs:7:12 + --> tests/ui/unicode.rs:8:12 | LL | print!("Here >­< is a SHY, and ­another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected - --> tests/ui/unicode.rs:9:12 + --> tests/ui/unicode.rs:11: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 - --> tests/ui/unicode.rs:15:12 + --> tests/ui/unicode.rs:18:12 | LL | print!("̀àh?"); | ^^^^^ help: consider replacing the string with: `"̀àh?"` @@ -29,37 +29,37 @@ LL | print!("̀àh?"); = help: to override `-D warnings` add `#[allow(clippy::unicode_not_nfc)]` error: literal non-ASCII character detected - --> tests/ui/unicode.rs:23:16 + --> tests/ui/unicode.rs:27:16 | LL | print!("Üben!"); | ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"` | note: the lint level is defined here - --> tests/ui/unicode.rs:20:13 + --> tests/ui/unicode.rs:24:13 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal non-ASCII character detected - --> tests/ui/unicode.rs:29:36 + --> tests/ui/unicode.rs:34:36 | LL | const _EMPTY_BLOCK: char = '▱'; | ^^^ help: consider replacing the string with: `'\u{25b1}'` error: literal non-ASCII character detected - --> tests/ui/unicode.rs:30:35 + --> tests/ui/unicode.rs:36:35 | LL | const _FULL_BLOCK: char = '▰'; | ^^^ help: consider replacing the string with: `'\u{25b0}'` error: literal non-ASCII character detected - --> tests/ui/unicode.rs:50:21 + --> tests/ui/unicode.rs:57:21 | LL | let _ = "悲しいかな、ここに日本語を書くことはできない。"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"\u{60b2}\u{3057}\u{3044}\u{304b}\u{306a}\u{3001}\u{3053}\u{3053}\u{306b}\u{65e5}\u{672c}\u{8a9e}\u{3092}\u{66f8}\u{304f}\u{3053}\u{3068}\u{306f}\u{3067}\u{304d}\u{306a}\u{3044}\u{3002}"` | note: the lint level is defined here - --> tests/ui/unicode.rs:39:17 + --> tests/ui/unicode.rs:46:17 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninhabited_references.rs b/tests/ui/uninhabited_references.rs index 3569366ed056..649af4312ce4 100644 --- a/tests/ui/uninhabited_references.rs +++ b/tests/ui/uninhabited_references.rs @@ -3,13 +3,16 @@ #![feature(never_type)] fn ret_uninh_ref() -> &'static std::convert::Infallible { +//~^ uninhabited_references unsafe { std::mem::transmute(&()) } } macro_rules! ret_something { ($name:ident, $ty:ty) => { fn $name(x: &$ty) -> &$ty { + //~^ uninhabited_references &*x + //~^ uninhabited_references } }; } @@ -20,4 +23,5 @@ ret_something!(id_never, !); fn main() { let x = ret_uninh_ref(); let _ = *x; + //~^ uninhabited_references } diff --git a/tests/ui/uninhabited_references.stderr b/tests/ui/uninhabited_references.stderr index 8c9b206f4296..ac05ab5bb4d4 100644 --- a/tests/ui/uninhabited_references.stderr +++ b/tests/ui/uninhabited_references.stderr @@ -8,7 +8,7 @@ LL | fn ret_uninh_ref() -> &'static std::convert::Infallible { = help: to override `-D warnings` add `#[allow(clippy::uninhabited_references)]` error: dereferencing a reference to an uninhabited type would be undefined behavior - --> tests/ui/uninhabited_references.rs:11:30 + --> tests/ui/uninhabited_references.rs:12:30 | LL | fn $name(x: &$ty) -> &$ty { | ^^^^ @@ -19,7 +19,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> tests/ui/uninhabited_references.rs:12:14 + --> tests/ui/uninhabited_references.rs:14:14 | LL | &*x | ^^ @@ -30,7 +30,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> tests/ui/uninhabited_references.rs:22:13 + --> tests/ui/uninhabited_references.rs:25:13 | LL | let _ = *x; | ^^ diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index 10a4c22b5b91..965ef4a10b39 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -10,8 +10,9 @@ 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 + //~^ uninit_assumed_init + + // This is OK, because ZSTs do not contain data. let _: () = unsafe { MaybeUninit::uninit().assume_init() }; @@ -33,7 +34,8 @@ fn main() { // Was a false negative. let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; - //~^ ERROR: this call for this type may be undefined behavior + //~^ uninit_assumed_init + polymorphic::<()>(); polymorphic_maybe_uninit_array::<10>(); @@ -42,7 +44,8 @@ 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 + //~^ uninit_assumed_init + } fn polymorphic_maybe_uninit_array() { diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr index 81577fe3fd47..9179a2b28dbb 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 - --> tests/ui/uninit.rs:35:29 + --> tests/ui/uninit.rs:36:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:44:29 + --> tests/ui/uninit.rs:46:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninit_vec.rs b/tests/ui/uninit_vec.rs index 464f88140bdb..a48397137992 100644 --- a/tests/ui/uninit_vec.rs +++ b/tests/ui/uninit_vec.rs @@ -16,40 +16,46 @@ union MyOwnMaybeUninit { // https://github.com/rust-lang/rust/issues/119620 unsafe fn requires_paramenv() { let mut vec = Vec::>::with_capacity(1); + //~^ uninit_vec vec.set_len(1); } 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 + //~^ uninit_vec + 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 + //~^ uninit_vec + 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 + //~^ uninit_vec + 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 + //~^ uninit_vec + unsafe { vec.set_len(200); } let mut vec: Vec = Vec::default(); - //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values + //~^ uninit_vec + unsafe { vec.set_len(200); } @@ -57,16 +63,19 @@ 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 + //~^ uninit_vec + vec.set_len(200); vec.reserve(1000); - //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini + //~^ uninit_vec + vec.set_len(200); } let mut vec: Vec = Vec::with_capacity(1000); - //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial + //~^ uninit_vec + unsafe { // test the case where there are other statements in the following unsafe block vec.set_len(200); @@ -76,13 +85,15 @@ 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 + //~^ uninit_vec + 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 + //~^ uninit_vec + unsafe { my_vec.vec.set_len(200); } @@ -137,7 +148,8 @@ 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 + //~^ uninit_vec + unsafe { vec.set_len(10); } @@ -165,6 +177,7 @@ fn main() { let mut vec: Vec> = Vec::with_capacity(1); //~^ uninit_vec + unsafe { vec.set_len(1); } @@ -178,6 +191,7 @@ fn main() { // Enums can have a discriminant that can't be uninit, so this should still warn let mut vec: Vec> = Vec::with_capacity(1); //~^ uninit_vec + unsafe { vec.set_len(1); } diff --git a/tests/ui/uninit_vec.stderr b/tests/ui/uninit_vec.stderr index e7c81cf792f2..7ff6140a2c3e 100644 --- a/tests/ui/uninit_vec.stderr +++ b/tests/ui/uninit_vec.stderr @@ -3,6 +3,7 @@ error: calling `set_len()` immediately after reserving a buffer creates uninitia | LL | let mut vec = Vec::>::with_capacity(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(1); | ^^^^^^^^^^^^^^ | @@ -11,7 +12,7 @@ LL | vec.set_len(1); = help: to override `-D warnings` add `#[allow(clippy::uninit_vec)]` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> tests/ui/uninit_vec.rs:24:5 + --> tests/ui/uninit_vec.rs:25:5 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +23,7 @@ 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 - --> tests/ui/uninit_vec.rs:31:5 + --> tests/ui/uninit_vec.rs:33:5 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ @@ -33,7 +34,7 @@ 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 - --> tests/ui/uninit_vec.rs:38:5 + --> tests/ui/uninit_vec.rs:41:5 | LL | let mut vec: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +43,7 @@ LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> tests/ui/uninit_vec.rs:45:5 + --> tests/ui/uninit_vec.rs:49:5 | LL | let mut vec: Vec = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +52,7 @@ LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> tests/ui/uninit_vec.rs:51:5 + --> tests/ui/uninit_vec.rs:56:5 | LL | let mut vec: Vec = Vec::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> tests/ui/uninit_vec.rs:68:5 + --> tests/ui/uninit_vec.rs:76:5 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +72,7 @@ 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 - --> tests/ui/uninit_vec.rs:78:5 + --> tests/ui/uninit_vec.rs:87:5 | LL | my_vec.vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +83,7 @@ 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 - --> tests/ui/uninit_vec.rs:84:5 + --> tests/ui/uninit_vec.rs:94:5 | LL | my_vec.vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -93,29 +94,29 @@ 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 - --> tests/ui/uninit_vec.rs:59:9 + --> tests/ui/uninit_vec.rs:65: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 - --> tests/ui/uninit_vec.rs:63:9 + --> tests/ui/uninit_vec.rs:70: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 - --> tests/ui/uninit_vec.rs:139:9 + --> tests/ui/uninit_vec.rs:150:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,7 +127,7 @@ LL | vec.set_len(10); = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> tests/ui/uninit_vec.rs:166:9 + --> tests/ui/uninit_vec.rs:178:9 | LL | let mut vec: Vec> = Vec::with_capacity(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,7 +138,7 @@ LL | vec.set_len(1); = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> tests/ui/uninit_vec.rs:179:9 + --> tests/ui/uninit_vec.rs:192:9 | LL | let mut vec: Vec> = Vec::with_capacity(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 111a2e1987c8..444a5b1cfb5f 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -43,75 +43,137 @@ fn tester(fn_arg: i32) { let _: &[u8; 3] = b" "; // <- println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("val='{local_i32}'"); // 3 spaces + //~^ uninlined_format_args println!("val='{local_i32}'"); // tab + //~^ uninlined_format_args println!("val='{local_i32}'"); // space+tab + //~^ uninlined_format_args println!("val='{local_i32}'"); // tab+space + //~^ uninlined_format_args println!( + //~^ uninlined_format_args "val='{local_i32}'" ); println!("{local_i32}"); + //~^ uninlined_format_args println!("{fn_arg}"); + //~^ uninlined_format_args println!("{local_i32:?}"); + //~^ uninlined_format_args println!("{local_i32:#?}"); + //~^ uninlined_format_args println!("{local_i32:4}"); + //~^ uninlined_format_args println!("{local_i32:04}"); + //~^ uninlined_format_args println!("{local_i32:<3}"); + //~^ uninlined_format_args println!("{local_i32:#010x}"); + //~^ uninlined_format_args println!("{local_f64:.1}"); + //~^ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); println!("Hello {} is {:.*}", local_i32, 5, local_f64); println!("Hello {} is {2:.*}", local_i32, 5, local_f64); println!("{local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); println!("{val}"); + //~^ uninlined_format_args println!("{val}"); + //~^ uninlined_format_args println!("{} {1}", local_i32, 42); println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("val='{fn_arg}'"); + //~^ uninlined_format_args println!("{local_i32}"); + //~^ uninlined_format_args println!("{local_i32:?}"); + //~^ uninlined_format_args println!("{local_i32:#?}"); + //~^ uninlined_format_args println!("{local_i32:04}"); + //~^ uninlined_format_args println!("{local_i32:<3}"); + //~^ uninlined_format_args println!("{local_i32:#010x}"); + //~^ uninlined_format_args println!("{local_f64:.1}"); + //~^ uninlined_format_args println!("{local_i32} {local_i32}"); + //~^ uninlined_format_args println!("{local_f64} {local_i32} {local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{local_i32} {local_f64}"); + //~^ uninlined_format_args println!("{local_f64} {local_i32}"); + //~^ uninlined_format_args println!("{local_f64} {local_i32} {local_f64} {local_i32}"); + //~^ uninlined_format_args println!("{1} {0}", "str", local_i32); println!("{local_i32}"); + //~^ uninlined_format_args println!("{local_i32:width$}"); + //~^ uninlined_format_args println!("{local_i32:width$}"); + //~^ uninlined_format_args println!("{local_i32:.prec$}"); + //~^ uninlined_format_args println!("{local_i32:.prec$}"); + //~^ uninlined_format_args println!("{val:val$}"); + //~^ uninlined_format_args println!("{val:val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{val:val$.val$}"); + //~^ uninlined_format_args println!("{width:width$}"); + //~^ uninlined_format_args println!("{local_i32:width$}"); + //~^ uninlined_format_args println!("{width:width$}"); + //~^ uninlined_format_args println!("{local_i32:width$}"); + //~^ uninlined_format_args println!("{prec:.prec$}"); + //~^ uninlined_format_args println!("{local_i32:.prec$}"); + //~^ uninlined_format_args println!("{prec:.prec$}"); + //~^ uninlined_format_args println!("{local_i32:.prec$}"); + //~^ uninlined_format_args println!("{width:width$.prec$}"); + //~^ uninlined_format_args println!("{width:width$.prec$}"); + //~^ uninlined_format_args println!("{local_f64:width$.prec$}"); + //~^ uninlined_format_args println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); + //~^ uninlined_format_args println!( + //~^ uninlined_format_args "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}", ); println!( @@ -122,8 +184,11 @@ fn tester(fn_arg: i32) { 1 + 2 ); println!("Width = {local_i32}, value with width = {local_f64:local_i32$}"); + //~^ uninlined_format_args println!("{local_i32:width$.prec$}"); + //~^ uninlined_format_args println!("{width:width$.prec$}"); + //~^ uninlined_format_args println!("{}", format!("{}", local_i32)); my_println!("{}", local_i32); my_println_args!("{}", local_i32); @@ -143,21 +208,26 @@ fn tester(fn_arg: i32) { println!(no_param_str!(), local_i32); println!( + //~^ uninlined_format_args "{val}", ); println!("{val}"); + //~^ uninlined_format_args println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64); println!("{}", with_span!(span val)); if local_i32 > 0 { panic!("p1 {local_i32}"); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p2 {local_i32}"); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p3 {local_i32}"); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p4 {local_i32}"); @@ -178,6 +248,7 @@ fn _under_msrv() { fn _meets_msrv() { let local_i32 = 1; println!("expand='{local_i32}'"); + //~^ uninlined_format_args } fn _do_not_fire() { @@ -280,7 +351,11 @@ fn user_format() { let local_f64 = 2.0; usr_println!(true, "val='{local_i32}'"); + //~^ uninlined_format_args usr_println!(true, "{local_i32}"); + //~^ uninlined_format_args usr_println!(true, "{local_i32:#010x}"); + //~^ uninlined_format_args usr_println!(true, "{local_f64:.1}"); + //~^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index 81fe24765674..526fd98dfa4b 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -43,77 +43,139 @@ fn tester(fn_arg: i32) { let _: &[u8; 3] = b" "; // <- println!("val='{}'", local_i32); + //~^ uninlined_format_args println!("val='{ }'", local_i32); // 3 spaces + //~^ uninlined_format_args println!("val='{ }'", local_i32); // tab + //~^ uninlined_format_args println!("val='{ }'", local_i32); // space+tab + //~^ uninlined_format_args println!("val='{ }'", local_i32); // tab+space + //~^ uninlined_format_args println!( + //~^ uninlined_format_args "val='{ }'", local_i32 ); println!("{}", local_i32); + //~^ uninlined_format_args println!("{}", fn_arg); + //~^ uninlined_format_args println!("{:?}", local_i32); + //~^ uninlined_format_args println!("{:#?}", local_i32); + //~^ uninlined_format_args println!("{:4}", local_i32); + //~^ uninlined_format_args println!("{:04}", local_i32); + //~^ uninlined_format_args println!("{:<3}", local_i32); + //~^ uninlined_format_args println!("{:#010x}", local_i32); + //~^ uninlined_format_args println!("{:.1}", local_f64); + //~^ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); println!("Hello {} is {:.*}", local_i32, 5, local_f64); println!("Hello {} is {2:.*}", local_i32, 5, local_f64); println!("{} {}", local_i32, local_f64); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); println!("{}", val); + //~^ uninlined_format_args println!("{}", v = val); + //~^ uninlined_format_args println!("{} {1}", local_i32, 42); println!("val='{\t }'", local_i32); + //~^ uninlined_format_args println!("val='{\n }'", local_i32); + //~^ uninlined_format_args println!("val='{local_i32}'", local_i32 = local_i32); + //~^ uninlined_format_args println!("val='{local_i32}'", local_i32 = fn_arg); + //~^ uninlined_format_args println!("{0}", local_i32); + //~^ uninlined_format_args println!("{0:?}", local_i32); + //~^ uninlined_format_args println!("{0:#?}", local_i32); + //~^ uninlined_format_args println!("{0:04}", local_i32); + //~^ uninlined_format_args println!("{0:<3}", local_i32); + //~^ uninlined_format_args println!("{0:#010x}", local_i32); + //~^ uninlined_format_args println!("{0:.1}", local_f64); + //~^ uninlined_format_args println!("{0} {0}", local_i32); + //~^ uninlined_format_args println!("{1} {} {0} {}", local_i32, local_f64); + //~^ uninlined_format_args println!("{0} {1}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0} {1} {0}", local_i32, local_f64); + //~^ uninlined_format_args println!("{1} {0}", "str", local_i32); println!("{v}", v = local_i32); + //~^ uninlined_format_args println!("{local_i32:0$}", width); + //~^ uninlined_format_args println!("{local_i32:w$}", w = width); + //~^ uninlined_format_args println!("{local_i32:.0$}", prec); + //~^ uninlined_format_args println!("{local_i32:.p$}", p = prec); + //~^ uninlined_format_args println!("{:0$}", v = val); + //~^ uninlined_format_args println!("{0:0$}", v = val); + //~^ uninlined_format_args println!("{:0$.0$}", v = val); + //~^ uninlined_format_args println!("{0:0$.0$}", v = val); + //~^ uninlined_format_args println!("{0:0$.v$}", v = val); + //~^ uninlined_format_args println!("{0:v$.0$}", v = val); + //~^ uninlined_format_args println!("{v:0$.0$}", v = val); + //~^ uninlined_format_args println!("{v:v$.0$}", v = val); + //~^ uninlined_format_args println!("{v:0$.v$}", v = val); + //~^ uninlined_format_args println!("{v:v$.v$}", v = val); + //~^ uninlined_format_args println!("{:0$}", width); + //~^ uninlined_format_args println!("{:1$}", local_i32, width); + //~^ uninlined_format_args println!("{:w$}", w = width); + //~^ uninlined_format_args println!("{:w$}", local_i32, w = width); + //~^ uninlined_format_args println!("{:.0$}", prec); + //~^ uninlined_format_args println!("{:.1$}", local_i32, prec); + //~^ uninlined_format_args println!("{:.p$}", p = prec); + //~^ uninlined_format_args println!("{:.p$}", local_i32, p = prec); + //~^ uninlined_format_args println!("{:0$.1$}", width, prec); + //~^ uninlined_format_args println!("{:0$.w$}", width, w = prec); + //~^ uninlined_format_args println!("{:1$.2$}", local_f64, width, prec); + //~^ uninlined_format_args println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); + //~^ uninlined_format_args println!( + //~^ uninlined_format_args "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", local_i32, width, prec, ); @@ -125,8 +187,11 @@ fn tester(fn_arg: i32) { 1 + 2 ); println!("Width = {}, value with width = {:0$}", local_i32, local_f64); + //~^ uninlined_format_args println!("{:w$.p$}", local_i32, w = width, p = prec); + //~^ uninlined_format_args println!("{:w$.p$}", w = width, p = prec); + //~^ uninlined_format_args println!("{}", format!("{}", local_i32)); my_println!("{}", local_i32); my_println_args!("{}", local_i32); @@ -146,23 +211,28 @@ fn tester(fn_arg: i32) { println!(no_param_str!(), local_i32); println!( + //~^ uninlined_format_args "{}", // comment with a comma , in it val, ); println!("{}", /* comment with a comma , in it */ val); + //~^ uninlined_format_args println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64); println!("{}", with_span!(span val)); if local_i32 > 0 { panic!("p1 {}", local_i32); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p2 {0}", local_i32); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p3 {local_i32}", local_i32 = local_i32); + //~^ uninlined_format_args } if local_i32 > 0 { panic!("p4 {local_i32}"); @@ -183,6 +253,7 @@ fn _under_msrv() { fn _meets_msrv() { let local_i32 = 1; println!("expand='{}'", local_i32); + //~^ uninlined_format_args } fn _do_not_fire() { @@ -285,7 +356,11 @@ fn user_format() { let local_f64 = 2.0; usr_println!(true, "val='{}'", local_i32); + //~^ uninlined_format_args usr_println!(true, "{}", local_i32); + //~^ uninlined_format_args usr_println!(true, "{:#010x}", local_i32); + //~^ uninlined_format_args usr_println!(true, "{:.1}", local_f64); + //~^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index 77961fea2c53..df688bc757c7 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -13,7 +13,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:46:5 + --> tests/ui/uninlined_format_args.rs:47:5 | LL | println!("val='{ }'", local_i32); // 3 spaces | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:47:5 + --> tests/ui/uninlined_format_args.rs:49:5 | LL | println!("val='{ }'", local_i32); // tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("val='{local_i32}'"); // tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:48:5 + --> tests/ui/uninlined_format_args.rs:51:5 | LL | println!("val='{ }'", local_i32); // space+tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("val='{local_i32}'"); // space+tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:49:5 + --> tests/ui/uninlined_format_args.rs:53:5 | LL | println!("val='{ }'", local_i32); // tab+space | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,9 +61,10 @@ LL + println!("val='{local_i32}'"); // tab+space | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:50:5 + --> tests/ui/uninlined_format_args.rs:55:5 | LL | / println!( +LL | | LL | | "val='{ LL | | }'", LL | | local_i32 @@ -71,7 +72,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:55:5 + --> tests/ui/uninlined_format_args.rs:61:5 | LL | println!("{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +84,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:56:5 + --> tests/ui/uninlined_format_args.rs:63:5 | LL | println!("{}", fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +96,7 @@ LL + println!("{fn_arg}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:57:5 + --> tests/ui/uninlined_format_args.rs:65:5 | LL | println!("{:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -107,7 +108,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:58:5 + --> tests/ui/uninlined_format_args.rs:67:5 | LL | println!("{:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -119,7 +120,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:59:5 + --> tests/ui/uninlined_format_args.rs:69:5 | LL | println!("{:4}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +132,7 @@ LL + println!("{local_i32:4}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:60:5 + --> tests/ui/uninlined_format_args.rs:71:5 | LL | println!("{:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -143,7 +144,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:61:5 + --> tests/ui/uninlined_format_args.rs:73:5 | LL | println!("{:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +156,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:62:5 + --> tests/ui/uninlined_format_args.rs:75:5 | LL | println!("{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +168,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:63:5 + --> tests/ui/uninlined_format_args.rs:77:5 | LL | println!("{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +180,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:67:5 + --> tests/ui/uninlined_format_args.rs:82:5 | LL | println!("{} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -191,7 +192,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:69:5 + --> tests/ui/uninlined_format_args.rs:85:5 | LL | println!("{}", val); | ^^^^^^^^^^^^^^^^^^^ @@ -203,7 +204,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:70:5 + --> tests/ui/uninlined_format_args.rs:87:5 | LL | println!("{}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -215,7 +216,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:72:5 + --> tests/ui/uninlined_format_args.rs:90:5 | LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -227,7 +228,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:73:5 + --> tests/ui/uninlined_format_args.rs:92:5 | LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -239,7 +240,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:74:5 + --> tests/ui/uninlined_format_args.rs:94:5 | LL | println!("val='{local_i32}'", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -251,7 +252,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:75:5 + --> tests/ui/uninlined_format_args.rs:96:5 | LL | println!("val='{local_i32}'", local_i32 = fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +264,7 @@ LL + println!("val='{fn_arg}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:76:5 + --> tests/ui/uninlined_format_args.rs:98:5 | LL | println!("{0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -275,7 +276,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:77:5 + --> tests/ui/uninlined_format_args.rs:100:5 | LL | println!("{0:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +288,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:78:5 + --> tests/ui/uninlined_format_args.rs:102:5 | LL | println!("{0:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +300,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:79:5 + --> tests/ui/uninlined_format_args.rs:104:5 | LL | println!("{0:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -311,7 +312,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:80:5 + --> tests/ui/uninlined_format_args.rs:106:5 | LL | println!("{0:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -323,7 +324,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:81:5 + --> tests/ui/uninlined_format_args.rs:108:5 | LL | println!("{0:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -335,7 +336,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:82:5 + --> tests/ui/uninlined_format_args.rs:110:5 | LL | println!("{0:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -347,7 +348,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:83:5 + --> tests/ui/uninlined_format_args.rs:112:5 | LL | println!("{0} {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -359,7 +360,7 @@ LL + println!("{local_i32} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:84:5 + --> tests/ui/uninlined_format_args.rs:114:5 | LL | println!("{1} {} {0} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -371,7 +372,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:85:5 + --> tests/ui/uninlined_format_args.rs:116:5 | LL | println!("{0} {1}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -383,7 +384,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:86:5 + --> tests/ui/uninlined_format_args.rs:118:5 | LL | println!("{1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -395,7 +396,7 @@ LL + println!("{local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:87:5 + --> tests/ui/uninlined_format_args.rs:120:5 | LL | println!("{1} {0} {1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -407,7 +408,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:89:5 + --> tests/ui/uninlined_format_args.rs:123:5 | LL | println!("{v}", v = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -419,7 +420,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:90:5 + --> tests/ui/uninlined_format_args.rs:125:5 | LL | println!("{local_i32:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -431,7 +432,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:91:5 + --> tests/ui/uninlined_format_args.rs:127:5 | LL | println!("{local_i32:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -443,7 +444,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:92:5 + --> tests/ui/uninlined_format_args.rs:129:5 | LL | println!("{local_i32:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -455,7 +456,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:93:5 + --> tests/ui/uninlined_format_args.rs:131:5 | LL | println!("{local_i32:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -467,7 +468,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:94:5 + --> tests/ui/uninlined_format_args.rs:133:5 | LL | println!("{:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -479,7 +480,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:95:5 + --> tests/ui/uninlined_format_args.rs:135:5 | LL | println!("{0:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -491,7 +492,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:96:5 + --> tests/ui/uninlined_format_args.rs:137:5 | LL | println!("{:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -503,7 +504,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:97:5 + --> tests/ui/uninlined_format_args.rs:139:5 | LL | println!("{0:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -515,7 +516,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:98:5 + --> tests/ui/uninlined_format_args.rs:141:5 | LL | println!("{0:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -527,7 +528,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:99:5 + --> tests/ui/uninlined_format_args.rs:143:5 | LL | println!("{0:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -539,7 +540,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:100:5 + --> tests/ui/uninlined_format_args.rs:145:5 | LL | println!("{v:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -551,7 +552,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:101:5 + --> tests/ui/uninlined_format_args.rs:147:5 | LL | println!("{v:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -563,7 +564,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:102:5 + --> tests/ui/uninlined_format_args.rs:149:5 | LL | println!("{v:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -575,7 +576,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:103:5 + --> tests/ui/uninlined_format_args.rs:151:5 | LL | println!("{v:v$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -587,7 +588,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:104:5 + --> tests/ui/uninlined_format_args.rs:153:5 | LL | println!("{:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -599,7 +600,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:105:5 + --> tests/ui/uninlined_format_args.rs:155:5 | LL | println!("{:1$}", local_i32, width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -611,7 +612,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:106:5 + --> tests/ui/uninlined_format_args.rs:157:5 | LL | println!("{:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -623,7 +624,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:107:5 + --> tests/ui/uninlined_format_args.rs:159:5 | LL | println!("{:w$}", local_i32, w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -635,7 +636,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:108:5 + --> tests/ui/uninlined_format_args.rs:161:5 | LL | println!("{:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -647,7 +648,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:109:5 + --> tests/ui/uninlined_format_args.rs:163:5 | LL | println!("{:.1$}", local_i32, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -659,7 +660,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:110:5 + --> tests/ui/uninlined_format_args.rs:165:5 | LL | println!("{:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -671,7 +672,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:111:5 + --> tests/ui/uninlined_format_args.rs:167:5 | LL | println!("{:.p$}", local_i32, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -683,7 +684,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:112:5 + --> tests/ui/uninlined_format_args.rs:169:5 | LL | println!("{:0$.1$}", width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -695,7 +696,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:113:5 + --> tests/ui/uninlined_format_args.rs:171:5 | LL | println!("{:0$.w$}", width, w = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -707,7 +708,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:114:5 + --> tests/ui/uninlined_format_args.rs:173:5 | LL | println!("{:1$.2$}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -719,7 +720,7 @@ LL + println!("{local_f64:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:115:5 + --> tests/ui/uninlined_format_args.rs:175:5 | LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -731,16 +732,17 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:116:5 + --> tests/ui/uninlined_format_args.rs:177:5 | LL | / println!( +LL | | LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", LL | | local_i32, width, prec, LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:127:5 + --> tests/ui/uninlined_format_args.rs:189:5 | LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -752,7 +754,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$ | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:128:5 + --> tests/ui/uninlined_format_args.rs:191:5 | LL | println!("{:w$.p$}", local_i32, w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -764,7 +766,7 @@ LL + println!("{local_i32:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:129:5 + --> tests/ui/uninlined_format_args.rs:193:5 | LL | println!("{:w$.p$}", w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -776,17 +778,17 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:148:5 + --> tests/ui/uninlined_format_args.rs:213:5 | LL | / println!( +LL | | LL | | "{}", -LL | | // comment with a comma , in it -LL | | val, +... | LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:153:5 + --> tests/ui/uninlined_format_args.rs:219:5 | LL | println!("{}", /* comment with a comma , in it */ val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -798,7 +800,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:159:9 + --> tests/ui/uninlined_format_args.rs:226:9 | LL | panic!("p1 {}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -810,7 +812,7 @@ LL + panic!("p1 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:162:9 + --> tests/ui/uninlined_format_args.rs:230:9 | LL | panic!("p2 {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -822,7 +824,7 @@ LL + panic!("p2 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:165:9 + --> tests/ui/uninlined_format_args.rs:234:9 | LL | panic!("p3 {local_i32}", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -834,7 +836,7 @@ LL + panic!("p3 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:185:5 + --> tests/ui/uninlined_format_args.rs:255:5 | LL | println!("expand='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -846,7 +848,7 @@ LL + println!("expand='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:287:5 + --> tests/ui/uninlined_format_args.rs:358:5 | LL | usr_println!(true, "val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -858,7 +860,7 @@ LL + usr_println!(true, "val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:288:5 + --> tests/ui/uninlined_format_args.rs:360:5 | LL | usr_println!(true, "{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -870,7 +872,7 @@ LL + usr_println!(true, "{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:289:5 + --> tests/ui/uninlined_format_args.rs:362:5 | LL | usr_println!(true, "{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -882,7 +884,7 @@ LL + usr_println!(true, "{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:290:5 + --> tests/ui/uninlined_format_args.rs:364:5 | LL | usr_println!(true, "{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.edition2018.fixed b/tests/ui/uninlined_format_args_panic.edition2018.fixed index 9911d1317070..3710036c0589 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2018.fixed @@ -9,15 +9,19 @@ fn main() { let var = 1; println!("val='{var}'"); + //~^ uninlined_format_args if var > 0 { panic!("p1 {}", var); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p2 {0}", var); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p3 {var}", var = var); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -28,5 +32,7 @@ fn main() { } assert!(var == 1, "p5 {}", var); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {}", var); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args_panic.edition2021.fixed b/tests/ui/uninlined_format_args_panic.edition2021.fixed index 87b74670565f..8a754d313806 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2021.fixed @@ -9,15 +9,19 @@ fn main() { let var = 1; println!("val='{var}'"); + //~^ uninlined_format_args if var > 0 { panic!("p1 {var}"); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p2 {var}"); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p3 {var}"); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -28,5 +32,7 @@ fn main() { } assert!(var == 1, "p5 {var}"); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {var}"); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/uninlined_format_args_panic.edition2021.stderr b/tests/ui/uninlined_format_args_panic.edition2021.stderr index 7638d3f8bbad..4db6e6a99312 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2021.stderr @@ -13,7 +13,7 @@ LL + println!("val='{var}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:14:9 + --> tests/ui/uninlined_format_args_panic.rs:15:9 | LL | panic!("p1 {}", var); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + panic!("p1 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:17:9 + --> tests/ui/uninlined_format_args_panic.rs:19:9 | LL | panic!("p2 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + panic!("p2 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:20:9 + --> tests/ui/uninlined_format_args_panic.rs:23:9 | LL | panic!("p3 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + panic!("p3 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:30:5 + --> tests/ui/uninlined_format_args_panic.rs:34:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!(var == 1, "p5 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:31:5 + --> tests/ui/uninlined_format_args_panic.rs:36: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 647c69bc5c41..94de4f057e99 100644 --- a/tests/ui/uninlined_format_args_panic.rs +++ b/tests/ui/uninlined_format_args_panic.rs @@ -9,15 +9,19 @@ fn main() { let var = 1; println!("val='{}'", var); + //~^ uninlined_format_args if var > 0 { panic!("p1 {}", var); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p2 {0}", var); + //~[edition2021]^ uninlined_format_args } if var > 0 { panic!("p3 {var}", var = var); + //~[edition2021]^ uninlined_format_args } #[allow(non_fmt_panics)] @@ -28,5 +32,7 @@ fn main() { } assert!(var == 1, "p5 {}", var); + //~[edition2021]^ uninlined_format_args debug_assert!(var == 1, "p6 {}", var); + //~[edition2021]^ uninlined_format_args } diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 2e1390621a6c..3a3962d09143 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -61,23 +61,30 @@ impl Tr for B { fn bad() { foo({ + //~^ unit_arg 1; }); foo(foo(1)); + //~^ unit_arg foo({ + //~^ unit_arg foo(1); foo(2); }); let b = Bar; b.bar({ + //~^ unit_arg 1; }); taking_multiple_units(foo(0), foo(1)); + //~^ unit_arg taking_multiple_units(foo(0), { + //~^ unit_arg foo(1); foo(2); }); taking_multiple_units( + //~^ unit_arg { foo(0); foo(1); @@ -89,9 +96,11 @@ fn bad() { ); // here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block None.or(Some(foo(2))); + //~^ unit_arg // in this case, the suggestion can be inlined, no need for a surrounding block // foo(()); foo(()) instead of { foo(()); foo(()) } foo(foo(())); + //~^ unit_arg } fn ok() { @@ -129,6 +138,7 @@ mod issue_2945 { #[allow(dead_code)] fn returning_expr() -> Option<()> { Some(foo(1)) + //~^ unit_arg } fn taking_multiple_units(a: (), b: ()) {} diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 41ad1a2d3834..2ddb28bd4cc4 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -2,6 +2,7 @@ error: passing a unit value to a function --> tests/ui/unit_arg.rs:63:5 | LL | / foo({ +LL | | LL | | 1; LL | | }); | |______^ @@ -15,13 +16,14 @@ LL | 1 help: or move the expression in front of the call and replace it with the unit literal `()` | LL ~ { +LL + LL + 1; LL + }; LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:66:5 + --> tests/ui/unit_arg.rs:67:5 | LL | foo(foo(1)); | ^^^^^^^^^^^ @@ -33,9 +35,10 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:67:5 + --> tests/ui/unit_arg.rs:69:5 | LL | / foo({ +LL | | LL | | foo(1); LL | | foo(2); LL | | }); @@ -48,6 +51,7 @@ LL | foo(2) help: or move the expression in front of the call and replace it with the unit literal `()` | LL ~ { +LL + LL + foo(1); LL + foo(2); LL + }; @@ -55,9 +59,10 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:72:5 + --> tests/ui/unit_arg.rs:75:5 | LL | / b.bar({ +LL | | LL | | 1; LL | | }); | |______^ @@ -69,13 +74,14 @@ LL | 1 help: or move the expression in front of the call and replace it with the unit literal `()` | LL ~ { +LL + LL + 1; LL + }; LL ~ b.bar(()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:75:5 + --> tests/ui/unit_arg.rs:79:5 | LL | taking_multiple_units(foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,9 +94,10 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:76:5 + --> tests/ui/unit_arg.rs:81:5 | LL | / taking_multiple_units(foo(0), { +LL | | LL | | foo(1); LL | | foo(2); LL | | }); @@ -104,6 +111,7 @@ help: or move the expressions in front of the call and replace them with the uni | LL ~ foo(0); LL + { +LL + LL + foo(1); LL + foo(2); LL + }; @@ -111,12 +119,12 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:80:5 + --> tests/ui/unit_arg.rs:86:5 | LL | / taking_multiple_units( +LL | | LL | | { LL | | foo(0); -LL | | foo(1); ... | LL | | }, LL | | ); @@ -141,13 +149,14 @@ LL + foo(2); LL + foo(3); LL + }; LL + taking_multiple_units( +LL + LL + (), LL + (), LL ~ ); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:91:13 + --> tests/ui/unit_arg.rs:98:13 | LL | None.or(Some(foo(2))); | ^^^^^^^^^^^^ @@ -161,7 +170,7 @@ LL ~ }); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:94:5 + --> tests/ui/unit_arg.rs:102:5 | LL | foo(foo(())); | ^^^^^^^^^^^^ @@ -173,7 +182,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:131:5 + --> tests/ui/unit_arg.rs:140:5 | LL | Some(foo(1)) | ^^^^^^^^^^^^ diff --git a/tests/ui/unit_arg_empty_blocks.fixed b/tests/ui/unit_arg_empty_blocks.fixed index a947ded7b1e7..b045a33608d7 100644 --- a/tests/ui/unit_arg_empty_blocks.fixed +++ b/tests/ui/unit_arg_empty_blocks.fixed @@ -14,12 +14,16 @@ fn foo3(t1: T1, t2: T2, t3: T3) { fn bad() { foo(()); + //~^ unit_arg foo3((), 2, 2); + //~^ unit_arg foo(0); taking_two_units((), ()); + //~^ unit_arg foo(0); foo(1); taking_three_units((), (), ()); + //~^ unit_arg } fn taking_two_units(a: (), b: ()) {} diff --git a/tests/ui/unit_arg_empty_blocks.rs b/tests/ui/unit_arg_empty_blocks.rs index 058c4f84a9e8..ab305913f3f6 100644 --- a/tests/ui/unit_arg_empty_blocks.rs +++ b/tests/ui/unit_arg_empty_blocks.rs @@ -14,9 +14,13 @@ fn foo3(t1: T1, t2: T2, t3: T3) { fn bad() { foo({}); + //~^ unit_arg foo3({}, 2, 2); + //~^ unit_arg taking_two_units({}, foo(0)); + //~^ unit_arg taking_three_units({}, foo(0), foo(1)); + //~^ unit_arg } fn taking_two_units(a: (), b: ()) {} diff --git a/tests/ui/unit_arg_empty_blocks.stderr b/tests/ui/unit_arg_empty_blocks.stderr index d971195dda26..2c686d58ecc1 100644 --- a/tests/ui/unit_arg_empty_blocks.stderr +++ b/tests/ui/unit_arg_empty_blocks.stderr @@ -10,7 +10,7 @@ LL | foo({}); = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` error: passing a unit value to a function - --> tests/ui/unit_arg_empty_blocks.rs:17:5 + --> tests/ui/unit_arg_empty_blocks.rs:18:5 | LL | foo3({}, 2, 2); | ^^^^^--^^^^^^^ @@ -18,7 +18,7 @@ LL | foo3({}, 2, 2); | help: use a unit literal instead: `()` error: passing unit values to a function - --> tests/ui/unit_arg_empty_blocks.rs:18:5 + --> tests/ui/unit_arg_empty_blocks.rs:20:5 | LL | taking_two_units({}, foo(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL ~ taking_two_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg_empty_blocks.rs:19:5 + --> tests/ui/unit_arg_empty_blocks.rs:22:5 | LL | taking_three_units({}, foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index cea89026da6f..0b1cccfbadf6 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -15,22 +15,25 @@ 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` + //~^ unit_cmp + + true; } == { false; } {} if { - //~^ ERROR: >-comparison of unit values detected. This will always be false + //~^ unit_cmp + true; } > { false; } {} assert_eq!( - //~^ ERROR: `assert_eq` of unit values detected. This will always succeed + //~^ unit_cmp + { true; }, @@ -39,7 +42,8 @@ fn main() { } ); debug_assert_eq!( - //~^ ERROR: `debug_assert_eq` of unit values detected. This will always succeed + //~^ unit_cmp + { true; }, @@ -49,7 +53,8 @@ fn main() { ); assert_ne!( - //~^ ERROR: `assert_ne` of unit values detected. This will always fail + //~^ unit_cmp + { true; }, @@ -58,7 +63,8 @@ fn main() { } ); debug_assert_ne!( - //~^ ERROR: `debug_assert_ne` of unit values detected. This will always fail + //~^ unit_cmp + { true; }, diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 9e067edb8467..0c485edd9736 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -3,10 +3,7 @@ error: ==-comparison of unit values detected. This will always be true | LL | if { | ________^ -LL | | -LL | | -LL | | true; -LL | | } == { +... | LL | | false; LL | | } {} | |_____^ @@ -15,11 +12,12 @@ LL | | } {} = help: to override `-D warnings` add `#[allow(clippy::unit_cmp)]` error: >-comparison of unit values detected. This will always be false - --> tests/ui/unit_cmp.rs:25:8 + --> tests/ui/unit_cmp.rs:26:8 | LL | if { | ________^ LL | | +LL | | LL | | true; LL | | } > { LL | | false; @@ -27,45 +25,33 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:32:5 + --> tests/ui/unit_cmp.rs:34:5 | LL | / assert_eq!( -LL | | -LL | | { -LL | | true; ... | LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:41:5 + --> tests/ui/unit_cmp.rs:44:5 | LL | / debug_assert_eq!( -LL | | -LL | | { -LL | | true; ... | LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:51:5 + --> tests/ui/unit_cmp.rs:55:5 | LL | / assert_ne!( -LL | | -LL | | { -LL | | true; ... | LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:60:5 + --> tests/ui/unit_cmp.rs:65:5 | LL | / debug_assert_ne!( -LL | | -LL | | { -LL | | true; ... | LL | | ); | |_____^ diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed index ed0facf1b963..4df67c783d32 100644 --- a/tests/ui/unit_hash.fixed +++ b/tests/ui/unit_hash.fixed @@ -17,18 +17,21 @@ 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 + //~^ unit_hash + + 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 + //~^ unit_hash + + #[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 + //~^ unit_hash + + } diff --git a/tests/ui/unit_hash.rs b/tests/ui/unit_hash.rs index f3636d1644da..15f27aab95e1 100644 --- a/tests/ui/unit_hash.rs +++ b/tests/ui/unit_hash.rs @@ -17,18 +17,21 @@ 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 + //~^ unit_hash + + 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 + //~^ unit_hash + + #[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 + //~^ unit_hash + + } diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index b48f3a543b76..be019d398b58 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -9,7 +9,7 @@ LL | Foo::Empty => ().hash(&mut state), = help: to override `-D warnings` add `#[allow(clippy::unit_hash)]` error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:26:5 + --> tests/ui/unit_hash.rs:27:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -17,7 +17,7 @@ LL | res.hash(&mut state); = note: the implementation of `Hash` for `()` is a no-op error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:31:5 + --> tests/ui/unit_hash.rs:33: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 5f62157dd6d5..3585eb5395db 100644 --- a/tests/ui/unit_return_expecting_ord.rs +++ b/tests/ui/unit_return_expecting_ord.rs @@ -16,16 +16,19 @@ 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 + //~^ unit_return_expecting_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 + //~^ unit_return_expecting_ord + double(s.field); }); structs.is_sorted_by_key(|s| { - //~^ ERROR: this closure returns the unit type which also implements PartialOrd + //~^ unit_return_expecting_ord + if s.field > 0 { () } else { @@ -36,5 +39,6 @@ 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 + //~^ unit_return_expecting_ord + } diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index 329832048e88..d5ce2fb0b51d 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -5,7 +5,7 @@ LL | structs.sort_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> tests/ui/unit_return_expecting_ord.rs:20:24 + --> tests/ui/unit_return_expecting_ord.rs:21:24 | LL | double(s.field); | ^ @@ -13,25 +13,25 @@ LL | double(s.field); = help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]` error: this closure returns the unit type which also implements PartialOrd - --> tests/ui/unit_return_expecting_ord.rs:23:30 + --> tests/ui/unit_return_expecting_ord.rs:24:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> tests/ui/unit_return_expecting_ord.rs:25:24 + --> tests/ui/unit_return_expecting_ord.rs:27:24 | LL | double(s.field); | ^ error: this closure returns the unit type which also implements PartialOrd - --> tests/ui/unit_return_expecting_ord.rs:27:30 + --> tests/ui/unit_return_expecting_ord.rs:29:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ error: this closure returns the unit type which also implements Ord - --> tests/ui/unit_return_expecting_ord.rs:38:25 + --> tests/ui/unit_return_expecting_ord.rs:41:25 | LL | structs.sort_by_key(|s| unit(s.field)); | ^^^ diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed index c0ccd41c19ab..f97452c34eb5 100644 --- a/tests/ui/unknown_clippy_lints.fixed +++ b/tests/ui/unknown_clippy_lints.fixed @@ -1,18 +1,27 @@ #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::all)] +//~^ ERROR: unknown lint #![warn(clippy::cmp_owned)] +//~^ ERROR: unknown lint // Should suggest similar clippy lint name #[warn(clippy::if_not_else)] +//~^ ERROR: unknown lint #[warn(clippy::unnecessary_cast)] +//~^ ERROR: unknown lint #[warn(clippy::useless_transmute)] +//~^ ERROR: unknown lint // Should suggest rustc lint name(`dead_code`) #[warn(dead_code)] +//~^ ERROR: unknown lint // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_self)] +//~^ ERROR: unknown lint // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) #[warn(clippy::redundant_static_lifetimes)] +//~^ ERROR: unknown lint // issue #118183, should report `missing_docs` from rustc lint #[warn(missing_docs)] +//~^ ERROR: unknown lint fn main() {} diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs index 7a59ad364aa7..2ff4dd80bddc 100644 --- a/tests/ui/unknown_clippy_lints.rs +++ b/tests/ui/unknown_clippy_lints.rs @@ -1,18 +1,27 @@ #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::All)] +//~^ ERROR: unknown lint #![warn(clippy::CMP_OWNED)] +//~^ ERROR: unknown lint // Should suggest similar clippy lint name #[warn(clippy::if_not_els)] +//~^ ERROR: unknown lint #[warn(clippy::UNNecsaRy_cAst)] +//~^ ERROR: unknown lint #[warn(clippy::useles_transute)] +//~^ ERROR: unknown lint // Should suggest rustc lint name(`dead_code`) #[warn(clippy::dead_cod)] +//~^ ERROR: unknown lint // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_colle)] +//~^ ERROR: unknown lint // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) #[warn(clippy::const_static_lifetim)] +//~^ ERROR: unknown lint // issue #118183, should report `missing_docs` from rustc lint #[warn(clippy::missing_docs)] +//~^ ERROR: unknown lint fn main() {} diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index aa2c2f3c0e20..96a35312755c 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -8,31 +8,31 @@ LL | #![allow(clippy::All)] = help: to override `-D warnings` add `#[allow(unknown_lints)]` error: unknown lint: `clippy::CMP_OWNED` - --> tests/ui/unknown_clippy_lints.rs:4:9 + --> tests/ui/unknown_clippy_lints.rs:5:9 | LL | #![warn(clippy::CMP_OWNED)] | ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned` error: unknown lint: `clippy::if_not_els` - --> tests/ui/unknown_clippy_lints.rs:7:8 + --> tests/ui/unknown_clippy_lints.rs:9:8 | LL | #[warn(clippy::if_not_els)] | ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else` error: unknown lint: `clippy::UNNecsaRy_cAst` - --> tests/ui/unknown_clippy_lints.rs:8:8 + --> tests/ui/unknown_clippy_lints.rs:11:8 | LL | #[warn(clippy::UNNecsaRy_cAst)] | ^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unnecessary_cast` error: unknown lint: `clippy::useles_transute` - --> tests/ui/unknown_clippy_lints.rs:9:8 + --> tests/ui/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::useles_transute)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::useless_transmute` error: unknown lint: `clippy::dead_cod` - --> tests/ui/unknown_clippy_lints.rs:11:8 + --> tests/ui/unknown_clippy_lints.rs:16:8 | LL | #[warn(clippy::dead_cod)] | ^^^^^^^^^^^^^^^^ @@ -43,19 +43,19 @@ LL | #[warn(dead_code)] | ~~~~~~~~~ error: unknown lint: `clippy::unused_colle` - --> tests/ui/unknown_clippy_lints.rs:13:8 + --> tests/ui/unknown_clippy_lints.rs:19:8 | LL | #[warn(clippy::unused_colle)] | ^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unused_self` error: unknown lint: `clippy::const_static_lifetim` - --> tests/ui/unknown_clippy_lints.rs:15:8 + --> tests/ui/unknown_clippy_lints.rs:22:8 | LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` error: unknown lint: `clippy::missing_docs` - --> tests/ui/unknown_clippy_lints.rs:17:8 + --> tests/ui/unknown_clippy_lints.rs:25:8 | LL | #[warn(clippy::missing_docs)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_box_returns.rs b/tests/ui/unnecessary_box_returns.rs index bcdaca33b644..5037c05a0acb 100644 --- a/tests/ui/unnecessary_box_returns.rs +++ b/tests/ui/unnecessary_box_returns.rs @@ -3,7 +3,8 @@ trait Bar { // lint fn baz(&self) -> Box; - //~^ ERROR: boxed return of the sized type `usize` + //~^ unnecessary_box_returns + } pub struct Foo {} @@ -17,7 +18,8 @@ impl Bar for Foo { impl Foo { fn baz(&self) -> Box { - //~^ ERROR: boxed return of the sized type `usize` + //~^ unnecessary_box_returns + // lint Box::new(13) } @@ -25,13 +27,15 @@ impl Foo { // lint fn bxed_usize() -> Box { - //~^ ERROR: boxed return of the sized type `usize` +//~^ unnecessary_box_returns + Box::new(5) } // lint fn _bxed_foo() -> Box { - //~^ ERROR: boxed return of the sized type `Foo` +//~^ unnecessary_box_returns + Box::new(Foo {}) } diff --git a/tests/ui/unnecessary_box_returns.stderr b/tests/ui/unnecessary_box_returns.stderr index cb88ba1b0016..9df056569a29 100644 --- a/tests/ui/unnecessary_box_returns.stderr +++ b/tests/ui/unnecessary_box_returns.stderr @@ -9,7 +9,7 @@ LL | fn baz(&self) -> Box; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` error: boxed return of the sized type `usize` - --> tests/ui/unnecessary_box_returns.rs:19:22 + --> tests/ui/unnecessary_box_returns.rs:20:22 | LL | fn baz(&self) -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -17,7 +17,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` - --> tests/ui/unnecessary_box_returns.rs:27:20 + --> tests/ui/unnecessary_box_returns.rs:29:20 | LL | fn bxed_usize() -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -25,7 +25,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` - --> tests/ui/unnecessary_box_returns.rs:33:19 + --> tests/ui/unnecessary_box_returns.rs:36:19 | LL | fn _bxed_foo() -> Box { | ^^^^^^^^ help: try: `Foo` diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index c43e50761bd5..abaab6aa9a05 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -17,6 +17,7 @@ type PtrMutU8 = *mut u8; fn owo(ptr: *const T) -> *const T { ptr + //~^ unnecessary_cast } fn uwu(ptr: *const T) -> *const U { @@ -52,21 +53,32 @@ fn bbb() -> UnsignedThirtyTwoBitInteger { fn main() { // Test cast_unnecessary 1_i32; + //~^ unnecessary_cast 1_f32; + //~^ unnecessary_cast false; + //~^ unnecessary_cast &1i32 as &i32; -1_i32; + //~^ unnecessary_cast - 1_i32; + //~^ unnecessary_cast -1_f32; + //~^ unnecessary_cast 1_i32; + //~^ unnecessary_cast 1_f32; + //~^ unnecessary_cast let _: *mut u8 = [1u8, 2].as_ptr() as *mut u8; + //~^ unnecessary_cast [1u8, 2].as_ptr(); + //~^ unnecessary_cast [1u8, 2].as_ptr() as *mut u8; [1u8, 2].as_mut_ptr(); + //~^ unnecessary_cast [1u8, 2].as_mut_ptr() as *const u8; [1u8, 2].as_ptr() as PtrConstU8; [1u8, 2].as_ptr() as PtrMutU8; @@ -78,9 +90,12 @@ fn main() { let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _; owo::([1u32].as_ptr()); + //~^ unnecessary_cast uwu::([1u32].as_ptr()); + //~^ unnecessary_cast // this will not lint in the function body even though they have the same type, instead here uwu::([1u32].as_ptr()); + //~^ unnecessary_cast // macro version macro_rules! foo { @@ -116,8 +131,10 @@ fn main() { let pid = unsafe { fake_libc::getpid() }; pid as i32; aaa(); + //~^ unnecessary_cast let x = aaa(); aaa(); + //~^ unnecessary_cast // Will not lint currently. bbb() as u32; let x = bbb(); @@ -154,13 +171,21 @@ mod fixable { fn main() { // casting integer literal to float is unnecessary 100_f32; + //~^ unnecessary_cast 100_f64; + //~^ unnecessary_cast 100_f64; + //~^ unnecessary_cast let _ = -100_f32; + //~^ unnecessary_cast let _ = -100_f64; + //~^ unnecessary_cast let _ = -100_f64; + //~^ unnecessary_cast 100_f32; + //~^ unnecessary_cast 100_f64; + //~^ unnecessary_cast // Should not trigger #[rustfmt::skip] let v = vec!(1); @@ -173,32 +198,44 @@ mod fixable { 0b11 as f64; 1_u32; + //~^ unnecessary_cast 0x10_i32; + //~^ unnecessary_cast 0b10_usize; + //~^ unnecessary_cast 0o73_u16; + //~^ unnecessary_cast 1_000_000_000_u32; + //~^ unnecessary_cast 1.0_f64; + //~^ unnecessary_cast 0.5_f32; + //~^ unnecessary_cast 1.0 as u16; let _ = -1_i32; + //~^ unnecessary_cast let _ = -1.0_f32; + //~^ unnecessary_cast let _ = 1 as I32Alias; let _ = &1 as &I32Alias; let x = 1i32; let _ = &{ x }; + //~^ unnecessary_cast } type I32Alias = i32; fn issue_9380() { let _: i32 = -1_i32; + //~^ unnecessary_cast let _: f32 = -(1) as f32; let _: i64 = -1_i64; + //~^ unnecessary_cast let _: i64 = -(1.0) as i64; let _ = -(1 + 1) as i64; @@ -206,8 +243,10 @@ mod fixable { fn issue_9563() { let _: f64 = (-8.0_f64).exp(); + //~^ unnecessary_cast #[allow(ambiguous_negative_literals)] let _: f64 = -8.0_f64.exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior + //~^ unnecessary_cast } fn issue_9562_non_literal() { @@ -216,6 +255,7 @@ mod fixable { } let _num = foo(); + //~^ unnecessary_cast } fn issue_9603() { @@ -226,5 +266,6 @@ mod fixable { // `*x.pow(2)` which tries to dereference the return value rather than `x`. fn issue_11968(x: &usize) -> usize { { *x }.pow(2) + //~^ unnecessary_cast } } diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index 4a5ca231315e..8f2493def09a 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -17,6 +17,7 @@ type PtrMutU8 = *mut u8; fn owo(ptr: *const T) -> *const T { ptr as *const T + //~^ unnecessary_cast } fn uwu(ptr: *const T) -> *const U { @@ -52,21 +53,32 @@ fn bbb() -> UnsignedThirtyTwoBitInteger { fn main() { // Test cast_unnecessary 1i32 as i32; + //~^ unnecessary_cast 1f32 as f32; + //~^ unnecessary_cast false as bool; + //~^ unnecessary_cast &1i32 as &i32; -1_i32 as i32; + //~^ unnecessary_cast - 1_i32 as i32; + //~^ unnecessary_cast -1f32 as f32; + //~^ unnecessary_cast 1_i32 as i32; + //~^ unnecessary_cast 1_f32 as f32; + //~^ unnecessary_cast let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; + //~^ unnecessary_cast [1u8, 2].as_ptr() as *const u8; + //~^ unnecessary_cast [1u8, 2].as_ptr() as *mut u8; [1u8, 2].as_mut_ptr() as *mut u8; + //~^ unnecessary_cast [1u8, 2].as_mut_ptr() as *const u8; [1u8, 2].as_ptr() as PtrConstU8; [1u8, 2].as_ptr() as PtrMutU8; @@ -78,9 +90,12 @@ fn main() { let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _; owo::([1u32].as_ptr()) as *const u32; + //~^ unnecessary_cast uwu::([1u32].as_ptr()) as *const u8; + //~^ unnecessary_cast // this will not lint in the function body even though they have the same type, instead here uwu::([1u32].as_ptr()) as *const u32; + //~^ unnecessary_cast // macro version macro_rules! foo { @@ -116,8 +131,10 @@ fn main() { let pid = unsafe { fake_libc::getpid() }; pid as i32; aaa() as u32; + //~^ unnecessary_cast let x = aaa(); aaa() as u32; + //~^ unnecessary_cast // Will not lint currently. bbb() as u32; let x = bbb(); @@ -154,13 +171,21 @@ mod fixable { fn main() { // casting integer literal to float is unnecessary 100 as f32; + //~^ unnecessary_cast 100 as f64; + //~^ unnecessary_cast 100_i32 as f64; + //~^ unnecessary_cast let _ = -100 as f32; + //~^ unnecessary_cast let _ = -100 as f64; + //~^ unnecessary_cast let _ = -100_i32 as f64; + //~^ unnecessary_cast 100. as f32; + //~^ unnecessary_cast 100. as f64; + //~^ unnecessary_cast // Should not trigger #[rustfmt::skip] let v = vec!(1); @@ -173,32 +198,44 @@ mod fixable { 0b11 as f64; 1 as u32; + //~^ unnecessary_cast 0x10 as i32; + //~^ unnecessary_cast 0b10 as usize; + //~^ unnecessary_cast 0o73 as u16; + //~^ unnecessary_cast 1_000_000_000 as u32; + //~^ unnecessary_cast 1.0 as f64; + //~^ unnecessary_cast 0.5 as f32; + //~^ unnecessary_cast 1.0 as u16; let _ = -1 as i32; + //~^ unnecessary_cast let _ = -1.0 as f32; + //~^ unnecessary_cast let _ = 1 as I32Alias; let _ = &1 as &I32Alias; let x = 1i32; let _ = &(x as i32); + //~^ unnecessary_cast } type I32Alias = i32; fn issue_9380() { let _: i32 = -(1) as i32; + //~^ unnecessary_cast let _: f32 = -(1) as f32; let _: i64 = -(1) as i64; + //~^ unnecessary_cast let _: i64 = -(1.0) as i64; let _ = -(1 + 1) as i64; @@ -206,8 +243,10 @@ mod fixable { fn issue_9563() { let _: f64 = (-8.0 as f64).exp(); + //~^ unnecessary_cast #[allow(ambiguous_negative_literals)] let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior + //~^ unnecessary_cast } fn issue_9562_non_literal() { @@ -216,6 +255,7 @@ mod fixable { } let _num = foo() as f32; + //~^ unnecessary_cast } fn issue_9603() { @@ -226,5 +266,6 @@ mod fixable { // `*x.pow(2)` which tries to dereference the return value rather than `x`. fn issue_11968(x: &usize) -> usize { (*x as usize).pow(2) + //~^ unnecessary_cast } } diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 80fd5c13d818..3b8f5d0c5fd1 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -8,241 +8,241 @@ LL | ptr as *const T = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:54:5 + --> tests/ui/unnecessary_cast.rs:55:5 | LL | 1i32 as i32; | ^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:55:5 + --> tests/ui/unnecessary_cast.rs:57:5 | LL | 1f32 as f32; | ^^^^^^^^^^^ help: try: `1_f32` error: casting to the same type is unnecessary (`bool` -> `bool`) - --> tests/ui/unnecessary_cast.rs:56:5 + --> tests/ui/unnecessary_cast.rs:59:5 | LL | false as bool; | ^^^^^^^^^^^^^ help: try: `false` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:59:5 + --> tests/ui/unnecessary_cast.rs:63:5 | LL | -1_i32 as i32; | ^^^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:60:5 + --> tests/ui/unnecessary_cast.rs:65:5 | LL | - 1_i32 as i32; | ^^^^^^^^^^^^^^ help: try: `- 1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:61:5 + --> tests/ui/unnecessary_cast.rs:67:5 | LL | -1f32 as f32; | ^^^^^^^^^^^^ help: try: `-1_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:62:5 + --> tests/ui/unnecessary_cast.rs:69:5 | LL | 1_i32 as i32; | ^^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:63:5 + --> tests/ui/unnecessary_cast.rs:71:5 | LL | 1_f32 as f32; | ^^^^^^^^^^^^ help: try: `1_f32` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:65:22 + --> tests/ui/unnecessary_cast.rs:74:22 | LL | let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:67:5 + --> tests/ui/unnecessary_cast.rs:77:5 | LL | [1u8, 2].as_ptr() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*mut u8` -> `*mut u8`) - --> tests/ui/unnecessary_cast.rs:69:5 + --> tests/ui/unnecessary_cast.rs:80:5 | LL | [1u8, 2].as_mut_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_mut_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:80:5 + --> tests/ui/unnecessary_cast.rs:92:5 | LL | owo::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `owo::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:81:5 + --> tests/ui/unnecessary_cast.rs:94:5 | LL | uwu::([1u32].as_ptr()) as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:83:5 + --> tests/ui/unnecessary_cast.rs:97:5 | LL | uwu::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:118:5 + --> tests/ui/unnecessary_cast.rs:133:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:120:5 + --> tests/ui/unnecessary_cast.rs:136:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:156:9 + --> tests/ui/unnecessary_cast.rs:173:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:157:9 + --> tests/ui/unnecessary_cast.rs:175:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:158:9 + --> tests/ui/unnecessary_cast.rs:177:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:159:17 + --> tests/ui/unnecessary_cast.rs:179:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:160:17 + --> tests/ui/unnecessary_cast.rs:181:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:161:17 + --> tests/ui/unnecessary_cast.rs:183:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:162:9 + --> tests/ui/unnecessary_cast.rs:185:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:163:9 + --> tests/ui/unnecessary_cast.rs:187:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:175:9 + --> tests/ui/unnecessary_cast.rs:200:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:176:9 + --> tests/ui/unnecessary_cast.rs:202:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> tests/ui/unnecessary_cast.rs:177:9 + --> tests/ui/unnecessary_cast.rs:204:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> tests/ui/unnecessary_cast.rs:178:9 + --> tests/ui/unnecessary_cast.rs:206:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:179:9 + --> tests/ui/unnecessary_cast.rs:208:9 | LL | 1_000_000_000 as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:181:9 + --> tests/ui/unnecessary_cast.rs:211:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:182:9 + --> tests/ui/unnecessary_cast.rs:213:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:186:17 + --> tests/ui/unnecessary_cast.rs:218:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:187:17 + --> tests/ui/unnecessary_cast.rs:220:17 | LL | let _ = -1.0 as f32; | ^^^^^^^^^^^ help: try: `-1.0_f32` error: casting to the same type is unnecessary (`i32` -> `i32`) - --> tests/ui/unnecessary_cast.rs:193:18 + --> tests/ui/unnecessary_cast.rs:227:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:199:22 + --> tests/ui/unnecessary_cast.rs:234:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> tests/ui/unnecessary_cast.rs:201:22 + --> tests/ui/unnecessary_cast.rs:237:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:208:22 + --> tests/ui/unnecessary_cast.rs:245:22 | LL | let _: f64 = (-8.0 as f64).exp(); | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:210:23 + --> tests/ui/unnecessary_cast.rs:248:23 | LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior | ^^^^^^^^^^^^ help: try: `8.0_f64` error: casting to the same type is unnecessary (`f32` -> `f32`) - --> tests/ui/unnecessary_cast.rs:218:20 + --> tests/ui/unnecessary_cast.rs:257:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:228:9 + --> tests/ui/unnecessary_cast.rs:268:9 | LL | (*x as usize).pow(2) | ^^^^^^^^^^^^^ help: try: `{ *x }` diff --git a/tests/ui/unnecessary_cast_unfixable.rs b/tests/ui/unnecessary_cast_unfixable.rs index 36adf19c91ca..05dd20c7a114 100644 --- a/tests/ui/unnecessary_cast_unfixable.rs +++ b/tests/ui/unnecessary_cast_unfixable.rs @@ -2,8 +2,9 @@ //@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` + //~^ unnecessary_cast + + } mod issue11113 { @@ -19,7 +20,8 @@ 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 + //~^ unnecessary_cast + } } } diff --git a/tests/ui/unnecessary_cast_unfixable.stderr b/tests/ui/unnecessary_cast_unfixable.stderr index cafaffeae6c3..0047b38850b7 100644 --- a/tests/ui/unnecessary_cast_unfixable.stderr +++ b/tests/ui/unnecessary_cast_unfixable.stderr @@ -8,7 +8,7 @@ LL | let _ = std::ptr::null() as *const u8; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) - --> tests/ui/unnecessary_cast_unfixable.rs:21:16 + --> tests/ui/unnecessary_cast_unfixable.rs:22:16 | LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs index 9915f8b843ef..406c0133c5d3 100644 --- a/tests/ui/unnecessary_clippy_cfg.rs +++ b/tests/ui/unnecessary_clippy_cfg.rs @@ -2,22 +2,32 @@ #![warn(clippy::unnecessary_clippy_cfg)] #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg +//~| duplicated_attributes + #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg +//~| duplicated_attributes + #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] -//~^ ERROR: no need to put clippy lints behind a `clippy` cfg +//~^ unnecessary_clippy_cfg + pub struct Bar; fn main() {} diff --git a/tests/ui/unnecessary_clippy_cfg.stderr b/tests/ui/unnecessary_clippy_cfg.stderr index 01f842a657de..f6f36fbf2baa 100644 --- a/tests/ui/unnecessary_clippy_cfg.stderr +++ b/tests/ui/unnecessary_clippy_cfg.stderr @@ -8,7 +8,7 @@ LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] = help: to override `-D warnings` add `#[allow(clippy::unnecessary_clippy_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:6:37 + --> tests/ui/unnecessary_clippy_cfg.rs:7:37 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:8:37 + --> tests/ui/unnecessary_clippy_cfg.rs:10:37 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,19 +24,19 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:10:1 + --> tests/ui/unnecessary_clippy_cfg.rs:14:1 | LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:13:1 + --> tests/ui/unnecessary_clippy_cfg.rs:18:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:15:36 + --> tests/ui/unnecessary_clippy_cfg.rs:21:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:17:36 + --> tests/ui/unnecessary_clippy_cfg.rs:24:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,24 +52,24 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:19:1 + --> tests/ui/unnecessary_clippy_cfg.rs:28:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:8:26 + --> tests/ui/unnecessary_clippy_cfg.rs:10:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ | note: first defined here - --> tests/ui/unnecessary_clippy_cfg.rs:6:26 + --> tests/ui/unnecessary_clippy_cfg.rs:7:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:8:26 + --> tests/ui/unnecessary_clippy_cfg.rs:10:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ @@ -77,18 +77,18 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:17:25 + --> tests/ui/unnecessary_clippy_cfg.rs:24:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ | note: first defined here - --> tests/ui/unnecessary_clippy_cfg.rs:15:25 + --> tests/ui/unnecessary_clippy_cfg.rs:21:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:17:25 + --> tests/ui/unnecessary_clippy_cfg.rs:24:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 12ac96aa64ca..3ce7c7ef0252 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -21,34 +21,41 @@ 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` + //~^ clone_on_ref_ptr + + Rc::clone(&rc); arc.clone(); - //~^ ERROR: using `.clone()` on a ref-counted pointer + //~^ clone_on_ref_ptr + Arc::clone(&arc); rcweak.clone(); - //~^ ERROR: using `.clone()` on a ref-counted pointer + //~^ clone_on_ref_ptr + rc::Weak::clone(&rcweak); arc_weak.clone(); - //~^ ERROR: using `.clone()` on a ref-counted pointer + //~^ clone_on_ref_ptr + sync::Weak::clone(&arc_weak); let x = Arc::new(SomeImpl); let _: Arc = x.clone(); - //~^ ERROR: using `.clone()` on a ref-counted pointer + //~^ clone_on_ref_ptr + } 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` + //~^ clone_on_copy + + Some(t).clone(); - //~^ ERROR: using `clone` on type `Option` which implements the `Copy` trait + //~^ clone_on_copy + } mod many_derefs { @@ -83,7 +90,8 @@ mod many_derefs { fn go1() { let a = A; let _: E = a.clone(); - //~^ ERROR: using `clone` on type `E` which implements the `Copy` trait + //~^ clone_on_copy + let _: E = *****a; } } @@ -103,6 +111,7 @@ mod issue2076 { fn func() -> Option> { let rc = Rc::new(42); Some(try_opt!(Some(rc)).clone()) - //~^ ERROR: using `.clone()` on a ref-counted pointer + //~^ clone_on_ref_ptr + } } diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index e34a387c77e2..cf508eb4c645 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -8,31 +8,31 @@ LL | rc.clone(); = help: to override `-D warnings` add `#[allow(clippy::clone_on_ref_ptr)]` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:28:5 + --> tests/ui/unnecessary_clone.rs:29:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try: `Arc::::clone(&arc)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:32:5 + --> tests/ui/unnecessary_clone.rs:34:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try: `Weak::::clone(&rcweak)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:36:5 + --> tests/ui/unnecessary_clone.rs:39:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try: `Weak::::clone(&arc_weak)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:41:33 + --> tests/ui/unnecessary_clone.rs:45:33 | LL | let _: Arc = x.clone(); | ^^^^^^^^^ help: try: `Arc::::clone(&x)` error: using `clone` on type `T` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:46:5 + --> tests/ui/unnecessary_clone.rs:51:5 | LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` @@ -41,19 +41,19 @@ LL | t.clone(); = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `Option` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:50:5 + --> tests/ui/unnecessary_clone.rs:56:5 | LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on type `E` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:85:20 + --> tests/ui/unnecessary_clone.rs:92:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:105:14 + --> tests/ui/unnecessary_clone.rs:113:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::::clone(&try_opt!(Some(rc)))` diff --git a/tests/ui/unnecessary_fallible_conversions.fixed b/tests/ui/unnecessary_fallible_conversions.fixed index b6dd1f267743..59d24e9bb7e2 100644 --- a/tests/ui/unnecessary_fallible_conversions.fixed +++ b/tests/ui/unnecessary_fallible_conversions.fixed @@ -4,40 +4,50 @@ fn main() { // --- TryFromMethod `T::try_from(u)` --- let _: i64 = 0i32.into(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = 0i32.into(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryFromFunction `T::try_from(U)` --- let _ = i64::from(0i32); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _ = i64::from(0i32); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryIntoFunction `U::try_into(t)` --- let _: i64 = i32::into(0); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = i32::into(0i32); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryFromFunction `>::try_from(U)` --- let _ = >::from(0); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _ = >::from(0); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryIntoFunction `>::try_into(U)` --- let _: i64 = >::into(0); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = >::into(0); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + } diff --git a/tests/ui/unnecessary_fallible_conversions.rs b/tests/ui/unnecessary_fallible_conversions.rs index 6f8df7365e89..7e504acb5e21 100644 --- a/tests/ui/unnecessary_fallible_conversions.rs +++ b/tests/ui/unnecessary_fallible_conversions.rs @@ -4,40 +4,50 @@ fn main() { // --- TryFromMethod `T::try_from(u)` --- let _: i64 = 0i32.try_into().unwrap(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = 0i32.try_into().expect("can't happen"); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryFromFunction `T::try_from(U)` --- let _ = i64::try_from(0i32).unwrap(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _ = i64::try_from(0i32).expect("can't happen"); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryIntoFunction `U::try_into(t)` --- let _: i64 = i32::try_into(0).unwrap(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = i32::try_into(0i32).expect("can't happen"); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryFromFunction `>::try_from(U)` --- let _ = >::try_from(0).unwrap(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _ = >::try_from(0).expect("can't happen"); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + // --- TryIntoFunction `>::try_into(U)` --- let _: i64 = >::try_into(0).unwrap(); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + let _: i64 = >::try_into(0).expect("can't happen"); - //~^ ERROR: use of a fallible conversion when an infallible one could be used + //~^ unnecessary_fallible_conversions + } diff --git a/tests/ui/unnecessary_fallible_conversions.stderr b/tests/ui/unnecessary_fallible_conversions.stderr index ade3aada9289..160917694c44 100644 --- a/tests/ui/unnecessary_fallible_conversions.stderr +++ b/tests/ui/unnecessary_fallible_conversions.stderr @@ -14,7 +14,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:9:23 + --> tests/ui/unnecessary_fallible_conversions.rs:10:23 | LL | let _: i64 = 0i32.try_into().expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:14:13 + --> tests/ui/unnecessary_fallible_conversions.rs:16:13 | LL | let _ = i64::try_from(0i32).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:17:13 + --> tests/ui/unnecessary_fallible_conversions.rs:20:13 | LL | let _ = i64::try_from(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:22:18 + --> tests/ui/unnecessary_fallible_conversions.rs:26:18 | LL | let _: i64 = i32::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL + let _: i64 = i32::into(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:25:18 + --> tests/ui/unnecessary_fallible_conversions.rs:30:18 | LL | let _: i64 = i32::try_into(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ LL + let _: i64 = i32::into(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:30:13 + --> tests/ui/unnecessary_fallible_conversions.rs:36:13 | LL | let _ = >::try_from(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL + let _ = >::from(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:33:13 + --> tests/ui/unnecessary_fallible_conversions.rs:40:13 | LL | let _ = >::try_from(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL + let _ = >::from(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:38:18 + --> tests/ui/unnecessary_fallible_conversions.rs:46:18 | LL | let _: i64 = >::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL + let _: i64 = >::into(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:41:18 + --> tests/ui/unnecessary_fallible_conversions.rs:50:18 | LL | let _: i64 = >::try_into(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 8cf102ab0a55..e05161d207ec 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -3,29 +3,36 @@ fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); - //~^ ERROR: this `.filter_map` can be written more simply - //~| NOTE: `-D clippy::unnecessary-filter-map` implied by `-D warnings` + //~^ unnecessary_filter_map + + let _ = (0..4).filter_map(|x| { - //~^ ERROR: this `.filter_map` can be written more simply + //~^ unnecessary_filter_map + if x > 1 { return Some(x); }; None }); let _ = (0..4).filter_map(|x| match x { - //~^ ERROR: this `.filter_map` can be written more simply + //~^ unnecessary_filter_map + 0 | 1 => None, _ => Some(x), }); let _ = (0..4).filter_map(|x| Some(x + 1)); - //~^ ERROR: this `.filter_map` can be written more simply + //~^ unnecessary_filter_map + let _ = (0..4).filter_map(i32::checked_abs); let _ = (0..4).filter_map(Some); let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); + //~^ redundant_closure + //~| unnecessary_filter_map + //~| unnecessary_filter_map } fn filter_map_none_changes_item_type() -> impl Iterator { @@ -163,4 +170,5 @@ fn issue11260() { // #11260 is about unnecessary_find_map, but the fix also kind of applies to // unnecessary_filter_map let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); + //~^ unnecessary_filter_map } diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index b21589c5f844..94435ab3effd 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -8,37 +8,38 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:8:13 + --> tests/ui/unnecessary_filter_map.rs:9:13 | LL | let _ = (0..4).filter_map(|x| { | _____________^ LL | | +LL | | LL | | if x > 1 { -LL | | return Some(x); -LL | | }; +... | LL | | None LL | | }); | |______^ help: try instead: `filter` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:15:13 + --> tests/ui/unnecessary_filter_map.rs:17:13 | LL | let _ = (0..4).filter_map(|x| match x { | _____________^ LL | | +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ help: try instead: `filter` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:21:13 + --> tests/ui/unnecessary_filter_map.rs:24:13 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map` error: redundant closure - --> tests/ui/unnecessary_filter_map.rs:28:57 + --> tests/ui/unnecessary_filter_map.rs:32:57 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^^^^^^^^ help: replace the closure with the function itself: `Some` @@ -47,19 +48,19 @@ LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: filter_map is unnecessary - --> tests/ui/unnecessary_filter_map.rs:28:61 + --> tests/ui/unnecessary_filter_map.rs:32:61 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^ help: try removing the filter_map error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:28:13 + --> tests/ui/unnecessary_filter_map.rs:32:13 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:165:14 + --> tests/ui/unnecessary_filter_map.rs:172:14 | LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `filter` diff --git a/tests/ui/unnecessary_find_map.rs b/tests/ui/unnecessary_find_map.rs index c357d8532481..f883b4eb38c5 100644 --- a/tests/ui/unnecessary_find_map.rs +++ b/tests/ui/unnecessary_find_map.rs @@ -3,23 +3,27 @@ fn main() { let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); - //~^ ERROR: this `.find_map` can be written more simply - //~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings` + //~^ unnecessary_find_map + + let _ = (0..4).find_map(|x| { - //~^ ERROR: this `.find_map` can be written more simply + //~^ unnecessary_find_map + if x > 1 { return Some(x); }; None }); let _ = (0..4).find_map(|x| match x { - //~^ ERROR: this `.find_map` can be written more simply + //~^ unnecessary_find_map + 0 | 1 => None, _ => Some(x), }); let _ = (0..4).find_map(|x| Some(x + 1)); - //~^ ERROR: this `.find_map` can be written more simply + //~^ unnecessary_find_map + let _ = (0..4).find_map(i32::checked_abs); } @@ -31,5 +35,6 @@ fn find_map_none_changes_item_type() -> Option { fn issue11260() { let y = Some(1); let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); + //~^ unnecessary_find_map let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()` } diff --git a/tests/ui/unnecessary_find_map.stderr b/tests/ui/unnecessary_find_map.stderr index 98a6c3d164a6..079c1092784e 100644 --- a/tests/ui/unnecessary_find_map.stderr +++ b/tests/ui/unnecessary_find_map.stderr @@ -8,37 +8,38 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:8:13 + --> tests/ui/unnecessary_find_map.rs:9:13 | LL | let _ = (0..4).find_map(|x| { | _____________^ LL | | +LL | | LL | | if x > 1 { -LL | | return Some(x); -LL | | }; +... | LL | | None LL | | }); | |______^ help: try instead: `find` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:15:13 + --> tests/ui/unnecessary_find_map.rs:17:13 | LL | let _ = (0..4).find_map(|x| match x { | _____________^ LL | | +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ help: try instead: `find` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:21:13 + --> tests/ui/unnecessary_find_map.rs:24:13 | LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map(..).next()` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:33:14 + --> tests/ui/unnecessary_find_map.rs:37:14 | LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `find` diff --git a/tests/ui/unnecessary_first_then_check.fixed b/tests/ui/unnecessary_first_then_check.fixed index 7202e1bbd179..aa049eb33751 100644 --- a/tests/ui/unnecessary_first_then_check.fixed +++ b/tests/ui/unnecessary_first_then_check.fixed @@ -4,19 +4,26 @@ fn main() { let s = [1, 2, 3]; let _: bool = !s.is_empty(); + //~^ unnecessary_first_then_check let _: bool = s.is_empty(); + //~^ unnecessary_first_then_check let v = vec![1, 2, 3]; let _: bool = !v.is_empty(); + //~^ unnecessary_first_then_check let n = [[1, 2, 3], [4, 5, 6]]; let _: bool = !n[0].is_empty(); + //~^ unnecessary_first_then_check let _: bool = n[0].is_empty(); + //~^ unnecessary_first_then_check struct Foo { bar: &'static [i32], } let f = [Foo { bar: &[] }]; let _: bool = !f[0].bar.is_empty(); + //~^ unnecessary_first_then_check let _: bool = f[0].bar.is_empty(); + //~^ unnecessary_first_then_check } diff --git a/tests/ui/unnecessary_first_then_check.rs b/tests/ui/unnecessary_first_then_check.rs index 762b95999288..4c2ac3ba40a2 100644 --- a/tests/ui/unnecessary_first_then_check.rs +++ b/tests/ui/unnecessary_first_then_check.rs @@ -4,19 +4,26 @@ fn main() { let s = [1, 2, 3]; let _: bool = s.first().is_some(); + //~^ unnecessary_first_then_check let _: bool = s.first().is_none(); + //~^ unnecessary_first_then_check let v = vec![1, 2, 3]; let _: bool = v.first().is_some(); + //~^ unnecessary_first_then_check let n = [[1, 2, 3], [4, 5, 6]]; let _: bool = n[0].first().is_some(); + //~^ unnecessary_first_then_check let _: bool = n[0].first().is_none(); + //~^ unnecessary_first_then_check struct Foo { bar: &'static [i32], } let f = [Foo { bar: &[] }]; let _: bool = f[0].bar.first().is_some(); + //~^ unnecessary_first_then_check let _: bool = f[0].bar.first().is_none(); + //~^ unnecessary_first_then_check } diff --git a/tests/ui/unnecessary_first_then_check.stderr b/tests/ui/unnecessary_first_then_check.stderr index bbaf7e68edab..408b388ecf71 100644 --- a/tests/ui/unnecessary_first_then_check.stderr +++ b/tests/ui/unnecessary_first_then_check.stderr @@ -8,37 +8,37 @@ LL | let _: bool = s.first().is_some(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_first_then_check)]` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:7:21 + --> tests/ui/unnecessary_first_then_check.rs:8:21 | LL | let _: bool = s.first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:10:19 + --> tests/ui/unnecessary_first_then_check.rs:12:19 | LL | let _: bool = v.first().is_some(); | ^^^^^^^^^^^^^^^^^^^ help: replace this with: `!v.is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:13:19 + --> tests/ui/unnecessary_first_then_check.rs:16:19 | LL | let _: bool = n[0].first().is_some(); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `!n[0].is_empty()` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:14:24 + --> tests/ui/unnecessary_first_then_check.rs:18:24 | LL | let _: bool = n[0].first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:20:19 + --> tests/ui/unnecessary_first_then_check.rs:25:19 | LL | let _: bool = f[0].bar.first().is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `!f[0].bar.is_empty()` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:21:28 + --> tests/ui/unnecessary_first_then_check.rs:27:28 | LL | let _: bool = f[0].bar.first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed index c5bc11b55ab5..2c3f87513c40 100644 --- a/tests/ui/unnecessary_fold.fixed +++ b/tests/ui/unnecessary_fold.fixed @@ -8,19 +8,25 @@ fn is_any(acc: bool, x: usize) -> bool { fn unnecessary_fold() { // Can be replaced by .any let _ = (0..3).any(|x| x > 2); + //~^ unnecessary_fold // Can be replaced by .any (checking suggestion) let _ = (0..3).fold(false, is_any); + //~^ redundant_closure // Can be replaced by .all let _ = (0..3).all(|x| x > 2); + //~^ unnecessary_fold // Can be replaced by .sum let _: i32 = (0..3).sum(); + //~^ unnecessary_fold // Can be replaced by .product let _: i32 = (0..3).product(); + //~^ unnecessary_fold } /// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` fn unnecessary_fold_span_for_multi_element_chain() { let _: bool = (0..3).map(|x| 2 * x).any(|x| x > 2); + //~^ unnecessary_fold } /// Calls which should not trigger the `UNNECESSARY_FOLD` lint @@ -51,6 +57,7 @@ fn unnecessary_fold_over_multiple_lines() { .map(|x| x + 1) .filter(|x| x % 2 == 0) .any(|x| x > 2); + //~^ unnecessary_fold } fn issue10000() { @@ -62,16 +69,25 @@ fn issue10000() { fn smoketest_map(mut map: HashMap) { map.insert(0, 0); assert_eq!(map.values().sum::(), 0); + //~^ unnecessary_fold // more cases: let _ = map.values().sum::(); + //~^ unnecessary_fold let _ = map.values().product::(); + //~^ unnecessary_fold let _: i32 = map.values().sum(); + //~^ unnecessary_fold let _: i32 = map.values().product(); + //~^ unnecessary_fold anything(map.values().sum::()); + //~^ unnecessary_fold anything(map.values().product::()); + //~^ unnecessary_fold num(map.values().sum()); + //~^ unnecessary_fold num(map.values().product()); + //~^ unnecessary_fold } smoketest_map(HashMap::new()); diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index 3a5136eeeaeb..954020046763 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -8,19 +8,25 @@ fn is_any(acc: bool, x: usize) -> bool { fn unnecessary_fold() { // Can be replaced by .any let _ = (0..3).fold(false, |acc, x| acc || x > 2); + //~^ unnecessary_fold // Can be replaced by .any (checking suggestion) let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); + //~^ redundant_closure // Can be replaced by .all let _ = (0..3).fold(true, |acc, x| acc && x > 2); + //~^ unnecessary_fold // Can be replaced by .sum let _: i32 = (0..3).fold(0, |acc, x| acc + x); + //~^ unnecessary_fold // Can be replaced by .product let _: i32 = (0..3).fold(1, |acc, x| acc * x); + //~^ unnecessary_fold } /// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)` fn unnecessary_fold_span_for_multi_element_chain() { let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); + //~^ unnecessary_fold } /// Calls which should not trigger the `UNNECESSARY_FOLD` lint @@ -51,6 +57,7 @@ fn unnecessary_fold_over_multiple_lines() { .map(|x| x + 1) .filter(|x| x % 2 == 0) .fold(false, |acc, x| acc || x > 2); + //~^ unnecessary_fold } fn issue10000() { @@ -62,16 +69,25 @@ fn issue10000() { fn smoketest_map(mut map: HashMap) { map.insert(0, 0); assert_eq!(map.values().fold(0, |x, y| x + y), 0); + //~^ unnecessary_fold // more cases: let _ = map.values().fold(0, |x, y| x + y); + //~^ unnecessary_fold let _ = map.values().fold(1, |x, y| x * y); + //~^ unnecessary_fold let _: i32 = map.values().fold(0, |x, y| x + y); + //~^ unnecessary_fold let _: i32 = map.values().fold(1, |x, y| x * y); + //~^ unnecessary_fold anything(map.values().fold(0, |x, y| x + y)); + //~^ unnecessary_fold anything(map.values().fold(1, |x, y| x * y)); + //~^ unnecessary_fold num(map.values().fold(0, |x, y| x + y)); + //~^ unnecessary_fold num(map.values().fold(1, |x, y| x * y)); + //~^ unnecessary_fold } smoketest_map(HashMap::new()); diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr index 31abab62f4c6..d82b1f39b48b 100644 --- a/tests/ui/unnecessary_fold.stderr +++ b/tests/ui/unnecessary_fold.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_fold)]` error: redundant closure - --> tests/ui/unnecessary_fold.rs:12:32 + --> tests/ui/unnecessary_fold.rs:13:32 | LL | let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `is_any` @@ -17,85 +17,85 @@ LL | let _ = (0..3).fold(false, |acc, x| is_any(acc, x)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: this `.fold` can be written more succinctly using another method - --> tests/ui/unnecessary_fold.rs:14:20 + --> tests/ui/unnecessary_fold.rs:16: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 - --> tests/ui/unnecessary_fold.rs:16:25 + --> tests/ui/unnecessary_fold.rs:19: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 - --> tests/ui/unnecessary_fold.rs:18:25 + --> tests/ui/unnecessary_fold.rs:22: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 - --> tests/ui/unnecessary_fold.rs:23:41 + --> tests/ui/unnecessary_fold.rs:28: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 - --> tests/ui/unnecessary_fold.rs:53:10 + --> tests/ui/unnecessary_fold.rs:59: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 - --> tests/ui/unnecessary_fold.rs:64:33 + --> tests/ui/unnecessary_fold.rs:71: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 - --> tests/ui/unnecessary_fold.rs:67:30 + --> tests/ui/unnecessary_fold.rs:75: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 - --> tests/ui/unnecessary_fold.rs:68:30 + --> tests/ui/unnecessary_fold.rs:77: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 - --> tests/ui/unnecessary_fold.rs:69:35 + --> tests/ui/unnecessary_fold.rs:79: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 - --> tests/ui/unnecessary_fold.rs:70:35 + --> tests/ui/unnecessary_fold.rs:81: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 - --> tests/ui/unnecessary_fold.rs:71:31 + --> tests/ui/unnecessary_fold.rs:83: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 - --> tests/ui/unnecessary_fold.rs:72:31 + --> tests/ui/unnecessary_fold.rs:85: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 - --> tests/ui/unnecessary_fold.rs:73:26 + --> tests/ui/unnecessary_fold.rs:87: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 - --> tests/ui/unnecessary_fold.rs:74:26 + --> tests/ui/unnecessary_fold.rs:89:26 | LL | num(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` diff --git a/tests/ui/unnecessary_get_then_check.fixed b/tests/ui/unnecessary_get_then_check.fixed index 178a3300c346..6aba66b87318 100644 --- a/tests/ui/unnecessary_get_then_check.fixed +++ b/tests/ui/unnecessary_get_then_check.fixed @@ -4,23 +4,33 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; fn main() { let s: HashSet = HashSet::new(); - let _ = s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = !s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.contains("a"); +//~^ unnecessary_get_then_check +let _ = !s.contains("a"); +//~^ unnecessary_get_then_check let s: HashMap = HashMap::new(); - let _ = s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = !s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.contains_key("a"); +//~^ unnecessary_get_then_check +let _ = !s.contains_key("a"); +//~^ unnecessary_get_then_check let s: BTreeSet = BTreeSet::new(); - let _ = s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = !s.contains("a"); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.contains("a"); +//~^ unnecessary_get_then_check +let _ = !s.contains("a"); +//~^ unnecessary_get_then_check let s: BTreeMap = BTreeMap::new(); - let _ = s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = !s.contains_key("a"); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.contains_key("a"); +//~^ unnecessary_get_then_check +let _ = !s.contains_key("a"); +//~^ unnecessary_get_then_check // Import to check that the generic annotations are kept! let s: HashSet = HashSet::new(); - let _ = s.contains::("a"); //~ ERROR: unnecessary use of `get::("a").is_some()` - let _ = !s.contains::("a"); //~ ERROR: unnecessary use of `get::("a").is_none()` +let _ = s.contains::("a"); +//~^ unnecessary_get_then_check +let _ = !s.contains::("a"); +//~^ unnecessary_get_then_check } diff --git a/tests/ui/unnecessary_get_then_check.rs b/tests/ui/unnecessary_get_then_check.rs index c197bdef47ea..d56e7d209e4e 100644 --- a/tests/ui/unnecessary_get_then_check.rs +++ b/tests/ui/unnecessary_get_then_check.rs @@ -4,23 +4,33 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; fn main() { let s: HashSet = HashSet::new(); - let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.get("a").is_some(); +//~^ unnecessary_get_then_check +let _ = s.get("a").is_none(); +//~^ unnecessary_get_then_check let s: HashMap = HashMap::new(); - let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.get("a").is_some(); +//~^ unnecessary_get_then_check +let _ = s.get("a").is_none(); +//~^ unnecessary_get_then_check let s: BTreeSet = BTreeSet::new(); - let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.get("a").is_some(); +//~^ unnecessary_get_then_check +let _ = s.get("a").is_none(); +//~^ unnecessary_get_then_check let s: BTreeMap = BTreeMap::new(); - let _ = s.get("a").is_some(); //~ ERROR: unnecessary use of `get("a").is_some()` - let _ = s.get("a").is_none(); //~ ERROR: unnecessary use of `get("a").is_none()` +let _ = s.get("a").is_some(); +//~^ unnecessary_get_then_check +let _ = s.get("a").is_none(); +//~^ unnecessary_get_then_check // Import to check that the generic annotations are kept! let s: HashSet = HashSet::new(); - let _ = s.get::("a").is_some(); //~ ERROR: unnecessary use of `get::("a").is_some()` - let _ = s.get::("a").is_none(); //~ ERROR: unnecessary use of `get::("a").is_none()` +let _ = s.get::("a").is_some(); +//~^ unnecessary_get_then_check +let _ = s.get::("a").is_none(); +//~^ unnecessary_get_then_check } diff --git a/tests/ui/unnecessary_get_then_check.stderr b/tests/ui/unnecessary_get_then_check.stderr index 0477c03d16dd..a33409b30c80 100644 --- a/tests/ui/unnecessary_get_then_check.stderr +++ b/tests/ui/unnecessary_get_then_check.stderr @@ -1,75 +1,75 @@ error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:7:15 + --> tests/ui/unnecessary_get_then_check.rs:7:11 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` | = note: `-D clippy::unnecessary-get-then-check` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_get_then_check)]` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:8:15 + --> tests/ui/unnecessary_get_then_check.rs:9:11 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:11:15 + --> tests/ui/unnecessary_get_then_check.rs:13:11 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:12:15 + --> tests/ui/unnecessary_get_then_check.rs:15:11 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains_key("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains_key("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:15:15 + --> tests/ui/unnecessary_get_then_check.rs:19:11 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:16:15 + --> tests/ui/unnecessary_get_then_check.rs:21:11 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:19:15 + --> tests/ui/unnecessary_get_then_check.rs:25:11 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:20:15 + --> tests/ui/unnecessary_get_then_check.rs:27:11 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains_key("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains_key("a")` error: unnecessary use of `get::("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:24:15 + --> tests/ui/unnecessary_get_then_check.rs:32:11 | -LL | let _ = s.get::("a").is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains::("a")` +LL | let _ = s.get::("a").is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains::("a")` error: unnecessary use of `get::("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:25:15 + --> tests/ui/unnecessary_get_then_check.rs:34:11 | -LL | let _ = s.get::("a").is_none(); - | --^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains::("a")` +LL | let _ = s.get::("a").is_none(); + | --^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains::("a")` error: aborting due to 10 previous errors diff --git a/tests/ui/unnecessary_iter_cloned.fixed b/tests/ui/unnecessary_iter_cloned.fixed index dc5e163ff04e..533059d91fce 100644 --- a/tests/ui/unnecessary_iter_cloned.fixed +++ b/tests/ui/unnecessary_iter_cloned.fixed @@ -29,6 +29,7 @@ fn main() { // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { for (t, path) in files { + //~^ unnecessary_to_owned let other = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -44,6 +45,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { for (t, path) in files.iter() { + //~^ unnecessary_to_owned let other = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -175,7 +177,8 @@ mod issue_12821 { fn foo() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter() { - //~^ ERROR: unnecessary use of `cloned` + //~^ unnecessary_to_owned + println!("{c}"); // should not suggest to remove `&` } } @@ -183,8 +186,9 @@ mod issue_12821 { fn bar() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter() { - //~^ ERROR: unnecessary use of `cloned` - let ref_c = c; //~ HELP: remove any references to the binding + //~^ unnecessary_to_owned + +let ref_c = c; println!("{ref_c}"); } } @@ -192,8 +196,9 @@ mod issue_12821 { fn baz() { let v: Vec<_> = "hello".chars().enumerate().collect(); for (i, c) in v.iter() { - //~^ ERROR: unnecessary use of `cloned` - let ref_c = c; //~ HELP: remove any references to the binding + //~^ unnecessary_to_owned + +let ref_c = c; let ref_i = i; println!("{i} {ref_c}"); // should not suggest to remove `&` from `i` } diff --git a/tests/ui/unnecessary_iter_cloned.rs b/tests/ui/unnecessary_iter_cloned.rs index 8f797ac717fb..5e0c2e6d78ec 100644 --- a/tests/ui/unnecessary_iter_cloned.rs +++ b/tests/ui/unnecessary_iter_cloned.rs @@ -29,6 +29,7 @@ fn main() { // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { for (t, path) in files.iter().copied() { + //~^ unnecessary_to_owned let other = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -44,6 +45,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { for (t, path) in files.iter().copied() { + //~^ unnecessary_to_owned let other = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -175,7 +177,8 @@ mod issue_12821 { fn foo() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter().cloned() { - //~^ ERROR: unnecessary use of `cloned` + //~^ unnecessary_to_owned + println!("{c}"); // should not suggest to remove `&` } } @@ -183,8 +186,9 @@ mod issue_12821 { fn bar() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter().cloned() { - //~^ ERROR: unnecessary use of `cloned` - let ref_c = &c; //~ HELP: remove any references to the binding + //~^ unnecessary_to_owned + +let ref_c = &c; println!("{ref_c}"); } } @@ -192,8 +196,9 @@ mod issue_12821 { fn baz() { let v: Vec<_> = "hello".chars().enumerate().collect(); for (i, c) in v.iter().cloned() { - //~^ ERROR: unnecessary use of `cloned` - let ref_c = &c; //~ HELP: remove any references to the binding + //~^ unnecessary_to_owned + +let ref_c = &c; let ref_i = &i; println!("{i} {ref_c}"); // should not suggest to remove `&` from `i` } diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index 6f2ae0ab1f35..61ae9acc35cc 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -9,11 +9,12 @@ LL | for (t, path) in files.iter().copied() { help: remove any references to the binding | LL ~ for (t, path) in files { +LL | LL ~ let other = match get_file_path(t) { | error: unnecessary use of `copied` - --> tests/ui/unnecessary_iter_cloned.rs:46:22 + --> tests/ui/unnecessary_iter_cloned.rs:47:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ @@ -21,17 +22,18 @@ LL | for (t, path) in files.iter().copied() { help: remove any references to the binding | LL ~ for (t, path) in files.iter() { +LL | LL ~ let other = match get_file_path(t) { | error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:177:18 + --> tests/ui/unnecessary_iter_cloned.rs:179:18 | LL | for c in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ help: remove any references to the binding: `v.iter()` error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:185:18 + --> tests/ui/unnecessary_iter_cloned.rs:188:18 | LL | for c in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ @@ -40,11 +42,12 @@ help: remove any references to the binding | LL ~ for c in v.iter() { LL | -LL ~ let ref_c = c; +LL | +LL ~ let ref_c = c; | error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:194:23 + --> tests/ui/unnecessary_iter_cloned.rs:198:23 | LL | for (i, c) in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ @@ -53,7 +56,8 @@ help: remove any references to the binding | LL ~ for (i, c) in v.iter() { LL | -LL ~ let ref_c = c; +LL | +LL ~ let ref_c = c; LL ~ let ref_i = i; | diff --git a/tests/ui/unnecessary_join.rs b/tests/ui/unnecessary_join.rs index d042d9e5c212..e58b2696645a 100644 --- a/tests/ui/unnecessary_join.rs +++ b/tests/ui/unnecessary_join.rs @@ -8,6 +8,7 @@ fn main() { .iter() .map(|item| item.to_uppercase()) .collect::>() + //~^ unnecessary_join .join(""); println!("{}", output); @@ -17,6 +18,7 @@ fn main() { .iter() .map(|item| item.to_uppercase()) .collect::>() + //~^ unnecessary_join .join(""); println!("{}", output); diff --git a/tests/ui/unnecessary_join.stderr b/tests/ui/unnecessary_join.stderr index a06a1059033b..a7677fe2f9eb 100644 --- a/tests/ui/unnecessary_join.stderr +++ b/tests/ui/unnecessary_join.stderr @@ -3,6 +3,7 @@ error: called `.collect::>().join("")` on an iterator | LL | .collect::>() | __________^ +LL | | LL | | .join(""); | |_________________^ help: consider using: `collect::()` | @@ -10,10 +11,11 @@ LL | | .join(""); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_join)]` error: called `.collect::>().join("")` on an iterator - --> tests/ui/unnecessary_join.rs:19:10 + --> tests/ui/unnecessary_join.rs:20:10 | LL | .collect::>() | __________^ +LL | | LL | | .join(""); | |_________________^ help: consider using: `collect::()` diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed index d8031c484e5e..9a3290816389 100644 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ b/tests/ui/unnecessary_lazy_eval.fixed @@ -81,42 +81,69 @@ fn main() { // Should lint - Option let _ = opt.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or(astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or(ext_str.some_field); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_arr[0]); let _ = opt.and(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or(None); + //~^ unnecessary_lazy_evaluations let _ = opt.get_or_insert(2); + //~^ unnecessary_lazy_evaluations let _ = opt.ok_or(2); + //~^ unnecessary_lazy_evaluations let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); + //~^ unnecessary_lazy_evaluations let _ = cond.then_some(astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = true.then_some({}); + //~^ unnecessary_lazy_evaluations let _ = true.then_some({}); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref let r = &1; let _ = Some(1).unwrap_or(*r); + //~^ unnecessary_lazy_evaluations let b = Box::new(1); let _ = Some(1).unwrap_or(*b); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref through autoderef let _ = Some(1).as_ref().unwrap_or(&r); + //~^ unnecessary_lazy_evaluations let _ = Some(1).as_ref().unwrap_or(&b); + //~^ unnecessary_lazy_evaluations // Cases when unwrap is not called on a simple variable let _ = Some(10).unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = Some(10).and(ext_opt); + //~^ unnecessary_lazy_evaluations let _: Option = None.or(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = None.get_or_insert(2); + //~^ unnecessary_lazy_evaluations let _: Result = None.ok_or(2); + //~^ unnecessary_lazy_evaluations let _: Option = None.or(None); + //~^ unnecessary_lazy_evaluations let mut deep = Deep(Some(42)); let _ = deep.0.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.and(ext_opt); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or(None); + //~^ unnecessary_lazy_evaluations let _ = deep.0.get_or_insert(2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.ok_or(2); + //~^ unnecessary_lazy_evaluations // Should not lint - Option let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); @@ -148,16 +175,22 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Option = None.or(Some(3)); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or(Some(3)); + //~^ unnecessary_lazy_evaluations let _ = opt.or(Some(3)); + //~^ unnecessary_lazy_evaluations // Should lint - Result let res: Result = Err(5); let res2: Result = Err(SomeStruct { some_field: 5 }); let _ = res2.unwrap_or(2); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or(astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or(ext_str.some_field); + //~^ unnecessary_lazy_evaluations // Should not lint - Result let _ = res.unwrap_or_else(|err| err); @@ -180,13 +213,20 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Result = res.and(Err(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and(Err(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and(Err(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or(Ok(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res. + //~^ unnecessary_lazy_evaluations // some lines // some lines // some lines @@ -217,39 +257,39 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { // See comments in `eager_or_lazy.rs` for the rules that this is meant to follow let _x = false.then_some(i32::MAX + 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(i32::MAX * 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(i32::MAX - 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(i32::MIN - 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(255u8 << 7); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(255u8 << 8); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(255u8 >> 8); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255u8 >> x); let _x = false.then_some(i32::MAX + -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(-i32::MAX); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(-i32::MIN); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| -y); let _x = false.then_some(255 >> -7); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(255 << -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(1 / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(x << -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(x << 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| x + x); let _x = false.then(|| x * x); let _x = false.then(|| x - x); @@ -259,19 +299,19 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { let _x = false.then(|| 1 + x); let _x = false.then_some(x / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(x % 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| y / -1); let _x = false.then_some(1 / -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(i32::MIN / -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MIN / x as i32); let _x = false.then_some(i32::MIN / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then_some(4 / 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 1 / x); // const eval doesn't read variables, but floating point math never panics, so we can still emit a @@ -279,5 +319,5 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { let f1 = 1.0; let f2 = 2.0; let _x = false.then_some(f1 + f2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations } diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs index ea55b1d9a905..2d05ef5c2917 100644 --- a/tests/ui/unnecessary_lazy_eval.rs +++ b/tests/ui/unnecessary_lazy_eval.rs @@ -81,42 +81,69 @@ fn main() { // Should lint - Option let _ = opt.unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_str.some_field); + //~^ unnecessary_lazy_evaluations let _ = opt.unwrap_or_else(|| ext_arr[0]); let _ = opt.and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or_else(|| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = opt.or_else(|| None); + //~^ unnecessary_lazy_evaluations let _ = opt.get_or_insert_with(|| 2); + //~^ unnecessary_lazy_evaluations let _ = opt.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); + //~^ unnecessary_lazy_evaluations let _ = cond.then(|| astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = true.then(|| -> _ {}); + //~^ unnecessary_lazy_evaluations let _ = true.then(|| {}); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref let r = &1; let _ = Some(1).unwrap_or_else(|| *r); + //~^ unnecessary_lazy_evaluations let b = Box::new(1); let _ = Some(1).unwrap_or_else(|| *b); + //~^ unnecessary_lazy_evaluations // Should lint - Builtin deref through autoderef let _ = Some(1).as_ref().unwrap_or_else(|| &r); + //~^ unnecessary_lazy_evaluations let _ = Some(1).as_ref().unwrap_or_else(|| &b); + //~^ unnecessary_lazy_evaluations // Cases when unwrap is not called on a simple variable let _ = Some(10).unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = Some(10).and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _: Option = None.or_else(|| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = None.get_or_insert_with(|| 2); + //~^ unnecessary_lazy_evaluations let _: Result = None.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _: Option = None.or_else(|| None); + //~^ unnecessary_lazy_evaluations let mut deep = Deep(Some(42)); let _ = deep.0.unwrap_or_else(|| 2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.and_then(|_| ext_opt); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or_else(|| None); + //~^ unnecessary_lazy_evaluations let _ = deep.0.get_or_insert_with(|| 2); + //~^ unnecessary_lazy_evaluations let _ = deep.0.ok_or_else(|| 2); + //~^ unnecessary_lazy_evaluations // Should not lint - Option let _ = opt.unwrap_or_else(|| ext_str.return_some_field()); @@ -148,16 +175,22 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Option = None.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations let _ = deep.0.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations let _ = opt.or_else(|| Some(3)); + //~^ unnecessary_lazy_evaluations // Should lint - Result let res: Result = Err(5); let res2: Result = Err(SomeStruct { some_field: 5 }); let _ = res2.unwrap_or_else(|_| 2); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or_else(|_| astronomers_pi); + //~^ unnecessary_lazy_evaluations let _ = res2.unwrap_or_else(|_| ext_str.some_field); + //~^ unnecessary_lazy_evaluations // Should not lint - Result let _ = res.unwrap_or_else(|err| err); @@ -180,13 +213,20 @@ fn main() { // should lint, bind_instead_of_map doesn't apply let _: Result = res.and_then(|_| Err(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and_then(|_| Err(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.and_then(|_| Err(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(2)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(astronomers_pi)); + //~^ unnecessary_lazy_evaluations let _: Result = res.or_else(|_| Ok(ext_str.some_field)); + //~^ unnecessary_lazy_evaluations let _: Result = res. + //~^ unnecessary_lazy_evaluations // some lines // some lines // some lines @@ -217,39 +257,39 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { // See comments in `eager_or_lazy.rs` for the rules that this is meant to follow let _x = false.then(|| i32::MAX + 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MAX * 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MAX - 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MIN - 1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255u8 << 7); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255u8 << 8); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255u8 >> 8); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255u8 >> x); let _x = false.then(|| i32::MAX + -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| -i32::MAX); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| -i32::MIN); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| -y); let _x = false.then(|| 255 >> -7); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 255 << -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 1 / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| x << -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| x << 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| x + x); let _x = false.then(|| x * x); let _x = false.then(|| x - x); @@ -259,19 +299,19 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { let _x = false.then(|| 1 + x); let _x = false.then(|| x / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| x % 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| y / -1); let _x = false.then(|| 1 / -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MIN / -1); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| i32::MIN / x as i32); let _x = false.then(|| i32::MIN / 0); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 4 / 2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations let _x = false.then(|| 1 / x); // const eval doesn't read variables, but floating point math never panics, so we can still emit a @@ -279,5 +319,5 @@ fn panicky_arithmetic_ops(x: usize, y: isize) { let f1 = 1.0; let f2 = 2.0; let _x = false.then(|| f1 + f2); - //~^ ERROR: unnecessary closure used with `bool::then` + //~^ unnecessary_lazy_evaluations } diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 35a2144c389f..d1bb08cceadf 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -12,7 +12,7 @@ LL | let _ = opt.unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:84:13 + --> tests/ui/unnecessary_lazy_eval.rs:85:13 | LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = opt.unwrap_or(astronomers_pi); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:85:13 + --> tests/ui/unnecessary_lazy_eval.rs:87:13 | LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = opt.unwrap_or(ext_str.some_field); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:87:13 + --> tests/ui/unnecessary_lazy_eval.rs:90:13 | LL | let _ = opt.and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = opt.and(ext_opt); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:88:13 + --> tests/ui/unnecessary_lazy_eval.rs:92:13 | LL | let _ = opt.or_else(|| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = opt.or(ext_opt); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:89:13 + --> tests/ui/unnecessary_lazy_eval.rs:94:13 | LL | let _ = opt.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _ = opt.or(None); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:90:13 + --> tests/ui/unnecessary_lazy_eval.rs:96:13 | LL | let _ = opt.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _ = opt.get_or_insert(2); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:91:13 + --> tests/ui/unnecessary_lazy_eval.rs:98:13 | LL | let _ = opt.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = opt.ok_or(2); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:92:13 + --> tests/ui/unnecessary_lazy_eval.rs:100:13 | LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:93:13 + --> tests/ui/unnecessary_lazy_eval.rs:102:13 | LL | let _ = cond.then(|| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _ = cond.then_some(astronomers_pi); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:94:13 + --> tests/ui/unnecessary_lazy_eval.rs:104:13 | LL | let _ = true.then(|| -> _ {}); | ^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = true.then_some({}); | ~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:95:13 + --> tests/ui/unnecessary_lazy_eval.rs:106:13 | LL | let _ = true.then(|| {}); | ^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = true.then_some({}); | ~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:99:13 + --> tests/ui/unnecessary_lazy_eval.rs:111:13 | LL | let _ = Some(1).unwrap_or_else(|| *r); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _ = Some(1).unwrap_or(*r); | ~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:101:13 + --> tests/ui/unnecessary_lazy_eval.rs:114:13 | LL | let _ = Some(1).unwrap_or_else(|| *b); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | let _ = Some(1).unwrap_or(*b); | ~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:103:13 + --> tests/ui/unnecessary_lazy_eval.rs:117:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | let _ = Some(1).as_ref().unwrap_or(&r); | ~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:104:13 + --> tests/ui/unnecessary_lazy_eval.rs:119:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _ = Some(1).as_ref().unwrap_or(&b); | ~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:107:13 + --> tests/ui/unnecessary_lazy_eval.rs:123:13 | LL | let _ = Some(10).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -188,7 +188,7 @@ LL | let _ = Some(10).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:108:13 + --> tests/ui/unnecessary_lazy_eval.rs:125:13 | LL | let _ = Some(10).and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | let _ = Some(10).and(ext_opt); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:109:28 + --> tests/ui/unnecessary_lazy_eval.rs:127:28 | LL | let _: Option = None.or_else(|| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +210,7 @@ LL | let _: Option = None.or(ext_opt); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:110:13 + --> tests/ui/unnecessary_lazy_eval.rs:129:13 | LL | let _ = None.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -221,7 +221,7 @@ LL | let _ = None.get_or_insert(2); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:111:35 + --> tests/ui/unnecessary_lazy_eval.rs:131:35 | LL | let _: Result = None.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^ @@ -232,7 +232,7 @@ LL | let _: Result = None.ok_or(2); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:112:28 + --> tests/ui/unnecessary_lazy_eval.rs:133:28 | LL | let _: Option = None.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^^ @@ -243,7 +243,7 @@ LL | let _: Option = None.or(None); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:115:13 + --> tests/ui/unnecessary_lazy_eval.rs:137:13 | LL | let _ = deep.0.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -254,7 +254,7 @@ LL | let _ = deep.0.unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:116:13 + --> tests/ui/unnecessary_lazy_eval.rs:139:13 | LL | let _ = deep.0.and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL | let _ = deep.0.and(ext_opt); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:117:13 + --> tests/ui/unnecessary_lazy_eval.rs:141:13 | LL | let _ = deep.0.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL | let _ = deep.0.or(None); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:118:13 + --> tests/ui/unnecessary_lazy_eval.rs:143:13 | LL | let _ = deep.0.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | let _ = deep.0.get_or_insert(2); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:119:13 + --> tests/ui/unnecessary_lazy_eval.rs:145:13 | LL | let _ = deep.0.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -298,7 +298,7 @@ LL | let _ = deep.0.ok_or(2); | ~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:150:28 + --> tests/ui/unnecessary_lazy_eval.rs:177:28 | LL | let _: Option = None.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL | let _: Option = None.or(Some(3)); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:151:13 + --> tests/ui/unnecessary_lazy_eval.rs:179:13 | LL | let _ = deep.0.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -320,7 +320,7 @@ LL | let _ = deep.0.or(Some(3)); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:152:13 + --> tests/ui/unnecessary_lazy_eval.rs:181:13 | LL | let _ = opt.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -331,7 +331,7 @@ LL | let _ = opt.or(Some(3)); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:158:13 + --> tests/ui/unnecessary_lazy_eval.rs:188:13 | LL | let _ = res2.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -342,7 +342,7 @@ LL | let _ = res2.unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:159:13 + --> tests/ui/unnecessary_lazy_eval.rs:190:13 | LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -353,7 +353,7 @@ LL | let _ = res2.unwrap_or(astronomers_pi); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:160:13 + --> tests/ui/unnecessary_lazy_eval.rs:192:13 | LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | let _ = res2.unwrap_or(ext_str.some_field); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:182:35 + --> tests/ui/unnecessary_lazy_eval.rs:215:35 | LL | let _: Result = res.and_then(|_| Err(2)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL | let _: Result = res.and(Err(2)); | ~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:183:35 + --> tests/ui/unnecessary_lazy_eval.rs:217:35 | LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -386,7 +386,7 @@ LL | let _: Result = res.and(Err(astronomers_pi)); | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:184:35 + --> tests/ui/unnecessary_lazy_eval.rs:219:35 | LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _: Result = res.and(Err(ext_str.some_field)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:186:35 + --> tests/ui/unnecessary_lazy_eval.rs:222:35 | LL | let _: Result = res.or_else(|_| Ok(2)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -408,7 +408,7 @@ LL | let _: Result = res.or(Ok(2)); | ~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:187:35 + --> tests/ui/unnecessary_lazy_eval.rs:224:35 | LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -419,7 +419,7 @@ LL | let _: Result = res.or(Ok(astronomers_pi)); | ~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:188:35 + --> tests/ui/unnecessary_lazy_eval.rs:226:35 | LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -430,7 +430,7 @@ LL | let _: Result = res.or(Ok(ext_str.some_field)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:189:35 + --> tests/ui/unnecessary_lazy_eval.rs:228:35 | LL | let _: Result = res. | ___________________________________^ @@ -444,7 +444,7 @@ LL | or(Ok(ext_str.some_field)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:219:14 + --> tests/ui/unnecessary_lazy_eval.rs:259:14 | LL | let _x = false.then(|| i32::MAX + 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -455,7 +455,7 @@ LL | let _x = false.then_some(i32::MAX + 1); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:221:14 + --> tests/ui/unnecessary_lazy_eval.rs:261:14 | LL | let _x = false.then(|| i32::MAX * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -466,7 +466,7 @@ LL | let _x = false.then_some(i32::MAX * 2); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:223:14 + --> tests/ui/unnecessary_lazy_eval.rs:263:14 | LL | let _x = false.then(|| i32::MAX - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -477,7 +477,7 @@ LL | let _x = false.then_some(i32::MAX - 1); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:225:14 + --> tests/ui/unnecessary_lazy_eval.rs:265:14 | LL | let _x = false.then(|| i32::MIN - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -488,7 +488,7 @@ LL | let _x = false.then_some(i32::MIN - 1); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:227:14 + --> tests/ui/unnecessary_lazy_eval.rs:267:14 | LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -499,7 +499,7 @@ LL | let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:229:14 + --> tests/ui/unnecessary_lazy_eval.rs:269:14 | LL | let _x = false.then(|| 255u8 << 7); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -510,7 +510,7 @@ LL | let _x = false.then_some(255u8 << 7); | ~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:231:14 + --> tests/ui/unnecessary_lazy_eval.rs:271:14 | LL | let _x = false.then(|| 255u8 << 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -521,7 +521,7 @@ LL | let _x = false.then_some(255u8 << 8); | ~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:233:14 + --> tests/ui/unnecessary_lazy_eval.rs:273:14 | LL | let _x = false.then(|| 255u8 >> 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +532,7 @@ LL | let _x = false.then_some(255u8 >> 8); | ~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:236:14 + --> tests/ui/unnecessary_lazy_eval.rs:276:14 | LL | let _x = false.then(|| i32::MAX + -1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL | let _x = false.then_some(i32::MAX + -1); | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:238:14 + --> tests/ui/unnecessary_lazy_eval.rs:278:14 | LL | let _x = false.then(|| -i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -554,7 +554,7 @@ LL | let _x = false.then_some(-i32::MAX); | ~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:240:14 + --> tests/ui/unnecessary_lazy_eval.rs:280:14 | LL | let _x = false.then(|| -i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -565,7 +565,7 @@ LL | let _x = false.then_some(-i32::MIN); | ~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:243:14 + --> tests/ui/unnecessary_lazy_eval.rs:283:14 | LL | let _x = false.then(|| 255 >> -7); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -576,7 +576,7 @@ LL | let _x = false.then_some(255 >> -7); | ~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:245:14 + --> tests/ui/unnecessary_lazy_eval.rs:285:14 | LL | let _x = false.then(|| 255 << -1); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -587,7 +587,7 @@ LL | let _x = false.then_some(255 << -1); | ~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:247:14 + --> tests/ui/unnecessary_lazy_eval.rs:287:14 | LL | let _x = false.then(|| 1 / 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -598,7 +598,7 @@ LL | let _x = false.then_some(1 / 0); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:249:14 + --> tests/ui/unnecessary_lazy_eval.rs:289:14 | LL | let _x = false.then(|| x << -1); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -609,7 +609,7 @@ LL | let _x = false.then_some(x << -1); | ~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:251:14 + --> tests/ui/unnecessary_lazy_eval.rs:291:14 | LL | let _x = false.then(|| x << 2); | ^^^^^^^^^^^^^^^^^^^^^ @@ -620,7 +620,7 @@ LL | let _x = false.then_some(x << 2); | ~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:261:14 + --> tests/ui/unnecessary_lazy_eval.rs:301:14 | LL | let _x = false.then(|| x / 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -631,7 +631,7 @@ LL | let _x = false.then_some(x / 0); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:263:14 + --> tests/ui/unnecessary_lazy_eval.rs:303:14 | LL | let _x = false.then(|| x % 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -642,7 +642,7 @@ LL | let _x = false.then_some(x % 0); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:266:14 + --> tests/ui/unnecessary_lazy_eval.rs:306:14 | LL | let _x = false.then(|| 1 / -1); | ^^^^^^^^^^^^^^^^^^^^^ @@ -653,7 +653,7 @@ LL | let _x = false.then_some(1 / -1); | ~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:268:14 + --> tests/ui/unnecessary_lazy_eval.rs:308:14 | LL | let _x = false.then(|| i32::MIN / -1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -664,7 +664,7 @@ LL | let _x = false.then_some(i32::MIN / -1); | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:271:14 + --> tests/ui/unnecessary_lazy_eval.rs:311:14 | LL | let _x = false.then(|| i32::MIN / 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -675,7 +675,7 @@ LL | let _x = false.then_some(i32::MIN / 0); | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:273:14 + --> tests/ui/unnecessary_lazy_eval.rs:313:14 | LL | let _x = false.then(|| 4 / 2); | ^^^^^^^^^^^^^^^^^^^^ @@ -686,7 +686,7 @@ LL | let _x = false.then_some(4 / 2); | ~~~~~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:281:14 + --> tests/ui/unnecessary_lazy_eval.rs:321:14 | LL | let _x = false.then(|| f1 + f2); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index 412d4aaafb4a..54a2d4cee36f 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -11,15 +11,18 @@ 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` + //~^ unnecessary_lazy_evaluations + + mod e { pub struct E; } let _ = Ok(1).unwrap_or_else(|e::E| 2); - //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` + //~^ unnecessary_lazy_evaluations + let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); - //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` + //~^ unnecessary_lazy_evaluations + // Fix #6343 let arr = [(Some(1),)]; @@ -29,4 +32,5 @@ fn main() { fn issue11672() { // Return type annotation helps type inference and removing it can break code let _ = true.then(|| -> &[u8] { &[] }); + //~^ unnecessary_lazy_evaluations } diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 390235b21247..11eecdf6fa4a 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -12,7 +12,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:19:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:20:13 | LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:21:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:23:13 | LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:31:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:34:13 | LL | let _ = true.then(|| -> &[u8] { &[] }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_literal_bound.fixed b/tests/ui/unnecessary_literal_bound.fixed index 107e397466d0..5ac38a5b76ae 100644 --- a/tests/ui/unnecessary_literal_bound.fixed +++ b/tests/ui/unnecessary_literal_bound.fixed @@ -7,6 +7,7 @@ struct Struct<'a> { impl Struct<'_> { // Should warn fn returns_lit(&self) -> &'static str { + //~^ unnecessary_literal_bound "Hello" } @@ -27,6 +28,7 @@ impl Struct<'_> { // Should warn fn contionally_returns_literals_explicit(&self, cond: bool) -> &'static str { + //~^ unnecessary_literal_bound if cond { return "Literal"; } @@ -51,6 +53,7 @@ trait ReturnsStr { impl ReturnsStr for u8 { // Should warn, even though not useful without trait refinement fn trait_method(&self) -> &'static str { + //~^ unnecessary_literal_bound "Literal" } } diff --git a/tests/ui/unnecessary_literal_bound.rs b/tests/ui/unnecessary_literal_bound.rs index b371ff9d3a2e..487ca04c6ab3 100644 --- a/tests/ui/unnecessary_literal_bound.rs +++ b/tests/ui/unnecessary_literal_bound.rs @@ -7,6 +7,7 @@ struct Struct<'a> { impl Struct<'_> { // Should warn fn returns_lit(&self) -> &str { + //~^ unnecessary_literal_bound "Hello" } @@ -27,6 +28,7 @@ impl Struct<'_> { // Should warn fn contionally_returns_literals_explicit(&self, cond: bool) -> &str { + //~^ unnecessary_literal_bound if cond { return "Literal"; } @@ -51,6 +53,7 @@ trait ReturnsStr { impl ReturnsStr for u8 { // Should warn, even though not useful without trait refinement fn trait_method(&self) -> &str { + //~^ unnecessary_literal_bound "Literal" } } diff --git a/tests/ui/unnecessary_literal_bound.stderr b/tests/ui/unnecessary_literal_bound.stderr index 512b2f9a0afa..e510d86622d6 100644 --- a/tests/ui/unnecessary_literal_bound.stderr +++ b/tests/ui/unnecessary_literal_bound.stderr @@ -8,13 +8,13 @@ LL | fn returns_lit(&self) -> &str { = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_bound)]` error: returning a `str` unnecessarily tied to the lifetime of arguments - --> tests/ui/unnecessary_literal_bound.rs:29:68 + --> tests/ui/unnecessary_literal_bound.rs:30:68 | LL | fn contionally_returns_literals_explicit(&self, cond: bool) -> &str { | ^^^^ help: try: `&'static str` error: returning a `str` unnecessarily tied to the lifetime of arguments - --> tests/ui/unnecessary_literal_bound.rs:53:31 + --> tests/ui/unnecessary_literal_bound.rs:55:31 | LL | fn trait_method(&self) -> &str { | ^^^^ help: try: `&'static str` diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index b17343aa9ba5..e999dc3ade7f 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -9,73 +9,119 @@ fn unwrap_option_some() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap } #[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }` fn unwrap_option_none() { let _val = panic!(); + //~^ unnecessary_literal_unwrap let _val = panic!("this always happens"); + //~^ unnecessary_literal_unwrap let _val: String = String::default(); + //~^ unnecessary_literal_unwrap let _val: u16 = 234; + //~^ unnecessary_literal_unwrap let _val: u16 = 234; + //~^ unnecessary_literal_unwrap let _val: u16 = { 234 }; + //~^ unnecessary_literal_unwrap let _val: u16 = { 234 }; + //~^ unnecessary_literal_unwrap panic!(); + //~^ unnecessary_literal_unwrap panic!("this always happens"); + //~^ unnecessary_literal_unwrap String::default(); + //~^ unnecessary_literal_unwrap 234; + //~^ unnecessary_literal_unwrap 234; + //~^ unnecessary_literal_unwrap { 234 }; + //~^ unnecessary_literal_unwrap { 234 }; + //~^ unnecessary_literal_unwrap } fn unwrap_result_ok() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap let _val = panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_result_err() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap let _val = panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap panic!("{:?}", 1); + //~^ unnecessary_literal_unwrap panic!("{1}: {:?}", 1, "this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_methods_option() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap } fn unwrap_methods_result() { let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap let _val = 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap 1; + //~^ unnecessary_literal_unwrap } fn unwrap_from_binding() { @@ -90,12 +136,19 @@ fn unwrap_from_binding() { fn unwrap_unchecked() { let _ = 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block + //~^ unnecessary_literal_unwrap let _ = 1 + 1; + //~^ unnecessary_literal_unwrap let _ = 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { 1 + *(&1 as *const i32) }; + //~^ unnecessary_literal_unwrap let _ = 1 + 1; + //~^ unnecessary_literal_unwrap let _ = 123; + //~^ unnecessary_literal_unwrap } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index 7bd8deea4d1b..1f47d3898bbb 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -9,73 +9,119 @@ fn unwrap_option_some() { let _val = Some(1).unwrap(); + //~^ unnecessary_literal_unwrap let _val = Some(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap Some(1).unwrap(); + //~^ unnecessary_literal_unwrap Some(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap } #[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }` fn unwrap_option_none() { let _val = None::<()>.unwrap(); + //~^ unnecessary_literal_unwrap let _val = None::<()>.expect("this always happens"); + //~^ unnecessary_literal_unwrap let _val: String = None.unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or(234); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| 234); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| { 234 }); + //~^ unnecessary_literal_unwrap let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); + //~^ unnecessary_literal_unwrap None::<()>.unwrap(); + //~^ unnecessary_literal_unwrap None::<()>.expect("this always happens"); + //~^ unnecessary_literal_unwrap None::.unwrap_or_default(); + //~^ unnecessary_literal_unwrap None::.unwrap_or(234); + //~^ unnecessary_literal_unwrap None::.unwrap_or_else(|| 234); + //~^ unnecessary_literal_unwrap None::.unwrap_or_else(|| { 234 }); + //~^ unnecessary_literal_unwrap None::.unwrap_or_else(|| -> u16 { 234 }); + //~^ unnecessary_literal_unwrap } fn unwrap_result_ok() { let _val = Ok::<_, ()>(1).unwrap(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).expect_err("this always happens"); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap(); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).expect("this never happens"); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).expect_err("this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_result_err() { let _val = Err::<(), _>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).expect_err("this never happens"); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).unwrap(); + //~^ unnecessary_literal_unwrap let _val = Err::<(), _>(1).expect("this always happens"); + //~^ unnecessary_literal_unwrap Err::<(), _>(1).unwrap_err(); + //~^ unnecessary_literal_unwrap Err::<(), _>(1).expect_err("this never happens"); + //~^ unnecessary_literal_unwrap Err::<(), _>(1).unwrap(); + //~^ unnecessary_literal_unwrap Err::<(), _>(1).expect("this always happens"); + //~^ unnecessary_literal_unwrap } fn unwrap_methods_option() { let _val = Some(1).unwrap_or(2); + //~^ unnecessary_literal_unwrap let _val = Some(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val = Some(1).unwrap_or_else(|| 2); + //~^ unnecessary_literal_unwrap Some(1).unwrap_or(2); + //~^ unnecessary_literal_unwrap Some(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap Some(1).unwrap_or_else(|| 2); + //~^ unnecessary_literal_unwrap } fn unwrap_methods_result() { let _val = Ok::<_, ()>(1).unwrap_or(2); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_or(2); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_or_default(); + //~^ unnecessary_literal_unwrap Ok::<_, ()>(1).unwrap_or_else(|_| 2); + //~^ unnecessary_literal_unwrap } fn unwrap_from_binding() { @@ -90,12 +136,19 @@ fn unwrap_from_binding() { fn unwrap_unchecked() { let _ = unsafe { Some(1).unwrap_unchecked() }; + //~^ unnecessary_literal_unwrap let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block + //~^ unnecessary_literal_unwrap let _ = unsafe { Some(1).unwrap_unchecked() } + 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; + //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; + //~^ unnecessary_literal_unwrap let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; + //~^ unnecessary_literal_unwrap } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 37ee9195fce6..f4880637375a 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -13,7 +13,7 @@ LL + let _val = 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:12:16 + --> tests/ui/unnecessary_literal_unwrap.rs:13:16 | LL | let _val = Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:14:5 + --> tests/ui/unnecessary_literal_unwrap.rs:16:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:15:5 + --> tests/ui/unnecessary_literal_unwrap.rs:18:5 | LL | Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,13 +49,13 @@ LL + 1; | error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:20:16 + --> tests/ui/unnecessary_literal_unwrap.rs:24:16 | LL | let _val = None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:21:16 + --> tests/ui/unnecessary_literal_unwrap.rs:26:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,13 +66,13 @@ LL | let _val = panic!("this always happens"); | ~~~~~~~ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:22:24 + --> tests/ui/unnecessary_literal_unwrap.rs:28: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 - --> tests/ui/unnecessary_literal_unwrap.rs:23:21 + --> tests/ui/unnecessary_literal_unwrap.rs:30:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:24:21 + --> tests/ui/unnecessary_literal_unwrap.rs:32:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:25:21 + --> tests/ui/unnecessary_literal_unwrap.rs:34:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:26:21 + --> tests/ui/unnecessary_literal_unwrap.rs:36:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,13 +120,13 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:28:5 + --> tests/ui/unnecessary_literal_unwrap.rs:39:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:29:5 + --> tests/ui/unnecessary_literal_unwrap.rs:41:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,13 +137,13 @@ LL | panic!("this always happens"); | ~~~~~~~ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:30:5 + --> tests/ui/unnecessary_literal_unwrap.rs:43:5 | LL | None::.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` error: used `unwrap_or()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:31:5 + --> tests/ui/unnecessary_literal_unwrap.rs:45:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:32:5 + --> tests/ui/unnecessary_literal_unwrap.rs:47:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:33:5 + --> tests/ui/unnecessary_literal_unwrap.rs:49:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:34:5 + --> tests/ui/unnecessary_literal_unwrap.rs:51:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -191,7 +191,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:38:16 + --> tests/ui/unnecessary_literal_unwrap.rs:56:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:39:16 + --> tests/ui/unnecessary_literal_unwrap.rs:58:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -215,7 +215,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:40:16 + --> tests/ui/unnecessary_literal_unwrap.rs:60:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,7 +226,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:41:16 + --> tests/ui/unnecessary_literal_unwrap.rs:62:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:43:5 + --> tests/ui/unnecessary_literal_unwrap.rs:65:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:44:5 + --> tests/ui/unnecessary_literal_unwrap.rs:67:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:45:5 + --> tests/ui/unnecessary_literal_unwrap.rs:69:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -272,7 +272,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:46:5 + --> tests/ui/unnecessary_literal_unwrap.rs:71:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -283,7 +283,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:50:16 + --> tests/ui/unnecessary_literal_unwrap.rs:76:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -295,7 +295,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:51:16 + --> tests/ui/unnecessary_literal_unwrap.rs:78:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -307,7 +307,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:52:16 + --> tests/ui/unnecessary_literal_unwrap.rs:80:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -318,7 +318,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:53:16 + --> tests/ui/unnecessary_literal_unwrap.rs:82:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -329,7 +329,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:55:5 + --> tests/ui/unnecessary_literal_unwrap.rs:85:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -341,7 +341,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:56:5 + --> tests/ui/unnecessary_literal_unwrap.rs:87:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -353,7 +353,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:57:5 + --> tests/ui/unnecessary_literal_unwrap.rs:89:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:58:5 + --> tests/ui/unnecessary_literal_unwrap.rs:91:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:62:16 + --> tests/ui/unnecessary_literal_unwrap.rs:96:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:63:16 + --> tests/ui/unnecessary_literal_unwrap.rs:98:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -399,7 +399,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:64:16 + --> tests/ui/unnecessary_literal_unwrap.rs:100:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -411,7 +411,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:66:5 + --> tests/ui/unnecessary_literal_unwrap.rs:103:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -423,7 +423,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:67:5 + --> tests/ui/unnecessary_literal_unwrap.rs:105:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:68:5 + --> tests/ui/unnecessary_literal_unwrap.rs:107:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -447,7 +447,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:72:16 + --> tests/ui/unnecessary_literal_unwrap.rs:112:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:73:16 + --> tests/ui/unnecessary_literal_unwrap.rs:114:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:74:16 + --> tests/ui/unnecessary_literal_unwrap.rs:116:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:76:5 + --> tests/ui/unnecessary_literal_unwrap.rs:119:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -495,7 +495,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:77:5 + --> tests/ui/unnecessary_literal_unwrap.rs:121:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -507,7 +507,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:78:5 + --> tests/ui/unnecessary_literal_unwrap.rs:123:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -519,7 +519,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:92:22 + --> tests/ui/unnecessary_literal_unwrap.rs:138:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -531,7 +531,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:93:22 + --> tests/ui/unnecessary_literal_unwrap.rs:140:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +543,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:94:22 + --> tests/ui/unnecessary_literal_unwrap.rs:142:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:95:22 + --> tests/ui/unnecessary_literal_unwrap.rs:144:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:96:22 + --> tests/ui/unnecessary_literal_unwrap.rs:146:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:97:22 + --> tests/ui/unnecessary_literal_unwrap.rs:148:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -591,7 +591,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:98:22 + --> tests/ui/unnecessary_literal_unwrap.rs:150:22 | LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 61058b7988a2..4bb93fc391e6 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -5,154 +5,206 @@ fn unwrap_option_some() { let val = Some(1); let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this never happens"); - //~^ ERROR: used `expect()` on `Some` value + //~^ unnecessary_literal_unwrap + } fn unwrap_option_some_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap(); - //~^ ERROR: used `unwrap()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); - //~^ ERROR: used `expect()` on `Some` value + //~^ unnecessary_literal_unwrap + let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this never happens"); - //~^ ERROR: used `expect()` on `Some` value + //~^ unnecessary_literal_unwrap + } fn unwrap_option_none() { let val = None::<()>; let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `None` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this always happens"); - //~^ ERROR: used `expect()` on `None` value + //~^ unnecessary_literal_unwrap + let _val3: u8 = None.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `None` value + //~^ unnecessary_literal_unwrap + None::<()>.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `None` value + //~^ unnecessary_literal_unwrap + } fn unwrap_result_ok() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this never happens"); - //~^ ERROR: used `expect()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect_err("this always happens"); - //~^ ERROR: used `expect_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + } fn unwrap_result_ok_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); - //~^ ERROR: used `unwrap()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); - //~^ ERROR: used `expect()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); - //~^ ERROR: used `expect_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this never happens"); - //~^ ERROR: used `expect()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect_err("this always happens"); - //~^ ERROR: used `expect_err()` on `Ok` value + //~^ unnecessary_literal_unwrap + } fn unwrap_result_err() { let val = Err::<(), _>(1); let _val2 = val.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect_err("this never happens"); - //~^ ERROR: used `expect_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this always happens"); - //~^ ERROR: used `expect()` on `Err` value + //~^ unnecessary_literal_unwrap + } fn unwrap_result_err_context() { let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); - //~^ ERROR: used `expect_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); - //~^ ERROR: used `unwrap()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); - //~^ ERROR: used `expect()` on `Err` value + //~^ unnecessary_literal_unwrap + let val = Err::<(), usize>([1, 2, 3].iter().sum()); let _val2 = val.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect_err("this never happens"); - //~^ ERROR: used `expect_err()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap(); - //~^ ERROR: used `unwrap()` on `Err` value + //~^ unnecessary_literal_unwrap + let _val2 = val.expect("this always happens"); - //~^ ERROR: used `expect()` on `Err` value + //~^ unnecessary_literal_unwrap + } fn unwrap_methods_option() { let val = Some(1); let _val2 = val.unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_else(|| 2); - //~^ ERROR: used `unwrap_or_else()` on `Some` value + //~^ unnecessary_literal_unwrap + } fn unwrap_methods_option_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); - //~^ ERROR: used `unwrap_or_else()` on `Some` value + //~^ unnecessary_literal_unwrap + let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Some` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_else(|| 2); - //~^ ERROR: used `unwrap_or_else()` on `Some` value + //~^ unnecessary_literal_unwrap + } fn unwrap_methods_result() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_else(|_| 2); - //~^ ERROR: used `unwrap_or_else()` on `Ok` value + //~^ unnecessary_literal_unwrap + } fn unwrap_methods_result_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); - //~^ ERROR: used `unwrap_or_else()` on `Ok` value + //~^ unnecessary_literal_unwrap + let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); - //~^ ERROR: used `unwrap_or()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_default(); - //~^ ERROR: used `unwrap_or_default()` on `Ok` value + //~^ unnecessary_literal_unwrap + let _val2 = val.unwrap_or_else(|_| 2); - //~^ ERROR: used `unwrap_or_else()` on `Ok` value + //~^ unnecessary_literal_unwrap + } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index b7dd7ae729fd..b579bb74ef74 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -13,7 +13,7 @@ LL | let val = Some(1); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:9:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:10:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,589 +25,589 @@ LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:14:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:14:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:20:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:24:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:23:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:27:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:23:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:28:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:27:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:33:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:37:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:27:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:33:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:32:21 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:40: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 - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:5 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:43:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:40:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:50:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:39:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:42:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:53:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:39:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:56:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:39:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:46:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:59:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:39:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:51:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:51:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:53:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:53:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:55:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:55:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:57:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:74:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:57:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:74:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:61:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:82:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:85:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:67:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:95:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:75:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:98:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:77:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:101:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:104:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:84:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:84:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:116:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:116:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:90:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:90:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:124:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:93:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:96:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:127:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:93:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:98:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:130:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:93:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:100:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:93:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:106:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:140:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:143:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:152:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:152:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:117:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:155:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:117:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:155:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:158:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:158:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:163:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:122:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:125:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:122:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:127:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:169:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:122:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:176:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:132:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:135:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:179:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:132:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:137:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:182:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:132:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:142:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:188:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:142:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:188:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:191:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:191:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:194:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:194:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:199:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:152:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:202:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:205:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_map_on_constructor.fixed b/tests/ui/unnecessary_map_on_constructor.fixed index d0ba7ed749e4..4452fda38c40 100644 --- a/tests/ui/unnecessary_map_on_constructor.fixed +++ b/tests/ui/unnecessary_map_on_constructor.fixed @@ -30,14 +30,22 @@ fn main() { let c: SimpleResult = Err(err); let a = Some(fun(x)); + //~^ unnecessary_map_on_constructor let b: SimpleResult = Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: SimpleResult = Err(notfun(err)); + //~^ unnecessary_map_on_constructor let a = Option::Some(fun(x)); + //~^ unnecessary_map_on_constructor let b: SimpleResult = SimpleResult::Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: SimpleResult = SimpleResult::Err(notfun(err)); + //~^ unnecessary_map_on_constructor let b: std::result::Result = Ok(fun(x)); + //~^ unnecessary_map_on_constructor let c: std::result::Result = Err(notfun(err)); + //~^ unnecessary_map_on_constructor let a = Some(fun(x)); let b: SimpleResult = Ok(fun(x)); diff --git a/tests/ui/unnecessary_map_on_constructor.rs b/tests/ui/unnecessary_map_on_constructor.rs index e89e7aad4c40..0cd41f2b363a 100644 --- a/tests/ui/unnecessary_map_on_constructor.rs +++ b/tests/ui/unnecessary_map_on_constructor.rs @@ -30,14 +30,22 @@ fn main() { let c: SimpleResult = Err(err); let a = Some(x).map(fun); + //~^ unnecessary_map_on_constructor let b: SimpleResult = Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: SimpleResult = Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let a = Option::Some(x).map(fun); + //~^ unnecessary_map_on_constructor let b: SimpleResult = SimpleResult::Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let b: std::result::Result = Ok(x).map(fun); + //~^ unnecessary_map_on_constructor let c: std::result::Result = Err(err).map_err(notfun); + //~^ unnecessary_map_on_constructor let a = Some(fun(x)); let b: SimpleResult = Ok(fun(x)); diff --git a/tests/ui/unnecessary_map_on_constructor.stderr b/tests/ui/unnecessary_map_on_constructor.stderr index ecbf65244154..f29bfec60f72 100644 --- a/tests/ui/unnecessary_map_on_constructor.stderr +++ b/tests/ui/unnecessary_map_on_constructor.stderr @@ -8,43 +8,43 @@ LL | let a = Some(x).map(fun); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_on_constructor)]` error: unnecessary map on constructor Ok(_) - --> tests/ui/unnecessary_map_on_constructor.rs:33:27 + --> tests/ui/unnecessary_map_on_constructor.rs:34:27 | LL | let b: SimpleResult = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary map_err on constructor Err(_) - --> tests/ui/unnecessary_map_on_constructor.rs:34:27 + --> tests/ui/unnecessary_map_on_constructor.rs:36:27 | LL | let c: SimpleResult = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` error: unnecessary map on constructor Option::Some(_) - --> tests/ui/unnecessary_map_on_constructor.rs:36:13 + --> tests/ui/unnecessary_map_on_constructor.rs:39:13 | LL | let a = Option::Some(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option::Some(fun(x))` error: unnecessary map on constructor SimpleResult::Ok(_) - --> tests/ui/unnecessary_map_on_constructor.rs:37:27 + --> tests/ui/unnecessary_map_on_constructor.rs:41:27 | LL | let b: SimpleResult = SimpleResult::Ok(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Ok(fun(x))` error: unnecessary map_err on constructor SimpleResult::Err(_) - --> tests/ui/unnecessary_map_on_constructor.rs:38:27 + --> tests/ui/unnecessary_map_on_constructor.rs:43:27 | LL | let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Err(notfun(err))` error: unnecessary map on constructor Ok(_) - --> tests/ui/unnecessary_map_on_constructor.rs:39:52 + --> tests/ui/unnecessary_map_on_constructor.rs:45:52 | LL | let b: std::result::Result = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary map_err on constructor Err(_) - --> tests/ui/unnecessary_map_on_constructor.rs:40:52 + --> tests/ui/unnecessary_map_on_constructor.rs:47:52 | LL | let c: std::result::Result = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` diff --git a/tests/ui/unnecessary_map_or.fixed b/tests/ui/unnecessary_map_or.fixed index 27532373a7b9..f51da49edabb 100644 --- a/tests/ui/unnecessary_map_or.fixed +++ b/tests/ui/unnecessary_map_or.fixed @@ -11,24 +11,39 @@ extern crate proc_macros; fn main() { // should trigger let _ = Some(5) == Some(5); + //~^ unnecessary_map_or let _ = Some(5) != Some(5); + //~^ unnecessary_map_or let _ = Some(5) == Some(5); let _ = Some(5).is_some_and(|n| { + //~^ unnecessary_map_or let _ = n; 6 >= 5 }); let _ = Some(vec![5]).is_some_and(|n| n == [5]); + //~^ unnecessary_map_or let _ = Some(vec![1]).is_some_and(|n| vec![2] == n); + //~^ unnecessary_map_or let _ = Some(5).is_some_and(|n| n == n); + //~^ unnecessary_map_or let _ = Some(5).is_some_and(|n| n == if 2 > 1 { n } else { 0 }); + //~^ unnecessary_map_or let _ = Ok::, i32>(vec![5]).is_ok_and(|n| n == [5]); + //~^ unnecessary_map_or let _ = Ok::(5) == Ok(5); + //~^ unnecessary_map_or let _ = (Some(5) == Some(5)).then(|| 1); + //~^ unnecessary_map_or let _ = Some(5).is_none_or(|n| n == 5); + //~^ unnecessary_map_or let _ = Some(5).is_none_or(|n| 5 == n); + //~^ unnecessary_map_or let _ = !(Some(5) == Some(5)); + //~^ unnecessary_map_or let _ = (Some(5) == Some(5)) || false; + //~^ unnecessary_map_or let _ = (Some(5) == Some(5)) as usize; + //~^ unnecessary_map_or macro_rules! x { () => { @@ -53,18 +68,23 @@ fn main() { struct S; let r: Result = Ok(3); let _ = r.is_ok_and(|x| x == 7); + //~^ unnecessary_map_or // lint constructs that are not comparaisons as well let func = |_x| true; let r: Result = Ok(3); let _ = r.is_ok_and(func); + //~^ unnecessary_map_or let _ = Some(5).is_some_and(func); + //~^ unnecessary_map_or let _ = Some(5).is_none_or(func); + //~^ unnecessary_map_or #[derive(PartialEq)] struct S2; let r: Result = Ok(4); let _ = r == Ok(8); + //~^ unnecessary_map_or // do not lint `Result::map_or(true, …)` let r: Result = Ok(4); @@ -85,6 +105,8 @@ fn msrv_1_81() { fn with_refs(o: &mut Option) -> bool { o.is_none_or(|n| n > 5) || (o as &Option).is_none_or(|n| n < 5) + //~^ unnecessary_map_or + //~| unnecessary_map_or } struct S; @@ -98,6 +120,7 @@ impl std::ops::Deref for S { fn with_deref(o: &S) -> bool { o.is_none_or(|n| n > 5) + //~^ unnecessary_map_or } fn issue14201(a: Option, b: Option, s: &String) -> bool { diff --git a/tests/ui/unnecessary_map_or.rs b/tests/ui/unnecessary_map_or.rs index 6496defe1300..a1ae97af2b9f 100644 --- a/tests/ui/unnecessary_map_or.rs +++ b/tests/ui/unnecessary_map_or.rs @@ -11,27 +11,43 @@ extern crate proc_macros; fn main() { // should trigger let _ = Some(5).map_or(false, |n| n == 5); + //~^ unnecessary_map_or let _ = Some(5).map_or(true, |n| n != 5); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| { + //~^ unnecessary_map_or let _ = 1; n == 5 }); let _ = Some(5).map_or(false, |n| { + //~^ unnecessary_map_or let _ = n; 6 >= 5 }); let _ = Some(vec![5]).map_or(false, |n| n == [5]); + //~^ unnecessary_map_or let _ = Some(vec![1]).map_or(false, |n| vec![2] == n); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| n == n); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| n == if 2 > 1 { n } else { 0 }); + //~^ unnecessary_map_or let _ = Ok::, i32>(vec![5]).map_or(false, |n| n == [5]); + //~^ unnecessary_map_or let _ = Ok::(5).map_or(false, |n| n == 5); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); + //~^ unnecessary_map_or let _ = Some(5).map_or(true, |n| n == 5); + //~^ unnecessary_map_or let _ = Some(5).map_or(true, |n| 5 == n); + //~^ unnecessary_map_or let _ = !Some(5).map_or(false, |n| n == 5); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| n == 5) || false; + //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| n == 5) as usize; + //~^ unnecessary_map_or macro_rules! x { () => { @@ -56,18 +72,23 @@ fn main() { struct S; let r: Result = Ok(3); let _ = r.map_or(false, |x| x == 7); + //~^ unnecessary_map_or // lint constructs that are not comparaisons as well let func = |_x| true; let r: Result = Ok(3); let _ = r.map_or(false, func); + //~^ unnecessary_map_or let _ = Some(5).map_or(false, func); + //~^ unnecessary_map_or let _ = Some(5).map_or(true, func); + //~^ unnecessary_map_or #[derive(PartialEq)] struct S2; let r: Result = Ok(4); let _ = r.map_or(false, |x| x == 8); + //~^ unnecessary_map_or // do not lint `Result::map_or(true, …)` let r: Result = Ok(4); @@ -88,6 +109,8 @@ fn msrv_1_81() { fn with_refs(o: &mut Option) -> bool { o.map_or(true, |n| n > 5) || (o as &Option).map_or(true, |n| n < 5) + //~^ unnecessary_map_or + //~| unnecessary_map_or } struct S; @@ -101,6 +124,7 @@ impl std::ops::Deref for S { fn with_deref(o: &S) -> bool { o.map_or(true, |n| n > 5) + //~^ unnecessary_map_or } fn issue14201(a: Option, b: Option, s: &String) -> bool { diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index f672f55dd04d..57a76c21c70d 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -12,7 +12,7 @@ LL | let _ = Some(5) == Some(5); | ~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:14:13 + --> tests/ui/unnecessary_map_or.rs:15:13 | LL | let _ = Some(5).map_or(true, |n| n != 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,10 +23,11 @@ LL | let _ = Some(5) != Some(5); | ~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:15:13 + --> tests/ui/unnecessary_map_or.rs:17:13 | LL | let _ = Some(5).map_or(false, |n| { | _____________^ +LL | | LL | | let _ = 1; LL | | n == 5 LL | | }); @@ -38,10 +39,11 @@ LL | let _ = Some(5) == Some(5); | ~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:19:13 + --> tests/ui/unnecessary_map_or.rs:22:13 | LL | let _ = Some(5).map_or(false, |n| { | _____________^ +LL | | LL | | let _ = n; LL | | 6 >= 5 LL | | }); @@ -54,7 +56,7 @@ LL + let _ = Some(5).is_some_and(|n| { | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:23:13 + --> tests/ui/unnecessary_map_or.rs:27:13 | LL | let _ = Some(vec![5]).map_or(false, |n| n == [5]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +68,7 @@ LL + let _ = Some(vec![5]).is_some_and(|n| n == [5]); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:24:13 + --> tests/ui/unnecessary_map_or.rs:29:13 | LL | let _ = Some(vec![1]).map_or(false, |n| vec![2] == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +80,7 @@ LL + let _ = Some(vec![1]).is_some_and(|n| vec![2] == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:25:13 + --> tests/ui/unnecessary_map_or.rs:31:13 | LL | let _ = Some(5).map_or(false, |n| n == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +92,7 @@ LL + let _ = Some(5).is_some_and(|n| n == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:26:13 + --> tests/ui/unnecessary_map_or.rs:33:13 | LL | let _ = Some(5).map_or(false, |n| n == if 2 > 1 { n } else { 0 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -102,7 +104,7 @@ LL + let _ = Some(5).is_some_and(|n| n == if 2 > 1 { n } else { 0 }); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:27:13 + --> tests/ui/unnecessary_map_or.rs:35:13 | LL | let _ = Ok::, i32>(vec![5]).map_or(false, |n| n == [5]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +116,7 @@ LL + let _ = Ok::, i32>(vec![5]).is_ok_and(|n| n == [5]); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:28:13 + --> tests/ui/unnecessary_map_or.rs:37:13 | LL | let _ = Ok::(5).map_or(false, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -125,7 +127,7 @@ LL | let _ = Ok::(5) == Ok(5); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:29:13 + --> tests/ui/unnecessary_map_or.rs:39:13 | LL | let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +138,7 @@ LL | let _ = (Some(5) == Some(5)).then(|| 1); | ~~~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:30:13 + --> tests/ui/unnecessary_map_or.rs:41:13 | LL | let _ = Some(5).map_or(true, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,7 +150,7 @@ LL + let _ = Some(5).is_none_or(|n| n == 5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:31:13 + --> tests/ui/unnecessary_map_or.rs:43:13 | LL | let _ = Some(5).map_or(true, |n| 5 == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +162,7 @@ LL + let _ = Some(5).is_none_or(|n| 5 == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:32:14 + --> tests/ui/unnecessary_map_or.rs:45:14 | LL | let _ = !Some(5).map_or(false, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -171,7 +173,7 @@ LL | let _ = !(Some(5) == Some(5)); | ~~~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:33:13 + --> tests/ui/unnecessary_map_or.rs:47:13 | LL | let _ = Some(5).map_or(false, |n| n == 5) || false; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -182,7 +184,7 @@ LL | let _ = (Some(5) == Some(5)) || false; | ~~~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:34:13 + --> tests/ui/unnecessary_map_or.rs:49:13 | LL | let _ = Some(5).map_or(false, |n| n == 5) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +195,7 @@ LL | let _ = (Some(5) == Some(5)) as usize; | ~~~~~~~~~~~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:58:13 + --> tests/ui/unnecessary_map_or.rs:74:13 | LL | let _ = r.map_or(false, |x| x == 7); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +207,7 @@ LL + let _ = r.is_ok_and(|x| x == 7); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:63:13 + --> tests/ui/unnecessary_map_or.rs:80:13 | LL | let _ = r.map_or(false, func); | ^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +219,7 @@ LL + let _ = r.is_ok_and(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:64:13 + --> tests/ui/unnecessary_map_or.rs:82:13 | LL | let _ = Some(5).map_or(false, func); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +231,7 @@ LL + let _ = Some(5).is_some_and(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:65:13 + --> tests/ui/unnecessary_map_or.rs:84:13 | LL | let _ = Some(5).map_or(true, func); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +243,7 @@ LL + let _ = Some(5).is_none_or(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:70:13 + --> tests/ui/unnecessary_map_or.rs:90:13 | LL | let _ = r.map_or(false, |x| x == 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -252,7 +254,7 @@ LL | let _ = r == Ok(8); | ~~~~~~~~~~ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:90:5 + --> tests/ui/unnecessary_map_or.rs:111:5 | LL | o.map_or(true, |n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -264,7 +266,7 @@ LL + o.is_none_or(|n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:90:34 + --> tests/ui/unnecessary_map_or.rs:111:34 | LL | o.map_or(true, |n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +278,7 @@ LL + o.map_or(true, |n| n > 5) || (o as &Option).is_none_or(|n| n < 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:103:5 + --> tests/ui/unnecessary_map_or.rs:126:5 | LL | o.map_or(true, |n| n > 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_min_or_max.fixed b/tests/ui/unnecessary_min_or_max.fixed index 1f3e131516ce..2650cae5baf4 100644 --- a/tests/ui/unnecessary_min_or_max.fixed +++ b/tests/ui/unnecessary_min_or_max.fixed @@ -11,30 +11,47 @@ const X: i32 = 1; fn main() { // Both are Literals let _ = (-6_i32); + //~^ unnecessary_min_or_max let _ = 9; + //~^ unnecessary_min_or_max let _ = 6; + //~^ unnecessary_min_or_max let _ = 9_u32; + //~^ unnecessary_min_or_max let _ = 6; + //~^ unnecessary_min_or_max let _ = 7_u8; + //~^ unnecessary_min_or_max let x: u32 = 42; // unsigned with zero let _ = 0; + //~^ unnecessary_min_or_max let _ = x; + //~^ unnecessary_min_or_max let _ = 0_u32; + //~^ unnecessary_min_or_max let _ = x; + //~^ unnecessary_min_or_max let x: i32 = 42; // signed MIN let _ = i32::MIN; + //~^ unnecessary_min_or_max let _ = x; + //~^ unnecessary_min_or_max let _ = i32::MIN; + //~^ unnecessary_min_or_max let _ = x; + //~^ unnecessary_min_or_max let _ = i32::MIN - 0; + //~^ unnecessary_min_or_max let _ = x; + //~^ unnecessary_min_or_max let _ = i32::MIN - 0; + //~^ unnecessary_min_or_max // The below cases shouldn't be lint let mut min = u32::MAX; diff --git a/tests/ui/unnecessary_min_or_max.rs b/tests/ui/unnecessary_min_or_max.rs index 58356b9d49e7..2f3c480b3d15 100644 --- a/tests/ui/unnecessary_min_or_max.rs +++ b/tests/ui/unnecessary_min_or_max.rs @@ -11,30 +11,47 @@ const X: i32 = 1; fn main() { // Both are Literals let _ = (-6_i32).min(9); + //~^ unnecessary_min_or_max let _ = (-6_i32).max(9); + //~^ unnecessary_min_or_max let _ = 9_u32.min(6); + //~^ unnecessary_min_or_max let _ = 9_u32.max(6); + //~^ unnecessary_min_or_max let _ = 6.min(7_u8); + //~^ unnecessary_min_or_max let _ = 6.max(7_u8); + //~^ unnecessary_min_or_max let x: u32 = 42; // unsigned with zero let _ = 0.min(x); + //~^ unnecessary_min_or_max let _ = 0.max(x); + //~^ unnecessary_min_or_max let _ = x.min(0_u32); + //~^ unnecessary_min_or_max let _ = x.max(0_u32); + //~^ unnecessary_min_or_max let x: i32 = 42; // signed MIN let _ = i32::MIN.min(x); + //~^ unnecessary_min_or_max let _ = i32::MIN.max(x); + //~^ unnecessary_min_or_max let _ = x.min(i32::MIN); + //~^ unnecessary_min_or_max let _ = x.max(i32::MIN); + //~^ unnecessary_min_or_max let _ = x.min(i32::MIN - 0); + //~^ unnecessary_min_or_max let _ = x.max(i32::MIN); + //~^ unnecessary_min_or_max let _ = x.min(i32::MIN - 0); + //~^ unnecessary_min_or_max // The below cases shouldn't be lint let mut min = u32::MAX; diff --git a/tests/ui/unnecessary_min_or_max.stderr b/tests/ui/unnecessary_min_or_max.stderr index f5cd31fbaf24..dfe6910dfa5c 100644 --- a/tests/ui/unnecessary_min_or_max.stderr +++ b/tests/ui/unnecessary_min_or_max.stderr @@ -8,97 +8,97 @@ LL | let _ = (-6_i32).min(9); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_min_or_max)]` error: `(-6_i32)` is never greater than `9` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:14:13 + --> tests/ui/unnecessary_min_or_max.rs:15:13 | LL | let _ = (-6_i32).max(9); | ^^^^^^^^^^^^^^^ help: try: `9` error: `9_u32` is never smaller than `6` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:15:13 + --> tests/ui/unnecessary_min_or_max.rs:17:13 | LL | let _ = 9_u32.min(6); | ^^^^^^^^^^^^ help: try: `6` error: `9_u32` is never smaller than `6` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:16:13 + --> tests/ui/unnecessary_min_or_max.rs:19:13 | LL | let _ = 9_u32.max(6); | ^^^^^^^^^^^^ help: try: `9_u32` error: `6` is never greater than `7_u8` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:17:13 + --> tests/ui/unnecessary_min_or_max.rs:21:13 | LL | let _ = 6.min(7_u8); | ^^^^^^^^^^^ help: try: `6` error: `6` is never greater than `7_u8` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:18:13 + --> tests/ui/unnecessary_min_or_max.rs:23:13 | LL | let _ = 6.max(7_u8); | ^^^^^^^^^^^ help: try: `7_u8` error: `0` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:22:13 + --> tests/ui/unnecessary_min_or_max.rs:28:13 | LL | let _ = 0.min(x); | ^^^^^^^^ help: try: `0` error: `0` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:23:13 + --> tests/ui/unnecessary_min_or_max.rs:30:13 | LL | let _ = 0.max(x); | ^^^^^^^^ help: try: `x` error: `x` is never smaller than `0_u32` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:24:13 + --> tests/ui/unnecessary_min_or_max.rs:32:13 | LL | let _ = x.min(0_u32); | ^^^^^^^^^^^^ help: try: `0_u32` error: `x` is never smaller than `0_u32` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:25:13 + --> tests/ui/unnecessary_min_or_max.rs:34:13 | LL | let _ = x.max(0_u32); | ^^^^^^^^^^^^ help: try: `x` error: `i32::MIN` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:29:13 + --> tests/ui/unnecessary_min_or_max.rs:39:13 | LL | let _ = i32::MIN.min(x); | ^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `i32::MIN` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:30:13 + --> tests/ui/unnecessary_min_or_max.rs:41:13 | LL | let _ = i32::MIN.max(x); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:31:13 + --> tests/ui/unnecessary_min_or_max.rs:43:13 | LL | let _ = x.min(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:32:13 + --> tests/ui/unnecessary_min_or_max.rs:45:13 | LL | let _ = x.max(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN - 0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:34:13 + --> tests/ui/unnecessary_min_or_max.rs:48:13 | LL | let _ = x.min(i32::MIN - 0); | ^^^^^^^^^^^^^^^^^^^ help: try: `i32::MIN - 0` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:35:13 + --> tests/ui/unnecessary_min_or_max.rs:50:13 | LL | let _ = x.max(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN - 0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:37:13 + --> tests/ui/unnecessary_min_or_max.rs:53:13 | LL | let _ = x.min(i32::MIN - 0); | ^^^^^^^^^^^^^^^^^^^ help: try: `i32::MIN - 0` diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index 006f123cbcdf..ec3e64e15b85 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -68,22 +68,39 @@ where fn main() { get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation get_struct(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation 5;get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation 5;6;get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation 5;get_number(); + //~^ unnecessary_operation 42;get_number(); + //~^ unnecessary_operation assert!([42, 55].len() > get_usize()); + //~^ unnecessary_operation 42;get_number(); + //~^ unnecessary_operation get_number(); + //~^ unnecessary_operation assert!([42; 55].len() > get_usize()); + //~^ unnecessary_operation get_number(); String::from("blah"); @@ -124,5 +141,6 @@ const _: () = { const fn foo() { assert!([42, 55].len() > get_usize()); - //~^ ERROR: unnecessary operation + //~^ unnecessary_operation + } diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index b4067c740741..3f903cd04ef8 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -68,26 +68,45 @@ where fn main() { Tuple(get_number()); + //~^ unnecessary_operation Struct { field: get_number() }; + //~^ unnecessary_operation Struct { ..get_struct() }; + //~^ unnecessary_operation Enum::Tuple(get_number()); + //~^ unnecessary_operation Enum::Struct { field: get_number() }; + //~^ unnecessary_operation 5 + get_number(); + //~^ unnecessary_operation *&get_number(); + //~^ unnecessary_operation &get_number(); + //~^ unnecessary_operation (5, 6, get_number()); + //~^ unnecessary_operation get_number()..; + //~^ unnecessary_operation ..get_number(); + //~^ unnecessary_operation 5..get_number(); + //~^ unnecessary_operation [42, get_number()]; + //~^ unnecessary_operation [42, 55][get_usize()]; + //~^ unnecessary_operation (42, get_number()).1; + //~^ unnecessary_operation [get_number(); 55]; + //~^ unnecessary_operation [42; 55][get_usize()]; + //~^ unnecessary_operation { + //~^ unnecessary_operation get_number() }; FooString { + //~^ unnecessary_operation s: String::from("blah"), }; @@ -128,5 +147,6 @@ const _: () = { const fn foo() { [42, 55][get_usize()]; - //~^ ERROR: unnecessary operation + //~^ unnecessary_operation + } diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index 036a9a44bbad..eb98af09e7a3 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -8,119 +8,121 @@ LL | Tuple(get_number()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_operation)]` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:71:5 + --> tests/ui/unnecessary_operation.rs:72:5 | LL | Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:72:5 + --> tests/ui/unnecessary_operation.rs:74:5 | LL | Struct { ..get_struct() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:73:5 + --> tests/ui/unnecessary_operation.rs:76:5 | LL | Enum::Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:74:5 + --> tests/ui/unnecessary_operation.rs:78:5 | LL | Enum::Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:75:5 + --> tests/ui/unnecessary_operation.rs:80:5 | LL | 5 + get_number(); | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:76:5 + --> tests/ui/unnecessary_operation.rs:82:5 | LL | *&get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:77:5 + --> tests/ui/unnecessary_operation.rs:84:5 | LL | &get_number(); | ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:78:5 + --> tests/ui/unnecessary_operation.rs:86:5 | LL | (5, 6, get_number()); | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;6;get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:79:5 + --> tests/ui/unnecessary_operation.rs:88:5 | LL | get_number()..; | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:80:5 + --> tests/ui/unnecessary_operation.rs:90:5 | LL | ..get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:81:5 + --> tests/ui/unnecessary_operation.rs:92:5 | LL | 5..get_number(); | ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:82:5 + --> tests/ui/unnecessary_operation.rs:94:5 | LL | [42, get_number()]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:83:5 + --> tests/ui/unnecessary_operation.rs:96:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:84:5 + --> tests/ui/unnecessary_operation.rs:98:5 | LL | (42, get_number()).1; | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:85:5 + --> tests/ui/unnecessary_operation.rs:100:5 | LL | [get_number(); 55]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:86:5 + --> tests/ui/unnecessary_operation.rs:102:5 | LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:87:5 + --> tests/ui/unnecessary_operation.rs:104:5 | LL | / { +LL | | LL | | get_number() LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:90:5 + --> tests/ui/unnecessary_operation.rs:108:5 | LL | / FooString { +LL | | LL | | s: String::from("blah"), LL | | }; | |______^ help: statement can be reduced to: `String::from("blah");` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:130:5 + --> tests/ui/unnecessary_operation.rs:149:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` diff --git a/tests/ui/unnecessary_owned_empty_strings.fixed b/tests/ui/unnecessary_owned_empty_strings.fixed index 75cd63db8a1a..dc0e495be30f 100644 --- a/tests/ui/unnecessary_owned_empty_strings.fixed +++ b/tests/ui/unnecessary_owned_empty_strings.fixed @@ -8,10 +8,12 @@ fn ref_string_argument(_value: &String) {} fn main() { // should be linted ref_str_argument(""); + //~^ unnecessary_owned_empty_strings // should be linted #[allow(clippy::manual_string_new)] ref_str_argument(""); + //~^ unnecessary_owned_empty_strings // should not be linted ref_str_argument(""); diff --git a/tests/ui/unnecessary_owned_empty_strings.rs b/tests/ui/unnecessary_owned_empty_strings.rs index 2edc0bd86d38..e2c5de447444 100644 --- a/tests/ui/unnecessary_owned_empty_strings.rs +++ b/tests/ui/unnecessary_owned_empty_strings.rs @@ -8,10 +8,12 @@ fn ref_string_argument(_value: &String) {} fn main() { // should be linted ref_str_argument(&String::new()); + //~^ unnecessary_owned_empty_strings // should be linted #[allow(clippy::manual_string_new)] ref_str_argument(&String::from("")); + //~^ unnecessary_owned_empty_strings // should not be linted ref_str_argument(""); diff --git a/tests/ui/unnecessary_owned_empty_strings.stderr b/tests/ui/unnecessary_owned_empty_strings.stderr index 1820ea4ef5d8..8bcf3ee88765 100644 --- a/tests/ui/unnecessary_owned_empty_strings.stderr +++ b/tests/ui/unnecessary_owned_empty_strings.stderr @@ -8,7 +8,7 @@ LL | ref_str_argument(&String::new()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_owned_empty_strings)]` error: usage of `&String::from("")` for a function expecting a `&str` argument - --> tests/ui/unnecessary_owned_empty_strings.rs:14:22 + --> tests/ui/unnecessary_owned_empty_strings.rs:15:22 | LL | ref_str_argument(&String::from("")); | ^^^^^^^^^^^^^^^^^ help: try: `""` diff --git a/tests/ui/unnecessary_result_map_or_else.fixed b/tests/ui/unnecessary_result_map_or_else.fixed index 224e0b52d75d..784a42a04ba8 100644 --- a/tests/ui/unnecessary_result_map_or_else.fixed +++ b/tests/ui/unnecessary_result_map_or_else.fixed @@ -3,16 +3,19 @@ fn main() { let x: Result<(), ()> = Ok(()); - x.unwrap_or_else(|err| err); //~ ERROR: unused "map closure" when calling +x.unwrap_or_else(|err| err); +//~^ unnecessary_result_map_or_else // Type ascribtion. let x: Result<(), ()> = Ok(()); - x.unwrap_or_else(|err: ()| err); //~ ERROR: unused "map closure" when calling +x.unwrap_or_else(|err: ()| err); +//~^ unnecessary_result_map_or_else // Auto-deref. let y = String::new(); let x: Result<&String, &String> = Ok(&y); - let y: &str = x.unwrap_or_else(|err| err); //~ ERROR: unused "map closure" when calling +let y: &str = x.unwrap_or_else(|err| err); +//~^ unnecessary_result_map_or_else // Temporary variable. let x: Result<(), ()> = Ok(()); diff --git a/tests/ui/unnecessary_result_map_or_else.rs b/tests/ui/unnecessary_result_map_or_else.rs index 4fe950a4cfa6..39b15f6d26d0 100644 --- a/tests/ui/unnecessary_result_map_or_else.rs +++ b/tests/ui/unnecessary_result_map_or_else.rs @@ -3,21 +3,25 @@ fn main() { let x: Result<(), ()> = Ok(()); - x.map_or_else(|err| err, |n| n); //~ ERROR: unused "map closure" when calling +x.map_or_else(|err| err, |n| n); +//~^ unnecessary_result_map_or_else // Type ascribtion. let x: Result<(), ()> = Ok(()); - x.map_or_else(|err: ()| err, |n: ()| n); //~ ERROR: unused "map closure" when calling +x.map_or_else(|err: ()| err, |n: ()| n); +//~^ unnecessary_result_map_or_else // Auto-deref. let y = String::new(); let x: Result<&String, &String> = Ok(&y); - let y: &str = x.map_or_else(|err| err, |n| n); //~ ERROR: unused "map closure" when calling +let y: &str = x.map_or_else(|err| err, |n| n); +//~^ unnecessary_result_map_or_else // Temporary variable. let x: Result<(), ()> = Ok(()); x.map_or_else( - //~^ ERROR: unused "map closure" when calling + //~^ unnecessary_result_map_or_else + |err| err, |n| { let tmp = n; diff --git a/tests/ui/unnecessary_result_map_or_else.stderr b/tests/ui/unnecessary_result_map_or_else.stderr index e3a6dbf8ecd8..6334fe5eca68 100644 --- a/tests/ui/unnecessary_result_map_or_else.stderr +++ b/tests/ui/unnecessary_result_map_or_else.stderr @@ -1,31 +1,31 @@ error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:6:5 + --> tests/ui/unnecessary_result_map_or_else.rs:6:1 | -LL | x.map_or_else(|err| err, |n| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` +LL | x.map_or_else(|err| err, |n| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` | = note: `-D clippy::unnecessary-result-map-or-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_result_map_or_else)]` error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:10:5 + --> tests/ui/unnecessary_result_map_or_else.rs:11:1 | -LL | x.map_or_else(|err: ()| err, |n: ()| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err: ()| err)` +LL | x.map_or_else(|err: ()| err, |n: ()| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err: ()| err)` error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:15:19 + --> tests/ui/unnecessary_result_map_or_else.rs:17:15 | -LL | let y: &str = x.map_or_else(|err| err, |n| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` +LL | let y: &str = x.map_or_else(|err| err, |n| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:19:5 + --> tests/ui/unnecessary_result_map_or_else.rs:22:5 | LL | / x.map_or_else( LL | | +LL | | LL | | |err| err, -LL | | |n| { ... | LL | | }, LL | | ); diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index bdc6fa0f46bb..3bdeda2724c6 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -4,19 +4,24 @@ mod unsafe_items_invalid_comment { // SAFETY: const CONST: u32 = 0; - //~^ ERROR: constant item has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: static STATIC: u32 = 0; - //~^ ERROR: static item has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: struct Struct; - //~^ ERROR: struct has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: enum Enum {} - //~^ ERROR: enum has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: mod module {} - //~^ ERROR: module has unnecessary safety comment + //~^ unnecessary_safety_comment + } mod unnecessary_from_macro { @@ -36,6 +41,7 @@ mod unnecessary_from_macro { ($t:ty) => { // Safety: unnecessary impl T for $t {} + //~^ unnecessary_safety_comment }; } @@ -45,15 +51,18 @@ mod unnecessary_from_macro { fn unnecessary_on_stmt_and_expr() -> u32 { // SAFETY: unnecessary let num = 42; - //~^ ERROR: statement has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: unnecessary if num > 24 {} - //~^ ERROR: statement has unnecessary safety comment + //~^ unnecessary_safety_comment + // SAFETY: unnecessary 24 - //~^ ERROR: expression has unnecessary safety comment + //~^ unnecessary_safety_comment + } mod issue_10084 { diff --git a/tests/ui/unnecessary_safety_comment.stderr b/tests/ui/unnecessary_safety_comment.stderr index 139ed769975b..3f9e35b095b9 100644 --- a/tests/ui/unnecessary_safety_comment.stderr +++ b/tests/ui/unnecessary_safety_comment.stderr @@ -13,55 +13,55 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: static item has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:9:5 + --> tests/ui/unnecessary_safety_comment.rs:10:5 | LL | static STATIC: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:8:5 + --> tests/ui/unnecessary_safety_comment.rs:9:5 | LL | // SAFETY: | ^^^^^^^^^^ error: struct has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:12:5 + --> tests/ui/unnecessary_safety_comment.rs:14:5 | LL | struct Struct; | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:11:5 + --> tests/ui/unnecessary_safety_comment.rs:13:5 | LL | // SAFETY: | ^^^^^^^^^^ error: enum has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:15:5 + --> tests/ui/unnecessary_safety_comment.rs:18:5 | LL | enum Enum {} | ^^^^^^^^^^^^ | -help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:14:5 - | -LL | // SAFETY: - | ^^^^^^^^^^ - -error: module has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:18:5 - | -LL | mod module {} - | ^^^^^^^^^^^^^ - | help: consider removing the safety comment --> tests/ui/unnecessary_safety_comment.rs:17:5 | LL | // SAFETY: | ^^^^^^^^^^ +error: module has unnecessary safety comment + --> tests/ui/unnecessary_safety_comment.rs:22:5 + | +LL | mod module {} + | ^^^^^^^^^^^^^ + | +help: consider removing the safety comment + --> tests/ui/unnecessary_safety_comment.rs:21:5 + | +LL | // SAFETY: + | ^^^^^^^^^^ + error: impl has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:38:13 + --> tests/ui/unnecessary_safety_comment.rs:43:13 | LL | impl T for $t {} | ^^^^^^^^^^^^^^^^ @@ -70,44 +70,44 @@ LL | with_safety_comment!(i32); | ------------------------- in this macro invocation | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:37:13 + --> tests/ui/unnecessary_safety_comment.rs:42: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 - --> tests/ui/unnecessary_safety_comment.rs:55:5 + --> tests/ui/unnecessary_safety_comment.rs:63:5 | LL | 24 | ^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:54:5 + --> tests/ui/unnecessary_safety_comment.rs:62:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:47:5 + --> tests/ui/unnecessary_safety_comment.rs:53:5 | LL | let num = 42; | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:46:5 + --> tests/ui/unnecessary_safety_comment.rs:52:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:51:5 + --> tests/ui/unnecessary_safety_comment.rs:58:5 | LL | if num > 24 {} | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:50:5 + --> tests/ui/unnecessary_safety_comment.rs:57:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_self_imports.fixed b/tests/ui/unnecessary_self_imports.fixed index c265dcd2414f..0fd74705bde0 100644 --- a/tests/ui/unnecessary_self_imports.fixed +++ b/tests/ui/unnecessary_self_imports.fixed @@ -3,7 +3,9 @@ use std::collections::hash_map::{self, *}; use std::fs as alias; +//~^ unnecessary_self_imports use std::io::{self, Read}; use std::rc; +//~^ unnecessary_self_imports fn main() {} diff --git a/tests/ui/unnecessary_self_imports.rs b/tests/ui/unnecessary_self_imports.rs index c3fcf7c951a1..d09c5fcb8caa 100644 --- a/tests/ui/unnecessary_self_imports.rs +++ b/tests/ui/unnecessary_self_imports.rs @@ -3,7 +3,9 @@ use std::collections::hash_map::{self, *}; use std::fs::{self as alias}; +//~^ unnecessary_self_imports use std::io::{self, Read}; use std::rc::{self}; +//~^ unnecessary_self_imports fn main() {} diff --git a/tests/ui/unnecessary_self_imports.stderr b/tests/ui/unnecessary_self_imports.stderr index 9b143b48c9a6..1bb22c46a6c1 100644 --- a/tests/ui/unnecessary_self_imports.stderr +++ b/tests/ui/unnecessary_self_imports.stderr @@ -11,7 +11,7 @@ LL | use std::fs::{self as alias}; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_self_imports)]` error: import ending with `::{self}` - --> tests/ui/unnecessary_self_imports.rs:7:1 + --> tests/ui/unnecessary_self_imports.rs:8:1 | LL | use std::rc::{self}; | ^^^^^^^^^----------- diff --git a/tests/ui/unnecessary_semicolon.edition2021.fixed b/tests/ui/unnecessary_semicolon.edition2021.fixed index 343c88b98155..1dcc6484a195 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.fixed +++ b/tests/ui/unnecessary_semicolon.edition2021.fixed @@ -27,13 +27,15 @@ fn main() { if a == 2 { println!("This is weird"); } - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + a.match { 3 => println!("three"), _ => println!("not three"), } - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + } // This is a problem in edition 2021 and below @@ -45,6 +47,7 @@ fn borrow_issue() { }, None => {}, }; + //~[edition2024]^ unnecessary_semicolon } fn no_borrow_issue(a: u32, b: u32) { @@ -54,6 +57,7 @@ fn no_borrow_issue(a: u32, b: u32) { }, None => {}, } + //~^ unnecessary_semicolon } fn issue14100() -> bool { diff --git a/tests/ui/unnecessary_semicolon.edition2021.stderr b/tests/ui/unnecessary_semicolon.edition2021.stderr index ccff33084172..3299442a5c1d 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.stderr +++ b/tests/ui/unnecessary_semicolon.edition2021.stderr @@ -8,13 +8,13 @@ LL | }; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]` error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:35:6 + --> tests/ui/unnecessary_semicolon.rs:36:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:56:6 + --> tests/ui/unnecessary_semicolon.rs:59:6 | LL | }; | ^ help: remove diff --git a/tests/ui/unnecessary_semicolon.edition2024.fixed b/tests/ui/unnecessary_semicolon.edition2024.fixed index 1cba5760eb0a..91eef8022ed2 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.fixed +++ b/tests/ui/unnecessary_semicolon.edition2024.fixed @@ -27,13 +27,15 @@ fn main() { if a == 2 { println!("This is weird"); } - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + a.match { 3 => println!("three"), _ => println!("not three"), } - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + } // This is a problem in edition 2021 and below @@ -45,6 +47,7 @@ fn borrow_issue() { }, None => {}, } + //~[edition2024]^ unnecessary_semicolon } fn no_borrow_issue(a: u32, b: u32) { @@ -54,6 +57,7 @@ fn no_borrow_issue(a: u32, b: u32) { }, None => {}, } + //~^ unnecessary_semicolon } fn issue14100() -> bool { diff --git a/tests/ui/unnecessary_semicolon.edition2024.stderr b/tests/ui/unnecessary_semicolon.edition2024.stderr index 4e526af2147d..98adc2f0a0a2 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.stderr +++ b/tests/ui/unnecessary_semicolon.edition2024.stderr @@ -8,19 +8,19 @@ LL | }; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]` error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:35:6 + --> tests/ui/unnecessary_semicolon.rs:36:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:47:6 + --> tests/ui/unnecessary_semicolon.rs:49:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:56:6 + --> tests/ui/unnecessary_semicolon.rs:59:6 | LL | }; | ^ help: remove diff --git a/tests/ui/unnecessary_semicolon.rs b/tests/ui/unnecessary_semicolon.rs index 6abbbd79aaf2..6c48bfae14ce 100644 --- a/tests/ui/unnecessary_semicolon.rs +++ b/tests/ui/unnecessary_semicolon.rs @@ -27,13 +27,15 @@ fn main() { if a == 2 { println!("This is weird"); }; - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + a.match { 3 => println!("three"), _ => println!("not three"), }; - //~^ ERROR: unnecessary semicolon + //~^ unnecessary_semicolon + } // This is a problem in edition 2021 and below @@ -45,6 +47,7 @@ fn borrow_issue() { }, None => {}, }; + //~[edition2024]^ unnecessary_semicolon } fn no_borrow_issue(a: u32, b: u32) { @@ -54,6 +57,7 @@ fn no_borrow_issue(a: u32, b: u32) { }, None => {}, }; + //~^ unnecessary_semicolon } fn issue14100() -> bool { diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed index 6b667e00c978..5255ab173efb 100644 --- a/tests/ui/unnecessary_sort_by.fixed +++ b/tests/ui/unnecessary_sort_by.fixed @@ -10,13 +10,19 @@ fn unnecessary_sort_by() { let mut vec: Vec = vec![3, 6, 1, 2, 5]; // Forward examples vec.sort(); + //~^ unnecessary_sort_by vec.sort_unstable(); + //~^ unnecessary_sort_by vec.sort_by_key(|a| (a + 5).abs()); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|a| id(-a)); + //~^ unnecessary_sort_by // Reverse examples vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow vec.sort_by_key(|b| std::cmp::Reverse((b + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|b| std::cmp::Reverse(id(-b))); + //~^ unnecessary_sort_by // Negative examples (shouldn't be changed) let c = &7; vec.sort_by(|a, b| (b - a).cmp(&(a - b))); @@ -27,7 +33,9 @@ fn unnecessary_sort_by() { // Vectors of references are fine as long as the resulting key does not borrow let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; vec.sort_by_key(|a| (***a).abs()); + //~^ unnecessary_sort_by vec.sort_unstable_by_key(|a| (***a).abs()); + //~^ unnecessary_sort_by // `Reverse(b)` would borrow in the following cases, don't lint vec.sort_by(|a, b| b.cmp(a)); vec.sort_unstable_by(|a, b| b.cmp(a)); @@ -87,10 +95,14 @@ mod issue_6001 { // Forward args.sort_by_key(|a| a.name()); + //~^ unnecessary_sort_by args.sort_unstable_by_key(|a| a.name()); + //~^ unnecessary_sort_by // Reverse args.sort_by_key(|b| std::cmp::Reverse(b.name())); + //~^ unnecessary_sort_by args.sort_unstable_by_key(|b| std::cmp::Reverse(b.name())); + //~^ unnecessary_sort_by } } diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs index 0ff20fb9ef28..65db7ca3f137 100644 --- a/tests/ui/unnecessary_sort_by.rs +++ b/tests/ui/unnecessary_sort_by.rs @@ -10,13 +10,19 @@ fn unnecessary_sort_by() { let mut vec: Vec = vec![3, 6, 1, 2, 5]; // Forward examples vec.sort_by(|a, b| a.cmp(b)); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| a.cmp(b)); + //~^ unnecessary_sort_by vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); + //~^ unnecessary_sort_by // Reverse examples vec.sort_by(|a, b| b.cmp(a)); // not linted to avoid suggesting `Reverse(b)` which would borrow vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); + //~^ unnecessary_sort_by // Negative examples (shouldn't be changed) let c = &7; vec.sort_by(|a, b| (b - a).cmp(&(a - b))); @@ -27,7 +33,9 @@ fn unnecessary_sort_by() { // Vectors of references are fine as long as the resulting key does not borrow let mut vec: Vec<&&&isize> = vec![&&&3, &&&6, &&&1, &&&2, &&&5]; vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); + //~^ unnecessary_sort_by vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); + //~^ unnecessary_sort_by // `Reverse(b)` would borrow in the following cases, don't lint vec.sort_by(|a, b| b.cmp(a)); vec.sort_unstable_by(|a, b| b.cmp(a)); @@ -87,10 +95,14 @@ mod issue_6001 { // Forward args.sort_by(|a, b| a.name().cmp(&b.name())); + //~^ unnecessary_sort_by args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); + //~^ unnecessary_sort_by // Reverse args.sort_by(|a, b| b.name().cmp(&a.name())); + //~^ unnecessary_sort_by args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); + //~^ unnecessary_sort_by } } diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr index e2013a4e6f9d..9a38d3746da8 100644 --- a/tests/ui/unnecessary_sort_by.stderr +++ b/tests/ui/unnecessary_sort_by.stderr @@ -8,67 +8,67 @@ LL | vec.sort_by(|a, b| a.cmp(b)); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_sort_by)]` error: consider using `sort` - --> tests/ui/unnecessary_sort_by.rs:13:5 + --> tests/ui/unnecessary_sort_by.rs:14:5 | LL | vec.sort_unstable_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable()` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:14:5 + --> tests/ui/unnecessary_sort_by.rs:16: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: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:15:5 + --> tests/ui/unnecessary_sort_by.rs:18:5 | LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:18:5 + --> tests/ui/unnecessary_sort_by.rs:22: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: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:19:5 + --> tests/ui/unnecessary_sort_by.rs:24: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: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:29:5 + --> tests/ui/unnecessary_sort_by.rs:35:5 | LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:30:5 + --> tests/ui/unnecessary_sort_by.rs:37:5 | LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:89:9 + --> tests/ui/unnecessary_sort_by.rs:97:9 | LL | args.sort_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:90:9 + --> tests/ui/unnecessary_sort_by.rs:99:9 | LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:92:9 + --> tests/ui/unnecessary_sort_by.rs:102: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: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:93:9 + --> tests/ui/unnecessary_sort_by.rs:104: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_sort_by_no_std.fixed b/tests/ui/unnecessary_sort_by_no_std.fixed index c7be000b820c..40e6aecd1b6d 100644 --- a/tests/ui/unnecessary_sort_by_no_std.fixed +++ b/tests/ui/unnecessary_sort_by_no_std.fixed @@ -8,6 +8,7 @@ fn issue_11524() -> Vec { // Should lint and suggest `vec.sort_by_key(|a| a + 1);` vec.sort_by_key(|a| a + 1); + //~^ unnecessary_sort_by vec } @@ -16,5 +17,6 @@ fn issue_11524_2() -> Vec { // Should lint and suggest `vec.sort_by_key(|b| core::cmp::Reverse(b + 1));` vec.sort_by_key(|b| core::cmp::Reverse(b + 1)); + //~^ unnecessary_sort_by vec } diff --git a/tests/ui/unnecessary_sort_by_no_std.rs b/tests/ui/unnecessary_sort_by_no_std.rs index 5f44be97c61f..184c90d959eb 100644 --- a/tests/ui/unnecessary_sort_by_no_std.rs +++ b/tests/ui/unnecessary_sort_by_no_std.rs @@ -8,6 +8,7 @@ fn issue_11524() -> Vec { // Should lint and suggest `vec.sort_by_key(|a| a + 1);` vec.sort_by(|a, b| (a + 1).cmp(&(b + 1))); + //~^ unnecessary_sort_by vec } @@ -16,5 +17,6 @@ fn issue_11524_2() -> Vec { // Should lint and suggest `vec.sort_by_key(|b| core::cmp::Reverse(b + 1));` vec.sort_by(|a, b| (b + 1).cmp(&(a + 1))); + //~^ unnecessary_sort_by vec } diff --git a/tests/ui/unnecessary_sort_by_no_std.stderr b/tests/ui/unnecessary_sort_by_no_std.stderr index a57fbc7a6328..de3ef4123514 100644 --- a/tests/ui/unnecessary_sort_by_no_std.stderr +++ b/tests/ui/unnecessary_sort_by_no_std.stderr @@ -8,7 +8,7 @@ LL | vec.sort_by(|a, b| (a + 1).cmp(&(b + 1))); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_sort_by)]` error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by_no_std.rs:18:5 + --> tests/ui/unnecessary_sort_by_no_std.rs:19:5 | LL | vec.sort_by(|a, b| (b + 1).cmp(&(a + 1))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|b| core::cmp::Reverse(b + 1))` diff --git a/tests/ui/unnecessary_struct_initialization.fixed b/tests/ui/unnecessary_struct_initialization.fixed index b0e8f4546353..07dc90acfa30 100644 --- a/tests/ui/unnecessary_struct_initialization.fixed +++ b/tests/ui/unnecessary_struct_initialization.fixed @@ -35,6 +35,7 @@ impl Clone for V { fn clone(&self) -> Self { // Lint: `Self` implements `Copy` *self + //~^ unnecessary_struct_initialization } } @@ -42,9 +43,11 @@ fn main() { // Should lint: `a` would be consumed anyway let a = S { f: String::from("foo") }; let mut b = a; + //~^ unnecessary_struct_initialization // Should lint: `b` would be consumed, and is mutable let c = &mut b; + //~^ unnecessary_struct_initialization // Should not lint as `d` is not mutable let d = S { f: String::from("foo") }; @@ -53,6 +56,7 @@ fn main() { // Should lint as `f` would be consumed anyway let f = S { f: String::from("foo") }; let g = &f; + //~^ unnecessary_struct_initialization // Should lint: the result of an expression is mutable let h = &mut *Box::new(S { f: String::from("foo") }); @@ -77,6 +81,7 @@ fn main() { // Should lint: all fields of `q` would be consumed anyway let q = W { f1: 42, f2: 1337 }; let r = q; + //~^ unnecessary_struct_initialization // Should not lint: not all fields of `t` from same source let s = W { f1: 1337, f2: 42 }; @@ -88,6 +93,7 @@ fn main() { // Should lint: all fields of `v` would be consumed anyway let v = W { f1: 42, f2: 1337 }; let w = v; + //~^ unnecessary_struct_initialization // Should not lint: source differs between fields and base let x = W { f1: 42, f2: 1337 }; @@ -96,6 +102,7 @@ fn main() { // Should lint: range desugars to struct let r1 = 0..5; let r2 = r1; + //~^ unnecessary_struct_initialization references(); shorthand(); @@ -109,6 +116,7 @@ fn references() { // Should lint as `d` is a shared reference let c = W { f1: 42, f2: 1337 }; let d = &c; + //~^ unnecessary_struct_initialization // Should not lint as `e` is not mutable let e = W { f1: 42, f2: 1337 }; @@ -117,6 +125,7 @@ fn references() { // Should lint as `h` is a shared reference let g = W { f1: 42, f2: 1337 }; let h = &g; + //~^ unnecessary_struct_initialization // Should not lint as `j` is copy let i = V { f: 0x1701d }; diff --git a/tests/ui/unnecessary_struct_initialization.rs b/tests/ui/unnecessary_struct_initialization.rs index b0db71af4d4c..2b26bc413b8f 100644 --- a/tests/ui/unnecessary_struct_initialization.rs +++ b/tests/ui/unnecessary_struct_initialization.rs @@ -35,6 +35,7 @@ impl Clone for V { fn clone(&self) -> Self { // Lint: `Self` implements `Copy` Self { ..*self } + //~^ unnecessary_struct_initialization } } @@ -42,9 +43,11 @@ fn main() { // Should lint: `a` would be consumed anyway let a = S { f: String::from("foo") }; let mut b = S { ..a }; + //~^ unnecessary_struct_initialization // Should lint: `b` would be consumed, and is mutable let c = &mut S { ..b }; + //~^ unnecessary_struct_initialization // Should not lint as `d` is not mutable let d = S { f: String::from("foo") }; @@ -53,9 +56,11 @@ fn main() { // Should lint as `f` would be consumed anyway let f = S { f: String::from("foo") }; let g = &S { ..f }; + //~^ unnecessary_struct_initialization // Should lint: the result of an expression is mutable let h = &mut S { + //~^ unnecessary_struct_initialization ..*Box::new(S { f: String::from("foo") }) }; @@ -75,12 +80,14 @@ fn main() { // Should lint: the result of an expression is mutable and temporary let p = &mut T { + //~^ unnecessary_struct_initialization ..*Box::new(T { f: 5 }) }; // Should lint: all fields of `q` would be consumed anyway let q = W { f1: 42, f2: 1337 }; let r = W { f1: q.f1, f2: q.f2 }; + //~^ unnecessary_struct_initialization // Should not lint: not all fields of `t` from same source let s = W { f1: 1337, f2: 42 }; @@ -92,6 +99,7 @@ fn main() { // Should lint: all fields of `v` would be consumed anyway let v = W { f1: 42, f2: 1337 }; let w = W { f1: v.f1, ..v }; + //~^ unnecessary_struct_initialization // Should not lint: source differs between fields and base let x = W { f1: 42, f2: 1337 }; @@ -100,6 +108,7 @@ fn main() { // Should lint: range desugars to struct let r1 = 0..5; let r2 = r1.start..r1.end; + //~^ unnecessary_struct_initialization references(); shorthand(); @@ -113,6 +122,7 @@ fn references() { // Should lint as `d` is a shared reference let c = W { f1: 42, f2: 1337 }; let d = &W { f1: c.f1, f2: c.f2 }; + //~^ unnecessary_struct_initialization // Should not lint as `e` is not mutable let e = W { f1: 42, f2: 1337 }; @@ -121,6 +131,7 @@ fn references() { // Should lint as `h` is a shared reference let g = W { f1: 42, f2: 1337 }; let h = &W { f1: g.f1, ..g }; + //~^ unnecessary_struct_initialization // Should not lint as `j` is copy let i = V { f: 0x1701d }; diff --git a/tests/ui/unnecessary_struct_initialization.stderr b/tests/ui/unnecessary_struct_initialization.stderr index 56982cc0a39f..5177b3252547 100644 --- a/tests/ui/unnecessary_struct_initialization.stderr +++ b/tests/ui/unnecessary_struct_initialization.stderr @@ -8,67 +8,69 @@ LL | Self { ..*self } = help: to override `-D warnings` add `#[allow(clippy::unnecessary_struct_initialization)]` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:44:17 + --> tests/ui/unnecessary_struct_initialization.rs:45:17 | LL | let mut b = S { ..a }; | ^^^^^^^^^ help: replace with: `a` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:47:18 + --> tests/ui/unnecessary_struct_initialization.rs:49:18 | LL | let c = &mut S { ..b }; | ^^^^^^^^^ help: replace with: `b` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:55:14 + --> tests/ui/unnecessary_struct_initialization.rs:58:14 | LL | let g = &S { ..f }; | ^^^^^^^^^ help: replace with: `f` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:58:18 + --> tests/ui/unnecessary_struct_initialization.rs:62:18 | LL | let h = &mut S { | __________________^ +LL | | LL | | ..*Box::new(S { f: String::from("foo") }) LL | | }; | |_____^ help: replace with: `*Box::new(S { f: String::from("foo") })` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:77:18 + --> tests/ui/unnecessary_struct_initialization.rs:82:18 | LL | let p = &mut T { | __________________^ +LL | | LL | | ..*Box::new(T { f: 5 }) LL | | }; | |_____^ help: replace with: `*Box::new(T { f: 5 })` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:83:13 + --> tests/ui/unnecessary_struct_initialization.rs:89:13 | LL | let r = W { f1: q.f1, f2: q.f2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `q` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:94:13 + --> tests/ui/unnecessary_struct_initialization.rs:101:13 | LL | let w = W { f1: v.f1, ..v }; | ^^^^^^^^^^^^^^^^^^^ help: replace with: `v` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:102:14 + --> tests/ui/unnecessary_struct_initialization.rs:110:14 | LL | let r2 = r1.start..r1.end; | ^^^^^^^^^^^^^^^^ help: replace with: `r1` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:115:14 + --> tests/ui/unnecessary_struct_initialization.rs:124:14 | LL | let d = &W { f1: c.f1, f2: c.f2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `c` error: unnecessary struct building - --> tests/ui/unnecessary_struct_initialization.rs:123:14 + --> tests/ui/unnecessary_struct_initialization.rs:133:14 | LL | let h = &W { f1: g.f1, ..g }; | ^^^^^^^^^^^^^^^^^^^ help: replace with: `g` diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index 027dac419375..a03bfb2eafe3 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -62,82 +62,151 @@ fn main() { let x_ref = &x; require_c_str(&Cow::from(c_str)); + //~^ unnecessary_to_owned require_c_str(c_str); + //~^ unnecessary_to_owned require_os_str(os_str); + //~^ unnecessary_to_owned require_os_str(&Cow::from(os_str)); + //~^ unnecessary_to_owned require_os_str(os_str); + //~^ unnecessary_to_owned require_path(path); + //~^ unnecessary_to_owned require_path(&Cow::from(path)); + //~^ unnecessary_to_owned require_path(path); + //~^ unnecessary_to_owned require_str(s); + //~^ unnecessary_to_owned require_str(&Cow::from(s)); + //~^ unnecessary_to_owned require_str(s); + //~^ unnecessary_to_owned require_str(x_ref.as_ref()); + //~^ unnecessary_to_owned require_slice(slice); + //~^ unnecessary_to_owned require_slice(&Cow::from(slice)); + //~^ unnecessary_to_owned require_slice(array.as_ref()); + //~^ unnecessary_to_owned require_slice(array_ref.as_ref()); + //~^ unnecessary_to_owned require_slice(slice); + //~^ unnecessary_to_owned require_slice(&x_ref.to_owned()); // No longer flagged because of #8759. require_x(&Cow::::Owned(x.clone())); + //~^ unnecessary_to_owned require_x(&x_ref.to_owned()); // No longer flagged because of #8759. require_deref_c_str(c_str); + //~^ unnecessary_to_owned require_deref_os_str(os_str); + //~^ unnecessary_to_owned require_deref_path(path); + //~^ unnecessary_to_owned require_deref_str(s); + //~^ unnecessary_to_owned require_deref_slice(slice); + //~^ unnecessary_to_owned require_impl_deref_c_str(c_str); + //~^ unnecessary_to_owned require_impl_deref_os_str(os_str); + //~^ unnecessary_to_owned require_impl_deref_path(path); + //~^ unnecessary_to_owned require_impl_deref_str(s); + //~^ unnecessary_to_owned require_impl_deref_slice(slice); + //~^ unnecessary_to_owned require_deref_str_slice(s, slice); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_deref_slice_str(slice, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_c_str(c_str); + //~^ unnecessary_to_owned require_as_ref_os_str(os_str); + //~^ unnecessary_to_owned require_as_ref_path(path); + //~^ unnecessary_to_owned require_as_ref_str(s); + //~^ unnecessary_to_owned require_as_ref_str(&x); + //~^ unnecessary_to_owned require_as_ref_slice(array); + //~^ unnecessary_to_owned require_as_ref_slice(array_ref); + //~^ unnecessary_to_owned require_as_ref_slice(slice); + //~^ unnecessary_to_owned require_impl_as_ref_c_str(c_str); + //~^ unnecessary_to_owned require_impl_as_ref_os_str(os_str); + //~^ unnecessary_to_owned require_impl_as_ref_path(path); + //~^ unnecessary_to_owned require_impl_as_ref_str(s); + //~^ unnecessary_to_owned require_impl_as_ref_str(&x); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array_ref); + //~^ unnecessary_to_owned require_impl_as_ref_slice(slice); + //~^ unnecessary_to_owned require_as_ref_str_slice(s, array); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s, array_ref); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s, slice); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array_ref, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(slice, s); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned let _ = x.join(x_ref); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = slice.iter().copied(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].iter().cloned(); + //~^ unnecessary_to_owned let _ = check_files(&[FileType::Account]); @@ -153,15 +222,23 @@ fn main() { // The following should be flagged by `redundant_clone`, but not by this lint. require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap()); + //~^ redundant_clone require_os_str(&OsString::from("x")); + //~^ redundant_clone require_path(&std::path::PathBuf::from("x")); + //~^ redundant_clone require_str(&String::from("x")); + //~^ redundant_clone require_slice(&[String::from("x")]); + //~^ redundant_clone let slice = [0u8; 1024]; let _ref_str: &str = core::str::from_utf8(&slice).expect("not UTF-8"); + //~^ unnecessary_to_owned let _ref_str: &str = core::str::from_utf8(b"foo").unwrap(); + //~^ unnecessary_to_owned let _ref_str: &str = core::str::from_utf8(b"foo".as_slice()).unwrap(); + //~^ unnecessary_to_owned // Expression is of type `&String`, can't suggest `str::from_utf8` here let _ref_string = &String::from_utf8(b"foo".to_vec()).unwrap(); macro_rules! arg_from_macro { @@ -219,6 +296,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { for t in file_types { + //~^ unnecessary_to_owned let path = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -242,11 +320,13 @@ fn require_string(_: &String) {} fn _msrv_1_35() { // `copied` was stabilized in 1.36, so clippy should use `cloned`. let _ = &["x"][..].iter().cloned(); + //~^ unnecessary_to_owned } #[clippy::msrv = "1.36"] fn _msrv_1_36() { let _ = &["x"][..].iter().copied(); + //~^ unnecessary_to_owned } // https://github.com/rust-lang/rust-clippy/issues/8507 @@ -295,6 +375,7 @@ mod issue_8507 { // Should lint because Y is copy. fn test_y(y: Y) -> Box { Box::new(build(y)) + //~^ unnecessary_to_owned } } @@ -404,6 +485,7 @@ mod issue_9351 { // Should lint fn single_return() -> impl AsRef { id("abc") + //~^ unnecessary_to_owned } // Should not lint @@ -547,6 +629,7 @@ mod issue_11952 { fn bar() { IntoFuture::into_future(foo([], &0)); + //~^ unnecessary_to_owned } } @@ -556,18 +639,23 @@ fn borrow_checks() { fn inner(a: &[&str]) { let mut s = HashSet::from([vec!["a"]]); - s.remove(a); //~ ERROR: unnecessary use of `to_vec` +s.remove(a); +//~^ unnecessary_to_owned } let mut s = HashSet::from(["a".to_string()]); - s.remove("b"); //~ ERROR: unnecessary use of `to_owned` - s.remove("b"); //~ ERROR: unnecessary use of `to_string` +s.remove("b"); +//~^ unnecessary_to_owned +s.remove("b"); +//~^ unnecessary_to_owned // Should not warn. s.remove("b"); let mut s = HashSet::from([vec!["a"]]); - s.remove(["b"].as_slice()); //~ ERROR: unnecessary use of `to_vec` - s.remove((&["b"]).as_slice()); //~ ERROR: unnecessary use of `to_vec` +s.remove(["b"].as_slice()); +//~^ unnecessary_to_owned +s.remove((&["b"]).as_slice()); +//~^ unnecessary_to_owned // Should not warn. s.remove(&["b"].to_vec().clone()); diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs index b89f3d552f84..a03b13d47565 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -62,82 +62,151 @@ fn main() { let x_ref = &x; require_c_str(&Cow::from(c_str).into_owned()); + //~^ unnecessary_to_owned require_c_str(&c_str.to_owned()); + //~^ unnecessary_to_owned require_os_str(&os_str.to_os_string()); + //~^ unnecessary_to_owned require_os_str(&Cow::from(os_str).into_owned()); + //~^ unnecessary_to_owned require_os_str(&os_str.to_owned()); + //~^ unnecessary_to_owned require_path(&path.to_path_buf()); + //~^ unnecessary_to_owned require_path(&Cow::from(path).into_owned()); + //~^ unnecessary_to_owned require_path(&path.to_owned()); + //~^ unnecessary_to_owned require_str(&s.to_string()); + //~^ unnecessary_to_owned require_str(&Cow::from(s).into_owned()); + //~^ unnecessary_to_owned require_str(&s.to_owned()); + //~^ unnecessary_to_owned require_str(&x_ref.to_string()); + //~^ unnecessary_to_owned require_slice(&slice.to_vec()); + //~^ unnecessary_to_owned require_slice(&Cow::from(slice).into_owned()); + //~^ unnecessary_to_owned require_slice(&array.to_owned()); + //~^ unnecessary_to_owned require_slice(&array_ref.to_owned()); + //~^ unnecessary_to_owned require_slice(&slice.to_owned()); + //~^ unnecessary_to_owned require_slice(&x_ref.to_owned()); // No longer flagged because of #8759. require_x(&Cow::::Owned(x.clone()).into_owned()); + //~^ unnecessary_to_owned require_x(&x_ref.to_owned()); // No longer flagged because of #8759. require_deref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_deref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_deref_path(path.to_owned()); + //~^ unnecessary_to_owned require_deref_str(s.to_owned()); + //~^ unnecessary_to_owned require_deref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_path(path.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_str(s.to_owned()); + //~^ unnecessary_to_owned require_impl_deref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_deref_str_slice(s.to_owned(), slice.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_deref_slice_str(slice.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_as_ref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_as_ref_path(path.to_owned()); + //~^ unnecessary_to_owned require_as_ref_str(s.to_owned()); + //~^ unnecessary_to_owned require_as_ref_str(x.to_owned()); + //~^ unnecessary_to_owned require_as_ref_slice(array.to_owned()); + //~^ unnecessary_to_owned require_as_ref_slice(array_ref.to_owned()); + //~^ unnecessary_to_owned require_as_ref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_c_str(c_str.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_os_str(os_str.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_path(path.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_str(s.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_str(x.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_slice(array_ref.to_owned()); + //~^ unnecessary_to_owned require_impl_as_ref_slice(slice.to_owned()); + //~^ unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), array.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_str_slice(s.to_owned(), slice.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned require_as_ref_slice_str(slice.to_owned(), s.to_owned()); + //~^ unnecessary_to_owned + //~| unnecessary_to_owned let _ = x.join(&x_ref.to_string()); + //~^ unnecessary_to_owned let _ = slice.to_vec().into_iter(); + //~^ unnecessary_to_owned let _ = slice.to_owned().into_iter(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].to_vec().into_iter(); + //~^ unnecessary_to_owned let _ = [std::path::PathBuf::new()][..].to_owned().into_iter(); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter(slice.to_vec()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter(slice.to_owned()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec()); + //~^ unnecessary_to_owned let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); + //~^ unnecessary_to_owned let _ = check_files(&[FileType::Account]); @@ -153,15 +222,23 @@ fn main() { // The following should be flagged by `redundant_clone`, but not by this lint. require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); + //~^ redundant_clone require_os_str(&OsString::from("x").to_os_string()); + //~^ redundant_clone require_path(&std::path::PathBuf::from("x").to_path_buf()); + //~^ redundant_clone require_str(&String::from("x").to_string()); + //~^ redundant_clone require_slice(&[String::from("x")].to_owned()); + //~^ redundant_clone let slice = [0u8; 1024]; let _ref_str: &str = &String::from_utf8(slice.to_vec()).expect("not UTF-8"); + //~^ unnecessary_to_owned let _ref_str: &str = &String::from_utf8(b"foo".to_vec()).unwrap(); + //~^ unnecessary_to_owned let _ref_str: &str = &String::from_utf8(b"foo".as_slice().to_owned()).unwrap(); + //~^ unnecessary_to_owned // Expression is of type `&String`, can't suggest `str::from_utf8` here let _ref_string = &String::from_utf8(b"foo".to_vec()).unwrap(); macro_rules! arg_from_macro { @@ -219,6 +296,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { for t in file_types.to_vec() { + //~^ unnecessary_to_owned let path = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -242,11 +320,13 @@ fn require_string(_: &String) {} fn _msrv_1_35() { // `copied` was stabilized in 1.36, so clippy should use `cloned`. let _ = &["x"][..].to_vec().into_iter(); + //~^ unnecessary_to_owned } #[clippy::msrv = "1.36"] fn _msrv_1_36() { let _ = &["x"][..].to_vec().into_iter(); + //~^ unnecessary_to_owned } // https://github.com/rust-lang/rust-clippy/issues/8507 @@ -295,6 +375,7 @@ mod issue_8507 { // Should lint because Y is copy. fn test_y(y: Y) -> Box { Box::new(build(y.to_string())) + //~^ unnecessary_to_owned } } @@ -404,6 +485,7 @@ mod issue_9351 { // Should lint fn single_return() -> impl AsRef { id("abc".to_string()) + //~^ unnecessary_to_owned } // Should not lint @@ -547,6 +629,7 @@ mod issue_11952 { fn bar() { IntoFuture::into_future(foo([].to_vec(), &0)); + //~^ unnecessary_to_owned } } @@ -556,18 +639,23 @@ fn borrow_checks() { fn inner(a: &[&str]) { let mut s = HashSet::from([vec!["a"]]); - s.remove(&a.to_vec()); //~ ERROR: unnecessary use of `to_vec` +s.remove(&a.to_vec()); +//~^ unnecessary_to_owned } let mut s = HashSet::from(["a".to_string()]); - s.remove(&"b".to_owned()); //~ ERROR: unnecessary use of `to_owned` - s.remove(&"b".to_string()); //~ ERROR: unnecessary use of `to_string` +s.remove(&"b".to_owned()); +//~^ unnecessary_to_owned +s.remove(&"b".to_string()); +//~^ unnecessary_to_owned // Should not warn. s.remove("b"); let mut s = HashSet::from([vec!["a"]]); - s.remove(&["b"].to_vec()); //~ ERROR: unnecessary use of `to_vec` - s.remove(&(&["b"]).to_vec()); //~ ERROR: unnecessary use of `to_vec` +s.remove(&["b"].to_vec()); +//~^ unnecessary_to_owned +s.remove(&(&["b"]).to_vec()); +//~^ unnecessary_to_owned // Should not warn. s.remove(&["b"].to_vec().clone()); diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 498ac68cdaa0..23963fd6779a 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:155:64 + --> tests/ui/unnecessary_to_owned.rs:224:64 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:155:20 + --> tests/ui/unnecessary_to_owned.rs:224:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,49 +13,49 @@ LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()) = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:156:40 + --> tests/ui/unnecessary_to_owned.rs:226:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:156:21 + --> tests/ui/unnecessary_to_owned.rs:226:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:157:48 + --> tests/ui/unnecessary_to_owned.rs:228:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:157:19 + --> tests/ui/unnecessary_to_owned.rs:228:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:158:35 + --> tests/ui/unnecessary_to_owned.rs:230:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:158:18 + --> tests/ui/unnecessary_to_owned.rs:230:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:159:39 + --> tests/ui/unnecessary_to_owned.rs:232:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:159:20 + --> tests/ui/unnecessary_to_owned.rs:232:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ @@ -70,415 +70,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:65:19 + --> tests/ui/unnecessary_to_owned.rs:66:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> tests/ui/unnecessary_to_owned.rs:67:20 + --> tests/ui/unnecessary_to_owned.rs:69:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:68:38 + --> tests/ui/unnecessary_to_owned.rs:71:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:69:20 + --> tests/ui/unnecessary_to_owned.rs:73:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> tests/ui/unnecessary_to_owned.rs:71:18 + --> tests/ui/unnecessary_to_owned.rs:76:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:72:34 + --> tests/ui/unnecessary_to_owned.rs:78:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:73:18 + --> tests/ui/unnecessary_to_owned.rs:80:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:75:17 + --> tests/ui/unnecessary_to_owned.rs:83:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:76:30 + --> tests/ui/unnecessary_to_owned.rs:85:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:77:17 + --> tests/ui/unnecessary_to_owned.rs:87:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:78:17 + --> tests/ui/unnecessary_to_owned.rs:89:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:80:19 + --> tests/ui/unnecessary_to_owned.rs:92:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:81:36 + --> tests/ui/unnecessary_to_owned.rs:94:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:82:19 + --> tests/ui/unnecessary_to_owned.rs:96:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:83:19 + --> tests/ui/unnecessary_to_owned.rs:98:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:84:19 + --> tests/ui/unnecessary_to_owned.rs:100:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:87:42 + --> tests/ui/unnecessary_to_owned.rs:104:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:90:25 + --> tests/ui/unnecessary_to_owned.rs:108:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:91:26 + --> tests/ui/unnecessary_to_owned.rs:110:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:92:24 + --> tests/ui/unnecessary_to_owned.rs:112:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:93:23 + --> tests/ui/unnecessary_to_owned.rs:114:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:94:25 + --> tests/ui/unnecessary_to_owned.rs:116:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:96:30 + --> tests/ui/unnecessary_to_owned.rs:119:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:97:31 + --> tests/ui/unnecessary_to_owned.rs:121:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:98:29 + --> tests/ui/unnecessary_to_owned.rs:123:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:99:28 + --> tests/ui/unnecessary_to_owned.rs:125:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:100:30 + --> tests/ui/unnecessary_to_owned.rs:127:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:102:29 + --> tests/ui/unnecessary_to_owned.rs:130:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:102:43 + --> tests/ui/unnecessary_to_owned.rs:130:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:103:29 + --> tests/ui/unnecessary_to_owned.rs:133:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:103:47 + --> tests/ui/unnecessary_to_owned.rs:133:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:105:26 + --> tests/ui/unnecessary_to_owned.rs:137:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:106:27 + --> tests/ui/unnecessary_to_owned.rs:139:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:107:25 + --> tests/ui/unnecessary_to_owned.rs:141:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:108:24 + --> tests/ui/unnecessary_to_owned.rs:143:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:109:24 + --> tests/ui/unnecessary_to_owned.rs:145:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:110:26 + --> tests/ui/unnecessary_to_owned.rs:147:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:111:26 + --> tests/ui/unnecessary_to_owned.rs:149:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:112:26 + --> tests/ui/unnecessary_to_owned.rs:151:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:114:31 + --> tests/ui/unnecessary_to_owned.rs:154:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:115:32 + --> tests/ui/unnecessary_to_owned.rs:156:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:116:30 + --> tests/ui/unnecessary_to_owned.rs:158:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:117:29 + --> tests/ui/unnecessary_to_owned.rs:160:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:118:29 + --> tests/ui/unnecessary_to_owned.rs:162:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:119:31 + --> tests/ui/unnecessary_to_owned.rs:164:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:120:31 + --> tests/ui/unnecessary_to_owned.rs:166:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:121:31 + --> tests/ui/unnecessary_to_owned.rs:168:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:123:30 + --> tests/ui/unnecessary_to_owned.rs:171:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:123:44 + --> tests/ui/unnecessary_to_owned.rs:171:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:124:30 + --> tests/ui/unnecessary_to_owned.rs:174:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:124:44 + --> tests/ui/unnecessary_to_owned.rs:174:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:125:30 + --> tests/ui/unnecessary_to_owned.rs:177:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:125:44 + --> tests/ui/unnecessary_to_owned.rs:177:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:126:30 + --> tests/ui/unnecessary_to_owned.rs:180:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:126:48 + --> tests/ui/unnecessary_to_owned.rs:180:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:127:30 + --> tests/ui/unnecessary_to_owned.rs:183:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:127:52 + --> tests/ui/unnecessary_to_owned.rs:183:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:128:30 + --> tests/ui/unnecessary_to_owned.rs:186:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:128:48 + --> tests/ui/unnecessary_to_owned.rs:186:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:130:20 + --> tests/ui/unnecessary_to_owned.rs:190:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:132:13 + --> tests/ui/unnecessary_to_owned.rs:193:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:133:13 + --> tests/ui/unnecessary_to_owned.rs:195:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:134:13 + --> tests/ui/unnecessary_to_owned.rs:197: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` - --> tests/ui/unnecessary_to_owned.rs:135:13 + --> tests/ui/unnecessary_to_owned.rs:199: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` - --> tests/ui/unnecessary_to_owned.rs:137:13 + --> tests/ui/unnecessary_to_owned.rs:202:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:138:13 + --> tests/ui/unnecessary_to_owned.rs:204:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:139:13 + --> tests/ui/unnecessary_to_owned.rs:206: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` - --> tests/ui/unnecessary_to_owned.rs:140:13 + --> tests/ui/unnecessary_to_owned.rs:208:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:162:26 + --> tests/ui/unnecessary_to_owned.rs:236:26 | LL | let _ref_str: &str = &String::from_utf8(slice.to_vec()).expect("not UTF-8"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -490,7 +490,7 @@ LL + let _ref_str: &str = core::str::from_utf8(&slice).expect("not UTF-8"); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:163:26 + --> tests/ui/unnecessary_to_owned.rs:238:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".to_vec()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -502,7 +502,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo").unwrap(); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:164:26 + --> tests/ui/unnecessary_to_owned.rs:240:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".as_slice().to_owned()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -514,7 +514,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo".as_slice()).unwrap(); | error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:221:14 + --> tests/ui/unnecessary_to_owned.rs:298:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -522,68 +522,69 @@ LL | for t in file_types.to_vec() { help: remove any references to the binding | LL ~ for t in file_types { +LL | LL ~ let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:244:14 + --> tests/ui/unnecessary_to_owned.rs:322:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:249:14 + --> tests/ui/unnecessary_to_owned.rs:328:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:297:24 + --> tests/ui/unnecessary_to_owned.rs:377:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:406:12 + --> tests/ui/unnecessary_to_owned.rs:487:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:549:37 + --> tests/ui/unnecessary_to_owned.rs:631:37 | LL | IntoFuture::into_future(foo([].to_vec(), &0)); | ^^^^^^^^^^^ help: use: `[]` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:559:18 + --> tests/ui/unnecessary_to_owned.rs:642:10 | -LL | s.remove(&a.to_vec()); - | ^^^^^^^^^^^ help: replace it with: `a` +LL | s.remove(&a.to_vec()); + | ^^^^^^^^^^^ help: replace it with: `a` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:563:14 + --> tests/ui/unnecessary_to_owned.rs:647:10 | -LL | s.remove(&"b".to_owned()); - | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` +LL | s.remove(&"b".to_owned()); + | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:564:14 + --> tests/ui/unnecessary_to_owned.rs:649:10 | -LL | s.remove(&"b".to_string()); - | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` +LL | s.remove(&"b".to_string()); + | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:569:14 + --> tests/ui/unnecessary_to_owned.rs:655:10 | -LL | s.remove(&["b"].to_vec()); - | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` +LL | s.remove(&["b"].to_vec()); + | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:570:14 + --> tests/ui/unnecessary_to_owned.rs:657:10 | -LL | s.remove(&(&["b"]).to_vec()); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` +LL | s.remove(&(&["b"]).to_vec()); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` error: aborting due to 88 previous errors diff --git a/tests/ui/unnecessary_to_owned_on_split.fixed b/tests/ui/unnecessary_to_owned_on_split.fixed index e0ba216f41bf..be453758ff3a 100644 --- a/tests/ui/unnecessary_to_owned_on_split.fixed +++ b/tests/ui/unnecessary_to_owned_on_split.fixed @@ -17,22 +17,31 @@ impl ToString for Issue12068 { fn main() { let _ = "a".split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = "a".split("a").next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = "a".split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = "a".split("a").next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = Issue12068.as_ref().split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = [1].split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_vec` + //~^ unnecessary_to_owned + let _ = [1].split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_vec` + //~^ unnecessary_to_owned + let _ = [1].split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = [1].split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + } diff --git a/tests/ui/unnecessary_to_owned_on_split.rs b/tests/ui/unnecessary_to_owned_on_split.rs index 70efc6ebba5d..b6317db80d7c 100644 --- a/tests/ui/unnecessary_to_owned_on_split.rs +++ b/tests/ui/unnecessary_to_owned_on_split.rs @@ -17,22 +17,31 @@ impl ToString for Issue12068 { fn main() { let _ = "a".to_string().split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = "a".to_string().split("a").next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = "a".to_owned().split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = "a".to_owned().split("a").next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = Issue12068.to_string().split('a').next().unwrap(); - //~^ ERROR: unnecessary use of `to_string` + //~^ unnecessary_to_owned + let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_vec` + //~^ unnecessary_to_owned + let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_vec` + //~^ unnecessary_to_owned + let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); - //~^ ERROR: unnecessary use of `to_owned` + //~^ unnecessary_to_owned + } diff --git a/tests/ui/unnecessary_to_owned_on_split.stderr b/tests/ui/unnecessary_to_owned_on_split.stderr index cf5c964bcf3c..32cf52381d83 100644 --- a/tests/ui/unnecessary_to_owned_on_split.stderr +++ b/tests/ui/unnecessary_to_owned_on_split.stderr @@ -8,49 +8,49 @@ LL | let _ = "a".to_string().split('a').next().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned_on_split.rs:21:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:22:13 | LL | let _ = "a".to_string().split("a").next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:23:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:25:13 | LL | let _ = "a".to_owned().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split('a')` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:25:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:28:13 | LL | let _ = "a".to_owned().split("a").next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned_on_split.rs:27:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:31:13 | LL | let _ = Issue12068.to_string().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Issue12068.as_ref().split('a')` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:30:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:35:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:32:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:38:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:34:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:41:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:36:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:44:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 5ad117eb8db6..2fe6c2b23a66 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -17,6 +17,7 @@ pub fn destroy_the_planet() { /// /// This function shouldn't be called unless the horsemen are ready pub fn apocalypse(universe: &mut ()) { +//~^ unnecessary_safety_doc unimplemented!(); } @@ -43,6 +44,7 @@ mod private_mod { /// /// Unnecessary safety! pub fn republished() { + //~^ unnecessary_safety_doc unimplemented!(); } } @@ -56,6 +58,7 @@ pub trait SafeTraitSafeMethods { /// /// Unnecessary! fn documented(self); + //~^ unnecessary_safety_doc } pub trait SafeTrait { @@ -66,6 +69,7 @@ pub trait SafeTrait { /// /// Unnecessary! pub trait DocumentedSafeTrait { +//~^ unnecessary_safety_doc fn method2(); } @@ -94,6 +98,7 @@ impl Struct { /// /// Unnecessary! pub fn documented() -> Self { + //~^ unnecessary_safety_doc unimplemented!(); } @@ -121,6 +126,7 @@ macro_rules! very_safe { /// /// Driving is very safe already! pub fn drive() { + //~^ unnecessary_safety_doc whee() } }; @@ -149,5 +155,6 @@ pub mod __macro { /// # Implementation safety pub trait DocumentedSafeTraitWithImplementationHeader { +//~^ unnecessary_safety_doc fn method(); } diff --git a/tests/ui/unnecessary_unsafety_doc.stderr b/tests/ui/unnecessary_unsafety_doc.stderr index d8a9f0aa38c3..dd9d8b65f75e 100644 --- a/tests/ui/unnecessary_unsafety_doc.stderr +++ b/tests/ui/unnecessary_unsafety_doc.stderr @@ -8,31 +8,31 @@ LL | pub fn apocalypse(universe: &mut ()) { = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_doc)]` error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:45:5 + --> tests/ui/unnecessary_unsafety_doc.rs:46:5 | LL | pub fn republished() { | ^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:58:5 + --> tests/ui/unnecessary_unsafety_doc.rs:60:5 | LL | fn documented(self); | ^^^^^^^^^^^^^^^^^^^^ error: docs for safe trait have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:68:1 + --> tests/ui/unnecessary_unsafety_doc.rs:71:1 | LL | pub trait DocumentedSafeTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:96:5 + --> tests/ui/unnecessary_unsafety_doc.rs:100:5 | LL | pub fn documented() -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:123:9 + --> tests/ui/unnecessary_unsafety_doc.rs:128:9 | LL | pub fn drive() { | ^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | very_safe!(); = note: this error originates in the macro `very_safe` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for safe trait have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:151:1 + --> tests/ui/unnecessary_unsafety_doc.rs:157:1 | LL | pub trait DocumentedSafeTraitWithImplementationHeader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index 200aefff1bbf..dee51ef67c3d 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -7,8 +7,9 @@ // 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` +//~^ unnecessary_wraps + + if a && b { return Some(42); } @@ -22,7 +23,8 @@ 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` +//~^ unnecessary_wraps + if a && b { return Some(10); } @@ -41,7 +43,8 @@ fn func4(a: bool) -> Option { // should be linted fn func5() -> Option { - //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` +//~^ unnecessary_wraps + Some(1) } @@ -52,7 +55,8 @@ fn func6() -> Option { // should be linted fn func7() -> Result { - //~^ ERROR: this function's return value is unnecessarily wrapped by `Result` +//~^ unnecessary_wraps + Ok(1) } @@ -81,7 +85,8 @@ impl A { // should be linted fn func12() -> Option { - //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` + //~^ unnecessary_wraps + Some(1) } } @@ -109,7 +114,8 @@ 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 +//~^ unnecessary_wraps + if a && b { return Some(()); } @@ -123,7 +129,8 @@ 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 +//~^ unnecessary_wraps + if a && b { return Ok(()); } diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index b304d4dce6ea..c193c4cf91ad 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -2,9 +2,6 @@ error: this function's return value is unnecessarily wrapped by `Option` --> tests/ui/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { -LL | | -LL | | -LL | | if a && b { ... | LL | | } | |_^ @@ -27,13 +24,13 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:24:1 + --> tests/ui/unnecessary_wraps.rs:25:1 | LL | / fn func2(a: bool, b: bool) -> Option { LL | | +LL | | LL | | if a && b { -LL | | return Some(10); -LL | | } +... | LL | | if a { Some(20) } else { Some(30) } LL | | } | |_^ @@ -50,10 +47,11 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:43:1 + --> tests/ui/unnecessary_wraps.rs:45:1 | LL | / fn func5() -> Option { LL | | +LL | | LL | | Some(1) LL | | } | |_^ @@ -68,10 +66,11 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> tests/ui/unnecessary_wraps.rs:54:1 + --> tests/ui/unnecessary_wraps.rs:57:1 | LL | / fn func7() -> Result { LL | | +LL | | LL | | Ok(1) LL | | } | |_^ @@ -86,10 +85,11 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:83:5 + --> tests/ui/unnecessary_wraps.rs:87:5 | LL | / fn func12() -> Option { LL | | +LL | | LL | | Some(1) LL | | } | |_____^ @@ -104,12 +104,12 @@ LL | 1 | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:111:1 + --> tests/ui/unnecessary_wraps.rs:116:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { LL | | +LL | | LL | | if a && b { -LL | | return Some(()); ... | LL | | } | |_^ @@ -130,12 +130,12 @@ LL ~ return ; | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:125:1 + --> tests/ui/unnecessary_wraps.rs:131:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { LL | | +LL | | LL | | if a && b { -LL | | return Ok(()); ... | LL | | } | |_^ diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index 1d42f81711bd..e4f6a704024b 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -16,8 +16,10 @@ fn main() { match f { Foo { a: _, b: 0, .. } => {}, + //~^ unneeded_field_pattern Foo { a: _, b: _, c: _ } => {}, + //~^ unneeded_field_pattern } match f { Foo { b: 0, .. } => {}, // should be OK diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr index 4ea33a5db9e2..27e10f129dd6 100644 --- a/tests/ui/unneeded_field_pattern.stderr +++ b/tests/ui/unneeded_field_pattern.stderr @@ -9,7 +9,7 @@ LL | Foo { a: _, b: 0, .. } => {}, = help: to override `-D warnings` add `#[allow(clippy::unneeded_field_pattern)]` error: all the struct fields are matched to a wildcard pattern, consider using `..` - --> tests/ui/unneeded_field_pattern.rs:20:9 + --> tests/ui/unneeded_field_pattern.rs:21:9 | LL | Foo { a: _, b: _, c: _ } => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unneeded_struct_pattern.fixed b/tests/ui/unneeded_struct_pattern.fixed index 5bd269896a6b..3f24094ff316 100644 --- a/tests/ui/unneeded_struct_pattern.fixed +++ b/tests/ui/unneeded_struct_pattern.fixed @@ -2,7 +2,8 @@ #![allow( clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::redundant_pattern_matching + clippy::redundant_pattern_matching, + clippy::no_effect )] #![warn(clippy::unneeded_struct_pattern)] @@ -15,11 +16,13 @@ fn main() { match Some(114514) { Some(v) => v, None => 0, + //~^ unneeded_struct_pattern }; match Some(1919810) { Some(v) => v, None => 0, + //~^ unneeded_struct_pattern }; match Some(123456) { @@ -30,15 +33,23 @@ fn main() { match Some(Some(123456)) { Some(Some(v)) => v, Some(None) => 0, + //~^ unneeded_struct_pattern None => 0, + //~^ unneeded_struct_pattern }; if let None = Some(0) {} + //~^ unneeded_struct_pattern if let None = Some(0) {} + //~^ unneeded_struct_pattern if let Some(None) = Some(Some(0)) {} + //~^ unneeded_struct_pattern let None = Some(0) else { panic!() }; + //~^ unneeded_struct_pattern let None = Some(0) else { panic!() }; + //~^ unneeded_struct_pattern let Some(None) = Some(Some(0)) else { panic!() }; + //~^ unneeded_struct_pattern enum Custom { HasFields { @@ -54,28 +65,19 @@ fn main() { match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields {} => 0, - Custom::NoBrackets => 0, //~ ERROR: struct pattern is not needed for a unit variant - Custom::NoBracketsNonExhaustive => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields { .. } => 0, - Custom::NoBrackets => 0, //~ ERROR: struct pattern is not needed for a unit variant - Custom::NoBracketsNonExhaustive => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; - match Custom::Init { - Custom::NoBrackets if true => 0, //~ ERROR: struct pattern is not needed for a unit variant - _ => 0, - }; + 0; + //~^^^ match_single_binding - match Custom::Init { - Custom::NoBrackets | Custom::NoBracketsNonExhaustive => 0, //~ ERROR: struct pattern is not needed for a unit variant - _ => 0, - }; + 0; if let Custom::HasFields { field: value } = Custom::Init { noop(); @@ -87,23 +89,24 @@ fn main() { noop(); } if let Custom::NoBrackets = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets | Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } @@ -118,18 +121,17 @@ fn main() { let Custom::HasBracketsNoFields { .. } = Custom::Init else { panic!() }; - let Custom::NoBrackets = Custom::Init else { panic!() }; //~ ERROR: struct pattern is not needed for a unit variant let Custom::NoBrackets = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; @@ -137,11 +139,7 @@ fn main() { Variant, } - fn pat_in_fn_param_1(Refutable::Variant: Refutable) {} //~ ERROR: struct pattern is not needed for a unit variant - fn pat_in_fn_param_2(Refutable::Variant: Refutable) {} //~ ERROR: struct pattern is not needed for a unit variant - for Refutable::Variant in [] {} //~ ERROR: struct pattern is not needed for a unit variant - for Refutable::Variant in [] {} //~ ERROR: struct pattern is not needed for a unit variant } fn external_crate() { @@ -153,17 +151,9 @@ fn external_crate() { _ => 0, }; - match ExhaustiveUnit { - // Exhaustive variant - ExhaustiveUnit => 0, //~ ERROR: struct pattern is not needed for a unit variant - _ => 0, - }; + 0; - match ExhaustiveUnit { - // Exhaustive variant - ExhaustiveUnit => 0, //~ ERROR: struct pattern is not needed for a unit variant - _ => 0, - }; + 0; match ExhaustiveUnit { ExhaustiveUnit => 0, diff --git a/tests/ui/unneeded_struct_pattern.rs b/tests/ui/unneeded_struct_pattern.rs index c7658617ad37..0e6ae5124822 100644 --- a/tests/ui/unneeded_struct_pattern.rs +++ b/tests/ui/unneeded_struct_pattern.rs @@ -2,7 +2,8 @@ #![allow( clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::redundant_pattern_matching + clippy::redundant_pattern_matching, + clippy::no_effect )] #![warn(clippy::unneeded_struct_pattern)] @@ -15,11 +16,13 @@ fn main() { match Some(114514) { Some(v) => v, None {} => 0, + //~^ unneeded_struct_pattern }; match Some(1919810) { Some(v) => v, None { .. } => 0, + //~^ unneeded_struct_pattern }; match Some(123456) { @@ -30,15 +33,23 @@ fn main() { match Some(Some(123456)) { Some(Some(v)) => v, Some(None {}) => 0, + //~^ unneeded_struct_pattern None {} => 0, + //~^ unneeded_struct_pattern }; if let None {} = Some(0) {} + //~^ unneeded_struct_pattern if let None { .. } = Some(0) {} + //~^ unneeded_struct_pattern if let Some(None {}) = Some(Some(0)) {} + //~^ unneeded_struct_pattern let None {} = Some(0) else { panic!() }; + //~^ unneeded_struct_pattern let None { .. } = Some(0) else { panic!() }; + //~^ unneeded_struct_pattern let Some(None {}) = Some(Some(0)) else { panic!() }; + //~^ unneeded_struct_pattern enum Custom { HasFields { @@ -54,26 +65,22 @@ fn main() { match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields {} => 0, - Custom::NoBrackets {} => 0, //~ ERROR: struct pattern is not needed for a unit variant - Custom::NoBracketsNonExhaustive {} => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields { .. } => 0, - Custom::NoBrackets { .. } => 0, //~ ERROR: struct pattern is not needed for a unit variant - Custom::NoBracketsNonExhaustive { .. } => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; match Custom::Init { - Custom::NoBrackets {} if true => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; + //~^^^ match_single_binding match Custom::Init { - Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, //~ ERROR: struct pattern is not needed for a unit variant + //~^ match_single_binding _ => 0, }; @@ -87,23 +94,24 @@ fn main() { noop(); } if let Custom::NoBrackets {} = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets { .. } = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive {} = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive { .. } = Custom::Init { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern noop(); } @@ -118,18 +126,17 @@ fn main() { let Custom::HasBracketsNoFields { .. } = Custom::Init else { panic!() }; - let Custom::NoBrackets {} = Custom::Init else { panic!() }; //~ ERROR: struct pattern is not needed for a unit variant let Custom::NoBrackets { .. } = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive {} = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { - //~^ ERROR: struct pattern is not needed for a unit variant + //~^ unneeded_struct_pattern panic!() }; @@ -137,11 +144,7 @@ fn main() { Variant, } - fn pat_in_fn_param_1(Refutable::Variant {}: Refutable) {} //~ ERROR: struct pattern is not needed for a unit variant - fn pat_in_fn_param_2(Refutable::Variant { .. }: Refutable) {} //~ ERROR: struct pattern is not needed for a unit variant - for Refutable::Variant {} in [] {} //~ ERROR: struct pattern is not needed for a unit variant - for Refutable::Variant { .. } in [] {} //~ ERROR: struct pattern is not needed for a unit variant } fn external_crate() { @@ -154,14 +157,14 @@ fn external_crate() { }; match ExhaustiveUnit { + //~^ match_single_binding // Exhaustive variant - ExhaustiveUnit { .. } => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; match ExhaustiveUnit { + //~^ match_single_binding // Exhaustive variant - ExhaustiveUnit {} => 0, //~ ERROR: struct pattern is not needed for a unit variant _ => 0, }; diff --git a/tests/ui/unneeded_struct_pattern.stderr b/tests/ui/unneeded_struct_pattern.stderr index 3a7f59583802..9fd698ebf861 100644 --- a/tests/ui/unneeded_struct_pattern.stderr +++ b/tests/ui/unneeded_struct_pattern.stderr @@ -1,5 +1,5 @@ error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:17:13 + --> tests/ui/unneeded_struct_pattern.rs:18:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern @@ -8,196 +8,152 @@ LL | None {} => 0, = help: to override `-D warnings` add `#[allow(clippy::unneeded_struct_pattern)]` error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:22:13 + --> tests/ui/unneeded_struct_pattern.rs:24:13 | LL | None { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:32:18 + --> tests/ui/unneeded_struct_pattern.rs:35:18 | LL | Some(None {}) => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:33:13 + --> tests/ui/unneeded_struct_pattern.rs:37:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:36:16 + --> tests/ui/unneeded_struct_pattern.rs:41:16 | LL | if let None {} = Some(0) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:37:16 + --> tests/ui/unneeded_struct_pattern.rs:43:16 | LL | if let None { .. } = Some(0) {} | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:38:21 + --> tests/ui/unneeded_struct_pattern.rs:45:21 | LL | if let Some(None {}) = Some(Some(0)) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:39:13 + --> tests/ui/unneeded_struct_pattern.rs:47:13 | LL | let None {} = Some(0) else { panic!() }; | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:40:13 + --> tests/ui/unneeded_struct_pattern.rs:49:13 | LL | let None { .. } = Some(0) else { panic!() }; | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:41:18 + --> tests/ui/unneeded_struct_pattern.rs:51:18 | LL | let Some(None {}) = Some(Some(0)) else { panic!() }; | ^^^ help: remove the struct pattern -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:57:27 +error: this match could be replaced by its body itself + --> tests/ui/unneeded_struct_pattern.rs:77:5 | -LL | Custom::NoBrackets {} => 0, - | ^^^ help: remove the struct pattern +LL | / match Custom::Init { +LL | | _ => 0, +LL | | }; + | |_____^ help: consider using the match body instead: `0` + | + = note: `-D clippy::match-single-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` + +error: this match could be replaced by its body itself + --> tests/ui/unneeded_struct_pattern.rs:82:5 + | +LL | / match Custom::Init { +LL | | +LL | | _ => 0, +LL | | }; + | |_____^ help: consider using the match body instead: `0` error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:58:40 - | -LL | Custom::NoBracketsNonExhaustive {} => 0, - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:65:27 - | -LL | Custom::NoBrackets { .. } => 0, - | ^^^^^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:66:40 - | -LL | Custom::NoBracketsNonExhaustive { .. } => 0, - | ^^^^^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:71:27 - | -LL | Custom::NoBrackets {} if true => 0, - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:76:27 - | -LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:76:64 - | -LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:89:30 + --> tests/ui/unneeded_struct_pattern.rs:96:30 | LL | if let Custom::NoBrackets {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:93:30 + --> tests/ui/unneeded_struct_pattern.rs:100:30 | LL | if let Custom::NoBrackets { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:97:30 + --> tests/ui/unneeded_struct_pattern.rs:104:30 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:97:67 + --> tests/ui/unneeded_struct_pattern.rs:104:67 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:101:43 + --> tests/ui/unneeded_struct_pattern.rs:109:43 | LL | if let Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:105:43 + --> tests/ui/unneeded_struct_pattern.rs:113:43 | LL | if let Custom::NoBracketsNonExhaustive { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:121:27 - | -LL | let Custom::NoBrackets {} = Custom::Init else { panic!() }; - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:123:27 + --> tests/ui/unneeded_struct_pattern.rs:130:27 | LL | let Custom::NoBrackets { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:127:40 + --> tests/ui/unneeded_struct_pattern.rs:134:40 | LL | let Custom::NoBracketsNonExhaustive {} = Custom::Init else { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:131:40 + --> tests/ui/unneeded_struct_pattern.rs:138:40 | LL | let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:140:44 +error: this match could be replaced by its body itself + --> tests/ui/unneeded_struct_pattern.rs:159:5 | -LL | fn pat_in_fn_param_1(Refutable::Variant {}: Refutable) {} - | ^^^ help: remove the struct pattern +LL | / match ExhaustiveUnit { +LL | | +LL | | // Exhaustive variant +LL | | _ => 0, +LL | | }; + | |_____^ help: consider using the match body instead: `0` -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:141:44 +error: this match could be replaced by its body itself + --> tests/ui/unneeded_struct_pattern.rs:165:5 | -LL | fn pat_in_fn_param_2(Refutable::Variant { .. }: Refutable) {} - | ^^^^^^^ help: remove the struct pattern +LL | / match ExhaustiveUnit { +LL | | +LL | | // Exhaustive variant +LL | | _ => 0, +LL | | }; + | |_____^ help: consider using the match body instead: `0` -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:143:27 - | -LL | for Refutable::Variant {} in [] {} - | ^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:144:27 - | -LL | for Refutable::Variant { .. } in [] {} - | ^^^^^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:158:23 - | -LL | ExhaustiveUnit { .. } => 0, - | ^^^^^^^ help: remove the struct pattern - -error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:164:23 - | -LL | ExhaustiveUnit {} => 0, - | ^^^ help: remove the struct pattern - -error: aborting due to 33 previous errors +error: aborting due to 23 previous errors diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed index cbf91ed4910a..7e6a493b86c1 100644 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ b/tests/ui/unneeded_wildcard_pattern.fixed @@ -10,11 +10,17 @@ fn main() { let t = (0, 1, 2, 3); if let (0, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (0, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (.., 0) = t {}; + //~^ unneeded_wildcard_pattern if let (.., 0) = t {}; + //~^ unneeded_wildcard_pattern if let (0, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (0, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (_, 0, ..) = t {}; if let (.., 0, _) = t {}; if let (0, _, _, _) = t {}; @@ -24,6 +30,7 @@ fn main() { #[rustfmt::skip] { if let (0, ..,) = t {}; + //~^ unneeded_wildcard_pattern } struct S(usize, usize, usize, usize); @@ -31,11 +38,17 @@ fn main() { let s = S(0, 1, 2, 3); if let S(0, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(.., 0) = s {}; + //~^ unneeded_wildcard_pattern if let S(.., 0) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(_, 0, ..) = s {}; if let S(.., 0, _) = s {}; if let S(0, _, _, _) = s {}; @@ -45,6 +58,7 @@ fn main() { #[rustfmt::skip] { if let S(0, ..,) = s {}; + //~^ unneeded_wildcard_pattern } external! { let t = (0, 1, 2, 3); diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs index 10df2b93d5e0..c91383e2cca5 100644 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ b/tests/ui/unneeded_wildcard_pattern.rs @@ -10,11 +10,17 @@ fn main() { let t = (0, 1, 2, 3); if let (0, .., _) = t {}; + //~^ unneeded_wildcard_pattern if let (0, _, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (_, .., 0) = t {}; + //~^ unneeded_wildcard_pattern if let (.., _, 0) = t {}; + //~^ unneeded_wildcard_pattern if let (0, _, _, ..) = t {}; + //~^ unneeded_wildcard_pattern if let (0, .., _, _) = t {}; + //~^ unneeded_wildcard_pattern if let (_, 0, ..) = t {}; if let (.., 0, _) = t {}; if let (0, _, _, _) = t {}; @@ -24,6 +30,7 @@ fn main() { #[rustfmt::skip] { if let (0, .., _, _,) = t {}; + //~^ unneeded_wildcard_pattern } struct S(usize, usize, usize, usize); @@ -31,11 +38,17 @@ fn main() { let s = S(0, 1, 2, 3); if let S(0, .., _) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, _, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(_, .., 0) = s {}; + //~^ unneeded_wildcard_pattern if let S(.., _, 0) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, _, _, ..) = s {}; + //~^ unneeded_wildcard_pattern if let S(0, .., _, _) = s {}; + //~^ unneeded_wildcard_pattern if let S(_, 0, ..) = s {}; if let S(.., 0, _) = s {}; if let S(0, _, _, _) = s {}; @@ -45,6 +58,7 @@ fn main() { #[rustfmt::skip] { if let S(0, .., _, _,) = s {}; + //~^ unneeded_wildcard_pattern } external! { let t = (0, 1, 2, 3); diff --git a/tests/ui/unneeded_wildcard_pattern.stderr b/tests/ui/unneeded_wildcard_pattern.stderr index ceb7d7fe9e09..20666268a8ca 100644 --- a/tests/ui/unneeded_wildcard_pattern.stderr +++ b/tests/ui/unneeded_wildcard_pattern.stderr @@ -11,79 +11,79 @@ LL | #![deny(clippy::unneeded_wildcard_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:13:16 + --> tests/ui/unneeded_wildcard_pattern.rs:14:16 | LL | if let (0, _, ..) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:14:13 + --> tests/ui/unneeded_wildcard_pattern.rs:16:13 | LL | if let (_, .., 0) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:15:15 + --> tests/ui/unneeded_wildcard_pattern.rs:18:15 | LL | if let (.., _, 0) = t {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:16:16 + --> tests/ui/unneeded_wildcard_pattern.rs:20:16 | LL | if let (0, _, _, ..) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:17:18 + --> tests/ui/unneeded_wildcard_pattern.rs:22:18 | LL | if let (0, .., _, _) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:26:22 + --> tests/ui/unneeded_wildcard_pattern.rs:32:22 | LL | if let (0, .., _, _,) = t {}; | ^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:33:19 + --> tests/ui/unneeded_wildcard_pattern.rs:40:19 | LL | if let S(0, .., _) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:34:17 + --> tests/ui/unneeded_wildcard_pattern.rs:42:17 | LL | if let S(0, _, ..) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:35:14 + --> tests/ui/unneeded_wildcard_pattern.rs:44:14 | LL | if let S(_, .., 0) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:36:16 + --> tests/ui/unneeded_wildcard_pattern.rs:46:16 | LL | if let S(.., _, 0) = s {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:37:17 + --> tests/ui/unneeded_wildcard_pattern.rs:48:17 | LL | if let S(0, _, _, ..) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:38:19 + --> tests/ui/unneeded_wildcard_pattern.rs:50:19 | LL | if let S(0, .., _, _) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:47:23 + --> tests/ui/unneeded_wildcard_pattern.rs:60: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 53ec556d1008..791b2fa131f2 100644 --- a/tests/ui/unnested_or_patterns.fixed +++ b/tests/ui/unnested_or_patterns.fixed @@ -14,27 +14,43 @@ fn main() { if let &0 | &2 = &0 {} if let box (0 | 2) = Box::new(0) {} + //~^ unnested_or_patterns if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + //~^ unnested_or_patterns const C0: Option = Some(1); if let Some(1 | 2) | C0 = None {} + //~^ unnested_or_patterns if let &mut (0 | 2) = &mut 0 {} + //~^ unnested_or_patterns if let x @ (0 | 2) = 0 {} + //~^ unnested_or_patterns if let (0, 1 | 2 | 3) = (0, 0) {} + //~^ unnested_or_patterns if let (1 | 2 | 3, 0) = (0, 0) {} + //~^ unnested_or_patterns if let (x, ..) | (x, 1 | 2) = (0, 1) {} + //~^ unnested_or_patterns if let [0 | 1] = [0] {} + //~^ unnested_or_patterns if let [x, 0 | 1] = [0, 1] {} + //~^ unnested_or_patterns if let [x, 0 | 1 | 2] = [0, 1] {} + //~^ unnested_or_patterns if let [x, ..] | [x, 1 | 2] = [0, 1] {} + //~^ unnested_or_patterns struct TS(u8, u8); if let TS(0 | 1, x) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(1 | 2 | 3, 0) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} + //~^ unnested_or_patterns struct S { x: u8, y: u8, } if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} + //~^ unnested_or_patterns if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} } @@ -46,4 +62,5 @@ fn msrv_1_52() { #[clippy::msrv = "1.53"] fn msrv_1_53() { if let [1 | 53] = [0] {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs index e5e378e922af..e7e7c7cd2e49 100644 --- a/tests/ui/unnested_or_patterns.rs +++ b/tests/ui/unnested_or_patterns.rs @@ -14,27 +14,43 @@ fn main() { if let &0 | &2 = &0 {} if let box 0 | box 2 = Box::new(0) {} + //~^ unnested_or_patterns if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} + //~^ unnested_or_patterns const C0: Option = Some(1); if let Some(1) | C0 | Some(2) = None {} + //~^ unnested_or_patterns if let &mut 0 | &mut 2 = &mut 0 {} + //~^ unnested_or_patterns if let x @ 0 | x @ 2 = 0 {} + //~^ unnested_or_patterns if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} + //~^ unnested_or_patterns if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} + //~^ unnested_or_patterns if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} + //~^ unnested_or_patterns if let [0] | [1] = [0] {} + //~^ unnested_or_patterns if let [x, 0] | [x, 1] = [0, 1] {} + //~^ unnested_or_patterns if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} + //~^ unnested_or_patterns if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} + //~^ unnested_or_patterns struct TS(u8, u8); if let TS(0, x) | TS(1, x) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} + //~^ unnested_or_patterns if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} + //~^ unnested_or_patterns struct S { x: u8, y: u8, } if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} + //~^ unnested_or_patterns if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} } @@ -46,4 +62,5 @@ fn msrv_1_52() { #[clippy::msrv = "1.53"] fn msrv_1_53() { if let [1] | [53] = [0] {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index bd15ef62368e..3dfd34df4efc 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -12,7 +12,7 @@ LL | if let box (0 | 2) = Box::new(0) {} | ~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:17:12 + --> tests/ui/unnested_or_patterns.rs:18:12 | LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:19:12 + --> tests/ui/unnested_or_patterns.rs:21:12 | LL | if let Some(1) | C0 | Some(2) = None {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | if let Some(1 | 2) | C0 = None {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:20:12 + --> tests/ui/unnested_or_patterns.rs:23:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | if let &mut (0 | 2) = &mut 0 {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:21:12 + --> tests/ui/unnested_or_patterns.rs:25:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let x @ (0 | 2) = 0 {} | ~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:22:12 + --> tests/ui/unnested_or_patterns.rs:27:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:23:12 + --> tests/ui/unnested_or_patterns.rs:29:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:24:12 + --> tests/ui/unnested_or_patterns.rs:31:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:25:12 + --> tests/ui/unnested_or_patterns.rs:33:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -100,7 +100,7 @@ LL | if let [0 | 1] = [0] {} | ~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:26:12 + --> tests/ui/unnested_or_patterns.rs:35:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | if let [x, 0 | 1] = [0, 1] {} | ~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:27:12 + --> tests/ui/unnested_or_patterns.rs:37:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:28:12 + --> tests/ui/unnested_or_patterns.rs:39:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:30:12 + --> tests/ui/unnested_or_patterns.rs:42:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:31:12 + --> tests/ui/unnested_or_patterns.rs:44:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:32:12 + --> tests/ui/unnested_or_patterns.rs:46:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:37:12 + --> tests/ui/unnested_or_patterns.rs:52:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:48:12 + --> tests/ui/unnested_or_patterns.rs:64:12 | LL | if let [1] | [53] = [0] {} | ^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed index b2a4e83dadc3..6d601ea5e57f 100644 --- a/tests/ui/unnested_or_patterns2.fixed +++ b/tests/ui/unnested_or_patterns2.fixed @@ -10,11 +10,19 @@ fn main() { if let Some(Some(0 | 1)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1 | 2)) = None {} + //~^ unnested_or_patterns if let ((0 | 1 | 2,),) = ((0,),) {} + //~^ unnested_or_patterns if let 0 | 1 | 2 = 0 {} + //~^ unnested_or_patterns if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} + //~^ unnested_or_patterns if let box box (0 | 2 | 4) = Box::new(Box::new(0)) {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs index 58435f8990d2..7e5ea0161bff 100644 --- a/tests/ui/unnested_or_patterns2.rs +++ b/tests/ui/unnested_or_patterns2.rs @@ -10,11 +10,19 @@ fn main() { if let Some(Some(0)) | Some(Some(1)) = None {} + //~^ unnested_or_patterns if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} + //~^ unnested_or_patterns if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} + //~^ unnested_or_patterns if let Some(Some(0) | Some(1 | 2)) = None {} + //~^ unnested_or_patterns if let ((0,),) | ((1,) | (2,),) = ((0,),) {} + //~^ unnested_or_patterns if let 0 | (1 | 2) = 0 {} + //~^ unnested_or_patterns if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} + //~^ unnested_or_patterns if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} + //~^ unnested_or_patterns } diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 54f03937508a..040bb46b0847 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -12,7 +12,7 @@ LL | if let Some(Some(0 | 1)) = None {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:13:12 + --> tests/ui/unnested_or_patterns2.rs:14:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:14:12 + --> tests/ui/unnested_or_patterns2.rs:16:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:15:12 + --> tests/ui/unnested_or_patterns2.rs:18:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:16:12 + --> tests/ui/unnested_or_patterns2.rs:20:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {} | ~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:17:12 + --> tests/ui/unnested_or_patterns2.rs:22:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | if let 0 | 1 | 2 = 0 {} | ~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:18:12 + --> tests/ui/unnested_or_patterns2.rs:24:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:19:12 + --> tests/ui/unnested_or_patterns2.rs:26: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 fb9c2672db82..646481ab040b 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -29,14 +29,24 @@ fn main() { 1.123_4_f32, ); let _bad = (0b11_0110_i64, 0x1234_5678_usize, 123_456_f32, 1.234_567_f32); + //~^ unreadable_literal + //~| unreadable_literal + //~| unreadable_literal + //~| unreadable_literal let _good_sci = 1.1234e1; let _bad_sci = 1.123_456e1; + //~^ unreadable_literal let _fail1 = 0x00ab_cdef; + //~^ unreadable_literal let _fail2: u32 = 0xBAFE_BAFE; + //~^ unreadable_literal let _fail3 = 0x0abc_deff; + //~^ unreadable_literal let _fail4: i128 = 0x00ab_cabc_abca_bcab_cabc; + //~^ unreadable_literal let _fail5 = 1.100_300_400; + //~^ unreadable_literal let _ = foo!(); let _ = bar!(); diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 0a24fa852546..973d1a8e196a 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -29,14 +29,24 @@ fn main() { 1.123_4_f32, ); let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); + //~^ unreadable_literal + //~| unreadable_literal + //~| unreadable_literal + //~| unreadable_literal let _good_sci = 1.1234e1; let _bad_sci = 1.123456e1; + //~^ unreadable_literal let _fail1 = 0xabcdef; + //~^ unreadable_literal let _fail2: u32 = 0xBAFEBAFE; + //~^ unreadable_literal let _fail3 = 0xabcdeff; + //~^ unreadable_literal let _fail4: i128 = 0xabcabcabcabcabcabc; + //~^ unreadable_literal let _fail5 = 1.100300400; + //~^ unreadable_literal let _ = foo!(); let _ = bar!(); diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index 5e350d760643..d019bf1b1feb 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -26,37 +26,37 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:33:20 + --> tests/ui/unreadable_literal.rs:37:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:35:18 + --> tests/ui/unreadable_literal.rs:40:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:36:23 + --> tests/ui/unreadable_literal.rs:42:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:37:18 + --> tests/ui/unreadable_literal.rs:44:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:38:24 + --> tests/ui/unreadable_literal.rs:46:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> tests/ui/unreadable_literal.rs:39:18 + --> tests/ui/unreadable_literal.rs:48:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index e9e6c8312f5e..124206e8e353 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -3,11 +3,13 @@ #![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` +//~^ unsafe_removed_from_name + + use std::cell::UnsafeCell as TotallySafeCellAgain; -//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` +//~^ unsafe_removed_from_name + // Shouldn't error use std::cell::RefCell as ProbablyNotUnsafe; @@ -26,12 +28,15 @@ 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` +//~^ unsafe_removed_from_name + // 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` +//~^ unsafe_removed_from_name +//~| unsafe_removed_from_name + + // 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 998cdbb579f6..899d438ea76b 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -8,25 +8,25 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; = help: to override `-D warnings` add `#[allow(clippy::unsafe_removed_from_name)]` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> tests/ui/unsafe_removed_from_name.rs:9:1 + --> tests/ui/unsafe_removed_from_name.rs:10:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> tests/ui/unsafe_removed_from_name.rs:28:1 + --> tests/ui/unsafe_removed_from_name.rs:30:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> tests/ui/unsafe_removed_from_name.rs:32:1 + --> tests/ui/unsafe_removed_from_name.rs:35:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `B` - --> tests/ui/unsafe_removed_from_name.rs:32:1 + --> tests/ui/unsafe_removed_from_name.rs:35:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed index 93f7f747b7cd..e13dd561d627 100644 --- a/tests/ui/unseparated_prefix_literals.fixed +++ b/tests/ui/unseparated_prefix_literals.fixed @@ -13,6 +13,7 @@ struct Foo; macro_rules! lit_from_macro { () => { 42_usize + //~^ unseparated_literal_suffix }; } @@ -21,15 +22,22 @@ fn main() { let _ok2 = 1234_isize; let _ok3 = 0x123_isize; let _fail1 = 1234_i32; + //~^ unseparated_literal_suffix let _fail2 = 1234_u32; + //~^ unseparated_literal_suffix let _fail3 = 1234_isize; + //~^ unseparated_literal_suffix let _fail4 = 1234_usize; + //~^ unseparated_literal_suffix let _fail5 = 0x123_isize; + //~^ unseparated_literal_suffix let _okf1 = 1.5_f32; let _okf2 = 1_f32; let _failf1 = 1.5_f32; + //~^ unseparated_literal_suffix let _failf2 = 1_f32; + //~^ unseparated_literal_suffix // Test for macro let _ = lit_from_macro!(); @@ -38,4 +46,5 @@ fn main() { let _ = line!(); // Because `assert!` contains `line!()` macro. assert_eq!(4897_u32, 32223); + //~^ unseparated_literal_suffix } diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs index c960ff6b5dcc..6f7b16ccba54 100644 --- a/tests/ui/unseparated_prefix_literals.rs +++ b/tests/ui/unseparated_prefix_literals.rs @@ -13,6 +13,7 @@ struct Foo; macro_rules! lit_from_macro { () => { 42usize + //~^ unseparated_literal_suffix }; } @@ -21,15 +22,22 @@ fn main() { let _ok2 = 1234_isize; let _ok3 = 0x123_isize; let _fail1 = 1234i32; + //~^ unseparated_literal_suffix let _fail2 = 1234u32; + //~^ unseparated_literal_suffix let _fail3 = 1234isize; + //~^ unseparated_literal_suffix let _fail4 = 1234usize; + //~^ unseparated_literal_suffix let _fail5 = 0x123isize; + //~^ unseparated_literal_suffix let _okf1 = 1.5_f32; let _okf2 = 1_f32; let _failf1 = 1.5f32; + //~^ unseparated_literal_suffix let _failf2 = 1f32; + //~^ unseparated_literal_suffix // Test for macro let _ = lit_from_macro!(); @@ -38,4 +46,5 @@ fn main() { let _ = line!(); // Because `assert!` contains `line!()` macro. assert_eq!(4897u32, 32223); + //~^ unseparated_literal_suffix } diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr index 1c51f7ada91f..4cfbf5e4b74e 100644 --- a/tests/ui/unseparated_prefix_literals.stderr +++ b/tests/ui/unseparated_prefix_literals.stderr @@ -1,5 +1,5 @@ error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:23:18 + --> tests/ui/unseparated_prefix_literals.rs:24:18 | LL | let _fail1 = 1234i32; | ^^^^^^^ help: add an underscore: `1234_i32` @@ -8,37 +8,37 @@ LL | let _fail1 = 1234i32; = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:24:18 + --> tests/ui/unseparated_prefix_literals.rs:26:18 | LL | let _fail2 = 1234u32; | ^^^^^^^ help: add an underscore: `1234_u32` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:25:18 + --> tests/ui/unseparated_prefix_literals.rs:28:18 | LL | let _fail3 = 1234isize; | ^^^^^^^^^ help: add an underscore: `1234_isize` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:26:18 + --> tests/ui/unseparated_prefix_literals.rs:30:18 | LL | let _fail4 = 1234usize; | ^^^^^^^^^ help: add an underscore: `1234_usize` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:27:18 + --> tests/ui/unseparated_prefix_literals.rs:32:18 | LL | let _fail5 = 0x123isize; | ^^^^^^^^^^ help: add an underscore: `0x123_isize` error: float type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:31:19 + --> tests/ui/unseparated_prefix_literals.rs:37:19 | LL | let _failf1 = 1.5f32; | ^^^^^^ help: add an underscore: `1.5_f32` error: float type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:32:19 + --> tests/ui/unseparated_prefix_literals.rs:39:19 | LL | let _failf2 = 1f32; | ^^^^ help: add an underscore: `1_f32` @@ -55,7 +55,7 @@ LL | let _ = lit_from_macro!(); = note: this error originates in the macro `lit_from_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:40:16 + --> tests/ui/unseparated_prefix_literals.rs:48:16 | LL | assert_eq!(4897u32, 32223); | ^^^^^^^ help: add an underscore: `4897_u32` diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 838d6f0aa971..225f09ed94e6 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -10,7 +10,8 @@ mod issue10800 { use std::future::ready; async fn async_block_await() { - //~^ ERROR: unused `async` for function with no await statements + //~^ unused_async + async { ready(()).await; }; @@ -43,7 +44,8 @@ mod issue9695 { async fn f() {} async fn f2() {} async fn f3() {} - //~^ ERROR: unused `async` for function with no await statements + //~^ unused_async + fn needs_async_fn>(_: fn() -> F) {} @@ -72,7 +74,8 @@ mod issue13466 { } async fn foo() -> i32 { - //~^ ERROR: unused `async` for function with no await statements +//~^ unused_async + 4 } @@ -84,7 +87,8 @@ struct S; impl S { async fn unused(&self) -> i32 { - //~^ ERROR: unused `async` for function with no await statements + //~^ unused_async + 1 } diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 4811df63658a..5b8d8f5097be 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -3,6 +3,7 @@ error: unused `async` for function with no await statements | LL | / async fn async_block_await() { LL | | +LL | | LL | | async { LL | | ready(()).await; LL | | }; @@ -11,7 +12,7 @@ LL | | } | = help: consider removing the `async` from this function note: `await` used in an async block, which does not require the enclosing function to be `async` - --> tests/ui/unused_async.rs:15:23 + --> tests/ui/unused_async.rs:16:23 | LL | ready(()).await; | ^^^^^ @@ -19,7 +20,7 @@ LL | ready(()).await; = help: to override `-D warnings` add `#[allow(clippy::unused_async)]` error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:45:5 + --> tests/ui/unused_async.rs:46:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -27,10 +28,11 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:74:1 + --> tests/ui/unused_async.rs:76:1 | LL | / async fn foo() -> i32 { LL | | +LL | | LL | | 4 LL | | } | |_^ @@ -38,10 +40,11 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:86:5 + --> tests/ui/unused_async.rs:89:5 | LL | / async fn unused(&self) -> i32 { LL | | +LL | | LL | | 1 LL | | } | |_____^ diff --git a/tests/ui/unused_enumerate_index.fixed b/tests/ui/unused_enumerate_index.fixed index cffd02b0acc8..8c713e273f4a 100644 --- a/tests/ui/unused_enumerate_index.fixed +++ b/tests/ui/unused_enumerate_index.fixed @@ -10,6 +10,7 @@ fn get_enumerate() -> Enumerate> { fn main() { let v = [1, 2, 3]; for x in v.iter() { + //~^ unused_enumerate_index println!("{x}"); } @@ -57,12 +58,15 @@ fn main() { let dummy = Dummy3(vec![1, 2, 3].into_iter()); for x in dummy { + //~^ unused_enumerate_index println!("{x}"); } let _ = vec![1, 2, 3].into_iter().map(|x| println!("{x}")); + //~^ unused_enumerate_index let p = vec![1, 2, 3].into_iter(); + //~^ unused_enumerate_index p.map(|x| println!("{x}")); // This shouldn't trigger the lint. `get_enumerate` may come from an external library on which we @@ -84,6 +88,7 @@ fn main() { }; } _ = mac2!().map(|_v| {}); + //~^ unused_enumerate_index // This shouldn't trigger the lint because of the `allow`. #[allow(clippy::unused_enumerate_index)] @@ -92,15 +97,18 @@ fn main() { // This should keep the explicit type of `x`. let v = [1, 2, 3].iter().copied(); + //~^ unused_enumerate_index let x = v.map(|x: i32| x).sum::(); assert_eq!(x, 6); // This should keep the explicit type of `x`. let v = [1, 2, 3].iter().copied(); + //~^ unused_enumerate_index let x = v.map(|x: i32| x).sum::(); assert_eq!(x, 6); let v = [1, 2, 3].iter().copied(); + //~^ unused_enumerate_index let x = v.map(|x| x).sum::(); assert_eq!(x, 6); } diff --git a/tests/ui/unused_enumerate_index.rs b/tests/ui/unused_enumerate_index.rs index f2b5f8b91247..97018ee985e5 100644 --- a/tests/ui/unused_enumerate_index.rs +++ b/tests/ui/unused_enumerate_index.rs @@ -10,6 +10,7 @@ fn get_enumerate() -> Enumerate> { fn main() { let v = [1, 2, 3]; for (_, x) in v.iter().enumerate() { + //~^ unused_enumerate_index println!("{x}"); } @@ -57,12 +58,15 @@ fn main() { let dummy = Dummy3(vec![1, 2, 3].into_iter()); for (_, x) in dummy.enumerate() { + //~^ unused_enumerate_index println!("{x}"); } let _ = vec![1, 2, 3].into_iter().enumerate().map(|(_, x)| println!("{x}")); + //~^ unused_enumerate_index let p = vec![1, 2, 3].into_iter().enumerate(); + //~^ unused_enumerate_index p.map(|(_, x)| println!("{x}")); // This shouldn't trigger the lint. `get_enumerate` may come from an external library on which we @@ -84,6 +88,7 @@ fn main() { }; } _ = mac2!().enumerate().map(|(_, _v)| {}); + //~^ unused_enumerate_index // This shouldn't trigger the lint because of the `allow`. #[allow(clippy::unused_enumerate_index)] @@ -92,15 +97,18 @@ fn main() { // This should keep the explicit type of `x`. let v = [1, 2, 3].iter().copied().enumerate(); + //~^ unused_enumerate_index let x = v.map(|(_, x): (usize, i32)| x).sum::(); assert_eq!(x, 6); // This should keep the explicit type of `x`. let v = [1, 2, 3].iter().copied().enumerate(); + //~^ unused_enumerate_index let x = v.map(|(_, x): (_, i32)| x).sum::(); assert_eq!(x, 6); let v = [1, 2, 3].iter().copied().enumerate(); + //~^ unused_enumerate_index let x = v.map(|(_, x)| x).sum::(); assert_eq!(x, 6); } diff --git a/tests/ui/unused_enumerate_index.stderr b/tests/ui/unused_enumerate_index.stderr index 6ec07dcbff0a..9ea65631a5f2 100644 --- a/tests/ui/unused_enumerate_index.stderr +++ b/tests/ui/unused_enumerate_index.stderr @@ -12,7 +12,7 @@ LL | for x in v.iter() { | ~ ~~~~~~~~ error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:59:19 + --> tests/ui/unused_enumerate_index.rs:60:19 | LL | for (_, x) in dummy.enumerate() { | ^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for x in dummy { | ~ ~~~~~ error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:63:39 + --> tests/ui/unused_enumerate_index.rs:65:39 | LL | let _ = vec![1, 2, 3].into_iter().enumerate().map(|(_, x)| println!("{x}")); | ^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL + let _ = vec![1, 2, 3].into_iter().map(|x| println!("{x}")); | error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:65:39 + --> tests/ui/unused_enumerate_index.rs:68:39 | LL | let p = vec![1, 2, 3].into_iter().enumerate(); | ^^^^^^^^^^^ @@ -43,11 +43,12 @@ LL | let p = vec![1, 2, 3].into_iter().enumerate(); help: remove the `.enumerate()` call | LL ~ let p = vec![1, 2, 3].into_iter(); +LL | LL ~ p.map(|x| println!("{x}")); | error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:86:17 + --> tests/ui/unused_enumerate_index.rs:90:17 | LL | _ = mac2!().enumerate().map(|(_, _v)| {}); | ^^^^^^^^^^^ @@ -58,18 +59,6 @@ LL - _ = mac2!().enumerate().map(|(_, _v)| {}); LL + _ = mac2!().map(|_v| {}); | -error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:94:39 - | -LL | let v = [1, 2, 3].iter().copied().enumerate(); - | ^^^^^^^^^^^ - | -help: remove the `.enumerate()` call - | -LL ~ let v = [1, 2, 3].iter().copied(); -LL ~ let x = v.map(|x: i32| x).sum::(); - | - error: you seem to use `.enumerate()` and immediately discard the index --> tests/ui/unused_enumerate_index.rs:99:39 | @@ -79,11 +68,12 @@ LL | let v = [1, 2, 3].iter().copied().enumerate(); help: remove the `.enumerate()` call | LL ~ let v = [1, 2, 3].iter().copied(); +LL | LL ~ let x = v.map(|x: i32| x).sum::(); | error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:103:39 + --> tests/ui/unused_enumerate_index.rs:105:39 | LL | let v = [1, 2, 3].iter().copied().enumerate(); | ^^^^^^^^^^^ @@ -91,6 +81,20 @@ LL | let v = [1, 2, 3].iter().copied().enumerate(); help: remove the `.enumerate()` call | LL ~ let v = [1, 2, 3].iter().copied(); +LL | +LL ~ let x = v.map(|x: i32| x).sum::(); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:110:39 + | +LL | let v = [1, 2, 3].iter().copied().enumerate(); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL ~ let v = [1, 2, 3].iter().copied(); +LL | LL ~ let x = v.map(|x| x).sum::(); | diff --git a/tests/ui/unused_format_specs.1.fixed b/tests/ui/unused_format_specs.1.fixed index 157c2b08d3cf..850240bab608 100644 --- a/tests/ui/unused_format_specs.1.fixed +++ b/tests/ui/unused_format_specs.1.fixed @@ -10,18 +10,22 @@ macro_rules! format_args_from_macro { fn main() { // prints `.`, not ` .` println!("{:5}.", format!("")); - //~^ ERROR: format specifiers have no effect on `format_args!()` - //~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` + //~^ unused_format_specs + + //prints `abcde`, not `abc` println!("{:.3}", format!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + println!("{}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); println!("{args}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint() { @@ -46,17 +50,21 @@ macro_rules! usr_println { fn should_lint_user() { // prints `.`, not ` .` usr_println!(true, "{:5}.", format!("")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + //prints `abcde`, not `abc` usr_println!(true, "{:.3}", format!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + usr_println!(true, "{}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); usr_println!(true, "{args}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.2.fixed b/tests/ui/unused_format_specs.2.fixed index 92c7b951f3ca..f8d5f615e045 100644 --- a/tests/ui/unused_format_specs.2.fixed +++ b/tests/ui/unused_format_specs.2.fixed @@ -10,18 +10,22 @@ macro_rules! format_args_from_macro { fn main() { // prints `.`, not ` .` println!("{}.", format_args!("")); - //~^ ERROR: format specifiers have no effect on `format_args!()` - //~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` + //~^ unused_format_specs + + //prints `abcde`, not `abc` println!("{}", format_args!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + println!("{}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); println!("{args}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint() { @@ -46,17 +50,21 @@ macro_rules! usr_println { fn should_lint_user() { // prints `.`, not ` .` usr_println!(true, "{}.", format_args!("")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + //prints `abcde`, not `abc` usr_println!(true, "{}", format_args!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + usr_println!(true, "{}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); usr_println!(true, "{args}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.rs b/tests/ui/unused_format_specs.rs index a5df4d8a8668..777901258a77 100644 --- a/tests/ui/unused_format_specs.rs +++ b/tests/ui/unused_format_specs.rs @@ -10,18 +10,22 @@ 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` + //~^ unused_format_specs + + //prints `abcde`, not `abc` println!("{:.3}", format_args!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + println!("{:5}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); println!("{args:5}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint() { @@ -46,17 +50,21 @@ macro_rules! usr_println { fn should_lint_user() { // prints `.`, not ` .` usr_println!(true, "{:5}.", format_args!("")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + //prints `abcde`, not `abc` usr_println!(true, "{:.3}", format_args!("abcde")); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + usr_println!(true, "{:5}.", format_args_from_macro!()); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + let args = format_args!(""); usr_println!(true, "{args:5}"); - //~^ ERROR: format specifiers have no effect on `format_args!()` + //~^ unused_format_specs + } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.stderr b/tests/ui/unused_format_specs.stderr index df61d59130ef..a88a808afe82 100644 --- a/tests/ui/unused_format_specs.stderr +++ b/tests/ui/unused_format_specs.stderr @@ -17,7 +17,7 @@ LL + println!("{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:16:15 + --> tests/ui/unused_format_specs.rs:17:15 | LL | println!("{:.3}", format_args!("abcde")); | ^^^^^ @@ -33,7 +33,7 @@ LL + println!("{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:19:15 + --> tests/ui/unused_format_specs.rs:21:15 | LL | println!("{:5}.", format_args_from_macro!()); | ^^^^ @@ -46,7 +46,7 @@ LL + println!("{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:23:15 + --> tests/ui/unused_format_specs.rs:26:15 | LL | println!("{args:5}"); | ^^^^^^^^ @@ -59,7 +59,7 @@ LL + println!("{args}"); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:48:25 + --> tests/ui/unused_format_specs.rs:52:25 | LL | usr_println!(true, "{:5}.", format_args!("")); | ^^^^ @@ -75,7 +75,7 @@ LL + usr_println!(true, "{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:51:25 + --> tests/ui/unused_format_specs.rs:56:25 | LL | usr_println!(true, "{:.3}", format_args!("abcde")); | ^^^^^ @@ -91,7 +91,7 @@ LL + usr_println!(true, "{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:54:25 + --> tests/ui/unused_format_specs.rs:60:25 | LL | usr_println!(true, "{:5}.", format_args_from_macro!()); | ^^^^ @@ -104,7 +104,7 @@ LL + usr_println!(true, "{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:58:25 + --> tests/ui/unused_format_specs.rs:65:25 | LL | usr_println!(true, "{args:5}"); | ^^^^^^^^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index 175c4ca76895..f0531836db1c 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -8,26 +8,26 @@ use std::io::{self, Read}; fn question_mark(s: &mut T) -> io::Result<()> { s.write(b"test")?; - //~^ ERROR: written amount is not handled + //~^ unused_io_amount let mut buf = [0u8; 4]; s.read(&mut buf)?; - //~^ ERROR: read amount is not handled + //~^ unused_io_amount Ok(()) } fn unwrap(s: &mut T) { s.write(b"test").unwrap(); - //~^ ERROR: written amount is not handled + //~^ unused_io_amount let mut buf = [0u8; 4]; s.read(&mut buf).unwrap(); - //~^ ERROR: read amount is not handled + //~^ unused_io_amount } fn vectored(s: &mut T) -> io::Result<()> { s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; - //~^ ERROR: read amount is not handled + //~^ unused_io_amount s.write_vectored(&[io::IoSlice::new(&[])])?; - //~^ ERROR: written amount is not handled + //~^ unused_io_amount Ok(()) } @@ -35,7 +35,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 + //~^ unused_io_amount Some(()) } @@ -45,7 +45,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 + //~^ unused_io_amount Ok(()) } @@ -58,7 +58,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 + //~^ unused_io_amount Ok(()) } @@ -66,7 +66,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 + //~^ unused_io_amount .read(&mut result) .or(Err(Error::Kind)) .or(Err(Error::Kind)) @@ -76,25 +76,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 + //~^ unused_io_amount s.write(b"err").is_err(); - //~^ ERROR: written amount is not handled + //~^ unused_io_amount let mut buf = [0u8; 0]; s.read(&mut buf).is_ok(); - //~^ ERROR: read amount is not handled + //~^ unused_io_amount s.read(&mut buf).is_err(); - //~^ ERROR: read amount is not handled + //~^ unused_io_amount } async fn bad_async_write(w: &mut W) { w.write(b"hello world").await.unwrap(); - //~^ ERROR: written amount is not handled + //~^ unused_io_amount } 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 + //~^ unused_io_amount } async fn io_not_ignored_async_write(mut w: W) { @@ -102,13 +102,14 @@ async fn io_not_ignored_async_write(mut w: W) { // warning about _that_ (or we would, if it were enabled), but we // won't get one about ignoring the return value. w.write(b"hello world"); + //~^ unused_io_amount } fn bad_async_write_closure(w: W) -> impl futures::Future> { let mut w = w; async move { w.write(b"hello world").await?; - //~^ ERROR: written amount is not handled + //~^ unused_io_amount Ok(()) } } @@ -117,7 +118,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 + //~^ unused_io_amount } Ok(buf) } @@ -126,13 +127,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 + //~^ unused_io_amount } 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 + //~^ unused_io_amount } async fn undetected_bad_async_write(w: &mut W) { @@ -145,35 +146,31 @@ async fn undetected_bad_async_write(w: &mut W) { fn match_okay_underscore(s: &mut T) { match s.write(b"test") { - //~^ ERROR: written amount is not handled + //~^ unused_io_amount Ok(_) => todo!(), - //~^ NOTE: the result is consumed here, but the amount of I/O bytes remains unhandled Err(_) => todo!(), }; let mut buf = [0u8; 4]; match s.read(&mut buf) { - //~^ ERROR: read amount is not handled + //~^ unused_io_amount Ok(_) => todo!(), - //~^ NOTE: the result is consumed here, but the amount of I/O bytes remains unhandled Err(_) => todo!(), } } fn match_okay_underscore_read_expr(s: &mut T) { match s.read(&mut [0u8; 4]) { - //~^ ERROR: read amount is not handled + //~^ unused_io_amount Ok(_) => todo!(), - //~^ NOTE: the result is consumed here, but the amount of I/O bytes remains unhandled Err(_) => todo!(), } } fn match_okay_underscore_write_expr(s: &mut T) { match s.write(b"test") { - //~^ ERROR: written amount is not handled + //~^ unused_io_amount Ok(_) => todo!(), - //~^ NOTE: the result is consumed here, but the amount of I/O bytes remains unhandled Err(_) => todo!(), } } @@ -184,21 +181,21 @@ fn returned_value_should_not_lint(s: &mut T) -> Result< fn if_okay_underscore_read_expr(s: &mut T) { if let Ok(_) = s.read(&mut [0u8; 4]) { - //~^ ERROR: read amount is not handled + //~^ unused_io_amount todo!() } } fn if_okay_underscore_write_expr(s: &mut T) { if let Ok(_) = s.write(b"test") { - //~^ ERROR: written amount is not handled + //~^ unused_io_amount todo!() } } fn if_okay_dots_write_expr(s: &mut T) { if let Ok(..) = s.write(b"test") { - //~^ ERROR: written amount is not handled + //~^ unused_io_amount todo!() } } diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 771e463ca010..71bb4c40de84 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -138,7 +138,7 @@ LL | w.write(b"hello world"); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: written amount is not handled - --> tests/ui/unused_io_amount.rs:110:9 + --> tests/ui/unused_io_amount.rs:111:9 | LL | w.write(b"hello world").await?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -146,7 +146,7 @@ LL | w.write(b"hello world").await?; = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:119:9 + --> tests/ui/unused_io_amount.rs:120:9 | LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:128:5 + --> tests/ui/unused_io_amount.rs:129:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:134:5 + --> tests/ui/unused_io_amount.rs:135:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -170,14 +170,14 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:147:11 + --> tests/ui/unused_io_amount.rs:148:11 | LL | match s.write(b"test") { | ^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:149:9 + --> tests/ui/unused_io_amount.rs:150:9 | LL | Ok(_) => todo!(), | ^^^^^ @@ -196,66 +196,66 @@ LL | Ok(_) => todo!(), | ^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:164:11 + --> tests/ui/unused_io_amount.rs:163:11 | LL | match s.read(&mut [0u8; 4]) { | ^^^^^^^^^^^^^^^^^^^^^ | = help: use `Read::read_exact` instead, or handle partial reads note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:166:9 + --> tests/ui/unused_io_amount.rs:165:9 | LL | Ok(_) => todo!(), | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:173:11 + --> tests/ui/unused_io_amount.rs:171:11 | LL | match s.write(b"test") { | ^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:175:9 + --> tests/ui/unused_io_amount.rs:173:9 | LL | Ok(_) => todo!(), | ^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:186:8 + --> tests/ui/unused_io_amount.rs:183:8 | LL | if let Ok(_) = s.read(&mut [0u8; 4]) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Read::read_exact` instead, or handle partial reads note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:186:12 + --> tests/ui/unused_io_amount.rs:183:12 | LL | if let Ok(_) = s.read(&mut [0u8; 4]) { | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:193:8 + --> tests/ui/unused_io_amount.rs:190:8 | LL | if let Ok(_) = s.write(b"test") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:193:12 + --> tests/ui/unused_io_amount.rs:190:12 | LL | if let Ok(_) = s.write(b"test") { | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:200:8 + --> tests/ui/unused_io_amount.rs:197:8 | LL | if let Ok(..) = s.write(b"test") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:200:12 + --> tests/ui/unused_io_amount.rs:197:12 | LL | if let Ok(..) = s.write(b"test") { | ^^^^^^ diff --git a/tests/ui/unused_peekable.rs b/tests/ui/unused_peekable.rs index 5865bba43508..8382db3be005 100644 --- a/tests/ui/unused_peekable.rs +++ b/tests/ui/unused_peekable.rs @@ -11,17 +11,20 @@ fn main() { #[allow(clippy::unused_unit)] fn invalid() { let peekable = std::iter::empty::().peekable(); - //~^ ERROR: `peek` never called on `Peekable` iterator + //~^ unused_peekable + // Only lint `new_local` let old_local = std::iter::empty::().peekable(); let new_local = old_local; - //~^ ERROR: `peek` never called on `Peekable` iterator + //~^ unused_peekable + // 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 + //~^ unused_peekable + // Explicitly returns `Peekable` fn returns_peekable() -> Peekable> { @@ -29,26 +32,31 @@ fn invalid() { } let peekable_from_fn = returns_peekable(); - //~^ ERROR: `peek` never called on `Peekable` iterator + //~^ unused_peekable + // Using a method not exclusive to `Peekable` let mut peekable_using_iterator_method = std::iter::empty::().peekable(); - //~^ ERROR: `peek` never called on `Peekable` iterator + //~^ unused_peekable + 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 + //~^ unused_peekable + 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 + //~^ unused_peekable + let mut peekable_in_for_loop = std::iter::empty::().peekable(); - //~^ ERROR: `peek` never called on `Peekable` iterator + //~^ unused_peekable + for x in peekable_in_for_loop {} } diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index 00c6a52bab33..9b49e32fa8ba 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -9,7 +9,7 @@ LL | let peekable = std::iter::empty::().peekable(); = help: to override `-D warnings` add `#[allow(clippy::unused_peekable)]` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:18:9 + --> tests/ui/unused_peekable.rs:19:9 | LL | let new_local = old_local; | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let new_local = old_local; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:23:9 + --> tests/ui/unused_peekable.rs:25:9 | LL | let by_mut_ref = &mut by_mut_ref_test; | ^^^^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/unused_peekable.rs:31:9 + --> tests/ui/unused_peekable.rs:34:9 | LL | let peekable_from_fn = returns_peekable(); | ^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let peekable_from_fn = returns_peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:35:13 + --> tests/ui/unused_peekable.rs:39:13 | LL | let mut peekable_using_iterator_method = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/unused_peekable.rs:41:9 + --> tests/ui/unused_peekable.rs:46:9 | LL | let passed_along_ref = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let passed_along_ref = std::iter::empty::().peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:47:9 + --> tests/ui/unused_peekable.rs:53:9 | LL | let _by_ref = by_ref_test.by_ref(); | ^^^^^^^ @@ -57,7 +57,7 @@ LL | let _by_ref = by_ref_test.by_ref(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:50:13 + --> tests/ui/unused_peekable.rs:57:13 | LL | let mut peekable_in_for_loop = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_result_ok.fixed b/tests/ui/unused_result_ok.fixed index e78fde5c9e3c..faedd96216c2 100644 --- a/tests/ui/unused_result_ok.fixed +++ b/tests/ui/unused_result_ok.fixed @@ -7,6 +7,7 @@ extern crate proc_macros; fn bad_style(x: &str) { let _ = x.parse::(); + //~^ unused_result_ok } fn good_style(x: &str) -> Option { @@ -16,6 +17,7 @@ fn good_style(x: &str) -> Option { #[rustfmt::skip] fn strange_parse(x: &str) { let _ = x . parse::(); + //~^ unused_result_ok } macro_rules! v { @@ -27,11 +29,13 @@ macro_rules! v { macro_rules! w { () => { let _ = Ok::<(), ()>(()); + //~^ unused_result_ok }; } fn main() { let _ = v!(); + //~^ unused_result_ok w!(); external! { diff --git a/tests/ui/unused_result_ok.rs b/tests/ui/unused_result_ok.rs index 117d64c4cec6..6ab974861b63 100644 --- a/tests/ui/unused_result_ok.rs +++ b/tests/ui/unused_result_ok.rs @@ -7,6 +7,7 @@ extern crate proc_macros; fn bad_style(x: &str) { x.parse::().ok(); + //~^ unused_result_ok } fn good_style(x: &str) -> Option { @@ -16,6 +17,7 @@ fn good_style(x: &str) -> Option { #[rustfmt::skip] fn strange_parse(x: &str) { x . parse::() . ok (); + //~^ unused_result_ok } macro_rules! v { @@ -27,11 +29,13 @@ macro_rules! v { macro_rules! w { () => { Ok::<(), ()>(()).ok(); + //~^ unused_result_ok }; } fn main() { v!().ok(); + //~^ unused_result_ok w!(); external! { diff --git a/tests/ui/unused_result_ok.stderr b/tests/ui/unused_result_ok.stderr index 241e0c71261e..e6fbd8666514 100644 --- a/tests/ui/unused_result_ok.stderr +++ b/tests/ui/unused_result_ok.stderr @@ -12,7 +12,7 @@ LL | let _ = x.parse::(); | ~~~~~~~~~~~~~~~~~~~~~~~~ error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:18:5 + --> tests/ui/unused_result_ok.rs:19:5 | LL | x . parse::() . ok (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = x . parse::(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:34:5 + --> tests/ui/unused_result_ok.rs:37:5 | LL | v!().ok(); | ^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = v!(); | ~~~~~~~~~~~~ error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:29:9 + --> tests/ui/unused_result_ok.rs:31:9 | LL | Ok::<(), ()>(()).ok(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_rounding.fixed b/tests/ui/unused_rounding.fixed index 7af2c8650a3d..461d97c55531 100644 --- a/tests/ui/unused_rounding.fixed +++ b/tests/ui/unused_rounding.fixed @@ -4,15 +4,20 @@ fn main() { let _ = 1f32; + //~^ unused_rounding let _ = 1.0f64; + //~^ unused_rounding let _ = 1.00f32; + //~^ unused_rounding let _ = 2e-54f64.floor(); // issue9866 let _ = 3.3_f32.round(); let _ = 3.3_f64.round(); let _ = 3.0_f32; + //~^ unused_rounding let _ = 3_3.0_0_f32; + //~^ unused_rounding let _ = 3_3.0_1_f64.round(); } diff --git a/tests/ui/unused_rounding.rs b/tests/ui/unused_rounding.rs index 1b0b22a9b685..0d5ebf941a5e 100644 --- a/tests/ui/unused_rounding.rs +++ b/tests/ui/unused_rounding.rs @@ -4,15 +4,20 @@ fn main() { let _ = 1f32.ceil(); + //~^ unused_rounding let _ = 1.0f64.floor(); + //~^ unused_rounding let _ = 1.00f32.round(); + //~^ unused_rounding let _ = 2e-54f64.floor(); // issue9866 let _ = 3.3_f32.round(); let _ = 3.3_f64.round(); let _ = 3.0_f32.round(); + //~^ unused_rounding let _ = 3_3.0_0_f32.round(); + //~^ unused_rounding let _ = 3_3.0_1_f64.round(); } diff --git a/tests/ui/unused_rounding.stderr b/tests/ui/unused_rounding.stderr index c5ae2da75f84..494b0cc7352d 100644 --- a/tests/ui/unused_rounding.stderr +++ b/tests/ui/unused_rounding.stderr @@ -8,25 +8,25 @@ LL | let _ = 1f32.ceil(); = help: to override `-D warnings` add `#[allow(clippy::unused_rounding)]` error: used the `floor` method with a whole number float - --> tests/ui/unused_rounding.rs:7:13 + --> tests/ui/unused_rounding.rs:8:13 | LL | let _ = 1.0f64.floor(); | ^^^^^^^^^^^^^^ help: remove the `floor` method call: `1.0f64` error: used the `round` method with a whole number float - --> tests/ui/unused_rounding.rs:8:13 + --> tests/ui/unused_rounding.rs:10:13 | LL | let _ = 1.00f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32` error: used the `round` method with a whole number float - --> tests/ui/unused_rounding.rs:14:13 + --> tests/ui/unused_rounding.rs:17: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 - --> tests/ui/unused_rounding.rs:16:13 + --> tests/ui/unused_rounding.rs:20: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_self.rs b/tests/ui/unused_self.rs index d3d06037cb49..fac0b36c33a4 100644 --- a/tests/ui/unused_self.rs +++ b/tests/ui/unused_self.rs @@ -9,25 +9,34 @@ mod unused_self { impl A { fn unused_self_move(self) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_ref(&self) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_mut_ref(&mut self) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_pin_ref(self: Pin<&Self>) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_pin_nested(self: Pin>) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_self_box(self: Box) {} - //~^ ERROR: unused `self` argument + //~^ unused_self + fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { - //~^ ERROR: unused `self` argument + //~^ unused_self + x + y } fn unused_self_class_method(&self) { - //~^ ERROR: unused `self` argument + //~^ unused_self + Self::static_method(); } diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr index 5d5f1b643a4a..e29f5f96c886 100644 --- a/tests/ui/unused_self.stderr +++ b/tests/ui/unused_self.stderr @@ -9,7 +9,7 @@ LL | fn unused_self_move(self) {} = help: to override `-D warnings` add `#[allow(clippy::unused_self)]` error: unused `self` argument - --> tests/ui/unused_self.rs:13:28 + --> tests/ui/unused_self.rs:14:28 | LL | fn unused_self_ref(&self) {} | ^^^^^ @@ -17,7 +17,7 @@ LL | fn unused_self_ref(&self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:15:32 + --> tests/ui/unused_self.rs:17:32 | LL | fn unused_self_mut_ref(&mut self) {} | ^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn unused_self_mut_ref(&mut self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:17:32 + --> tests/ui/unused_self.rs:20:32 | LL | fn unused_self_pin_ref(self: Pin<&Self>) {} | ^^^^ @@ -33,7 +33,7 @@ LL | fn unused_self_pin_ref(self: Pin<&Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:19:36 + --> tests/ui/unused_self.rs:23:36 | LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} | ^^^^ @@ -41,7 +41,7 @@ LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:21:35 + --> tests/ui/unused_self.rs:26:35 | LL | fn unused_self_pin_nested(self: Pin>) {} | ^^^^ @@ -49,7 +49,7 @@ LL | fn unused_self_pin_nested(self: Pin>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:23:28 + --> tests/ui/unused_self.rs:29:28 | LL | fn unused_self_box(self: Box) {} | ^^^^ @@ -57,7 +57,7 @@ LL | fn unused_self_box(self: Box) {} = help: consider refactoring to an associated function error: unused `self` argument - --> tests/ui/unused_self.rs:25:40 + --> tests/ui/unused_self.rs:32:40 | LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { | ^^^^^ @@ -65,7 +65,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 - --> tests/ui/unused_self.rs:29:37 + --> tests/ui/unused_self.rs:37:37 | LL | fn unused_self_class_method(&self) { | ^^^^^ diff --git a/tests/ui/unused_trait_names.fixed b/tests/ui/unused_trait_names.fixed index 7dfd0db65aa1..17e32ddfd9d9 100644 --- a/tests/ui/unused_trait_names.fixed +++ b/tests/ui/unused_trait_names.fixed @@ -10,6 +10,7 @@ fn main() {} fn bad() { use std::any::Any as _; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -29,6 +30,7 @@ fn used_good() { fn multi_bad() { use std::any::{self, Any as _, TypeId}; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -41,12 +43,14 @@ fn multi_good() { fn renamed_bad() { use std::any::Any as _; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } fn multi_renamed_bad() { use std::any::{Any as _, TypeId as MyTypeId}; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -70,6 +74,7 @@ mod used_mod_good { mod mod_import_bad { fn mod_import_bad() { use std::any::Any as _; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -111,6 +116,7 @@ mod nested_mod_used_good3 { mod nested_mod_used_bad { use std::any::Any as _; + //~^ unused_trait_names fn bar() { println!("{:?}", "foo".type_id()); @@ -130,6 +136,7 @@ mod nested_mod_used_bad { // the code would still compile. mod nested_mod_used_bad1 { use std::any::Any as _; + //~^ unused_trait_names use std::any::Any as MyAny; @@ -189,6 +196,7 @@ fn msrv_1_32() { #[clippy::msrv = "1.33"] fn msrv_1_33() { use simple_trait::{MyStruct, MyTrait as _}; + //~^ unused_trait_names MyStruct.do_things(); } @@ -196,6 +204,7 @@ mod lint_inside_macro_expansion_bad { macro_rules! foo { () => { use std::any::Any as _; + //~^ unused_trait_names fn bar() { "bar".type_id(); } @@ -243,6 +252,7 @@ proc_macros::with_span!( #[warn(unused)] mod unused_import { + //~^ ERROR: unused import } #[allow(clippy::unused_trait_names)] diff --git a/tests/ui/unused_trait_names.rs b/tests/ui/unused_trait_names.rs index ce44eedbc79c..3cf8597e5351 100644 --- a/tests/ui/unused_trait_names.rs +++ b/tests/ui/unused_trait_names.rs @@ -10,6 +10,7 @@ fn main() {} fn bad() { use std::any::Any; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -29,6 +30,7 @@ fn used_good() { fn multi_bad() { use std::any::{self, Any, TypeId}; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -41,12 +43,14 @@ fn multi_good() { fn renamed_bad() { use std::any::Any as MyAny; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } fn multi_renamed_bad() { use std::any::{Any as MyAny, TypeId as MyTypeId}; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -70,6 +74,7 @@ mod used_mod_good { mod mod_import_bad { fn mod_import_bad() { use std::any::Any; + //~^ unused_trait_names println!("{:?}", "foo".type_id()); } @@ -111,6 +116,7 @@ mod nested_mod_used_good3 { mod nested_mod_used_bad { use std::any::Any; + //~^ unused_trait_names fn bar() { println!("{:?}", "foo".type_id()); @@ -130,6 +136,7 @@ mod nested_mod_used_bad { // the code would still compile. mod nested_mod_used_bad1 { use std::any::Any; + //~^ unused_trait_names use std::any::Any as MyAny; @@ -189,6 +196,7 @@ fn msrv_1_32() { #[clippy::msrv = "1.33"] fn msrv_1_33() { use simple_trait::{MyStruct, MyTrait}; + //~^ unused_trait_names MyStruct.do_things(); } @@ -196,6 +204,7 @@ mod lint_inside_macro_expansion_bad { macro_rules! foo { () => { use std::any::Any; + //~^ unused_trait_names fn bar() { "bar".type_id(); } @@ -243,6 +252,7 @@ proc_macros::with_span!( #[warn(unused)] mod unused_import { use std::any::Any; + //~^ ERROR: unused import } #[allow(clippy::unused_trait_names)] diff --git a/tests/ui/unused_trait_names.stderr b/tests/ui/unused_trait_names.stderr index f59d8f58a170..3183289d8533 100644 --- a/tests/ui/unused_trait_names.stderr +++ b/tests/ui/unused_trait_names.stderr @@ -1,5 +1,5 @@ error: unused import: `std::any::Any` - --> tests/ui/unused_trait_names.rs:245:9 + --> tests/ui/unused_trait_names.rs:254:9 | LL | use std::any::Any; | ^^^^^^^^^^^^^ @@ -17,49 +17,49 @@ LL | use std::any::Any; = help: to override `-D warnings` add `#[allow(clippy::unused_trait_names)]` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:31:26 + --> tests/ui/unused_trait_names.rs:32:26 | LL | use std::any::{self, Any, TypeId}; | ^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:43:19 + --> tests/ui/unused_trait_names.rs:45:19 | LL | use std::any::Any as MyAny; | ^^^^^^^^^^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:49:20 + --> tests/ui/unused_trait_names.rs:52:20 | LL | use std::any::{Any as MyAny, TypeId as MyTypeId}; | ^^^^^^^^^^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:72:23 + --> tests/ui/unused_trait_names.rs:76:23 | LL | use std::any::Any; | ^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:113:19 + --> tests/ui/unused_trait_names.rs:118:19 | LL | use std::any::Any; | ^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:132:19 + --> tests/ui/unused_trait_names.rs:138:19 | LL | use std::any::Any; | ^^^ help: use: `Any as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:191:34 + --> tests/ui/unused_trait_names.rs:198:34 | LL | use simple_trait::{MyStruct, MyTrait}; | ^^^^^^^ help: use: `MyTrait as _` error: importing trait that is only used anonymously - --> tests/ui/unused_trait_names.rs:198:27 + --> tests/ui/unused_trait_names.rs:206:27 | LL | use std::any::Any; | ^^^ help: use: `Any as _` diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed index 04fe2d3b7af1..e3c02681c9fd 100644 --- a/tests/ui/unused_unit.fixed +++ b/tests/ui/unused_unit.fixed @@ -18,8 +18,12 @@ struct Unitter; impl Unitter { #[allow(clippy::no_effect)] pub fn get_unit(&self, f: F, _g: G) + //~^ unused_unit + //~| unused_unit where G: Fn() { + //~^ unused_unit let _y: &dyn Fn() = &f; + //~^ unused_unit (); // this should not lint, as it's not in return type position } } @@ -27,25 +31,35 @@ impl Unitter { impl Into<()> for Unitter { #[rustfmt::skip] fn into(self) { + //~^ unused_unit + //~^ unused_unit } } trait Trait { fn redundant(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where G: FnMut(), + //~^ unused_unit H: Fn(); + //~^ unused_unit } impl Trait for Unitter { fn redundant(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where G: FnMut(), + //~^ unused_unit H: Fn() {} + //~^ unused_unit } fn return_unit() { } +//~^ unused_unit +//~| unused_unit #[allow(clippy::needless_return)] #[allow(clippy::never_loop)] @@ -56,8 +70,10 @@ fn main() { return_unit(); loop { break; + //~^ unused_unit } return; + //~^ unused_unit } // https://github.com/rust-lang/rust-clippy/issues/4076 @@ -75,12 +91,15 @@ fn foo() { #[rustfmt::skip] fn test(){} +//~^ unused_unit #[rustfmt::skip] fn test2(){} +//~^ unused_unit #[rustfmt::skip] fn test3(){} +//~^ unused_unit fn macro_expr() { macro_rules! e { diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index 25c2ed59873a..4353026c594c 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -18,8 +18,12 @@ struct Unitter; impl Unitter { #[allow(clippy::no_effect)] pub fn get_unit (), G>(&self, f: F, _g: G) -> () + //~^ unused_unit + //~| unused_unit where G: Fn() -> () { + //~^ unused_unit let _y: &dyn Fn() -> () = &f; + //~^ unused_unit (); // this should not lint, as it's not in return type position } } @@ -27,25 +31,35 @@ impl Unitter { impl Into<()> for Unitter { #[rustfmt::skip] fn into(self) -> () { + //~^ unused_unit () + //~^ unused_unit } } trait Trait { fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where G: FnMut() -> (), + //~^ unused_unit H: Fn() -> (); + //~^ unused_unit } impl Trait for Unitter { fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) + //~^ unused_unit where G: FnMut() -> (), + //~^ unused_unit H: Fn() -> () {} + //~^ unused_unit } fn return_unit() -> () { () } +//~^ unused_unit +//~| unused_unit #[allow(clippy::needless_return)] #[allow(clippy::never_loop)] @@ -56,8 +70,10 @@ fn main() { return_unit(); loop { break(); + //~^ unused_unit } return(); + //~^ unused_unit } // https://github.com/rust-lang/rust-clippy/issues/4076 @@ -75,12 +91,15 @@ fn foo() { #[rustfmt::skip] fn test()->(){} +//~^ unused_unit #[rustfmt::skip] fn test2() ->(){} +//~^ unused_unit #[rustfmt::skip] fn test3()-> (){} +//~^ unused_unit fn macro_expr() { macro_rules! e { diff --git a/tests/ui/unused_unit.stderr b/tests/ui/unused_unit.stderr index 104159ad5fc6..172fe0655028 100644 --- a/tests/ui/unused_unit.stderr +++ b/tests/ui/unused_unit.stderr @@ -17,49 +17,31 @@ LL | pub fn get_unit (), G>(&self, f: F, _g: G) -> () | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:21:18 + --> tests/ui/unused_unit.rs:23:18 | LL | where G: Fn() -> () { | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:22:26 + --> tests/ui/unused_unit.rs:25:26 | LL | let _y: &dyn Fn() -> () = &f; | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:29:18 + --> tests/ui/unused_unit.rs:33:18 | LL | fn into(self) -> () { | ^^^^^^ help: remove the `-> ()` error: unneeded unit expression - --> tests/ui/unused_unit.rs:30:9 + --> tests/ui/unused_unit.rs:35:9 | LL | () | ^^ help: remove the final `()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:35:29 - | -LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> tests/ui/unused_unit.rs:37:19 - | -LL | G: FnMut() -> (), - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> tests/ui/unused_unit.rs:38:16 - | -LL | H: Fn() -> (); - | ^^^^^^ help: remove the `-> ()` - -error: unneeded unit return type - --> tests/ui/unused_unit.rs:42:29 + --> tests/ui/unused_unit.rs:41:29 | LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) | ^^^^^^ help: remove the `-> ()` @@ -71,49 +53,67 @@ LL | G: FnMut() -> (), | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:45:16 + --> tests/ui/unused_unit.rs:46:16 + | +LL | H: Fn() -> (); + | ^^^^^^ help: remove the `-> ()` + +error: unneeded unit return type + --> tests/ui/unused_unit.rs:51:29 + | +LL | fn redundant (), G, H>(&self, _f: F, _g: G, _h: H) + | ^^^^^^ help: remove the `-> ()` + +error: unneeded unit return type + --> tests/ui/unused_unit.rs:54:19 + | +LL | G: FnMut() -> (), + | ^^^^^^ help: remove the `-> ()` + +error: unneeded unit return type + --> tests/ui/unused_unit.rs:56:16 | LL | H: Fn() -> () {} | ^^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:48:17 + --> tests/ui/unused_unit.rs:60:17 | LL | fn return_unit() -> () { () } | ^^^^^^ help: remove the `-> ()` error: unneeded unit expression - --> tests/ui/unused_unit.rs:48:26 + --> tests/ui/unused_unit.rs:60:26 | LL | fn return_unit() -> () { () } | ^^ help: remove the final `()` error: unneeded `()` - --> tests/ui/unused_unit.rs:58:14 + --> tests/ui/unused_unit.rs:72:14 | LL | break(); | ^^ help: remove the `()` error: unneeded `()` - --> tests/ui/unused_unit.rs:60:11 + --> tests/ui/unused_unit.rs:75:11 | LL | return(); | ^^ help: remove the `()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:77:10 + --> tests/ui/unused_unit.rs:93:10 | LL | fn test()->(){} | ^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:80:11 + --> tests/ui/unused_unit.rs:97:11 | LL | fn test2() ->(){} | ^^^^^ help: remove the `-> ()` error: unneeded unit return type - --> tests/ui/unused_unit.rs:83:11 + --> tests/ui/unused_unit.rs:101:11 | LL | fn test3()-> (){} | ^^^^^ help: remove the `-> ()` diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs index 8ad7e98503bf..637d2da3750e 100644 --- a/tests/ui/unwrap.rs +++ b/tests/ui/unwrap.rs @@ -4,15 +4,18 @@ fn unwrap_option() { let opt = Some(0); let _ = opt.unwrap(); - //~^ ERROR: used `unwrap()` on an `Option` value + //~^ unwrap_used + } fn unwrap_result() { let res: Result = Ok(0); let _ = res.unwrap(); - //~^ ERROR: used `unwrap()` on a `Result` value + //~^ unwrap_used + let _ = res.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on a `Result` value + //~^ unwrap_used + } fn main() { diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 3c1b37bc3d9b..c568d8308200 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -10,7 +10,7 @@ LL | let _ = opt.unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `unwrap()` on a `Result` value - --> tests/ui/unwrap.rs:12:13 + --> tests/ui/unwrap.rs:13:13 | LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _ = res.unwrap(); = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value - --> tests/ui/unwrap.rs:14:13 + --> tests/ui/unwrap.rs:16:13 | LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index bab99f2ffbdd..c2c9db775370 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -25,9 +25,11 @@ impl OptionExt for Option { fn main() { Some(3).unwrap(); - //~^ ERROR: used `unwrap()` on an `Option` value + //~^ unwrap_used + Some(3).expect("Hello world!"); - //~^ ERROR: used `expect()` on an `Option` value + //~^ expect_used + // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); @@ -43,13 +45,16 @@ fn main() { let a: Result = Ok(3); a.unwrap(); - //~^ ERROR: used `unwrap()` on a `Result` value + //~^ unwrap_used + a.expect("Hello world!"); - //~^ ERROR: used `expect()` on a `Result` value + //~^ expect_used + a.unwrap_err(); - //~^ ERROR: used `unwrap_err()` on a `Result` value + //~^ unwrap_used + a.expect_err("Hello error!"); - //~^ ERROR: used `expect_err()` on a `Result` value + //~^ expect_used // Don't trigger in compile time contexts by default const SOME: Option = Some(3); diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index 9069522a4df1..7476e372bcbb 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -9,7 +9,7 @@ LL | Some(3).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `expect()` on an `Option` value - --> tests/ui/unwrap_expect_used.rs:29:5 + --> tests/ui/unwrap_expect_used.rs:30:5 | LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | Some(3).expect("Hello world!"); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `unwrap()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:45:5 + --> tests/ui/unwrap_expect_used.rs:47:5 | LL | a.unwrap(); | ^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | a.unwrap(); = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:47:5 + --> tests/ui/unwrap_expect_used.rs:50:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL | a.expect("Hello world!"); = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:49:5 + --> tests/ui/unwrap_expect_used.rs:53:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | a.unwrap_err(); = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:51:5 + --> tests/ui/unwrap_expect_used.rs:56:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_in_result.rs b/tests/ui/unwrap_in_result.rs index 62c6d959c84b..58235d138658 100644 --- a/tests/ui/unwrap_in_result.rs +++ b/tests/ui/unwrap_in_result.rs @@ -20,7 +20,8 @@ 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 + //~^ unwrap_in_result + // checks whether a string represents a number divisible by 3 let i = i_str.parse::().unwrap(); if i % 3 == 0 { @@ -31,7 +32,8 @@ impl A { } fn example_option_expect(i_str: String) -> Option { - //~^ ERROR: used unwrap or expect in a function that returns result or option + //~^ unwrap_in_result + let i = i_str.parse::().expect("not a number"); if i % 3 == 0 { return Some(true); @@ -40,6 +42,7 @@ impl A { } fn in_closure(a: Option) -> Option { + //~^ unwrap_in_result let c = || a.unwrap(); Some(c()) } diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr index 201d4ae36ae3..5e3eab813e07 100644 --- a/tests/ui/unwrap_in_result.stderr +++ b/tests/ui/unwrap_in_result.stderr @@ -2,16 +2,13 @@ error: used unwrap or expect in a function that returns result or option --> tests/ui/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 | | } | |_____^ | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> tests/ui/unwrap_in_result.rs:25:17 + --> tests/ui/unwrap_in_result.rs:26:17 | LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,12 +16,12 @@ LL | let i = i_str.parse::().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_in_result)]` error: used unwrap or expect in a function that returns result or option - --> tests/ui/unwrap_in_result.rs:33:5 + --> tests/ui/unwrap_in_result.rs:34:5 | LL | / fn example_option_expect(i_str: String) -> Option { LL | | +LL | | LL | | let i = i_str.parse::().expect("not a number"); -LL | | if i % 3 == 0 { ... | LL | | None LL | | } @@ -32,15 +29,16 @@ LL | | } | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> tests/ui/unwrap_in_result.rs:35:17 + --> tests/ui/unwrap_in_result.rs:37:17 | LL | let i = i_str.parse::().expect("not a number"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used unwrap or expect in a function that returns result or option - --> tests/ui/unwrap_in_result.rs:42:5 + --> tests/ui/unwrap_in_result.rs:44:5 | LL | / fn in_closure(a: Option) -> Option { +LL | | LL | | let c = || a.unwrap(); LL | | Some(c()) LL | | } @@ -48,7 +46,7 @@ LL | | } | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> tests/ui/unwrap_in_result.rs:43:20 + --> tests/ui/unwrap_in_result.rs:46:20 | LL | let c = || a.unwrap(); | ^^^^^^^^^^ diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index 62bc1966da6f..7a00d346cac5 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -3,11 +3,13 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: function call inside of `unwrap_or` - //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` + //~^ or_fun_call + + } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: function call inside of `unwrap_or` + //~^ or_fun_call + } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index e8e4b6b7168f..30779ac1b109 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -3,11 +3,13 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: function call inside of `unwrap_or` - //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` + //~^ or_fun_call + + } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: function call inside of `unwrap_or` + //~^ or_fun_call + } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index b712f8cf693d..b2c20a9e9b5e 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -8,7 +8,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: function call inside of `unwrap_or` - --> tests/ui/unwrap_or.rs:11:47 + --> tests/ui/unwrap_or.rs:12: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/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 8d5d34175c52..561cbce473de 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -44,6 +44,7 @@ fn unwrap_or_else_default() { let with_new = Some(vec![1]); with_new.unwrap_or_default(); + //~^ unwrap_or_default let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); @@ -58,43 +59,56 @@ fn unwrap_or_else_default() { let with_real_default = None::; with_real_default.unwrap_or_default(); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let with_default_type: Option> = None; with_default_type.unwrap_or_default(); + //~^ unwrap_or_default let empty_string = None::; empty_string.unwrap_or_default(); + //~^ unwrap_or_default } fn type_certainty(option: Option>) { option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option: std::option::Option> = None; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option: Option> = None; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option = std::option::Option::>::None; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option = Option::>::None; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option = std::option::Option::None::>; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option = Option::None::>; option.unwrap_or_default().push(1); + //~^ unwrap_or_default let option = None::>; option.unwrap_or_default().push(1); + //~^ unwrap_or_default // should not be changed: type annotation with infer, unconcretized initializer let option: Option> = None; @@ -111,6 +125,7 @@ fn type_certainty(option: Option>) { type Alias = Option>; let option: Alias = Option::>::Some(Vec::new()); option.unwrap_or_default().push(1); + //~^ unwrap_or_default } fn method_call_with_deref() { @@ -128,6 +143,7 @@ fn method_call_with_deref() { let inner_map = outer_map.get_mut(&option.unwrap()).unwrap(); let _ = inner_map.entry(0).or_default(); + //~^ unwrap_or_default } fn missing_suggested_method() { diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index adbcb4b44659..8389be964fe6 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -44,6 +44,7 @@ fn unwrap_or_else_default() { let with_new = Some(vec![1]); with_new.unwrap_or_else(Vec::new); + //~^ unwrap_or_default let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); @@ -58,43 +59,56 @@ fn unwrap_or_else_default() { let with_real_default = None::; with_real_default.unwrap_or_else(::default); + //~^ unwrap_or_default let with_default_trait = Some(1); with_default_trait.unwrap_or_else(Default::default); + //~^ unwrap_or_default let with_default_type = Some(1); with_default_type.unwrap_or_else(u64::default); + //~^ unwrap_or_default let with_default_type: Option> = None; with_default_type.unwrap_or_else(Vec::new); + //~^ unwrap_or_default let empty_string = None::; empty_string.unwrap_or_else(|| "".to_string()); + //~^ unwrap_or_default } fn type_certainty(option: Option>) { option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option: std::option::Option> = None; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option: Option> = None; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option = std::option::Option::>::None; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option = Option::>::None; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option = std::option::Option::None::>; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option = Option::None::>; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default let option = None::>; option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default // should not be changed: type annotation with infer, unconcretized initializer let option: Option> = None; @@ -111,6 +125,7 @@ fn type_certainty(option: Option>) { type Alias = Option>; let option: Alias = Option::>::Some(Vec::new()); option.unwrap_or_else(Vec::new).push(1); + //~^ unwrap_or_default } fn method_call_with_deref() { @@ -128,6 +143,7 @@ fn method_call_with_deref() { let inner_map = outer_map.get_mut(&option.unwrap()).unwrap(); let _ = inner_map.entry(0).or_insert_with(Default::default); + //~^ unwrap_or_default } fn missing_suggested_method() { diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index e4b4a0a1f6aa..a001f7e46add 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -8,47 +8,35 @@ LL | with_new.unwrap_or_else(Vec::new); = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:60:23 + --> tests/ui/unwrap_or_else_default.rs:61:23 | LL | with_real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:63:24 + --> tests/ui/unwrap_or_else_default.rs:65:24 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:66:23 + --> tests/ui/unwrap_or_else_default.rs:69:23 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:69:23 + --> tests/ui/unwrap_or_else_default.rs:73:23 | LL | with_default_type.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:72:18 + --> tests/ui/unwrap_or_else_default.rs:77:18 | LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs: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 - --> tests/ui/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 --> tests/ui/unwrap_or_else_default.rs:82:12 | @@ -56,19 +44,13 @@ LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:85:12 + --> tests/ui/unwrap_or_else_default.rs:86:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs: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 - --> tests/ui/unwrap_or_else_default.rs:91:12 + --> tests/ui/unwrap_or_else_default.rs:90:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -80,19 +62,37 @@ LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:97:12 + --> tests/ui/unwrap_or_else_default.rs:98:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:113:12 + --> tests/ui/unwrap_or_else_default.rs:102:12 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` + +error: use of `unwrap_or_else` to construct default value + --> tests/ui/unwrap_or_else_default.rs:106:12 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` + +error: use of `unwrap_or_else` to construct default value + --> tests/ui/unwrap_or_else_default.rs:110:12 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` + +error: use of `unwrap_or_else` to construct default value + --> tests/ui/unwrap_or_else_default.rs:127:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/unwrap_or_else_default.rs:130:32 + --> tests/ui/unwrap_or_else_default.rs:145: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 index a8023ed00d21..b8c10b370680 100644 --- a/tests/ui/upper_case_acronyms.fixed +++ b/tests/ui/upper_case_acronyms.fixed @@ -7,22 +7,30 @@ 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` + //~^ upper_case_acronyms + + Ece, - //~^ ERROR: name `ECE` contains a capitalized acronym + //~^ upper_case_acronyms + Urg, - //~^ ERROR: name `URG` contains a capitalized acronym + //~^ upper_case_acronyms + Ack, - //~^ ERROR: name `ACK` contains a capitalized acronym + //~^ upper_case_acronyms + Psh, - //~^ ERROR: name `PSH` contains a capitalized acronym + //~^ upper_case_acronyms + Rst, - //~^ ERROR: name `RST` contains a capitalized acronym + //~^ upper_case_acronyms + Syn, - //~^ ERROR: name `SYN` contains a capitalized acronym + //~^ upper_case_acronyms + Fin, - //~^ ERROR: name `FIN` contains a capitalized acronym + //~^ upper_case_acronyms + } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -43,18 +51,21 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { Wasd(u8), - //~^ ERROR: name `WASD` contains a capitalized acronym + //~^ upper_case_acronyms + Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct Json; -//~^ ERROR: name `JSON` contains a capitalized acronym +//~^ upper_case_acronyms + // do lint here enum Yaml { - //~^ ERROR: name `YAML` contains a capitalized acronym +//~^ upper_case_acronyms + Num(u32), Str(String), } @@ -62,7 +73,8 @@ enum Yaml { // test for issue #7708 enum AllowOnField { Disallow, - //~^ ERROR: name `DISALLOW` contains a capitalized acronym + //~^ upper_case_acronyms + #[allow(clippy::upper_case_acronyms)] ALLOW, } diff --git a/tests/ui/upper_case_acronyms.rs b/tests/ui/upper_case_acronyms.rs index c4711b87ec38..4ad6c6d4c8c8 100644 --- a/tests/ui/upper_case_acronyms.rs +++ b/tests/ui/upper_case_acronyms.rs @@ -7,22 +7,30 @@ 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` + //~^ upper_case_acronyms + + ECE, - //~^ ERROR: name `ECE` contains a capitalized acronym + //~^ upper_case_acronyms + URG, - //~^ ERROR: name `URG` contains a capitalized acronym + //~^ upper_case_acronyms + ACK, - //~^ ERROR: name `ACK` contains a capitalized acronym + //~^ upper_case_acronyms + PSH, - //~^ ERROR: name `PSH` contains a capitalized acronym + //~^ upper_case_acronyms + RST, - //~^ ERROR: name `RST` contains a capitalized acronym + //~^ upper_case_acronyms + SYN, - //~^ ERROR: name `SYN` contains a capitalized acronym + //~^ upper_case_acronyms + FIN, - //~^ ERROR: name `FIN` contains a capitalized acronym + //~^ upper_case_acronyms + } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -43,18 +51,21 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { WASD(u8), - //~^ ERROR: name `WASD` contains a capitalized acronym + //~^ upper_case_acronyms + Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct JSON; -//~^ ERROR: name `JSON` contains a capitalized acronym +//~^ upper_case_acronyms + // do lint here enum YAML { - //~^ ERROR: name `YAML` contains a capitalized acronym +//~^ upper_case_acronyms + Num(u32), Str(String), } @@ -62,7 +73,8 @@ enum YAML { // test for issue #7708 enum AllowOnField { DISALLOW, - //~^ ERROR: name `DISALLOW` contains a capitalized acronym + //~^ upper_case_acronyms + #[allow(clippy::upper_case_acronyms)] ALLOW, } diff --git a/tests/ui/upper_case_acronyms.stderr b/tests/ui/upper_case_acronyms.stderr index 1f8046c8e841..24e1d808d8ed 100644 --- a/tests/ui/upper_case_acronyms.stderr +++ b/tests/ui/upper_case_acronyms.stderr @@ -8,67 +8,67 @@ LL | CWR, = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `ECE` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:12:5 + --> tests/ui/upper_case_acronyms.rs:13:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:14:5 + --> tests/ui/upper_case_acronyms.rs:16:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:16:5 + --> tests/ui/upper_case_acronyms.rs:19:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:18:5 + --> tests/ui/upper_case_acronyms.rs:22:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:20:5 + --> tests/ui/upper_case_acronyms.rs:25:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:22:5 + --> tests/ui/upper_case_acronyms.rs:28:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:24:5 + --> tests/ui/upper_case_acronyms.rs:31:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `WASD` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:45:5 + --> tests/ui/upper_case_acronyms.rs:53:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `JSON` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:52:8 + --> tests/ui/upper_case_acronyms.rs:61:8 | LL | struct JSON; | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json` error: name `YAML` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:56:6 + --> tests/ui/upper_case_acronyms.rs:66:6 | LL | enum YAML { | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml` error: name `DISALLOW` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:64:5 + --> tests/ui/upper_case_acronyms.rs:75:5 | LL | DISALLOW, | ^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `Disallow` diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index b44840d440b2..faabf0e256db 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -21,16 +21,22 @@ mod use_self { impl Foo { fn new() -> Self { + //~^ use_self Self {} + //~^ use_self } fn test() -> Self { + //~^ use_self Self::new() + //~^ use_self } } impl Default for Foo { fn default() -> Self { + //~^ use_self Self::new() + //~^ use_self } } } @@ -72,6 +78,7 @@ mod lifetimes { } fn clone(&self) -> Self { + //~^ use_self Foo { foo_str: self.foo_str } } @@ -105,6 +112,8 @@ mod existential { impl Foo { fn bad(foos: &[Self]) -> impl Iterator { + //~^ use_self + //~| use_self foos.iter() } @@ -120,6 +129,7 @@ mod tuple_structs { impl TS { pub fn ts() -> Self { Self(0) + //~^ use_self } } } @@ -155,7 +165,9 @@ mod nesting { impl Bar { fn bar() -> Self { + //~^ use_self Self { foo: Foo {} } + //~^ use_self } } @@ -167,7 +179,9 @@ mod nesting { // Should lint here fn baz() -> Self { + //~^ use_self Self {} + //~^ use_self } } @@ -185,8 +199,11 @@ mod nesting { fn method2() { let _ = Self::B(42); + //~^ use_self let _ = Self::C { field: true }; + //~^ use_self let _ = Self::A; + //~^ use_self } } } @@ -229,9 +246,12 @@ mod rustfix { fn fun_2() { Self::fun_1(); + //~^ use_self Self::A; + //~^ use_self Self {}; + //~^ use_self } } } @@ -251,6 +271,7 @@ mod issue3567 { impl Test for TestStruct { fn test() -> TestStruct { Self::from_something() + //~^ use_self } } } @@ -265,11 +286,15 @@ mod paths_created_by_lowering { const B: usize = 1; async fn g() -> Self { + //~^ use_self Self {} + //~^ use_self } fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { &p[Self::A..Self::B] + //~^ use_self + //~| use_self } } @@ -293,7 +318,9 @@ mod generics { impl Foo { // `Self` is applicable here fn foo(value: T) -> Self { + //~^ use_self Self { value } + //~^ use_self } // `Cannot` use `Self` as a return type as the generic types are different @@ -466,6 +493,7 @@ mod nested_paths { impl A { fn test() -> Self { Self::new::(submod::B {}) + //~^ use_self } } } @@ -503,6 +531,7 @@ mod issue7206 { impl<'a> S2> { fn new_again() -> Self { Self::new() + //~^ use_self } } } @@ -540,13 +569,16 @@ mod use_self_in_pat { fn do_stuff(self) { match self { Self::Bar => unimplemented!(), + //~^ use_self Self::Baz => unimplemented!(), + //~^ use_self } match Some(1) { Some(_) => unimplemented!(), None => unimplemented!(), } if let Self::Bar = self { + //~^ use_self unimplemented!() } } @@ -571,16 +603,22 @@ mod issue8845 { fn get_value(&self) -> u8 { match self { Self::Num(n) => *n, + //~^ use_self Self::TupleNums(n, _m) => *n, + //~^ use_self Self::StructNums { one, two: _ } => *one, + //~^ use_self } } fn use_crate(&self) -> u8 { match self { Self::Num(n) => *n, + //~^ use_self Self::TupleNums(n, _m) => *n, + //~^ use_self Self::StructNums { one, two: _ } => *one, + //~^ use_self } } @@ -597,11 +635,13 @@ mod issue8845 { impl Foo { fn get_value(&self) -> u8 { let Self(x) = self; + //~^ use_self *x } fn use_crate(&self) -> u8 { let Self(x) = self; + //~^ use_self *x } } @@ -609,11 +649,13 @@ mod issue8845 { impl Bar { fn get_value(&self) -> u8 { let Self { x, .. } = self; + //~^ use_self *x } fn use_crate(&self) -> u8 { let Self { x, .. } = self; + //~^ use_self *x } } @@ -653,6 +695,7 @@ fn msrv_1_37() { fn foo(self) { match self { Self::A => {}, + //~^ use_self } } } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 342c724c8e48..b91856e48097 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -21,16 +21,22 @@ mod use_self { impl Foo { fn new() -> Foo { + //~^ use_self Foo {} + //~^ use_self } fn test() -> Foo { + //~^ use_self Foo::new() + //~^ use_self } } impl Default for Foo { fn default() -> Foo { + //~^ use_self Foo::new() + //~^ use_self } } } @@ -72,6 +78,7 @@ mod lifetimes { } fn clone(&self) -> Foo<'a> { + //~^ use_self Foo { foo_str: self.foo_str } } @@ -105,6 +112,8 @@ mod existential { impl Foo { fn bad(foos: &[Foo]) -> impl Iterator { + //~^ use_self + //~| use_self foos.iter() } @@ -120,6 +129,7 @@ mod tuple_structs { impl TS { pub fn ts() -> Self { TS(0) + //~^ use_self } } } @@ -155,7 +165,9 @@ mod nesting { impl Bar { fn bar() -> Bar { + //~^ use_self Bar { foo: Foo {} } + //~^ use_self } } @@ -167,7 +179,9 @@ mod nesting { // Should lint here fn baz() -> Foo { + //~^ use_self Foo {} + //~^ use_self } } @@ -185,8 +199,11 @@ mod nesting { fn method2() { let _ = Enum::B(42); + //~^ use_self let _ = Enum::C { field: true }; + //~^ use_self let _ = Enum::A; + //~^ use_self } } } @@ -229,9 +246,12 @@ mod rustfix { fn fun_2() { nested::A::fun_1(); + //~^ use_self nested::A::A; + //~^ use_self nested::A {}; + //~^ use_self } } } @@ -251,6 +271,7 @@ mod issue3567 { impl Test for TestStruct { fn test() -> TestStruct { TestStruct::from_something() + //~^ use_self } } } @@ -265,11 +286,15 @@ mod paths_created_by_lowering { const B: usize = 1; async fn g() -> S { + //~^ use_self S {} + //~^ use_self } fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] { &p[S::A..S::B] + //~^ use_self + //~| use_self } } @@ -293,7 +318,9 @@ mod generics { impl Foo { // `Self` is applicable here fn foo(value: T) -> Foo { + //~^ use_self Foo:: { value } + //~^ use_self } // `Cannot` use `Self` as a return type as the generic types are different @@ -466,6 +493,7 @@ mod nested_paths { impl A { fn test() -> Self { A::new::(submod::B {}) + //~^ use_self } } } @@ -503,6 +531,7 @@ mod issue7206 { impl<'a> S2> { fn new_again() -> Self { S2::new() + //~^ use_self } } } @@ -540,13 +569,16 @@ mod use_self_in_pat { fn do_stuff(self) { match self { Foo::Bar => unimplemented!(), + //~^ use_self Foo::Baz => unimplemented!(), + //~^ use_self } match Some(1) { Some(_) => unimplemented!(), None => unimplemented!(), } if let Foo::Bar = self { + //~^ use_self unimplemented!() } } @@ -571,16 +603,22 @@ mod issue8845 { fn get_value(&self) -> u8 { match self { Something::Num(n) => *n, + //~^ use_self Something::TupleNums(n, _m) => *n, + //~^ use_self Something::StructNums { one, two: _ } => *one, + //~^ use_self } } fn use_crate(&self) -> u8 { match self { crate::issue8845::Something::Num(n) => *n, + //~^ use_self crate::issue8845::Something::TupleNums(n, _m) => *n, + //~^ use_self crate::issue8845::Something::StructNums { one, two: _ } => *one, + //~^ use_self } } @@ -597,11 +635,13 @@ mod issue8845 { impl Foo { fn get_value(&self) -> u8 { let Foo(x) = self; + //~^ use_self *x } fn use_crate(&self) -> u8 { let crate::issue8845::Foo(x) = self; + //~^ use_self *x } } @@ -609,11 +649,13 @@ mod issue8845 { impl Bar { fn get_value(&self) -> u8 { let Bar { x, .. } = self; + //~^ use_self *x } fn use_crate(&self) -> u8 { let crate::issue8845::Bar { x, .. } = self; + //~^ use_self *x } } @@ -653,6 +695,7 @@ fn msrv_1_37() { fn foo(self) { match self { E::A => {}, + //~^ use_self } } } diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index bd5b685b45d5..781327696ac1 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -8,253 +8,253 @@ LL | fn new() -> Foo { = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:24:13 + --> tests/ui/use_self.rs:25:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:26:22 + --> tests/ui/use_self.rs:28:22 | LL | fn test() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:27:13 + --> tests/ui/use_self.rs:30:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:32:25 + --> tests/ui/use_self.rs:36:25 | LL | fn default() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:33:13 + --> tests/ui/use_self.rs:38:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:74:28 + --> tests/ui/use_self.rs:80:28 | LL | fn clone(&self) -> Foo<'a> { | ^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:107:24 + --> tests/ui/use_self.rs:114:24 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:107:55 + --> tests/ui/use_self.rs:114:55 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:122:13 + --> tests/ui/use_self.rs:131:13 | LL | TS(0) | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:157:29 + --> tests/ui/use_self.rs:167:29 | LL | fn bar() -> Bar { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:158:21 + --> tests/ui/use_self.rs:169:21 | LL | Bar { foo: Foo {} } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:169:21 + --> tests/ui/use_self.rs:181:21 | LL | fn baz() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:170:13 + --> tests/ui/use_self.rs:183:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:187:21 + --> tests/ui/use_self.rs:201:21 | LL | let _ = Enum::B(42); | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:188:21 + --> tests/ui/use_self.rs:203:21 | LL | let _ = Enum::C { field: true }; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:189:21 + --> tests/ui/use_self.rs:205:21 | LL | let _ = Enum::A; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:231:13 + --> tests/ui/use_self.rs:248:13 | LL | nested::A::fun_1(); | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:232:13 + --> tests/ui/use_self.rs:250:13 | LL | nested::A::A; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:234:13 + --> tests/ui/use_self.rs:253:13 | LL | nested::A {}; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:253:13 + --> tests/ui/use_self.rs:273:13 | LL | TestStruct::from_something() | ^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:267:25 + --> tests/ui/use_self.rs:288:25 | LL | async fn g() -> S { | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:268:13 + --> tests/ui/use_self.rs:290:13 | LL | S {} | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:272:16 + --> tests/ui/use_self.rs:295:16 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:272:22 + --> tests/ui/use_self.rs:295:22 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:295:29 + --> tests/ui/use_self.rs:320:29 | LL | fn foo(value: T) -> Foo { | ^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:296:13 + --> tests/ui/use_self.rs:322:13 | LL | Foo:: { value } | ^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:468:13 + --> tests/ui/use_self.rs:495:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:505:13 + --> tests/ui/use_self.rs:533:13 | LL | S2::new() | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:542:17 + --> tests/ui/use_self.rs:571:17 | LL | Foo::Bar => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:543:17 + --> tests/ui/use_self.rs:573:17 | LL | Foo::Baz => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:549:20 + --> tests/ui/use_self.rs:580:20 | LL | if let Foo::Bar = self { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:573:17 + --> tests/ui/use_self.rs:605:17 | LL | Something::Num(n) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:574:17 + --> tests/ui/use_self.rs:607:17 | LL | Something::TupleNums(n, _m) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:575:17 + --> tests/ui/use_self.rs:609:17 | LL | Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:581:17 + --> tests/ui/use_self.rs:616:17 | LL | crate::issue8845::Something::Num(n) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:582:17 + --> tests/ui/use_self.rs:618:17 | LL | crate::issue8845::Something::TupleNums(n, _m) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:583:17 + --> tests/ui/use_self.rs:620:17 | LL | crate::issue8845::Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:599:17 + --> tests/ui/use_self.rs:637:17 | LL | let Foo(x) = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:604:17 + --> tests/ui/use_self.rs:643:17 | LL | let crate::issue8845::Foo(x) = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:611:17 + --> tests/ui/use_self.rs:651:17 | LL | let Bar { x, .. } = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:616:17 + --> tests/ui/use_self.rs:657:17 | LL | let crate::issue8845::Bar { x, .. } = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:655:17 + --> tests/ui/use_self.rs:697: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 2758ec7aca1f..2df7eec92f2f 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -17,28 +17,42 @@ struct Bad; impl SelfTrait for Bad { fn refs(p1: &Self) -> &Self { + //~^ use_self + //~| use_self p1 } fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { + //~^ use_self + //~| use_self p1 } fn mut_refs(p1: &mut Self) -> &mut Self { + //~^ use_self + //~| use_self p1 } fn nested(_p1: Box, _p2: (&u8, &Self)) {} + //~^ use_self + //~| use_self fn vals(_: Self) -> Self { + //~^ use_self + //~| use_self Self + //~^ use_self } } impl Mul for Bad { type Output = Self; + //~^ use_self fn mul(self, rhs: Self) -> Self { + //~^ use_self + //~| use_self rhs } } @@ -46,6 +60,7 @@ impl Mul for Bad { impl Clone for Bad { fn clone(&self) -> Self { Self + //~^ use_self } } @@ -143,6 +158,7 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { Self // Should lint + //~^ use_self } } } diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index 31031e8f50b2..48118e59fe67 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -17,28 +17,42 @@ struct Bad; impl SelfTrait for Bad { fn refs(p1: &Bad) -> &Bad { + //~^ use_self + //~| use_self p1 } fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { + //~^ use_self + //~| use_self p1 } fn mut_refs(p1: &mut Bad) -> &mut Bad { + //~^ use_self + //~| use_self p1 } fn nested(_p1: Box, _p2: (&u8, &Bad)) {} + //~^ use_self + //~| use_self fn vals(_: Bad) -> Bad { + //~^ use_self + //~| use_self Bad + //~^ use_self } } impl Mul for Bad { type Output = Bad; + //~^ use_self fn mul(self, rhs: Bad) -> Bad { + //~^ use_self + //~| use_self rhs } } @@ -46,6 +60,7 @@ impl Mul for Bad { impl Clone for Bad { fn clone(&self) -> Self { Bad + //~^ use_self } } @@ -143,6 +158,7 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { std::fmt::Error // Should lint + //~^ use_self } } } diff --git a/tests/ui/use_self_trait.stderr b/tests/ui/use_self_trait.stderr index 9cbb728ebe66..1b664b3b7a28 100644 --- a/tests/ui/use_self_trait.stderr +++ b/tests/ui/use_self_trait.stderr @@ -14,85 +14,85 @@ LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:23:33 + --> tests/ui/use_self_trait.rs:25:33 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:23:49 + --> tests/ui/use_self_trait.rs:25:49 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:27:26 + --> tests/ui/use_self_trait.rs:31:26 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:27:39 + --> tests/ui/use_self_trait.rs:31:39 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:31:24 + --> tests/ui/use_self_trait.rs:37:24 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:31:42 + --> tests/ui/use_self_trait.rs:37:42 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:33:16 + --> tests/ui/use_self_trait.rs:41:16 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:33:24 + --> tests/ui/use_self_trait.rs:41:24 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:34:9 + --> tests/ui/use_self_trait.rs:44:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:39:19 + --> tests/ui/use_self_trait.rs:50:19 | LL | type Output = Bad; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:41:23 + --> tests/ui/use_self_trait.rs:53:23 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:41:31 + --> tests/ui/use_self_trait.rs:53:31 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:48:9 + --> tests/ui/use_self_trait.rs:62:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self_trait.rs:145:13 + --> tests/ui/use_self_trait.rs:160:13 | LL | std::fmt::Error // Should lint | ^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index 84dccf28f3b2..3b063fd16be1 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -21,12 +21,16 @@ macro_rules! test_macro { /// Tests that we lint if we use a binding with a single leading underscore fn prefix_underscore(_foo: u32) -> u32 { _foo + 1 + //~^ used_underscore_binding } /// Tests that we lint if we use a `_`-variable defined outside within a macro expansion fn in_macro_or_desugar(_foo: u32) { println!("{}", _foo); + //~^ used_underscore_binding assert_eq!(_foo, _foo); + //~^ used_underscore_binding + //~| used_underscore_binding test_macro!() + 1; } @@ -40,6 +44,7 @@ struct StructFieldTest { fn in_struct_field() { let mut s = StructFieldTest { _underscore_field: 0 }; s._underscore_field += 1; + //~^ used_underscore_binding } /// Tests that we do not lint if the struct field is used in code created with derive. @@ -101,6 +106,7 @@ async fn await_desugaring() { ({ let _i = 5; uses_i(_i); + //~^ used_underscore_binding foo() }) .await diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr index f9e8013d3ad5..7d94d79f9b3b 100644 --- a/tests/ui/used_underscore_binding.stderr +++ b/tests/ui/used_underscore_binding.stderr @@ -13,61 +13,61 @@ LL | fn prefix_underscore(_foo: u32) -> u32 { = help: to override `-D warnings` add `#[allow(clippy::used_underscore_binding)]` error: used underscore-prefixed binding - --> tests/ui/used_underscore_binding.rs:28:20 + --> tests/ui/used_underscore_binding.rs:29:20 | LL | println!("{}", _foo); | ^^^^ | note: binding is defined here - --> tests/ui/used_underscore_binding.rs:27:24 + --> tests/ui/used_underscore_binding.rs:28:24 | LL | fn in_macro_or_desugar(_foo: u32) { | ^^^^ error: used underscore-prefixed binding - --> tests/ui/used_underscore_binding.rs:29:16 + --> tests/ui/used_underscore_binding.rs:31:16 | LL | assert_eq!(_foo, _foo); | ^^^^ | note: binding is defined here - --> tests/ui/used_underscore_binding.rs:27:24 + --> tests/ui/used_underscore_binding.rs:28:24 | LL | fn in_macro_or_desugar(_foo: u32) { | ^^^^ error: used underscore-prefixed binding - --> tests/ui/used_underscore_binding.rs:29:22 + --> tests/ui/used_underscore_binding.rs:31:22 | LL | assert_eq!(_foo, _foo); | ^^^^ | note: binding is defined here - --> tests/ui/used_underscore_binding.rs:27:24 + --> tests/ui/used_underscore_binding.rs:28:24 | LL | fn in_macro_or_desugar(_foo: u32) { | ^^^^ error: used underscore-prefixed binding - --> tests/ui/used_underscore_binding.rs:42:5 + --> tests/ui/used_underscore_binding.rs:46:5 | LL | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ | note: binding is defined here - --> tests/ui/used_underscore_binding.rs:36:5 + --> tests/ui/used_underscore_binding.rs:40:5 | LL | _underscore_field: u32, | ^^^^^^^^^^^^^^^^^^^^^^ error: used underscore-prefixed binding - --> tests/ui/used_underscore_binding.rs:103:16 + --> tests/ui/used_underscore_binding.rs:108:16 | LL | uses_i(_i); | ^^ | note: binding is defined here - --> tests/ui/used_underscore_binding.rs:102:13 + --> tests/ui/used_underscore_binding.rs:107:13 | LL | let _i = 5; | ^^ diff --git a/tests/ui/used_underscore_items.rs b/tests/ui/used_underscore_items.rs index ed76f4e68dc9..3401df6ae743 100644 --- a/tests/ui/used_underscore_items.rs +++ b/tests/ui/used_underscore_items.rs @@ -41,16 +41,25 @@ mod a { fn main() { _foo1(); + //~^ used_underscore_items let _ = _foo2(); + //~^ used_underscore_items a::b::c::_foo3(); + //~^ used_underscore_items let _ = &_FooStruct {}; + //~^ used_underscore_items let _ = _FooStruct {}; + //~^ used_underscore_items let foo_struct = _FooStruct {}; + //~^ used_underscore_items foo_struct._method_call(); + //~^ used_underscore_items let foo_struct2 = a::b::c::_FooStruct2 {}; + //~^ used_underscore_items foo_struct2._method_call(); + //~^ used_underscore_items } // should not lint exteranl crate. diff --git a/tests/ui/used_underscore_items.stderr b/tests/ui/used_underscore_items.stderr index 93ac3a6fec6b..d6e23f1e726a 100644 --- a/tests/ui/used_underscore_items.stderr +++ b/tests/ui/used_underscore_items.stderr @@ -13,7 +13,7 @@ LL | fn _foo1() {} = help: to override `-D warnings` add `#[allow(clippy::used_underscore_items)]` error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:44:13 + --> tests/ui/used_underscore_items.rs:45:13 | LL | let _ = _foo2(); | ^^^^^^^ @@ -25,7 +25,7 @@ LL | fn _foo2() -> i32 { | ^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:45:5 + --> tests/ui/used_underscore_items.rs:47:5 | LL | a::b::c::_foo3(); | ^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | pub fn _foo3() {} | ^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:46:14 + --> tests/ui/used_underscore_items.rs:49:14 | LL | let _ = &_FooStruct {}; | ^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | struct _FooStruct {} | ^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:47:13 + --> tests/ui/used_underscore_items.rs:51:13 | LL | let _ = _FooStruct {}; | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | struct _FooStruct {} | ^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:49:22 + --> tests/ui/used_underscore_items.rs:54:22 | LL | let foo_struct = _FooStruct {}; | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | struct _FooStruct {} | ^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:50:5 + --> tests/ui/used_underscore_items.rs:56:5 | LL | foo_struct._method_call(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | fn _method_call(self) {} | ^^^^^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:52:23 + --> tests/ui/used_underscore_items.rs:59:23 | LL | let foo_struct2 = a::b::c::_FooStruct2 {}; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | pub struct _FooStruct2 {} | ^^^^^^^^^^^^^^^^^^^^^^ error: used underscore-prefixed item - --> tests/ui/used_underscore_items.rs:53:5 + --> tests/ui/used_underscore_items.rs:61:5 | LL | foo_struct2._method_call(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useful_asref.rs b/tests/ui/useful_asref.rs index d17db9371ee8..a37c2785bde2 100644 --- a/tests/ui/useful_asref.rs +++ b/tests/ui/useful_asref.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![deny(clippy::useless_asref)] #![allow(clippy::needless_lifetimes)] diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index 2f179200bb37..235b49649001 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -48,14 +48,18 @@ fn not_ok() { { let rslice: &[i32] = &*mrslice; foo_rstr(rstr); + //~^ useless_asref foo_rstr(rstr); foo_rslice(rslice); + //~^ useless_asref foo_rslice(rslice); } { foo_mrslice(mrslice); + //~^ useless_asref foo_mrslice(mrslice); foo_rslice(mrslice); + //~^ useless_asref foo_rslice(mrslice); } @@ -63,19 +67,24 @@ fn not_ok() { let rrrrrstr = &&&&rstr; let rrrrrslice = &&&&&*mrslice; foo_rslice(rrrrrslice); + //~^ useless_asref foo_rslice(rrrrrslice); foo_rstr(rrrrrstr); + //~^ useless_asref foo_rstr(rrrrrstr); } { let mrrrrrslice = &mut &mut &mut &mut mrslice; foo_mrslice(mrrrrrslice); + //~^ useless_asref foo_mrslice(mrrrrrslice); foo_rslice(mrrrrrslice); + //~^ useless_asref foo_rslice(mrrrrrslice); } #[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)] foo_rrrrmr((&&&&MoreRef)); + //~^ useless_asref generic_not_ok(mrslice); generic_ok(mrslice); @@ -126,8 +135,10 @@ fn foo_rt(t: &T) { fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { foo_mrt(mrt); + //~^ useless_asref foo_mrt(mrt); foo_rt(mrt); + //~^ useless_asref foo_rt(mrt); } @@ -139,11 +150,14 @@ fn generic_ok + AsRef + ?Sized, T: Debug + ?Sized>(mru: &mut U) { fn foo() { let x = Some(String::new()); let z = x.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + let z = x.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + let z = x.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + } mod issue12135 { @@ -167,16 +181,20 @@ mod issue12135 { pub fn f(x: &Struct) -> Option { x.field.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + // https://github.com/rust-lang/rust-clippy/pull/12136#discussion_r1451565223 #[allow(clippy::clone_on_copy)] Some(1).clone(); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.as_ref().map(|v| v.method().clone()) } diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index 9851a0caac4f..261bbe18e357 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -48,14 +48,18 @@ fn not_ok() { { let rslice: &[i32] = &*mrslice; foo_rstr(rstr.as_ref()); + //~^ useless_asref foo_rstr(rstr); foo_rslice(rslice.as_ref()); + //~^ useless_asref foo_rslice(rslice); } { foo_mrslice(mrslice.as_mut()); + //~^ useless_asref foo_mrslice(mrslice); foo_rslice(mrslice.as_ref()); + //~^ useless_asref foo_rslice(mrslice); } @@ -63,19 +67,24 @@ fn not_ok() { let rrrrrstr = &&&&rstr; let rrrrrslice = &&&&&*mrslice; foo_rslice(rrrrrslice.as_ref()); + //~^ useless_asref foo_rslice(rrrrrslice); foo_rstr(rrrrrstr.as_ref()); + //~^ useless_asref foo_rstr(rrrrrstr); } { let mrrrrrslice = &mut &mut &mut &mut mrslice; foo_mrslice(mrrrrrslice.as_mut()); + //~^ useless_asref foo_mrslice(mrrrrrslice); foo_rslice(mrrrrrslice.as_ref()); + //~^ useless_asref foo_rslice(mrrrrrslice); } #[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)] foo_rrrrmr((&&&&MoreRef).as_ref()); + //~^ useless_asref generic_not_ok(mrslice); generic_ok(mrslice); @@ -126,8 +135,10 @@ fn foo_rt(t: &T) { fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { foo_mrt(mrt.as_mut()); + //~^ useless_asref foo_mrt(mrt); foo_rt(mrt.as_ref()); + //~^ useless_asref foo_rt(mrt); } @@ -139,11 +150,14 @@ fn generic_ok + AsRef + ?Sized, T: Debug + ?Sized>(mru: &mut U) { fn foo() { let x = Some(String::new()); let z = x.as_ref().map(String::clone); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + let z = x.as_ref().map(|z| z.clone()); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + let z = x.as_ref().map(|z| String::clone(z)); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + } mod issue12135 { @@ -167,16 +181,20 @@ mod issue12135 { pub fn f(x: &Struct) -> Option { x.field.as_ref().map(|v| v.clone()); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.as_ref().map(Clone::clone); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.as_ref().map(|v| Clone::clone(v)); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + // https://github.com/rust-lang/rust-clippy/pull/12136#discussion_r1451565223 #[allow(clippy::clone_on_copy)] Some(1).as_ref().map(|&x| x.clone()); - //~^ ERROR: this call to `as_ref.map(...)` does nothing + //~^ useless_asref + x.field.as_ref().map(|v| v.method().clone()) } diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index 5f495c396705..97be7996f008 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -11,103 +11,103 @@ LL | #![deny(clippy::useless_asref)] | ^^^^^^^^^^^^^^^^^^^^^ error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:52:20 + --> tests/ui/useless_asref.rs:53:20 | LL | foo_rslice(rslice.as_ref()); | ^^^^^^^^^^^^^^^ help: try: `rslice` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:56:21 + --> tests/ui/useless_asref.rs:58:21 | LL | foo_mrslice(mrslice.as_mut()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:58:20 + --> tests/ui/useless_asref.rs:61:20 | LL | foo_rslice(mrslice.as_ref()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:65:20 + --> tests/ui/useless_asref.rs:69:20 | LL | foo_rslice(rrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:67:18 + --> tests/ui/useless_asref.rs:72:18 | LL | foo_rstr(rrrrrstr.as_ref()); | ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:72:21 + --> tests/ui/useless_asref.rs:78:21 | LL | foo_mrslice(mrrrrrslice.as_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:74:20 + --> tests/ui/useless_asref.rs:81:20 | LL | foo_rslice(mrrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:78:16 + --> tests/ui/useless_asref.rs:86:16 | LL | foo_rrrrmr((&&&&MoreRef).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:128:13 + --> tests/ui/useless_asref.rs:137:13 | LL | foo_mrt(mrt.as_mut()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:130:12 + --> tests/ui/useless_asref.rs:140:12 | LL | foo_rt(mrt.as_ref()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:141:13 + --> tests/ui/useless_asref.rs:152:13 | LL | let z = x.as_ref().map(String::clone); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:143:13 + --> tests/ui/useless_asref.rs:155:13 | LL | let z = x.as_ref().map(|z| z.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:145:13 + --> tests/ui/useless_asref.rs:158:13 | LL | let z = x.as_ref().map(|z| String::clone(z)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:169:9 + --> tests/ui/useless_asref.rs:183:9 | LL | x.field.as_ref().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:171:9 + --> tests/ui/useless_asref.rs:186:9 | LL | x.field.as_ref().map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:173:9 + --> tests/ui/useless_asref.rs:189:9 | LL | x.field.as_ref().map(|v| Clone::clone(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:178:9 + --> tests/ui/useless_asref.rs:195:9 | LL | Some(1).as_ref().map(|&x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(1).clone()` diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index de1062f123b7..a96c8f46f551 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -6,7 +6,9 @@ #![feature(rustc_private)] #![allow(dead_code)] +//~^ useless_attribute #![cfg_attr(clippy, allow(dead_code))] +//~^ useless_attribute #[rustfmt::skip] #[allow(unused_imports)] #[allow(unused_extern_crates)] @@ -18,6 +20,7 @@ extern crate proc_macro_derive; fn test_indented_attr() { #![allow(clippy::almost_swapped)] + //~^ useless_attribute use std::collections::HashSet; let _ = HashSet::::default(); diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 94657dd1ca37..b26410134bbb 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -6,7 +6,9 @@ #![feature(rustc_private)] #[allow(dead_code)] +//~^ useless_attribute #[cfg_attr(clippy, allow(dead_code))] +//~^ useless_attribute #[rustfmt::skip] #[allow(unused_imports)] #[allow(unused_extern_crates)] @@ -18,6 +20,7 @@ extern crate proc_macro_derive; fn test_indented_attr() { #[allow(clippy::almost_swapped)] + //~^ useless_attribute use std::collections::HashSet; let _ = HashSet::::default(); diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index 19f0e02de680..91383adf994b 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -8,13 +8,13 @@ LL | #[allow(dead_code)] = help: to override `-D warnings` add `#[allow(clippy::useless_attribute)]` error: useless lint attribute - --> tests/ui/useless_attribute.rs:9:1 + --> tests/ui/useless_attribute.rs:10:1 | LL | #[cfg_attr(clippy, allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(clippy, allow(dead_code)` error: useless lint attribute - --> tests/ui/useless_attribute.rs:20:5 + --> tests/ui/useless_attribute.rs:22: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 697d437b3885..2b9ef0209047 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -7,7 +7,9 @@ use std::ops::ControlFlow; fn test_generic(val: T) -> T { let _ = val; + //~^ useless_conversion val + //~^ useless_conversion } fn test_generic2 + Into, U: From>(val: T) { @@ -20,6 +22,7 @@ fn test_generic2 + Into, U: From>(val: T) { fn test_questionmark() -> Result<(), ()> { { let _: i32 = 0i32; + //~^ useless_conversion Ok(Ok(())) }??; Ok(()) @@ -50,28 +53,33 @@ fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines(); if Some("ok") == lines.next() {} + //~^ useless_conversion } fn lint_into_iter_on_expr_implementing_iterator() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines(); + //~^ useless_conversion if Some("ok") == lines.next() {} } fn lint_into_iter_on_expr_implementing_iterator_2() { let text = "foo\r\nbar\n\nbaz\n"; if Some("ok") == text.lines().next() {} + //~^ useless_conversion } #[allow(const_item_mutation)] fn lint_into_iter_on_const_implementing_iterator() { const NUMBERS: std::ops::Range = 0..10; let _ = NUMBERS.next(); + //~^ useless_conversion } fn lint_into_iter_on_const_implementing_iterator_2() { const NUMBERS: std::ops::Range = 0..10; let mut n = NUMBERS; + //~^ useless_conversion n.next(); } @@ -134,27 +142,38 @@ fn main() { } let _: String = "foo".to_string(); + //~^ useless_conversion let _: String = "foo".to_string(); + //~^ useless_conversion let _ = "foo".to_string(); + //~^ useless_conversion let _ = format!("A: {:04}", 123); + //~^ useless_conversion let _ = "".lines(); + //~^ useless_conversion let _ = vec![1, 2, 3].into_iter(); + //~^ useless_conversion let _: String = format!("Hello {}", "world"); + //~^ useless_conversion // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = (a + b) * 3; + //~^ useless_conversion // see #7205 let s: Foo<'a'> = Foo; let _: Foo<'b'> = s.into(); let s2: Foo<'a'> = Foo; let _: Foo<'a'> = s2; + //~^ useless_conversion let s3: Foo<'a'> = Foo; let _ = s3; + //~^ useless_conversion let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter(); + //~^ useless_conversion issue11300::bar(); } @@ -187,12 +206,17 @@ fn explicit_into_iter_fn_arg() { a(vec![1, 2].into_iter()); b(vec![1, 2]); + //~^ useless_conversion c(vec![1, 2]); + //~^ useless_conversion d(vec![1, 2]); + //~^ useless_conversion b([&1, &2, &3].into_iter().cloned()); b(vec![1, 2]); + //~^ useless_conversion b(vec![1, 2]); + //~^ useless_conversion macro_rules! macro_generated { () => { @@ -239,6 +263,7 @@ mod issue11300 { // This should trigger the lint, receiver type [i32; 3] also implements `Helper` foo2::([1, 2, 3]); + //~^ useless_conversion // This again should *not* lint, since X = () and I = std::array::IntoIter, // and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter: Helper<()>` is). @@ -247,6 +272,7 @@ mod issue11300 { // This should lint. Removing the `.into_iter()` means that `I` gets substituted with `[i32; 3]`, // and `i32: Helper2<[i32, 3]>` is true, so this call is indeed unnecessary. foo3([1, 2, 3]); + //~^ useless_conversion } fn ice() { @@ -256,6 +282,7 @@ mod issue11300 { } S1.foo([1, 2]); + //~^ useless_conversion // ICE that occurred in itertools trait Itertools { @@ -275,6 +302,7 @@ mod issue11300 { let v0: Vec = vec![0, 2, 4]; let v1: Vec = vec![1, 3, 5, 7]; v0.into_iter().interleave_shortest(v1); + //~^ useless_conversion trait TraitWithLifetime<'a> {} impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} @@ -303,19 +331,25 @@ impl From> for Foo<'b'> { fn direct_application() { let _: Result<(), std::io::Error> = test_issue_3913(); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913(); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913(); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913(); //~^ useless_conversion + + let c: ControlFlow<()> = ControlFlow::Continue(()); + let _: ControlFlow<()> = c; + //~^ useless_conversion + let c: ControlFlow<()> = ControlFlow::Continue(()); let _: ControlFlow<()> = c; //~^ useless_conversion - let c: ControlFlow<()> = ControlFlow::Continue(()); - let _: ControlFlow<()> = c; - //~^ useless_conversion + struct Absorb; impl From<()> for Absorb { @@ -331,6 +365,7 @@ fn direct_application() { let _: Vec = [1u32].into_iter().collect(); //~^ useless_conversion + // No lint for those let _: Result = test_issue_3913().map(Into::into); let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into); @@ -341,6 +376,7 @@ fn direct_application() { fn gen_identity(x: [T; 3]) -> Vec { x.into_iter().collect() //~^ useless_conversion + } mod issue11819 { @@ -357,6 +393,7 @@ mod issue11819 { { takes_into_iter(&self.my_field); //~^ useless_conversion + } pub fn with_ref_mut<'a>(&'a mut self) @@ -365,6 +402,7 @@ mod issue11819 { { takes_into_iter(&mut self.my_field); //~^ useless_conversion + } pub fn with_deref(&mut self) @@ -374,6 +412,7 @@ mod issue11819 { { takes_into_iter(*self.my_field); //~^ useless_conversion + } pub fn with_reborrow<'a, Y: 'a>(&'a mut self) @@ -383,6 +422,7 @@ mod issue11819 { { takes_into_iter(&*self.my_field); //~^ useless_conversion + } pub fn with_reborrow_mut<'a, Y: 'a>(&'a mut self) @@ -392,6 +432,7 @@ mod issue11819 { { takes_into_iter(&mut *self.my_field); //~^ useless_conversion + } } } diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 4d8ad61a8c99..84b5b12580e5 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -7,7 +7,9 @@ use std::ops::ControlFlow; fn test_generic(val: T) -> T { let _ = T::from(val); + //~^ useless_conversion val.into() + //~^ useless_conversion } fn test_generic2 + Into, U: From>(val: T) { @@ -20,6 +22,7 @@ fn test_generic2 + Into, U: From>(val: T) { fn test_questionmark() -> Result<(), ()> { { let _: i32 = 0i32.into(); + //~^ useless_conversion Ok(Ok(())) }??; Ok(()) @@ -50,28 +53,33 @@ fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines(); if Some("ok") == lines.into_iter().next() {} + //~^ useless_conversion } fn lint_into_iter_on_expr_implementing_iterator() { let text = "foo\r\nbar\n\nbaz\n"; let mut lines = text.lines().into_iter(); + //~^ useless_conversion if Some("ok") == lines.next() {} } fn lint_into_iter_on_expr_implementing_iterator_2() { let text = "foo\r\nbar\n\nbaz\n"; if Some("ok") == text.lines().into_iter().next() {} + //~^ useless_conversion } #[allow(const_item_mutation)] fn lint_into_iter_on_const_implementing_iterator() { const NUMBERS: std::ops::Range = 0..10; let _ = NUMBERS.into_iter().next(); + //~^ useless_conversion } fn lint_into_iter_on_const_implementing_iterator_2() { const NUMBERS: std::ops::Range = 0..10; let mut n = NUMBERS.into_iter(); + //~^ useless_conversion n.next(); } @@ -134,27 +142,38 @@ fn main() { } let _: String = "foo".to_string().into(); + //~^ useless_conversion let _: String = From::from("foo".to_string()); + //~^ useless_conversion let _ = String::from("foo".to_string()); + //~^ useless_conversion let _ = String::from(format!("A: {:04}", 123)); + //~^ useless_conversion let _ = "".lines().into_iter(); + //~^ useless_conversion let _ = vec![1, 2, 3].into_iter().into_iter(); + //~^ useless_conversion let _: String = format!("Hello {}", "world").into(); + //~^ useless_conversion // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = i32::from(a + b) * 3; + //~^ useless_conversion // see #7205 let s: Foo<'a'> = Foo; let _: Foo<'b'> = s.into(); let s2: Foo<'a'> = Foo; let _: Foo<'a'> = s2.into(); + //~^ useless_conversion let s3: Foo<'a'> = Foo; let _ = Foo::<'a'>::from(s3); + //~^ useless_conversion let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter().into_iter(); + //~^ useless_conversion issue11300::bar(); } @@ -187,12 +206,17 @@ fn explicit_into_iter_fn_arg() { a(vec![1, 2].into_iter()); b(vec![1, 2].into_iter()); + //~^ useless_conversion c(vec![1, 2].into_iter()); + //~^ useless_conversion d(vec![1, 2].into_iter()); + //~^ useless_conversion b([&1, &2, &3].into_iter().cloned()); b(vec![1, 2].into_iter().into_iter()); + //~^ useless_conversion b(vec![1, 2].into_iter().into_iter().into_iter()); + //~^ useless_conversion macro_rules! macro_generated { () => { @@ -239,6 +263,7 @@ mod issue11300 { // This should trigger the lint, receiver type [i32; 3] also implements `Helper` foo2::([1, 2, 3].into_iter()); + //~^ useless_conversion // This again should *not* lint, since X = () and I = std::array::IntoIter, // and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter: Helper<()>` is). @@ -247,6 +272,7 @@ mod issue11300 { // This should lint. Removing the `.into_iter()` means that `I` gets substituted with `[i32; 3]`, // and `i32: Helper2<[i32, 3]>` is true, so this call is indeed unnecessary. foo3([1, 2, 3].into_iter()); + //~^ useless_conversion } fn ice() { @@ -256,6 +282,7 @@ mod issue11300 { } S1.foo([1, 2].into_iter()); + //~^ useless_conversion // ICE that occurred in itertools trait Itertools { @@ -275,6 +302,7 @@ mod issue11300 { let v0: Vec = vec![0, 2, 4]; let v1: Vec = vec![1, 3, 5, 7]; v0.into_iter().interleave_shortest(v1.into_iter()); + //~^ useless_conversion trait TraitWithLifetime<'a> {} impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} @@ -303,20 +331,26 @@ impl From> for Foo<'b'> { fn direct_application() { let _: Result<(), std::io::Error> = test_issue_3913().map(Into::into); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913().map_err(Into::into); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913().map(From::from); //~^ useless_conversion + let _: Result<(), std::io::Error> = test_issue_3913().map_err(From::from); //~^ useless_conversion + let c: ControlFlow<()> = ControlFlow::Continue(()); let _: ControlFlow<()> = c.map_break(Into::into); //~^ useless_conversion + let c: ControlFlow<()> = ControlFlow::Continue(()); let _: ControlFlow<()> = c.map_continue(Into::into); //~^ useless_conversion + struct Absorb; impl From<()> for Absorb { fn from(_: ()) -> Self { @@ -331,6 +365,7 @@ fn direct_application() { let _: Vec = [1u32].into_iter().map(Into::into).collect(); //~^ useless_conversion + // No lint for those let _: Result = test_issue_3913().map(Into::into); let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into); @@ -341,6 +376,7 @@ fn direct_application() { fn gen_identity(x: [T; 3]) -> Vec { x.into_iter().map(Into::into).collect() //~^ useless_conversion + } mod issue11819 { @@ -357,6 +393,7 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion + } pub fn with_ref_mut<'a>(&'a mut self) @@ -365,6 +402,7 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion + } pub fn with_deref(&mut self) @@ -374,6 +412,7 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion + } pub fn with_reborrow<'a, Y: 'a>(&'a mut self) @@ -383,6 +422,7 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion + } pub fn with_reborrow_mut<'a, Y: 'a>(&'a mut self) @@ -392,6 +432,7 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion + } } } diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index ed50f3071862..39c625429c66 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -11,115 +11,115 @@ LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> tests/ui/useless_conversion.rs:10:5 + --> tests/ui/useless_conversion.rs:11:5 | LL | val.into() | ^^^^^^^^^^ help: consider removing `.into()`: `val` error: useless conversion to the same type: `i32` - --> tests/ui/useless_conversion.rs:22:22 + --> tests/ui/useless_conversion.rs:24:22 | LL | let _: i32 = 0i32.into(); | ^^^^^^^^^^^ help: consider removing `.into()`: `0i32` error: useless conversion to the same type: `std::str::Lines<'_>` - --> tests/ui/useless_conversion.rs:52:22 + --> tests/ui/useless_conversion.rs:55: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<'_>` - --> tests/ui/useless_conversion.rs:57:21 + --> tests/ui/useless_conversion.rs:61: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<'_>` - --> tests/ui/useless_conversion.rs:63:22 + --> tests/ui/useless_conversion.rs:68: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` - --> tests/ui/useless_conversion.rs:69:13 + --> tests/ui/useless_conversion.rs:75:13 | LL | let _ = NUMBERS.into_iter().next(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::ops::Range` - --> tests/ui/useless_conversion.rs:74:17 + --> tests/ui/useless_conversion.rs:81:17 | LL | let mut n = NUMBERS.into_iter(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::string::String` - --> tests/ui/useless_conversion.rs:136:21 + --> tests/ui/useless_conversion.rs:144: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` - --> tests/ui/useless_conversion.rs:137:21 + --> tests/ui/useless_conversion.rs:146: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` - --> tests/ui/useless_conversion.rs:138:13 + --> tests/ui/useless_conversion.rs:148: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` - --> tests/ui/useless_conversion.rs:139:13 + --> tests/ui/useless_conversion.rs:150: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<'_>` - --> tests/ui/useless_conversion.rs:140:13 + --> tests/ui/useless_conversion.rs:152:13 | LL | let _ = "".lines().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` error: useless conversion to the same type: `std::vec::IntoIter` - --> tests/ui/useless_conversion.rs:141:13 + --> tests/ui/useless_conversion.rs:154: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` - --> tests/ui/useless_conversion.rs:142:21 + --> tests/ui/useless_conversion.rs:156:21 | LL | let _: String = format!("Hello {}", "world").into(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")` error: useless conversion to the same type: `i32` - --> tests/ui/useless_conversion.rs:147:13 + --> tests/ui/useless_conversion.rs:162:13 | LL | let _ = i32::from(a + b) * 3; | ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)` error: useless conversion to the same type: `Foo<'a'>` - --> tests/ui/useless_conversion.rs:153:23 + --> tests/ui/useless_conversion.rs:169:23 | LL | let _: Foo<'a'> = s2.into(); | ^^^^^^^^^ help: consider removing `.into()`: `s2` error: useless conversion to the same type: `Foo<'a'>` - --> tests/ui/useless_conversion.rs:155:13 + --> tests/ui/useless_conversion.rs:172:13 | LL | let _ = Foo::<'a'>::from(s3); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3` error: useless conversion to the same type: `std::vec::IntoIter>` - --> tests/ui/useless_conversion.rs:157:13 + --> tests/ui/useless_conversion.rs:175: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` - --> tests/ui/useless_conversion.rs:189:7 + --> tests/ui/useless_conversion.rs:208:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^------------ @@ -127,13 +127,13 @@ LL | b(vec![1, 2].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:179:13 + --> tests/ui/useless_conversion.rs:198:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:190:7 + --> tests/ui/useless_conversion.rs:210:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^------------ @@ -141,13 +141,13 @@ LL | c(vec![1, 2].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:180:18 + --> tests/ui/useless_conversion.rs:199:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:191:7 + --> tests/ui/useless_conversion.rs:212:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^------------ @@ -155,13 +155,13 @@ LL | d(vec![1, 2].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:183:12 + --> tests/ui/useless_conversion.rs:202:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:194:7 + --> tests/ui/useless_conversion.rs:216:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^------------------------ @@ -169,13 +169,13 @@ LL | b(vec![1, 2].into_iter().into_iter()); | help: consider removing the `.into_iter()`s | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:179:13 + --> tests/ui/useless_conversion.rs:198:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:195:7 + --> tests/ui/useless_conversion.rs:218:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^------------------------------------ @@ -183,13 +183,13 @@ LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | help: consider removing the `.into_iter()`s | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:179:13 + --> tests/ui/useless_conversion.rs:198:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:241:24 + --> tests/ui/useless_conversion.rs:265:24 | LL | foo2::([1, 2, 3].into_iter()); | ^^^^^^^^^------------ @@ -197,13 +197,13 @@ LL | foo2::([1, 2, 3].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:220:12 + --> tests/ui/useless_conversion.rs:244:12 | LL | I: IntoIterator + Helper, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:249:14 + --> tests/ui/useless_conversion.rs:274:14 | LL | foo3([1, 2, 3].into_iter()); | ^^^^^^^^^------------ @@ -211,13 +211,13 @@ LL | foo3([1, 2, 3].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:229:12 + --> tests/ui/useless_conversion.rs:253:12 | LL | I: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:258:16 + --> tests/ui/useless_conversion.rs:284:16 | LL | S1.foo([1, 2].into_iter()); | ^^^^^^------------ @@ -225,13 +225,13 @@ LL | S1.foo([1, 2].into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:255:27 + --> tests/ui/useless_conversion.rs:281:27 | LL | pub fn foo(&self, _: I) {} | ^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:277:44 + --> tests/ui/useless_conversion.rs:304:44 | LL | v0.into_iter().interleave_shortest(v1.into_iter()); | ^^------------ @@ -239,67 +239,67 @@ LL | v0.into_iter().interleave_shortest(v1.into_iter()); | help: consider removing the `.into_iter()` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:264:20 + --> tests/ui/useless_conversion.rs:291:20 | LL | J: IntoIterator, | ^^^^^^^^^^^^ error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:304:58 + --> tests/ui/useless_conversion.rs:332:58 | LL | let _: Result<(), std::io::Error> = test_issue_3913().map(Into::into); | ^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `std::io::Error` - --> tests/ui/useless_conversion.rs:306:58 + --> tests/ui/useless_conversion.rs:335:58 | LL | let _: Result<(), std::io::Error> = test_issue_3913().map_err(Into::into); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:308:58 + --> tests/ui/useless_conversion.rs:338:58 | LL | let _: Result<(), std::io::Error> = test_issue_3913().map(From::from); | ^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `std::io::Error` - --> tests/ui/useless_conversion.rs:310:58 + --> tests/ui/useless_conversion.rs:341:58 | LL | let _: Result<(), std::io::Error> = test_issue_3913().map_err(From::from); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:314:31 + --> tests/ui/useless_conversion.rs:346:31 | LL | let _: ControlFlow<()> = c.map_break(Into::into); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:317:31 + --> tests/ui/useless_conversion.rs:350:31 | LL | let _: ControlFlow<()> = c.map_continue(Into::into); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `u32` - --> tests/ui/useless_conversion.rs:331:41 + --> tests/ui/useless_conversion.rs:365:41 | LL | let _: Vec = [1u32].into_iter().map(Into::into).collect(); | ^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `T` - --> tests/ui/useless_conversion.rs:342:18 + --> tests/ui/useless_conversion.rs:377:18 | LL | x.into_iter().map(Into::into).collect() | ^^^^^^^^^^^^^^^^ help: consider removing error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:358:29 + --> tests/ui/useless_conversion.rs:394:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:347:32 + --> tests/ui/useless_conversion.rs:383:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -310,13 +310,13 @@ LL + takes_into_iter(&self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:366:29 + --> tests/ui/useless_conversion.rs:403:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:347:32 + --> tests/ui/useless_conversion.rs:383:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -327,13 +327,13 @@ LL + takes_into_iter(&mut self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:375:29 + --> tests/ui/useless_conversion.rs:413:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:347:32 + --> tests/ui/useless_conversion.rs:383:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -344,13 +344,13 @@ LL + takes_into_iter(*self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:384:29 + --> tests/ui/useless_conversion.rs:423:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:347:32 + --> tests/ui/useless_conversion.rs:383:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,13 +361,13 @@ LL + takes_into_iter(&*self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:393:29 + --> tests/ui/useless_conversion.rs:433:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:347:32 + --> tests/ui/useless_conversion.rs:383:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useless_conversion_try.rs b/tests/ui/useless_conversion_try.rs index 23edeae12b83..7f469a819ef2 100644 --- a/tests/ui/useless_conversion_try.rs +++ b/tests/ui/useless_conversion_try.rs @@ -7,9 +7,11 @@ fn test_generic(val: T) -> T { let _ = T::try_from(val).unwrap(); - //~^ ERROR: useless conversion to the same type: `T` + //~^ useless_conversion + val.try_into().unwrap() - //~^ ERROR: useless conversion to the same type: `T` + //~^ useless_conversion + } fn test_generic2 + Into, U: From>(val: T) { @@ -32,19 +34,26 @@ 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` + //~^ useless_conversion + let _: String = TryFrom::try_from("foo".to_string()).unwrap(); - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + let _ = String::try_from("foo".to_string()).unwrap(); - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + let _: String = format!("Hello {}", "world").try_into().unwrap(); - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + let _: String = String::new().try_into().unwrap(); - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + let _: String = match String::from("_").try_into() { - //~^ ERROR: useless conversion to the same type: `std::string::String` + //~^ useless_conversion + Ok(a) => a, Err(_) => String::new(), }; diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr index 30a43629dbd6..af2199837bf7 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` - --> tests/ui/useless_conversion_try.rs:11:5 + --> tests/ui/useless_conversion_try.rs:12: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` - --> tests/ui/useless_conversion_try.rs:34:21 + --> tests/ui/useless_conversion_try.rs:36: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` - --> tests/ui/useless_conversion_try.rs:36:21 + --> tests/ui/useless_conversion_try.rs:39: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` - --> tests/ui/useless_conversion_try.rs:38:13 + --> tests/ui/useless_conversion_try.rs:42: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` - --> tests/ui/useless_conversion_try.rs:40:13 + --> tests/ui/useless_conversion_try.rs:45: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` - --> tests/ui/useless_conversion_try.rs:42:21 + --> tests/ui/useless_conversion_try.rs:48: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` - --> tests/ui/useless_conversion_try.rs:44:21 + --> tests/ui/useless_conversion_try.rs:51: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` - --> tests/ui/useless_conversion_try.rs:46:27 + --> tests/ui/useless_conversion_try.rs:54:27 | LL | let _: String = match String::from("_").try_into() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useless_nonzero_new_unchecked.fixed b/tests/ui/useless_nonzero_new_unchecked.fixed index 03b34afa54ec..8e5e105215a9 100644 --- a/tests/ui/useless_nonzero_new_unchecked.fixed +++ b/tests/ui/useless_nonzero_new_unchecked.fixed @@ -5,7 +5,8 @@ use std::num::{NonZero, NonZeroUsize}; #[clippy::msrv = "1.83"] const fn func() -> NonZeroUsize { const { NonZeroUsize::new(3).unwrap() } - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + } #[clippy::msrv = "1.82"] @@ -35,17 +36,21 @@ macro_rules! nzu { fn main() { const _A: NonZeroUsize = NonZeroUsize::new(3).unwrap(); - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + static _B: NonZero = NonZero::::new(42).unwrap(); - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const _C: usize = unsafe { NonZeroUsize::new(3).unwrap().get() }; - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const AUX: usize = 3; const _D: NonZeroUsize = NonZeroUsize::new(AUX).unwrap(); - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const _X: NonZeroUsize = uns!(NonZeroUsize::new_unchecked(3)); const _Y: NonZeroUsize = unsafe { nzu!() }; diff --git a/tests/ui/useless_nonzero_new_unchecked.rs b/tests/ui/useless_nonzero_new_unchecked.rs index d450e3a03ec5..43fd1f2e5849 100644 --- a/tests/ui/useless_nonzero_new_unchecked.rs +++ b/tests/ui/useless_nonzero_new_unchecked.rs @@ -5,7 +5,8 @@ use std::num::{NonZero, NonZeroUsize}; #[clippy::msrv = "1.83"] const fn func() -> NonZeroUsize { const { unsafe { NonZeroUsize::new_unchecked(3) } } - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + } #[clippy::msrv = "1.82"] @@ -35,17 +36,21 @@ macro_rules! nzu { fn main() { const _A: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + static _B: NonZero = unsafe { NonZero::::new_unchecked(42) }; - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const AUX: usize = 3; const _D: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(AUX) }; - //~^ ERROR: `Option::unwrap()` can be safely used in a `const` context + //~^ useless_nonzero_new_unchecked + const _X: NonZeroUsize = uns!(NonZeroUsize::new_unchecked(3)); const _Y: NonZeroUsize = unsafe { nzu!() }; diff --git a/tests/ui/useless_nonzero_new_unchecked.stderr b/tests/ui/useless_nonzero_new_unchecked.stderr index adb146167633..b9fc333dd4f5 100644 --- a/tests/ui/useless_nonzero_new_unchecked.stderr +++ b/tests/ui/useless_nonzero_new_unchecked.stderr @@ -8,19 +8,19 @@ LL | const { unsafe { NonZeroUsize::new_unchecked(3) } } = help: to override `-D warnings` add `#[allow(clippy::useless_nonzero_new_unchecked)]` error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:37:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:38:30 | LL | const _A: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(3).unwrap()` error: `NonZero::::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:40:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:42:30 | LL | static _B: NonZero = unsafe { NonZero::::new_unchecked(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZero::::new(42).unwrap()` error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:43:32 + --> tests/ui/useless_nonzero_new_unchecked.rs:46:32 | LL | const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(3).unwrap()` @@ -28,7 +28,7 @@ LL | const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; = note: the fixed expression does not require an `unsafe` context error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:47:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:51:30 | LL | const _D: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(AUX) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(AUX).unwrap()` diff --git a/tests/ui/useless_vec.rs b/tests/ui/useless_vec.rs index 880809f81d7a..65aafb66568f 100644 --- a/tests/ui/useless_vec.rs +++ b/tests/ui/useless_vec.rs @@ -6,7 +6,8 @@ fn foo() { // There should be no suggestion in this case. let _some_variable = vec![ - //~^ useless_vec + //~^ useless_vec + 1, 2, // i'm here to stay 3, 4, // but this one going away ;-; ]; // that is life anyways diff --git a/tests/ui/useless_vec.stderr b/tests/ui/useless_vec.stderr index e47364fb06d3..39927d0b4654 100644 --- a/tests/ui/useless_vec.stderr +++ b/tests/ui/useless_vec.stderr @@ -4,6 +4,7 @@ error: useless use of `vec!` LL | let _some_variable = vec![ | __________________________^ LL | | +LL | | LL | | 1, 2, // i'm here to stay LL | | 3, 4, // but this one going away ;-; LL | | ]; // that is life anyways diff --git a/tests/ui/vec.fixed b/tests/ui/vec.fixed index 9e755a82af45..5b35b2b26243 100644 --- a/tests/ui/vec.fixed +++ b/tests/ui/vec.fixed @@ -28,24 +28,34 @@ impl Line { fn main() { on_slice(&[]); + //~^ useless_vec on_slice(&[]); on_mut_slice(&mut []); + //~^ useless_vec on_slice(&[1, 2]); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut [1, 2]); + //~^ useless_vec on_slice(&[1, 2]); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut [1, 2]); + //~^ useless_vec #[rustfmt::skip] on_slice(&[1, 2]); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut [1, 2]); + //~^ useless_vec on_slice(&[1; 2]); + //~^ useless_vec on_slice(&[1; 2]); on_mut_slice(&mut [1; 2]); + //~^ useless_vec on_vec(&vec![]); on_vec(&vec![1, 2]); @@ -72,17 +82,21 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 let _x: i32 = [1, 2, 3].iter().sum(); + //~^ useless_vec // Do lint let mut x = [1, 2, 3]; + //~^ useless_vec x.fill(123); dbg!(x[0]); dbg!(x.len()); dbg!(x.iter().sum::()); let _x: &[i32] = &[1, 2, 3]; + //~^ useless_vec for _ in [1, 2, 3] {} + //~^ useless_vec // Don't lint let x = vec![1, 2, 3]; @@ -122,6 +136,7 @@ fn issue11075() { } #[allow(clippy::never_loop)] for _string in [repro!(true), repro!(null)] { + //~^ useless_vec unimplemented!(); } @@ -139,6 +154,8 @@ fn issue11075() { } in_macro!(1, [1, 2], [1; 2]); + //~^ useless_vec + //~| useless_vec macro_rules! from_macro { () => { @@ -158,10 +175,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { for a in [1, 2, 3] { + //~^ useless_vec let _: usize = a; } for a in [String::new(), String::new()] { + //~^ useless_vec let _: String = a; } } @@ -193,7 +212,8 @@ fn issue11861() { // Do not lint the next line this_macro_needs_vec!(vec![1]); - this_macro_doesnt_need_vec!([1]); //~ ERROR: useless use of `vec!` +this_macro_doesnt_need_vec!([1]); +//~^ useless_vec macro_rules! m { ($x:expr) => { @@ -220,4 +240,5 @@ fn issue_11958() { fn issue_12101() { for a in &[1, 2] {} + //~^ useless_vec } diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index c483271438b1..c82580b2fd1a 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -28,24 +28,34 @@ impl Line { fn main() { on_slice(&vec![]); + //~^ useless_vec on_slice(&[]); on_mut_slice(&mut vec![]); + //~^ useless_vec on_slice(&vec![1, 2]); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut vec![1, 2]); + //~^ useless_vec on_slice(&vec![1, 2]); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut vec![1, 2]); + //~^ useless_vec #[rustfmt::skip] on_slice(&vec!(1, 2)); + //~^ useless_vec on_slice(&[1, 2]); on_mut_slice(&mut vec![1, 2]); + //~^ useless_vec on_slice(&vec![1; 2]); + //~^ useless_vec on_slice(&[1; 2]); on_mut_slice(&mut vec![1; 2]); + //~^ useless_vec on_vec(&vec![]); on_vec(&vec![1, 2]); @@ -72,17 +82,21 @@ fn main() { // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 let _x: i32 = vec![1, 2, 3].iter().sum(); + //~^ useless_vec // Do lint let mut x = vec![1, 2, 3]; + //~^ useless_vec x.fill(123); dbg!(x[0]); dbg!(x.len()); dbg!(x.iter().sum::()); let _x: &[i32] = &vec![1, 2, 3]; + //~^ useless_vec for _ in vec![1, 2, 3] {} + //~^ useless_vec // Don't lint let x = vec![1, 2, 3]; @@ -122,6 +136,7 @@ fn issue11075() { } #[allow(clippy::never_loop)] for _string in vec![repro!(true), repro!(null)] { + //~^ useless_vec unimplemented!(); } @@ -139,6 +154,8 @@ fn issue11075() { } in_macro!(1, vec![1, 2], vec![1; 2]); + //~^ useless_vec + //~| useless_vec macro_rules! from_macro { () => { @@ -158,10 +175,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { for a in vec![1, 2, 3] { + //~^ useless_vec let _: usize = a; } for a in vec![String::new(), String::new()] { + //~^ useless_vec let _: String = a; } } @@ -193,7 +212,8 @@ fn issue11861() { // Do not lint the next line this_macro_needs_vec!(vec![1]); - this_macro_doesnt_need_vec!(vec![1]); //~ ERROR: useless use of `vec!` +this_macro_doesnt_need_vec!(vec![1]); +//~^ useless_vec macro_rules! m { ($x:expr) => { @@ -220,4 +240,5 @@ fn issue_11958() { fn issue_12101() { for a in &(vec![1, 2]) {} + //~^ useless_vec } diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index 3faea8033fe2..1063e0e37d89 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -8,31 +8,19 @@ LL | on_slice(&vec![]); = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` error: useless use of `vec!` - --> tests/ui/vec.rs:32:18 + --> tests/ui/vec.rs:33:18 | LL | on_mut_slice(&mut vec![]); | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` error: useless use of `vec!` - --> tests/ui/vec.rs:34:14 + --> tests/ui/vec.rs:36:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:36:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:38:14 - | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:40:18 + --> tests/ui/vec.rs:39:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` @@ -40,89 +28,101 @@ LL | on_mut_slice(&mut vec![1, 2]); error: useless use of `vec!` --> tests/ui/vec.rs:42:14 | -LL | on_slice(&vec!(1, 2)); +LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:44:18 + --> tests/ui/vec.rs:45:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:46:14 + --> tests/ui/vec.rs:48:14 + | +LL | on_slice(&vec!(1, 2)); + | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` + +error: useless use of `vec!` + --> tests/ui/vec.rs:51:18 + | +LL | on_mut_slice(&mut vec![1, 2]); + | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` + +error: useless use of `vec!` + --> tests/ui/vec.rs:54:14 | LL | on_slice(&vec![1; 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:48:18 + --> tests/ui/vec.rs:57:18 | LL | on_mut_slice(&mut vec![1; 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:74:19 + --> tests/ui/vec.rs:84:19 | LL | let _x: i32 = vec![1, 2, 3].iter().sum(); | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:77:17 + --> tests/ui/vec.rs:88:17 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:83:22 + --> tests/ui/vec.rs:95:22 | LL | let _x: &[i32] = &vec![1, 2, 3]; | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:85:14 + --> tests/ui/vec.rs:98:14 | LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:124:20 + --> tests/ui/vec.rs:138:20 | LL | for _string in vec![repro!(true), repro!(null)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` error: useless use of `vec!` - --> tests/ui/vec.rs:141:18 + --> tests/ui/vec.rs:156:18 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:141:30 + --> tests/ui/vec.rs:156:30 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:160:14 + --> tests/ui/vec.rs:177:14 | LL | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:164:14 + --> tests/ui/vec.rs:182:14 | LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` error: useless use of `vec!` - --> tests/ui/vec.rs:196:33 + --> tests/ui/vec.rs:215:29 | -LL | this_macro_doesnt_need_vec!(vec![1]); - | ^^^^^^^ help: you can use an array directly: `[1]` +LL | this_macro_doesnt_need_vec!(vec![1]); + | ^^^^^^^ help: you can use an array directly: `[1]` error: useless use of `vec!` - --> tests/ui/vec.rs:222:14 + --> tests/ui/vec.rs:242:14 | LL | for a in &(vec![1, 2]) {} | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs index 49eaf8e062af..d32081c26a03 100644 --- a/tests/ui/vec_box_sized.rs +++ b/tests/ui/vec_box_sized.rs @@ -24,22 +24,30 @@ unsafe impl Allocator for DummyAllocator { mod should_trigger { use super::{DummyAllocator, SizedStruct}; const C: Vec> = Vec::new(); + //~^ vec_box static S: Vec> = Vec::new(); + //~^ vec_box struct StructWithVecBox { sized_type: Vec>, + //~^ vec_box } struct A(Vec>); + //~^ vec_box struct B(Vec>>); + //~^ vec_box fn allocator_global_defined_vec() -> Vec, std::alloc::Global> { + //~^ vec_box Vec::new() } fn allocator_global_defined_box() -> Vec> { + //~^ vec_box Vec::new() } fn allocator_match() -> Vec, DummyAllocator> { + //~^ vec_box Vec::new_in(DummyAllocator) } } @@ -77,6 +85,7 @@ mod inner_mod { use super::inner::S; pub fn f() -> Vec> { + //~^ vec_box vec![] } } diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr index 0ffcc8314340..65db267977a6 100644 --- a/tests/ui/vec_box_sized.stderr +++ b/tests/ui/vec_box_sized.stderr @@ -8,49 +8,49 @@ LL | const C: Vec> = Vec::new(); = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:27:15 + --> tests/ui/vec_box_sized.rs:28:15 | LL | static S: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:30:21 + --> tests/ui/vec_box_sized.rs:32:21 | LL | sized_type: Vec>, | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:33:14 + --> tests/ui/vec_box_sized.rs:36:14 | LL | struct A(Vec>); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:34:18 + --> tests/ui/vec_box_sized.rs:38:18 | LL | struct B(Vec>>); | ^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:36:42 + --> tests/ui/vec_box_sized.rs:41:42 | LL | fn allocator_global_defined_vec() -> Vec, std::alloc::Global> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:39:42 + --> tests/ui/vec_box_sized.rs:45:42 | LL | fn allocator_global_defined_box() -> Vec> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:42:29 + --> tests/ui/vec_box_sized.rs:49:29 | LL | fn allocator_match() -> Vec, DummyAllocator> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui/vec_box_sized.rs:79:23 + --> tests/ui/vec_box_sized.rs:87: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 1c60a75c56ae..31cd84d2cf40 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -3,16 +3,19 @@ //@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` + //~^ vec_init_then_push + + def_err.push(0); let mut new_err = Vec::::new(); - //~^ ERROR: calls to `push` immediately after creation + //~^ vec_init_then_push + new_err.push(1); let mut cap_err = Vec::with_capacity(2); - //~^ ERROR: calls to `push` immediately after creation + //~^ vec_init_then_push + cap_err.push(0); cap_err.push(1); cap_err.push(2); @@ -25,7 +28,8 @@ fn main() { cap_ok.push(0); new_err = Vec::new(); - //~^ ERROR: calls to `push` immediately after creation + //~^ vec_init_then_push + new_err.push(0); let mut vec = Vec::new(); @@ -76,7 +80,8 @@ 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 + //~^ vec_init_then_push + v.push(x); v.push(1); v[0] = v[1] + 5; @@ -85,7 +90,8 @@ 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 + //~^ vec_init_then_push + v.push(0); v.push(1); v.push(0); @@ -99,7 +105,8 @@ fn _cond_push_with_large_start(x: bool) -> Vec { } let mut v2 = Vec::new(); - //~^ ERROR: calls to `push` immediately after creation + //~^ vec_init_then_push + v2.push(0); v2.push(1); v2.push(0); @@ -115,7 +122,8 @@ fn _cond_push_with_large_start(x: bool) -> Vec { fn f() { let mut v = Vec::new(); - //~^ ERROR: calls to `push` immediately after creation + //~^ vec_init_then_push + 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 f35625c9b085..3be277bb07b9 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -10,69 +10,71 @@ LL | | def_err.push(0); = help: to override `-D warnings` add `#[allow(clippy::vec_init_then_push)]` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:10:5 + --> tests/ui/vec_init_then_push.rs:11: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 - --> tests/ui/vec_init_then_push.rs:14:5 + --> tests/ui/vec_init_then_push.rs:16:5 | LL | / let mut cap_err = Vec::with_capacity(2); LL | | +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 - --> tests/ui/vec_init_then_push.rs:27:5 + --> tests/ui/vec_init_then_push.rs:30: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 - --> tests/ui/vec_init_then_push.rs:78:5 + --> tests/ui/vec_init_then_push.rs:82:5 | LL | / let mut v = Vec::new(); LL | | +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 - --> tests/ui/vec_init_then_push.rs:87:5 + --> tests/ui/vec_init_then_push.rs:92:5 | LL | / let mut v = Vec::new(); LL | | +LL | | LL | | v.push(0); -LL | | v.push(1); ... | 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 - --> tests/ui/vec_init_then_push.rs:101:5 + --> tests/ui/vec_init_then_push.rs:107:5 | LL | / let mut v2 = Vec::new(); LL | | +LL | | LL | | v2.push(0); -LL | | v2.push(1); ... | 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 - --> tests/ui/vec_init_then_push.rs:117:5 + --> tests/ui/vec_init_then_push.rs:124: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 b4c2d8209e76..f5c0ecd72e00 100644 --- a/tests/ui/vec_resize_to_zero.fixed +++ b/tests/ui/vec_resize_to_zero.fixed @@ -5,7 +5,8 @@ fn main() { // applicable here v.clear(); - //~^ ERROR: emptying a vector with `resize` + //~^ vec_resize_to_zero + // 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 5b11c940f21a..2b75b475223c 100644 --- a/tests/ui/vec_resize_to_zero.rs +++ b/tests/ui/vec_resize_to_zero.rs @@ -5,7 +5,8 @@ fn main() { // applicable here v.resize(0, 5); - //~^ ERROR: emptying a vector with `resize` + //~^ vec_resize_to_zero + // not applicable v.resize(2, 5); diff --git a/tests/ui/verbose_file_reads.rs b/tests/ui/verbose_file_reads.rs index 9dd4f4e1d9be..374cd39df947 100644 --- a/tests/ui/verbose_file_reads.rs +++ b/tests/ui/verbose_file_reads.rs @@ -21,10 +21,12 @@ 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` + //~^ verbose_file_reads + // ...and this let mut string_buffer = String::new(); f.read_to_string(&mut string_buffer)?; - //~^ ERROR: use of `File::read_to_string` + //~^ verbose_file_reads + Ok(()) } diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr index e85068fc7a9c..9e6f6788562f 100644 --- a/tests/ui/verbose_file_reads.stderr +++ b/tests/ui/verbose_file_reads.stderr @@ -9,7 +9,7 @@ LL | f.read_to_end(&mut buffer)?; = help: to override `-D warnings` add `#[allow(clippy::verbose_file_reads)]` error: use of `File::read_to_string` - --> tests/ui/verbose_file_reads.rs:27:5 + --> tests/ui/verbose_file_reads.rs:28:5 | LL | f.read_to_string(&mut string_buffer)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/waker_clone_wake.fixed b/tests/ui/waker_clone_wake.fixed index 9c02b9a90fdd..d7b5000a5d50 100644 --- a/tests/ui/waker_clone_wake.fixed +++ b/tests/ui/waker_clone_wake.fixed @@ -13,8 +13,10 @@ macro_rules! mac { pub fn wake(cx: &mut std::task::Context) { cx.waker().wake_by_ref(); + //~^ waker_clone_wake mac!(cx).wake_by_ref(); + //~^ waker_clone_wake } pub fn no_lint(cx: &mut std::task::Context, c: &Custom) { diff --git a/tests/ui/waker_clone_wake.rs b/tests/ui/waker_clone_wake.rs index edc3bbd8fc08..27fa922d1112 100644 --- a/tests/ui/waker_clone_wake.rs +++ b/tests/ui/waker_clone_wake.rs @@ -13,8 +13,10 @@ macro_rules! mac { pub fn wake(cx: &mut std::task::Context) { cx.waker().clone().wake(); + //~^ waker_clone_wake mac!(cx).clone().wake(); + //~^ waker_clone_wake } pub fn no_lint(cx: &mut std::task::Context, c: &Custom) { diff --git a/tests/ui/waker_clone_wake.stderr b/tests/ui/waker_clone_wake.stderr index bf2c02a76c9b..9eb167d13107 100644 --- a/tests/ui/waker_clone_wake.stderr +++ b/tests/ui/waker_clone_wake.stderr @@ -8,7 +8,7 @@ LL | cx.waker().clone().wake(); = help: to override `-D warnings` add `#[allow(clippy::waker_clone_wake)]` error: cloning a `Waker` only to wake it - --> tests/ui/waker_clone_wake.rs:17:5 + --> tests/ui/waker_clone_wake.rs:18:5 | LL | mac!(cx).clone().wake(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `mac!(cx).wake_by_ref()` diff --git a/tests/ui/while_float.rs b/tests/ui/while_float.rs index a3b0618948e6..06dc700c1980 100644 --- a/tests/ui/while_float.rs +++ b/tests/ui/while_float.rs @@ -2,9 +2,11 @@ fn main() { let mut x = 0.0_f32; while x < 42.0_f32 { + //~^ while_float x += 0.5; } while x < 42.0 { + //~^ while_float x += 1.0; } let mut x = 0; diff --git a/tests/ui/while_float.stderr b/tests/ui/while_float.stderr index b8e934b97c6c..e83e1b925c16 100644 --- a/tests/ui/while_float.stderr +++ b/tests/ui/while_float.stderr @@ -11,7 +11,7 @@ LL | #[deny(clippy::while_float)] | ^^^^^^^^^^^^^^^^^^^ error: while condition comparing floats - --> tests/ui/while_float.rs:7:11 + --> tests/ui/while_float.rs:8:11 | LL | while x < 42.0 { | ^^^^^^^^ diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs index fa5325bebffa..ea442b9b2b5c 100644 --- a/tests/ui/while_let_loop.rs +++ b/tests/ui/while_let_loop.rs @@ -4,8 +4,9 @@ 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` + //~^ while_let_loop + + if let Some(_x) = y { let _v = 1; } else { @@ -23,7 +24,8 @@ fn main() { } loop { - //~^ ERROR: this loop could be written as a `while let` loop + //~^ while_let_loop + match y { Some(_x) => true, None => break, @@ -31,7 +33,8 @@ fn main() { } loop { - //~^ ERROR: this loop could be written as a `while let` loop + //~^ while_let_loop + let x = match y { Some(x) => x, None => break, @@ -41,7 +44,8 @@ fn main() { } loop { - //~^ ERROR: this loop could be written as a `while let` loop + //~^ while_let_loop + let x = match y { Some(x) => x, None => break, @@ -72,7 +76,8 @@ fn main() { // #675, this used to have a wrong suggestion loop { - //~^ ERROR: this loop could be written as a `while let` loop + //~^ 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 10c2311d82f7..3bd8ab85a92f 100644 --- a/tests/ui/while_let_loop.stderr +++ b/tests/ui/while_let_loop.stderr @@ -2,9 +2,6 @@ error: this loop could be written as a `while let` loop --> tests/ui/while_let_loop.rs:6:5 | LL | / loop { -LL | | -LL | | -LL | | if let Some(_x) = y { ... | LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` @@ -13,47 +10,47 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:25:5 + --> tests/ui/while_let_loop.rs:26:5 | LL | / loop { LL | | +LL | | LL | | match y { -LL | | Some(_x) => true, -LL | | None => break, +... | LL | | }; LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:33:5 + --> tests/ui/while_let_loop.rs:35:5 | LL | / loop { LL | | +LL | | LL | | let x = match y { -LL | | Some(x) => x, ... | LL | | let _str = "foo"; LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:43:5 + --> tests/ui/while_let_loop.rs:46:5 | LL | / loop { LL | | +LL | | LL | | let x = match y { -LL | | Some(x) => x, ... | LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:74:5 + --> tests/ui/while_let_loop.rs:78:5 | LL | / loop { LL | | +LL | | LL | | let (e, l) = match "".split_whitespace().next() { -LL | | Some(word) => (word.is_empty(), word.len()), ... | LL | | let _ = (e, l); LL | | } diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index b8087c6e000f..bf4950620340 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -13,16 +13,19 @@ fn base() { let mut iter = 1..20; for x in iter { + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; for x in iter { + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; for _ in iter {} + //~^ while_let_on_iterator let mut iter = 1..20; while let None = iter.next() {} // this is fine (if nonsensical) @@ -99,6 +102,7 @@ fn refutable2() { let mut it = v.windows(2); for [..] in it {} + //~^ while_let_on_iterator let v = vec![[1], [2], [3]]; let mut it = v.iter(); @@ -106,6 +110,7 @@ fn refutable2() { let mut it = v.iter(); for [_x] in it {} + //~^ while_let_on_iterator } // binding @@ -119,6 +124,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); for x @ [_] in it { + //~^ while_let_on_iterator println!("{:?}", x); } } @@ -139,6 +145,7 @@ fn nested_loops() { loop { let mut y = a.iter(); for _ in y { + //~^ while_let_on_iterator // use a for loop here } } @@ -196,6 +203,7 @@ fn issue6491() { let mut it = 1..40; while let Some(n) = it.next() { for m in it.by_ref() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -207,8 +215,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; for n in it { + //~^ while_let_on_iterator let mut it = 1..40; for m in it { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -218,6 +228,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); for m in it { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -227,6 +238,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; for m in it.by_ref() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -244,6 +256,7 @@ fn issue6231() { let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { for m in it.by_ref() { + //~^ while_let_on_iterator if n % 10 == 0 { break; } @@ -259,6 +272,7 @@ fn issue1924() { fn f(&mut self) -> Option { // Used as a field. for i in self.0.by_ref() { + //~^ while_let_on_iterator if !(3..8).contains(&i) { return Some(i); } @@ -291,6 +305,7 @@ fn issue1924() { } // This one is fine, a different field is borrowed for i in self.0.0.0.by_ref() { + //~^ while_let_on_iterator if i == 1 { return self.0.1.take(); } else { @@ -320,6 +335,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); for n in it.by_ref() { + //~^ while_let_on_iterator if n == 0 { break; } @@ -332,6 +348,7 @@ fn issue7249() { let mut x = || { // Needs &mut, the closure can be called multiple times for x in it.by_ref() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -346,6 +363,7 @@ fn issue7510() { let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable for x in it.by_ref() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -357,6 +375,7 @@ fn issue7510() { let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable for x in it.0.by_ref() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -392,6 +411,7 @@ fn custom_deref() { let mut s = S2(S1 { x: 0..10 }); for x in s.x.by_ref() { + //~^ while_let_on_iterator println!("{}", x); } } @@ -399,6 +419,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; for x in x[0].by_ref() { + //~^ while_let_on_iterator println!("{}", x); } } @@ -407,6 +428,7 @@ fn fn_once_closure() { let mut it = 0..10; (|| { for x in it.by_ref() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -417,6 +439,7 @@ fn fn_once_closure() { let mut it = 0..10; f(|| { for x in it { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -427,6 +450,7 @@ fn fn_once_closure() { let mut it = 0..10; f2(|| { for x in it.by_ref() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -437,6 +461,7 @@ fn fn_once_closure() { f3(|| { let mut it = 0..10; for x in it { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -449,6 +474,7 @@ fn fn_once_closure() { let mut it = 0..10; f4(|| { for x in it { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -459,6 +485,7 @@ fn fn_once_closure() { fn issue13123() { let mut it = 0..20; 'label: for n in it { + //~^ while_let_on_iterator if n % 25 == 0 { break 'label; } @@ -468,6 +495,7 @@ fn issue13123() { fn main() { let mut it = 0..20; for _ in it { + //~^ while_let_on_iterator println!("test"); } } diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index 8e02f59b5126..d34b78efc706 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -13,16 +13,19 @@ fn base() { let mut iter = 1..20; while let Option::Some(x) = iter.next() { + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; while let Some(x) = iter.next() { + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; while let Some(_) = iter.next() {} + //~^ while_let_on_iterator let mut iter = 1..20; while let None = iter.next() {} // this is fine (if nonsensical) @@ -99,6 +102,7 @@ fn refutable2() { let mut it = v.windows(2); while let Some([..]) = it.next() {} + //~^ while_let_on_iterator let v = vec![[1], [2], [3]]; let mut it = v.iter(); @@ -106,6 +110,7 @@ fn refutable2() { let mut it = v.iter(); while let Some([_x]) = it.next() {} + //~^ while_let_on_iterator } // binding @@ -119,6 +124,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); while let Some(x @ [_]) = it.next() { + //~^ while_let_on_iterator println!("{:?}", x); } } @@ -139,6 +145,7 @@ fn nested_loops() { loop { let mut y = a.iter(); while let Some(_) = y.next() { + //~^ while_let_on_iterator // use a for loop here } } @@ -196,6 +203,7 @@ fn issue6491() { let mut it = 1..40; while let Some(n) = it.next() { while let Some(m) = it.next() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -207,8 +215,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; while let Some(n) = it.next() { + //~^ while_let_on_iterator let mut it = 1..40; while let Some(m) = it.next() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -218,6 +228,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); while let Some(m) = it.next() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -227,6 +238,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; while let Some(m) = it.next() { + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -244,6 +256,7 @@ fn issue6231() { let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { while let Some(m) = it.next() { + //~^ while_let_on_iterator if n % 10 == 0 { break; } @@ -259,6 +272,7 @@ fn issue1924() { fn f(&mut self) -> Option { // Used as a field. while let Some(i) = self.0.next() { + //~^ while_let_on_iterator if !(3..8).contains(&i) { return Some(i); } @@ -291,6 +305,7 @@ fn issue1924() { } // This one is fine, a different field is borrowed while let Some(i) = self.0.0.0.next() { + //~^ while_let_on_iterator if i == 1 { return self.0.1.take(); } else { @@ -320,6 +335,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); while let Some(n) = it.next() { + //~^ while_let_on_iterator if n == 0 { break; } @@ -332,6 +348,7 @@ fn issue7249() { let mut x = || { // Needs &mut, the closure can be called multiple times while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -346,6 +363,7 @@ fn issue7510() { let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -357,6 +375,7 @@ fn issue7510() { let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable while let Some(x) = it.0.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -392,6 +411,7 @@ fn custom_deref() { let mut s = S2(S1 { x: 0..10 }); while let Some(x) = s.x.next() { + //~^ while_let_on_iterator println!("{}", x); } } @@ -399,6 +419,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; while let Some(x) = x[0].next() { + //~^ while_let_on_iterator println!("{}", x); } } @@ -407,6 +428,7 @@ fn fn_once_closure() { let mut it = 0..10; (|| { while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -417,6 +439,7 @@ fn fn_once_closure() { let mut it = 0..10; f(|| { while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -427,6 +450,7 @@ fn fn_once_closure() { let mut it = 0..10; f2(|| { while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -437,6 +461,7 @@ fn fn_once_closure() { f3(|| { let mut it = 0..10; while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -449,6 +474,7 @@ fn fn_once_closure() { let mut it = 0..10; f4(|| { while let Some(x) = it.next() { + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -459,6 +485,7 @@ fn fn_once_closure() { fn issue13123() { let mut it = 0..20; 'label: while let Some(n) = it.next() { + //~^ while_let_on_iterator if n % 25 == 0 { break 'label; } @@ -468,6 +495,7 @@ fn issue13123() { fn main() { let mut it = 0..20; while let Some(..) = it.next() { + //~^ while_let_on_iterator println!("test"); } } diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index d96b26acf345..50f20227b90f 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -8,59 +8,53 @@ LL | while let Option::Some(x) = iter.next() { = help: to override `-D warnings` add `#[allow(clippy::while_let_on_iterator)]` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:20:5 + --> tests/ui/while_let_on_iterator.rs:21:5 | LL | while let Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:25:5 + --> tests/ui/while_let_on_iterator.rs:27:5 | LL | while let Some(_) = iter.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:101:9 + --> tests/ui/while_let_on_iterator.rs:104:9 | LL | while let Some([..]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:108:9 + --> tests/ui/while_let_on_iterator.rs:112:9 | LL | while let Some([_x]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:121:9 + --> tests/ui/while_let_on_iterator.rs:126:9 | LL | while let Some(x @ [_]) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:141:9 + --> tests/ui/while_let_on_iterator.rs:147:9 | LL | while let Some(_) = y.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:198:9 + --> tests/ui/while_let_on_iterator.rs:205: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 - --> tests/ui/while_let_on_iterator.rs:209:5 + --> tests/ui/while_let_on_iterator.rs:217:5 | LL | while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it` -error: this loop could be written as a `for` loop - --> tests/ui/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 --> tests/ui/while_let_on_iterator.rs:220:9 | @@ -68,103 +62,109 @@ LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:229:9 + --> tests/ui/while_let_on_iterator.rs:230:9 + | +LL | while let Some(m) = it.next() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` + +error: this loop could be written as a `for` loop + --> tests/ui/while_let_on_iterator.rs:240: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 - --> tests/ui/while_let_on_iterator.rs:246:9 + --> tests/ui/while_let_on_iterator.rs:258: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 - --> tests/ui/while_let_on_iterator.rs:261:13 + --> tests/ui/while_let_on_iterator.rs:274: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 - --> tests/ui/while_let_on_iterator.rs:293:13 + --> tests/ui/while_let_on_iterator.rs:307: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 - --> tests/ui/while_let_on_iterator.rs:322:5 + --> tests/ui/while_let_on_iterator.rs:337: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 - --> tests/ui/while_let_on_iterator.rs:334:9 + --> tests/ui/while_let_on_iterator.rs:350: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 - --> tests/ui/while_let_on_iterator.rs:348:5 + --> tests/ui/while_let_on_iterator.rs:365: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 - --> tests/ui/while_let_on_iterator.rs:359:5 + --> tests/ui/while_let_on_iterator.rs:377: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 - --> tests/ui/while_let_on_iterator.rs:394:5 + --> tests/ui/while_let_on_iterator.rs:413: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 - --> tests/ui/while_let_on_iterator.rs:401:5 + --> tests/ui/while_let_on_iterator.rs:421: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 - --> tests/ui/while_let_on_iterator.rs:409:9 + --> tests/ui/while_let_on_iterator.rs:430: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 - --> tests/ui/while_let_on_iterator.rs:419:9 + --> tests/ui/while_let_on_iterator.rs:441:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:429:9 + --> tests/ui/while_let_on_iterator.rs:452: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 - --> tests/ui/while_let_on_iterator.rs:439:9 + --> tests/ui/while_let_on_iterator.rs:463:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:451:9 + --> tests/ui/while_let_on_iterator.rs:476:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:461:5 + --> tests/ui/while_let_on_iterator.rs:487:5 | LL | 'label: while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'label: for n in it` error: this loop could be written as a `for` loop - --> tests/ui/while_let_on_iterator.rs:470:5 + --> tests/ui/while_let_on_iterator.rs:497:5 | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs index bc8a1dbee71d..8d194a38ddf8 100644 --- a/tests/ui/wild_in_or_pats.rs +++ b/tests/ui/wild_in_or_pats.rs @@ -6,7 +6,8 @@ fn main() { dbg!("matched a"); }, "bar" | _ => { - //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway + //~^ wildcard_in_or_patterns + dbg!("matched (bar or) wild"); }, }; @@ -15,7 +16,8 @@ fn main() { dbg!("matched a"); }, "bar" | "bar2" | _ => { - //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway + //~^ wildcard_in_or_patterns + dbg!("matched (bar or bar2 or) wild"); }, }; @@ -24,7 +26,8 @@ fn main() { dbg!("matched a"); }, _ | "bar" | _ => { - //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway + //~^ wildcard_in_or_patterns + dbg!("matched (bar or) wild"); }, }; @@ -33,7 +36,8 @@ fn main() { dbg!("matched a"); }, _ | "bar" => { - //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway + //~^ wildcard_in_or_patterns + dbg!("matched (bar or) wild"); }, }; @@ -67,6 +71,7 @@ fn main() { dbg!("Change the color"); }, ExhaustiveEnum::Quit | _ => { + //~^ wildcard_in_or_patterns dbg!("Quit or other"); }, }; @@ -102,6 +107,7 @@ fn main() { dbg!("On the y axis at {y}"); }, ExhaustiveStruct { x: 1, y: 1 } | _ => { + //~^ wildcard_in_or_patterns dbg!("On neither axis: ({x}, {y})"); }, } diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr index 5e409d6dfa6d..09b2b533cd3e 100644 --- a/tests/ui/wild_in_or_pats.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -9,7 +9,7 @@ LL | "bar" | _ => { = help: to override `-D warnings` add `#[allow(clippy::wildcard_in_or_patterns)]` error: wildcard pattern covers any other pattern as it will match anyway - --> tests/ui/wild_in_or_pats.rs:17:9 + --> tests/ui/wild_in_or_pats.rs:18:9 | LL | "bar" | "bar2" | _ => { | ^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | "bar" | "bar2" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> tests/ui/wild_in_or_pats.rs:26:9 + --> tests/ui/wild_in_or_pats.rs:28:9 | LL | _ | "bar" | _ => { | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | _ | "bar" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> tests/ui/wild_in_or_pats.rs:35:9 + --> tests/ui/wild_in_or_pats.rs:38:9 | LL | _ | "bar" => { | ^^^^^^^^^ @@ -33,7 +33,7 @@ LL | _ | "bar" => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> tests/ui/wild_in_or_pats.rs:69:9 + --> tests/ui/wild_in_or_pats.rs:73:9 | LL | ExhaustiveEnum::Quit | _ => { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | ExhaustiveEnum::Quit | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> tests/ui/wild_in_or_pats.rs:104:9 + --> tests/ui/wild_in_or_pats.rs:109:9 | LL | ExhaustiveStruct { x: 1, y: 1 } | _ => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index 1089415733a9..141ff6eb2ac7 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -37,14 +37,17 @@ fn main() { match color { Color::Red => println!("Red"), Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; match color { Color::Red => println!("Red"), _not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; let _str = match color { Color::Red => "Red".to_owned(), not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red), + //~^ wildcard_enum_match_arm }; match color { Color::Red => {}, @@ -61,6 +64,7 @@ fn main() { match color { Color::Rgb(r, _, _) if r > 0 => "Some red", Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red", + //~^ wildcard_enum_match_arm }; match color { Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, @@ -78,6 +82,7 @@ fn main() { match error_kind { ErrorKind::NotFound => {}, ErrorKind::PermissionDenied | _ => {}, + //~^ wildcard_enum_match_arm } match error_kind { ErrorKind::NotFound => {}, @@ -96,6 +101,7 @@ fn main() { match Enum::A { Enum::A => (), Enum::B | Enum::__Private => (), + //~^ wildcard_enum_match_arm } } } diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index d9285c56f3ef..a13684e9100b 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -37,14 +37,17 @@ fn main() { match color { Color::Red => println!("Red"), _ => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; match color { Color::Red => println!("Red"), _not_red => eprintln!("Not red"), + //~^ wildcard_enum_match_arm }; let _str = match color { Color::Red => "Red".to_owned(), not_red => format!("{:?}", not_red), + //~^ wildcard_enum_match_arm }; match color { Color::Red => {}, @@ -61,6 +64,7 @@ fn main() { match color { Color::Rgb(r, _, _) if r > 0 => "Some red", _ => "No red", + //~^ wildcard_enum_match_arm }; match color { Color::Red | Color::Green | Color::Blue | Color::Cyan => {}, @@ -78,6 +82,7 @@ fn main() { match error_kind { ErrorKind::NotFound => {}, _ => {}, + //~^ wildcard_enum_match_arm } match error_kind { ErrorKind::NotFound => {}, @@ -96,6 +101,7 @@ fn main() { match Enum::A { Enum::A => (), _ => (), + //~^ wildcard_enum_match_arm } } } diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 70ac768aaacd..088c6b7b2841 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -11,31 +11,31 @@ LL | #![deny(clippy::wildcard_enum_match_arm)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wildcard match will also match any future added variants - --> tests/ui/wildcard_enum_match_arm.rs:43:9 + --> tests/ui/wildcard_enum_match_arm.rs:44: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 - --> tests/ui/wildcard_enum_match_arm.rs:47:9 + --> tests/ui/wildcard_enum_match_arm.rs:49: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 - --> tests/ui/wildcard_enum_match_arm.rs:63:9 + --> tests/ui/wildcard_enum_match_arm.rs:66: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 - --> tests/ui/wildcard_enum_match_arm.rs:80:9 + --> tests/ui/wildcard_enum_match_arm.rs:84:9 | LL | _ => {}, | ^ help: try: `ErrorKind::PermissionDenied | _` error: wildcard match will also match any future added variants - --> tests/ui/wildcard_enum_match_arm.rs:98:13 + --> tests/ui/wildcard_enum_match_arm.rs:103:13 | LL | _ => (), | ^ help: try: `Enum::B | Enum::__Private` diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed index 46890ee9213f..a26b4a34190c 100644 --- a/tests/ui/wildcard_imports.fixed +++ b/tests/ui/wildcard_imports.fixed @@ -13,15 +13,21 @@ extern crate wildcard_imports_helper; use crate::fn_mod::foo; +//~^ wildcard_imports use crate::mod_mod::inner_mod; +//~^ wildcard_imports use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; +//~^ wildcard_imports #[macro_use] use crate::struct_mod::{A, inner_struct_mod}; +//~^ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +//~^ wildcard_imports use wildcard_imports_helper::{ExternA, extern_foo}; +//~^ wildcard_imports use std::io::prelude::*; use wildcard_imports_helper::extern_prelude::v1::*; @@ -92,6 +98,7 @@ mod underscore_mod { fn does_lint() { use self::exports_underscore_ish::{_Deref, dummy}; + //~^ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -123,13 +130,16 @@ mod in_fn_test { fn test_intern() { use crate::fn_mod::foo; + //~^ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; + //~^ wildcard_imports use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -142,6 +152,8 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); @@ -149,6 +161,7 @@ mod in_fn_test { fn test_extern_reexported() { use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + //~^ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -178,6 +191,7 @@ mod in_fn_test { fn test_reexported() { use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + //~^ wildcard_imports exported(); let _ = ExportedStruct; @@ -187,6 +201,7 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { use crate:: in_fn_test::exported; + //~^ wildcard_imports use crate:: fn_mod::foo; exported(); @@ -198,6 +213,7 @@ mod super_imports { mod should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_super() { let _ = foofoo(); @@ -236,6 +252,7 @@ mod super_imports { fn insidefoo() {} mod inner { use super::insidefoo; + //~^ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -244,6 +261,7 @@ mod super_imports { mod use_explicit_should_be_replaced { use crate::super_imports::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -253,6 +271,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { use super::super::foofoo; + //~^ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -262,6 +281,7 @@ mod super_imports { mod use_super_explicit_should_be_replaced { use super::super::super_imports::foofoo; + //~^ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -270,6 +290,7 @@ mod super_imports { mod attestation_should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 1a5586cbb88d..2168f0a8918d 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -13,15 +13,21 @@ extern crate wildcard_imports_helper; use crate::fn_mod::*; +//~^ wildcard_imports use crate::mod_mod::*; +//~^ wildcard_imports use crate::multi_fn_mod::*; +//~^ wildcard_imports #[macro_use] use crate::struct_mod::*; +//~^ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::*; +//~^ wildcard_imports use wildcard_imports_helper::*; +//~^ wildcard_imports use std::io::prelude::*; use wildcard_imports_helper::extern_prelude::v1::*; @@ -92,6 +98,7 @@ mod underscore_mod { fn does_lint() { use self::exports_underscore_ish::*; + //~^ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -123,13 +130,16 @@ mod in_fn_test { fn test_intern() { use crate::fn_mod::*; + //~^ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; + //~^ wildcard_imports use wildcard_imports_helper::*; + //~^ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -142,6 +152,8 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::*, inner2::*}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); @@ -149,6 +161,7 @@ mod in_fn_test { fn test_extern_reexported() { use wildcard_imports_helper::*; + //~^ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -178,6 +191,7 @@ mod in_fn_test { fn test_reexported() { use crate::in_fn_test::*; + //~^ wildcard_imports exported(); let _ = ExportedStruct; @@ -187,7 +201,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { use crate:: in_fn_test:: * ; + //~^ wildcard_imports use crate:: fn_mod:: + //~^ wildcard_imports *; exported(); @@ -199,6 +215,7 @@ mod super_imports { mod should_be_replaced { use super::*; + //~^ wildcard_imports fn with_super() { let _ = foofoo(); @@ -237,6 +254,7 @@ mod super_imports { fn insidefoo() {} mod inner { use super::*; + //~^ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -245,6 +263,7 @@ mod super_imports { mod use_explicit_should_be_replaced { use crate::super_imports::*; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -254,6 +273,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { use super::super::*; + //~^ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -263,6 +283,7 @@ mod super_imports { mod use_super_explicit_should_be_replaced { use super::super::super_imports::*; + //~^ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -271,6 +292,7 @@ mod super_imports { mod attestation_should_be_replaced { use super::*; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr index 8e88f216394d..f774126102bc 100644 --- a/tests/ui/wildcard_imports.stderr +++ b/tests/ui/wildcard_imports.stderr @@ -8,129 +8,130 @@ LL | use crate::fn_mod::*; = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:16:5 + --> tests/ui/wildcard_imports.rs:17:5 | LL | use crate::mod_mod::*; | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:17:5 + --> tests/ui/wildcard_imports.rs:19:5 | LL | use crate::multi_fn_mod::*; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:19:5 + --> tests/ui/wildcard_imports.rs:22:5 | LL | use crate::struct_mod::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:23:5 + --> tests/ui/wildcard_imports.rs:27:5 | LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:24:5 + --> tests/ui/wildcard_imports.rs:29:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:94:13 + --> tests/ui/wildcard_imports.rs:100:13 | LL | use self::exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self::exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:125:13 + --> tests/ui/wildcard_imports.rs:132:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:131:75 + --> tests/ui/wildcard_imports.rs:139:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:132:13 + --> tests/ui/wildcard_imports.rs:141:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:144:20 + --> tests/ui/wildcard_imports.rs:154:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:144:30 + --> tests/ui/wildcard_imports.rs:154:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:151:13 + --> tests/ui/wildcard_imports.rs:163:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:180:9 + --> tests/ui/wildcard_imports.rs:193:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:189:9 + --> tests/ui/wildcard_imports.rs:203:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:190:9 + --> tests/ui/wildcard_imports.rs:205:9 | LL | use crate:: fn_mod:: | _________^ +LL | | LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:201:13 + --> tests/ui/wildcard_imports.rs:217:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:239:17 + --> tests/ui/wildcard_imports.rs:256:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:247:13 + --> tests/ui/wildcard_imports.rs:265:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:256:17 + --> tests/ui/wildcard_imports.rs:275:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:265:13 + --> tests/ui/wildcard_imports.rs:285:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports.rs:273:13 + --> tests/ui/wildcard_imports.rs:294:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.edition2018.fixed b/tests/ui/wildcard_imports_2021.edition2018.fixed index 197dd3b94df0..a3d1aebba8af 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.fixed +++ b/tests/ui/wildcard_imports_2021.edition2018.fixed @@ -11,14 +11,20 @@ extern crate wildcard_imports_helper; use crate::fn_mod::foo; +//~^ wildcard_imports use crate::mod_mod::inner_mod; +//~^ wildcard_imports use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; +//~^ wildcard_imports use crate::struct_mod::{A, inner_struct_mod}; +//~^ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; use wildcard_imports_helper::{ExternA, extern_foo}; +//~^ wildcard_imports use std::io::prelude::*; @@ -87,6 +93,7 @@ mod underscore_mod { fn does_lint() { use exports_underscore_ish::{_Deref, dummy}; + //~^ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -117,13 +124,16 @@ mod in_fn_test { fn test_intern() { use crate::fn_mod::foo; + //~^ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; + //~^ wildcard_imports use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,6 +146,8 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); @@ -143,6 +155,7 @@ mod in_fn_test { fn test_extern_reexported() { use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + //~^ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -172,6 +185,7 @@ mod in_fn_test { fn test_reexported() { use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + //~^ wildcard_imports exported(); let _ = ExportedStruct; @@ -181,6 +195,7 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { use crate:: in_fn_test::exported; + //~^ wildcard_imports use crate:: fn_mod::foo; exported(); @@ -192,6 +207,7 @@ mod super_imports { mod should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_super() { let _ = foofoo(); @@ -230,6 +246,7 @@ mod super_imports { fn insidefoo() {} mod inner { use super::insidefoo; + //~^ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -238,6 +255,7 @@ mod super_imports { mod use_explicit_should_be_replaced { use crate::super_imports::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -247,6 +265,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { use super::super::foofoo; + //~^ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -256,6 +275,7 @@ mod super_imports { mod use_super_explicit_should_be_replaced { use super::super::super_imports::foofoo; + //~^ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -264,6 +284,7 @@ mod super_imports { mod attestation_should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports_2021.edition2018.stderr b/tests/ui/wildcard_imports_2021.edition2018.stderr index 66adacd95dcc..a1b557f39f0d 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.stderr +++ b/tests/ui/wildcard_imports_2021.edition2018.stderr @@ -8,129 +8,130 @@ LL | use crate::fn_mod::*; = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:14:5 + --> tests/ui/wildcard_imports_2021.rs:15:5 | LL | use crate::mod_mod::*; | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:15:5 + --> tests/ui/wildcard_imports_2021.rs:17:5 | LL | use crate::multi_fn_mod::*; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:16:5 + --> tests/ui/wildcard_imports_2021.rs:19:5 | LL | use crate::struct_mod::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:19:5 + --> tests/ui/wildcard_imports_2021.rs:23:5 | LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:21:5 + --> tests/ui/wildcard_imports_2021.rs:26:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:89:13 + --> tests/ui/wildcard_imports_2021.rs:95:13 | LL | use exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:119:13 + --> tests/ui/wildcard_imports_2021.rs:126:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:125:75 + --> tests/ui/wildcard_imports_2021.rs:133:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:126:13 + --> tests/ui/wildcard_imports_2021.rs:135:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:138:20 + --> tests/ui/wildcard_imports_2021.rs:148:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:138:30 + --> tests/ui/wildcard_imports_2021.rs:148:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:145:13 + --> tests/ui/wildcard_imports_2021.rs:157:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:174:9 + --> tests/ui/wildcard_imports_2021.rs:187:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:183:9 + --> tests/ui/wildcard_imports_2021.rs:197:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:184:9 + --> tests/ui/wildcard_imports_2021.rs:199:9 | LL | use crate:: fn_mod:: | _________^ +LL | | LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:195:13 + --> tests/ui/wildcard_imports_2021.rs:211:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:233:17 + --> tests/ui/wildcard_imports_2021.rs:250:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:241:13 + --> tests/ui/wildcard_imports_2021.rs:259:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:250:17 + --> tests/ui/wildcard_imports_2021.rs:269:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:259:13 + --> tests/ui/wildcard_imports_2021.rs:279:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:267:13 + --> tests/ui/wildcard_imports_2021.rs:288:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.edition2021.fixed b/tests/ui/wildcard_imports_2021.edition2021.fixed index 197dd3b94df0..a3d1aebba8af 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.fixed +++ b/tests/ui/wildcard_imports_2021.edition2021.fixed @@ -11,14 +11,20 @@ extern crate wildcard_imports_helper; use crate::fn_mod::foo; +//~^ wildcard_imports use crate::mod_mod::inner_mod; +//~^ wildcard_imports use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; +//~^ wildcard_imports use crate::struct_mod::{A, inner_struct_mod}; +//~^ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; use wildcard_imports_helper::{ExternA, extern_foo}; +//~^ wildcard_imports use std::io::prelude::*; @@ -87,6 +93,7 @@ mod underscore_mod { fn does_lint() { use exports_underscore_ish::{_Deref, dummy}; + //~^ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -117,13 +124,16 @@ mod in_fn_test { fn test_intern() { use crate::fn_mod::foo; + //~^ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; + //~^ wildcard_imports use wildcard_imports_helper::{ExternA, extern_foo}; + //~^ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,6 +146,8 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::inner_foo, inner2::inner_bar}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); @@ -143,6 +155,7 @@ mod in_fn_test { fn test_extern_reexported() { use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + //~^ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -172,6 +185,7 @@ mod in_fn_test { fn test_reexported() { use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + //~^ wildcard_imports exported(); let _ = ExportedStruct; @@ -181,6 +195,7 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { use crate:: in_fn_test::exported; + //~^ wildcard_imports use crate:: fn_mod::foo; exported(); @@ -192,6 +207,7 @@ mod super_imports { mod should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_super() { let _ = foofoo(); @@ -230,6 +246,7 @@ mod super_imports { fn insidefoo() {} mod inner { use super::insidefoo; + //~^ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -238,6 +255,7 @@ mod super_imports { mod use_explicit_should_be_replaced { use crate::super_imports::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -247,6 +265,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { use super::super::foofoo; + //~^ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -256,6 +275,7 @@ mod super_imports { mod use_super_explicit_should_be_replaced { use super::super::super_imports::foofoo; + //~^ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -264,6 +284,7 @@ mod super_imports { mod attestation_should_be_replaced { use super::foofoo; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports_2021.edition2021.stderr b/tests/ui/wildcard_imports_2021.edition2021.stderr index 66adacd95dcc..a1b557f39f0d 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.stderr +++ b/tests/ui/wildcard_imports_2021.edition2021.stderr @@ -8,129 +8,130 @@ LL | use crate::fn_mod::*; = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:14:5 + --> tests/ui/wildcard_imports_2021.rs:15:5 | LL | use crate::mod_mod::*; | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:15:5 + --> tests/ui/wildcard_imports_2021.rs:17:5 | LL | use crate::multi_fn_mod::*; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:16:5 + --> tests/ui/wildcard_imports_2021.rs:19:5 | LL | use crate::struct_mod::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:19:5 + --> tests/ui/wildcard_imports_2021.rs:23:5 | LL | use wildcard_imports_helper::inner::inner_for_self_import::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:21:5 + --> tests/ui/wildcard_imports_2021.rs:26:5 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:89:13 + --> tests/ui/wildcard_imports_2021.rs:95:13 | LL | use exports_underscore_ish::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `exports_underscore_ish::{_Deref, dummy}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:119:13 + --> tests/ui/wildcard_imports_2021.rs:126:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:125:75 + --> tests/ui/wildcard_imports_2021.rs:133:75 | LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; | ^ help: try: `inner_extern_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:126:13 + --> tests/ui/wildcard_imports_2021.rs:135:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:138:20 + --> tests/ui/wildcard_imports_2021.rs:148:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:138:30 + --> tests/ui/wildcard_imports_2021.rs:148:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:145:13 + --> tests/ui/wildcard_imports_2021.rs:157:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:174:9 + --> tests/ui/wildcard_imports_2021.rs:187:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:183:9 + --> tests/ui/wildcard_imports_2021.rs:197:9 | LL | use crate:: in_fn_test:: * ; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:184:9 + --> tests/ui/wildcard_imports_2021.rs:199:9 | LL | use crate:: fn_mod:: | _________^ +LL | | LL | | *; | |_________^ help: try: `crate:: fn_mod::foo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:195:13 + --> tests/ui/wildcard_imports_2021.rs:211:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:233:17 + --> tests/ui/wildcard_imports_2021.rs:250:17 | LL | use super::*; | ^^^^^^^^ help: try: `super::insidefoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:241:13 + --> tests/ui/wildcard_imports_2021.rs:259:13 | LL | use crate::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:250:17 + --> tests/ui/wildcard_imports_2021.rs:269:17 | LL | use super::super::*; | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:259:13 + --> tests/ui/wildcard_imports_2021.rs:279:13 | LL | use super::super::super_imports::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo` error: usage of wildcard import - --> tests/ui/wildcard_imports_2021.rs:267:13 + --> tests/ui/wildcard_imports_2021.rs:288:13 | LL | use super::*; | ^^^^^^^^ help: try: `super::foofoo` diff --git a/tests/ui/wildcard_imports_2021.rs b/tests/ui/wildcard_imports_2021.rs index 606ff080e774..8075c15bc14f 100644 --- a/tests/ui/wildcard_imports_2021.rs +++ b/tests/ui/wildcard_imports_2021.rs @@ -11,14 +11,20 @@ extern crate wildcard_imports_helper; use crate::fn_mod::*; +//~^ wildcard_imports use crate::mod_mod::*; +//~^ wildcard_imports use crate::multi_fn_mod::*; +//~^ wildcard_imports use crate::struct_mod::*; +//~^ wildcard_imports #[allow(unused_imports)] use wildcard_imports_helper::inner::inner_for_self_import::*; +//~^ wildcard_imports use wildcard_imports_helper::prelude::v1::*; use wildcard_imports_helper::*; +//~^ wildcard_imports use std::io::prelude::*; @@ -87,6 +93,7 @@ mod underscore_mod { fn does_lint() { use exports_underscore_ish::*; + //~^ wildcard_imports let _ = (&0).deref(); dummy(); } @@ -117,13 +124,16 @@ mod in_fn_test { fn test_intern() { use crate::fn_mod::*; + //~^ wildcard_imports foo(); } fn test_extern() { use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; + //~^ wildcard_imports use wildcard_imports_helper::*; + //~^ wildcard_imports inner_for_self_import::inner_extern_foo(); inner_extern_foo(); @@ -136,6 +146,8 @@ mod in_fn_test { fn test_inner_nested() { #[rustfmt::skip] use self::{inner::*, inner2::*}; + //~^ wildcard_imports + //~| wildcard_imports inner_foo(); inner_bar(); @@ -143,6 +155,7 @@ mod in_fn_test { fn test_extern_reexported() { use wildcard_imports_helper::*; + //~^ wildcard_imports extern_exported(); let _ = ExternExportedStruct; @@ -172,6 +185,7 @@ mod in_fn_test { fn test_reexported() { use crate::in_fn_test::*; + //~^ wildcard_imports exported(); let _ = ExportedStruct; @@ -181,7 +195,9 @@ fn test_reexported() { #[rustfmt::skip] fn test_weird_formatting() { use crate:: in_fn_test:: * ; + //~^ wildcard_imports use crate:: fn_mod:: + //~^ wildcard_imports *; exported(); @@ -193,6 +209,7 @@ mod super_imports { mod should_be_replaced { use super::*; + //~^ wildcard_imports fn with_super() { let _ = foofoo(); @@ -231,6 +248,7 @@ mod super_imports { fn insidefoo() {} mod inner { use super::*; + //~^ wildcard_imports fn with_super() { let _ = insidefoo(); } @@ -239,6 +257,7 @@ mod super_imports { mod use_explicit_should_be_replaced { use crate::super_imports::*; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); @@ -248,6 +267,7 @@ mod super_imports { mod use_double_super_should_be_replaced { mod inner { use super::super::*; + //~^ wildcard_imports fn with_double_super() { let _ = foofoo(); @@ -257,6 +277,7 @@ mod super_imports { mod use_super_explicit_should_be_replaced { use super::super::super_imports::*; + //~^ wildcard_imports fn with_super_explicit() { let _ = foofoo(); @@ -265,6 +286,7 @@ mod super_imports { mod attestation_should_be_replaced { use super::*; + //~^ wildcard_imports fn with_explicit() { let _ = foofoo(); diff --git a/tests/ui/wildcard_imports_cfgtest.rs b/tests/ui/wildcard_imports_cfgtest.rs index 203c4e15b50c..c41458d5bb0a 100644 --- a/tests/ui/wildcard_imports_cfgtest.rs +++ b/tests/ui/wildcard_imports_cfgtest.rs @@ -1,3 +1,4 @@ +//@check-pass //@compile-flags: --test #![warn(clippy::wildcard_imports)] diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed index f1def776e1bc..b82d77aaa418 100644 --- a/tests/ui/write_literal.fixed +++ b/tests/ui/write_literal.fixed @@ -29,46 +29,60 @@ 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` + //~^ write_literal + + writeln!(v, "Hello {} world", world); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "Hello world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "a literal {:.4}", 5); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // 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 + //~^ write_literal + writeln!(v, "world hello"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // named args shouldn't change anything either writeln!(v, "hello world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "world hello"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // #10128 writeln!(v, "hello {0} world", 2); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "world {0} hello", 2); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "hello {0} {1}, {bar}", 2, 3, bar = 4); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); - //~^ ERROR: literal with an empty format string + //~^ write_literal + } fn issue_13959() { let mut v = Vec::new(); writeln!(v, "\""); + //~^ write_literal writeln!( v, " + //~^ write_literal foo \\ \\\\ diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index 1b7df91b47e1..e9f5990d7ec6 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -29,47 +29,61 @@ 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` + //~^ write_literal + + writeln!(v, "Hello {} {}", world, "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "Hello {}", "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{} {:.4}", "a literal", 5); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // 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 + //~^ write_literal + writeln!(v, "{1} {0}", "hello", "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // named args shouldn't change anything either writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // #10128 writeln!(v, "{0} {1} {2}", "hello", 2, "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{2} {1} {0}", "hello", 2, "world"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{0} {1} {2}, {bar}", "hello", 2, 3, bar = 4); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); - //~^ ERROR: literal with an empty format string + //~^ write_literal + } fn issue_13959() { let mut v = Vec::new(); writeln!(v, "{}", r#"""#); + //~^ write_literal writeln!( v, "{}", r#" + //~^ write_literal foo \ \\ diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 35c93d567cd3..834162473c58 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -13,7 +13,7 @@ LL + write!(v, "Hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:34:39 + --> tests/ui/write_literal.rs:35:39 | LL | writeln!(v, "Hello {} {}", world, "world"); | ^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, "Hello {} world", world); | error: literal with an empty format string - --> tests/ui/write_literal.rs:36:29 + --> tests/ui/write_literal.rs:38:29 | LL | writeln!(v, "Hello {}", "world"); | ^^^^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "Hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:38:29 + --> tests/ui/write_literal.rs:41:29 | LL | writeln!(v, "{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + writeln!(v, "a literal {:.4}", 5); | error: literal with an empty format string - --> tests/ui/write_literal.rs:44:28 + --> tests/ui/write_literal.rs:48:28 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + writeln!(v, "hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:46:28 + --> tests/ui/write_literal.rs:51:28 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + writeln!(v, "world hello"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:50:38 + --> tests/ui/write_literal.rs:56:38 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + writeln!(v, "hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:52:38 + --> tests/ui/write_literal.rs:59:38 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + writeln!(v, "world hello"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:56:32 + --> tests/ui/write_literal.rs:64:32 | LL | writeln!(v, "{0} {1} {2}", "hello", 2, "world"); | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + writeln!(v, "hello {0} world", 2); | error: literal with an empty format string - --> tests/ui/write_literal.rs:58:32 + --> tests/ui/write_literal.rs:67:32 | LL | writeln!(v, "{2} {1} {0}", "hello", 2, "world"); | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + writeln!(v, "world {0} hello", 2); | error: literal with an empty format string - --> tests/ui/write_literal.rs:60:39 + --> tests/ui/write_literal.rs:70:39 | LL | writeln!(v, "{0} {1} {2}, {bar}", "hello", 2, 3, bar = 4); | ^^^^^^^ @@ -133,7 +133,7 @@ LL + writeln!(v, "hello {0} {1}, {bar}", 2, 3, bar = 4); | error: literal with an empty format string - --> tests/ui/write_literal.rs:62:41 + --> tests/ui/write_literal.rs:73:41 | LL | writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); | error: literal with an empty format string - --> tests/ui/write_literal.rs:68:23 + --> tests/ui/write_literal.rs:80:23 | LL | writeln!(v, "{}", r#"""#); | ^^^^^^ @@ -157,12 +157,12 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> tests/ui/write_literal.rs:72:9 + --> tests/ui/write_literal.rs:85:9 | LL | / r#" +LL | | LL | | foo LL | | \ -LL | | \\ ... | LL | | bar LL | | "# @@ -171,6 +171,7 @@ LL | | "# help: try | LL ~ " +LL + LL + foo LL + \\ LL + \\\\ diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index b2ed552d46bc..2edd50c43403 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -8,44 +8,58 @@ 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` + //~^ write_literal + + writeln!(v, r"{}", r"{hello}"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{}", '\''); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{}", '"'); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, r"{}", '"'); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, r"{}", '\''); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!( v, "some {}", "hello \ + //~^ write_literal world!", - //~^^ ERROR: literal with an empty format string + ); writeln!( v, "some {}\ {} \\ {}", "1", "2", "3", + //~^ write_literal ); writeln!(v, "{}", "\\"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, r"{}", "\\"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, r#"{}"#, "\\"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{}", r"\"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + writeln!(v, "{}", "\r"); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // hard mode writeln!(v, r#"{}{}"#, '#', '"'); - //~^ ERROR: literal with an empty format string + //~^ write_literal + // should not lint writeln!(v, r"{}", "\r"); } diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 9fba3ce548a0..f3f86586ef85 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -13,7 +13,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:13:24 + --> tests/ui/write_literal_2.rs:14:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:15:23 + --> tests/ui/write_literal_2.rs:17:23 | LL | writeln!(v, "{}", '\''); | ^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "'"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:17:23 + --> tests/ui/write_literal_2.rs:20:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -49,13 +49,13 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:19:24 + --> tests/ui/write_literal_2.rs:23:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> tests/ui/write_literal_2.rs:21:24 + --> tests/ui/write_literal_2.rs:26:24 | LL | writeln!(v, r"{}", '\''); | ^^^^ @@ -67,20 +67,22 @@ LL + writeln!(v, r"'"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:26:9 + --> tests/ui/write_literal_2.rs:32:9 | LL | / "hello \ +LL | | LL | | world!", | |_______________^ | help: try | LL ~ "some hello \ +LL + LL ~ world!", | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:34:9 + --> tests/ui/write_literal_2.rs:41:9 | LL | "1", "2", "3", | ^^^^^^^^^^^^^ @@ -92,7 +94,7 @@ LL ~ 2 \\ 3", | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:36:23 + --> tests/ui/write_literal_2.rs:44:23 | LL | writeln!(v, "{}", "\\"); | ^^^^ @@ -104,7 +106,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:38:24 + --> tests/ui/write_literal_2.rs:47:24 | LL | writeln!(v, r"{}", "\\"); | ^^^^ @@ -116,7 +118,7 @@ LL + writeln!(v, r"\"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:40:26 + --> tests/ui/write_literal_2.rs:50:26 | LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ @@ -128,7 +130,7 @@ LL + writeln!(v, r#"\"#); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:42:23 + --> tests/ui/write_literal_2.rs:53:23 | LL | writeln!(v, "{}", r"\"); | ^^^^ @@ -140,7 +142,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:44:23 + --> tests/ui/write_literal_2.rs:56:23 | LL | writeln!(v, "{}", "\r"); | ^^^^ @@ -152,7 +154,7 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:47:28 + --> tests/ui/write_literal_2.rs:60:28 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^^^^^^ diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index 82afff5c81f5..bd2285d16bcf 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -10,16 +10,21 @@ 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` + //~^ write_with_newline + + writeln!(v, "Hello {}", "world"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + writeln!(v, "Hello {} {}", "world", "#2"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + writeln!(v, "{}", 1265); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + writeln!(v); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + // These should be fine write!(v, ""); @@ -42,7 +47,8 @@ fn main() { // #3514 write!(v, "\\n"); writeln!(v, "\\"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + write!(v, "\\\\n"); // Raw strings @@ -51,11 +57,13 @@ fn main() { // Literal newlines should also fail writeln!( - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + v ); writeln!( - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + v ); @@ -63,7 +71,8 @@ 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_with_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 96e4bf0fbc4b..b70349ae82e6 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -10,16 +10,21 @@ 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_with_newline + + write!(v, "Hello {}\n", "world"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + write!(v, "Hello {} {}\n", "world", "#2"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + write!(v, "{}\n", 1265); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + write!(v, "\n"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + // These should be fine write!(v, ""); @@ -42,7 +47,8 @@ fn main() { // #3514 write!(v, "\\n"); write!(v, "\\\n"); - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + write!(v, "\\\\n"); // Raw strings @@ -51,13 +57,15 @@ fn main() { // Literal newlines should also fail write!( - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + v, " " ); write!( - //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~^ write_with_newline + v, r" " @@ -67,7 +75,8 @@ 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_with_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 7eb741107a7b..9ab17cfdf3af 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -13,7 +13,7 @@ LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:15:5 + --> tests/ui/write_with_newline.rs:16:5 | LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:17:5 + --> tests/ui/write_with_newline.rs:19:5 | LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:19:5 + --> tests/ui/write_with_newline.rs:22:5 | LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:21:5 + --> tests/ui/write_with_newline.rs:25:5 | LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:44:5 + --> tests/ui/write_with_newline.rs:49:5 | LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ @@ -73,10 +73,11 @@ LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:53:5 + --> tests/ui/write_with_newline.rs:59:5 | LL | / write!( LL | | +LL | | LL | | v, LL | | " LL | | " @@ -87,14 +88,16 @@ help: use `writeln!` instead | LL ~ writeln!( LL | +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:59:5 + --> tests/ui/write_with_newline.rs:66:5 | LL | / write!( LL | | +LL | | LL | | v, LL | | r" LL | | " @@ -105,11 +108,12 @@ help: use `writeln!` instead | LL ~ writeln!( LL | +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:69:5 + --> tests/ui/write_with_newline.rs:77:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/writeln_empty_string.fixed b/tests/ui/writeln_empty_string.fixed index f6a7481f6422..5cb702b10f2d 100644 --- a/tests/ui/writeln_empty_string.fixed +++ b/tests/ui/writeln_empty_string.fixed @@ -7,9 +7,11 @@ fn main() { // These should fail writeln!(v); + //~^ writeln_empty_string let mut suggestion = Vec::new(); writeln!(suggestion); + //~^ writeln_empty_string // These should be fine writeln!(v); diff --git a/tests/ui/writeln_empty_string.rs b/tests/ui/writeln_empty_string.rs index 0297dba8c45d..e6478264a578 100644 --- a/tests/ui/writeln_empty_string.rs +++ b/tests/ui/writeln_empty_string.rs @@ -7,9 +7,11 @@ fn main() { // These should fail writeln!(v, ""); + //~^ writeln_empty_string let mut suggestion = Vec::new(); writeln!(suggestion, ""); + //~^ writeln_empty_string // These should be fine writeln!(v); diff --git a/tests/ui/writeln_empty_string.stderr b/tests/ui/writeln_empty_string.stderr index 20ece6a41926..43e76309ba64 100644 --- a/tests/ui/writeln_empty_string.stderr +++ b/tests/ui/writeln_empty_string.stderr @@ -10,7 +10,7 @@ LL | writeln!(v, ""); = help: to override `-D warnings` add `#[allow(clippy::writeln_empty_string)]` error: empty string literal in `writeln!` - --> tests/ui/writeln_empty_string.rs:12:5 + --> tests/ui/writeln_empty_string.rs:13:5 | LL | writeln!(suggestion, ""); | ^^^^^^^^^^^^^^^^^^^----^ diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index d7ed883b767c..42d600b67f8e 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -14,14 +14,16 @@ impl Foo { fn is_u32(&self) {} fn to_i32(self) {} fn from_i32(self) {} - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + 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` + //~^ wrong_self_convention + // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] pub fn from_cake(self) {} @@ -34,30 +36,40 @@ struct Bar; impl Bar { fn as_i32(self) {} - //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl + //~^ wrong_self_convention + fn as_u32(&self) {} fn into_i32(&self) {} - //~^ ERROR: methods called `into_*` usually take `self` by value + //~^ wrong_self_convention + fn into_u32(self) {} fn is_i32(self) {} - //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b + //~^ wrong_self_convention + fn is_u32(&self) {} fn to_i32(self) {} - //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not + //~^ wrong_self_convention + fn to_u32(&self) {} fn from_i32(self) {} - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + pub fn as_i64(self) {} - //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl + //~^ wrong_self_convention + pub fn into_i64(&self) {} - //~^ ERROR: methods called `into_*` usually take `self` by value + //~^ wrong_self_convention + pub fn is_i64(self) {} - //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b + //~^ wrong_self_convention + pub fn to_i64(self) {} - //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not + //~^ wrong_self_convention + pub fn from_i64(self) {} - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + // test for false positives fn as_(self) {} @@ -103,19 +115,23 @@ mod issue4037 { mod issue6307 { trait T: Sized { fn as_i32(self) {} - //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu + //~^ wrong_self_convention + fn as_u32(&self) {} fn into_i32(self) {} fn into_i32_ref(&self) {} - //~^ ERROR: methods called `into_*` usually take `self` by value + //~^ wrong_self_convention + fn into_u32(self) {} fn is_i32(self) {} - //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel + //~^ wrong_self_convention + fn is_u32(&self) {} fn to_i32(self) {} fn to_u32(&self) {} fn from_i32(self) {} - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self) {} @@ -131,19 +147,23 @@ mod issue6307 { trait U { fn as_i32(self); - //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu + //~^ wrong_self_convention + fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); - //~^ ERROR: methods called `into_*` usually take `self` by value + //~^ wrong_self_convention + fn into_u32(self); fn is_i32(self); - //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel + //~^ wrong_self_convention + fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -162,14 +182,16 @@ mod issue6307 { fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); - //~^ ERROR: methods called `into_*` usually take `self` by value + //~^ wrong_self_convention + 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` + //~^ wrong_self_convention + // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -194,7 +216,8 @@ mod issue6727 { } // trigger lint fn to_u64_v2(&self) -> u64 { - //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is + //~^ wrong_self_convention + 1 } } @@ -204,7 +227,8 @@ mod issue6727 { impl FooNoCopy { // trigger lint fn to_u64(self) -> u64 { - //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is + //~^ wrong_self_convention + 2 } fn to_u64_v2(&self) -> u64 { diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index 5c286721c478..fe6d231578b1 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -9,7 +9,7 @@ LL | fn from_i32(self) {} = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:23:21 + --> tests/ui/wrong_self_convention.rs:24:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -17,7 +17,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 - --> tests/ui/wrong_self_convention.rs:36:15 + --> tests/ui/wrong_self_convention.rs:38:15 | LL | fn as_i32(self) {} | ^^^^ @@ -25,7 +25,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:39:17 + --> tests/ui/wrong_self_convention.rs:42:17 | LL | fn into_i32(&self) {} | ^^^^^ @@ -33,7 +33,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` - --> tests/ui/wrong_self_convention.rs:42:15 + --> tests/ui/wrong_self_convention.rs:46:15 | LL | fn is_i32(self) {} | ^^^^ @@ -41,7 +41,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 - --> tests/ui/wrong_self_convention.rs:45:15 + --> tests/ui/wrong_self_convention.rs:50:15 | LL | fn to_i32(self) {} | ^^^^ @@ -49,7 +49,7 @@ LL | fn to_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:48:17 + --> tests/ui/wrong_self_convention.rs:54:17 | LL | fn from_i32(self) {} | ^^^^ @@ -57,7 +57,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 - --> tests/ui/wrong_self_convention.rs:51:19 + --> tests/ui/wrong_self_convention.rs:58:19 | LL | pub fn as_i64(self) {} | ^^^^ @@ -65,7 +65,7 @@ LL | pub fn as_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:53:21 + --> tests/ui/wrong_self_convention.rs:61:21 | LL | pub fn into_i64(&self) {} | ^^^^^ @@ -73,7 +73,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` - --> tests/ui/wrong_self_convention.rs:55:19 + --> tests/ui/wrong_self_convention.rs:64:19 | LL | pub fn is_i64(self) {} | ^^^^ @@ -81,7 +81,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 - --> tests/ui/wrong_self_convention.rs:57:19 + --> tests/ui/wrong_self_convention.rs:67:19 | LL | pub fn to_i64(self) {} | ^^^^ @@ -89,7 +89,7 @@ LL | pub fn to_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:59:21 + --> tests/ui/wrong_self_convention.rs:70:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -97,7 +97,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 - --> tests/ui/wrong_self_convention.rs:105:19 + --> tests/ui/wrong_self_convention.rs:117:19 | LL | fn as_i32(self) {} | ^^^^ @@ -105,7 +105,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:109:25 + --> tests/ui/wrong_self_convention.rs:122:25 | LL | fn into_i32_ref(&self) {} | ^^^^^ @@ -113,7 +113,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` - --> tests/ui/wrong_self_convention.rs:112:19 + --> tests/ui/wrong_self_convention.rs:126:19 | LL | fn is_i32(self) {} | ^^^^ @@ -121,7 +121,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:117:21 + --> tests/ui/wrong_self_convention.rs:132:21 | LL | fn from_i32(self) {} | ^^^^ @@ -129,7 +129,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 - --> tests/ui/wrong_self_convention.rs:133:19 + --> tests/ui/wrong_self_convention.rs:149:19 | LL | fn as_i32(self); | ^^^^ @@ -137,7 +137,7 @@ LL | fn as_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:137:25 + --> tests/ui/wrong_self_convention.rs:154:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -145,7 +145,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` - --> tests/ui/wrong_self_convention.rs:140:19 + --> tests/ui/wrong_self_convention.rs:158:19 | LL | fn is_i32(self); | ^^^^ @@ -153,7 +153,7 @@ LL | fn is_i32(self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:145:21 + --> tests/ui/wrong_self_convention.rs:164:21 | LL | fn from_i32(self); | ^^^^ @@ -161,7 +161,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:164:25 + --> tests/ui/wrong_self_convention.rs:184:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -169,7 +169,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:171:21 + --> tests/ui/wrong_self_convention.rs:192:21 | LL | fn from_i32(self); | ^^^^ @@ -177,7 +177,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 - --> tests/ui/wrong_self_convention.rs:196:22 + --> tests/ui/wrong_self_convention.rs:218:22 | LL | fn to_u64_v2(&self) -> u64 { | ^^^^^ @@ -185,7 +185,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 - --> tests/ui/wrong_self_convention.rs:206:19 + --> tests/ui/wrong_self_convention.rs:229:19 | LL | fn to_u64(self) -> u64 { | ^^^^ diff --git a/tests/ui/wrong_self_convention2.rs b/tests/ui/wrong_self_convention2.rs index 44b70f877be4..0740af48d741 100644 --- a/tests/ui/wrong_self_convention2.rs +++ b/tests/ui/wrong_self_convention2.rs @@ -52,7 +52,8 @@ mod issue7179 { // lint pub fn from_be_self(self) -> Self { - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + S(i32::from_be(self.0)) } } @@ -62,7 +63,8 @@ mod issue7179 { fn from_be(s: Self) -> Self; // lint fn from_be_self(self) -> Self; - //~^ ERROR: methods called `from_*` usually take no `self` + //~^ wrong_self_convention + } trait Foo: Sized { diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr index 7aabdcd408c6..2eafb95d9bbe 100644 --- a/tests/ui/wrong_self_convention2.stderr +++ b/tests/ui/wrong_self_convention2.stderr @@ -9,7 +9,7 @@ LL | pub fn from_be_self(self) -> Self { = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention2.rs:64:25 + --> tests/ui/wrong_self_convention2.rs:65: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 9169fc6d71f6..73df332d77ce 100644 --- a/tests/ui/wrong_self_conventions_mut.rs +++ b/tests/ui/wrong_self_conventions_mut.rs @@ -12,7 +12,8 @@ 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 + //~^ wrong_self_convention + match self { Self::Many(data) => Some(data), _ => None, @@ -21,7 +22,8 @@ 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 + //~^ wrong_self_convention + 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 f52a36632101..5ea2e8192efe 100644 --- a/tests/ui/wrong_self_conventions_mut.stderr +++ b/tests/ui/wrong_self_conventions_mut.stderr @@ -9,7 +9,7 @@ LL | pub fn to_many(&mut self) -> Option<&mut [T]> { = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference - --> tests/ui/wrong_self_conventions_mut.rs:23:28 + --> tests/ui/wrong_self_conventions_mut.rs:24: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 340ed5ef1339..79a309f49933 100644 --- a/tests/ui/zero_div_zero.rs +++ b/tests/ui/zero_div_zero.rs @@ -2,13 +2,17 @@ #[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 + //~^ zero_divided_by_zero + let f64_nan = 0.0 / 0.0f64; - //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN + //~^ zero_divided_by_zero + let other_f64_nan = 0.0f64 / 0.0; - //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN + //~^ zero_divided_by_zero + let one_more_f64_nan = 0.0f64 / 0.0f64; - //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN + //~^ zero_divided_by_zero + 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 5294ebdfa5da..bcf752d7c26c 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -9,7 +9,7 @@ LL | let nan = 0.0 / 0.0; = help: to override `-D warnings` add `#[allow(clippy::zero_divided_by_zero)]` error: constant division of `0.0` with `0.0` will always result in NaN - --> tests/ui/zero_div_zero.rs:6:19 + --> tests/ui/zero_div_zero.rs:7:19 | LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/zero_div_zero.rs:8:25 + --> tests/ui/zero_div_zero.rs:10:25 | LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/zero_div_zero.rs:10:28 + --> tests/ui/zero_div_zero.rs:13: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 c7a69dee4b2d..dd2063ee5d9e 100644 --- a/tests/ui/zero_offset.rs +++ b/tests/ui/zero_offset.rs @@ -3,24 +3,32 @@ 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 + //~^ zst_offset + + m.wrapping_add(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + m.sub(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + m.wrapping_sub(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + let c = &() as *const (); c.offset(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + c.wrapping_add(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + c.sub(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + c.wrapping_sub(0); - //~^ ERROR: offset calculation on zero-sized value + //~^ zst_offset + let sized = &1 as *const i32; sized.offset(0); diff --git a/tests/ui/zero_offset.stderr b/tests/ui/zero_offset.stderr index a1efe3904c18..4dfde7d4e1b0 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 - --> tests/ui/zero_offset.rs:8:9 + --> tests/ui/zero_offset.rs:9:9 | LL | m.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:10:9 + --> tests/ui/zero_offset.rs:12:9 | LL | m.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:12:9 + --> tests/ui/zero_offset.rs:15:9 | LL | m.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:16:9 + --> tests/ui/zero_offset.rs:20:9 | LL | c.offset(0); | ^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:18:9 + --> tests/ui/zero_offset.rs:23:9 | LL | c.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:20:9 + --> tests/ui/zero_offset.rs:26:9 | LL | c.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:22:9 + --> tests/ui/zero_offset.rs:29:9 | LL | c.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_ptr.fixed b/tests/ui/zero_ptr.fixed index 5d99bc9b757d..f2375d57f3a2 100644 --- a/tests/ui/zero_ptr.fixed +++ b/tests/ui/zero_ptr.fixed @@ -2,11 +2,16 @@ pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { let _ = std::ptr::null::(); + //~^ zero_ptr let _ = std::ptr::null_mut::(); + //~^ zero_ptr let _: *const u8 = std::ptr::null(); + //~^ zero_ptr foo(0 as _, 0 as _); foo(std::ptr::null(), std::ptr::null_mut()); + //~^ zero_ptr + //~| zero_ptr let z = 0; let _ = z as *const usize; // this is currently not caught diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index 09d321c7a18d..ee01e426a43b 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -2,11 +2,16 @@ pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { let _ = 0 as *const usize; + //~^ zero_ptr let _ = 0 as *mut f64; + //~^ zero_ptr let _: *const u8 = 0 as *const _; + //~^ zero_ptr foo(0 as _, 0 as _); foo(0 as *const _, 0 as *mut _); + //~^ zero_ptr + //~| zero_ptr let z = 0; let _ = z as *const usize; // this is currently not caught diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr index a580bebd5d3a..8dc781f36258 100644 --- a/tests/ui/zero_ptr.stderr +++ b/tests/ui/zero_ptr.stderr @@ -8,25 +8,25 @@ LL | let _ = 0 as *const usize; = help: to override `-D warnings` add `#[allow(clippy::zero_ptr)]` error: `0 as *mut _` detected - --> tests/ui/zero_ptr.rs:5:13 + --> tests/ui/zero_ptr.rs:6:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `std::ptr::null_mut::()` error: `0 as *const _` detected - --> tests/ui/zero_ptr.rs:6:24 + --> tests/ui/zero_ptr.rs:8:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *const _` detected - --> tests/ui/zero_ptr.rs:9:9 + --> tests/ui/zero_ptr.rs:12:9 | LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *mut _` detected - --> tests/ui/zero_ptr.rs:9:24 + --> tests/ui/zero_ptr.rs:12: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 25143eee8cc3..bbb2464e41d2 100644 --- a/tests/ui/zero_ptr_no_std.fixed +++ b/tests/ui/zero_ptr_no_std.fixed @@ -4,7 +4,10 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let _ = core::ptr::null::(); + //~^ zero_ptr let _ = core::ptr::null_mut::(); + //~^ zero_ptr let _: *const u8 = core::ptr::null(); + //~^ zero_ptr 0 } diff --git a/tests/ui/zero_ptr_no_std.rs b/tests/ui/zero_ptr_no_std.rs index 965733b45d92..22fe2d24e4b1 100644 --- a/tests/ui/zero_ptr_no_std.rs +++ b/tests/ui/zero_ptr_no_std.rs @@ -4,7 +4,10 @@ pub fn main(_argc: isize, _argv: *const *const u8) -> isize { let _ = 0 as *const usize; + //~^ zero_ptr let _ = 0 as *mut f64; + //~^ zero_ptr let _: *const u8 = 0 as *const _; + //~^ zero_ptr 0 } diff --git a/tests/ui/zero_ptr_no_std.stderr b/tests/ui/zero_ptr_no_std.stderr index 014bf312bf32..77978d0a38b2 100644 --- a/tests/ui/zero_ptr_no_std.stderr +++ b/tests/ui/zero_ptr_no_std.stderr @@ -11,13 +11,13 @@ LL | #![deny(clippy::zero_ptr)] | ^^^^^^^^^^^^^^^^ error: `0 as *mut _` detected - --> tests/ui/zero_ptr_no_std.rs:7:13 + --> tests/ui/zero_ptr_no_std.rs:8:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `core::ptr::null_mut::()` error: `0 as *const _` detected - --> tests/ui/zero_ptr_no_std.rs:8:24 + --> tests/ui/zero_ptr_no_std.rs:10:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `core::ptr::null()` diff --git a/tests/ui/zero_repeat_side_effects.fixed b/tests/ui/zero_repeat_side_effects.fixed index 989e8ae70e58..fb9d7880a4a7 100644 --- a/tests/ui/zero_repeat_side_effects.fixed +++ b/tests/ui/zero_repeat_side_effects.fixed @@ -16,27 +16,36 @@ fn main() { // on arrays f(); let a: [i32; 0] = []; + //~^ zero_repeat_side_effects let mut b; f(); b = [] as [i32; 0]; + //~^ zero_repeat_side_effects // on vecs // vecs dont support inferring value of consts f(); let c: std::vec::Vec = vec![]; + //~^ zero_repeat_side_effects let d; f(); d = vec![] as std::vec::Vec; + //~^ zero_repeat_side_effects // for macros println!("side effect"); let e: [(); 0] = []; + //~^ zero_repeat_side_effects // for nested calls { f() }; let g: [i32; 0] = []; + //~^ zero_repeat_side_effects // as function param drop({ f(); vec![] as std::vec::Vec }); + //~^ zero_repeat_side_effects // when singled out/not part of assignment/local { f(); vec![] as std::vec::Vec }; + //~^ zero_repeat_side_effects { f(); [] as [i32; 0] }; + //~^ zero_repeat_side_effects // should not trigger let a = [f(); N]; diff --git a/tests/ui/zero_repeat_side_effects.rs b/tests/ui/zero_repeat_side_effects.rs index 68511f41a95e..8b22ff840244 100644 --- a/tests/ui/zero_repeat_side_effects.rs +++ b/tests/ui/zero_repeat_side_effects.rs @@ -16,27 +16,36 @@ fn main() { // on arrays let a = [f(); 0]; + //~^ zero_repeat_side_effects let mut b; b = [f(); 0]; + //~^ zero_repeat_side_effects // on vecs // vecs dont support inferring value of consts let c = vec![f(); 0]; + //~^ zero_repeat_side_effects let d; d = vec![f(); 0]; + //~^ zero_repeat_side_effects // for macros let e = [println!("side effect"); 0]; + //~^ zero_repeat_side_effects // for nested calls let g = [{ f() }; 0]; + //~^ zero_repeat_side_effects // as function param drop(vec![f(); 0]); + //~^ zero_repeat_side_effects // when singled out/not part of assignment/local vec![f(); 0]; + //~^ zero_repeat_side_effects [f(); 0]; + //~^ zero_repeat_side_effects // should not trigger let a = [f(); N]; diff --git a/tests/ui/zero_repeat_side_effects.stderr b/tests/ui/zero_repeat_side_effects.stderr index d578e22b9716..2dba52e2112e 100644 --- a/tests/ui/zero_repeat_side_effects.stderr +++ b/tests/ui/zero_repeat_side_effects.stderr @@ -8,49 +8,49 @@ LL | let a = [f(); 0]; = help: to override `-D warnings` add `#[allow(clippy::zero_repeat_side_effects)]` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:20:5 + --> tests/ui/zero_repeat_side_effects.rs:21:5 | LL | b = [f(); 0]; | ^^^^^^^^^^^^ help: consider using: `f(); b = [] as [i32; 0]` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:24:5 + --> tests/ui/zero_repeat_side_effects.rs:26:5 | LL | let c = vec![f(); 0]; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let c: std::vec::Vec = vec![];` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:26:5 + --> tests/ui/zero_repeat_side_effects.rs:29:5 | LL | d = vec![f(); 0]; | ^^^^^^^^^^^^^^^^ help: consider using: `f(); d = vec![] as std::vec::Vec` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:29:5 + --> tests/ui/zero_repeat_side_effects.rs:33:5 | LL | let e = [println!("side effect"); 0]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `println!("side effect"); let e: [(); 0] = [];` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:32:5 + --> tests/ui/zero_repeat_side_effects.rs:37:5 | LL | let g = [{ f() }; 0]; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `{ f() }; let g: [i32; 0] = [];` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:35:10 + --> tests/ui/zero_repeat_side_effects.rs:41:10 | LL | drop(vec![f(); 0]); | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec }` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:38:5 + --> tests/ui/zero_repeat_side_effects.rs:45:5 | LL | vec![f(); 0]; | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec }` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:39:5 + --> tests/ui/zero_repeat_side_effects.rs:47:5 | LL | [f(); 0]; | ^^^^^^^^ help: consider using: `{ f(); [] as [i32; 0] }` diff --git a/tests/ui/zero_sized_btreemap_values.rs b/tests/ui/zero_sized_btreemap_values.rs index 565f639201ff..ddcfce672bf9 100644 --- a/tests/ui/zero_sized_btreemap_values.rs +++ b/tests/ui/zero_sized_btreemap_values.rs @@ -3,28 +3,34 @@ use std::collections::BTreeMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + type OkMap = BTreeMap; type NotOkMap = BTreeMap; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + enum TestEnum { Ok(BTreeMap), NotOk(BTreeMap), - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } struct Test { ok: BTreeMap, not_ok: BTreeMap, - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + also_not_ok: Vec>, - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } trait TestTrait { @@ -33,7 +39,8 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: BTreeMap); - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } impl Test { @@ -42,7 +49,8 @@ impl Test { } fn not_ok(&self) -> BTreeMap { - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + todo!() } } @@ -60,8 +68,10 @@ 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 +//~^ zero_sized_map_values +//~| zero_sized_map_values + + todo!(); } @@ -71,10 +81,13 @@ 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 + //~^ zero_sized_map_values + //~| zero_sized_map_values + + let _: BTreeMap = BTreeMap::new(); let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index 65fc81e10e6c..f9184dc9ae1f 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -9,7 +9,7 @@ LL | const CONST_NOT_OK: Option> = None; = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:9:30 + --> tests/ui/zero_sized_btreemap_values.rs:10:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:13:17 + --> tests/ui/zero_sized_btreemap_values.rs:15:17 | LL | type NotOkMap = BTreeMap; | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | type NotOkMap = BTreeMap; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:18:11 + --> tests/ui/zero_sized_btreemap_values.rs:21:11 | LL | NotOk(BTreeMap), | ^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | NotOk(BTreeMap), = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:24:13 + --> tests/ui/zero_sized_btreemap_values.rs:28:13 | LL | not_ok: BTreeMap, | ^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | not_ok: BTreeMap, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:26:22 + --> tests/ui/zero_sized_btreemap_values.rs:31:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:35:30 + --> tests/ui/zero_sized_btreemap_values.rs:41:30 | LL | fn weird_map(&self, map: BTreeMap); | ^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | fn weird_map(&self, map: BTreeMap); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:44:25 + --> tests/ui/zero_sized_btreemap_values.rs:51:25 | LL | fn not_ok(&self) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | fn not_ok(&self) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:62:14 + --> tests/ui/zero_sized_btreemap_values.rs:70:14 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:62:50 + --> tests/ui/zero_sized_btreemap_values.rs:70:50 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:73:35 + --> tests/ui/zero_sized_btreemap_values.rs:83:35 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:73:12 + --> tests/ui/zero_sized_btreemap_values.rs:83:12 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:78:12 + --> tests/ui/zero_sized_btreemap_values.rs:90: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 5498261ee95a..132716da3b27 100644 --- a/tests/ui/zero_sized_hashmap_values.rs +++ b/tests/ui/zero_sized_hashmap_values.rs @@ -3,28 +3,34 @@ use std::collections::HashMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + type OkMap = HashMap; type NotOkMap = HashMap; -//~^ ERROR: map with zero-sized value type +//~^ zero_sized_map_values + enum TestEnum { Ok(HashMap), NotOk(HashMap), - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } struct Test { ok: HashMap, not_ok: HashMap, - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + also_not_ok: Vec>, - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } trait TestTrait { @@ -33,7 +39,8 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: HashMap); - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } impl Test { @@ -42,7 +49,8 @@ impl Test { } fn not_ok(&self) -> HashMap { - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + todo!() } } @@ -60,8 +68,10 @@ 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 +//~^ zero_sized_map_values +//~| zero_sized_map_values + + todo!(); } @@ -71,10 +81,13 @@ 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 + //~^ zero_sized_map_values + //~| zero_sized_map_values + + let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); - //~^ ERROR: map with zero-sized value type + //~^ zero_sized_map_values + } diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 08afef58a2aa..059902047b55 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -9,7 +9,7 @@ LL | const CONST_NOT_OK: Option> = None; = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:9:30 + --> tests/ui/zero_sized_hashmap_values.rs:10:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:13:17 + --> tests/ui/zero_sized_hashmap_values.rs:15:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:18:11 + --> tests/ui/zero_sized_hashmap_values.rs:21:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:24:13 + --> tests/ui/zero_sized_hashmap_values.rs:28:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:26:22 + --> tests/ui/zero_sized_hashmap_values.rs:31:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:35:30 + --> tests/ui/zero_sized_hashmap_values.rs:41:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | fn weird_map(&self, map: HashMap); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:44:25 + --> tests/ui/zero_sized_hashmap_values.rs:51:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:62:14 + --> tests/ui/zero_sized_hashmap_values.rs:70:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:62:49 + --> tests/ui/zero_sized_hashmap_values.rs:70:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:73:34 + --> tests/ui/zero_sized_hashmap_values.rs:83:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:73:12 + --> tests/ui/zero_sized_hashmap_values.rs:83:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:78:12 + --> tests/ui/zero_sized_hashmap_values.rs:90:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ diff --git a/tests/ui/zombie_processes.rs b/tests/ui/zombie_processes.rs index 6f0d2760a860..25bbc02ffb76 100644 --- a/tests/ui/zombie_processes.rs +++ b/tests/ui/zombie_processes.rs @@ -13,6 +13,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + x.kill(); x.id(); } @@ -40,6 +41,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + let v = &x; // (allow shared refs is fine because one cannot call `.wait()` through that) } @@ -65,6 +67,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { std::process::exit(0); } @@ -72,6 +75,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { while false {} // Calling `exit()` after leaving a while loop should still be linted. @@ -98,6 +102,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { return; } @@ -107,6 +112,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { x.wait().unwrap(); } @@ -115,6 +121,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { x.wait().unwrap(); } else { @@ -125,6 +132,7 @@ fn main() { { let mut x = Command::new("").spawn().unwrap(); //~^ zombie_processes + if true { // this else block exists to test the other help message } else { diff --git a/tests/ui/zombie_processes.stderr b/tests/ui/zombie_processes.stderr index afc518c60db2..0374d097b1b5 100644 --- a/tests/ui/zombie_processes.stderr +++ b/tests/ui/zombie_processes.stderr @@ -11,7 +11,7 @@ LL | let mut x = Command::new("").spawn().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::zombie_processes)]` error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes.rs:41:21 + --> tests/ui/zombie_processes.rs:42:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let mut x = Command::new("").spawn().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes.rs:66:21 + --> tests/ui/zombie_processes.rs:68:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | let mut x = Command::new("").spawn().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes.rs:73:21 + --> tests/ui/zombie_processes.rs:76:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,18 +41,18 @@ LL | let mut x = Command::new("").spawn().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is not `wait()`ed on in all code paths - --> tests/ui/zombie_processes.rs:99:21 + --> tests/ui/zombie_processes.rs:103:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: no `wait()` call exists on the code path to this early return - --> tests/ui/zombie_processes.rs:102:13 + --> tests/ui/zombie_processes.rs:107:13 | LL | return; | ^^^^^^ note: `wait()` call exists, but it is unreachable due to the early return - --> tests/ui/zombie_processes.rs:104:9 + --> tests/ui/zombie_processes.rs:109:9 | LL | x.wait().unwrap(); | ^ @@ -61,20 +61,20 @@ LL | x.wait().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is not `wait()`ed on in all code paths - --> tests/ui/zombie_processes.rs:108:21 + --> tests/ui/zombie_processes.rs:113:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this if expression has a `wait()` call, but it is missing an else block - --> tests/ui/zombie_processes.rs:110:9 + --> tests/ui/zombie_processes.rs:116:9 | LL | / if true { LL | | x.wait().unwrap(); LL | | } | |_________^ note: `wait()` called here - --> tests/ui/zombie_processes.rs:111:13 + --> tests/ui/zombie_processes.rs:117:13 | LL | x.wait().unwrap(); | ^ @@ -83,13 +83,13 @@ LL | x.wait().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is not `wait()`ed on in all code paths - --> tests/ui/zombie_processes.rs:116:21 + --> tests/ui/zombie_processes.rs:122:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `wait()` is not called in this if branch - --> tests/ui/zombie_processes.rs:120:10 + --> tests/ui/zombie_processes.rs:127:10 | LL | } else { | __________^ @@ -97,7 +97,7 @@ LL | | // this else block exists to test the other help message LL | | } | |_________^ note: `wait()` is called in the other branch - --> tests/ui/zombie_processes.rs:119:13 + --> tests/ui/zombie_processes.rs:126:13 | LL | x.wait().unwrap(); | ^ @@ -106,20 +106,20 @@ LL | x.wait().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is not `wait()`ed on in all code paths - --> tests/ui/zombie_processes.rs:126:21 + --> tests/ui/zombie_processes.rs:133:21 | LL | let mut x = Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `wait()` is not called in this if branch - --> tests/ui/zombie_processes.rs:128:9 + --> tests/ui/zombie_processes.rs:136:9 | LL | / if true { LL | | // this else block exists to test the other help message LL | | } else { | |_________^ note: `wait()` is called in the other branch - --> tests/ui/zombie_processes.rs:131:13 + --> tests/ui/zombie_processes.rs:139:13 | LL | x.wait().unwrap(); | ^ diff --git a/tests/ui/zombie_processes_fixable.fixed b/tests/ui/zombie_processes_fixable.fixed index 6045262f519a..220abbfcfd7b 100644 --- a/tests/ui/zombie_processes_fixable.fixed +++ b/tests/ui/zombie_processes_fixable.fixed @@ -5,16 +5,20 @@ use std::process::{Child, Command}; fn main() { let _ = Command::new("").spawn().unwrap().wait(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + Command::new("").spawn().unwrap().wait(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + spawn_proc().wait(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + spawn_proc().wait().unwrap(); // OK } fn not_main() { Command::new("").spawn().unwrap().wait(); + //~^ zombie_processes } fn spawn_proc() -> Child { diff --git a/tests/ui/zombie_processes_fixable.rs b/tests/ui/zombie_processes_fixable.rs index e1ecb771641e..820a839cd461 100644 --- a/tests/ui/zombie_processes_fixable.rs +++ b/tests/ui/zombie_processes_fixable.rs @@ -5,16 +5,20 @@ use std::process::{Child, Command}; fn main() { let _ = Command::new("").spawn().unwrap(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + Command::new("").spawn().unwrap(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + spawn_proc(); - //~^ ERROR: spawned process is never `wait()`ed on + //~^ zombie_processes + spawn_proc().wait().unwrap(); // OK } fn not_main() { Command::new("").spawn().unwrap(); + //~^ zombie_processes } fn spawn_proc() -> Child { diff --git a/tests/ui/zombie_processes_fixable.stderr b/tests/ui/zombie_processes_fixable.stderr index e1c40472c325..abc593fe4396 100644 --- a/tests/ui/zombie_processes_fixable.stderr +++ b/tests/ui/zombie_processes_fixable.stderr @@ -10,7 +10,7 @@ LL | let _ = Command::new("").spawn().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::zombie_processes)]` error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes_fixable.rs:9:5 + --> tests/ui/zombie_processes_fixable.rs:10:5 | LL | Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try: `.wait()` @@ -19,7 +19,7 @@ LL | Command::new("").spawn().unwrap(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes_fixable.rs:11:5 + --> tests/ui/zombie_processes_fixable.rs:13:5 | LL | spawn_proc(); | ^^^^^^^^^^^^- help: try: `.wait()` @@ -28,7 +28,7 @@ LL | spawn_proc(); = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning error: spawned process is never `wait()`ed on - --> tests/ui/zombie_processes_fixable.rs:17:5 + --> tests/ui/zombie_processes_fixable.rs:20:5 | LL | Command::new("").spawn().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try: `.wait()` From 10184ecbe1f5c9036cfbe779adfd4248d070619d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Feb 2025 18:22:04 +0100 Subject: [PATCH 085/161] Allowed `clippy::tests/ui/attrs.2.fixed` in `tests/ui/attr.rs` because when adding annotations, it doesn't work anymore --- tests/ui/attrs.rs | 2 +- tests/ui/attrs.stderr | 44 +------------------------------------------ 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 6f08bb304260..32e4053e74b0 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -1,5 +1,5 @@ #![warn(clippy::inline_always, clippy::deprecated_semver)] -#![allow(clippy::assertions_on_constants)] +#![allow(clippy::assertions_on_constants, clippy::empty_line_after_outer_attr)] #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index 74d4068f6331..f4803380cc41 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -13,24 +13,6 @@ error: the since field must contain a semver-compliant version LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ -error: empty lines after outer attribute - --> tests/ui/attrs.rs:5:1 - | -LL | / #[inline(always)] -... | -LL | | - | |_^ -LL | fn test_attr_lint() { - | ------------------- the attribute applies to this function - | - = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` - = help: if the empty lines are unintentional remove them -help: if the attribute should apply to the crate use an inner attribute - | -LL | #![inline(always)] - | + - error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea --> tests/ui/attrs.rs:5:1 | @@ -40,29 +22,5 @@ LL | #[inline(always)] = note: `-D clippy::inline-always` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::inline_always)]` -error: empty lines after outer attribute - --> tests/ui/attrs.rs:28:1 - | -LL | / #[deprecated(since = "forever")] -... | -LL | | - | |_^ -LL | pub const SOME_CONST: u8 = 42; - | ------------------------ the attribute applies to this constant - | - = help: if the empty lines are unintentional remove them - -error: empty line after outer attribute - --> tests/ui/attrs.rs:34:1 - | -LL | / #[deprecated(since = "1")] -LL | | -LL | | - | |_^ -LL | pub const ANOTHER_CONST: u8 = 23; - | --------------------------- the attribute applies to this constant - | - = help: if the empty line is unintentional remove it - -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors From 0a990758fb4293ecadf0a5731d64ac49ebe44b78 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Feb 2025 17:21:40 +0100 Subject: [PATCH 086/161] Handle compilation error in `builtin_type_shadow.rs` --- tests/ui/builtin_type_shadow.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ui/builtin_type_shadow.rs b/tests/ui/builtin_type_shadow.rs index 41d6207ea3f5..31df0c21b67e 100644 --- a/tests/ui/builtin_type_shadow.rs +++ b/tests/ui/builtin_type_shadow.rs @@ -3,8 +3,7 @@ fn foo(a: u32) -> u32 { //~^ builtin_type_shadow - 42 - + 42 //~ ERROR: mismatched type } fn main() {} From d5ebe505053748b3bbea506f7b6d8d5ee0cf61a2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Feb 2025 17:42:51 +0100 Subject: [PATCH 087/161] Add manual annotations --- tests/ui/expect_tool_lint_rfc_2383.rs | 3 +++ tests/ui/expect_tool_lint_rfc_2383.stderr | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs index 2634c56794e7..2295691c8127 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -30,11 +30,14 @@ mod rustc_warn { #[expect(dead_code)] //~^ ERROR: this lint expectation is unfulfilled //~| NOTE: `-D unfulfilled-lint-expectations` implied by `-D warnings` + //~| HELP: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` pub fn rustc_lints() { let x = 42; #[expect(invalid_nan_comparisons)] //~^ ERROR: this lint expectation is unfulfilled + //~| NOTE: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + //~| ERROR: this lint expectation is unfulfilled let _b = x == 5; } } diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 028e22ca724e..b274d5c23693 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -8,13 +8,13 @@ LL | #[expect(dead_code)] = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:36:18 + --> tests/ui/expect_tool_lint_rfc_2383.rs:37:18 | LL | #[expect(invalid_nan_comparisons)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:36:18 + --> tests/ui/expect_tool_lint_rfc_2383.rs:37:18 | LL | #[expect(invalid_nan_comparisons)] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,25 +22,25 @@ LL | #[expect(invalid_nan_comparisons)] = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:107:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:110:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:115:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:118:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:121:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:124:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> tests/ui/expect_tool_lint_rfc_2383.rs:127:14 + --> tests/ui/expect_tool_lint_rfc_2383.rs:130:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 8a2dae63c3737ed9623035d55ed5e0e90e2942ab Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Feb 2025 17:55:46 +0100 Subject: [PATCH 088/161] Make `if_let_mutex` test pass on both 2021 and 2024 editions --- tests/ui/if_let_mutex.edition2021.stderr | 8 ++++---- tests/ui/if_let_mutex.rs | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/ui/if_let_mutex.edition2021.stderr b/tests/ui/if_let_mutex.edition2021.stderr index 984d6adbb2a4..58afd03c8c24 100644 --- a/tests/ui/if_let_mutex.edition2021.stderr +++ b/tests/ui/if_let_mutex.edition2021.stderr @@ -1,5 +1,5 @@ error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> tests/ui/if_let_mutex.rs:16:5 + --> tests/ui/if_let_mutex.rs:17:5 | LL | if let Err(locked) = m.lock() { | ^ - this Mutex will remain locked for the entire `if let`-block... @@ -19,7 +19,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::if_let_mutex)]` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> tests/ui/if_let_mutex.rs:29:5 + --> tests/ui/if_let_mutex.rs:30:5 | LL | if let Some(locked) = m.lock().unwrap().deref() { | ^ - this Mutex will remain locked for the entire `if let`-block... @@ -37,7 +37,7 @@ 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 - --> tests/ui/if_let_mutex.rs:51:5 + --> tests/ui/if_let_mutex.rs:52:5 | LL | if let Ok(i) = mutex.lock() { | ^ ----- this Mutex will remain locked for the entire `if let`-block... @@ -54,7 +54,7 @@ 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 - --> tests/ui/if_let_mutex.rs:60:5 + --> tests/ui/if_let_mutex.rs:61:5 | LL | if let Ok(_) = m1.lock() { | ^ -- this Mutex will remain locked for the entire `if let`-block... diff --git a/tests/ui/if_let_mutex.rs b/tests/ui/if_let_mutex.rs index ddf178b63048..72058ea33ee7 100644 --- a/tests/ui/if_let_mutex.rs +++ b/tests/ui/if_let_mutex.rs @@ -3,6 +3,7 @@ //@revisions: edition2021 edition2024 //@[edition2021] edition:2021 //@[edition2024] edition:2024 +//@[edition2024] check-pass #![warn(clippy::if_let_mutex)] #![allow(clippy::redundant_pattern_matching)] @@ -62,10 +63,7 @@ fn multiple_mutexes(m1: &Mutex<()>, m2: &Mutex<()>) { } else { m1.lock(); } - //~^ if_let_mutex - //~^ if_let_mutex - //~^ if_let_mutex - //~^ if_let_mutex + //~[edition2021]^^^^^ if_let_mutex } fn main() {} From 1f94d55a183c493ae2ca2754d9485f89e4ac76ae Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Feb 2025 23:44:38 +0100 Subject: [PATCH 089/161] Fix new tests updates --- tests/ui/as_pointer_underscore.fixed | 2 - tests/ui/as_pointer_underscore.rs | 2 - tests/ui/as_pointer_underscore.stderr | 2 +- tests/ui/as_ptr_cast_mut.rs | 1 - tests/ui/as_ptr_cast_mut.stderr | 2 +- tests/ui/asm_syntax_x86.rs | 2 - tests/ui/asm_syntax_x86.stderr | 2 +- tests/ui/assertions_on_constants.rs | 6 - tests/ui/assertions_on_constants.stderr | 16 +- tests/ui/assign_ops2.rs | 3 - tests/ui/assign_ops2.stderr | 18 +- tests/ui/attrs.rs | 2 - tests/ui/attrs.stderr | 4 +- tests/ui/await_holding_refcell_ref.rs | 2 - tests/ui/await_holding_refcell_ref.stderr | 14 +- tests/ui/bind_instead_of_map_multipart.fixed | 2 +- tests/ui/bind_instead_of_map_multipart.rs | 2 +- tests/ui/bit_masks.rs | 9 - tests/ui/bit_masks.stderr | 30 +-- tests/ui/blanket_clippy_restriction_lints.rs | 3 - .../blanket_clippy_restriction_lints.stderr | 4 +- tests/ui/bool_comparison.fixed | 28 +-- tests/ui/bool_comparison.rs | 28 +-- tests/ui/bool_to_int_with_if.rs | 16 +- tests/ui/borrow_box.fixed | 6 - tests/ui/borrow_box.rs | 6 - tests/ui/borrow_box.stderr | 18 +- tests/ui/borrow_deref_ref_unfixable.rs | 2 - .../borrow_interior_mutable_const/others.rs | 56 ++--- .../others.stderr | 112 ++++----- .../borrow_interior_mutable_const/traits.rs | 68 ++--- .../traits.stderr | 102 ++++---- tests/ui/box_collection.rs | 9 - tests/ui/box_collection.stderr | 16 +- tests/ui/boxed_local.rs | 7 +- tests/ui/boxed_local.stderr | 6 +- .../branches_sharing_code/shared_at_bottom.rs | 10 +- .../shared_at_bottom.stderr | 31 ++- .../ui/branches_sharing_code/shared_at_top.rs | 15 +- .../shared_at_top.stderr | 14 +- .../shared_at_top_and_bottom.rs | 10 +- .../branches_sharing_code/valid_if_blocks.rs | 5 - .../valid_if_blocks.stderr | 16 +- tests/ui/builtin_type_shadow.rs | 2 +- tests/ui/bytecount.rs | 3 - tests/ui/bytecount.stderr | 4 +- tests/ui/cast.rs | 24 -- tests/ui/cast.stderr | 182 +++++++------- tests/ui/cast_alignment.rs | 3 - tests/ui/cast_alignment.stderr | 6 +- tests/ui/cast_enum_constructor.rs | 1 - tests/ui/cast_enum_constructor.stderr | 2 +- tests/ui/cast_lossless_integer.fixed | 13 - tests/ui/cast_lossless_integer.rs | 13 - tests/ui/cast_lossless_integer.stderr | 64 ++--- tests/ui/cast_nan_to_int.rs | 8 - tests/ui/cast_nan_to_int.stderr | 10 +- tests/ui/cast_slice_different_sizes.rs | 20 +- tests/ui/cast_slice_different_sizes.stderr | 28 +-- tests/ui/char_lit_as_u8.rs | 2 - .../ui/checked_unwrap/complex_conditionals.rs | 4 - .../complex_conditionals.stderr | 32 +-- .../ui/checked_unwrap/simple_conditionals.rs | 18 +- .../checked_unwrap/simple_conditionals.stderr | 46 ++-- tests/ui/cmp_null.fixed | 10 +- tests/ui/cmp_null.rs | 10 +- tests/ui/cmp_null.stderr | 8 +- tests/ui/cmp_owned/comparison_flip.fixed | 4 +- tests/ui/cmp_owned/comparison_flip.rs | 4 +- tests/ui/cmp_owned/without_suggestion.rs | 4 - tests/ui/cmp_owned/without_suggestion.stderr | 4 +- tests/ui/cognitive_complexity.rs | 37 ++- tests/ui/cognitive_complexity.stderr | 32 +-- tests/ui/cognitive_complexity_attr_used.rs | 2 +- tests/ui/collapsible_match.rs | 32 +-- tests/ui/collapsible_match.stderr | 62 +++-- tests/ui/collapsible_match2.rs | 14 +- tests/ui/collapsible_match2.stderr | 28 +-- tests/ui/collection_is_never_read.rs | 1 - tests/ui/collection_is_never_read.stderr | 38 +-- tests/ui/comparison_chain.rs | 16 +- tests/ui/comparison_to_empty.fixed | 2 +- tests/ui/comparison_to_empty.rs | 2 +- tests/ui/const_comparisons.rs | 30 --- tests/ui/const_comparisons.stderr | 60 ++--- tests/ui/const_is_empty.rs | 21 +- tests/ui/const_is_empty.stderr | 52 ++-- tests/ui/copy_iterator.rs | 3 +- tests/ui/copy_iterator.stderr | 3 + tests/ui/crashes/ice-11803.rs | 4 +- tests/ui/crashes/ice-2774.fixed | 3 +- tests/ui/crashes/ice-2774.rs | 3 +- tests/ui/crashes/ice-360.rs | 7 +- tests/ui/crashes/ice-360.stderr | 2 +- tests/ui/crashes/ice-3717.fixed | 2 +- tests/ui/crashes/ice-3717.rs | 2 +- tests/ui/crashes/ice-3969.rs | 8 +- tests/ui/crashes/ice-5872.fixed | 2 - tests/ui/crashes/ice-5872.rs | 2 - tests/ui/crashes/ice-6250.rs | 4 +- tests/ui/crashes/ice-6251.rs | 6 +- tests/ui/crashes/ice-7169.fixed | 2 - tests/ui/crashes/ice-7169.rs | 2 - tests/ui/crashes/ice-7869.rs | 3 +- tests/ui/crashes/ice-7869.stderr | 1 - tests/ui/crashes/ice-8250.fixed | 1 - tests/ui/crashes/ice-8250.rs | 1 - tests/ui/crashes/ice-9041.rs | 2 - .../needless_lifetimes_impl_trait.fixed | 2 +- .../crashes/needless_lifetimes_impl_trait.rs | 2 +- .../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 | 1 - .../crate_level_checks/std_main_recursion.rs | 1 - tests/ui/dbg_macro/dbg_macro.fixed | 12 +- tests/ui/dbg_macro/dbg_macro.rs | 12 +- tests/ui/dbg_macro/dbg_macro.stderr | 54 ++-- tests/ui/dbg_macro/dbg_macro_unfixable.rs | 1 - .../declare_interior_mutable_const/enums.rs | 39 ++- .../enums.stderr | 53 ++-- .../declare_interior_mutable_const/others.rs | 2 - .../others.stderr | 4 +- .../declare_interior_mutable_const/traits.rs | 49 ++-- .../traits.stderr | 72 +++--- 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_union_representation.rs | 12 +- tests/ui/default_union_representation.stderr | 10 +- tests/ui/deref_addrof_double_trigger.rs | 4 - tests/ui/deref_addrof_double_trigger.stderr | 4 +- tests/ui/derivable_impls.rs | 22 +- tests/ui/derive.rs | 10 +- tests/ui/derive_ord_xor_partial_ord.rs | 4 +- tests/ui/disallowed_names.rs | 10 +- tests/ui/disallowed_names.stderr | 26 +- tests/ui/disallowed_script_idents.rs | 1 - tests/ui/diverging_sub_expression.rs | 2 - tests/ui/diverging_sub_expression.stderr | 20 +- tests/ui/doc/issue_12795.fixed | 4 - tests/ui/doc/issue_12795.rs | 4 - tests/ui/doc_errors.rs | 14 +- tests/ui/doc_errors.stderr | 12 +- tests/ui/doc_unsafe.rs | 10 +- tests/ui/double_comparison.fixed | 16 +- tests/ui/double_comparison.rs | 16 +- tests/ui/double_must_use.rs | 8 +- tests/ui/duplicate_underscore_argument.rs | 1 - tests/ui/else_if_without_else.rs | 8 +- tests/ui/empty_drop.rs | 4 +- tests/ui/empty_enum.rs | 1 - .../empty_enum_variants_with_brackets.fixed | 18 +- tests/ui/empty_enum_variants_with_brackets.rs | 18 +- .../empty_enum_variants_with_brackets.stderr | 24 +- .../ui/empty_line_after/doc_comments.1.fixed | 11 +- .../ui/empty_line_after/doc_comments.2.fixed | 13 +- tests/ui/empty_line_after/doc_comments.rs | 11 +- tests/ui/empty_line_after/doc_comments.stderr | 32 +-- tests/ui/empty_loop_no_std.rs | 1 - tests/ui/entry.fixed | 18 +- tests/ui/entry.rs | 22 +- tests/ui/entry_btree.fixed | 2 +- tests/ui/entry_btree.rs | 2 +- tests/ui/entry_with_else.fixed | 14 +- tests/ui/entry_with_else.rs | 14 +- tests/ui/enum_clike_unportable_variant.rs | 10 - tests/ui/enum_clike_unportable_variant.stderr | 16 +- tests/ui/enum_variants.rs | 21 +- tests/ui/enum_variants.stderr | 19 +- tests/ui/eprint_with_newline.fixed | 8 +- tests/ui/eprint_with_newline.rs | 8 +- tests/ui/eprint_with_newline.stderr | 20 +- tests/ui/eq_op.rs | 13 - tests/ui/eq_op.stderr | 56 ++--- tests/ui/equatable_if_let.fixed | 2 +- tests/ui/equatable_if_let.rs | 2 +- tests/ui/erasing_op.rs | 2 - tests/ui/erasing_op.stderr | 8 +- tests/ui/error_impl_error.rs | 6 +- tests/ui/error_impl_error.stderr | 12 +- tests/ui/exhaustive_items.fixed | 6 +- tests/ui/exhaustive_items.rs | 6 +- tests/ui/exit1.rs | 2 - tests/ui/exit2.rs | 2 - tests/ui/expect.rs | 2 - tests/ui/expect.stderr | 4 +- tests/ui/explicit_counter_loop.rs | 22 +- tests/ui/explicit_counter_loop.stderr | 18 +- tests/ui/explicit_deref_methods.fixed | 2 +- tests/ui/explicit_deref_methods.rs | 2 +- tests/ui/extra_unused_lifetimes.rs | 8 +- tests/ui/extra_unused_type_parameters.fixed | 16 +- tests/ui/extra_unused_type_parameters.rs | 16 +- .../extra_unused_type_parameters_unfixable.rs | 3 - ...ra_unused_type_parameters_unfixable.stderr | 4 +- tests/ui/fallible_impl_from.rs | 8 +- tests/ui/filetype_is_file.rs | 6 +- tests/ui/filter_map_bool_then.fixed | 6 +- tests/ui/filter_map_bool_then.rs | 6 +- tests/ui/filter_map_identity.fixed | 20 +- tests/ui/filter_map_identity.rs | 10 +- tests/ui/filter_map_identity.stderr | 42 ++-- tests/ui/float_arithmetic.rs | 5 - tests/ui/float_arithmetic.stderr | 8 +- tests/ui/float_cmp.rs | 3 - tests/ui/float_cmp.stderr | 6 +- tests/ui/float_cmp_const.rs | 3 - tests/ui/float_cmp_const.stderr | 6 +- tests/ui/float_equality_without_abs.rs | 4 - tests/ui/float_equality_without_abs.stderr | 20 +- tests/ui/fn_to_numeric_cast_any.rs | 8 - tests/ui/fn_to_numeric_cast_any.stderr | 32 +-- tests/ui/for_kv_map.fixed | 13 +- tests/ui/for_kv_map.rs | 13 +- tests/ui/for_kv_map.stderr | 10 +- tests/ui/forget_non_drop.rs | 1 - tests/ui/forget_non_drop.stderr | 4 +- tests/ui/format.rs | 2 +- tests/ui/format_args.fixed | 4 +- tests/ui/format_args.rs | 4 +- tests/ui/format_args.stderr | 4 +- tests/ui/format_args_unfixable.rs | 8 +- tests/ui/format_args_unfixable.stderr | 34 ++- tests/ui/format_collect.rs | 4 +- tests/ui/format_collect.stderr | 16 +- tests/ui/format_push_string.rs | 8 +- tests/ui/format_push_string.stderr | 7 +- tests/ui/from_over_into.fixed | 14 +- tests/ui/from_over_into.rs | 14 +- tests/ui/from_over_into_unfixable.rs | 8 +- 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 | 4 - tests/ui/from_str_radix_10.rs | 4 - tests/ui/from_str_radix_10.stderr | 14 +- tests/ui/functions.rs | 9 - tests/ui/functions.stderr | 30 +-- tests/ui/functions_maxlines.rs | 3 +- tests/ui/functions_maxlines.stderr | 3 + tests/ui/future_not_send.rs | 14 +- tests/ui/future_not_send.stderr | 17 +- tests/ui/get_first.fixed | 1 - tests/ui/get_first.rs | 1 - tests/ui/identity_op.fixed | 7 - tests/ui/identity_op.rs | 7 - tests/ui/identity_op.stderr | 50 ++-- tests/ui/if_not_else.fixed | 12 +- tests/ui/if_not_else.rs | 12 +- tests/ui/if_same_then_else.rs | 5 - tests/ui/if_same_then_else.stderr | 20 +- tests/ui/if_same_then_else2.rs | 6 - tests/ui/if_same_then_else2.stderr | 20 +- tests/ui/if_then_some_else_none.fixed | 2 - tests/ui/if_then_some_else_none.rs | 8 +- tests/ui/if_then_some_else_none.stderr | 6 +- tests/ui/ifs_same_cond.rs | 11 +- tests/ui/ifs_same_cond.stderr | 12 +- tests/ui/impl.rs | 7 +- tests/ui/impl_trait_in_params.rs | 9 +- tests/ui/impl_trait_in_params.stderr | 20 +- tests/ui/implicit_hasher.fixed | 10 +- tests/ui/implicit_hasher.rs | 10 +- tests/ui/implicit_saturating_add.rs | 48 ++-- tests/ui/implicit_saturating_sub.rs | 48 ++-- tests/ui/implied_bounds_in_impls.fixed | 10 +- tests/ui/implied_bounds_in_impls.rs | 10 +- tests/ui/incompatible_msrv.rs | 2 - tests/ui/incompatible_msrv.stderr | 2 +- .../ui/inconsistent_struct_constructor.fixed | 4 +- tests/ui/inconsistent_struct_constructor.rs | 4 +- .../if_let_slice_binding.fixed | 21 +- .../if_let_slice_binding.rs | 21 +- .../if_let_slice_binding.stderr | 12 +- tests/ui/ineffective_open_options.fixed | 6 +- tests/ui/ineffective_open_options.rs | 8 +- tests/ui/ineffective_open_options.stderr | 12 +- tests/ui/infallible_destructuring_match.rs | 8 +- tests/ui/infinite_iter.rs | 9 +- tests/ui/infinite_iter.stderr | 27 +- tests/ui/infinite_loop.rs | 33 +-- tests/ui/infinite_loop.stderr | 36 +-- tests/ui/infinite_loops.rs | 42 ++-- tests/ui/inherent_to_string.rs | 4 +- tests/ui/init_numbered_fields.rs | 4 +- tests/ui/inspect_for_each.rs | 2 +- tests/ui/into_iter_on_ref.fixed | 104 ++++---- tests/ui/into_iter_on_ref.rs | 104 ++++---- tests/ui/into_iter_on_ref.stderr | 234 +++++++++--------- tests/ui/into_iter_without_iter.rs | 12 +- tests/ui/invalid_upcast_comparisons.rs | 5 - tests/ui/invalid_upcast_comparisons.stderr | 52 ++-- tests/ui/issue-7447.rs | 2 - tests/ui/issue-7447.stderr | 2 +- tests/ui/issue_2356.fixed | 2 +- tests/ui/issue_2356.rs | 2 +- tests/ui/issue_4266.rs | 5 +- tests/ui/issue_4266.stderr | 4 +- tests/ui/items_after_statement.rs | 7 +- tests/ui/items_after_statement.stderr | 8 +- .../items_after_test_module/root_module.fixed | 2 +- .../ui/items_after_test_module/root_module.rs | 2 +- tests/ui/iter_filter_is_ok.fixed | 13 +- tests/ui/iter_filter_is_ok.rs | 13 +- tests/ui/iter_filter_is_ok.stderr | 18 +- tests/ui/iter_filter_is_some.fixed | 11 +- tests/ui/iter_filter_is_some.rs | 11 +- tests/ui/iter_filter_is_some.stderr | 14 +- tests/ui/iter_kv_map.fixed | 8 +- tests/ui/iter_kv_map.rs | 8 +- tests/ui/iter_kv_map.stderr | 14 +- tests/ui/iter_not_returning_iterator.rs | 6 +- tests/ui/iter_not_returning_iterator.stderr | 4 +- tests/ui/iter_on_empty_collections.fixed | 2 +- tests/ui/iter_on_empty_collections.rs | 2 +- tests/ui/iter_out_of_bounds.rs | 17 +- tests/ui/iter_out_of_bounds.stderr | 22 +- tests/ui/iter_over_hash_type.rs | 26 +- tests/ui/iter_overeager_cloned.fixed | 2 +- tests/ui/iter_overeager_cloned.rs | 2 +- tests/ui/iter_skip_next_unfixable.rs | 2 - tests/ui/iter_skip_next_unfixable.stderr | 4 +- tests/ui/iter_without_into_iter.rs | 16 +- tests/ui/iterator_step_by_zero.rs | 5 - tests/ui/iterator_step_by_zero.stderr | 12 +- tests/ui/join_absolute_paths.rs | 4 - tests/ui/join_absolute_paths.stderr | 6 +- tests/ui/large_enum_variant.rs | 40 +-- tests/ui/large_futures.fixed | 9 +- tests/ui/large_futures.rs | 9 +- tests/ui/large_futures.stderr | 14 +- tests/ui/large_stack_frames.rs | 6 +- tests/ui/large_types_passed_by_value.rs | 4 +- tests/ui/len_without_is_empty.rs | 34 ++- tests/ui/len_without_is_empty.stderr | 40 +-- tests/ui/len_zero.fixed | 24 +- tests/ui/len_zero.rs | 24 +- tests/ui/let_and_return.edition2021.fixed | 11 - tests/ui/let_and_return.edition2021.stderr | 18 +- tests/ui/let_and_return.edition2024.fixed | 11 - tests/ui/let_and_return.edition2024.stderr | 28 +-- tests/ui/let_and_return.rs | 11 - tests/ui/let_if_seq.rs | 3 - tests/ui/let_if_seq.stderr | 17 +- tests/ui/let_underscore_future.rs | 2 - tests/ui/let_underscore_future.stderr | 2 +- tests/ui/let_underscore_must_use.rs | 7 - tests/ui/let_underscore_must_use.stderr | 18 +- tests/ui/let_unit.fixed | 4 +- tests/ui/let_unit.rs | 4 +- tests/ui/linkedlist.rs | 6 +- tests/ui/linkedlist.stderr | 14 +- tests/ui/literals.rs | 13 - tests/ui/literals.stderr | 38 +-- tests/ui/manual_arithmetic_check-2.rs | 2 - tests/ui/manual_arithmetic_check-2.stderr | 16 +- tests/ui/manual_arithmetic_check.fixed | 2 - tests/ui/manual_arithmetic_check.rs | 2 - tests/ui/manual_arithmetic_check.stderr | 4 +- tests/ui/manual_assert.rs | 20 +- tests/ui/manual_async_fn.rs | 18 +- tests/ui/manual_clamp.fixed | 21 -- tests/ui/manual_clamp.rs | 76 ++---- tests/ui/manual_clamp.stderr | 125 +++++++--- tests/ui/manual_div_ceil.fixed | 20 +- tests/ui/manual_div_ceil.rs | 20 +- tests/ui/manual_div_ceil.stderr | 30 +-- tests/ui/manual_filter.rs | 30 +-- tests/ui/manual_filter_map.rs | 2 +- tests/ui/manual_find.rs | 6 +- tests/ui/manual_find.stderr | 8 +- tests/ui/manual_find_fixable.rs | 22 +- tests/ui/manual_flatten.rs | 16 +- tests/ui/manual_ignore_case_cmp.fixed | 8 +- tests/ui/manual_ignore_case_cmp.rs | 8 +- tests/ui/manual_inspect.fixed | 26 +- tests/ui/manual_inspect.rs | 26 +- tests/ui/manual_let_else.rs | 50 ++-- tests/ui/manual_let_else.stderr | 61 +++-- tests/ui/manual_let_else_match.rs | 31 +-- tests/ui/manual_let_else_match.stderr | 30 +-- tests/ui/manual_let_else_question_mark.rs | 4 +- tests/ui/manual_map_option.rs | 38 +-- tests/ui/manual_map_option_2.rs | 14 +- tests/ui/manual_memcpy/with_loop_counters.rs | 23 +- .../manual_memcpy/with_loop_counters.stderr | 24 +- .../ui/manual_memcpy/without_loop_counters.rs | 37 ++- .../without_loop_counters.stderr | 38 +-- tests/ui/manual_non_exhaustive_enum.rs | 4 +- tests/ui/manual_ok_err.rs | 22 +- tests/ui/manual_ok_err.stderr | 20 +- tests/ui/manual_option_as_slice.fixed | 9 +- tests/ui/manual_option_as_slice.rs | 10 +- tests/ui/manual_option_as_slice.stderr | 13 +- tests/ui/manual_retain.rs | 4 +- tests/ui/manual_saturating_arithmetic.rs | 10 +- tests/ui/manual_slice_fill.rs | 8 +- tests/ui/manual_strip.rs | 4 - tests/ui/manual_strip.stderr | 16 +- tests/ui/manual_try_fold.rs | 4 +- tests/ui/manual_unwrap_or.rs | 28 +-- tests/ui/manual_unwrap_or_default.rs | 21 +- tests/ui/manual_unwrap_or_default.stderr | 19 +- .../ui/manual_unwrap_or_default_unfixable.rs | 2 +- tests/ui/many_single_char_names.rs | 5 - tests/ui/many_single_char_names.stderr | 4 +- tests/ui/map_all_any_identity.fixed | 1 - tests/ui/map_all_any_identity.rs | 1 - tests/ui/map_clone.fixed | 12 - tests/ui/map_clone.rs | 12 - tests/ui/map_clone.stderr | 14 +- tests/ui/map_err.rs | 1 - tests/ui/map_flatten.rs | 1 - tests/ui/map_flatten_fixable.fixed | 2 +- tests/ui/map_flatten_fixable.rs | 2 +- tests/ui/map_identity.rs | 4 +- ...map_with_unused_argument_over_ranges.fixed | 2 +- .../map_with_unused_argument_over_ranges.rs | 2 +- tests/ui/match_as_ref.rs | 6 +- tests/ui/match_bool.rs | 39 +-- tests/ui/match_bool.stderr | 50 ++-- tests/ui/match_on_vec_items.rs | 25 +- 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_ref_pats.fixed | 10 +- tests/ui/match_ref_pats.rs | 10 +- tests/ui/match_result_ok.fixed | 2 +- tests/ui/match_result_ok.rs | 2 +- tests/ui/match_same_arms.rs | 28 +-- tests/ui/match_same_arms.stderr | 60 ++--- tests/ui/match_same_arms2.fixed | 33 ++- tests/ui/match_same_arms2.rs | 43 ++-- tests/ui/match_same_arms2.stderr | 86 +++---- tests/ui/match_same_arms_non_exhaustive.fixed | 2 - tests/ui/match_same_arms_non_exhaustive.rs | 2 - .../ui/match_same_arms_non_exhaustive.stderr | 6 +- tests/ui/match_single_binding.rs | 48 ++-- tests/ui/match_single_binding2.fixed | 2 +- tests/ui/match_single_binding2.rs | 6 +- tests/ui/match_wild_err_arm.rs | 9 +- tests/ui/match_wild_err_arm.stderr | 6 +- tests/ui/mem_forget.rs | 8 - tests/ui/mem_forget.stderr | 6 +- tests/ui/mem_replace.stderr | 6 +- tests/ui/methods.rs | 2 +- tests/ui/methods_unfixable.rs | 1 - tests/ui/min_ident_chars.rs | 10 +- tests/ui/min_max.rs | 6 - tests/ui/min_max.stderr | 24 +- tests/ui/min_rust_version_attr.rs | 6 - tests/ui/min_rust_version_attr.stderr | 10 +- tests/ui/mismatching_type_param_order.rs | 10 - tests/ui/mismatching_type_param_order.stderr | 16 +- tests/ui/misnamed_getters.fixed | 37 ++- tests/ui/misnamed_getters.rs | 37 ++- tests/ui/misnamed_getters.stderr | 37 +-- tests/ui/missing_asserts_for_indexing.fixed | 5 - tests/ui/missing_asserts_for_indexing.rs | 5 - tests/ui/missing_asserts_for_indexing.stderr | 82 +++--- .../missing_asserts_for_indexing_unfixable.rs | 3 - ...sing_asserts_for_indexing_unfixable.stderr | 44 ++-- .../missing_const_for_fn/could_be_const.fixed | 36 +-- .../ui/missing_const_for_fn/could_be_const.rs | 36 +-- tests/ui/missing_const_for_thread_local.fixed | 4 - tests/ui/missing_const_for_thread_local.rs | 4 - .../ui/missing_const_for_thread_local.stderr | 10 +- tests/ui/missing_doc.rs | 6 +- tests/ui/missing_doc_crate_missing.rs | 2 - tests/ui/missing_doc_impl.rs | 6 +- tests/ui/missing_fields_in_debug.rs | 6 +- tests/ui/missing_inline.rs | 3 - tests/ui/missing_inline.stderr | 10 +- tests/ui/missing_panics_doc.rs | 24 +- tests/ui/missing_trait_methods.rs | 3 +- tests/ui/missing_trait_methods.stderr | 34 +-- tests/ui/mixed_read_write_in_expression.rs | 6 +- .../ui/mixed_read_write_in_expression.stderr | 12 +- tests/ui/module_inception.rs | 9 +- tests/ui/module_inception.stderr | 10 +- tests/ui/module_name_repetitions.rs | 3 - tests/ui/module_name_repetitions.stderr | 10 +- tests/ui/modulo_arithmetic_float.rs | 21 -- tests/ui/modulo_arithmetic_float.stderr | 30 +-- tests/ui/modulo_arithmetic_integral.rs | 25 -- tests/ui/modulo_arithmetic_integral.stderr | 32 +-- tests/ui/modulo_arithmetic_integral_const.rs | 19 -- .../modulo_arithmetic_integral_const.stderr | 32 +-- tests/ui/modulo_one.rs | 1 - tests/ui/modulo_one.stderr | 10 +- tests/ui/multi_assignments.rs | 3 - tests/ui/multi_assignments.stderr | 10 +- tests/ui/multiple_bound_locations.rs | 6 - tests/ui/multiple_bound_locations.stderr | 10 +- tests/ui/multiple_unsafe_ops_per_block.rs | 14 +- tests/ui/must_use_candidates.fixed | 10 +- tests/ui/must_use_candidates.rs | 10 +- tests/ui/mut_from_ref.rs | 11 +- tests/ui/mut_from_ref.stderr | 16 +- tests/ui/mut_key.rs | 8 +- tests/ui/mut_key.stderr | 26 +- tests/ui/mut_mut.rs | 2 +- tests/ui/mut_range_bound.rs | 10 - tests/ui/mut_range_bound.stderr | 12 +- tests/ui/mut_reference.rs | 3 - tests/ui/mut_reference.stderr | 4 +- tests/ui/mutex_atomic.rs | 3 - tests/ui/mutex_atomic.stderr | 20 +- tests/ui/needless_arbitrary_self_type.fixed | 12 +- tests/ui/needless_arbitrary_self_type.rs | 12 +- tests/ui/needless_as_bytes.fixed | 12 +- tests/ui/needless_as_bytes.rs | 12 +- tests/ui/needless_as_bytes.stderr | 12 +- tests/ui/needless_bitwise_bool.fixed | 2 +- tests/ui/needless_bitwise_bool.rs | 2 +- tests/ui/needless_borrow_pat.fixed | 16 +- tests/ui/needless_borrow_pat.rs | 16 +- tests/ui/needless_borrow_pat.stderr | 22 +- tests/ui/needless_borrowed_ref.fixed | 2 +- tests/ui/needless_borrowed_ref.rs | 2 +- tests/ui/needless_character_iteration.fixed | 3 - tests/ui/needless_character_iteration.rs | 7 +- tests/ui/needless_character_iteration.stderr | 10 +- tests/ui/needless_collect.fixed | 2 +- tests/ui/needless_collect.rs | 2 +- tests/ui/needless_continue.rs | 16 +- tests/ui/needless_continue.stderr | 36 +-- tests/ui/needless_for_each_fixable.fixed | 16 +- tests/ui/needless_for_each_fixable.rs | 16 +- tests/ui/needless_for_each_unfixable.rs | 3 +- tests/ui/needless_for_each_unfixable.stderr | 4 +- tests/ui/needless_if.fixed | 4 +- tests/ui/needless_if.rs | 4 +- tests/ui/needless_lifetimes.fixed | 76 +++--- tests/ui/needless_lifetimes.rs | 76 +++--- tests/ui/needless_match.rs | 22 +- tests/ui/needless_maybe_sized.fixed | 8 +- tests/ui/needless_maybe_sized.rs | 8 +- tests/ui/needless_option_take.fixed | 8 - tests/ui/needless_option_take.rs | 8 - tests/ui/needless_option_take.stderr | 16 +- tests/ui/needless_pass_by_ref_mut.rs | 46 ++-- tests/ui/needless_pass_by_ref_mut.stderr | 62 ++--- tests/ui/needless_pass_by_ref_mut2.fixed | 4 +- tests/ui/needless_pass_by_ref_mut2.rs | 4 +- tests/ui/needless_pass_by_value.rs | 45 ++-- tests/ui/needless_pass_by_value.stderr | 50 ++-- tests/ui/needless_range_loop.rs | 29 ++- tests/ui/needless_range_loop.stderr | 26 +- tests/ui/needless_range_loop2.rs | 17 +- 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 | 33 ++- tests/ui/never_loop.stderr | 30 +-- tests/ui/new_ret_no_self.rs | 24 +- tests/ui/new_ret_no_self.stderr | 28 ++- tests/ui/new_ret_no_self_overflow.rs | 2 +- tests/ui/new_without_default.fixed | 19 +- tests/ui/new_without_default.rs | 19 +- tests/ui/new_without_default.stderr | 20 +- tests/ui/no_effect.rs | 1 - tests/ui/no_effect.stderr | 6 +- tests/ui/no_effect_async_fn.rs | 4 - tests/ui/no_effect_async_fn.stderr | 6 +- tests/ui/no_effect_replace.rs | 3 - tests/ui/no_effect_replace.stderr | 14 +- tests/ui/no_effect_return.rs | 9 - tests/ui/no_effect_return.stderr | 16 +- tests/ui/no_mangle_with_rust_abi.rs | 2 +- tests/ui/no_mangle_with_rust_abi_2021.rs | 2 +- tests/ui/non_canonical_clone_impl.rs | 8 +- tests/ui/non_canonical_partial_ord_impl.fixed | 4 +- tests/ui/non_canonical_partial_ord_impl.rs | 4 +- ...n_canonical_partial_ord_impl_fully_qual.rs | 4 +- tests/ui/non_expressive_names.rs | 24 +- tests/ui/non_expressive_names.stderr | 36 +-- tests/ui/non_zero_suggestions.fixed | 6 - tests/ui/non_zero_suggestions.rs | 6 - tests/ui/non_zero_suggestions.stderr | 10 +- tests/ui/non_zero_suggestions_unfixable.rs | 2 - .../ui/non_zero_suggestions_unfixable.stderr | 4 +- tests/ui/nonminimal_bool.rs | 59 +++-- tests/ui/nonminimal_bool.stderr | 122 ++++----- tests/ui/nonminimal_bool_methods.fixed | 108 ++++---- tests/ui/nonminimal_bool_methods.rs | 108 ++++---- tests/ui/nonminimal_bool_methods.stderr | 168 ++++++------- tests/ui/nonminimal_bool_methods_unfixable.rs | 6 +- .../nonminimal_bool_methods_unfixable.stderr | 12 +- tests/ui/obfuscated_if_else.fixed | 9 - tests/ui/obfuscated_if_else.rs | 9 - tests/ui/obfuscated_if_else.stderr | 24 +- tests/ui/octal_escapes.rs | 30 ++- tests/ui/octal_escapes.stderr | 102 ++++---- tests/ui/ok_expect.rs | 1 - tests/ui/only_used_in_recursion.rs | 36 ++- tests/ui/only_used_in_recursion.stderr | 56 ++--- tests/ui/only_used_in_recursion2.rs | 10 +- tests/ui/op_ref.fixed | 3 - tests/ui/op_ref.rs | 3 - tests/ui/op_ref.stderr | 6 +- tests/ui/open_options.rs | 5 - tests/ui/open_options.stderr | 14 +- tests/ui/open_options_fixable.fixed | 1 - tests/ui/open_options_fixable.rs | 1 - tests/ui/option_filter_map.fixed | 1 - tests/ui/option_filter_map.rs | 3 - tests/ui/option_filter_map.stderr | 12 +- tests/ui/option_if_let_else.fixed | 12 +- tests/ui/option_if_let_else.rs | 36 +-- tests/ui/option_map_or_none.fixed | 2 +- tests/ui/option_map_or_none.rs | 2 +- tests/ui/or_fun_call.fixed | 3 +- tests/ui/or_fun_call.rs | 3 +- tests/ui/or_fun_call.stderr | 12 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 2 - .../out_of_bounds_indexing/issue-3102.stderr | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 2 - tests/ui/out_of_bounds_indexing/simple.stderr | 10 +- tests/ui/panic_in_result_fn.rs | 4 +- tests/ui/panic_in_result_fn.stderr | 18 +- tests/ui/panic_in_result_fn_assertions.rs | 3 - tests/ui/panic_in_result_fn_assertions.stderr | 22 +- tests/ui/panicking_macros.rs | 5 - tests/ui/panicking_macros.stderr | 30 +-- tests/ui/panicking_overflow_checks.rs | 24 +- tests/ui/panicking_overflow_checks.stderr | 36 +-- tests/ui/partial_pub_fields.rs | 4 - tests/ui/partial_pub_fields.stderr | 6 +- tests/ui/partialeq_ne_impl.rs | 3 +- tests/ui/partialeq_ne_impl.stderr | 4 +- tests/ui/partialeq_to_none.fixed | 2 +- tests/ui/partialeq_to_none.rs | 2 +- tests/ui/path_ends_with_ext.fixed | 2 - tests/ui/path_ends_with_ext.rs | 2 - tests/ui/path_ends_with_ext.stderr | 2 +- tests/ui/pathbuf_init_then_push.fixed | 8 +- tests/ui/pathbuf_init_then_push.rs | 16 +- tests/ui/pathbuf_init_then_push.stderr | 16 +- tests/ui/pattern_type_mismatch/mutability.rs | 2 - .../pattern_type_mismatch/mutability.stderr | 2 +- .../pattern_alternatives.rs | 1 - .../pattern_type_mismatch/pattern_structs.rs | 2 - .../pattern_structs.stderr | 10 +- .../pattern_type_mismatch/pattern_tuples.rs | 3 - .../pattern_tuples.stderr | 14 +- tests/ui/pattern_type_mismatch/syntax.rs | 9 +- tests/ui/pattern_type_mismatch/syntax.stderr | 16 +- tests/ui/patterns.fixed | 2 +- tests/ui/patterns.rs | 2 +- tests/ui/permissions_set_readonly_false.rs | 1 - tests/ui/pointers_in_nomem_asm_block.rs | 2 - tests/ui/pointers_in_nomem_asm_block.stderr | 2 +- tests/ui/print.rs | 9 - tests/ui/print.stderr | 14 +- tests/ui/print_in_format_impl.rs | 1 - tests/ui/print_in_format_impl.stderr | 12 +- tests/ui/print_literal.fixed | 4 - tests/ui/print_literal.rs | 4 - tests/ui/print_literal.stderr | 34 +-- tests/ui/print_stderr.rs | 1 - tests/ui/print_stderr.stderr | 2 +- tests/ui/print_with_newline.fixed | 8 +- tests/ui/print_with_newline.rs | 8 +- tests/ui/print_with_newline.stderr | 20 +- tests/ui/ptr_arg.rs | 51 ++-- tests/ui/ptr_arg.stderr | 52 ++-- tests/ui/pub_use.rs | 1 - tests/ui/question_mark.rs | 32 +-- tests/ui/rc_clone_in_vec_init/arc.rs | 4 - tests/ui/rc_clone_in_vec_init/arc.stderr | 6 +- tests/ui/rc_clone_in_vec_init/rc.rs | 4 - tests/ui/rc_clone_in_vec_init/rc.stderr | 6 +- tests/ui/rc_clone_in_vec_init/weak.rs | 9 - tests/ui/rc_clone_in_vec_init/weak.stderr | 14 +- tests/ui/rc_mutex.rs | 1 - tests/ui/read_line_without_trim.fixed | 4 +- tests/ui/read_line_without_trim.rs | 4 +- tests/ui/readonly_write_lock.fixed | 1 - tests/ui/readonly_write_lock.rs | 1 - 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 | 49 +--- tests/ui/redundant_allocation.stderr | 38 +-- tests/ui/redundant_clone.fixed | 2 +- tests/ui/redundant_clone.rs | 2 +- tests/ui/redundant_closure_call_early.rs | 3 - tests/ui/redundant_closure_call_early.stderr | 2 +- tests/ui/redundant_closure_call_fixable.fixed | 4 +- tests/ui/redundant_closure_call_fixable.rs | 4 +- tests/ui/redundant_closure_call_late.rs | 3 - tests/ui/redundant_closure_call_late.stderr | 4 +- tests/ui/redundant_else.fixed | 14 +- tests/ui/redundant_else.rs | 14 +- tests/ui/redundant_else.stderr | 14 +- tests/ui/redundant_field_names.fixed | 1 - tests/ui/redundant_field_names.rs | 1 - tests/ui/redundant_field_names.stderr | 14 +- tests/ui/redundant_guards.fixed | 2 +- tests/ui/redundant_guards.rs | 2 +- ...edundant_pattern_matching_drop_order.fixed | 6 +- .../redundant_pattern_matching_drop_order.rs | 6 +- ...dundant_pattern_matching_if_let_true.fixed | 4 +- .../redundant_pattern_matching_if_let_true.rs | 4 +- .../redundant_pattern_matching_ipaddr.fixed | 6 +- tests/ui/redundant_pattern_matching_ipaddr.rs | 18 +- .../redundant_pattern_matching_option.fixed | 8 +- tests/ui/redundant_pattern_matching_option.rs | 26 +- .../ui/redundant_pattern_matching_poll.fixed | 6 +- tests/ui/redundant_pattern_matching_poll.rs | 16 +- .../redundant_pattern_matching_result.fixed | 4 +- tests/ui/redundant_pattern_matching_result.rs | 24 +- tests/ui/redundant_pub_crate.fixed | 6 +- tests/ui/redundant_pub_crate.rs | 6 +- .../ui/redundant_static_lifetimes_multiple.rs | 11 - ...redundant_static_lifetimes_multiple.stderr | 16 +- tests/ui/redundant_type_annotations.rs | 16 -- tests/ui/redundant_type_annotations.stderr | 32 +-- tests/ui/ref_binding_to_reference.rs | 13 +- tests/ui/ref_binding_to_reference.stderr | 12 +- tests/ui/ref_option/ref_option.all.fixed | 10 +- tests/ui/ref_option/ref_option.private.fixed | 10 +- tests/ui/ref_option/ref_option.rs | 10 +- tests/ui/ref_option_ref.rs | 11 +- tests/ui/ref_option_ref.stderr | 20 +- tests/ui/ref_patterns.rs | 3 - tests/ui/ref_patterns.stderr | 4 +- tests/ui/repeat_vec_with_capacity.fixed | 3 - tests/ui/repeat_vec_with_capacity.rs | 3 - tests/ui/repeat_vec_with_capacity.stderr | 4 +- tests/ui/repl_uninit.rs | 1 - tests/ui/repl_uninit.stderr | 6 +- tests/ui/repr_packed_without_abi.rs | 4 +- tests/ui/rest_pat_in_fully_bound_structs.rs | 3 - .../ui/rest_pat_in_fully_bound_structs.stderr | 4 +- tests/ui/result_filter_map.rs | 4 - tests/ui/result_filter_map.stderr | 14 +- tests/ui/result_large_err.rs | 24 +- tests/ui/result_map_or_into_option.fixed | 1 - tests/ui/result_map_or_into_option.rs | 1 - tests/ui/result_unit_error.rs | 9 +- tests/ui/result_unit_error.stderr | 6 +- tests/ui/result_unit_error_no_std.rs | 2 +- tests/ui/return_and_then.fixed | 8 +- tests/ui/return_and_then.rs | 4 +- tests/ui/return_and_then.stderr | 6 +- tests/ui/return_self_not_must_use.rs | 4 +- .../reversed_empty_ranges_loops_fixable.fixed | 12 +- .../ui/reversed_empty_ranges_loops_fixable.rs | 12 +- .../reversed_empty_ranges_loops_unfixable.rs | 5 +- ...versed_empty_ranges_loops_unfixable.stderr | 2 +- tests/ui/reversed_empty_ranges_unfixable.rs | 3 - .../ui/reversed_empty_ranges_unfixable.stderr | 4 +- tests/ui/same_functions_in_if_condition.rs | 18 +- .../ui/same_functions_in_if_condition.stderr | 20 +- tests/ui/same_item_push.rs | 6 - tests/ui/same_item_push.stderr | 10 +- tests/ui/same_name_method.rs | 6 - tests/ui/same_name_method.stderr | 22 +- tests/ui/search_is_some_fixable_none.fixed | 4 +- tests/ui/search_is_some_fixable_none.rs | 6 +- tests/ui/self_assignment.rs | 3 - tests/ui/self_assignment.stderr | 20 +- tests/ui/self_named_constructors.rs | 3 +- tests/ui/self_named_constructors.stderr | 4 +- tests/ui/set_contains_or_insert.rs | 28 +-- tests/ui/shadow.rs | 6 +- tests/ui/short_circuit_statement.fixed | 2 - tests/ui/short_circuit_statement.rs | 2 - tests/ui/short_circuit_statement.stderr | 4 +- tests/ui/should_impl_trait/method_list_1.rs | 30 +-- tests/ui/should_impl_trait/method_list_2.rs | 30 +-- tests/ui/significant_drop_in_scrutinee.rs | 62 ++--- tests/ui/similar_names.rs | 5 - tests/ui/similar_names.stderr | 16 +- tests/ui/single_call_fn.rs | 2 +- tests/ui/single_char_lifetime_names.rs | 9 +- tests/ui/single_char_lifetime_names.stderr | 6 +- ...gle_component_path_imports_nested_first.rs | 3 - ...component_path_imports_nested_first.stderr | 4 +- tests/ui/single_element_loop.fixed | 16 +- tests/ui/single_element_loop.rs | 16 +- tests/ui/single_option_map.rs | 6 +- .../size_of_in_element_count/expressions.rs | 4 - .../expressions.stderr | 6 +- .../ui/size_of_in_element_count/functions.rs | 7 - .../size_of_in_element_count/functions.stderr | 34 +-- tests/ui/size_of_ref.rs | 2 - tests/ui/size_of_ref.stderr | 2 +- tests/ui/slow_vector_initialization.rs | 1 - tests/ui/slow_vector_initialization.stderr | 24 +- tests/ui/starts_ends_with.fixed | 12 +- tests/ui/starts_ends_with.rs | 12 +- tests/ui/str_to_string.fixed | 1 - tests/ui/str_to_string.rs | 1 - tests/ui/string_slice.rs | 2 - tests/ui/string_slice.stderr | 6 +- tests/ui/string_to_string.rs | 1 - tests/ui/struct_excessive_bools.rs | 6 +- tests/ui/struct_excessive_bools.stderr | 10 +- tests/ui/suspicious_arithmetic_impl.rs | 11 - tests/ui/suspicious_arithmetic_impl.stderr | 16 +- tests/ui/suspicious_command_arg_space.fixed | 2 - tests/ui/suspicious_command_arg_space.rs | 2 - tests/ui/suspicious_command_arg_space.stderr | 2 +- tests/ui/suspicious_doc_comments.fixed | 2 +- tests/ui/suspicious_doc_comments.rs | 2 +- tests/ui/suspicious_doc_comments.stderr | 2 - tests/ui/suspicious_doc_comments_unfixable.rs | 1 - .../suspicious_doc_comments_unfixable.stderr | 7 +- tests/ui/suspicious_map.rs | 2 - tests/ui/suspicious_map.stderr | 2 +- tests/ui/suspicious_operation_groupings.fixed | 2 +- tests/ui/suspicious_operation_groupings.rs | 2 +- tests/ui/suspicious_splitn.rs | 11 - tests/ui/suspicious_splitn.stderr | 16 +- tests/ui/suspicious_to_owned.rs | 3 - tests/ui/suspicious_to_owned.stderr | 10 +- tests/ui/suspicious_xor_used_as_pow.rs | 1 - tests/ui/suspicious_xor_used_as_pow.stderr | 10 +- tests/ui/swap_ptr_to_ref_unfixable.rs | 2 - tests/ui/swap_ptr_to_ref_unfixable.stderr | 4 +- .../non_expressive_names_error_recovery.fixed | 1 + .../non_expressive_names_error_recovery.rs | 1 + tests/ui/temporary_assignment.rs | 5 +- tests/ui/temporary_assignment.stderr | 10 +- tests/ui/test_attr_in_doctest.rs | 9 +- tests/ui/test_attr_in_doctest.stderr | 4 +- tests/ui/to_string_trait_impl.rs | 2 +- tests/ui/toplevel_ref_arg_non_rustfix.rs | 2 +- tests/ui/trailing_empty_array.rs | 29 +-- tests/ui/trailing_empty_array.stderr | 30 +-- tests/ui/trailing_zeros.fixed | 1 - tests/ui/trailing_zeros.rs | 1 - tests/ui/trailing_zeros.stderr | 2 +- tests/ui/trait_duplication_in_bounds.fixed | 17 +- tests/ui/trait_duplication_in_bounds.rs | 17 +- tests/ui/trait_duplication_in_bounds.stderr | 4 +- .../trait_duplication_in_bounds_unfixable.rs | 16 +- ...ait_duplication_in_bounds_unfixable.stderr | 12 +- tests/ui/transmute.rs | 32 --- tests/ui/transmute.stderr | 124 +++++----- tests/ui/transmute_64bit.rs | 3 - tests/ui/transmute_64bit.stderr | 2 +- tests/ui/transmute_collection.rs | 8 - 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 | 26 +- tests/ui/transmute_int_to_char.fixed | 2 - tests/ui/transmute_int_to_char.rs | 2 - tests/ui/transmute_int_to_char.stderr | 2 +- tests/ui/transmute_int_to_char_no_std.fixed | 2 - tests/ui/transmute_int_to_char_no_std.rs | 2 - tests/ui/transmute_int_to_char_no_std.stderr | 2 +- tests/ui/transmute_int_to_non_zero.fixed | 3 - tests/ui/transmute_int_to_non_zero.rs | 3 - tests/ui/transmute_int_to_non_zero.stderr | 18 +- tests/ui/transmute_null_to_fn.rs | 2 - tests/ui/transmute_null_to_fn.stderr | 8 +- tests/ui/transmute_ptr_to_ptr.fixed | 2 - tests/ui/transmute_ptr_to_ptr.rs | 2 - tests/ui/transmute_ptr_to_ptr.stderr | 14 +- tests/ui/transmute_ref_to_ref.rs | 1 - tests/ui/transmute_ref_to_ref_no_std.rs | 1 - tests/ui/transmute_undefined_repr.rs | 17 -- tests/ui/transmute_undefined_repr.stderr | 22 +- tests/ui/transmuting_null.rs | 2 - tests/ui/transmuting_null.stderr | 4 +- tests/ui/type_complexity.rs | 12 +- tests/ui/type_complexity.stderr | 28 +-- tests/ui/type_id_on_box.fixed | 4 - tests/ui/type_id_on_box.rs | 4 - tests/ui/type_id_on_box.stderr | 6 +- tests/ui/type_id_on_box_unfixable.rs | 2 - tests/ui/type_id_on_box_unfixable.stderr | 2 +- tests/ui/unbuffered_bytes.rs | 4 + tests/ui/unbuffered_bytes.stderr | 6 +- tests/ui/unconditional_recursion.rs | 40 +-- tests/ui/uninhabited_references.rs | 4 +- tests/ui/uninit.rs | 4 - tests/ui/uninit.stderr | 4 +- tests/ui/uninlined_format_args.fixed | 6 +- tests/ui/uninlined_format_args.rs | 6 +- tests/ui/unit_arg.rs | 10 +- tests/ui/unit_cmp.rs | 17 +- tests/ui/unit_cmp.stderr | 27 +- 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 | 7 +- tests/ui/unnecessary_box_returns.rs | 7 +- tests/ui/unnecessary_box_returns.stderr | 6 +- tests/ui/unnecessary_cast_unfixable.rs | 3 - tests/ui/unnecessary_cast_unfixable.stderr | 2 +- tests/ui/unnecessary_clippy_cfg.rs | 7 - tests/ui/unnecessary_clippy_cfg.stderr | 26 +- tests/ui/unnecessary_clone.rs | 6 - tests/ui/unnecessary_clone.stderr | 16 +- .../ui/unnecessary_fallible_conversions.fixed | 10 - tests/ui/unnecessary_fallible_conversions.rs | 10 - .../unnecessary_fallible_conversions.stderr | 18 +- tests/ui/unnecessary_filter_map.rs | 7 +- tests/ui/unnecessary_filter_map.stderr | 15 +- tests/ui/unnecessary_find_map.rs | 7 +- tests/ui/unnecessary_find_map.stderr | 9 +- tests/ui/unnecessary_fold.fixed | 2 +- tests/ui/unnecessary_fold.rs | 2 +- tests/ui/unnecessary_get_then_check.fixed | 40 +-- tests/ui/unnecessary_get_then_check.rs | 40 +-- tests/ui/unnecessary_get_then_check.stderr | 80 +++--- tests/ui/unnecessary_iter_cloned.fixed | 14 +- tests/ui/unnecessary_iter_cloned.rs | 14 +- tests/ui/unnecessary_iter_cloned.stderr | 4 +- tests/ui/unnecessary_lazy_eval_unfixable.rs | 2 - .../ui/unnecessary_lazy_eval_unfixable.stderr | 6 +- tests/ui/unnecessary_literal_bound.fixed | 6 +- tests/ui/unnecessary_literal_bound.rs | 6 +- .../unnecessary_literal_unwrap_unfixable.rs | 16 -- ...nnecessary_literal_unwrap_unfixable.stderr | 196 +++++++-------- tests/ui/unnecessary_map_or.fixed | 2 +- tests/ui/unnecessary_map_or.rs | 4 +- tests/ui/unnecessary_operation.fixed | 1 - tests/ui/unnecessary_operation.rs | 5 +- tests/ui/unnecessary_result_map_or_else.fixed | 12 +- tests/ui/unnecessary_result_map_or_else.rs | 15 +- .../ui/unnecessary_result_map_or_else.stderr | 20 +- tests/ui/unnecessary_safety_comment.rs | 4 - tests/ui/unnecessary_safety_comment.stderr | 16 +- .../unnecessary_semicolon.edition2021.fixed | 2 - .../unnecessary_semicolon.edition2021.stderr | 4 +- .../unnecessary_semicolon.edition2024.fixed | 2 - .../unnecessary_semicolon.edition2024.stderr | 6 +- tests/ui/unnecessary_semicolon.rs | 2 - tests/ui/unnecessary_struct_initialization.rs | 4 +- tests/ui/unnecessary_to_owned.fixed | 22 +- tests/ui/unnecessary_to_owned.rs | 22 +- tests/ui/unnecessary_to_owned.stderr | 30 +-- tests/ui/unnecessary_to_owned_on_split.fixed | 2 - tests/ui/unnecessary_to_owned_on_split.rs | 2 - tests/ui/unnecessary_to_owned_on_split.stderr | 8 +- tests/ui/unnecessary_unsafety_doc.rs | 12 +- tests/ui/unnecessary_wraps.rs | 15 +- tests/ui/unnecessary_wraps.stderr | 15 +- tests/ui/unneeded_field_pattern.rs | 1 - tests/ui/unneeded_field_pattern.stderr | 2 +- tests/ui/unneeded_struct_pattern.fixed | 20 +- tests/ui/unneeded_struct_pattern.rs | 26 +- tests/ui/unneeded_struct_pattern.stderr | 4 +- tests/ui/unsafe_removed_from_name.rs | 6 - tests/ui/unsafe_removed_from_name.stderr | 8 +- tests/ui/unused_async.rs | 7 +- tests/ui/unused_async.stderr | 4 +- tests/ui/unused_enumerate_index.fixed | 4 +- tests/ui/unused_enumerate_index.rs | 4 +- tests/ui/unused_format_specs.1.fixed | 7 - tests/ui/unused_format_specs.2.fixed | 7 - tests/ui/unused_format_specs.rs | 7 - tests/ui/unused_format_specs.stderr | 14 +- tests/ui/unused_io_amount.rs | 16 +- tests/ui/unused_peekable.rs | 5 - tests/ui/unused_peekable.stderr | 14 +- tests/ui/unused_self.rs | 4 +- tests/ui/unwrap.rs | 2 - tests/ui/unwrap.stderr | 4 +- tests/ui/unwrap_expect_used.rs | 1 - tests/ui/unwrap_expect_used.stderr | 8 +- tests/ui/unwrap_in_result.rs | 6 +- tests/ui/unwrap_or.fixed | 3 - tests/ui/unwrap_or.rs | 3 - tests/ui/unwrap_or.stderr | 2 +- tests/ui/upper_case_acronyms.fixed | 15 +- tests/ui/upper_case_acronyms.rs | 15 +- tests/ui/upper_case_acronyms.stderr | 22 +- tests/ui/use_self.fixed | 22 +- tests/ui/use_self.rs | 22 +- tests/ui/use_self_trait.fixed | 20 +- tests/ui/use_self_trait.rs | 20 +- tests/ui/useless_asref.fixed | 3 - tests/ui/useless_asref.rs | 3 - tests/ui/useless_asref.stderr | 8 +- tests/ui/useless_conversion.fixed | 9 - tests/ui/useless_conversion.rs | 9 - tests/ui/useless_conversion.stderr | 28 +-- tests/ui/useless_conversion_try.rs | 4 +- tests/ui/useless_conversion_try.stderr | 14 +- tests/ui/useless_nonzero_new_unchecked.fixed | 5 - tests/ui/useless_nonzero_new_unchecked.rs | 5 - tests/ui/useless_nonzero_new_unchecked.stderr | 8 +- tests/ui/useless_vec.rs | 3 +- tests/ui/useless_vec.stderr | 1 - tests/ui/vec.fixed | 10 +- tests/ui/vec.rs | 10 +- tests/ui/vec.stderr | 6 +- tests/ui/vec_box_sized.rs | 8 +- tests/ui/vec_init_then_push.rs | 1 - tests/ui/vec_init_then_push.stderr | 14 +- tests/ui/vec_resize_to_zero.fixed | 1 - tests/ui/vec_resize_to_zero.rs | 1 - tests/ui/while_float.rs | 4 +- tests/ui/while_let_loop.rs | 11 +- tests/ui/while_let_loop.stderr | 11 +- tests/ui/while_let_on_iterator.fixed | 50 ++-- tests/ui/while_let_on_iterator.rs | 50 ++-- tests/ui/wild_in_or_pats.rs | 12 +- tests/ui/write_literal.fixed | 5 - tests/ui/write_literal.rs | 5 - tests/ui/write_literal.stderr | 26 +- tests/ui/write_literal_2.rs | 8 +- tests/ui/write_literal_2.stderr | 20 +- tests/ui/write_with_newline.fixed | 8 +- tests/ui/write_with_newline.rs | 8 +- tests/ui/write_with_newline.stderr | 20 +- tests/ui/wrong_self_convention.rs | 7 +- tests/ui/wrong_self_convention.stderr | 46 ++-- tests/ui/wrong_self_convention2.rs | 3 +- tests/ui/wrong_self_conventions_mut.rs | 4 +- tests/ui/zero_offset.rs | 3 - tests/ui/zero_offset.stderr | 14 +- tests/ui/zero_sized_btreemap_values.rs | 16 +- tests/ui/zero_sized_btreemap_values.stderr | 24 +- tests/ui/zero_sized_hashmap_values.rs | 16 +- tests/ui/zero_sized_hashmap_values.stderr | 24 +- 1025 files changed, 6097 insertions(+), 7930 deletions(-) diff --git a/tests/ui/as_pointer_underscore.fixed b/tests/ui/as_pointer_underscore.fixed index 374c8a7f611a..93daae6bc668 100644 --- a/tests/ui/as_pointer_underscore.fixed +++ b/tests/ui/as_pointer_underscore.fixed @@ -7,11 +7,9 @@ struct S; fn f(s: &S) -> usize { &s as *const &S as usize //~^ as_pointer_underscore - } fn g(s: &mut S) -> usize { s as *mut S as usize //~^ as_pointer_underscore - } diff --git a/tests/ui/as_pointer_underscore.rs b/tests/ui/as_pointer_underscore.rs index b194b3f473e2..56f1a8935255 100644 --- a/tests/ui/as_pointer_underscore.rs +++ b/tests/ui/as_pointer_underscore.rs @@ -7,11 +7,9 @@ struct S; fn f(s: &S) -> usize { &s as *const _ as usize //~^ as_pointer_underscore - } fn g(s: &mut S) -> usize { s as *mut _ as usize //~^ as_pointer_underscore - } diff --git a/tests/ui/as_pointer_underscore.stderr b/tests/ui/as_pointer_underscore.stderr index fd9f061322b5..270056f36454 100644 --- a/tests/ui/as_pointer_underscore.stderr +++ b/tests/ui/as_pointer_underscore.stderr @@ -8,7 +8,7 @@ LL | &s as *const _ as usize = help: to override `-D warnings` add `#[allow(clippy::as_pointer_underscore)]` error: using inferred pointer cast - --> tests/ui/as_pointer_underscore.rs:14:10 + --> tests/ui/as_pointer_underscore.rs:13:10 | LL | s as *mut _ as usize | ^^^^^^ help: use explicit type: `*mut S` diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 751e4a70b0fa..baf7279adc4a 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -22,7 +22,6 @@ fn main() { let _ = string.as_ptr() as *mut u8; //~^ as_ptr_cast_mut - let _: *mut i8 = string.as_ptr() as *mut _; //~^ as_ptr_cast_mut diff --git a/tests/ui/as_ptr_cast_mut.stderr b/tests/ui/as_ptr_cast_mut.stderr index 67dd7ddb8291..b3fc223ccdba 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -8,7 +8,7 @@ LL | let _ = string.as_ptr() as *mut u8; = help: to override `-D warnings` add `#[allow(clippy::as_ptr_cast_mut)]` error: casting the result of `as_ptr` to *mut i8 - --> tests/ui/as_ptr_cast_mut.rs:26:22 + --> tests/ui/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_x86.rs b/tests/ui/asm_syntax_x86.rs index 0d30b95dcf5e..4e91f27cd318 100644 --- a/tests/ui/asm_syntax_x86.rs +++ b/tests/ui/asm_syntax_x86.rs @@ -40,14 +40,12 @@ mod warn_att { asm!("", options(nostack, att_syntax)); //~^ inline_asm_x86_att_syntax - } global_asm!(""); global_asm!("", options()); global_asm!("", options(att_syntax)); //~^ inline_asm_x86_att_syntax - } fn main() { diff --git a/tests/ui/asm_syntax_x86.stderr b/tests/ui/asm_syntax_x86.stderr index 8e1992b66bca..2dcd955f0347 100644 --- a/tests/ui/asm_syntax_x86.stderr +++ b/tests/ui/asm_syntax_x86.stderr @@ -59,7 +59,7 @@ LL | asm!("", options(nostack, att_syntax)); = help: use Intel x86 assembly syntax error: AT&T x86 assembly syntax used - --> tests/ui/asm_syntax_x86.rs:48:5 + --> tests/ui/asm_syntax_x86.rs:47:5 | LL | global_asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 96b9c16d4303..c2516c541475 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -19,17 +19,14 @@ fn main() { assert!(false, "false message"); //~^ assertions_on_constants - let msg = "panic message"; assert!(false, "{}", msg.to_uppercase()); //~^ assertions_on_constants - const B: bool = true; assert!(B); //~^ assertions_on_constants - const C: bool = false; assert!(C); //~^ assertions_on_constants @@ -37,7 +34,6 @@ fn main() { assert!(C, "C message"); //~^ assertions_on_constants - debug_assert!(true); //~^ assertions_on_constants @@ -58,11 +54,9 @@ fn main() { const _: () = assert!(true); //~^ assertions_on_constants - assert!(8 == (7 + 1)); //~^ assertions_on_constants - // Don't lint if the value is dependent on a defined constant: const N: usize = 1024; const _: () = assert!(N.is_power_of_two()); diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index b0e6496982f9..8b7440ec4832 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -33,7 +33,7 @@ LL | assert!(false, "false message"); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(false, ..)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:24:5 + --> tests/ui/assertions_on_constants.rs:23:5 | LL | assert!(false, "{}", msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | assert!(false, "{}", msg.to_uppercase()); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:29:5 + --> tests/ui/assertions_on_constants.rs:27:5 | LL | assert!(B); | ^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | assert!(B); = help: remove it error: `assert!(false)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:34:5 + --> tests/ui/assertions_on_constants.rs:31:5 | LL | assert!(C); | ^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | assert!(C); = help: use `panic!()` or `unreachable!()` error: `assert!(false, ..)` should probably be replaced - --> tests/ui/assertions_on_constants.rs:37:5 + --> tests/ui/assertions_on_constants.rs:34:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | assert!(C, "C message"); = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:41:5 + --> tests/ui/assertions_on_constants.rs:37:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | debug_assert!(true); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:58:19 + --> tests/ui/assertions_on_constants.rs:54:19 | LL | const _: () = assert!(true); | ^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | const _: () = assert!(true); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:62:5 + --> tests/ui/assertions_on_constants.rs:57:5 | LL | assert!(8 == (7 + 1)); | ^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | assert!(8 == (7 + 1)); = help: remove it error: `assert!(true)` will be optimized out by the compiler - --> tests/ui/assertions_on_constants.rs:72:5 + --> tests/ui/assertions_on_constants.rs:66:5 | LL | assert!(true); | ^^^^^^^^^^^^^ diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 7cac9f51ea4e..51867fa6962c 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -8,7 +8,6 @@ fn main() { a += a + 1; //~^ misrefactored_assign_op - a += 1 + a; //~^ misrefactored_assign_op @@ -72,8 +71,6 @@ fn cow_add_assign() { buf = buf + cows.clone(); //~^ assign_op_pattern - - // this should not as cow Add is not commutative buf = cows + buf; println!("{}", buf); diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index 56b5219dd646..19deebe17850 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -16,7 +16,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:12:5 + --> tests/ui/assign_ops2.rs:11:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:15:5 + --> tests/ui/assign_ops2.rs:14:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:18:5 + --> tests/ui/assign_ops2.rs:17:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:21:5 + --> tests/ui/assign_ops2.rs:20:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:24:5 + --> tests/ui/assign_ops2.rs:23:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:27:5 + --> tests/ui/assign_ops2.rs:26:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:30:5 + --> tests/ui/assign_ops2.rs:29:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> tests/ui/assign_ops2.rs:33:5 + --> tests/ui/assign_ops2.rs:32:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> tests/ui/assign_ops2.rs:72:5 + --> tests/ui/assign_ops2.rs:71: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 32e4053e74b0..583a0ada437d 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -5,7 +5,6 @@ #[inline(always)] //~^ inline_always - fn test_attr_lint() { assert!(true) } @@ -28,7 +27,6 @@ fn empty_and_false_positive_stmt() { #[deprecated(since = "forever")] //~^ deprecated_semver - pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index f4803380cc41..a7fdceaba6f3 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -1,5 +1,5 @@ error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:28:14 + --> tests/ui/attrs.rs:27:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | #[deprecated(since = "forever")] = help: to override `-D warnings` add `#[allow(clippy::deprecated_semver)]` error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:34:14 + --> tests/ui/attrs.rs:32:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ diff --git a/tests/ui/await_holding_refcell_ref.rs b/tests/ui/await_holding_refcell_ref.rs index 258e16c07e04..e1db2e387497 100644 --- a/tests/ui/await_holding_refcell_ref.rs +++ b/tests/ui/await_holding_refcell_ref.rs @@ -36,7 +36,6 @@ async fn also_bad(x: &RefCell) -> u32 { let b = x.borrow_mut(); //~^ await_holding_refcell_ref - let second = baz().await; let third = baz().await; @@ -50,7 +49,6 @@ async fn less_bad(x: &RefCell) -> u32 { let b = x.borrow_mut(); //~^ await_holding_refcell_ref - let second = baz().await; drop(b); diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index ce7c71ae8fec..ed8aa747bd07 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -34,7 +34,7 @@ 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 - --> tests/ui/await_holding_refcell_ref.rs:40:24 + --> tests/ui/await_holding_refcell_ref.rs:39:24 | LL | let second = baz().await; | ^^^^^ @@ -43,40 +43,40 @@ LL | let third = baz().await; | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:50:9 + --> tests/ui/await_holding_refcell_ref.rs:49: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 - --> tests/ui/await_holding_refcell_ref.rs:54:24 + --> tests/ui/await_holding_refcell_ref.rs:52:24 | LL | let second = baz().await; | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:67:13 + --> tests/ui/await_holding_refcell_ref.rs:65: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 - --> tests/ui/await_holding_refcell_ref.rs:70:15 + --> tests/ui/await_holding_refcell_ref.rs:68:15 | LL | baz().await | ^^^^^ error: this `RefCell` reference is held across an await point - --> tests/ui/await_holding_refcell_ref.rs:81:13 + --> tests/ui/await_holding_refcell_ref.rs:79: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 - --> tests/ui/await_holding_refcell_ref.rs:84:15 + --> tests/ui/await_holding_refcell_ref.rs:82:15 | LL | baz().await | ^^^^^ diff --git a/tests/ui/bind_instead_of_map_multipart.fixed b/tests/ui/bind_instead_of_map_multipart.fixed index a1da2cfc9fc6..b61ce97fe8e6 100644 --- a/tests/ui/bind_instead_of_map_multipart.fixed +++ b/tests/ui/bind_instead_of_map_multipart.fixed @@ -20,7 +20,7 @@ pub fn main() { fn hard_example() { Some("42").map(|s| { - //~^ bind_instead_of_map + //~^ bind_instead_of_map if { if s == "43" { return 43; diff --git a/tests/ui/bind_instead_of_map_multipart.rs b/tests/ui/bind_instead_of_map_multipart.rs index 5710254ddf6e..37f406def197 100644 --- a/tests/ui/bind_instead_of_map_multipart.rs +++ b/tests/ui/bind_instead_of_map_multipart.rs @@ -20,7 +20,7 @@ pub fn main() { fn hard_example() { Some("42").and_then(|s| { - //~^ bind_instead_of_map + //~^ bind_instead_of_map if { if s == "43" { return Some(43); diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index b38523a03960..87dcdb3084d0 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -15,9 +15,6 @@ fn main() { //~^ bad_bit_mask //~| erasing_op - - - x & 1 == 1; //ok, distinguishes bit 0 x & 1 == 0; //ok, compared with zero x & 2 == 1; @@ -29,7 +26,6 @@ fn main() { x | 3 == 2; //~^ bad_bit_mask - x & 1 > 1; //~^ bad_bit_mask @@ -51,12 +47,10 @@ fn main() { x | EVEN_MORE_REDIRECTION < 7; //~^ bad_bit_mask - 0 & x == 0; //~^ bad_bit_mask //~| erasing_op - 1 | x > 1; // and should now also match uncommon usage @@ -69,7 +63,6 @@ fn main() { 1 == x & 2; //~^ bad_bit_mask - x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); } @@ -82,7 +75,6 @@ fn ineffective() { x | 1 > 3; //~^ ineffective_bit_mask - x | 1 < 4; //~^ ineffective_bit_mask @@ -92,7 +84,6 @@ fn ineffective() { x | 1 >= 8; //~^ ineffective_bit_mask - x | 1 > 2; // not an error (yet), better written as x >= 2 x | 1 >= 7; // not an error (yet), better written as x >= 6 x | 3 > 4; // not an error (yet), better written as x >= 4 diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index 300c93df9250..666ad671edee 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -16,73 +16,73 @@ LL | x & 0 == 0; = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:23:5 + --> tests/ui/bit_masks.rs:20:5 | LL | x & 2 == 1; | ^^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:29:5 + --> tests/ui/bit_masks.rs:26:5 | LL | x | 3 == 2; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> tests/ui/bit_masks.rs:33:5 + --> tests/ui/bit_masks.rs:29:5 | LL | x & 1 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:39:5 + --> tests/ui/bit_masks.rs:35:5 | LL | x | 2 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> tests/ui/bit_masks.rs:48:5 + --> tests/ui/bit_masks.rs:44:5 | LL | x & THREE_BITS == 8; | ^^^^^^^^^^^^^^^^^^^ error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> tests/ui/bit_masks.rs:51:5 + --> tests/ui/bit_masks.rs:47:5 | LL | x | EVEN_MORE_REDIRECTION < 7; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: &-masking with zero - --> tests/ui/bit_masks.rs:55:5 + --> tests/ui/bit_masks.rs:50:5 | LL | 0 & x == 0; | ^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/bit_masks.rs:55:5 + --> tests/ui/bit_masks.rs:50:5 | LL | 0 & x == 0; | ^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:63:5 + --> tests/ui/bit_masks.rs:57:5 | LL | 1 < 2 | x; | ^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:66:5 + --> tests/ui/bit_masks.rs:60:5 | LL | 2 == 3 | x; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:69:5 + --> tests/ui/bit_masks.rs:63:5 | LL | 1 == x & 2; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:82:5 + --> tests/ui/bit_masks.rs:75:5 | LL | x | 1 > 3; | ^^^^^^^^^ @@ -91,19 +91,19 @@ LL | x | 1 > 3; = help: to override `-D warnings` add `#[allow(clippy::ineffective_bit_mask)]` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> tests/ui/bit_masks.rs:86:5 + --> tests/ui/bit_masks.rs:78:5 | LL | x | 1 < 4; | ^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:89:5 + --> tests/ui/bit_masks.rs:81:5 | LL | x | 1 <= 3; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> tests/ui/bit_masks.rs:92:5 + --> tests/ui/bit_masks.rs:84:5 | LL | x | 1 >= 8; | ^^^^^^^^^^ diff --git a/tests/ui/blanket_clippy_restriction_lints.rs b/tests/ui/blanket_clippy_restriction_lints.rs index 16e2e62c523d..de699309b16d 100644 --- a/tests/ui/blanket_clippy_restriction_lints.rs +++ b/tests/ui/blanket_clippy_restriction_lints.rs @@ -6,12 +6,9 @@ //! Test that the whole restriction group is not enabled #![warn(clippy::restriction)] //~^ blanket_clippy_restriction_lints - #![deny(clippy::restriction)] //~^ blanket_clippy_restriction_lints - #![forbid(clippy::restriction)] //~^ blanket_clippy_restriction_lints - fn main() {} diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 5bfd7d208307..ff3a7cfc3931 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -14,7 +14,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 - --> tests/ui/blanket_clippy_restriction_lints.rs:10:9 + --> tests/ui/blanket_clippy_restriction_lints.rs:9:9 | LL | #![deny(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,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 - --> tests/ui/blanket_clippy_restriction_lints.rs:13:11 + --> tests/ui/blanket_clippy_restriction_lints.rs:11:11 | LL | #![forbid(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/bool_comparison.fixed b/tests/ui/bool_comparison.fixed index 724bf9253d33..166abbe549c3 100644 --- a/tests/ui/bool_comparison.fixed +++ b/tests/ui/bool_comparison.fixed @@ -5,86 +5,86 @@ fn main() { let x = true; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if !x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; let y = true; if !x & y { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x & !y { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index 6d11f9efe569..7265c2b4c5a6 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -5,86 +5,86 @@ fn main() { let x = true; if x == true { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x == false { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if true == x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if false == x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x != true { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x != false { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if true != x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if false != x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x < true { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if false < x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x > false { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if true > x { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; let y = true; if x < y { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" }; if x > y { - //~^ bool_comparison + //~^ bool_comparison "yes" } else { "no" diff --git a/tests/ui/bool_to_int_with_if.rs b/tests/ui/bool_to_int_with_if.rs index d12b0af5312e..72c7e2c71c56 100644 --- a/tests/ui/bool_to_int_with_if.rs +++ b/tests/ui/bool_to_int_with_if.rs @@ -12,37 +12,37 @@ fn main() { // Should lint // precedence if a { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 }; if a { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 0 } else { 1 }; if !a { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 }; if a || b { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 }; if cond(a, b) { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 }; if x + y < 4 { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 @@ -52,7 +52,7 @@ fn main() { if a { 123 } else if b { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 1 } else { 0 @@ -62,7 +62,7 @@ fn main() { if a { 123 } else if b { - //~^ bool_to_int_with_if + //~^ bool_to_int_with_if 0 } else { 1 diff --git a/tests/ui/borrow_box.fixed b/tests/ui/borrow_box.fixed index 4529138c0edc..e6e7f74af7cf 100644 --- a/tests/ui/borrow_box.fixed +++ b/tests/ui/borrow_box.fixed @@ -24,19 +24,16 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &bool; //~^ borrowed_box - } struct Test3<'a> { foo: &'a bool, //~^ borrowed_box - } trait Test4 { fn test4(a: &bool); //~^ borrowed_box - } use std::any::Any; @@ -105,7 +102,6 @@ pub fn test15(_display: &(dyn Display + Send)) {} pub fn test16<'a>(_display: &'a (dyn Display + 'a)) {} //~^ borrowed_box - pub fn test17(_display: &impl Display) {} //~^ borrowed_box @@ -115,14 +111,12 @@ pub fn test18(_display: &(impl Display + Send)) {} pub fn test19<'a>(_display: &'a (impl Display + 'a)) {} //~^ borrowed_box - // 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: &(dyn Display + Send)) {} //~^ borrowed_box - #[allow(clippy::borrowed_box)] trait Trait { fn f(b: &Box); diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 3f2a0168ef42..43cf809306b3 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -24,19 +24,16 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &Box; //~^ borrowed_box - } struct Test3<'a> { foo: &'a Box, //~^ borrowed_box - } trait Test4 { fn test4(a: &Box); //~^ borrowed_box - } use std::any::Any; @@ -105,7 +102,6 @@ pub fn test15(_display: &Box) {} pub fn test16<'a>(_display: &'a Box) {} //~^ borrowed_box - pub fn test17(_display: &Box) {} //~^ borrowed_box @@ -115,14 +111,12 @@ pub fn test18(_display: &Box) {} pub fn test19<'a>(_display: &'a Box) {} //~^ borrowed_box - // 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)>) {} //~^ borrowed_box - #[allow(clippy::borrowed_box)] trait Trait { fn f(b: &Box); diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index e23e49f1c88b..dbe3757dd435 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` - --> tests/ui/borrow_box.rs:31:10 + --> tests/ui/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` - --> tests/ui/borrow_box.rs:37:17 + --> tests/ui/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` - --> tests/ui/borrow_box.rs:99:25 + --> tests/ui/borrow_box.rs:96:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:102:25 + --> tests/ui/borrow_box.rs:99: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` - --> tests/ui/borrow_box.rs:105:29 + --> tests/ui/borrow_box.rs:102: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` - --> tests/ui/borrow_box.rs:109:25 + --> tests/ui/borrow_box.rs:105:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:112:25 + --> tests/ui/borrow_box.rs:108: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` - --> tests/ui/borrow_box.rs:115:29 + --> tests/ui/borrow_box.rs:111: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` - --> tests/ui/borrow_box.rs:122:25 + --> tests/ui/borrow_box.rs:117: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 e51d9912b308..f05a90d2c1fa 100644 --- a/tests/ui/borrow_deref_ref_unfixable.rs +++ b/tests/ui/borrow_deref_ref_unfixable.rs @@ -8,7 +8,5 @@ mod should_lint { let s = &String::new(); let x: &str = &*s; //~^ borrow_deref_ref - - } } diff --git a/tests/ui/borrow_interior_mutable_const/others.rs b/tests/ui/borrow_interior_mutable_const/others.rs index eaf90ce6a8dd..fa729b62d7f5 100644 --- a/tests/ui/borrow_interior_mutable_const/others.rs +++ b/tests/ui/borrow_interior_mutable_const/others.rs @@ -62,20 +62,20 @@ mod issue12979 { const CELL_REF: StaticRef<(UnsafeCell,)> = unsafe { StaticRef::new(std::ptr::null()) }; fn main() { -ATOMIC.store(1, Ordering::SeqCst); -//~^ borrow_interior_mutable_const -assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); -//~^ borrow_interior_mutable_const + ATOMIC.store(1, Ordering::SeqCst); + //~^ borrow_interior_mutable_const + assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); + //~^ borrow_interior_mutable_const let _once = ONCE_INIT; -let _once_ref = &ONCE_INIT; -//~^ borrow_interior_mutable_const -let _once_ref_2 = &&ONCE_INIT; -//~^ borrow_interior_mutable_const -let _once_ref_4 = &&&&ONCE_INIT; -//~^ borrow_interior_mutable_const -let _once_mut = &mut ONCE_INIT; -//~^ borrow_interior_mutable_const + let _once_ref = &ONCE_INIT; + //~^ borrow_interior_mutable_const + let _once_ref_2 = &&ONCE_INIT; + //~^ borrow_interior_mutable_const + let _once_ref_4 = &&&&ONCE_INIT; + //~^ borrow_interior_mutable_const + let _once_mut = &mut ONCE_INIT; + //~^ borrow_interior_mutable_const let _atomic_into_inner = ATOMIC.into_inner(); // these should be all fine. let _twice = (ONCE_INIT, ONCE_INIT); @@ -86,30 +86,30 @@ let _once_mut = &mut ONCE_INIT; let _ref_array_once = &[ONCE_INIT, ONCE_INIT][0]; // referencing projection is still bad. -let _ = &ATOMIC_TUPLE; -//~^ borrow_interior_mutable_const -let _ = &ATOMIC_TUPLE.0; -//~^ borrow_interior_mutable_const -let _ = &(&&&&ATOMIC_TUPLE).0; -//~^ borrow_interior_mutable_const -let _ = &ATOMIC_TUPLE.0[0]; -//~^ borrow_interior_mutable_const -let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); -//~^ borrow_interior_mutable_const + let _ = &ATOMIC_TUPLE; + //~^ borrow_interior_mutable_const + let _ = &ATOMIC_TUPLE.0; + //~^ borrow_interior_mutable_const + let _ = &(&&&&ATOMIC_TUPLE).0; + //~^ borrow_interior_mutable_const + let _ = &ATOMIC_TUPLE.0[0]; + //~^ borrow_interior_mutable_const + let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); + //~^ borrow_interior_mutable_const let _ = &ATOMIC_TUPLE.2; let _ = (&&&&ATOMIC_TUPLE).0; let _ = (&&&&ATOMIC_TUPLE).2; let _ = ATOMIC_TUPLE.0; -let _ = ATOMIC_TUPLE.0[0]; -//~^ borrow_interior_mutable_const + let _ = ATOMIC_TUPLE.0[0]; + //~^ borrow_interior_mutable_const let _ = ATOMIC_TUPLE.1.into_iter(); let _ = ATOMIC_TUPLE.2; let _ = &{ ATOMIC_TUPLE }; -CELL.set(2); -//~^ borrow_interior_mutable_const -assert_eq!(CELL.get(), 6); -//~^ borrow_interior_mutable_const + CELL.set(2); + //~^ borrow_interior_mutable_const + assert_eq!(CELL.get(), 6); + //~^ borrow_interior_mutable_const assert_eq!(INTEGER, 8); assert!(STRING.is_empty()); diff --git a/tests/ui/borrow_interior_mutable_const/others.stderr b/tests/ui/borrow_interior_mutable_const/others.stderr index f15664030151..decea153f717 100644 --- a/tests/ui/borrow_interior_mutable_const/others.stderr +++ b/tests/ui/borrow_interior_mutable_const/others.stderr @@ -1,8 +1,8 @@ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:65:1 + --> tests/ui/borrow_interior_mutable_const/others.rs:65:5 | -LL | ATOMIC.store(1, Ordering::SeqCst); - | ^^^^^^ +LL | ATOMIC.store(1, Ordering::SeqCst); + | ^^^^^^ | = help: assign this const to a local or static variable, and use the variable here note: the lint level is defined here @@ -12,106 +12,106 @@ LL | #![deny(clippy::borrow_interior_mutable_const)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:67:12 + --> tests/ui/borrow_interior_mutable_const/others.rs:67:16 | -LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); - | ^^^^^^ +LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); + | ^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:71:18 + --> tests/ui/borrow_interior_mutable_const/others.rs:71:22 | -LL | let _once_ref = &ONCE_INIT; - | ^^^^^^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:73:21 - | -LL | let _once_ref_2 = &&ONCE_INIT; - | ^^^^^^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:75:23 - | -LL | let _once_ref_4 = &&&&ONCE_INIT; - | ^^^^^^^^^ - | - = help: assign this const to a local or static variable, and use the variable here - -error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:77:22 - | -LL | let _once_mut = &mut ONCE_INIT; +LL | let _once_ref = &ONCE_INIT; | ^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:89:10 + --> tests/ui/borrow_interior_mutable_const/others.rs:73:25 | -LL | let _ = &ATOMIC_TUPLE; - | ^^^^^^^^^^^^ +LL | let _once_ref_2 = &&ONCE_INIT; + | ^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:91:10 + --> tests/ui/borrow_interior_mutable_const/others.rs:75:27 | -LL | let _ = &ATOMIC_TUPLE.0; - | ^^^^^^^^^^^^ +LL | let _once_ref_4 = &&&&ONCE_INIT; + | ^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:93:15 + --> tests/ui/borrow_interior_mutable_const/others.rs:77:26 | -LL | let _ = &(&&&&ATOMIC_TUPLE).0; - | ^^^^^^^^^^^^ +LL | let _once_mut = &mut ONCE_INIT; + | ^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:95:10 + --> tests/ui/borrow_interior_mutable_const/others.rs:89:14 | -LL | let _ = &ATOMIC_TUPLE.0[0]; - | ^^^^^^^^^^^^ +LL | let _ = &ATOMIC_TUPLE; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:97:9 + --> tests/ui/borrow_interior_mutable_const/others.rs:91:14 | -LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); - | ^^^^^^^^^^^^ +LL | let _ = &ATOMIC_TUPLE.0; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:103:9 + --> tests/ui/borrow_interior_mutable_const/others.rs:93:19 | -LL | let _ = ATOMIC_TUPLE.0[0]; - | ^^^^^^^^^^^^ +LL | let _ = &(&&&&ATOMIC_TUPLE).0; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:109:1 + --> tests/ui/borrow_interior_mutable_const/others.rs:95:14 | -LL | CELL.set(2); - | ^^^^ +LL | let _ = &ATOMIC_TUPLE.0[0]; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/others.rs:111:12 + --> tests/ui/borrow_interior_mutable_const/others.rs:97:13 | -LL | assert_eq!(CELL.get(), 6); - | ^^^^ +LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); + | ^^^^^^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:103:13 + | +LL | let _ = ATOMIC_TUPLE.0[0]; + | ^^^^^^^^^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:109:5 + | +LL | CELL.set(2); + | ^^^^ + | + = help: assign this const to a local or static variable, and use the variable here + +error: a `const` item with interior mutability should not be borrowed + --> tests/ui/borrow_interior_mutable_const/others.rs:111:16 + | +LL | assert_eq!(CELL.get(), 6); + | ^^^^ | = help: assign this const to a local or static variable, and use the variable here diff --git a/tests/ui/borrow_interior_mutable_const/traits.rs b/tests/ui/borrow_interior_mutable_const/traits.rs index 8e2b7ffd554f..c4878dbe57b2 100644 --- a/tests/ui/borrow_interior_mutable_const/traits.rs +++ b/tests/ui/borrow_interior_mutable_const/traits.rs @@ -12,8 +12,8 @@ trait ConcreteTypes { const STRING: String; fn function() { -let _ = &Self::ATOMIC; -//~^ borrow_interior_mutable_const + let _ = &Self::ATOMIC; + //~^ borrow_interior_mutable_const let _ = &Self::STRING; } } @@ -24,8 +24,8 @@ impl ConcreteTypes for u64 { fn function() { // Lint this again since implementers can choose not to borrow it. -let _ = &Self::ATOMIC; -//~^ borrow_interior_mutable_const + let _ = &Self::ATOMIC; + //~^ borrow_interior_mutable_const let _ = &Self::STRING; } } @@ -50,8 +50,8 @@ impl GenericTypes for Vec { fn function() { let _ = &Self::TO_REMAIN_GENERIC; -let _ = &Self::TO_BE_CONCRETE; -//~^ borrow_interior_mutable_const + let _ = &Self::TO_BE_CONCRETE; + //~^ borrow_interior_mutable_const } } @@ -86,10 +86,10 @@ impl AssocTypes for Vec { fn function() { let _ = &Self::TO_BE_FROZEN; -let _ = &Self::TO_BE_UNFROZEN; -//~^ borrow_interior_mutable_const -let _ = &Self::WRAPPED_TO_BE_UNFROZEN; -//~^ borrow_interior_mutable_const + let _ = &Self::TO_BE_UNFROZEN; + //~^ borrow_interior_mutable_const + let _ = &Self::WRAPPED_TO_BE_UNFROZEN; + //~^ borrow_interior_mutable_const let _ = &Self::WRAPPED_TO_BE_GENERIC_PARAM; } } @@ -111,8 +111,8 @@ where fn function() { let _ = &Self::NOT_BOUNDED; -let _ = &Self::BOUNDED; -//~^ borrow_interior_mutable_const + let _ = &Self::BOUNDED; + //~^ borrow_interior_mutable_const } } @@ -125,8 +125,8 @@ where fn function() { let _ = &Self::NOT_BOUNDED; -let _ = &Self::BOUNDED; -//~^ borrow_interior_mutable_const + let _ = &Self::BOUNDED; + //~^ borrow_interior_mutable_const } } @@ -155,10 +155,10 @@ impl SelfType for AtomicUsize { const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); fn function() { -let _ = &Self::SELF; -//~^ borrow_interior_mutable_const -let _ = &Self::WRAPPED_SELF; -//~^ borrow_interior_mutable_const + let _ = &Self::SELF; + //~^ borrow_interior_mutable_const + let _ = &Self::WRAPPED_SELF; + //~^ borrow_interior_mutable_const } } @@ -167,10 +167,10 @@ trait BothOfCellAndGeneric { const INDIRECT: Cell<*const T>; fn function() { -let _ = &Self::DIRECT; -//~^ borrow_interior_mutable_const -let _ = &Self::INDIRECT; -//~^ borrow_interior_mutable_const + let _ = &Self::DIRECT; + //~^ borrow_interior_mutable_const + let _ = &Self::INDIRECT; + //~^ borrow_interior_mutable_const } } @@ -179,10 +179,10 @@ impl BothOfCellAndGeneric for Vec { const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null()); fn function() { -let _ = &Self::DIRECT; -//~^ borrow_interior_mutable_const -let _ = &Self::INDIRECT; -//~^ borrow_interior_mutable_const + let _ = &Self::DIRECT; + //~^ borrow_interior_mutable_const + let _ = &Self::INDIRECT; + //~^ borrow_interior_mutable_const } } @@ -201,19 +201,19 @@ where const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); fn function() { -let _ = &Self::ATOMIC; -//~^ borrow_interior_mutable_const + let _ = &Self::ATOMIC; + //~^ borrow_interior_mutable_const let _ = &Self::COW; let _ = &Self::GENERIC_TYPE; let _ = &Self::ASSOC_TYPE; -let _ = &Self::BOUNDED_ASSOC_TYPE; -//~^ borrow_interior_mutable_const + let _ = &Self::BOUNDED_ASSOC_TYPE; + //~^ borrow_interior_mutable_const } } fn main() { -u64::ATOMIC.store(5, Ordering::SeqCst); -//~^ borrow_interior_mutable_const -assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); -//~^ borrow_interior_mutable_const + u64::ATOMIC.store(5, Ordering::SeqCst); + //~^ borrow_interior_mutable_const + assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); + //~^ borrow_interior_mutable_const } diff --git a/tests/ui/borrow_interior_mutable_const/traits.stderr b/tests/ui/borrow_interior_mutable_const/traits.stderr index 6998ba6fc090..cad68ca9260c 100644 --- a/tests/ui/borrow_interior_mutable_const/traits.stderr +++ b/tests/ui/borrow_interior_mutable_const/traits.stderr @@ -1,8 +1,8 @@ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:15:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:15:18 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here note: the lint level is defined here @@ -12,130 +12,130 @@ LL | #![deny(clippy::borrow_interior_mutable_const)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:27:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:27:18 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:53:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:53:18 | -LL | let _ = &Self::TO_BE_CONCRETE; - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::TO_BE_CONCRETE; + | ^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:89:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:89:18 | -LL | let _ = &Self::TO_BE_UNFROZEN; - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::TO_BE_UNFROZEN; + | ^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:91:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:91:18 | -LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:114:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:114:18 | -LL | let _ = &Self::BOUNDED; - | ^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED; + | ^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:128:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:128:18 | -LL | let _ = &Self::BOUNDED; - | ^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED; + | ^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:158:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:158:18 | -LL | let _ = &Self::SELF; - | ^^^^^^^^^^ +LL | let _ = &Self::SELF; + | ^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:160:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:160:18 | -LL | let _ = &Self::WRAPPED_SELF; - | ^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::WRAPPED_SELF; + | ^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:170:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:170:18 | -LL | let _ = &Self::DIRECT; - | ^^^^^^^^^^^^ +LL | let _ = &Self::DIRECT; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:172:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:172:18 | -LL | let _ = &Self::INDIRECT; - | ^^^^^^^^^^^^^^ +LL | let _ = &Self::INDIRECT; + | ^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:182:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:182:18 | -LL | let _ = &Self::DIRECT; - | ^^^^^^^^^^^^ +LL | let _ = &Self::DIRECT; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:184:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:184:18 | -LL | let _ = &Self::INDIRECT; - | ^^^^^^^^^^^^^^ +LL | let _ = &Self::INDIRECT; + | ^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:204:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:204:18 | -LL | let _ = &Self::ATOMIC; - | ^^^^^^^^^^^^ +LL | let _ = &Self::ATOMIC; + | ^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:209:10 + --> tests/ui/borrow_interior_mutable_const/traits.rs:209:18 | -LL | let _ = &Self::BOUNDED_ASSOC_TYPE; - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ = &Self::BOUNDED_ASSOC_TYPE; + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:215:1 + --> tests/ui/borrow_interior_mutable_const/traits.rs:215:5 | -LL | u64::ATOMIC.store(5, Ordering::SeqCst); - | ^^^^^^^^^^^ +LL | u64::ATOMIC.store(5, Ordering::SeqCst); + | ^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here error: a `const` item with interior mutability should not be borrowed - --> tests/ui/borrow_interior_mutable_const/traits.rs:217:12 + --> tests/ui/borrow_interior_mutable_const/traits.rs:217:16 | -LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); - | ^^^^^^^^^^^ +LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); + | ^^^^^^^^^^^ | = help: assign this const to a local or static variable, and use the variable here diff --git a/tests/ui/box_collection.rs b/tests/ui/box_collection.rs index 61117412016a..0f7d3c74ddd0 100644 --- a/tests/ui/box_collection.rs +++ b/tests/ui/box_collection.rs @@ -21,7 +21,6 @@ fn test_macro() { fn test1(foo: Box>) {} //~^ box_collection - fn test2(foo: Box)>) { // pass if #31 is fixed foo(vec![1, 2, 3]) @@ -30,35 +29,27 @@ fn test2(foo: Box)>) { fn test3(foo: Box) {} //~^ box_collection - fn test4(foo: Box>) {} //~^ box_collection - fn test5(foo: Box>) {} //~^ box_collection - fn test6(foo: Box>) {} //~^ box_collection - fn test7(foo: Box>) {} //~^ box_collection - fn test8(foo: Box>) {} //~^ box_collection - fn test9(foo: Box>) {} //~^ box_collection - fn test10(foo: Box>) {} //~^ box_collection - fn test_local_not_linted() { let _: Box>; } diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index 644556edd572..ebbc3d92b57f 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -9,7 +9,7 @@ LL | fn test1(foo: Box>) {} = help: to override `-D warnings` add `#[allow(clippy::box_collection)]` error: you seem to be trying to use `Box`. Consider using just `String` - --> tests/ui/box_collection.rs:30:15 + --> tests/ui/box_collection.rs:29:15 | LL | fn test3(foo: Box) {} | ^^^^^^^^^^^ @@ -17,7 +17,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<..>` - --> tests/ui/box_collection.rs:34:15 + --> tests/ui/box_collection.rs:32:15 | LL | fn test4(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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<..>` - --> tests/ui/box_collection.rs:38:15 + --> tests/ui/box_collection.rs:35:15 | LL | fn test5(foo: Box>) {} | ^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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<..>` - --> tests/ui/box_collection.rs:42:15 + --> tests/ui/box_collection.rs:38:15 | LL | fn test6(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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<..>` - --> tests/ui/box_collection.rs:46:15 + --> tests/ui/box_collection.rs:41:15 | LL | fn test7(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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<..>` - --> tests/ui/box_collection.rs:50:15 + --> tests/ui/box_collection.rs:44:15 | LL | fn test8(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,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<..>` - --> tests/ui/box_collection.rs:54:15 + --> tests/ui/box_collection.rs:47:15 | LL | fn test9(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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<..>` - --> tests/ui/box_collection.rs:58:16 + --> tests/ui/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 fa234dce1a99..3fb685aa36c1 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -38,8 +38,7 @@ fn warn_call() { } fn warn_arg(x: Box) { -//~^ boxed_local - + //~^ boxed_local x.foo(); } @@ -124,7 +123,6 @@ pub struct PeekableSeekable { pub fn new(_needs_name: Box>) -> () {} //~^ boxed_local - /// Regression for #916, #1123 /// /// This shouldn't warn for `boxed_local`as the implementation of a trait @@ -189,7 +187,7 @@ mod issue4804 { // warn on `x: Box` fn default_impl_x(self: Box, x: Box) -> u32 { - //~^ boxed_local + //~^ boxed_local 4 } @@ -199,7 +197,6 @@ mod issue4804 { // warn on `x: Box` fn foo(x: Box) {} //~^ boxed_local - } } diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 5ce2c8083f15..81ebc4fde498 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -8,19 +8,19 @@ LL | fn warn_arg(x: Box) { = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:124:12 + --> tests/ui/boxed_local.rs:123:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:191:44 + --> tests/ui/boxed_local.rs:189:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:200:16 + --> tests/ui/boxed_local.rs:198: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 050c8c0d53f2..06472a4f5d57 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -35,7 +35,6 @@ fn simple_examples() { let result = false; //~^ branches_sharing_code - println!("Block end!"); result }; @@ -55,7 +54,6 @@ fn simple_examples() { println!("This is also eq with the else block"); println!("Same end of block"); //~^ branches_sharing_code - } // Use of outer scope value @@ -73,8 +71,7 @@ fn simple_examples() { println!("I'm a local because I use the value `z`: `{}`", z); println!( - //~^ branches_sharing_code - + //~^ branches_sharing_code "I'm moveable because I know: `outer_scope_value`: '{}'", outer_scope_value ); @@ -88,7 +85,6 @@ fn simple_examples() { } else { println!("Hello World"); //~^ branches_sharing_code - } } } @@ -188,8 +184,6 @@ fn added_note_for_expression_use() -> u32 { let _ = 6; x << 2 //~^ branches_sharing_code - - }; if x == 9 { @@ -198,8 +192,6 @@ fn added_note_for_expression_use() -> u32 { let _ = 17; x * 4 //~^ branches_sharing_code - - } } diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_bottom.stderr index b7bb07775241..648a99c65ed2 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -2,7 +2,9 @@ error: all if blocks contain the same code at the end --> tests/ui/branches_sharing_code/shared_at_bottom.rs:35:5 | LL | / let result = false; -... | +LL | | +LL | | +LL | | println!("Block end!"); LL | | result LL | | }; | |_____^ @@ -19,16 +21,15 @@ LL ~ } LL + let result = false; LL + LL + -LL + LL + println!("Block end!"); LL ~ result; | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:56:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:55:5 | LL | / println!("Same end of block"); -... | +LL | | LL | | } | |_____^ | @@ -39,11 +40,10 @@ LL + println!("Same end of block"); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:75:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:73:5 | LL | / println!( LL | | -LL | | LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | outer_scope_value LL | | ); @@ -55,17 +55,16 @@ help: consider moving these statements after the if LL ~ } LL + println!( LL + -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 - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:89:9 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:86:9 | LL | / println!("Hello World"); -... | +LL | | LL | | } | |_________^ | @@ -76,7 +75,7 @@ LL + println!("Hello World"); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:107:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:103:5 | LL | / let later_used_value = "A string value"; LL | | @@ -97,7 +96,7 @@ LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:122:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:118:5 | LL | / let simple_examples = "I now identify as a &str :)"; LL | | @@ -117,10 +116,10 @@ LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:189:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:185:5 | LL | / x << 2 -... | +LL | | LL | | }; | |_____^ | @@ -132,10 +131,10 @@ LL ~ x << 2; | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:199:5 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:193:5 | LL | / x * 4 -... | +LL | | LL | | } | |_____^ | @@ -147,7 +146,7 @@ LL + x * 4 | error: all if blocks contain the same code at the end - --> tests/ui/branches_sharing_code/shared_at_bottom.rs:214:44 + --> tests/ui/branches_sharing_code/shared_at_bottom.rs:206: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 a6f8ce8a3816..694c67d4c85b 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/tests/ui/branches_sharing_code/shared_at_top.rs @@ -9,7 +9,7 @@ fn simple_examples() { // Simple if true { - //~^ branches_sharing_code + //~^ branches_sharing_code println!("Hello World!"); println!("I'm branch nr: 1"); } else { @@ -17,10 +17,9 @@ fn simple_examples() { println!("I'm branch nr: 2"); } - // Else if if x == 0 { - //~^ branches_sharing_code + //~^ branches_sharing_code let y = 9; println!("The value y was set to: `{}`", y); let _z = y; @@ -40,10 +39,9 @@ fn simple_examples() { println!("Ha, Pascal allows you to start the array where you want") } - // Return a value let _ = if x == 7 { - //~^ branches_sharing_code + //~^ branches_sharing_code let y = 16; println!("What can I say except: \"you're welcome?\""); @@ -63,7 +61,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 { - //~^ branches_sharing_code + //~^ branches_sharing_code let used_value_name = "Different type"; println!("Str: {}", used_value_name); let _ = 1; @@ -79,7 +77,7 @@ fn simple_but_suggestion_is_invalid() { let can_be_overridden = 8; let _ = can_be_overridden; if x == 11 { - //~^ branches_sharing_code + //~^ branches_sharing_code let can_be_overridden = "Move me"; println!("I'm also moveable"); @@ -97,7 +95,7 @@ fn check_if_same_than_else_mask() { #[allow(clippy::if_same_then_else)] if x == 2020 { - //~^ branches_sharing_code + //~^ branches_sharing_code println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); println!("Because `IF_SAME_THEN_ELSE` is allowed here"); @@ -112,7 +110,6 @@ fn check_if_same_than_else_mask() { println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); } //~^^^^^ if_same_then_else - } #[allow(clippy::vec_init_then_push)] diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index 5b0422d5df18..d28e9c7af296 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -18,7 +18,7 @@ LL + if true { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:22:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:21:5 | LL | / if x == 0 { LL | | @@ -37,7 +37,7 @@ LL + if x == 0 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:45:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:43:5 | LL | / let _ = if x == 7 { ... | @@ -51,7 +51,7 @@ LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:65:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:63:5 | LL | / if x == 10 { LL | | @@ -68,7 +68,7 @@ LL + if x == 10 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:81:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:79:5 | LL | / if x == 11 { LL | | @@ -86,7 +86,7 @@ LL + if x == 11 { | error: all if blocks contain the same code at the start - --> tests/ui/branches_sharing_code/shared_at_top.rs:99:5 + --> tests/ui/branches_sharing_code/shared_at_top.rs:97:5 | LL | / if x == 2020 { LL | | @@ -103,7 +103,7 @@ LL + if x == 2020 { | error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/shared_at_top.rs:109:18 + --> tests/ui/branches_sharing_code/shared_at_top.rs:107:18 | LL | if x == 2019 { | __________________^ @@ -112,7 +112,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/shared_at_top.rs:111:12 + --> tests/ui/branches_sharing_code/shared_at_top.rs:109: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 799f58d28430..75334f70f1f6 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,7 +15,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 7 { - //~^ branches_sharing_code + //~^ branches_sharing_code let t = 7; let _overlap_start = t * 2; @@ -33,7 +33,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 99 { - //~^ branches_sharing_code + //~^ branches_sharing_code let r = 7; let _overlap_start = r; @@ -64,7 +64,7 @@ fn complexer_example() { let x = 8; let y = 9; if (x > 7 && y < 13) || (x + y) % 2 == 1 { - //~^ branches_sharing_code + //~^ branches_sharing_code let a = 0xcafe; let b = 0xffff00ff; @@ -99,7 +99,7 @@ fn added_note_for_expression_use() -> u32 { let x = 9; let _ = if x == 7 { - //~^ branches_sharing_code + //~^ branches_sharing_code let _ = 19; @@ -113,7 +113,7 @@ fn added_note_for_expression_use() -> u32 { }; if x == 9 { - //~^ branches_sharing_code + //~^ branches_sharing_code let _ = 17; diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.rs b/tests/ui/branches_sharing_code/valid_if_blocks.rs index 23ea86c88f54..d72c5eef87ad 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.rs +++ b/tests/ui/branches_sharing_code/valid_if_blocks.rs @@ -110,7 +110,6 @@ fn valid_examples() { } else { } //~^^^ if_same_then_else - } /// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint @@ -130,12 +129,10 @@ fn trigger_other_lint() { } //~^^^^^^^^^ if_same_then_else - // Only same expression let _ = if x == 6 { 7 } else { 7 }; //~^ if_same_then_else - // Same in else if block let _ = if x == 67 { println!("Well I'm the most important block"); @@ -151,7 +148,6 @@ fn trigger_other_lint() { }; //~^^^^^^^^^ if_same_then_else - if x == 0 { println!("I'm single"); } else if x == 68 { @@ -160,7 +156,6 @@ fn trigger_other_lint() { println!("I'm a doppelgänger"); } //~^^^^^ if_same_then_else - } fn main() {} diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/tests/ui/branches_sharing_code/valid_if_blocks.stderr index a0c4dd24d6b4..4c7e4141b629 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -20,7 +20,7 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:122:15 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:121:15 | LL | if x == 0 { | _______________^ @@ -31,7 +31,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:126:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:125:12 | LL | } else { | ____________^ @@ -42,19 +42,19 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:135:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:133:23 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:135:34 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:133:34 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:143:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:140:23 | LL | } else if x == 68 { | _______________________^ @@ -65,7 +65,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:147:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:144:12 | LL | } else { | ____________^ @@ -76,7 +76,7 @@ LL | | }; | |_____^ error: this `if` has identical blocks - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:157:23 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:153:23 | LL | } else if x == 68 { | _______________________^ @@ -85,7 +85,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/branches_sharing_code/valid_if_blocks.rs:159:12 + --> tests/ui/branches_sharing_code/valid_if_blocks.rs:155:12 | LL | } else { | ____________^ diff --git a/tests/ui/builtin_type_shadow.rs b/tests/ui/builtin_type_shadow.rs index 31df0c21b67e..eda22b7c38ef 100644 --- a/tests/ui/builtin_type_shadow.rs +++ b/tests/ui/builtin_type_shadow.rs @@ -2,7 +2,7 @@ #![allow(non_camel_case_types)] fn foo(a: u32) -> u32 { -//~^ builtin_type_shadow + //~^ builtin_type_shadow 42 //~ ERROR: mismatched type } diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index bad39fcf8f66..f03f99177d54 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -10,12 +10,10 @@ fn main() { let _ = x.iter().filter(|&&a| a == 0).count(); //~^ naive_bytecount - // naive byte count let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); //~^ naive_bytecount - // not an equality count, OK. let _ = x.iter().filter(|a| **a > 0).count(); @@ -34,7 +32,6 @@ fn main() { let _ = x.iter().filter(|a| b + 1 == **a).count(); //~^ naive_bytecount - let y = vec![0_u16; 3]; // naive count, but not bytes diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 9a0986f56478..d1a73fe98358 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 - --> tests/ui/bytecount.rs:15:13 + --> tests/ui/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 - --> tests/ui/bytecount.rs:34:13 + --> tests/ui/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 b2e92d36f402..56e4326cdc1d 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -25,7 +25,6 @@ fn main() { x0 as f32; //~^ cast_precision_loss - let x1 = 1i64; x1 as f32; //~^ cast_precision_loss @@ -52,8 +51,6 @@ fn main() { //~^ cast_possible_truncation //~| cast_sign_loss - - 1f64 as f32; //~^ cast_possible_truncation @@ -70,14 +67,11 @@ fn main() { //~^ cast_possible_truncation //~| cast_sign_loss - 1f32 as u32 as u16; //~^ cast_possible_truncation //~| cast_possible_truncation //~| cast_sign_loss - - { let _x: i8 = 1i32 as _; //~^ cast_possible_truncation @@ -91,14 +85,11 @@ fn main() { 1f32 as u8; //~^ cast_possible_truncation //~| cast_sign_loss - - } // Test clippy::cast_possible_wrap 1u8 as i8; //~^ cast_possible_wrap - 1u16 as i16; //~^ cast_possible_wrap @@ -120,14 +111,11 @@ fn main() { //~^ cast_possible_truncation //~| cast_possible_wrap - - // wraps on 32 bit ptr size 1usize as i32; //~^ cast_possible_truncation //~| cast_possible_wrap - // wraps on 64 bit ptr size 1usize as i64; //~^ cast_possible_wrap @@ -138,7 +126,6 @@ fn main() { 1u16 as isize; //~^ cast_possible_wrap - // wraps on 32 bit ptr size 1u32 as isize; //~^ cast_possible_wrap @@ -148,7 +135,6 @@ fn main() { //~^ cast_possible_truncation //~| cast_possible_wrap - // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; @@ -253,7 +239,6 @@ fn main() { (-99999999999i64).min(1) as i8; //~^ cast_possible_truncation - // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; (999999u64 % 15) as u8; @@ -268,7 +253,6 @@ fn main() { 999999u64.clamp(0, 256) as u8; //~^ cast_possible_truncation - #[derive(Clone, Copy)] enum E1 { A, @@ -295,7 +279,6 @@ fn main() { let _ = Self::B as u8; //~^ cast_enum_truncation - // Don't lint. `255..=256` fits in i16 let _ = self as i16; // Don't lint. @@ -468,7 +451,6 @@ fn issue11642() { (-2_i32).pow(3) as u32; //~^ cast_sign_loss - (3_i32 % 2) as u32; (3_i32 % -2) as u32; (-5_i32 % 2) as u32; @@ -481,14 +463,12 @@ fn issue11642() { (-2_i32 >> 1) as u32; //~^ cast_sign_loss - let x: i32 = 10; (x * x) as u32; //~^ cast_sign_loss (x * x * x) as u32; //~^ cast_sign_loss - let y: i16 = -2; (y * y * y * y * -2) as u16; //~^ cast_sign_loss @@ -502,14 +482,12 @@ fn issue11642() { //~^ cast_sign_loss //~| eq_op - (y + y + y + -2) as u16; //~^ cast_sign_loss (y + y + y + 2) as u16; //~^ cast_sign_loss - let z: i16 = 2; (z + -2) as u16; //~^ cast_sign_loss @@ -547,7 +525,6 @@ fn issue11642() { (a.abs() * b.pow(2) / c.abs()) as u32 //~^ cast_sign_loss - } } @@ -590,5 +567,4 @@ fn issue12721() { (255 % 999999u64) as u8; //~^ cast_possible_truncation - } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index daabb8192141..484be7905d42 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -8,37 +8,37 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> tests/ui/cast.rs:30:5 + --> tests/ui/cast.rs:29: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) - --> tests/ui/cast.rs:33:5 + --> tests/ui/cast.rs:32: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) - --> tests/ui/cast.rs:37:5 + --> tests/ui/cast.rs:36: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) - --> tests/ui/cast.rs:41:5 + --> tests/ui/cast.rs:40: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) - --> tests/ui/cast.rs:44:5 + --> tests/ui/cast.rs:43:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:48:5 + --> tests/ui/cast.rs:47:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | 1f32 as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:51:5 + --> tests/ui/cast.rs:50:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -56,7 +56,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 - --> tests/ui/cast.rs:51:5 + --> tests/ui/cast.rs:50:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | 1f32 as u32; = help: to override `-D warnings` add `#[allow(clippy::cast_sign_loss)]` error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:57:5 + --> tests/ui/cast.rs:54:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/cast.rs:60:5 + --> tests/ui/cast.rs:57:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -85,7 +85,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> tests/ui/cast.rs:63:5 + --> tests/ui/cast.rs:60:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> tests/ui/cast.rs:66:5 + --> tests/ui/cast.rs:63:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/cast.rs:69:5 + --> tests/ui/cast.rs:66:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -113,13 +113,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 - --> tests/ui/cast.rs:69:5 + --> tests/ui/cast.rs:66:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> tests/ui/cast.rs:74:5 + --> tests/ui/cast.rs:70:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> tests/ui/cast.rs:74:5 + --> tests/ui/cast.rs:70:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -139,13 +139,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 - --> tests/ui/cast.rs:74:5 + --> tests/ui/cast.rs:70:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> tests/ui/cast.rs:82:22 + --> tests/ui/cast.rs:76:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -157,7 +157,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> tests/ui/cast.rs:85:9 + --> tests/ui/cast.rs:79:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -165,7 +165,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 - --> tests/ui/cast.rs:88:9 + --> tests/ui/cast.rs:82:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -173,7 +173,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 - --> tests/ui/cast.rs:91:9 + --> tests/ui/cast.rs:85:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -181,13 +181,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 - --> tests/ui/cast.rs:91:9 + --> tests/ui/cast.rs:85:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> tests/ui/cast.rs:98:5 + --> tests/ui/cast.rs:90:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -196,31 +196,31 @@ LL | 1u8 as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `u16` to `i16` may wrap around the value - --> tests/ui/cast.rs:102:5 + --> tests/ui/cast.rs:93:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> tests/ui/cast.rs:105:5 + --> tests/ui/cast.rs:96:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> tests/ui/cast.rs:108:5 + --> tests/ui/cast.rs:99:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> tests/ui/cast.rs:111:5 + --> tests/ui/cast.rs:102:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> tests/ui/cast.rs:115:5 + --> tests/ui/cast.rs:106:5 | LL | 1usize as i8; | ^^^^^^^^^^^^ @@ -232,7 +232,7 @@ LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> tests/ui/cast.rs:119:5 + --> tests/ui/cast.rs:110:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -244,7 +244,7 @@ LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:119:5 + --> tests/ui/cast.rs:110:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -253,7 +253,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 - --> tests/ui/cast.rs:126:5 + --> tests/ui/cast.rs:115:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -265,19 +265,19 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:126:5 + --> tests/ui/cast.rs:115:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:132:5 + --> tests/ui/cast.rs:120:5 | LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> tests/ui/cast.rs:138:5 + --> tests/ui/cast.rs:126:5 | LL | 1u16 as isize; | ^^^^^^^^^^^^^ @@ -286,13 +286,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 - --> tests/ui/cast.rs:143:5 + --> tests/ui/cast.rs:130:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:147:5 + --> tests/ui/cast.rs:134:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -304,55 +304,55 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast.rs:147:5 + --> tests/ui/cast.rs:134:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:154:5 + --> tests/ui/cast.rs:140:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:158:5 + --> tests/ui/cast.rs:144:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i8` to `u8` may lose the sign of the value - --> tests/ui/cast.rs:170:5 + --> tests/ui/cast.rs:156:5 | LL | (i8::MIN).abs() as u8; | ^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:175:5 + --> tests/ui/cast.rs:161:5 | LL | (-1i64).abs() as u64; | ^^^^^^^^^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:177:5 + --> tests/ui/cast.rs:163:5 | LL | (-1isize).abs() as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:185:5 + --> tests/ui/cast.rs:171:5 | LL | (unsafe { (-1i64).checked_abs().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `u64` may lose the sign of the value - --> tests/ui/cast.rs:201:5 + --> tests/ui/cast.rs:187:5 | LL | (unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }) as u64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> tests/ui/cast.rs:253:5 + --> tests/ui/cast.rs:239:5 | LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -364,7 +364,7 @@ LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:268:5 + --> tests/ui/cast.rs:253:5 | LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -376,7 +376,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> tests/ui/cast.rs:292:21 + --> tests/ui/cast.rs:276:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -388,7 +388,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> tests/ui/cast.rs:295:21 + --> tests/ui/cast.rs:279:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _ = Self::B as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_enum_truncation)]` error: casting `main::E5` to `i8` may truncate the value - --> tests/ui/cast.rs:338:21 + --> tests/ui/cast.rs:321:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -409,13 +409,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> tests/ui/cast.rs:341:21 + --> tests/ui/cast.rs:324:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> tests/ui/cast.rs:359:21 + --> tests/ui/cast.rs:342:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -427,7 +427,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:379:21 + --> tests/ui/cast.rs:362:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -439,7 +439,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> tests/ui/cast.rs:427:21 + --> tests/ui/cast.rs:410:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -451,7 +451,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:439:13 + --> tests/ui/cast.rs:422:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -463,7 +463,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:444:13 + --> tests/ui/cast.rs:427:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ @@ -475,85 +475,85 @@ LL | let c = u8::try_from(q / 1000); | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:457:9 + --> tests/ui/cast.rs:440:9 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:463:32 + --> tests/ui/cast.rs:446:32 | LL | let _a = |x: i32| -> u32 { (x * x * x * x) as u32 }; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:466:5 + --> tests/ui/cast.rs:449:5 | LL | (2_i32).checked_pow(3).unwrap() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:468:5 + --> tests/ui/cast.rs:451:5 | LL | (-2_i32).pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:474:5 + --> tests/ui/cast.rs:456:5 | LL | (-5_i32 % 2) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:477:5 + --> tests/ui/cast.rs:459:5 | LL | (-5_i32 % -2) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:481:5 + --> tests/ui/cast.rs:463:5 | LL | (-2_i32 >> 1) as u32; | ^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:486:5 + --> tests/ui/cast.rs:467:5 | LL | (x * x) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:488:5 + --> tests/ui/cast.rs:469:5 | LL | (x * x * x) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:493:5 + --> tests/ui/cast.rs:473:5 | LL | (y * y * y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:496:5 + --> tests/ui/cast.rs:476:5 | LL | (y * y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:498:5 + --> tests/ui/cast.rs:478:5 | LL | (y * y / y * 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:501:5 + --> tests/ui/cast.rs:481:5 | LL | (y / y * y * -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `/` - --> tests/ui/cast.rs:501:6 + --> tests/ui/cast.rs:481:6 | LL | (y / y * y * -2) as u16; | ^^^^^ @@ -561,97 +561,97 @@ LL | (y / y * y * -2) as u16; = note: `#[deny(clippy::eq_op)]` on by default error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:506:5 + --> tests/ui/cast.rs:485:5 | LL | (y + y + y + -2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:509:5 + --> tests/ui/cast.rs:488:5 | LL | (y + y + y + 2) as u16; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:514:5 + --> tests/ui/cast.rs:492:5 | LL | (z + -2) as u16; | ^^^^^^^^^^^^^^^ error: casting `i16` to `u16` may lose the sign of the value - --> tests/ui/cast.rs:517:5 + --> tests/ui/cast.rs:495:5 | LL | (z + z + 2) as u16; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:521:9 + --> tests/ui/cast.rs:499:9 | LL | (a * a * b * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:523:9 + --> tests/ui/cast.rs:501:9 | LL | (a * b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:526:9 + --> tests/ui/cast.rs:504:9 | LL | (a * -b * c) as u32; | ^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:529:9 + --> tests/ui/cast.rs:507:9 | LL | (a * b * c * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:531:9 + --> tests/ui/cast.rs:509:9 | LL | (a * -2) as u32; | ^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:534:9 + --> tests/ui/cast.rs:512:9 | LL | (a * b * c * -2) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:537:9 + --> tests/ui/cast.rs:515:9 | LL | (a / b) as u32; | ^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:539:9 + --> tests/ui/cast.rs:517:9 | LL | (a / b * c) as u32; | ^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:542:9 + --> tests/ui/cast.rs:520:9 | LL | (a / b + b * c) as u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:545:9 + --> tests/ui/cast.rs:523:9 | LL | a.saturating_pow(3) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:548:9 + --> tests/ui/cast.rs:526:9 | LL | (a.abs() * b.pow(2) / c.abs()) as u32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> tests/ui/cast.rs:557:21 + --> tests/ui/cast.rs:534:21 | LL | let _ = i32::MIN as u32; // cast_sign_loss | ^^^^^^^^^^^^^^^ @@ -662,7 +662,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:559:21 + --> tests/ui/cast.rs:536:21 | LL | let _ = u32::MAX as u8; // cast_possible_truncation | ^^^^^^^^^^^^^^ @@ -678,7 +678,7 @@ LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:561:21 + --> tests/ui/cast.rs:538:21 | LL | let _ = std::f64::consts::PI as f32; // cast_possible_truncation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -690,7 +690,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:571:5 + --> tests/ui/cast.rs:548:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -702,13 +702,13 @@ LL | usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:571:5 + --> tests/ui/cast.rs:548:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:588:5 + --> tests/ui/cast.rs:565:5 | LL | (256 & 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL | u8::try_from(256 & 999999u64); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:591:5 + --> tests/ui/cast.rs:568:5 | LL | (255 % 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_alignment.rs b/tests/ui/cast_alignment.rs index 1f14cb8a8452..5773ffddb917 100644 --- a/tests/ui/cast_alignment.rs +++ b/tests/ui/cast_alignment.rs @@ -19,11 +19,9 @@ fn main() { (&1u8 as *const u8) as *const u16; //~^ cast_ptr_alignment - (&mut 1u8 as *mut u8) as *mut u16; //~^ cast_ptr_alignment - // cast to more-strictly-aligned type, but with the `pointer::cast` function. (&1u8 as *const u8).cast::(); //~^ cast_ptr_alignment @@ -31,7 +29,6 @@ fn main() { (&mut 1u8 as *mut u8).cast::(); //~^ cast_ptr_alignment - /* These should be ok */ // not a pointer type diff --git a/tests/ui/cast_alignment.stderr b/tests/ui/cast_alignment.stderr index a1598eb1b6b4..6d9a81f0ecfd 100644 --- a/tests/ui/cast_alignment.stderr +++ b/tests/ui/cast_alignment.stderr @@ -8,19 +8,19 @@ LL | (&1u8 as *const u8) as *const u16; = help: to override `-D warnings` add `#[allow(clippy::cast_ptr_alignment)]` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> tests/ui/cast_alignment.rs:23:5 + --> tests/ui/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) - --> tests/ui/cast_alignment.rs:28:5 + --> tests/ui/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) - --> tests/ui/cast_alignment.rs:31:5 + --> tests/ui/cast_alignment.rs:29: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 9de5b4095556..eecf56f71a33 100644 --- a/tests/ui/cast_enum_constructor.rs +++ b/tests/ui/cast_enum_constructor.rs @@ -13,7 +13,6 @@ fn main() { let _ = Foo::Y as usize; //~^ cast_enum_constructor - let _ = Foo::Y as isize; //~^ cast_enum_constructor diff --git a/tests/ui/cast_enum_constructor.stderr b/tests/ui/cast_enum_constructor.stderr index 890d88cacdf2..67cca6807315 100644 --- a/tests/ui/cast_enum_constructor.stderr +++ b/tests/ui/cast_enum_constructor.stderr @@ -8,7 +8,7 @@ LL | let _ = Foo::Y as usize; = help: to override `-D warnings` add `#[allow(clippy::cast_enum_constructor)]` error: cast of an enum tuple constructor to an integer - --> tests/ui/cast_enum_constructor.rs:17:13 + --> tests/ui/cast_enum_constructor.rs:16:13 | LL | let _ = Foo::Y as isize; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed index cd689801702a..2af2dbd1282d 100644 --- a/tests/ui/cast_lossless_integer.fixed +++ b/tests/ui/cast_lossless_integer.fixed @@ -29,7 +29,6 @@ fn main() { i128::from(0u8); //~^ cast_lossless - u32::from(0u16); //~^ cast_lossless @@ -48,7 +47,6 @@ fn main() { i128::from(0u16); //~^ cast_lossless - u64::from(0u32); //~^ cast_lossless @@ -61,14 +59,12 @@ fn main() { i128::from(0u32); //~^ cast_lossless - u128::from(0u64); //~^ cast_lossless i128::from(0u64); //~^ cast_lossless - i16::from(0i8); //~^ cast_lossless @@ -81,7 +77,6 @@ fn main() { i128::from(0i8); //~^ cast_lossless - i32::from(0i16); //~^ cast_lossless @@ -91,27 +86,22 @@ fn main() { i128::from(0i16); //~^ cast_lossless - i64::from(0i32); //~^ cast_lossless i128::from(0i32); //~^ cast_lossless - i128::from(0i64); //~^ cast_lossless - // Test with an expression wrapped in parens let _ = u16::from(1u8 + 1u8); //~^ cast_lossless - let _ = I64Alias::from(1i8); //~^ cast_lossless - let _: u16 = 0u8.into(); //~^ cast_lossless @@ -123,7 +113,6 @@ fn main() { let _: u32 = (1i8 as u16).into(); //~^ cast_lossless - } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -162,7 +151,6 @@ fn issue11458() { let _ = i32::from(sign_cast!(x, u8, i8) + 1); //~^ cast_lossless - } fn issue12695() { @@ -170,7 +158,6 @@ fn issue12695() { () => { u32::from(1u8) //~^ cast_lossless - }; } diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index 03c1a77c34ad..c65b725bb729 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -29,7 +29,6 @@ fn main() { 0u8 as i128; //~^ cast_lossless - 0u16 as u32; //~^ cast_lossless @@ -48,7 +47,6 @@ fn main() { 0u16 as i128; //~^ cast_lossless - 0u32 as u64; //~^ cast_lossless @@ -61,14 +59,12 @@ fn main() { 0u32 as i128; //~^ cast_lossless - 0u64 as u128; //~^ cast_lossless 0u64 as i128; //~^ cast_lossless - 0i8 as i16; //~^ cast_lossless @@ -81,7 +77,6 @@ fn main() { 0i8 as i128; //~^ cast_lossless - 0i16 as i32; //~^ cast_lossless @@ -91,27 +86,22 @@ fn main() { 0i16 as i128; //~^ cast_lossless - 0i32 as i64; //~^ cast_lossless 0i32 as i128; //~^ cast_lossless - 0i64 as i128; //~^ cast_lossless - // Test with an expression wrapped in parens let _ = (1u8 + 1u8) as u16; //~^ cast_lossless - let _ = 1i8 as I64Alias; //~^ cast_lossless - let _: u16 = 0u8 as _; //~^ cast_lossless @@ -123,7 +113,6 @@ fn main() { let _: u32 = 1i8 as u16 as _; //~^ cast_lossless - } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, @@ -162,7 +151,6 @@ fn issue11458() { let _ = (sign_cast!(x, u8, i8) + 1) as i32; //~^ cast_lossless - } fn issue12695() { @@ -170,7 +158,6 @@ fn issue12695() { () => { 1u8 as u32 //~^ cast_lossless - }; } diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index 3bec773ff861..393c20f68294 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -97,7 +97,7 @@ LL | i128::from(0u8); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:33:5 + --> tests/ui/cast_lossless_integer.rs:32:5 | LL | 0u16 as u32; | ^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | u32::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:36:5 + --> tests/ui/cast_lossless_integer.rs:35:5 | LL | 0u16 as i32; | ^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | i32::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:39:5 + --> tests/ui/cast_lossless_integer.rs:38:5 | LL | 0u16 as u64; | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | u64::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:42:5 + --> tests/ui/cast_lossless_integer.rs:41:5 | LL | 0u16 as i64; | ^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | i64::from(0u16); | ~~~~~~~~~~~~~~~ error: casts from `u16` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:45:5 + --> tests/ui/cast_lossless_integer.rs:44:5 | LL | 0u16 as u128; | ^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | u128::from(0u16); | ~~~~~~~~~~~~~~~~ error: casts from `u16` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:48:5 + --> tests/ui/cast_lossless_integer.rs:47:5 | LL | 0u16 as i128; | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL | i128::from(0u16); | ~~~~~~~~~~~~~~~~ error: casts from `u32` to `u64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:52:5 + --> tests/ui/cast_lossless_integer.rs:50:5 | LL | 0u32 as u64; | ^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL | u64::from(0u32); | ~~~~~~~~~~~~~~~ error: casts from `u32` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:55:5 + --> tests/ui/cast_lossless_integer.rs:53:5 | LL | 0u32 as i64; | ^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | i64::from(0u32); | ~~~~~~~~~~~~~~~ error: casts from `u32` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:58:5 + --> tests/ui/cast_lossless_integer.rs:56:5 | LL | 0u32 as u128; | ^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL | u128::from(0u32); | ~~~~~~~~~~~~~~~~ error: casts from `u32` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:61:5 + --> tests/ui/cast_lossless_integer.rs:59:5 | LL | 0u32 as i128; | ^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | i128::from(0u32); | ~~~~~~~~~~~~~~~~ error: casts from `u64` to `u128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:65:5 + --> tests/ui/cast_lossless_integer.rs:62:5 | LL | 0u64 as u128; | ^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL | u128::from(0u64); | ~~~~~~~~~~~~~~~~ error: casts from `u64` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:68:5 + --> tests/ui/cast_lossless_integer.rs:65:5 | LL | 0u64 as i128; | ^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL | i128::from(0u64); | ~~~~~~~~~~~~~~~~ error: casts from `i8` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:72:5 + --> tests/ui/cast_lossless_integer.rs:68:5 | LL | 0i8 as i16; | ^^^^^^^^^^ @@ -253,7 +253,7 @@ LL | i16::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:75:5 + --> tests/ui/cast_lossless_integer.rs:71:5 | LL | 0i8 as i32; | ^^^^^^^^^^ @@ -265,7 +265,7 @@ LL | i32::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:78:5 + --> tests/ui/cast_lossless_integer.rs:74:5 | LL | 0i8 as i64; | ^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | i64::from(0i8); | ~~~~~~~~~~~~~~ error: casts from `i8` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:81:5 + --> tests/ui/cast_lossless_integer.rs:77:5 | LL | 0i8 as i128; | ^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL | i128::from(0i8); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:85:5 + --> tests/ui/cast_lossless_integer.rs:80:5 | LL | 0i16 as i32; | ^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL | i32::from(0i16); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:88:5 + --> tests/ui/cast_lossless_integer.rs:83:5 | LL | 0i16 as i64; | ^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL | i64::from(0i16); | ~~~~~~~~~~~~~~~ error: casts from `i16` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:91:5 + --> tests/ui/cast_lossless_integer.rs:86:5 | LL | 0i16 as i128; | ^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL | i128::from(0i16); | ~~~~~~~~~~~~~~~~ error: casts from `i32` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:95:5 + --> tests/ui/cast_lossless_integer.rs:89:5 | LL | 0i32 as i64; | ^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL | i64::from(0i32); | ~~~~~~~~~~~~~~~ error: casts from `i32` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:98:5 + --> tests/ui/cast_lossless_integer.rs:92:5 | LL | 0i32 as i128; | ^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL | i128::from(0i32); | ~~~~~~~~~~~~~~~~ error: casts from `i64` to `i128` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:102:5 + --> tests/ui/cast_lossless_integer.rs:95:5 | LL | 0i64 as i128; | ^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL | i128::from(0i64); | ~~~~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:107:13 + --> tests/ui/cast_lossless_integer.rs:99:13 | LL | let _ = (1u8 + 1u8) as u16; | ^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL | let _ = u16::from(1u8 + 1u8); | ~~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i64` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:111:13 + --> tests/ui/cast_lossless_integer.rs:102:13 | LL | let _ = 1i8 as I64Alias; | ^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL | let _ = I64Alias::from(1i8); | ~~~~~~~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:115:18 + --> tests/ui/cast_lossless_integer.rs:105:18 | LL | let _: u16 = 0u8 as _; | ^^^^^^^^ @@ -397,7 +397,7 @@ LL | let _: u16 = 0u8.into(); | ~~~~~~~~~~ error: casts from `i8` to `i16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:118:18 + --> tests/ui/cast_lossless_integer.rs:108:18 | LL | let _: i16 = -1i8 as _; | ^^^^^^^^^ @@ -409,7 +409,7 @@ LL | let _: i16 = (-1i8).into(); | ~~~~~~~~~~~~~ error: casts from `u8` to `u16` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:121:18 + --> tests/ui/cast_lossless_integer.rs:111:18 | LL | let _: u16 = (1u8 + 2) as _; | ^^^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL | let _: u16 = (1u8 + 2).into(); | ~~~~~~~~~~~~~~~~ error: casts from `u16` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:124:18 + --> tests/ui/cast_lossless_integer.rs:114:18 | LL | let _: u32 = 1i8 as u16 as _; | ^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ LL | let _: u32 = (1i8 as u16).into(); | ~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:160:13 + --> tests/ui/cast_lossless_integer.rs:149:13 | LL | let _ = sign_cast!(x, u8, i8) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -445,7 +445,7 @@ LL | let _ = i32::from(sign_cast!(x, u8, i8)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casts from `i8` to `i32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:163:13 + --> tests/ui/cast_lossless_integer.rs:152:13 | LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -457,7 +457,7 @@ LL | let _ = i32::from(sign_cast!(x, u8, i8) + 1); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casts from `u8` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:171:13 + --> tests/ui/cast_lossless_integer.rs:159:13 | LL | 1u8 as u32 | ^^^^^^^^^^ @@ -473,7 +473,7 @@ LL | u32::from(1u8) | error: casts from `u8` to `u32` can be expressed infallibly using `From` - --> tests/ui/cast_lossless_integer.rs:187:13 + --> tests/ui/cast_lossless_integer.rs:174:13 | LL | let _ = 0u8 as ty!(); | ^^^^^^^^^^^^ diff --git a/tests/ui/cast_nan_to_int.rs b/tests/ui/cast_nan_to_int.rs index 227dae3b1c4b..72e61b3542e2 100644 --- a/tests/ui/cast_nan_to_int.rs +++ b/tests/ui/cast_nan_to_int.rs @@ -7,29 +7,21 @@ fn main() { let _ = (0.0_f32 / -0.0) as usize; //~^ cast_nan_to_int - let _ = (f64::INFINITY * -0.0) as usize; //~^ cast_nan_to_int - let _ = (0.0 * f32::INFINITY) as usize; //~^ cast_nan_to_int - - let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; //~^ cast_nan_to_int - let _ = (f32::INFINITY - f32::INFINITY) as usize; //~^ cast_nan_to_int - let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; //~^ cast_nan_to_int - - // those won't be linted: let _ = (1.0_f32 / 0.0) as usize; let _ = (f32::INFINITY * f32::NEG_INFINITY) as usize; diff --git a/tests/ui/cast_nan_to_int.stderr b/tests/ui/cast_nan_to_int.stderr index 0f9b3565485f..15ca3876ea18 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -9,7 +9,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; = help: to override `-D warnings` add `#[allow(clippy::cast_nan_to_int)]` error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:11:13 + --> tests/ui/cast_nan_to_int.rs:10:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:15:13 + --> tests/ui/cast_nan_to_int.rs:13:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:20:13 + --> tests/ui/cast_nan_to_int.rs:16:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:24:13 + --> tests/ui/cast_nan_to_int.rs:19:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> tests/ui/cast_nan_to_int.rs:28:13 + --> tests/ui/cast_nan_to_int.rs:22:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_slice_different_sizes.rs b/tests/ui/cast_slice_different_sizes.rs index 2db14d4f2515..518ed77ab220 100644 --- a/tests/ui/cast_slice_different_sizes.rs +++ b/tests/ui/cast_slice_different_sizes.rs @@ -10,16 +10,13 @@ fn main() { let b = a as *const [u8]; //~^ cast_slice_different_sizes - let c = b as *const [u32]; //~^ cast_slice_different_sizes - // loses data let loss = r_x as *const [i32] as *const [u8]; //~^ cast_slice_different_sizes - // 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 let restore = r_x as *const [i32] as *const [u8] as *const [u32]; @@ -29,7 +26,7 @@ fn main() { //~^ cast_slice_different_sizes let loss_block_2 = { - //~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes let _ = (); r_x as *const [i32] @@ -65,48 +62,47 @@ fn foo2(x: *mut [u8]) -> *mut [u8] { // Test that casts as part of function returns work fn bar(x: *mut [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes x as *mut [u8] } fn uwu(x: *mut [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes x as *mut _ } fn bar2(x: *mut [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes x as _ } // constify fn bar3(x: *mut [u16]) -> *const [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes x as _ } // unconstify fn bar4(x: *const [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes x as _ } // function returns plus blocks fn blocks(x: *mut [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes ({ x }) as _ } fn more_blocks(x: *mut [u16]) -> *mut [u8] { -//~^ cast_slice_different_sizes + //~^ cast_slice_different_sizes { ({ x }) as _ } //~^ cast_slice_different_sizes - } diff --git a/tests/ui/cast_slice_different_sizes.stderr b/tests/ui/cast_slice_different_sizes.stderr index e028e13db616..307d37ac2ea8 100644 --- a/tests/ui/cast_slice_different_sizes.stderr +++ b/tests/ui/cast_slice_different_sizes.stderr @@ -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 - --> tests/ui/cast_slice_different_sizes.rs:14:13 + --> tests/ui/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 - --> tests/ui/cast_slice_different_sizes.rs:19:16 + --> tests/ui/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 - --> tests/ui/cast_slice_different_sizes.rs:28:24 + --> tests/ui/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 - --> tests/ui/cast_slice_different_sizes.rs:31:24 + --> tests/ui/cast_slice_different_sizes.rs:28:24 | LL | let loss_block_2 = { | ________________________^ @@ -47,13 +47,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 - --> tests/ui/cast_slice_different_sizes.rs:50:27 + --> tests/ui/cast_slice_different_sizes.rs:47: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 - --> tests/ui/cast_slice_different_sizes.rs:67:36 + --> tests/ui/cast_slice_different_sizes.rs:64:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ @@ -64,7 +64,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 - --> tests/ui/cast_slice_different_sizes.rs:73:36 + --> tests/ui/cast_slice_different_sizes.rs:70:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ @@ -75,7 +75,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 - --> tests/ui/cast_slice_different_sizes.rs:79:37 + --> tests/ui/cast_slice_different_sizes.rs:76:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ @@ -86,7 +86,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 - --> tests/ui/cast_slice_different_sizes.rs:86:39 + --> tests/ui/cast_slice_different_sizes.rs:83:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ @@ -97,7 +97,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 - --> tests/ui/cast_slice_different_sizes.rs:93:39 + --> tests/ui/cast_slice_different_sizes.rs:90:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ @@ -108,7 +108,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 - --> tests/ui/cast_slice_different_sizes.rs:100:39 + --> tests/ui/cast_slice_different_sizes.rs:97:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ @@ -119,19 +119,19 @@ 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 - --> tests/ui/cast_slice_different_sizes.rs:106:44 + --> tests/ui/cast_slice_different_sizes.rs:103:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ LL | | 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 - --> tests/ui/cast_slice_different_sizes.rs:109:5 + --> tests/ui/cast_slice_different_sizes.rs:106: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/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index 41e3c5e545cb..c8774c7f3091 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -4,6 +4,4 @@ fn main() { // no suggestion, since a byte literal won't work. let _ = '❤' as u8; //~^ char_lit_as_u8 - - } diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 3eedb659ebf6..7d0bcc547a42 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -24,7 +24,6 @@ fn test_complex_conditions() { // unnecessary y.unwrap_err(); //~^ unnecessary_unwrap - } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -53,7 +52,6 @@ fn test_complex_conditions() { // unnecessary y.unwrap_err(); //~^ unnecessary_unwrap - } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { @@ -80,7 +78,6 @@ fn test_complex_conditions() { // will panic z.unwrap_err(); //~^ panicking_unwrap - } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -111,7 +108,6 @@ fn test_complex_conditions() { // unnecessary z.unwrap_err(); //~^ unnecessary_unwrap - } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index 02118affe731..d3905850c970 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -50,7 +50,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/complex_conditionals.rs:42:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:41: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:46:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:45: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:50:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:49: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:54:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:53: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:61:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:59: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:65:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:63: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:69:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:67: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:73:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:71: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:77:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:75: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:81:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:79: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:92:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:89: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:96:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:93: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:100:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:97: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:104:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:101: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 - --> tests/ui/checked_unwrap/complex_conditionals.rs:108:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:105: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` - --> tests/ui/checked_unwrap/complex_conditionals.rs:112:9 + --> tests/ui/checked_unwrap/complex_conditionals.rs:109:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 7736643d894c..4101897d3800 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -50,7 +50,6 @@ fn main() { // unnecessary x.expect("an error message"); //~^ unnecessary_unwrap - } else { // will panic x.unwrap(); @@ -59,18 +58,15 @@ fn main() { // will panic x.expect("an error message"); //~^ panicking_unwrap - } if x.is_none() { // will panic x.unwrap(); //~^ panicking_unwrap - } else { // unnecessary x.unwrap(); //~^ unnecessary_unwrap - } m!(x); // ok @@ -92,7 +88,6 @@ fn main() { // will panic x.unwrap_err(); //~^ panicking_unwrap - } else { // will panic x.unwrap(); @@ -105,7 +100,6 @@ fn main() { // unnecessary x.unwrap_err(); //~^ unnecessary_unwrap - } if x.is_err() { // will panic @@ -115,7 +109,6 @@ fn main() { // unnecessary x.unwrap_err(); //~^ unnecessary_unwrap - } else { // unnecessary x.unwrap(); @@ -124,7 +117,6 @@ fn main() { // will panic x.unwrap_err(); //~^ panicking_unwrap - } if x.is_ok() { x = Err(()); @@ -150,11 +142,9 @@ fn issue11371() { if option.is_some() { option.as_ref().unwrap(); //~^ unnecessary_unwrap - } else { option.as_ref().unwrap(); //~^ panicking_unwrap - } let result = Ok::<(), ()>(()); @@ -162,33 +152,27 @@ fn issue11371() { if result.is_ok() { result.as_ref().unwrap(); //~^ unnecessary_unwrap - } else { result.as_ref().unwrap(); //~^ panicking_unwrap - } let mut option = Some(()); if option.is_some() { option.as_mut().unwrap(); //~^ unnecessary_unwrap - } else { option.as_mut().unwrap(); //~^ panicking_unwrap - } let mut result = Ok::<(), ()>(()); if result.is_ok() { result.as_mut().unwrap(); //~^ unnecessary_unwrap - } else { result.as_mut().unwrap(); //~^ panicking_unwrap - } // This should not lint. Statics are, at the time of writing, not linted on anyway, @@ -197,7 +181,7 @@ fn issue11371() { static mut X: Option = Some(123); unsafe { if X.is_some() { - //~^ ERROR: creating a shared reference + //~^ ERROR: creating a shared reference X = None; X.unwrap(); } diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 789a4a8f92bc..c17eaef2326b 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -23,7 +23,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:56:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:55: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:60:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:59: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:66:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:64: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:71:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:68: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:85:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:81: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:89:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:85: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:93:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:89: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:98:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:93: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:102:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:97: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:106:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:101: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:112:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:106: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:116:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:110: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` - --> tests/ui/checked_unwrap/simple_conditionals.rs:121:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:114: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 - --> tests/ui/checked_unwrap/simple_conditionals.rs:125:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:118:9 | LL | if x.is_err() { | ---------- because of this check @@ -169,7 +169,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:151:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:143:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &option` @@ -177,7 +177,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:155:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:146:9 | LL | if option.is_some() { | ---------------- because of this check @@ -186,7 +186,7 @@ LL | option.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:163:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &result` @@ -194,7 +194,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:167:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9 | LL | if result.is_ok() { | -------------- because of this check @@ -203,7 +203,7 @@ LL | result.as_ref().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `option` after checking its variant with `is_some` - --> tests/ui/checked_unwrap/simple_conditionals.rs:174:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:162:9 | LL | if option.is_some() { | ------------------- help: try: `if let Some() = &mut option` @@ -211,7 +211,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:178:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:165:9 | LL | if option.is_some() { | ---------------- because of this check @@ -220,7 +220,7 @@ LL | option.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap` on `result` after checking its variant with `is_ok` - --> tests/ui/checked_unwrap/simple_conditionals.rs:185:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:171:9 | LL | if result.is_ok() { | ----------------- help: try: `if let Ok() = &mut result` @@ -228,7 +228,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> tests/ui/checked_unwrap/simple_conditionals.rs:189:9 + --> tests/ui/checked_unwrap/simple_conditionals.rs:174:9 | LL | if result.is_ok() { | -------------- because of this check @@ -237,7 +237,7 @@ LL | result.as_mut().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: creating a shared reference to mutable static is discouraged - --> tests/ui/checked_unwrap/simple_conditionals.rs:199:12 + --> tests/ui/checked_unwrap/simple_conditionals.rs:183:12 | LL | if X.is_some() { | ^^^^^^^^^^^ shared reference to mutable static diff --git a/tests/ui/cmp_null.fixed b/tests/ui/cmp_null.fixed index 27b831950dc7..140ddb10aeb8 100644 --- a/tests/ui/cmp_null.fixed +++ b/tests/ui/cmp_null.fixed @@ -7,13 +7,12 @@ fn main() { let x = 0; let p: *const usize = &x; if p.is_null() { - //~^ cmp_null - + //~^ cmp_null println!("This is surprising!"); } if p.is_null() { - //~^ cmp_null + //~^ cmp_null println!("This is surprising!"); } @@ -21,17 +20,16 @@ fn main() { let mut y = 0; let mut m: *mut usize = &mut y; if m.is_null() { - //~^ cmp_null + //~^ cmp_null println!("This is surprising, too!"); } if m.is_null() { - //~^ cmp_null + //~^ cmp_null println!("This is surprising, too!"); } let _ = (x as *const ()).is_null(); //~^ cmp_null - } diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index ac1bf83e094c..16ed17765dac 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -7,13 +7,12 @@ fn main() { let x = 0; let p: *const usize = &x; if p == ptr::null() { - //~^ cmp_null - + //~^ cmp_null println!("This is surprising!"); } if ptr::null() == p { - //~^ cmp_null + //~^ cmp_null println!("This is surprising!"); } @@ -21,17 +20,16 @@ fn main() { let mut y = 0; let mut m: *mut usize = &mut y; if m == ptr::null_mut() { - //~^ cmp_null + //~^ cmp_null println!("This is surprising, too!"); } if ptr::null_mut() == m { - //~^ cmp_null + //~^ cmp_null println!("This is surprising, too!"); } let _ = x as *const () == ptr::null(); //~^ cmp_null - } diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index a44dd8067613..6821846d0466 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -8,25 +8,25 @@ LL | if p == ptr::null() { = help: to override `-D warnings` add `#[allow(clippy::cmp_null)]` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:15:8 + --> tests/ui/cmp_null.rs:14:8 | LL | if ptr::null() == p { | ^^^^^^^^^^^^^^^^ help: try: `p.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:23:8 + --> tests/ui/cmp_null.rs:22:8 | LL | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:28:8 + --> tests/ui/cmp_null.rs:27:8 | LL | if ptr::null_mut() == m { | ^^^^^^^^^^^^^^^^^^^^ help: try: `m.is_null()` error: comparing with null is better expressed by the `.is_null()` method - --> tests/ui/cmp_null.rs:34:13 + --> tests/ui/cmp_null.rs:33:13 | LL | let _ = x as *const () == ptr::null(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(x as *const ()).is_null()` diff --git a/tests/ui/cmp_owned/comparison_flip.fixed b/tests/ui/cmp_owned/comparison_flip.fixed index a926857c78a1..711fbca1c8d2 100644 --- a/tests/ui/cmp_owned/comparison_flip.fixed +++ b/tests/ui/cmp_owned/comparison_flip.fixed @@ -4,12 +4,12 @@ fn main() { let a = Foo; if a != "bar" { - //~^ cmp_owned + //~^ cmp_owned println!("foo"); } if a != "bar" { - //~^ cmp_owned + //~^ cmp_owned println!("foo"); } } diff --git a/tests/ui/cmp_owned/comparison_flip.rs b/tests/ui/cmp_owned/comparison_flip.rs index 169d472203c5..ce86bb3f7b5c 100644 --- a/tests/ui/cmp_owned/comparison_flip.rs +++ b/tests/ui/cmp_owned/comparison_flip.rs @@ -4,12 +4,12 @@ fn main() { let a = Foo; if a.to_string() != "bar" { - //~^ cmp_owned + //~^ cmp_owned println!("foo"); } if "bar" != a.to_string() { - //~^ cmp_owned + //~^ cmp_owned println!("foo"); } } diff --git a/tests/ui/cmp_owned/without_suggestion.rs b/tests/ui/cmp_owned/without_suggestion.rs index 71bcac44ed7c..4e14c3054d9f 100644 --- a/tests/ui/cmp_owned/without_suggestion.rs +++ b/tests/ui/cmp_owned/without_suggestion.rs @@ -7,14 +7,11 @@ fn main() { y.to_owned() == *x; //~^ cmp_owned - - let x = &&Baz; let y = &Baz; y.to_owned() == **x; //~^ cmp_owned - let x = 0u32; let y = U32Wrapper(x); let _ = U32Wrapper::from(x) == y; @@ -26,7 +23,6 @@ impl PartialEq for Foo { fn eq(&self, other: &Self) -> bool { self.to_owned() == *other //~^ cmp_owned - } } diff --git a/tests/ui/cmp_owned/without_suggestion.stderr b/tests/ui/cmp_owned/without_suggestion.stderr index 6efaf9688e20..c8e2efab4915 100644 --- a/tests/ui/cmp_owned/without_suggestion.stderr +++ b/tests/ui/cmp_owned/without_suggestion.stderr @@ -8,13 +8,13 @@ LL | y.to_owned() == *x; = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/without_suggestion.rs:14:5 + --> tests/ui/cmp_owned/without_suggestion.rs:12:5 | LL | y.to_owned() == **x; | ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating error: this creates an owned instance just for comparison - --> tests/ui/cmp_owned/without_suggestion.rs:27:9 + --> tests/ui/cmp_owned/without_suggestion.rs:24: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 d750202d00ec..2dbec955f63f 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -91,7 +91,7 @@ fn main() { #[clippy::cognitive_complexity = "1"] fn kaboom() { -//~^ cognitive_complexity + //~^ cognitive_complexity let n = 0; 'a: for i in 0..20 { @@ -151,11 +151,10 @@ fn lots_of_short_circuits2() -> bool { #[clippy::cognitive_complexity = "1"] fn baa() { -//~^ cognitive_complexity - - let x = || match 99 { //~^ cognitive_complexity + let x = || match 99 { + //~^ cognitive_complexity 0 => 0, 1 => 1, 2 => 2, @@ -173,7 +172,7 @@ fn baa() { #[clippy::cognitive_complexity = "1"] fn bar() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -186,7 +185,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() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -196,7 +195,7 @@ fn dont_warn_on_tests() { #[clippy::cognitive_complexity = "1"] fn barr() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -208,7 +207,7 @@ fn barr() { #[clippy::cognitive_complexity = "1"] fn barr2() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -226,7 +225,7 @@ fn barr2() { #[clippy::cognitive_complexity = "1"] fn barrr() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -238,7 +237,7 @@ fn barrr() { #[clippy::cognitive_complexity = "1"] fn barrr2() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -256,7 +255,7 @@ fn barrr2() { #[clippy::cognitive_complexity = "1"] fn barrrr() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -268,7 +267,7 @@ fn barrrr() { #[clippy::cognitive_complexity = "1"] fn barrrr2() { -//~^ cognitive_complexity + //~^ cognitive_complexity match 99 { 0 => println!("hi"), @@ -286,7 +285,7 @@ fn barrrr2() { #[clippy::cognitive_complexity = "1"] fn cake() { -//~^ cognitive_complexity + //~^ cognitive_complexity if 4 == 5 { println!("yea"); @@ -298,7 +297,7 @@ fn cake() { #[clippy::cognitive_complexity = "1"] pub fn read_file(input_path: &str) -> String { -//~^ cognitive_complexity + //~^ cognitive_complexity use std::fs::File; use std::io::{Read, Write}; @@ -331,7 +330,7 @@ enum Void {} #[clippy::cognitive_complexity = "1"] fn void(void: Void) { -//~^ cognitive_complexity + //~^ cognitive_complexity if true { match void {} @@ -407,7 +406,7 @@ fn early_ret() -> i32 { #[clippy::cognitive_complexity = "1"] fn closures() { let x = |a: i32, b: i32| -> i32 { - //~^ cognitive_complexity + //~^ cognitive_complexity if true { println!("moo"); @@ -422,7 +421,7 @@ struct Moo; #[clippy::cognitive_complexity = "1"] impl Moo { fn moo(&self) { - //~^ cognitive_complexity + //~^ cognitive_complexity if true { println!("moo"); @@ -433,7 +432,7 @@ impl Moo { #[clippy::cognitive_complexity = "1"] mod issue9300 { async fn a() { - //~^ cognitive_complexity + //~^ cognitive_complexity let a = 0; if a == 0 {} @@ -442,7 +441,7 @@ mod issue9300 { pub struct S; impl S { pub async fn async_method() { - //~^ cognitive_complexity + //~^ cognitive_complexity let a = 0; if a == 0 {} diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index 60a834765a6b..52607b87c60e 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -33,7 +33,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) - --> tests/ui/cognitive_complexity.rs:175:4 + --> tests/ui/cognitive_complexity.rs:174:4 | LL | fn bar() { | ^^^ @@ -41,7 +41,7 @@ LL | fn bar() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:188:4 + --> tests/ui/cognitive_complexity.rs:187:4 | LL | fn dont_warn_on_tests() { | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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) - --> tests/ui/cognitive_complexity.rs:198:4 + --> tests/ui/cognitive_complexity.rs:197:4 | LL | fn barr() { | ^^^^ @@ -57,7 +57,7 @@ LL | fn barr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:210:4 + --> tests/ui/cognitive_complexity.rs:209:4 | LL | fn barr2() { | ^^^^^ @@ -65,7 +65,7 @@ LL | fn barr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:228:4 + --> tests/ui/cognitive_complexity.rs:227:4 | LL | fn barrr() { | ^^^^^ @@ -73,7 +73,7 @@ LL | fn barrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:240:4 + --> tests/ui/cognitive_complexity.rs:239:4 | LL | fn barrr2() { | ^^^^^^ @@ -81,7 +81,7 @@ LL | fn barrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:258:4 + --> tests/ui/cognitive_complexity.rs:257:4 | LL | fn barrrr() { | ^^^^^^ @@ -89,7 +89,7 @@ LL | fn barrrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> tests/ui/cognitive_complexity.rs:270:4 + --> tests/ui/cognitive_complexity.rs:269:4 | LL | fn barrrr2() { | ^^^^^^^ @@ -97,7 +97,7 @@ LL | fn barrrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> tests/ui/cognitive_complexity.rs:288:4 + --> tests/ui/cognitive_complexity.rs:287:4 | LL | fn cake() { | ^^^^ @@ -105,7 +105,7 @@ LL | fn cake() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (4/1) - --> tests/ui/cognitive_complexity.rs:300:8 + --> tests/ui/cognitive_complexity.rs:299:8 | LL | pub fn read_file(input_path: &str) -> String { | ^^^^^^^^^ @@ -113,7 +113,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) - --> tests/ui/cognitive_complexity.rs:333:4 + --> tests/ui/cognitive_complexity.rs:332:4 | LL | fn void(void: Void) { | ^^^^ @@ -121,7 +121,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) - --> tests/ui/cognitive_complexity.rs:386:4 + --> tests/ui/cognitive_complexity.rs:385:4 | LL | fn early_ret() -> i32 { | ^^^^^^^^^ @@ -129,7 +129,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) - --> tests/ui/cognitive_complexity.rs:409:13 + --> tests/ui/cognitive_complexity.rs:408:13 | LL | let x = |a: i32, b: i32| -> i32 { | ^^^^^^^^^^^^^^^^ @@ -137,7 +137,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) - --> tests/ui/cognitive_complexity.rs:424:8 + --> tests/ui/cognitive_complexity.rs:423:8 | LL | fn moo(&self) { | ^^^ @@ -145,7 +145,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) - --> tests/ui/cognitive_complexity.rs:435:14 + --> tests/ui/cognitive_complexity.rs:434:14 | LL | async fn a() { | ^ @@ -153,7 +153,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) - --> tests/ui/cognitive_complexity.rs:444:22 + --> tests/ui/cognitive_complexity.rs:443: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 ed62dd7b933e..a260fdee3cfd 100644 --- a/tests/ui/cognitive_complexity_attr_used.rs +++ b/tests/ui/cognitive_complexity_attr_used.rs @@ -7,7 +7,7 @@ fn main() { #[clippy::cognitive_complexity = "0"] fn kaboom() { -//~^ cognitive_complexity + //~^ cognitive_complexity if 42 == 43 { panic!(); diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs index 14e3ab95dbd1..796cabd4b669 100644 --- a/tests/ui/collapsible_match.rs +++ b/tests/ui/collapsible_match.rs @@ -12,8 +12,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match without block match res_opt { Ok(val) => match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, }, @@ -23,8 +22,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match with block match res_opt { Ok(val) => match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, }, @@ -34,7 +32,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 { - //~^ collapsible_match + //~^ collapsible_match take(n); } @@ -43,7 +41,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 { - //~^ collapsible_match + //~^ collapsible_match take(n); } else { @@ -56,8 +54,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, match if let Ok(val) = res_opt { match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => (), } @@ -67,7 +64,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { - //~^ collapsible_match + //~^ collapsible_match take(n); } @@ -78,8 +75,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, match if let Ok(val) = res_opt { match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, } @@ -91,7 +87,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { - //~^ collapsible_match + //~^ collapsible_match take(n); } else { @@ -104,8 +100,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 { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), None => return, }, @@ -115,8 +110,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 { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, }, @@ -260,7 +254,7 @@ fn negative_cases(res_opt: Result, String>, res_res: Result>>() { Some(val) => match val { - //~^ collapsible_match + //~^ collapsible_match E::A(val) | E::B(val) => foo(val), _ => return, }, @@ -292,7 +286,7 @@ pub enum Issue9647 { pub fn test_1(x: Issue9647) { if let Issue9647::A { a, .. } = x { if let Some(u) = a { - //~^ collapsible_match + //~^ collapsible_match println!("{u:?}") } @@ -302,7 +296,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 { - //~^ collapsible_match + //~^ collapsible_match println!("{u}") } diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 471e58f27770..5294a9d6975d 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -4,7 +4,6 @@ error: this `match` can be collapsed into the outer `match` LL | Ok(val) => match val { | ____________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -15,35 +14,34 @@ 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` = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:25:20 + --> tests/ui/collapsible_match.rs:24:20 | LL | Ok(val) => match val { | ____________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:25:12 + --> tests/ui/collapsible_match.rs:24: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` - --> tests/ui/collapsible_match.rs:36:9 + --> tests/ui/collapsible_match.rs:34:9 | LL | / if let Some(n) = val { LL | | @@ -53,7 +51,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:35:15 + --> tests/ui/collapsible_match.rs:33:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -61,7 +59,7 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:45:9 + --> tests/ui/collapsible_match.rs:43:9 | LL | / if let Some(n) = val { LL | | @@ -73,7 +71,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:44:15 + --> tests/ui/collapsible_match.rs:42:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -81,18 +79,17 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:58:9 + --> tests/ui/collapsible_match.rs:56:9 | LL | / match val { LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => (), LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:57:15 + --> tests/ui/collapsible_match.rs:55:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -101,7 +98,7 @@ LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:69:13 + --> tests/ui/collapsible_match.rs:66:13 | LL | / if let Some(n) = val { LL | | @@ -111,7 +108,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:68:12 + --> tests/ui/collapsible_match.rs:65:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -119,18 +116,17 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:80:9 + --> tests/ui/collapsible_match.rs:77:9 | LL | / match val { LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:79:15 + --> tests/ui/collapsible_match.rs:76:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -139,7 +135,7 @@ LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:93:13 + --> tests/ui/collapsible_match.rs:89:13 | LL | / if let Some(n) = val { LL | | @@ -151,7 +147,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:92:12 + --> tests/ui/collapsible_match.rs:88:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -159,49 +155,47 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match.rs:106:20 + --> tests/ui/collapsible_match.rs:102:20 | LL | Ok(val) => match val { | ____________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | None => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:106:12 + --> tests/ui/collapsible_match.rs:102: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` - --> tests/ui/collapsible_match.rs:117:22 + --> tests/ui/collapsible_match.rs:112:22 | LL | Some(val) => match val { | ______________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:117:14 + --> tests/ui/collapsible_match.rs:112:14 | LL | Some(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` - --> tests/ui/collapsible_match.rs:262:22 + --> tests/ui/collapsible_match.rs:256:22 | LL | Some(val) => match val { | ______________________^ @@ -212,7 +206,7 @@ LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:262:14 + --> tests/ui/collapsible_match.rs:256:14 | LL | Some(val) => match val { | ^^^ replace this binding @@ -221,7 +215,7 @@ LL | E::A(val) | E::B(val) => foo(val), | ^^^^^^^^^^^^^^^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:294:9 + --> tests/ui/collapsible_match.rs:288:9 | LL | / if let Some(u) = a { LL | | @@ -231,7 +225,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:293:27 + --> tests/ui/collapsible_match.rs:287:27 | LL | if let Issue9647::A { a, .. } = x { | ^ replace this binding @@ -239,7 +233,7 @@ LL | if let Some(u) = a { | ^^^^^^^ with this pattern, prefixed by `a`: error: this `if let` can be collapsed into the outer `if let` - --> tests/ui/collapsible_match.rs:304:9 + --> tests/ui/collapsible_match.rs:298:9 | LL | / if let Some(u) = a { LL | | @@ -249,7 +243,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match.rs:303:35 + --> tests/ui/collapsible_match.rs:297: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 1831fc3f0e35..ba7f2f2720dc 100644 --- a/tests/ui/collapsible_match2.rs +++ b/tests/ui/collapsible_match2.rs @@ -11,8 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> { match res_opt { Ok(val) if make() => match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, }, @@ -20,8 +19,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> } match res_opt { Ok(val) => match val { - //~^ collapsible_match - + //~^ collapsible_match Some(n) => foo(n), _ => return, }, @@ -36,7 +34,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> ($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => { match $outer { $pat => match $e { - //~^ collapsible_match + //~^ collapsible_match $inner_pat => $then, _ => return, }, @@ -54,8 +52,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // deref reference value match Some(&[1]) { Some(s) => match *s { - //~^ collapsible_match - + //~^ collapsible_match [n] => foo(n), _ => (), }, @@ -65,8 +62,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // ref pattern and deref match Some(&[1]) { Some(ref s) => match s { - //~^ collapsible_match - + //~^ collapsible_match [n] => foo(n), _ => (), }, diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 322c583fda77..7b2730637528 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -4,7 +4,6 @@ error: this `match` can be collapsed into the outer `match` LL | Ok(val) if make() => match val { | __________________________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -15,35 +14,34 @@ 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` = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> tests/ui/collapsible_match2.rs:22:24 + --> tests/ui/collapsible_match2.rs:21:24 | LL | Ok(val) => match val { | ________________________^ LL | | -LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match2.rs:22:16 + --> tests/ui/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` - --> tests/ui/collapsible_match2.rs:38:29 + --> tests/ui/collapsible_match2.rs:36:29 | LL | $pat => match $e { | _____________________________^ @@ -57,7 +55,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 - --> tests/ui/collapsible_match2.rs:51:28 + --> tests/ui/collapsible_match2.rs:49:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -66,44 +64,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` - --> tests/ui/collapsible_match2.rs:56:20 + --> tests/ui/collapsible_match2.rs:54:20 | LL | Some(s) => match *s { | ____________________^ LL | | -LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match2.rs:56:14 + --> tests/ui/collapsible_match2.rs:54: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` - --> tests/ui/collapsible_match2.rs:67:24 + --> tests/ui/collapsible_match2.rs:64:24 | LL | Some(ref s) => match s { | ________________________^ LL | | -LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> tests/ui/collapsible_match2.rs:67:14 + --> tests/ui/collapsible_match2.rs:64: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 406b5f8f9f69..77cc84fef177 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -21,7 +21,6 @@ fn write_without_read() { let mut x = HashMap::new(); //~^ collection_is_never_read - x.insert(1, 2); } diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 674552629f7d..d92b84c4a652 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -8,115 +8,115 @@ LL | let mut x = HashMap::new(); = help: to override `-D warnings` add `#[allow(clippy::collection_is_never_read)]` error: collection is never read - --> tests/ui/collection_is_never_read.rs:63:5 + --> tests/ui/collection_is_never_read.rs:62:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:80:5 + --> tests/ui/collection_is_never_read.rs:79:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:87:5 + --> tests/ui/collection_is_never_read.rs:86:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:97:5 + --> tests/ui/collection_is_never_read.rs:96:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:105:5 + --> tests/ui/collection_is_never_read.rs:104:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:113:5 + --> tests/ui/collection_is_never_read.rs:112:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:122:5 + --> tests/ui/collection_is_never_read.rs:121:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:141:5 + --> tests/ui/collection_is_never_read.rs:140:5 | LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:157:5 + --> tests/ui/collection_is_never_read.rs:156:5 | LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:194:5 + --> tests/ui/collection_is_never_read.rs:193:5 | LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:199:5 + --> tests/ui/collection_is_never_read.rs:198:5 | LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:204:5 + --> tests/ui/collection_is_never_read.rs:203:5 | LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:209:5 + --> tests/ui/collection_is_never_read.rs:208:5 | LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:214:5 + --> tests/ui/collection_is_never_read.rs:213:5 | LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:219:5 + --> tests/ui/collection_is_never_read.rs:218:5 | LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:224:5 + --> tests/ui/collection_is_never_read.rs:223:5 | LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:229:5 + --> tests/ui/collection_is_never_read.rs:228:5 | LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:234:5 + --> tests/ui/collection_is_never_read.rs:233:5 | LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> tests/ui/collection_is_never_read.rs:240:5 + --> tests/ui/collection_is_never_read.rs:239:5 | LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/comparison_chain.rs b/tests/ui/comparison_chain.rs index 418c88b7d5a3..669690a4d42c 100644 --- a/tests/ui/comparison_chain.rs +++ b/tests/ui/comparison_chain.rs @@ -13,7 +13,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if x < y { @@ -28,7 +28,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if x < y { @@ -38,7 +38,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if y > x { @@ -48,7 +48,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > 1 { - //~^ comparison_chain + //~^ comparison_chain a() } else if x < 1 { @@ -124,7 +124,7 @@ fn g(x: f64, y: f64, z: f64) { fn h(x: T, y: T, z: T) { if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if x < y { @@ -132,7 +132,7 @@ fn h(x: T, y: T, z: T) { } if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if x < y { @@ -142,7 +142,7 @@ fn h(x: T, y: T, z: T) { } if x > y { - //~^ comparison_chain + //~^ comparison_chain a() } else if y > x { @@ -249,7 +249,7 @@ const fn sign_i8(n: i8) -> Sign { fn needs_parens() -> &'static str { let (x, y) = (1, 2); if x + 1 > y * 2 { - //~^ comparison_chain + //~^ comparison_chain "aa" } else if x + 1 < y * 2 { diff --git a/tests/ui/comparison_to_empty.fixed b/tests/ui/comparison_to_empty.fixed index 205abe31cd86..dfbb61683840 100644 --- a/tests/ui/comparison_to_empty.fixed +++ b/tests/ui/comparison_to_empty.fixed @@ -25,7 +25,7 @@ fn main() { if s.is_empty() //~^ comparison_to_empty && s.is_empty() - //~^ comparison_to_empty + //~^ comparison_to_empty {} // Allow comparisons to non-empty diff --git a/tests/ui/comparison_to_empty.rs b/tests/ui/comparison_to_empty.rs index 4da6327050a8..61cdb2bbe9f8 100644 --- a/tests/ui/comparison_to_empty.rs +++ b/tests/ui/comparison_to_empty.rs @@ -25,7 +25,7 @@ fn main() { if let [] = &*s //~^ comparison_to_empty && s == [] - //~^ comparison_to_empty + //~^ comparison_to_empty {} // Allow comparisons to non-empty diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index 0df4b8eb356e..b732d7d142fc 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -45,52 +45,38 @@ fn main() { status_code <= 400 && status_code > 500; //~^ impossible_comparisons - status_code > 500 && status_code < 400; //~^ impossible_comparisons - status_code < 500 && status_code > 500; //~^ impossible_comparisons - - // More complex expressions status_code < { 400 } && status_code > { 500 }; //~^ impossible_comparisons - status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; //~^ impossible_comparisons - status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; //~^ impossible_comparisons - status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; //~^ impossible_comparisons - - // Comparing two different types, via the `impl PartialOrd for Status` status < { 400 } && status > { 500 }; //~^ impossible_comparisons - status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; //~^ impossible_comparisons - status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; //~^ impossible_comparisons - status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; //~^ impossible_comparisons - - // Yoda conditions // Correct 500 <= status_code && 600 > status_code; @@ -100,13 +86,10 @@ fn main() { 500 >= status_code && 600 < status_code; //~^ impossible_comparisons - // Incorrect 500 >= status_code && status_code > 600; //~^ impossible_comparisons - - // Yoda conditions, comparing two different types // Correct 500 <= status && 600 > status; @@ -116,13 +99,10 @@ fn main() { 500 >= status && 600 < status; //~^ impossible_comparisons - // Incorrect 500 >= status && status > 600; //~^ impossible_comparisons - - // Expressions where one of the sides has no effect status_code < 200 && status_code <= 299; //~^ redundant_comparisons @@ -130,7 +110,6 @@ fn main() { status_code > 200 && status_code >= 299; //~^ redundant_comparisons - // Useless left status_code >= 500 && status_code > 500; //~^ redundant_comparisons @@ -147,29 +126,20 @@ fn main() { status_code < 500 && status_code <= 500; //~^ redundant_comparisons - // Other types let name = "Steve"; name < "Jennifer" && name > "Shannon"; //~^ impossible_comparisons - - let numbers = [1, 2]; numbers < [3, 4] && numbers > [5, 6]; //~^ impossible_comparisons - - let letter = 'a'; letter < 'b' && letter > 'c'; //~^ impossible_comparisons - - let area = 42.0; area < std::f32::consts::E && area > std::f32::consts::PI; //~^ impossible_comparisons - - } diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index 2f3f5c9523e3..48a2c6e8d487 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -9,7 +9,7 @@ LL | status_code <= 400 && status_code > 500; = help: to override `-D warnings` add `#[allow(clippy::impossible_comparisons)]` error: boolean expression will never evaluate to 'true' - --> tests/ui/const_comparisons.rs:49:5 + --> tests/ui/const_comparisons.rs:48:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,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' - --> tests/ui/const_comparisons.rs:53:5 + --> tests/ui/const_comparisons.rs:51:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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' - --> tests/ui/const_comparisons.rs:59:5 + --> tests/ui/const_comparisons.rs:55:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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' - --> tests/ui/const_comparisons.rs:63:5 + --> tests/ui/const_comparisons.rs:58:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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' - --> tests/ui/const_comparisons.rs:67:5 + --> tests/ui/const_comparisons.rs:61:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,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' - --> tests/ui/const_comparisons.rs:71:5 + --> tests/ui/const_comparisons.rs:64:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,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' - --> tests/ui/const_comparisons.rs:77:5 + --> tests/ui/const_comparisons.rs:68:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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' - --> tests/ui/const_comparisons.rs:81:5 + --> tests/ui/const_comparisons.rs:71:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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' - --> tests/ui/const_comparisons.rs:85:5 + --> tests/ui/const_comparisons.rs:74:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,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' - --> tests/ui/const_comparisons.rs:89:5 + --> tests/ui/const_comparisons.rs:77:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,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' - --> tests/ui/const_comparisons.rs:100:5 + --> tests/ui/const_comparisons.rs:86:5 | LL | 500 >= status_code && 600 < status_code; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ 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' - --> tests/ui/const_comparisons.rs:105:5 + --> tests/ui/const_comparisons.rs:90:5 | LL | 500 >= status_code && status_code > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ 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' - --> tests/ui/const_comparisons.rs:116:5 + --> tests/ui/const_comparisons.rs:99:5 | LL | 500 >= status && 600 < status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ 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' - --> tests/ui/const_comparisons.rs:121:5 + --> tests/ui/const_comparisons.rs:103:5 | LL | 500 >= status && status > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,13 +121,13 @@ 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 - --> tests/ui/const_comparisons.rs:127:5 + --> tests/ui/const_comparisons.rs:107: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 - --> tests/ui/const_comparisons.rs:127:23 + --> tests/ui/const_comparisons.rs:107:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ @@ -135,67 +135,67 @@ LL | status_code < 200 && status_code <= 299; = help: to override `-D warnings` add `#[allow(clippy::redundant_comparisons)]` error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:130:5 + --> tests/ui/const_comparisons.rs:110: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 - --> tests/ui/const_comparisons.rs:130:5 + --> tests/ui/const_comparisons.rs:110:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:135:5 + --> tests/ui/const_comparisons.rs:114:5 | 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 - --> tests/ui/const_comparisons.rs:135:5 + --> tests/ui/const_comparisons.rs:114:5 | LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:139:5 + --> tests/ui/const_comparisons.rs:118:5 | 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 - --> tests/ui/const_comparisons.rs:139:23 + --> tests/ui/const_comparisons.rs:118:23 | LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:143:5 + --> tests/ui/const_comparisons.rs:122:5 | 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 - --> tests/ui/const_comparisons.rs:143:5 + --> tests/ui/const_comparisons.rs:122:5 | LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> tests/ui/const_comparisons.rs:147:5 + --> tests/ui/const_comparisons.rs:126:5 | 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 - --> tests/ui/const_comparisons.rs:147:23 + --> tests/ui/const_comparisons.rs:126:23 | LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> tests/ui/const_comparisons.rs:153:5 + --> tests/ui/const_comparisons.rs:131:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,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' - --> tests/ui/const_comparisons.rs:159:5 + --> tests/ui/const_comparisons.rs:135:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -211,7 +211,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' - --> tests/ui/const_comparisons.rs:165:5 + --> tests/ui/const_comparisons.rs:139:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,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' - --> tests/ui/const_comparisons.rs:171:5 + --> tests/ui/const_comparisons.rs:143:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const_is_empty.rs b/tests/ui/const_is_empty.rs index 29891ae4c0e5..8bb4f0e5d975 100644 --- a/tests/ui/const_is_empty.rs +++ b/tests/ui/const_is_empty.rs @@ -3,23 +3,19 @@ fn test_literal() { if "".is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } if "foobar".is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } } fn test_byte_literal() { if b"".is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } if b"foobar".is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } } @@ -36,12 +32,10 @@ fn test_propagated() { let empty2 = empty; let non_empty2 = non_empty; if empty2.is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } if non_empty2.is_empty() { - //~^ const_is_empty - + //~^ const_is_empty } } @@ -106,7 +100,6 @@ fn test_from_const() { let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); //~^ const_is_empty - } fn main() { @@ -123,7 +116,6 @@ fn main() { let _ = b"".is_empty(); //~^ const_is_empty - } fn str_from_arg(var: &str) { @@ -178,7 +170,6 @@ fn not_cfg_conditioned() { #[cfg(not(target_os = "inexistent"))] let _ = val.is_empty(); //~^ const_is_empty - } const fn const_rand() -> &'static str { diff --git a/tests/ui/const_is_empty.stderr b/tests/ui/const_is_empty.stderr index 9557ad18dfc8..2ba189058e83 100644 --- a/tests/ui/const_is_empty.stderr +++ b/tests/ui/const_is_empty.stderr @@ -8,157 +8,157 @@ LL | if "".is_empty() { = help: to override `-D warnings` add `#[allow(clippy::const_is_empty)]` error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:9:8 + --> tests/ui/const_is_empty.rs:8:8 | LL | if "foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:16:8 + --> tests/ui/const_is_empty.rs:14:8 | LL | if b"".is_empty() { | ^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:20:8 + --> tests/ui/const_is_empty.rs:17:8 | LL | if b"foobar".is_empty() { | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:38:8 + --> tests/ui/const_is_empty.rs:34:8 | LL | if empty2.is_empty() { | ^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:42:8 + --> tests/ui/const_is_empty.rs:37:8 | LL | if non_empty2.is_empty() { | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:65:13 + --> tests/ui/const_is_empty.rs:59:13 | LL | let _ = EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:68:13 + --> tests/ui/const_is_empty.rs:62:13 | LL | let _ = NON_EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:71:13 + --> tests/ui/const_is_empty.rs:65:13 | LL | let _ = EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:74:13 + --> tests/ui/const_is_empty.rs:68:13 | LL | let _ = NON_EMPTY_BSTR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:77:13 + --> tests/ui/const_is_empty.rs:71:13 | LL | let _ = EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:80:13 + --> tests/ui/const_is_empty.rs:74:13 | LL | let _ = EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:83:13 + --> tests/ui/const_is_empty.rs:77:13 | LL | let _ = EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:86:13 + --> tests/ui/const_is_empty.rs:80:13 | LL | let _ = NON_EMPTY_U8_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:89:13 + --> tests/ui/const_is_empty.rs:83:13 | LL | let _ = NON_EMPTY_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:92:13 + --> tests/ui/const_is_empty.rs:86:13 | LL | let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:95:13 + --> tests/ui/const_is_empty.rs:89:13 | LL | let _ = EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:98:13 + --> tests/ui/const_is_empty.rs:92:13 | LL | let _ = NON_EMPTY_REF_ARRAY.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:101:13 + --> tests/ui/const_is_empty.rs:95:13 | LL | let _ = EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:104:13 + --> tests/ui/const_is_empty.rs:98:13 | LL | let _ = NON_EMPTY_SLICE.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:107:13 + --> tests/ui/const_is_empty.rs:101:13 | LL | let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:114:13 + --> tests/ui/const_is_empty.rs:107:13 | LL | let _ = value.is_empty(); | ^^^^^^^^^^^^^^^^ error: this expression always evaluates to false - --> tests/ui/const_is_empty.rs:118:13 + --> tests/ui/const_is_empty.rs:111:13 | LL | let _ = x.is_empty(); | ^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:121:13 + --> tests/ui/const_is_empty.rs:114:13 | LL | let _ = "".is_empty(); | ^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:124:13 + --> tests/ui/const_is_empty.rs:117:13 | LL | let _ = b"".is_empty(); | ^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:179:13 + --> tests/ui/const_is_empty.rs:171:13 | LL | let _ = val.is_empty(); | ^^^^^^^^^^^^^^ error: this expression always evaluates to true - --> tests/ui/const_is_empty.rs:211:9 + --> tests/ui/const_is_empty.rs:202:9 | LL | EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/copy_iterator.rs b/tests/ui/copy_iterator.rs index f048f7541bc6..5639583289d2 100644 --- a/tests/ui/copy_iterator.rs +++ b/tests/ui/copy_iterator.rs @@ -5,8 +5,7 @@ struct Countdown(u8); impl Iterator for Countdown { -//~^ copy_iterator - + //~^ copy_iterator type Item = u8; diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 86fd326c36c5..2f6378a85fee 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -2,6 +2,9 @@ error: you are implementing `Iterator` on a `Copy` type --> tests/ui/copy_iterator.rs:7:1 | LL | / impl Iterator for Countdown { +LL | | +LL | | +LL | | type Item = u8; ... | LL | | } | |_^ diff --git a/tests/ui/crashes/ice-11803.rs b/tests/ui/crashes/ice-11803.rs index aced75b3ad12..e85f31909388 100644 --- a/tests/ui/crashes/ice-11803.rs +++ b/tests/ui/crashes/ice-11803.rs @@ -3,8 +3,8 @@ #![warn(clippy::impl_trait_in_params)] pub fn g>>() { -//~^ impl_trait_in_params -//~| impl_trait_in_params + //~^ impl_trait_in_params + //~| impl_trait_in_params extern "C" fn implementation_detail() {} } diff --git a/tests/ui/crashes/ice-2774.fixed b/tests/ui/crashes/ice-2774.fixed index d096584fa75c..35d969441763 100644 --- a/tests/ui/crashes/ice-2774.fixed +++ b/tests/ui/crashes/ice-2774.fixed @@ -13,8 +13,7 @@ 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>) { -//~^ needless_lifetimes - + //~^ needless_lifetimes 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 83fb7be626df..1eb6df0095ed 100644 --- a/tests/ui/crashes/ice-2774.rs +++ b/tests/ui/crashes/ice-2774.rs @@ -13,8 +13,7 @@ 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>) { -//~^ needless_lifetimes - + //~^ needless_lifetimes 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 43becad3183f..cb8176a2973f 100644 --- a/tests/ui/crashes/ice-360.rs +++ b/tests/ui/crashes/ice-360.rs @@ -3,10 +3,8 @@ fn main() {} fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { - //~^ never_loop - //~| while_let_loop - - + //~^ never_loop + //~| while_let_loop let _ = match iter.next() { Some(ele) => ele, @@ -14,6 +12,5 @@ fn no_panic(slice: &[T]) { }; loop {} //~^ empty_loop - } } diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index e4bd436abc54..9961eb21485d 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -20,7 +20,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: empty `loop {}` wastes CPU cycles - --> tests/ui/crashes/ice-360.rs:15:9 + --> tests/ui/crashes/ice-360.rs:13:9 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/crashes/ice-3717.fixed b/tests/ui/crashes/ice-3717.fixed index 0d7c38f95217..5581b67fa5c4 100644 --- a/tests/ui/crashes/ice-3717.fixed +++ b/tests/ui/crashes/ice-3717.fixed @@ -5,7 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { -//~^ implicit_hasher + //~^ implicit_hasher let _ = [0u8; 0]; let _: HashSet = HashSet::default(); diff --git a/tests/ui/crashes/ice-3717.rs b/tests/ui/crashes/ice-3717.rs index 7c286abf32b0..c612270865c5 100644 --- a/tests/ui/crashes/ice-3717.rs +++ b/tests/ui/crashes/ice-3717.rs @@ -5,7 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { -//~^ implicit_hasher + //~^ implicit_hasher let _ = [0u8; 0]; let _: HashSet = HashSet::new(); diff --git a/tests/ui/crashes/ice-3969.rs b/tests/ui/crashes/ice-3969.rs index 1db7f0ad8b5b..fa3ca6f1d538 100644 --- a/tests/ui/crashes/ice-3969.rs +++ b/tests/ui/crashes/ice-3969.rs @@ -23,7 +23,7 @@ where fn unsized_local() where for<'a> Dst: Sized, -//~^ ERROR: trait bound + //~^ ERROR: trait bound { let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); } @@ -31,7 +31,7 @@ where fn return_str() -> str where str: Sized, -//~^ ERROR: trait bound + //~^ ERROR: trait bound { *"Sized".to_string().into_boxed_str() } @@ -39,7 +39,7 @@ where fn use_op(s: String) -> String where String: ::std::ops::Neg, -//~^ ERROR: trait bound + //~^ ERROR: trait bound { -s } @@ -47,7 +47,7 @@ where fn use_for() where i32: Iterator, -//~^ ERROR: trait bound + //~^ ERROR: trait bound { for _ in 2i32 {} } diff --git a/tests/ui/crashes/ice-5872.fixed b/tests/ui/crashes/ice-5872.fixed index a3235c3c7b7c..521fa15e1846 100644 --- a/tests/ui/crashes/ice-5872.fixed +++ b/tests/ui/crashes/ice-5872.fixed @@ -3,6 +3,4 @@ fn main() { let _ = vec![1, 2, 3].into_iter().next().is_none(); //~^ needless_collect - - } diff --git a/tests/ui/crashes/ice-5872.rs b/tests/ui/crashes/ice-5872.rs index 7d3ad01f56e7..10235ea8ab7f 100644 --- a/tests/ui/crashes/ice-5872.rs +++ b/tests/ui/crashes/ice-5872.rs @@ -3,6 +3,4 @@ fn main() { let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); //~^ needless_collect - - } diff --git a/tests/ui/crashes/ice-6250.rs b/tests/ui/crashes/ice-6250.rs index 37db2ce68757..65cdce793142 100644 --- a/tests/ui/crashes/ice-6250.rs +++ b/tests/ui/crashes/ice-6250.rs @@ -10,8 +10,8 @@ pub fn list_data(cache: &Cache, key: usize) { if /* let */ Some(reference) = cache.data.get(key) { - //~^ ERROR: mismatched types - //~| ERROR: mismatched types + //~^ ERROR: mismatched types + //~| ERROR: mismatched types unimplemented!() } } diff --git a/tests/ui/crashes/ice-6251.rs b/tests/ui/crashes/ice-6251.rs index 8191a53b3e59..a58265752ec3 100644 --- a/tests/ui/crashes/ice-6251.rs +++ b/tests/ui/crashes/ice-6251.rs @@ -2,8 +2,8 @@ // assertion failed: `(left == right)` ; different DefIds //@no-rustfix fn bug() -> impl Iterator { -//~^ ERROR: the size for values -//~| ERROR: the size for values -//~| ERROR: mismatched types + //~^ ERROR: the size for values + //~| ERROR: the size for values + //~| ERROR: mismatched types std::iter::empty() } diff --git a/tests/ui/crashes/ice-7169.fixed b/tests/ui/crashes/ice-7169.fixed index d69b472a3617..71a40ad7de71 100644 --- a/tests/ui/crashes/ice-7169.fixed +++ b/tests/ui/crashes/ice-7169.fixed @@ -9,6 +9,4 @@ struct A { fn main() { if Ok::<_, ()>(A::::default()).is_ok() {} //~^ redundant_pattern_matching - - } diff --git a/tests/ui/crashes/ice-7169.rs b/tests/ui/crashes/ice-7169.rs index 918f2b0f0b3c..d43e2cc164d7 100644 --- a/tests/ui/crashes/ice-7169.rs +++ b/tests/ui/crashes/ice-7169.rs @@ -9,6 +9,4 @@ struct A { fn main() { if let Ok(_) = Ok::<_, ()>(A::::default()) {} //~^ redundant_pattern_matching - - } diff --git a/tests/ui/crashes/ice-7869.rs b/tests/ui/crashes/ice-7869.rs index 68648462b57a..a5b557849aba 100644 --- a/tests/ui/crashes/ice-7869.rs +++ b/tests/ui/crashes/ice-7869.rs @@ -1,6 +1,5 @@ enum Tila { -//~^ enum_variant_names - + //~^ enum_variant_names TyöAlkoi, TyöKeskeytyi, TyöValmis, diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 7d70e3834e9d..2377b4fd5b6b 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -3,7 +3,6 @@ error: all variants have the same prefix: `Työ` | LL | / enum Tila { LL | | -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 2474c47944ef..b0c2ddb2450d 100644 --- a/tests/ui/crashes/ice-8250.fixed +++ b/tests/ui/crashes/ice-8250.fixed @@ -2,7 +2,6 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].split('.').next()?; //~^ needless_splitn - Some(()) } diff --git a/tests/ui/crashes/ice-8250.rs b/tests/ui/crashes/ice-8250.rs index 8f938246f37a..ee0eb8e1eb1a 100644 --- a/tests/ui/crashes/ice-8250.rs +++ b/tests/ui/crashes/ice-8250.rs @@ -2,7 +2,6 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].splitn(2, '.').next()?; //~^ needless_splitn - Some(()) } diff --git a/tests/ui/crashes/ice-9041.rs b/tests/ui/crashes/ice-9041.rs index 69e74e6e394b..4b2a0f953114 100644 --- a/tests/ui/crashes/ice-9041.rs +++ b/tests/ui/crashes/ice-9041.rs @@ -4,8 +4,6 @@ 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() //~^ search_is_some - - } fn main() {} diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index cc5ed052d264..da3b82a60c5f 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -14,7 +14,7 @@ impl Foo for Baz<'_> {} impl Bar { fn baz(&self) -> impl Foo + '_ { - //~^ needless_lifetimes + //~^ needless_lifetimes Baz { bar: self } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 258fb3118ef0..456d315926db 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -14,7 +14,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { - //~^ needless_lifetimes + //~^ needless_lifetimes 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 128ff4a1c036..7d7286ceb99a 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 @@ -7,5 +7,4 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: &Foo<'_>) {} //~^ needless_pass_by_value - 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 b82cc831c6e0..949cd5de7fb8 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 @@ -7,5 +7,4 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: Foo<'_>) {} //~^ needless_pass_by_value - 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 e332e10ea4ba..66ca97690c17 100644 --- a/tests/ui/crate_level_checks/no_std_swap.rs +++ b/tests/ui/crate_level_checks/no_std_swap.rs @@ -11,6 +11,5 @@ pub fn main() { a = b; //~^ almost_swapped - b = a; } diff --git a/tests/ui/crate_level_checks/std_main_recursion.rs b/tests/ui/crate_level_checks/std_main_recursion.rs index b582d560668a..50f82b59a96e 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.rs +++ b/tests/ui/crate_level_checks/std_main_recursion.rs @@ -4,5 +4,4 @@ fn main() { println!("Hello, World!"); main(); //~^ main_recursion - } diff --git a/tests/ui/dbg_macro/dbg_macro.fixed b/tests/ui/dbg_macro/dbg_macro.fixed index de715db8faab..fd1a0d8934b3 100644 --- a/tests/ui/dbg_macro/dbg_macro.fixed +++ b/tests/ui/dbg_macro/dbg_macro.fixed @@ -4,21 +4,18 @@ fn foo(n: u32) -> u32 { if let Some(n) = n.checked_sub(4) { n } else { n } //~^ dbg_macro - } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if n <= 1 { - //~^ dbg_macro + //~^ dbg_macro 1 //~^ dbg_macro - } else { n * factorial(n - 1) //~^ dbg_macro - } } @@ -31,7 +28,6 @@ fn main() { (1, 2, 3, 4, 5); //~^ dbg_macro - } fn issue9914() { @@ -49,7 +45,6 @@ fn issue9914() { () => { //~^ dbg_macro - }; } @@ -91,7 +86,6 @@ mod issue7274 { define_thing!(MyThing, { 2; //~^ dbg_macro - }); } @@ -99,14 +93,12 @@ mod issue7274 { pub fn issue8481() { 1; //~^ dbg_macro - } #[cfg(test)] fn foo2() { 1; //~^ dbg_macro - } #[cfg(test)] @@ -114,7 +106,6 @@ mod mod1 { fn func() { 1; //~^ dbg_macro - } } @@ -125,6 +116,5 @@ mod issue12131 { print!("{}", s); //~^ dbg_macro - } } diff --git a/tests/ui/dbg_macro/dbg_macro.rs b/tests/ui/dbg_macro/dbg_macro.rs index 90a72d131667..c96e2c7251c2 100644 --- a/tests/ui/dbg_macro/dbg_macro.rs +++ b/tests/ui/dbg_macro/dbg_macro.rs @@ -4,21 +4,18 @@ fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } //~^ dbg_macro - } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { - //~^ dbg_macro + //~^ dbg_macro dbg!(1) //~^ dbg_macro - } else { dbg!(n * factorial(n - 1)) //~^ dbg_macro - } } @@ -31,7 +28,6 @@ fn main() { dbg!(1, 2, 3, 4, 5); //~^ dbg_macro - } fn issue9914() { @@ -49,7 +45,6 @@ fn issue9914() { () => { dbg!(); //~^ dbg_macro - }; } @@ -91,7 +86,6 @@ mod issue7274 { define_thing!(MyThing, { dbg!(2); //~^ dbg_macro - }); } @@ -99,14 +93,12 @@ mod issue7274 { pub fn issue8481() { dbg!(1); //~^ dbg_macro - } #[cfg(test)] fn foo2() { dbg!(1); //~^ dbg_macro - } #[cfg(test)] @@ -114,7 +106,6 @@ mod mod1 { fn func() { dbg!(1); //~^ dbg_macro - } } @@ -125,6 +116,5 @@ mod issue12131 { print!("{}", dbg!(s)); //~^ dbg_macro - } } diff --git a/tests/ui/dbg_macro/dbg_macro.stderr b/tests/ui/dbg_macro/dbg_macro.stderr index ee0cfc12b347..83b497a539c0 100644 --- a/tests/ui/dbg_macro/dbg_macro.stderr +++ b/tests/ui/dbg_macro/dbg_macro.stderr @@ -12,7 +12,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:12:8 + --> tests/ui/dbg_macro/dbg_macro.rs:11:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:15:9 + --> tests/ui/dbg_macro/dbg_macro.rs:14:9 | LL | dbg!(1) | ^^^^^^^ @@ -34,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:19:9 + --> tests/ui/dbg_macro/dbg_macro.rs:17:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:26:5 + --> tests/ui/dbg_macro/dbg_macro.rs:23:5 | LL | dbg!(42); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:29:14 + --> tests/ui/dbg_macro/dbg_macro.rs:26:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:32:5 + --> tests/ui/dbg_macro/dbg_macro.rs:29:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:56:5 + --> tests/ui/dbg_macro/dbg_macro.rs:51:5 | LL | dbg!(); | ^^^^^^ @@ -89,7 +89,7 @@ LL - dbg!(); | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:60:13 + --> tests/ui/dbg_macro/dbg_macro.rs:55:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:63:9 + --> tests/ui/dbg_macro/dbg_macro.rs:58:9 | LL | bar(dbg!()); | ^^^^^^ @@ -111,7 +111,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:66:10 + --> tests/ui/dbg_macro/dbg_macro.rs:61:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -122,7 +122,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:69:16 + --> tests/ui/dbg_macro/dbg_macro.rs:64:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -133,7 +133,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:50:13 + --> tests/ui/dbg_macro/dbg_macro.rs:46:13 | LL | dbg!(); | ^^^^^^ @@ -148,7 +148,7 @@ LL - dbg!(); | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:92:9 + --> tests/ui/dbg_macro/dbg_macro.rs:87:9 | LL | dbg!(2); | ^^^^^^^ @@ -158,6 +158,17 @@ help: remove the invocation before committing it to a version control system LL | 2; | ~ +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro.rs:94:5 + | +LL | dbg!(1); + | ^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | 1; + | ~ + error: the `dbg!` macro is intended as a debugging tool --> tests/ui/dbg_macro/dbg_macro.rs:100:5 | @@ -170,18 +181,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:107:5 - | -LL | dbg!(1); - | ^^^^^^^ - | -help: remove the invocation before committing it to a version control system - | -LL | 1; - | ~ - -error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:115:9 + --> tests/ui/dbg_macro/dbg_macro.rs:107:9 | LL | dbg!(1); | ^^^^^^^ @@ -192,7 +192,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:123:31 + --> tests/ui/dbg_macro/dbg_macro.rs:114:31 | LL | println!("dbg: {:?}", dbg!(s)); | ^^^^^^^ @@ -203,7 +203,7 @@ LL | println!("dbg: {:?}", s); | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:126:22 + --> tests/ui/dbg_macro/dbg_macro.rs:117:22 | LL | print!("{}", dbg!(s)); | ^^^^^^^ diff --git a/tests/ui/dbg_macro/dbg_macro_unfixable.rs b/tests/ui/dbg_macro/dbg_macro_unfixable.rs index bd16306b89db..1a5119651b53 100644 --- a/tests/ui/dbg_macro/dbg_macro_unfixable.rs +++ b/tests/ui/dbg_macro/dbg_macro_unfixable.rs @@ -14,5 +14,4 @@ fn main() { dbg!(1, 2, dbg!(3, 4)); //~^ dbg_macro //~| dbg_macro - } diff --git a/tests/ui/declare_interior_mutable_const/enums.rs b/tests/ui/declare_interior_mutable_const/enums.rs index 0f454786156e..c87468277fb3 100644 --- a/tests/ui/declare_interior_mutable_const/enums.rs +++ b/tests/ui/declare_interior_mutable_const/enums.rs @@ -45,8 +45,7 @@ struct NestedOutermost { // a constant with enums should be linted according to its value, no matter how structs involve. const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { -//~^ declare_interior_mutable_const - + //~^ declare_interior_mutable_const outer: NestedOuter::NestedInner(NestedInner { inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), }), @@ -60,14 +59,14 @@ const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost { trait AssocConsts { // When there's no default value, lint it only according to its type. // Further details are on the corresponding code (`NonCopyConst::check_trait_item`). -const TO_BE_UNFROZEN_VARIANT: OptionalCell; -//~^ declare_interior_mutable_const -const TO_BE_FROZEN_VARIANT: OptionalCell; -//~^ declare_interior_mutable_const + const TO_BE_UNFROZEN_VARIANT: OptionalCell; + //~^ declare_interior_mutable_const + const TO_BE_FROZEN_VARIANT: OptionalCell; + //~^ declare_interior_mutable_const // Lint default values accordingly. -const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); -//~^ declare_interior_mutable_const + const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); + //~^ declare_interior_mutable_const const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen; } @@ -93,8 +92,8 @@ trait AssocTypes { impl AssocTypes for u64 { type ToBeUnfrozen = AtomicUsize; -const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); -//~^ declare_interior_mutable_const + const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); + //~^ declare_interior_mutable_const const TO_BE_FROZEN_VARIANT: Option = None; } @@ -106,30 +105,30 @@ enum BothOfCellAndGeneric { } impl BothOfCellAndGeneric { -const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); -//~^ declare_interior_mutable_const + const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); + //~^ declare_interior_mutable_const // This is a false positive. The argument about this is on `is_value_unfrozen_raw` -const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); -//~^ declare_interior_mutable_const + const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + //~^ declare_interior_mutable_const const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); // This is what is likely to be a false negative when one tries to fix // the `GENERIC_VARIANT` false positive. -const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); -//~^ declare_interior_mutable_const + const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); + //~^ declare_interior_mutable_const } // associated types here is basically the same as the one above. trait BothOfCellAndGenericWithAssocType { type AssocType; -const UNFROZEN_VARIANT: BothOfCellAndGeneric = -//~^ declare_interior_mutable_const + const UNFROZEN_VARIANT: BothOfCellAndGeneric = + //~^ declare_interior_mutable_const BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); -const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); -//~^ declare_interior_mutable_const + const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + //~^ declare_interior_mutable_const const FROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Frozen(5); } diff --git a/tests/ui/declare_interior_mutable_const/enums.stderr b/tests/ui/declare_interior_mutable_const/enums.stderr index a6f14ec71feb..32839d14f0ed 100644 --- a/tests/ui/declare_interior_mutable_const/enums.stderr +++ b/tests/ui/declare_interior_mutable_const/enums.stderr @@ -21,7 +21,6 @@ error: a `const` item should not be interior mutable | LL | / const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost { LL | | -LL | | LL | | outer: NestedOuter::NestedInner(NestedInner { LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)), LL | | }), @@ -31,60 +30,60 @@ LL | | }; = help: consider making this a static item error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:63:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:62:5 | -LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:65:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:64:5 | -LL | const TO_BE_FROZEN_VARIANT: OptionalCell; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_FROZEN_VARIANT: OptionalCell; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:69:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:68:5 | -LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:96:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:95:5 | -LL | const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN_VARIANT: Option = Some(Self::ToBeUnfrozen::new(4)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:109:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:108:5 | -LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:113:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:112:5 | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:120:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:119:5 | -LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:128:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:127:5 | -LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric = +LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric = LL | | LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); | |____________________________________________________________________^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/enums.rs:131:1 + --> tests/ui/declare_interior_mutable_const/enums.rs:130:5 | -LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const GENERIC_VARIANT: BothOfCellAndGeneric = BothOfCellAndGeneric::Generic(std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 12 previous errors diff --git a/tests/ui/declare_interior_mutable_const/others.rs b/tests/ui/declare_interior_mutable_const/others.rs index 9820626ae454..7ce04a3f2c34 100644 --- a/tests/ui/declare_interior_mutable_const/others.rs +++ b/tests/ui/declare_interior_mutable_const/others.rs @@ -14,12 +14,10 @@ const CELL: Cell = Cell::new(6); const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], Vec::new(), 7); //~^ declare_interior_mutable_const - macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { const $name: $ty = $e; //~^ declare_interior_mutable_const - }; } declare_const!(_ONCE: Once = Once::new()); diff --git a/tests/ui/declare_interior_mutable_const/others.stderr b/tests/ui/declare_interior_mutable_const/others.stderr index 3c388e3bcf37..09299b290416 100644 --- a/tests/ui/declare_interior_mutable_const/others.stderr +++ b/tests/ui/declare_interior_mutable_const/others.stderr @@ -25,7 +25,7 @@ LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec, u8) = ([ATOMIC], V = help: consider making this a static item error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:20:9 + --> tests/ui/declare_interior_mutable_const/others.rs:19:9 | LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | declare_const!(_ONCE: Once = Once::new()); = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/others.rs:49:13 + --> tests/ui/declare_interior_mutable_const/others.rs:47:13 | LL | const _BAZ: Cell = Cell::new(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/declare_interior_mutable_const/traits.rs b/tests/ui/declare_interior_mutable_const/traits.rs index 83d6c1307ea2..d3139be6859f 100644 --- a/tests/ui/declare_interior_mutable_const/traits.rs +++ b/tests/ui/declare_interior_mutable_const/traits.rs @@ -8,14 +8,13 @@ macro_rules! declare_const { ($name:ident: $ty:ty = $e:expr) => { const $name: $ty = $e; //~^ declare_interior_mutable_const - }; } // a constant whose type is a concrete type should be linted at the definition site. trait ConcreteTypes { -const ATOMIC: AtomicUsize; -//~^ declare_interior_mutable_const + const ATOMIC: AtomicUsize; + //~^ declare_interior_mutable_const const INTEGER: u64; const STRING: String; declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); @@ -43,8 +42,8 @@ trait GenericTypes { impl GenericTypes for u64 { const TO_REMAIN_GENERIC: T = T::DEFAULT; -const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); -//~^ declare_interior_mutable_const + const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); + //~^ declare_interior_mutable_const } // a helper type used below @@ -69,10 +68,10 @@ impl AssocTypes for Vec { type ToBeGenericParam = T; const TO_BE_FROZEN: Self::ToBeFrozen = 12; -const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); -//~^ declare_interior_mutable_const -const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); -//~^ declare_interior_mutable_const + const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); + //~^ declare_interior_mutable_const + const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); + //~^ declare_interior_mutable_const const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper = Wrapper(T::DEFAULT); } @@ -91,8 +90,8 @@ where T: AssocTypesHelper, { const NOT_BOUNDED: T::NotToBeBounded; -const BOUNDED: T::ToBeBounded; -//~^ declare_interior_mutable_const + const BOUNDED: T::ToBeBounded; + //~^ declare_interior_mutable_const } impl AssocTypesFromGenericParam for u64 @@ -120,24 +119,24 @@ impl SelfType for u64 { impl SelfType for AtomicUsize { // this (interior mutable `Self` const) exists in `parking_lot`. // `const_trait_impl` will replace it in the future, hopefully. -const SELF: Self = AtomicUsize::new(17); -//~^ declare_interior_mutable_const -const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); -//~^ declare_interior_mutable_const + const SELF: Self = AtomicUsize::new(17); + //~^ declare_interior_mutable_const + const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); + //~^ declare_interior_mutable_const } // Even though a constant contains a generic type, if it also have an interior mutable type, // it should be linted at the definition site. trait BothOfCellAndGeneric { -const DIRECT: Cell; -//~^ declare_interior_mutable_const -const INDIRECT: Cell<*const T>; -//~^ declare_interior_mutable_const + const DIRECT: Cell; + //~^ declare_interior_mutable_const + const INDIRECT: Cell<*const T>; + //~^ declare_interior_mutable_const } impl BothOfCellAndGeneric for u64 { -const DIRECT: Cell = Cell::new(T::DEFAULT); -//~^ declare_interior_mutable_const + const DIRECT: Cell = Cell::new(T::DEFAULT); + //~^ declare_interior_mutable_const const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null()); } @@ -149,15 +148,15 @@ impl Local where T: ConstDefault + AssocTypesHelper, { -const ATOMIC: AtomicUsize = AtomicUsize::new(18); -//~^ declare_interior_mutable_const + const ATOMIC: AtomicUsize = AtomicUsize::new(18); + //~^ declare_interior_mutable_const const COW: Cow<'static, str> = Cow::Borrowed("tuvwxy"); const GENERIC_TYPE: T = T::DEFAULT; const ASSOC_TYPE: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED; -const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); -//~^ declare_interior_mutable_const + const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); + //~^ declare_interior_mutable_const } fn main() {} diff --git a/tests/ui/declare_interior_mutable_const/traits.stderr b/tests/ui/declare_interior_mutable_const/traits.stderr index 1be6b9d2ec60..b03dd7a08403 100644 --- a/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/tests/ui/declare_interior_mutable_const/traits.stderr @@ -1,8 +1,8 @@ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:17:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:16:5 | -LL | const ATOMIC: AtomicUsize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const ATOMIC: AtomicUsize; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` @@ -19,70 +19,70 @@ LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:46:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:45:5 | -LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:72:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:71:5 | -LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:74:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:73:5 | -LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper = Wrapper(AtomicUsize::new(14)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:94:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:93:5 | -LL | const BOUNDED: T::ToBeBounded; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BOUNDED: T::ToBeBounded; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:123:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:122:5 | -LL | const SELF: Self = AtomicUsize::new(17); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const SELF: Self = AtomicUsize::new(17); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:125:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:124:5 | -LL | const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const WRAPPED_SELF: Option = Some(AtomicUsize::new(21)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:132:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:131:5 | -LL | const DIRECT: Cell; - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const DIRECT: Cell; + | ^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:134:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:133:5 | -LL | const INDIRECT: Cell<*const T>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const INDIRECT: Cell<*const T>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:139:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:138:5 | -LL | const DIRECT: Cell = Cell::new(T::DEFAULT); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const DIRECT: Cell = Cell::new(T::DEFAULT); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:152:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:151:5 | -LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: a `const` item should not be interior mutable - --> tests/ui/declare_interior_mutable_const/traits.rs:159:1 + --> tests/ui/declare_interior_mutable_const/traits.rs:158:5 | -LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 13 previous errors diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed index a4d66f951f75..cf1ccab688c5 100644 --- a/tests/ui/default_numeric_fallback_f64.fixed +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -30,7 +30,7 @@ mod basic_expr { //~| default_numeric_fallback //~| default_numeric_fallback let x = match 1.0_f64 { - //~^ default_numeric_fallback + //~^ default_numeric_fallback _ => 1.0_f64, //~^ default_numeric_fallback }; diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index d1446c35557f..345e65e0b4f9 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -30,7 +30,7 @@ mod basic_expr { //~| default_numeric_fallback //~| default_numeric_fallback let x = match 1. { - //~^ default_numeric_fallback + //~^ default_numeric_fallback _ => 1., //~^ default_numeric_fallback }; diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed index e95c49dd6b66..496408aa9e87 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -29,7 +29,7 @@ mod basic_expr { //~| default_numeric_fallback //~| default_numeric_fallback let x = match 1_i32 { - //~^ default_numeric_fallback + //~^ default_numeric_fallback 1_i32 => 1_i32, //~^ default_numeric_fallback //~| default_numeric_fallback diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index 377c8934c5be..90fcf4091ddc 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -29,7 +29,7 @@ mod basic_expr { //~| default_numeric_fallback //~| default_numeric_fallback let x = match 1 { - //~^ default_numeric_fallback + //~^ default_numeric_fallback 1 => 1, //~^ default_numeric_fallback //~| default_numeric_fallback diff --git a/tests/ui/default_union_representation.rs b/tests/ui/default_union_representation.rs index 90d1a20e6d8d..92c429c79a07 100644 --- a/tests/ui/default_union_representation.rs +++ b/tests/ui/default_union_representation.rs @@ -3,8 +3,7 @@ #![allow(clippy::repr_packed_without_abi)] union NoAttribute { -//~^ default_union_representation - + //~^ default_union_representation a: i32, b: u32, } @@ -17,8 +16,7 @@ union ReprC { #[repr(packed)] union ReprPacked { -//~^ default_union_representation - + //~^ default_union_representation a: i32, b: u32, } @@ -37,8 +35,7 @@ union ReprCAlign { #[repr(align(32))] union ReprAlign { -//~^ default_union_representation - + //~^ default_union_representation a: i32, b: u32, } @@ -59,8 +56,7 @@ union ZSTsAndField2 { f3: (), } union ZSTAndTwoFields { -//~^ default_union_representation - + //~^ default_union_representation f0: u32, f1: u64, f2: (), diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index 07c106d4092d..d558a3e8de1b 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -3,7 +3,6 @@ error: this union has the default representation | LL | / union NoAttribute { LL | | -LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -14,11 +13,10 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::default_union_representation)]` error: this union has the default representation - --> tests/ui/default_union_representation.rs:19:1 + --> tests/ui/default_union_representation.rs:18:1 | LL | / union ReprPacked { LL | | -LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -27,11 +25,10 @@ LL | | } = help: consider annotating `ReprPacked` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> tests/ui/default_union_representation.rs:39:1 + --> tests/ui/default_union_representation.rs:37:1 | LL | / union ReprAlign { LL | | -LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -40,11 +37,10 @@ LL | | } = help: consider annotating `ReprAlign` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> tests/ui/default_union_representation.rs:61:1 + --> tests/ui/default_union_representation.rs:58:1 | LL | / union ZSTAndTwoFields { LL | | -LL | | LL | | f0: u32, LL | | f1: u64, LL | | f2: (), diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs index 928907f516a4..b08b2aba2319 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -10,13 +10,10 @@ fn main() { let b = **&&a; //~^ deref_addrof - - { let mut x = 10; let y = *&mut x; //~^ deref_addrof - } { @@ -25,6 +22,5 @@ fn main() { let mut x = 10; let y = **&mut &mut x; //~^ deref_addrof - } } diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr index 8e69f986b056..9ac60dd6d544 100644 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -8,13 +8,13 @@ LL | let b = **&&a; = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference - --> tests/ui/deref_addrof_double_trigger.rs:17:17 + --> tests/ui/deref_addrof_double_trigger.rs:15:17 | LL | let y = *&mut x; | ^^^^^^^ help: try: `x` error: immediately dereferencing a reference - --> tests/ui/deref_addrof_double_trigger.rs:26:18 + --> tests/ui/deref_addrof_double_trigger.rs:23:18 | LL | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try: `&mut x` diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index 1df2d88824b0..4826c5497b4a 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -18,7 +18,7 @@ struct FooDefault<'a> { } impl std::default::Default for FooDefault<'_> { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { Self { a: false, @@ -40,7 +40,7 @@ impl std::default::Default for FooDefault<'_> { struct TupleDefault(bool, i32, u64); impl std::default::Default for TupleDefault { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { Self(false, 0, 0u64) } @@ -93,7 +93,7 @@ impl Default for FooNDVec { struct StrDefault<'a>(&'a str); impl Default for StrDefault<'_> { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { Self("") } @@ -120,7 +120,7 @@ mac!(0); struct Y(u32); impl Default for Y { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { Self(mac!()) } @@ -160,7 +160,7 @@ struct WithoutSelfCurly { } impl Default for WithoutSelfCurly { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { WithoutSelfCurly { a: false } } @@ -169,7 +169,7 @@ impl Default for WithoutSelfCurly { struct WithoutSelfParan(bool); impl Default for WithoutSelfParan { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { WithoutSelfParan(false) } @@ -192,7 +192,7 @@ pub struct DirectDefaultDefaultCall { } impl Default for DirectDefaultDefaultCall { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { // When calling `Default::default()` in all fields, we know it is the same as deriving. Self { v: Default::default() } @@ -204,7 +204,7 @@ pub struct EquivalentToDefaultDefaultCallVec { } impl Default for EquivalentToDefaultDefaultCallVec { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { // The body of `::default()` is `Vec::new()`, so they are equivalent. Self { v: Vec::new() } @@ -232,7 +232,7 @@ pub struct EquivalentToDefaultDefaultCallLocal { } impl Default for EquivalentToDefaultDefaultCallLocal { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { // The body of `::default()` is `S::new()`, so they are equivalent. Self { v: S::new() } @@ -272,7 +272,7 @@ pub struct RepeatDefault1 { } impl Default for RepeatDefault1 { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { RepeatDefault1 { a: [0; 32] } } @@ -307,7 +307,7 @@ pub enum SimpleEnum { } impl Default for SimpleEnum { -//~^ derivable_impls + //~^ derivable_impls fn default() -> Self { SimpleEnum::Bar } diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 2e8b5959d498..75d888c31070 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -11,7 +11,7 @@ struct Qux; impl Clone for Qux { -//~^ expl_impl_clone_on_copy + //~^ expl_impl_clone_on_copy fn clone(&self) -> Self { Qux @@ -37,7 +37,7 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { -//~^ expl_impl_clone_on_copy + //~^ expl_impl_clone_on_copy fn clone(&self) -> Self { unimplemented!() @@ -50,7 +50,7 @@ struct BigArray { } impl Clone for BigArray { -//~^ expl_impl_clone_on_copy + //~^ expl_impl_clone_on_copy fn clone(&self) -> Self { unimplemented!() @@ -63,7 +63,7 @@ struct FnPtr { } impl Clone for FnPtr { -//~^ expl_impl_clone_on_copy + //~^ expl_impl_clone_on_copy fn clone(&self) -> Self { unimplemented!() @@ -85,7 +85,7 @@ impl Clone for Generic { #[derive(Copy)] struct Generic2(T); impl Clone for Generic2 { -//~^ expl_impl_clone_on_copy + //~^ expl_impl_clone_on_copy fn clone(&self) -> Self { Self(self.0.clone()) diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs index 0a2a1ee7bc9f..3ef4ee9463dc 100644 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ b/tests/ui/derive_ord_xor_partial_ord.rs @@ -45,7 +45,7 @@ impl PartialOrd for DeriveOrdWithExplicitType struct DerivePartialOrd; impl std::cmp::Ord for DerivePartialOrd { -//~^ derive_ord_xor_partial_ord + //~^ derive_ord_xor_partial_ord fn cmp(&self, other: &Self) -> Ordering { Ordering::Less @@ -67,7 +67,7 @@ mod use_ord { struct DerivePartialOrdInUseOrd; impl Ord for DerivePartialOrdInUseOrd { - //~^ derive_ord_xor_partial_ord + //~^ derive_ord_xor_partial_ord fn cmp(&self, other: &Self) -> Ordering { Ordering::Less diff --git a/tests/ui/disallowed_names.rs b/tests/ui/disallowed_names.rs index d6e26dfcf202..30fbdbc1fdc8 100644 --- a/tests/ui/disallowed_names.rs +++ b/tests/ui/disallowed_names.rs @@ -12,8 +12,6 @@ fn test(foo: ()) {} //~^ disallowed_names - - fn main() { let foo = 42; //~^ disallowed_names @@ -38,22 +36,18 @@ fn main() { //~^ disallowed_names //~| disallowed_names //~| disallowed_names - - - _ => (), } } fn issue_1647(mut foo: u8) { -//~^ disallowed_names + //~^ disallowed_names let mut baz = 0; //~^ disallowed_names if let Some(mut quux) = Some(42) {} //~^ disallowed_names - } fn issue_1647_ref() { @@ -62,7 +56,6 @@ fn issue_1647_ref() { if let Some(ref quux) = Some(42) {} //~^ disallowed_names - } fn issue_1647_ref_mut() { @@ -71,7 +64,6 @@ fn issue_1647_ref_mut() { if let Some(ref mut quux) = Some(42) {} //~^ disallowed_names - } #[cfg(test)] diff --git a/tests/ui/disallowed_names.stderr b/tests/ui/disallowed_names.stderr index e412d27e7fca..09398ebbab77 100644 --- a/tests/ui/disallowed_names.stderr +++ b/tests/ui/disallowed_names.stderr @@ -8,79 +8,79 @@ LL | fn test(foo: ()) {} = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:18:9 + --> tests/ui/disallowed_names.rs:16:9 | LL | let foo = 42; | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:21:9 + --> tests/ui/disallowed_names.rs:19:9 | LL | let baz = 42; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:24:9 + --> tests/ui/disallowed_names.rs:22:9 | LL | let quux = 42; | ^^^^ error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:37:10 + --> tests/ui/disallowed_names.rs:35:10 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:37:20 + --> tests/ui/disallowed_names.rs:35:20 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:37:26 + --> tests/ui/disallowed_names.rs:35:26 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `foo` - --> tests/ui/disallowed_names.rs:48:19 + --> tests/ui/disallowed_names.rs:43:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:51:13 + --> tests/ui/disallowed_names.rs:46:13 | LL | let mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:54:21 + --> tests/ui/disallowed_names.rs:49:21 | LL | if let Some(mut quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:60:13 + --> tests/ui/disallowed_names.rs:54:13 | LL | let ref baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:63:21 + --> tests/ui/disallowed_names.rs:57:21 | LL | if let Some(ref quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> tests/ui/disallowed_names.rs:69:17 + --> tests/ui/disallowed_names.rs:62:17 | LL | let ref mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> tests/ui/disallowed_names.rs:72:25 + --> tests/ui/disallowed_names.rs:65: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 00308d0063a8..08fd1d9669ee 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -14,5 +14,4 @@ fn main() { // Same for japanese. let カウンタ = 10; //~^ disallowed_script_idents - } diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index e3b40a0cae11..b226ba69799e 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -20,10 +20,8 @@ fn main() { b || diverge(); //~^ diverging_sub_expression - b || A.foo(); //~^ diverging_sub_expression - } #[allow(dead_code, unused_variables)] diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 617c7a0be8ab..3e417aa39cd8 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -8,31 +8,31 @@ LL | b || diverge(); = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:24:10 + --> tests/ui/diverging_sub_expression.rs:23:10 | LL | b || A.foo(); | ^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:36:26 + --> tests/ui/diverging_sub_expression.rs:34:26 | LL | 6 => true || return, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:39:26 + --> tests/ui/diverging_sub_expression.rs:37:26 | LL | 7 => true || continue, | ^^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:44:26 + --> tests/ui/diverging_sub_expression.rs:42:26 | LL | 3 => true || diverge(), | ^^^^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:49:30 + --> tests/ui/diverging_sub_expression.rs:47:30 | LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ @@ -40,31 +40,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 - --> tests/ui/diverging_sub_expression.rs:54:29 + --> tests/ui/diverging_sub_expression.rs:52:29 | LL | 15 => true || { return; }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:57:30 + --> tests/ui/diverging_sub_expression.rs:55:30 | LL | 16 => false || { return; }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:61:29 + --> tests/ui/diverging_sub_expression.rs:59:29 | LL | 17 => true || { return }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:64:30 + --> tests/ui/diverging_sub_expression.rs:62:30 | LL | 18 => false || { return }, | ^^^^^^ error: sub-expression diverges - --> tests/ui/diverging_sub_expression.rs:75:26 + --> tests/ui/diverging_sub_expression.rs:73:26 | LL | _ => true || break, | ^^^^^ diff --git a/tests/ui/doc/issue_12795.fixed b/tests/ui/doc/issue_12795.fixed index ff252c07ae8c..4172438a82a6 100644 --- a/tests/ui/doc/issue_12795.fixed +++ b/tests/ui/doc/issue_12795.fixed @@ -6,8 +6,4 @@ //~| doc_markdown //~| doc_markdown - - - - pub fn main() {} diff --git a/tests/ui/doc/issue_12795.rs b/tests/ui/doc/issue_12795.rs index b7e89cf4ea0e..dbc03cc70865 100644 --- a/tests/ui/doc/issue_12795.rs +++ b/tests/ui/doc/issue_12795.rs @@ -6,8 +6,4 @@ //~| doc_markdown //~| doc_markdown - - - - pub fn main() {} diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index 65783b22a58c..f67e3216c01e 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -5,28 +5,27 @@ use std::io; pub fn pub_fn_missing_errors_header() -> Result<(), ()> { -//~^ missing_errors_doc - + //~^ missing_errors_doc unimplemented!(); } pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { -//~^ missing_errors_doc + //~^ missing_errors_doc unimplemented!(); } /// This is not sufficiently documented. pub fn pub_fn_returning_io_result() -> io::Result<()> { -//~^ missing_errors_doc + //~^ missing_errors_doc unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { -//~^ missing_errors_doc + //~^ missing_errors_doc unimplemented!(); } @@ -58,14 +57,14 @@ pub struct Struct1; impl Struct1 { /// This is not sufficiently documented. pub fn pub_method_missing_errors_header() -> Result<(), ()> { - //~^ missing_errors_doc + //~^ missing_errors_doc unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { - //~^ missing_errors_doc + //~^ missing_errors_doc unimplemented!(); } @@ -119,7 +118,6 @@ pub trait Trait1 { fn trait_method_missing_errors_header() -> Result<(), ()>; //~^ missing_errors_doc - /// # Errors /// A description of the errors goes here. fn trait_method_with_errors_header() -> Result<(), ()>; diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index e719c186e600..aeb2516e5123 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -8,37 +8,37 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { = help: to override `-D warnings` add `#[allow(clippy::missing_errors_doc)]` error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:14:1 + --> tests/ui/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 - --> tests/ui/doc_errors.rs:21:1 + --> tests/ui/doc_errors.rs:20:1 | LL | pub fn pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:28:1 + --> tests/ui/doc_errors.rs:27:1 | LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:60:5 + --> tests/ui/doc_errors.rs:59:5 | LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:67:5 + --> tests/ui/doc_errors.rs:66:5 | LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> tests/ui/doc_errors.rs:119:5 + --> tests/ui/doc_errors.rs:118:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index ccdc59bfb5a2..1bdf01e4e22e 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -7,7 +7,7 @@ use proc_macros::external; /// This is not sufficiently documented pub unsafe fn destroy_the_planet() { -//~^ missing_safety_doc + //~^ missing_safety_doc unimplemented!(); } @@ -31,7 +31,7 @@ mod private_mod { } pub unsafe fn republished() { - //~^ missing_safety_doc + //~^ missing_safety_doc unimplemented!(); } } @@ -47,7 +47,7 @@ pub trait SafeTraitUnsafeMethods { } pub unsafe trait UnsafeTrait { -//~^ missing_safety_doc + //~^ missing_safety_doc fn method(); } @@ -78,7 +78,7 @@ unsafe impl DocumentedUnsafeTrait for Struct { impl Struct { pub unsafe fn more_undocumented_unsafe() -> Self { - //~^ missing_safety_doc + //~^ missing_safety_doc unimplemented!(); } @@ -95,7 +95,7 @@ impl Struct { macro_rules! very_unsafe { () => { pub unsafe fn whee() { - //~^ missing_safety_doc + //~^ missing_safety_doc unimplemented!() } diff --git a/tests/ui/double_comparison.fixed b/tests/ui/double_comparison.fixed index e9d707cdb53d..685e3319bf9a 100644 --- a/tests/ui/double_comparison.fixed +++ b/tests/ui/double_comparison.fixed @@ -4,35 +4,35 @@ fn main() { let x = 1; let y = 2; if x <= y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x <= y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x >= y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x >= y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x != y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x != y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x == y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x == y { - //~^ double_comparisons + //~^ double_comparisons // do something } } diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs index 4b9a141747db..3670a050e88d 100644 --- a/tests/ui/double_comparison.rs +++ b/tests/ui/double_comparison.rs @@ -4,35 +4,35 @@ fn main() { let x = 1; let y = 2; if x == y || x < y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x < y || x == y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x == y || x > y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x > y || x == y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x < y || x > y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x > y || x < y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x <= y && x >= y { - //~^ double_comparisons + //~^ double_comparisons // do something } if x >= y && x <= y { - //~^ double_comparisons + //~^ double_comparisons // do something } } diff --git a/tests/ui/double_must_use.rs b/tests/ui/double_must_use.rs index 1f69afad25d4..3d4aaa9baa49 100644 --- a/tests/ui/double_must_use.rs +++ b/tests/ui/double_must_use.rs @@ -3,21 +3,21 @@ #[must_use] pub fn must_use_result() -> Result<(), ()> { -//~^ double_must_use + //~^ double_must_use unimplemented!(); } #[must_use] pub fn must_use_tuple() -> (Result<(), ()>, u8) { -//~^ double_must_use + //~^ double_must_use unimplemented!(); } #[must_use] pub fn must_use_array() -> [Result<(), ()>; 1] { -//~^ double_must_use + //~^ double_must_use unimplemented!(); } @@ -35,7 +35,7 @@ async fn async_must_use() -> usize { #[must_use] async fn async_must_use_result() -> Result<(), ()> { -//~^ double_must_use + //~^ double_must_use Ok(()) } diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index cb4930363e8f..b71f5a20a843 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -3,7 +3,6 @@ fn join_the_dark_side(darth: i32, _darth: i32) {} //~^ duplicate_underscore_argument - fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one fn main() { diff --git a/tests/ui/else_if_without_else.rs b/tests/ui/else_if_without_else.rs index 8c0df6ee8786..05d56600e100 100644 --- a/tests/ui/else_if_without_else.rs +++ b/tests/ui/else_if_without_else.rs @@ -49,7 +49,7 @@ fn main() { if bla1() { println!("if"); } else if bla2() { - //~^ else_if_without_else + //~^ else_if_without_else println!("else if"); } @@ -59,7 +59,7 @@ fn main() { } else if bla2() { println!("else if 1"); } else if bla3() { - //~^ else_if_without_else + //~^ else_if_without_else println!("else if 2"); } @@ -87,7 +87,7 @@ fn main() { } else if bla4() { println!("else if 3"); } else if bla5() { - //~^ else_if_without_else + //~^ else_if_without_else println!("else if 4"); } @@ -118,7 +118,7 @@ fn main() { } else if bla4() { println!("else if 3"); } else if bla5() { - //~^ else_if_without_else + //~^ else_if_without_else println!("else if 4"); } diff --git a/tests/ui/empty_drop.rs b/tests/ui/empty_drop.rs index c2dc7a0193a3..5793f783a724 100644 --- a/tests/ui/empty_drop.rs +++ b/tests/ui/empty_drop.rs @@ -5,7 +5,7 @@ struct Foo; impl Drop for Foo { -//~^ empty_drop + //~^ empty_drop fn drop(&mut self) {} } @@ -22,7 +22,7 @@ impl Drop for Bar { struct Baz; impl Drop for Baz { -//~^ empty_drop + //~^ empty_drop fn drop(&mut self) { {} } diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index cc22a76734fe..439fd0974f5f 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -5,5 +5,4 @@ enum Empty {} //~^ empty_enum - fn main() {} diff --git a/tests/ui/empty_enum_variants_with_brackets.fixed b/tests/ui/empty_enum_variants_with_brackets.fixed index 8316d3b8fd34..885f6a50025e 100644 --- a/tests/ui/empty_enum_variants_with_brackets.fixed +++ b/tests/ui/empty_enum_variants_with_brackets.fixed @@ -4,20 +4,20 @@ pub enum PublicTestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error -EmptyBraces, -//~^ empty_enum_variants_with_brackets -EmptyParentheses, -//~^ empty_enum_variants_with_brackets + EmptyBraces, + //~^ empty_enum_variants_with_brackets + EmptyParentheses, + //~^ empty_enum_variants_with_brackets } enum TestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error -EmptyBraces, -//~^ empty_enum_variants_with_brackets -EmptyParentheses, -//~^ empty_enum_variants_with_brackets - AnotherEnum, // No error + EmptyBraces, + //~^ empty_enum_variants_with_brackets + EmptyParentheses, + //~^ empty_enum_variants_with_brackets + AnotherEnum, // No error } enum TestEnumWithFeatures { diff --git a/tests/ui/empty_enum_variants_with_brackets.rs b/tests/ui/empty_enum_variants_with_brackets.rs index 6cce2533b979..092712ee2ead 100644 --- a/tests/ui/empty_enum_variants_with_brackets.rs +++ b/tests/ui/empty_enum_variants_with_brackets.rs @@ -4,20 +4,20 @@ pub enum PublicTestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error -EmptyBraces {}, -//~^ empty_enum_variants_with_brackets -EmptyParentheses(), -//~^ empty_enum_variants_with_brackets + EmptyBraces {}, + //~^ empty_enum_variants_with_brackets + EmptyParentheses(), + //~^ empty_enum_variants_with_brackets } enum TestEnum { NonEmptyBraces { x: i32, y: i32 }, // No error NonEmptyParentheses(i32, i32), // No error -EmptyBraces {}, -//~^ empty_enum_variants_with_brackets -EmptyParentheses(), -//~^ empty_enum_variants_with_brackets - AnotherEnum, // No error + EmptyBraces {}, + //~^ empty_enum_variants_with_brackets + EmptyParentheses(), + //~^ empty_enum_variants_with_brackets + AnotherEnum, // No error } enum TestEnumWithFeatures { diff --git a/tests/ui/empty_enum_variants_with_brackets.stderr b/tests/ui/empty_enum_variants_with_brackets.stderr index f49e526584c8..a9ae3b476dd6 100644 --- a/tests/ui/empty_enum_variants_with_brackets.stderr +++ b/tests/ui/empty_enum_variants_with_brackets.stderr @@ -1,34 +1,34 @@ error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:7:12 + --> tests/ui/empty_enum_variants_with_brackets.rs:7:16 | -LL | EmptyBraces {}, - | ^^^ +LL | EmptyBraces {}, + | ^^^ | = note: `-D clippy::empty-enum-variants-with-brackets` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_enum_variants_with_brackets)]` = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:9:17 + --> tests/ui/empty_enum_variants_with_brackets.rs:9:21 | -LL | EmptyParentheses(), - | ^^ +LL | EmptyParentheses(), + | ^^ | = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:16:12 + --> tests/ui/empty_enum_variants_with_brackets.rs:16:16 | -LL | EmptyBraces {}, - | ^^^ +LL | EmptyBraces {}, + | ^^^ | = help: remove the brackets error: enum variant has empty brackets - --> tests/ui/empty_enum_variants_with_brackets.rs:18:17 + --> tests/ui/empty_enum_variants_with_brackets.rs:18:21 | -LL | EmptyParentheses(), - | ^^ +LL | EmptyParentheses(), + | ^^ | = help: remove the brackets diff --git a/tests/ui/empty_line_after/doc_comments.1.fixed b/tests/ui/empty_line_after/doc_comments.1.fixed index cf2cc497799f..c1a15f47ba10 100644 --- a/tests/ui/empty_line_after/doc_comments.1.fixed +++ b/tests/ui/empty_line_after/doc_comments.1.fixed @@ -1,6 +1,5 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] - /// Meant to be an /// inner doc comment /// for the crate @@ -23,14 +22,12 @@ mod some_mod { fn some_noop() {} } - /// # Indented //~^ empty_line_after_doc_comments /// Blank line fn indented() {} } - /// This should produce a warning //~^ empty_line_after_doc_comments fn with_doc_and_newline() {} @@ -40,7 +37,6 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} - /// This doc comment should produce a warning //~^ empty_line_after_doc_comments /** This is also a doc comment and is part of the warning @@ -57,7 +53,6 @@ mod misattributed { // fn old_code() {} fn new_code() {} - /// Docs /// for OldA //~^ empty_line_after_doc_comments @@ -74,23 +69,21 @@ mod misattributed { mod block_comments { /** - //~^ empty_line_after_doc_comments * Meant to be inner doc comment */ + //~^^^ empty_line_after_doc_comments fn first_in_module() {} - /** - //~^ empty_line_after_doc_comments * Docs for `old_code` */ + //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** * Docs for `new_code` */ fn new_code() {} - /// Docs for `old_code2` //~^ empty_line_after_doc_comments /* fn old_code2() {} */ diff --git a/tests/ui/empty_line_after/doc_comments.2.fixed b/tests/ui/empty_line_after/doc_comments.2.fixed index ee02e2f87d2d..abec7b54c632 100644 --- a/tests/ui/empty_line_after/doc_comments.2.fixed +++ b/tests/ui/empty_line_after/doc_comments.2.fixed @@ -1,6 +1,5 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] - // /// Meant to be an // /// inner doc comment // /// for the crate @@ -25,7 +24,6 @@ mod some_mod { fn some_noop() {} } - // /// # Indented //~^ empty_line_after_doc_comments @@ -33,7 +31,6 @@ mod some_mod { fn indented() {} } - // /// This should produce a warning //~^ empty_line_after_doc_comments @@ -44,7 +41,6 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} - // /// This doc comment should produce a warning //~^ empty_line_after_doc_comments @@ -64,7 +60,6 @@ mod misattributed { fn new_code() {} - // /// Docs // /// for OldA //~^ empty_line_after_doc_comments @@ -82,18 +77,17 @@ mod misattributed { mod block_comments { - /*! - //~^ empty_line_after_doc_comments + /* * Meant to be inner doc comment */ + //~^^^ empty_line_after_doc_comments fn first_in_module() {} - /* - //~^ empty_line_after_doc_comments * Docs for `old_code` */ + //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** @@ -101,7 +95,6 @@ mod block_comments { */ fn new_code() {} - // /// Docs for `old_code2` //~^ empty_line_after_doc_comments /* fn old_code2() {} */ diff --git a/tests/ui/empty_line_after/doc_comments.rs b/tests/ui/empty_line_after/doc_comments.rs index 789f14f39777..d225768f6125 100644 --- a/tests/ui/empty_line_after/doc_comments.rs +++ b/tests/ui/empty_line_after/doc_comments.rs @@ -1,6 +1,5 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] - /// Meant to be an /// inner doc comment /// for the crate @@ -25,7 +24,6 @@ mod some_mod { fn some_noop() {} } - /// # Indented //~^ empty_line_after_doc_comments @@ -33,7 +31,6 @@ mod some_mod { fn indented() {} } - /// This should produce a warning //~^ empty_line_after_doc_comments @@ -44,7 +41,6 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} - /// This doc comment should produce a warning //~^ empty_line_after_doc_comments @@ -64,7 +60,6 @@ mod misattributed { fn new_code() {} - /// Docs /// for OldA //~^ empty_line_after_doc_comments @@ -83,17 +78,16 @@ mod misattributed { mod block_comments { /** - //~^ empty_line_after_doc_comments * Meant to be inner doc comment */ + //~^^^ empty_line_after_doc_comments fn first_in_module() {} - /** - //~^ empty_line_after_doc_comments * Docs for `old_code` */ + //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** @@ -101,7 +95,6 @@ mod block_comments { */ fn new_code() {} - /// Docs for `old_code2` //~^ empty_line_after_doc_comments /* fn old_code2() {} */ diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index 91745dac3a79..9b627e8df1ff 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -1,5 +1,5 @@ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:6:1 + --> tests/ui/empty_line_after/doc_comments.rs:5:1 | LL | / /// for the crate LL | | @@ -19,7 +19,7 @@ LL ~ // /// for the crate | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:15:5 + --> tests/ui/empty_line_after/doc_comments.rs:14:5 | LL | / /// for the module LL | | @@ -37,7 +37,7 @@ LL ~ // /// for the module | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:29:5 + --> tests/ui/empty_line_after/doc_comments.rs:27:5 | LL | / /// # Indented LL | | @@ -54,7 +54,7 @@ LL | // /// # Indented | ++ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:37:1 + --> tests/ui/empty_line_after/doc_comments.rs:34:1 | LL | / /// This should produce a warning LL | | @@ -70,7 +70,7 @@ LL | // /// This should produce a warning | ++ error: empty lines after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:48:1 + --> tests/ui/empty_line_after/doc_comments.rs:44:1 | LL | / /// This doc comment should produce a warning LL | | @@ -93,7 +93,7 @@ LL ~ /* This is also a doc comment and is part of the warning | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:61:5 + --> tests/ui/empty_line_after/doc_comments.rs:57:5 | LL | / /// docs for `old_code` ... | @@ -109,7 +109,7 @@ LL | // /// docs for `old_code` | ++ error: empty lines after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:69:5 + --> tests/ui/empty_line_after/doc_comments.rs:64:5 | LL | / /// for OldA ... | @@ -132,31 +132,31 @@ LL ~ // /// for OldB | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:85:5 + --> tests/ui/empty_line_after/doc_comments.rs:80:5 | LL | / /** -LL | | LL | | * Meant to be inner doc comment LL | | */ +LL | | LL | | | |_^ LL | fn first_in_module() {} | -------------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the comment should document the parent module use an inner doc comment +help: if the doc comment should not document `first_in_module` comment it out + | +LL - /** +LL + /* | -LL | /*! - | ~ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:93:5 + --> tests/ui/empty_line_after/doc_comments.rs:87:5 | LL | / /** -LL | | LL | | * Docs for `old_code` LL | | */ -LL | | /* fn old_code() {} */ +... | LL | | | |_^ ... @@ -171,7 +171,7 @@ LL + /* | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:105:5 + --> tests/ui/empty_line_after/doc_comments.rs:98:5 | LL | / /// Docs for `old_code2` LL | | diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs index c3b2bafe2f87..6407bd678f9c 100644 --- a/tests/ui/empty_loop_no_std.rs +++ b/tests/ui/empty_loop_no_std.rs @@ -9,5 +9,4 @@ pub fn main(argc: isize, argv: *const *const u8) -> isize { // This should trigger the lint loop {} //~^ empty_loop - } diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index 87dc7a8de920..9856fa9b39fd 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -25,7 +25,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on insert, use or_insert_with(..) m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry if true { v } else { @@ -35,7 +35,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on if, use or_insert_with(..) m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry if true { v } else { @@ -45,7 +45,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // early return, use if let if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { - //~^ map_entry + //~^ map_entry if true { e.insert(v); } else { @@ -56,14 +56,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with(..) m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry foo(); v }); // semicolon on insert and match, use or_insert_with(..) m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry match 0 { 1 if true => { v @@ -76,7 +76,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // one branch doesn't insert, use if let if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { - //~^ map_entry + //~^ map_entry match 0 { 0 => foo(), _ => { @@ -87,7 +87,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry foo(); match 0 { 0 if false => { @@ -152,7 +152,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // or_insert_with. Partial move of a local declared in the closure is ok. m.entry(k).or_insert_with(|| { - //~^ map_entry + //~^ map_entry let x = (String::new(), String::new()); let _ = x.0; v @@ -186,7 +186,7 @@ pub fn issue_11935() { fn issue12489(map: &mut HashMap) -> Option<()> { if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) { - //~^ map_entry + //~^ map_entry let Some(1) = Some(2) else { return None; }; diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index c795d3b97590..bb8ebb4eac08 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -22,13 +22,13 @@ fn foo() {} fn hash_map(m: &mut HashMap, m2: &mut HashMap, k: K, k2: K, v: V, v2: V) { // or_insert(v) if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); } // semicolon on insert, use or_insert_with(..) if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry if true { m.insert(k, v); } else { @@ -38,7 +38,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // semicolon on if, use or_insert_with(..) if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry if true { m.insert(k, v) } else { @@ -48,7 +48,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // early return, use if let if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry if true { m.insert(k, v); } else { @@ -59,14 +59,14 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with(..) if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry foo(); m.insert(k, v); } // semicolon on insert and match, use or_insert_with(..) if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry match 0 { 1 if true => { m.insert(k, v); @@ -79,7 +79,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // one branch doesn't insert, use if let if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry match 0 { 0 => foo(), _ => { @@ -90,7 +90,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // use or_insert_with if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry foo(); match 0 { 0 if false => { @@ -125,7 +125,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // macro_expansion test, use or_insert(..) if !m.contains_key(&m!(k)) { - //~^ map_entry + //~^ map_entry m.insert(m!(k), m!(v)); } @@ -158,7 +158,7 @@ fn hash_map(m: &mut HashMap, m2: &mut HashMa // or_insert_with. Partial move of a local declared in the closure is ok. if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry let x = (String::new(), String::new()); let _ = x.0; m.insert(k, v); @@ -192,7 +192,7 @@ pub fn issue_11935() { fn issue12489(map: &mut HashMap) -> Option<()> { if !map.contains_key(&1) { - //~^ map_entry + //~^ map_entry let Some(1) = Some(2) else { return None; }; diff --git a/tests/ui/entry_btree.fixed b/tests/ui/entry_btree.fixed index 518f503475fc..1218202f02b9 100644 --- a/tests/ui/entry_btree.fixed +++ b/tests/ui/entry_btree.fixed @@ -8,7 +8,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { - //~^ map_entry + //~^ map_entry e.insert(v); foo(); } diff --git a/tests/ui/entry_btree.rs b/tests/ui/entry_btree.rs index 4e4b3a502e03..b795e32158ad 100644 --- a/tests/ui/entry_btree.rs +++ b/tests/ui/entry_btree.rs @@ -8,7 +8,7 @@ fn foo() {} fn btree_map(m: &mut BTreeMap, k: K, v: V) { // insert then do something, use if let if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); foo(); } diff --git a/tests/ui/entry_with_else.fixed b/tests/ui/entry_with_else.fixed index 995611803908..76e6998235c2 100644 --- a/tests/ui/entry_with_else.fixed +++ b/tests/ui/entry_with_else.fixed @@ -13,7 +13,7 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { - //~^ map_entry + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Occupied(mut e) => { @@ -23,7 +23,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { - //~^ map_entry + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Vacant(e) => { @@ -32,7 +32,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, } if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) { - //~^ map_entry + //~^ map_entry e.insert(v); } else { foo(); @@ -41,13 +41,13 @@ fn insert_if_absent0(m: &mut HashMap, k: K, if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { e.insert(v); } else { - //~^ map_entry + //~^ map_entry foo(); } match m.entry(k) { std::collections::hash_map::Entry::Vacant(e) => { - //~^ map_entry + //~^ map_entry e.insert(v); } std::collections::hash_map::Entry::Occupied(mut e) => { @@ -57,7 +57,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, match m.entry(k) { std::collections::hash_map::Entry::Occupied(mut e) => { - //~^ map_entry + //~^ map_entry if true { Some(e.insert(v)) } else { Some(e.insert(v2)) } } std::collections::hash_map::Entry::Vacant(e) => { @@ -67,7 +67,7 @@ fn insert_if_absent0(m: &mut HashMap, k: K, }; if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) { - //~^ map_entry + //~^ map_entry foo(); Some(e.insert(v)) } else { diff --git a/tests/ui/entry_with_else.rs b/tests/ui/entry_with_else.rs index dcfafedc11f8..1669cdc0c7cf 100644 --- a/tests/ui/entry_with_else.rs +++ b/tests/ui/entry_with_else.rs @@ -12,49 +12,49 @@ fn foo() {} fn insert_if_absent0(m: &mut HashMap, k: K, v: V, v2: V) { if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); } else { foo(); } if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry foo(); } else { m.insert(k, v); } if !m.contains_key(&k) { - //~^ map_entry + //~^ map_entry m.insert(k, v); } else { m.insert(k, v2); } if m.contains_key(&k) { - //~^ map_entry + //~^ map_entry if true { m.insert(k, v) } else { m.insert(k, v2) } } else { m.insert(k, v) }; if m.contains_key(&k) { - //~^ map_entry + //~^ map_entry foo(); m.insert(k, v) } else { diff --git a/tests/ui/enum_clike_unportable_variant.rs b/tests/ui/enum_clike_unportable_variant.rs index f54cca9c611c..4ff2024b25e9 100644 --- a/tests/ui/enum_clike_unportable_variant.rs +++ b/tests/ui/enum_clike_unportable_variant.rs @@ -7,8 +7,6 @@ enum NonPortable { X = 0x1_0000_0000, //~^ enum_clike_unportable_variant - - Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, @@ -17,12 +15,10 @@ enum NonPortable { enum NonPortableNoHint { X = 0x1_0000_0000, //~^ enum_clike_unportable_variant - Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, //~^ enum_clike_unportable_variant - } #[repr(isize)] @@ -31,14 +27,11 @@ enum NonPortableSigned { Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, //~^ enum_clike_unportable_variant - A = 0x1_0000_0000, //~^ enum_clike_unportable_variant - B = i32::MIN as isize, C = (i32::MIN as isize) - 1, //~^ enum_clike_unportable_variant - } enum NonPortableSignedNoHint { @@ -46,17 +39,14 @@ enum NonPortableSignedNoHint { Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, //~^ enum_clike_unportable_variant - A = 0x1_0000_0000, //~^ enum_clike_unportable_variant - } #[repr(usize)] enum NonPortable2 { X = ::Number, //~^ enum_clike_unportable_variant - Y = 0, } diff --git a/tests/ui/enum_clike_unportable_variant.stderr b/tests/ui/enum_clike_unportable_variant.stderr index ade2106ad96c..5a022a6fe8a6 100644 --- a/tests/ui/enum_clike_unportable_variant.stderr +++ b/tests/ui/enum_clike_unportable_variant.stderr @@ -8,49 +8,49 @@ LL | X = 0x1_0000_0000, = help: to override `-D warnings` add `#[allow(clippy::enum_clike_unportable_variant)]` error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:18:5 + --> tests/ui/enum_clike_unportable_variant.rs:16:5 | LL | X = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:23:5 + --> tests/ui/enum_clike_unportable_variant.rs:20:5 | LL | A = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:32:5 + --> tests/ui/enum_clike_unportable_variant.rs:28:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:35:5 + --> tests/ui/enum_clike_unportable_variant.rs:30:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:39:5 + --> tests/ui/enum_clike_unportable_variant.rs:33:5 | LL | C = (i32::MIN as isize) - 1, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:47:5 + --> tests/ui/enum_clike_unportable_variant.rs:40:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:50:5 + --> tests/ui/enum_clike_unportable_variant.rs:42:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> tests/ui/enum_clike_unportable_variant.rs:57:5 + --> tests/ui/enum_clike_unportable_variant.rs:48:5 | LL | X = ::Number, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index f3c81b2111ce..f7bbf83654f1 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -12,7 +12,7 @@ enum FakeCallType2 { } enum Foo { -//~^ enum_variant_names + //~^ enum_variant_names cFoo, //~^ enum_variant_names cBar, @@ -25,7 +25,7 @@ enum Fooo { } enum Food { -//~^ enum_variant_names + //~^ enum_variant_names FoodGood, //~^ enum_variant_names FoodMiddle, @@ -39,8 +39,7 @@ enum Stuff { } enum BadCallType { -//~^ enum_variant_names - + //~^ enum_variant_names CallTypeCall, CallTypeCreate, CallTypeDestroy, @@ -53,7 +52,7 @@ enum TwoCallType { } enum Consts { -//~^ enum_variant_names + //~^ enum_variant_names ConstantInt, ConstantCake, ConstantLie, @@ -66,7 +65,7 @@ enum Two { } enum Something { -//~^ enum_variant_names + //~^ enum_variant_names CCall, CCreate, CCryogenize, @@ -89,7 +88,7 @@ enum Sealll { } enum Seallll { -//~^ enum_variant_names + //~^ enum_variant_names WithOutCake, WithOutTea, WithOut, @@ -145,14 +144,14 @@ pub enum NetworkLayer { // should lint suggesting `IData`, not only `Data` (see #4639) enum IDataRequest { -//~^ enum_variant_names + //~^ enum_variant_names PutIData(String), GetIData(String), DeleteUnpubIData(String), } enum HIDataRequest { -//~^ enum_variant_names + //~^ enum_variant_names PutHIData(String), GetHIData(String), DeleteUnpubHIData(String), @@ -173,7 +172,7 @@ enum Phase { mod issue9018 { enum DoLint { - //~^ enum_variant_names + //~^ enum_variant_names _TypeCreate, _TypeRead, _TypeUpdate, @@ -181,7 +180,7 @@ mod issue9018 { } enum DoLintToo { - //~^ enum_variant_names + //~^ enum_variant_names _CreateType, _UpdateType, _DeleteType, diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index 2f0b0e6149d2..cca9d50033cf 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -55,7 +55,6 @@ error: all variants have the same prefix: `CallType` | LL | / enum BadCallType { LL | | -LL | | LL | | CallTypeCall, LL | | CallTypeCreate, LL | | CallTypeDestroy, @@ -65,7 +64,7 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `Constant` - --> tests/ui/enum_variants.rs:55:1 + --> tests/ui/enum_variants.rs:54:1 | LL | / enum Consts { LL | | @@ -78,7 +77,7 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `C` - --> tests/ui/enum_variants.rs:68:1 + --> tests/ui/enum_variants.rs:67:1 | LL | / enum Something { LL | | @@ -91,7 +90,7 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `WithOut` - --> tests/ui/enum_variants.rs:91:1 + --> tests/ui/enum_variants.rs:90:1 | LL | / enum Seallll { LL | | @@ -104,7 +103,7 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `IData` - --> tests/ui/enum_variants.rs:147:1 + --> tests/ui/enum_variants.rs:146:1 | LL | / enum IDataRequest { LL | | @@ -117,7 +116,7 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `HIData` - --> tests/ui/enum_variants.rs:154:1 + --> tests/ui/enum_variants.rs:153:1 | LL | / enum HIDataRequest { LL | | @@ -130,7 +129,7 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `_Type` - --> tests/ui/enum_variants.rs:175:5 + --> tests/ui/enum_variants.rs:174:5 | LL | / enum DoLint { LL | | @@ -144,7 +143,7 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `Type` - --> tests/ui/enum_variants.rs:183:5 + --> tests/ui/enum_variants.rs:182:5 | LL | / enum DoLintToo { LL | | @@ -157,13 +156,13 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: variant name starts with the enum's name - --> tests/ui/enum_variants.rs:212:9 + --> tests/ui/enum_variants.rs:211:9 | LL | DataDependent, | ^^^^^^^^^^^^^ error: variant name starts with the enum's name - --> tests/ui/enum_variants.rs:217:9 + --> tests/ui/enum_variants.rs:216:9 | LL | DatasDependent, | ^^^^^^^^^^^^^^ diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index cb6cff419e9d..c50a707ace92 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -5,7 +5,6 @@ fn main() { eprintln!("Hello"); //~^ print_with_newline - eprintln!("Hello {}", "world"); //~^ print_with_newline @@ -18,7 +17,6 @@ fn main() { eprintln!(); //~^ print_with_newline - // these are all fine eprint!(""); eprint!("Hello"); @@ -50,13 +48,11 @@ fn main() { // Literal newlines should also fail eprintln!( - //~^ print_with_newline - + //~^ print_with_newline ); eprintln!( - //~^ print_with_newline - + //~^ print_with_newline ); diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs index cfe503cec1f1..2c90480bdc78 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -5,7 +5,6 @@ fn main() { eprint!("Hello\n"); //~^ print_with_newline - eprint!("Hello {}\n", "world"); //~^ print_with_newline @@ -18,7 +17,6 @@ fn main() { eprint!("\n"); //~^ print_with_newline - // these are all fine eprint!(""); eprint!("Hello"); @@ -50,14 +48,12 @@ fn main() { // Literal newlines should also fail eprint!( - //~^ print_with_newline - + //~^ print_with_newline " " ); eprint!( - //~^ print_with_newline - + //~^ print_with_newline r" " ); diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 87dcb9126b6d..c78cffd40c99 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -13,7 +13,7 @@ LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:9:5 + --> tests/ui/eprint_with_newline.rs:8:5 | LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:12:5 + --> tests/ui/eprint_with_newline.rs:11:5 | LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:15:5 + --> tests/ui/eprint_with_newline.rs:14:5 | LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:18:5 + --> tests/ui/eprint_with_newline.rs:17:5 | LL | eprint!("\n"); | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:42:5 + --> tests/ui/eprint_with_newline.rs:40:5 | LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ @@ -73,11 +73,10 @@ LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:52:5 + --> tests/ui/eprint_with_newline.rs:50:5 | LL | / eprint!( LL | | -LL | | LL | | " LL | | " LL | | ); @@ -87,16 +86,14 @@ help: use `eprintln!` instead | LL ~ eprintln!( LL | -LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:58:5 + --> tests/ui/eprint_with_newline.rs:55:5 | LL | / eprint!( LL | | -LL | | LL | | r" LL | | " LL | | ); @@ -106,12 +103,11 @@ help: use `eprintln!` instead | LL ~ eprintln!( LL | -LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> tests/ui/eprint_with_newline.rs:68:5 + --> tests/ui/eprint_with_newline.rs:64:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index 757a7e011903..ced0452ee9a8 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -7,7 +7,6 @@ fn main() { let _ = 1 == 1; //~^ eq_op - let _ = "no" == "no"; //~^ eq_op @@ -25,8 +24,6 @@ fn main() { let _ = x != x; //~^ eq_op - - // casts, methods, parentheses let _ = (1u32 as u64) & (1u32 as u64); //~^ eq_op @@ -47,12 +44,9 @@ fn main() { //~| eq_op //~| eq_op - - let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~^ eq_op - // various other things let _ = ([1] != [1]); //~^ eq_op @@ -70,8 +64,6 @@ fn main() { //~^ eq_op //~| eq_op - - let _ = 1 - 1; //~^ eq_op @@ -81,11 +73,9 @@ fn main() { let _ = true && true; //~^ eq_op - let _ = true || true; //~^ eq_op - let a: u32 = 0; let b: u32 = 0; @@ -101,7 +91,6 @@ fn main() { let _ = a <= b && b >= a; //~^ eq_op - let mut a = vec![1]; let _ = a == a; //~^ eq_op @@ -117,7 +106,6 @@ fn main() { const C: u32 = A / B; // ok, different named constants const D: u32 = A / A; //~^ eq_op - } macro_rules! check_if_named_foo { @@ -150,7 +138,6 @@ 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 //~^ eq_op - } #[test] diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index bd9362f3e0dd..1696f09d6d17 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -8,31 +8,31 @@ LL | let _ = 1 == 1; = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:11:13 + --> tests/ui/eq_op.rs:10:13 | LL | let _ = "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:15:13 + --> tests/ui/eq_op.rs:14:13 | LL | let _ = false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> tests/ui/eq_op.rs:18:13 + --> tests/ui/eq_op.rs:17:13 | LL | let _ = 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> tests/ui/eq_op.rs:21:13 + --> tests/ui/eq_op.rs:20:13 | LL | let _ = 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:25:13 + --> tests/ui/eq_op.rs:24:13 | LL | let _ = x != x; | ^^^^^^ @@ -40,139 +40,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 `&` - --> tests/ui/eq_op.rs:31:13 + --> tests/ui/eq_op.rs:28:13 | LL | let _ = (1u32 as u64) & (1u32 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> tests/ui/eq_op.rs:36:17 + --> tests/ui/eq_op.rs:33:17 | LL | let _ = 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> tests/ui/eq_op.rs:42:13 + --> tests/ui/eq_op.rs:39:13 | LL | let _ = (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:45:13 + --> tests/ui/eq_op.rs:42:13 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> tests/ui/eq_op.rs:45:14 + --> tests/ui/eq_op.rs:42:14 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> tests/ui/eq_op.rs:45:35 + --> tests/ui/eq_op.rs:42:35 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:52:13 + --> tests/ui/eq_op.rs:47:13 | LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:57:13 + --> tests/ui/eq_op.rs:51:13 | LL | let _ = ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/eq_op.rs:60:13 + --> tests/ui/eq_op.rs:54:13 | LL | let _ = ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:66:13 + --> tests/ui/eq_op.rs:60:13 | LL | let _ = 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:69:13 + --> tests/ui/eq_op.rs:63:13 | LL | let _ = 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> tests/ui/eq_op.rs:69:13 + --> tests/ui/eq_op.rs:63:13 | LL | let _ = 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> tests/ui/eq_op.rs:75:13 + --> tests/ui/eq_op.rs:67:13 | LL | let _ = 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> tests/ui/eq_op.rs:78:13 + --> tests/ui/eq_op.rs:70:13 | LL | let _ = 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:81:13 + --> tests/ui/eq_op.rs:73:13 | LL | let _ = true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> tests/ui/eq_op.rs:85:13 + --> tests/ui/eq_op.rs:76:13 | LL | let _ = true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:92:13 + --> tests/ui/eq_op.rs:82:13 | LL | let _ = a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:95:13 + --> tests/ui/eq_op.rs:85:13 | LL | let _ = a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:98:13 + --> tests/ui/eq_op.rs:88:13 | LL | let _ = a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> tests/ui/eq_op.rs:101:13 + --> tests/ui/eq_op.rs:91:13 | LL | let _ = a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:106:13 + --> tests/ui/eq_op.rs:95:13 | LL | let _ = a == a; | ^^^^^^ error: equal expressions as operands to `/` - --> tests/ui/eq_op.rs:118:20 + --> tests/ui/eq_op.rs:107:20 | LL | const D: u32 = A / A; | ^^^^^ error: equal expressions as operands to `==` - --> tests/ui/eq_op.rs:151:5 + --> tests/ui/eq_op.rs:139: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/equatable_if_let.fixed b/tests/ui/equatable_if_let.fixed index 2f39c34cb394..166b1387ba26 100644 --- a/tests/ui/equatable_if_let.fixed +++ b/tests/ui/equatable_if_let.fixed @@ -97,7 +97,7 @@ fn main() { //~^ equatable_if_let if "abc" == inline!("abc") { - //~^ equatable_if_let + //~^ equatable_if_let println!("OK"); } diff --git a/tests/ui/equatable_if_let.rs b/tests/ui/equatable_if_let.rs index f7289a9ee56f..09c2483ae6d4 100644 --- a/tests/ui/equatable_if_let.rs +++ b/tests/ui/equatable_if_let.rs @@ -97,7 +97,7 @@ fn main() { //~^ equatable_if_let if let inline!("abc") = "abc" { - //~^ equatable_if_let + //~^ equatable_if_let println!("OK"); } diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index 9387a20cb5a0..9237b9eb11f0 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -35,7 +35,6 @@ fn test(x: u8) { x * 0; //~^ erasing_op - 0 & x; //~^ erasing_op @@ -48,7 +47,6 @@ fn test(x: u8) { Vec1 { x: 5 } * 0; //~^ erasing_op - } fn main() { diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 7029fac6c130..94730b066801 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -8,25 +8,25 @@ LL | x * 0; = help: to override `-D warnings` add `#[allow(clippy::erasing_op)]` error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:39:5 + --> tests/ui/erasing_op.rs:38:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:42:5 + --> tests/ui/erasing_op.rs:41:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:46:5 + --> tests/ui/erasing_op.rs:45:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/erasing_op.rs:49:5 + --> tests/ui/erasing_op.rs:48:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/error_impl_error.rs b/tests/ui/error_impl_error.rs index 3606e1bcefbb..5c88888f38ea 100644 --- a/tests/ui/error_impl_error.rs +++ b/tests/ui/error_impl_error.rs @@ -7,7 +7,6 @@ pub mod a { pub struct Error; //~^ error_impl_error - impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { todo!() @@ -22,7 +21,6 @@ mod b { pub(super) enum Error {} //~^ error_impl_error - impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { todo!() @@ -34,8 +32,7 @@ mod b { pub mod c { pub union Error { - //~^ error_impl_error - + //~^ error_impl_error a: u32, b: u32, } @@ -58,7 +55,6 @@ pub mod c { pub mod d { pub type Error = std::fmt::Error; //~^ error_impl_error - } mod e { diff --git a/tests/ui/error_impl_error.stderr b/tests/ui/error_impl_error.stderr index 4fa1ffeb4c92..087d43d1d083 100644 --- a/tests/ui/error_impl_error.stderr +++ b/tests/ui/error_impl_error.stderr @@ -5,7 +5,7 @@ LL | pub struct Error; | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:17:5 + --> tests/ui/error_impl_error.rs:16:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,31 +13,31 @@ LL | impl std::error::Error for Error {} = help: to override `-D warnings` add `#[allow(clippy::error_impl_error)]` error: exported type named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:22:21 + --> tests/ui/error_impl_error.rs:21:21 | LL | pub(super) enum Error {} | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:32:5 + --> tests/ui/error_impl_error.rs:30:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:36:15 + --> tests/ui/error_impl_error.rs:34:15 | LL | pub union Error { | ^^^^^ | note: `Error` was implemented here - --> tests/ui/error_impl_error.rs:55:5 + --> tests/ui/error_impl_error.rs:52:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type alias named `Error` that implements `Error` - --> tests/ui/error_impl_error.rs:59:14 + --> tests/ui/error_impl_error.rs:56:14 | LL | pub type Error = std::fmt::Error; | ^^^^^ diff --git a/tests/ui/exhaustive_items.fixed b/tests/ui/exhaustive_items.fixed index a3c584c2a269..79c74aeefbd8 100644 --- a/tests/ui/exhaustive_items.fixed +++ b/tests/ui/exhaustive_items.fixed @@ -8,7 +8,7 @@ fn main() { pub mod enums { #[non_exhaustive] pub enum Exhaustive { - //~^ exhaustive_enums + //~^ exhaustive_enums Foo, Bar, Baz, @@ -19,7 +19,7 @@ pub mod enums { #[repr(C)] #[non_exhaustive] pub enum ExhaustiveWithAttrs { - //~^ exhaustive_enums + //~^ exhaustive_enums Foo, Bar, Baz, @@ -56,7 +56,7 @@ pub mod enums { pub mod structs { #[non_exhaustive] pub struct Exhaustive { - //~^ exhaustive_structs + //~^ exhaustive_structs pub foo: u8, pub bar: String, } diff --git a/tests/ui/exhaustive_items.rs b/tests/ui/exhaustive_items.rs index b1f0c789b709..4e851f4c492e 100644 --- a/tests/ui/exhaustive_items.rs +++ b/tests/ui/exhaustive_items.rs @@ -7,7 +7,7 @@ fn main() { pub mod enums { pub enum Exhaustive { - //~^ exhaustive_enums + //~^ exhaustive_enums Foo, Bar, Baz, @@ -17,7 +17,7 @@ pub mod enums { /// Some docs #[repr(C)] pub enum ExhaustiveWithAttrs { - //~^ exhaustive_enums + //~^ exhaustive_enums Foo, Bar, Baz, @@ -53,7 +53,7 @@ pub mod enums { pub mod structs { pub struct Exhaustive { - //~^ exhaustive_structs + //~^ exhaustive_structs pub foo: u8, pub bar: String, } diff --git a/tests/ui/exit1.rs b/tests/ui/exit1.rs index 127c72aac99f..be8752cc7d8e 100644 --- a/tests/ui/exit1.rs +++ b/tests/ui/exit1.rs @@ -4,8 +4,6 @@ fn not_main() { if true { std::process::exit(4); //~^ exit - - } } diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs index 2e2c4828afe6..2be8a84b6d4b 100644 --- a/tests/ui/exit2.rs +++ b/tests/ui/exit2.rs @@ -3,8 +3,6 @@ fn also_not_main() { std::process::exit(3); //~^ exit - - } fn main() { diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs index 575c29e6f31c..8f7379f00214 100644 --- a/tests/ui/expect.rs +++ b/tests/ui/expect.rs @@ -5,7 +5,6 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); //~^ expect_used - } fn expect_result() { @@ -15,7 +14,6 @@ fn expect_result() { let _ = res.expect_err(""); //~^ expect_used - } fn main() { diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index b44429a3b71d..70cf3072003e 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -9,7 +9,7 @@ LL | let _ = opt.expect(""); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value - --> tests/ui/expect.rs:13:13 + --> tests/ui/expect.rs:12:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value - --> tests/ui/expect.rs:16:13 + --> tests/ui/expect.rs:15:13 | LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index 585e261c2f43..8340d99ace22 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -5,8 +5,7 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; for _v in &vec { - //~^ explicit_counter_loop - + //~^ explicit_counter_loop _index += 1 } @@ -14,21 +13,21 @@ fn main() { let mut _index = 1; _index = 0; for _v in &vec { - //~^ explicit_counter_loop + //~^ explicit_counter_loop _index += 1 } let mut _index = 0; for _v in &mut vec { - //~^ explicit_counter_loop + //~^ explicit_counter_loop _index += 1; } let mut _index = 0; for _v in vec { - //~^ explicit_counter_loop + //~^ explicit_counter_loop _index += 1; } @@ -117,7 +116,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { - //~^ explicit_counter_loop + //~^ explicit_counter_loop println!("{}", count); count += 1; @@ -130,7 +129,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { - //~^ explicit_counter_loop + //~^ explicit_counter_loop println!("{}", count); count += 1; @@ -190,7 +189,7 @@ mod issue_1670 { pub fn test() { let mut count = 0; for _i in 3..10 { - //~^ explicit_counter_loop + //~^ explicit_counter_loop count += 1; } @@ -232,7 +231,7 @@ mod issue_7920 { // should suggest `enumerate` for _item in slice { - //~^ explicit_counter_loop + //~^ explicit_counter_loop if idx_usize == index_usize { break; @@ -246,8 +245,7 @@ mod issue_7920 { // should suggest `zip` for _item in slice { - //~^ explicit_counter_loop - + //~^ explicit_counter_loop if idx_u32 == index_u32 { break; @@ -293,7 +291,7 @@ mod issue_13123 { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; 'label: for v in vec { - //~^ explicit_counter_loop + //~^ explicit_counter_loop _index += 1; if v == 1 { break 'label; diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index c565bd4cf356..a73516558c20 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -8,49 +8,49 @@ LL | for _v in &vec { = help: to override `-D warnings` add `#[allow(clippy::explicit_counter_loop)]` error: the variable `_index` is used as a loop counter - --> tests/ui/explicit_counter_loop.rs:16:5 + --> tests/ui/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 - --> tests/ui/explicit_counter_loop.rs:23:5 + --> tests/ui/explicit_counter_loop.rs:22: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 - --> tests/ui/explicit_counter_loop.rs:30:5 + --> tests/ui/explicit_counter_loop.rs:29: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 - --> tests/ui/explicit_counter_loop.rs:119:9 + --> tests/ui/explicit_counter_loop.rs:118: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 - --> tests/ui/explicit_counter_loop.rs:132:9 + --> tests/ui/explicit_counter_loop.rs:131: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 - --> tests/ui/explicit_counter_loop.rs:192:9 + --> tests/ui/explicit_counter_loop.rs:191: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 - --> tests/ui/explicit_counter_loop.rs:234:9 + --> tests/ui/explicit_counter_loop.rs:233: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 - --> tests/ui/explicit_counter_loop.rs:248:9 + --> tests/ui/explicit_counter_loop.rs:247:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())` @@ -58,7 +58,7 @@ LL | for _item in slice { = note: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumerate` error: the variable `_index` is used as a loop counter - --> tests/ui/explicit_counter_loop.rs:295:9 + --> tests/ui/explicit_counter_loop.rs:293:9 | LL | 'label: for v in vec { | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `'label: for (_index, v) in vec.into_iter().enumerate()` diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index ae63f7cbfd8c..0d1a5f80f3d5 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -67,7 +67,7 @@ fn main() { #[allow(clippy::match_single_binding)] match &*a { - //~^ explicit_deref_methods + //~^ explicit_deref_methods _ => (), } diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index a1378bda85fa..8d4a899cd260 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -67,7 +67,7 @@ fn main() { #[allow(clippy::match_single_binding)] match a.deref() { - //~^ explicit_deref_methods + //~^ explicit_deref_methods _ => (), } diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index fb853bb58305..5fdcd5a7e078 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -84,16 +84,16 @@ mod issue6437 { pub struct Scalar; impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar { - //~^ extra_unused_lifetimes + //~^ extra_unused_lifetimes fn add_assign(&mut self, _rhs: &Scalar) { unimplemented!(); } } impl<'b> Scalar { - //~^ extra_unused_lifetimes - pub fn something<'c>() -> Self { //~^ extra_unused_lifetimes + pub fn something<'c>() -> Self { + //~^ extra_unused_lifetimes Self } } @@ -123,7 +123,7 @@ mod second_case { // Should lint. The response to the above comment incorrectly called this a false positive. The // lifetime `'a` can be removed, as demonstrated below. impl<'a, T: Source + ?Sized + 'a> Source for Box { - //~^ extra_unused_lifetimes + //~^ extra_unused_lifetimes fn hey() {} } diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed index 1ab74d398314..32d4f6c69390 100644 --- a/tests/ui/extra_unused_type_parameters.fixed +++ b/tests/ui/extra_unused_type_parameters.fixed @@ -7,17 +7,17 @@ extern crate proc_macros; use proc_macros::with_span; fn unused_ty(x: u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } fn unused_multi(x: u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } fn unused_with_lt<'a>(x: &'a u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } @@ -30,12 +30,12 @@ fn used_ret(x: u8) -> T { } fn unused_bounded(x: U) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } fn some_unused(b: B, c: C) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } @@ -61,7 +61,7 @@ struct S; impl S { fn unused_ty_impl(&self) { - //~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } } @@ -84,7 +84,7 @@ where } fn unused_opaque(dummy: impl Default) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } @@ -98,7 +98,7 @@ mod unexported_trait_bounds { } fn unused_with_priv_trait_bound() { - //~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } } diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs index 0837efef27bb..c1e6f32ca12f 100644 --- a/tests/ui/extra_unused_type_parameters.rs +++ b/tests/ui/extra_unused_type_parameters.rs @@ -7,17 +7,17 @@ extern crate proc_macros; use proc_macros::with_span; fn unused_ty(x: u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } fn unused_multi(x: u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } fn unused_with_lt<'a, T>(x: &'a u8) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } @@ -30,12 +30,12 @@ fn used_ret(x: u8) -> T { } fn unused_bounded(x: U) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } fn some_unused, E>(b: B, c: C) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } @@ -61,7 +61,7 @@ struct S; impl S { fn unused_ty_impl(&self) { - //~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } } @@ -84,7 +84,7 @@ where } fn unused_opaque(dummy: impl Default) { -//~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!() } @@ -98,7 +98,7 @@ mod unexported_trait_bounds { } fn unused_with_priv_trait_bound() { - //~^ extra_unused_type_parameters + //~^ extra_unused_type_parameters unimplemented!(); } } diff --git a/tests/ui/extra_unused_type_parameters_unfixable.rs b/tests/ui/extra_unused_type_parameters_unfixable.rs index e69c924af00d..87ce517a0a45 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.rs +++ b/tests/ui/extra_unused_type_parameters_unfixable.rs @@ -2,7 +2,6 @@ fn unused_where_clause(x: U) //~^ extra_unused_type_parameters - where T: Default, { @@ -11,7 +10,6 @@ where fn unused_multi_where_clause(x: U) //~^ extra_unused_type_parameters - where T: Default, { @@ -20,7 +18,6 @@ where fn unused_all_where_clause() //~^ extra_unused_type_parameters - where T: Default, { diff --git a/tests/ui/extra_unused_type_parameters_unfixable.stderr b/tests/ui/extra_unused_type_parameters_unfixable.stderr index 8accb7e5924e..0765c4160936 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -9,7 +9,7 @@ LL | fn unused_where_clause(x: U) = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, V - --> tests/ui/extra_unused_type_parameters_unfixable.rs:12:30 + --> tests/ui/extra_unused_type_parameters_unfixable.rs:11:30 | LL | fn unused_multi_where_clause(x: U) | ^ ^^^^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/extra_unused_type_parameters_unfixable.rs:21:28 + --> tests/ui/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 56bd8a482684..1c62c1e937b6 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -4,7 +4,7 @@ // docs example struct Foo(i32); impl From for Foo { -//~^ fallible_impl_from + //~^ fallible_impl_from fn from(s: String) -> Self { Foo(s.parse().unwrap()) @@ -27,7 +27,7 @@ impl From for Valid { struct Invalid; impl From for Invalid { -//~^ fallible_impl_from + //~^ fallible_impl_from fn from(i: usize) -> Invalid { if i != 42 { @@ -38,7 +38,7 @@ impl From for Invalid { } impl From> for Invalid { -//~^ fallible_impl_from + //~^ fallible_impl_from fn from(s: Option) -> Invalid { let s = s.unwrap(); @@ -58,7 +58,7 @@ impl ProjStrTrait for Box { type ProjString = String; } impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { -//~^ fallible_impl_from + //~^ fallible_impl_from fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { if s.parse::().ok().unwrap() != 42 { diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs index 0e9c160e4a90..8ca01b91210f 100644 --- a/tests/ui/filetype_is_file.rs +++ b/tests/ui/filetype_is_file.rs @@ -7,21 +7,21 @@ fn main() -> std::io::Result<()> { // !filetype.is_dir() if fs::metadata("foo.txt")?.file_type().is_file() { - //~^ filetype_is_file + //~^ filetype_is_file // read file } // positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file() { - //~^ filetype_is_file + //~^ filetype_is_file // handle dir } // false positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { - //~^ filetype_is_file + //~^ filetype_is_file // ... } diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed index 6d9564dc828b..b3e112f19eb4 100644 --- a/tests/ui/filter_map_bool_then.fixed +++ b/tests/ui/filter_map_bool_then.fixed @@ -23,17 +23,17 @@ fn main() { v.clone() .into_iter() .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - //~^ filter_map_bool_then + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - //~^ filter_map_bool_then + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); - //~^ filter_map_bool_then + //~^ filter_map_bool_then // 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. diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs index dffd798da254..d996b3cb3c52 100644 --- a/tests/ui/filter_map_bool_then.rs +++ b/tests/ui/filter_map_bool_then.rs @@ -23,17 +23,17 @@ fn main() { v.clone() .into_iter() .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); - //~^ filter_map_bool_then + //~^ filter_map_bool_then v.clone() .into_iter() .filter(|&i| i != 1000) .filter_map(|i| (i % 2 == 0).then(|| i + 1)); - //~^ filter_map_bool_then + //~^ filter_map_bool_then v.iter() .copied() .filter(|&i| i != 1000) .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); - //~^ filter_map_bool_then + //~^ filter_map_bool_then // 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. diff --git a/tests/ui/filter_map_identity.fixed b/tests/ui/filter_map_identity.fixed index 40c3f58da976..c9e2c5f5049f 100644 --- a/tests/ui/filter_map_identity.fixed +++ b/tests/ui/filter_map_identity.fixed @@ -40,14 +40,6 @@ fn main() { copy_vec_non_inferred().into_iter().flatten(); //~^ filter_map_identity - - non_copy_vec().into_iter().flatten(); - //~^ filter_map_identity - - non_copy_vec().into_iter().flatten(); - //~^ filter_map_identity - - non_copy_vec().into_iter().flatten(); //~^ filter_map_identity @@ -60,6 +52,11 @@ fn main() { non_copy_vec().into_iter().flatten(); //~^ filter_map_identity + non_copy_vec().into_iter().flatten(); + //~^ filter_map_identity + + non_copy_vec().into_iter().flatten(); + //~^ filter_map_identity copy_vec::().into_iter().flatten(); //~^ filter_map_identity @@ -73,7 +70,6 @@ fn main() { copy_vec::().into_iter().flatten(); //~^ filter_map_identity - // we are forced to pass the type in the call. copy_vec::().into_iter().flatten(); //~^ filter_map_identity @@ -89,18 +85,16 @@ fn main() { #[rustfmt::skip] copy_vec::().into_iter().flatten(); - //~^ filter_map_identity + //~^ filter_map_identity #[rustfmt::skip] copy_vec::().into_iter().flatten(); - //~^ filter_map_identity - + //~^ filter_map_identity // note, the compiler requires that we pass the type to `opaque`. This is mostly for reference, // it behaves the same as copy_vec. opaque::().into_iter().flatten(); //~^ filter_map_identity - } } diff --git a/tests/ui/filter_map_identity.rs b/tests/ui/filter_map_identity.rs index f11f80437e85..4c8d48f5221f 100644 --- a/tests/ui/filter_map_identity.rs +++ b/tests/ui/filter_map_identity.rs @@ -40,14 +40,12 @@ fn main() { copy_vec_non_inferred().into_iter().filter_map(|x| return x); //~^ filter_map_identity - non_copy_vec().into_iter().filter_map(|x| x); //~^ filter_map_identity non_copy_vec().into_iter().filter_map(|x| x); //~^ filter_map_identity - non_copy_vec().into_iter().filter_map(std::convert::identity); //~^ filter_map_identity @@ -60,7 +58,6 @@ fn main() { non_copy_vec().into_iter().filter_map(|x| return x); //~^ filter_map_identity - copy_vec::().into_iter().filter_map(|x: Option<_>| x); //~^ filter_map_identity @@ -73,7 +70,6 @@ fn main() { copy_vec::().into_iter().filter_map(|x: Option<_>| return x); //~^ filter_map_identity - // we are forced to pass the type in the call. copy_vec::().into_iter().filter_map(|x: Option| x); //~^ filter_map_identity @@ -89,18 +85,16 @@ fn main() { #[rustfmt::skip] copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ x }}); - //~^ filter_map_identity + //~^ filter_map_identity #[rustfmt::skip] copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ return x }}); - //~^ filter_map_identity - + //~^ filter_map_identity // note, the compiler requires that we pass the type to `opaque`. This is mostly for reference, // it behaves the same as copy_vec. opaque::().into_iter().filter_map(|x| x); //~^ filter_map_identity - } } diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index 4223343251f1..26b6e0bc7b34 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -32,41 +32,47 @@ LL | copy_vec_non_inferred().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:44:36 + --> tests/ui/filter_map_identity.rs:43:36 | LL | non_copy_vec().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:47:36 + --> tests/ui/filter_map_identity.rs:46:36 | LL | non_copy_vec().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:51:36 + --> tests/ui/filter_map_identity.rs:49:36 | LL | non_copy_vec().into_iter().filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:54:36 + --> tests/ui/filter_map_identity.rs:52:36 | LL | non_copy_vec().into_iter().filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:57:36 + --> tests/ui/filter_map_identity.rs:55:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:60:36 + --> tests/ui/filter_map_identity.rs:58:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` +error: use of `filter_map` with an identity function + --> tests/ui/filter_map_identity.rs:61:39 + | +LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` + error: use of `filter_map` with an identity function --> tests/ui/filter_map_identity.rs:64:39 | @@ -76,8 +82,8 @@ LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); error: use of `filter_map` with an identity function --> tests/ui/filter_map_identity.rs:67:39 | -LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` +LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function --> tests/ui/filter_map_identity.rs:70:39 @@ -86,49 +92,43 @@ LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:73:39 - | -LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` - -error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:78:39 + --> tests/ui/filter_map_identity.rs:74:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:81:39 + --> tests/ui/filter_map_identity.rs:77:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:84:39 + --> tests/ui/filter_map_identity.rs:80:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:87:39 + --> tests/ui/filter_map_identity.rs:83:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:91:43 + --> tests/ui/filter_map_identity.rs:87:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:95:43 + --> tests/ui/filter_map_identity.rs:91:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ return x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:101:37 + --> tests/ui/filter_map_identity.rs:96:37 | LL | opaque::().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/float_arithmetic.rs b/tests/ui/float_arithmetic.rs index 3b87d2ec066d..3c447bc94c66 100644 --- a/tests/ui/float_arithmetic.rs +++ b/tests/ui/float_arithmetic.rs @@ -58,30 +58,25 @@ pub fn float_arith_ref() { &3.5_f32 + &1.3_f32; //~^ float_arithmetic - } pub fn float_foo(f: &f32) -> f32 { let a = 5.1; a + f //~^ float_arithmetic - } pub fn float_bar(f1: &f32, f2: &f32) -> f32 { f1 + f2 //~^ float_arithmetic - } pub fn float_baz(f1: f32, f2: &f32) -> f32 { f1 + f2 //~^ float_arithmetic - } pub fn float_qux(f1: f32, f2: f32) -> f32 { (&f1 + &f2) //~^ float_arithmetic - } diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr index c01fdf8b46ec..8704f7bbd7c4 100644 --- a/tests/ui/float_arithmetic.stderr +++ b/tests/ui/float_arithmetic.stderr @@ -80,25 +80,25 @@ LL | &3.5_f32 + &1.3_f32; | ^^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:66:5 + --> tests/ui/float_arithmetic.rs:65:5 | LL | a + f | ^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:72:5 + --> tests/ui/float_arithmetic.rs:70:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:78:5 + --> tests/ui/float_arithmetic.rs:75:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> tests/ui/float_arithmetic.rs:84:5 + --> tests/ui/float_arithmetic.rs:80:5 | LL | (&f1 + &f2) | ^^^^^^^^^^^ diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 84cf67ed4f10..ce0ffd8a2192 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -84,7 +84,6 @@ fn main() { twice(x) != twice(ONE as f64); //~^ float_cmp - x < 0.0; // no errors, lower or greater comparisons need no fuzzyness x > 0.0; x <= 0.0; @@ -106,7 +105,6 @@ fn main() { NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; //~^ float_cmp - let a1: [f32; 1] = [0.0]; let a2: [f32; 1] = [1.1]; @@ -116,7 +114,6 @@ fn main() { a1[0] == a2[0]; //~^ float_cmp - // no errors - comparing signums is ok let x32 = 3.21f32; 1.23f32.signum() == x32.signum(); diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index 1b57e15bbb97..e573c0baeac2 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -20,19 +20,19 @@ 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` error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:106:5 + --> tests/ui/float_cmp.rs:105: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` error: strict comparison of `f32` or `f64` arrays - --> tests/ui/float_cmp.rs:113:5 + --> tests/ui/float_cmp.rs:111:5 | LL | a1 == a2; | ^^^^^^^^ error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:116:5 + --> tests/ui/float_cmp.rs:114: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 86b3e5d46a06..3af53f2e84a2 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -28,7 +28,6 @@ fn main() { x as f32 == ONE; //~^ float_cmp_const - let v = 0.9; v == ONE; //~^ float_cmp_const @@ -36,7 +35,6 @@ fn main() { v != ONE; //~^ float_cmp_const - // no errors, lower than or greater than comparisons v < ONE; v > ONE; @@ -69,5 +67,4 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; //~^ float_cmp_const - } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index c2c7b229870a..482a55a54be6 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -32,19 +32,19 @@ LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:33:5 + --> tests/ui/float_cmp_const.rs:32:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:36:5 + --> tests/ui/float_cmp_const.rs:35:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> tests/ui/float_cmp_const.rs:70:5 + --> tests/ui/float_cmp_const.rs:68: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 db0a4f492607..a1548db6710d 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -6,8 +6,6 @@ pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON //~^ float_equality_without_abs - - } pub fn main() { @@ -31,7 +29,6 @@ pub fn main() { let _ = 1.0 - 2.0 < f32::EPSILON; //~^ float_equality_without_abs - let _ = f32::EPSILON > (a - b); //~^ float_equality_without_abs @@ -47,7 +44,6 @@ pub fn main() { let _ = f32::EPSILON > 1.0 - 2.0; //~^ float_equality_without_abs - // those are correct let _ = (a - b).abs() < f32::EPSILON; let _ = (a as f64 - b as f64).abs() < f64::EPSILON; diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr index 5696ec54d765..d4c89ce72ba9 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -10,7 +10,7 @@ LL | (a - b) < f32::EPSILON = help: to override `-D warnings` add `#[allow(clippy::float_equality_without_abs)]` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:19:13 + --> tests/ui/float_equality_without_abs.rs:17:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:22:13 + --> tests/ui/float_equality_without_abs.rs:20:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:25:13 + --> tests/ui/float_equality_without_abs.rs:23:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:28:13 + --> tests/ui/float_equality_without_abs.rs:26:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -42,7 +42,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()` - --> tests/ui/float_equality_without_abs.rs:31:13 + --> tests/ui/float_equality_without_abs.rs:29:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:35:13 + --> tests/ui/float_equality_without_abs.rs:32:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -58,7 +58,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:38:13 + --> tests/ui/float_equality_without_abs.rs:35:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -66,7 +66,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:41:13 + --> tests/ui/float_equality_without_abs.rs:38:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -74,7 +74,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> tests/ui/float_equality_without_abs.rs:44:13 + --> tests/ui/float_equality_without_abs.rs:41:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -82,7 +82,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()` - --> tests/ui/float_equality_without_abs.rs:47:13 + --> tests/ui/float_equality_without_abs.rs:44:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/tests/ui/fn_to_numeric_cast_any.rs b/tests/ui/fn_to_numeric_cast_any.rs index 3359e24c2b6a..42f2128cd378 100644 --- a/tests/ui/fn_to_numeric_cast_any.rs +++ b/tests/ui/fn_to_numeric_cast_any.rs @@ -23,7 +23,6 @@ fn fn_pointer_to_integer() { let _ = foo as i8; //~^ fn_to_numeric_cast_any - let _ = foo as i16; //~^ fn_to_numeric_cast_any @@ -39,7 +38,6 @@ fn fn_pointer_to_integer() { let _ = foo as isize; //~^ fn_to_numeric_cast_any - let _ = foo as u8; //~^ fn_to_numeric_cast_any @@ -57,25 +55,21 @@ fn fn_pointer_to_integer() { let _ = foo as usize; //~^ fn_to_numeric_cast_any - } fn static_method_to_integer() { let _ = Struct::static_method as usize; //~^ fn_to_numeric_cast_any - } fn fn_with_fn_arg(f: fn(i32) -> u32) -> usize { f as usize //~^ fn_to_numeric_cast_any - } fn fn_with_generic_static_trait_method() -> usize { T::static_method as usize //~^ fn_to_numeric_cast_any - } fn closure_to_fn_to_integer() { @@ -83,13 +77,11 @@ fn closure_to_fn_to_integer() { let _ = (clos as fn(u32) -> u32) as usize; //~^ fn_to_numeric_cast_any - } fn fn_to_raw_ptr() { let _ = foo as *const (); //~^ fn_to_numeric_cast_any - } 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 c6a7b2403395..0a98952faef1 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -12,7 +12,7 @@ LL | let _ = foo() as i8; | ~~~~~~~~~~~ error: casting function pointer `foo` to `i16` - --> tests/ui/fn_to_numeric_cast_any.rs:27:13 + --> tests/ui/fn_to_numeric_cast_any.rs:26:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = foo() as i16; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i32` - --> tests/ui/fn_to_numeric_cast_any.rs:30:13 + --> tests/ui/fn_to_numeric_cast_any.rs:29:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = foo() as i32; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast_any.rs:33:13 + --> tests/ui/fn_to_numeric_cast_any.rs:32:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = foo() as i64; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast_any.rs:36:13 + --> tests/ui/fn_to_numeric_cast_any.rs:35:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = foo() as i128; | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast_any.rs:39:13 + --> tests/ui/fn_to_numeric_cast_any.rs:38:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | let _ = foo() as isize; | ~~~~~~~~~~~~~~ error: casting function pointer `foo` to `u8` - --> tests/ui/fn_to_numeric_cast_any.rs:43:13 + --> tests/ui/fn_to_numeric_cast_any.rs:41:13 | LL | let _ = foo as u8; | ^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _ = foo() as u8; | ~~~~~~~~~~~ error: casting function pointer `foo` to `u16` - --> tests/ui/fn_to_numeric_cast_any.rs:46:13 + --> tests/ui/fn_to_numeric_cast_any.rs:44:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = foo() as u16; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u32` - --> tests/ui/fn_to_numeric_cast_any.rs:49:13 + --> tests/ui/fn_to_numeric_cast_any.rs:47:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | let _ = foo() as u32; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast_any.rs:52:13 + --> tests/ui/fn_to_numeric_cast_any.rs:50:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _ = foo() as u64; | ~~~~~~~~~~~~ error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast_any.rs:55:13 + --> tests/ui/fn_to_numeric_cast_any.rs:53:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = foo() as u128; | ~~~~~~~~~~~~~ error: casting function pointer `foo` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:58:13 + --> tests/ui/fn_to_numeric_cast_any.rs:56:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | let _ = foo() as usize; | ~~~~~~~~~~~~~~ error: casting function pointer `Struct::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:64:13 + --> tests/ui/fn_to_numeric_cast_any.rs:61:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let _ = Struct::static_method() as usize; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `f` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:70:5 + --> tests/ui/fn_to_numeric_cast_any.rs:66:5 | LL | f as usize | ^^^^^^^^^^ @@ -155,7 +155,7 @@ LL | f() as usize | error: casting function pointer `T::static_method` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:76:5 + --> tests/ui/fn_to_numeric_cast_any.rs:71:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL | T::static_method() as usize | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> tests/ui/fn_to_numeric_cast_any.rs:84:13 + --> tests/ui/fn_to_numeric_cast_any.rs:78:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | let _ = (clos as fn(u32) -> u32)() as usize; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting function pointer `foo` to `*const ()` - --> tests/ui/fn_to_numeric_cast_any.rs:90:13 + --> tests/ui/fn_to_numeric_cast_any.rs:83:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/for_kv_map.fixed b/tests/ui/for_kv_map.fixed index 402098e9394b..2a68b7443fbf 100644 --- a/tests/ui/for_kv_map.fixed +++ b/tests/ui/for_kv_map.fixed @@ -7,15 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for v in m.values() { - //~^ for_kv_map - + //~^ for_kv_map let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for v in (*m).values() { - //~^ for_kv_map + //~^ for_kv_map let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't @@ -25,14 +24,14 @@ fn main() { let mut m: HashMap = HashMap::new(); for v in m.values_mut() { - //~^ for_kv_map + //~^ for_kv_map let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for v in (*m).values_mut() { - //~^ for_kv_map + //~^ for_kv_map let _v = v; } @@ -40,7 +39,7 @@ fn main() { let m: HashMap = HashMap::new(); let rm = &m; for k in rm.keys() { - //~^ for_kv_map + //~^ for_kv_map let _k = k; } @@ -48,7 +47,7 @@ fn main() { let m: HashMap = HashMap::new(); let rm = &m; 'label: for k in rm.keys() { - //~^ for_kv_map + //~^ for_kv_map let _k = k; if *k == 0u64 { diff --git a/tests/ui/for_kv_map.rs b/tests/ui/for_kv_map.rs index 407590747a4b..485a97815e3c 100644 --- a/tests/ui/for_kv_map.rs +++ b/tests/ui/for_kv_map.rs @@ -7,15 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for (_, v) in &m { - //~^ for_kv_map - + //~^ for_kv_map let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for (_, v) in &*m { - //~^ for_kv_map + //~^ for_kv_map let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't @@ -25,14 +24,14 @@ fn main() { let mut m: HashMap = HashMap::new(); for (_, v) in &mut m { - //~^ for_kv_map + //~^ for_kv_map let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for (_, v) in &mut *m { - //~^ for_kv_map + //~^ for_kv_map let _v = v; } @@ -40,7 +39,7 @@ fn main() { let m: HashMap = HashMap::new(); let rm = &m; for (k, _value) in rm { - //~^ for_kv_map + //~^ for_kv_map let _k = k; } @@ -48,7 +47,7 @@ fn main() { let m: HashMap = HashMap::new(); let rm = &m; 'label: for (k, _value) in rm { - //~^ for_kv_map + //~^ for_kv_map let _k = k; if *k == 0u64 { diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index 5c28da81a961..878c43532194 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -12,7 +12,7 @@ LL | for v in m.values() { | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:17:19 + --> tests/ui/for_kv_map.rs:16:19 | LL | for (_, v) in &*m { | ^^^ @@ -23,7 +23,7 @@ LL | for v in (*m).values() { | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:27:19 + --> tests/ui/for_kv_map.rs:26:19 | LL | for (_, v) in &mut m { | ^^^^^^ @@ -34,7 +34,7 @@ LL | for v in m.values_mut() { | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> tests/ui/for_kv_map.rs:34:19 + --> tests/ui/for_kv_map.rs:33:19 | LL | for (_, v) in &mut *m { | ^^^^^^^ @@ -45,7 +45,7 @@ LL | for v in (*m).values_mut() { | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> tests/ui/for_kv_map.rs:42:24 + --> tests/ui/for_kv_map.rs:41:24 | LL | for (k, _value) in rm { | ^^ @@ -56,7 +56,7 @@ LL | for k in rm.keys() { | ~ ~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> tests/ui/for_kv_map.rs:50:32 + --> tests/ui/for_kv_map.rs:49:32 | LL | 'label: for (k, _value) in rm { | ^^ diff --git a/tests/ui/forget_non_drop.rs b/tests/ui/forget_non_drop.rs index a69fa0f20359..0235709b1f1c 100644 --- a/tests/ui/forget_non_drop.rs +++ b/tests/ui/forget_non_drop.rs @@ -13,7 +13,6 @@ fn main() { forget(Foo); //~^ forget_non_drop - struct Bar; impl Drop for Bar { fn drop(&mut self) {} diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index 0bff152a7132..e121984154c7 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -13,13 +13,13 @@ LL | forget(Foo); = help: to override `-D warnings` add `#[allow(clippy::forget_non_drop)]` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it - --> tests/ui/forget_non_drop.rs:26:5 + --> tests/ui/forget_non_drop.rs:25:5 | LL | forget(Baz(Foo)); | ^^^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> tests/ui/forget_non_drop.rs:26:12 + --> tests/ui/forget_non_drop.rs:25:12 | LL | forget(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/format.rs b/tests/ui/format.rs index b40eb9d1eb9e..06371378f27e 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -24,7 +24,7 @@ fn main() { format!("{{}} abc {{}}"); //~^ useless_format format!( - //~^ useless_format + //~^ useless_format r##"foo {{}} " bar"## ); diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed index 075450451b24..edfdaa23ca12 100644 --- a/tests/ui/format_args.fixed +++ b/tests/ui/format_args.fixed @@ -79,13 +79,13 @@ fn main() { let _ = write!( stdout(), "error: something failed at {}", - Location::caller() + Location::caller(), //~^ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", - Location::caller() + Location::caller(), //~^ to_string_in_format_args ); print!("error: something failed at {}", Location::caller()); diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs index 4d7a018732c7..367560d577dd 100644 --- a/tests/ui/format_args.rs +++ b/tests/ui/format_args.rs @@ -79,13 +79,13 @@ fn main() { let _ = write!( stdout(), "error: something failed at {}", - Location::caller().to_string() + Location::caller().to_string(), //~^ to_string_in_format_args ); let _ = writeln!( stdout(), "error: something failed at {}", - Location::caller().to_string() + Location::caller().to_string(), //~^ to_string_in_format_args ); print!("error: something failed at {}", Location::caller().to_string()); diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index 68c3c9c322d9..589c341ce859 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -10,13 +10,13 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_ error: `to_string` applied to a type that implements `Display` in `write!` args --> tests/ui/format_args.rs:82:27 | -LL | Location::caller().to_string() +LL | Location::caller().to_string(), | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `writeln!` args --> tests/ui/format_args.rs:88:27 | -LL | Location::caller().to_string() +LL | Location::caller().to_string(), | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs index adbdaca7313b..08cd7dbe54f7 100644 --- a/tests/ui/format_args_unfixable.rs +++ b/tests/ui/format_args_unfixable.rs @@ -48,15 +48,13 @@ fn main() { //~^ format_in_format_args let _ = write!( - //~^ format_in_format_args - + //~^ format_in_format_args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); let _ = writeln!( - //~^ format_in_format_args - + //~^ format_in_format_args stdout(), "error: {}", format!("something failed at {}", Location::caller()) @@ -85,7 +83,6 @@ fn main() { panic!("error: {}", format!("something failed at {}", Location::caller())); //~^ format_in_format_args - // negative tests println!("error: {}", format_args!("something failed at {}", Location::caller())); println!("error: {:>70}", format!("something failed at {}", Location::caller())); @@ -171,5 +168,4 @@ fn user_format() { usr_println!(true, "error: {}", format!("boom at {} {0}", Location::caller())); //~^ format_in_format_args - } diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index 82af72229066..1271e80b60a7 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -78,7 +78,6 @@ error: `format!` in `write!` args LL | let _ = write!( | _____________^ LL | | -LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -89,12 +88,11 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `writeln!` args - --> tests/ui/format_args_unfixable.rs:57:13 + --> tests/ui/format_args_unfixable.rs:56:13 | LL | let _ = writeln!( | _____________^ LL | | -LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -105,7 +103,7 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `print!` args - --> tests/ui/format_args_unfixable.rs:64:5 + --> tests/ui/format_args_unfixable.rs:62:5 | LL | print!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +112,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `eprint!` args - --> tests/ui/format_args_unfixable.rs:67:5 + --> tests/ui/format_args_unfixable.rs:65:5 | LL | eprint!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +121,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `eprintln!` args - --> tests/ui/format_args_unfixable.rs:70:5 + --> tests/ui/format_args_unfixable.rs:68:5 | LL | eprintln!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +130,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call = help: or consider changing `format!` to `format_args!` error: `format!` in `format_args!` args - --> tests/ui/format_args_unfixable.rs:73:13 + --> tests/ui/format_args_unfixable.rs:71:13 | LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -141,7 +139,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc = help: or consider changing `format!` to `format_args!` error: `format!` in `assert!` args - --> tests/ui/format_args_unfixable.rs:76:5 + --> tests/ui/format_args_unfixable.rs:74:5 | LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -150,7 +148,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_eq!` args - --> tests/ui/format_args_unfixable.rs:79:5 + --> tests/ui/format_args_unfixable.rs:77:5 | LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -159,7 +157,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 - --> tests/ui/format_args_unfixable.rs:82:5 + --> tests/ui/format_args_unfixable.rs:80:5 | LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,7 +166,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 - --> tests/ui/format_args_unfixable.rs:85:5 + --> tests/ui/format_args_unfixable.rs:83:5 | LL | panic!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +175,7 @@ LL | panic!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:154:5 + --> tests/ui/format_args_unfixable.rs:151:5 | LL | usr_println!(true, "error: {}", format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -186,7 +184,7 @@ LL | usr_println!(true, "error: {}", format!("boom at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:157:5 + --> tests/ui/format_args_unfixable.rs:154:5 | LL | usr_println!(true, "{}: {}", error, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -195,7 +193,7 @@ LL | usr_println!(true, "{}: {}", error, format!("boom at {}", Location::cal = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:160:5 + --> tests/ui/format_args_unfixable.rs:157:5 | LL | usr_println!(true, "{:?}: {}", error, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -204,7 +202,7 @@ LL | usr_println!(true, "{:?}: {}", error, format!("boom at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:163:5 + --> tests/ui/format_args_unfixable.rs:160:5 | LL | usr_println!(true, "{{}}: {}", format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -213,7 +211,7 @@ LL | usr_println!(true, "{{}}: {}", format!("boom at {}", Location::caller() = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:166:5 + --> tests/ui/format_args_unfixable.rs:163:5 | LL | usr_println!(true, r#"error: "{}""#, format!("boom at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -222,7 +220,7 @@ LL | usr_println!(true, r#"error: "{}""#, format!("boom at {}", Location::ca = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:169:5 + --> tests/ui/format_args_unfixable.rs:166:5 | LL | usr_println!(true, "error: {}", format!(r#"boom at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -231,7 +229,7 @@ LL | usr_println!(true, "error: {}", format!(r#"boom at "{}""#, Location::ca = help: or consider changing `format!` to `format_args!` error: `format!` in `usr_println!` args - --> tests/ui/format_args_unfixable.rs:172:5 + --> tests/ui/format_args_unfixable.rs:169:5 | LL | usr_println!(true, "error: {}", format!("boom at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_collect.rs b/tests/ui/format_collect.rs index 85dbd5692fef..8f8633a52d86 100644 --- a/tests/ui/format_collect.rs +++ b/tests/ui/format_collect.rs @@ -4,7 +4,6 @@ fn hex_encode(bytes: &[u8]) -> String { bytes.iter().map(|b| format!("{b:02X}")).collect() //~^ format_collect - } #[rustfmt::skip] @@ -26,8 +25,7 @@ fn from_macro(bytes: &[u8]) -> String { fn with_block() -> String { (1..10) - //~^ format_collect - + //~^ format_collect .map(|s| { let y = 1; format!("{s} {y}") diff --git a/tests/ui/format_collect.stderr b/tests/ui/format_collect.stderr index a87951efa543..343e38a87b71 100644 --- a/tests/ui/format_collect.stderr +++ b/tests/ui/format_collect.stderr @@ -19,42 +19,42 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() = help: to override `-D warnings` add `#[allow(clippy::format_collect)]` error: use of `format!` to build up a string from an iterator - --> tests/ui/format_collect.rs:12:5 + --> tests/ui/format_collect.rs:11:5 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: call `fold` instead - --> tests/ui/format_collect.rs:12:18 + --> tests/ui/format_collect.rs:11:18 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^ help: ... and use the `write!` macro here - --> tests/ui/format_collect.rs:12:32 + --> tests/ui/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 - --> tests/ui/format_collect.rs:28:5 + --> tests/ui/format_collect.rs:27:5 | LL | / (1..10) LL | | -LL | | LL | | .map(|s| { -... | +LL | | let y = 1; +LL | | format!("{s} {y}") LL | | }) LL | | .collect() | |__________________^ | help: call `fold` instead - --> tests/ui/format_collect.rs:31:10 + --> tests/ui/format_collect.rs:29:10 | LL | .map(|s| { | ^^^ help: ... and use the `write!` macro here - --> tests/ui/format_collect.rs:33:13 + --> tests/ui/format_collect.rs:31:13 | LL | format!("{s} {y}") | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_push_string.rs b/tests/ui/format_push_string.rs index c047118b5f50..056ef59ff0e2 100644 --- a/tests/ui/format_push_string.rs +++ b/tests/ui/format_push_string.rs @@ -7,7 +7,6 @@ fn main() { string.push_str(&format!("{:?}", 5678)); //~^ format_push_string - } mod issue9493 { @@ -15,7 +14,7 @@ mod issue9493 { let mut hex = String::with_capacity(vector.len() * 2); for byte in vector { hex += &(if upper { - //~^ format_push_string + //~^ format_push_string format!("{byte:02X}") } else { @@ -29,7 +28,7 @@ mod issue9493 { let mut s = String::new(); // if let s += &(if let Some(_a) = Some(1234) { - //~^ format_push_string + //~^ format_push_string format!("{}", 1234) } else { @@ -37,8 +36,7 @@ mod issue9493 { }); // match s += &(match Some(1234) { - //~^ format_push_string - + //~^ format_push_string Some(_) => format!("{}", 1234), None => format!("{}", 1234), }); diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index a496371938e9..bba2a8947c43 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -17,7 +17,7 @@ LL | string.push_str(&format!("{:?}", 5678)); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:17:13 + --> tests/ui/format_push_string.rs:16:13 | LL | / hex += &(if upper { LL | | @@ -31,7 +31,7 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:31:9 + --> tests/ui/format_push_string.rs:30:9 | LL | / s += &(if let Some(_a) = Some(1234) { LL | | @@ -45,11 +45,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> tests/ui/format_push_string.rs:39:9 + --> tests/ui/format_push_string.rs:38:9 | LL | / s += &(match Some(1234) { LL | | -LL | | LL | | Some(_) => format!("{}", 1234), LL | | None => format!("{}", 1234), LL | | }); diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index 85befb87fe5b..7d6780a0e02c 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -7,7 +7,7 @@ struct StringWrapper(String); impl From for StringWrapper { -//~^ from_over_into + //~^ from_over_into fn from(val: String) -> Self { StringWrapper(val) } @@ -16,7 +16,7 @@ impl From for StringWrapper { struct SelfType(String); impl From for SelfType { -//~^ from_over_into + //~^ from_over_into fn from(val: String) -> Self { SelfType(String::new()) } @@ -32,7 +32,7 @@ impl X { struct SelfKeywords; impl From for SelfKeywords { -//~^ from_over_into + //~^ from_over_into fn from(val: X) -> Self { let _ = X; let _ = X::FOO; @@ -45,7 +45,7 @@ impl From for SelfKeywords { struct ExplicitPaths(bool); impl core::convert::From for bool { -//~^ from_over_into + //~^ from_over_into fn from(mut val: crate::ExplicitPaths) -> Self { let in_closure = || val.0; @@ -66,7 +66,7 @@ impl From for A { struct PathInExpansion; impl From for String { -//~^ from_over_into + //~^ from_over_into fn from(val: PathInExpansion) -> Self { // non self/Self paths in expansions are fine panic!() @@ -89,7 +89,7 @@ fn msrv_1_41() { struct FromOverInto(Vec); impl From> for FromOverInto { - //~^ from_over_into + //~^ from_over_into fn from(val: Vec) -> Self { FromOverInto(val) } @@ -100,7 +100,7 @@ fn issue_12138() { struct Hello; impl From for () { - //~^ from_over_into + //~^ from_over_into fn from(val: Hello) {} } } diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index d4bdad56473a..387ddde359c1 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -7,7 +7,7 @@ struct StringWrapper(String); impl Into for String { -//~^ from_over_into + //~^ from_over_into fn into(self) -> StringWrapper { StringWrapper(self) } @@ -16,7 +16,7 @@ impl Into for String { struct SelfType(String); impl Into for String { -//~^ from_over_into + //~^ from_over_into fn into(self) -> SelfType { SelfType(Self::new()) } @@ -32,7 +32,7 @@ impl X { struct SelfKeywords; impl Into for X { -//~^ from_over_into + //~^ from_over_into fn into(self) -> SelfKeywords { let _ = Self; let _ = Self::FOO; @@ -45,7 +45,7 @@ impl Into for X { struct ExplicitPaths(bool); impl core::convert::Into for crate::ExplicitPaths { -//~^ from_over_into + //~^ from_over_into fn into(mut self) -> bool { let in_closure = || self.0; @@ -66,7 +66,7 @@ impl From for A { struct PathInExpansion; impl Into for PathInExpansion { -//~^ from_over_into + //~^ from_over_into fn into(self) -> String { // non self/Self paths in expansions are fine panic!() @@ -89,7 +89,7 @@ fn msrv_1_41() { struct FromOverInto(Vec); impl Into> for Vec { - //~^ from_over_into + //~^ from_over_into fn into(self) -> FromOverInto { FromOverInto(self) } @@ -100,7 +100,7 @@ fn issue_12138() { struct Hello; impl Into<()> for Hello { - //~^ from_over_into + //~^ from_over_into fn into(self) {} } } diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index 23aab9b52e1b..de90c7c21a65 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -9,7 +9,7 @@ macro_rules! in_macro { } impl Into for String { -//~^ from_over_into + //~^ from_over_into fn into(self) -> InMacro { InMacro(in_macro!()) @@ -19,7 +19,7 @@ impl Into for String { struct WeirdUpperSelf; impl Into for &'static [u8] { -//~^ from_over_into + //~^ from_over_into fn into(self) -> WeirdUpperSelf { let _ = Self::default(); @@ -30,7 +30,7 @@ impl Into for &'static [u8] { struct ContainsVal; impl Into for ContainsVal { -//~^ from_over_into + //~^ from_over_into fn into(self) -> u8 { let val = 1; @@ -43,7 +43,7 @@ pub struct Lval(T); pub struct Rval(T); impl Into> for Lval { -//~^ from_over_into + //~^ from_over_into fn into(self) -> Rval { Rval(self) diff --git a/tests/ui/from_raw_with_void_ptr.rs b/tests/ui/from_raw_with_void_ptr.rs index 840508ad340d..390313884433 100644 --- a/tests/ui/from_raw_with_void_ptr.rs +++ b/tests/ui/from_raw_with_void_ptr.rs @@ -11,7 +11,6 @@ fn main() { let _ = unsafe { Box::from_raw(ptr) }; //~^ from_raw_with_void_ptr - // shouldn't be linted let _ = unsafe { Box::from_raw(ptr as *mut usize) }; @@ -24,22 +23,18 @@ fn main() { let _ = unsafe { Rc::from_raw(ptr) }; //~^ from_raw_with_void_ptr - // must lint let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void; let _ = unsafe { Arc::from_raw(ptr) }; //~^ from_raw_with_void_ptr - // 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) }; //~^ from_raw_with_void_ptr - // 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) }; //~^ from_raw_with_void_ptr - } diff --git a/tests/ui/from_raw_with_void_ptr.stderr b/tests/ui/from_raw_with_void_ptr.stderr index ab55cfd48a5b..e5bcb783d18b 100644 --- a/tests/ui/from_raw_with_void_ptr.stderr +++ b/tests/ui/from_raw_with_void_ptr.stderr @@ -13,49 +13,49 @@ LL | let _ = unsafe { Box::from_raw(ptr) }; = help: to override `-D warnings` add `#[allow(clippy::from_raw_with_void_ptr)]` error: creating a `Rc` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:24:22 + --> tests/ui/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 - --> tests/ui/from_raw_with_void_ptr.rs:24:35 + --> tests/ui/from_raw_with_void_ptr.rs:23:35 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^ error: creating a `Arc` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:30:22 + --> tests/ui/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 - --> tests/ui/from_raw_with_void_ptr.rs:30:36 + --> tests/ui/from_raw_with_void_ptr.rs:28:36 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> tests/ui/from_raw_with_void_ptr.rs:36:22 + --> tests/ui/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 - --> tests/ui/from_raw_with_void_ptr.rs:36:46 + --> tests/ui/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 - --> tests/ui/from_raw_with_void_ptr.rs:42:22 + --> tests/ui/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 - --> tests/ui/from_raw_with_void_ptr.rs:42:48 + --> tests/ui/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 e9f4de518bbc..4b8fd778685e 100644 --- a/tests/ui/from_str_radix_10.fixed +++ b/tests/ui/from_str_radix_10.fixed @@ -28,7 +28,6 @@ fn main() -> Result<(), Box> { "30".parse::()?; //~^ from_str_radix_10 - "24".parse::()?; //~^ from_str_radix_10 @@ -44,17 +43,14 @@ fn main() -> Result<(), Box> { (Test + Test).parse::()?; //~^ from_str_radix_10 - let string = "300"; string.parse::()?; //~^ from_str_radix_10 - let stringier = "400".to_string(); stringier.parse::()?; //~^ from_str_radix_10 - // none of these should trigger the lint u16::from_str_radix("20", 3)?; i32::from_str_radix("45", 12)?; diff --git a/tests/ui/from_str_radix_10.rs b/tests/ui/from_str_radix_10.rs index 9ebead7f75ba..89002b11a995 100644 --- a/tests/ui/from_str_radix_10.rs +++ b/tests/ui/from_str_radix_10.rs @@ -28,7 +28,6 @@ fn main() -> Result<(), Box> { u32::from_str_radix("30", 10)?; //~^ from_str_radix_10 - i64::from_str_radix("24", 10)?; //~^ from_str_radix_10 @@ -44,17 +43,14 @@ fn main() -> Result<(), Box> { i128::from_str_radix(Test + Test, 10)?; //~^ from_str_radix_10 - let string = "300"; i32::from_str_radix(string, 10)?; //~^ from_str_radix_10 - let stringier = "400".to_string(); i32::from_str_radix(&stringier, 10)?; //~^ from_str_radix_10 - // none of these should trigger the lint u16::from_str_radix("20", 3)?; i32::from_str_radix("45", 12)?; diff --git a/tests/ui/from_str_radix_10.stderr b/tests/ui/from_str_radix_10.stderr index 7f0a12a03f3c..c693e8f50ff6 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -8,43 +8,43 @@ LL | u32::from_str_radix("30", 10)?; = help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> tests/ui/from_str_radix_10.rs:32:5 + --> tests/ui/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` - --> tests/ui/from_str_radix_10.rs:35:5 + --> tests/ui/from_str_radix_10.rs:34: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` - --> tests/ui/from_str_radix_10.rs:38:5 + --> tests/ui/from_str_radix_10.rs:37: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` - --> tests/ui/from_str_radix_10.rs:41:5 + --> tests/ui/from_str_radix_10.rs:40: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` - --> tests/ui/from_str_radix_10.rs:44:5 + --> tests/ui/from_str_radix_10.rs:43: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` - --> tests/ui/from_str_radix_10.rs:49:5 + --> tests/ui/from_str_radix_10.rs:47: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` - --> tests/ui/from_str_radix_10.rs:54:5 + --> tests/ui/from_str_radix_10.rs:51: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 9114dd96ce4d..9c1ca8bf9300 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -8,8 +8,6 @@ fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} //~^ too_many_arguments - - #[rustfmt::skip] fn bad_multiline( //~^ too_many_arguments @@ -50,7 +48,6 @@ pub trait Foo { fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); //~^ too_many_arguments - fn ptr(p: *const u8); } @@ -60,7 +57,6 @@ 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: ()) {} //~^ too_many_arguments - } // ok, we don’t want to warn implementations @@ -72,13 +68,11 @@ impl Foo for Bar { println!("{}", unsafe { *p }); //~^ not_unsafe_ptr_arg_deref - println!("{:?}", unsafe { p.as_ref() }); //~^ not_unsafe_ptr_arg_deref unsafe { std::ptr::read(p) }; //~^ not_unsafe_ptr_arg_deref - } } @@ -97,7 +91,6 @@ pub fn public(p: *const u8) { unsafe { std::ptr::read(p) }; //~^ not_unsafe_ptr_arg_deref - } type Alias = *const u8; @@ -111,7 +104,6 @@ pub fn type_alias(p: Alias) { unsafe { std::ptr::read(p) }; //~^ not_unsafe_ptr_arg_deref - } impl Bar { @@ -128,7 +120,6 @@ impl Bar { unsafe { std::ptr::read(p) }; //~^ not_unsafe_ptr_arg_deref - } pub fn public_ok(self, p: *const u8) { diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 4e3cf2edb085..c8770023f77a 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -8,7 +8,7 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` error: this function has too many arguments (8/7) - --> tests/ui/functions.rs:14:1 + --> tests/ui/functions.rs:12:1 | LL | / fn bad_multiline( LL | | @@ -20,19 +20,19 @@ LL | | ) { | |_^ error: this function has too many arguments (8/7) - --> tests/ui/functions.rs:50:5 + --> tests/ui/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) - --> tests/ui/functions.rs:61:5 + --> tests/ui/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` - --> tests/ui/functions.rs:72:34 + --> tests/ui/functions.rs:68:34 | LL | println!("{}", unsafe { *p }); | ^ @@ -41,67 +41,67 @@ LL | println!("{}", unsafe { *p }); = help: to override `-D warnings` add `#[allow(clippy::not_unsafe_ptr_arg_deref)]` error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:76:35 + --> tests/ui/functions.rs:71:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:79:33 + --> tests/ui/functions.rs:74:33 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:92:30 + --> tests/ui/functions.rs:86:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:95:31 + --> tests/ui/functions.rs:89:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:98:29 + --> tests/ui/functions.rs:92:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:106:30 + --> tests/ui/functions.rs:99:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:109:31 + --> tests/ui/functions.rs:102:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:112:29 + --> tests/ui/functions.rs:105:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:123:34 + --> tests/ui/functions.rs:115:34 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:126:35 + --> tests/ui/functions.rs:118:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> tests/ui/functions.rs:129:33 + --> tests/ui/functions.rs:121:33 | LL | unsafe { std::ptr::read(p) }; | ^ diff --git a/tests/ui/functions_maxlines.rs b/tests/ui/functions_maxlines.rs index 3c32e88c6880..e0990dadaaa9 100644 --- a/tests/ui/functions_maxlines.rs +++ b/tests/ui/functions_maxlines.rs @@ -56,8 +56,7 @@ fn good_lines() { } fn bad_lines() { -//~^ too_many_lines - + //~^ too_many_lines println!("Dont get confused by braces: {{}}"); println!("This is bad."); diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr index 82d5fc8d5859..f42a2b2a22a2 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -2,6 +2,9 @@ error: this function has too many lines (102/100) --> tests/ui/functions_maxlines.rs:58:1 | LL | / fn bad_lines() { +LL | | +LL | | +LL | | println!("Dont get confused by braces: {{}}"); ... | LL | | println!("This is bad."); LL | | } diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs index 1df0b1334827..662ecb9c955d 100644 --- a/tests/ui/future_not_send.rs +++ b/tests/ui/future_not_send.rs @@ -6,13 +6,13 @@ use std::rc::Rc; use std::sync::Arc; async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { -//~^ future_not_send + //~^ future_not_send async { true }.await } pub async fn public_future(rc: Rc<[u8]>) { -//~^ future_not_send + //~^ future_not_send async { true }.await; } @@ -22,7 +22,7 @@ pub async fn public_send(arc: Arc<[u8]>) -> bool { } async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { -//~^ future_not_send + //~^ future_not_send true } @@ -30,7 +30,6 @@ async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { pub async fn public_future2(rc: Rc<[u8]>) {} //~^ future_not_send - pub async fn public_send2(arc: Arc<[u8]>) -> bool { false } @@ -41,14 +40,14 @@ struct Dummy { impl Dummy { async fn private_future(&self) -> usize { - //~^ future_not_send + //~^ future_not_send async { true }.await; self.rc.len() } pub async fn public_future(&self) { - //~^ future_not_send + //~^ future_not_send self.private_future().await; } @@ -61,7 +60,6 @@ impl Dummy { async fn generic_future(t: T) -> T //~^ future_not_send - where T: Send, { @@ -83,7 +81,7 @@ async fn maybe_send_generic_future2 Fut, Fut: Future>(f: F) { } async fn generic_future_always_unsend(_: Rc) { -//~^ future_not_send + //~^ future_not_send async { true }.await; } diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 4dcff55942a6..e366dc2d2195 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -71,13 +71,13 @@ LL | pub async fn public_future2(rc: Rc<[u8]>) {} = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:43:5 + --> tests/ui/future_not_send.rs:42:5 | 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 - --> tests/ui/future_not_send.rs:46:24 + --> tests/ui/future_not_send.rs:45:24 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` @@ -87,30 +87,29 @@ LL | async { true }.await; = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:50:5 + --> tests/ui/future_not_send.rs:49:5 | LL | pub async fn public_future(&self) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `public_future` is not `Send` | note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` - --> tests/ui/future_not_send.rs:50:32 + --> tests/ui/future_not_send.rs:49:32 | LL | pub async fn public_future(&self) { | ^^^^^ has type `&Dummy` which is not `Send`, because `Dummy` is not `Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:62:1 + --> tests/ui/future_not_send.rs:61:1 | LL | / async fn generic_future(t: T) -> T LL | | -LL | | LL | | where LL | | T: Send, | |____________^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> tests/ui/future_not_send.rs:69:20 + --> tests/ui/future_not_send.rs:67:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` @@ -119,13 +118,13 @@ LL | async { true }.await; = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> tests/ui/future_not_send.rs:85:1 + --> tests/ui/future_not_send.rs:83:1 | LL | async fn generic_future_always_unsend(_: Rc) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `generic_future_always_unsend` is not `Send` | note: future is not `Send` as this value is used across an await - --> tests/ui/future_not_send.rs:88:20 + --> tests/ui/future_not_send.rs:86:20 | LL | async fn generic_future_always_unsend(_: Rc) { | - has type `std::rc::Rc` which is not `Send` diff --git a/tests/ui/get_first.fixed b/tests/ui/get_first.fixed index 090fe48096ae..584080defa1e 100644 --- a/tests/ui/get_first.fixed +++ b/tests/ui/get_first.fixed @@ -51,5 +51,4 @@ fn main() { let non_primitives = [vec![1, 2], vec![3, 4]]; let _ = non_primitives.first(); //~^ get_first - } diff --git a/tests/ui/get_first.rs b/tests/ui/get_first.rs index c85d5aa89ca2..f01fbdf43c6d 100644 --- a/tests/ui/get_first.rs +++ b/tests/ui/get_first.rs @@ -51,5 +51,4 @@ fn main() { let non_primitives = [vec![1, 2], vec![3, 4]]; let _ = non_primitives.get(0); //~^ get_first - } diff --git a/tests/ui/identity_op.fixed b/tests/ui/identity_op.fixed index b3836bda2b6f..a1b556029987 100644 --- a/tests/ui/identity_op.fixed +++ b/tests/ui/identity_op.fixed @@ -217,7 +217,6 @@ fn issue_12050() { let _: i32 = *x; //~^ identity_op - } { let x = &&0i32; @@ -227,7 +226,6 @@ fn issue_12050() { let x = &&0i32; let _: i32 = **x; //~^ identity_op - } { // this is just silly @@ -250,7 +248,6 @@ fn issue_12050() { let _: i32 = **&&*&x; //~^ identity_op - } { // this is getting ridiculous, but we should still see the same @@ -261,7 +258,6 @@ fn issue_12050() { let _: i32 = ***&&*&x; //~^ identity_op - } } @@ -284,7 +280,6 @@ fn issue_13470() { let _: u64 = 5u64 + ((x + y)) as u64; //~^ identity_op - // If we don't maintain the parens here, the behavior changes let _ = -(x + y); //~^ identity_op @@ -312,10 +307,8 @@ fn issue_13470() { let _ = 2i32 + (x * y); //~^ identity_op - let x = 1i16; let y = 1i16; let _: u64 = 1u64 + ((x as i32 + y as i32) as u64); //~^ identity_op - } diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index 9d545a95bdd3..f603e1078e4e 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -217,7 +217,6 @@ fn issue_12050() { let _: i32 = x + 0; //~^ identity_op - } { let x = &&0i32; @@ -227,7 +226,6 @@ fn issue_12050() { let x = &&0i32; let _: i32 = *x + 0; //~^ identity_op - } { // this is just silly @@ -250,7 +248,6 @@ fn issue_12050() { let _: i32 = **&&*&x + 0; //~^ identity_op - } { // this is getting ridiculous, but we should still see the same @@ -261,7 +258,6 @@ fn issue_12050() { let _: i32 = **&&*&x + 0; //~^ identity_op - } } @@ -284,7 +280,6 @@ fn issue_13470() { let _: u64 = 5u64 + ((x + y) + 0i32) as u64; //~^ identity_op - // If we don't maintain the parens here, the behavior changes let _ = -(x + y + 0i32); //~^ identity_op @@ -312,10 +307,8 @@ fn issue_13470() { let _ = 2i32 + (x * y * 1i32); //~^ identity_op - let x = 1i16; let y = 1i16; let _: u64 = 1u64 + ((x as i32 + y as i32) as u64 + 0u64); //~^ identity_op - } diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index 8952f2fb7b8b..8f9c2b603c49 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -254,53 +254,59 @@ LL | let _: i32 = x + 0; | ^^^^^ help: consider reducing it to: `*x` error: this operation has no effect - --> tests/ui/identity_op.rs:224:22 + --> tests/ui/identity_op.rs:223:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> tests/ui/identity_op.rs:228:22 + --> tests/ui/identity_op.rs:227:22 | LL | let _: i32 = *x + 0; | ^^^^^^ help: consider reducing it to: `**x` error: this operation has no effect - --> tests/ui/identity_op.rs:235:22 + --> tests/ui/identity_op.rs:233:22 | LL | let _: i32 = ***x + 0; | ^^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> tests/ui/identity_op.rs:238:22 + --> tests/ui/identity_op.rs:236:22 | LL | let _: i32 = **x + 0; | ^^^^^^^ help: consider reducing it to: `***x` error: this operation has no effect - --> tests/ui/identity_op.rs:242:22 + --> tests/ui/identity_op.rs:240:22 | LL | let _: i32 = *&x + 0; | ^^^^^^^ help: consider reducing it to: `*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:245:22 + --> tests/ui/identity_op.rs:243:22 | LL | let _: i32 = **&&x + 0; | ^^^^^^^^^ help: consider reducing it to: `**&&x` error: this operation has no effect - --> tests/ui/identity_op.rs:248:22 + --> tests/ui/identity_op.rs:246:22 | LL | let _: i32 = *&*&x + 0; | ^^^^^^^^^ help: consider reducing it to: `*&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:251:22 + --> tests/ui/identity_op.rs:249:22 | LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `**&&*&x` +error: this operation has no effect + --> tests/ui/identity_op.rs:256:22 + | +LL | let _: i32 = **&&*&x + 0; + | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` + error: this operation has no effect --> tests/ui/identity_op.rs:259:22 | @@ -308,73 +314,67 @@ LL | let _: i32 = **&&*&x + 0; | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` error: this operation has no effect - --> tests/ui/identity_op.rs:262:22 - | -LL | let _: i32 = **&&*&x + 0; - | ^^^^^^^^^^^ help: consider reducing it to: `***&&*&x` - -error: this operation has no effect - --> tests/ui/identity_op.rs:272:18 + --> tests/ui/identity_op.rs:268:18 | LL | let _: u64 = (x + y + 0i32) as u64; | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:276:25 + --> tests/ui/identity_op.rs:272:25 | LL | let _: u64 = 1u64 & (x + y + 0i32) as u64; | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:280:25 + --> tests/ui/identity_op.rs:276:25 | LL | let _: u64 = 1u64 & ((x + y) + 0i32) as u64; | ^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x + y))` error: this operation has no effect - --> tests/ui/identity_op.rs:284:25 + --> tests/ui/identity_op.rs:280:25 | LL | let _: u64 = 5u64 + ((x + y) + 0i32) as u64; | ^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x + y))` error: this operation has no effect - --> tests/ui/identity_op.rs:289:14 + --> tests/ui/identity_op.rs:284:14 | LL | let _ = -(x + y + 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:293:14 + --> tests/ui/identity_op.rs:288:14 | LL | let _ = -(x / y / 1i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x / y)` error: this operation has no effect - --> tests/ui/identity_op.rs:297:20 + --> tests/ui/identity_op.rs:292:20 | LL | let _ = 2i32 * (x + y + 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x + y)` error: this operation has no effect - --> tests/ui/identity_op.rs:302:20 + --> tests/ui/identity_op.rs:297:20 | LL | let _ = 2i32 - (x - y - 0i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x - y)` error: this operation has no effect - --> tests/ui/identity_op.rs:307:17 + --> tests/ui/identity_op.rs:302:17 | LL | let _ = 2 + (x + (y * z) + 0); | ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(x + (y * z))` error: this operation has no effect - --> tests/ui/identity_op.rs:312:20 + --> tests/ui/identity_op.rs:307:20 | LL | let _ = 2i32 + (x * y * 1i32); | ^^^^^^^^^^^^^^ help: consider reducing it to: `(x * y)` error: this operation has no effect - --> tests/ui/identity_op.rs:318:25 + --> tests/ui/identity_op.rs:312:25 | LL | let _: u64 = 1u64 + ((x as i32 + y as i32) as u64 + 0u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `((x as i32 + y as i32) as u64)` diff --git a/tests/ui/if_not_else.fixed b/tests/ui/if_not_else.fixed index 1b58bdda5217..d26a15156cd8 100644 --- a/tests/ui/if_not_else.fixed +++ b/tests/ui/if_not_else.fixed @@ -12,14 +12,14 @@ fn main() { if bla() { println!("Bunny"); } else { - //~^ if_not_else + //~^ if_not_else println!("Bugs"); } if 4 == 5 { println!("Bunny"); } else { - //~^ if_not_else + //~^ if_not_else println!("Bugs"); } @@ -34,7 +34,7 @@ fn main() { if (foo() && bla()) { println!("both true"); } else { - //~^ if_not_else + //~^ if_not_else #[cfg(not(debug_assertions))] println!("not debug"); #[cfg(debug_assertions)] @@ -53,7 +53,7 @@ fn with_comments() { if foo() { println!("foo"); /* foo */ } else { - //~^ if_not_else + //~^ if_not_else /* foo is false */ println!("foo is false"); } @@ -61,7 +61,7 @@ fn with_comments() { if bla() { println!("bla"); // bla } else { - //~^ if_not_else + //~^ if_not_else // bla is false println!("bla"); } @@ -72,7 +72,7 @@ fn with_annotations() { if foo() { println!("foo"); /* foo */ } else { - //~^ if_not_else + //~^ if_not_else /* foo is false */ println!("foo is false"); } diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index 0d035e283774..6171cf116495 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -10,14 +10,14 @@ fn bla() -> bool { fn main() { if !bla() { - //~^ if_not_else + //~^ if_not_else println!("Bugs"); } else { println!("Bunny"); } if 4 != 5 { - //~^ if_not_else + //~^ if_not_else println!("Bugs"); } else { @@ -32,7 +32,7 @@ fn main() { } if !(foo() && bla()) { - //~^ if_not_else + //~^ if_not_else #[cfg(not(debug_assertions))] println!("not debug"); #[cfg(debug_assertions)] @@ -51,7 +51,7 @@ fn main() { fn with_comments() { if !foo() { - //~^ if_not_else + //~^ if_not_else /* foo is false */ println!("foo is false"); } else { @@ -59,7 +59,7 @@ fn with_comments() { } if !bla() { - //~^ if_not_else + //~^ if_not_else // bla is false println!("bla"); } else { @@ -70,7 +70,7 @@ fn with_comments() { fn with_annotations() { #[cfg(debug_assertions)] if !foo() { - //~^ if_not_else + //~^ if_not_else /* foo is false */ println!("foo is false"); } else { diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index 5eaf4015b77b..6d2e63e7299a 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -39,7 +39,6 @@ fn if_same_then_else() { } //~^^^^^^^^^^^^^^^^^ if_same_then_else - if true { Foo { bar: 42 }; } else { @@ -68,11 +67,9 @@ fn if_same_then_else() { let _ = if true { 0.0 } else { 0.0 }; //~^ if_same_then_else - let _ = if true { -0.0 } else { -0.0 }; //~^ if_same_then_else - let _ = if true { 0.0 } else { -0.0 }; // Different NaNs @@ -85,7 +82,6 @@ fn if_same_then_else() { let _ = if true { 42 } else { 42 }; //~^ if_same_then_else - if true { let bar = if true { 42 } else { 43 }; @@ -103,7 +99,6 @@ fn if_same_then_else() { } //~^^^^^^^^^^^^^^^ if_same_then_else - if true { let _ = match 42 { 42 => 1, diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index e715dbfa2258..b76da3fb1cb5 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -27,43 +27,43 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:68:21 + --> tests/ui/if_same_then_else.rs:67:21 | LL | let _ = if true { 0.0 } else { 0.0 }; | ^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:68:34 + --> tests/ui/if_same_then_else.rs:67:34 | LL | let _ = if true { 0.0 } else { 0.0 }; | ^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:72:21 + --> tests/ui/if_same_then_else.rs:70:21 | LL | let _ = if true { -0.0 } else { -0.0 }; | ^^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:72:35 + --> tests/ui/if_same_then_else.rs:70:35 | LL | let _ = if true { -0.0 } else { -0.0 }; | ^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:85:21 + --> tests/ui/if_same_then_else.rs:82:21 | LL | let _ = if true { 42 } else { 42 }; | ^^^^^^ | note: same as this - --> tests/ui/if_same_then_else.rs:85:33 + --> tests/ui/if_same_then_else.rs:82:33 | LL | let _ = if true { 42 } else { 42 }; | ^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:89:13 + --> tests/ui/if_same_then_else.rs:85:13 | LL | if true { | _____________^ @@ -76,7 +76,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else.rs:96:12 + --> tests/ui/if_same_then_else.rs:92:12 | LL | } else { | ____________^ @@ -89,7 +89,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else.rs:243:14 + --> tests/ui/if_same_then_else.rs:238:14 | LL | if x { | ______________^ @@ -98,7 +98,7 @@ LL | | } else { | |_________^ | note: same as this - --> tests/ui/if_same_then_else.rs:245:16 + --> tests/ui/if_same_then_else.rs:240:16 | LL | } else { | ________________^ diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index 2ccd85224cd3..5b74aecdacbe 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -33,7 +33,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } //~^^^^^^^^^^^^^^^^^^^ if_same_then_else - if true { if let Some(a) = Some(42) {} } else { @@ -41,7 +40,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } //~^^^^^ if_same_then_else - if true { if let (1, .., 3) = (1, 2, 3) {} } else { @@ -49,7 +47,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } //~^^^^^ if_same_then_else - if true { if let (1, .., 3) = (1, 2, 3) {} } else { @@ -96,7 +93,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { let _ = if true { f32::NAN } else { f32::NAN }; //~^ if_same_then_else - if true { Ok("foo")?; } else { @@ -104,7 +100,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } //~^^^^^ if_same_then_else - if true { let foo = ""; return Ok(&foo[0..]); @@ -131,7 +126,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> { } //~^^^^^^^ if_same_then_else - // False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559. if true { let foo = ""; diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 3465482f9872..369d6f667372 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -25,7 +25,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:37:13 + --> tests/ui/if_same_then_else2.rs:36:13 | LL | if true { | _____________^ @@ -34,7 +34,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:39:12 + --> tests/ui/if_same_then_else2.rs:38:12 | LL | } else { | ____________^ @@ -43,7 +43,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:45:13 + --> tests/ui/if_same_then_else2.rs:43:13 | LL | if true { | _____________^ @@ -52,7 +52,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:47:12 + --> tests/ui/if_same_then_else2.rs:45:12 | LL | } else { | ____________^ @@ -61,19 +61,19 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:96:21 + --> tests/ui/if_same_then_else2.rs:93:21 | LL | let _ = if true { f32::NAN } else { f32::NAN }; | ^^^^^^^^^^^^ | note: same as this - --> tests/ui/if_same_then_else2.rs:96:39 + --> tests/ui/if_same_then_else2.rs:93:39 | LL | let _ = if true { f32::NAN } else { f32::NAN }; | ^^^^^^^^^^^^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:100:13 + --> tests/ui/if_same_then_else2.rs:96:13 | LL | if true { | _____________^ @@ -82,7 +82,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:102:12 + --> tests/ui/if_same_then_else2.rs:98:12 | LL | } else { | ____________^ @@ -91,7 +91,7 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> tests/ui/if_same_then_else2.rs:125:20 + --> tests/ui/if_same_then_else2.rs:120:20 | LL | } else if true { | ____________________^ @@ -101,7 +101,7 @@ LL | | } else { | |_____^ | note: same as this - --> tests/ui/if_same_then_else2.rs:128:12 + --> tests/ui/if_same_then_else2.rs:123:12 | LL | } else { | ____________^ diff --git a/tests/ui/if_then_some_else_none.fixed b/tests/ui/if_then_some_else_none.fixed index 1f9ea9bf9bc0..f774608712d1 100644 --- a/tests/ui/if_then_some_else_none.fixed +++ b/tests/ui/if_then_some_else_none.fixed @@ -13,13 +13,11 @@ fn main() { let _ = x.and_then(|o| (o < 32).then_some(o)); //~^ if_then_some_else_none - // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = (!x).then_some(0); //~^ if_then_some_else_none - // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { println!("true!"); diff --git a/tests/ui/if_then_some_else_none.rs b/tests/ui/if_then_some_else_none.rs index 238d524a5522..8b8ff0a6ea00 100644 --- a/tests/ui/if_then_some_else_none.rs +++ b/tests/ui/if_then_some_else_none.rs @@ -4,7 +4,7 @@ fn main() { // Should issue an error. let _ = if foo() { - //~^ if_then_some_else_none + //~^ if_then_some_else_none println!("true!"); Some("foo") @@ -14,7 +14,7 @@ fn main() { // Should issue an error when macros are used. let _ = if matches!(true, true) { - //~^ if_then_some_else_none + //~^ if_then_some_else_none println!("true!"); Some(matches!(true, false)) @@ -27,13 +27,11 @@ fn main() { let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); //~^ if_then_some_else_none - // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = if !x { Some(0) } else { None }; //~^ if_then_some_else_none - // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { println!("true!"); @@ -88,7 +86,7 @@ fn _msrv_1_49() { #[clippy::msrv = "1.50"] fn _msrv_1_50() { let _ = if foo() { - //~^ if_then_some_else_none + //~^ if_then_some_else_none println!("true!"); Some(150) diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index a996dec236d6..71285574ef24 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -34,13 +34,13 @@ LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` - --> tests/ui/if_then_some_else_none.rs:33:13 + --> tests/ui/if_then_some_else_none.rs:32:13 | LL | let _ = if !x { Some(0) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!x).then_some(0)` error: this could be simplified with `bool::then` - --> tests/ui/if_then_some_else_none.rs:90:13 + --> tests/ui/if_then_some_else_none.rs:88:13 | LL | let _ = if foo() { | _____________^ @@ -53,7 +53,7 @@ LL | | }; | |_____^ help: try: `foo().then(|| { println!("true!"); 150 })` error: this could be simplified with `bool::then` - --> tests/ui/if_then_some_else_none.rs:140:5 + --> tests/ui/if_then_some_else_none.rs:138:5 | LL | if s == "1" { Some(true) } else { None } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(s == "1").then(|| true)` diff --git a/tests/ui/ifs_same_cond.rs b/tests/ui/ifs_same_cond.rs index 202b164d03ba..6ecb7cb1eba9 100644 --- a/tests/ui/ifs_same_cond.rs +++ b/tests/ui/ifs_same_cond.rs @@ -12,21 +12,18 @@ fn ifs_same_cond() { if b { } else if b { - //~^ ifs_same_cond - + //~^ ifs_same_cond } if a == 1 { } else if a == 1 { - //~^ ifs_same_cond - + //~^ ifs_same_cond } if 2 * a == 1 { } else if 2 * a == 2 { } else if 2 * a == 1 { - //~^ ifs_same_cond - + //~^ ifs_same_cond } else if a == 1 { } @@ -59,7 +56,7 @@ fn issue10272() { let a = String::from("ha"); if a.contains("ah") { } else if a.contains("ah") { - //~^ ifs_same_cond + //~^ ifs_same_cond // Trigger this lint } else if a.contains("ha") { diff --git a/tests/ui/ifs_same_cond.stderr b/tests/ui/ifs_same_cond.stderr index a45e01d26227..81fbb921e846 100644 --- a/tests/ui/ifs_same_cond.stderr +++ b/tests/ui/ifs_same_cond.stderr @@ -13,37 +13,37 @@ LL | if b { = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:20:15 + --> tests/ui/ifs_same_cond.rs:19:15 | LL | } else if a == 1 { | ^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:19:8 + --> tests/ui/ifs_same_cond.rs:18:8 | LL | if a == 1 { | ^^^^^^ error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:27:15 + --> tests/ui/ifs_same_cond.rs:25:15 | LL | } else if 2 * a == 1 { | ^^^^^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:25:8 + --> tests/ui/ifs_same_cond.rs:23:8 | LL | if 2 * a == 1 { | ^^^^^^^^^^ error: this `if` has the same condition as a previous `if` - --> tests/ui/ifs_same_cond.rs:61:15 + --> tests/ui/ifs_same_cond.rs:58:15 | LL | } else if a.contains("ah") { | ^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/ifs_same_cond.rs:60:8 + --> tests/ui/ifs_same_cond.rs:57:8 | LL | if a.contains("ah") { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index 423c8d501741..1b9e4a5cdee1 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -8,7 +8,7 @@ impl MyStruct { } impl MyStruct { -//~^ multiple_inherent_impl + //~^ multiple_inherent_impl fn second() {} } @@ -24,7 +24,7 @@ mod submod { } impl super::MyStruct { - //~^ multiple_inherent_impl + //~^ multiple_inherent_impl fn third() {} } @@ -46,7 +46,7 @@ impl WithArgs { fn f2() {} } impl WithArgs { -//~^ multiple_inherent_impl + //~^ multiple_inherent_impl fn f3() {} } @@ -71,5 +71,4 @@ impl OneAllowedImpl {} impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. //~^ multiple_inherent_impl - fn main() {} diff --git a/tests/ui/impl_trait_in_params.rs b/tests/ui/impl_trait_in_params.rs index 6d502a685bf7..2039f6339a87 100644 --- a/tests/ui/impl_trait_in_params.rs +++ b/tests/ui/impl_trait_in_params.rs @@ -12,7 +12,6 @@ pub fn a(_: impl Trait) {} pub fn c(_: C, _: impl Trait) {} //~^ impl_trait_in_params - // Shouldn't warn pub fn b(_: B) {} @@ -35,12 +34,12 @@ trait Private { struct S; impl S { -pub fn h(_: impl Trait) {} -//~^ impl_trait_in_params + pub fn h(_: impl Trait) {} + //~^ impl_trait_in_params fn i(_: impl Trait) {} pub fn j(_: J) {} -pub fn k>(_: K, _: impl AnotherTrait) {} -//~^ impl_trait_in_params + pub fn k>(_: K, _: impl AnotherTrait) {} + //~^ impl_trait_in_params } // Trying with traits diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr index ad735d034317..c904d5843c93 100644 --- a/tests/ui/impl_trait_in_params.stderr +++ b/tests/ui/impl_trait_in_params.stderr @@ -23,26 +23,26 @@ LL | pub fn c(_: C, _: impl Trait) {} | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> tests/ui/impl_trait_in_params.rs:38:13 + --> tests/ui/impl_trait_in_params.rs:37:17 | -LL | pub fn h(_: impl Trait) {} - | ^^^^^^^^^^ +LL | pub fn h(_: impl Trait) {} + | ^^^^^^^^^^ | help: add a type parameter | -LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {} - | +++++++++++++++++++++++++++++++ +LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {} + | +++++++++++++++++++++++++++++++ error: `impl Trait` used as a function parameter - --> tests/ui/impl_trait_in_params.rs:42:41 + --> tests/ui/impl_trait_in_params.rs:41:45 | -LL | pub fn k>(_: K, _: impl AnotherTrait) {} - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | pub fn k>(_: K, _: impl AnotherTrait) {} + | ^^^^^^^^^^^^^^^^^^^^^^ | help: add a type parameter | -LL | pub fn k, { /* Generic name */ }: AnotherTrait>(_: K, _: impl AnotherTrait) {} - | +++++++++++++++++++++++++++++++++++++++++++ +LL | pub fn k, { /* Generic name */ }: AnotherTrait>(_: K, _: impl AnotherTrait) {} + | +++++++++++++++++++++++++++++++++++++++++++ error: aborting due to 4 previous errors diff --git a/tests/ui/implicit_hasher.fixed b/tests/ui/implicit_hasher.fixed index fd6c4ffc9122..bea5b9afc43a 100644 --- a/tests/ui/implicit_hasher.fixed +++ b/tests/ui/implicit_hasher.fixed @@ -13,7 +13,7 @@ pub trait Foo: Sized { } impl Foo for HashMap { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { // OK, don't suggest to modify these let _: HashMap = HashMap::new(); @@ -23,13 +23,13 @@ impl Foo for HashMap } } impl Foo for (HashMap,) { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) } } impl Foo for HashMap { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) } @@ -47,13 +47,13 @@ impl Foo for HashMap { } impl Foo for HashSet { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) } } impl Foo for HashSet { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) } diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs index 29a1afd2efc8..afdf4da61650 100644 --- a/tests/ui/implicit_hasher.rs +++ b/tests/ui/implicit_hasher.rs @@ -13,7 +13,7 @@ pub trait Foo: Sized { } impl Foo for HashMap { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { // OK, don't suggest to modify these let _: HashMap = HashMap::new(); @@ -23,13 +23,13 @@ impl Foo for HashMap { } } impl Foo for (HashMap,) { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { ((HashMap::new(),), (HashMap::with_capacity(10),)) } } impl Foo for HashMap { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashMap::new(), HashMap::with_capacity(10)) } @@ -47,13 +47,13 @@ impl Foo for HashMap { } impl Foo for HashSet { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::new(), HashSet::with_capacity(10)) } } impl Foo for HashSet { -//~^ implicit_hasher + //~^ implicit_hasher fn make() -> (Self, Self) { (HashSet::new(), HashSet::with_capacity(10)) } diff --git a/tests/ui/implicit_saturating_add.rs b/tests/ui/implicit_saturating_add.rs index 2396db8daa0c..d9d035bdcd31 100644 --- a/tests/ui/implicit_saturating_add.rs +++ b/tests/ui/implicit_saturating_add.rs @@ -19,12 +19,12 @@ fn main() { } if u_8 != u8::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_8 += 1; } if u_8 < u8::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_8 += 1; } @@ -33,107 +33,107 @@ fn main() { } if u_16 != u16::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_16 += 1; } if u_16 < u16::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_16 += 1; } if u16::MAX > u_16 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_16 += 1; } if u_32 != u32::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_32 += 1; } if u_32 < u32::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_32 += 1; } if u32::MAX > u_32 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_32 += 1; } if u_64 != u64::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_64 += 1; } if u_64 < u64::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_64 += 1; } if u64::MAX > u_64 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_64 += 1; } if i_8 != i8::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_8 += 1; } if i_8 < i8::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_8 += 1; } if i8::MAX > i_8 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_8 += 1; } if i_16 != i16::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_16 += 1; } if i_16 < i16::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_16 += 1; } if i16::MAX > i_16 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_16 += 1; } if i_32 != i32::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_32 += 1; } if i_32 < i32::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_32 += 1; } if i32::MAX > i_32 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_32 += 1; } if i_64 != i64::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_64 += 1; } if i_64 < i64::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_64 += 1; } if i64::MAX > i_64 { - //~^ implicit_saturating_add + //~^ implicit_saturating_add i_64 += 1; } @@ -170,7 +170,7 @@ fn main() { if u_32 < 42 { println!("brace yourself!"); } else if u_32 < u32::MAX { - //~^ implicit_saturating_add + //~^ implicit_saturating_add u_32 += 1; } } diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index 5b7221b7060f..140cf0338602 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -25,7 +25,7 @@ fn main() { // Lint if u_8 > 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_8 = u_8 - 1; } @@ -33,7 +33,7 @@ fn main() { 10 => { // Lint if u_8 > 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_8 -= 1; } }, @@ -48,7 +48,7 @@ fn main() { // Lint if u_16 > 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_16 -= 1; } @@ -59,7 +59,7 @@ fn main() { // Lint if u_32 != 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_32 -= 1; } @@ -81,19 +81,19 @@ fn main() { // Lint if u_64 > 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_64 -= 1; } // Lint if 0 < u_64 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_64 -= 1; } // Lint if 0 != u_64 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_64 -= 1; } @@ -115,7 +115,7 @@ fn main() { // Lint if u_usize > 0 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub u_usize -= 1; } @@ -128,25 +128,25 @@ fn main() { // Lint if i_8 > i8::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 > i8::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 != i8::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_8 -= 1; } // Lint if i_8 != i8::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_8 -= 1; } @@ -157,25 +157,25 @@ fn main() { // Lint if i_16 > i16::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 > i16::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 != i16::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_16 -= 1; } // Lint if i_16 != i16::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_16 -= 1; } @@ -186,25 +186,25 @@ fn main() { // Lint if i_32 > i32::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 > i32::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 != i32::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_32 -= 1; } // Lint if i_32 != i32::MIN { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_32 -= 1; } @@ -215,19 +215,19 @@ fn main() { // Lint if i64::MIN < i_64 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_64 -= 1; } // Lint if i64::MIN != i_64 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_64 -= 1; } // Lint if i64::MIN < i_64 { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub i_64 -= 1; } @@ -296,7 +296,7 @@ fn regression_13524(a: usize, b: usize, c: bool) -> usize { if c { 123 } else if a >= b { - //~^ implicit_saturating_sub + //~^ implicit_saturating_sub 0 } else { b - a diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed index fe44d7c64b6e..bac7af59491f 100644 --- a/tests/ui/implied_bounds_in_impls.fixed +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -11,7 +11,7 @@ fn normal_deref(x: T) -> impl Deref { // Deref implied by DerefMut fn deref_derefmut(x: T) -> impl DerefMut { -//~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(x) } @@ -63,14 +63,14 @@ struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. fn f() -> impl DerefMut { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. fn f() -> impl DerefMut { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(42) } } @@ -98,13 +98,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion fn my_iter() -> impl DoubleEndedIterator { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion fn f() -> impl Copy { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls 1 } diff --git a/tests/ui/implied_bounds_in_impls.rs b/tests/ui/implied_bounds_in_impls.rs index 0e100262d2d9..2014cd46ada7 100644 --- a/tests/ui/implied_bounds_in_impls.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -11,7 +11,7 @@ fn normal_deref(x: T) -> impl Deref { // Deref implied by DerefMut fn deref_derefmut(x: T) -> impl Deref + DerefMut { -//~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(x) } @@ -63,14 +63,14 @@ struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. fn f() -> impl Deref + DerefMut { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. fn f() -> impl Deref + DerefMut { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls Box::new(42) } } @@ -98,13 +98,13 @@ mod issue11422 { mod issue11435 { // Associated type needs to be included on DoubleEndedIterator in the suggestion fn my_iter() -> impl Iterator + DoubleEndedIterator { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls 0..5 } // Removing the `Clone` bound should include the `+` behind it in its remove suggestion fn f() -> impl Copy + Clone { - //~^ implied_bounds_in_impls + //~^ implied_bounds_in_impls 1 } diff --git a/tests/ui/incompatible_msrv.rs b/tests/ui/incompatible_msrv.rs index 523c754437aa..b4fea4cae5ed 100644 --- a/tests/ui/incompatible_msrv.rs +++ b/tests/ui/incompatible_msrv.rs @@ -16,12 +16,10 @@ fn foo() { if let Entry::Vacant(v) = map.entry("poneyland") { v.into_key(); //~^ incompatible_msrv - } // Should warn for `sleep` but not for `Duration` (which was added in `1.3.0`). sleep(Duration::new(1, 0)); //~^ incompatible_msrv - } #[test] diff --git a/tests/ui/incompatible_msrv.stderr b/tests/ui/incompatible_msrv.stderr index f14e9810b203..56c9eae5aafa 100644 --- a/tests/ui/incompatible_msrv.stderr +++ b/tests/ui/incompatible_msrv.stderr @@ -14,7 +14,7 @@ LL | v.into_key(); | ^^^^^^^^^^ error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` - --> tests/ui/incompatible_msrv.rs:22:5 + --> tests/ui/incompatible_msrv.rs:21:5 | LL | sleep(Duration::new(1, 0)); | ^^^^^ diff --git a/tests/ui/inconsistent_struct_constructor.fixed b/tests/ui/inconsistent_struct_constructor.fixed index 1b3f27a45d6a..66232c0b9d8e 100644 --- a/tests/ui/inconsistent_struct_constructor.fixed +++ b/tests/ui/inconsistent_struct_constructor.fixed @@ -34,7 +34,7 @@ mod without_base { // Should lint. Foo { x, y, z }; - //~^ inconsistent_struct_constructor + //~^ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -66,7 +66,7 @@ mod with_base { z, ..Default::default() }; - //~^^^^ inconsistent_struct_constructor + //~^^^^ inconsistent_struct_constructor // Should NOT lint because the order is consistent with the definition. Foo { diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs index ec29bdaf93f0..8dd228e72ed7 100644 --- a/tests/ui/inconsistent_struct_constructor.rs +++ b/tests/ui/inconsistent_struct_constructor.rs @@ -34,7 +34,7 @@ mod without_base { // Should lint. Foo { y, x, z }; - //~^ inconsistent_struct_constructor + //~^ inconsistent_struct_constructor // Should NOT lint. // issue #7069. @@ -66,7 +66,7 @@ mod with_base { x, ..Default::default() }; - //~^^^^ inconsistent_struct_constructor + //~^^^^ inconsistent_struct_constructor // Should NOT lint because the order is consistent with the definition. Foo { 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 f5f66d6eca61..e19aa4acb4c1 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -12,7 +12,7 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some([slice_0, ..]) = slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice_0); } @@ -20,7 +20,7 @@ fn lintable_examples() { // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some([slice_0, ..]) = slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice_0); } @@ -28,7 +28,7 @@ fn lintable_examples() { // 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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice_2); println!("{}", slice_0); @@ -37,7 +37,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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice_0); } @@ -46,9 +46,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) { - //~^ index_refutable_slice - //~| index_refutable_slice - + //~^ index_refutable_slice + //~| index_refutable_slice println!("{} -> {}", a_2, b_1); } @@ -57,7 +56,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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{:?}", slice_1); } @@ -67,7 +66,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some([slice_0, ..]) = &slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{:?}", slice_0); } @@ -138,7 +137,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some([slice_0, ..]) = wrap.inner { - //~^ index_refutable_slice + //~^ index_refutable_slice if wrap.is_awesome { println!("This is awesome! {}", slice_0); @@ -147,7 +146,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some([slice_0, ..]) = wrap.inner { - //~^ index_refutable_slice + //~^ index_refutable_slice 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 408fd85cfe6a..290393568554 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -12,7 +12,7 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice[0]); } @@ -20,7 +20,7 @@ fn lintable_examples() { // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some(slice) = slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice[0]); } @@ -28,7 +28,7 @@ fn lintable_examples() { // 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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice[2]); println!("{}", slice[0]); @@ -37,7 +37,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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{}", slice[0]); } @@ -46,9 +46,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) { - //~^ index_refutable_slice - //~| index_refutable_slice - + //~^ index_refutable_slice + //~| index_refutable_slice println!("{} -> {}", a[2], b[1]); } @@ -57,7 +56,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 { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{:?}", slice[1]); } @@ -67,7 +66,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(slice) = &slice { - //~^ index_refutable_slice + //~^ index_refutable_slice println!("{:?}", slice[0]); } @@ -138,7 +137,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some(slice) = wrap.inner { - //~^ index_refutable_slice + //~^ index_refutable_slice if wrap.is_awesome { println!("This is awesome! {}", slice[0]); @@ -147,7 +146,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some(slice) = wrap.inner { - //~^ index_refutable_slice + //~^ index_refutable_slice 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 6abbc3d7dfad..04bc9838d0c2 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr @@ -70,7 +70,7 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let (SomeEnum::Three([_, _, a_2, ..]), Some(b)) = (a_wrapped, b_wrapped) { LL | -... +LL | LL | LL ~ println!("{} -> {}", a_2, b[1]); | @@ -85,13 +85,13 @@ help: replace the binding and indexed access with a slice pattern | LL ~ if let (SomeEnum::Three(a), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { LL | -... +LL | LL | LL ~ println!("{} -> {}", a[2], b_1); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:59:21 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:58:21 | LL | if let Some(ref slice) = slice { | ^^^^^ @@ -105,7 +105,7 @@ LL ~ println!("{:?}", slice_1); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:69:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:68:17 | LL | if let Some(slice) = &slice { | ^^^^^ @@ -119,7 +119,7 @@ LL ~ println!("{:?}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:140:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:139:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ @@ -134,7 +134,7 @@ LL ~ println!("This is awesome! {}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:149:17 + --> tests/ui/index_refutable_slice/if_let_slice_binding.rs:148:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ diff --git a/tests/ui/ineffective_open_options.fixed b/tests/ui/ineffective_open_options.fixed index c229278e78b2..03b73f99961a 100644 --- a/tests/ui/ineffective_open_options.fixed +++ b/tests/ui/ineffective_open_options.fixed @@ -5,7 +5,8 @@ use std::fs::OpenOptions; fn main() { let file = OpenOptions::new() .create(true) -//~^ ineffective_open_options + + //~^ ineffective_open_options .append(true) .open("dump.json") .unwrap(); @@ -13,7 +14,8 @@ fn main() { let file = OpenOptions::new() .create(true) .append(true) -//~^ ineffective_open_options + + //~^ ineffective_open_options .open("dump.json") .unwrap(); diff --git a/tests/ui/ineffective_open_options.rs b/tests/ui/ineffective_open_options.rs index ed1fe79a2782..e333a71490fb 100644 --- a/tests/ui/ineffective_open_options.rs +++ b/tests/ui/ineffective_open_options.rs @@ -5,8 +5,8 @@ use std::fs::OpenOptions; fn main() { let file = OpenOptions::new() .create(true) -.write(true) -//~^ ineffective_open_options + .write(true) + //~^ ineffective_open_options .append(true) .open("dump.json") .unwrap(); @@ -14,8 +14,8 @@ fn main() { let file = OpenOptions::new() .create(true) .append(true) -.write(true) -//~^ ineffective_open_options + .write(true) + //~^ ineffective_open_options .open("dump.json") .unwrap(); diff --git a/tests/ui/ineffective_open_options.stderr b/tests/ui/ineffective_open_options.stderr index afc97ecd755c..42bb0438dcee 100644 --- a/tests/ui/ineffective_open_options.stderr +++ b/tests/ui/ineffective_open_options.stderr @@ -1,17 +1,17 @@ error: unnecessary use of `.write(true)` because there is `.append(true)` - --> tests/ui/ineffective_open_options.rs:8:1 + --> tests/ui/ineffective_open_options.rs:8:9 | -LL | .write(true) - | ^^^^^^^^^^^^ help: remove `.write(true)` +LL | .write(true) + | ^^^^^^^^^^^^ help: remove `.write(true)` | = note: `-D clippy::ineffective-open-options` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ineffective_open_options)]` error: unnecessary use of `.write(true)` because there is `.append(true)` - --> tests/ui/ineffective_open_options.rs:17:1 + --> tests/ui/ineffective_open_options.rs:17:9 | -LL | .write(true) - | ^^^^^^^^^^^^ help: remove `.write(true)` +LL | .write(true) + | ^^^^^^^^^^^^ help: remove `.write(true)` error: aborting due to 2 previous errors diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs index 3db3aca18f23..5db30ebca88f 100644 --- a/tests/ui/infallible_destructuring_match.rs +++ b/tests/ui/infallible_destructuring_match.rs @@ -26,7 +26,7 @@ fn infallible_destructuring_match_enum() { // This should lint! let data = match wrapper { - //~^ infallible_destructuring_match + //~^ infallible_destructuring_match SingleVariantEnum::Variant(i) => i, }; @@ -59,7 +59,7 @@ fn infallible_destructuring_match_struct() { // This should lint! let data = match wrapper { - //~^ infallible_destructuring_match + //~^ infallible_destructuring_match TupleStruct(i) => i, }; @@ -84,7 +84,7 @@ fn infallible_destructuring_match_struct_with_noncopy() { // This should lint! (keeping `ref` in the suggestion) let data = match wrapper { - //~^ infallible_destructuring_match + //~^ infallible_destructuring_match TupleStructWithNonCopy(ref n) => n, }; @@ -104,7 +104,7 @@ fn never_enum() { // This should lint! let data = match wrapper { - //~^ infallible_destructuring_match + //~^ infallible_destructuring_match Ok(i) => i, }; diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 2f8cc954e70c..002a791a6579 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -26,8 +26,7 @@ fn infinite_iters() { .min(); // infinite iter (0..8_u32) - //~^ infinite_iter - + //~^ infinite_iter .rev() .cycle() .map(|x| x + 1_u32) @@ -60,8 +59,7 @@ fn potential_infinite_iters() { // maybe infinite iter (1..) - //~^ maybe_infinite_iter - + //~^ maybe_infinite_iter .scan(0, |state, x| { *state += x; Some(*state) @@ -83,7 +81,6 @@ fn potential_infinite_iters() { (0..).all(|x| x == 24); //~^ maybe_infinite_iter - // not infinite (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); // iterator is not exhausted @@ -110,8 +107,6 @@ mod finite_collect { let _: HashSet = (0..).collect(); //~^ infinite_iter - - // 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 ef3836a5ab59..47133a2ea62e 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -27,7 +27,6 @@ error: infinite iteration detected | LL | / (0..8_u32) LL | | -LL | | LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) @@ -35,73 +34,73 @@ LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:38:5 + --> tests/ui/infinite_iter.rs:37:5 | LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:42:5 + --> tests/ui/infinite_iter.rs:41:5 | LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:54:5 + --> tests/ui/infinite_iter.rs:53:5 | LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/infinite_iter.rs:51:8 + --> tests/ui/infinite_iter.rs:50:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:58:5 + --> tests/ui/infinite_iter.rs:57:5 | LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:62:5 + --> tests/ui/infinite_iter.rs:61:5 | LL | / (1..) LL | | -LL | | LL | | .scan(0, |state, x| { -... | +LL | | *state += x; +LL | | Some(*state) LL | | }) LL | | .min(); | |______________^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:71:5 + --> tests/ui/infinite_iter.rs:69:5 | LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:75:5 + --> tests/ui/infinite_iter.rs:73:5 | LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:79:5 + --> tests/ui/infinite_iter.rs:77:5 | LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:83:5 + --> tests/ui/infinite_iter.rs:81:5 | LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:110:31 + --> tests/ui/infinite_iter.rs:107:31 | LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 02d40e84eed9..4a0968918bfb 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -20,16 +20,14 @@ fn immutable_condition() { // Should warn when all vars mentioned are immutable let y = 0; while y < 10 { - //~^ while_immutable_condition - + //~^ while_immutable_condition println!("KO - y is immutable"); } let x = 0; while y < 10 && x < 3 { - //~^ while_immutable_condition - + //~^ while_immutable_condition let mut k = 1; k += 2; @@ -38,8 +36,7 @@ fn immutable_condition() { let cond = false; while !cond { - //~^ while_immutable_condition - + //~^ while_immutable_condition println!("KO - cond immutable"); } @@ -85,23 +82,20 @@ fn unused_var() { let (mut i, mut j) = (0, 0); while i < 3 { - //~^ while_immutable_condition - + //~^ while_immutable_condition j = 3; println!("KO - i not mentioned"); } while i < 3 && j > 0 { - //~^ while_immutable_condition - + //~^ while_immutable_condition println!("KO - i and j not mentioned"); } while i < 3 { - //~^ while_immutable_condition - + //~^ while_immutable_condition let mut i = 5; fn_mutref(&mut i); @@ -118,16 +112,14 @@ fn used_immutable() { let mut i = 0; while i < 3 { - //~^ while_immutable_condition - + //~^ while_immutable_condition fn_constref(&i); println!("KO - const reference"); } while i < 3 { - //~^ while_immutable_condition - + //~^ while_immutable_condition fn_val(i); println!("KO - passed by value"); @@ -195,8 +187,7 @@ impl Counter { fn print_n(&self, n: usize) { while self.count < n { - //~^ while_immutable_condition - + //~^ while_immutable_condition println!("KO - {} is not mutated", self.count); } @@ -206,8 +197,7 @@ impl Counter { fn while_loop_with_break_and_return() { let y = 0; while y < 10 { - //~^ while_immutable_condition - + //~^ while_immutable_condition if y == 0 { break; @@ -216,8 +206,7 @@ fn while_loop_with_break_and_return() { } while y < 10 { - //~^ while_immutable_condition - + //~^ while_immutable_condition if y == 0 { return; diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index f2876fd6ddb8..7ba1374d64f4 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -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 - --> tests/ui/infinite_loop.rs:30:11 + --> tests/ui/infinite_loop.rs:29: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 - --> tests/ui/infinite_loop.rs:40:11 + --> tests/ui/infinite_loop.rs:38: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 - --> tests/ui/infinite_loop.rs:87:11 + --> tests/ui/infinite_loop.rs:84: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 - --> tests/ui/infinite_loop.rs:95:11 + --> tests/ui/infinite_loop.rs:91: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 - --> tests/ui/infinite_loop.rs:102:11 + --> tests/ui/infinite_loop.rs:97: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 - --> tests/ui/infinite_loop.rs:120:11 + --> tests/ui/infinite_loop.rs:114: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 - --> tests/ui/infinite_loop.rs:128:11 + --> tests/ui/infinite_loop.rs:121:11 | LL | while i < 3 { | ^^^^^ @@ -64,13 +64,23 @@ 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 - --> tests/ui/infinite_loop.rs:197:15 + --> tests/ui/infinite_loop.rs:189:15 | 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 + --> tests/ui/infinite_loop.rs:199:11 + | +LL | while y < 10 { + | ^^^^^^ + | + = note: this may lead to an infinite or to a never running loop + = note: this loop contains `return`s or `break`s + = help: rewrite it as `if cond { loop { } }` + error: variables in the condition are not mutated in the loop body --> tests/ui/infinite_loop.rs:208:11 | @@ -81,15 +91,5 @@ LL | while y < 10 { = note: this loop contains `return`s or `break`s = help: rewrite it as `if cond { loop { } }` -error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:218:11 - | -LL | while y < 10 { - | ^^^^^^ - | - = note: this may lead to an infinite or to a never running loop - = note: this loop contains `return`s or `break`s - = help: rewrite it as `if cond { loop { } }` - error: aborting due to 11 previous errors diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs index b5c1a5688eca..eaa8d0088068 100644 --- a/tests/ui/infinite_loops.rs +++ b/tests/ui/infinite_loops.rs @@ -11,18 +11,18 @@ fn do_something() {} fn no_break() { loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } } fn all_inf() { loop { - //~^ infinite_loop - loop { //~^ infinite_loop - loop { + loop { //~^ infinite_loop + loop { + //~^ infinite_loop do_something(); } } @@ -36,7 +36,7 @@ fn no_break_return_some_ty() -> Option { return None; } loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } } @@ -49,7 +49,7 @@ fn no_break_never_ret() -> ! { fn no_break_never_ret_noise() { loop { - //~^ infinite_loop + //~^ infinite_loop fn inner_fn() -> ! { std::process::exit(0); } @@ -93,7 +93,7 @@ fn has_indirect_break_2(stop_num: i32) { fn break_inner_but_not_outer_1(cond: bool) { loop { - //~^ infinite_loop + //~^ infinite_loop loop { if cond { break; @@ -104,7 +104,7 @@ fn break_inner_but_not_outer_1(cond: bool) { fn break_inner_but_not_outer_2(cond: bool) { loop { - //~^ infinite_loop + //~^ infinite_loop 'inner: loop { loop { if cond { @@ -118,7 +118,7 @@ fn break_inner_but_not_outer_2(cond: bool) { fn break_outer_but_not_inner() { loop { loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } break; @@ -141,7 +141,7 @@ fn break_wrong_loop(cond: bool) { // 'inner has statement to break 'outer loop, but it was broken out of early by a labeled child loop 'outer: loop { loop { - //~^ infinite_loop + //~^ infinite_loop 'inner: loop { loop { loop { @@ -181,7 +181,7 @@ enum Foo { fn match_like() { let opt: Option = Some(1); loop { - //~^ infinite_loop + //~^ infinite_loop match opt { Some(v) => { println!("{v}"); @@ -222,12 +222,12 @@ fn match_like() { } loop { - //~^ infinite_loop + //~^ infinite_loop let _x = matches!(result, Ok(v) if v != 0).then_some(0); } loop { - //~^ infinite_loop + //~^ infinite_loop // This `return` does not return the function, so it doesn't count let _x = matches!(result, Ok(v) if v != 0).then(|| { if true { @@ -332,7 +332,7 @@ fn exit_directly(cond: bool) { trait MyTrait { fn problematic_trait_method() { loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } } @@ -342,7 +342,7 @@ trait MyTrait { impl MyTrait for String { fn could_be_problematic() { loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } } @@ -351,7 +351,7 @@ impl MyTrait for String { fn inf_loop_in_closure() { let _loop_forever = || { loop { - //~^ infinite_loop + //~^ infinite_loop do_something(); } }; @@ -365,7 +365,7 @@ fn inf_loop_in_closure() { fn inf_loop_in_res() -> Result<(), i32> { Ok(loop { - //~^ infinite_loop + //~^ infinite_loop do_something() }) } @@ -408,16 +408,16 @@ fn continue_outer() { // This should lint as we continue the loop itself 'infinite: loop { - //~^ infinite_loop + //~^ infinite_loop loop { continue 'infinite; } } // This should lint as we continue an inner loop loop { - //~^ infinite_loop - 'inner: loop { //~^ infinite_loop + 'inner: loop { + //~^ infinite_loop loop { continue 'inner; } @@ -426,7 +426,7 @@ fn continue_outer() { // This should lint as we continue the loop itself loop { - //~^ infinite_loop + //~^ infinite_loop continue; } } diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs index a1a810dad1e4..30977f2d93ac 100644 --- a/tests/ui/inherent_to_string.rs +++ b/tests/ui/inherent_to_string.rs @@ -20,7 +20,7 @@ struct J; impl A { // Should be detected; emit warning fn to_string(&self) -> String { - //~^ inherent_to_string + //~^ inherent_to_string "A.to_string()".to_string() } @@ -46,7 +46,7 @@ impl B { impl C { // Should be detected and emit error as C also implements Display fn to_string(&self) -> String { - //~^ inherent_to_string_shadow_display + //~^ inherent_to_string_shadow_display "C.to_string()".to_string() } diff --git a/tests/ui/init_numbered_fields.rs b/tests/ui/init_numbered_fields.rs index dc33921e3df9..ae5dfe889575 100644 --- a/tests/ui/init_numbered_fields.rs +++ b/tests/ui/init_numbered_fields.rs @@ -15,7 +15,7 @@ fn main() { // This should lint let _ = TupleStruct { - //~^ init_numbered_fields + //~^ init_numbered_fields 0: 1u32, 1: 42, 2: 23u8, @@ -23,7 +23,7 @@ fn main() { // This should also lint and order the fields correctly let _ = TupleStruct { - //~^ init_numbered_fields + //~^ init_numbered_fields 0: 1u32, 2: 2u8, 1: 3u32, diff --git a/tests/ui/inspect_for_each.rs b/tests/ui/inspect_for_each.rs index d3eb7fcbba4d..8bfd9cec66dc 100644 --- a/tests/ui/inspect_for_each.rs +++ b/tests/ui/inspect_for_each.rs @@ -5,7 +5,7 @@ fn main() { let mut b: Vec = Vec::new(); a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { - //~^ inspect_for_each + //~^ inspect_for_each let y = do_some(x); let z = do_more(y); diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index 6d62a6547427..7626569fd422 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -10,60 +10,60 @@ fn main() { for _ in &vec![X, X] {} let _ = vec![1, 2, 3].into_iter(); -let _ = (&vec![1, 2, 3]).iter(); -//~^ into_iter_on_ref -let _ = std::rc::Rc::from(&[X][..]).iter(); -//~^ into_iter_on_ref -let _ = std::sync::Arc::from(&[X][..]).iter(); -//~^ into_iter_on_ref + let _ = (&vec![1, 2, 3]).iter(); + //~^ into_iter_on_ref + let _ = std::rc::Rc::from(&[X][..]).iter(); + //~^ into_iter_on_ref + let _ = std::sync::Arc::from(&[X][..]).iter(); + //~^ into_iter_on_ref -let _ = (&&&&&&&[1, 2, 3]).iter(); -//~^ into_iter_on_ref -let _ = (&&&&mut &&&[1, 2, 3]).iter(); -//~^ into_iter_on_ref -let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); -//~^ into_iter_on_ref + let _ = (&&&&&&&[1, 2, 3]).iter(); + //~^ into_iter_on_ref + let _ = (&&&&mut &&&[1, 2, 3]).iter(); + //~^ into_iter_on_ref + let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); + //~^ into_iter_on_ref -let _ = (&Some(4)).iter(); -//~^ into_iter_on_ref -let _ = (&mut Some(5)).iter_mut(); -//~^ into_iter_on_ref -let _ = (&Ok::<_, i32>(6)).iter(); -//~^ into_iter_on_ref -let _ = (&mut Err::(7)).iter_mut(); -//~^ into_iter_on_ref -let _ = (&Vec::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&mut Vec::::new()).iter_mut(); -//~^ into_iter_on_ref -let _ = (&BTreeMap::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&mut BTreeMap::::new()).iter_mut(); -//~^ into_iter_on_ref -let _ = (&VecDeque::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&mut VecDeque::::new()).iter_mut(); -//~^ into_iter_on_ref -let _ = (&LinkedList::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&mut LinkedList::::new()).iter_mut(); -//~^ into_iter_on_ref -let _ = (&HashMap::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&mut HashMap::::new()).iter_mut(); -//~^ into_iter_on_ref + let _ = (&Some(4)).iter(); + //~^ into_iter_on_ref + let _ = (&mut Some(5)).iter_mut(); + //~^ into_iter_on_ref + let _ = (&Ok::<_, i32>(6)).iter(); + //~^ into_iter_on_ref + let _ = (&mut Err::(7)).iter_mut(); + //~^ into_iter_on_ref + let _ = (&Vec::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&mut Vec::::new()).iter_mut(); + //~^ into_iter_on_ref + let _ = (&BTreeMap::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&mut BTreeMap::::new()).iter_mut(); + //~^ into_iter_on_ref + let _ = (&VecDeque::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&mut VecDeque::::new()).iter_mut(); + //~^ into_iter_on_ref + let _ = (&LinkedList::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&mut LinkedList::::new()).iter_mut(); + //~^ into_iter_on_ref + let _ = (&HashMap::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&mut HashMap::::new()).iter_mut(); + //~^ into_iter_on_ref -let _ = (&BTreeSet::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&BinaryHeap::::new()).iter(); -//~^ into_iter_on_ref -let _ = (&HashSet::::new()).iter(); -//~^ into_iter_on_ref -let _ = std::path::Path::new("12/34").iter(); -//~^ into_iter_on_ref -let _ = std::path::PathBuf::from("12/34").iter(); -//~^ into_iter_on_ref + let _ = (&BTreeSet::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&BinaryHeap::::new()).iter(); + //~^ into_iter_on_ref + let _ = (&HashSet::::new()).iter(); + //~^ into_iter_on_ref + let _ = std::path::Path::new("12/34").iter(); + //~^ into_iter_on_ref + let _ = std::path::PathBuf::from("12/34").iter(); + //~^ into_iter_on_ref -let _ = (&[1, 2, 3]).iter().next(); -//~^ into_iter_on_ref + let _ = (&[1, 2, 3]).iter().next(); + //~^ into_iter_on_ref } diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 3e678761d751..286a62c69ce5 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -10,60 +10,60 @@ fn main() { for _ in &vec![X, X] {} let _ = vec![1, 2, 3].into_iter(); -let _ = (&vec![1, 2, 3]).into_iter(); -//~^ into_iter_on_ref -let _ = std::rc::Rc::from(&[X][..]).into_iter(); -//~^ into_iter_on_ref -let _ = std::sync::Arc::from(&[X][..]).into_iter(); -//~^ into_iter_on_ref + let _ = (&vec![1, 2, 3]).into_iter(); + //~^ into_iter_on_ref + let _ = std::rc::Rc::from(&[X][..]).into_iter(); + //~^ into_iter_on_ref + let _ = std::sync::Arc::from(&[X][..]).into_iter(); + //~^ into_iter_on_ref -let _ = (&&&&&&&[1, 2, 3]).into_iter(); -//~^ into_iter_on_ref -let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); -//~^ into_iter_on_ref + let _ = (&&&&&&&[1, 2, 3]).into_iter(); + //~^ into_iter_on_ref + let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); + //~^ into_iter_on_ref -let _ = (&Some(4)).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut Some(5)).into_iter(); -//~^ into_iter_on_ref -let _ = (&Ok::<_, i32>(6)).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut Err::(7)).into_iter(); -//~^ into_iter_on_ref -let _ = (&Vec::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut Vec::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&BTreeMap::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut BTreeMap::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&VecDeque::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut VecDeque::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&LinkedList::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut LinkedList::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&HashMap::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&mut HashMap::::new()).into_iter(); -//~^ into_iter_on_ref + let _ = (&Some(4)).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut Some(5)).into_iter(); + //~^ into_iter_on_ref + let _ = (&Ok::<_, i32>(6)).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut Err::(7)).into_iter(); + //~^ into_iter_on_ref + let _ = (&Vec::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut Vec::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&BTreeMap::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut BTreeMap::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&VecDeque::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut VecDeque::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&LinkedList::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut LinkedList::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&HashMap::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&mut HashMap::::new()).into_iter(); + //~^ into_iter_on_ref -let _ = (&BTreeSet::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&BinaryHeap::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = (&HashSet::::new()).into_iter(); -//~^ into_iter_on_ref -let _ = std::path::Path::new("12/34").into_iter(); -//~^ into_iter_on_ref -let _ = std::path::PathBuf::from("12/34").into_iter(); -//~^ into_iter_on_ref + let _ = (&BTreeSet::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&BinaryHeap::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = (&HashSet::::new()).into_iter(); + //~^ into_iter_on_ref + let _ = std::path::Path::new("12/34").into_iter(); + //~^ into_iter_on_ref + let _ = std::path::PathBuf::from("12/34").into_iter(); + //~^ into_iter_on_ref -let _ = (&[1, 2, 3]).into_iter().next(); -//~^ into_iter_on_ref + let _ = (&[1, 2, 3]).into_iter().next(); + //~^ into_iter_on_ref } diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 2c472fca9da5..57ff097a6ca2 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,161 +1,161 @@ error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> tests/ui/into_iter_on_ref.rs:13:26 + --> tests/ui/into_iter_on_ref.rs:13:30 | -LL | let _ = (&vec![1, 2, 3]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +LL | let _ = (&vec![1, 2, 3]).into_iter(); + | ^^^^^^^^^ help: call directly: `iter` | = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::into_iter_on_ref)]` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> tests/ui/into_iter_on_ref.rs:15:37 + --> tests/ui/into_iter_on_ref.rs:15:41 | -LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:17:40 + --> tests/ui/into_iter_on_ref.rs:17:44 | -LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:20:28 + --> tests/ui/into_iter_on_ref.rs:20: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` - --> tests/ui/into_iter_on_ref.rs:22:32 - | -LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); +LL | let _ = (&&&&&&&[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` - --> tests/ui/into_iter_on_ref.rs:24:36 +error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` + --> tests/ui/into_iter_on_ref.rs:22:36 | -LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` + --> tests/ui/into_iter_on_ref.rs:24: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` - --> tests/ui/into_iter_on_ref.rs:27:20 + --> tests/ui/into_iter_on_ref.rs:27:24 | -LL | let _ = (&Some(4)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:29:24 + --> tests/ui/into_iter_on_ref.rs:29:28 | -LL | let _ = (&mut Some(5)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:31:28 + --> tests/ui/into_iter_on_ref.rs:31:32 | -LL | let _ = (&Ok::<_, i32>(6)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter` +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` - --> tests/ui/into_iter_on_ref.rs:33:33 + --> tests/ui/into_iter_on_ref.rs:33:37 | -LL | let _ = (&mut Err::(7)).into_iter(); - | ^^^^^^^^^ help: call directly: `iter_mut` +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` - --> tests/ui/into_iter_on_ref.rs:35:30 + --> tests/ui/into_iter_on_ref.rs:35: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` - --> tests/ui/into_iter_on_ref.rs:37:34 - | -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` - --> tests/ui/into_iter_on_ref.rs:39:40 - | -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` - --> tests/ui/into_iter_on_ref.rs:41:44 - | -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` - --> tests/ui/into_iter_on_ref.rs:43:35 - | -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` - --> tests/ui/into_iter_on_ref.rs:45:39 - | -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` - --> tests/ui/into_iter_on_ref.rs:47:37 - | -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` - --> tests/ui/into_iter_on_ref.rs:49:41 - | -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` - --> tests/ui/into_iter_on_ref.rs:51:39 - | -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` - --> tests/ui/into_iter_on_ref.rs:53:43 - | -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` - --> tests/ui/into_iter_on_ref.rs:56:35 - | -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` - --> tests/ui/into_iter_on_ref.rs:58:37 - | -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` - --> tests/ui/into_iter_on_ref.rs:60:34 - | -LL | let _ = (&HashSet::::new()).into_iter(); +LL | let _ = (&Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Path` - --> tests/ui/into_iter_on_ref.rs:62:39 +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Vec` + --> tests/ui/into_iter_on_ref.rs:37:38 | -LL | let _ = std::path::Path::new("12/34").into_iter(); +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` + --> tests/ui/into_iter_on_ref.rs:39: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` + --> tests/ui/into_iter_on_ref.rs:41: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` + --> tests/ui/into_iter_on_ref.rs:43:39 + | +LL | let _ = (&VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `PathBuf` - --> tests/ui/into_iter_on_ref.rs:64:43 +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `VecDeque` + --> tests/ui/into_iter_on_ref.rs:45:43 | -LL | let _ = std::path::PathBuf::from("12/34").into_iter(); +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` + --> tests/ui/into_iter_on_ref.rs:47: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` + --> tests/ui/into_iter_on_ref.rs:49: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` + --> tests/ui/into_iter_on_ref.rs:51:43 + | +LL | let _ = (&HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` -error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> tests/ui/into_iter_on_ref.rs:67:22 +error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` + --> tests/ui/into_iter_on_ref.rs:53:47 | -LL | let _ = (&[1, 2, 3]).into_iter().next(); - | ^^^^^^^^^ help: call directly: `iter` +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` + --> tests/ui/into_iter_on_ref.rs:56: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` + --> tests/ui/into_iter_on_ref.rs:58: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` + --> tests/ui/into_iter_on_ref.rs:60: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` + --> tests/ui/into_iter_on_ref.rs:62: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` + --> tests/ui/into_iter_on_ref.rs:64: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` + --> tests/ui/into_iter_on_ref.rs:67:26 + | +LL | let _ = (&[1, 2, 3]).into_iter().next(); + | ^^^^^^^^^ help: call directly: `iter` error: aborting due to 26 previous errors diff --git a/tests/ui/into_iter_without_iter.rs b/tests/ui/into_iter_without_iter.rs index 368313af6f91..45e34b3930ad 100644 --- a/tests/ui/into_iter_without_iter.rs +++ b/tests/ui/into_iter_without_iter.rs @@ -7,7 +7,7 @@ use std::iter::IntoIterator; pub struct S1; impl<'a> IntoIterator for &'a S1 { -//~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, u8>; type Item = &'a u8; fn into_iter(self) -> Self::IntoIter { @@ -15,7 +15,7 @@ impl<'a> IntoIterator for &'a S1 { } } impl<'a> IntoIterator for &'a mut S1 { -//~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, u8>; type Item = &'a mut u8; fn into_iter(self) -> Self::IntoIter { @@ -25,7 +25,7 @@ impl<'a> IntoIterator for &'a mut S1 { pub struct S2(T); impl<'a, T> IntoIterator for &'a S2 { -//~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, T>; type Item = &'a T; fn into_iter(self) -> Self::IntoIter { @@ -33,7 +33,7 @@ impl<'a, T> IntoIterator for &'a S2 { } } impl<'a, T> IntoIterator for &'a mut S2 { -//~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, T>; type Item = &'a mut T; fn into_iter(self) -> Self::IntoIter { @@ -84,7 +84,7 @@ impl<'a, T> IntoIterator for &S4<'a, T> { } impl<'a, T> IntoIterator for &mut S4<'a, T> { -//~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::IterMut<'a, T>; type Item = &'a mut T; fn into_iter(self) -> Self::IntoIter { @@ -118,7 +118,7 @@ pub struct Issue12037; macro_rules! generate_impl { () => { impl<'a> IntoIterator for &'a Issue12037 { - //~^ into_iter_without_iter + //~^ into_iter_without_iter type IntoIter = std::slice::Iter<'a, u8>; type Item = &'a u8; fn into_iter(self) -> Self::IntoIter { diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index bb2166862efc..4f3194869f43 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -21,7 +21,6 @@ fn main() { (u8 as u32) > 300; //~^ invalid_upcast_comparisons - (u8 as i32) > 300; //~^ invalid_upcast_comparisons @@ -68,7 +67,6 @@ fn main() { 300 != (u8 as i32); //~^ invalid_upcast_comparisons - // always false, since u8 -> i32 doesn't wrap (u8 as i32) < 0; //~^ invalid_upcast_comparisons @@ -83,7 +81,6 @@ fn main() { -5 == (u8 as i32); //~^ invalid_upcast_comparisons - // always false, since no u8 can be 1337 1337 == (u8 as i32); //~^ invalid_upcast_comparisons @@ -98,7 +95,6 @@ fn main() { 1337 != (u8 as u32); //~^ invalid_upcast_comparisons - // Those are Ok: (u8 as u32) > 20; 42 == (u8 as i32); @@ -135,6 +131,5 @@ fn main() { -5 >= (u8 as i32); //~^ invalid_upcast_comparisons - -5 == (u32 as i32); } diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index 911022c005c9..ef36f18eabc9 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -8,157 +8,157 @@ LL | (u8 as u32) > 300; = help: to override `-D warnings` add `#[allow(clippy::invalid_upcast_comparisons)]` error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:25:5 + --> tests/ui/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 - --> tests/ui/invalid_upcast_comparisons.rs:28:5 + --> tests/ui/invalid_upcast_comparisons.rs:27:5 | LL | (u8 as u32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:31:5 + --> tests/ui/invalid_upcast_comparisons.rs:30:5 | LL | (u8 as i32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:34:5 + --> tests/ui/invalid_upcast_comparisons.rs:33:5 | LL | 300 < (u8 as u32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:37:5 + --> tests/ui/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 false - --> tests/ui/invalid_upcast_comparisons.rs:40:5 + --> tests/ui/invalid_upcast_comparisons.rs:39:5 | LL | 300 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:43:5 + --> tests/ui/invalid_upcast_comparisons.rs:42:5 | LL | 300 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:47:5 + --> tests/ui/invalid_upcast_comparisons.rs:46:5 | LL | (u8 as u32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:50:5 + --> tests/ui/invalid_upcast_comparisons.rs:49:5 | LL | (u8 as i32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:53:5 + --> tests/ui/invalid_upcast_comparisons.rs:52:5 | LL | (u8 as u32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:56:5 + --> tests/ui/invalid_upcast_comparisons.rs:55:5 | LL | (u8 as i32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:59:5 + --> tests/ui/invalid_upcast_comparisons.rs:58:5 | LL | 300 >= (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:62:5 + --> tests/ui/invalid_upcast_comparisons.rs:61:5 | LL | 300 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:65:5 + --> tests/ui/invalid_upcast_comparisons.rs:64:5 | LL | 300 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:68:5 + --> tests/ui/invalid_upcast_comparisons.rs:67:5 | LL | 300 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:73:5 + --> tests/ui/invalid_upcast_comparisons.rs:71:5 | LL | (u8 as i32) < 0; | ^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:76:5 + --> tests/ui/invalid_upcast_comparisons.rs:74:5 | LL | -5 != (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:80:5 + --> tests/ui/invalid_upcast_comparisons.rs:78:5 | LL | (u8 as i32) >= 0; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:83:5 + --> tests/ui/invalid_upcast_comparisons.rs:81:5 | LL | -5 == (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:88:5 + --> tests/ui/invalid_upcast_comparisons.rs:85:5 | LL | 1337 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:91:5 + --> tests/ui/invalid_upcast_comparisons.rs:88:5 | LL | 1337 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:95:5 + --> tests/ui/invalid_upcast_comparisons.rs:92:5 | LL | 1337 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:98:5 + --> tests/ui/invalid_upcast_comparisons.rs:95:5 | LL | 1337 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> tests/ui/invalid_upcast_comparisons.rs:114:5 + --> tests/ui/invalid_upcast_comparisons.rs:110:5 | LL | (u8 as i32) > -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:117:5 + --> tests/ui/invalid_upcast_comparisons.rs:113:5 | LL | (u8 as i32) < -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> tests/ui/invalid_upcast_comparisons.rs:135:5 + --> tests/ui/invalid_upcast_comparisons.rs:131:5 | LL | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issue-7447.rs b/tests/ui/issue-7447.rs index 25ace345ad14..452011de1195 100644 --- a/tests/ui/issue-7447.rs +++ b/tests/ui/issue-7447.rs @@ -26,8 +26,6 @@ fn main() { byte_view(panic!()); //~^ diverging_sub_expression - group_entries(panic!()); //~^ diverging_sub_expression - } diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 1ba53631b52d..5e28c1423840 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -9,7 +9,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 - --> tests/ui/issue-7447.rs:30:19 + --> tests/ui/issue-7447.rs:29:19 | LL | group_entries(panic!()); | ^^^^^^^^ diff --git a/tests/ui/issue_2356.fixed b/tests/ui/issue_2356.fixed index c96d3c1a24f9..46ba653eba2c 100644 --- a/tests/ui/issue_2356.fixed +++ b/tests/ui/issue_2356.fixed @@ -15,7 +15,7 @@ impl Foo { fn foo2>(mut it: I) { for e in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{:?}", e); } } diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs index a4040cb37ced..defe2584a93e 100644 --- a/tests/ui/issue_2356.rs +++ b/tests/ui/issue_2356.rs @@ -15,7 +15,7 @@ impl Foo { fn foo2>(mut it: I) { while let Some(e) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{:?}", e); } } diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index aabf72a93ce2..664f0b84a207 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -4,12 +4,11 @@ async fn sink1<'a>(_: &'a str) {} // lint //~^ needless_lifetimes - async fn sink1_elided(_: &str) {} // ok // lint async fn one_to_one<'a>(s: &'a str) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes s } @@ -31,7 +30,7 @@ struct Foo; impl Foo { // ok pub async fn new(&mut self) -> Self { - //~^ wrong_self_convention + //~^ wrong_self_convention Foo {} } diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index ce0588521810..0e181025430f 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -8,13 +8,13 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` error: the following explicit lifetimes could be elided: 'a - --> tests/ui/issue_4266.rs:11:21 + --> tests/ui/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` - --> tests/ui/issue_4266.rs:33:22 + --> tests/ui/issue_4266.rs:32: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 db3583464e9a..b97c831f37ec 100644 --- a/tests/ui/items_after_statement.rs +++ b/tests/ui/items_after_statement.rs @@ -11,8 +11,7 @@ fn ok() { fn last() { foo(); fn foo() { - //~^ items_after_statements - + //~^ items_after_statements println!("foo"); } @@ -21,7 +20,7 @@ fn last() { fn main() { foo(); fn foo() { - //~^ items_after_statements + //~^ items_after_statements println!("foo"); } @@ -36,7 +35,7 @@ fn mac() { () => {{ a = 6; fn say_something() { - //~^ items_after_statements + //~^ items_after_statements println!("something"); } }}; diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index d6186f1305a0..7a5ae2c8d47d 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -2,7 +2,9 @@ error: adding items after statements is confusing, since items exist from the st --> tests/ui/items_after_statement.rs:13:5 | LL | / fn foo() { -... | +LL | | +LL | | +LL | | println!("foo"); LL | | } | |_____^ | @@ -10,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::items_after_statements)]` error: adding items after statements is confusing, since items exist from the start of the scope - --> tests/ui/items_after_statement.rs:23:5 + --> tests/ui/items_after_statement.rs:22:5 | LL | / fn foo() { LL | | @@ -20,7 +22,7 @@ LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> tests/ui/items_after_statement.rs:38:13 + --> tests/ui/items_after_statement.rs:37:13 | LL | / fn say_something() { LL | | diff --git a/tests/ui/items_after_test_module/root_module.fixed b/tests/ui/items_after_test_module/root_module.fixed index 25eff3d38f76..f036b368a667 100644 --- a/tests/ui/items_after_test_module/root_module.fixed +++ b/tests/ui/items_after_test_module/root_module.fixed @@ -17,7 +17,7 @@ macro_rules! should_lint { #[allow(clippy::allow_attributes)] #[cfg(test)] mod tests { -//~^ items_after_test_module + //~^ items_after_test_module #[test] fn hi() {} } diff --git a/tests/ui/items_after_test_module/root_module.rs b/tests/ui/items_after_test_module/root_module.rs index 94afffd92de5..de0cbb120330 100644 --- a/tests/ui/items_after_test_module/root_module.rs +++ b/tests/ui/items_after_test_module/root_module.rs @@ -10,7 +10,7 @@ fn should_not_lint() {} #[allow(clippy::allow_attributes)] #[cfg(test)] mod tests { -//~^ items_after_test_module + //~^ items_after_test_module #[test] fn hi() {} } diff --git a/tests/ui/iter_filter_is_ok.fixed b/tests/ui/iter_filter_is_ok.fixed index d3aeeff7d7b4..3223e19d23a7 100644 --- a/tests/ui/iter_filter_is_ok.fixed +++ b/tests/ui/iter_filter_is_ok.fixed @@ -17,55 +17,46 @@ fn main() { #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); //~^ iter_filter_is_ok - let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); //~^ iter_filter_is_ok - #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ iter_filter_is_ok - + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .flatten(); - //~^ iter_filter_is_ok + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); //~^ iter_filter_is_ok - let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().flatten(); //~^ iter_filter_is_ok - #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().flatten(); //~^ iter_filter_is_ok - } } diff --git a/tests/ui/iter_filter_is_ok.rs b/tests/ui/iter_filter_is_ok.rs index 7ed974876693..973653819850 100644 --- a/tests/ui/iter_filter_is_ok.rs +++ b/tests/ui/iter_filter_is_ok.rs @@ -17,55 +17,46 @@ fn main() { #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); //~^ iter_filter_is_ok - let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); //~^ iter_filter_is_ok - #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(std::result::Result::is_ok); - //~^ iter_filter_is_ok - + //~^ iter_filter_is_ok let _ = vec![Ok(1), Err(2), Ok(3)] .into_iter() .filter(|a| std::result::Result::is_ok(a)); - //~^ iter_filter_is_ok + //~^ iter_filter_is_ok #[rustfmt::skip] let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); //~^ iter_filter_is_ok - } { let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); //~^ iter_filter_is_ok - let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); //~^ iter_filter_is_ok - #[rustfmt::skip] let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); //~^ iter_filter_is_ok - } } diff --git a/tests/ui/iter_filter_is_ok.stderr b/tests/ui/iter_filter_is_ok.stderr index 56c60c093a4b..b7fd0d25cc23 100644 --- a/tests/ui/iter_filter_is_ok.stderr +++ b/tests/ui/iter_filter_is_ok.stderr @@ -20,55 +20,55 @@ LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:24:56 + --> tests/ui/iter_filter_is_ok.rs:23:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:28:56 + --> tests/ui/iter_filter_is_ok.rs:26:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|&a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:33:49 + --> tests/ui/iter_filter_is_ok.rs:30:49 | LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|&o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:41:14 + --> tests/ui/iter_filter_is_ok.rs:37:14 | LL | .filter(std::result::Result::is_ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:47:14 + --> tests/ui/iter_filter_is_ok.rs:42:14 | LL | .filter(|a| std::result::Result::is_ok(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:51:56 + --> tests/ui/iter_filter_is_ok.rs:46:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|a| { std::result::Result::is_ok(a) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:57:56 + --> tests/ui/iter_filter_is_ok.rs:51:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:61:56 + --> tests/ui/iter_filter_is_ok.rs:54:56 | LL | let _ = vec![Ok(1), Err(2), Ok(3)].into_iter().filter(|ref a| a.is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_ok` on iterator over `Result`s - --> tests/ui/iter_filter_is_ok.rs:66:49 + --> tests/ui/iter_filter_is_ok.rs:58:49 | LL | let _ = vec![Ok(1), Err(2)].into_iter().filter(|ref o| { o.is_ok() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/iter_filter_is_some.fixed b/tests/ui/iter_filter_is_some.fixed index f76e7a619079..99e764e957fb 100644 --- a/tests/ui/iter_filter_is_some.fixed +++ b/tests/ui/iter_filter_is_some.fixed @@ -21,47 +21,40 @@ fn main() { #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ iter_filter_is_some - + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)] .into_iter() .flatten(); - //~^ iter_filter_is_some + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().flatten(); //~^ iter_filter_is_some - } } diff --git a/tests/ui/iter_filter_is_some.rs b/tests/ui/iter_filter_is_some.rs index 536af0021420..ecb7a04ab4df 100644 --- a/tests/ui/iter_filter_is_some.rs +++ b/tests/ui/iter_filter_is_some.rs @@ -21,47 +21,40 @@ fn main() { #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_some() }); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(std::option::Option::is_some); - //~^ iter_filter_is_some - + //~^ iter_filter_is_some let _ = vec![Some(1), None, Some(3)] .into_iter() .filter(|a| std::option::Option::is_some(a)); - //~^ iter_filter_is_some + //~^ iter_filter_is_some #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); //~^ iter_filter_is_some - #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); //~^ iter_filter_is_some - } { let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); //~^ iter_filter_is_some - #[rustfmt::skip] let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); //~^ iter_filter_is_some - } } diff --git a/tests/ui/iter_filter_is_some.stderr b/tests/ui/iter_filter_is_some.stderr index d1653fe1b7a3..cd01a3e05cd0 100644 --- a/tests/ui/iter_filter_is_some.stderr +++ b/tests/ui/iter_filter_is_some.stderr @@ -20,43 +20,43 @@ LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|o| { o.is_ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:30:14 + --> tests/ui/iter_filter_is_some.rs:29:14 | LL | .filter(std::option::Option::is_some); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:36:14 + --> tests/ui/iter_filter_is_some.rs:34:14 | LL | .filter(|a| std::option::Option::is_some(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:40:58 + --> tests/ui/iter_filter_is_some.rs:38:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|a| { std::option::Option::is_some(a) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:46:58 + --> tests/ui/iter_filter_is_some.rs:43:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:51:58 + --> tests/ui/iter_filter_is_some.rs:47:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|&o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:57:58 + --> tests/ui/iter_filter_is_some.rs:52:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref a| a.is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `is_some` on iterator over `Option` - --> tests/ui/iter_filter_is_some.rs:62:58 + --> tests/ui/iter_filter_is_some.rs:56:58 | LL | let _ = vec![Some(1), None, Some(3)].into_iter().filter(|ref o| { o.is_some() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/iter_kv_map.fixed b/tests/ui/iter_kv_map.fixed index b9d86d8dd803..7fcab6592e26 100644 --- a/tests/ui/iter_kv_map.fixed +++ b/tests/ui/iter_kv_map.fixed @@ -52,7 +52,7 @@ fn main() { // Preserve the mut in the fix. let _ = map - //~^ iter_kv_map + //~^ iter_kv_map .clone().into_values().map(|mut val| { val += 2; val @@ -106,7 +106,7 @@ fn main() { // Preserve the mut in the fix. let _ = map - //~^ iter_kv_map + //~^ iter_kv_map .clone().into_values().map(|mut val| { val += 2; val @@ -138,7 +138,6 @@ fn msrv_1_53() { let _ = map.values().map(|v| v + 2).collect::>(); //~^ iter_kv_map - } #[clippy::msrv = "1.54"] @@ -152,14 +151,12 @@ fn msrv_1_54() { let _ = map.clone().into_keys().map(|key| key + 2).collect::>(); //~^ iter_kv_map - let _ = map.clone().into_values().collect::>(); //~^ iter_kv_map let _ = map.clone().into_values().map(|val| val + 2).collect::>(); //~^ iter_kv_map - let _ = map.keys().collect::>(); //~^ iter_kv_map @@ -168,5 +165,4 @@ fn msrv_1_54() { let _ = map.values().map(|v| v + 2).collect::>(); //~^ iter_kv_map - } diff --git a/tests/ui/iter_kv_map.rs b/tests/ui/iter_kv_map.rs index b14786180b1f..b590aef7b803 100644 --- a/tests/ui/iter_kv_map.rs +++ b/tests/ui/iter_kv_map.rs @@ -52,7 +52,7 @@ fn main() { // Preserve the mut in the fix. let _ = map - //~^ iter_kv_map + //~^ iter_kv_map .clone() .into_iter() .map(|(_, mut val)| { @@ -108,7 +108,7 @@ fn main() { // Preserve the mut in the fix. let _ = map - //~^ iter_kv_map + //~^ iter_kv_map .clone() .into_iter() .map(|(_, mut val)| { @@ -142,7 +142,6 @@ fn msrv_1_53() { let _ = map.iter().map(|(_, v)| v + 2).collect::>(); //~^ iter_kv_map - } #[clippy::msrv = "1.54"] @@ -156,14 +155,12 @@ fn msrv_1_54() { let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); //~^ iter_kv_map - let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); //~^ iter_kv_map let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); //~^ iter_kv_map - let _ = map.iter().map(|(key, _)| key).collect::>(); //~^ iter_kv_map @@ -172,5 +169,4 @@ fn msrv_1_54() { let _ = map.iter().map(|(_, v)| v + 2).collect::>(); //~^ iter_kv_map - } diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr index d99fea1124a7..00d566ed14a2 100644 --- a/tests/ui/iter_kv_map.stderr +++ b/tests/ui/iter_kv_map.stderr @@ -222,43 +222,43 @@ LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> tests/ui/iter_kv_map.rs:153:13 + --> tests/ui/iter_kv_map.rs:152:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> tests/ui/iter_kv_map.rs:156:13 + --> tests/ui/iter_kv_map.rs:155: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 - --> tests/ui/iter_kv_map.rs:160:13 + --> tests/ui/iter_kv_map.rs:158:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:163:13 + --> tests/ui/iter_kv_map.rs:161: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 keys - --> tests/ui/iter_kv_map.rs:167:13 + --> tests/ui/iter_kv_map.rs:164:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:170:13 + --> tests/ui/iter_kv_map.rs:167:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> tests/ui/iter_kv_map.rs:173:13 + --> tests/ui/iter_kv_map.rs:170:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` diff --git a/tests/ui/iter_not_returning_iterator.rs b/tests/ui/iter_not_returning_iterator.rs index 4c0c667be80f..5c8c8eb4a43d 100644 --- a/tests/ui/iter_not_returning_iterator.rs +++ b/tests/ui/iter_not_returning_iterator.rs @@ -28,14 +28,13 @@ struct Counter2 { impl Data2 { fn iter(&self) -> Counter2 { - //~^ iter_not_returning_iterator - + //~^ iter_not_returning_iterator todo!() } fn iter_mut(&self) -> Counter2 { - //~^ iter_not_returning_iterator + //~^ iter_not_returning_iterator todo!() } @@ -54,7 +53,6 @@ trait Iter { type I; fn iter(&self) -> Self::I; //~^ iter_not_returning_iterator - } impl Iter for () { diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr index 8c0ebd847110..74ee8325d53e 100644 --- a/tests/ui/iter_not_returning_iterator.stderr +++ b/tests/ui/iter_not_returning_iterator.stderr @@ -8,13 +8,13 @@ LL | fn iter(&self) -> Counter2 { = help: to override `-D warnings` add `#[allow(clippy::iter_not_returning_iterator)]` error: this method is named `iter_mut` but its return type does not implement `Iterator` - --> tests/ui/iter_not_returning_iterator.rs:37:5 + --> tests/ui/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` - --> tests/ui/iter_not_returning_iterator.rs:55:5 + --> tests/ui/iter_not_returning_iterator.rs:54:5 | LL | fn iter(&self) -> Self::I; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_on_empty_collections.fixed b/tests/ui/iter_on_empty_collections.fixed index e1e4e331843b..0c2100034e18 100644 --- a/tests/ui/iter_on_empty_collections.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -32,7 +32,7 @@ fn array() { // Don't trigger when the empty collection iter is relied upon for its concrete type // But do trigger if it is just an iterator, despite being an argument to a method for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain(std::iter::empty()) { - //~^ iter_on_empty_collections + //~^ iter_on_empty_collections println!("{i}"); } diff --git a/tests/ui/iter_on_empty_collections.rs b/tests/ui/iter_on_empty_collections.rs index 3a4ad7fb372a..0fb7a32d3691 100644 --- a/tests/ui/iter_on_empty_collections.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -32,7 +32,7 @@ fn array() { // Don't trigger when the empty collection iter is relied upon for its concrete type // But do trigger if it is just an iterator, despite being an argument to a method for i in smth.as_ref().map_or([].iter(), |s| s.iter()).chain([].iter()) { - //~^ iter_on_empty_collections + //~^ iter_on_empty_collections println!("{i}"); } diff --git a/tests/ui/iter_out_of_bounds.rs b/tests/ui/iter_out_of_bounds.rs index 243dce9939c1..b34e4ad78240 100644 --- a/tests/ui/iter_out_of_bounds.rs +++ b/tests/ui/iter_out_of_bounds.rs @@ -10,12 +10,12 @@ fn opaque_empty_iter() -> impl Iterator { fn main() { #[allow(clippy::never_loop)] for _ in [1, 2, 3].iter().skip(4) { - //~^ iter_out_of_bounds + //~^ iter_out_of_bounds unreachable!(); } for (i, _) in [1, 2, 3].iter().take(4).enumerate() { - //~^ iter_out_of_bounds + //~^ iter_out_of_bounds assert!(i <= 2); } @@ -24,56 +24,45 @@ fn main() { for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} //~^ iter_out_of_bounds - for _ in [1, 2, 3].iter().skip(4) {} //~^ iter_out_of_bounds - for _ in [1; 3].iter().skip(4) {} //~^ iter_out_of_bounds - // Should not lint for _ in opaque_empty_iter().skip(1) {} for _ in vec![1, 2, 3].iter().skip(4) {} //~^ iter_out_of_bounds - for _ in vec![1; 3].iter().skip(4) {} //~^ iter_out_of_bounds - let x = [1, 2, 3]; for _ in x.iter().skip(4) {} //~^ iter_out_of_bounds - let n = 4; for _ in x.iter().skip(n) {} //~^ iter_out_of_bounds - let empty = std::iter::empty::; for _ in empty().skip(1) {} //~^ iter_out_of_bounds - for _ in empty().take(1) {} //~^ iter_out_of_bounds - for _ in std::iter::once(1).skip(2) {} //~^ iter_out_of_bounds - for _ in std::iter::once(1).take(2) {} //~^ iter_out_of_bounds - for x in [].iter().take(1) { - //~^ iter_out_of_bounds + //~^ iter_out_of_bounds let _: &i32 = x; } diff --git a/tests/ui/iter_out_of_bounds.stderr b/tests/ui/iter_out_of_bounds.stderr index 42984e00e1d4..19ac60b9d0ac 100644 --- a/tests/ui/iter_out_of_bounds.stderr +++ b/tests/ui/iter_out_of_bounds.stderr @@ -28,7 +28,7 @@ LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:28:14 + --> tests/ui/iter_out_of_bounds.rs:27:14 | LL | for _ in [1, 2, 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | for _ in [1, 2, 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:32:14 + --> tests/ui/iter_out_of_bounds.rs:30:14 | LL | for _ in [1; 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | for _ in [1; 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:39:14 + --> tests/ui/iter_out_of_bounds.rs:36:14 | LL | for _ in vec![1, 2, 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | for _ in vec![1, 2, 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:43:14 + --> tests/ui/iter_out_of_bounds.rs:39:14 | LL | for _ in vec![1; 3].iter().skip(4) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | for _ in vec![1; 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:48:14 + --> tests/ui/iter_out_of_bounds.rs:43:14 | LL | for _ in x.iter().skip(4) {} | ^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | for _ in x.iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:53:14 + --> tests/ui/iter_out_of_bounds.rs:47:14 | LL | for _ in x.iter().skip(n) {} | ^^^^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | for _ in x.iter().skip(n) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:59:14 + --> tests/ui/iter_out_of_bounds.rs:52:14 | LL | for _ in empty().skip(1) {} | ^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL | for _ in empty().skip(1) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:63:14 + --> tests/ui/iter_out_of_bounds.rs:55:14 | LL | for _ in empty().take(1) {} | ^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | for _ in empty().take(1) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:67:14 + --> tests/ui/iter_out_of_bounds.rs:58:14 | LL | for _ in std::iter::once(1).skip(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | for _ in std::iter::once(1).skip(2) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:71:14 + --> tests/ui/iter_out_of_bounds.rs:61:14 | LL | for _ in std::iter::once(1).take(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | for _ in std::iter::once(1).take(2) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:75:14 + --> tests/ui/iter_out_of_bounds.rs:64:14 | LL | for x in [].iter().take(1) { | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_over_hash_type.rs b/tests/ui/iter_over_hash_type.rs index 0dd9544cfe01..914cc9df0de9 100644 --- a/tests/ui/iter_over_hash_type.rs +++ b/tests/ui/iter_over_hash_type.rs @@ -16,59 +16,59 @@ fn main() { // test hashset for x in &hash_set { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_set.iter() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_set.clone() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_set.drain() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } // test hashmap for (x, y) in &hash_map { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = (x, y); } for x in hash_map.keys() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_map.values() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_map.values_mut() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type *x += 1; } for x in hash_map.iter() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_map.clone() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in hash_map.drain() { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } // test type-aliased hashers for x in fx_hash_set { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } for x in fx_hash_map { - //~^ iter_over_hash_type + //~^ iter_over_hash_type let _ = x; } diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index bc6cf76a58d8..999912690290 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -28,7 +28,7 @@ fn main() { //~^ iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] - //~^ iter_overeager_cloned + //~^ iter_overeager_cloned .iter() .flatten().cloned(); diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 094760893c3e..6a860dad5afd 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -28,7 +28,7 @@ fn main() { //~^ iter_overeager_cloned let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] - //~^ iter_overeager_cloned + //~^ iter_overeager_cloned .iter() .cloned() .flatten(); diff --git a/tests/ui/iter_skip_next_unfixable.rs b/tests/ui/iter_skip_next_unfixable.rs index 273ccd25ddcc..3f855b54d12a 100644 --- a/tests/ui/iter_skip_next_unfixable.rs +++ b/tests/ui/iter_skip_next_unfixable.rs @@ -12,7 +12,6 @@ fn main() { if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); //~^ iter_skip_next - }; fn check(s: T) where @@ -20,6 +19,5 @@ fn main() { { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); //~^ iter_skip_next - } } diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index cfbf75d85304..44c5c1f85442 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -25,13 +25,13 @@ LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { | ^ error: called `skip(..).next()` on an iterator - --> tests/ui/iter_skip_next_unfixable.rs:21:29 + --> tests/ui/iter_skip_next_unfixable.rs:20: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 - --> tests/ui/iter_skip_next_unfixable.rs:17:17 + --> tests/ui/iter_skip_next_unfixable.rs:16:17 | LL | fn check(s: T) | ^ diff --git a/tests/ui/iter_without_into_iter.rs b/tests/ui/iter_without_into_iter.rs index 80fb736b9bde..dc3149be2cb4 100644 --- a/tests/ui/iter_without_into_iter.rs +++ b/tests/ui/iter_without_into_iter.rs @@ -7,11 +7,11 @@ extern crate proc_macros; pub struct S1; impl S1 { pub fn iter(&self) -> std::slice::Iter<'_, u8> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter [].iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter [].iter_mut() } } @@ -27,11 +27,11 @@ impl S2 { pub struct S3<'a>(&'a mut [u8]); impl<'a> S3<'a> { pub fn iter(&self) -> std::slice::Iter<'_, u8> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter self.0.iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter self.0.iter_mut() } } @@ -68,7 +68,7 @@ impl S7 { pub struct S8(T); impl S8 { pub fn iter(&self) -> std::slice::Iter<'static, T> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter todo!() } } @@ -77,11 +77,11 @@ impl S8 { pub struct S9(T); impl S9 { pub fn iter(&self) -> std::slice::Iter<'_, T> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter todo!() } pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter todo!() } } @@ -130,7 +130,7 @@ macro_rules! generate_impl { () => { impl Issue12037 { fn iter(&self) -> std::slice::Iter<'_, u8> { - //~^ iter_without_into_iter + //~^ iter_without_into_iter todo!() } } diff --git a/tests/ui/iterator_step_by_zero.rs b/tests/ui/iterator_step_by_zero.rs index c416095cb426..a729101bd403 100644 --- a/tests/ui/iterator_step_by_zero.rs +++ b/tests/ui/iterator_step_by_zero.rs @@ -4,14 +4,12 @@ fn main() { let _ = vec!["A", "B", "B"].iter().step_by(0); //~^ iterator_step_by_zero - let _ = "XXX".chars().step_by(0); //~^ iterator_step_by_zero let _ = (0..1).step_by(0); //~^ iterator_step_by_zero - // No error, not an iterator. let y = NotIterator; y.step_by(0); @@ -25,17 +23,14 @@ fn main() { let _ = (1..=2).step_by(0); //~^ iterator_step_by_zero - let x = 0..1; let _ = x.step_by(0); //~^ iterator_step_by_zero - // check const eval let v1 = vec![1, 2, 3]; let _ = v1.iter().step_by(2 / 3); //~^ iterator_step_by_zero - } struct NotIterator; diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr index 8cc79a978bca..0ff916b6dd5e 100644 --- a/tests/ui/iterator_step_by_zero.stderr +++ b/tests/ui/iterator_step_by_zero.stderr @@ -8,37 +8,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); = help: to override `-D warnings` add `#[allow(clippy::iterator_step_by_zero)]` error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:8:13 + --> tests/ui/iterator_step_by_zero.rs:7:13 | LL | let _ = "XXX".chars().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:11:13 + --> tests/ui/iterator_step_by_zero.rs:10:13 | LL | let _ = (0..1).step_by(0); | ^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:22:13 + --> tests/ui/iterator_step_by_zero.rs:20:13 | LL | let _ = (1..).step_by(0); | ^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:25:13 + --> tests/ui/iterator_step_by_zero.rs:23:13 | LL | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:30:13 + --> tests/ui/iterator_step_by_zero.rs:27:13 | LL | let _ = x.step_by(0); | ^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> tests/ui/iterator_step_by_zero.rs:36:13 + --> tests/ui/iterator_step_by_zero.rs:32:13 | LL | let _ = v1.iter().step_by(2 / 3); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/join_absolute_paths.rs b/tests/ui/join_absolute_paths.rs index ada160d963a6..144c9147c2a1 100644 --- a/tests/ui/join_absolute_paths.rs +++ b/tests/ui/join_absolute_paths.rs @@ -10,22 +10,18 @@ fn main() { path.join("/sh"); //~^ join_absolute_paths - let path = Path::new("C:\\Users"); path.join("\\user"); //~^ join_absolute_paths - let path = PathBuf::from("/bin"); path.join("/sh"); //~^ join_absolute_paths - let path = PathBuf::from("/bin"); path.join(r#"/sh"#); //~^ join_absolute_paths - let path: &[&str] = &["/bin"]; path.join("/sh"); diff --git a/tests/ui/join_absolute_paths.stderr b/tests/ui/join_absolute_paths.stderr index 94e8beb38446..e7fd5508823a 100644 --- a/tests/ui/join_absolute_paths.stderr +++ b/tests/ui/join_absolute_paths.stderr @@ -17,7 +17,7 @@ LL | PathBuf::from("/sh"); | ~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:15:15 + --> tests/ui/join_absolute_paths.rs:14:15 | LL | path.join("\\user"); | ^^^^^^^^ @@ -33,7 +33,7 @@ LL | PathBuf::from("\\user"); | ~~~~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:20:15 + --> tests/ui/join_absolute_paths.rs:18:15 | LL | path.join("/sh"); | ^^^^^ @@ -49,7 +49,7 @@ LL | PathBuf::from("/sh"); | ~~~~~~~~~~~~~~~~~~~~ error: argument to `Path::join` starts with a path separator - --> tests/ui/join_absolute_paths.rs:25:15 + --> tests/ui/join_absolute_paths.rs:22:15 | LL | path.join(r#"/sh"#); | ^^^^^^^^ diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 0ed562f90bc0..9e0fc03cb4e1 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -9,7 +9,7 @@ extern crate proc_macros; use proc_macros::external; enum LargeEnum { -//~^ large_enum_variant + //~^ large_enum_variant A(i32), B([i32; 8000]), } @@ -34,26 +34,26 @@ enum LargeEnumGeneric { } enum LargeEnum2 { -//~^ large_enum_variant + //~^ large_enum_variant VariantOk(i32, u32), ContainingLargeEnum(LargeEnum), } enum LargeEnum3 { -//~^ large_enum_variant + //~^ large_enum_variant ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), VoidVariant, StructLikeLittle { x: i32, y: i32 }, } enum LargeEnum4 { -//~^ large_enum_variant + //~^ large_enum_variant VariantOk(i32, u32), StructLikeLarge { x: [i32; 8000], y: i32 }, } enum LargeEnum5 { -//~^ large_enum_variant + //~^ large_enum_variant VariantOk(i32, u32), StructLikeLarge2 { x: [i32; 8000] }, } @@ -70,32 +70,32 @@ enum LargeEnum6 { } enum LargeEnum7 { -//~^ large_enum_variant + //~^ large_enum_variant A, B([u8; 1255]), C([u8; 200]), } enum LargeEnum8 { -//~^ large_enum_variant + //~^ large_enum_variant VariantOk(i32, u32), ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), } enum LargeEnum9 { -//~^ large_enum_variant + //~^ large_enum_variant A(Struct<()>), B(Struct2), } enum LargeEnumOk2 { -//~^ large_enum_variant + //~^ large_enum_variant A(T), B(Struct2), } enum LargeEnumOk3 { -//~^ large_enum_variant + //~^ large_enum_variant A(Struct), B(Struct2), } @@ -111,13 +111,13 @@ struct Struct2 { #[derive(Copy, Clone)] enum CopyableLargeEnum { -//~^ large_enum_variant + //~^ large_enum_variant A(bool), B([u64; 8000]), } enum ManuallyCopyLargeEnum { -//~^ large_enum_variant + //~^ large_enum_variant A(bool), B([u64; 8000]), } @@ -131,7 +131,7 @@ impl Clone for ManuallyCopyLargeEnum { impl Copy for ManuallyCopyLargeEnum {} enum SomeGenericPossiblyCopyEnum { -//~^ large_enum_variant + //~^ large_enum_variant A(bool, std::marker::PhantomData), B([u64; 4000]), } @@ -145,7 +145,7 @@ impl Clone for SomeGenericPossiblyCopyEnum { impl Copy for SomeGenericPossiblyCopyEnum {} enum LargeEnumWithGenerics { -//~^ large_enum_variant + //~^ large_enum_variant Small, Large((T, [u8; 512])), } @@ -155,7 +155,7 @@ struct Foo { } enum WithGenerics { -//~^ large_enum_variant + //~^ large_enum_variant Large([Foo; 64]), Small(u8), } @@ -166,13 +166,13 @@ enum PossiblyLargeEnumWithConst { } enum LargeEnumOfConst { -//~^ large_enum_variant + //~^ large_enum_variant Ok, Error(PossiblyLargeEnumWithConst<256>), } enum WithRecursion { -//~^ large_enum_variant + //~^ large_enum_variant Large([u64; 64]), Recursive(Box), } @@ -183,7 +183,7 @@ enum WithRecursionAndGenerics { } enum LargeEnumWithGenericsAndRecursive { -//~^ large_enum_variant + //~^ large_enum_variant Ok(), Error(WithRecursionAndGenerics), } @@ -219,13 +219,13 @@ mod issue11915 { } enum NoWarnings { - //~^ large_enum_variant + //~^ large_enum_variant BigBoi(PublishWithBytes), _SmallBoi(u8), } enum MakesClippyAngry { - //~^ large_enum_variant + //~^ large_enum_variant BigBoi(PublishWithVec), _SmallBoi(u8), } diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index dabb96e42918..c2159c58de1e 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -9,12 +9,9 @@ async fn wait() { let f = async { Box::pin(big_fut([0u8; 1024 * 16])).await; //~^ large_futures - - }; Box::pin(f).await //~^ large_futures - } async fn calls_fut(fut: impl std::future::Future) { loop { @@ -26,7 +23,6 @@ async fn calls_fut(fut: impl std::future::Future) { } else { Box::pin(wait()).await; //~^ large_futures - } } } @@ -38,7 +34,6 @@ pub async fn test() { Box::pin(calls_fut(fut)).await; //~^ large_futures - } pub fn foo() -> impl std::future::Future { @@ -51,7 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { Box::pin(async { - //~^ large_futures + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; @@ -64,7 +59,7 @@ pub async fn macro_expn() { macro_rules! macro_ { () => { Box::pin(async { - //~^ large_futures + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; println!("macro: {:?}", x); diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index bafb0e2e3ba5..567f6344afea 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -9,12 +9,9 @@ async fn wait() { let f = async { big_fut([0u8; 1024 * 16]).await; //~^ large_futures - - }; f.await //~^ large_futures - } async fn calls_fut(fut: impl std::future::Future) { loop { @@ -26,7 +23,6 @@ async fn calls_fut(fut: impl std::future::Future) { } else { wait().await; //~^ large_futures - } } } @@ -38,7 +34,6 @@ pub async fn test() { calls_fut(fut).await; //~^ large_futures - } pub fn foo() -> impl std::future::Future { @@ -51,7 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { async { - //~^ large_futures + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; @@ -64,7 +59,7 @@ pub async fn macro_expn() { macro_rules! macro_ { () => { async { - //~^ large_futures + //~^ large_futures let x = [0i32; 1024 * 16]; async {}.await; println!("macro: {:?}", x); diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index cefc4769e846..fd6ba4e3563d 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -8,37 +8,37 @@ LL | big_fut([0u8; 1024 * 16]).await; = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: large future with a size of 16386 bytes - --> tests/ui/large_futures.rs:15:5 + --> tests/ui/large_futures.rs:13:5 | LL | f.await | ^ help: consider `Box::pin` on it: `Box::pin(f)` error: large future with a size of 16387 bytes - --> tests/ui/large_futures.rs:21:9 + --> tests/ui/large_futures.rs:18:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> tests/ui/large_futures.rs:27:13 + --> tests/ui/large_futures.rs:24:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:36:5 + --> tests/ui/large_futures.rs:32:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> tests/ui/large_futures.rs:39:5 + --> tests/ui/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 - --> tests/ui/large_futures.rs:53:5 + --> tests/ui/large_futures.rs:48:5 | LL | / async { LL | | @@ -61,7 +61,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> tests/ui/large_futures.rs:66:13 + --> tests/ui/large_futures.rs:61:13 | LL | / async { LL | | diff --git a/tests/ui/large_stack_frames.rs b/tests/ui/large_stack_frames.rs index 81d89cc1c5ca..3ed124f69ef3 100644 --- a/tests/ui/large_stack_frames.rs +++ b/tests/ui/large_stack_frames.rs @@ -25,7 +25,7 @@ impl Default for ArrayDefault { } fn many_small_arrays() { -//~^ large_stack_frames + //~^ large_stack_frames let x = [0u8; 500_000]; let x2 = [0u8; 500_000]; @@ -36,13 +36,13 @@ fn many_small_arrays() { } fn large_return_value() -> ArrayDefault<1_000_000> { -//~^ large_stack_frames + //~^ large_stack_frames Default::default() } fn large_fn_arg(x: ArrayDefault<1_000_000>) { -//~^ large_stack_frames + //~^ large_stack_frames black_box(&x); } diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs index cd0c88b6834c..562a46306e06 100644 --- a/tests/ui/large_types_passed_by_value.rs +++ b/tests/ui/large_types_passed_by_value.rs @@ -62,12 +62,12 @@ fn foo_always(x: LargeAndCopy) { } #[inline(never)] fn foo_never(x: LargeAndCopy) { -//~^ large_types_passed_by_value + //~^ large_types_passed_by_value todo!(); } #[inline] fn foo(x: LargeAndCopy) { -//~^ large_types_passed_by_value + //~^ large_types_passed_by_value todo!(); } diff --git a/tests/ui/len_without_is_empty.rs b/tests/ui/len_without_is_empty.rs index 781c28d04bec..011833072d76 100644 --- a/tests/ui/len_without_is_empty.rs +++ b/tests/ui/len_without_is_empty.rs @@ -5,8 +5,7 @@ pub struct PubOne; impl PubOne { pub fn len(&self) -> isize { - //~^ len_without_is_empty - + //~^ len_without_is_empty 1 } @@ -56,7 +55,7 @@ impl PubAllowedStruct { } pub trait PubTraitsToo { -//~^ len_without_is_empty + //~^ len_without_is_empty fn len(&self) -> isize; } @@ -71,7 +70,7 @@ pub struct HasIsEmpty; impl HasIsEmpty { pub fn len(&self) -> isize { - //~^ len_without_is_empty + //~^ len_without_is_empty 1 } @@ -85,7 +84,7 @@ pub struct HasWrongIsEmpty; impl HasWrongIsEmpty { pub fn len(&self) -> isize { - //~^ len_without_is_empty + //~^ len_without_is_empty 1 } @@ -99,7 +98,7 @@ pub struct MismatchedSelf; impl MismatchedSelf { pub fn len(self) -> isize { - //~^ len_without_is_empty + //~^ len_without_is_empty 1 } @@ -180,7 +179,7 @@ pub trait InheritingEmpty: Empty { pub trait Foo: Sized {} pub trait DependsOnFoo: Foo { -//~^ len_without_is_empty + //~^ len_without_is_empty fn len(&mut self) -> usize; } @@ -227,7 +226,7 @@ impl OptionalLen2 { pub struct OptionalLen3; impl OptionalLen3 { pub fn len(&self) -> usize { - //~^ len_without_is_empty + //~^ len_without_is_empty 0 } @@ -241,9 +240,8 @@ impl OptionalLen3 { pub struct ResultLen; impl ResultLen { pub fn len(&self) -> Result { - //~^ len_without_is_empty - //~| result_unit_err - + //~^ len_without_is_empty + //~| result_unit_err Ok(0) } @@ -257,13 +255,13 @@ impl ResultLen { pub struct ResultLen2; impl ResultLen2 { pub fn len(&self) -> Result { - //~^ result_unit_err + //~^ result_unit_err Ok(0) } pub fn is_empty(&self) -> Result { - //~^ result_unit_err + //~^ result_unit_err Ok(true) } @@ -272,7 +270,7 @@ impl ResultLen2 { pub struct ResultLen3; impl ResultLen3 { pub fn len(&self) -> Result { - //~^ result_unit_err + //~^ result_unit_err Ok(0) } @@ -315,7 +313,7 @@ impl AsyncLenWithoutIsEmpty { } pub async fn len(&self) -> usize { - //~^ len_without_is_empty + //~^ len_without_is_empty usize::from(!self.async_task().await) } @@ -329,7 +327,7 @@ impl AsyncOptionLenWithoutIsEmpty { } pub async fn len(&self) -> Option { - //~^ len_without_is_empty + //~^ len_without_is_empty None } @@ -352,7 +350,7 @@ impl AsyncResultLenWithoutIsEmpty { } pub async fn len(&self) -> Result { - //~^ len_without_is_empty + //~^ len_without_is_empty Err(()) } @@ -469,7 +467,7 @@ pub struct Aliased2; pub type Alias2 = Aliased2; impl Alias2 { pub fn len(&self) -> usize { - //~^ len_without_is_empty + //~^ len_without_is_empty todo!() } diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index 0fd445c720bd..748a55712f88 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -8,7 +8,7 @@ LL | pub fn len(&self) -> isize { = help: to override `-D warnings` add `#[allow(clippy::len_without_is_empty)]` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> tests/ui/len_without_is_empty.rs:58:1 + --> tests/ui/len_without_is_empty.rs:57:1 | LL | / pub trait PubTraitsToo { LL | | @@ -18,45 +18,45 @@ LL | | } | |_^ error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method - --> tests/ui/len_without_is_empty.rs:73:5 + --> tests/ui/len_without_is_empty.rs:72:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:79:5 + --> tests/ui/len_without_is_empty.rs:78:5 | LL | fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature - --> tests/ui/len_without_is_empty.rs:87:5 + --> tests/ui/len_without_is_empty.rs:86:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:93:5 + --> tests/ui/len_without_is_empty.rs:92: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 - --> tests/ui/len_without_is_empty.rs:101:5 + --> tests/ui/len_without_is_empty.rs:100:5 | LL | pub fn len(self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:107:5 + --> tests/ui/len_without_is_empty.rs:106: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 - --> tests/ui/len_without_is_empty.rs:182:1 + --> tests/ui/len_without_is_empty.rs:181:1 | LL | / pub trait DependsOnFoo: Foo { LL | | @@ -66,33 +66,33 @@ LL | | } | |_^ error: struct `OptionalLen3` has a public `len` method, but the `is_empty` method has an unexpected signature - --> tests/ui/len_without_is_empty.rs:229:5 + --> tests/ui/len_without_is_empty.rs:228:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:236:5 + --> tests/ui/len_without_is_empty.rs:235: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 - --> tests/ui/len_without_is_empty.rs:243:5 + --> tests/ui/len_without_is_empty.rs:242:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> tests/ui/len_without_is_empty.rs:252:5 + --> tests/ui/len_without_is_empty.rs:250:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` or `(&self) -> Result error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:243:5 + --> tests/ui/len_without_is_empty.rs:242:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL | pub fn len(&self) -> Result { = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:259:5 + --> tests/ui/len_without_is_empty.rs:257:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:265:5 + --> tests/ui/len_without_is_empty.rs:263:5 | LL | pub fn is_empty(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | pub fn is_empty(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/len_without_is_empty.rs:274:5 + --> tests/ui/len_without_is_empty.rs:272:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,25 +126,25 @@ 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 - --> tests/ui/len_without_is_empty.rs:317:5 + --> tests/ui/len_without_is_empty.rs:315:5 | LL | pub async fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:331:5 + --> tests/ui/len_without_is_empty.rs:329:5 | LL | pub async fn len(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:354:5 + --> tests/ui/len_without_is_empty.rs:352:5 | LL | pub async fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: type `Alias2` has a public `len` method, but no `is_empty` method - --> tests/ui/len_without_is_empty.rs:471:5 + --> tests/ui/len_without_is_empty.rs:469:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/len_zero.fixed b/tests/ui/len_zero.fixed index e24a569cfde8..b8573ef13b0e 100644 --- a/tests/ui/len_zero.fixed +++ b/tests/ui/len_zero.fixed @@ -86,7 +86,7 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; if x.is_empty() { - //~^ len_zero + //~^ len_zero println!("This should not happen!"); } @@ -134,23 +134,23 @@ fn main() { let has_is_empty = HasIsEmpty; if has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 1 { @@ -162,23 +162,23 @@ fn main() { println!("This can happen."); } if has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if !has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 1 < has_is_empty.len() { @@ -193,7 +193,7 @@ fn main() { let with_is_empty: &dyn WithIsEmpty = &Wither; if with_is_empty.is_empty() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } assert!(!with_is_empty.is_empty()); diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index b558dd9a215e..ef3c49c1ab30 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -86,7 +86,7 @@ impl Deref for DerefToString { fn main() { let x = [1, 2]; if x.len() == 0 { - //~^ len_zero + //~^ len_zero println!("This should not happen!"); } @@ -134,23 +134,23 @@ fn main() { let has_is_empty = HasIsEmpty; if has_is_empty.len() == 0 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() != 0 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 0 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() < 1 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() >= 1 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if has_is_empty.len() > 1 { @@ -162,23 +162,23 @@ fn main() { println!("This can happen."); } if 0 == has_is_empty.len() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 0 != has_is_empty.len() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 0 < has_is_empty.len() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 1 <= has_is_empty.len() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 1 > has_is_empty.len() { - //~^ len_zero + //~^ len_zero println!("Or this!"); } if 1 < has_is_empty.len() { @@ -193,7 +193,7 @@ fn main() { let with_is_empty: &dyn WithIsEmpty = &Wither; if with_is_empty.len() == 0 { - //~^ len_zero + //~^ len_zero println!("Or this!"); } assert!(!with_is_empty.is_empty()); diff --git a/tests/ui/let_and_return.edition2021.fixed b/tests/ui/let_and_return.edition2021.fixed index 83e4a0298a7d..70d503018e0f 100644 --- a/tests/ui/let_and_return.edition2021.fixed +++ b/tests/ui/let_and_return.edition2021.fixed @@ -12,8 +12,6 @@ fn test() -> i32 { 5 //~^ let_and_return - - } fn test_inner() -> i32 { @@ -21,7 +19,6 @@ fn test_inner() -> i32 { 5 //~^ let_and_return - } else { 0 } @@ -85,7 +82,6 @@ fn issue_3792() -> String { stdin.lock().lines().next().unwrap().unwrap() //~^ let_and_return - } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -181,7 +177,6 @@ mod issue_5729 { (Arc::clone(&self.foo)) as _ //~^ let_and_return - } } } @@ -201,7 +196,6 @@ mod issue_11335 { E::B(x) => x, }) as _ //~^ let_and_return - } } } @@ -228,21 +222,18 @@ fn issue12801() { (if true { "a".to_string() } else { "b".to_string() } + "c") //~^ let_and_return - } fn no_par_needed() -> String { "c".to_string() + if true { "a" } else { "b" } //~^ let_and_return - } fn conjunctive_blocks() -> String { ({ "a".to_string() } + "b" + { "c" } + "d") //~^ let_and_return - } #[allow(clippy::overly_complex_bool_expr)] @@ -251,13 +242,11 @@ fn issue12801() { (if true { 2 } else { 3 } << 4) //~^ let_and_return - }; let _ = || { ({ true } || { false } && { 2 <= 3 }) //~^ let_and_return - }; } } diff --git a/tests/ui/let_and_return.edition2021.stderr b/tests/ui/let_and_return.edition2021.stderr index 4302053c7815..f9536d1b5477 100644 --- a/tests/ui/let_and_return.edition2021.stderr +++ b/tests/ui/let_and_return.edition2021.stderr @@ -15,7 +15,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:22:9 + --> tests/ui/let_and_return.rs:20:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -29,7 +29,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:86:5 + --> tests/ui/let_and_return.rs:83:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -43,7 +43,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:182:13 + --> tests/ui/let_and_return.rs:178:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding @@ -57,7 +57,7 @@ LL ~ (Arc::clone(&self.foo)) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:202:13 + --> tests/ui/let_and_return.rs:197:13 | LL | / let result = match self { LL | | E::A(x) => x, @@ -79,7 +79,7 @@ LL + }) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:229:9 + --> tests/ui/let_and_return.rs:223:9 | LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; | ------------------------------------------------------------------- unnecessary `let` binding @@ -93,7 +93,7 @@ LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:236:9 + --> tests/ui/let_and_return.rs:229:9 | LL | let s = "c".to_string() + if true { "a" } else { "b" }; | ------------------------------------------------------- unnecessary `let` binding @@ -107,7 +107,7 @@ LL ~ "c".to_string() + if true { "a" } else { "b" } | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:243:9 + --> tests/ui/let_and_return.rs:235:9 | LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; | -------------------------------------------------- unnecessary `let` binding @@ -121,7 +121,7 @@ LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:252:13 + --> tests/ui/let_and_return.rs:243:13 | LL | let s = if true { 2 } else { 3 } << 4; | -------------------------------------- unnecessary `let` binding @@ -135,7 +135,7 @@ LL ~ (if true { 2 } else { 3 } << 4) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:258:13 + --> tests/ui/let_and_return.rs:248:13 | LL | let s = { true } || { false } && { 2 <= 3 }; | -------------------------------------------- unnecessary `let` binding diff --git a/tests/ui/let_and_return.edition2024.fixed b/tests/ui/let_and_return.edition2024.fixed index 4846d6ada3ca..9990c3b71205 100644 --- a/tests/ui/let_and_return.edition2024.fixed +++ b/tests/ui/let_and_return.edition2024.fixed @@ -12,8 +12,6 @@ fn test() -> i32 { 5 //~^ let_and_return - - } fn test_inner() -> i32 { @@ -21,7 +19,6 @@ fn test_inner() -> i32 { 5 //~^ let_and_return - } else { 0 } @@ -85,7 +82,6 @@ fn issue_3792() -> String { stdin.lock().lines().next().unwrap().unwrap() //~^ let_and_return - } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -181,7 +177,6 @@ mod issue_5729 { (Arc::clone(&self.foo)) as _ //~^ let_and_return - } } } @@ -201,7 +196,6 @@ mod issue_11335 { E::B(x) => x, }) as _ //~^ let_and_return - } } } @@ -228,21 +222,18 @@ fn issue12801() { (if true { "a".to_string() } else { "b".to_string() } + "c") //~^ let_and_return - } fn no_par_needed() -> String { "c".to_string() + if true { "a" } else { "b" } //~^ let_and_return - } fn conjunctive_blocks() -> String { ({ "a".to_string() } + "b" + { "c" } + "d") //~^ let_and_return - } #[allow(clippy::overly_complex_bool_expr)] @@ -251,13 +242,11 @@ fn issue12801() { (if true { 2 } else { 3 } << 4) //~^ let_and_return - }; let _ = || { ({ true } || { false } && { 2 <= 3 }) //~^ let_and_return - }; } } diff --git a/tests/ui/let_and_return.edition2024.stderr b/tests/ui/let_and_return.edition2024.stderr index 4b7f1a019f27..ca378fa43232 100644 --- a/tests/ui/let_and_return.edition2024.stderr +++ b/tests/ui/let_and_return.edition2024.stderr @@ -15,7 +15,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:22:9 + --> tests/ui/let_and_return.rs:20:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -29,7 +29,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:86:5 + --> tests/ui/let_and_return.rs:83:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -43,7 +43,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:110:9 + --> tests/ui/let_and_return.rs:106:9 | LL | let ret = value.borrow().baz(); | ------------------------------- unnecessary `let` binding @@ -57,7 +57,7 @@ LL ~ value.borrow().baz() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:121:9 + --> tests/ui/let_and_return.rs:117:9 | LL | let ret = f(|| value.borrow().baz())(); | --------------------------------------- unnecessary `let` binding @@ -71,7 +71,7 @@ LL ~ f(|| value.borrow().baz())() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:153:13 + --> tests/ui/let_and_return.rs:149:13 | LL | let value = some_foo(&x).value(); | --------------------------------- unnecessary `let` binding @@ -85,7 +85,7 @@ LL ~ some_foo(&x).value() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:160:13 + --> tests/ui/let_and_return.rs:156:13 | LL | let value = Foo::new(&x).value(); | --------------------------------- unnecessary `let` binding @@ -99,7 +99,7 @@ LL ~ Foo::new(&x).value() | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:182:13 + --> tests/ui/let_and_return.rs:178:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding @@ -113,7 +113,7 @@ LL ~ (Arc::clone(&self.foo)) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:202:13 + --> tests/ui/let_and_return.rs:197:13 | LL | / let result = match self { LL | | E::A(x) => x, @@ -135,7 +135,7 @@ LL + }) as _ | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:229:9 + --> tests/ui/let_and_return.rs:223:9 | LL | let s = if true { "a".to_string() } else { "b".to_string() } + "c"; | ------------------------------------------------------------------- unnecessary `let` binding @@ -149,7 +149,7 @@ LL ~ (if true { "a".to_string() } else { "b".to_string() } + "c") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:236:9 + --> tests/ui/let_and_return.rs:229:9 | LL | let s = "c".to_string() + if true { "a" } else { "b" }; | ------------------------------------------------------- unnecessary `let` binding @@ -163,7 +163,7 @@ LL ~ "c".to_string() + if true { "a" } else { "b" } | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:243:9 + --> tests/ui/let_and_return.rs:235:9 | LL | let s = { "a".to_string() } + "b" + { "c" } + "d"; | -------------------------------------------------- unnecessary `let` binding @@ -177,7 +177,7 @@ LL ~ ({ "a".to_string() } + "b" + { "c" } + "d") | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:252:13 + --> tests/ui/let_and_return.rs:243:13 | LL | let s = if true { 2 } else { 3 } << 4; | -------------------------------------- unnecessary `let` binding @@ -191,7 +191,7 @@ LL ~ (if true { 2 } else { 3 } << 4) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:258:13 + --> tests/ui/let_and_return.rs:248:13 | LL | let s = { true } || { false } && { 2 <= 3 }; | -------------------------------------------- unnecessary `let` binding @@ -205,7 +205,7 @@ LL ~ ({ true } || { false } && { 2 <= 3 }) | error: returning the result of a `let` binding from a block - --> tests/ui/let_and_return.rs:271:5 + --> tests/ui/let_and_return.rs:260:5 | LL | / let r = match &*v.borrow() { LL | | Some(v) => Ok(Ok(v[0])), diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index ab5338837a53..48c20cdd60db 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -12,8 +12,6 @@ fn test() -> i32 { let x = 5; x //~^ let_and_return - - } fn test_inner() -> i32 { @@ -21,7 +19,6 @@ fn test_inner() -> i32 { let x = 5; x //~^ let_and_return - } else { 0 } @@ -85,7 +82,6 @@ fn issue_3792() -> String { let line = stdin.lock().lines().next().unwrap().unwrap(); line //~^ let_and_return - } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -181,7 +177,6 @@ mod issue_5729 { let clone = Arc::clone(&self.foo); clone //~^ let_and_return - } } } @@ -201,7 +196,6 @@ mod issue_11335 { result //~^ let_and_return - } } } @@ -228,21 +222,18 @@ fn issue12801() { let s = if true { "a".to_string() } else { "b".to_string() } + "c"; s //~^ let_and_return - } fn no_par_needed() -> String { let s = "c".to_string() + if true { "a" } else { "b" }; s //~^ let_and_return - } fn conjunctive_blocks() -> String { let s = { "a".to_string() } + "b" + { "c" } + "d"; s //~^ let_and_return - } #[allow(clippy::overly_complex_bool_expr)] @@ -251,13 +242,11 @@ fn issue12801() { let s = if true { 2 } else { 3 } << 4; s //~^ let_and_return - }; let _ = || { let s = { true } || { false } && { 2 <= 3 }; s //~^ let_and_return - }; } } diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index cc482155eda7..2db206212aa5 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -77,7 +77,6 @@ fn main() { let mut foo = 0; //~^ useless_let_if_seq - if f() { foo = 42; } @@ -85,7 +84,6 @@ fn main() { let mut bar = 0; //~^ useless_let_if_seq - if f() { f(); bar = 42; @@ -127,7 +125,6 @@ fn main() { let mut baz = 0; //~^ useless_let_if_seq - if f() { baz = 42; } diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index b63a31b99129..f59d42bf4c8d 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -2,7 +2,9 @@ error: `if _ { .. } else { .. }` is an expression --> tests/ui/let_if_seq.rs:77:5 | LL | / let mut foo = 0; -... | +LL | | +LL | | +LL | | if f() { LL | | foo = 42; LL | | } | |_____^ help: it is more idiomatic to write: `let foo = if f() { 42 } else { 0 };` @@ -12,9 +14,12 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:85:5 + --> tests/ui/let_if_seq.rs:84:5 | LL | / let mut bar = 0; +LL | | +LL | | +LL | | if f() { ... | LL | | f(); LL | | } @@ -23,7 +28,7 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:96:5 + --> tests/ui/let_if_seq.rs:94:5 | LL | / let quz; LL | | @@ -35,10 +40,12 @@ LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:127:5 + --> tests/ui/let_if_seq.rs:125:5 | LL | / let mut baz = 0; -... | +LL | | +LL | | +LL | | if f() { LL | | baz = 42; LL | | } | |_____^ help: it is more idiomatic to write: `let baz = if f() { 42 } else { 0 };` diff --git a/tests/ui/let_underscore_future.rs b/tests/ui/let_underscore_future.rs index 2d57e83fd54d..6347c792280e 100644 --- a/tests/ui/let_underscore_future.rs +++ b/tests/ui/let_underscore_future.rs @@ -17,10 +17,8 @@ fn main() { let _ = custom(); //~^ let_underscore_future - let mut future = some_async_fn(); do_something_to_future(&mut future); let _ = future; //~^ let_underscore_future - } diff --git a/tests/ui/let_underscore_future.stderr b/tests/ui/let_underscore_future.stderr index e59e1f68911a..baa489551d4a 100644 --- a/tests/ui/let_underscore_future.stderr +++ b/tests/ui/let_underscore_future.stderr @@ -17,7 +17,7 @@ LL | let _ = custom(); = help: consider awaiting the future or dropping explicitly with `std::mem::drop` error: non-binding `let` on a future - --> tests/ui/let_underscore_future.rs:23:5 + --> tests/ui/let_underscore_future.rs:22:5 | LL | let _ = future; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 730e586eea79..5cf31ec63c66 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -74,7 +74,6 @@ fn main() { let _ = l(0_u32); //~^ let_underscore_must_use - let s = S {}; let _ = s.f(); @@ -91,29 +90,23 @@ fn main() { let _ = S::p(); //~^ let_underscore_must_use - let _ = S::a(); //~^ let_underscore_must_use - let _ = if true { Ok(()) } else { Err(()) }; //~^ let_underscore_must_use - let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); //~^ let_underscore_must_use - let _ = a.map(|_| ()); //~^ let_underscore_must_use - let _ = a; //~^ let_underscore_must_use - #[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 fda2a2b2adaa..130ea11646fd 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -25,7 +25,7 @@ LL | let _ = l(0_u32); = help: consider explicitly using function result error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:80:5 + --> tests/ui/let_underscore_must_use.rs:79:5 | LL | let _ = s.f(); | ^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = s.f(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:83:5 + --> tests/ui/let_underscore_must_use.rs:82:5 | LL | let _ = s.g(); | ^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = s.g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:88:5 + --> tests/ui/let_underscore_must_use.rs:87:5 | LL | let _ = S::h(); | ^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = S::h(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:91:5 + --> tests/ui/let_underscore_must_use.rs:90:5 | LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = S::p(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:95:5 + --> tests/ui/let_underscore_must_use.rs:93:5 | LL | let _ = S::a(); | ^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = S::a(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:99:5 + --> tests/ui/let_underscore_must_use.rs:96:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/let_underscore_must_use.rs:105:5 + --> tests/ui/let_underscore_must_use.rs:101:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:109:5 + --> tests/ui/let_underscore_must_use.rs:104:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = a.map(|_| ()); = help: consider explicitly using expression value error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:113:5 + --> tests/ui/let_underscore_must_use.rs:107:5 | LL | let _ = a; | ^^^^^^^^^^ diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 23145bd132f5..5e7a2ad37a84 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -58,7 +58,7 @@ fn multiline_sugg() { let v: Vec = vec![2]; v - //~^ let_unit_value + //~^ let_unit_value .into_iter() .map(|i| i * 2) .filter(|i| i % 2 == 0) @@ -108,7 +108,7 @@ fn _returns_generic() { let x: () = if true { f() } else { f2(0) }; match Some(0) { - //~^ let_unit_value + //~^ let_unit_value None => f2(1), Some(0) => f(), Some(1) => f2(3), diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index 59800b553a8c..7b06f6940121 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -58,7 +58,7 @@ fn multiline_sugg() { let v: Vec = vec![2]; let _ = v - //~^ let_unit_value + //~^ let_unit_value .into_iter() .map(|i| i * 2) .filter(|i| i % 2 == 0) @@ -108,7 +108,7 @@ fn _returns_generic() { let x: () = if true { f() } else { f2(0) }; let x = match Some(0) { - //~^ let_unit_value + //~^ let_unit_value None => f2(1), Some(0) => f(), Some(1) => f2(3), diff --git a/tests/ui/linkedlist.rs b/tests/ui/linkedlist.rs index eddbe730c174..64a9ba0029da 100644 --- a/tests/ui/linkedlist.rs +++ b/tests/ui/linkedlist.rs @@ -11,7 +11,6 @@ const C: LinkedList = LinkedList::new(); static S: LinkedList = LinkedList::new(); //~^ linkedlist - trait Foo { type Baz = LinkedList; //~^ linkedlist @@ -21,7 +20,6 @@ trait Foo { const BAR: Option>; //~^ linkedlist - } // Ok, we don’t want to warn for implementations; see issue #605. @@ -33,13 +31,11 @@ impl Foo for LinkedList { pub struct Bar { priv_linked_list_field: LinkedList, //~^ linkedlist - pub pub_linked_list_field: LinkedList, } impl Bar { fn foo(_: LinkedList) {} //~^ linkedlist - } // All of these test should be trigger the lint because they are not @@ -48,7 +44,7 @@ fn test(my_favorite_linked_list: LinkedList) {} //~^ linkedlist fn test_ret() -> Option> { -//~^ linkedlist + //~^ linkedlist None } diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index 22382d49e3a4..419fbcc7e188 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -17,7 +17,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? - --> tests/ui/linkedlist.rs:16:16 + --> tests/ui/linkedlist.rs:15:16 | LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ @@ -25,7 +25,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? - --> tests/ui/linkedlist.rs:19:15 + --> tests/ui/linkedlist.rs:18:15 | LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ @@ -33,7 +33,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? - --> tests/ui/linkedlist.rs:22:23 + --> tests/ui/linkedlist.rs:21:23 | LL | const BAR: Option>; | ^^^^^^^^^^^^^^ @@ -41,7 +41,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? - --> tests/ui/linkedlist.rs:34:29 + --> tests/ui/linkedlist.rs:32:29 | LL | priv_linked_list_field: LinkedList, | ^^^^^^^^^^^^^^ @@ -49,7 +49,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? - --> tests/ui/linkedlist.rs:40:15 + --> tests/ui/linkedlist.rs:37:15 | LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -57,7 +57,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? - --> tests/ui/linkedlist.rs:47:34 + --> tests/ui/linkedlist.rs:43:34 | LL | fn test(my_favorite_linked_list: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -65,7 +65,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? - --> tests/ui/linkedlist.rs:50:25 + --> tests/ui/linkedlist.rs:46:25 | LL | fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index 300a2d7802dd..d21d49310a07 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -13,7 +13,6 @@ fn main() { let ok4 = 0xab_cd_i32; //~^ separated_literal_suffix - let ok5 = 0xAB_CD_u32; //~^ separated_literal_suffix @@ -23,25 +22,18 @@ fn main() { let fail1 = 0xabCD; //~^ mixed_case_hex_literals - let fail2 = 0xabCD_u32; //~^ separated_literal_suffix //~| mixed_case_hex_literals - let fail2 = 0xabCD_isize; //~^ separated_literal_suffix //~| mixed_case_hex_literals - let fail_multi_zero = 000_123usize; //~^ unseparated_literal_suffix //~| zero_prefixed_literal - - - - let ok9 = 0; let ok10 = 0_i64; //~^ separated_literal_suffix @@ -49,7 +41,6 @@ fn main() { let fail8 = 0123; //~^ zero_prefixed_literal - let ok11 = 0o123; let ok12 = 0b10_1010; @@ -65,18 +56,15 @@ fn main() { let fail19 = 12_3456_21; //~^ inconsistent_digit_grouping - let fail22 = 3__4___23; //~^ inconsistent_digit_grouping let fail23 = 3__16___23; //~^ inconsistent_digit_grouping - let fail24 = 0xAB_ABC_AB; //~^ unusual_byte_groupings - let fail25 = 0b01_100_101; let ok26 = 0x6_A0_BF; let ok27 = 0b1_0010_0101; @@ -92,5 +80,4 @@ fn issue9651() { let _ = 089; //~^ zero_prefixed_literal - } diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 1e19af071f82..dcee7169c0a8 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -8,19 +8,19 @@ LL | let ok4 = 0xab_cd_i32; = help: to override `-D warnings` add `#[allow(clippy::separated_literal_suffix)]` error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:17:15 + --> tests/ui/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 - --> tests/ui/literals.rs:20:15 + --> tests/ui/literals.rs:19:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:23:17 + --> tests/ui/literals.rs:22:17 | LL | let fail1 = 0xabCD; | ^^^^^^ @@ -29,31 +29,31 @@ LL | let fail1 = 0xabCD; = help: to override `-D warnings` add `#[allow(clippy::mixed_case_hex_literals)]` error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:27:17 + --> tests/ui/literals.rs:25:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:27:17 + --> tests/ui/literals.rs:25:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:32:17 + --> tests/ui/literals.rs:29:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> tests/ui/literals.rs:32:17 + --> tests/ui/literals.rs:29:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> tests/ui/literals.rs:37:27 + --> tests/ui/literals.rs:33:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` @@ -62,7 +62,7 @@ LL | let fail_multi_zero = 000_123usize; = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: this is a decimal constant - --> tests/ui/literals.rs:37:27 + --> tests/ui/literals.rs:33:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ @@ -79,13 +79,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:46:16 + --> tests/ui/literals.rs:38:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> tests/ui/literals.rs:49:17 + --> tests/ui/literals.rs:41:17 | LL | let fail8 = 0123; | ^^^^ @@ -100,13 +100,13 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> tests/ui/literals.rs:60:16 + --> tests/ui/literals.rs:51:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:65:18 + --> tests/ui/literals.rs:56:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` @@ -115,19 +115,19 @@ LL | let fail19 = 12_3456_21; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:69:18 + --> tests/ui/literals.rs:59:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> tests/ui/literals.rs:72:18 + --> tests/ui/literals.rs:62: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 - --> tests/ui/literals.rs:76:18 + --> tests/ui/literals.rs:65:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` @@ -136,7 +136,7 @@ LL | let fail24 = 0xAB_ABC_AB; = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: this is a decimal constant - --> tests/ui/literals.rs:87:13 + --> tests/ui/literals.rs:75:13 | LL | let _ = 08; | ^^ @@ -147,7 +147,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> tests/ui/literals.rs:90:13 + --> tests/ui/literals.rs:78:13 | LL | let _ = 09; | ^^ @@ -158,7 +158,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> tests/ui/literals.rs:93:13 + --> tests/ui/literals.rs:81:13 | LL | let _ = 089; | ^^^ diff --git a/tests/ui/manual_arithmetic_check-2.rs b/tests/ui/manual_arithmetic_check-2.rs index 51515e7d9dcf..749d15f1cbd8 100644 --- a/tests/ui/manual_arithmetic_check-2.rs +++ b/tests/ui/manual_arithmetic_check-2.rs @@ -12,7 +12,6 @@ fn main() { let result = if b < a { b - a } else { 0 }; //~^ inverted_saturating_sub - let result = if a > b { 0 } else { a - b }; //~^ inverted_saturating_sub @@ -25,7 +24,6 @@ fn main() { let result = if b <= a { 0 } else { a - b }; //~^ inverted_saturating_sub - let af = 12f32; let bf = 13f32; // Should not lint! diff --git a/tests/ui/manual_arithmetic_check-2.stderr b/tests/ui/manual_arithmetic_check-2.stderr index 3d51a8be670c..8841210befda 100644 --- a/tests/ui/manual_arithmetic_check-2.stderr +++ b/tests/ui/manual_arithmetic_check-2.stderr @@ -24,49 +24,49 @@ LL | let result = if b < a { b - a } else { 0 }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:16:23 + --> tests/ui/manual_arithmetic_check-2.rs:15:23 | LL | let result = if a > b { 0 } else { a - b }; | ^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:16:40 + --> tests/ui/manual_arithmetic_check-2.rs:15:40 | LL | let result = if a > b { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:19:23 + --> tests/ui/manual_arithmetic_check-2.rs:18:23 | LL | let result = if a >= b { 0 } else { a - b }; | ^^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:19:41 + --> tests/ui/manual_arithmetic_check-2.rs:18:41 | LL | let result = if a >= b { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:22:23 + --> tests/ui/manual_arithmetic_check-2.rs:21:23 | LL | let result = if b < a { 0 } else { a - b }; | ^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:22:40 + --> tests/ui/manual_arithmetic_check-2.rs:21:40 | LL | let result = if b < a { 0 } else { a - b }; | ^^^^^ error: inverted arithmetic check before subtraction - --> tests/ui/manual_arithmetic_check-2.rs:25:23 + --> tests/ui/manual_arithmetic_check-2.rs:24:23 | LL | let result = if b <= a { 0 } else { a - b }; | ^^ ----- help: try replacing it with: `b - a` | note: this subtraction underflows when `a < b` - --> tests/ui/manual_arithmetic_check-2.rs:25:41 + --> tests/ui/manual_arithmetic_check-2.rs:24:41 | LL | let result = if b <= a { 0 } else { a - b }; | ^^^^^ diff --git a/tests/ui/manual_arithmetic_check.fixed b/tests/ui/manual_arithmetic_check.fixed index 5bda101c7b7c..99ed1faf90a6 100644 --- a/tests/ui/manual_arithmetic_check.fixed +++ b/tests/ui/manual_arithmetic_check.fixed @@ -12,14 +12,12 @@ fn main() { let result = a.saturating_sub(b); //~^ implicit_saturating_sub - let result = a.saturating_sub(b); //~^ implicit_saturating_sub let result = a.saturating_sub(b); //~^ implicit_saturating_sub - // Should not warn! let result = if a > b { a - b } else { a - c }; diff --git a/tests/ui/manual_arithmetic_check.rs b/tests/ui/manual_arithmetic_check.rs index ba296c736f01..cf202fa35a6a 100644 --- a/tests/ui/manual_arithmetic_check.rs +++ b/tests/ui/manual_arithmetic_check.rs @@ -12,14 +12,12 @@ fn main() { let result = if b < a { a - b } else { 0 }; //~^ implicit_saturating_sub - let result = if a < b { 0 } else { a - b }; //~^ implicit_saturating_sub let result = if b > a { 0 } else { a - b }; //~^ implicit_saturating_sub - // Should not warn! let result = if a > b { a - b } else { a - c }; diff --git a/tests/ui/manual_arithmetic_check.stderr b/tests/ui/manual_arithmetic_check.stderr index fe5663f586f4..b1598a5d06dc 100644 --- a/tests/ui/manual_arithmetic_check.stderr +++ b/tests/ui/manual_arithmetic_check.stderr @@ -14,13 +14,13 @@ LL | let result = if b < a { a - b } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` error: manual arithmetic check found - --> tests/ui/manual_arithmetic_check.rs:16:18 + --> tests/ui/manual_arithmetic_check.rs:15:18 | LL | let result = if a < b { 0 } else { a - b }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` error: manual arithmetic check found - --> tests/ui/manual_arithmetic_check.rs:19:18 + --> tests/ui/manual_arithmetic_check.rs:18:18 | LL | let result = if b > a { 0 } else { a - b }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)` diff --git a/tests/ui/manual_assert.rs b/tests/ui/manual_assert.rs index 2c9b17bb8b1b..46a42c3d00af 100644 --- a/tests/ui/manual_assert.rs +++ b/tests/ui/manual_assert.rs @@ -30,11 +30,11 @@ fn main() { panic!("qaqaq{:?}", a); } if !a.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("qaqaq{:?}", a); } if !a.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("qwqwq"); } if a.len() == 3 { @@ -52,27 +52,27 @@ fn main() { } let b = vec![1, 2, 3]; if b.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("panic1"); } if b.is_empty() && a.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("panic2"); } if a.is_empty() && !b.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("panic3"); } if b.is_empty() || a.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("panic4"); } if a.is_empty() || !b.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("panic5"); } if a.is_empty() { - //~^ manual_assert + //~^ manual_assert panic!("with expansion {}", one!()) } if a.is_empty() { @@ -85,7 +85,7 @@ fn main() { fn issue7730(a: u8) { // Suggestion should preserve comment if a > 2 { - //~^ manual_assert + //~^ manual_assert // comment /* this is a multiline @@ -100,7 +100,7 @@ fn issue12505() { impl Foo { const BAR: () = if N == 0 { - //~^ manual_assert + //~^ manual_assert panic!() }; } diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index a699e40868d7..fe367b4bc7b9 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -4,7 +4,7 @@ use std::future::Future; fn fut() -> impl Future { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } @@ -21,7 +21,7 @@ fn fut3()-> impl Future { } fn empty_fut() -> impl Future { -//~^ manual_async_fn + //~^ manual_async_fn async {} } @@ -38,7 +38,7 @@ fn empty_fut3()-> impl Future { } fn core_fut() -> impl core::future::Future { -//~^ manual_async_fn + //~^ manual_async_fn async move { 42 } } @@ -61,7 +61,7 @@ async fn already_async() -> impl Future { struct S; impl S { fn inh_fut() -> impl Future { - //~^ manual_async_fn + //~^ manual_async_fn async { // NOTE: this code is here just to check that the indentation is correct in the suggested fix let a = 42; @@ -97,7 +97,7 @@ impl S { // Tests related to lifetime capture fn elided(_: &i32) -> impl Future + '_ { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } @@ -108,7 +108,7 @@ fn elided_not_bound(_: &i32) -> impl Future { #[allow(clippy::needless_lifetimes)] fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } @@ -138,17 +138,17 @@ mod issue_5765 { } pub fn issue_10450() -> impl Future { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } pub(crate) fn issue_10450_2() -> impl Future { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } pub(self) fn issue_10450_3() -> impl Future { -//~^ manual_async_fn + //~^ manual_async_fn async { 42 } } diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed index 1e2b1d009907..2450a4f4c611 100644 --- a/tests/ui/manual_clamp.fixed +++ b/tests/ui/manual_clamp.fixed @@ -152,13 +152,9 @@ fn const_main() { let x4 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - - let x5 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - - let x6 = input.clamp(CONST_MIN, CONST_MAX); let x7 = input.clamp(CONST_MIN, CONST_MAX); @@ -191,68 +187,51 @@ fn const_main() { let x16 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x17 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x18 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x19 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x20 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x21 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x22 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let x23 = input.clamp(CONST_MIN, CONST_MAX); //~^ manual_clamp - let input: f64 = cmp_min_max(1) as f64; let x24 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x25 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x26 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x27 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x28 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x29 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x30 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - let x31 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); //~^ manual_clamp - - } let mut x32 = input; x32 = x32.clamp(CONST_MIN, CONST_MAX); diff --git a/tests/ui/manual_clamp.rs b/tests/ui/manual_clamp.rs index bf40e09969a4..ee341d50768f 100644 --- a/tests/ui/manual_clamp.rs +++ b/tests/ui/manual_clamp.rs @@ -142,8 +142,7 @@ fn const_main() { let input = 0; // Min and max are const, so this should trigger the lint. let x0 = if CONST_MAX < input { - //~^ manual_clamp - + //~^ manual_clamp CONST_MAX } else if CONST_MIN > input { @@ -153,8 +152,7 @@ fn const_main() { }; let x1 = if input > CONST_MAX { - //~^ manual_clamp - + //~^ manual_clamp CONST_MAX } else if input < CONST_MIN { @@ -164,8 +162,7 @@ fn const_main() { }; let x2 = if input < CONST_MIN { - //~^ manual_clamp - + //~^ manual_clamp CONST_MIN } else if input > CONST_MAX { @@ -175,8 +172,7 @@ fn const_main() { }; let x3 = if CONST_MIN > input { - //~^ manual_clamp - + //~^ manual_clamp CONST_MIN } else if CONST_MAX < input { @@ -188,35 +184,25 @@ fn const_main() { let x4 = input.max(CONST_MIN).min(CONST_MAX); //~^ manual_clamp - - let x5 = input.min(CONST_MAX).max(CONST_MIN); //~^ manual_clamp - - let x6 = match input { - //~^ manual_clamp - - + //~^ manual_clamp x if x > CONST_MAX => CONST_MAX, x if x < CONST_MIN => CONST_MIN, x => x, }; let x7 = match input { - //~^ manual_clamp - - + //~^ manual_clamp x if x < CONST_MIN => CONST_MIN, x if x > CONST_MAX => CONST_MAX, x => x, }; let x8 = match input { - //~^ manual_clamp - - + //~^ manual_clamp x if CONST_MAX < x => CONST_MAX, x if CONST_MIN > x => CONST_MIN, x => x, @@ -224,8 +210,7 @@ fn const_main() { let mut x9 = input; if x9 < CONST_MIN { - //~^ manual_clamp - + //~^ manual_clamp x9 = CONST_MIN; } @@ -234,9 +219,7 @@ fn const_main() { } let x10 = match input { - //~^ manual_clamp - - + //~^ manual_clamp x if CONST_MIN > x => CONST_MIN, x if CONST_MAX < x => CONST_MAX, x => x, @@ -245,8 +228,7 @@ fn const_main() { let mut x11 = input; let _ = 1; if x11 > CONST_MAX { - //~^ manual_clamp - + //~^ manual_clamp x11 = CONST_MAX; } @@ -256,8 +238,7 @@ fn const_main() { let mut x12 = input; if CONST_MIN > x12 { - //~^ manual_clamp - + //~^ manual_clamp x12 = CONST_MIN; } @@ -267,8 +248,7 @@ fn const_main() { let mut x13 = input; if CONST_MAX < x13 { - //~^ manual_clamp - + //~^ manual_clamp x13 = CONST_MAX; } @@ -277,8 +257,7 @@ fn const_main() { } let x14 = if input > CONST_MAX { - //~^ manual_clamp - + //~^ manual_clamp CONST_MAX } else if input < CONST_MIN { @@ -289,8 +268,7 @@ fn const_main() { { let input = 0.0f64; let x15 = if input > CONST_F64_MAX { - //~^ manual_clamp - + //~^ manual_clamp CONST_F64_MAX } else if input < CONST_F64_MIN { @@ -305,73 +283,55 @@ fn const_main() { let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); //~^ manual_clamp - let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); //~^ manual_clamp - let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); //~^ manual_clamp - let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); //~^ manual_clamp - let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); //~^ manual_clamp - let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); //~^ manual_clamp - let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); //~^ manual_clamp - let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); //~^ manual_clamp - let input: f64 = cmp_min_max(1) as f64; let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); //~^ manual_clamp - let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); //~^ manual_clamp - let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); //~^ manual_clamp - let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); //~^ manual_clamp - let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); //~^ manual_clamp - let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); //~^ manual_clamp - let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); //~^ manual_clamp - let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); //~^ manual_clamp - - } let mut x32 = input; if x32 < CONST_MIN { - //~^ manual_clamp - + //~^ manual_clamp x32 = CONST_MIN; } else if x32 > CONST_MAX { @@ -401,8 +361,7 @@ fn const_main() { // It's important this be the last set of statements let mut x35 = input; if CONST_MAX < x35 { - //~^ manual_clamp - + //~^ manual_clamp x35 = CONST_MAX; } @@ -564,8 +523,7 @@ fn msrv_1_49() { fn msrv_1_50() { let input = 0; let _ = if input > CONST_MAX { - //~^ manual_clamp - + //~^ manual_clamp CONST_MAX } else if input < CONST_MIN { diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index ca7da23efec2..4a0e4fa51646 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -1,7 +1,10 @@ error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:226:5 + --> tests/ui/manual_clamp.rs:212:5 | LL | / if x9 < CONST_MIN { +LL | | +LL | | +LL | | x9 = CONST_MIN; ... | LL | | x9 = CONST_MAX; LL | | } @@ -12,9 +15,12 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_clamp)]` error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:247:5 + --> tests/ui/manual_clamp.rs:230:5 | LL | / if x11 > CONST_MAX { +LL | | +LL | | +LL | | x11 = CONST_MAX; ... | LL | | x11 = CONST_MIN; LL | | } @@ -23,9 +29,12 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:258:5 + --> tests/ui/manual_clamp.rs:240:5 | LL | / if CONST_MIN > x12 { +LL | | +LL | | +LL | | x12 = CONST_MIN; ... | LL | | x12 = CONST_MAX; LL | | } @@ -34,9 +43,12 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:269:5 + --> tests/ui/manual_clamp.rs:250:5 | LL | / if CONST_MAX < x13 { +LL | | +LL | | +LL | | x13 = CONST_MAX; ... | LL | | x13 = CONST_MIN; LL | | } @@ -45,9 +57,12 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:403:5 + --> tests/ui/manual_clamp.rs:363:5 | LL | / if CONST_MAX < x35 { +LL | | +LL | | +LL | | x35 = CONST_MAX; ... | LL | | x35 = CONST_MIN; LL | | } @@ -60,6 +75,9 @@ error: clamp-like pattern without using clamp function | LL | let x0 = if CONST_MAX < input { | ______________^ +LL | | +LL | | +LL | | CONST_MAX ... | LL | | input LL | | }; @@ -68,10 +86,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:155:14 + --> tests/ui/manual_clamp.rs:154:14 | LL | let x1 = if input > CONST_MAX { | ______________^ +LL | | +LL | | +LL | | CONST_MAX ... | LL | | input LL | | }; @@ -80,10 +101,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:166:14 + --> tests/ui/manual_clamp.rs:164:14 | LL | let x2 = if input < CONST_MIN { | ______________^ +LL | | +LL | | +LL | | CONST_MIN ... | LL | | input LL | | }; @@ -92,10 +116,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:177:14 + --> tests/ui/manual_clamp.rs:174:14 | LL | let x3 = if CONST_MIN > input { | ______________^ +LL | | +LL | | +LL | | CONST_MIN ... | LL | | input LL | | }; @@ -104,7 +131,7 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:188:14 + --> tests/ui/manual_clamp.rs:184:14 | LL | let x4 = input.max(CONST_MIN).min(CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -112,7 +139,7 @@ LL | let x4 = input.max(CONST_MIN).min(CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:193:14 + --> tests/ui/manual_clamp.rs:187:14 | LL | let x5 = input.min(CONST_MAX).max(CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -120,11 +147,13 @@ LL | let x5 = input.min(CONST_MAX).max(CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:198:14 + --> tests/ui/manual_clamp.rs:190:14 | LL | let x6 = match input { | ______________^ -... | +LL | | +LL | | x if x > CONST_MAX => CONST_MAX, +LL | | x if x < CONST_MIN => CONST_MIN, LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -132,11 +161,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:207:14 + --> tests/ui/manual_clamp.rs:197:14 | LL | let x7 = match input { | ______________^ -... | +LL | | +LL | | x if x < CONST_MIN => CONST_MIN, +LL | | x if x > CONST_MAX => CONST_MAX, LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -144,11 +175,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:216:14 + --> tests/ui/manual_clamp.rs:204:14 | LL | let x8 = match input { | ______________^ -... | +LL | | +LL | | x if CONST_MAX < x => CONST_MAX, +LL | | x if CONST_MIN > x => CONST_MIN, LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -156,11 +189,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:236:15 + --> tests/ui/manual_clamp.rs:221:15 | LL | let x10 = match input { | _______________^ -... | +LL | | +LL | | x if CONST_MIN > x => CONST_MIN, +LL | | x if CONST_MAX < x => CONST_MAX, LL | | x => x, LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -168,10 +203,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:279:15 + --> tests/ui/manual_clamp.rs:259:15 | LL | let x14 = if input > CONST_MAX { | _______________^ +LL | | +LL | | +LL | | CONST_MAX ... | LL | | input LL | | }; @@ -180,10 +218,13 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:291:19 + --> tests/ui/manual_clamp.rs:270:19 | LL | let x15 = if input > CONST_F64_MAX { | ___________________^ +LL | | +LL | | +LL | | CONST_F64_MAX ... | LL | | input LL | | }; @@ -193,7 +234,7 @@ LL | | }; = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:305:19 + --> tests/ui/manual_clamp.rs:283:19 | LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -201,7 +242,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 - --> tests/ui/manual_clamp.rs:309:19 + --> tests/ui/manual_clamp.rs:286:19 | LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -209,7 +250,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 - --> tests/ui/manual_clamp.rs:313:19 + --> tests/ui/manual_clamp.rs:289:19 | LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -217,7 +258,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 - --> tests/ui/manual_clamp.rs:317:19 + --> tests/ui/manual_clamp.rs:292:19 | LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -225,7 +266,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 - --> tests/ui/manual_clamp.rs:321:19 + --> tests/ui/manual_clamp.rs:295:19 | LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -233,7 +274,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 - --> tests/ui/manual_clamp.rs:325:19 + --> tests/ui/manual_clamp.rs:298:19 | LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -241,7 +282,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 - --> tests/ui/manual_clamp.rs:329:19 + --> tests/ui/manual_clamp.rs:301:19 | LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -249,7 +290,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 - --> tests/ui/manual_clamp.rs:333:19 + --> tests/ui/manual_clamp.rs:304:19 | LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -257,7 +298,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 - --> tests/ui/manual_clamp.rs:338:19 + --> tests/ui/manual_clamp.rs:308: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)` @@ -266,7 +307,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 - --> tests/ui/manual_clamp.rs:342:19 + --> tests/ui/manual_clamp.rs:311: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)` @@ -275,7 +316,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 - --> tests/ui/manual_clamp.rs:346:19 + --> tests/ui/manual_clamp.rs:314: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)` @@ -284,7 +325,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 - --> tests/ui/manual_clamp.rs:350:19 + --> tests/ui/manual_clamp.rs:317: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)` @@ -293,7 +334,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 - --> tests/ui/manual_clamp.rs:354:19 + --> tests/ui/manual_clamp.rs:320: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)` @@ -302,7 +343,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 - --> tests/ui/manual_clamp.rs:358:19 + --> tests/ui/manual_clamp.rs:323: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)` @@ -311,7 +352,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 - --> tests/ui/manual_clamp.rs:362:19 + --> tests/ui/manual_clamp.rs:326: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)` @@ -320,7 +361,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 - --> tests/ui/manual_clamp.rs:366:19 + --> tests/ui/manual_clamp.rs:329: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)` @@ -329,10 +370,13 @@ 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 - --> tests/ui/manual_clamp.rs:372:5 + --> tests/ui/manual_clamp.rs:333:5 | LL | / if x32 < CONST_MIN { -... | +LL | | +LL | | +LL | | x32 = CONST_MIN; +LL | | } else if x32 > CONST_MAX { LL | | x32 = CONST_MAX; LL | | } | |_____^ help: replace with clamp: `x32 = x32.clamp(CONST_MIN, CONST_MAX);` @@ -340,10 +384,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> tests/ui/manual_clamp.rs:566:13 + --> tests/ui/manual_clamp.rs:525:13 | LL | let _ = if input > CONST_MAX { | _____________^ +LL | | +LL | | +LL | | CONST_MAX ... | LL | | input LL | | }; diff --git a/tests/ui/manual_div_ceil.fixed b/tests/ui/manual_div_ceil.fixed index 6657c695abea..57fe8917afe8 100644 --- a/tests/ui/manual_div_ceil.fixed +++ b/tests/ui/manual_div_ceil.fixed @@ -6,17 +6,17 @@ fn main() { let z = 11_u32; // Lint -let _ = x.div_ceil(y); -//~^ manual_div_ceil -let _ = x.div_ceil(y); -//~^ manual_div_ceil -let _ = x.div_ceil(y); -//~^ manual_div_ceil + let _ = x.div_ceil(y); + //~^ manual_div_ceil + let _ = x.div_ceil(y); + //~^ manual_div_ceil + let _ = x.div_ceil(y); + //~^ manual_div_ceil -let _ = 7_u32.div_ceil(4); -//~^ manual_div_ceil -let _ = (7_i32 as u32).div_ceil(4); -//~^ manual_div_ceil + let _ = 7_u32.div_ceil(4); + //~^ manual_div_ceil + let _ = (7_i32 as u32).div_ceil(4); + //~^ manual_div_ceil // No lint let _ = (x + (y - 2)) / y; diff --git a/tests/ui/manual_div_ceil.rs b/tests/ui/manual_div_ceil.rs index 2c8506e84cb5..ec343513e5ce 100644 --- a/tests/ui/manual_div_ceil.rs +++ b/tests/ui/manual_div_ceil.rs @@ -6,17 +6,17 @@ fn main() { let z = 11_u32; // Lint -let _ = (x + (y - 1)) / y; -//~^ manual_div_ceil -let _ = ((y - 1) + x) / y; -//~^ manual_div_ceil -let _ = (x + y - 1) / y; -//~^ manual_div_ceil + let _ = (x + (y - 1)) / y; + //~^ manual_div_ceil + let _ = ((y - 1) + x) / y; + //~^ manual_div_ceil + let _ = (x + y - 1) / y; + //~^ manual_div_ceil -let _ = (7_u32 + (4 - 1)) / 4; -//~^ manual_div_ceil -let _ = (7_i32 as u32 + (4 - 1)) / 4; -//~^ manual_div_ceil + let _ = (7_u32 + (4 - 1)) / 4; + //~^ manual_div_ceil + let _ = (7_i32 as u32 + (4 - 1)) / 4; + //~^ manual_div_ceil // No lint let _ = (x + (y - 2)) / y; diff --git a/tests/ui/manual_div_ceil.stderr b/tests/ui/manual_div_ceil.stderr index d6793dcfb5f3..8e14ab274269 100644 --- a/tests/ui/manual_div_ceil.stderr +++ b/tests/ui/manual_div_ceil.stderr @@ -1,35 +1,35 @@ error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:9:9 + --> tests/ui/manual_div_ceil.rs:9:13 | -LL | let _ = (x + (y - 1)) / y; - | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = (x + (y - 1)) / y; + | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` | = note: `-D clippy::manual-div-ceil` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_div_ceil)]` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:11:9 + --> tests/ui/manual_div_ceil.rs:11:13 | -LL | let _ = ((y - 1) + x) / y; - | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = ((y - 1) + x) / y; + | ^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:13:9 + --> tests/ui/manual_div_ceil.rs:13:13 | -LL | let _ = (x + y - 1) / y; - | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` +LL | let _ = (x + y - 1) / y; + | ^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:16:9 + --> tests/ui/manual_div_ceil.rs:16:13 | -LL | let _ = (7_u32 + (4 - 1)) / 4; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `7_u32.div_ceil(4)` +LL | let _ = (7_u32 + (4 - 1)) / 4; + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `7_u32.div_ceil(4)` error: manually reimplementing `div_ceil` - --> tests/ui/manual_div_ceil.rs:18:9 + --> tests/ui/manual_div_ceil.rs:18:13 | -LL | let _ = (7_i32 as u32 + (4 - 1)) / 4; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_i32 as u32).div_ceil(4)` +LL | let _ = (7_i32 as u32 + (4 - 1)) / 4; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `(7_i32 as u32).div_ceil(4)` error: manually reimplementing `div_ceil` --> tests/ui/manual_div_ceil.rs:39:13 diff --git a/tests/ui/manual_filter.rs b/tests/ui/manual_filter.rs index a83a316f95ad..a9d0c35f8bb7 100644 --- a/tests/ui/manual_filter.rs +++ b/tests/ui/manual_filter.rs @@ -3,7 +3,7 @@ fn main() { match Some(0) { - //~^ manual_filter + //~^ manual_filter None => None, Some(x) => { if x > 0 { @@ -15,7 +15,7 @@ fn main() { }; match Some(1) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if x > 0 { None @@ -27,7 +27,7 @@ fn main() { }; match Some(2) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if x > 0 { None @@ -39,7 +39,7 @@ fn main() { }; match Some(3) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if x > 0 { Some(x) @@ -52,7 +52,7 @@ fn main() { let y = Some(4); match y { - //~^ manual_filter + //~^ manual_filter // Some(4) None => None, Some(x) => { @@ -65,7 +65,7 @@ fn main() { }; match Some(5) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if x > 0 { Some(x) @@ -77,7 +77,7 @@ fn main() { }; match Some(6) { - //~^ manual_filter + //~^ manual_filter Some(ref x) => { if x > &0 { Some(x) @@ -90,7 +90,7 @@ fn main() { let external_cond = true; match Some(String::new()) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if external_cond { Some(x) @@ -102,14 +102,14 @@ fn main() { }; if let Some(x) = Some(7) { - //~^ manual_filter + //~^ manual_filter if external_cond { Some(x) } else { None } } else { None }; match &Some(8) { - //~^ manual_filter + //~^ manual_filter &Some(x) => { if x != 0 { Some(x) @@ -121,7 +121,7 @@ fn main() { }; match Some(9) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if x > 10 && x < 100 { Some(x) @@ -148,7 +148,7 @@ fn main() { #[allow(clippy::blocks_in_conditions)] match Some(11) { - //~^ manual_filter + //~^ manual_filter // Lint, statement is preserved by `.filter` Some(x) => { if { @@ -193,7 +193,7 @@ fn main() { true } let _ = match Some(14) { - //~^ manual_filter + //~^ manual_filter Some(x) => { if unsafe { f(x) } { Some(x) @@ -204,7 +204,7 @@ fn main() { None => None, }; let _ = match Some(15) { - //~^ manual_filter + //~^ manual_filter Some(x) => unsafe { if f(x) { Some(x) } else { None } }, None => None, }; @@ -213,7 +213,7 @@ fn main() { if let Some(_) = Some(16) { Some(16) } else if let Some(x) = Some(16) { - //~^ manual_filter + //~^ manual_filter // Lint starting from here if x % 2 == 0 { Some(x) } else { None } } else { diff --git a/tests/ui/manual_filter_map.rs b/tests/ui/manual_filter_map.rs index 75e15d3b5a5a..013c88da6b36 100644 --- a/tests/ui/manual_filter_map.rs +++ b/tests/ui/manual_filter_map.rs @@ -171,7 +171,7 @@ fn issue8010() { let iter = [Enum::A(123), Enum::B].into_iter(); let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { - //~^ manual_filter_map + //~^ manual_filter_map Enum::A(s) => s, _ => unreachable!(), }); diff --git a/tests/ui/manual_find.rs b/tests/ui/manual_find.rs index d3c24d0b8849..20b557f21d14 100644 --- a/tests/ui/manual_find.rs +++ b/tests/ui/manual_find.rs @@ -3,8 +3,7 @@ //@no-rustfix fn vec_string(strings: Vec) -> Option { for s in strings { - //~^ manual_find - + //~^ manual_find if s == String::new() { return Some(s); @@ -15,8 +14,7 @@ fn vec_string(strings: Vec) -> Option { fn tuple(arr: Vec<(String, i32)>) -> Option { for (s, _) in arr { - //~^ manual_find - + //~^ manual_find if s == String::new() { return Some(s); diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index 2dbe0b16b75a..a4e7878a247c 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -2,6 +2,9 @@ error: manual implementation of `Iterator::find` --> tests/ui/manual_find.rs:5:5 | LL | / for s in strings { +LL | | +LL | | +LL | | if s == String::new() { ... | LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` @@ -11,9 +14,12 @@ LL | | None = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> tests/ui/manual_find.rs:17:5 + --> tests/ui/manual_find.rs:16:5 | LL | / for (s, _) in arr { +LL | | +LL | | +LL | | if s == String::new() { ... | LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(s, _)| s).find(|s| s == String::new())` diff --git a/tests/ui/manual_find_fixable.rs b/tests/ui/manual_find_fixable.rs index 3966d8df89b9..08a7dd2c6eee 100644 --- a/tests/ui/manual_find_fixable.rs +++ b/tests/ui/manual_find_fixable.rs @@ -8,7 +8,7 @@ const ARRAY: &[u32; 5] = &[2, 7, 1, 9, 3]; fn lookup(n: u32) -> Option { for &v in ARRAY { - //~^ manual_find + //~^ manual_find if v == n { return Some(v); } @@ -18,7 +18,7 @@ fn lookup(n: u32) -> Option { fn with_pat(arr: Vec<(u32, u32)>) -> Option { for (a, _) in arr { - //~^ manual_find + //~^ manual_find if a % 2 == 0 { return Some(a); } @@ -32,7 +32,7 @@ struct Data { } fn with_struct(arr: Vec) -> Option { for el in arr { - //~^ manual_find + //~^ manual_find if el.name.len() == 10 { return Some(el); } @@ -43,7 +43,7 @@ fn with_struct(arr: Vec) -> Option { struct Tuple(usize, usize); fn with_tuple_struct(arr: Vec) -> Option { for Tuple(a, _) in arr { - //~^ manual_find + //~^ manual_find if a >= 3 { return Some(a); } @@ -59,7 +59,7 @@ impl A { } fn with_method_call(arr: Vec) -> Option { for el in arr { - //~^ manual_find + //~^ manual_find if el.should_keep() { return Some(el); } @@ -70,7 +70,7 @@ fn with_method_call(arr: Vec) -> Option { fn with_closure(arr: Vec) -> Option { let f = |el: u32| -> u32 { el + 10 }; for el in arr { - //~^ manual_find + //~^ manual_find if f(el) == 20 { return Some(el); } @@ -81,7 +81,7 @@ fn with_closure(arr: Vec) -> Option { fn with_closure2(arr: HashMap) -> Option { let f = |el: i32| -> bool { el == 10 }; for &el in arr.values() { - //~^ manual_find + //~^ manual_find if f(el) { return Some(el); } @@ -91,7 +91,7 @@ fn with_closure2(arr: HashMap) -> Option { fn with_bool(arr: Vec) -> Option { for el in arr { - //~^ manual_find + //~^ manual_find if el.is_true { return Some(el); } @@ -122,7 +122,7 @@ fn with_else(arr: Vec) -> Option { fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { for (_, &x) in v { - //~^ manual_find + //~^ manual_find if x > 10 { return Some(x); } @@ -132,7 +132,7 @@ fn tuple_with_ref(v: [(u8, &u8); 3]) -> Option { fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { for &(_, &x) in v { - //~^ manual_find + //~^ manual_find if x > 10 { return Some(x); } @@ -142,7 +142,7 @@ fn ref_to_tuple_with_ref(v: &[(u8, &u8)]) -> Option { fn explicit_ret(arr: Vec) -> Option { for x in arr { - //~^ manual_find + //~^ manual_find if x >= 5 { return Some(x); } diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs index e22025c6f1a8..97f35c36e24c 100644 --- a/tests/ui/manual_flatten.rs +++ b/tests/ui/manual_flatten.rs @@ -5,7 +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 { - //~^ manual_flatten + //~^ manual_flatten if let Some(y) = n { println!("{}", y); @@ -15,7 +15,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` statement let y: Vec> = vec![]; for n in y.clone() { - //~^ manual_flatten + //~^ manual_flatten if let Ok(n) = n { println!("{}", n); @@ -24,7 +24,7 @@ fn main() { // Test for loop over by reference for n in &y { - //~^ manual_flatten + //~^ manual_flatten if let Ok(n) = n { println!("{}", n); @@ -34,7 +34,7 @@ fn main() { // Test for loop over an implicit reference let z = &y; for n in z { - //~^ manual_flatten + //~^ manual_flatten if let Ok(n) = n { println!("{}", n); @@ -45,7 +45,7 @@ fn main() { let z = vec![Some(1), Some(2), Some(3)]; let z = z.iter(); for n in z { - //~^ manual_flatten + //~^ manual_flatten if let Some(m) = n { println!("{}", m); @@ -80,7 +80,7 @@ fn main() { let vec_of_ref = vec![&Some(1)]; for n in &vec_of_ref { - //~^ manual_flatten + //~^ manual_flatten if let Some(n) = n { println!("{:?}", n); @@ -89,7 +89,7 @@ fn main() { let vec_of_ref = &vec_of_ref; for n in vec_of_ref { - //~^ manual_flatten + //~^ manual_flatten if let Some(n) = n { println!("{:?}", n); @@ -98,7 +98,7 @@ fn main() { let slice_of_ref = &[&Some(1)]; for n in slice_of_ref { - //~^ manual_flatten + //~^ manual_flatten if let Some(n) = n { println!("{:?}", n); diff --git a/tests/ui/manual_ignore_case_cmp.fixed b/tests/ui/manual_ignore_case_cmp.fixed index a75b0702a5ff..c1c929585cfd 100644 --- a/tests/ui/manual_ignore_case_cmp.fixed +++ b/tests/ui/manual_ignore_case_cmp.fixed @@ -7,11 +7,11 @@ fn main() {} fn variants(a: &str, b: &str) { if a.eq_ignore_ascii_case(b) { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } if a.eq_ignore_ascii_case(b) { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } let r = a.eq_ignore_ascii_case(b); @@ -22,11 +22,11 @@ fn variants(a: &str, b: &str) { //~^ manual_ignore_case_cmp // != if !a.eq_ignore_ascii_case(b) { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } if !a.eq_ignore_ascii_case(b) { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } let r = !a.eq_ignore_ascii_case(b); diff --git a/tests/ui/manual_ignore_case_cmp.rs b/tests/ui/manual_ignore_case_cmp.rs index 822f171a4506..ca401e595fe9 100644 --- a/tests/ui/manual_ignore_case_cmp.rs +++ b/tests/ui/manual_ignore_case_cmp.rs @@ -7,11 +7,11 @@ fn main() {} fn variants(a: &str, b: &str) { if a.to_ascii_lowercase() == b.to_ascii_lowercase() { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } if a.to_ascii_uppercase() == b.to_ascii_uppercase() { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); @@ -22,11 +22,11 @@ fn variants(a: &str, b: &str) { //~^ manual_ignore_case_cmp // != if a.to_ascii_lowercase() != b.to_ascii_lowercase() { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } if a.to_ascii_uppercase() != b.to_ascii_uppercase() { - //~^ manual_ignore_case_cmp + //~^ manual_ignore_case_cmp return; } let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); diff --git a/tests/ui/manual_inspect.fixed b/tests/ui/manual_inspect.fixed index 8512da0bdf62..44f15d61f856 100644 --- a/tests/ui/manual_inspect.fixed +++ b/tests/ui/manual_inspect.fixed @@ -3,29 +3,29 @@ fn main() { let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); }); let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{x}"); }); let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x * 5 + 1); }); let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect if x == 0 { panic!(); } }); let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect if &x == &0 { let _y = x; panic!(); @@ -76,7 +76,7 @@ fn main() { } let _ = Some((String::new(), 0u32)).inspect(|x| { - //~^ manual_inspect + //~^ manual_inspect if x.1 == 0 { let _x = x.1; panic!(); @@ -102,7 +102,7 @@ fn main() { }); let _ = Some(String::new()).inspect(|x| { - //~^ manual_inspect + //~^ manual_inspect if x.is_empty() { let _ = || { let _x = x; @@ -113,7 +113,7 @@ fn main() { }); let _ = Some(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect if x == 0 { let _ = || { let _x = x; @@ -128,7 +128,7 @@ fn main() { struct Cell2(core::cell::Cell); let _ = Some(Cell2(Cell::new(0u32))).inspect(|x| { - //~^ manual_inspect + //~^ manual_inspect x.0.set(1); }); @@ -144,20 +144,20 @@ fn main() { } let _: Result<_, ()> = Ok(0).inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); }); let _: Result<(), _> = Err(0).inspect_err(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); }); let _ = [0] - //~^ suspicious_map + //~^ suspicious_map .into_iter() .inspect(|&x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); }) .count(); diff --git a/tests/ui/manual_inspect.rs b/tests/ui/manual_inspect.rs index 7f07394d4b22..d34f2abce6ae 100644 --- a/tests/ui/manual_inspect.rs +++ b/tests/ui/manual_inspect.rs @@ -3,25 +3,25 @@ fn main() { let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); x }); let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{x}"); x }); let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x * 5 + 1); x }); let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect if x == 0 { panic!(); } @@ -29,7 +29,7 @@ fn main() { }); let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect if &x == &0 { let _y = x; panic!(); @@ -81,7 +81,7 @@ fn main() { } let _ = Some((String::new(), 0u32)).map(|x| { - //~^ manual_inspect + //~^ manual_inspect if x.1 == 0 { let _x = x.1; panic!(); @@ -108,7 +108,7 @@ fn main() { }); let _ = Some(String::new()).map(|x| { - //~^ manual_inspect + //~^ manual_inspect if x.is_empty() { let _ = || { let _x = &x; @@ -120,7 +120,7 @@ fn main() { }); let _ = Some(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect if x == 0 { let _ = || { let _x = x; @@ -136,7 +136,7 @@ fn main() { struct Cell2(core::cell::Cell); let _ = Some(Cell2(Cell::new(0u32))).map(|x| { - //~^ manual_inspect + //~^ manual_inspect x.0.set(1); x }); @@ -153,22 +153,22 @@ fn main() { } let _: Result<_, ()> = Ok(0).map(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); x }); let _: Result<(), _> = Err(0).map_err(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); x }); let _ = [0] - //~^ suspicious_map + //~^ suspicious_map .into_iter() .map(|x| { - //~^ manual_inspect + //~^ manual_inspect println!("{}", x); x }) diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index e5ef55c0b8a8..d2350d97ed00 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -29,9 +29,8 @@ fn fire() { let v = if let Some(v_some) = g() { v_some } else { return }; //~^ manual_let_else - let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -39,7 +38,7 @@ fn fire() { }; let v = if let Some(v) = g() { - //~^ manual_let_else + //~^ manual_let_else // Blocks around the identity should have no impact { { v } } @@ -56,17 +55,15 @@ fn fire() { let v = if let Some(v_some) = g() { v_some } else { break }; //~^ manual_let_else - } // panic also diverges let v = if let Some(v_some) = g() { v_some } else { panic!() }; //~^ manual_let_else - // abort also diverges let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -75,7 +72,7 @@ fn fire() { // If whose two branches diverge also diverges let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -84,7 +81,7 @@ fn fire() { // Diverging after an if still makes the block diverge: let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -94,7 +91,7 @@ fn fire() { // The final expression will need to be turned into a statement. let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -104,7 +101,7 @@ fn fire() { // Even if the result is buried multiple expressions deep. let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -121,7 +118,7 @@ fn fire() { // Or if a break gives the value. let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -133,7 +130,7 @@ fn fire() { // Even if the break is in a weird position. let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -150,7 +147,7 @@ fn fire() { // A match diverges if all branches diverge: let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -162,7 +159,7 @@ fn fire() { // An if's expression can cause divergence: let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -171,7 +168,7 @@ fn fire() { // An expression of a match can cause divergence: let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -182,7 +179,7 @@ fn fire() { // Top level else if let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else if true { @@ -193,7 +190,7 @@ fn fire() { // All match arms diverge let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -212,7 +209,7 @@ fn fire() { // Tuples supported for the declared variables let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { - //~^ manual_let_else + //~^ manual_let_else v_some } else { @@ -221,7 +218,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) { - //~^ manual_let_else + //~^ manual_let_else (w_some, v_some) } else { @@ -244,16 +241,14 @@ fn fire() { let v = if let Variant::A(a, 0) = e() { a } else { return }; //~^ manual_let_else - // `mut v` is inserted into the pattern let mut v = if let Variant::B(b) = e() { b } else { return }; //~^ manual_let_else - // Nesting works let nested = Ok(Some(e())); let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { - //~^ manual_let_else + //~^ manual_let_else b } else { @@ -263,15 +258,13 @@ fn fire() { let v = if let Variant::A(.., a) = e() { a } else { return }; //~^ manual_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 }; //~^ manual_let_else - // Tuple structs work let w = if let Some(S { v: x }) = Some(S { v: 0 }) { - //~^ manual_let_else + //~^ manual_let_else x } else { @@ -280,7 +273,7 @@ fn fire() { // Field init shorthand is suggested let v = if let Some(S { v: x }) = Some(S { v: 0 }) { - //~^ manual_let_else + //~^ manual_let_else x } else { @@ -289,7 +282,7 @@ fn fire() { // Multi-field structs also work let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { - //~^ manual_let_else + //~^ manual_let_else (x, v, w) } else { @@ -407,8 +400,7 @@ fn not_fire() { let ff = Some(1); let _ = match ff { - //~^ manual_let_else - + //~^ manual_let_else Some(value) => value, _ => macro_call!(), }; diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index 8982a1c567bf..8f5cba64d545 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -8,7 +8,7 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:33:5 + --> tests/ui/manual_let_else.rs:32:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -27,7 +27,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:41:5 + --> tests/ui/manual_let_else.rs:40:5 | LL | / let v = if let Some(v) = g() { ... | @@ -45,25 +45,25 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:54:9 + --> tests/ui/manual_let_else.rs:53: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` - --> tests/ui/manual_let_else.rs:57:9 + --> tests/ui/manual_let_else.rs:56: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` - --> tests/ui/manual_let_else.rs:63:5 + --> tests/ui/manual_let_else.rs:61: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` - --> tests/ui/manual_let_else.rs:68:5 + --> tests/ui/manual_let_else.rs:65:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -82,7 +82,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:77:5 + --> tests/ui/manual_let_else.rs:74:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -101,7 +101,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:86:5 + --> tests/ui/manual_let_else.rs:83:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -121,7 +121,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:96:5 + --> tests/ui/manual_let_else.rs:93:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -141,7 +141,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:106:5 + --> tests/ui/manual_let_else.rs:103:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -167,7 +167,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:123:5 + --> tests/ui/manual_let_else.rs:120:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -188,7 +188,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:135:5 + --> tests/ui/manual_let_else.rs:132:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -214,7 +214,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:152:5 + --> tests/ui/manual_let_else.rs:149:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -236,7 +236,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:164:5 + --> tests/ui/manual_let_else.rs:161:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -255,7 +255,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:173:5 + --> tests/ui/manual_let_else.rs:170:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -276,7 +276,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:184:5 + --> tests/ui/manual_let_else.rs:181:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -297,7 +297,7 @@ LL + } }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:195:5 + --> tests/ui/manual_let_else.rs:192:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -325,7 +325,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:214:5 + --> tests/ui/manual_let_else.rs:211:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { LL | | @@ -344,7 +344,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:223:5 + --> tests/ui/manual_let_else.rs:220:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { LL | | @@ -363,7 +363,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:234:13 + --> tests/ui/manual_let_else.rs:231:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -374,19 +374,19 @@ 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` - --> tests/ui/manual_let_else.rs:244:5 + --> tests/ui/manual_let_else.rs:241: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` - --> tests/ui/manual_let_else.rs:249:5 + --> tests/ui/manual_let_else.rs:245: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` - --> tests/ui/manual_let_else.rs:255:5 + --> tests/ui/manual_let_else.rs:250:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { LL | | @@ -405,19 +405,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:263:5 + --> tests/ui/manual_let_else.rs:258: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` - --> tests/ui/manual_let_else.rs:268:5 + --> tests/ui/manual_let_else.rs:262: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` - --> tests/ui/manual_let_else.rs:273:5 + --> tests/ui/manual_let_else.rs:266:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -436,7 +436,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:282:5 + --> tests/ui/manual_let_else.rs:275:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -455,7 +455,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:291:5 + --> tests/ui/manual_let_else.rs:284:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { LL | | @@ -474,18 +474,17 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:409:5 + --> tests/ui/manual_let_else.rs:402:5 | LL | / let _ = match ff { LL | | -LL | | LL | | Some(value) => value, LL | | _ => macro_call!(), LL | | }; | |______^ help: consider writing: `let Some(_) = ff else { macro_call!() };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:487:9 + --> tests/ui/manual_let_else.rs:479:9 | LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs index cdb407030111..6416753bac10 100644 --- a/tests/ui/manual_let_else_match.rs +++ b/tests/ui/manual_let_else_match.rs @@ -34,16 +34,13 @@ fn main() {} fn fire() { let v = match g() { - //~^ manual_let_else - - + //~^ manual_let_else Some(v_some) => v_some, None => return, }; let v = match g() { - //~^ manual_let_else - + //~^ manual_let_else Some(v_some) => v_some, _ => return, }; @@ -51,15 +48,13 @@ fn fire() { loop { // More complex pattern for the identity arm and diverging arm let v = match h() { - //~^ manual_let_else - + //~^ manual_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() { - //~^ manual_let_else - + //~^ manual_let_else Variant::Bar(v) | Variant::Baz(v) => v, _ => continue, }; @@ -68,16 +63,14 @@ fn fire() { // There is a _ in the diverging arm // TODO also support unused bindings aka _v let v = match f() { - //~^ manual_let_else - + //~^ manual_let_else Ok(v) => v, Err(_) => return, }; // Err(()) is an allowed pattern let v = match f().map_err(|_| ()) { - //~^ manual_let_else - + //~^ manual_let_else Ok(v) => v, Err(()) => return, }; @@ -85,23 +78,20 @@ fn fire() { let f = Variant::Bar(1); let _value = match f { - //~^ manual_let_else - + //~^ manual_let_else Variant::Bar(v) | Variant::Baz(v) => v, _ => return, }; let _value = match Some(build_enum()) { - //~^ manual_let_else - + //~^ manual_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() { - //~^ manual_let_else - + //~^ manual_let_else [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, _ => return, }; @@ -182,8 +172,7 @@ fn not_fire() { fn issue11579() { let msg = match Some("hi") { - //~^ manual_let_else - + //~^ manual_let_else Some(m) => m, _ => unreachable!("can't happen"), }; diff --git a/tests/ui/manual_let_else_match.stderr b/tests/ui/manual_let_else_match.stderr index 6a65186d6b53..393562c629ba 100644 --- a/tests/ui/manual_let_else_match.stderr +++ b/tests/ui/manual_let_else_match.stderr @@ -2,7 +2,8 @@ error: this could be rewritten as `let...else` --> tests/ui/manual_let_else_match.rs:36:5 | LL | / let v = match g() { -... | +LL | | +LL | | Some(v_some) => v_some, LL | | None => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` @@ -11,99 +12,90 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_match.rs:44:5 + --> tests/ui/manual_let_else_match.rs:42:5 | LL | / let v = match g() { LL | | -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` - --> tests/ui/manual_let_else_match.rs:53:9 + --> tests/ui/manual_let_else_match.rs:50:9 | LL | / let v = match h() { LL | | -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` - --> tests/ui/manual_let_else_match.rs:60:9 + --> tests/ui/manual_let_else_match.rs:56:9 | LL | / let v = match build_enum() { LL | | -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` - --> tests/ui/manual_let_else_match.rs:70:5 + --> tests/ui/manual_let_else_match.rs:65:5 | LL | / let v = match f() { LL | | -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` - --> tests/ui/manual_let_else_match.rs:78:5 + --> tests/ui/manual_let_else_match.rs:72:5 | LL | / let v = match f().map_err(|_| ()) { LL | | -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` - --> tests/ui/manual_let_else_match.rs:87:5 + --> tests/ui/manual_let_else_match.rs:80:5 | LL | / let _value = match f { LL | | -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` - --> tests/ui/manual_let_else_match.rs:94:5 + --> tests/ui/manual_let_else_match.rs:86:5 | LL | / let _value = match Some(build_enum()) { LL | | -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` - --> tests/ui/manual_let_else_match.rs:102:5 + --> tests/ui/manual_let_else_match.rs:93:5 | LL | / let data = match data.as_slice() { LL | | -LL | | LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0]) = data.as_slice() else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else_match.rs:184:5 + --> tests/ui/manual_let_else_match.rs:174:5 | LL | / let msg = match Some("hi") { LL | | -LL | | LL | | Some(m) => m, LL | | _ => unreachable!("can't happen"), LL | | }; diff --git a/tests/ui/manual_let_else_question_mark.rs b/tests/ui/manual_let_else_question_mark.rs index a07801ce0681..8b43d59816f9 100644 --- a/tests/ui/manual_let_else_question_mark.rs +++ b/tests/ui/manual_let_else_question_mark.rs @@ -43,7 +43,7 @@ fn foo() -> Option<()> { // Do fire manual_let_else in this instance: question mark cannot be used here due to the return // body. let v = if let Some(v_some) = g() { - //~^ manual_let_else + //~^ manual_let_else v_some } else { return Some(()); @@ -55,7 +55,7 @@ fn foo() -> Option<()> { #[allow(clippy::question_mark)] { let v = match g() { - //~^ manual_let_else + //~^ manual_let_else Some(v_some) => v_some, _ => return None, }; diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index 9d7cf754f4b8..9477d0d795d2 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -12,25 +12,25 @@ fn main() { match Some(0) { - //~^ manual_map + //~^ manual_map Some(_) => Some(2), None:: => None, }; match Some(0) { - //~^ manual_map + //~^ manual_map Some(x) => Some(x + 1), _ => None, }; match Some("") { - //~^ manual_map + //~^ manual_map Some(x) => Some(x.is_empty()), None => None, }; if let Some(x) = Some(0) { - //~^ manual_map + //~^ manual_map Some(!x) } else { None @@ -44,7 +44,7 @@ fn main() { }; match Some(&String::new()) { - //~^ manual_map + //~^ manual_map Some(x) => Some(str::len(x)), None => None, }; @@ -55,31 +55,31 @@ fn main() { }; match &Some([0, 1]) { - //~^ manual_map + //~^ manual_map Some(x) => Some(x[0]), &None => None, }; match &Some(0) { - //~^ manual_map + //~^ manual_map &Some(x) => Some(x * 2), None => None, }; match Some(String::new()) { - //~^ manual_map + //~^ manual_map Some(ref x) => Some(x.is_empty()), _ => None, }; match &&Some(String::new()) { - //~^ manual_map + //~^ manual_map Some(x) => Some(x.len()), _ => None, }; match &&Some(0) { - //~^ manual_map + //~^ manual_map &&Some(x) => Some(x + x), &&_ => None, }; @@ -93,38 +93,38 @@ fn main() { #[allow(clippy::option_map_unit_fn)] { match &mut Some(String::new()) { - //~^ manual_map + //~^ manual_map Some(x) => Some(x.push_str("")), None => None, }; } match &mut Some(String::new()) { - //~^ manual_map + //~^ manual_map Some(ref x) => Some(x.len()), None => None, }; match &mut &Some(String::new()) { - //~^ manual_map + //~^ manual_map Some(x) => Some(x.is_empty()), &mut _ => None, }; match Some((0, 1, 2)) { - //~^ manual_map + //~^ manual_map Some((x, y, z)) => Some(x + y + z), None => None, }; match Some([1, 2, 3]) { - //~^ manual_map + //~^ manual_map Some([first, ..]) => Some(first), None => None, }; match &Some((String::new(), "test")) { - //~^ manual_map + //~^ manual_map Some((x, y)) => Some((y, x)), None => None, }; @@ -194,7 +194,7 @@ fn main() { }; match option_env!("") { - //~^ manual_map + //~^ manual_map Some(x) => Some(String::from(x)), None => None, }; @@ -215,7 +215,7 @@ fn main() { if let Some(_) = Some(0) { Some(0) } else if let Some(x) = Some(0) { - //~^ manual_map + //~^ manual_map Some(x + 1) } else { None @@ -224,7 +224,7 @@ fn main() { if true { Some(0) } else if let Some(x) = Some(0) { - //~^ manual_map + //~^ manual_map Some(x + 1) } else { None diff --git a/tests/ui/manual_map_option_2.rs b/tests/ui/manual_map_option_2.rs index 9f45349d5c89..069c2381f6db 100644 --- a/tests/ui/manual_map_option_2.rs +++ b/tests/ui/manual_map_option_2.rs @@ -4,7 +4,7 @@ fn main() { // Lint. `y` is declared within the arm, so it isn't captured by the map closure let _ = match Some(0) { - //~^ manual_map + //~^ manual_map Some(x) => Some({ let y = (String::new(), String::new()); (x, y.0) @@ -47,7 +47,7 @@ fn main() { let s = Some(String::new()); // Lint. `s` is captured by reference, so no lifetime issues. let _ = match &s { - //~^ manual_map + //~^ manual_map Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }), None => None, }; @@ -63,18 +63,18 @@ fn main() { } unsafe { let _ = match Some(0) { - //~^ manual_map + //~^ manual_map Some(x) => Some(f(x)), None => None, }; } let _ = match Some(0) { - //~^ manual_map + //~^ manual_map Some(x) => unsafe { Some(f(x)) }, None => None, }; let _ = match Some(0) { - //~^ manual_map + //~^ manual_map Some(x) => Some(unsafe { f(x) }), None => None, }; @@ -111,7 +111,7 @@ mod with_type_coercion { }; let _ = match Some(0) { - //~^ manual_map + //~^ manual_map Some(_) => Some(match f() { Ok(res) => Ok(Box::new(res)), _ => Err(()), @@ -134,7 +134,7 @@ mod with_type_coercion { }); let _: Option> = match Some(0) { - //~^ manual_map + //~^ manual_map Some(_) => Some(g(x)), None => None, }; diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index eee6c8235daa..c83a26cab21a 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -3,8 +3,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let mut count = 0; for i in 3..src.len() { - //~^ manual_memcpy - + //~^ manual_memcpy dst[i] = src[count]; count += 1; @@ -12,7 +11,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 0; for i in 3..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[count] = src[i]; count += 1; @@ -20,7 +19,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; for i in 0..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[count] = src[i]; count += 1; @@ -28,7 +27,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; for i in 0..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[count]; count += 1; @@ -36,7 +35,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 0; for i in 3..(3 + src.len()) { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[count]; count += 1; @@ -44,7 +43,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; for i in 5..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[count - 2]; count += 1; @@ -52,7 +51,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 2; for i in 0..dst.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[count]; count += 1; @@ -60,7 +59,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 5; for i in 3..10 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[count]; count += 1; @@ -69,7 +68,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() { - //~^ manual_memcpy + //~^ manual_memcpy dst[count] = src[i]; dst2[count2] = src[i]; @@ -81,7 +80,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 { - //~^ manual_memcpy + //~^ manual_memcpy dst[count] = src[i + 2]; count += 1; @@ -90,7 +89,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() { - //~^ manual_memcpy + //~^ manual_memcpy 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 fe42842b969b..70da8309f398 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -2,7 +2,9 @@ error: it looks like you're manually copying between slices --> tests/ui/manual_memcpy/with_loop_counters.rs:5:5 | LL | / for i in 3..src.len() { -... | +LL | | +LL | | +LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..src.len()].copy_from_slice(&src[..(src.len() - 3)]);` @@ -11,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/with_loop_counters.rs:14:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:13:5 | LL | / for i in 3..src.len() { LL | | @@ -22,7 +24,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:22:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { LL | | @@ -33,7 +35,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:30:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:29:5 | LL | / for i in 0..src.len() { LL | | @@ -44,7 +46,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:38:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:37:5 | LL | / for i in 3..(3 + src.len()) { LL | | @@ -55,7 +57,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:46:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:45:5 | LL | / for i in 5..src.len() { LL | | @@ -66,7 +68,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:54:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:53:5 | LL | / for i in 0..dst.len() { LL | | @@ -77,7 +79,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:62:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:61:5 | LL | / for i in 3..10 { LL | | @@ -88,7 +90,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:71:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:70:5 | LL | / for i in 0..src.len() { LL | | @@ -106,7 +108,7 @@ LL + dst2[30..(src.len() + 30)].copy_from_slice(&src[..]); | error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/with_loop_counters.rs:83:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:82:5 | LL | / for i in 0..1 << 1 { LL | | @@ -117,7 +119,7 @@ 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 - --> tests/ui/manual_memcpy/with_loop_counters.rs:92:5 + --> tests/ui/manual_memcpy/with_loop_counters.rs:91:5 | LL | / for i in 3..src.len() { LL | | diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs index 65254df0aab4..a3b8763812d7 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -12,36 +12,35 @@ 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() { - //~^ manual_memcpy - + //~^ manual_memcpy dst[i] = src[i]; } // dst offset memcpy for i in 0..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i + 10] = src[i]; } // src offset memcpy for i in 0..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i + 10]; } // src offset memcpy for i in 11..src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i - 10]; } // overwrite entire dst for i in 0..dst.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i]; } @@ -56,7 +55,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // multiple copies - suggest two memcpy statements for i in 10..256 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i - 5]; dst2[i + 500] = src[i] @@ -70,7 +69,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 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i + LOOP_OFFSET] = src[i - some_var]; } @@ -85,7 +84,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() { - //~^ manual_memcpy + //~^ manual_memcpy dst_vec[i] = src_vec[i]; } @@ -116,27 +115,27 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let from = 1; for i in from..from + src.len() { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i - from]; } for i in from..from + 3 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i - from]; } #[allow(clippy::identity_op)] for i in 0..5 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i - 0] = src[i]; } #[allow(clippy::reversed_empty_ranges)] for i in 0..0 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i]; } @@ -161,21 +160,21 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let src = [0, 1, 2, 3, 4]; let mut dst = [0; 4]; for i in 0..4 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i]; } let mut dst = [0; 6]; for i in 0..5 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i]; } let mut dst = [0; 5]; for i in 0..5 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[i]; } @@ -223,14 +222,14 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let src = [[0; 5]; 5]; let mut dst = [0; 5]; for i in 0..5 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[0][i]; } let src = [[[0; 5]; 5]; 5]; for i in 0..5 { - //~^ manual_memcpy + //~^ manual_memcpy dst[i] = src[0][1][i]; } @@ -239,7 +238,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() { - //~^ manual_memcpy + //~^ manual_memcpy 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 2599bc02c3ca..0e656dcbc63a 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -2,7 +2,9 @@ error: it looks like you're manually copying between slices --> tests/ui/manual_memcpy/without_loop_counters.rs:14: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[..]);` | @@ -10,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:22:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { LL | | @@ -20,7 +22,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:29:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:28:5 | LL | / for i in 0..src.len() { LL | | @@ -30,7 +32,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:36:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:35:5 | LL | / for i in 11..src.len() { LL | | @@ -40,7 +42,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:43:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:42:5 | LL | / for i in 0..dst.len() { LL | | @@ -50,7 +52,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..dst.len()]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:58:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:57:5 | LL | / for i in 10..256 { LL | | @@ -67,7 +69,7 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:72:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:71:5 | LL | / for i in 10..LOOP_OFFSET { LL | | @@ -77,7 +79,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:87:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:86:5 | LL | / for i in 0..src_vec.len() { LL | | @@ -87,7 +89,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:118:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:117:5 | LL | / for i in from..from + src.len() { LL | | @@ -97,7 +99,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:124:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:123:5 | LL | / for i in from..from + 3 { LL | | @@ -107,7 +109,7 @@ 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 - --> tests/ui/manual_memcpy/without_loop_counters.rs:131:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:130:5 | LL | / for i in 0..5 { LL | | @@ -117,7 +119,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:138:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:137:5 | LL | / for i in 0..0 { LL | | @@ -127,7 +129,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:163:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:162:5 | LL | / for i in 0..4 { LL | | @@ -137,7 +139,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..4]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:170:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:169:5 | LL | / for i in 0..5 { LL | | @@ -147,7 +149,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:177:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:176:5 | LL | / for i in 0..5 { LL | | @@ -157,7 +159,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:225:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:224:5 | LL | / for i in 0..5 { LL | | @@ -167,7 +169,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:232:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:231:5 | LL | / for i in 0..5 { LL | | @@ -177,7 +179,7 @@ LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[0][1]);` error: it looks like you're manually copying between slices - --> tests/ui/manual_memcpy/without_loop_counters.rs:241:5 + --> tests/ui/manual_memcpy/without_loop_counters.rs:240:5 | LL | / for i in 0..src.len() { LL | | diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index aaa5b549e734..bb22165d478f 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -2,7 +2,7 @@ #![allow(unused)] //@no-rustfix pub enum E { -//~^ manual_non_exhaustive + //~^ manual_non_exhaustive A, B, #[doc(hidden)] @@ -27,7 +27,7 @@ pub enum NoDocHidden { // name of variant with doc hidden does not start with underscore pub enum NoUnderscore { -//~^ manual_non_exhaustive + //~^ manual_non_exhaustive A, B, #[doc(hidden)] diff --git a/tests/ui/manual_ok_err.rs b/tests/ui/manual_ok_err.rs index 976311604a38..77300b7af539 100644 --- a/tests/ui/manual_ok_err.rs +++ b/tests/ui/manual_ok_err.rs @@ -6,35 +6,31 @@ fn funcall() -> Result { fn main() { let _ = match funcall() { - //~^ manual_ok_err - + //~^ manual_ok_err Ok(v) => Some(v), Err(_) => None, }; let _ = match funcall() { - //~^ manual_ok_err - + //~^ manual_ok_err Ok(v) => Some(v), _v => None, }; let _ = match funcall() { - //~^ manual_ok_err - + //~^ manual_ok_err Err(v) => Some(v), Ok(_) => None, }; let _ = match funcall() { - //~^ manual_ok_err - + //~^ manual_ok_err Err(v) => Some(v), _v => None, }; let _ = if let Ok(v) = funcall() { - //~^ manual_ok_err + //~^ manual_ok_err Some(v) } else { @@ -42,7 +38,7 @@ fn main() { }; let _ = if let Err(v) = funcall() { - //~^ manual_ok_err + //~^ manual_ok_err Some(v) } else { @@ -51,8 +47,7 @@ fn main() { #[allow(clippy::redundant_pattern)] let _ = match funcall() { - //~^ manual_ok_err - + //~^ manual_ok_err Ok(v) => Some(v), _v @ _ => None, }; @@ -69,8 +64,7 @@ fn main() { // Suggestion should be properly parenthesized let _ = match -S { - //~^ manual_ok_err - + //~^ manual_ok_err Ok(v) => Some(v), _ => None, }; diff --git a/tests/ui/manual_ok_err.stderr b/tests/ui/manual_ok_err.stderr index ea430dd3eb45..f10f52cc4c97 100644 --- a/tests/ui/manual_ok_err.stderr +++ b/tests/ui/manual_ok_err.stderr @@ -4,7 +4,6 @@ error: manual implementation of `ok` LL | let _ = match funcall() { | _____________^ LL | | -LL | | LL | | Ok(v) => Some(v), LL | | Err(_) => None, LL | | }; @@ -14,43 +13,40 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_ok_err)]` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:15:13 + --> tests/ui/manual_ok_err.rs:14:13 | LL | let _ = match funcall() { | _____________^ LL | | -LL | | LL | | Ok(v) => Some(v), LL | | _v => None, LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:22:13 + --> tests/ui/manual_ok_err.rs:20:13 | LL | let _ = match funcall() { | _____________^ LL | | -LL | | LL | | Err(v) => Some(v), LL | | Ok(_) => None, LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:29:13 + --> tests/ui/manual_ok_err.rs:26:13 | LL | let _ = match funcall() { | _____________^ LL | | -LL | | LL | | Err(v) => Some(v), LL | | _v => None, LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:36:13 + --> tests/ui/manual_ok_err.rs:32:13 | LL | let _ = if let Ok(v) = funcall() { | _____________^ @@ -63,7 +59,7 @@ LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `err` - --> tests/ui/manual_ok_err.rs:44:13 + --> tests/ui/manual_ok_err.rs:40:13 | LL | let _ = if let Err(v) = funcall() { | _____________^ @@ -76,24 +72,22 @@ LL | | }; | |_____^ help: replace with: `funcall().err()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:53:13 + --> tests/ui/manual_ok_err.rs:49:13 | LL | let _ = match funcall() { | _____________^ LL | | -LL | | LL | | Ok(v) => Some(v), LL | | _v @ _ => None, LL | | }; | |_____^ help: replace with: `funcall().ok()` error: manual implementation of `ok` - --> tests/ui/manual_ok_err.rs:71:13 + --> tests/ui/manual_ok_err.rs:66:13 | LL | let _ = match -S { | _____________^ LL | | -LL | | LL | | Ok(v) => Some(v), LL | | _ => None, LL | | }; diff --git a/tests/ui/manual_option_as_slice.fixed b/tests/ui/manual_option_as_slice.fixed index 17a412017a43..48337d7654de 100644 --- a/tests/ui/manual_option_as_slice.fixed +++ b/tests/ui/manual_option_as_slice.fixed @@ -9,24 +9,19 @@ fn check(x: Option) { _ = x.as_slice(); //~^ manual_option_as_slice + _ = x.as_slice(); + //~^ manual_option_as_slice _ = x.as_slice(); //~^ manual_option_as_slice - _ = x.as_slice(); //~^ manual_option_as_slice - - _ = x.as_slice(); - //~^ manual_option_as_slice - - { use std::slice::from_ref; _ = x.as_slice(); //~^ manual_option_as_slice - } // possible false positives diff --git a/tests/ui/manual_option_as_slice.rs b/tests/ui/manual_option_as_slice.rs index 71166399cbea..e1a97a6b2711 100644 --- a/tests/ui/manual_option_as_slice.rs +++ b/tests/ui/manual_option_as_slice.rs @@ -3,14 +3,13 @@ fn check(x: Option) { _ = match x.as_ref() { - //~^ manual_option_as_slice - + //~^ manual_option_as_slice Some(f) => std::slice::from_ref(f), None => &[], }; _ = if let Some(f) = x.as_ref() { - //~^ manual_option_as_slice + //~^ manual_option_as_slice std::slice::from_ref(f) } else { @@ -20,24 +19,19 @@ fn check(x: Option) { _ = x.as_ref().map_or(&[][..], std::slice::from_ref); //~^ manual_option_as_slice - _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); //~^ manual_option_as_slice - _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); //~^ manual_option_as_slice - _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); //~^ manual_option_as_slice - { use std::slice::from_ref; _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); //~^ manual_option_as_slice - } // possible false positives diff --git a/tests/ui/manual_option_as_slice.stderr b/tests/ui/manual_option_as_slice.stderr index 3a07c6a02dae..e240ae8eb7d9 100644 --- a/tests/ui/manual_option_as_slice.stderr +++ b/tests/ui/manual_option_as_slice.stderr @@ -4,7 +4,6 @@ error: use `Option::as_slice` LL | _ = match x.as_ref() { | _________^ LL | | -LL | | LL | | Some(f) => std::slice::from_ref(f), LL | | None => &[], LL | | }; @@ -14,7 +13,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_option_as_slice)]` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:12:9 + --> tests/ui/manual_option_as_slice.rs:11:9 | LL | _ = if let Some(f) = x.as_ref() { | _________^ @@ -27,31 +26,31 @@ LL | | }; | |_____^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:20:9 + --> tests/ui/manual_option_as_slice.rs:19:9 | LL | _ = x.as_ref().map_or(&[][..], std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:24:9 + --> tests/ui/manual_option_as_slice.rs:22:9 | LL | _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:28:9 + --> tests/ui/manual_option_as_slice.rs:25:9 | LL | _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:32:9 + --> tests/ui/manual_option_as_slice.rs:28:9 | LL | _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` error: use `Option::as_slice` - --> tests/ui/manual_option_as_slice.rs:38:13 + --> tests/ui/manual_option_as_slice.rs:33:13 | LL | _ = x.as_ref().map_or_else(<&[_]>::default, from_ref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()` diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index 61e2d73b544f..cd05a41f3f25 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -69,7 +69,7 @@ fn btree_map_retain() { btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); //~^ manual_retain btree_map = btree_map - //~^ manual_retain + //~^ manual_retain .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) .collect(); @@ -141,7 +141,7 @@ fn hash_map_retain() { hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); //~^ manual_retain hash_map = hash_map - //~^ manual_retain + //~^ manual_retain .into_iter() .filter(|(k, v)| (k % 2 == 0) && (v % 2 == 0)) .collect(); diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs index c0d7f26916ee..98246a5cd96c 100644 --- a/tests/ui/manual_saturating_arithmetic.rs +++ b/tests/ui/manual_saturating_arithmetic.rs @@ -10,7 +10,7 @@ fn main() { let _ = 1u8.checked_add(1).unwrap_or(255); //~^ manual_saturating_arithmetic let _ = 1u128 - //~^ manual_saturating_arithmetic + //~^ manual_saturating_arithmetic .checked_add(1) .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); let _ = 1u32.checked_add(1).unwrap_or(1234); // ok @@ -34,7 +34,7 @@ fn main() { let _ = 1i8.checked_add(1).unwrap_or(127); //~^ manual_saturating_arithmetic let _ = 1i128 - //~^ manual_saturating_arithmetic + //~^ manual_saturating_arithmetic .checked_add(1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); @@ -44,7 +44,7 @@ fn main() { let _ = 1i8.checked_add(-1).unwrap_or(-128); //~^ manual_saturating_arithmetic let _ = 1i128 - //~^ manual_saturating_arithmetic + //~^ manual_saturating_arithmetic .checked_add(-1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); let _ = 1i32.checked_add(1).unwrap_or(1234); // ok @@ -58,7 +58,7 @@ fn main() { let _ = 1i8.checked_sub(1).unwrap_or(-128); //~^ manual_saturating_arithmetic let _ = 1i128 - //~^ manual_saturating_arithmetic + //~^ manual_saturating_arithmetic .checked_sub(1) .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); @@ -68,7 +68,7 @@ fn main() { let _ = 1i8.checked_sub(-1).unwrap_or(127); //~^ manual_saturating_arithmetic let _ = 1i128 - //~^ manual_saturating_arithmetic + //~^ manual_saturating_arithmetic .checked_sub(-1) .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); let _ = 1i32.checked_sub(1).unwrap_or(1234); // ok diff --git a/tests/ui/manual_slice_fill.rs b/tests/ui/manual_slice_fill.rs index cd62a476d174..f758f47bbcb0 100644 --- a/tests/ui/manual_slice_fill.rs +++ b/tests/ui/manual_slice_fill.rs @@ -23,25 +23,25 @@ fn should_lint() { let mut some_slice = [1, 2, 3, 4, 5]; for i in 0..some_slice.len() { - //~^ manual_slice_fill + //~^ manual_slice_fill some_slice[i] = 0; } let x = 5; for i in 0..some_slice.len() { - //~^ manual_slice_fill + //~^ manual_slice_fill some_slice[i] = x; } for i in &mut some_slice { - //~^ manual_slice_fill + //~^ manual_slice_fill *i = 0; } // This should trigger `manual_slice_fill`, but the applicability is `MaybeIncorrect` since comments // within the loop might be purely informational. for i in 0..some_slice.len() { - //~^ manual_slice_fill + //~^ manual_slice_fill some_slice[i] = 0; // foo } diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs index d3dbf301d9c0..ce53c99e6b50 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -36,7 +36,6 @@ fn main() { if s.starts_with(prefix) { str::to_string(&s[prefix.len()..]); //~^ manual_strip - } // Constant prefix @@ -53,7 +52,6 @@ fn main() { if TARGET.starts_with(prefix) { str::to_string(&TARGET[prefix.len()..]); //~^ manual_strip - } // String target - not mutated. @@ -61,7 +59,6 @@ fn main() { if s1.starts_with("ab") { s1[2..].to_uppercase(); //~^ manual_strip - } // String target - mutated. (Don't lint.) @@ -93,6 +90,5 @@ fn msrv_1_45() { if s.starts_with('a') { s[1..].to_string(); //~^ manual_strip - } } diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index 78967e521baa..41d15da610c4 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -84,13 +84,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:45:24 + --> tests/ui/manual_strip.rs:44:24 | LL | str::to_string(&s[PREFIX.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:44:5 + --> tests/ui/manual_strip.rs:43:5 | LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,13 +104,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:54:24 + --> tests/ui/manual_strip.rs:53:24 | LL | str::to_string(&TARGET[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:53:5 + --> tests/ui/manual_strip.rs:52:5 | LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,13 +121,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:62:9 + --> tests/ui/manual_strip.rs:60:9 | LL | s1[2..].to_uppercase(); | ^^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:61:5 + --> tests/ui/manual_strip.rs:59:5 | LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,13 +138,13 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:94:9 + --> tests/ui/manual_strip.rs:91:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:93:5 + --> tests/ui/manual_strip.rs:90:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_try_fold.rs b/tests/ui/manual_try_fold.rs index 749fc7c7b683..c91ea41bb84c 100644 --- a/tests/ui/manual_try_fold.rs +++ b/tests/ui/manual_try_fold.rs @@ -62,11 +62,11 @@ fn main() { [1, 2, 3] .iter() .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); - //~^ manual_try_fold + //~^ manual_try_fold [1, 2, 3] .iter() .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); - //~^ manual_try_fold + //~^ manual_try_fold // Do not lint [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap(); [1, 2, 3].iter().fold(0i32, |sum, i| sum + i); diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 80a677d726ef..c88b6f95da68 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -9,21 +9,21 @@ fn option_unwrap_or() { // int case match Some(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Some(i) => i, None => 42, }; // int case reversed match Some(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or None => 42, Some(i) => i, }; // richer none expr match Some(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Some(i) => i, None => 1 + 42, }; @@ -42,7 +42,7 @@ fn option_unwrap_or() { // string case match Some("Bob") { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Some(i) => i, None => "Alice", }; @@ -90,7 +90,7 @@ fn option_unwrap_or() { }; if let Some(x) = Some(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or x } else { 42 @@ -124,7 +124,7 @@ fn option_unwrap_or() { fn result_unwrap_or() { // int case match Ok::(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; @@ -132,14 +132,14 @@ fn result_unwrap_or() { // int case, scrutinee is a binding let a = Ok::(1); match a { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; // int case, suggestion must surround Result expr with parentheses match Ok(1) as Result { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 42, }; @@ -153,21 +153,21 @@ fn result_unwrap_or() { } let s = S {}; match s.method() { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Some(i) => i, None => 42, }; // int case reversed match Ok::(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Err(_) => 42, Ok(i) => i, }; // richer none expr match Ok::(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Ok(i) => i, Err(_) => 1 + 42, }; @@ -186,7 +186,7 @@ fn result_unwrap_or() { // string case match Ok::<&str, &str>("Bob") { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Ok(i) => i, Err(_) => "Alice", }; @@ -223,7 +223,7 @@ fn result_unwrap_or() { }; if let Ok(x) = Ok::(1) { - //~^ manual_unwrap_or + //~^ manual_unwrap_or x } else { 42 @@ -278,7 +278,7 @@ mod issue6965 { fn test() { let _ = match some_macro!() { - //~^ manual_unwrap_or + //~^ manual_unwrap_or Some(val) => val, None => 0, }; diff --git a/tests/ui/manual_unwrap_or_default.rs b/tests/ui/manual_unwrap_or_default.rs index 1ef07cf84bde..bedb3f0af0f3 100644 --- a/tests/ui/manual_unwrap_or_default.rs +++ b/tests/ui/manual_unwrap_or_default.rs @@ -4,39 +4,35 @@ fn main() { let x: Option> = None; match x { - //~^ manual_unwrap_or_default - + //~^ manual_unwrap_or_default Some(v) => v, None => Vec::default(), }; let x: Option> = None; match x { - //~^ manual_unwrap_or_default - + //~^ manual_unwrap_or_default Some(v) => v, _ => Vec::default(), }; let x: Option = None; match x { - //~^ manual_unwrap_or_default - + //~^ manual_unwrap_or_default Some(v) => v, None => String::new(), }; let x: Option> = None; match x { - //~^ manual_unwrap_or_default - + //~^ manual_unwrap_or_default None => Vec::default(), Some(v) => v, }; let x: Option> = None; if let Some(v) = x { - //~^ manual_unwrap_or_default + //~^ manual_unwrap_or_default v } else { @@ -55,15 +51,14 @@ fn main() { let x: Result = Ok(String::new()); match x { - //~^ manual_unwrap_or_default - + //~^ manual_unwrap_or_default Ok(v) => v, Err(_) => String::new(), }; let x: Result = Ok(String::new()); if let Ok(v) = x { - //~^ manual_unwrap_or_default + //~^ manual_unwrap_or_default v } else { @@ -76,7 +71,7 @@ unsafe fn no_deref_ptr(a: Option, b: *const Option) -> i32 { match a { // `*b` being correct depends on `a == Some(_)` Some(_) => match *b { - //~^ manual_unwrap_or_default + //~^ manual_unwrap_or_default Some(v) => v, _ => 0, }, diff --git a/tests/ui/manual_unwrap_or_default.stderr b/tests/ui/manual_unwrap_or_default.stderr index ff388ba85d51..ca9aa159152e 100644 --- a/tests/ui/manual_unwrap_or_default.stderr +++ b/tests/ui/manual_unwrap_or_default.stderr @@ -3,7 +3,6 @@ error: match can be simplified with `.unwrap_or_default()` | LL | / match x { LL | | -LL | | LL | | Some(v) => v, LL | | None => Vec::default(), LL | | }; @@ -13,40 +12,37 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:14:5 + --> tests/ui/manual_unwrap_or_default.rs:13:5 | LL | / match x { LL | | -LL | | LL | | Some(v) => v, LL | | _ => Vec::default(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:22:5 + --> tests/ui/manual_unwrap_or_default.rs:20:5 | LL | / match x { LL | | -LL | | LL | | Some(v) => v, LL | | None => String::new(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:30:5 + --> tests/ui/manual_unwrap_or_default.rs:27:5 | LL | / match x { LL | | -LL | | LL | | None => Vec::default(), LL | | Some(v) => v, LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:38:5 + --> tests/ui/manual_unwrap_or_default.rs:34:5 | LL | / if let Some(v) = x { LL | | @@ -58,18 +54,17 @@ LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:57:5 + --> tests/ui/manual_unwrap_or_default.rs:53:5 | LL | / match x { LL | | -LL | | LL | | Ok(v) => v, LL | | Err(_) => String::new(), LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: if let can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:65:5 + --> tests/ui/manual_unwrap_or_default.rs:60:5 | LL | / if let Ok(v) = x { LL | | @@ -81,7 +76,7 @@ LL | | }; | |_____^ help: replace it with: `x.unwrap_or_default()` error: match can be simplified with `.unwrap_or_default()` - --> tests/ui/manual_unwrap_or_default.rs:78:20 + --> tests/ui/manual_unwrap_or_default.rs:73:20 | LL | Some(_) => match *b { | ____________________^ diff --git a/tests/ui/manual_unwrap_or_default_unfixable.rs b/tests/ui/manual_unwrap_or_default_unfixable.rs index fb61d639f9c0..c48a4d5ee515 100644 --- a/tests/ui/manual_unwrap_or_default_unfixable.rs +++ b/tests/ui/manual_unwrap_or_default_unfixable.rs @@ -3,7 +3,7 @@ fn issue_12670() { // no auto: type not found #[allow(clippy::match_result_ok)] let _ = if let Some(x) = "1".parse().ok() { - //~^ manual_unwrap_or_default + //~^ manual_unwrap_or_default x } else { i32::default() diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs index 6e662e246061..b60109224855 100644 --- a/tests/ui/many_single_char_names.rs +++ b/tests/ui/many_single_char_names.rs @@ -7,9 +7,6 @@ fn bla() { //~| many_single_char_names //~| many_single_char_names - - - let (b, c, d): (i32, i64, i16); { { @@ -37,11 +34,9 @@ fn bla() { fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} //~^ many_single_char_names - fn bindings2() { let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); //~^ many_single_char_names - } fn shadowing() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index ad45f9a34fd4..131836ef7c88 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -40,13 +40,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> tests/ui/many_single_char_names.rs:37:13 + --> tests/ui/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 - --> tests/ui/many_single_char_names.rs:42:10 + --> tests/ui/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_all_any_identity.fixed b/tests/ui/map_all_any_identity.fixed index 436b94bde0fc..35543d239752 100644 --- a/tests/ui/map_all_any_identity.fixed +++ b/tests/ui/map_all_any_identity.fixed @@ -7,7 +7,6 @@ fn main() { let _ = ["foo"].into_iter().all(|s| s == "foo"); //~^ map_all_any_identity - // // Do not lint // diff --git a/tests/ui/map_all_any_identity.rs b/tests/ui/map_all_any_identity.rs index 68fe7b77f5c6..704eb821aaaa 100644 --- a/tests/ui/map_all_any_identity.rs +++ b/tests/ui/map_all_any_identity.rs @@ -7,7 +7,6 @@ fn main() { let _ = ["foo"].into_iter().map(|s| s == "foo").all(std::convert::identity); //~^ map_all_any_identity - // // Do not lint // diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 5e2c31bb31df..8db4b21be684 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -78,23 +78,17 @@ fn main() { let y = x.cloned(); //~^ map_clone - let y = x.cloned(); //~^ map_clone - - let x: Option = Some(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.copied(); //~^ map_clone - let y = x.copied(); //~^ map_clone - - // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Option = Some(0); let y = x.map(|x| u32::clone(&x)); @@ -106,23 +100,17 @@ fn main() { let y = x.cloned(); //~^ map_clone - let y = x.cloned(); //~^ map_clone - - let x: Result = Ok(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.copied(); //~^ map_clone - let y = x.copied(); //~^ map_clone - - // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Result = Ok(0); let y = x.map(|x| u32::clone(&x)); diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index f15889d64c52..a726e3561634 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -78,23 +78,17 @@ fn main() { let y = x.map(Clone::clone); //~^ map_clone - let y = x.map(String::clone); //~^ map_clone - - let x: Option = Some(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| u32::clone(x)); //~^ map_clone - let y = x.map(|x| Clone::clone(x)); //~^ map_clone - - // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Option = Some(0); let y = x.map(|x| u32::clone(&x)); @@ -106,23 +100,17 @@ fn main() { let y = x.map(|x| String::clone(x)); //~^ map_clone - let y = x.map(|x| Clone::clone(x)); //~^ map_clone - - let x: Result = Ok(0); let x = x.as_ref(); // We do this to prevent triggering the `useless_asref` lint. let y = x.map(|x| u32::clone(x)); //~^ map_clone - let y = x.map(|x| Clone::clone(x)); //~^ map_clone - - // Should not suggest `copied` or `cloned` here since `T` is not a reference. let x: Result = Ok(0); let y = x.map(|x| u32::clone(&x)); diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index 5c88ec579328..8bf54e4e8aee 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -50,43 +50,43 @@ LL | let y = x.map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:82:13 + --> tests/ui/map_clone.rs:81:13 | LL | let y = x.map(String::clone); | ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:89:13 + --> tests/ui/map_clone.rs:86:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:93:13 + --> tests/ui/map_clone.rs:89:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:106:13 + --> tests/ui/map_clone.rs:100:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:110:13 + --> tests/ui/map_clone.rs:103:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:117:13 + --> tests/ui/map_clone.rs:108:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:121:13 + --> tests/ui/map_clone.rs:111:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` diff --git a/tests/ui/map_err.rs b/tests/ui/map_err.rs index 43f6ea0b3ae0..0f0c8f6c71cf 100644 --- a/tests/ui/map_err.rs +++ b/tests/ui/map_err.rs @@ -22,7 +22,6 @@ fn main() -> Result<(), Errors> { println!("{:?}", x.map_err(|_| Errors::Ignored)); //~^ map_err_ignore - // Should not warn you because you explicitly ignore the parameter // using a named wildcard value println!("{:?}", x.map_err(|_foo| Errors::Ignored)); diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs index e16a11f83ed5..d7e9c9d9900d 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -67,7 +67,6 @@ fn no_suggestion_if_comments_present() { // a lovely comment explaining the code in very detail .map(|x| x.iter()) //~^ map_flatten - // the answer to life, the universe and everything could be here .flatten(); } diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index a5dc17cc06ca..948fec970d86 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -42,7 +42,7 @@ fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() .flat_map(|n| match n { - //~^ map_flatten + //~^ map_flatten 1 => [n .saturating_add(1) .saturating_add(1) diff --git a/tests/ui/map_flatten_fixable.rs b/tests/ui/map_flatten_fixable.rs index 57b8e7943f41..67a91ab94147 100644 --- a/tests/ui/map_flatten_fixable.rs +++ b/tests/ui/map_flatten_fixable.rs @@ -42,7 +42,7 @@ fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() .map(|n| match n { - //~^ map_flatten + //~^ map_flatten 1 => [n .saturating_add(1) .saturating_add(1) diff --git a/tests/ui/map_identity.rs b/tests/ui/map_identity.rs index 7c891dda79ce..e839c551364b 100644 --- a/tests/ui/map_identity.rs +++ b/tests/ui/map_identity.rs @@ -12,7 +12,7 @@ fn main() { let _: Option = Some(3).map(|x| x); //~^ map_identity let _: Result = Ok(-3).map(|x| { - //~^ map_identity + //~^ map_identity return x; }); // should not lint @@ -36,7 +36,7 @@ fn issue7189() { let _ = x.clone().map(|(x, y)| (x, y)); //~^ map_identity let _ = x.clone().map(|(x, y)| { - //~^ map_identity + //~^ map_identity return (x, y); }); let _ = x.clone().map(|(x, y)| return (x, y)); diff --git a/tests/ui/map_with_unused_argument_over_ranges.fixed b/tests/ui/map_with_unused_argument_over_ranges.fixed index 08bc1c7a6283..254c46ecae38 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.fixed +++ b/tests/ui/map_with_unused_argument_over_ranges.fixed @@ -35,7 +35,7 @@ fn main() { std::iter::repeat_n(3, 10); //~^ map_with_unused_argument_over_ranges std::iter::repeat_with(|| { - //~^ map_with_unused_argument_over_ranges + //~^ map_with_unused_argument_over_ranges let x = 3; x + 2 }).take(10); diff --git a/tests/ui/map_with_unused_argument_over_ranges.rs b/tests/ui/map_with_unused_argument_over_ranges.rs index 151ebdf97e5d..05c8d64f8012 100644 --- a/tests/ui/map_with_unused_argument_over_ranges.rs +++ b/tests/ui/map_with_unused_argument_over_ranges.rs @@ -35,7 +35,7 @@ fn main() { (0..10).map(|_| 3); //~^ map_with_unused_argument_over_ranges (0..10).map(|_| { - //~^ map_with_unused_argument_over_ranges + //~^ map_with_unused_argument_over_ranges let x = 3; x + 2 }); diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs index 7eaabcdc3d0e..3a5b1227331e 100644 --- a/tests/ui/match_as_ref.rs +++ b/tests/ui/match_as_ref.rs @@ -4,14 +4,14 @@ fn match_as_ref() { let owned: Option<()> = None; let borrowed: Option<&()> = match owned { - //~^ match_as_ref + //~^ match_as_ref None => None, Some(ref v) => Some(v), }; let mut mut_owned: Option<()> = None; let borrow_mut: Option<&mut ()> = match mut_owned { - //~^ match_as_ref + //~^ match_as_ref None => None, Some(ref mut v) => Some(v), }; @@ -30,7 +30,7 @@ mod issue4437 { impl Error for E { fn source(&self) -> Option<&(dyn Error + 'static)> { match self.source { - //~^ match_as_ref + //~^ match_as_ref Some(ref s) => Some(s), None => None, } diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index 7d4afd3f2890..719b4e51eb6d 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -5,23 +5,20 @@ fn match_bool() { let test: bool = true; match test { - //~^ match_bool - + //~^ match_bool true => 0, false => 42, }; let option = 1; match option == 1 { - //~^ match_bool - + //~^ match_bool true => 1, false => 0, }; match test { - //~^ match_bool - + //~^ match_bool true => (), false => { println!("Noooo!"); @@ -29,8 +26,7 @@ fn match_bool() { }; match test { - //~^ match_bool - + //~^ match_bool false => { println!("Noooo!"); }, @@ -38,8 +34,7 @@ fn match_bool() { }; match test && test { - //~^ match_bool - + //~^ match_bool false => { println!("Noooo!"); }, @@ -47,8 +42,7 @@ fn match_bool() { }; match test { - //~^ match_bool - + //~^ match_bool false => { println!("Noooo!"); }, @@ -73,43 +67,37 @@ fn match_bool() { }; let _ = match test { - //~^ match_bool - + //~^ match_bool true if option == 5 => 10, _ => 1, }; let _ = match test { - //~^ match_bool - + //~^ match_bool false if option == 5 => 10, _ => 1, }; match test { - //~^ match_bool - + //~^ match_bool true if option == 5 => println!("Hello"), _ => (), }; match test { - //~^ match_bool - + //~^ match_bool true if option == 5 => (), _ => println!("Hello"), }; match test { - //~^ match_bool - + //~^ match_bool false if option == 5 => println!("Hello"), _ => (), }; match test { - //~^ match_bool - + //~^ match_bool false if option == 5 => (), _ => println!("Hello"), }; @@ -117,8 +105,7 @@ fn match_bool() { fn issue14099() { match true { - //~^ match_bool - + //~^ match_bool true => 'a: { break 'a; }, diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index c25aad27cef2..c05742e56339 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -3,7 +3,6 @@ error: `match` on a boolean expression | LL | / match test { LL | | -LL | | LL | | true => 0, LL | | false => 42, LL | | }; @@ -16,24 +15,23 @@ LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: `match` on a boolean expression - --> tests/ui/match_bool.rs:15:5 + --> tests/ui/match_bool.rs:14:5 | LL | / match option == 1 { LL | | -LL | | LL | | true => 1, LL | | false => 0, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:22:5 + --> tests/ui/match_bool.rs:20:5 | LL | / match test { LL | | -LL | | LL | | true => (), -... | +LL | | false => { +LL | | println!("Noooo!"); LL | | }, LL | | }; | |_____^ @@ -46,13 +44,13 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:31:5 + --> tests/ui/match_bool.rs:28:5 | LL | / match test { LL | | -LL | | LL | | false => { -... | +LL | | println!("Noooo!"); +LL | | }, LL | | _ => (), LL | | }; | |_____^ @@ -65,13 +63,13 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:40:5 + --> tests/ui/match_bool.rs:36:5 | LL | / match test && test { LL | | -LL | | LL | | false => { -... | +LL | | println!("Noooo!"); +LL | | }, LL | | _ => (), LL | | }; | |_____^ @@ -84,12 +82,12 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:49:5 + --> tests/ui/match_bool.rs:44:5 | LL | / match test { LL | | -LL | | LL | | false => { +LL | | println!("Noooo!"); ... | LL | | }, LL | | }; @@ -105,81 +103,75 @@ LL ~ }; | error: `match` on a boolean expression - --> tests/ui/match_bool.rs:75:13 + --> tests/ui/match_bool.rs:69:13 | LL | let _ = match test { | _____________^ LL | | -LL | | LL | | true if option == 5 => 10, LL | | _ => 1, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test && option == 5 { 10 } else { 1 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:82:13 + --> tests/ui/match_bool.rs:75:13 | LL | let _ = match test { | _____________^ LL | | -LL | | LL | | false if option == 5 => 10, LL | | _ => 1, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !test && option == 5 { 10 } else { 1 }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:89:5 + --> tests/ui/match_bool.rs:81:5 | LL | / match test { LL | | -LL | | LL | | true if option == 5 => println!("Hello"), LL | | _ => (), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test && option == 5 { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:96:5 + --> tests/ui/match_bool.rs:87:5 | LL | / match test { LL | | -LL | | LL | | true if option == 5 => (), LL | | _ => println!("Hello"), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !(test && option == 5) { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:103:5 + --> tests/ui/match_bool.rs:93:5 | LL | / match test { LL | | -LL | | LL | | false if option == 5 => println!("Hello"), LL | | _ => (), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !test && option == 5 { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:110:5 + --> tests/ui/match_bool.rs:99:5 | LL | / match test { LL | | -LL | | LL | | false if option == 5 => (), LL | | _ => println!("Hello"), LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if !(!test && option == 5) { println!("Hello") }` error: `match` on a boolean expression - --> tests/ui/match_bool.rs:119:5 + --> tests/ui/match_bool.rs:107:5 | LL | / match true { LL | | -LL | | LL | | true => 'a: { -... | +LL | | break 'a; +LL | | }, LL | | _ => (), LL | | } | |_____^ diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs index 1b7ce69f3ae7..f3174ec9734d 100644 --- a/tests/ui/match_on_vec_items.rs +++ b/tests/ui/match_on_vec_items.rs @@ -8,9 +8,7 @@ fn match_with_wildcard() { // Lint, may panic match arr[idx] { - //~^ match_on_vec_items - - + //~^ match_on_vec_items 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -18,8 +16,7 @@ fn match_with_wildcard() { // Lint, may panic match arr[range] { - //~^ match_on_vec_items - + //~^ match_on_vec_items [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, @@ -33,8 +30,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[idx] { - //~^ match_on_vec_items - + //~^ match_on_vec_items 0 => println!("0"), 1 => println!("1"), num => {}, @@ -42,8 +38,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[range] { - //~^ match_on_vec_items - + //~^ match_on_vec_items [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), [ref sub @ ..] => {}, @@ -57,8 +52,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[idx] { - //~^ match_on_vec_items - + //~^ match_on_vec_items 0 => println!("0"), 1 => println!("1"), _ => println!("Hello, World!"), @@ -66,8 +60,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[range] { - //~^ match_on_vec_items - + //~^ match_on_vec_items [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => println!("Hello, World!"), @@ -81,8 +74,7 @@ fn match_vec_ref() { // Lint, may panic match arr[idx] { - //~^ match_on_vec_items - + //~^ match_on_vec_items 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -90,8 +82,7 @@ fn match_vec_ref() { // Lint, may panic match arr[range] { - //~^ match_on_vec_items - + //~^ match_on_vec_items [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 b00b2cb662a0..ae79e1305f7f 100644 --- a/tests/ui/match_on_vec_items.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -8,43 +8,43 @@ LL | match arr[idx] { = help: to override `-D warnings` add `#[allow(clippy::match_on_vec_items)]` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:20:11 + --> tests/ui/match_on_vec_items.rs:18:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:35:11 + --> tests/ui/match_on_vec_items.rs:32:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:44:11 + --> tests/ui/match_on_vec_items.rs:40:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:59:11 + --> tests/ui/match_on_vec_items.rs:54:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:68:11 + --> tests/ui/match_on_vec_items.rs:62:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:83:11 + --> tests/ui/match_on_vec_items.rs:76:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> tests/ui/match_on_vec_items.rs:92:11 + --> tests/ui/match_on_vec_items.rs:84: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 3885731264f7..176287e3d2e0 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -8,7 +8,6 @@ fn overlapping() { match 42 { 0..=10 => println!("0..=10"), //~^ match_overlapping_arm - 0..=11 => println!("0..=11"), _ => (), } @@ -16,7 +15,6 @@ fn overlapping() { match 42 { 0..=5 => println!("0..=5"), //~^ match_overlapping_arm - 6..=7 => println!("6..=7"), FOO..=11 => println!("FOO..=11"), _ => (), @@ -55,7 +53,6 @@ fn overlapping() { match 42 { 0..11 => println!("0..11"), //~^ match_overlapping_arm - 0..=11 => println!("0..=11"), _ => (), } @@ -82,14 +79,12 @@ fn overlapping() { 5..14 => println!("5..14"), 0..=10 => println!("0..=10"), //~^ match_overlapping_arm - _ => (), } match 42 { 0..7 => println!("0..7"), //~^ match_overlapping_arm - 0..=10 => println!("0..=10"), _ => (), } @@ -103,7 +98,6 @@ fn overlapping() { match 42 { ..=23 => println!("..=23"), //~^ match_overlapping_arm - ..26 => println!("..26"), _ => (), } @@ -114,7 +108,6 @@ fn overlapping() { 0..=20 => (), 21..=30 => (), //~^ match_overlapping_arm - 21..=40 => (), _ => (), } @@ -130,7 +123,6 @@ fn overlapping() { match 42u128 { 0..=0x0000_0000_0000_00ff => (), //~^ match_overlapping_arm - 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 cc928b4066a9..a60a09a07990 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -5,7 +5,7 @@ LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:12:9 + --> tests/ui/match_overlapping_arm.rs:11:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ @@ -13,85 +13,85 @@ LL | 0..=11 => println!("0..=11"), = help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]` error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:17:9 + --> tests/ui/match_overlapping_arm.rs:16:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:21:9 + --> tests/ui/match_overlapping_arm.rs:19:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:56:9 + --> tests/ui/match_overlapping_arm.rs:54:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:59:9 + --> tests/ui/match_overlapping_arm.rs:56:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:83:9 + --> tests/ui/match_overlapping_arm.rs:80:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:82:9 + --> tests/ui/match_overlapping_arm.rs:79:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:90:9 + --> tests/ui/match_overlapping_arm.rs:86:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:93:9 + --> tests/ui/match_overlapping_arm.rs:88:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:104:9 + --> tests/ui/match_overlapping_arm.rs:99:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:107:9 + --> tests/ui/match_overlapping_arm.rs:101:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:115:9 + --> tests/ui/match_overlapping_arm.rs:109:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:118:9 + --> tests/ui/match_overlapping_arm.rs:111:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> tests/ui/match_overlapping_arm.rs:131:9 + --> tests/ui/match_overlapping_arm.rs:124:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> tests/ui/match_overlapping_arm.rs:134:9 + --> tests/ui/match_overlapping_arm.rs:126:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_ref_pats.fixed b/tests/ui/match_ref_pats.fixed index 8ada28985198..8add3da0c99f 100644 --- a/tests/ui/match_ref_pats.fixed +++ b/tests/ui/match_ref_pats.fixed @@ -6,7 +6,7 @@ fn ref_pats() { { let v = &Some(0); match *v { - //~^ match_ref_pats + //~^ match_ref_pats Some(v) => println!("{:?}", v), None => println!("none"), } @@ -24,7 +24,7 @@ fn ref_pats() { // Special case: using `&` both in expr and pats. let w = Some(0); match w { - //~^ match_ref_pats + //~^ match_ref_pats Some(v) => println!("{:?}", v), None => println!("none"), } @@ -37,13 +37,13 @@ fn ref_pats() { let a = &Some(0); if a.is_none() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching println!("none"); } let b = Some(0); if b.is_none() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching println!("none"); } } @@ -104,7 +104,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 match *foobar_variant!(0) { - //~^ match_ref_pats + //~^ match_ref_pats FooBar::Foo => println!("Foo"), FooBar::Bar => println!("Bar"), FooBar::FooBar => println!("FooBar"), diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs index cac6240bde31..07889b0dfc24 100644 --- a/tests/ui/match_ref_pats.rs +++ b/tests/ui/match_ref_pats.rs @@ -6,7 +6,7 @@ fn ref_pats() { { let v = &Some(0); match v { - //~^ match_ref_pats + //~^ match_ref_pats &Some(v) => println!("{:?}", v), &None => println!("none"), } @@ -24,7 +24,7 @@ fn ref_pats() { // Special case: using `&` both in expr and pats. let w = Some(0); match &w { - //~^ match_ref_pats + //~^ match_ref_pats &Some(v) => println!("{:?}", v), &None => println!("none"), } @@ -37,13 +37,13 @@ fn ref_pats() { let a = &Some(0); if let &None = a { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching println!("none"); } let b = Some(0); if let &None = &b { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching println!("none"); } } @@ -104,7 +104,7 @@ mod issue_7740 { fn issue_7740() { // Issue #7740 match foobar_variant!(0) { - //~^ match_ref_pats + //~^ match_ref_pats &FooBar::Foo => println!("Foo"), &FooBar::Bar => println!("Bar"), &FooBar::FooBar => println!("FooBar"), diff --git a/tests/ui/match_result_ok.fixed b/tests/ui/match_result_ok.fixed index 2032394f0e92..0e630e6a2904 100644 --- a/tests/ui/match_result_ok.fixed +++ b/tests/ui/match_result_ok.fixed @@ -49,7 +49,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; while let Ok(a) = wat.next() { - //~^ match_result_ok + //~^ match_result_ok println!("{}", a); } } diff --git a/tests/ui/match_result_ok.rs b/tests/ui/match_result_ok.rs index c15e32d112d4..63bf6e8ab508 100644 --- a/tests/ui/match_result_ok.rs +++ b/tests/ui/match_result_ok.rs @@ -49,7 +49,7 @@ impl Wat { fn base_1(x: i32) { let mut wat = Wat { counter: x }; while let Some(a) = wat.next().ok() { - //~^ match_result_ok + //~^ match_result_ok println!("{}", a); } } diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs index 073c66930357..55441948e91b 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -9,37 +9,36 @@ pub enum Abc { fn match_same_arms() { let _ = match Abc::A { -Abc::A => 0, -//~^ match_same_arms + Abc::A => 0, + //~^ match_same_arms Abc::B => 1, _ => 0, }; match (1, 2, 3) { -(1, .., 3) => 42, -//~^ match_same_arms + (1, .., 3) => 42, + //~^ match_same_arms (.., 3) => 42, _ => 0, }; let _ = match 42 { 42 => 1, -51 => 1, -//~^ match_same_arms -41 => 2, -//~^ match_same_arms + 51 => 1, + //~^ match_same_arms + 41 => 2, + //~^ match_same_arms 52 => 2, _ => 0, }; let _ = match 42 { 1 => 2, -2 => 2, -//~^ match_same_arms -//~| match_same_arms - -3 => 2, -//~^ match_same_arms + 2 => 2, + //~^ match_same_arms + //~| match_same_arms + 3 => 2, + //~^ match_same_arms 4 => 3, _ => 0, }; @@ -58,7 +57,6 @@ mod issue4244 { CommandInfo::BuiltIn { name, .. } => name.to_string(), CommandInfo::External { name, .. } => name.to_string(), //~^ match_same_arms - } } } diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index a269c4f39267..3744b83d89cc 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -1,9 +1,9 @@ error: this match arm has an identical body to the `_` wildcard arm - --> tests/ui/match_same_arms.rs:12:1 + --> tests/ui/match_same_arms.rs:12:9 | -LL | / Abc::A => 0, +LL | / Abc::A => 0, LL | | - | |_^ help: try removing the arm + | |________^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here @@ -15,66 +15,66 @@ LL | _ => 0, = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:19:1 + --> tests/ui/match_same_arms.rs:19:9 | -LL | (1, .., 3) => 42, - | ^^^^^^^^^^^^^^^^ +LL | (1, .., 3) => 42, + | ^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (1, .., 3) | (.., 3) => 42, +LL ~ (1, .., 3) | (.., 3) => 42, LL | LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:27:1 + --> tests/ui/match_same_arms.rs:27:9 | -LL | 51 => 1, - | ^^^^^^^ +LL | 51 => 1, + | ^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 42 => 1, -LL - 51 => 1, +LL - 51 => 1, LL + 51 | 42 => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:29:1 + --> tests/ui/match_same_arms.rs:29:9 | -LL | 41 => 2, - | ^^^^^^^ +LL | 41 => 2, + | ^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ 41 | 52 => 2, +LL ~ 41 | 52 => 2, LL | LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:37:1 + --> tests/ui/match_same_arms.rs:37:9 | -LL | 2 => 2, - | ^^^^^^ +LL | 2 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 1 => 2, -LL - 2 => 2, +LL - 2 => 2, LL + 2 | 1 => 2, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:41:1 + --> tests/ui/match_same_arms.rs:40:9 | -LL | 3 => 2, - | ^^^^^^ +LL | 3 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm @@ -82,24 +82,26 @@ help: or try merging the arm patterns and removing the obsolete arm LL ~ 2 => 2, LL | LL | -LL | -LL ~ 3 | 1 => 2, +LL ~ 3 | 1 => 2, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:37:1 + --> tests/ui/match_same_arms.rs:37:9 | -LL | 2 => 2, - | ^^^^^^ +LL | 2 => 2, + | ^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ 2 | 3 => 2, +LL ~ 2 | 3 => 2, +LL | +LL | +LL ~ | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms.rs:59:17 + --> tests/ui/match_same_arms.rs:58:17 | LL | CommandInfo::External { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms2.fixed b/tests/ui/match_same_arms2.fixed index 855c3287532c..0d93e2c728d7 100644 --- a/tests/ui/match_same_arms2.fixed +++ b/tests/ui/match_same_arms2.fixed @@ -26,16 +26,15 @@ fn match_same_arms() { }, }; - let _ = match 42 { 51 | 42 => foo(), -//~^ match_same_arms + //~^ match_same_arms _ => true, }; let _ = match Some(42) { None | Some(_) => 24, -//~^ match_same_arms + //~^ match_same_arms }; let _ = match Some(42) { @@ -57,7 +56,7 @@ fn match_same_arms() { match (Some(42), Some(42)) { (None, Some(a)) | (Some(a), None) => bar(a), -//~^ match_same_arms + //~^ match_same_arms _ => (), } @@ -71,13 +70,13 @@ fn match_same_arms() { let _ = match (Some(42), Some(42)) { (None, Some(a)) | (Some(a), None) if a == 42 => a, -//~^ match_same_arms + //~^ match_same_arms _ => 0, }; match (Some(42), Some(42)) { -(Some(a), ..) | (.., Some(a)) => bar(a), -//~^ match_same_arms + (Some(a), ..) | (.., Some(a)) => bar(a), + //~^ match_same_arms _ => (), } @@ -110,8 +109,8 @@ fn match_same_arms() { } match (x, Some(1i32)) { -(Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), -//~^ match_same_arms + (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), + //~^ match_same_arms _ => println!("err"), } @@ -126,7 +125,7 @@ fn match_same_arms() { match x { Ok(_tmp) => println!("ok"), Ok(_) | Ok(3) => println!("ok"), -//~^ match_same_arms + //~^ match_same_arms Err(_) => { unreachable!(); }, @@ -159,7 +158,6 @@ fn match_same_arms() { }, } - match_expr_like_matches_macro_priority(); } @@ -202,8 +200,8 @@ fn main() { // Suggest moving `Foo::Z(_)` up. let _ = match Foo::X(0) { -Foo::X(0) | Foo::Z(_) => 1, -//~^ match_same_arms + Foo::X(0) | Foo::Z(_) => 1, + //~^ match_same_arms Foo::X(_) | Foo::Y(_) => 2, _ => 0, }; @@ -211,8 +209,8 @@ Foo::X(0) | Foo::Z(_) => 1, // Suggest moving `Foo::X(0)` down. let _ = match Foo::X(0) { Foo::Y(_) | Foo::Z(0) => 2, -Foo::Z(_) | Foo::X(0) => 1, -//~^ match_same_arms + Foo::Z(_) | Foo::X(0) => 1, + //~^ match_same_arms _ => 0, }; @@ -234,8 +232,8 @@ Foo::Z(_) | Foo::X(0) => 1, let _ = match None { Some(Bar { y: 10, z: 0, .. }) => 2, None => 50, -Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, -//~^ match_same_arms + Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, + //~^ match_same_arms _ => 200, }; @@ -266,7 +264,6 @@ mod with_lifetime { match *self { MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s, //~^ match_same_arms - } } } diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs index 73a4fd432551..b0ebc4784f33 100644 --- a/tests/ui/match_same_arms2.rs +++ b/tests/ui/match_same_arms2.rs @@ -35,18 +35,17 @@ fn match_same_arms() { }, }; - let _ = match 42 { 42 => foo(), -51 => foo(), -//~^ match_same_arms + 51 => foo(), + //~^ match_same_arms _ => true, }; let _ = match Some(42) { Some(_) => 24, -None => 24, -//~^ match_same_arms + None => 24, + //~^ match_same_arms }; let _ = match Some(42) { @@ -68,8 +67,8 @@ None => 24, match (Some(42), Some(42)) { (Some(a), None) => bar(a), -(None, Some(a)) => bar(a), -//~^ match_same_arms + (None, Some(a)) => bar(a), + //~^ match_same_arms _ => (), } @@ -83,14 +82,14 @@ None => 24, let _ = match (Some(42), Some(42)) { (Some(a), None) if a == 42 => a, -(None, Some(a)) if a == 42 => a, -//~^ match_same_arms + (None, Some(a)) if a == 42 => a, + //~^ match_same_arms _ => 0, }; match (Some(42), Some(42)) { -(Some(a), ..) => bar(a), -//~^ match_same_arms + (Some(a), ..) => bar(a), + //~^ match_same_arms (.., Some(a)) => bar(a), _ => (), } @@ -124,8 +123,8 @@ None => 24, } match (x, Some(1i32)) { -(Ok(x), Some(_)) => println!("ok {}", x), -//~^ match_same_arms + (Ok(x), Some(_)) => println!("ok {}", x), + //~^ match_same_arms (Ok(_), Some(x)) => println!("ok {}", x), _ => println!("err"), } @@ -141,8 +140,8 @@ None => 24, match x { Ok(_tmp) => println!("ok"), Ok(3) => println!("ok"), -Ok(_) => println!("ok"), -//~^ match_same_arms + Ok(_) => println!("ok"), + //~^ match_same_arms Err(_) => { unreachable!(); }, @@ -178,7 +177,6 @@ Ok(_) => println!("ok"), }, } - match_expr_like_matches_macro_priority(); } @@ -221,8 +219,8 @@ fn main() { // Suggest moving `Foo::Z(_)` up. let _ = match Foo::X(0) { -Foo::X(0) => 1, -//~^ match_same_arms + Foo::X(0) => 1, + //~^ match_same_arms Foo::X(_) | Foo::Y(_) => 2, Foo::Z(_) => 1, _ => 0, @@ -232,8 +230,8 @@ Foo::X(0) => 1, let _ = match Foo::X(0) { Foo::X(0) => 1, Foo::Y(_) | Foo::Z(0) => 2, -Foo::Z(_) => 1, -//~^ match_same_arms + Foo::Z(_) => 1, + //~^ match_same_arms _ => 0, }; @@ -256,8 +254,8 @@ Foo::Z(_) => 1, Some(Bar { x: 0, y: 5, .. }) => 1, Some(Bar { y: 10, z: 0, .. }) => 2, None => 50, -Some(Bar { y: 0, x: 5, .. }) => 1, -//~^ match_same_arms + Some(Bar { y: 0, x: 5, .. }) => 1, + //~^ match_same_arms _ => 200, }; @@ -290,7 +288,6 @@ mod with_lifetime { MaybeStaticStr::Static(s) => s, MaybeStaticStr::Borrowed(s) => s, //~^ match_same_arms - } } } diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index c67ac5475aae..21a8743cc324 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -26,105 +26,105 @@ LL | | }, = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:41:1 + --> tests/ui/match_same_arms2.rs:40:9 | -LL | 51 => foo(), - | ^^^^^^^^^^^ +LL | 51 => foo(), + | ^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - 42 => foo(), -LL - 51 => foo(), +LL - 51 => foo(), LL + 51 | 42 => foo(), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:48:1 + --> tests/ui/match_same_arms2.rs:47:9 | -LL | None => 24, - | ^^^^^^^^^^ +LL | None => 24, + | ^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - Some(_) => 24, -LL - None => 24, +LL - None => 24, LL + None | Some(_) => 24, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:71:1 + --> tests/ui/match_same_arms2.rs:70:9 | -LL | (None, Some(a)) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (None, Some(a)) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - (Some(a), None) => bar(a), -LL - (None, Some(a)) => bar(a), +LL - (None, Some(a)) => bar(a), LL + (None, Some(a)) | (Some(a), None) => bar(a), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:86:1 + --> tests/ui/match_same_arms2.rs:85:9 | -LL | (None, Some(a)) if a == 42 => a, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (None, Some(a)) if a == 42 => a, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - (Some(a), None) if a == 42 => a, -LL - (None, Some(a)) if a == 42 => a, +LL - (None, Some(a)) if a == 42 => a, LL + (None, Some(a)) | (Some(a), None) if a == 42 => a, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:92:1 + --> tests/ui/match_same_arms2.rs:91:9 | -LL | (Some(a), ..) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Some(a), ..) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (Some(a), ..) | (.., Some(a)) => bar(a), +LL ~ (Some(a), ..) | (.., Some(a)) => bar(a), LL | LL ~ _ => (), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:127:1 + --> tests/ui/match_same_arms2.rs:126:9 | -LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Ok(x), Some(_)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), +LL ~ (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), LL | LL ~ _ => println!("err"), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:144:1 + --> tests/ui/match_same_arms2.rs:143:9 | -LL | Ok(_) => println!("ok"), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | Ok(_) => println!("ok"), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL - Ok(3) => println!("ok"), -LL - Ok(_) => println!("ok"), +LL - Ok(_) => println!("ok"), LL + Ok(_) | Ok(3) => println!("ok"), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:172:9 + --> tests/ui/match_same_arms2.rs:171:9 | LL | / 1 => { LL | | empty!(0); @@ -142,49 +142,49 @@ LL + 1 | 0 => { | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:224:1 + --> tests/ui/match_same_arms2.rs:222:9 | -LL | Foo::X(0) => 1, - | ^^^^^^^^^^^^^^ +LL | Foo::X(0) => 1, + | ^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | -LL ~ Foo::X(0) | Foo::Z(_) => 1, +LL ~ Foo::X(0) | Foo::Z(_) => 1, LL | LL | Foo::X(_) | Foo::Y(_) => 2, LL ~ _ => 0, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:235:1 + --> tests/ui/match_same_arms2.rs:233:9 | -LL | Foo::Z(_) => 1, - | ^^^^^^^^^^^^^^ +LL | Foo::Z(_) => 1, + | ^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL ~ Foo::Y(_) | Foo::Z(0) => 2, -LL ~ Foo::Z(_) | Foo::X(0) => 1, +LL ~ Foo::Z(_) | Foo::X(0) => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:259:1 + --> tests/ui/match_same_arms2.rs:257:9 | -LL | Some(Bar { y: 0, x: 5, .. }) => 1, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Some(Bar { y: 0, x: 5, .. }) => 1, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try changing either arm body help: or try merging the arm patterns and removing the obsolete arm | LL ~ Some(Bar { y: 10, z: 0, .. }) => 2, LL | None => 50, -LL ~ Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, +LL ~ Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:274:9 + --> tests/ui/match_same_arms2.rs:272:9 | LL | 1 => cfg!(not_enable), | ^^^^^^^^^^^^^^^^^^^^^ @@ -198,7 +198,7 @@ LL + 1 | 0 => cfg!(not_enable), | error: this match arm has an identical body to another arm - --> tests/ui/match_same_arms2.rs:291:17 + --> tests/ui/match_same_arms2.rs:289:17 | LL | MaybeStaticStr::Borrowed(s) => s, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms_non_exhaustive.fixed b/tests/ui/match_same_arms_non_exhaustive.fixed index 71041cff8d0a..0c9398933b80 100644 --- a/tests/ui/match_same_arms_non_exhaustive.fixed +++ b/tests/ui/match_same_arms_non_exhaustive.fixed @@ -42,7 +42,6 @@ pub fn g(x: Ordering) { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), //~^ match_same_arms - _ => repeat(), } } @@ -56,7 +55,6 @@ mod g { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), //~^ match_same_arms - _ => repeat(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index 45dc5d78883b..304a9e5c28e7 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -43,7 +43,6 @@ pub fn g(x: Ordering) { Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => repeat(), //~^ match_same_arms - _ => repeat(), } } @@ -58,7 +57,6 @@ mod g { Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => repeat(), //~^ match_same_arms - _ => repeat(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index 1033203c7237..aa7f8c95dce8 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -7,7 +7,7 @@ LL | | | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms_non_exhaustive.rs:47:9 + --> tests/ui/match_same_arms_non_exhaustive.rs:46:9 | LL | _ => repeat(), | ^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | _ => repeat(), = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to the `_` wildcard arm - --> tests/ui/match_same_arms_non_exhaustive.rs:59:13 + --> tests/ui/match_same_arms_non_exhaustive.rs:58:13 | LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), LL | | @@ -23,7 +23,7 @@ LL | | | = help: or try changing either arm body note: `_` wildcard arm here - --> tests/ui/match_same_arms_non_exhaustive.rs:62:13 + --> tests/ui/match_same_arms_non_exhaustive.rs:60:13 | LL | _ => repeat(), | ^^^^^^^^^^^^^ diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs index 27fd7d601abf..ada51254c6cd 100644 --- a/tests/ui/match_single_binding.rs +++ b/tests/ui/match_single_binding.rs @@ -31,14 +31,14 @@ fn main() { let c = 3; // Lint match (a, b, c) { - //~^ match_single_binding + //~^ match_single_binding (x, y, z) => { println!("{} {} {}", x, y, z); }, } // Lint match (a, b, c) { - //~^ match_single_binding + //~^ match_single_binding (x, y, z) => println!("{} {} {}", x, y, z), } // Ok @@ -56,12 +56,12 @@ fn main() { } // Lint match a { - //~^ match_single_binding + //~^ match_single_binding _ => println!("whatever"), } // Lint match a { - //~^ match_single_binding + //~^ match_single_binding _ => { let x = 29; println!("x has a value of {}", x); @@ -69,7 +69,7 @@ fn main() { } // Lint match a { - //~^ match_single_binding + //~^ match_single_binding _ => { let e = 5 * a; if e >= 5 { @@ -80,29 +80,29 @@ fn main() { // Lint let p = Point { x: 0, y: 7 }; match p { - //~^ match_single_binding + //~^ match_single_binding Point { x, y } => println!("Coords: ({}, {})", x, y), } // Lint match p { - //~^ match_single_binding + //~^ match_single_binding Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), } // Lint let x = 5; match x { - //~^ match_single_binding + //~^ match_single_binding ref r => println!("Got a reference to {}", r), } // Lint let mut x = 5; match x { - //~^ match_single_binding + //~^ match_single_binding ref mut mr => println!("Got a mutable reference to {}", mr), } // Lint let product = match coords() { - //~^ match_single_binding + //~^ match_single_binding Point { x, y } => x * y, }; // Lint @@ -111,7 +111,7 @@ fn main() { let _ = v .iter() .map(|i| match i.unwrap() { - //~^ match_single_binding + //~^ match_single_binding unwrapped => unwrapped, }) .collect::>(); @@ -138,7 +138,7 @@ fn main() { // Lint let x = 1; match x { - //~^ match_single_binding + //~^ match_single_binding // => _ => println!("Not an array index start"), } @@ -148,7 +148,7 @@ fn issue_8723() { let (mut val, idx) = ("a b", 1); val = match val.split_at(idx) { - //~^ match_single_binding + //~^ match_single_binding (pre, suf) => { println!("{}", pre); suf @@ -162,14 +162,14 @@ fn side_effects() {} fn issue_9575() { let _ = || match side_effects() { - //~^ match_single_binding + //~^ match_single_binding _ => println!("Needs curlies"), }; } fn issue_9725(r: Option) { match r { - //~^ match_single_binding + //~^ match_single_binding x => match x { Some(_) => { println!("Some"); @@ -183,46 +183,46 @@ fn issue_9725(r: Option) { fn issue_10447() -> usize { match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => (), } let a = match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => (), }; match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => side_effects(), } let b = match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => side_effects(), }; match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => println!("1"), } let c = match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => println!("1"), }; let in_expr = [ match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => (), }, match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => side_effects(), }, match 1 { - //~^ match_single_binding + //~^ match_single_binding _ => println!("1"), }, ]; diff --git a/tests/ui/match_single_binding2.fixed b/tests/ui/match_single_binding2.fixed index 1d34f179ea4a..988121f50d0f 100644 --- a/tests/ui/match_single_binding2.fixed +++ b/tests/ui/match_single_binding2.fixed @@ -45,7 +45,7 @@ fn main() { // issue #7094 let x = 1; match x { - //~^ match_single_binding + //~^ match_single_binding 0 => 1, _ => 2, }; diff --git a/tests/ui/match_single_binding2.rs b/tests/ui/match_single_binding2.rs index 8c18d7c133c1..a4fb2bd6f381 100644 --- a/tests/ui/match_single_binding2.rs +++ b/tests/ui/match_single_binding2.rs @@ -15,7 +15,7 @@ fn main() { fn size_hint(iter: &AppendIter) -> (usize, Option) { match &iter.inner { Some((iter, _item)) => match iter.size_hint() { - //~^ match_single_binding + //~^ match_single_binding (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))), }, None => (0, Some(0)), @@ -41,7 +41,7 @@ fn main() { // Lint (scrutinee has side effects) // issue #7094 match side_effects() { - //~^ match_single_binding + //~^ match_single_binding _ => println!("Side effects"), } @@ -49,7 +49,7 @@ fn main() { // issue #7094 let x = 1; match match x { - //~^ match_single_binding + //~^ match_single_binding 0 => 1, _ => 2, } { diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs index f7f7c398d647..d18d4047e2a6 100644 --- a/tests/ui/match_wild_err_arm.rs +++ b/tests/ui/match_wild_err_arm.rs @@ -22,8 +22,6 @@ fn match_wild_err_arm() { Ok(_) => println!("ok"), Err(_) => panic!("err"), //~^ match_wild_err_arm - - } match x { @@ -31,16 +29,13 @@ fn match_wild_err_arm() { Ok(_) => println!("ok"), Err(_) => panic!(), //~^ match_wild_err_arm - - } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => { - //~^ match_wild_err_arm - + //~^ match_wild_err_arm panic!(); }, @@ -51,8 +46,6 @@ fn match_wild_err_arm() { Ok(_) => println!("ok"), Err(_e) => panic!(), //~^ match_wild_err_arm - - } // Allowed when used in `panic!`. diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index ec0ca602f5f9..fc65924f0873 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -9,7 +9,7 @@ LL | Err(_) => panic!("err"), = help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]` error: `Err(_)` matches all errors - --> tests/ui/match_wild_err_arm.rs:32:9 + --> tests/ui/match_wild_err_arm.rs:30:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -17,7 +17,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 - --> tests/ui/match_wild_err_arm.rs:41:9 + --> tests/ui/match_wild_err_arm.rs:37:9 | LL | Err(_) => { | ^^^^^^ @@ -25,7 +25,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 - --> tests/ui/match_wild_err_arm.rs:52:9 + --> tests/ui/match_wild_err_arm.rs:47:9 | LL | Err(_e) => panic!(), | ^^^^^^^ diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index ad9bd079b98d..b510af8ac6f1 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -14,25 +14,17 @@ fn main() { memstuff::forget(six); //~^ mem_forget - - let seven: Rc = Rc::new(7); std::mem::forget(seven); //~^ mem_forget - - let eight: Vec = vec![8]; forgetSomething(eight); //~^ mem_forget - - let string = String::new(); std::mem::forget(string); //~^ mem_forget - - std::mem::forget(7); } diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 4dd1efc1a240..049db54a04b0 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -9,7 +9,7 @@ LL | memstuff::forget(six); = help: to override `-D warnings` add `#[allow(clippy::mem_forget)]` error: usage of `mem::forget` on `Drop` type - --> tests/ui/mem_forget.rs:20:5 + --> tests/ui/mem_forget.rs:18:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | std::mem::forget(seven); = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type - --> tests/ui/mem_forget.rs:26:5 + --> tests/ui/mem_forget.rs:22:5 | LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | forgetSomething(eight); = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields - --> tests/ui/mem_forget.rs:32:5 + --> tests/ui/mem_forget.rs:26:5 | LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 98417df8c84b..fb4a367266d3 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -161,7 +161,7 @@ LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` error: replacing an `Option` with `Some(..)` - --> tests/ui/mem_replace.rs:138:20 + --> tests/ui/mem_replace.rs:164:20 | LL | let replaced = mem::replace(&mut an_option, Some(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `an_option.replace(1)` @@ -170,13 +170,13 @@ LL | let replaced = mem::replace(&mut an_option, Some(1)); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_some)]` error: replacing an `Option` with `Some(..)` - --> tests/ui/mem_replace.rs:142:20 + --> tests/ui/mem_replace.rs:168:20 | LL | let replaced = mem::replace(an_option, Some(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `an_option.replace(1)` error: replacing an `Option` with `Some(..)` - --> tests/ui/mem_replace.rs:147:20 + --> tests/ui/mem_replace.rs:173:20 | LL | let replaced = mem::replace(if b { &mut opt1 } else { &mut opt2 }, Some(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::replace()` instead: `(if b { &mut opt1 } else { &mut opt2 }).replace(1)` diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index a7e37b2e8d23..85a4d59e5ca0 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -101,7 +101,7 @@ struct BadNew; impl BadNew { fn new() -> i32 { - //~^ new_ret_no_self + //~^ new_ret_no_self 0 } } diff --git a/tests/ui/methods_unfixable.rs b/tests/ui/methods_unfixable.rs index a9881080d6f4..c19a769f7974 100644 --- a/tests/ui/methods_unfixable.rs +++ b/tests/ui/methods_unfixable.rs @@ -8,5 +8,4 @@ pub fn issue10029() { let iter = (0..10); let _ = iter.filter(|_| true).next(); //~^ filter_next - } diff --git a/tests/ui/min_ident_chars.rs b/tests/ui/min_ident_chars.rs index 5eae52d5c25c..f473ac848a8e 100644 --- a/tests/ui/min_ident_chars.rs +++ b/tests/ui/min_ident_chars.rs @@ -7,7 +7,7 @@ extern crate proc_macros; use proc_macros::{external, with_span}; struct A { -//~^ min_ident_chars + //~^ min_ident_chars a: u32, //~^ min_ident_chars i: u32, @@ -21,7 +21,7 @@ struct B(u32); //~^ min_ident_chars struct O { -//~^ min_ident_chars + //~^ min_ident_chars o: u32, //~^ min_ident_chars } @@ -29,7 +29,7 @@ struct O { struct i; enum C { -//~^ min_ident_chars + //~^ min_ident_chars D, //~^ min_ident_chars E, @@ -116,8 +116,8 @@ fn main() { fn b() {} //~^ min_ident_chars fn wrong_pythagoras(a: f32, b: f32) -> f32 { -//~^ min_ident_chars -//~| min_ident_chars + //~^ min_ident_chars + //~| min_ident_chars a * a + a * b } diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index 1b1a6a0eb10b..f3eeb85f20ed 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -22,7 +22,6 @@ fn main() { min(1, max(3, x)); //~^ min_max - min(max(3, x), 1); //~^ min_max @@ -32,11 +31,9 @@ fn main() { max(3, min(x, 1)); //~^ min_max - my_max(3, my_min(x, 1)); //~^ min_max - min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x min(1, max(LARGE, x)); // no error, we don't lookup consts here @@ -51,7 +48,6 @@ fn main() { max(min(s, "Apple"), "Zoo"); //~^ min_max - max("Apple", min(s, "Zoo")); // ok let f = 3f32; @@ -64,7 +60,6 @@ fn main() { f.max(3f32).min(1f32); //~^ min_max - x.max(1).min(3); // ok x.min(3).max(1); // ok f.min(3f32).max(1f32); // ok @@ -80,7 +75,6 @@ fn main() { s.min("Apple").max("Zoo"); //~^ min_max - s.min("Zoo").max("Apple"); // ok let not_ord = NotOrd(1); diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index 91b3d722b3c6..84b4d3754552 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -8,73 +8,73 @@ LL | min(1, max(3, x)); = help: to override `-D warnings` add `#[allow(clippy::min_max)]` error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:26:5 + --> tests/ui/min_max.rs:25:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:29:5 + --> tests/ui/min_max.rs:28:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:32:5 + --> tests/ui/min_max.rs:31:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:36:5 + --> tests/ui/min_max.rs:34:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:48:5 + --> tests/ui/min_max.rs:45:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:51:5 + --> tests/ui/min_max.rs:48:5 | LL | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:58:5 + --> tests/ui/min_max.rs:54:5 | LL | x.min(1).max(3); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:61:5 + --> tests/ui/min_max.rs:57:5 | LL | x.max(3).min(1); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:64:5 + --> tests/ui/min_max.rs:60:5 | LL | f.max(3f32).min(1f32); | ^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:72:5 + --> tests/ui/min_max.rs:67:5 | LL | max(x.min(1), 3); | ^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:77:5 + --> tests/ui/min_max.rs:72:5 | LL | s.max("Zoo").min("Apple"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> tests/ui/min_max.rs:80:5 + --> tests/ui/min_max.rs:75: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 4793eb9726d6..4627bef28a29 100644 --- a/tests/ui/min_rust_version_attr.rs +++ b/tests/ui/min_rust_version_attr.rs @@ -12,14 +12,12 @@ fn just_under_msrv() { fn meets_msrv() { let log2_10 = 3.321928094887362; //~^ approx_constant - } #[clippy::msrv = "1.44.0"] fn just_above_msrv() { let log2_10 = 3.321928094887362; //~^ approx_constant - } #[clippy::msrv = "1.42"] @@ -31,7 +29,6 @@ fn no_patch_under() { fn no_patch_meets() { let log2_10 = 3.321928094887362; //~^ approx_constant - } fn inner_attr_under() { @@ -43,7 +40,6 @@ fn inner_attr_meets() { #![clippy::msrv = "1.43"] let log2_10 = 3.321928094887362; //~^ approx_constant - } // https://github.com/rust-lang/rust-clippy/issues/6920 @@ -56,7 +52,6 @@ fn scoping() { let log2_10 = 3.321928094887362; //~^ approx_constant - mod a { #![clippy::msrv = "1.42.0"] @@ -64,7 +59,6 @@ fn scoping() { #![clippy::msrv = "1.43.0"] let log2_10 = 3.321928094887362; //~^ approx_constant - } fn should_not_warn() { diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index 6d4a8d9bd86e..809b1cfe73bf 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 - --> tests/ui/min_rust_version_attr.rs:20:19 + --> tests/ui/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 - --> tests/ui/min_rust_version_attr.rs:32:19 + --> tests/ui/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 - --> tests/ui/min_rust_version_attr.rs:44:19 + --> tests/ui/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 - --> tests/ui/min_rust_version_attr.rs:56:19 + --> tests/ui/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 - --> tests/ui/min_rust_version_attr.rs:65:27 + --> tests/ui/min_rust_version_attr.rs:60:27 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mismatching_type_param_order.rs b/tests/ui/mismatching_type_param_order.rs index 7e6044d0f5ff..11ff865b583b 100644 --- a/tests/ui/mismatching_type_param_order.rs +++ b/tests/ui/mismatching_type_param_order.rs @@ -12,13 +12,10 @@ fn main() { //~^ mismatching_type_param_order //~| mismatching_type_param_order - - // lint on the 2nd param impl Foo {} //~^ mismatching_type_param_order - // should not lint impl Foo {} @@ -32,8 +29,6 @@ fn main() { //~^ mismatching_type_param_order //~| mismatching_type_param_order - - struct Bar { x: i32, } @@ -53,9 +48,6 @@ fn main() { //~| mismatching_type_param_order //~| mismatching_type_param_order - - - // also works for unions union FooUnion where @@ -69,8 +61,6 @@ fn main() { //~^ mismatching_type_param_order //~| mismatching_type_param_order - - impl FooUnion where A: Copy, diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index 817ab8c99796..214d9d734d1b 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -17,7 +17,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 - --> tests/ui/mismatching_type_param_order.rs:18:23 + --> tests/ui/mismatching_type_param_order.rs:16:23 | LL | impl Foo {} | ^ @@ -25,7 +25,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 - --> tests/ui/mismatching_type_param_order.rs:31:44 + --> tests/ui/mismatching_type_param_order.rs:28:44 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -33,7 +33,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 - --> tests/ui/mismatching_type_param_order.rs:31:47 + --> tests/ui/mismatching_type_param_order.rs:28:47 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -41,7 +41,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 - --> tests/ui/mismatching_type_param_order.rs:51:27 + --> tests/ui/mismatching_type_param_order.rs:46:27 | LL | impl FooEnum {} | ^ @@ -49,7 +49,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 - --> tests/ui/mismatching_type_param_order.rs:51:30 + --> tests/ui/mismatching_type_param_order.rs:46:30 | LL | impl FooEnum {} | ^ @@ -57,7 +57,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 - --> tests/ui/mismatching_type_param_order.rs:51:33 + --> tests/ui/mismatching_type_param_order.rs:46:33 | LL | impl FooEnum {} | ^ @@ -65,7 +65,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 - --> tests/ui/mismatching_type_param_order.rs:68:31 + --> tests/ui/mismatching_type_param_order.rs:60:31 | LL | impl FooUnion where A: Copy {} | ^ @@ -73,7 +73,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 - --> tests/ui/mismatching_type_param_order.rs:68:34 + --> tests/ui/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 81af604e2e63..cada5307b1c8 100644 --- a/tests/ui/misnamed_getters.fixed +++ b/tests/ui/misnamed_getters.fixed @@ -10,37 +10,36 @@ struct A { impl A { fn a(&self) -> &u8 { - //~^ misnamed_getters - + //~^ misnamed_getters &self.a } fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } fn b(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.b } fn b_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } fn c(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.c } fn c_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.c } @@ -53,24 +52,24 @@ union B { impl B { unsafe fn a(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.a } unsafe fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } unsafe fn b(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.b } unsafe fn b_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } @@ -84,24 +83,24 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.a } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } unsafe fn b_unchecked(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.b } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } @@ -135,23 +134,23 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.a } fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } fn d(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.d } fn d_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.d } diff --git a/tests/ui/misnamed_getters.rs b/tests/ui/misnamed_getters.rs index cb83ae02ccf1..f529c56b4717 100644 --- a/tests/ui/misnamed_getters.rs +++ b/tests/ui/misnamed_getters.rs @@ -10,37 +10,36 @@ struct A { impl A { fn a(&self) -> &u8 { - //~^ misnamed_getters - + //~^ misnamed_getters &self.b } fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } fn b(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.a } fn b_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } fn c(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.b } fn c_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } @@ -53,24 +52,24 @@ union B { impl B { unsafe fn a(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.b } unsafe fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } unsafe fn b(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.a } unsafe fn b_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } @@ -84,24 +83,24 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.b } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } unsafe fn b_unchecked(self) -> u8 { - //~^ misnamed_getters + //~^ misnamed_getters self.a } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.a } @@ -135,23 +134,23 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.b } fn a_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } fn d(&self) -> &u8 { - //~^ misnamed_getters + //~^ misnamed_getters &self.b } fn d_mut(&mut self) -> &mut u8 { - //~^ misnamed_getters + //~^ misnamed_getters &mut self.b } diff --git a/tests/ui/misnamed_getters.stderr b/tests/ui/misnamed_getters.stderr index e3ea40b7a94e..5dd1d75bcf6f 100644 --- a/tests/ui/misnamed_getters.stderr +++ b/tests/ui/misnamed_getters.stderr @@ -2,7 +2,8 @@ error: getter function appears to return the wrong field --> tests/ui/misnamed_getters.rs:12:5 | LL | / fn a(&self) -> &u8 { -... | +LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } @@ -12,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::misnamed_getters)]` error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:18:5 + --> tests/ui/misnamed_getters.rs:17:5 | LL | / fn a_mut(&mut self) -> &mut u8 { LL | | @@ -23,7 +24,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:24:5 + --> tests/ui/misnamed_getters.rs:23:5 | LL | / fn b(self) -> u8 { LL | | @@ -34,7 +35,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:30:5 + --> tests/ui/misnamed_getters.rs:29:5 | LL | / fn b_mut(&mut self) -> &mut u8 { LL | | @@ -45,7 +46,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:36:5 + --> tests/ui/misnamed_getters.rs:35:5 | LL | / fn c(&self) -> &u8 { LL | | @@ -56,7 +57,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:42:5 + --> tests/ui/misnamed_getters.rs:41:5 | LL | / fn c_mut(&mut self) -> &mut u8 { LL | | @@ -67,7 +68,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:55:5 + --> tests/ui/misnamed_getters.rs:54:5 | LL | / unsafe fn a(&self) -> &u8 { LL | | @@ -78,7 +79,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:60:5 + --> tests/ui/misnamed_getters.rs:59:5 | LL | / unsafe fn a_mut(&mut self) -> &mut u8 { LL | | @@ -89,7 +90,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:66:5 + --> tests/ui/misnamed_getters.rs:65:5 | LL | / unsafe fn b(self) -> u8 { LL | | @@ -100,7 +101,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:72:5 + --> tests/ui/misnamed_getters.rs:71:5 | LL | / unsafe fn b_mut(&mut self) -> &mut u8 { LL | | @@ -111,7 +112,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:86:5 + --> tests/ui/misnamed_getters.rs:85:5 | LL | / unsafe fn a_unchecked(&self) -> &u8 { LL | | @@ -122,7 +123,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:91:5 + --> tests/ui/misnamed_getters.rs:90:5 | LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { LL | | @@ -133,7 +134,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:97:5 + --> tests/ui/misnamed_getters.rs:96:5 | LL | / unsafe fn b_unchecked(self) -> u8 { LL | | @@ -144,7 +145,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:103:5 + --> tests/ui/misnamed_getters.rs:102:5 | LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { LL | | @@ -155,7 +156,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:137:5 + --> tests/ui/misnamed_getters.rs:136:5 | LL | / fn a(&self) -> &u8 { LL | | @@ -166,7 +167,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:142:5 + --> tests/ui/misnamed_getters.rs:141:5 | LL | / fn a_mut(&mut self) -> &mut u8 { LL | | @@ -177,7 +178,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:148:5 + --> tests/ui/misnamed_getters.rs:147:5 | LL | / fn d(&self) -> &u8 { LL | | @@ -188,7 +189,7 @@ LL | | } | |_____^ error: getter function appears to return the wrong field - --> tests/ui/misnamed_getters.rs:153:5 + --> tests/ui/misnamed_getters.rs:152:5 | LL | / fn d_mut(&mut self) -> &mut u8 { LL | | diff --git a/tests/ui/missing_asserts_for_indexing.fixed b/tests/ui/missing_asserts_for_indexing.fixed index ce23c45b5214..3bbafe0bba3f 100644 --- a/tests/ui/missing_asserts_for_indexing.fixed +++ b/tests/ui/missing_asserts_for_indexing.fixed @@ -29,28 +29,24 @@ fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() > 4); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } // ok, don't lint for single array access @@ -103,7 +99,6 @@ fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { let _ = v2[5] + v2[15]; //~^ missing_asserts_for_indexing - } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() > 12); diff --git a/tests/ui/missing_asserts_for_indexing.rs b/tests/ui/missing_asserts_for_indexing.rs index 2d129c6b7e2c..f8ea0173c13f 100644 --- a/tests/ui/missing_asserts_for_indexing.rs +++ b/tests/ui/missing_asserts_for_indexing.rs @@ -29,28 +29,24 @@ fn sum_with_assert_lt(v: &[u8]) -> u8 { assert!(v.len() < 5); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_assert_le(v: &[u8]) -> u8 { assert!(v.len() <= 5); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { assert!(v.len() > 3); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { assert!(v.len() >= 4); v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } // ok, don't lint for single array access @@ -103,7 +99,6 @@ fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { let _ = v2[5] + v2[15]; //~^ missing_asserts_for_indexing - } fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { assert!(v1.len() >= 12); diff --git a/tests/ui/missing_asserts_for_indexing.stderr b/tests/ui/missing_asserts_for_indexing.stderr index a1559d21150b..5d30920ccf52 100644 --- a/tests/ui/missing_asserts_for_indexing.stderr +++ b/tests/ui/missing_asserts_for_indexing.stderr @@ -36,7 +36,7 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:37:5 + --> tests/ui/missing_asserts_for_indexing.rs:36:5 | LL | assert!(v.len() <= 5); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -44,34 +44,34 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:37:5 + --> tests/ui/missing_asserts_for_indexing.rs:36:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:37:12 + --> tests/ui/missing_asserts_for_indexing.rs:36:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:37:19 + --> tests/ui/missing_asserts_for_indexing.rs:36:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:37:26 + --> tests/ui/missing_asserts_for_indexing.rs:36:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:37:33 + --> tests/ui/missing_asserts_for_indexing.rs:36:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:44:5 + --> tests/ui/missing_asserts_for_indexing.rs:42:5 | LL | assert!(v.len() > 3); | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -79,34 +79,34 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:44:5 + --> tests/ui/missing_asserts_for_indexing.rs:42:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:44:12 + --> tests/ui/missing_asserts_for_indexing.rs:42:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:44:19 + --> tests/ui/missing_asserts_for_indexing.rs:42:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:44:26 + --> tests/ui/missing_asserts_for_indexing.rs:42:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:44:33 + --> tests/ui/missing_asserts_for_indexing.rs:42:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:51:5 + --> tests/ui/missing_asserts_for_indexing.rs:48:5 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -114,34 +114,34 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:51:5 + --> tests/ui/missing_asserts_for_indexing.rs:48:5 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:51:12 + --> tests/ui/missing_asserts_for_indexing.rs:48:12 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:51:19 + --> tests/ui/missing_asserts_for_indexing.rs:48:19 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:51:26 + --> tests/ui/missing_asserts_for_indexing.rs:48:26 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:51:33 + --> tests/ui/missing_asserts_for_indexing.rs:48:33 | LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:70:13 + --> tests/ui/missing_asserts_for_indexing.rs:66:13 | LL | assert!(v.len() >= 3); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)` @@ -152,19 +152,19 @@ LL | | let _ = v[1..4]; | |___________________^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:70:13 + --> tests/ui/missing_asserts_for_indexing.rs:66:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:73:13 + --> tests/ui/missing_asserts_for_indexing.rs:69:13 | LL | let _ = v[1..4]; | ^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:85:13 + --> tests/ui/missing_asserts_for_indexing.rs:81:13 | LL | assert!(v.len() >= 4); | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` @@ -175,19 +175,19 @@ LL | | let _ = v[1..=4]; | |____________________^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:85:13 + --> tests/ui/missing_asserts_for_indexing.rs:81:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:88:13 + --> tests/ui/missing_asserts_for_indexing.rs:84:13 | LL | let _ = v[1..=4]; | ^^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:101:13 + --> tests/ui/missing_asserts_for_indexing.rs:97:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` @@ -196,19 +196,19 @@ LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:101:13 + --> tests/ui/missing_asserts_for_indexing.rs:97:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:101:21 + --> tests/ui/missing_asserts_for_indexing.rs:97:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:104:13 + --> tests/ui/missing_asserts_for_indexing.rs:100:13 | LL | assert!(v2.len() >= 15); | ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)` @@ -217,19 +217,19 @@ LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:104:13 + --> tests/ui/missing_asserts_for_indexing.rs:100:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:104:21 + --> tests/ui/missing_asserts_for_indexing.rs:100:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:111:13 + --> tests/ui/missing_asserts_for_indexing.rs:106:13 | LL | assert!(v1.len() >= 12); | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` @@ -238,19 +238,19 @@ LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:111:13 + --> tests/ui/missing_asserts_for_indexing.rs:106:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:111:21 + --> tests/ui/missing_asserts_for_indexing.rs:106:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:136:13 + --> tests/ui/missing_asserts_for_indexing.rs:131:13 | LL | assert!(v1.len() == 2); | ---------------------- help: provide the highest index that is indexed with: `assert!(v1.len() == 3)` @@ -259,24 +259,24 @@ LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:136:13 + --> tests/ui/missing_asserts_for_indexing.rs:131:13 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:136:21 + --> tests/ui/missing_asserts_for_indexing.rs:131:21 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:136:29 + --> tests/ui/missing_asserts_for_indexing.rs:131:29 | LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times with an `assert` that does not cover the highest index - --> tests/ui/missing_asserts_for_indexing.rs:141:13 + --> tests/ui/missing_asserts_for_indexing.rs:136:13 | LL | assert!(2 == v3.len()); | ---------------------- help: provide the highest index that is indexed with: `assert!(v3.len() == 3)` @@ -285,17 +285,17 @@ LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^^^^^^^^^^^^^^^^^ | note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:141:13 + --> tests/ui/missing_asserts_for_indexing.rs:136:13 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:141:21 + --> tests/ui/missing_asserts_for_indexing.rs:136:21 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing.rs:141:29 + --> tests/ui/missing_asserts_for_indexing.rs:136:29 | LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^ diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.rs b/tests/ui/missing_asserts_for_indexing_unfixable.rs index c2083a90a19a..a520151a2dd9 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.rs +++ b/tests/ui/missing_asserts_for_indexing_unfixable.rs @@ -4,7 +4,6 @@ fn sum(v: &[u8]) -> u8 { v[0] + v[1] + v[2] + v[3] + v[4] //~^ missing_asserts_for_indexing - } fn subslice(v: &[u8]) { @@ -45,7 +44,6 @@ struct Foo<'a> { fn index_struct_field(f: &Foo<'_>) { let _ = f.v[0] + f.v[1]; //~^ missing_asserts_for_indexing - } fn index_struct_different_fields(f: &Foo<'_>) { @@ -60,7 +58,6 @@ fn shadowing() { let x: &[i32] = &[1]; let _ = x[0] + x[1]; //~^ missing_asserts_for_indexing - } pub fn issue11856(values: &[i32]) -> usize { diff --git a/tests/ui/missing_asserts_for_indexing_unfixable.stderr b/tests/ui/missing_asserts_for_indexing_unfixable.stderr index f6557fb2e50f..24109b052a8a 100644 --- a/tests/ui/missing_asserts_for_indexing_unfixable.stderr +++ b/tests/ui/missing_asserts_for_indexing_unfixable.stderr @@ -35,7 +35,7 @@ LL | v[0] + v[1] + v[2] + v[3] + v[4] = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:11:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:10:13 | LL | let _ = v[0]; | _____________^ @@ -45,19 +45,19 @@ LL | | let _ = v[1..4]; | = help: consider asserting the length before indexing: `assert!(v.len() > 3);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:11:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:10:13 | LL | let _ = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:14:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:13:13 | LL | let _ = v[1..4]; | ^^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:18:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:17:13 | LL | let a = v[0]; | _____________^ @@ -69,112 +69,112 @@ LL | | let c = v[2]; | = help: consider asserting the length before indexing: `assert!(v.len() > 2);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:18:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:17:13 | LL | let a = v[0]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:21:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:20:13 | LL | let b = v[1]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:22:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:21:13 | LL | let c = v[2]; | ^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:26:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v1.len() > 12);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:26:13 | LL | let _ = v1[0] + v1[12]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:27:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:26:21 | LL | let _ = v1[0] + v1[12]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:28:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:28:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:29:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:28:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:35:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:35:13 | LL | let _ = v2[5] + v2[15]; | ^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:36:21 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:35:21 | LL | let _ = v2[5] + v2[15]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:45:13 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(f.v.len() > 1);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:45:13 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:46:22 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:45:22 | LL | let _ = f.v[0] + f.v[1]; | ^^^^^^ = note: asserting the length before indexing will elide bounds checks error: indexing into a slice multiple times without an `assert` - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:59:13 | LL | let _ = x[0] + x[1]; | ^^^^^^^^^^^ | = help: consider asserting the length before indexing: `assert!(x.len() > 1);` note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:13 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:59:13 | LL | let _ = x[0] + x[1]; | ^^^^ note: slice indexed here - --> tests/ui/missing_asserts_for_indexing_unfixable.rs:61:20 + --> tests/ui/missing_asserts_for_indexing_unfixable.rs:59:20 | LL | let _ = x[0] + x[1]; | ^^^^ diff --git a/tests/ui/missing_const_for_fn/could_be_const.fixed b/tests/ui/missing_const_for_fn/could_be_const.fixed index 592302c34ae6..10df44e73b85 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.fixed +++ b/tests/ui/missing_const_for_fn/could_be_const.fixed @@ -11,44 +11,44 @@ struct Game { impl Game { // Could be const pub const fn new() -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { guess: 42 } } const fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { - //~^ missing_const_for_fn + //~^ missing_const_for_fn b } } // Could be const const fn one() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 1 } // Could also be const const fn two() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn let abc = 2; abc } // Could be const (since Rust 1.39) const fn string() -> String { -//~^ missing_const_for_fn + //~^ missing_const_for_fn String::new() } // Could be const const unsafe fn four() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 4 } // Could also be const const fn generic(t: T) -> T { -//~^ missing_const_for_fn + //~^ missing_const_for_fn t } @@ -57,7 +57,7 @@ fn sub(x: u32) -> usize { } const fn generic_arr(t: [T; 1]) -> T { -//~^ missing_const_for_fn + //~^ missing_const_for_fn t[0] } @@ -71,7 +71,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub const fn b(self, a: &A) -> B { - //~^ missing_const_for_fn + //~^ missing_const_for_fn B } } @@ -81,7 +81,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. const fn const_fn_stabilized_before_msrv(byte: u8) { - //~^ missing_const_for_fn + //~^ missing_const_for_fn byte.is_ascii_digit(); } } @@ -93,7 +93,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] const fn msrv_1_46() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 46 } @@ -121,12 +121,12 @@ mod msrv { impl Foo { #[clippy::msrv = "1.58"] const fn deref_ptr_can_be_const(self) -> usize { - //~^ missing_const_for_fn + //~^ missing_const_for_fn unsafe { *self.0 as usize } } const fn deref_copied_val(self) -> usize { - //~^ missing_const_for_fn + //~^ missing_const_for_fn *self.1 as usize } } @@ -137,7 +137,7 @@ mod msrv { #[clippy::msrv = "1.56"] const fn union_access_can_be_const() { - //~^ missing_const_for_fn + //~^ missing_const_for_fn let bar = Bar { val: 1 }; let _ = unsafe { bar.val }; } @@ -167,13 +167,13 @@ mod issue12677 { impl Wrapper { #[must_use] pub const fn new(strings: Vec) -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { strings } } #[must_use] pub const fn empty() -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { strings: Vec::new() } } } @@ -185,7 +185,7 @@ mod issue12677 { impl Other { pub const fn new(text: String) -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn let vec = Vec::new(); Self { text, vec } } @@ -218,6 +218,6 @@ mod extern_fn { } const fn mut_add(x: &mut i32) { -//~^ missing_const_for_fn + //~^ missing_const_for_fn *x += 1; } 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 f689f9bb7f92..bc44b34daef7 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -11,44 +11,44 @@ struct Game { impl Game { // Could be const pub fn new() -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { guess: 42 } } fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { - //~^ missing_const_for_fn + //~^ missing_const_for_fn b } } // Could be const fn one() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 1 } // Could also be const fn two() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn let abc = 2; abc } // Could be const (since Rust 1.39) fn string() -> String { -//~^ missing_const_for_fn + //~^ missing_const_for_fn String::new() } // Could be const unsafe fn four() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 4 } // Could also be const fn generic(t: T) -> T { -//~^ missing_const_for_fn + //~^ missing_const_for_fn t } @@ -57,7 +57,7 @@ fn sub(x: u32) -> usize { } fn generic_arr(t: [T; 1]) -> T { -//~^ missing_const_for_fn + //~^ missing_const_for_fn t[0] } @@ -71,7 +71,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub fn b(self, a: &A) -> B { - //~^ missing_const_for_fn + //~^ missing_const_for_fn B } } @@ -81,7 +81,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) { - //~^ missing_const_for_fn + //~^ missing_const_for_fn byte.is_ascii_digit(); } } @@ -93,7 +93,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] fn msrv_1_46() -> i32 { -//~^ missing_const_for_fn + //~^ missing_const_for_fn 46 } @@ -121,12 +121,12 @@ mod msrv { impl Foo { #[clippy::msrv = "1.58"] fn deref_ptr_can_be_const(self) -> usize { - //~^ missing_const_for_fn + //~^ missing_const_for_fn unsafe { *self.0 as usize } } fn deref_copied_val(self) -> usize { - //~^ missing_const_for_fn + //~^ missing_const_for_fn *self.1 as usize } } @@ -137,7 +137,7 @@ mod msrv { #[clippy::msrv = "1.56"] fn union_access_can_be_const() { - //~^ missing_const_for_fn + //~^ missing_const_for_fn let bar = Bar { val: 1 }; let _ = unsafe { bar.val }; } @@ -167,13 +167,13 @@ mod issue12677 { impl Wrapper { #[must_use] pub fn new(strings: Vec) -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { strings } } #[must_use] pub fn empty() -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn Self { strings: Vec::new() } } } @@ -185,7 +185,7 @@ mod issue12677 { impl Other { pub fn new(text: String) -> Self { - //~^ missing_const_for_fn + //~^ missing_const_for_fn let vec = Vec::new(); Self { text, vec } } @@ -218,6 +218,6 @@ mod extern_fn { } fn mut_add(x: &mut i32) { -//~^ missing_const_for_fn + //~^ missing_const_for_fn *x += 1; } diff --git a/tests/ui/missing_const_for_thread_local.fixed b/tests/ui/missing_const_for_thread_local.fixed index 281d7a6c9da3..2efe10c153da 100644 --- a/tests/ui/missing_const_for_thread_local.fixed +++ b/tests/ui/missing_const_for_thread_local.fixed @@ -9,7 +9,6 @@ fn main() { //~^ missing_const_for_thread_local } - // don't lint thread_local! { static BUF_2: RefCell = const { RefCell::new(String::new()) }; @@ -20,7 +19,6 @@ fn main() { //~^ missing_const_for_thread_local } - // lint and suggest const for all non const items thread_local! { static BUF_3_CAN_BE_MADE_CONST: RefCell = const { RefCell::new(String::new()) }; @@ -30,8 +28,6 @@ fn main() { //~^ missing_const_for_thread_local } - - thread_local! { static PEEL_ME: i32 = const { 1 }; //~^ missing_const_for_thread_local diff --git a/tests/ui/missing_const_for_thread_local.rs b/tests/ui/missing_const_for_thread_local.rs index 07239e5fa617..119cc5a99fa0 100644 --- a/tests/ui/missing_const_for_thread_local.rs +++ b/tests/ui/missing_const_for_thread_local.rs @@ -9,7 +9,6 @@ fn main() { //~^ missing_const_for_thread_local } - // don't lint thread_local! { static BUF_2: RefCell = const { RefCell::new(String::new()) }; @@ -20,7 +19,6 @@ fn main() { //~^ missing_const_for_thread_local } - // lint and suggest const for all non const items thread_local! { static BUF_3_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); @@ -30,8 +28,6 @@ fn main() { //~^ missing_const_for_thread_local } - - thread_local! { static PEEL_ME: i32 = { 1 }; //~^ missing_const_for_thread_local diff --git a/tests/ui/missing_const_for_thread_local.stderr b/tests/ui/missing_const_for_thread_local.stderr index 76104a3761eb..4e90c10c92f8 100644 --- a/tests/ui/missing_const_for_thread_local.stderr +++ b/tests/ui/missing_const_for_thread_local.stderr @@ -8,31 +8,31 @@ LL | static BUF_1: RefCell = RefCell::new(String::new()); = help: to override `-D warnings` add `#[allow(clippy::missing_const_for_thread_local)]` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:19:29 + --> tests/ui/missing_const_for_thread_local.rs:18:29 | LL | static SIMPLE:i32 = 1; | ^ help: replace with: `const { 1 }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:26:59 + --> tests/ui/missing_const_for_thread_local.rs:24:59 | LL | static BUF_3_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { RefCell::new(String::new()) }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:29:59 + --> tests/ui/missing_const_for_thread_local.rs:27:59 | LL | static BUF_4_CAN_BE_MADE_CONST: RefCell = RefCell::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { RefCell::new(String::new()) }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:36:31 + --> tests/ui/missing_const_for_thread_local.rs:32:31 | LL | static PEEL_ME: i32 = { 1 }; | ^^^^^ help: replace with: `const { 1 }` error: initializer for `thread_local` value can be made `const` - --> tests/ui/missing_const_for_thread_local.rs:39:36 + --> tests/ui/missing_const_for_thread_local.rs:35:36 | LL | static PEEL_ME_MANY: i32 = { let x = 1; x * x }; | ^^^^^^^^^^^^^^^^^^^^ help: replace with: `const { { let x = 1; x * x } }` diff --git a/tests/ui/missing_doc.rs b/tests/ui/missing_doc.rs index 301c46e0f1b9..705de959cb7d 100644 --- a/tests/ui/missing_doc.rs +++ b/tests/ui/missing_doc.rs @@ -43,7 +43,7 @@ mod a { } enum Baz { -//~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items BazA { a: isize, b: isize }, //~^ missing_docs_in_private_items //~| missing_docs_in_private_items @@ -94,7 +94,7 @@ pub static BAR3: u32 = 0; pub static BAR4: u32 = 0; mod internal_impl { -//~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items /// dox pub fn documented() {} pub fn undocumented1() {} @@ -133,7 +133,7 @@ with_span!(span pub const FOO2_PM: u32 = 0;); const _: () = (); fn issue13298() { -//~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items // Rustdoc doesn't generate documentation for items within other items like fns or consts const MSG: &str = "Hello, world!"; } diff --git a/tests/ui/missing_doc_crate_missing.rs b/tests/ui/missing_doc_crate_missing.rs index 70e96f4dd547..f55d8b67cb84 100644 --- a/tests/ui/missing_doc_crate_missing.rs +++ b/tests/ui/missing_doc_crate_missing.rs @@ -1,6 +1,4 @@ #![warn(clippy::missing_docs_in_private_items)] //~^ missing_docs_in_private_items - - fn main() {} diff --git a/tests/ui/missing_doc_impl.rs b/tests/ui/missing_doc_impl.rs index e2d268c4e3bd..034ce31dfe76 100644 --- a/tests/ui/missing_doc_impl.rs +++ b/tests/ui/missing_doc_impl.rs @@ -11,7 +11,7 @@ extern crate proc_macros; use proc_macros::with_span; struct Foo { -//~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items a: isize, //~^ missing_docs_in_private_items b: isize, @@ -69,7 +69,7 @@ pub trait E: Sized { impl Foo { pub fn new() -> Self { - //~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items Foo { a: 0, b: 0 } } fn bar() {} @@ -82,7 +82,7 @@ impl PubFoo { pub fn foo1() {} #[must_use = "yep"] fn foo2() -> u32 { - //~^ missing_docs_in_private_items + //~^ missing_docs_in_private_items 1 } #[allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/missing_fields_in_debug.rs b/tests/ui/missing_fields_in_debug.rs index bf69eae05169..14803b5485a1 100644 --- a/tests/ui/missing_fields_in_debug.rs +++ b/tests/ui/missing_fields_in_debug.rs @@ -12,7 +12,7 @@ struct NamedStruct1Ignored { } impl fmt::Debug for NamedStruct1Ignored { -//~^ missing_fields_in_debug + //~^ missing_fields_in_debug // unused field: hidden fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -32,7 +32,7 @@ struct NamedStructMultipleIgnored { } impl fmt::Debug for NamedStructMultipleIgnored { -//~^ missing_fields_in_debug + //~^ missing_fields_in_debug // unused fields: hidden, hidden2, hidden4 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -95,7 +95,7 @@ struct MultiExprDebugImpl { // ok impl fmt::Debug for MultiExprDebugImpl { -//~^ missing_fields_in_debug + //~^ missing_fields_in_debug fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = formatter.debug_struct("MultiExprDebugImpl"); diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index ec21de4ca41c..c1801005b777 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -20,7 +20,6 @@ fn foo() {} pub fn pub_foo() {} //~^ missing_inline_in_public_items - #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -64,7 +63,6 @@ impl PubBar for PubFoo { // missing #[inline] fn PubBar_c() {} //~^ missing_inline_in_public_items - } // do not need inline because Foo is not exported @@ -77,7 +75,6 @@ impl PubFoo { // missing #[inline] pub fn PubFooImpl() {} //~^ missing_inline_in_public_items - } // 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 2ce335a696ce..99ee828e805c 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -8,31 +8,31 @@ LL | pub fn pub_foo() {} = help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]` error: missing `#[inline]` for a default trait method - --> tests/ui/missing_inline.rs:40:5 + --> tests/ui/missing_inline.rs:39:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:57:5 + --> tests/ui/missing_inline.rs:56:5 | LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:61:5 + --> tests/ui/missing_inline.rs:60:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:65:5 + --> tests/ui/missing_inline.rs:64:5 | LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> tests/ui/missing_inline.rs:78:5 + --> tests/ui/missing_inline.rs:76:5 | LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index f8aeffb3d041..95e361c5d555 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -11,20 +11,20 @@ fn main() {} /// This needs to be documented pub fn unwrap() { -//~^ missing_panics_doc + //~^ missing_panics_doc let result = Err("Hi"); result.unwrap() } /// This needs to be documented pub fn panic() { -//~^ missing_panics_doc + //~^ missing_panics_doc panic!("This function panics") } /// This needs to be documented pub fn inner_body(opt: Option) { -//~^ missing_panics_doc + //~^ missing_panics_doc opt.map(|x| { if x == 10 { panic!() @@ -34,20 +34,20 @@ pub fn inner_body(opt: Option) { /// This needs to be documented pub fn unreachable_and_panic() { -//~^ missing_panics_doc + //~^ missing_panics_doc if true { unreachable!() } else { panic!() } } /// This needs to be documented pub fn assert_eq() { -//~^ missing_panics_doc + //~^ missing_panics_doc let x = 0; assert_eq!(x, 0); } /// This needs to be documented pub fn assert_ne() { -//~^ missing_panics_doc + //~^ missing_panics_doc let x = 0; assert_ne!(x, 0); } @@ -155,36 +155,36 @@ pub fn debug_assertions() { // `pub` is required, because the lint does not consider unreachable items pub mod issue10240 { pub fn option_unwrap(v: &[T]) -> &T { - //~^ missing_panics_doc + //~^ missing_panics_doc let o: Option<&T> = v.last(); o.unwrap() } pub fn option_expect(v: &[T]) -> &T { - //~^ missing_panics_doc + //~^ missing_panics_doc let o: Option<&T> = v.last(); o.expect("passed an empty thing") } pub fn result_unwrap(v: &[T]) -> &T { - //~^ missing_panics_doc + //~^ missing_panics_doc let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.unwrap() } pub fn result_expect(v: &[T]) -> &T { - //~^ missing_panics_doc + //~^ missing_panics_doc let res: Result<&T, &str> = v.last().ok_or("oh noes"); res.expect("passed an empty thing") } pub fn last_unwrap(v: &[u32]) -> u32 { - //~^ missing_panics_doc + //~^ missing_panics_doc *v.last().unwrap() } pub fn last_expect(v: &[u32]) -> u32 { - //~^ missing_panics_doc + //~^ missing_panics_doc *v.last().expect("passed an empty thing") } } diff --git a/tests/ui/missing_trait_methods.rs b/tests/ui/missing_trait_methods.rs index bcca5e1ae5bd..7af186ba3322 100644 --- a/tests/ui/missing_trait_methods.rs +++ b/tests/ui/missing_trait_methods.rs @@ -22,9 +22,8 @@ struct Partial; impl A for Partial {} //~^ missing_trait_methods - impl B for Partial { -//~^ missing_trait_methods + //~^ missing_trait_methods fn required() {} diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index 4af7b9ae1ea9..d9fb8951ab3d 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -13,7 +13,7 @@ LL | fn provided() {} = help: to override `-D warnings` add `#[allow(clippy::missing_trait_methods)]` error: missing trait method provided by default: `b` - --> tests/ui/missing_trait_methods.rs:26:1 + --> tests/ui/missing_trait_methods.rs:25:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,19 @@ LL | fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing trait method provided by default: `one` - --> tests/ui/missing_trait_methods.rs:60:1 + --> tests/ui/missing_trait_methods.rs:59:1 + | +LL | impl MissingMultiple for Partial {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: implement the method + --> tests/ui/missing_trait_methods.rs:54:5 + | +LL | fn one() {} + | ^^^^^^^^ + +error: missing trait method provided by default: `two` + --> tests/ui/missing_trait_methods.rs:59:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,11 +45,11 @@ LL | impl MissingMultiple for Partial {} help: implement the method --> tests/ui/missing_trait_methods.rs:55:5 | -LL | fn one() {} +LL | fn two() {} | ^^^^^^^^ -error: missing trait method provided by default: `two` - --> tests/ui/missing_trait_methods.rs:60:1 +error: missing trait method provided by default: `three` + --> tests/ui/missing_trait_methods.rs:59:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,18 +57,6 @@ LL | impl MissingMultiple for Partial {} help: implement the method --> tests/ui/missing_trait_methods.rs:56:5 | -LL | fn two() {} - | ^^^^^^^^ - -error: missing trait method provided by default: `three` - --> tests/ui/missing_trait_methods.rs:60:1 - | -LL | impl MissingMultiple for Partial {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: implement the method - --> tests/ui/missing_trait_methods.rs:57:5 - | LL | fn three() {} | ^^^^^^^^^^ diff --git a/tests/ui/mixed_read_write_in_expression.rs b/tests/ui/mixed_read_write_in_expression.rs index cff7996243bb..2ead166bf801 100644 --- a/tests/ui/mixed_read_write_in_expression.rs +++ b/tests/ui/mixed_read_write_in_expression.rs @@ -14,10 +14,9 @@ fn main() { } + x; //~^ mixed_read_write_in_expression - // Example from iss#277 x += { - //~^ mixed_read_write_in_expression + //~^ mixed_read_write_in_expression x = 20; 2 @@ -33,7 +32,6 @@ fn main() { let foo = Foo { a: x, //~^ mixed_read_write_in_expression - ..{ x = 6; base @@ -43,7 +41,7 @@ fn main() { let closure = || { let mut x = 0; x += { - //~^ mixed_read_write_in_expression + //~^ mixed_read_write_in_expression x = 20; 2 diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index ebb3e691e6b7..e34dce2bb132 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -13,37 +13,37 @@ LL | x = 1; = help: to override `-D warnings` add `#[allow(clippy::mixed_read_write_in_expression)]` error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:19:5 + --> tests/ui/mixed_read_write_in_expression.rs:18:5 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:22:9 + --> tests/ui/mixed_read_write_in_expression.rs:21:9 | LL | x = 20; | ^^^^^^ error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:34:12 + --> tests/ui/mixed_read_write_in_expression.rs:33:12 | LL | a: x, | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:38:13 + --> tests/ui/mixed_read_write_in_expression.rs:36:13 | LL | x = 6; | ^^^^^ error: unsequenced read of `x` - --> tests/ui/mixed_read_write_in_expression.rs:45:9 + --> tests/ui/mixed_read_write_in_expression.rs:43:9 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> tests/ui/mixed_read_write_in_expression.rs:48:13 + --> tests/ui/mixed_read_write_in_expression.rs:46:13 | LL | x = 20; | ^^^^^^ diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index f04f0c5eeeba..15b7fb877770 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -3,15 +3,14 @@ pub mod foo2 { pub mod bar2 { pub mod bar2 { - //~^ module_inception - + //~^ module_inception pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { - //~^ module_inception + //~^ module_inception pub mod bar2 {} } @@ -20,14 +19,14 @@ pub mod foo2 { mod foo { mod bar { mod bar { - //~^ module_inception + //~^ module_inception mod foo {} } mod foo {} } mod foo { - //~^ module_inception + //~^ module_inception mod bar {} } diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index 3aaf304ac0e5..8e7d555cebc6 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -2,7 +2,9 @@ error: module has the same name as its containing module --> tests/ui/module_inception.rs:5:9 | LL | / pub mod bar2 { -... | +LL | | +LL | | +LL | | pub mod foo2 {} LL | | } | |_________^ | @@ -10,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module - --> tests/ui/module_inception.rs:13:5 + --> tests/ui/module_inception.rs:12:5 | LL | / pub mod foo2 { LL | | @@ -20,7 +22,7 @@ LL | | } | |_____^ error: module has the same name as its containing module - --> tests/ui/module_inception.rs:22:9 + --> tests/ui/module_inception.rs:21:9 | LL | / mod bar { LL | | @@ -30,7 +32,7 @@ LL | | } | |_________^ error: module has the same name as its containing module - --> tests/ui/module_inception.rs:29:5 + --> tests/ui/module_inception.rs:28:5 | LL | / mod foo { LL | | diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index b45120a8d10c..2fde98d7927c 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -8,7 +8,6 @@ pub mod foo { pub fn foo_bar() {} //~^ module_name_repetitions - pub fn bar_foo() {} //~^ module_name_repetitions @@ -21,7 +20,6 @@ pub mod foo { pub struct Foo7Bar; //~^ module_name_repetitions - // Should not warn pub struct Foobar; @@ -35,7 +33,6 @@ pub mod foo { pub use error::FooError; //~^ module_name_repetitions - // FIXME: This should also warn because it creates the public path `foo::FooIter`. mod iter { pub struct FooIter; diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index 664a816ae5d1..9000c44a3902 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -8,31 +8,31 @@ LL | pub fn foo_bar() {} = help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` error: item name ends with its containing module's name - --> tests/ui/module_name_repetitions.rs:12:12 + --> tests/ui/module_name_repetitions.rs:11:12 | LL | pub fn bar_foo() {} | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:15:16 + --> tests/ui/module_name_repetitions.rs:14:16 | LL | pub struct FooCake; | ^^^^^^^ error: item name ends with its containing module's name - --> tests/ui/module_name_repetitions.rs:18:14 + --> tests/ui/module_name_repetitions.rs:17:14 | LL | pub enum CakeFoo {} | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:21:16 + --> tests/ui/module_name_repetitions.rs:20:16 | LL | pub struct Foo7Bar; | ^^^^^^^ error: item name starts with its containing module's name - --> tests/ui/module_name_repetitions.rs:35:20 + --> tests/ui/module_name_repetitions.rs:33:20 | LL | pub use error::FooError; | ^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs index 1b622151bcc2..0e08174f686e 100644 --- a/tests/ui/modulo_arithmetic_float.rs +++ b/tests/ui/modulo_arithmetic_float.rs @@ -8,82 +8,61 @@ fn main() { -1.6 % 2.1; //~^ modulo_arithmetic - 1.6 % -2.1; //~^ modulo_arithmetic - (1.1 - 2.3) % (1.1 + 2.3); //~^ modulo_arithmetic - (1.1 + 2.3) % (1.1 - 2.3); //~^ modulo_arithmetic - - // Lint on floating point numbers let a_f16: f16 = -1.6; let mut b_f16: f16 = 2.1; a_f16 % b_f16; //~^ modulo_arithmetic - b_f16 % a_f16; //~^ modulo_arithmetic - b_f16 %= a_f16; //~^ modulo_arithmetic - - // Lint on floating point numbers let a_f32: f32 = -1.6; let mut b_f32: f32 = 2.1; a_f32 % b_f32; //~^ modulo_arithmetic - b_f32 % a_f32; //~^ modulo_arithmetic - b_f32 %= a_f32; //~^ modulo_arithmetic - - let a_f64: f64 = -1.6; let mut b_f64: f64 = 2.1; a_f64 % b_f64; //~^ modulo_arithmetic - b_f64 % a_f64; //~^ modulo_arithmetic - b_f64 %= a_f64; //~^ modulo_arithmetic - - let a_f128: f128 = -1.6; let mut b_f128: f128 = 2.1; a_f128 % b_f128; //~^ modulo_arithmetic - b_f128 % a_f128; //~^ modulo_arithmetic - b_f128 %= a_f128; //~^ modulo_arithmetic - - // No lint when both sides are const and of the same sign 1.6 % 2.1; -1.6 % -2.1; diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index 9eb9a328664b..91b5c80ce9f4 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -9,7 +9,7 @@ LL | -1.6 % 2.1; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> tests/ui/modulo_arithmetic_float.rs:12:5 + --> tests/ui/modulo_arithmetic_float.rs:11:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -17,7 +17,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` - --> tests/ui/modulo_arithmetic_float.rs:16:5 + --> tests/ui/modulo_arithmetic_float.rs:14:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,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` - --> tests/ui/modulo_arithmetic_float.rs:20:5 + --> tests/ui/modulo_arithmetic_float.rs:17:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/modulo_arithmetic_float.rs:28:5 + --> tests/ui/modulo_arithmetic_float.rs:23:5 | LL | a_f16 % b_f16; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | a_f16 % b_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:32:5 + --> tests/ui/modulo_arithmetic_float.rs:26:5 | LL | b_f16 % a_f16; | ^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | b_f16 % a_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:36:5 + --> tests/ui/modulo_arithmetic_float.rs:29:5 | LL | b_f16 %= a_f16; | ^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | b_f16 %= a_f16; = 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 - --> tests/ui/modulo_arithmetic_float.rs:44:5 + --> tests/ui/modulo_arithmetic_float.rs:35:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/modulo_arithmetic_float.rs:48:5 + --> tests/ui/modulo_arithmetic_float.rs:38:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/modulo_arithmetic_float.rs:52:5 + --> tests/ui/modulo_arithmetic_float.rs:41:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -81,7 +81,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 - --> tests/ui/modulo_arithmetic_float.rs:59:5 + --> tests/ui/modulo_arithmetic_float.rs:46:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -89,7 +89,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 - --> tests/ui/modulo_arithmetic_float.rs:63:5 + --> tests/ui/modulo_arithmetic_float.rs:49:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -97,7 +97,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 - --> tests/ui/modulo_arithmetic_float.rs:67:5 + --> tests/ui/modulo_arithmetic_float.rs:52:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ @@ -105,7 +105,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 - --> tests/ui/modulo_arithmetic_float.rs:74:5 + --> tests/ui/modulo_arithmetic_float.rs:57:5 | LL | a_f128 % b_f128; | ^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ LL | a_f128 % b_f128; = 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 - --> tests/ui/modulo_arithmetic_float.rs:78:5 + --> tests/ui/modulo_arithmetic_float.rs:60:5 | LL | b_f128 % a_f128; | ^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | b_f128 % a_f128; = 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 - --> tests/ui/modulo_arithmetic_float.rs:82:5 + --> tests/ui/modulo_arithmetic_float.rs:63:5 | LL | b_f128 %= a_f128; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral.rs b/tests/ui/modulo_arithmetic_integral.rs index e3a6df7c88f3..d7cd910e43cb 100644 --- a/tests/ui/modulo_arithmetic_integral.rs +++ b/tests/ui/modulo_arithmetic_integral.rs @@ -8,93 +8,68 @@ fn main() { a % b; //~^ modulo_arithmetic - b % a; //~^ modulo_arithmetic - b %= a; //~^ modulo_arithmetic - - let a_i8: i8 = 1; let mut b_i8: i8 = 2; a_i8 % b_i8; //~^ modulo_arithmetic - b_i8 %= a_i8; //~^ modulo_arithmetic - - let a_i16: i16 = 1; let mut b_i16: i16 = 2; a_i16 % b_i16; //~^ modulo_arithmetic - b_i16 %= a_i16; //~^ modulo_arithmetic - - let a_i32: i32 = 1; let mut b_i32: i32 = 2; a_i32 % b_i32; //~^ modulo_arithmetic - b_i32 %= a_i32; //~^ modulo_arithmetic - - let a_i64: i64 = 1; let mut b_i64: i64 = 2; a_i64 % b_i64; //~^ modulo_arithmetic - b_i64 %= a_i64; //~^ modulo_arithmetic - - let a_i128: i128 = 1; let mut b_i128: i128 = 2; a_i128 % b_i128; //~^ modulo_arithmetic - b_i128 %= a_i128; //~^ modulo_arithmetic - - let a_isize: isize = 1; let mut b_isize: isize = 2; a_isize % b_isize; //~^ modulo_arithmetic - b_isize %= a_isize; //~^ modulo_arithmetic - - let a = 1; let mut b = 2; a % b; //~^ modulo_arithmetic - b %= a; //~^ modulo_arithmetic - - // No lint on unsigned integral value let a_u8: u8 = 17; let b_u8: u8 = 3; diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr index 32cf45240c1b..d1b71cdab5e4 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -10,7 +10,7 @@ LL | a % b; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on types that might have different signs - --> tests/ui/modulo_arithmetic_integral.rs:12:5 + --> tests/ui/modulo_arithmetic_integral.rs:11:5 | LL | b % a; | ^^^^^ @@ -19,7 +19,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 - --> tests/ui/modulo_arithmetic_integral.rs:16:5 + --> tests/ui/modulo_arithmetic_integral.rs:14:5 | LL | b %= a; | ^^^^^^ @@ -28,7 +28,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 - --> tests/ui/modulo_arithmetic_integral.rs:23:5 + --> tests/ui/modulo_arithmetic_integral.rs:19:5 | LL | a_i8 % b_i8; | ^^^^^^^^^^^ @@ -37,7 +37,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 - --> tests/ui/modulo_arithmetic_integral.rs:27:5 + --> tests/ui/modulo_arithmetic_integral.rs:22:5 | LL | b_i8 %= a_i8; | ^^^^^^^^^^^^ @@ -46,7 +46,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 - --> tests/ui/modulo_arithmetic_integral.rs:34:5 + --> tests/ui/modulo_arithmetic_integral.rs:27:5 | LL | a_i16 % b_i16; | ^^^^^^^^^^^^^ @@ -55,7 +55,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 - --> tests/ui/modulo_arithmetic_integral.rs:38:5 + --> tests/ui/modulo_arithmetic_integral.rs:30:5 | LL | b_i16 %= a_i16; | ^^^^^^^^^^^^^^ @@ -64,7 +64,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 - --> tests/ui/modulo_arithmetic_integral.rs:45:5 + --> tests/ui/modulo_arithmetic_integral.rs:35:5 | LL | a_i32 % b_i32; | ^^^^^^^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/modulo_arithmetic_integral.rs:49:5 + --> tests/ui/modulo_arithmetic_integral.rs:38:5 | LL | b_i32 %= a_i32; | ^^^^^^^^^^^^^^ @@ -82,7 +82,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 - --> tests/ui/modulo_arithmetic_integral.rs:56:5 + --> tests/ui/modulo_arithmetic_integral.rs:43:5 | LL | a_i64 % b_i64; | ^^^^^^^^^^^^^ @@ -91,7 +91,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 - --> tests/ui/modulo_arithmetic_integral.rs:60:5 + --> tests/ui/modulo_arithmetic_integral.rs:46:5 | LL | b_i64 %= a_i64; | ^^^^^^^^^^^^^^ @@ -100,7 +100,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 - --> tests/ui/modulo_arithmetic_integral.rs:67:5 + --> tests/ui/modulo_arithmetic_integral.rs:51:5 | LL | a_i128 % b_i128; | ^^^^^^^^^^^^^^^ @@ -109,7 +109,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 - --> tests/ui/modulo_arithmetic_integral.rs:71:5 + --> tests/ui/modulo_arithmetic_integral.rs:54:5 | LL | b_i128 %= a_i128; | ^^^^^^^^^^^^^^^^ @@ -118,7 +118,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 - --> tests/ui/modulo_arithmetic_integral.rs:78:5 + --> tests/ui/modulo_arithmetic_integral.rs:59:5 | LL | a_isize % b_isize; | ^^^^^^^^^^^^^^^^^ @@ -127,7 +127,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 - --> tests/ui/modulo_arithmetic_integral.rs:82:5 + --> tests/ui/modulo_arithmetic_integral.rs:62:5 | LL | b_isize %= a_isize; | ^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,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 - --> tests/ui/modulo_arithmetic_integral.rs:89:5 + --> tests/ui/modulo_arithmetic_integral.rs:67:5 | LL | a % b; | ^^^^^ @@ -145,7 +145,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 - --> tests/ui/modulo_arithmetic_integral.rs:93:5 + --> tests/ui/modulo_arithmetic_integral.rs:70:5 | LL | b %= a; | ^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral_const.rs b/tests/ui/modulo_arithmetic_integral_const.rs index ddcf4b219073..9f5fb697df0e 100644 --- a/tests/ui/modulo_arithmetic_integral_const.rs +++ b/tests/ui/modulo_arithmetic_integral_const.rs @@ -11,73 +11,54 @@ fn main() { -1 % 2; //~^ modulo_arithmetic - 1 % -2; //~^ modulo_arithmetic - (1 - 2) % (1 + 2); //~^ modulo_arithmetic - (1 + 2) % (1 - 2); //~^ modulo_arithmetic - 35 * (7 - 4 * 2) % (-500 * -600); //~^ modulo_arithmetic - - -1i8 % 2i8; //~^ modulo_arithmetic - 1i8 % -2i8; //~^ modulo_arithmetic - -1i16 % 2i16; //~^ modulo_arithmetic - 1i16 % -2i16; //~^ modulo_arithmetic - -1i32 % 2i32; //~^ modulo_arithmetic - 1i32 % -2i32; //~^ modulo_arithmetic - -1i64 % 2i64; //~^ modulo_arithmetic - 1i64 % -2i64; //~^ modulo_arithmetic - -1i128 % 2i128; //~^ modulo_arithmetic - 1i128 % -2i128; //~^ modulo_arithmetic - -1isize % 2isize; //~^ modulo_arithmetic - 1isize % -2isize; //~^ modulo_arithmetic - - // No lint when both sides are const and of the same sign 1 % 2; -1 % -2; diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr index 49a5a2c6433a..12edee8cf425 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -10,7 +10,7 @@ LL | -1 % 2; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1 % -2` - --> tests/ui/modulo_arithmetic_integral_const.rs:15:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:14:5 | LL | 1 % -2; | ^^^^^^ @@ -19,7 +19,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:19:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:17:5 | LL | (1 - 2) % (1 + 2); | ^^^^^^^^^^^^^^^^^ @@ -28,7 +28,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:23:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:20:5 | LL | (1 + 2) % (1 - 2); | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:27:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:23:5 | LL | 35 * (7 - 4 * 2) % (-500 * -600); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:32:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:26:5 | LL | -1i8 % 2i8; | ^^^^^^^^^^ @@ -55,7 +55,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:36:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:29:5 | LL | 1i8 % -2i8; | ^^^^^^^^^^ @@ -64,7 +64,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:40:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:32:5 | LL | -1i16 % 2i16; | ^^^^^^^^^^^^ @@ -73,7 +73,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:44:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:35:5 | LL | 1i16 % -2i16; | ^^^^^^^^^^^^ @@ -82,7 +82,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:48:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:38:5 | LL | -1i32 % 2i32; | ^^^^^^^^^^^^ @@ -91,7 +91,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:52:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:41:5 | LL | 1i32 % -2i32; | ^^^^^^^^^^^^ @@ -100,7 +100,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:56:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:44:5 | LL | -1i64 % 2i64; | ^^^^^^^^^^^^ @@ -109,7 +109,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:60:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:47:5 | LL | 1i64 % -2i64; | ^^^^^^^^^^^^ @@ -118,7 +118,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:64:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:50:5 | LL | -1i128 % 2i128; | ^^^^^^^^^^^^^^ @@ -127,7 +127,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:68:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:53:5 | LL | 1i128 % -2i128; | ^^^^^^^^^^^^^^ @@ -136,7 +136,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:72:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:56:5 | LL | -1isize % 2isize; | ^^^^^^^^^^^^^^^^ @@ -145,7 +145,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` - --> tests/ui/modulo_arithmetic_integral_const.rs:76:5 + --> tests/ui/modulo_arithmetic_integral_const.rs:59:5 | LL | 1isize % -2isize; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index 6ad038e60744..63ae61059cb8 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -9,7 +9,6 @@ fn main() { 10 % 1; //~^ modulo_one - 10 % -1; //~^ modulo_one diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 1eb886123d85..1c9c79d1c621 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -8,31 +8,31 @@ LL | 10 % 1; = help: to override `-D warnings` add `#[allow(clippy::modulo_one)]` error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:13:5 + --> tests/ui/modulo_one.rs:12:5 | LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:18:5 + --> tests/ui/modulo_one.rs:17:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> tests/ui/modulo_one.rs:25:5 + --> tests/ui/modulo_one.rs:24:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:30:5 + --> tests/ui/modulo_one.rs:29:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> tests/ui/modulo_one.rs:36:5 + --> tests/ui/modulo_one.rs:35:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/multi_assignments.rs b/tests/ui/multi_assignments.rs index 651cdc5773de..5a0d9a7aa37c 100644 --- a/tests/ui/multi_assignments.rs +++ b/tests/ui/multi_assignments.rs @@ -4,12 +4,10 @@ fn main() { a = b = c; //~^ multi_assignments - a = b = c = d; //~^ multi_assignments //~| multi_assignments - a = b = { c }; //~^ multi_assignments @@ -18,5 +16,4 @@ fn main() { a = (b = c); //~^ multi_assignments - } diff --git a/tests/ui/multi_assignments.stderr b/tests/ui/multi_assignments.stderr index 3c5bbcdea5f3..f56489c0b4b7 100644 --- a/tests/ui/multi_assignments.stderr +++ b/tests/ui/multi_assignments.stderr @@ -8,31 +8,31 @@ LL | a = b = c; = help: to override `-D warnings` add `#[allow(clippy::multi_assignments)]` error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:8:5 + --> tests/ui/multi_assignments.rs:7:5 | LL | a = b = c = d; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:8:9 + --> tests/ui/multi_assignments.rs:7:9 | LL | a = b = c = d; | ^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:13:5 + --> tests/ui/multi_assignments.rs:11:5 | LL | a = b = { c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:16:5 + --> tests/ui/multi_assignments.rs:14:5 | LL | a = { b = c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> tests/ui/multi_assignments.rs:19:5 + --> tests/ui/multi_assignments.rs:17:5 | LL | a = (b = c); | ^^^^^^^^^^^ diff --git a/tests/ui/multiple_bound_locations.rs b/tests/ui/multiple_bound_locations.rs index 45524c90b7f2..95b269d8935d 100644 --- a/tests/ui/multiple_bound_locations.rs +++ b/tests/ui/multiple_bound_locations.rs @@ -2,7 +2,6 @@ fn ty(a: F) //~^ multiple_bound_locations - where F: Sized, { @@ -10,7 +9,6 @@ where fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) //~^ multiple_bound_locations - where 'b: 'c, { @@ -18,7 +16,6 @@ where fn ty_pred() //~^ multiple_bound_locations - where for<'a> F: Send + 'a, { @@ -29,7 +26,6 @@ struct B; impl B { fn ty(a: F) //~^ multiple_bound_locations - where F: Sized, { @@ -37,7 +33,6 @@ impl B { fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) //~^ multiple_bound_locations - where 'b: 'c, { @@ -45,7 +40,6 @@ impl B { fn ty_pred() //~^ multiple_bound_locations - where for<'a> F: Send + 'a, { diff --git a/tests/ui/multiple_bound_locations.stderr b/tests/ui/multiple_bound_locations.stderr index bccc57fe7054..22dd2e0a5524 100644 --- a/tests/ui/multiple_bound_locations.stderr +++ b/tests/ui/multiple_bound_locations.stderr @@ -11,7 +11,7 @@ LL | F: Sized, = help: to override `-D warnings` add `#[allow(clippy::multiple_bound_locations)]` error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:11:17 + --> tests/ui/multiple_bound_locations.rs:10:17 | LL | fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) | ^^ @@ -20,7 +20,7 @@ LL | 'b: 'c, | ^^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:19:12 + --> tests/ui/multiple_bound_locations.rs:17:12 | LL | fn ty_pred() | ^ @@ -29,7 +29,7 @@ LL | for<'a> F: Send + 'a, | ^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:30:11 + --> tests/ui/multiple_bound_locations.rs:27:11 | LL | fn ty(a: F) | ^ @@ -38,7 +38,7 @@ LL | F: Sized, | ^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:38:21 + --> tests/ui/multiple_bound_locations.rs:34:21 | LL | fn lifetime<'a, 'b: 'a, 'c>(a: &'b str, b: &'a str, c: &'c str) | ^^ @@ -47,7 +47,7 @@ LL | 'b: 'c, | ^^ error: bound is defined in more than one place - --> tests/ui/multiple_bound_locations.rs:46:16 + --> tests/ui/multiple_bound_locations.rs:41:16 | LL | fn ty_pred() | ^ diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index cc5d455f78cf..016fd89a7b7a 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -36,7 +36,7 @@ static mut STATIC: i32 = 0; fn test1() { unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block STATIC += 1; not_very_safe(); } @@ -46,7 +46,7 @@ fn test2() { let u = U { i: 0 }; unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block drop(u.u); *raw_ptr(); } @@ -54,7 +54,7 @@ fn test2() { fn test3() { unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block asm!("nop"); sample.not_very_safe(); STATIC = 0; @@ -64,7 +64,7 @@ fn test3() { fn test_all() { let u = U { i: 0 }; unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block drop(u.u); drop(STATIC); sample.not_very_safe(); @@ -128,7 +128,7 @@ fn issue10259() { fn _fn_ptr(x: unsafe fn()) { unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block x(); x(); } @@ -140,7 +140,7 @@ fn _assoc_const() { } fn _f() { unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block T::X(); T::X(); } @@ -151,7 +151,7 @@ fn _field_fn_ptr(x: unsafe fn()) { struct X(unsafe fn()); let x = X(x); unsafe { - //~^ multiple_unsafe_ops_per_block + //~^ multiple_unsafe_ops_per_block x.0(); x.0(); } diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 7c70c7f6399f..b5d356a50217 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -14,13 +14,13 @@ pub struct MyAtomic(AtomicBool); pub struct MyPure; #[must_use] pub fn pure(i: u8) -> u8 { -//~^ must_use_candidate + //~^ must_use_candidate i } impl MyPure { #[must_use] pub fn inherent_pure(&self) -> u8 { - //~^ must_use_candidate + //~^ must_use_candidate 0 } } @@ -52,7 +52,7 @@ pub fn with_callback bool>(f: &F) -> bool { } #[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate true } @@ -65,7 +65,7 @@ pub fn atomics(b: &AtomicBool) -> bool { } #[must_use] pub fn rcd(_x: Rc) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate true } @@ -74,7 +74,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { } #[must_use] pub fn arcd(_x: Arc) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate false } diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index a422e952dbcd..14ea16662fdb 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -14,13 +14,13 @@ pub struct MyAtomic(AtomicBool); pub struct MyPure; pub fn pure(i: u8) -> u8 { -//~^ must_use_candidate + //~^ must_use_candidate i } impl MyPure { pub fn inherent_pure(&self) -> u8 { - //~^ must_use_candidate + //~^ must_use_candidate 0 } } @@ -52,7 +52,7 @@ pub fn with_callback bool>(f: &F) -> bool { } pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate true } @@ -65,7 +65,7 @@ pub fn atomics(b: &AtomicBool) -> bool { } pub fn rcd(_x: Rc) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate true } @@ -74,7 +74,7 @@ pub fn rcmut(_x: Rc<&mut u32>) -> bool { } pub fn arcd(_x: Arc) -> bool { -//~^ must_use_candidate + //~^ must_use_candidate false } diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index d2d82135d641..b8c10f3eeb8f 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -5,7 +5,7 @@ struct Foo; impl Foo { fn this_wont_hurt_a_bit(&self) -> &mut Foo { - //~^ mut_from_ref + //~^ mut_from_ref unsafe { unimplemented!() } } @@ -14,7 +14,6 @@ impl Foo { trait Ouch { fn ouch(x: &Foo) -> &mut Foo; //~^ mut_from_ref - } impl Ouch for Foo { @@ -24,19 +23,19 @@ impl Ouch for Foo { } fn fail(x: &u32) -> &mut u16 { -//~^ mut_from_ref + //~^ mut_from_ref unsafe { unimplemented!() } } fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { -//~^ mut_from_ref + //~^ mut_from_ref unsafe { unimplemented!() } } fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { -//~^ mut_from_ref + //~^ mut_from_ref unsafe { unimplemented!() } } @@ -52,7 +51,7 @@ fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 { } unsafe fn also_broken(x: &u32) -> &mut u32 { -//~^ mut_from_ref + //~^ mut_from_ref unimplemented!() } diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index 593e7acdaed8..8c3c8e0c3d85 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -25,49 +25,49 @@ LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:26:21 + --> tests/ui/mut_from_ref.rs:25:21 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:26:12 + --> tests/ui/mut_from_ref.rs:25:12 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:32:50 + --> tests/ui/mut_from_ref.rs:31:50 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:32:25 + --> tests/ui/mut_from_ref.rs:31:25 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^ error: mutable borrow from immutable input(s) - --> tests/ui/mut_from_ref.rs:38:67 + --> tests/ui/mut_from_ref.rs:37:67 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:38:27 + --> tests/ui/mut_from_ref.rs:37: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) - --> tests/ui/mut_from_ref.rs:54:35 + --> tests/ui/mut_from_ref.rs:53:35 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^^^^^ | note: immutable borrow here - --> tests/ui/mut_from_ref.rs:54:26 + --> tests/ui/mut_from_ref.rs:53: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 55b7fe2bcca0..29dc2d020132 100644 --- a/tests/ui/mut_key.rs +++ b/tests/ui/mut_key.rs @@ -29,10 +29,8 @@ impl Hash for Key { } fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { -//~^ mutable_key_type -//~| mutable_key_type - - + //~^ mutable_key_type + //~| mutable_key_type let _other: HashMap = HashMap::new(); //~^ mutable_key_type @@ -66,7 +64,6 @@ fn tuples(_m: &mut HashMap<((), U), ()>) {} fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} //~^ mutable_key_type - fn main() { let _ = should_not_take_this_arg(&mut HashMap::new(), 1); this_is_ok(&mut HashMap::new()); @@ -112,7 +109,6 @@ fn main() { let _map = HashMap::>, usize>::new(); //~^ mutable_key_type - // Not interior mutability let _map = HashMap::<&mut usize, usize>::new(); let _map = HashMap::, usize>::new(); diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index 1887604b080a..0d504584fbae 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -21,7 +21,7 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:37:5 + --> tests/ui/mut_key.rs:35:5 | LL | let _other: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | let _other: HashMap = HashMap::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:66:22 + --> tests/ui/mut_key.rs:64:22 | LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:80:5 + --> tests/ui/mut_key.rs:77:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL | let _map = HashMap::, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:83:5 + --> tests/ui/mut_key.rs:80:5 | LL | let _map = HashMap::<&mut Cell, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _map = HashMap::<&mut Cell, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:87:5 + --> tests/ui/mut_key.rs:84:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:90:5 + --> tests/ui/mut_key.rs:87:5 | LL | let _map = HashMap::, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _map = HashMap::, ()>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:93:5 + --> tests/ui/mut_key.rs:90:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:96:5 + --> tests/ui/mut_key.rs:93:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:99:5 + --> tests/ui/mut_key.rs:96:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:102:5 + --> tests/ui/mut_key.rs:99:5 | LL | let _map = HashMap::>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let _map = HashMap::>>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:106:5 + --> tests/ui/mut_key.rs:103:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:109:5 + --> tests/ui/mut_key.rs:106:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -142,7 +142,7 @@ LL | let _map = HashMap::>, usize>::new(); = note: ... because it contains `UnsafeCell`, which has interior mutability error: mutable key type - --> tests/ui/mut_key.rs:112:5 + --> tests/ui/mut_key.rs:109:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index 47f52621794b..bbcdbc89b6a4 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -13,7 +13,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; fn fun(x: &mut &mut u32) -> bool { -//~^ mut_mut + //~^ mut_mut **x > 0 } diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 326afb42ccb2..107a6229b86d 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -7,8 +7,6 @@ fn mut_range_bound_upper() { for i in 0..m { m = 5; //~^ mut_range_bound - - } } @@ -17,8 +15,6 @@ fn mut_range_bound_lower() { for i in m..10 { m *= 2; //~^ mut_range_bound - - } } @@ -29,11 +25,8 @@ fn mut_range_bound_both() { m = 5; //~^ mut_range_bound - n = 7; //~^ mut_range_bound - - } } @@ -50,7 +43,6 @@ fn mut_borrow_range_bound() { let n = &mut m; //~^ mut_range_bound - *n += 1; } } @@ -86,7 +78,6 @@ fn mut_range_bound_no_immediate_break() { m = 2; //~^ mut_range_bound - if m == 4 { break; } @@ -99,7 +90,6 @@ fn mut_range_bound_no_immediate_break() { n = 1; //~^ mut_range_bound - let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index 3dbc70f87f0f..3aae6e2dca6d 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -9,7 +9,7 @@ LL | m = 5; = help: to override `-D warnings` add `#[allow(clippy::mut_range_bound)]` error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:18:9 + --> tests/ui/mut_range_bound.rs:16:9 | LL | m *= 2; | ^ @@ -17,7 +17,7 @@ LL | m *= 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:29:9 + --> tests/ui/mut_range_bound.rs:25:9 | LL | m = 5; | ^ @@ -25,7 +25,7 @@ LL | m = 5; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:33:9 + --> tests/ui/mut_range_bound.rs:28:9 | LL | n = 7; | ^ @@ -33,7 +33,7 @@ LL | n = 7; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:50:22 + --> tests/ui/mut_range_bound.rs:43:22 | LL | let n = &mut m; | ^ @@ -41,7 +41,7 @@ LL | let n = &mut m; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:86:9 + --> tests/ui/mut_range_bound.rs:78:9 | LL | m = 2; | ^ @@ -49,7 +49,7 @@ LL | m = 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> tests/ui/mut_range_bound.rs:99:13 + --> tests/ui/mut_range_bound.rs:90:13 | LL | n = 1; | ^ diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 4ae57940cf2d..f664c373cdc3 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -30,18 +30,15 @@ fn main() { takes_an_immutable_reference(&mut 42); //~^ unnecessary_mut_passed - let as_ptr: fn(&i32) = takes_an_immutable_reference; as_ptr(&mut 42); //~^ unnecessary_mut_passed - // Methods let my_struct = MyStruct; my_struct.takes_an_immutable_reference(&mut 42); //~^ unnecessary_mut_passed - // No error // Functions diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index fb489360a1a3..474221329c25 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -8,13 +8,13 @@ LL | takes_an_immutable_reference(&mut 42); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]` error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/mut_reference.rs:35:12 + --> tests/ui/mut_reference.rs:34:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> tests/ui/mut_reference.rs:41:44 + --> tests/ui/mut_reference.rs:39: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 993ea880d66b..80a712a9286a 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -8,7 +8,6 @@ fn main() { Mutex::new(true); //~^ mutex_atomic - Mutex::new(5usize); //~^ mutex_atomic @@ -25,7 +24,6 @@ fn main() { Mutex::new(0u32); //~^ mutex_integer - Mutex::new(0i32); //~^ mutex_integer @@ -43,7 +41,6 @@ fn main() { Mutex::new(X); //~^ mutex_integer - // there are no 128 atomics, so these two should not lint { Mutex::new(0u128); diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 83be2ef995ce..838fc1d7c36e 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -8,31 +8,31 @@ LL | Mutex::new(true); = help: to override `-D warnings` add `#[allow(clippy::mutex_atomic)]` 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<()>` - --> tests/ui/mutex_atomic.rs:12:5 + --> tests/ui/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<()>` - --> tests/ui/mutex_atomic.rs:15:5 + --> tests/ui/mutex_atomic.rs:14: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<()>` - --> tests/ui/mutex_atomic.rs:19:5 + --> tests/ui/mutex_atomic.rs:18: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<()>` - --> tests/ui/mutex_atomic.rs:22:5 + --> tests/ui/mutex_atomic.rs:21:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicU32` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:25:5 + --> tests/ui/mutex_atomic.rs:24:5 | LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ @@ -41,31 +41,31 @@ LL | Mutex::new(0u32); = help: to override `-D warnings` add `#[allow(clippy::mutex_integer)]` error: consider using an `AtomicI32` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:29:5 + --> tests/ui/mutex_atomic.rs:27:5 | LL | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ error: consider using an `AtomicU8` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:33:5 + --> tests/ui/mutex_atomic.rs:31:5 | LL | Mutex::new(0u8); | ^^^^^^^^^^^^^^^ error: consider using an `AtomicI16` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:36:5 + --> tests/ui/mutex_atomic.rs:34:5 | LL | Mutex::new(0i16); | ^^^^^^^^^^^^^^^^ error: consider using an `AtomicI8` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:39:25 + --> tests/ui/mutex_atomic.rs:37:25 | LL | let _x: Mutex = Mutex::new(0); | ^^^^^^^^^^^^^ error: consider using an `AtomicI64` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> tests/ui/mutex_atomic.rs:43:5 + --> tests/ui/mutex_atomic.rs:41:5 | LL | Mutex::new(X); | ^^^^^^^^^^^^^ diff --git a/tests/ui/needless_arbitrary_self_type.fixed b/tests/ui/needless_arbitrary_self_type.fixed index 22dd127f01f3..adb9096c9f24 100644 --- a/tests/ui/needless_arbitrary_self_type.fixed +++ b/tests/ui/needless_arbitrary_self_type.fixed @@ -8,7 +8,7 @@ pub enum ValType { impl ValType { pub fn bad(self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -17,7 +17,7 @@ impl ValType { } pub fn mut_bad(mut self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -26,7 +26,7 @@ impl ValType { } pub fn ref_bad(&self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -35,7 +35,7 @@ impl ValType { } pub fn ref_bad_with_lifetime<'a>(&'a self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -44,7 +44,7 @@ impl ValType { } pub fn mut_ref_bad(&mut self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -53,7 +53,7 @@ impl ValType { } pub fn mut_ref_bad_with_lifetime<'a>(&'a mut self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } diff --git a/tests/ui/needless_arbitrary_self_type.rs b/tests/ui/needless_arbitrary_self_type.rs index 5b1702bfdf96..550546ed24fd 100644 --- a/tests/ui/needless_arbitrary_self_type.rs +++ b/tests/ui/needless_arbitrary_self_type.rs @@ -8,7 +8,7 @@ pub enum ValType { impl ValType { pub fn bad(self: Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -17,7 +17,7 @@ impl ValType { } pub fn mut_bad(mut self: Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -26,7 +26,7 @@ impl ValType { } pub fn ref_bad(self: &Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -35,7 +35,7 @@ impl ValType { } pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -44,7 +44,7 @@ impl ValType { } pub fn mut_ref_bad(self: &mut Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } @@ -53,7 +53,7 @@ impl ValType { } pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { - //~^ needless_arbitrary_self_type + //~^ needless_arbitrary_self_type unimplemented!(); } diff --git a/tests/ui/needless_as_bytes.fixed b/tests/ui/needless_as_bytes.fixed index 2f9e82218889..9cbc7b9c2651 100644 --- a/tests/ui/needless_as_bytes.fixed +++ b/tests/ui/needless_as_bytes.fixed @@ -15,34 +15,30 @@ impl S { fn main() { if "some string".is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", "some string".len()); //~^ needless_as_bytes - } if "some string".is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", "some string".len()); //~^ needless_as_bytes - } let s = String::from("yet another string"); if s.is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", s.len()); //~^ needless_as_bytes - } if s.is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", s.len()); //~^ needless_as_bytes - } // Do not lint diff --git a/tests/ui/needless_as_bytes.rs b/tests/ui/needless_as_bytes.rs index 2f0fc352d192..7de699647e85 100644 --- a/tests/ui/needless_as_bytes.rs +++ b/tests/ui/needless_as_bytes.rs @@ -15,34 +15,30 @@ impl S { fn main() { if "some string".as_bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", "some string".as_bytes().len()); //~^ needless_as_bytes - } if "some string".bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", "some string".bytes().len()); //~^ needless_as_bytes - } let s = String::from("yet another string"); if s.as_bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", s.as_bytes().len()); //~^ needless_as_bytes - } if s.bytes().is_empty() { - //~^ needless_as_bytes + //~^ needless_as_bytes println!("len = {}", s.bytes().len()); //~^ needless_as_bytes - } // Do not lint diff --git a/tests/ui/needless_as_bytes.stderr b/tests/ui/needless_as_bytes.stderr index 72746c05b8e2..0eead9815f8a 100644 --- a/tests/ui/needless_as_bytes.stderr +++ b/tests/ui/needless_as_bytes.stderr @@ -14,37 +14,37 @@ LL | println!("len = {}", "some string".as_bytes().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:24:8 + --> tests/ui/needless_as_bytes.rs:23:8 | LL | if "some string".bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `"some string".is_empty()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:27:30 + --> tests/ui/needless_as_bytes.rs:26:30 | LL | println!("len = {}", "some string".bytes().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` error: needless call to `as_bytes` - --> tests/ui/needless_as_bytes.rs:33:8 + --> tests/ui/needless_as_bytes.rs:31:8 | LL | if s.as_bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` error: needless call to `as_bytes` - --> tests/ui/needless_as_bytes.rs:36:30 + --> tests/ui/needless_as_bytes.rs:34:30 | LL | println!("len = {}", s.as_bytes().len()); | ^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:40:8 + --> tests/ui/needless_as_bytes.rs:37:8 | LL | if s.bytes().is_empty() { | ^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` error: needless call to `bytes` - --> tests/ui/needless_as_bytes.rs:43:30 + --> tests/ui/needless_as_bytes.rs:40:30 | LL | println!("len = {}", s.bytes().len()); | ^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` diff --git a/tests/ui/needless_bitwise_bool.fixed b/tests/ui/needless_bitwise_bool.fixed index 7fc36e0f94b4..89a3c1474f25 100644 --- a/tests/ui/needless_bitwise_bool.fixed +++ b/tests/ui/needless_bitwise_bool.fixed @@ -21,7 +21,7 @@ fn main() { println!("true") } if y && !x { - //~^ needless_bitwise_bool + //~^ needless_bitwise_bool println!("true") } diff --git a/tests/ui/needless_bitwise_bool.rs b/tests/ui/needless_bitwise_bool.rs index dcbc08334a77..f5aa7a9f3d9e 100644 --- a/tests/ui/needless_bitwise_bool.rs +++ b/tests/ui/needless_bitwise_bool.rs @@ -21,7 +21,7 @@ fn main() { println!("true") } if y & !x { - //~^ needless_bitwise_bool + //~^ needless_bitwise_bool println!("true") } diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed index d067f1c6016b..fe966a716df7 100644 --- a/tests/ui/needless_borrow_pat.fixed +++ b/tests/ui/needless_borrow_pat.fixed @@ -58,8 +58,6 @@ fn main() { let _: &String = match Some(&x) { Some(x) => x, //~^ needless_borrow - - None => return, }; @@ -67,14 +65,13 @@ fn main() { let _: &String = match Some(&x) { Some(x) => x, //~^ needless_borrow - None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => { - //~^ needless_borrow + //~^ needless_borrow f1(x); f1(x); @@ -87,13 +84,12 @@ fn main() { match Some(&x) { Some(x) => m1!(x), //~^ needless_borrow - None => return, }; // Err, reference to a &String let _ = |&x: &&String| { - //~^ needless_borrow + //~^ needless_borrow let _: &String = x; }; @@ -113,7 +109,6 @@ fn main() { let _: u32 = match Some(&x) { Some(x) => x.0, //~^ needless_borrow - None => return, }; @@ -125,7 +120,6 @@ fn main() { let _: &u32 = match E::A(&0) { E::A(x) | E::B(x) => x, //~^ needless_borrow - }; // Err, reference to &String. @@ -142,7 +136,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&x: &&'a String) -> &'a String { -//~^ needless_borrow + //~^ needless_borrow let _: &String = x; x @@ -151,7 +145,7 @@ fn f2<'a>(&x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&x: &&String) { - //~^ needless_borrow + //~^ needless_borrow let _: &String = x; } @@ -161,7 +155,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&x: &&String) { - //~^ needless_borrow + //~^ needless_borrow let _: &String = x; } diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index 7c39183d7916..a6b43855cad1 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -58,8 +58,6 @@ fn main() { let _: &String = match Some(&x) { Some(ref x) => x, //~^ needless_borrow - - None => return, }; @@ -67,14 +65,13 @@ fn main() { let _: &String = match Some(&x) { Some(ref x) => *x, //~^ needless_borrow - None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => { - //~^ needless_borrow + //~^ needless_borrow f1(x); f1(*x); @@ -87,13 +84,12 @@ fn main() { match Some(&x) { Some(ref x) => m1!(x), //~^ needless_borrow - None => return, }; // Err, reference to a &String let _ = |&ref x: &&String| { - //~^ needless_borrow + //~^ needless_borrow let _: &String = x; }; @@ -113,7 +109,6 @@ fn main() { let _: u32 = match Some(&x) { Some(ref x) => x.0, //~^ needless_borrow - None => return, }; @@ -125,7 +120,6 @@ fn main() { let _: &u32 = match E::A(&0) { E::A(ref x) | E::B(ref x) => *x, //~^ needless_borrow - }; // Err, reference to &String. @@ -142,7 +136,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { -//~^ needless_borrow + //~^ needless_borrow let _: &String = x; *x @@ -151,7 +145,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { - //~^ needless_borrow + //~^ needless_borrow let _: &String = x; } @@ -161,7 +155,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { - //~^ needless_borrow + //~^ needless_borrow let _: &String = *x; } diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 7e1b3694e30f..018e74a4f11d 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -8,7 +8,7 @@ LL | Some(ref x) => x, = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:68:14 + --> tests/ui/needless_borrow_pat.rs:66:14 | LL | Some(ref x) => *x, | ^^^^^ @@ -19,7 +19,7 @@ LL | Some(x) => x, | ~ ~ error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:76:14 + --> tests/ui/needless_borrow_pat.rs:73:14 | LL | Some(ref x) => { | ^^^^^ @@ -34,19 +34,19 @@ LL ~ f1(x); | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:88:14 + --> tests/ui/needless_borrow_pat.rs:85:14 | LL | Some(ref x) => m1!(x), | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:95:15 + --> tests/ui/needless_borrow_pat.rs:91:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:102:10 + --> tests/ui/needless_borrow_pat.rs:98:10 | LL | let (ref y,) = (&x,); | ^^^^^ @@ -60,13 +60,13 @@ LL ~ let _: &String = y; | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:114:14 + --> tests/ui/needless_borrow_pat.rs:110:14 | LL | Some(ref x) => x.0, | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:126:14 + --> tests/ui/needless_borrow_pat.rs:121:14 | LL | E::A(ref x) | E::B(ref x) => *x, | ^^^^^ ^^^^^ @@ -77,13 +77,13 @@ LL | E::A(x) | E::B(x) => x, | ~ ~ ~ error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:134:21 + --> tests/ui/needless_borrow_pat.rs:128:21 | LL | if let Some(ref x) = Some(&String::new()); | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:144:12 + --> tests/ui/needless_borrow_pat.rs:138:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -98,13 +98,13 @@ LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:153:11 + --> tests/ui/needless_borrow_pat.rs:147:11 | LL | fn f(&ref x: &&String) { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> tests/ui/needless_borrow_pat.rs:163:11 + --> tests/ui/needless_borrow_pat.rs:157:11 | LL | fn f(&ref x: &&String) { | ^^^^^ diff --git a/tests/ui/needless_borrowed_ref.fixed b/tests/ui/needless_borrowed_ref.fixed index 1cad115e96d1..e4504bc2784c 100644 --- a/tests/ui/needless_borrowed_ref.fixed +++ b/tests/ui/needless_borrowed_ref.fixed @@ -69,7 +69,7 @@ fn should_lint( //~^ needless_borrowed_reference if let Struct { - //~^ needless_borrowed_reference + //~^ needless_borrowed_reference a, b: b, c: renamed, diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index ae6377fd4421..7edfda60b979 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -69,7 +69,7 @@ fn should_lint( //~^ needless_borrowed_reference if let &Struct { - //~^ needless_borrowed_reference + //~^ needless_borrowed_reference ref a, b: ref b, c: ref renamed, diff --git a/tests/ui/needless_character_iteration.fixed b/tests/ui/needless_character_iteration.fixed index 584b578fa8be..e25db9bb590f 100644 --- a/tests/ui/needless_character_iteration.fixed +++ b/tests/ui/needless_character_iteration.fixed @@ -27,7 +27,6 @@ fn main() { !"foo".is_ascii(); //~^ needless_character_iteration - let s = String::new(); s.is_ascii(); //~^ needless_character_iteration @@ -35,14 +34,12 @@ fn main() { !"foo".to_string().is_ascii(); //~^ needless_character_iteration - "foo".is_ascii(); !"foo".is_ascii(); S::default().field().is_ascii(); //~^ needless_character_iteration - // Should not lint! "foo".chars().all(|c| { let x = c; diff --git a/tests/ui/needless_character_iteration.rs b/tests/ui/needless_character_iteration.rs index 1ef5c3a79a3e..9b184dab6bc8 100644 --- a/tests/ui/needless_character_iteration.rs +++ b/tests/ui/needless_character_iteration.rs @@ -27,7 +27,6 @@ fn main() { "foo".chars().any(|c| !char::is_ascii(&c)); //~^ needless_character_iteration - let s = String::new(); s.chars().all(|c| c.is_ascii()); //~^ needless_character_iteration @@ -35,15 +34,14 @@ fn main() { "foo".to_string().chars().any(|c| !c.is_ascii()); //~^ needless_character_iteration - "foo".chars().all(|c| { - //~^ needless_character_iteration + //~^ needless_character_iteration let x = c; x.is_ascii() }); "foo".chars().any(|c| { - //~^ needless_character_iteration + //~^ needless_character_iteration let x = c; !x.is_ascii() @@ -52,7 +50,6 @@ fn main() { S::default().field().chars().all(|x| x.is_ascii()); //~^ needless_character_iteration - // Should not lint! "foo".chars().all(|c| { let x = c; diff --git a/tests/ui/needless_character_iteration.stderr b/tests/ui/needless_character_iteration.stderr index 29e5a674e0c5..995404996644 100644 --- a/tests/ui/needless_character_iteration.stderr +++ b/tests/ui/needless_character_iteration.stderr @@ -26,19 +26,19 @@ LL | "foo".chars().any(|c| !char::is_ascii(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:32:5 + --> tests/ui/needless_character_iteration.rs:31:5 | LL | s.chars().all(|c| c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:35:5 + --> tests/ui/needless_character_iteration.rs:34:5 | LL | "foo".to_string().chars().any(|c| !c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".to_string().is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:39:5 + --> tests/ui/needless_character_iteration.rs:37:5 | LL | / "foo".chars().all(|c| { LL | | @@ -49,7 +49,7 @@ LL | | }); | |______^ help: try: `"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:45:5 + --> tests/ui/needless_character_iteration.rs:43:5 | LL | / "foo".chars().any(|c| { LL | | @@ -60,7 +60,7 @@ LL | | }); | |______^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:52:5 + --> tests/ui/needless_character_iteration.rs:50:5 | LL | S::default().field().chars().all(|x| x.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `S::default().field().is_ascii()` diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index c2267b84de42..104941dc9937 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -9,7 +9,7 @@ fn main() { let len = sample.iter().count(); //~^ needless_collect if sample.iter().next().is_none() { - //~^ needless_collect + //~^ needless_collect // Empty } sample.iter().cloned().any(|x| x == 1); diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 854bc3fff19d..7f05f51b82e9 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -9,7 +9,7 @@ fn main() { let len = sample.iter().collect::>().len(); //~^ needless_collect if sample.iter().collect::>().is_empty() { - //~^ needless_collect + //~^ needless_collect // Empty } sample.iter().cloned().collect::>().contains(&1); diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 0adef7e72ee4..e873db6dee14 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -28,7 +28,7 @@ fn main() { let i = 0; println!("bar {} ", i); } else { - //~^ needless_continue + //~^ needless_continue continue; } @@ -45,7 +45,7 @@ fn main() { } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { - //~^ needless_continue + //~^ needless_continue continue; } else { @@ -61,7 +61,6 @@ fn simple_loop() { loop { continue; //~^ needless_continue - } } @@ -70,7 +69,6 @@ fn simple_loop2() { println!("bleh"); continue; //~^ needless_continue - } } @@ -98,7 +96,6 @@ fn simple_loop5() { println!("bleh"); { continue } //~^ needless_continue - } } @@ -149,7 +146,7 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { - //~^ needless_continue + //~^ needless_continue continue 'inner; } @@ -157,7 +154,7 @@ mod issue_2329 { update_condition(); if condition() { - //~^ needless_continue + //~^ needless_continue continue; } else { @@ -182,7 +179,6 @@ fn issue_13641() { 'b: loop { continue 'b; //~^ needless_continue - } } } @@ -221,7 +217,7 @@ mod issue_4077 { loop { if true { } else { - //~^ needless_continue + //~^ needless_continue // redundant `else` continue; // redundant `continue` } @@ -229,7 +225,7 @@ mod issue_4077 { loop { if some_expr() { - //~^ needless_continue + //~^ needless_continue continue; } else { do_something(); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 947e61cac12e..878c1e731e32 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -71,7 +71,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:71:9 + --> tests/ui/needless_continue.rs:70:9 | LL | continue; | ^^^^^^^^ @@ -79,7 +79,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:80:9 + --> tests/ui/needless_continue.rs:78:9 | LL | continue | ^^^^^^^^ @@ -87,7 +87,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:90:9 + --> tests/ui/needless_continue.rs:88:9 | LL | continue | ^^^^^^^^ @@ -95,7 +95,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:99:11 + --> tests/ui/needless_continue.rs:97:11 | LL | { continue } | ^^^^^^^^ @@ -103,7 +103,7 @@ LL | { continue } = help: consider dropping the `continue` expression error: this `else` block is redundant - --> tests/ui/needless_continue.rs:151:24 + --> tests/ui/needless_continue.rs:148:24 | LL | } else { | ________________________^ @@ -130,7 +130,7 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> tests/ui/needless_continue.rs:159:17 + --> tests/ui/needless_continue.rs:156:17 | LL | / if condition() { LL | | @@ -152,13 +152,21 @@ LL | | } } error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:183:13 + --> tests/ui/needless_continue.rs:180:13 | LL | continue 'b; | ^^^^^^^^^^^ | = help: consider dropping the `continue` expression +error: this `continue` expression is redundant + --> tests/ui/needless_continue.rs:196:21 + | +LL | continue 'inner; + | ^^^^^^^^^^^^^^^ + | + = help: consider dropping the `continue` expression + error: this `continue` expression is redundant --> tests/ui/needless_continue.rs:200:21 | @@ -168,15 +176,7 @@ LL | continue 'inner; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:204:21 - | -LL | continue 'inner; - | ^^^^^^^^^^^^^^^ - | - = help: consider dropping the `continue` expression - -error: this `continue` expression is redundant - --> tests/ui/needless_continue.rs:215:21 + --> tests/ui/needless_continue.rs:211:21 | LL | continue; | ^^^^^^^^ @@ -184,7 +184,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `else` block is redundant - --> tests/ui/needless_continue.rs:223:20 + --> tests/ui/needless_continue.rs:219:20 | LL | } else { | ____________________^ @@ -201,7 +201,7 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> tests/ui/needless_continue.rs:231:13 + --> tests/ui/needless_continue.rs:227:13 | LL | / if some_expr() { LL | | diff --git a/tests/ui/needless_for_each_fixable.fixed b/tests/ui/needless_for_each_fixable.fixed index 873bad552af1..fa23e18318f1 100644 --- a/tests/ui/needless_for_each_fixable.fixed +++ b/tests/ui/needless_for_each_fixable.fixed @@ -13,34 +13,34 @@ fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; for elem in v.iter() { - //~^ needless_for_each + //~^ needless_for_each acc += elem; } for elem in v.into_iter() { - //~^ needless_for_each + //~^ needless_for_each acc += elem; } for elem in [1, 2, 3].iter() { - //~^ needless_for_each + //~^ needless_for_each acc += elem; } let mut hash_map: HashMap = HashMap::new(); for (k, v) in hash_map.iter() { - //~^ needless_for_each + //~^ needless_for_each acc += k + v; } for (k, v) in hash_map.iter_mut() { - //~^ needless_for_each + //~^ needless_for_each acc += *k + *v; } for k in hash_map.keys() { - //~^ needless_for_each + //~^ needless_for_each acc += k; } for v in hash_map.values() { - //~^ needless_for_each + //~^ needless_for_each acc += v; } @@ -48,7 +48,7 @@ fn should_lint() { Vec::new() } for elem in my_vec().iter() { - //~^ needless_for_each + //~^ needless_for_each acc += elem; } } diff --git a/tests/ui/needless_for_each_fixable.rs b/tests/ui/needless_for_each_fixable.rs index 5e650dfc06c1..2c7e68a6f512 100644 --- a/tests/ui/needless_for_each_fixable.rs +++ b/tests/ui/needless_for_each_fixable.rs @@ -13,34 +13,34 @@ fn should_lint() { let v: Vec = Vec::new(); let mut acc = 0; v.iter().for_each(|elem| { - //~^ needless_for_each + //~^ needless_for_each acc += elem; }); v.into_iter().for_each(|elem| { - //~^ needless_for_each + //~^ needless_for_each acc += elem; }); [1, 2, 3].iter().for_each(|elem| { - //~^ needless_for_each + //~^ needless_for_each acc += elem; }); let mut hash_map: HashMap = HashMap::new(); hash_map.iter().for_each(|(k, v)| { - //~^ needless_for_each + //~^ needless_for_each acc += k + v; }); hash_map.iter_mut().for_each(|(k, v)| { - //~^ needless_for_each + //~^ needless_for_each acc += *k + *v; }); hash_map.keys().for_each(|k| { - //~^ needless_for_each + //~^ needless_for_each acc += k; }); hash_map.values().for_each(|v| { - //~^ needless_for_each + //~^ needless_for_each acc += v; }); @@ -48,7 +48,7 @@ fn should_lint() { Vec::new() } my_vec().iter().for_each(|elem| { - //~^ needless_for_each + //~^ needless_for_each acc += elem; }); } diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 56faa471ed8c..159cbe49828f 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -6,8 +6,7 @@ fn main() { let v: Vec = Vec::new(); // This is unfixable because the closure includes `return`. v.iter().for_each(|v| { - //~^ needless_for_each - + //~^ needless_for_each if *v == 10 { return; diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 37470a8a622e..7e42bd133f06 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -2,6 +2,9 @@ error: needless use of `for_each` --> tests/ui/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { +LL | | +LL | | +LL | | if *v == 10 { ... | LL | | }); | |_______^ @@ -13,7 +16,6 @@ help: try LL ~ for v in v.iter() { LL + LL + -LL + LL + if *v == 10 { LL + return; LL + } else { diff --git a/tests/ui/needless_if.fixed b/tests/ui/needless_if.fixed index 1e2842a27aa6..6208ca19b82b 100644 --- a/tests/ui/needless_if.fixed +++ b/tests/ui/needless_if.fixed @@ -34,7 +34,7 @@ fn main() { } else { } ({ - //~^ needless_if + //~^ needless_if return; }); // Do not lint if `else if` is present @@ -51,7 +51,7 @@ fn main() { {} // Can lint nested `if let`s ({ - //~^ needless_if + //~^ needless_if if let true = true && true { diff --git a/tests/ui/needless_if.rs b/tests/ui/needless_if.rs index a753c66da5a5..b459ff877be6 100644 --- a/tests/ui/needless_if.rs +++ b/tests/ui/needless_if.rs @@ -34,7 +34,7 @@ fn main() { } else { } if { - //~^ needless_if + //~^ needless_if return; } {} // Do not lint if `else if` is present @@ -51,7 +51,7 @@ fn main() { {} // Can lint nested `if let`s if { - //~^ needless_if + //~^ needless_if if let true = true && true { diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index 3cfbce84cd9b..283635d42def 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -31,7 +31,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} fn in_and_out(x: &u8, _y: u8) -> &u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -44,7 +44,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -52,7 +52,7 @@ fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes y } @@ -70,7 +70,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(x) } @@ -78,7 +78,7 @@ fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(y) } @@ -88,7 +88,7 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { } fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(x) } @@ -163,7 +163,7 @@ struct X { impl X { fn self_and_out(&self) -> &u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes &self.x } @@ -171,7 +171,7 @@ impl X { // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes &self.x } @@ -179,7 +179,7 @@ impl X { // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -204,7 +204,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { } fn struct_with_lt(_foo: Foo<'_>) -> &str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -223,7 +223,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -232,7 +232,7 @@ fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -248,14 +248,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. fn trait_obj_elided2(_arg: &dyn Drop) -> &str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } type FooAlias<'a> = Foo<'a>; fn alias_with_lt(_foo: FooAlias<'_>) -> &str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -274,7 +274,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -283,12 +283,12 @@ fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } fn named_input_elided_output(_arg: &str) -> &str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -297,7 +297,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { } fn trait_bound_ok>(_: &u8, _: T) { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { @@ -334,7 +334,7 @@ struct Cow<'a> { x: &'a str, } fn out_return_type_lts(e: &str) -> Cow<'_> { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -362,7 +362,7 @@ mod issue2944 { //~^ needless_lifetimes impl Bar { fn baz(&self) -> impl Foo + '_ { - //~^ needless_lifetimes + //~^ needless_lifetimes Baz { bar: self } } } @@ -395,7 +395,7 @@ mod nested_elision_sites { f(i) } fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(&i32) -> &i32) -> &i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -405,7 +405,7 @@ mod nested_elision_sites { } // lint fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -434,7 +434,7 @@ mod nested_elision_sites { } // lint fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -448,11 +448,11 @@ mod nested_elision_sites { // lint fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes |f| 42 } fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { - //~^ needless_lifetimes + //~^ needless_lifetimes |f| () } } @@ -475,21 +475,21 @@ mod issue7296 { struct Foo; impl Foo { fn implicit(&self) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } fn implicit_mut(&mut self) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit(self: &Arc) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit_mut(self: &mut Rc) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -502,7 +502,7 @@ mod issue7296 { } fn lifetime_elsewhere(self: Box, here: &()) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } } @@ -511,7 +511,7 @@ mod issue7296 { fn implicit(&self) -> &(); //~^ needless_lifetimes fn implicit_provided(&self) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } @@ -520,7 +520,7 @@ mod issue7296 { //~^ needless_lifetimes #[clippy::msrv = "1.81"] fn explicit_provided(self: &Arc) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -533,7 +533,7 @@ mod issue7296 { fn lifetime_elsewhere(self: Box, here: &()) -> &(); //~^ needless_lifetimes fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } } @@ -554,13 +554,13 @@ mod pr_9743_output_lifetime_checks { // lint: only one input fn one_input(x: &u8) -> &u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } // lint: multiple inputs, output would not be elided fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) -> &'b u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -673,7 +673,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&self` fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { match self { @@ -684,7 +684,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&'_ self` fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { match self { @@ -705,7 +705,7 @@ mod issue13923 { } impl<'t> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&Self` fn map_content5( self: std::pin::Pin<&Self>, diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 612e7546d962..2853870473db 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -31,7 +31,7 @@ fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) {} fn mut_and_static_input(_x: &mut u8, _y: &'static str) {} fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -44,7 +44,7 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { // fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 // ^^^ fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -52,7 +52,7 @@ fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { // fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 // ^^^ fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { -//~^ needless_lifetimes + //~^ needless_lifetimes y } @@ -70,7 +70,7 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { // fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> // ^^^ fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(x) } @@ -78,7 +78,7 @@ fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { // fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> // ^^^ fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(y) } @@ -88,7 +88,7 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { } fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { -//~^ needless_lifetimes + //~^ needless_lifetimes Ok(x) } @@ -163,7 +163,7 @@ struct X { impl X { fn self_and_out<'s>(&'s self) -> &'s u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes &self.x } @@ -171,7 +171,7 @@ impl X { // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 // ^^^ fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes &self.x } @@ -179,7 +179,7 @@ impl X { // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 // ^^^^^ fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes x } @@ -204,7 +204,7 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { } fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -223,7 +223,7 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { // fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str // ^^ fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -232,7 +232,7 @@ fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str // ^^^^ fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -248,14 +248,14 @@ fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str { // Should warn because there is no lifetime on `Drop`, so this would be // unambiguous if we elided the lifetime. fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } type FooAlias<'a> = Foo<'a>; fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -274,7 +274,7 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { // fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str // ^^ fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -283,12 +283,12 @@ fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str // ^^^^^^^^^ fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } fn named_input_elided_output<'a>(_arg: &'a str) -> &str { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -297,7 +297,7 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { } fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { @@ -334,7 +334,7 @@ struct Cow<'a> { x: &'a str, } fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { -//~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -362,7 +362,7 @@ mod issue2944 { //~^ needless_lifetimes impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { - //~^ needless_lifetimes + //~^ needless_lifetimes Baz { bar: self } } } @@ -395,7 +395,7 @@ mod nested_elision_sites { f(i) } fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -405,7 +405,7 @@ mod nested_elision_sites { } // lint fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -434,7 +434,7 @@ mod nested_elision_sites { } // lint fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes f(i) } @@ -448,11 +448,11 @@ mod nested_elision_sites { // lint fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { - //~^ needless_lifetimes + //~^ needless_lifetimes |f| 42 } fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { - //~^ needless_lifetimes + //~^ needless_lifetimes |f| () } } @@ -475,21 +475,21 @@ mod issue7296 { struct Foo; impl Foo { fn implicit<'a>(&'a self) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } fn implicit_mut<'a>(&'a mut self) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit<'a>(self: &'a Arc) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.81"] fn explicit_mut<'a>(self: &'a mut Rc) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -502,7 +502,7 @@ mod issue7296 { } fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } } @@ -511,7 +511,7 @@ mod issue7296 { fn implicit<'a>(&'a self) -> &'a (); //~^ needless_lifetimes fn implicit_provided<'a>(&'a self) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } @@ -520,7 +520,7 @@ mod issue7296 { //~^ needless_lifetimes #[clippy::msrv = "1.81"] fn explicit_provided<'a>(self: &'a Arc) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } #[clippy::msrv = "1.80"] @@ -533,7 +533,7 @@ mod issue7296 { fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); //~^ needless_lifetimes fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { - //~^ needless_lifetimes + //~^ needless_lifetimes &() } } @@ -554,13 +554,13 @@ mod pr_9743_output_lifetime_checks { // lint: only one input fn one_input<'a>(x: &'a u8) -> &'a u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } // lint: multiple inputs, output would not be elided fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { - //~^ needless_lifetimes + //~^ needless_lifetimes unimplemented!() } @@ -673,7 +673,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&self` fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { match self { @@ -684,7 +684,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&'_ self` fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { match self { @@ -705,7 +705,7 @@ mod issue13923 { } impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes + //~^ needless_lifetimes // `'py` can be elided because of `&Self` fn map_content5( self: std::pin::Pin<&Self>, diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs index 848490d9b35e..1cb670edc60f 100644 --- a/tests/ui/needless_match.rs +++ b/tests/ui/needless_match.rs @@ -13,7 +13,7 @@ enum Simple { fn useless_match() { let i = 10; let _: i32 = match i { - //~^ needless_match + //~^ needless_match 0 => 0, 1 => 1, 2 => 2, @@ -21,7 +21,7 @@ fn useless_match() { }; let s = "test"; let _: &str = match s { - //~^ needless_match + //~^ needless_match "a" => "a", "b" => "b", s => s, @@ -31,7 +31,7 @@ fn useless_match() { fn custom_type_match() { let se = Simple::A; let _: Simple = match se { - //~^ needless_match + //~^ needless_match Simple::A => Simple::A, Simple::B => Simple::B, Simple::C => Simple::C, @@ -54,7 +54,7 @@ fn custom_type_match() { fn option_match(x: Option) { let _: Option = match x { - //~^ needless_match + //~^ needless_match Some(a) => Some(a), None => None, }; @@ -71,12 +71,12 @@ fn func_ret_err(err: T) -> Result { fn result_match() { let _: Result = match Ok(1) { - //~^ needless_match + //~^ needless_match Ok(a) => Ok(a), Err(err) => Err(err), }; let _: Result = match func_ret_err(0_i32) { - //~^ needless_match + //~^ needless_match Err(err) => Err(err), Ok(a) => Ok(a), }; @@ -136,7 +136,7 @@ fn if_let_result() { fn if_let_custom_enum(x: Simple) { let _: Simple = if let Simple::A = x { - //~^ needless_match + //~^ needless_match Simple::A } else if let Simple::B = x { Simple::B @@ -176,7 +176,7 @@ mod issue8542 { let bb = false; let _: Complex = match ce { - //~^ needless_match + //~^ needless_match Complex::A(a) => Complex::A(a), Complex::B(a, b) => Complex::B(a, b), Complex::C(a, b, c) => Complex::C(a, b, c), @@ -261,14 +261,14 @@ mod issue9084 { // should lint let _ = match e { - //~^ needless_match + //~^ needless_match _ if some_bool => e, _ => e, }; // should lint let _ = match e { - //~^ needless_match + //~^ needless_match Some(i) => Some(i), _ if some_bool => e, _ => e, @@ -350,7 +350,7 @@ pub fn issue13574() -> Option<()> { // Same const, should lint let _ = { if let Some(num) = A { - //~^ needless_match + //~^ needless_match Some(num) } else if let Some(num) = A { Some(num) diff --git a/tests/ui/needless_maybe_sized.fixed b/tests/ui/needless_maybe_sized.fixed index 68252ba54fd4..f8b164396990 100644 --- a/tests/ui/needless_maybe_sized.fixed +++ b/tests/ui/needless_maybe_sized.fixed @@ -51,23 +51,23 @@ struct Struct(T); //~^ needless_maybe_sized impl Struct { -//~^ needless_maybe_sized + //~^ needless_maybe_sized fn method(&self) {} //~^ needless_maybe_sized } enum Enum { -//~^ needless_maybe_sized + //~^ needless_maybe_sized Variant(&'static T), } union Union<'a, T: Sized> { -//~^ needless_maybe_sized + //~^ needless_maybe_sized a: &'a T, } trait Trait { -//~^ needless_maybe_sized + //~^ needless_maybe_sized fn trait_method() {} //~^ needless_maybe_sized diff --git a/tests/ui/needless_maybe_sized.rs b/tests/ui/needless_maybe_sized.rs index 0cafc0d9ff6e..e4312b40563f 100644 --- a/tests/ui/needless_maybe_sized.rs +++ b/tests/ui/needless_maybe_sized.rs @@ -54,23 +54,23 @@ struct Struct(T); //~^ needless_maybe_sized impl Struct { -//~^ needless_maybe_sized + //~^ needless_maybe_sized fn method(&self) {} //~^ needless_maybe_sized } enum Enum { -//~^ needless_maybe_sized + //~^ needless_maybe_sized Variant(&'static T), } union Union<'a, T: Sized + ?Sized> { -//~^ needless_maybe_sized + //~^ needless_maybe_sized a: &'a T, } trait Trait { -//~^ needless_maybe_sized + //~^ needless_maybe_sized fn trait_method() {} //~^ needless_maybe_sized diff --git a/tests/ui/needless_option_take.fixed b/tests/ui/needless_option_take.fixed index ae2bfab0e06d..a8bd50b79899 100644 --- a/tests/ui/needless_option_take.fixed +++ b/tests/ui/needless_option_take.fixed @@ -23,7 +23,6 @@ fn main() { x.as_ref(); //~^ needless_option_take - println!("Testing non erroneous option_take_on_temporary"); let mut x = Some(3); let y = x.as_mut(); @@ -35,33 +34,26 @@ fn main() { let y = x.replace(289); //~^ needless_option_take - let y = Some(3).as_mut(); //~^ needless_option_take - let y = Option::as_mut(&mut x); //~^ needless_option_take - let x = return_option(); let x = return_option(); //~^ needless_option_take - let x = MyStruct::get_option(); let x = MyStruct::get_option(); //~^ needless_option_take - let mut my_vec = vec![1, 2, 3]; my_vec.push(4); let y = my_vec.first(); let y = my_vec.first(); //~^ needless_option_take - let y = my_vec.first(); //~^ needless_option_take - } diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index 723930f59a11..8141ee43db11 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -23,7 +23,6 @@ fn main() { x.as_ref().take(); //~^ needless_option_take - println!("Testing non erroneous option_take_on_temporary"); let mut x = Some(3); let y = x.as_mut(); @@ -35,33 +34,26 @@ fn main() { let y = x.replace(289).take(); //~^ needless_option_take - let y = Some(3).as_mut().take(); //~^ needless_option_take - let y = Option::as_mut(&mut x).take(); //~^ needless_option_take - let x = return_option(); let x = return_option().take(); //~^ needless_option_take - let x = MyStruct::get_option(); let x = MyStruct::get_option().take(); //~^ needless_option_take - let mut my_vec = vec![1, 2, 3]; my_vec.push(4); let y = my_vec.first(); let y = my_vec.first().take(); //~^ needless_option_take - let y = my_vec.first().take(); //~^ needless_option_take - } diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index 271e1a0c7915..9054463c07cd 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -11,7 +11,7 @@ LL | x.as_ref().take(); = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:32:13 + --> tests/ui/needless_option_take.rs:31:13 | LL | let y = x.as_mut().take(); | ^^^^^^^^^^------- @@ -21,7 +21,7 @@ LL | let y = x.as_mut().take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:35:13 + --> tests/ui/needless_option_take.rs:34:13 | LL | let y = x.replace(289).take(); | ^^^^^^^^^^^^^^------- @@ -31,7 +31,7 @@ LL | let y = x.replace(289).take(); = note: `replace` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:39:13 + --> tests/ui/needless_option_take.rs:37:13 | LL | let y = Some(3).as_mut().take(); | ^^^^^^^^^^^^^^^^------- @@ -41,7 +41,7 @@ LL | let y = Some(3).as_mut().take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:43:13 + --> tests/ui/needless_option_take.rs:40:13 | LL | let y = Option::as_mut(&mut x).take(); | ^^^^^^^^^^^^^^^^^^^^^^------- @@ -51,7 +51,7 @@ LL | let y = Option::as_mut(&mut x).take(); = note: `as_mut` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:48:13 + --> tests/ui/needless_option_take.rs:44:13 | LL | let x = return_option().take(); | ^^^^^^^^^^^^^^^------- @@ -61,7 +61,7 @@ LL | let x = return_option().take(); = note: `return_option` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:53:13 + --> tests/ui/needless_option_take.rs:48:13 | LL | let x = MyStruct::get_option().take(); | ^^^^^^^^^^^^^^^^^^^^^^------- @@ -71,7 +71,7 @@ LL | let x = MyStruct::get_option().take(); = note: `get_option` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:60:13 + --> tests/ui/needless_option_take.rs:54:13 | LL | let y = my_vec.first().take(); | ^^^^^^^^^^^^^^------- @@ -81,7 +81,7 @@ LL | let y = my_vec.first().take(); = note: `first` creates a temporary value, so calling take() has no effect error: called `Option::take()` on a temporary value - --> tests/ui/needless_option_take.rs:64:13 + --> tests/ui/needless_option_take.rs:57:13 | LL | let y = my_vec.first().take(); | ^^^^^^^^^^^^^^------- diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index 415a13163805..f0c5a716ac99 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -9,7 +9,7 @@ use std::ptr::NonNull; fn foo(s: &mut Vec, b: &u32, x: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut *x += *b + s.len() as u32; } @@ -35,7 +35,7 @@ fn foo5(s: &mut Vec) { } fn foo6(s: &mut Vec) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut non_mut_ref(s); } @@ -48,9 +48,8 @@ impl Bar { fn bar(&mut self) {} //~^ needless_pass_by_ref_mut - fn mushroom(&self, vec: &mut Vec) -> usize { - //~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut vec.len() } @@ -128,43 +127,43 @@ async fn f7(x: &mut i32, y: i32, z: &mut i32, a: i32) { } async fn a1(x: &mut i32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a2(x: &mut i32, y: String) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a3(x: &mut i32, y: String, z: String) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a4(x: &mut i32, y: i32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a5(x: i32, y: &mut i32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a6(x: i32, y: &mut i32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", x); } async fn a7(x: i32, y: i32, z: &mut i32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut println!("{:?}", z); } async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { -//~^ needless_pass_by_ref_mut -//~| needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut + //~| needless_pass_by_ref_mut println!("{:?}", z); } @@ -201,14 +200,10 @@ fn lint_attr(s: &mut u32) {} fn cfg_warn(s: &mut u32) {} //~^ needless_pass_by_ref_mut - - #[cfg(not(feature = "a"))] mod foo { fn cfg_warn(s: &mut u32) {} //~^ needless_pass_by_ref_mut - - } // Should not warn. @@ -221,7 +216,7 @@ async fn inner_async(x: &mut i32, y: &mut u32) { } async fn inner_async2(x: &mut i32, y: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *x += 1; @@ -230,7 +225,7 @@ async fn inner_async2(x: &mut i32, y: &mut u32) { } async fn inner_async3(x: &mut i32, y: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *y += 1; @@ -250,7 +245,7 @@ async fn async_vec2(b: &mut Vec) { fn non_mut(n: &str) {} //Should warn async fn call_in_closure1(n: &mut str) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut (|| non_mut(n))() } fn str_mut(str: &mut String) -> bool { @@ -270,7 +265,7 @@ async fn closure(n: &mut usize) -> impl '_ + FnMut() { // Should warn. fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut || *n + 1 } @@ -282,7 +277,7 @@ async fn closure3(n: &mut usize) { // Should warn. async fn closure4(n: &mut usize) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut (|| { let _x = *n + 1; @@ -340,9 +335,8 @@ impl MutSelf { //~^ needless_pass_by_ref_mut async fn foo(&mut self, u: &mut i32, v: &mut u32) { - //~^ needless_pass_by_ref_mut - //~| needless_pass_by_ref_mut - + //~^ needless_pass_by_ref_mut + //~| needless_pass_by_ref_mut async { *u += 1; @@ -350,7 +344,7 @@ impl MutSelf { .await; } async fn foo2(&mut self, u: &mut i32, v: &mut u32) { - //~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { self.a += 1; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 0492acf7cc08..6637a255b5f5 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -20,67 +20,67 @@ LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:52:29 + --> tests/ui/needless_pass_by_ref_mut.rs:51:29 | LL | fn mushroom(&self, vec: &mut Vec) -> usize { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:130:16 + --> tests/ui/needless_pass_by_ref_mut.rs:129:16 | LL | async fn a1(x: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:135:16 + --> tests/ui/needless_pass_by_ref_mut.rs:134:16 | LL | async fn a2(x: &mut i32, y: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:140:16 + --> tests/ui/needless_pass_by_ref_mut.rs:139:16 | LL | async fn a3(x: &mut i32, y: String, z: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:145:16 + --> tests/ui/needless_pass_by_ref_mut.rs:144:16 | LL | async fn a4(x: &mut i32, y: i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:150:24 + --> tests/ui/needless_pass_by_ref_mut.rs:149:24 | LL | async fn a5(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:155:24 + --> tests/ui/needless_pass_by_ref_mut.rs:154:24 | LL | async fn a6(x: i32, y: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:160:32 + --> tests/ui/needless_pass_by_ref_mut.rs:159:32 | LL | async fn a7(x: i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:165:24 + --> tests/ui/needless_pass_by_ref_mut.rs:164:24 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:165:45 + --> tests/ui/needless_pass_by_ref_mut.rs:164:45 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:201:16 + --> tests/ui/needless_pass_by_ref_mut.rs:200:16 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -88,7 +88,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:208:20 + --> tests/ui/needless_pass_by_ref_mut.rs:205:20 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -96,115 +96,115 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:223:39 + --> tests/ui/needless_pass_by_ref_mut.rs:218: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 - --> tests/ui/needless_pass_by_ref_mut.rs:232:26 + --> tests/ui/needless_pass_by_ref_mut.rs:227:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:252:30 + --> tests/ui/needless_pass_by_ref_mut.rs:247:30 | LL | async fn call_in_closure1(n: &mut str) { | ^^^^^^^^ help: consider changing to: `&str` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:272:16 + --> tests/ui/needless_pass_by_ref_mut.rs:267:16 | LL | fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | ^^^^^^^^^^ help: consider changing to: `&usize` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:284:22 + --> tests/ui/needless_pass_by_ref_mut.rs:279:22 | LL | async fn closure4(n: &mut usize) { | ^^^^^^^^^^ help: consider changing to: `&usize` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:339:12 + --> tests/ui/needless_pass_by_ref_mut.rs:334:12 | LL | fn bar(&mut self) {} | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:342:18 + --> tests/ui/needless_pass_by_ref_mut.rs:337:18 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^^ help: consider changing to: `&self` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:342:45 + --> tests/ui/needless_pass_by_ref_mut.rs:337:45 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:352:46 + --> tests/ui/needless_pass_by_ref_mut.rs:346:46 | LL | async fn foo2(&mut self, u: &mut i32, v: &mut u32) { | ^^^^^^^^ help: consider changing to: `&u32` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:369:18 + --> tests/ui/needless_pass_by_ref_mut.rs:363:18 | LL | fn _empty_tup(x: &mut (())) {} | ^^^^^^^^^ help: consider changing to: `&()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:371:19 + --> tests/ui/needless_pass_by_ref_mut.rs:365:19 | LL | fn _single_tup(x: &mut ((i32,))) {} | ^^^^^^^^^^^^^ help: consider changing to: `&(i32,)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:373:18 + --> tests/ui/needless_pass_by_ref_mut.rs:367:18 | LL | fn _multi_tup(x: &mut ((i32, u32))) {} | ^^^^^^^^^^^^^^^^^ help: consider changing to: `&(i32, u32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:375:11 + --> tests/ui/needless_pass_by_ref_mut.rs:369:11 | LL | fn _fn(x: &mut (fn())) {} | ^^^^^^^^^^^ help: consider changing to: `&fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:378:23 + --> tests/ui/needless_pass_by_ref_mut.rs:372:23 | LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "Rust" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:380:20 + --> tests/ui/needless_pass_by_ref_mut.rs:374:20 | LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:382:18 + --> tests/ui/needless_pass_by_ref_mut.rs:376:18 | LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | ^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:384:25 + --> tests/ui/needless_pass_by_ref_mut.rs:378:25 | LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn()` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:386:20 + --> tests/ui/needless_pass_by_ref_mut.rs:380:20 | LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn(i32)` error: this argument is a mutable reference, but not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:388:20 + --> tests/ui/needless_pass_by_ref_mut.rs:382:20 | LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&unsafe extern "C" fn() -> (i32)` diff --git a/tests/ui/needless_pass_by_ref_mut2.fixed b/tests/ui/needless_pass_by_ref_mut2.fixed index fc40f8c8ca30..0e2ac0202364 100644 --- a/tests/ui/needless_pass_by_ref_mut2.fixed +++ b/tests/ui/needless_pass_by_ref_mut2.fixed @@ -6,7 +6,7 @@ #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &i32, y: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *y += 1; @@ -15,7 +15,7 @@ async fn inner_async3(x: &i32, y: &mut u32) { } async fn inner_async4(u: &mut i32, v: &u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *u += 1; diff --git a/tests/ui/needless_pass_by_ref_mut2.rs b/tests/ui/needless_pass_by_ref_mut2.rs index f921a7684236..9201d9a27298 100644 --- a/tests/ui/needless_pass_by_ref_mut2.rs +++ b/tests/ui/needless_pass_by_ref_mut2.rs @@ -6,7 +6,7 @@ #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &mut i32, y: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *y += 1; @@ -15,7 +15,7 @@ async fn inner_async3(x: &mut i32, y: &mut u32) { } async fn inner_async4(u: &mut i32, v: &mut u32) { -//~^ needless_pass_by_ref_mut + //~^ needless_pass_by_ref_mut async { *u += 1; diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index faa68c8140cb..885fb409417b 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -17,8 +17,7 @@ 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 { -//~^ needless_pass_by_value - + //~^ needless_pass_by_value assert_eq!(v.len(), 42); @@ -34,9 +33,8 @@ fn consume(_: T) {} struct Wrapper(String); fn bar(x: String, y: Wrapper) { -//~^ needless_pass_by_value -//~| needless_pass_by_value - + //~^ needless_pass_by_value + //~| needless_pass_by_value assert_eq!(x.len(), 42); assert_eq!(y.0.len(), 42); @@ -44,7 +42,7 @@ fn bar(x: String, y: Wrapper) { // V implements `Borrow`, but should be warned correctly fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { -//~^ needless_pass_by_value + //~^ needless_pass_by_value println!("{}", t.borrow()); println!("{}", u.as_ref()); @@ -58,7 +56,7 @@ fn test_fn i32>(f: F) { // x should be warned, but y is ok fn test_match(x: Option>, y: Option>) { -//~^ needless_pass_by_value + //~^ needless_pass_by_value match x { Some(Some(_)) => 1, // not moved @@ -73,9 +71,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) { -//~^ needless_pass_by_value -//~| needless_pass_by_value - + //~^ needless_pass_by_value + //~| needless_pass_by_value let Wrapper(s) = z; // moved let Wrapper(ref t) = y; // not moved @@ -95,15 +92,11 @@ impl Serialize for i32 {} fn test_blanket_ref(vals: T, serializable: S) {} //~^ needless_pass_by_value - fn issue_2114(s: String, t: String, u: Vec, v: Vec) { -//~^ needless_pass_by_value -//~| needless_pass_by_value -//~| needless_pass_by_value -//~| needless_pass_by_value - - - + //~^ needless_pass_by_value + //~| needless_pass_by_value + //~| needless_pass_by_value + //~| needless_pass_by_value s.capacity(); let _ = t.clone(); @@ -119,10 +112,8 @@ impl S { // taking `self` by value is always allowed s: String, //~^ needless_pass_by_value - t: String, //~^ needless_pass_by_value - ) -> usize { s.len() + t.capacity() } @@ -134,8 +125,6 @@ impl S { fn baz(&self, uu: U, ss: Self) {} //~^ needless_pass_by_value //~| needless_pass_by_value - - } trait FalsePositive { @@ -158,7 +147,7 @@ fn range>(range: T) { struct CopyWrapper(u32); fn bar_copy(x: u32, y: CopyWrapper) { -//~^ needless_pass_by_value + //~^ needless_pass_by_value assert_eq!(x, 42); assert_eq!(y.0, 42); @@ -166,11 +155,9 @@ fn bar_copy(x: u32, y: CopyWrapper) { // x and y should be warned, but z is ok fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { -//~^ needless_pass_by_value -//~| needless_pass_by_value -//~| needless_pass_by_value - - + //~^ needless_pass_by_value + //~| needless_pass_by_value + //~| needless_pass_by_value let CopyWrapper(s) = z; // moved let CopyWrapper(ref t) = y; // not moved @@ -186,14 +173,12 @@ impl<'b, T> Bar<'b, T> for T {} fn some_fun<'b, S: Bar<'b, ()>>(items: S) {} //~^ needless_pass_by_value - // Also this should not cause an ICE. See #2831 trait Club<'a, A> {} impl Club<'static, T> for T {} fn more_fun(items: impl Club<'static, i32>) {} //~^ needless_pass_by_value - fn is_sync(_: T) where T: Sync, diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 414ce347403a..47e008688215 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -8,55 +8,55 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec tests/ui/needless_pass_by_value.rs:36:11 + --> tests/ui/needless_pass_by_value.rs:35:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:36:22 + --> tests/ui/needless_pass_by_value.rs:35: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 - --> tests/ui/needless_pass_by_value.rs:46:71 + --> tests/ui/needless_pass_by_value.rs:44: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 - --> tests/ui/needless_pass_by_value.rs:60:18 + --> tests/ui/needless_pass_by_value.rs:58: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 - --> tests/ui/needless_pass_by_value.rs:75:24 + --> tests/ui/needless_pass_by_value.rs:73: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 - --> tests/ui/needless_pass_by_value.rs:75:36 + --> tests/ui/needless_pass_by_value.rs:73: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 - --> tests/ui/needless_pass_by_value.rs:95:49 + --> tests/ui/needless_pass_by_value.rs:92:49 | LL | fn test_blanket_ref(vals: T, serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:99:18 + --> tests/ui/needless_pass_by_value.rs:95: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 - --> tests/ui/needless_pass_by_value.rs:99:29 + --> tests/ui/needless_pass_by_value.rs:95:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -71,13 +71,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:99:40 + --> tests/ui/needless_pass_by_value.rs:95: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 - --> tests/ui/needless_pass_by_value.rs:99:53 + --> tests/ui/needless_pass_by_value.rs:95:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -92,85 +92,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:120:12 + --> tests/ui/needless_pass_by_value.rs:113:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:123:12 + --> tests/ui/needless_pass_by_value.rs:115: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 - --> tests/ui/needless_pass_by_value.rs:134:23 + --> tests/ui/needless_pass_by_value.rs:125:23 | LL | fn baz(&self, uu: U, ss: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:134:30 + --> tests/ui/needless_pass_by_value.rs:125:30 | LL | fn baz(&self, uu: U, ss: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:160:24 + --> tests/ui/needless_pass_by_value.rs:149:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:158:1 + --> tests/ui/needless_pass_by_value.rs:147:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:168:29 + --> tests/ui/needless_pass_by_value.rs:157:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:158:1 + --> tests/ui/needless_pass_by_value.rs:147:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:168:45 + --> tests/ui/needless_pass_by_value.rs:157:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:158:1 + --> tests/ui/needless_pass_by_value.rs:147:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:168:61 + --> tests/ui/needless_pass_by_value.rs:157:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:158:1 + --> tests/ui/needless_pass_by_value.rs:147:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:186:40 + --> tests/ui/needless_pass_by_value.rs:173:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:193:20 + --> tests/ui/needless_pass_by_value.rs:179:20 | LL | fn more_fun(items: 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 ff9699e35691..8a1c1be289cf 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -14,8 +14,7 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let vec2 = vec![1, 2, 3, 4]; for i in 0..vec.len() { - //~^ needless_range_loop - + //~^ needless_range_loop println!("{}", vec[i]); } @@ -26,26 +25,26 @@ fn main() { } for i in 0..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop let _ = vec[i]; } // ICE #746 for j in 0..4 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{:?}", STATIC[j]); } for j in 0..4 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{:?}", CONST[j]); } for i in 0..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop println!("{} {}", vec[i], i); } @@ -55,56 +54,56 @@ fn main() { } for i in 0..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec2[i]); } for i in 5..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec[i]); } for i in 0..MAX_LEN { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec[i]); } for i in 0..=MAX_LEN { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec[i]); } for i in 5..10 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec[i]); } for i in 5..=10 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", vec[i]); } for i in 5..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop println!("{} {}", vec[i], i); } for i in 5..10 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{} {}", vec[i], i); } // #2542 for i in 0..vec.len() { - //~^ needless_range_loop + //~^ needless_range_loop 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 a15830d721b6..86c2b550b071 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -12,7 +12,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:28:14 + --> tests/ui/needless_range_loop.rs:27:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> tests/ui/needless_range_loop.rs:35:14 + --> tests/ui/needless_range_loop.rs:34:14 | LL | for j in 0..4 { | ^^^^ @@ -34,7 +34,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> tests/ui/needless_range_loop.rs:41:14 + --> tests/ui/needless_range_loop.rs:40:14 | LL | for j in 0..4 { | ^^^^ @@ -45,7 +45,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:47:14 + --> tests/ui/needless_range_loop.rs:46:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> tests/ui/needless_range_loop.rs:57:14 + --> tests/ui/needless_range_loop.rs:56:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:63:14 + --> tests/ui/needless_range_loop.rs:62:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:69:14 + --> tests/ui/needless_range_loop.rs:68:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:75:14 + --> tests/ui/needless_range_loop.rs:74:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:81:14 + --> tests/ui/needless_range_loop.rs:80:14 | LL | for i in 5..10 { | ^^^^^ @@ -111,7 +111,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:87:14 + --> tests/ui/needless_range_loop.rs:86:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -122,7 +122,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:93:14 + --> tests/ui/needless_range_loop.rs:92:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:99:14 + --> tests/ui/needless_range_loop.rs:98:14 | LL | for i in 5..10 { | ^^^^^ @@ -144,7 +144,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:106:14 + --> tests/ui/needless_range_loop.rs:105: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 8a591a4bddae..68784a8df19d 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -9,8 +9,7 @@ fn main() { let ns = vec![2, 3, 5, 7]; for i in 3..10 { - //~^ needless_range_loop - + //~^ needless_range_loop println!("{}", ns[i]); } @@ -33,7 +32,7 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { - //~^ needless_range_loop + //~^ needless_range_loop ms[i] *= 2; } @@ -41,7 +40,7 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { - //~^ needless_range_loop + //~^ needless_range_loop let x = &mut ms[i]; *x *= 2; @@ -67,7 +66,7 @@ fn main() { let mut vec = vec![0; 9]; for i in x..x + 4 { - //~^ needless_range_loop + //~^ needless_range_loop vec[i] += 1; } @@ -76,7 +75,7 @@ fn main() { let mut vec = vec![0; 10]; for i in x..=x + 4 { - //~^ needless_range_loop + //~^ needless_range_loop vec[i] += 1; } @@ -84,19 +83,19 @@ fn main() { let arr = [1, 2, 3]; for i in 0..3 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", arr[i]); } for i in 0..2 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", arr[i]); } for i in 1..3 { - //~^ needless_range_loop + //~^ needless_range_loop println!("{}", arr[i]); } diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 34357c3db02f..0531e8e8f856 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -12,7 +12,7 @@ LL | for in ns.iter().take(10).skip(3) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> tests/ui/needless_range_loop2.rs:35:14 + --> tests/ui/needless_range_loop2.rs:34:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> tests/ui/needless_range_loop2.rs:43:14 + --> tests/ui/needless_range_loop2.rs:42:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop2.rs:69:14 + --> tests/ui/needless_range_loop2.rs:68:14 | LL | for i in x..x + 4 { | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | for in vec.iter_mut().skip(x).take(4) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop2.rs:78:14 + --> tests/ui/needless_range_loop2.rs:77:14 | LL | for i in x..=x + 4 { | ^^^^^^^^^ @@ -56,7 +56,7 @@ LL | for in vec.iter_mut().skip(x).take(4 + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:86:14 + --> tests/ui/needless_range_loop2.rs:85:14 | LL | for i in 0..3 { | ^^^^ @@ -67,7 +67,7 @@ LL | for in &arr { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:92:14 + --> tests/ui/needless_range_loop2.rs:91:14 | LL | for i in 0..2 { | ^^^^ @@ -78,7 +78,7 @@ LL | for in arr.iter().take(2) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> tests/ui/needless_range_loop2.rs:98:14 + --> tests/ui/needless_range_loop2.rs:97:14 | LL | for i in 1..3 { | ^^^^ diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 6e91c957e811..62e349234319 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -19,8 +19,6 @@ fn main() { S { a: 1, b: 1, ..base }; //~^ needless_update - - let base = T { x: 0, y: 0 }; T { ..base }; // no error T { x: 1, ..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 7d24429b5867..27b51b428170 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -16,23 +16,18 @@ fn main() { let _not_less = !(a_value < another_value); //~^ neg_cmp_op_on_partial_ord - - // Not Less or Equal but potentially Greater or Uncomparable. let _not_less_or_equal = !(a_value <= another_value); //~^ neg_cmp_op_on_partial_ord - // Not Greater but potentially Less, Equal or Uncomparable. let _not_greater = !(a_value > another_value); //~^ neg_cmp_op_on_partial_ord - // Not Greater or Equal but potentially Less or Uncomparable. let _not_greater_or_equal = !(a_value >= another_value); //~^ neg_cmp_op_on_partial_ord - // --- Good --- let _not_less = match a_value.partial_cmp(&another_value) { diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr index f6347b7d56cd..3c11d5b8826a 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -8,19 +8,19 @@ LL | let _not_less = !(a_value < another_value); = help: to override `-D warnings` add `#[allow(clippy::neg_cmp_op_on_partial_ord)]` 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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:22:30 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:20: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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:27:24 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:24: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 - --> tests/ui/neg_cmp_op_on_partial_ord.rs:32:33 + --> tests/ui/neg_cmp_op_on_partial_ord.rs:28: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 c366e7d86310..2d8e04c192e4 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -10,8 +10,7 @@ fn test1() { let mut x = 0; loop { - //~^ never_loop - + //~^ never_loop // clippy::never_loop x += 1; @@ -35,7 +34,7 @@ fn test2() { fn test3() { let mut x = 0; loop { - //~^ never_loop + //~^ never_loop // never loops x += 1; @@ -57,11 +56,11 @@ fn test4() { fn test5() { let i = 0; loop { - //~^ never_loop + //~^ never_loop // never loops while i == 0 { - //~^ never_loop + //~^ never_loop // never loops break; @@ -75,7 +74,7 @@ fn test6() { 'outer: loop { x += 1; loop { - //~^ never_loop + //~^ never_loop // never loops if x == 5 { @@ -113,7 +112,7 @@ fn test8() { fn test9() { let x = Some(1); while let Some(y) = x { - //~^ never_loop + //~^ never_loop // never loops return; @@ -122,7 +121,7 @@ fn test9() { fn test10() { for x in 0..10 { - //~^ never_loop + //~^ never_loop // never loops match x { @@ -172,7 +171,7 @@ pub fn test13() { pub fn test14() { let mut a = true; 'outer: while a { - //~^ never_loop + //~^ never_loop // never loops while a { @@ -189,7 +188,7 @@ pub fn test14() { pub fn test15() { 'label: loop { while false { - //~^ never_loop + //~^ never_loop break 'label; } @@ -242,7 +241,7 @@ pub fn test18() { }; // never loops let _ = loop { - //~^ never_loop + //~^ never_loop let Some(x) = x else { return; @@ -265,14 +264,12 @@ pub fn test19() { pub fn test20() { 'a: loop { - //~^ never_loop + //~^ never_loop 'b: { break 'b 'c: { break 'a; //~^ diverging_sub_expression - - }; } } @@ -304,7 +301,7 @@ pub fn test23() { for _ in 0..10 { 'block: { for _ in 0..20 { - //~^ never_loop + //~^ never_loop break 'block; } @@ -389,7 +386,7 @@ pub fn test31(b: bool) { 'a: loop { 'b: { 'c: loop { - //~^ never_loop + //~^ never_loop if b { break 'c } else { break 'b } } @@ -401,12 +398,12 @@ pub fn test31(b: bool) { pub fn test32() { loop { - //~^ never_loop + //~^ never_loop panic!("oh no"); } loop { - //~^ never_loop + //~^ never_loop unimplemented!("not yet"); } diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 6d492f8eb9da..72bf8da51dfe 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -10,7 +10,7 @@ LL | | } = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops - --> tests/ui/never_loop.rs:37:5 + --> tests/ui/never_loop.rs:36:5 | LL | / loop { ... | @@ -19,7 +19,7 @@ LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:59:5 + --> tests/ui/never_loop.rs:58:5 | LL | / loop { ... | @@ -28,7 +28,7 @@ LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:63:9 + --> tests/ui/never_loop.rs:62:9 | LL | / while i == 0 { ... | @@ -36,7 +36,7 @@ LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:77:9 + --> tests/ui/never_loop.rs:76:9 | LL | / loop { ... | @@ -45,7 +45,7 @@ LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:115:5 + --> tests/ui/never_loop.rs:114:5 | LL | / while let Some(y) = x { ... | @@ -53,7 +53,7 @@ LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:124:5 + --> tests/ui/never_loop.rs:123:5 | LL | / for x in 0..10 { ... | @@ -66,7 +66,7 @@ LL | if let Some(x) = (0..10).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> tests/ui/never_loop.rs:174:5 + --> tests/ui/never_loop.rs:173:5 | LL | / 'outer: while a { ... | @@ -75,7 +75,7 @@ LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:191:9 + --> tests/ui/never_loop.rs:190:9 | LL | / while false { LL | | @@ -85,7 +85,7 @@ LL | | } | |_________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:244:13 + --> tests/ui/never_loop.rs:243:13 | LL | let _ = loop { | _____________^ @@ -98,7 +98,7 @@ LL | | }; | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:267:5 + --> tests/ui/never_loop.rs:266:5 | LL | / 'a: loop { LL | | @@ -109,7 +109,7 @@ LL | | } | |_____^ error: sub-expression diverges - --> tests/ui/never_loop.rs:272:17 + --> tests/ui/never_loop.rs:271:17 | LL | break 'a; | ^^^^^^^^ @@ -118,7 +118,7 @@ LL | break 'a; = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: this loop never actually loops - --> tests/ui/never_loop.rs:306:13 + --> tests/ui/never_loop.rs:303:13 | LL | / for _ in 0..20 { LL | | @@ -133,7 +133,7 @@ LL | if let Some(_) = (0..20).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> tests/ui/never_loop.rs:391:13 + --> tests/ui/never_loop.rs:388:13 | LL | / 'c: loop { LL | | @@ -143,7 +143,7 @@ LL | | } | |_____________^ error: this loop never actually loops - --> tests/ui/never_loop.rs:403:5 + --> tests/ui/never_loop.rs:400:5 | LL | / loop { LL | | @@ -153,7 +153,7 @@ LL | | } | |_____^ error: this loop never actually loops - --> tests/ui/never_loop.rs:408:5 + --> tests/ui/never_loop.rs:405:5 | LL | / loop { LL | | diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index fc7dea97e48a..d61973f09b17 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -48,8 +48,7 @@ impl R for S3 { impl S3 { // should trigger the lint pub fn new(_: String) -> impl R { - //~^ new_ret_no_self - + //~^ new_ret_no_self S3 } @@ -83,7 +82,7 @@ struct U; impl U { // should trigger lint pub fn new() -> u32 { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -94,7 +93,7 @@ struct V; impl V { // should trigger lint pub fn new(_: String) -> u32 { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -132,7 +131,7 @@ struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint pub fn new() -> (u32, u32) { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -161,7 +160,7 @@ struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -181,7 +180,7 @@ struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint pub fn new() -> Option { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -237,7 +236,6 @@ mod issue5435 { // should trigger lint as we are in trait definition fn new() -> String; //~^ new_ret_no_self - } pub struct StructRet; impl TraitRet for StructRet { @@ -251,7 +249,6 @@ mod issue5435 { // should trigger lint fn new(_: String) -> String; //~^ new_ret_no_self - } trait TupleReturnerOk { @@ -287,7 +284,7 @@ mod issue5435 { trait TupleReturnerBad { // should trigger lint fn new() -> (u32, u32) { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -316,7 +313,7 @@ mod issue5435 { trait MutPointerReturnerBad { // should trigger lint fn new() -> *mut V { - //~^ new_ret_no_self + //~^ new_ret_no_self unimplemented!(); } @@ -388,7 +385,7 @@ mod issue7344 { impl RetImplTraitNoSelf { // should trigger lint fn new(t: T) -> impl Into { - //~^ new_ret_no_self + //~^ new_ret_no_self 1 } @@ -409,8 +406,7 @@ mod issue7344 { impl RetImplTraitNoSelf2 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { - //~^ new_ret_no_self - + //~^ new_ret_no_self } } diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index e31282c3fb7e..a758c746f918 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -2,7 +2,9 @@ error: methods called `new` usually return `Self` --> tests/ui/new_ret_no_self.rs:50:5 | LL | / pub fn new(_: String) -> impl R { -... | +LL | | +LL | | +LL | | S3 LL | | } | |_____^ | @@ -10,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:85:5 + --> tests/ui/new_ret_no_self.rs:84:5 | LL | / pub fn new() -> u32 { LL | | @@ -20,7 +22,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:96:5 + --> tests/ui/new_ret_no_self.rs:95:5 | LL | / pub fn new(_: String) -> u32 { LL | | @@ -30,7 +32,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:134:5 + --> tests/ui/new_ret_no_self.rs:133:5 | LL | / pub fn new() -> (u32, u32) { LL | | @@ -40,7 +42,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:163:5 + --> tests/ui/new_ret_no_self.rs:162:5 | LL | / pub fn new() -> *mut V { LL | | @@ -50,7 +52,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:183:5 + --> tests/ui/new_ret_no_self.rs:182:5 | LL | / pub fn new() -> Option { LL | | @@ -60,19 +62,19 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:238:9 + --> tests/ui/new_ret_no_self.rs:237:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:252:9 + --> tests/ui/new_ret_no_self.rs:250:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:289:9 + --> tests/ui/new_ret_no_self.rs:286:9 | LL | / fn new() -> (u32, u32) { LL | | @@ -82,7 +84,7 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:318:9 + --> tests/ui/new_ret_no_self.rs:315:9 | LL | / fn new() -> *mut V { LL | | @@ -92,7 +94,7 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:390:9 + --> tests/ui/new_ret_no_self.rs:387:9 | LL | / fn new(t: T) -> impl Into { LL | | @@ -102,10 +104,10 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:411:9 + --> tests/ui/new_ret_no_self.rs:408:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { -... | +LL | | LL | | } | |_________^ diff --git a/tests/ui/new_ret_no_self_overflow.rs b/tests/ui/new_ret_no_self_overflow.rs index db7ce9c4054e..8a85c5662276 100644 --- a/tests/ui/new_ret_no_self_overflow.rs +++ b/tests/ui/new_ret_no_self_overflow.rs @@ -18,7 +18,7 @@ mod issue10041 { impl Bomb2 { pub fn new() -> X { - //~^ ERROR: overflow evaluating the requirement + //~^ ERROR: overflow evaluating the requirement 0i32 } } diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 8fd703200835..277c335cd885 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -17,8 +17,7 @@ impl Default for Foo { impl Foo { pub fn new() -> Foo { - //~^ new_without_default - + //~^ new_without_default Foo } @@ -34,7 +33,7 @@ impl Default for Bar { impl Bar { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Bar } @@ -106,7 +105,7 @@ impl<'c> Default for LtKo<'c> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { - //~^ new_without_default + //~^ new_without_default unimplemented!() } @@ -146,7 +145,7 @@ impl Default for Const { impl Const { pub const fn new() -> Const { - //~^ new_without_default + //~^ new_without_default Const } // While Default is not const, it can still call const functions, so we should lint this } @@ -213,7 +212,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 { - //~^ new_without_default + //~^ new_without_default NewNotEqualToDerive { foo: 1 } } @@ -229,7 +228,7 @@ impl Default for FooGenerics { impl FooGenerics { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self(Default::default()) } @@ -244,7 +243,7 @@ impl Default for BarGenerics { impl BarGenerics { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self(Default::default()) } @@ -263,7 +262,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default todo!() } @@ -319,7 +318,7 @@ where K: std::hash::Hash + Eq + PartialEq, { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self { _kv: None } } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 856f515e4aba..f2844897c93d 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -11,8 +11,7 @@ pub struct Foo; impl Foo { pub fn new() -> Foo { - //~^ new_without_default - + //~^ new_without_default Foo } @@ -22,7 +21,7 @@ pub struct Bar; impl Bar { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Bar } @@ -88,7 +87,7 @@ pub struct LtKo<'a> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { - //~^ new_without_default + //~^ new_without_default unimplemented!() } @@ -122,7 +121,7 @@ pub struct Const; impl Const { pub const fn new() -> Const { - //~^ new_without_default + //~^ new_without_default Const } // While Default is not const, it can still call const functions, so we should lint this } @@ -183,7 +182,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 { - //~^ new_without_default + //~^ new_without_default NewNotEqualToDerive { foo: 1 } } @@ -193,7 +192,7 @@ impl NewNotEqualToDerive { pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self(Default::default()) } @@ -202,7 +201,7 @@ impl FooGenerics { pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self(Default::default()) } @@ -215,7 +214,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default todo!() } @@ -262,7 +261,7 @@ where K: std::hash::Hash + Eq + PartialEq, { pub fn new() -> Self { - //~^ new_without_default + //~^ new_without_default Self { _kv: None } } } diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 1a122d341a08..70a65aba464b 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -2,7 +2,9 @@ error: you should consider adding a `Default` implementation for `Foo` --> tests/ui/new_without_default.rs:13:5 | LL | / pub fn new() -> Foo { -... | +LL | | +LL | | +LL | | Foo LL | | } | |_____^ | @@ -18,7 +20,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> tests/ui/new_without_default.rs:24:5 + --> tests/ui/new_without_default.rs:23:5 | LL | / pub fn new() -> Self { LL | | @@ -37,7 +39,7 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> tests/ui/new_without_default.rs:90:5 + --> tests/ui/new_without_default.rs:89:5 | LL | / pub fn new() -> LtKo<'c> { LL | | @@ -56,7 +58,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Const` - --> tests/ui/new_without_default.rs:124:5 + --> tests/ui/new_without_default.rs:123:5 | LL | / pub const fn new() -> Const { LL | | @@ -74,7 +76,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> tests/ui/new_without_default.rs:185:5 + --> tests/ui/new_without_default.rs:184:5 | LL | / pub fn new() -> Self { LL | | @@ -93,7 +95,7 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> tests/ui/new_without_default.rs:195:5 + --> tests/ui/new_without_default.rs:194:5 | LL | / pub fn new() -> Self { LL | | @@ -112,7 +114,7 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> tests/ui/new_without_default.rs:204:5 + --> tests/ui/new_without_default.rs:203:5 | LL | / pub fn new() -> Self { LL | | @@ -131,7 +133,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:217:9 + --> tests/ui/new_without_default.rs:216:9 | LL | / pub fn new() -> Self { LL | | @@ -152,7 +154,7 @@ LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> tests/ui/new_without_default.rs:264:5 + --> tests/ui/new_without_default.rs:263:5 | LL | / pub fn new() -> Self { LL | | diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index cd992aed15e2..703c2a3d9847 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -186,7 +186,6 @@ fn main() { let _unused = 1; //~^ no_effect_underscore_binding - let _penguin = || println!("Some helpful closure"); //~^ no_effect_underscore_binding diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 617a43aaf60d..58a9380cbfde 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -149,19 +149,19 @@ LL | let _unused = 1; = help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]` error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:190:9 + --> tests/ui/no_effect.rs:189:9 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:193:9 + --> tests/ui/no_effect.rs:192:9 | LL | let _duck = Struct { field: 0 }; | ^^^^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect.rs:196:9 + --> tests/ui/no_effect.rs:195:9 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^ diff --git a/tests/ui/no_effect_async_fn.rs b/tests/ui/no_effect_async_fn.rs index 6fb3ccab8a08..a036a7e27bef 100644 --- a/tests/ui/no_effect_async_fn.rs +++ b/tests/ui/no_effect_async_fn.rs @@ -13,7 +13,6 @@ impl AsyncTrait for Bar { let _a = 0; //~^ no_effect_underscore_binding - // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _b = num(); @@ -21,7 +20,6 @@ impl AsyncTrait for Bar { let _c = 0; //~^ no_effect_underscore_binding - // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _d = num(); } @@ -34,7 +32,6 @@ async fn foo(_i: u64) { let _a = 0; //~^ no_effect_underscore_binding - // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _b = num(); @@ -42,7 +39,6 @@ async fn foo(_i: u64) { let _c = 0; //~^ no_effect_underscore_binding - // Shouldn't lint `binding to `_` prefixed variable with no side-effect` let _d = num(); } diff --git a/tests/ui/no_effect_async_fn.stderr b/tests/ui/no_effect_async_fn.stderr index 96ad7b9d6075..2325eb9aae59 100644 --- a/tests/ui/no_effect_async_fn.stderr +++ b/tests/ui/no_effect_async_fn.stderr @@ -1,5 +1,5 @@ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:21:17 + --> tests/ui/no_effect_async_fn.rs:20:17 | LL | let _c = 0; | ^^ @@ -14,13 +14,13 @@ LL | let _a = 0; | ^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:42:13 + --> tests/ui/no_effect_async_fn.rs:39:13 | LL | let _c = 0; | ^^ error: binding to `_` prefixed variable with no side-effect - --> tests/ui/no_effect_async_fn.rs:34:9 + --> tests/ui/no_effect_async_fn.rs:32:9 | LL | let _a = 0; | ^^ diff --git a/tests/ui/no_effect_replace.rs b/tests/ui/no_effect_replace.rs index dc8e66f69ff5..245898f50740 100644 --- a/tests/ui/no_effect_replace.rs +++ b/tests/ui/no_effect_replace.rs @@ -4,14 +4,12 @@ fn main() { let _ = "12345".replace('1', "1"); //~^ no_effect_replace - let _ = "12345".replace("12", "12"); //~^ no_effect_replace let _ = String::new().replace("12", "12"); //~^ no_effect_replace - let _ = "12345".replacen('1', "1", 1); //~^ no_effect_replace @@ -21,7 +19,6 @@ fn main() { let _ = String::new().replacen("12", "12", 1); //~^ no_effect_replace - let _ = "12345".replace("12", "22"); let _ = "12345".replacen("12", "22", 1); diff --git a/tests/ui/no_effect_replace.stderr b/tests/ui/no_effect_replace.stderr index 3861d042e6f5..33d13b1d72e8 100644 --- a/tests/ui/no_effect_replace.stderr +++ b/tests/ui/no_effect_replace.stderr @@ -8,43 +8,43 @@ LL | let _ = "12345".replace('1', "1"); = help: to override `-D warnings` add `#[allow(clippy::no_effect_replace)]` error: replacing text with itself - --> tests/ui/no_effect_replace.rs:8:13 + --> tests/ui/no_effect_replace.rs:7:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:11:13 + --> tests/ui/no_effect_replace.rs:10:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:15:13 + --> tests/ui/no_effect_replace.rs:13:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:18:13 + --> tests/ui/no_effect_replace.rs:16:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:21:13 + --> tests/ui/no_effect_replace.rs:19:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:29:13 + --> tests/ui/no_effect_replace.rs:26:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:34:13 + --> tests/ui/no_effect_replace.rs:31:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index 8bfd8367f104..4ba2fe07785d 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -8,8 +8,6 @@ fn a() -> u32 { { 0u32; //~^ no_effect - - } 0 } @@ -18,7 +16,6 @@ async fn b() -> u32 { { 0u32; //~^ no_effect - } 0 } @@ -28,7 +25,6 @@ async fn c() -> C { { 0i32 as C; //~^ no_effect - } 0 } @@ -49,7 +45,6 @@ fn e() -> u32 { // mismatched types 0u16; //~^ no_effect - } 0 } @@ -58,7 +53,6 @@ fn f() -> [u16; 1] { { [1u16]; //~^ no_effect - } [1] } @@ -67,7 +61,6 @@ fn g() -> ControlFlow<()> { { ControlFlow::Break::<()>(()); //~^ no_effect - } ControlFlow::Continue(()) } @@ -86,7 +79,6 @@ fn i() -> () { // does not suggest on function with explicit unit return type (); //~^ no_effect - } () } @@ -96,7 +88,6 @@ fn j() { // does not suggest on function without explicit return type (); //~^ no_effect - } () } diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index f6ff2ded33e0..e7bf7e4cd4f4 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -10,7 +10,7 @@ LL | 0u32; = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> tests/ui/no_effect_return.rs:19:9 + --> tests/ui/no_effect_return.rs:17:9 | LL | 0u32; | -^^^^ @@ -18,7 +18,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:29:9 + --> tests/ui/no_effect_return.rs:26:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -26,19 +26,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:39:9 + --> tests/ui/no_effect_return.rs:35:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:50:9 + --> tests/ui/no_effect_return.rs:46:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:59:9 + --> tests/ui/no_effect_return.rs:54:9 | LL | [1u16]; | -^^^^^^ @@ -46,7 +46,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:68:9 + --> tests/ui/no_effect_return.rs:62:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:87:9 + --> tests/ui/no_effect_return.rs:80:9 | LL | (); | ^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:97:9 + --> tests/ui/no_effect_return.rs:89:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index 99b731d4a597..0d09b3ceecde 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -24,7 +24,7 @@ unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} #[unsafe(no_mangle)] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( -//~^ no_mangle_with_rust_abi + //~^ no_mangle_with_rust_abi arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/tests/ui/no_mangle_with_rust_abi_2021.rs b/tests/ui/no_mangle_with_rust_abi_2021.rs index eba653889064..3d5c70cad2f3 100644 --- a/tests/ui/no_mangle_with_rust_abi_2021.rs +++ b/tests/ui/no_mangle_with_rust_abi_2021.rs @@ -28,7 +28,7 @@ unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} #[no_mangle] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( -//~^ no_mangle_with_rust_abi + //~^ no_mangle_with_rust_abi arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/tests/ui/non_canonical_clone_impl.rs b/tests/ui/non_canonical_clone_impl.rs index d735122e1845..7d101915517f 100644 --- a/tests/ui/non_canonical_clone_impl.rs +++ b/tests/ui/non_canonical_clone_impl.rs @@ -12,12 +12,12 @@ struct A(u32); impl Clone for A { fn clone(&self) -> Self { - //~^ non_canonical_clone_impl + //~^ non_canonical_clone_impl Self(self.0) } fn clone_from(&mut self, source: &Self) { - //~^ non_canonical_clone_impl + //~^ non_canonical_clone_impl source.clone(); *self = source.clone(); } @@ -85,12 +85,12 @@ struct F(u32); impl Clone for F { fn clone(&self) -> Self { - //~^ non_canonical_clone_impl + //~^ non_canonical_clone_impl Self(self.0) } fn clone_from(&mut self, source: &Self) { - //~^ non_canonical_clone_impl + //~^ non_canonical_clone_impl source.clone(); *self = source.clone(); } diff --git a/tests/ui/non_canonical_partial_ord_impl.fixed b/tests/ui/non_canonical_partial_ord_impl.fixed index 7d1211522f18..8774c666db11 100644 --- a/tests/ui/non_canonical_partial_ord_impl.fixed +++ b/tests/ui/non_canonical_partial_ord_impl.fixed @@ -14,7 +14,7 @@ impl Ord for A { } impl PartialOrd for A { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } @@ -47,7 +47,7 @@ impl Ord for C { } impl PartialOrd for C { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } diff --git a/tests/ui/non_canonical_partial_ord_impl.rs b/tests/ui/non_canonical_partial_ord_impl.rs index 4f3310557992..568b97c8fff7 100644 --- a/tests/ui/non_canonical_partial_ord_impl.rs +++ b/tests/ui/non_canonical_partial_ord_impl.rs @@ -14,7 +14,7 @@ impl Ord for A { } impl PartialOrd for A { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { todo!(); } @@ -49,7 +49,7 @@ impl Ord for C { } impl PartialOrd for C { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl fn partial_cmp(&self, _: &Self) -> Option { todo!(); } diff --git a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs index cbd1ae57be4a..99cd7ebac60c 100644 --- a/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs +++ b/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs @@ -21,7 +21,7 @@ impl cmp::Ord for A { } impl PartialOrd for A { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl 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 @@ -45,7 +45,7 @@ impl cmp::Ord for B { } impl PartialOrd for B { -//~^ non_canonical_partial_ord_impl + //~^ non_canonical_partial_ord_impl fn partial_cmp(&self, other: &Self) -> Option { // This calls `B.cmp`, not `Ord::cmp`! Some(self.cmp(other)) diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index 69e90c3d670b..b772c754f8b7 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -25,12 +25,12 @@ impl MaybeInst { } fn underscores_and_numbers() { -let _1 = 1; -//~^ just_underscores_and_digits -let ____1 = 1; -//~^ just_underscores_and_digits -let __1___2 = 12; -//~^ just_underscores_and_digits + let _1 = 1; + //~^ just_underscores_and_digits + let ____1 = 1; + //~^ just_underscores_and_digits + let __1___2 = 12; + //~^ just_underscores_and_digits let _1_ok = 1; } @@ -51,12 +51,12 @@ struct Bar; impl Bar { fn bar() { -let _1 = 1; -//~^ just_underscores_and_digits -let ____1 = 1; -//~^ just_underscores_and_digits -let __1___2 = 12; -//~^ just_underscores_and_digits + let _1 = 1; + //~^ just_underscores_and_digits + let ____1 = 1; + //~^ just_underscores_and_digits + let __1___2 = 12; + //~^ just_underscores_and_digits let _1_ok = 1; } } diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index 7aa67e1ca415..3bd77a730fe7 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -1,41 +1,41 @@ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:28:5 + --> tests/ui/non_expressive_names.rs:28:9 | -LL | let _1 = 1; - | ^^ +LL | let _1 = 1; + | ^^ | = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::just_underscores_and_digits)]` error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:30:5 + --> tests/ui/non_expressive_names.rs:30:9 | -LL | let ____1 = 1; - | ^^^^^ +LL | let ____1 = 1; + | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:32:5 + --> tests/ui/non_expressive_names.rs:32:9 | -LL | let __1___2 = 12; - | ^^^^^^^ +LL | let __1___2 = 12; + | ^^^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:54:5 + --> tests/ui/non_expressive_names.rs:54:13 | -LL | let _1 = 1; - | ^^ +LL | let _1 = 1; + | ^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:56:5 + --> tests/ui/non_expressive_names.rs:56:13 | -LL | let ____1 = 1; - | ^^^^^ +LL | let ____1 = 1; + | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:58:5 + --> tests/ui/non_expressive_names.rs:58:13 | -LL | let __1___2 = 12; - | ^^^^^^^ +LL | let __1___2 = 12; + | ^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/non_zero_suggestions.fixed b/tests/ui/non_zero_suggestions.fixed index 1459832be75e..4573896ecd67 100644 --- a/tests/ui/non_zero_suggestions.fixed +++ b/tests/ui/non_zero_suggestions.fixed @@ -9,22 +9,18 @@ fn main() { let r1 = x / NonZeroU64::from(y); //~^ non_zero_suggestions - let r2 = x % NonZeroU64::from(y); //~^ non_zero_suggestions - // U16 -> U32 let a: u32 = 50; let b = NonZeroU16::new(5).unwrap(); let r3 = a / NonZeroU32::from(b); //~^ non_zero_suggestions - let x = NonZeroU64::from(NonZeroU32::new(5).unwrap()); //~^ non_zero_suggestions - /// Negative test cases (lint should not trigger) // Left hand side expressions should not be triggered let c: u32 = 50; @@ -55,7 +51,6 @@ fn main() { fn divide_numbers(x: u64, y: NonZeroU32) -> u64 { x / NonZeroU64::from(y) //~^ non_zero_suggestions - } struct Calculator { @@ -66,6 +61,5 @@ impl Calculator { fn divide(&self, divisor: NonZeroU32) -> u64 { self.value / NonZeroU64::from(divisor) //~^ non_zero_suggestions - } } diff --git a/tests/ui/non_zero_suggestions.rs b/tests/ui/non_zero_suggestions.rs index 72a38131a132..3e7081e0c1c0 100644 --- a/tests/ui/non_zero_suggestions.rs +++ b/tests/ui/non_zero_suggestions.rs @@ -9,22 +9,18 @@ fn main() { let r1 = x / u64::from(y.get()); //~^ non_zero_suggestions - let r2 = x % u64::from(y.get()); //~^ non_zero_suggestions - // U16 -> U32 let a: u32 = 50; let b = NonZeroU16::new(5).unwrap(); let r3 = a / u32::from(b.get()); //~^ non_zero_suggestions - let x = u64::from(NonZeroU32::new(5).unwrap().get()); //~^ non_zero_suggestions - /// Negative test cases (lint should not trigger) // Left hand side expressions should not be triggered let c: u32 = 50; @@ -55,7 +51,6 @@ fn main() { fn divide_numbers(x: u64, y: NonZeroU32) -> u64 { x / u64::from(y.get()) //~^ non_zero_suggestions - } struct Calculator { @@ -66,6 +61,5 @@ impl Calculator { fn divide(&self, divisor: NonZeroU32) -> u64 { self.value / u64::from(divisor.get()) //~^ non_zero_suggestions - } } diff --git a/tests/ui/non_zero_suggestions.stderr b/tests/ui/non_zero_suggestions.stderr index f7ed71dcf56c..7a57f7983be7 100644 --- a/tests/ui/non_zero_suggestions.stderr +++ b/tests/ui/non_zero_suggestions.stderr @@ -8,31 +8,31 @@ LL | let r1 = x / u64::from(y.get()); = help: to override `-D warnings` add `#[allow(clippy::non_zero_suggestions)]` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:13:18 + --> tests/ui/non_zero_suggestions.rs:12:18 | LL | let r2 = x % u64::from(y.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` error: consider using `NonZeroU32::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:20:18 + --> tests/ui/non_zero_suggestions.rs:18:18 | LL | let r3 = a / u32::from(b.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU32::from(b)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:24:13 + --> tests/ui/non_zero_suggestions.rs:21:13 | LL | let x = u64::from(NonZeroU32::new(5).unwrap().get()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(NonZeroU32::new(5).unwrap())` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:56:9 + --> tests/ui/non_zero_suggestions.rs:52:9 | LL | x / u64::from(y.get()) | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:67:22 + --> tests/ui/non_zero_suggestions.rs:62:22 | LL | self.value / u64::from(divisor.get()) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(divisor)` diff --git a/tests/ui/non_zero_suggestions_unfixable.rs b/tests/ui/non_zero_suggestions_unfixable.rs index 4adbdf7bcc74..1224356236c7 100644 --- a/tests/ui/non_zero_suggestions_unfixable.rs +++ b/tests/ui/non_zero_suggestions_unfixable.rs @@ -6,7 +6,6 @@ fn main() { let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); //~^ non_zero_suggestions - let n = NonZeroU32::new(20).unwrap(); let y = u64::from(n.get()); //~^ non_zero_suggestions @@ -20,7 +19,6 @@ fn main() { fn return_non_zero(x: u64, y: NonZeroU32) -> u64 { u64::from(y.get()) //~^ non_zero_suggestions - } fn some_fn_that_only_takes_u64(_: u64) {} diff --git a/tests/ui/non_zero_suggestions_unfixable.stderr b/tests/ui/non_zero_suggestions_unfixable.stderr index dff70dada26d..d2ac983d4f7f 100644 --- a/tests/ui/non_zero_suggestions_unfixable.stderr +++ b/tests/ui/non_zero_suggestions_unfixable.stderr @@ -8,13 +8,13 @@ LL | let x: u64 = u64::from(NonZeroU32::new(5).unwrap().get()); = help: to override `-D warnings` add `#[allow(clippy::non_zero_suggestions)]` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions_unfixable.rs:11:13 + --> tests/ui/non_zero_suggestions_unfixable.rs:10:13 | LL | let y = u64::from(n.get()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(n)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions_unfixable.rs:21:5 + --> tests/ui/non_zero_suggestions_unfixable.rs:20:5 | LL | u64::from(y.get()) | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 1d41b2b9a84c..a155ff3508be 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -17,7 +17,6 @@ fn main() { let _ = !true; //~^ nonminimal_bool - let _ = !false; //~^ nonminimal_bool @@ -38,7 +37,6 @@ fn main() { let _ = !a && !(b && c); //~^ nonminimal_bool - } fn equality_stuff() { @@ -60,7 +58,6 @@ fn equality_stuff() { let _ = a != b && !(a != b && c == d); //~^ nonminimal_bool - } fn issue3847(a: u32, b: u32) -> bool { @@ -91,7 +88,7 @@ fn check_expect() { fn issue9428() { if matches!(true, true) && true { - //~^ nonminimal_bool + //~^ nonminimal_bool println!("foo"); } @@ -171,35 +168,35 @@ fn issue11932() { fn issue_5794() { let a = 0; -if !(12 == a) {} -//~^ nonminimal_bool -if !(a == 12) {} -//~^ nonminimal_bool -if !(12 != a) {} -//~^ nonminimal_bool -if !(a != 12) {} -//~^ nonminimal_bool + if !(12 == a) {} + //~^ nonminimal_bool + if !(a == 12) {} + //~^ nonminimal_bool + if !(12 != a) {} + //~^ nonminimal_bool + if !(a != 12) {} + //~^ nonminimal_bool let b = true; let c = false; -if !b == true {} -//~^ nonminimal_bool -//~| bool_comparison -//~| bool_comparison -if !b != true {} -//~^ nonminimal_bool -//~| bool_comparison -if true == !b {} -//~^ nonminimal_bool -//~| bool_comparison -//~| bool_comparison -if true != !b {} -//~^ nonminimal_bool -//~| bool_comparison -if !b == !c {} -//~^ nonminimal_bool -if !b != !c {} -//~^ nonminimal_bool + if !b == true {} + //~^ nonminimal_bool + //~| bool_comparison + //~| bool_comparison + if !b != true {} + //~^ nonminimal_bool + //~| bool_comparison + if true == !b {} + //~^ nonminimal_bool + //~| bool_comparison + //~| bool_comparison + if true != !b {} + //~^ nonminimal_bool + //~| bool_comparison + if !b == !c {} + //~^ nonminimal_bool + if !b != !c {} + //~^ nonminimal_bool } fn issue_12371(x: usize) -> bool { @@ -215,7 +212,7 @@ fn many_ops(a: bool, b: bool, c: bool, d: bool, e: bool, f: bool) -> bool { fn issue14184(a: f32, b: bool) { if !(a < 2.0 && !b) { - //~^ nonminimal_bool + //~^ nonminimal_bool println!("Hi"); } } diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index ca2c7ab8232a..06d3615c6e26 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -8,43 +8,43 @@ LL | let _ = !true; = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:21:13 + --> tests/ui/nonminimal_bool.rs:20:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:24:13 + --> tests/ui/nonminimal_bool.rs:23:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:27:13 + --> tests/ui/nonminimal_bool.rs:26:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:33:13 + --> tests/ui/nonminimal_bool.rs:32:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:36:13 + --> tests/ui/nonminimal_bool.rs:35:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:39:13 + --> tests/ui/nonminimal_bool.rs:38:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:49:13 + --> tests/ui/nonminimal_bool.rs:47:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:52:13 + --> tests/ui/nonminimal_bool.rs:50:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:55:13 + --> tests/ui/nonminimal_bool.rs:53:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:58:13 + --> tests/ui/nonminimal_bool.rs:56:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:61:13 + --> tests/ui/nonminimal_bool.rs:59:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,112 +109,112 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:93:8 + --> tests/ui/nonminimal_bool.rs:90:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:174:4 + --> tests/ui/nonminimal_bool.rs:171:8 | -LL | if !(12 == a) {} - | ^^^^^^^^^^ help: try: `(12 != a)` +LL | if !(12 == a) {} + | ^^^^^^^^^^ help: try: `(12 != a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:176:4 + --> tests/ui/nonminimal_bool.rs:173:8 | -LL | if !(a == 12) {} - | ^^^^^^^^^^ help: try: `(a != 12)` +LL | if !(a == 12) {} + | ^^^^^^^^^^ help: try: `(a != 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:178:4 + --> tests/ui/nonminimal_bool.rs:175:8 | -LL | if !(12 != a) {} - | ^^^^^^^^^^ help: try: `(12 == a)` +LL | if !(12 != a) {} + | ^^^^^^^^^^ help: try: `(12 == a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:180:4 + --> tests/ui/nonminimal_bool.rs:177:8 | -LL | if !(a != 12) {} - | ^^^^^^^^^^ help: try: `(a == 12)` +LL | if !(a != 12) {} + | ^^^^^^^^^^ help: try: `(a == 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:185:4 + --> tests/ui/nonminimal_bool.rs:182:8 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try: `b != true` +LL | if !b == true {} + | ^^^^^^^^^^ help: try: `b != true` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:185:4 + --> tests/ui/nonminimal_bool.rs:182:8 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` +LL | if !b == true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `b != true` | = note: `-D clippy::bool-comparison` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:185:4 + --> tests/ui/nonminimal_bool.rs:182:8 | -LL | if !b == true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!b` +LL | if !b == true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:189:4 + --> tests/ui/nonminimal_bool.rs:186:8 | -LL | if !b != true {} - | ^^^^^^^^^^ help: try: `b == true` +LL | if !b != true {} + | ^^^^^^^^^^ help: try: `b == true` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:189:4 + --> tests/ui/nonminimal_bool.rs:186:8 | -LL | if !b != true {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` +LL | if !b != true {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:192:4 + --> tests/ui/nonminimal_bool.rs:189:8 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try: `true != b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try: `true != b` error: this comparison might be written more concisely - --> tests/ui/nonminimal_bool.rs:192:4 + --> tests/ui/nonminimal_bool.rs:189:8 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `true != b` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:192:4 + --> tests/ui/nonminimal_bool.rs:189:8 | -LL | if true == !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!b` +LL | if true == !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:196:4 + --> tests/ui/nonminimal_bool.rs:193:8 | -LL | if true != !b {} - | ^^^^^^^^^^ help: try: `true == b` +LL | if true != !b {} + | ^^^^^^^^^^ help: try: `true == b` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:196:4 + --> tests/ui/nonminimal_bool.rs:193:8 | -LL | if true != !b {} - | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` +LL | if true != !b {} + | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:199:4 + --> tests/ui/nonminimal_bool.rs:196:8 | -LL | if !b == !c {} - | ^^^^^^^^ help: try: `b == c` +LL | if !b == !c {} + | ^^^^^^^^ help: try: `b == c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:201:4 + --> tests/ui/nonminimal_bool.rs:198:8 | -LL | if !b != !c {} - | ^^^^^^^^ help: try: `b != c` +LL | if !b != !c {} + | ^^^^^^^^ help: try: `b != c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:217:8 + --> tests/ui/nonminimal_bool.rs:214:8 | LL | if !(a < 2.0 && !b) { | ^^^^^^^^^^^^^^^^ help: try: `!(a < 2.0) || b` diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index 4b11dc2b5dda..c2377491f25b 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -123,34 +123,34 @@ fn dont_warn_for_negated_partial_ord_comparison() { fn issue_12625() { let a = 0; let b = 0; -if ((a as u64) < b) {} -//~^ nonminimal_bool -if ((a as u64) < b) {} -//~^ nonminimal_bool -if (a as u64 > b) {} -//~^ nonminimal_bool + if ((a as u64) < b) {} + //~^ nonminimal_bool + if ((a as u64) < b) {} + //~^ nonminimal_bool + if (a as u64 > b) {} + //~^ nonminimal_bool } fn issue_12761() { let a = 0; let b = 0; let c = 0; -if (a < b) as i32 == c {} -//~^ nonminimal_bool -if (a < b) | (a > c) {} -//~^ nonminimal_bool -//~| nonminimal_bool + if (a < b) as i32 == c {} + //~^ nonminimal_bool + if (a < b) | (a > c) {} + //~^ nonminimal_bool + //~| nonminimal_bool let opt: Option = Some(1); let res: Result = Ok(1); -if res.is_err() as i32 == c {} -//~^ nonminimal_bool -if res.is_err() | opt.is_some() {} -//~^ nonminimal_bool -//~| nonminimal_bool + if res.is_err() as i32 == c {} + //~^ nonminimal_bool + if res.is_err() | opt.is_some() {} + //~^ nonminimal_bool + //~| nonminimal_bool fn a(a: bool) -> bool { -(4 <= 3).b() -//~^ nonminimal_bool + (4 <= 3).b() + //~^ nonminimal_bool } trait B { @@ -175,18 +175,18 @@ fn issue_13436() { _ = opt.is_some_and(|x| x == 1000); _ = opt.is_some_and(|x| x != 1000); _ = opt.is_some_and(not_zero); -_ = opt.is_none_or(|x| x >= 1000); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x > 1000); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x <= 1000); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x < 1000); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x != 1000); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x == 1000); -//~^ nonminimal_bool + _ = opt.is_none_or(|x| x >= 1000); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x > 1000); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x <= 1000); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x < 1000); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x != 1000); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x == 1000); + //~^ nonminimal_bool _ = !opt.is_some_and(not_zero); _ = opt.is_none_or(|x| x < 1000); _ = opt.is_none_or(|x| x <= 1000); @@ -195,45 +195,45 @@ _ = opt.is_none_or(|x| x == 1000); _ = opt.is_none_or(|x| x == 1000); _ = opt.is_none_or(|x| x != 1000); _ = opt.is_none_or(not_zero); -_ = opt.is_some_and(|x| x >= 1000); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x > 1000); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x <= 1000); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x < 1000); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x != 1000); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x == 1000); -//~^ nonminimal_bool + _ = opt.is_some_and(|x| x >= 1000); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x > 1000); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x <= 1000); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x < 1000); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x != 1000); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x == 1000); + //~^ nonminimal_bool _ = !opt.is_none_or(not_zero); let opt = Some(true); _ = opt.is_some_and(|x| x); _ = opt.is_some_and(|x| !x); _ = !opt.is_some_and(|x| x); -_ = opt.is_none_or(|x| x); -//~^ nonminimal_bool + _ = opt.is_none_or(|x| x); + //~^ nonminimal_bool _ = opt.is_none_or(|x| x); _ = opt.is_none_or(|x| !x); _ = !opt.is_none_or(|x| x); -_ = opt.is_some_and(|x| x); -//~^ nonminimal_bool + _ = opt.is_some_and(|x| x); + //~^ nonminimal_bool let opt: Option> = Some(Ok(123)); _ = opt.is_some_and(|x| x.is_ok()); _ = opt.is_some_and(|x| x.is_err()); _ = opt.is_none_or(|x| x.is_ok()); _ = opt.is_none_or(|x| x.is_err()); -_ = opt.is_none_or(|x| x.is_err()); -//~^ nonminimal_bool -_ = opt.is_none_or(|x| x.is_ok()); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x.is_err()); -//~^ nonminimal_bool -_ = opt.is_some_and(|x| x.is_ok()); -//~^ nonminimal_bool + _ = opt.is_none_or(|x| x.is_err()); + //~^ nonminimal_bool + _ = opt.is_none_or(|x| x.is_ok()); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x.is_err()); + //~^ nonminimal_bool + _ = opt.is_some_and(|x| x.is_ok()); + //~^ nonminimal_bool #[clippy::msrv = "1.81"] fn before_stabilization() { diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index 3e574de2d156..1ae0f0064c6b 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -123,34 +123,34 @@ fn dont_warn_for_negated_partial_ord_comparison() { fn issue_12625() { let a = 0; let b = 0; -if !(a as u64 >= b) {} -//~^ nonminimal_bool -if !((a as u64) >= b) {} -//~^ nonminimal_bool -if !(a as u64 <= b) {} -//~^ nonminimal_bool + if !(a as u64 >= b) {} + //~^ nonminimal_bool + if !((a as u64) >= b) {} + //~^ nonminimal_bool + if !(a as u64 <= b) {} + //~^ nonminimal_bool } fn issue_12761() { let a = 0; let b = 0; let c = 0; -if !(a >= b) as i32 == c {} -//~^ nonminimal_bool -if !(a >= b) | !(a <= c) {} -//~^ nonminimal_bool -//~| nonminimal_bool + if !(a >= b) as i32 == c {} + //~^ nonminimal_bool + if !(a >= b) | !(a <= c) {} + //~^ nonminimal_bool + //~| nonminimal_bool let opt: Option = Some(1); let res: Result = Ok(1); -if !res.is_ok() as i32 == c {} -//~^ nonminimal_bool -if !res.is_ok() | !opt.is_none() {} -//~^ nonminimal_bool -//~| nonminimal_bool + if !res.is_ok() as i32 == c {} + //~^ nonminimal_bool + if !res.is_ok() | !opt.is_none() {} + //~^ nonminimal_bool + //~| nonminimal_bool fn a(a: bool) -> bool { -(!(4 > 3)).b() -//~^ nonminimal_bool + (!(4 > 3)).b() + //~^ nonminimal_bool } trait B { @@ -175,18 +175,18 @@ fn issue_13436() { _ = opt.is_some_and(|x| x == 1000); _ = opt.is_some_and(|x| x != 1000); _ = opt.is_some_and(not_zero); -_ = !opt.is_some_and(|x| x < 1000); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x <= 1000); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x > 1000); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x >= 1000); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x == 1000); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x != 1000); -//~^ nonminimal_bool + _ = !opt.is_some_and(|x| x < 1000); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x <= 1000); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x > 1000); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x >= 1000); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x == 1000); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x != 1000); + //~^ nonminimal_bool _ = !opt.is_some_and(not_zero); _ = opt.is_none_or(|x| x < 1000); _ = opt.is_none_or(|x| x <= 1000); @@ -195,45 +195,45 @@ _ = !opt.is_some_and(|x| x != 1000); _ = opt.is_none_or(|x| x == 1000); _ = opt.is_none_or(|x| x != 1000); _ = opt.is_none_or(not_zero); -_ = !opt.is_none_or(|x| x < 1000); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x <= 1000); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x > 1000); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x >= 1000); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x == 1000); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x != 1000); -//~^ nonminimal_bool + _ = !opt.is_none_or(|x| x < 1000); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x <= 1000); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x > 1000); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x >= 1000); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x == 1000); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x != 1000); + //~^ nonminimal_bool _ = !opt.is_none_or(not_zero); let opt = Some(true); _ = opt.is_some_and(|x| x); _ = opt.is_some_and(|x| !x); _ = !opt.is_some_and(|x| x); -_ = !opt.is_some_and(|x| !x); -//~^ nonminimal_bool + _ = !opt.is_some_and(|x| !x); + //~^ nonminimal_bool _ = opt.is_none_or(|x| x); _ = opt.is_none_or(|x| !x); _ = !opt.is_none_or(|x| x); -_ = !opt.is_none_or(|x| !x); -//~^ nonminimal_bool + _ = !opt.is_none_or(|x| !x); + //~^ nonminimal_bool let opt: Option> = Some(Ok(123)); _ = opt.is_some_and(|x| x.is_ok()); _ = opt.is_some_and(|x| x.is_err()); _ = opt.is_none_or(|x| x.is_ok()); _ = opt.is_none_or(|x| x.is_err()); -_ = !opt.is_some_and(|x| x.is_ok()); -//~^ nonminimal_bool -_ = !opt.is_some_and(|x| x.is_err()); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x.is_ok()); -//~^ nonminimal_bool -_ = !opt.is_none_or(|x| x.is_err()); -//~^ nonminimal_bool + _ = !opt.is_some_and(|x| x.is_ok()); + //~^ nonminimal_bool + _ = !opt.is_some_and(|x| x.is_err()); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x.is_ok()); + //~^ nonminimal_bool + _ = !opt.is_none_or(|x| x.is_err()); + //~^ nonminimal_bool #[clippy::msrv = "1.81"] fn before_stabilization() { diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index 3f03b8613596..b5155b3b1696 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -80,172 +80,172 @@ LL | if !res.is_none() {} | ^^^^^^^^^^^^^^ help: try: `res.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:126:4 + --> tests/ui/nonminimal_bool_methods.rs:126:8 | -LL | if !(a as u64 >= b) {} - | ^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` +LL | if !(a as u64 >= b) {} + | ^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:128:4 + --> tests/ui/nonminimal_bool_methods.rs:128:8 | -LL | if !((a as u64) >= b) {} - | ^^^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` +LL | if !((a as u64) >= b) {} + | ^^^^^^^^^^^^^^^^^^ help: try: `((a as u64) < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:130:4 + --> tests/ui/nonminimal_bool_methods.rs:130:8 | -LL | if !(a as u64 <= b) {} - | ^^^^^^^^^^^^^^^^ help: try: `(a as u64 > b)` +LL | if !(a as u64 <= b) {} + | ^^^^^^^^^^^^^^^^ help: try: `(a as u64 > b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:138:4 + --> tests/ui/nonminimal_bool_methods.rs:138:8 | -LL | if !(a >= b) as i32 == c {} - | ^^^^^^^^^ help: try: `(a < b)` +LL | if !(a >= b) as i32 == c {} + | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:140:4 + --> tests/ui/nonminimal_bool_methods.rs:140:8 | -LL | if !(a >= b) | !(a <= c) {} - | ^^^^^^^^^ help: try: `(a < b)` +LL | if !(a >= b) | !(a <= c) {} + | ^^^^^^^^^ help: try: `(a < b)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:140:16 + --> tests/ui/nonminimal_bool_methods.rs:140:20 | -LL | if !(a >= b) | !(a <= c) {} - | ^^^^^^^^^ help: try: `(a > c)` +LL | if !(a >= b) | !(a <= c) {} + | ^^^^^^^^^ help: try: `(a > c)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:145:4 + --> tests/ui/nonminimal_bool_methods.rs:145:8 | -LL | if !res.is_ok() as i32 == c {} - | ^^^^^^^^^^^^ help: try: `res.is_err()` +LL | if !res.is_ok() as i32 == c {} + | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:147:4 + --> tests/ui/nonminimal_bool_methods.rs:147:8 | -LL | if !res.is_ok() | !opt.is_none() {} - | ^^^^^^^^^^^^ help: try: `res.is_err()` +LL | if !res.is_ok() | !opt.is_none() {} + | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:147:19 + --> tests/ui/nonminimal_bool_methods.rs:147:23 | -LL | if !res.is_ok() | !opt.is_none() {} - | ^^^^^^^^^^^^^^ help: try: `opt.is_some()` +LL | if !res.is_ok() | !opt.is_none() {} + | ^^^^^^^^^^^^^^ help: try: `opt.is_some()` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:152:1 + --> tests/ui/nonminimal_bool_methods.rs:152:9 | -LL | (!(4 > 3)).b() - | ^^^^^^^^^^ help: try: `(4 <= 3)` +LL | (!(4 > 3)).b() + | ^^^^^^^^^^ help: try: `(4 <= 3)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:178:5 + --> tests/ui/nonminimal_bool_methods.rs:178:9 | -LL | _ = !opt.is_some_and(|x| x < 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` +LL | _ = !opt.is_some_and(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:180:5 + --> tests/ui/nonminimal_bool_methods.rs:180:9 | -LL | _ = !opt.is_some_and(|x| x <= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` +LL | _ = !opt.is_some_and(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:182:5 + --> tests/ui/nonminimal_bool_methods.rs:182:9 | -LL | _ = !opt.is_some_and(|x| x > 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` +LL | _ = !opt.is_some_and(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:184:5 + --> tests/ui/nonminimal_bool_methods.rs:184:9 | -LL | _ = !opt.is_some_and(|x| x >= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` +LL | _ = !opt.is_some_and(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:186:5 + --> tests/ui/nonminimal_bool_methods.rs:186:9 | -LL | _ = !opt.is_some_and(|x| x == 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` +LL | _ = !opt.is_some_and(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:188:5 + --> tests/ui/nonminimal_bool_methods.rs:188:9 | -LL | _ = !opt.is_some_and(|x| x != 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` +LL | _ = !opt.is_some_and(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:198:5 + --> tests/ui/nonminimal_bool_methods.rs:198:9 | -LL | _ = !opt.is_none_or(|x| x < 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` +LL | _ = !opt.is_none_or(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:200:5 + --> tests/ui/nonminimal_bool_methods.rs:200:9 | -LL | _ = !opt.is_none_or(|x| x <= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` +LL | _ = !opt.is_none_or(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:202:5 + --> tests/ui/nonminimal_bool_methods.rs:202:9 | -LL | _ = !opt.is_none_or(|x| x > 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` +LL | _ = !opt.is_none_or(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:204:5 + --> tests/ui/nonminimal_bool_methods.rs:204:9 | -LL | _ = !opt.is_none_or(|x| x >= 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` +LL | _ = !opt.is_none_or(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:206:5 + --> tests/ui/nonminimal_bool_methods.rs:206:9 | -LL | _ = !opt.is_none_or(|x| x == 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` +LL | _ = !opt.is_none_or(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:208:5 + --> tests/ui/nonminimal_bool_methods.rs:208:9 | -LL | _ = !opt.is_none_or(|x| x != 1000); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` +LL | _ = !opt.is_none_or(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:216:5 + --> tests/ui/nonminimal_bool_methods.rs:216:9 | -LL | _ = !opt.is_some_and(|x| !x); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` +LL | _ = !opt.is_some_and(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:221:5 + --> tests/ui/nonminimal_bool_methods.rs:221:9 | -LL | _ = !opt.is_none_or(|x| !x); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` +LL | _ = !opt.is_none_or(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:229:5 + --> tests/ui/nonminimal_bool_methods.rs:229:9 | -LL | _ = !opt.is_some_and(|x| x.is_ok()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` +LL | _ = !opt.is_some_and(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:231:5 + --> tests/ui/nonminimal_bool_methods.rs:231:9 | -LL | _ = !opt.is_some_and(|x| x.is_err()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` +LL | _ = !opt.is_some_and(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:233:5 + --> tests/ui/nonminimal_bool_methods.rs:233:9 | -LL | _ = !opt.is_none_or(|x| x.is_ok()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` +LL | _ = !opt.is_none_or(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods.rs:235:5 + --> tests/ui/nonminimal_bool_methods.rs:235:9 | -LL | _ = !opt.is_none_or(|x| x.is_err()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` +LL | _ = !opt.is_none_or(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` error: aborting due to 41 previous errors diff --git a/tests/ui/nonminimal_bool_methods_unfixable.rs b/tests/ui/nonminimal_bool_methods_unfixable.rs index aba156ac8ea9..850eba4851b8 100644 --- a/tests/ui/nonminimal_bool_methods_unfixable.rs +++ b/tests/ui/nonminimal_bool_methods_unfixable.rs @@ -3,9 +3,9 @@ fn issue_13436() { let opt_opt = Some(Some(500)); -_ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); -//~^ nonminimal_bool -//~| nonminimal_bool + _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + //~^ nonminimal_bool + //~| nonminimal_bool } fn main() {} diff --git a/tests/ui/nonminimal_bool_methods_unfixable.stderr b/tests/ui/nonminimal_bool_methods_unfixable.stderr index c228bafad325..5a90155844cd 100644 --- a/tests/ui/nonminimal_bool_methods_unfixable.stderr +++ b/tests/ui/nonminimal_bool_methods_unfixable.stderr @@ -1,17 +1,17 @@ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:5 + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:9 | -LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))` +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:30 + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:34 | -LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)` +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)` error: aborting due to 2 previous errors diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 61a8fdddcd7d..b7a9cc836475 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -8,7 +8,6 @@ fn main() { if true { "a" } else { "b" }; //~^ obfuscated_if_else - let a = 1; if a == 1 { "a" } else { "b" }; //~^ obfuscated_if_else @@ -16,7 +15,6 @@ fn main() { if a == 1 { "a" } else { "b" }; //~^ obfuscated_if_else - let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint @@ -26,7 +24,6 @@ fn main() { if true { () } else { a += 2 }; //~^ obfuscated_if_else - } fn issue11141() { @@ -34,31 +31,25 @@ fn issue11141() { let _ = (if true { 40 } else { 17 }) | 2; //~^ obfuscated_if_else - // Parentheses are required only for the leftmost expression let _ = (if true { 30 } else { 17 }) | if true { 2 } else { 3 } | if true { 10 } else { 1 }; //~^ obfuscated_if_else //~| obfuscated_if_else //~| obfuscated_if_else - // Parentheses are not required around the right side of a binary expression let _ = 2 | if true { 40 } else { 17 }; //~^ obfuscated_if_else - // Parentheses are not required for a cast let _ = if true { 42 } else { 17 } as u8; //~^ obfuscated_if_else - // Parentheses are not required for a deref let _ = *if true { &42 } else { &17 }; //~^ obfuscated_if_else - // Parentheses are not required for a deref followed by a cast let _ = *if true { &42 } else { &17 } as u8; //~^ obfuscated_if_else - } diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index 0eaafe8b66ad..a6470fedd5c6 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -8,7 +8,6 @@ fn main() { true.then(|| "a").unwrap_or("b"); //~^ obfuscated_if_else - let a = 1; (a == 1).then_some("a").unwrap_or("b"); //~^ obfuscated_if_else @@ -16,7 +15,6 @@ fn main() { (a == 1).then(|| "a").unwrap_or("b"); //~^ obfuscated_if_else - let partial = (a == 1).then_some("a"); partial.unwrap_or("b"); // not lint @@ -26,7 +24,6 @@ fn main() { true.then_some(()).unwrap_or(a += 2); //~^ obfuscated_if_else - } fn issue11141() { @@ -34,31 +31,25 @@ fn issue11141() { let _ = true.then_some(40).unwrap_or(17) | 2; //~^ obfuscated_if_else - // Parentheses are required only for the leftmost expression let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); //~^ obfuscated_if_else //~| obfuscated_if_else //~| obfuscated_if_else - // Parentheses are not required around the right side of a binary expression let _ = 2 | true.then_some(40).unwrap_or(17); //~^ obfuscated_if_else - // Parentheses are not required for a cast let _ = true.then_some(42).unwrap_or(17) as u8; //~^ obfuscated_if_else - // Parentheses are not required for a deref let _ = *true.then_some(&42).unwrap_or(&17); //~^ obfuscated_if_else - // Parentheses are not required for a deref followed by a cast let _ = *true.then_some(&42).unwrap_or(&17) as u8; //~^ obfuscated_if_else - } diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 2d635871950f..84caa848ece6 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -14,73 +14,73 @@ LL | true.then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:13:5 + --> tests/ui/obfuscated_if_else.rs:12:5 | LL | (a == 1).then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:16:5 + --> tests/ui/obfuscated_if_else.rs:15:5 | LL | (a == 1).then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:24:5 + --> tests/ui/obfuscated_if_else.rs:22:5 | LL | true.then_some(a += 1).unwrap_or(()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:27:5 + --> tests/ui/obfuscated_if_else.rs:25:5 | LL | true.then_some(()).unwrap_or(a += 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:34:13 + --> tests/ui/obfuscated_if_else.rs:31:13 | LL | let _ = true.then_some(40).unwrap_or(17) | 2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 40 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:39:13 + --> tests/ui/obfuscated_if_else.rs:35:13 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 30 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:39:48 + --> tests/ui/obfuscated_if_else.rs:35:48 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 2 } else { 3 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:39:81 + --> tests/ui/obfuscated_if_else.rs:35:81 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 10 } else { 1 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:46:17 + --> tests/ui/obfuscated_if_else.rs:41:17 | LL | let _ = 2 | true.then_some(40).unwrap_or(17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 40 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:51:13 + --> tests/ui/obfuscated_if_else.rs:45:13 | LL | let _ = true.then_some(42).unwrap_or(17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 42 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:56:14 + --> tests/ui/obfuscated_if_else.rs:49:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:61:14 + --> tests/ui/obfuscated_if_else.rs:53:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` diff --git a/tests/ui/octal_escapes.rs b/tests/ui/octal_escapes.rs index 08e0316d1124..d91d6c1d7bee 100644 --- a/tests/ui/octal_escapes.rs +++ b/tests/ui/octal_escapes.rs @@ -2,31 +2,29 @@ #![warn(clippy::octal_escapes)] fn main() { -let _bad1 = "\033[0m"; -//~^ octal_escapes -let _bad2 = b"\033[0m"; -//~^ octal_escapes -let _bad3 = "\\\033[0m"; -//~^ octal_escapes + let _bad1 = "\033[0m"; + //~^ octal_escapes + let _bad2 = b"\033[0m"; + //~^ octal_escapes + let _bad3 = "\\\033[0m"; + //~^ octal_escapes // maximum 3 digits (\012 is the escape) -let _bad4 = "\01234567"; -//~^ octal_escapes -let _bad5 = "\0\03"; -//~^ octal_escapes + let _bad4 = "\01234567"; + //~^ octal_escapes + let _bad5 = "\0\03"; + //~^ octal_escapes let _bad6 = "Text-\055\077-MoreText"; //~^ octal_escapes //~| octal_escapes - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; //~^ octal_escapes //~| octal_escapes - -let _bad8 = "锈\01锈"; -//~^ octal_escapes -let _bad9 = "锈\011锈"; -//~^ octal_escapes + let _bad8 = "锈\01锈"; + //~^ octal_escapes + let _bad9 = "锈\011锈"; + //~^ octal_escapes let _good1 = "\\033[0m"; let _good2 = "\0\\0"; diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 2f838a84dd48..024308cbf429 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -1,80 +1,80 @@ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:5:14 + --> tests/ui/octal_escapes.rs:5:18 | -LL | let _bad1 = "\033[0m"; - | ^^^^ +LL | let _bad1 = "\033[0m"; + | ^^^^ | = help: octal escapes are not supported, `\0` is always null = note: `-D clippy::octal-escapes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape is intended, use a hex escape instead | -LL | let _bad1 = "\x1b[0m"; - | ~~~~ +LL | let _bad1 = "\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad1 = "\x0033[0m"; - | ~~~~~~ +LL | let _bad1 = "\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:7:15 + --> tests/ui/octal_escapes.rs:7:19 | -LL | let _bad2 = b"\033[0m"; - | ^^^^ +LL | let _bad2 = b"\033[0m"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad2 = b"\x1b[0m"; - | ~~~~ +LL | let _bad2 = b"\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad2 = b"\x0033[0m"; - | ~~~~~~ +LL | let _bad2 = b"\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:9:16 + --> tests/ui/octal_escapes.rs:9:20 | -LL | let _bad3 = "\\\033[0m"; - | ^^^^ +LL | let _bad3 = "\\\033[0m"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad3 = "\\\x1b[0m"; - | ~~~~ +LL | let _bad3 = "\\\x1b[0m"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad3 = "\\\x0033[0m"; - | ~~~~~~ +LL | let _bad3 = "\\\x0033[0m"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:12:14 + --> tests/ui/octal_escapes.rs:12:18 | -LL | let _bad4 = "\01234567"; - | ^^^^ +LL | let _bad4 = "\01234567"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad4 = "\x0a34567"; - | ~~~~ +LL | let _bad4 = "\x0a34567"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad4 = "\x001234567"; - | ~~~~~~ +LL | let _bad4 = "\x001234567"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:14:16 + --> tests/ui/octal_escapes.rs:14:20 | -LL | let _bad5 = "\0\03"; - | ^^^ +LL | let _bad5 = "\0\03"; + | ^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad5 = "\0\x03"; - | ~~~~ +LL | let _bad5 = "\0\x03"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad5 = "\0\x0003"; - | ~~~~~~ +LL | let _bad5 = "\0\x0003"; + | ~~~~~~ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:16:23 @@ -107,7 +107,7 @@ LL | let _bad6 = "Text-\055\x0077-MoreText"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:21:31 + --> tests/ui/octal_escapes.rs:20:31 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^ @@ -122,7 +122,7 @@ LL | let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:21:34 + --> tests/ui/octal_escapes.rs:20:34 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^ @@ -137,34 +137,34 @@ LL | let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:26:15 + --> tests/ui/octal_escapes.rs:24:19 | -LL | let _bad8 = "锈\01锈"; - | ^^^ +LL | let _bad8 = "锈\01锈"; + | ^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad8 = "锈\x01锈"; - | ~~~~ +LL | let _bad8 = "锈\x01锈"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad8 = "锈\x0001锈"; - | ~~~~~~ +LL | let _bad8 = "锈\x0001锈"; + | ~~~~~~ error: octal-looking escape in a literal - --> tests/ui/octal_escapes.rs:28:15 + --> tests/ui/octal_escapes.rs:26:19 | -LL | let _bad9 = "锈\011锈"; - | ^^^^ +LL | let _bad9 = "锈\011锈"; + | ^^^^ | help: if an octal escape is intended, use a hex escape instead | -LL | let _bad9 = "锈\x09锈"; - | ~~~~ +LL | let _bad9 = "锈\x09锈"; + | ~~~~ help: if a null escape is intended, disambiguate using | -LL | let _bad9 = "锈\x0011锈"; - | ~~~~~~ +LL | let _bad9 = "锈\x0011锈"; + | ~~~~~~ error: aborting due to 11 previous errors diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index 33702878ddb7..efb56f242a74 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -35,5 +35,4 @@ fn main() { let res6: Result = Ok(0); res6.ok().expect("meh"); //~^ ok_expect - } diff --git a/tests/ui/only_used_in_recursion.rs b/tests/ui/only_used_in_recursion.rs index cf872920a6e2..7d6075ba9ea4 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -9,21 +9,20 @@ fn _simple2(x: u32) -> u32 { } fn _one_unused(flag: u32, a: usize) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { _one_unused(flag - 1, a) } } fn _two_unused(flag: u32, a: u32, b: i32) -> usize { -//~^ only_used_in_recursion -//~| only_used_in_recursion - + //~^ only_used_in_recursion + //~| only_used_in_recursion if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } } fn _with_calc(flag: u32, a: i64) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 @@ -38,9 +37,8 @@ fn _used_with_flag(flag: u32, a: u32) -> usize { } fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { -//~^ only_used_in_recursion -//~| only_used_in_recursion - + //~^ only_used_in_recursion + //~| only_used_in_recursion if flag == 0 { 0 @@ -50,9 +48,8 @@ fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { } fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { -//~^ only_used_in_recursion -//~| only_used_in_recursion - + //~^ only_used_in_recursion + //~| only_used_in_recursion if flag == 0 { 0 @@ -62,7 +59,7 @@ fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { } fn _not_primitive(flag: u32, b: String) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } } @@ -71,15 +68,14 @@ struct A; impl A { fn _method(flag: usize, a: usize) -> usize { - //~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { Self::_method(flag - 1, a) } } fn _method_self(&self, flag: usize, a: usize) -> usize { - //~^ only_used_in_recursion - //~| only_used_in_recursion - + //~^ only_used_in_recursion + //~| only_used_in_recursion if flag == 0 { 0 } else { self._method_self(flag - 1, a) } } @@ -92,13 +88,13 @@ trait B { impl B for A { fn method(flag: u32, a: usize) -> usize { - //~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { - //~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } @@ -126,13 +122,13 @@ impl B for u32 { trait C { fn method(flag: u32, a: usize) -> usize { - //~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { - //~^ only_used_in_recursion + //~^ 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 1f1aa75be662..ca08319e1120 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -19,7 +19,7 @@ LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:22:53 + --> tests/ui/only_used_in_recursion.rs:21:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ @@ -31,163 +31,163 @@ LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:22:56 + --> tests/ui/only_used_in_recursion.rs:21:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:25:26 + --> tests/ui/only_used_in_recursion.rs:24:26 | LL | fn _with_calc(flag: u32, a: i64) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:31:32 + --> tests/ui/only_used_in_recursion.rs:30:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:40:33 + --> tests/ui/only_used_in_recursion.rs:39:33 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:48:38 + --> tests/ui/only_used_in_recursion.rs:46:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:40:41 + --> tests/ui/only_used_in_recursion.rs:39:41 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:48:45 + --> tests/ui/only_used_in_recursion.rs:46:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:52:35 + --> tests/ui/only_used_in_recursion.rs:50:35 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:60:39 + --> tests/ui/only_used_in_recursion.rs:57:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:52:43 + --> tests/ui/only_used_in_recursion.rs:50:43 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:60:43 + --> tests/ui/only_used_in_recursion.rs:57:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:64:30 + --> tests/ui/only_used_in_recursion.rs:61:30 | LL | fn _not_primitive(flag: u32, b: String) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:67:56 + --> tests/ui/only_used_in_recursion.rs:64:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:73:29 + --> tests/ui/only_used_in_recursion.rs:70:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:76:59 + --> tests/ui/only_used_in_recursion.rs:73:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:79:22 + --> tests/ui/only_used_in_recursion.rs:76:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:84:35 + --> tests/ui/only_used_in_recursion.rs:80:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:79:41 + --> tests/ui/only_used_in_recursion.rs:76:41 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:84:63 + --> tests/ui/only_used_in_recursion.rs:80:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:94:26 + --> tests/ui/only_used_in_recursion.rs:90:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:97:58 + --> tests/ui/only_used_in_recursion.rs:93:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:100:38 + --> tests/ui/only_used_in_recursion.rs:96:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:103:62 + --> tests/ui/only_used_in_recursion.rs:99:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:128:26 + --> tests/ui/only_used_in_recursion.rs:124:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:131:58 + --> tests/ui/only_used_in_recursion.rs:127:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:134:38 + --> tests/ui/only_used_in_recursion.rs:130:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:137:62 + --> tests/ui/only_used_in_recursion.rs:133:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ diff --git a/tests/ui/only_used_in_recursion2.rs b/tests/ui/only_used_in_recursion2.rs index e4639c8b8a45..2fe4e7b35d38 100644 --- a/tests/ui/only_used_in_recursion2.rs +++ b/tests/ui/only_used_in_recursion2.rs @@ -1,10 +1,10 @@ #![warn(clippy::only_used_in_recursion)] //@no-rustfix fn _with_inner(flag: u32, a: u32, b: u32) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion fn inner(flag: u32, a: u32) -> u32 { - //~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 } else { inner(flag, a) } } @@ -14,7 +14,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 { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if let Some(x) = a.and_then(|x| f(x, x)) { _with_closure(Some(x), b, f) @@ -66,7 +66,7 @@ impl E<()> for () { } fn overwritten_param(flag: u32, mut a: usize) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { return 0; @@ -79,7 +79,7 @@ fn overwritten_param(flag: u32, mut a: usize) -> usize { } fn field_direct(flag: u32, mut a: (usize,)) -> usize { -//~^ only_used_in_recursion + //~^ only_used_in_recursion if flag == 0 { 0 diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index a67f883fe2e2..46a59e419cce 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -11,8 +11,6 @@ fn main() { let foo = 5 - 6; //~^ op_ref - - let bar = String::new(); let bar = "foo" == &bar; @@ -58,7 +56,6 @@ fn main() { let y = Y(2); let z = x & y; //~^ op_ref - } #[derive(Clone, Copy)] diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index 798484c9fe9e..e10840ff4b97 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -11,8 +11,6 @@ fn main() { let foo = &5 - &6; //~^ op_ref - - let bar = String::new(); let bar = "foo" == &bar; @@ -58,7 +56,6 @@ fn main() { let y = Y(2); let z = x & &y; //~^ op_ref - } #[derive(Clone, Copy)] diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index 86d0be4272c6..f3fb3920ee1f 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -12,7 +12,7 @@ LL | let foo = 5 - 6; | ~ ~ error: taken reference of right operand - --> tests/ui/op_ref.rs:59:13 + --> tests/ui/op_ref.rs:57:13 | LL | let z = x & &y; | ^^^^-- @@ -20,7 +20,7 @@ LL | let z = x & &y; | help: use the right value directly: `y` error: taken reference of right operand - --> tests/ui/op_ref.rs:94:17 + --> tests/ui/op_ref.rs:91:17 | LL | let _ = one * &self; | ^^^^^^----- @@ -28,7 +28,7 @@ LL | let _ = one * &self; | help: use the right value directly: `self` error: taken reference of right operand - --> tests/ui/op_ref.rs:97:17 + --> tests/ui/op_ref.rs:94:17 | LL | let _ = two + &three; | ^^^^^^------ diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index acc2a5f86164..f2f6e6edb4de 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -17,11 +17,9 @@ fn main() { OpenOptions::new().read(true).truncate(true).open("foo.txt"); //~^ nonsensical_open_options - OpenOptions::new().append(true).truncate(true).open("foo.txt"); //~^ nonsensical_open_options - OpenOptions::new().read(true).read(false).open("foo.txt"); //~^ nonsensical_open_options @@ -30,7 +28,6 @@ fn main() { .truncate(true) // Ensure we don't trigger suspicious open options by having create without truncate .create(false) //~^ nonsensical_open_options - .open("foo.txt"); OpenOptions::new().write(true).write(false).open("foo.txt"); //~^ nonsensical_open_options @@ -41,11 +38,9 @@ fn main() { OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); //~^ nonsensical_open_options - std::fs::File::options().read(true).read(false).open("foo.txt"); //~^ nonsensical_open_options - let mut options = std::fs::OpenOptions::new(); options.read(true); options.read(false); diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index 27d8d01f3b5f..11b2d55fa058 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -8,43 +8,43 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); = help: to override `-D warnings` add `#[allow(clippy::nonsensical_open_options)]` error: file opened with `append` and `truncate` - --> tests/ui/open_options.rs:21:5 + --> tests/ui/open_options.rs:20:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:25:35 + --> tests/ui/open_options.rs:23:35 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ error: the method `create` is called more than once - --> tests/ui/open_options.rs:31:10 + --> tests/ui/open_options.rs:29:10 | LL | .create(false) | ^^^^^^^^^^^^^ error: the method `write` is called more than once - --> tests/ui/open_options.rs:35:36 + --> tests/ui/open_options.rs:32:36 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^ error: the method `append` is called more than once - --> tests/ui/open_options.rs:38:37 + --> tests/ui/open_options.rs:35:37 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> tests/ui/open_options.rs:41:39 + --> tests/ui/open_options.rs:38:39 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:45:41 + --> tests/ui/open_options.rs:41:41 | LL | std::fs::File::options().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ diff --git a/tests/ui/open_options_fixable.fixed b/tests/ui/open_options_fixable.fixed index 7ba5a8782bef..7f601eec2cf0 100644 --- a/tests/ui/open_options_fixable.fixed +++ b/tests/ui/open_options_fixable.fixed @@ -4,5 +4,4 @@ use std::fs::OpenOptions; fn main() { OpenOptions::new().create(true).truncate(true).open("foo.txt"); //~^ suspicious_open_options - } diff --git a/tests/ui/open_options_fixable.rs b/tests/ui/open_options_fixable.rs index 230d6d782074..5f03528d7a56 100644 --- a/tests/ui/open_options_fixable.rs +++ b/tests/ui/open_options_fixable.rs @@ -4,5 +4,4 @@ use std::fs::OpenOptions; fn main() { OpenOptions::new().create(true).open("foo.txt"); //~^ suspicious_open_options - } diff --git a/tests/ui/option_filter_map.fixed b/tests/ui/option_filter_map.fixed index d8d3ba7edd28..d390c41af53c 100644 --- a/tests/ui/option_filter_map.fixed +++ b/tests/ui/option_filter_map.fixed @@ -14,7 +14,6 @@ fn main() { let _ = Some(1).map(odds_out).flatten(); //~^ option_filter_map - let _ = vec![Some(1)].into_iter().flatten(); //~^ option_filter_map diff --git a/tests/ui/option_filter_map.rs b/tests/ui/option_filter_map.rs index 68abaff01b44..2d3b983a7670 100644 --- a/tests/ui/option_filter_map.rs +++ b/tests/ui/option_filter_map.rs @@ -14,7 +14,6 @@ fn main() { let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); //~^ option_filter_map - let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); //~^ option_filter_map @@ -26,14 +25,12 @@ fn main() { .map(odds_out) .filter(Option::is_some) //~^ option_filter_map - .map(Option::unwrap); let _ = vec![1] .into_iter() .map(odds_out) .filter(|o| o.is_some()) //~^ option_filter_map - .map(|o| o.unwrap()); } diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index 24a3a2d7605c..df3c1f9d47b8 100644 --- a/tests/ui/option_filter_map.stderr +++ b/tests/ui/option_filter_map.stderr @@ -26,32 +26,32 @@ LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap( | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:18:39 + --> tests/ui/option_filter_map.rs:17:39 | LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:21:39 + --> tests/ui/option_filter_map.rs:20:39 | LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:27:10 + --> tests/ui/option_filter_map.rs:26:10 | LL | .filter(Option::is_some) | __________^ -... | +LL | | LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:34:10 + --> tests/ui/option_filter_map.rs:32:10 | LL | .filter(|o| o.is_some()) | __________^ -... | +LL | | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index eb1aabe63e75..56b313244e36 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -28,19 +28,19 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = num.as_ref().map_or(&0, |s| s); //~^ option_if_let_else let _ = num.as_mut().map_or(&0, |s| { - //~^ option_if_let_else + //~^ option_if_let_else *s += 1; s }); let _ = num.as_ref().map_or(&0, |s| s); //~^ option_if_let_else let _ = num.map_or(0, |mut s| { - //~^ option_if_let_else + //~^ option_if_let_else s += 1; s }); let _ = num.as_mut().map_or(&0, |s| { - //~^ option_if_let_else + //~^ option_if_let_else *s += 1; s }); @@ -48,7 +48,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { fn longer_body(arg: Option) -> u32 { arg.map_or(13, |x| { - //~^ option_if_let_else + //~^ option_if_let_else let y = x * x; y * y }) @@ -105,7 +105,7 @@ fn test_result_impure_else(variable: Result) -> bool { println!("Err"); false }, |binding| { - //~^ option_if_let_else + //~^ option_if_let_else println!("Ok {binding}"); true }) @@ -167,7 +167,7 @@ fn main() { let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. let _ = Some(0).map_or(1, |x| { - //~^ option_if_let_else + //~^ option_if_let_else let s = s; s.len() + x }); diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index f2e2de02a93d..4a4bb141ed54 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -10,7 +10,7 @@ fn bad1(string: Option<&str>) -> (bool, &str) { if let Some(x) = string { - //~^ option_if_let_else + //~^ option_if_let_else (true, x) } else { (false, "hello") @@ -33,7 +33,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = if let Some(s) = &num { s } else { &0 }; //~^ option_if_let_else let _ = if let Some(s) = &mut num { - //~^ option_if_let_else + //~^ option_if_let_else *s += 1; s } else { @@ -42,14 +42,14 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { let _ = if let Some(ref s) = num { s } else { &0 }; //~^ option_if_let_else let _ = if let Some(mut s) = num { - //~^ option_if_let_else + //~^ option_if_let_else s += 1; s } else { 0 }; let _ = if let Some(ref mut s) = num { - //~^ option_if_let_else + //~^ option_if_let_else *s += 1; s } else { @@ -59,7 +59,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option) { fn longer_body(arg: Option) -> u32 { if let Some(x) = arg { - //~^ option_if_let_else + //~^ option_if_let_else let y = x * x; y * y } else { @@ -73,7 +73,7 @@ fn impure_else(arg: Option) { 1 }; let _ = if let Some(x) = arg { - //~^ option_if_let_else + //~^ option_if_let_else x } else { // map_or_else must be suggested @@ -83,7 +83,7 @@ fn impure_else(arg: Option) { fn test_map_or_else(arg: Option) { let _ = if let Some(x) = arg { - //~^ option_if_let_else + //~^ option_if_let_else x * x * x * x } else { let mut y = 1; @@ -117,7 +117,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { .split('/') .flat_map(|s| { if let Some(idx) = s.find('.') { - //~^ option_if_let_else + //~^ option_if_let_else vec![s[..idx].to_string(), s[idx..].to_string()] } else { vec![s.to_string()] @@ -129,7 +129,7 @@ fn pattern_to_vec(pattern: &str) -> Vec { // #10335 fn test_result_impure_else(variable: Result) -> bool { if let Ok(binding) = variable { - //~^ option_if_let_else + //~^ option_if_let_else println!("Ok {binding}"); true } else { @@ -165,7 +165,7 @@ fn main() { let _ = impure_else(None); let _ = if let Some(x) = Some(0) { - //~^ option_if_let_else + //~^ option_if_let_else loop { if x == 0 { break x; @@ -199,7 +199,7 @@ fn main() { let s = String::new(); // Lint, `Some` branch consumes `s`, but else branch doesn't use `s`. let _ = if let Some(x) = Some(0) { - //~^ option_if_let_else + //~^ option_if_let_else let s = s; s.len() + x } else { @@ -239,24 +239,24 @@ fn main() { // issue #8492 let _ = match s { - //~^ option_if_let_else + //~^ option_if_let_else Some(string) => string.len(), None => 1, }; let _ = match Some(10) { - //~^ option_if_let_else + //~^ option_if_let_else Some(a) => a + 1, None => 5, }; let res: Result = Ok(5); let _ = match res { - //~^ option_if_let_else + //~^ option_if_let_else Ok(a) => a + 1, _ => 1, }; let _ = match res { - //~^ option_if_let_else + //~^ option_if_let_else Err(_) => 1, Ok(a) => a + 1, }; @@ -279,7 +279,7 @@ mod issue10729 { pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` let _ = match initial { - //~^ option_if_let_else + //~^ option_if_let_else Some(value) => do_something(value), None => 42, }; @@ -287,7 +287,7 @@ mod issue10729 { pub fn reproduce2(initial: &mut Option) { let _ = match initial { - //~^ option_if_let_else + //~^ option_if_let_else Some(value) => do_something2(value), None => 42, }; @@ -311,7 +311,7 @@ fn issue11429() { let opt: Option> = None; let mut _hashmap = if let Some(hm) = &opt { - //~^ option_if_let_else + //~^ option_if_let_else hm.clone() } else { HashMap::new() diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed index c4d9f25bd28c..183bf32e5361 100644 --- a/tests/ui/option_map_or_none.fixed +++ b/tests/ui/option_map_or_none.fixed @@ -16,7 +16,7 @@ fn main() { let _: Option = opt.and_then(bar); //~^ option_map_or_none let _: Option = opt.and_then(|x| { - //~^ option_map_or_none + //~^ option_map_or_none let offset = 0; let height = x; Some(offset + height) diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs index c3143f50cb6c..626f206b2598 100644 --- a/tests/ui/option_map_or_none.rs +++ b/tests/ui/option_map_or_none.rs @@ -19,7 +19,7 @@ fn main() { let _: Option = opt.map_or(None, bar); //~^ option_map_or_none let _: Option = opt.map_or(None, |x| { - //~^ option_map_or_none + //~^ option_map_or_none let offset = 0; let height = x; Some(offset + height) diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 73ba4394e983..7014e20c1f85 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -373,7 +373,6 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - let _ = opt.unwrap_or_else(f); // suggest `.unwrap_or_else(f)` //~^ or_fun_call // @@ -383,7 +382,7 @@ fn fn_call_in_nested_expr() { // let _ = opt.unwrap_or_else(|| { - //~^ or_fun_call + //~^ or_fun_call let x = f(); x + 1 }); diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index ed3469178196..d8a0ab033c4d 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -373,7 +373,6 @@ fn fn_call_in_nested_expr() { } let opt: Option = Some(1); - let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` //~^ or_fun_call // @@ -383,7 +382,7 @@ fn fn_call_in_nested_expr() { // let _ = opt.unwrap_or({ - //~^ or_fun_call + //~^ or_fun_call let x = f(); x + 1 }); diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index a1eaf08e4458..0cc8ad39421c 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -197,19 +197,19 @@ LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:377:17 + --> tests/ui/or_fun_call.rs:376:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:381:17 + --> tests/ui/or_fun_call.rs:380:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:385:17 + --> tests/ui/or_fun_call.rs:384:17 | LL | let _ = opt.unwrap_or({ | _________________^ @@ -229,19 +229,19 @@ LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:391:17 + --> tests/ui/or_fun_call.rs:390:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| f() + 1, |v| v)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:395:17 + --> tests/ui/or_fun_call.rs:394:17 | LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:402:21 + --> tests/ui/or_fun_call.rs:401:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index 3ba35482780d..e1e0fa02a937 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -9,8 +9,6 @@ fn main() { &x[num..10]; //~^ out_of_bounds_indexing - &x[10..num]; //~^ out_of_bounds_indexing - } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 304adcfdc2d3..8bf0152601df 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -8,7 +8,7 @@ LL | &x[num..10]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/issue-3102.rs:13:8 + --> tests/ui/out_of_bounds_indexing/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 86f29f9ee408..e613e527eee4 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -7,7 +7,6 @@ fn main() { &x[..=4]; //~^ out_of_bounds_indexing - &x[1..5]; //~^ out_of_bounds_indexing @@ -23,7 +22,6 @@ fn main() { &x[0..=4]; //~^ out_of_bounds_indexing - &x[4..]; // Ok, should not produce stderr. &x[..4]; // Ok, should not produce stderr. &x[..]; // 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 47f36e51bffa..f89531733431 100644 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -8,31 +8,31 @@ LL | &x[..=4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:11:11 + --> tests/ui/out_of_bounds_indexing/simple.rs:10:11 | LL | &x[1..5]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:14:8 + --> tests/ui/out_of_bounds_indexing/simple.rs:13:8 | LL | &x[5..]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:17:10 + --> tests/ui/out_of_bounds_indexing/simple.rs:16:10 | LL | &x[..5]; | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:20:8 + --> tests/ui/out_of_bounds_indexing/simple.rs:19:8 | LL | &x[5..].iter().map(|x| 2 * x).collect::>(); | ^ error: range is out of bounds - --> tests/ui/out_of_bounds_indexing/simple.rs:23:12 + --> tests/ui/out_of_bounds_indexing/simple.rs:22:12 | LL | &x[0..=4]; | ^ diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs index dc0fc65fd777..005e38db9021 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -5,7 +5,6 @@ struct A; impl A { fn result_with_panic() -> Result // should emit lint //~^ panic_in_result_fn - { panic!("error"); } @@ -53,13 +52,12 @@ impl A { fn function_result_with_panic() -> Result // should emit lint //~^ panic_in_result_fn - { panic!("error"); } fn in_closure() -> Result { -//~^ panic_in_result_fn + //~^ panic_in_result_fn let c = || panic!(); c() } diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index 17fd03733abc..1067f4fac11c 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -2,13 +2,15 @@ error: used `panic!()` or assertion in a function that returns `Result` --> tests/ui/panic_in_result_fn.rs:6:5 | LL | / fn result_with_panic() -> Result // should emit lint -... | +LL | | +LL | | { +LL | | panic!("error"); 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 - --> tests/ui/panic_in_result_fn.rs:10:9 + --> tests/ui/panic_in_result_fn.rs:9:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ @@ -16,22 +18,24 @@ LL | panic!("error"); = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn.rs:54:1 + --> tests/ui/panic_in_result_fn.rs:53:1 | LL | / fn function_result_with_panic() -> Result // should emit lint -... | +LL | | +LL | | { +LL | | panic!("error"); 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 - --> tests/ui/panic_in_result_fn.rs:58:5 + --> tests/ui/panic_in_result_fn.rs:56:5 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn.rs:61:1 + --> tests/ui/panic_in_result_fn.rs:59:1 | LL | / fn in_closure() -> Result { LL | | @@ -42,7 +46,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 - --> tests/ui/panic_in_result_fn.rs:63:16 + --> tests/ui/panic_in_result_fn.rs:61:16 | LL | let c = || panic!(); | ^^^^^^^^ diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs index 894e63f8ff1e..4e7028241579 100644 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ b/tests/ui/panic_in_result_fn_assertions.rs @@ -6,7 +6,6 @@ struct A; impl A { fn result_with_assert_with_message(x: i32) -> Result // should emit lint //~^ panic_in_result_fn - { assert!(x == 5, "wrong argument"); Ok(true) @@ -14,7 +13,6 @@ impl A { fn result_with_assert_eq(x: i32) -> Result // should emit lint //~^ panic_in_result_fn - { assert_eq!(x, 5); Ok(true) @@ -22,7 +20,6 @@ impl A { fn result_with_assert_ne(x: i32) -> Result // should emit lint //~^ panic_in_result_fn - { 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 46bc16fe8e16..cdb7762510d9 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -2,14 +2,16 @@ error: used `panic!()` or assertion in a function that returns `Result` --> tests/ui/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) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:11:9 + --> tests/ui/panic_in_result_fn_assertions.rs:10:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,33 +19,37 @@ LL | assert!(x == 5, "wrong argument"); = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn_assertions.rs:15:5 + --> tests/ui/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) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:19:9 + --> tests/ui/panic_in_result_fn_assertions.rs:17:9 | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> tests/ui/panic_in_result_fn_assertions.rs:23:5 + --> tests/ui/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) 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 - --> tests/ui/panic_in_result_fn_assertions.rs:27:9 + --> tests/ui/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 a718dd925216..65854d7eb4bf 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -22,7 +22,6 @@ fn panic() { panic!(); //~^ panic - panic!("message"); //~^ panic @@ -37,7 +36,6 @@ fn todo() { todo!(); //~^ todo - todo!("message"); //~^ todo @@ -52,7 +50,6 @@ fn unimplemented() { unimplemented!(); //~^ unimplemented - unimplemented!("message"); //~^ unimplemented @@ -67,7 +64,6 @@ fn unreachable() { unreachable!(); //~^ unreachable - unreachable!("message"); //~^ unreachable @@ -90,7 +86,6 @@ fn core_versions() { unreachable!(); //~^ unreachable - } fn assert() { diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 0c2b4508a803..03e459e4ec6e 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -8,19 +8,19 @@ LL | panic!(); = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:26:5 + --> tests/ui/panicking_macros.rs:25:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:29:5 + --> tests/ui/panicking_macros.rs:28:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:37:5 + --> tests/ui/panicking_macros.rs:36:5 | LL | todo!(); | ^^^^^^^ @@ -29,19 +29,19 @@ LL | todo!(); = help: to override `-D warnings` add `#[allow(clippy::todo)]` error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:41:5 + --> tests/ui/panicking_macros.rs:39:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:44:5 + --> tests/ui/panicking_macros.rs:42:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:52:5 + --> tests/ui/panicking_macros.rs:50:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ @@ -50,19 +50,19 @@ LL | unimplemented!(); = help: to override `-D warnings` add `#[allow(clippy::unimplemented)]` error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:56:5 + --> tests/ui/panicking_macros.rs:53:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:59:5 + --> tests/ui/panicking_macros.rs:56:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:67:5 + --> tests/ui/panicking_macros.rs:64:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ @@ -71,37 +71,37 @@ LL | unreachable!(); = help: to override `-D warnings` add `#[allow(clippy::unreachable)]` error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:71:5 + --> tests/ui/panicking_macros.rs:67:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:74:5 + --> tests/ui/panicking_macros.rs:70:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> tests/ui/panicking_macros.rs:82:5 + --> tests/ui/panicking_macros.rs:78:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> tests/ui/panicking_macros.rs:85:5 + --> tests/ui/panicking_macros.rs:81:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> tests/ui/panicking_macros.rs:88:5 + --> tests/ui/panicking_macros.rs:84:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> tests/ui/panicking_macros.rs:91:5 + --> tests/ui/panicking_macros.rs:87:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/panicking_overflow_checks.rs b/tests/ui/panicking_overflow_checks.rs index 57a829d50d2c..29789c949756 100644 --- a/tests/ui/panicking_overflow_checks.rs +++ b/tests/ui/panicking_overflow_checks.rs @@ -2,20 +2,20 @@ #![allow(clippy::needless_if)] fn test(a: u32, b: u32, c: u32) { -if a + b < a {} -//~^ panicking_overflow_checks -if a > a + b {} -//~^ panicking_overflow_checks -if a + b < b {} -//~^ panicking_overflow_checks -if b > a + b {} -//~^ panicking_overflow_checks + if a + b < a {} + //~^ panicking_overflow_checks + if a > a + b {} + //~^ panicking_overflow_checks + if a + b < b {} + //~^ panicking_overflow_checks + if b > a + b {} + //~^ panicking_overflow_checks if a - b > b {} if b < a - b {} -if a - b > a {} -//~^ panicking_overflow_checks -if a < a - b {} -//~^ panicking_overflow_checks + if a - b > a {} + //~^ panicking_overflow_checks + if a < a - b {} + //~^ panicking_overflow_checks if a + b < c {} if c > a + b {} if a - b < c {} diff --git a/tests/ui/panicking_overflow_checks.stderr b/tests/ui/panicking_overflow_checks.stderr index 3bb209ccfa7e..3022c9e52b0c 100644 --- a/tests/ui/panicking_overflow_checks.stderr +++ b/tests/ui/panicking_overflow_checks.stderr @@ -1,41 +1,41 @@ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:5:4 + --> tests/ui/panicking_overflow_checks.rs:5:8 | -LL | if a + b < a {} - | ^^^^^^^^^ +LL | if a + b < a {} + | ^^^^^^^^^ | = note: `-D clippy::panicking-overflow-checks` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::panicking_overflow_checks)]` error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:7:4 + --> tests/ui/panicking_overflow_checks.rs:7:8 | -LL | if a > a + b {} - | ^^^^^^^^^ +LL | if a > a + b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:9:4 + --> tests/ui/panicking_overflow_checks.rs:9:8 | -LL | if a + b < b {} - | ^^^^^^^^^ +LL | if a + b < b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:11:4 + --> tests/ui/panicking_overflow_checks.rs:11:8 | -LL | if b > a + b {} - | ^^^^^^^^^ +LL | if b > a + b {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:15:4 + --> tests/ui/panicking_overflow_checks.rs:15:8 | -LL | if a - b > a {} - | ^^^^^^^^^ +LL | if a - b > a {} + | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> tests/ui/panicking_overflow_checks.rs:17:4 + --> tests/ui/panicking_overflow_checks.rs:17:8 | -LL | if a < a - b {} - | ^^^^^^^^^ +LL | if a < a - b {} + | ^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs index a0ee4f2b0496..27f4b2a0b4fc 100644 --- a/tests/ui/partial_pub_fields.rs +++ b/tests/ui/partial_pub_fields.rs @@ -9,7 +9,6 @@ fn main() { files: HashMap, pub paths: HashMap, //~^ partial_pub_fields - } pub struct Color { @@ -17,18 +16,15 @@ fn main() { pub g: u8, b: u8, //~^ partial_pub_fields - } pub struct Point(i32, pub i32); //~^ partial_pub_fields - pub struct Visibility { r#pub: bool, pub pos: u32, //~^ partial_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 4232f3e82e45..af3b2f758757 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -9,7 +9,7 @@ LL | pub paths: HashMap, = help: to override `-D warnings` add `#[allow(clippy::partial_pub_fields)]` error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:18:9 + --> tests/ui/partial_pub_fields.rs:17:9 | LL | b: u8, | ^ @@ -17,7 +17,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:23:27 + --> tests/ui/partial_pub_fields.rs:21:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -25,7 +25,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:29:9 + --> tests/ui/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 42c235b381ef..a3b2b68708ba 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -7,8 +7,7 @@ impl PartialEq for Foo { true } fn ne(&self, _: &Foo) -> bool { - //~^ partialeq_ne_impl - + //~^ partialeq_ne_impl false } diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index ffc26afa075d..dc01a375060b 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -2,7 +2,9 @@ error: re-implementing `PartialEq::ne` is unnecessary --> tests/ui/partialeq_ne_impl.rs:9:5 | LL | / fn ne(&self, _: &Foo) -> bool { -... | +LL | | +LL | | +LL | | false LL | | } | |_____^ | diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index d650e28f2b68..e700cc56349f 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -64,7 +64,7 @@ fn main() { //~^ partialeq_to_none let _ = { - //~^ partialeq_to_none + //~^ partialeq_to_none /* This comment runs long */ diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index 77804b0765f1..1bae076dd337 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -64,7 +64,7 @@ fn main() { //~^ partialeq_to_none let _ = { - //~^ partialeq_to_none + //~^ partialeq_to_none /* This comment runs long */ diff --git a/tests/ui/path_ends_with_ext.fixed b/tests/ui/path_ends_with_ext.fixed index a20925f9ba67..fa4286e11644 100644 --- a/tests/ui/path_ends_with_ext.fixed +++ b/tests/ui/path_ends_with_ext.fixed @@ -11,7 +11,6 @@ fn test(path: &Path) { path.extension().is_some_and(|ext| ext == "md"); //~^ path_ends_with_ext - // some "extensions" are allowed by default path.ends_with(".git"); @@ -32,7 +31,6 @@ fn test(path: &Path) { fn under_msv(path: &Path) -> bool { path.extension().map_or(false, |ext| ext == "md") //~^ path_ends_with_ext - } fn main() {} diff --git a/tests/ui/path_ends_with_ext.rs b/tests/ui/path_ends_with_ext.rs index e20620e983d0..00d7ede8ef93 100644 --- a/tests/ui/path_ends_with_ext.rs +++ b/tests/ui/path_ends_with_ext.rs @@ -11,7 +11,6 @@ fn test(path: &Path) { path.ends_with(".md"); //~^ path_ends_with_ext - // some "extensions" are allowed by default path.ends_with(".git"); @@ -32,7 +31,6 @@ fn test(path: &Path) { fn under_msv(path: &Path) -> bool { path.ends_with(".md") //~^ path_ends_with_ext - } fn main() {} diff --git a/tests/ui/path_ends_with_ext.stderr b/tests/ui/path_ends_with_ext.stderr index 7016b8e5b8fb..deab71ff7626 100644 --- a/tests/ui/path_ends_with_ext.stderr +++ b/tests/ui/path_ends_with_ext.stderr @@ -8,7 +8,7 @@ LL | path.ends_with(".md"); = help: to override `-D warnings` add `#[allow(clippy::path_ends_with_ext)]` error: this looks like a failed attempt at checking for the file extension - --> tests/ui/path_ends_with_ext.rs:33:5 + --> tests/ui/path_ends_with_ext.rs:32:5 | LL | path.ends_with(".md") | ^^^^^^^^^^^^^^^^^^^^^ help: try: `path.extension().map_or(false, |ext| ext == "md")` diff --git a/tests/ui/pathbuf_init_then_push.fixed b/tests/ui/pathbuf_init_then_push.fixed index 43cc65f8dfbf..2a90b8ce2814 100644 --- a/tests/ui/pathbuf_init_then_push.fixed +++ b/tests/ui/pathbuf_init_then_push.fixed @@ -3,14 +3,14 @@ use std::path::PathBuf; fn main() { -let mut path_buf = PathBuf::from("foo"); + let mut path_buf = PathBuf::from("foo"); -path_buf = PathBuf::from("foo").join("bar"); + path_buf = PathBuf::from("foo").join("bar"); let bar = "bar"; -path_buf = PathBuf::from("foo").join(bar); + path_buf = PathBuf::from("foo").join(bar); -let mut path_buf = PathBuf::from("foo").join("bar").join("buz"); + let mut path_buf = PathBuf::from("foo").join("bar").join("buz"); let mut x = PathBuf::new(); println!("{}", x.display()); diff --git a/tests/ui/pathbuf_init_then_push.rs b/tests/ui/pathbuf_init_then_push.rs index f3adb6d27abf..7b65392e9519 100644 --- a/tests/ui/pathbuf_init_then_push.rs +++ b/tests/ui/pathbuf_init_then_push.rs @@ -3,21 +3,21 @@ use std::path::PathBuf; fn main() { -let mut path_buf = PathBuf::new(); -//~^ pathbuf_init_then_push + let mut path_buf = PathBuf::new(); + //~^ pathbuf_init_then_push path_buf.push("foo"); -path_buf = PathBuf::from("foo"); -//~^ pathbuf_init_then_push + path_buf = PathBuf::from("foo"); + //~^ pathbuf_init_then_push path_buf.push("bar"); let bar = "bar"; -path_buf = PathBuf::from("foo"); -//~^ pathbuf_init_then_push + path_buf = PathBuf::from("foo"); + //~^ pathbuf_init_then_push path_buf.push(bar); -let mut path_buf = PathBuf::from("foo").join("bar"); -//~^ pathbuf_init_then_push + let mut path_buf = PathBuf::from("foo").join("bar"); + //~^ pathbuf_init_then_push path_buf.push("buz"); let mut x = PathBuf::new(); diff --git a/tests/ui/pathbuf_init_then_push.stderr b/tests/ui/pathbuf_init_then_push.stderr index 80e7b836fce3..1aa730a0bea2 100644 --- a/tests/ui/pathbuf_init_then_push.stderr +++ b/tests/ui/pathbuf_init_then_push.stderr @@ -1,7 +1,7 @@ error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:6:1 + --> tests/ui/pathbuf_init_then_push.rs:6:5 | -LL | / let mut path_buf = PathBuf::new(); +LL | / let mut path_buf = PathBuf::new(); LL | | LL | | path_buf.push("foo"); | |_________________________^ help: consider using the `.join()`: `let mut path_buf = PathBuf::from("foo");` @@ -10,25 +10,25 @@ LL | | path_buf.push("foo"); = help: to override `-D warnings` add `#[allow(clippy::pathbuf_init_then_push)]` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:10:1 + --> tests/ui/pathbuf_init_then_push.rs:10:5 | -LL | / path_buf = PathBuf::from("foo"); +LL | / path_buf = PathBuf::from("foo"); LL | | LL | | path_buf.push("bar"); | |_________________________^ help: consider using the `.join()`: `path_buf = PathBuf::from("foo").join("bar");` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:15:1 + --> tests/ui/pathbuf_init_then_push.rs:15:5 | -LL | / path_buf = PathBuf::from("foo"); +LL | / path_buf = PathBuf::from("foo"); LL | | LL | | path_buf.push(bar); | |_______________________^ help: consider using the `.join()`: `path_buf = PathBuf::from("foo").join(bar);` error: calls to `push` immediately after creation - --> tests/ui/pathbuf_init_then_push.rs:19:1 + --> tests/ui/pathbuf_init_then_push.rs:19:5 | -LL | / let mut path_buf = PathBuf::from("foo").join("bar"); +LL | / let mut path_buf = PathBuf::from("foo").join("bar"); LL | | LL | | path_buf.push("buz"); | |_________________________^ help: consider using the `.join()`: `let mut path_buf = PathBuf::from("foo").join("bar").join("buz");` diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs index c62b33681439..bdac3764bf16 100644 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ b/tests/ui/pattern_type_mismatch/mutability.rs @@ -8,7 +8,6 @@ fn should_lint() { match value { Some(_) => (), //~^ pattern_type_mismatch - _ => (), } @@ -16,7 +15,6 @@ fn should_lint() { match value { Some(_) => (), //~^ pattern_type_mismatch - _ => (), } } diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index 805fc99ea212..e795ded7386d 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -9,7 +9,7 @@ LL | Some(_) => (), = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/mutability.rs:17:9 + --> tests/ui/pattern_type_mismatch/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 9df08bfe7246..3c789f570b03 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs @@ -21,7 +21,6 @@ fn alternatives() { if let Value::B | Value::A(Some(_)) = *ref_value {} //~^ pattern_type_mismatch - // ok if let &Value::B | &Value::A(_) = ref_value {} if let Value::B | Value::A(_) = *ref_value {} diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.rs b/tests/ui/pattern_type_mismatch/pattern_structs.rs index 862953120b4c..7fc53d591a91 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ b/tests/ui/pattern_type_mismatch/pattern_structs.rs @@ -19,7 +19,6 @@ fn struct_types() { if let Struct { ref_inner: Some(_) } = *ref_value {} //~^ pattern_type_mismatch - // ok let &Struct { .. } = ref_value; let Struct { .. } = *ref_value; @@ -50,7 +49,6 @@ fn struct_enum_variants() { if let StructEnum::Empty = ref_value {} //~^ pattern_type_mismatch - // ok if let &StructEnum::Var { .. } = ref_value {} 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 bdb11c73a457..70f7bdc38906 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:38:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:37:12 | LL | if let StructEnum::Var { .. } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:41:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:40:12 | LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:44:42 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:43:42 | LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:47:41 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:46:41 | LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} | ^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/pattern_structs.rs:50:12 + --> tests/ui/pattern_type_mismatch/pattern_structs.rs:49: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 4847e1a30a20..ecd95d9ae2b3 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.rs @@ -17,7 +17,6 @@ fn tuple_types() { if let TupleStruct(Some(_)) = *ref_value {} //~^ pattern_type_mismatch - // ok let &TupleStruct(_) = ref_value; let TupleStruct(_) = *ref_value; @@ -45,7 +44,6 @@ fn tuple_enum_variants() { if let TupleEnum::Empty = ref_value {} //~^ pattern_type_mismatch - // ok if let &TupleEnum::Var(_) = ref_value {} if let TupleEnum::Var(_) = *ref_value {} @@ -68,7 +66,6 @@ fn plain_tuples() { if let (_a, Some(_)) = *ref_value {} //~^ pattern_type_mismatch - // ok let &(_a, _b) = ref_value; 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 8a80a888f775..d47c5d509c3f 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:36:12 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:35:12 | LL | if let TupleEnum::Var(_) = ref_value {} | ^^^^^^^^^^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:39:28 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:38:28 | LL | if let &TupleEnum::Var(Some(_)) = ref_value {} | ^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:42:27 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:41:27 | LL | if let TupleEnum::Var(Some(_)) = *ref_value {} | ^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:45:12 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:44:12 | LL | if let TupleEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:62:9 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:60:9 | LL | let (_a, _b) = ref_value; | ^^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:65:18 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:63:18 | LL | if let &(_a, Some(_)) = ref_value {} | ^^^^^^^ @@ -73,7 +73,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 - --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:68:17 + --> tests/ui/pattern_type_mismatch/pattern_tuples.rs:66: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 77e9ec772aa8..0bbc26a0c27c 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -10,7 +10,6 @@ fn syntax_match() { match ref_value { Some(_) => (), //~^ pattern_type_mismatch - None => (), } @@ -32,7 +31,6 @@ fn syntax_if_let() { if let Some(_) = ref_value {} //~^ pattern_type_mismatch - // ok if let &Some(_) = ref_value {} if let Some(_) = *ref_value {} @@ -43,7 +41,7 @@ fn syntax_while_let() { // not ok while let Some(_) = ref_value { - //~^ pattern_type_mismatch + //~^ pattern_type_mismatch break; } @@ -65,7 +63,6 @@ fn syntax_for() { for (_a, _b) in slice.iter() {} //~^ pattern_type_mismatch - // ok for &(_a, _b) in slice.iter() {} } @@ -77,7 +74,6 @@ fn syntax_let() { let (_n, _m) = ref_value; //~^ pattern_type_mismatch - // ok let &(_n, _m) = ref_value; let (_n, _m) = *ref_value; @@ -88,7 +84,6 @@ fn syntax_fn() { fn foo((_a, _b): &(i32, i32)) {} //~^ pattern_type_mismatch - // ok fn foo_ok_1(&(_a, _b): &(i32, i32)) {} } @@ -104,7 +99,6 @@ fn syntax_closure() { foo(|(_a, _b)| ()); //~^ pattern_type_mismatch - // ok foo(|&(_a, _b)| ()); } @@ -121,7 +115,6 @@ fn macro_with_expression() { matching_macro!(match value { Some(_) => (), //~^ pattern_type_mismatch - _ => (), }); diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index eec9ea70c69d..3f6b5feb9b07 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -9,7 +9,7 @@ LL | Some(_) => (), = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> tests/ui/pattern_type_mismatch/syntax.rs:32:12 + --> tests/ui/pattern_type_mismatch/syntax.rs:31:12 | LL | if let Some(_) = ref_value {} | ^^^^^^^ @@ -17,7 +17,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:45:15 + --> tests/ui/pattern_type_mismatch/syntax.rs:43:15 | LL | while let Some(_) = ref_value { | ^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:65:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:63:9 | LL | for (_a, _b) in slice.iter() {} | ^^^^^^^^ @@ -33,7 +33,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:77:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:74:9 | LL | let (_n, _m) = ref_value; | ^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:88:12 + --> tests/ui/pattern_type_mismatch/syntax.rs:84:12 | LL | fn foo((_a, _b): &(i32, i32)) {} | ^^^^^^^^ @@ -49,7 +49,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:104:10 + --> tests/ui/pattern_type_mismatch/syntax.rs:99:10 | LL | foo(|(_a, _b)| ()); | ^^^^^^^^ @@ -57,7 +57,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:122:9 + --> tests/ui/pattern_type_mismatch/syntax.rs:116:9 | LL | Some(_) => (), | ^^^^^^^ @@ -65,7 +65,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 - --> tests/ui/pattern_type_mismatch/syntax.rs:144:17 + --> tests/ui/pattern_type_mismatch/syntax.rs:137:17 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index a119096865a0..bcb8ecfc38d2 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -28,7 +28,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { ref mut x => { - //~^ redundant_pattern + //~^ redundant_pattern x.push(4); println!("vec: {:?}", x); }, diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 4ba6ac319af9..19639ebd13d6 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -28,7 +28,7 @@ fn main() { // required "ref" left out in suggestion: #5271 match mutv { ref mut x @ _ => { - //~^ redundant_pattern + //~^ redundant_pattern x.push(4); println!("vec: {:?}", x); }, diff --git a/tests/ui/permissions_set_readonly_false.rs b/tests/ui/permissions_set_readonly_false.rs index 652ffd724d95..ccca523da551 100644 --- a/tests/ui/permissions_set_readonly_false.rs +++ b/tests/ui/permissions_set_readonly_false.rs @@ -19,7 +19,6 @@ fn main() { permissions.set_readonly(false); //~^ permissions_set_readonly_false - // no lint permissions.set_readonly(true); diff --git a/tests/ui/pointers_in_nomem_asm_block.rs b/tests/ui/pointers_in_nomem_asm_block.rs index 6d23bd78e919..171716be2602 100644 --- a/tests/ui/pointers_in_nomem_asm_block.rs +++ b/tests/ui/pointers_in_nomem_asm_block.rs @@ -26,11 +26,9 @@ unsafe fn nomem_good(p: &i32) { unsafe fn nomem_bad2(p: &mut i32) { asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags)); //~^ pointers_in_nomem_asm_block - } unsafe fn nomem_fn(p: extern "C" fn()) { asm!("call {p}", p = in(reg) p, options(nomem)); //~^ pointers_in_nomem_asm_block - } diff --git a/tests/ui/pointers_in_nomem_asm_block.stderr b/tests/ui/pointers_in_nomem_asm_block.stderr index 6de9c476312a..ca24e34f63c0 100644 --- a/tests/ui/pointers_in_nomem_asm_block.stderr +++ b/tests/ui/pointers_in_nomem_asm_block.stderr @@ -22,7 +22,7 @@ LL | asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags = note: if this is intentional and no pointers are read or written to, consider allowing the lint error: passing pointers to nomem asm block - --> tests/ui/pointers_in_nomem_asm_block.rs:33:22 + --> tests/ui/pointers_in_nomem_asm_block.rs:32:22 | LL | asm!("call {p}", p = in(reg) p, options(nomem)); | ^^^^^^^^^^^^^ diff --git a/tests/ui/print.rs b/tests/ui/print.rs index 7f7b8eb15b5d..ee3d9dc0de03 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -10,8 +10,6 @@ impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{:?}", 43.1415) //~^ use_debug - - } } @@ -26,27 +24,20 @@ fn main() { println!("Hello"); //~^ print_stdout - print!("Hello"); //~^ print_stdout - print!("Hello {}", "World"); //~^ print_stdout - print!("Hello {:?}", "World"); //~^ print_stdout //~| use_debug - - print!("Hello {:#?}", "#orld"); //~^ print_stdout //~| use_debug - - assert_eq!(42, 1337); vec![1, 2]; diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index 4e9d4135486c..9dd216bd1449 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -8,7 +8,7 @@ LL | write!(f, "{:?}", 43.1415) = help: to override `-D warnings` add `#[allow(clippy::use_debug)]` error: use of `println!` - --> tests/ui/print.rs:26:5 + --> tests/ui/print.rs:24:5 | LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ @@ -17,37 +17,37 @@ LL | println!("Hello"); = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `print!` - --> tests/ui/print.rs:30:5 + --> tests/ui/print.rs:27:5 | LL | print!("Hello"); | ^^^^^^^^^^^^^^^ error: use of `print!` - --> tests/ui/print.rs:34:5 + --> tests/ui/print.rs:30:5 | LL | print!("Hello {}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `print!` - --> tests/ui/print.rs:38:5 + --> tests/ui/print.rs:33:5 | LL | print!("Hello {:?}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> tests/ui/print.rs:38:19 + --> tests/ui/print.rs:33:19 | LL | print!("Hello {:?}", "World"); | ^^^^ error: use of `print!` - --> tests/ui/print.rs:44:5 + --> tests/ui/print.rs:37:5 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> tests/ui/print.rs:44:19 + --> tests/ui/print.rs:37:19 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^ diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index fdf630355044..8bc704921220 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -20,7 +20,6 @@ impl Debug for Foo { print!("{}", 1); //~^ print_in_format_impl - println!("{}", 2); //~^ print_in_format_impl diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 1a9c62d39e03..91d6ce953849 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -8,37 +8,37 @@ LL | print!("{}", 1); = help: to override `-D warnings` add `#[allow(clippy::print_in_format_impl)]` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:24:9 + --> tests/ui/print_in_format_impl.rs:23:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:27:9 + --> tests/ui/print_in_format_impl.rs:26:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:30:9 + --> tests/ui/print_in_format_impl.rs:29:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:34:13 + --> tests/ui/print_in_format_impl.rs:33:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> tests/ui/print_in_format_impl.rs:49:9 + --> tests/ui/print_in_format_impl.rs:48:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:61:9 + --> tests/ui/print_in_format_impl.rs:60:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index bcf022badc6e..24c45a4a61b9 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -27,7 +27,6 @@ fn main() { print!("Hello world"); //~^ print_literal - println!("Hello {} world", world); //~^ print_literal @@ -37,7 +36,6 @@ fn main() { println!("a literal {:.4}", 5); //~^ print_literal - // positional args don't change the fact // that we're using a literal -- this should // throw a warning @@ -47,7 +45,6 @@ fn main() { println!("world hello"); //~^ print_literal - // named args shouldn't change anything either println!("hello world"); //~^ print_literal @@ -55,7 +52,6 @@ fn main() { println!("world hello"); //~^ print_literal - // 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_literal.rs b/tests/ui/print_literal.rs index 96c150ae4810..42ae589ca639 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -27,7 +27,6 @@ fn main() { print!("Hello {}", "world"); //~^ print_literal - println!("Hello {} {}", world, "world"); //~^ print_literal @@ -37,7 +36,6 @@ fn main() { println!("{} {:.4}", "a literal", 5); //~^ print_literal - // positional args don't change the fact // that we're using a literal -- this should // throw a warning @@ -47,7 +45,6 @@ fn main() { println!("{1} {0}", "hello", "world"); //~^ print_literal - // named args shouldn't change anything either println!("{foo} {bar}", foo = "hello", bar = "world"); //~^ print_literal @@ -55,7 +52,6 @@ fn main() { println!("{bar} {foo}", foo = "hello", bar = "world"); //~^ print_literal - // 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_literal.stderr b/tests/ui/print_literal.stderr index c2bc7d495f27..da663000686f 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -13,7 +13,7 @@ LL + print!("Hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:31:36 + --> tests/ui/print_literal.rs:30:36 | LL | println!("Hello {} {}", world, "world"); | ^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {} world", world); | error: literal with an empty format string - --> tests/ui/print_literal.rs:34:26 + --> tests/ui/print_literal.rs:33:26 | LL | println!("Hello {}", "world"); | ^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("Hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:37:26 + --> tests/ui/print_literal.rs:36:26 | LL | println!("{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("a literal {:.4}", 5); | error: literal with an empty format string - --> tests/ui/print_literal.rs:44:25 + --> tests/ui/print_literal.rs:42:25 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:47:25 + --> tests/ui/print_literal.rs:45:25 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + println!("world hello"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:52:35 + --> tests/ui/print_literal.rs:49:35 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + println!("hello world"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:55:35 + --> tests/ui/print_literal.rs:52:35 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + println!("world hello"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:64:20 + --> tests/ui/print_literal.rs:60:20 | LL | println!("{}", "{} \x00 \u{ab123} \\\u{ab123} {:?}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + println!("{{}} \x00 \u{ab123} \\\u{ab123} {{:?}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:66:20 + --> tests/ui/print_literal.rs:62:20 | LL | println!("{}", "\\\u{1234}"); | ^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + println!("\\\u{1234}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:71:20 + --> tests/ui/print_literal.rs:67:20 | LL | println!("{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + println!("\\u{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:73:21 + --> tests/ui/print_literal.rs:69:21 | LL | println!(r"{}", r"\u{ab123} \u{{"); | ^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + println!(r"\u{{ab123}} \u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:75:20 + --> tests/ui/print_literal.rs:71:20 | LL | println!("{}", r"\{ab123} \u{{"); | ^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + println!("\\{{ab123}} \\u{{{{"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:77:20 + --> tests/ui/print_literal.rs:73:20 | LL | println!("{}", "\\u{ab123}"); | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + println!("\\u{{ab123}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:79:20 + --> tests/ui/print_literal.rs:75:20 | LL | println!("{}", "\\\\u{1234}"); | ^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + println!("\\\\u{{1234}}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:82:35 + --> tests/ui/print_literal.rs:78:35 | LL | println!("mixed: {} {world}", "{hello}"); | ^^^^^^^^^ @@ -193,7 +193,7 @@ LL + println!("mixed: {{hello}} {world}"); | error: literal with an empty format string - --> tests/ui/print_literal.rs:87:20 + --> tests/ui/print_literal.rs:83:20 | LL | println!("{}", r#"""#); | ^^^^^^ @@ -205,7 +205,7 @@ LL + println!("\""); | error: literal with an empty format string - --> tests/ui/print_literal.rs:91:9 + --> tests/ui/print_literal.rs:87:9 | LL | / r#" LL | | diff --git a/tests/ui/print_stderr.rs b/tests/ui/print_stderr.rs index 2ad2c97b7cc1..a086dfd37758 100644 --- a/tests/ui/print_stderr.rs +++ b/tests/ui/print_stderr.rs @@ -4,7 +4,6 @@ fn main() { eprintln!("Hello"); //~^ print_stderr - println!("This should not do anything"); eprint!("World"); //~^ print_stderr diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr index 7dfe72934c64..17019b886905 100644 --- a/tests/ui/print_stderr.stderr +++ b/tests/ui/print_stderr.stderr @@ -8,7 +8,7 @@ LL | eprintln!("Hello"); = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: use of `eprint!` - --> tests/ui/print_stderr.rs:9:5 + --> tests/ui/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 79bd8a2c8d36..96c5ee4c1e92 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -7,7 +7,6 @@ fn main() { println!("Hello"); //~^ print_with_newline - println!("Hello {}", "world"); //~^ print_with_newline @@ -20,7 +19,6 @@ fn main() { println!(); //~^ print_with_newline - // these are all fine print!(""); print!("Hello"); @@ -52,13 +50,11 @@ fn main() { // Literal newlines should also fail println!( - //~^ print_with_newline - + //~^ print_with_newline ); println!( - //~^ print_with_newline - + //~^ print_with_newline ); diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index a9cbd214fc61..60d1e4788308 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -7,7 +7,6 @@ fn main() { print!("Hello\n"); //~^ print_with_newline - print!("Hello {}\n", "world"); //~^ print_with_newline @@ -20,7 +19,6 @@ fn main() { print!("\n"); //~^ print_with_newline - // these are all fine print!(""); print!("Hello"); @@ -52,14 +50,12 @@ fn main() { // Literal newlines should also fail print!( - //~^ print_with_newline - + //~^ print_with_newline " " ); print!( - //~^ print_with_newline - + //~^ print_with_newline r" " ); diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 45f858d68966..9ead0fca113b 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -13,7 +13,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:11:5 + --> tests/ui/print_with_newline.rs:10:5 | LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:14:5 + --> tests/ui/print_with_newline.rs:13:5 | LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:17:5 + --> tests/ui/print_with_newline.rs:16:5 | LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:20:5 + --> tests/ui/print_with_newline.rs:19:5 | LL | print!("\n"); | ^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:44:5 + --> tests/ui/print_with_newline.rs:42:5 | LL | print!("\\\n"); | ^^^^^^^^^^^^^^ @@ -73,11 +73,10 @@ LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:54:5 + --> tests/ui/print_with_newline.rs:52:5 | LL | / print!( LL | | -LL | | LL | | " LL | | " LL | | ); @@ -87,16 +86,14 @@ help: use `println!` instead | LL ~ println!( LL | -LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:60:5 + --> tests/ui/print_with_newline.rs:57:5 | LL | / print!( LL | | -LL | | LL | | r" LL | | " LL | | ); @@ -106,12 +103,11 @@ help: use `println!` instead | LL ~ println!( LL | -LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:71:5 + --> tests/ui/print_with_newline.rs:67:5 | LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index e8332cb97e1b..2d77bf06ff94 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -11,45 +11,44 @@ use std::borrow::Cow; use std::path::{Path, PathBuf}; fn do_vec(x: &Vec) { -//~^ ptr_arg - + //~^ ptr_arg //Nothing here } fn do_vec_mut(x: &mut Vec) { -//~^ ptr_arg + //~^ ptr_arg //Nothing here } fn do_vec_mut2(x: &mut Vec) { -//~^ ptr_arg + //~^ ptr_arg x.len(); x.is_empty(); } fn do_str(x: &String) { -//~^ ptr_arg + //~^ ptr_arg //Nothing here either } fn do_str_mut(x: &mut String) { -//~^ ptr_arg + //~^ ptr_arg //Nothing here either } fn do_path(x: &PathBuf) { -//~^ ptr_arg + //~^ ptr_arg //Nothing here either } fn do_path_mut(x: &mut PathBuf) { -//~^ ptr_arg + //~^ ptr_arg //Nothing here either } @@ -74,7 +73,7 @@ impl Foo for Bar { } fn cloned(x: &Vec) -> Vec { -//~^ ptr_arg + //~^ ptr_arg let e = x.clone(); let f = e.clone(); // OK @@ -85,7 +84,7 @@ fn cloned(x: &Vec) -> Vec { } fn str_cloned(x: &String) -> String { -//~^ ptr_arg + //~^ ptr_arg let a = x.clone(); let b = x.clone(); @@ -95,7 +94,7 @@ fn str_cloned(x: &String) -> String { } fn path_cloned(x: &PathBuf) -> PathBuf { -//~^ ptr_arg + //~^ ptr_arg let a = x.clone(); let b = x.clone(); @@ -105,7 +104,7 @@ fn path_cloned(x: &PathBuf) -> PathBuf { } fn false_positive_capacity(x: &Vec, y: &String) { -//~^ ptr_arg + //~^ ptr_arg let a = x.capacity(); let b = y.clone(); @@ -123,7 +122,6 @@ fn false_positive_capacity_too(x: &String) -> String { fn test_cow_with_ref(c: &Cow<[i32]>) {} //~^ ptr_arg - fn test_cow(c: Cow<[i32]>) { let _c = c; } @@ -154,7 +152,6 @@ mod issue_5644 { fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} //~^ ptr_arg - struct S; impl S { fn allowed( @@ -183,21 +180,21 @@ mod issue6509 { use std::path::PathBuf; fn foo_vec(vec: &Vec) { - //~^ ptr_arg + //~^ ptr_arg let _ = vec.clone().pop(); let _ = vec.clone().clone(); } fn foo_path(path: &PathBuf) { - //~^ ptr_arg + //~^ ptr_arg let _ = path.clone().pop(); let _ = path.clone().clone(); } fn foo_str(str: &PathBuf) { - //~^ ptr_arg + //~^ ptr_arg let _ = str.clone().pop(); let _ = str.clone().clone(); @@ -205,7 +202,7 @@ mod issue6509 { } fn mut_vec_slice_methods(v: &mut Vec) { -//~^ ptr_arg + //~^ ptr_arg v.copy_within(1..5, 10); } @@ -269,9 +266,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) { -//~^ ptr_arg -//~| ptr_arg -//~| ptr_arg + //~^ ptr_arg + //~| ptr_arg + //~| ptr_arg trait T {} impl T for Vec {} @@ -296,26 +293,26 @@ mod issue_9218 { // This one has an anonymous lifetime so it's not okay fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { - //~^ ptr_arg + //~^ ptr_arg todo!() } // These two's return types don't use 'a so it's not okay fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { - //~^ ptr_arg + //~^ ptr_arg todo!() } fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { - //~^ ptr_arg + //~^ ptr_arg todo!() } // Inferred to be `&'a str`, afaik. fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str { - //~^ ERROR: elided lifetime has a name + //~^ ERROR: elided lifetime has a name todo!() } } @@ -348,8 +345,8 @@ mod issue_13308 { // Other cases that are still ok to lint and ideally shouldn't regress fn good(v1: &String, v2: &String) { - //~^ ptr_arg - //~| ptr_arg + //~^ ptr_arg + //~| ptr_arg h1(v1); h2(String::new(), v2); diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 94fa2184fd64..741e60cbd749 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -1,5 +1,5 @@ error: elided lifetime has a name - --> tests/ui/ptr_arg.rs:317:56 + --> tests/ui/ptr_arg.rs:314:56 | LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str { | -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a` @@ -17,49 +17,49 @@ LL | fn do_vec(x: &Vec) { = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:20:18 + --> tests/ui/ptr_arg.rs:19:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:26:19 + --> tests/ui/ptr_arg.rs:25:19 | LL | fn do_vec_mut2(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:33:14 + --> tests/ui/ptr_arg.rs:32: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 - --> tests/ui/ptr_arg.rs:39:18 + --> tests/ui/ptr_arg.rs:38: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 - --> tests/ui/ptr_arg.rs:45:15 + --> tests/ui/ptr_arg.rs:44: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 - --> tests/ui/ptr_arg.rs:51:19 + --> tests/ui/ptr_arg.rs:50: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 - --> tests/ui/ptr_arg.rs:61:18 + --> tests/ui/ptr_arg.rs:60:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:76:14 + --> tests/ui/ptr_arg.rs:75:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -78,7 +78,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:87:18 + --> tests/ui/ptr_arg.rs:86:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -96,7 +96,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:97:19 + --> tests/ui/ptr_arg.rs:96:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -114,7 +114,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:107:44 + --> tests/ui/ptr_arg.rs:106:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -130,19 +130,19 @@ LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:123:25 + --> tests/ui/ptr_arg.rs:122:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:154:66 + --> tests/ui/ptr_arg.rs:152: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 - --> tests/ui/ptr_arg.rs:185:21 + --> tests/ui/ptr_arg.rs:182:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -157,7 +157,7 @@ LL ~ let _ = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:192:23 + --> tests/ui/ptr_arg.rs:189:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -172,7 +172,7 @@ LL ~ let _ = path.to_path_buf().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:199:21 + --> tests/ui/ptr_arg.rs:196:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -187,55 +187,55 @@ LL ~ let _ = str.to_path_buf().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:207:29 + --> tests/ui/ptr_arg.rs:204: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 - --> tests/ui/ptr_arg.rs:271:17 + --> tests/ui/ptr_arg.rs:268: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 - --> tests/ui/ptr_arg.rs:271:35 + --> tests/ui/ptr_arg.rs:268: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 - --> tests/ui/ptr_arg.rs:271:51 + --> tests/ui/ptr_arg.rs:268: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 - --> tests/ui/ptr_arg.rs:298:39 + --> tests/ui/ptr_arg.rs:295:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:305:36 + --> tests/ui/ptr_arg.rs:302:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:310:40 + --> tests/ui/ptr_arg.rs:307:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:350:17 + --> tests/ui/ptr_arg.rs:347:17 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:350:30 + --> tests/ui/ptr_arg.rs:347:30 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ help: change this to: `&str` diff --git a/tests/ui/pub_use.rs b/tests/ui/pub_use.rs index 4c2c3dfb30cb..be4d1b2a964b 100644 --- a/tests/ui/pub_use.rs +++ b/tests/ui/pub_use.rs @@ -9,7 +9,6 @@ pub mod outer { // should be linted pub use inner::Test; //~^ pub_use - } // should not be linted diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index 609a4d3251e7..fffaa803f39c 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -5,7 +5,7 @@ fn some_func(a: Option) -> Option { if a.is_none() { - //~^ question_mark + //~^ question_mark return None; } @@ -86,7 +86,7 @@ pub struct MoveStruct { impl MoveStruct { pub fn ref_func(&self) -> Option> { if self.opt.is_none() { - //~^ question_mark + //~^ question_mark return None; } @@ -95,7 +95,7 @@ impl MoveStruct { pub fn mov_func_reuse(self) -> Option> { if self.opt.is_none() { - //~^ question_mark + //~^ question_mark return None; } @@ -104,7 +104,7 @@ impl MoveStruct { pub fn mov_func_no_use(self) -> Option> { if self.opt.is_none() { - //~^ question_mark + //~^ question_mark return None; } Some(Vec::new()) @@ -112,7 +112,7 @@ impl MoveStruct { pub fn if_let_ref_func(self) -> Option> { let v: &Vec<_> = if let Some(ref v) = self.opt { - //~^ question_mark + //~^ question_mark v } else { return None; @@ -123,7 +123,7 @@ impl MoveStruct { pub fn if_let_mov_func(self) -> Option> { let v = if let Some(v) = self.opt { - //~^ question_mark + //~^ question_mark v } else { return None; @@ -145,12 +145,12 @@ fn func() -> Option { } if f().is_none() { - //~^ question_mark + //~^ question_mark return None; } let _val = match f() { - //~^ question_mark + //~^ question_mark Some(val) => val, None => return None, }; @@ -161,13 +161,13 @@ fn func() -> Option { }; match f() { - //~^ question_mark + //~^ question_mark Some(val) => val, None => return None, }; match opt_none!() { - //~^ question_mark + //~^ question_mark Some(x) => x, None => return None, }; @@ -197,18 +197,18 @@ fn result_func(x: Result) -> Result { //~^ question_mark if x.is_err() { - //~^ question_mark + //~^ question_mark return x; } let _val = match func_returning_result() { - //~^ question_mark + //~^ question_mark Ok(val) => val, Err(err) => return Err(err), }; match func_returning_result() { - //~^ question_mark + //~^ question_mark Ok(val) => val, Err(err) => return Err(err), }; @@ -300,7 +300,7 @@ fn do_something() {} fn err_immediate_return() -> Result { if let Err(err) = func_returning_result() { - //~^ question_mark + //~^ question_mark return Err(err); } Ok(1) @@ -308,7 +308,7 @@ fn err_immediate_return() -> Result { fn err_immediate_return_and_do_something() -> Result { if let Err(err) = func_returning_result() { - //~^ question_mark + //~^ question_mark return Err(err); } do_something(); @@ -386,7 +386,7 @@ fn issue6828_nested_body() -> Option { try { fn f2(a: Option) -> Option { if a.is_none() { - //~^ question_mark + //~^ question_mark return None; // do lint here, the outer `try` is not relevant here // https://github.com/rust-lang/rust-clippy/pull/11001#issuecomment-1610636867 diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index 3b3e5dc643e1..ad5d131f34bc 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -8,8 +8,6 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Arc::new("x".to_string()); 2]; //~^ rc_clone_in_vec_init - - } fn should_warn_simple_case_with_big_indentation() { @@ -19,8 +17,6 @@ fn should_warn_simple_case_with_big_indentation() { if true { let v = vec![Arc::new("x".to_string()); 2]; //~^ rc_clone_in_vec_init - - } } } diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index 5d70bfc85363..598d3c0ae577 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:20:21 + --> tests/ui/rc_clone_in_vec_init/arc.rs:18:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:29:13 + --> tests/ui/rc_clone_in_vec_init/arc.rs:25:13 | LL | let v = vec![ | _____________^ @@ -74,7 +74,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:41:14 + --> tests/ui/rc_clone_in_vec_init/arc.rs:37: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 e93408798585..d5af17c29e1d 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -9,8 +9,6 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Rc::new("x".to_string()); 2]; //~^ rc_clone_in_vec_init - - } fn should_warn_simple_case_with_big_indentation() { @@ -20,8 +18,6 @@ fn should_warn_simple_case_with_big_indentation() { if true { let v = vec![Rc::new("x".to_string()); 2]; //~^ rc_clone_in_vec_init - - } } } diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index 57ea31f9ff89..60d7f33ada9c 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:21:21 + --> tests/ui/rc_clone_in_vec_init/rc.rs:19:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:30:13 + --> tests/ui/rc_clone_in_vec_init/rc.rs:26:13 | LL | let v = vec![ | _____________^ @@ -74,7 +74,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:42:14 + --> tests/ui/rc_clone_in_vec_init/rc.rs:38: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 af1ec1601dcf..add09b6ba859 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -10,20 +10,14 @@ fn should_warn_simple_case() { let v = vec![SyncWeak::::new(); 2]; //~^ rc_clone_in_vec_init - let v2 = vec![UnSyncWeak::::new(); 2]; //~^ rc_clone_in_vec_init - - let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; //~^ rc_clone_in_vec_init - let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; //~^ rc_clone_in_vec_init - - } fn should_warn_simple_case_with_big_indentation() { @@ -34,11 +28,8 @@ fn should_warn_simple_case_with_big_indentation() { let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; //~^ rc_clone_in_vec_init - let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; //~^ rc_clone_in_vec_init - - } } } diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index 26974dd7446c..8bd018ab586c 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -24,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:14:14 + --> tests/ui/rc_clone_in_vec_init/weak.rs:13:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:19:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:16:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:23:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:19:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -93,7 +93,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:34:21 + --> tests/ui/rc_clone_in_vec_init/weak.rs:28:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -116,7 +116,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:38:22 + --> tests/ui/rc_clone_in_vec_init/weak.rs:31:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,7 +139,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:47:13 + --> tests/ui/rc_clone_in_vec_init/weak.rs:38:13 | LL | let v = vec![ | _____________^ @@ -166,7 +166,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:59:14 + --> tests/ui/rc_clone_in_vec_init/weak.rs:50:14 | LL | let v1 = vec![ | ______________^ diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index cccbc751f417..c8700e13b11e 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -33,7 +33,6 @@ fn test2(foo: Rc>) {} fn test3(foo: Rc>>) {} //~^ rc_mutex - // All of these test should be allowed because they are part of the // public api and `avoid_breaking_exported_api` is `false` by default. pub fn pub_test1(foo: Rc>) {} diff --git a/tests/ui/read_line_without_trim.fixed b/tests/ui/read_line_without_trim.fixed index 9263a398ad85..e7f208e78d20 100644 --- a/tests/ui/read_line_without_trim.fixed +++ b/tests/ui/read_line_without_trim.fixed @@ -41,14 +41,14 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.trim_end() == "foo" { - //~^ read_line_without_trim + //~^ read_line_without_trim println!("This will never ever execute!"); } let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.trim_end().ends_with("foo") { - //~^ read_line_without_trim + //~^ read_line_without_trim println!("Neither will this"); } } diff --git a/tests/ui/read_line_without_trim.rs b/tests/ui/read_line_without_trim.rs index ba5196bb51ba..6664278b5a87 100644 --- a/tests/ui/read_line_without_trim.rs +++ b/tests/ui/read_line_without_trim.rs @@ -41,14 +41,14 @@ fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input == "foo" { - //~^ read_line_without_trim + //~^ read_line_without_trim println!("This will never ever execute!"); } let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); if input.ends_with("foo") { - //~^ read_line_without_trim + //~^ read_line_without_trim println!("Neither will this"); } } diff --git a/tests/ui/readonly_write_lock.fixed b/tests/ui/readonly_write_lock.fixed index 21822444f35f..0cb91247232b 100644 --- a/tests/ui/readonly_write_lock.fixed +++ b/tests/ui/readonly_write_lock.fixed @@ -16,7 +16,6 @@ fn main() { let writer = lock.read().unwrap(); //~^ readonly_write_lock - dbg!(&writer); } diff --git a/tests/ui/readonly_write_lock.rs b/tests/ui/readonly_write_lock.rs index b3fd1a611cc8..843755fe792c 100644 --- a/tests/ui/readonly_write_lock.rs +++ b/tests/ui/readonly_write_lock.rs @@ -16,7 +16,6 @@ fn main() { let writer = lock.write().unwrap(); //~^ readonly_write_lock - dbg!(&writer); } diff --git a/tests/ui/readonly_write_lock.stderr b/tests/ui/readonly_write_lock.stderr index a3f88e92bfae..6b1ef3c4720f 100644 --- a/tests/ui/readonly_write_lock.stderr +++ b/tests/ui/readonly_write_lock.stderr @@ -8,7 +8,7 @@ LL | let writer = lock.write().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::readonly_write_lock)]` error: this write lock is used only for reading - --> tests/ui/readonly_write_lock.rs:24:22 + --> tests/ui/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 d9b3a15eb9b1..9f46fef62354 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -30,8 +30,6 @@ impl fmt::Display for A { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.to_string()) //~^ recursive_format_impl - - } } @@ -77,7 +75,6 @@ impl std::fmt::Display for G { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) //~^ recursive_format_impl - } } @@ -88,7 +85,6 @@ impl std::fmt::Display for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self) //~^ recursive_format_impl - } } @@ -96,7 +92,6 @@ impl std::fmt::Debug for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", &self) //~^ recursive_format_impl - } } @@ -107,7 +102,6 @@ impl std::fmt::Display for H2 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &&&self) //~^ recursive_format_impl - } } @@ -183,7 +177,6 @@ impl std::fmt::Display for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &*self) //~^ recursive_format_impl - } } @@ -191,7 +184,6 @@ impl std::fmt::Debug for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", &*self) //~^ recursive_format_impl - } } @@ -209,7 +201,6 @@ impl std::fmt::Display for J2 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", *self) //~^ recursive_format_impl - } } @@ -227,7 +218,6 @@ impl std::fmt::Display for J3 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", **&&*self) //~^ recursive_format_impl - } } @@ -245,7 +235,6 @@ impl std::fmt::Display for J4 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &&**&&*self) //~^ recursive_format_impl - } } diff --git a/tests/ui/recursive_format_impl.stderr b/tests/ui/recursive_format_impl.stderr index 515f18d5b477..31960c7193b4 100644 --- a/tests/ui/recursive_format_impl.stderr +++ b/tests/ui/recursive_format_impl.stderr @@ -8,7 +8,7 @@ LL | write!(f, "{}", self.to_string()) = help: to override `-D warnings` add `#[allow(clippy::recursive_format_impl)]` error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> tests/ui/recursive_format_impl.rs:78:9 + --> tests/ui/recursive_format_impl.rs:76:9 | LL | write!(f, "{}", self) | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,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 - --> tests/ui/recursive_format_impl.rs:89:9 + --> tests/ui/recursive_format_impl.rs:86:9 | LL | write!(f, "{}", &self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,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 - --> tests/ui/recursive_format_impl.rs:97:9 + --> tests/ui/recursive_format_impl.rs:93:9 | LL | write!(f, "{:?}", &self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,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 - --> tests/ui/recursive_format_impl.rs:108:9 + --> tests/ui/recursive_format_impl.rs:103:9 | LL | write!(f, "{}", &&&self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,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 - --> tests/ui/recursive_format_impl.rs:184:9 + --> tests/ui/recursive_format_impl.rs:178:9 | LL | write!(f, "{}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,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 - --> tests/ui/recursive_format_impl.rs:192:9 + --> tests/ui/recursive_format_impl.rs:185:9 | LL | write!(f, "{:?}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,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 - --> tests/ui/recursive_format_impl.rs:210:9 + --> tests/ui/recursive_format_impl.rs:202:9 | LL | write!(f, "{}", *self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,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 - --> tests/ui/recursive_format_impl.rs:228:9 + --> tests/ui/recursive_format_impl.rs:219:9 | LL | write!(f, "{}", **&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,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 - --> tests/ui/recursive_format_impl.rs:246:9 + --> tests/ui/recursive_format_impl.rs:236:9 | LL | write!(f, "{}", &&**&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index e3bf6c58b153..0562f7dcc761 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -16,26 +16,18 @@ mod outer_box { pub fn box_test6(foo: Box>) {} //~^ redundant_allocation - - pub fn box_test7(foo: Box>) {} //~^ redundant_allocation - - pub fn box_test8() -> Box>> { - //~^ redundant_allocation - + //~^ redundant_allocation unimplemented!(); } pub fn box_test9(foo: Box>) -> Box>> { - //~^ redundant_allocation - //~| redundant_allocation - - - + //~^ redundant_allocation + //~| redundant_allocation unimplemented!(); } @@ -50,26 +42,18 @@ mod outer_rc { pub fn rc_test5(a: Rc>) {} //~^ redundant_allocation - - pub fn rc_test7(a: Rc>) {} //~^ redundant_allocation - - pub fn rc_test8() -> Rc>> { - //~^ redundant_allocation - + //~^ redundant_allocation unimplemented!(); } pub fn rc_test9(foo: Rc>) -> Rc>> { - //~^ redundant_allocation - //~| redundant_allocation - - - + //~^ redundant_allocation + //~| redundant_allocation unimplemented!(); } @@ -84,26 +68,18 @@ mod outer_arc { pub fn arc_test5(a: Arc>) {} //~^ redundant_allocation - - pub fn arc_test6(a: Arc>) {} //~^ redundant_allocation - - pub fn arc_test8() -> Arc>> { - //~^ redundant_allocation - + //~^ redundant_allocation unimplemented!(); } pub fn arc_test9(foo: Arc>) -> Arc>> { - //~^ redundant_allocation - //~| redundant_allocation - - - + //~^ redundant_allocation + //~| redundant_allocation unimplemented!(); } @@ -128,8 +104,6 @@ mod box_dyn { pub fn test_arc(_: Arc>) {} pub fn test_rc_box(_: Rc>>) {} //~^ redundant_allocation - - } // https://github.com/rust-lang/rust-clippy/issues/8604 @@ -164,19 +138,14 @@ mod box_fat_ptr { pub fn test_rc_box_str(_: Rc>>) {} //~^ redundant_allocation - pub fn test_rc_box_slice(_: Rc>>) {} //~^ redundant_allocation - pub fn test_rc_box_path(_: Rc>>) {} //~^ redundant_allocation - pub fn test_rc_box_custom(_: Rc>>) {} //~^ redundant_allocation - - } // https://github.com/rust-lang/rust-clippy/issues/11417 diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index 407cdef1c20d..44d30f95d7bc 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -10,7 +10,7 @@ LL | pub fn box_test6(foo: Box>) {} = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:21:30 + --> tests/ui/redundant_allocation.rs:19:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:26:27 + --> tests/ui/redundant_allocation.rs:22:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:33:30 + --> tests/ui/redundant_allocation.rs:28:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:33:46 + --> tests/ui/redundant_allocation.rs:28:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:50:24 + --> tests/ui/redundant_allocation.rs:42:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:55:24 + --> tests/ui/redundant_allocation.rs:45:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:60:26 + --> tests/ui/redundant_allocation.rs:48:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:67:29 + --> tests/ui/redundant_allocation.rs:54:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:67:44 + --> tests/ui/redundant_allocation.rs:54:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:84:25 + --> tests/ui/redundant_allocation.rs:68:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:89:25 + --> tests/ui/redundant_allocation.rs:71:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:94:27 + --> tests/ui/redundant_allocation.rs:74:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:101:30 + --> tests/ui/redundant_allocation.rs:80:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -127,7 +127,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:101:45 + --> tests/ui/redundant_allocation.rs:80:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:129:27 + --> tests/ui/redundant_allocation.rs:105:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:164:31 + --> tests/ui/redundant_allocation.rs:138:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:168:33 + --> tests/ui/redundant_allocation.rs:141:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:172:32 + --> tests/ui/redundant_allocation.rs:144:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -172,7 +172,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:176:34 + --> tests/ui/redundant_allocation.rs:147:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index e0657246bd00..23c00b34a00a 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -221,7 +221,7 @@ fn clone_then_move_cloned() { let x = Alpha; // ok, data is moved while the clone is in use. foo(&x, move || { - //~^ redundant_clone + //~^ redundant_clone let _ = x; }); diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index 53e60a44d7df..f9fe8ba0236d 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -221,7 +221,7 @@ fn clone_then_move_cloned() { let x = Alpha; // ok, data is moved while the clone is in use. foo(&x.clone(), move || { - //~^ redundant_clone + //~^ redundant_clone let _ = x; }); diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs index 2f4feeed9ae6..722f7c03909f 100644 --- a/tests/ui/redundant_closure_call_early.rs +++ b/tests/ui/redundant_closure_call_early.rs @@ -9,13 +9,10 @@ fn main() { let mut k = (|m| m + 1)(i); //~^ redundant_closure_call - - // lint here k = (|a, b| a * b)(1, 5); //~^ redundant_closure_call - // don't lint these #[allow(clippy::needless_return)] (|| return 2)(); diff --git a/tests/ui/redundant_closure_call_early.stderr b/tests/ui/redundant_closure_call_early.stderr index 4cfde9a64b57..1dd24baf9dae 100644 --- a/tests/ui/redundant_closure_call_early.stderr +++ b/tests/ui/redundant_closure_call_early.stderr @@ -8,7 +8,7 @@ LL | let mut k = (|m| m + 1)(i); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: try not to call a closure in the expression where it is declared - --> tests/ui/redundant_closure_call_early.rs:15:9 + --> tests/ui/redundant_closure_call_early.rs:13:9 | LL | k = (|a, b| a * b)(1, 5); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed index 528a2000693e..099c118e64e3 100644 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ b/tests/ui/redundant_closure_call_fixable.fixed @@ -15,13 +15,13 @@ fn main() { let a = 42; //~^ redundant_closure_call let b = async { - //~^ redundant_closure_call + //~^ redundant_closure_call let x = something().await; let y = something_else().await; x * y }; let c = { - //~^ redundant_closure_call + //~^ redundant_closure_call let x = 21; let y = 2; x * y diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs index c3cbd8d61ada..da5dd7ef263b 100644 --- a/tests/ui/redundant_closure_call_fixable.rs +++ b/tests/ui/redundant_closure_call_fixable.rs @@ -15,13 +15,13 @@ fn main() { let a = (|| 42)(); //~^ redundant_closure_call let b = (async || { - //~^ redundant_closure_call + //~^ redundant_closure_call let x = something().await; let y = something_else().await; x * y })(); let c = (|| { - //~^ redundant_closure_call + //~^ redundant_closure_call let x = 21; let y = 2; x * y diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs index c697fedb871e..fd997b1b5fa7 100644 --- a/tests/ui/redundant_closure_call_late.rs +++ b/tests/ui/redundant_closure_call_late.rs @@ -16,8 +16,6 @@ fn main() { i = redun_closure(); //~^ redundant_closure_call - - // shadowed closures are supported, lint here let shadowed_closure = || 1; i = shadowed_closure(); @@ -27,7 +25,6 @@ fn main() { i = shadowed_closure(); //~^ redundant_closure_call - // don't lint here let shadowed_closure = || 2; i = shadowed_closure(); diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr index abe7ac7b6595..ce2a21c23872 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -8,13 +8,13 @@ LL | i = redun_closure(); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:23:5 + --> tests/ui/redundant_closure_call_late.rs:21:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:27:5 + --> tests/ui/redundant_closure_call_late.rs:25:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_else.fixed b/tests/ui/redundant_else.fixed index 4dc325330249..8a3279f50180 100644 --- a/tests/ui/redundant_else.fixed +++ b/tests/ui/redundant_else.fixed @@ -10,7 +10,7 @@ fn main() { } //~^ redundant_else - println!("yet don't pull down your hedge."); + println!("yet don't pull down your hedge."); // continue if foo() { println!("He that lies down with Dogs,"); @@ -18,7 +18,7 @@ fn main() { } //~^ redundant_else - println!("shall rise up with fleas."); + println!("shall rise up with fleas."); // match block if foo() { match foo() { @@ -28,7 +28,7 @@ fn main() { } //~^ redundant_else - println!("You may delay, but time will not."); + println!("You may delay, but time will not."); } // else if if foo() { @@ -38,7 +38,7 @@ fn main() { } //~^ redundant_else - println!("A fat kitchen makes a lean will."); + println!("A fat kitchen makes a lean will."); // let binding outside of block let _ = { if foo() { @@ -46,7 +46,7 @@ fn main() { } //~^ redundant_else - 1 + 1 }; // else if with let binding outside of block let _ = { @@ -57,7 +57,7 @@ fn main() { } //~^ redundant_else - 2 + 2 }; // inside if let let _ = if let Some(1) = foo() { @@ -67,7 +67,7 @@ fn main() { } //~^ redundant_else - 1 + 1 } else { 1 }; diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 842cb4bc9411..78abf4247a56 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -8,7 +8,7 @@ fn main() { println!("Love your neighbor;"); break; } else { - //~^ redundant_else + //~^ redundant_else println!("yet don't pull down your hedge."); } @@ -17,7 +17,7 @@ fn main() { println!("He that lies down with Dogs,"); continue; } else { - //~^ redundant_else + //~^ redundant_else println!("shall rise up with fleas."); } @@ -28,7 +28,7 @@ fn main() { _ => return, } } else { - //~^ redundant_else + //~^ redundant_else println!("You may delay, but time will not."); } @@ -39,7 +39,7 @@ fn main() { } else if foo() { return; } else { - //~^ redundant_else + //~^ redundant_else println!("A fat kitchen makes a lean will."); } @@ -48,7 +48,7 @@ fn main() { if foo() { return; } else { - //~^ redundant_else + //~^ redundant_else 1 } @@ -60,7 +60,7 @@ fn main() { } else if foo() { return; } else { - //~^ redundant_else + //~^ redundant_else 2 } @@ -71,7 +71,7 @@ fn main() { if foo() { return; } else { - //~^ redundant_else + //~^ redundant_else 1 } diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index 2cb0fd6f127f..0902c97af0dd 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -16,7 +16,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + println!("yet don't pull down your hedge."); +LL + println!("yet don't pull down your hedge."); | error: redundant else block @@ -35,7 +35,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + println!("shall rise up with fleas."); +LL + println!("shall rise up with fleas."); | error: redundant else block @@ -54,7 +54,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + println!("You may delay, but time will not."); +LL + println!("You may delay, but time will not."); | error: redundant else block @@ -73,7 +73,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + println!("A fat kitchen makes a lean will."); +LL + println!("A fat kitchen makes a lean will."); | error: redundant else block @@ -92,7 +92,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + 1 +LL + 1 | error: redundant else block @@ -111,7 +111,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + 2 +LL + 2 | error: redundant else block @@ -130,7 +130,7 @@ help: remove the `else` block and move the contents out LL ~ } LL + LL + -LL + 1 +LL + 1 | error: aborting due to 7 previous errors diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed index 142828a2b2d8..4c922030eb66 100644 --- a/tests/ui/redundant_field_names.fixed +++ b/tests/ui/redundant_field_names.fixed @@ -34,7 +34,6 @@ fn main() { //~^ redundant_field_names age, //~^ redundant_field_names - name, //should be ok buzz: fizz, //should be ok foo: foo::BAR, //should be ok diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index 15fef11a0408..7d03e269cf25 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -34,7 +34,6 @@ fn main() { //~^ redundant_field_names age: age, //~^ redundant_field_names - name, //should be ok buzz: fizz, //should be ok foo: foo::BAR, //should be ok diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 78b8a4f1118e..5554c28b7cff 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -14,37 +14,37 @@ LL | age: age, | ^^^^^^^^ help: replace it with: `age` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:57:25 + --> tests/ui/redundant_field_names.rs:56:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:59:23 + --> tests/ui/redundant_field_names.rs:58:23 | LL | let _ = RangeTo { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:61:21 + --> tests/ui/redundant_field_names.rs:60:21 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:61:35 + --> tests/ui/redundant_field_names.rs:60:35 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:65:32 + --> tests/ui/redundant_field_names.rs:64:32 | LL | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:78:25 + --> tests/ui/redundant_field_names.rs:77:25 | LL | let _ = S { v: v }; | ^^^^ help: replace it with: `v` @@ -55,7 +55,7 @@ LL | internal!(v); = note: this error originates in the macro `internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: redundant field names in struct initialization - --> tests/ui/redundant_field_names.rs:107:25 + --> tests/ui/redundant_field_names.rs:106: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 c7e6f44ad83e..9dd9d341db2e 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -52,7 +52,7 @@ fn main() { Some(Some(1)) if true => .., //~^ redundant_guards Some(Some(1)) => { - //~^ redundant_guards + //~^ redundant_guards println!("a"); .. }, diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index d3c55c18884d..e9950d3bbd1d 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -52,7 +52,7 @@ fn main() { Some(x) if matches!(x, Some(1) if true) => .., //~^ redundant_guards Some(x) if matches!(x, Some(1)) => { - //~^ redundant_guards + //~^ redundant_guards println!("a"); .. }, diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index 4de47a1ad3ee..1141b5db3ebf 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -22,7 +22,7 @@ fn main() { //~^ redundant_pattern_matching } if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} @@ -46,7 +46,7 @@ fn main() { //~^ redundant_pattern_matching } if None::>.is_none() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } @@ -69,7 +69,7 @@ fn main() { //~^ redundant_pattern_matching } if Pending::>.is_pending() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index 4e37837c1fe6..f60ddf468309 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -22,7 +22,7 @@ fn main() { //~^ redundant_pattern_matching } if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} @@ -46,7 +46,7 @@ fn main() { //~^ redundant_pattern_matching } if let None = None::> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } @@ -69,7 +69,7 @@ fn main() { //~^ redundant_pattern_matching } if let Pending = Pending::> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching } else { } diff --git a/tests/ui/redundant_pattern_matching_if_let_true.fixed b/tests/ui/redundant_pattern_matching_if_let_true.fixed index f40cd01d16cb..980455da2ee7 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.fixed +++ b/tests/ui/redundant_pattern_matching_if_let_true.fixed @@ -27,11 +27,11 @@ fn main() { //~^ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} while k > 1 { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching k += 1; } while condition!() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching k += 1; } diff --git a/tests/ui/redundant_pattern_matching_if_let_true.rs b/tests/ui/redundant_pattern_matching_if_let_true.rs index 143c279e41c1..9cb0fe2e65f6 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.rs +++ b/tests/ui/redundant_pattern_matching_if_let_true.rs @@ -27,11 +27,11 @@ fn main() { //~^ redundant_pattern_matching if let (true, true) = (k > 1, k > 2) {} while let true = k > 1 { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching k += 1; } while let true = condition!() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching k += 1; } diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed index 05ea8f75dc89..549c97d9534a 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -52,7 +52,7 @@ fn main() { V6(Ipv6Addr::LOCALHOST).is_ipv4(); let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching true } else { false @@ -61,10 +61,10 @@ fn main() { ipaddr_const(); let _ = if gen_ipaddr().is_ipv4() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if gen_ipaddr().is_ipv6() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs index 4ff9b2204e8a..decb1396d56d 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -44,31 +44,31 @@ fn main() { } match V4(Ipv4Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; match V4(Ipv4Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; match V6(Ipv6Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; match V6(Ipv6Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching true } else { false @@ -77,10 +77,10 @@ fn main() { ipaddr_const(); let _ = if let V4(_) = gen_ipaddr() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if let V6(_) = gen_ipaddr() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 @@ -105,13 +105,13 @@ const fn ipaddr_const() { //~^ redundant_pattern_matching match V4(Ipv4Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => true, V6(_) => false, }; match V6(Ipv6Addr::LOCALHOST) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching V4(_) => false, V6(_) => true, }; diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index 7d45bb63a395..711196f8e19b 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -38,7 +38,7 @@ fn main() { //~^ redundant_pattern_matching if Some(42).is_some() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -55,7 +55,7 @@ fn main() { let mut v = vec![1, 2, 3]; while v.pop().is_some() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } @@ -78,10 +78,10 @@ fn main() { issue10803(); let _ = if gen_opt().is_some() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if gen_opt().is_none() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index 3d02bade4409..41106840cb8d 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -38,7 +38,7 @@ fn main() { //~^ redundant_pattern_matching if let Some(_) = Some(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -55,7 +55,7 @@ fn main() { let mut v = vec![1, 2, 3]; while let Some(_) = v.pop() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } @@ -64,19 +64,19 @@ fn main() { if Some(42).is_some() {} match Some(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => true, None => false, }; match None::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => false, None => true, }; let _ = match None::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => false, None => true, }; @@ -90,10 +90,10 @@ fn main() { issue10803(); let _ = if let Some(_) = gen_opt() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if let None = gen_opt() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 @@ -128,13 +128,13 @@ const fn issue6067() { //~^ redundant_pattern_matching match Some(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => true, None => false, }; match None::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => false, None => true, }; @@ -152,25 +152,25 @@ fn issue10726() { let x = Some(42); match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => true, _ => false, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching None => true, _ => false, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Some(_) => false, _ => true, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching None => false, _ => true, }; diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed index f3ffb6b3c755..c8e18e8676f2 100644 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ b/tests/ui/redundant_pattern_matching_poll.fixed @@ -19,7 +19,7 @@ fn main() { //~^ redundant_pattern_matching if Ready(42).is_ready() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -59,10 +59,10 @@ fn main() { poll_const(); let _ = if gen_poll().is_ready() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if gen_poll().is_pending() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs index 30e80b24521d..727503d21a54 100644 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ b/tests/ui/redundant_pattern_matching_poll.rs @@ -19,7 +19,7 @@ fn main() { //~^ redundant_pattern_matching if let Ready(_) = Ready(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching foo(); } else { bar(); @@ -47,19 +47,19 @@ fn main() { if Ready(42).is_ready() {} match Ready(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ready(_) => true, Pending => false, }; match Pending::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; let _ = match Pending::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; @@ -71,10 +71,10 @@ fn main() { poll_const(); let _ = if let Ready(_) = gen_poll() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if let Pending = gen_poll() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 @@ -103,13 +103,13 @@ const fn poll_const() { //~^ redundant_pattern_matching match Ready(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ready(_) => true, Pending => false, }; match Pending::<()> { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ready(_) => false, Pending => true, }; diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index 3bb9dacf4618..115879608314 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -53,10 +53,10 @@ fn main() { issue10803(); let _ = if gen_res().is_ok() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if gen_res().is_err() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index f2632286ea3c..35f8f91b3152 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -36,25 +36,25 @@ fn main() { } match Ok::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; match Ok::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; match Err::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; match Err::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; @@ -69,10 +69,10 @@ fn main() { issue10803(); let _ = if let Ok(_) = gen_res() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 1 } else if let Err(_) = gen_res() { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching 2 } else { 3 @@ -138,13 +138,13 @@ const fn issue6067() { //~^ redundant_pattern_matching match Ok::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => true, Err(_) => false, }; match Err::(42) { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => false, Err(_) => true, }; @@ -155,25 +155,25 @@ fn issue10726() { let x: Result = Ok(42); match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => true, _ => false, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Ok(_) => false, _ => true, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Err(_) => true, _ => false, }; match x { - //~^ redundant_pattern_matching + //~^ redundant_pattern_matching Err(_) => false, _ => true, }; diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index 2072282bd2c3..7424af19a999 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -16,7 +16,7 @@ mod m1 { } pub mod m1_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ private due to m1 fn f() {} pub fn g() {} // private due to m1_2 and m1 @@ -46,7 +46,7 @@ pub(crate) mod m2 { } pub mod m2_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ already crate visible due to m2 fn f() {} pub fn g() {} // already crate visible due to m2_2 and m2 @@ -103,7 +103,7 @@ mod m4 { } pub mod m4_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ private: not re-exported by `pub use m4::*` fn f() {} pub fn g() {} // private due to m4_2 diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index d8eaa8cdbc69..a995ed592289 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -16,7 +16,7 @@ mod m1 { } pub(crate) mod m1_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ private due to m1 fn f() {} pub(crate) fn g() {} // private due to m1_2 and m1 @@ -46,7 +46,7 @@ pub(crate) mod m2 { } pub(crate) mod m2_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ already crate visible due to m2 fn f() {} pub(crate) fn g() {} // already crate visible due to m2_2 and m2 @@ -103,7 +103,7 @@ mod m4 { } pub(crate) mod m4_2 { - //~^ redundant_pub_crate + //~^ redundant_pub_crate //:^ private: not re-exported by `pub use m4::*` fn f() {} pub(crate) fn g() {} // private due to m4_2 diff --git a/tests/ui/redundant_static_lifetimes_multiple.rs b/tests/ui/redundant_static_lifetimes_multiple.rs index 02f3829d8c03..8cb6e4491842 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/tests/ui/redundant_static_lifetimes_multiple.rs @@ -5,31 +5,20 @@ const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ER //~^ redundant_static_lifetimes //~| redundant_static_lifetimes - - - const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; //~^ redundant_static_lifetimes //~| redundant_static_lifetimes - - static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static //~^ redundant_static_lifetimes //~| redundant_static_lifetimes - - static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static //~^ redundant_static_lifetimes //~| redundant_static_lifetimes - - static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; //~^ redundant_static_lifetimes //~| redundant_static_lifetimes - - fn main() {} diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 486a23b06089..aed16204f1c2 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -14,49 +14,49 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> tests/ui/redundant_static_lifetimes_multiple.rs:11:29 + --> tests/ui/redundant_static_lifetimes_multiple.rs:8: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:11:39 + --> tests/ui/redundant_static_lifetimes_multiple.rs:8: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:17:40 + --> tests/ui/redundant_static_lifetimes_multiple.rs:12: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:17:55 + --> tests/ui/redundant_static_lifetimes_multiple.rs:12: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:23:26 + --> tests/ui/redundant_static_lifetimes_multiple.rs:16: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:23:38 + --> tests/ui/redundant_static_lifetimes_multiple.rs:16: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:29:37 + --> tests/ui/redundant_static_lifetimes_multiple.rs:20: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 - --> tests/ui/redundant_static_lifetimes_multiple.rs:29:47 + --> tests/ui/redundant_static_lifetimes_multiple.rs:20: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 5023ec7ee576..55c19d194a49 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -81,13 +81,11 @@ impl Pie { let v: u32 = self.return_an_int(); //~^ redundant_type_annotations - let v: &u32 = self.return_a_ref(); //~^ redundant_type_annotations let v: &Slice = self.return_a_ref_to_struct(); //~^ redundant_type_annotations - } } @@ -162,38 +160,29 @@ fn test_functions() { let _return: String = return_a_string(); //~^ redundant_type_annotations - let _return: Pie = return_a_struct(); //~^ redundant_type_annotations - let _return: Pizza = return_an_enum(); //~^ redundant_type_annotations - let _return: u32 = return_an_int(); //~^ redundant_type_annotations - let _return: String = String::new(); //~^ redundant_type_annotations - let new_pie: Pie = Pie::new(); //~^ redundant_type_annotations - let _return: u32 = new_pie.return_an_int(); //~^ redundant_type_annotations - let _return: u32 = Pie::associated_return_an_int(); //~^ redundant_type_annotations - let _return: String = Pie::associated_return_a_string(); //~^ redundant_type_annotations - } fn test_simple_types() { @@ -202,22 +191,17 @@ fn test_simple_types() { let _var: u32 = u32::MAX; //~^ redundant_type_annotations - let _var: u32 = 5_u32; //~^ redundant_type_annotations - let _var: &str = "test"; //~^ redundant_type_annotations - let _var: &[u8; 4] = b"test"; //~^ redundant_type_annotations - let _var: bool = false; //~^ redundant_type_annotations - } fn issue12212() { diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index de78ad5e4b48..d2f04cc4768e 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -8,97 +8,97 @@ LL | let v: u32 = self.return_an_int(); = help: to override `-D warnings` add `#[allow(clippy::redundant_type_annotations)]` error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:85:9 + --> tests/ui/redundant_type_annotations.rs:84:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:88:9 + --> tests/ui/redundant_type_annotations.rs:87:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:162:5 + --> tests/ui/redundant_type_annotations.rs:160:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:166:5 + --> tests/ui/redundant_type_annotations.rs:163:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:170:5 + --> tests/ui/redundant_type_annotations.rs:166:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:174:5 + --> tests/ui/redundant_type_annotations.rs:169:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:178:5 + --> tests/ui/redundant_type_annotations.rs:172:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:182:5 + --> tests/ui/redundant_type_annotations.rs:175:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:186:5 + --> tests/ui/redundant_type_annotations.rs:178:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:190:5 + --> tests/ui/redundant_type_annotations.rs:181:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:194:5 + --> tests/ui/redundant_type_annotations.rs:184:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:202:5 + --> tests/ui/redundant_type_annotations.rs:191:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:206:5 + --> tests/ui/redundant_type_annotations.rs:194:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:210:5 + --> tests/ui/redundant_type_annotations.rs:197:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:214:5 + --> tests/ui/redundant_type_annotations.rs:200:5 | LL | let _var: &[u8; 4] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:218:5 + --> tests/ui/redundant_type_annotations.rs:203: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 55df796c41dc..365fd8edea78 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -29,15 +29,13 @@ fn main() { let _: &&String = match Some(&x) { Some(ref x) => x, //~^ ref_binding_to_reference - - None => return, }; // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => { - //~^ ref_binding_to_reference + //~^ ref_binding_to_reference f1(x); f1(*x); @@ -50,13 +48,12 @@ fn main() { match Some(&x) { Some(ref x) => m2!(x), //~^ ref_binding_to_reference - None => return, } // Err, reference to a &String let _ = |&ref x: &&String| { - //~^ ref_binding_to_reference + //~^ ref_binding_to_reference let _: &&String = x; }; @@ -64,7 +61,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { -//~^ ref_binding_to_reference + //~^ ref_binding_to_reference let _: &&String = x; *x @@ -73,7 +70,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { - //~^ ref_binding_to_reference + //~^ ref_binding_to_reference let _: &&String = x; } @@ -83,7 +80,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { - //~^ ref_binding_to_reference + //~^ ref_binding_to_reference let _: &&String = x; } diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 66e769ec61b3..d245355c139d 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -12,7 +12,7 @@ LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:39:14 + --> tests/ui/ref_binding_to_reference.rs:37:14 | LL | Some(ref x) => { | ^^^^^ @@ -28,7 +28,7 @@ LL ~ &x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:51:14 + --> tests/ui/ref_binding_to_reference.rs:49:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -39,7 +39,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:58:15 + --> tests/ui/ref_binding_to_reference.rs:55:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -53,7 +53,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:66:12 + --> tests/ui/ref_binding_to_reference.rs:63:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -68,7 +68,7 @@ LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:75:11 + --> tests/ui/ref_binding_to_reference.rs:72:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -82,7 +82,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:85:11 + --> tests/ui/ref_binding_to_reference.rs:82:11 | LL | fn f(&ref x: &&String) { | ^^^^^ diff --git a/tests/ui/ref_option/ref_option.all.fixed b/tests/ui/ref_option/ref_option.all.fixed index d7b0e13e5bb9..4159e916f199 100644 --- a/tests/ui/ref_option/ref_option.all.fixed +++ b/tests/ui/ref_option/ref_option.all.fixed @@ -12,17 +12,17 @@ fn opt_gen(a: Option<&T>) {} fn opt_string(a: std::option::Option<&String>) {} //~^ ref_option fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { -//~^ ref_option + //~^ ref_option panic!() } fn ret_string_static() -> Option<&'static u8> { -//~^ ref_option + //~^ ref_option panic!() } fn mult_string(a: Option<&String>, b: Option<&Vec>) {} //~^ ref_option fn ret_box<'a>() -> Option<&'a Box> { -//~^ ref_option + //~^ ref_option panic!() } @@ -51,14 +51,14 @@ impl PubStruct { pub fn pub_opt_params(&self, a: Option<&()>) {} //~[all]^ ref_option pub fn pub_opt_ret(&self) -> Option<&String> { - //~[all]^ ref_option + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: Option<&()>) {} //~^ ref_option fn private_opt_ret(&self) -> Option<&String> { - //~^ ref_option + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option/ref_option.private.fixed b/tests/ui/ref_option/ref_option.private.fixed index 4036c6a08dca..3b158befb926 100644 --- a/tests/ui/ref_option/ref_option.private.fixed +++ b/tests/ui/ref_option/ref_option.private.fixed @@ -12,17 +12,17 @@ fn opt_gen(a: Option<&T>) {} fn opt_string(a: std::option::Option<&String>) {} //~^ ref_option fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { -//~^ ref_option + //~^ ref_option panic!() } fn ret_string_static() -> Option<&'static u8> { -//~^ ref_option + //~^ ref_option panic!() } fn mult_string(a: Option<&String>, b: Option<&Vec>) {} //~^ ref_option fn ret_box<'a>() -> Option<&'a Box> { -//~^ ref_option + //~^ ref_option panic!() } @@ -51,14 +51,14 @@ impl PubStruct { pub fn pub_opt_params(&self, a: &Option<()>) {} //~[all]^ ref_option pub fn pub_opt_ret(&self) -> &Option { - //~[all]^ ref_option + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: Option<&()>) {} //~^ ref_option fn private_opt_ret(&self) -> Option<&String> { - //~^ ref_option + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option/ref_option.rs b/tests/ui/ref_option/ref_option.rs index 86b5c6fe896b..35cd94174f8b 100644 --- a/tests/ui/ref_option/ref_option.rs +++ b/tests/ui/ref_option/ref_option.rs @@ -12,17 +12,17 @@ fn opt_gen(a: &Option) {} fn opt_string(a: &std::option::Option) {} //~^ ref_option fn ret_string<'a>(p: &'a str) -> &'a Option { -//~^ ref_option + //~^ ref_option panic!() } fn ret_string_static() -> &'static Option { -//~^ ref_option + //~^ ref_option panic!() } fn mult_string(a: &Option, b: &Option>) {} //~^ ref_option fn ret_box<'a>() -> &'a Option> { -//~^ ref_option + //~^ ref_option panic!() } @@ -51,14 +51,14 @@ impl PubStruct { pub fn pub_opt_params(&self, a: &Option<()>) {} //~[all]^ ref_option pub fn pub_opt_ret(&self) -> &Option { - //~[all]^ ref_option + //~[all]^ ref_option panic!() } fn private_opt_params(&self, a: &Option<()>) {} //~^ ref_option fn private_opt_ret(&self) -> &Option { - //~^ ref_option + //~^ ref_option panic!() } } diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index de936cb08108..9632611f7df4 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -10,25 +10,21 @@ static THRESHOLD: i32 = 10; static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); //~^ ref_option_ref - const CONST_THRESHOLD: &i32 = &10; const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); //~^ ref_option_ref - type RefOptRefU32<'a> = &'a Option<&'a u32>; //~^ ref_option_ref type RefOptRef<'a, T> = &'a Option<&'a T>; //~^ ref_option_ref - fn foo(data: &Option<&u32>) {} //~^ ref_option_ref - fn bar(data: &u32) -> &Option<&u32> { -//~^ ref_option_ref + //~^ ref_option_ref &None } @@ -36,18 +32,15 @@ fn bar(data: &u32) -> &Option<&u32> { struct StructRef<'a> { data: &'a Option<&'a u32>, //~^ ref_option_ref - } struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); //~^ ref_option_ref - enum EnumRef<'a> { Variant1(u32), Variant2(&'a Option<&'a u32>), //~^ ref_option_ref - } trait RefOptTrait { @@ -59,14 +52,12 @@ impl RefOptTrait for u32 { type A = &'static Option<&'static Self>; //~^ ref_option_ref - fn foo(&self, _: Self::A) {} } fn main() { let x: &Option<&u32> = &None; //~^ ref_option_ref - } fn issue9682(arg: &Option<&mut String>) { diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index fcafbc5ea18e..25064a61ee88 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -8,61 +8,61 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); = help: to override `-D warnings` add `#[allow(clippy::ref_option_ref)]` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:15:18 + --> tests/ui/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>` - --> tests/ui/ref_option_ref.rs:19:25 + --> tests/ui/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>` - --> tests/ui/ref_option_ref.rs:22:25 + --> tests/ui/ref_option_ref.rs:20:25 | LL | type RefOptRef<'a, T> = &'a Option<&'a T>; | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:26:14 + --> tests/ui/ref_option_ref.rs:23:14 | LL | fn foo(data: &Option<&u32>) {} | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:30:23 + --> tests/ui/ref_option_ref.rs:26:23 | LL | fn bar(data: &u32) -> &Option<&u32> { | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:37:11 + --> tests/ui/ref_option_ref.rs:33:11 | LL | data: &'a Option<&'a u32>, | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:42:32 + --> tests/ui/ref_option_ref.rs:37:32 | LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:48:14 + --> tests/ui/ref_option_ref.rs:42:14 | LL | Variant2(&'a Option<&'a u32>), | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:59:14 + --> tests/ui/ref_option_ref.rs:52:14 | LL | type A = &'static Option<&'static Self>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:67:12 + --> tests/ui/ref_option_ref.rs:59: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 214778b78b5b..2905af13ccb6 100644 --- a/tests/ui/ref_patterns.rs +++ b/tests/ui/ref_patterns.rs @@ -7,7 +7,6 @@ fn use_in_pattern() { None => {}, Some(ref opt) => {}, //~^ ref_patterns - } } @@ -15,11 +14,9 @@ fn use_in_binding() { let x = 5; let ref y = x; //~^ ref_patterns - } fn use_in_parameter(ref x: i32) {} //~^ ref_patterns - fn main() {} diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index bf63189a15b0..9e2d036e3483 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -9,7 +9,7 @@ LL | Some(ref opt) => {}, = help: to override `-D warnings` add `#[allow(clippy::ref_patterns)]` error: usage of ref pattern - --> tests/ui/ref_patterns.rs:16:9 + --> tests/ui/ref_patterns.rs:15:9 | LL | let ref y = x; | ^^^^^ @@ -17,7 +17,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> tests/ui/ref_patterns.rs:21:21 + --> tests/ui/ref_patterns.rs:19:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/tests/ui/repeat_vec_with_capacity.fixed b/tests/ui/repeat_vec_with_capacity.fixed index 318839db221e..5c6736a9a4ee 100644 --- a/tests/ui/repeat_vec_with_capacity.fixed +++ b/tests/ui/repeat_vec_with_capacity.fixed @@ -5,14 +5,12 @@ fn main() { { (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); //~^ repeat_vec_with_capacity - } { let n = 123; (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); //~^ repeat_vec_with_capacity - } { @@ -28,7 +26,6 @@ fn main() { { std::iter::repeat_with(|| Vec::<()>::with_capacity(42)); //~^ repeat_vec_with_capacity - } { diff --git a/tests/ui/repeat_vec_with_capacity.rs b/tests/ui/repeat_vec_with_capacity.rs index 0ce4658c1089..2646794822c0 100644 --- a/tests/ui/repeat_vec_with_capacity.rs +++ b/tests/ui/repeat_vec_with_capacity.rs @@ -5,14 +5,12 @@ fn main() { { vec![Vec::<()>::with_capacity(42); 123]; //~^ repeat_vec_with_capacity - } { let n = 123; vec![Vec::<()>::with_capacity(42); n]; //~^ repeat_vec_with_capacity - } { @@ -28,7 +26,6 @@ fn main() { { std::iter::repeat(Vec::<()>::with_capacity(42)); //~^ repeat_vec_with_capacity - } { diff --git a/tests/ui/repeat_vec_with_capacity.stderr b/tests/ui/repeat_vec_with_capacity.stderr index bdfd58137b0b..43027c9cb892 100644 --- a/tests/ui/repeat_vec_with_capacity.stderr +++ b/tests/ui/repeat_vec_with_capacity.stderr @@ -13,7 +13,7 @@ LL | (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:13:9 + --> tests/ui/repeat_vec_with_capacity.rs:12:9 | LL | vec![Vec::<()>::with_capacity(42); n]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:29:9 + --> tests/ui/repeat_vec_with_capacity.rs:27:9 | LL | std::iter::repeat(Vec::<()>::with_capacity(42)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs index f9887eedcf46..e9469d4c5e2f 100644 --- a/tests/ui/repl_uninit.rs +++ b/tests/ui/repl_uninit.rs @@ -15,7 +15,6 @@ fn main() { let taken_v = mem::replace(&mut v, mem::uninitialized()); //~^ mem_replace_with_uninit - let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr index 6e314d0dd166..08b0b265942d 100644 --- a/tests/ui/repl_uninit.stderr +++ b/tests/ui/repl_uninit.stderr @@ -8,13 +8,13 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_uninit)]` error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> tests/ui/repl_uninit.rs:24:23 + --> tests/ui/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()` - --> tests/ui/repl_uninit.rs:32:23 + --> tests/ui/repl_uninit.rs:31:23 | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,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()` - --> tests/ui/repl_uninit.rs:46:28 + --> tests/ui/repl_uninit.rs:45:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` diff --git a/tests/ui/repr_packed_without_abi.rs b/tests/ui/repr_packed_without_abi.rs index 4f51d4b9aec6..c5f1852e98b8 100644 --- a/tests/ui/repr_packed_without_abi.rs +++ b/tests/ui/repr_packed_without_abi.rs @@ -2,14 +2,14 @@ #[repr(packed)] struct NetworkPacketHeader { -//~^ repr_packed_without_abi + //~^ repr_packed_without_abi header_length: u8, header_version: u16, } #[repr(packed)] union Foo { -//~^ repr_packed_without_abi + //~^ repr_packed_without_abi a: u8, b: u16, } diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs index fd6cf0d1ce1f..bede01688972 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -22,10 +22,8 @@ fn main() { match a_struct { A { a: 5, b: 42, c: "", .. } => {}, // Lint //~^ rest_pat_in_fully_bound_structs - A { a: 0, b: 0, c: "", .. } => {}, // Lint //~^ rest_pat_in_fully_bound_structs - _ => {}, } @@ -33,7 +31,6 @@ fn main() { A { a: 5, b: 42, .. } => {}, A { a: 0, b: 0, c: "", .. } => {}, // Lint //~^ rest_pat_in_fully_bound_structs - _ => {}, } diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index 72cf778ca64c..d048933ddb7b 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -9,7 +9,7 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint = help: to override `-D warnings` add `#[allow(clippy::rest_pat_in_fully_bound_structs)]` error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> tests/ui/rest_pat_in_fully_bound_structs.rs:26:9 + --> tests/ui/rest_pat_in_fully_bound_structs.rs:25:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ 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 - --> tests/ui/rest_pat_in_fully_bound_structs.rs:34:9 + --> tests/ui/rest_pat_in_fully_bound_structs.rs:32:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_filter_map.rs b/tests/ui/result_filter_map.rs index f5e0a9da9ea5..ebd9c4288e3b 100644 --- a/tests/ui/result_filter_map.rs +++ b/tests/ui/result_filter_map.rs @@ -12,14 +12,12 @@ fn main() { .into_iter() .filter(Result::is_ok) //~^ result_filter_map - .map(Result::unwrap); let _ = vec![Ok(1) as Result] .into_iter() .filter(|o| o.is_ok()) //~^ result_filter_map - .map(|o| o.unwrap()); let _ = vec![1] @@ -27,13 +25,11 @@ fn main() { .map(odds_out) .filter(Result::is_ok) //~^ result_filter_map - .map(Result::unwrap); let _ = vec![1] .into_iter() .map(odds_out) .filter(|o| o.is_ok()) //~^ result_filter_map - .map(|o| o.unwrap()); } diff --git a/tests/ui/result_filter_map.stderr b/tests/ui/result_filter_map.stderr index f3ff5173c171..12eb7083b5a8 100644 --- a/tests/ui/result_filter_map.stderr +++ b/tests/ui/result_filter_map.stderr @@ -3,7 +3,7 @@ error: `filter` for `Ok` followed by `unwrap` | LL | .filter(Result::is_ok) | __________^ -... | +LL | | LL | | .map(Result::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` | @@ -11,29 +11,29 @@ LL | | .map(Result::unwrap); = help: to override `-D warnings` add `#[allow(clippy::result_filter_map)]` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:20:10 + --> tests/ui/result_filter_map.rs:19:10 | LL | .filter(|o| o.is_ok()) | __________^ -... | +LL | | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:28:10 + --> tests/ui/result_filter_map.rs:26:10 | LL | .filter(Result::is_ok) | __________^ -... | +LL | | LL | | .map(Result::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Ok` followed by `unwrap` - --> tests/ui/result_filter_map.rs:35:10 + --> tests/ui/result_filter_map.rs:32:10 | LL | .filter(|o| o.is_ok()) | __________^ -... | +LL | | LL | | .map(|o| o.unwrap()); | |____________________________^ help: consider using `flatten` instead: `flatten()` diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index bdcf40a99ab9..fa57b3f553fc 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -8,7 +8,7 @@ pub fn small_err() -> Result<(), u128> { } pub fn large_err() -> Result<(), [u8; 512]> { -//~^ result_large_err + //~^ result_large_err Ok(()) } @@ -21,21 +21,21 @@ pub struct FullyDefinedLargeError { impl FullyDefinedLargeError { pub fn ret() -> Result<(), Self> { - //~^ result_large_err + //~^ result_large_err Ok(()) } } pub fn struct_error() -> Result<(), FullyDefinedLargeError> { -//~^ result_large_err + //~^ result_large_err Ok(()) } type Fdlr = std::result::Result; pub fn large_err_via_type_alias(x: T) -> Fdlr { -//~^ result_large_err + //~^ result_large_err Ok(x) } @@ -45,7 +45,7 @@ pub fn param_small_error() -> Result<(), (R, u128)> { } pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { -//~^ result_large_err + //~^ result_large_err Ok(()) } @@ -58,7 +58,7 @@ pub enum LargeErrorVariants { impl LargeErrorVariants<()> { pub fn large_enum_error() -> Result<(), Self> { - //~^ result_large_err + //~^ result_large_err Ok(()) } @@ -72,7 +72,7 @@ enum MultipleLargeVariants { impl MultipleLargeVariants { fn large_enum_error() -> Result<(), Self> { - //~^ result_large_err + //~^ result_large_err Ok(()) } @@ -80,7 +80,7 @@ impl MultipleLargeVariants { trait TraitForcesLargeError { fn large_error() -> Result<(), [u8; 512]> { - //~^ result_large_err + //~^ result_large_err Ok(()) } @@ -101,7 +101,7 @@ pub union FullyDefinedUnionError { } pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { -//~^ result_large_err + //~^ result_large_err Ok(()) } @@ -112,7 +112,7 @@ pub union UnionError { } pub fn param_large_union() -> Result<(), UnionError> { -//~^ result_large_err + //~^ result_large_err Ok(()) } @@ -123,13 +123,13 @@ pub struct ArrayError { } pub fn array_error_subst() -> Result<(), ArrayError> { -//~^ result_large_err + //~^ result_large_err Ok(()) } pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { -//~^ result_large_err + //~^ result_large_err Ok(()) } diff --git a/tests/ui/result_map_or_into_option.fixed b/tests/ui/result_map_or_into_option.fixed index 47ba2b03bfc4..4cf218b84642 100644 --- a/tests/ui/result_map_or_into_option.fixed +++ b/tests/ui/result_map_or_into_option.fixed @@ -12,7 +12,6 @@ fn main() { let _ = opt.ok(); //~^ result_map_or_into_option - let rewrap = |s: u32| -> Option { Some(s) }; // A non-Some `f` arg should not emit the lint diff --git a/tests/ui/result_map_or_into_option.rs b/tests/ui/result_map_or_into_option.rs index 3c6b2f0e836f..9a0bde8569e8 100644 --- a/tests/ui/result_map_or_into_option.rs +++ b/tests/ui/result_map_or_into_option.rs @@ -12,7 +12,6 @@ fn main() { let _ = opt.map_or_else(|_| { None }, Some); //~^ result_map_or_into_option - let rewrap = |s: u32| -> Option { Some(s) }; // A non-Some `f` arg should not emit the lint diff --git a/tests/ui/result_unit_error.rs b/tests/ui/result_unit_error.rs index a6cf36bff913..ddbe0eb556c8 100644 --- a/tests/ui/result_unit_error.rs +++ b/tests/ui/result_unit_error.rs @@ -1,7 +1,7 @@ #![warn(clippy::result_unit_err)] pub fn returns_unit_error() -> Result { -//~^ result_unit_err + //~^ result_unit_err Err(()) } @@ -14,9 +14,8 @@ pub trait HasUnitError { fn get_that_error(&self) -> Result; //~^ result_unit_err - fn get_this_one_too(&self) -> Result { - //~^ result_unit_err + //~^ result_unit_err Err(()) } @@ -36,7 +35,7 @@ pub struct UnitErrorHolder; impl UnitErrorHolder { pub fn unit_error(&self) -> Result { - //~^ result_unit_err + //~^ result_unit_err Ok(0) } @@ -47,7 +46,7 @@ pub mod issue_6546 { type ResInv = Result; pub fn should_lint() -> ResInv<(), usize> { - //~^ result_unit_err + //~^ result_unit_err Ok(0) } diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index a59271f8f72e..d6c0924d8868 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -17,7 +17,7 @@ LL | fn get_that_error(&self) -> Result; = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:18:5 + --> tests/ui/result_unit_error.rs:17:5 | LL | fn get_this_one_too(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | fn get_this_one_too(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:38:5 + --> tests/ui/result_unit_error.rs:37:5 | LL | pub fn unit_error(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | pub fn unit_error(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> tests/ui/result_unit_error.rs:49:5 + --> tests/ui/result_unit_error.rs:48:5 | LL | pub fn should_lint() -> ResInv<(), usize> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_unit_error_no_std.rs b/tests/ui/result_unit_error_no_std.rs index cd2b17a52234..8a1849b8490a 100644 --- a/tests/ui/result_unit_error_no_std.rs +++ b/tests/ui/result_unit_error_no_std.rs @@ -10,7 +10,7 @@ pub fn returns_unit_error_no_lint() -> Result { #[clippy::msrv = "1.81"] pub fn returns_unit_error_lint() -> Result { -//~^ result_unit_err + //~^ result_unit_err Err(()) } diff --git a/tests/ui/return_and_then.fixed b/tests/ui/return_and_then.fixed index 732854d2b969..74efa14eeec8 100644 --- a/tests/ui/return_and_then.fixed +++ b/tests/ui/return_and_then.fixed @@ -4,9 +4,9 @@ fn main() { fn test_opt_block(opt: Option) -> Option { let n = opt?; //~^ return_and_then - let mut ret = n + 1; - ret += n; - if n > 1 { Some(ret) } else { None } + let mut ret = n + 1; + ret += n; + if n > 1 { Some(ret) } else { None } } fn test_opt_func(opt: Option) -> Option { @@ -43,7 +43,7 @@ fn main() { fn test_tmp_only() -> Option { // unused temporary: vec![1, 2, 4] let x = Some(match (vec![1, 2, 3], vec![1, 2, 4]) { - //~^ return_and_then + //~^ return_and_then (a, _) if a.len() > 1 => a, (_, b) => b, })?; diff --git a/tests/ui/return_and_then.rs b/tests/ui/return_and_then.rs index cfefee373c78..188dc57e588c 100644 --- a/tests/ui/return_and_then.rs +++ b/tests/ui/return_and_then.rs @@ -3,7 +3,7 @@ fn main() { fn test_opt_block(opt: Option) -> Option { opt.and_then(|n| { - //~^ return_and_then + //~^ return_and_then let mut ret = n + 1; ret += n; if n > 1 { Some(ret) } else { None } @@ -39,7 +39,7 @@ fn main() { fn test_tmp_only() -> Option { // unused temporary: vec![1, 2, 4] Some(match (vec![1, 2, 3], vec![1, 2, 4]) { - //~^ return_and_then + //~^ return_and_then (a, _) if a.len() > 1 => a, (_, b) => b, }) diff --git a/tests/ui/return_and_then.stderr b/tests/ui/return_and_then.stderr index ef5f7417de78..cc611c3dba67 100644 --- a/tests/ui/return_and_then.stderr +++ b/tests/ui/return_and_then.stderr @@ -15,9 +15,9 @@ help: try | LL ~ let n = opt?; LL + -LL + let mut ret = n + 1; -LL + ret += n; -LL + if n > 1 { Some(ret) } else { None } +LL + let mut ret = n + 1; +LL + ret += n; +LL + if n > 1 { Some(ret) } else { None } | error: use the question mark operator instead of an `and_then` call diff --git a/tests/ui/return_self_not_must_use.rs b/tests/ui/return_self_not_must_use.rs index 2e9a29aea0d7..83965662d15e 100644 --- a/tests/ui/return_self_not_must_use.rs +++ b/tests/ui/return_self_not_must_use.rs @@ -18,12 +18,12 @@ impl Bar { Self } pub fn foo(&self) -> Self { - //~^ return_self_not_must_use + //~^ return_self_not_must_use Self } pub fn bar(self) -> Self { - //~^ return_self_not_must_use + //~^ return_self_not_must_use self } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/tests/ui/reversed_empty_ranges_loops_fixable.fixed index 5d7f852e4e53..55080da8a137 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -5,17 +5,17 @@ fn main() { const MAX_LEN: usize = 42; for i in (0..10).rev() { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in (0..=10).rev() { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in (0..MAX_LEN).rev() { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } @@ -35,18 +35,18 @@ fn main() { } for i in (0..10).rev().map(|x| x * 2) { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } // testing that the empty range lint folds constants for i in (5 + 4..10).rev() { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in ((3 - 1)..(5 + 2)).rev() { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs index b65d4adb090a..e51557bc2796 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -5,17 +5,17 @@ fn main() { const MAX_LEN: usize = 42; for i in 10..0 { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in 10..=0 { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in MAX_LEN..0 { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } @@ -35,18 +35,18 @@ fn main() { } for i in (10..0).map(|x| x * 2) { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } // testing that the empty range lint folds constants for i in 10..5 + 4 { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } for i in (5 + 2)..(3 - 1) { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs index 4fc7fb50a9ec..00aa20d25bda 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -3,14 +3,13 @@ fn main() { for i in 5..5 { - //~^ reversed_empty_ranges - + //~^ reversed_empty_ranges println!("{}", i); } for i in (5 + 2)..(8 - 1) { - //~^ reversed_empty_ranges + //~^ reversed_empty_ranges println!("{}", i); } diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index b5c17aad46bc..b9e6fa04a34c 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -8,7 +8,7 @@ LL | for i in 5..5 { = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_loops_unfixable.rs:12:14 + --> tests/ui/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 1ed35786a0da..7bf434544378 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_unfixable.rs @@ -8,15 +8,12 @@ fn main() { let _ = &arr[3usize..=1usize]; //~^ reversed_empty_ranges - let _ = &arr[SOME_NUM..1]; //~^ reversed_empty_ranges - for _ in ANSWER..ANSWER {} //~^ reversed_empty_ranges - // 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 770d916bad66..bc2b9576c41d 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -8,13 +8,13 @@ LL | let _ = &arr[3usize..=1usize]; = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is reversed and using it to index a slice will panic at run-time - --> tests/ui/reversed_empty_ranges_unfixable.rs:12:18 + --> tests/ui/reversed_empty_ranges_unfixable.rs:11:18 | LL | let _ = &arr[SOME_NUM..1]; | ^^^^^^^^^^^ error: this range is empty so it will yield no values - --> tests/ui/reversed_empty_ranges_unfixable.rs:16:14 + --> tests/ui/reversed_empty_ranges_unfixable.rs:14:14 | LL | for _ in ANSWER..ANSWER {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs index 47954392178a..b7ed3aab0043 100644 --- a/tests/ui/same_functions_in_if_condition.rs +++ b/tests/ui/same_functions_in_if_condition.rs @@ -37,39 +37,33 @@ fn ifs_same_cond_fn() { if function() { } else if function() { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } if fn_arg(a) { } else if fn_arg(a) { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } if obj.method() { } else if obj.method() { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } if obj.method_arg(a) { } else if obj.method_arg(a) { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } let mut v = vec![1]; if v.pop().is_none() { } else if v.pop().is_none() { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } if v.len() == 42 { } else if v.len() == 42 { - //~^ same_functions_in_if_condition - + //~^ same_functions_in_if_condition } if v.len() == 1 { diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index 0d40c8359557..6cd4f96c13e3 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -16,61 +16,61 @@ LL | #![deny(clippy::same_functions_in_if_condition)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:45:15 + --> tests/ui/same_functions_in_if_condition.rs:44:15 | LL | } else if fn_arg(a) { | ^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:44:8 + --> tests/ui/same_functions_in_if_condition.rs:43:8 | LL | if fn_arg(a) { | ^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:51:15 + --> tests/ui/same_functions_in_if_condition.rs:49:15 | LL | } else if obj.method() { | ^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:50:8 + --> tests/ui/same_functions_in_if_condition.rs:48:8 | LL | if obj.method() { | ^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:57:15 + --> tests/ui/same_functions_in_if_condition.rs:54:15 | LL | } else if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:56:8 + --> tests/ui/same_functions_in_if_condition.rs:53:8 | LL | if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:64:15 + --> tests/ui/same_functions_in_if_condition.rs:60:15 | LL | } else if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:63:8 + --> tests/ui/same_functions_in_if_condition.rs:59:8 | LL | if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ error: this `if` has the same function call as a previous `if` - --> tests/ui/same_functions_in_if_condition.rs:70:15 + --> tests/ui/same_functions_in_if_condition.rs:65:15 | LL | } else if v.len() == 42 { | ^^^^^^^^^^^^^ | note: same as this - --> tests/ui/same_functions_in_if_condition.rs:69:8 + --> tests/ui/same_functions_in_if_condition.rs:64:8 | LL | if v.len() == 42 { | ^^^^^^^^^^^^^ diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs index dbe9c729bc56..a08e8872a932 100644 --- a/tests/ui/same_item_push.rs +++ b/tests/ui/same_item_push.rs @@ -22,7 +22,6 @@ fn main() { for _ in 5..=20 { vec.push(item); //~^ same_item_push - } let mut vec: Vec = Vec::new(); @@ -30,21 +29,18 @@ fn main() { let item = 2; vec.push(item); //~^ same_item_push - } let mut vec: Vec = Vec::new(); for _ in 0..15 { vec.push(13); //~^ same_item_push - } let mut vec = Vec::new(); for _ in 0..20 { vec.push(VALUE); //~^ same_item_push - } let mut vec = Vec::new(); @@ -52,7 +48,6 @@ fn main() { for _ in 0..20 { vec.push(item); //~^ same_item_push - } #[clippy::msrv = "1.81"] @@ -62,7 +57,6 @@ fn main() { for _ in 0..20 { vec.push(item); //~^ same_item_push - } } diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index d2bf5069a846..e3fa4f9cbcec 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -10,7 +10,7 @@ LL | vec.push(item); = help: to override `-D warnings` add `#[allow(clippy::same_item_push)]` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:31:9 + --> tests/ui/same_item_push.rs:30:9 | LL | vec.push(item); | ^^^ @@ -19,7 +19,7 @@ LL | vec.push(item); = help: or `vec.extend(std::iter::repeat_n(item, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:38:9 + --> tests/ui/same_item_push.rs:36:9 | LL | vec.push(13); | ^^^ @@ -28,7 +28,7 @@ LL | vec.push(13); = help: or `vec.extend(std::iter::repeat_n(13, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:45:9 + --> tests/ui/same_item_push.rs:42:9 | LL | vec.push(VALUE); | ^^^ @@ -37,7 +37,7 @@ LL | vec.push(VALUE); = help: or `vec.extend(std::iter::repeat_n(VALUE, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:53:9 + --> tests/ui/same_item_push.rs:49:9 | LL | vec.push(item); | ^^^ @@ -46,7 +46,7 @@ LL | vec.push(item); = help: or `vec.extend(std::iter::repeat_n(item, SIZE))` error: it looks like the same item is being pushed into this `Vec` - --> tests/ui/same_item_push.rs:63:13 + --> tests/ui/same_item_push.rs:58:13 | LL | vec.push(item); | ^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index 398f3a7d5f91..43c664b1505f 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -19,7 +19,6 @@ mod should_lint { impl S { fn foo() {} //~^ same_name_method - } impl T1 for S { @@ -35,7 +34,6 @@ mod should_lint { impl S { fn clone() {} //~^ same_name_method - } } @@ -47,7 +45,6 @@ mod should_lint { impl S { fn foo() {} //~^ same_name_method - } impl T1 for S { @@ -63,7 +60,6 @@ mod should_lint { impl S { fn foo() {} //~^ same_name_method - } impl T1 for S {} @@ -78,8 +74,6 @@ mod should_lint { fn foo() {} //~^ same_name_method //~| same_name_method - - } impl T1 for S {} diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index d3bf386ea545..fefdb5c9c23d 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -5,7 +5,7 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:26:13 + --> tests/ui/same_name_method.rs:25:13 | LL | fn foo() {} | ^^^^^^^^^^^ @@ -13,62 +13,62 @@ LL | fn foo() {} = help: to override `-D warnings` add `#[allow(clippy::same_name_method)]` error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:36:13 + --> tests/ui/same_name_method.rs:35:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> tests/ui/same_name_method.rs:32:18 + --> tests/ui/same_name_method.rs:31: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 - --> tests/ui/same_name_method.rs:48:13 + --> tests/ui/same_name_method.rs:46:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:54:13 + --> tests/ui/same_name_method.rs:51:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:64:13 + --> tests/ui/same_name_method.rs:61:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:69:9 + --> tests/ui/same_name_method.rs:65:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:78:13 + --> tests/ui/same_name_method.rs:74:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:85:9 + --> tests/ui/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> tests/ui/same_name_method.rs:78:13 + --> tests/ui/same_name_method.rs:74:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> tests/ui/same_name_method.rs:87:9 + --> tests/ui/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index e33f32d5bdb8..8169550b0d55 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -105,7 +105,7 @@ mod issue7392 { let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = !vfoo - //~^ search_is_some + //~^ search_is_some .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); } @@ -174,7 +174,7 @@ mod issue7392 { }, }]; let _ = !vfoo - //~^ search_is_some + //~^ search_is_some .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2); } diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index 86885c7d3be3..5935f0dd7e29 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -23,7 +23,7 @@ fn main() { let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); //~^ search_is_some let _ = (1..3) - //~^ search_is_some + //~^ search_is_some .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) .is_none(); @@ -108,7 +108,7 @@ mod issue7392 { let vfoo = vec![(42, Foo { foo: 1, bar: 2 })]; let _ = vfoo - //~^ search_is_some + //~^ search_is_some .iter() .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) .is_none(); @@ -179,7 +179,7 @@ mod issue7392 { }, }]; let _ = vfoo - //~^ search_is_some + //~^ search_is_some .iter() .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) .is_none(); diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index a12a2829ba1a..6e82b42cf6d7 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -13,7 +13,6 @@ pub fn positives(mut a: usize, b: &mut u32, mut s: S) { a = a; //~^ self_assignment - *b = *b; //~^ self_assignment @@ -38,14 +37,12 @@ pub fn positives(mut a: usize, b: &mut u32, mut s: S) { s.b[a + 10] = s.b[10 + a]; //~^ self_assignment - let mut t = (0, 1); t.1 = t.1; //~^ self_assignment t.0 = (t.0); //~^ self_assignment - } 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 02c5b4195e9c..e9a2164187ce 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -8,61 +8,61 @@ LL | a = a; = help: to override `-D warnings` add `#[allow(clippy::self_assignment)]` error: self-assignment of `*b` to `*b` - --> tests/ui/self_assignment.rs:17:5 + --> tests/ui/self_assignment.rs:16:5 | LL | *b = *b; | ^^^^^^^ error: self-assignment of `s` to `s` - --> tests/ui/self_assignment.rs:20:5 + --> tests/ui/self_assignment.rs:19:5 | LL | s = s; | ^^^^^ error: self-assignment of `s.a` to `s.a` - --> tests/ui/self_assignment.rs:23:5 + --> tests/ui/self_assignment.rs:22:5 | LL | s.a = s.a; | ^^^^^^^^^ error: self-assignment of `s.b[5 + 4]` to `s.b[9]` - --> tests/ui/self_assignment.rs:26:5 + --> tests/ui/self_assignment.rs:25:5 | LL | s.b[9] = s.b[5 + 4]; | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> tests/ui/self_assignment.rs:29:5 + --> tests/ui/self_assignment.rs:28:5 | LL | s.c[0][1] = s.c[0][1]; | ^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.b[a]` to `s.b[a]` - --> tests/ui/self_assignment.rs:32:5 + --> tests/ui/self_assignment.rs:31:5 | LL | s.b[a] = s.b[a]; | ^^^^^^^^^^^^^^^ error: self-assignment of `*s.e` to `*s.e` - --> tests/ui/self_assignment.rs:35:5 + --> tests/ui/self_assignment.rs:34:5 | LL | *s.e = *s.e; | ^^^^^^^^^^^ error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> tests/ui/self_assignment.rs:38:5 + --> tests/ui/self_assignment.rs:37:5 | LL | s.b[a + 10] = s.b[10 + a]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `t.1` to `t.1` - --> tests/ui/self_assignment.rs:43:5 + --> tests/ui/self_assignment.rs:41:5 | LL | t.1 = t.1; | ^^^^^^^^^ error: self-assignment of `(t.0)` to `t.0` - --> tests/ui/self_assignment.rs:46:5 + --> tests/ui/self_assignment.rs:44:5 | LL | t.0 = (t.0); | ^^^^^^^^^^^ diff --git a/tests/ui/self_named_constructors.rs b/tests/ui/self_named_constructors.rs index 3dcd20b58c9d..8b6453e0d1d7 100644 --- a/tests/ui/self_named_constructors.rs +++ b/tests/ui/self_named_constructors.rs @@ -5,8 +5,7 @@ struct ShouldNotSpawn; impl ShouldSpawn { pub fn should_spawn() -> ShouldSpawn { - //~^ self_named_constructors - + //~^ self_named_constructors ShouldSpawn } diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index 54d7fb939796..1d8b44f6bc2b 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -2,7 +2,9 @@ error: constructor `should_spawn` has the same name as the type --> tests/ui/self_named_constructors.rs:7:5 | LL | / pub fn should_spawn() -> ShouldSpawn { -... | +LL | | +LL | | +LL | | ShouldSpawn LL | | } | |_____^ | diff --git a/tests/ui/set_contains_or_insert.rs b/tests/ui/set_contains_or_insert.rs index 0e54afe91a80..575cfda139a4 100644 --- a/tests/ui/set_contains_or_insert.rs +++ b/tests/ui/set_contains_or_insert.rs @@ -10,42 +10,42 @@ fn should_warn_hashset() { let value = 5; if !set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if !set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); } if !!set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if (&set).contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); } let borrow_value = &6; if !set.contains(borrow_value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(*borrow_value); } let borrow_set = &mut set; if !borrow_set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert borrow_set.insert(value); } } @@ -84,42 +84,42 @@ fn should_warn_btreeset() { let value = 5; if !set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if !set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); } if !!set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); println!("Just a comment"); } if (&set).contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(value); } let borrow_value = &6; if !set.contains(borrow_value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert set.insert(*borrow_value); } let borrow_set = &mut set; if !borrow_set.contains(&value) { - //~^ set_contains_or_insert + //~^ set_contains_or_insert borrow_set.insert(value); } } diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index b44705dfc7d6..7d503a1cf6c1 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -49,7 +49,7 @@ fn shadow_reuse() -> Option<()> { //~^ shadow_reuse let y = 1; let y = match y { - //~^ shadow_reuse + //~^ shadow_reuse 1 => 2, _ => 3, }; @@ -77,7 +77,7 @@ fn syntax() { match Some(1) { Some(1) => {}, Some(x) => { - //~^ shadow_unrelated + //~^ shadow_unrelated let x = 1; //~^ shadow_unrelated }, @@ -88,7 +88,7 @@ fn syntax() { while let Some(x) = Some(1) {} //~^ shadow_unrelated let _ = |[x]: [u32; 1]| { - //~^ shadow_unrelated + //~^ shadow_unrelated let x = 1; //~^ shadow_unrelated }; diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed index 672f692db51e..133d296e259c 100644 --- a/tests/ui/short_circuit_statement.fixed +++ b/tests/ui/short_circuit_statement.fixed @@ -17,7 +17,6 @@ fn main() { if !(f() || g()) { H * 2; } //~^ short_circuit_statement - macro_rules! mac { ($f:ident or $g:ident) => { $f() || $g() @@ -36,7 +35,6 @@ fn main() { if !mac!() { mac!(); } //~^ short_circuit_statement - // Do not lint if the expression comes from a macro mac!(); } diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index ca8913c8e637..4275ae64fdd6 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -17,7 +17,6 @@ fn main() { (f() || g()) || (H * 2); //~^ short_circuit_statement - macro_rules! mac { ($f:ident or $g:ident) => { $f() || $g() @@ -36,7 +35,6 @@ fn main() { mac!() || mac!(); //~^ short_circuit_statement - // Do not lint if the expression comes from a macro mac!(); } diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index f69f411b4885..acd28d41a33a 100644 --- a/tests/ui/short_circuit_statement.stderr +++ b/tests/ui/short_circuit_statement.stderr @@ -32,13 +32,13 @@ LL | (f() || g()) || (H * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `if !(f() || g()) { H * 2; }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:33:5 + --> tests/ui/short_circuit_statement.rs:32:5 | LL | mac!() && mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if mac!() { mac!(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:36:5 + --> tests/ui/short_circuit_statement.rs:35:5 | LL | mac!() || mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if !mac!() { mac!(); }` diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs index 664d8aab7568..87b3a7d2fa0c 100644 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ b/tests/ui/should_impl_trait/method_list_1.rs @@ -23,91 +23,91 @@ impl T { // trait method list part 1, should lint all // ***************************************** pub fn add(self, other: T) -> T { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn as_mut(&mut self) -> &mut T { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn as_ref(&self) -> &T { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn bitand(self, rhs: T) -> T { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn bitor(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn bitxor(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn borrow(&self) -> &str { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn borrow_mut(&mut self) -> &mut str { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn clone(&self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn cmp(&self, other: &Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn default() -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn deref(&self) -> &Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn deref_mut(&mut self) -> &mut Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn div(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn drop(&mut self) { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs index 29b96c33ce9c..f0c4d4f15cb6 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -24,91 +24,91 @@ impl T { // ***************************************** pub fn eq(&self, other: &Self) -> bool { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn from_iter(iter: T) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn from_str(s: &str) -> Result { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn hash(&self, state: &mut T) { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn index(&self, index: usize) -> &Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn index_mut(&mut self, index: usize) -> &mut Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn into_iter(self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn mul(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn neg(self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn next(&mut self) -> Option { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn not(self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn rem(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn shl(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn shr(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } pub fn sub(self, rhs: Self) -> Self { - //~^ should_implement_trait + //~^ should_implement_trait unimplemented!() } diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index db4f8867fa41..4f65a06680d6 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -58,7 +58,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().bar(); }, @@ -145,7 +145,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -167,7 +167,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -216,7 +216,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 2 => { let current_count = counter.i.load(Ordering::Relaxed); println!("Current count {}", current_count); @@ -240,7 +240,7 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { { match (mutex1.lock().unwrap().s.len(), true) { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee (3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -250,7 +250,7 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex1.lock().unwrap().s.len(), true) { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee (_, 3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -261,8 +261,8 @@ 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()) { - //~^ significant_drop_in_scrutinee - //~| significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee (3, _, 3) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -314,7 +314,7 @@ 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 { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().s.len(); }, @@ -322,7 +322,7 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { }; match 1 < mutex.lock().unwrap().s.len() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => { mutex.lock().unwrap().s.len(); }, @@ -341,8 +341,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() { - //~^ significant_drop_in_scrutinee - //~| significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee true => { println!( "{} < {}", @@ -354,8 +354,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() { - //~^ significant_drop_in_scrutinee - //~| significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee + //~| significant_drop_in_scrutinee true => { println!( "{} >= {}", @@ -391,7 +391,7 @@ 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 { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => { mutex1.lock().unwrap().s.len(); }, @@ -409,7 +409,7 @@ 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 { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap(), } @@ -436,7 +436,7 @@ 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 { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee mutex1.lock().unwrap() } else { mutex2.lock().unwrap() @@ -491,7 +491,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 0 | 1 => println!("Value was less than 2"), _ => println!("Value is {}", s.lock().deref()), }; @@ -540,28 +540,28 @@ fn should_trigger_lint_in_assign_expr() { let mut i = 100; match mutex.lock().unwrap().i = i { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i = mutex.lock().unwrap().i { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee _ => { println!("{}", mutex.lock().unwrap().i); }, }; match mutex.lock().unwrap().i += 1 { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i += mutex.lock().unwrap().i { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee _ => { println!("{}", mutex.lock().unwrap().i); }, @@ -625,7 +625,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee Ok(n) => println!("Converted to number: {}", n), Err(e) => println!("Could not convert {} to number", e), }; @@ -652,7 +652,7 @@ 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() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => do_bar(&mutex), false => {}, }; @@ -714,7 +714,7 @@ fn should_not_trigger_for_significant_drop_ref() { } match guard.take().len() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee 0 => println!("empty"), _ => println!("not empty"), }; @@ -739,7 +739,7 @@ fn should_trigger_lint_if_and_only_if_lifetime_is_irrelevant() { // Should trigger lint even if `copy_old_lifetime()` has a lifetime, as the lifetime of // `&vec` is unrelated to the temporary with significant drop (i.e., the `MutexGuard`). for val in mutex.lock().unwrap().copy_old_lifetime() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee println!("{}", val); } @@ -778,7 +778,7 @@ fn should_not_trigger_lint_with_explicit_drop() { // Should trigger lint if there is no explicit drop. for val in [mutex.lock().unwrap()[0], 2] { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee println!("{:?}", val); } } @@ -787,7 +787,7 @@ fn should_trigger_lint_in_if_let() { let mutex = Mutex::new(vec![1]); if let Some(val) = mutex.lock().unwrap().first().copied() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee println!("{}", val); } @@ -802,7 +802,7 @@ fn should_trigger_lint_in_while_let() { let mutex = Mutex::new(vec![1]); while let Some(val) = mutex.lock().unwrap().pop() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee println!("{}", val); } } @@ -813,7 +813,7 @@ async fn foo_async(mutex: &Mutex) -> Option> { async fn should_trigger_lint_for_async(mutex: Mutex) -> i32 { match *foo_async(&mutex).await.unwrap() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee n if n < 10 => n, _ => 10, } @@ -833,7 +833,7 @@ fn should_trigger_lint_in_match_expr() { // is preserved until the end of the match, but there is no clear indication that this is the // case. let _ = match mutex.lock().unwrap().foo() { - //~^ significant_drop_in_scrutinee + //~^ significant_drop_in_scrutinee true => 0, false => 1, }; diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index a6b20b94a4a7..69b6ab6220bf 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -47,13 +47,11 @@ fn main() { let bluby: i32; //~^ similar_names - let cake: i32; let cakes: i32; let coke: i32; //~^ similar_names - match 5 { cheese @ 1 => {}, rabbit => panic!(), @@ -73,13 +71,11 @@ fn main() { let xyzeabc: i32; //~^ similar_names - let parser: i32; let parsed: i32; let parsee: i32; //~^ similar_names - let setter: i32; let getter: i32; let tx1: i32; @@ -101,7 +97,6 @@ fn foo() { apple: spring, bpple: sprang, //~^ similar_names - } = unimplemented!(); } diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 36255f52e825..8d722fb8b564 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -13,49 +13,49 @@ LL | let blubx: i32; = help: to override `-D warnings` add `#[allow(clippy::similar_names)]` error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:53:9 + --> tests/ui/similar_names.rs:52:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:51:9 + --> tests/ui/similar_names.rs:50:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:73:9 + --> tests/ui/similar_names.rs:71:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:71:9 + --> tests/ui/similar_names.rs:69:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:79:9 + --> tests/ui/similar_names.rs:76:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:77:9 + --> tests/ui/similar_names.rs:74:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:102:16 + --> tests/ui/similar_names.rs:98:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:101:16 + --> tests/ui/similar_names.rs:97:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index 0894509b73ea..c1cc4032bec9 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -34,7 +34,7 @@ fn g() { } fn c() { -//~^ single_call_fn + //~^ single_call_fn println!("really"); println!("long"); println!("function..."); diff --git a/tests/ui/single_char_lifetime_names.rs b/tests/ui/single_char_lifetime_names.rs index e6a35cfe1642..f4dcf46b0e2d 100644 --- a/tests/ui/single_char_lifetime_names.rs +++ b/tests/ui/single_char_lifetime_names.rs @@ -5,8 +5,6 @@ struct DiagnosticCtx<'a, 'b> //~^ single_char_lifetime_names //~| single_char_lifetime_names - - where 'a: 'b, { @@ -16,9 +14,8 @@ where // Only the lifetimes on the `impl`'s generics should be linted impl<'a, 'b> DiagnosticCtx<'a, 'b> { -//~^ single_char_lifetime_names -//~| single_char_lifetime_names - + //~^ single_char_lifetime_names + //~| single_char_lifetime_names fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> { Self { @@ -40,7 +37,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>) { -//~^ single_char_lifetime_names + //~^ single_char_lifetime_names base.split_once(other) .map(|(left, right)| (left, Some(right))) diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index 010390ce15cc..834b654baa57 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -17,7 +17,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:18:6 + --> tests/ui/single_char_lifetime_names.rs:16:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -25,7 +25,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:18:10 + --> tests/ui/single_char_lifetime_names.rs:16:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -33,7 +33,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:42:15 + --> tests/ui/single_char_lifetime_names.rs:39: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 b1c6e6f94e42..acfda8b3a9c8 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -4,8 +4,6 @@ use regex; //~^ single_component_path_imports - - use serde as edres; pub use serde; @@ -19,7 +17,6 @@ mod root_nested_use_mod { //~^ single_component_path_imports //~| single_component_path_imports - #[allow(dead_code)] fn root_nested_use_mod() {} } diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index 8df4d8404eea..6dbfd2711b4a 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -8,7 +8,7 @@ LL | use regex; = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:18:10 + --> tests/ui/single_component_path_imports_nested_first.rs:16:10 | LL | use {regex, serde}; | ^^^^^ @@ -16,7 +16,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:18:17 + --> tests/ui/single_component_path_imports_nested_first.rs:16:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed index eadf77f0fa50..76c3cf56c11e 100644 --- a/tests/ui/single_element_loop.fixed +++ b/tests/ui/single_element_loop.fixed @@ -7,33 +7,33 @@ fn main() { let item1 = 2; { let item = &item1; - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } { let item = &item1; - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in 0..5 { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in 0..5 { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in 0..5 { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in 0..5 { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } @@ -54,7 +54,7 @@ fn main() { // should lint (issue #10018) { let _ = 42; - //~^ single_element_loop + //~^ single_element_loop let _f = |n: u32| { for i in 0..n { if i > 10 { @@ -70,7 +70,7 @@ fn main() { { let (Ok(mut _x) | Err(mut _x)) = res_void; - //~^ single_element_loop + //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } } diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs index 6aa9269e56c0..2eb928397b0a 100644 --- a/tests/ui/single_element_loop.rs +++ b/tests/ui/single_element_loop.rs @@ -6,32 +6,32 @@ fn main() { let item1 = 2; for item in &[item1] { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in [item1].iter() { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in &[0..5] { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in [0..5].iter_mut() { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in [0..5] { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } for item in [0..5].into_iter() { - //~^ single_element_loop + //~^ single_element_loop dbg!(item); } @@ -51,7 +51,7 @@ fn main() { // should lint (issue #10018) for _ in [42] { - //~^ single_element_loop + //~^ single_element_loop let _f = |n: u32| { for i in 0..n { if i > 10 { @@ -66,7 +66,7 @@ fn main() { let res_void: Result = Ok(true); for (Ok(mut _x) | Err(mut _x)) in [res_void] { - //~^ single_element_loop + //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } } diff --git a/tests/ui/single_option_map.rs b/tests/ui/single_option_map.rs index fd9db9165bdc..6126582f4635 100644 --- a/tests/ui/single_option_map.rs +++ b/tests/ui/single_option_map.rs @@ -6,13 +6,13 @@ static ATOM: AtomicUsize = AtomicUsize::new(42); static MAYBE_ATOMIC: Option<&AtomicUsize> = Some(&ATOM); fn h(arg: Option) -> Option { -//~^ single_option_map + //~^ single_option_map arg.map(|x| x * 2) } fn j(arg: Option) -> Option { -//~^ single_option_map + //~^ single_option_map arg.map(|x| x * 2) } @@ -22,7 +22,7 @@ fn mul_args(a: String, b: u64) -> String { } fn mul_args_opt(a: Option, b: u64) -> Option { -//~^ single_option_map + //~^ single_option_map a.map(|val| mul_args(val, b + 1)) } diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index 39c482af78c0..3fe4d923441d 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -15,17 +15,14 @@ fn main() { unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; //~^ size_of_in_element_count - // 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) }; //~^ size_of_in_element_count - // 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) }; //~^ size_of_in_element_count - // 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::()) }; @@ -36,7 +33,6 @@ fn main() { unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; //~^ size_of_in_element_count - // 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 8af8867e04dd..74be0d7773df 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -9,7 +9,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of:: = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:20:62 + --> tests/ui/size_of_in_element_count/expressions.rs:19:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:25:47 + --> tests/ui/size_of_in_element_count/expressions.rs:23:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::( = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:36:47 + --> tests/ui/size_of_in_element_count/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 c8bb603d8165..afd12edec1ed 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -21,7 +21,6 @@ fn main() { unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; //~^ size_of_in_element_count - unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; //~^ size_of_in_element_count @@ -34,32 +33,27 @@ fn main() { unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; //~^ size_of_in_element_count - unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; //~^ size_of_in_element_count unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; //~^ size_of_in_element_count - unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; //~^ size_of_in_element_count - slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); //~^ size_of_in_element_count slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); //~^ size_of_in_element_count - unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; //~^ size_of_in_element_count unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; //~^ size_of_in_element_count - unsafe { y.as_mut_ptr().sub(size_of::()) }; //~^ size_of_in_element_count @@ -77,5 +71,4 @@ fn main() { y.as_mut_ptr().wrapping_offset(size_of::() as isize); //~^ size_of_in_element_count - } diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index a05f88436a6a..f11c33167669 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -17,7 +17,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` - --> tests/ui/size_of_in_element_count/functions.rs:25:49 + --> tests/ui/size_of_in_element_count/functions.rs:24:49 | LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -25,7 +25,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` - --> tests/ui/size_of_in_element_count/functions.rs:28:64 + --> tests/ui/size_of_in_element_count/functions.rs:27:64 | LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of:: tests/ui/size_of_in_element_count/functions.rs:31:51 + --> tests/ui/size_of_in_element_count/functions.rs:30:51 | LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -41,7 +41,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` - --> tests/ui/size_of_in_element_count/functions.rs:34:66 + --> tests/ui/size_of_in_element_count/functions.rs:33:66 | LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,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` - --> tests/ui/size_of_in_element_count/functions.rs:38:47 + --> tests/ui/size_of_in_element_count/functions.rs:36:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -57,7 +57,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` - --> tests/ui/size_of_in_element_count/functions.rs:41:47 + --> tests/ui/size_of_in_element_count/functions.rs:39:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,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` - --> tests/ui/size_of_in_element_count/functions.rs:45:66 + --> tests/ui/size_of_in_element_count/functions.rs:42:66 | LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,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` - --> tests/ui/size_of_in_element_count/functions.rs:49:46 + --> tests/ui/size_of_in_element_count/functions.rs:45:46 | LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,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` - --> tests/ui/size_of_in_element_count/functions.rs:52:38 + --> tests/ui/size_of_in_element_count/functions.rs:48:38 | LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,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` - --> tests/ui/size_of_in_element_count/functions.rs:56:49 + --> tests/ui/size_of_in_element_count/functions.rs:51:49 | LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,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` - --> tests/ui/size_of_in_element_count/functions.rs:59:41 + --> tests/ui/size_of_in_element_count/functions.rs:54:41 | LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,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` - --> tests/ui/size_of_in_element_count/functions.rs:63:33 + --> tests/ui/size_of_in_element_count/functions.rs:57:33 | LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -113,7 +113,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` - --> tests/ui/size_of_in_element_count/functions.rs:66:29 + --> tests/ui/size_of_in_element_count/functions.rs:60:29 | LL | y.as_ptr().wrapping_sub(size_of::()); | ^^^^^^^^^^^^^^^^ @@ -121,7 +121,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` - --> tests/ui/size_of_in_element_count/functions.rs:69:29 + --> tests/ui/size_of_in_element_count/functions.rs:63:29 | LL | unsafe { y.as_ptr().add(size_of::()) }; | ^^^^^^^^^^^^^^^^ @@ -129,7 +129,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` - --> tests/ui/size_of_in_element_count/functions.rs:72:33 + --> tests/ui/size_of_in_element_count/functions.rs:66:33 | LL | y.as_mut_ptr().wrapping_add(size_of::()); | ^^^^^^^^^^^^^^^^ @@ -137,7 +137,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` - --> tests/ui/size_of_in_element_count/functions.rs:75:32 + --> tests/ui/size_of_in_element_count/functions.rs:69:32 | LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,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` - --> tests/ui/size_of_in_element_count/functions.rs:78:36 + --> tests/ui/size_of_in_element_count/functions.rs:72: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 06ed216b3422..9a6a9419f681 100644 --- a/tests/ui/size_of_ref.rs +++ b/tests/ui/size_of_ref.rs @@ -15,7 +15,6 @@ fn main() { size_of_val(&y); //~^ size_of_ref - } struct S { @@ -28,6 +27,5 @@ impl S { pub fn size(&self) -> usize { std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) //~^ size_of_ref - } } diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index 0dc64673940e..6ac0b0dd2f06 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -17,7 +17,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 - --> tests/ui/size_of_ref.rs:29:9 + --> tests/ui/size_of_ref.rs:28: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 6a09d1f36a66..52f2a52fbbb8 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -14,7 +14,6 @@ fn extend_vector() { let mut vec1 = Vec::with_capacity(len); //~^ slow_vector_initialization - vec1.extend(repeat(0).take(len)); // Extend with len expression diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 67a0b928618a..e83eef826472 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -11,7 +11,7 @@ LL | | vec1.extend(repeat(0).take(len)); = help: to override `-D warnings` add `#[allow(clippy::slow_vector_initialization)]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:21:20 + --> tests/ui/slow_vector_initialization.rs:20:20 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ____________________^ @@ -20,7 +20,7 @@ LL | | vec2.extend(repeat(0).take(len - 10)); | |_________________________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:30:20 + --> tests/ui/slow_vector_initialization.rs:29:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ @@ -29,7 +29,7 @@ LL | | vec4.extend(repeat(0).take(vec4.capacity())); | |________________________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:42:27 + --> tests/ui/slow_vector_initialization.rs:41:27 | LL | let mut resized_vec = Vec::with_capacity(30); | ___________________________^ @@ -38,7 +38,7 @@ LL | | resized_vec.resize(30, 0); | |_____________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:47:26 + --> tests/ui/slow_vector_initialization.rs:46:26 | LL | let mut extend_vec = Vec::with_capacity(30); | __________________________^ @@ -47,7 +47,7 @@ LL | | extend_vec.extend(repeat(0).take(30)); | |_________________________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:56:20 + --> tests/ui/slow_vector_initialization.rs:55:20 | LL | let mut vec1 = Vec::with_capacity(len); | ____________________^ @@ -56,7 +56,7 @@ LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:66:20 + --> tests/ui/slow_vector_initialization.rs:65:20 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ____________________^ @@ -65,7 +65,7 @@ LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:71:20 + --> tests/ui/slow_vector_initialization.rs:70:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ @@ -74,7 +74,7 @@ LL | | vec4.resize(vec4.capacity(), 0); | |___________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:77:12 + --> tests/ui/slow_vector_initialization.rs:76:12 | LL | vec1 = Vec::with_capacity(10); | ____________^ @@ -83,7 +83,7 @@ LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:86:20 + --> tests/ui/slow_vector_initialization.rs:85:20 | LL | let mut vec1 = Vec::new(); | ____________________^ @@ -92,7 +92,7 @@ LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:92:20 + --> tests/ui/slow_vector_initialization.rs:91:20 | LL | let mut vec3 = Vec::new(); | ____________________^ @@ -101,7 +101,7 @@ LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:98:12 + --> tests/ui/slow_vector_initialization.rs:97:12 | LL | vec1 = Vec::new(); | ____________^ @@ -110,7 +110,7 @@ LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:103:12 + --> tests/ui/slow_vector_initialization.rs:102:12 | LL | vec1 = vec![]; | ____________^ diff --git a/tests/ui/starts_ends_with.fixed b/tests/ui/starts_ends_with.fixed index 3e1ea00a341e..b4f9d5867703 100644 --- a/tests/ui/starts_ends_with.fixed +++ b/tests/ui/starts_ends_with.fixed @@ -19,32 +19,32 @@ fn starts_with() { fn chars_cmp_with_unwrap() { let s = String::from("foo"); if s.starts_with('f') { - //~^ chars_next_cmp + //~^ chars_next_cmp // s.starts_with('f') // Nothing here } if s.ends_with('o') { - //~^ chars_last_cmp + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.ends_with('o') { - //~^ chars_last_cmp + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if !s.starts_with('f') { - //~^ chars_next_cmp + //~^ chars_next_cmp // !s.starts_with('f') // Nothing here } if !s.ends_with('o') { - //~^ chars_last_cmp + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } if !s.ends_with('\n') { - //~^ chars_last_cmp + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index ef7143a455f9..dae04ac4a62d 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -19,32 +19,32 @@ fn starts_with() { fn chars_cmp_with_unwrap() { let s = String::from("foo"); if s.chars().next().unwrap() == 'f' { - //~^ chars_next_cmp + //~^ chars_next_cmp // s.starts_with('f') // Nothing here } if s.chars().next_back().unwrap() == 'o' { - //~^ chars_last_cmp + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.chars().last().unwrap() == 'o' { - //~^ chars_last_cmp + //~^ chars_last_cmp // s.ends_with('o') // Nothing here } if s.chars().next().unwrap() != 'f' { - //~^ chars_next_cmp + //~^ chars_next_cmp // !s.starts_with('f') // Nothing here } if s.chars().next_back().unwrap() != 'o' { - //~^ chars_last_cmp + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } if s.chars().last().unwrap() != '\n' { - //~^ chars_last_cmp + //~^ chars_last_cmp // !s.ends_with('o') // Nothing here } diff --git a/tests/ui/str_to_string.fixed b/tests/ui/str_to_string.fixed index 4977e9c944d1..2941c4dbd33d 100644 --- a/tests/ui/str_to_string.fixed +++ b/tests/ui/str_to_string.fixed @@ -7,5 +7,4 @@ fn main() { let msg = &hello[..]; msg.to_owned(); //~^ str_to_string - } diff --git a/tests/ui/str_to_string.rs b/tests/ui/str_to_string.rs index f710761471b6..4c4d2bb18062 100644 --- a/tests/ui/str_to_string.rs +++ b/tests/ui/str_to_string.rs @@ -7,5 +7,4 @@ fn main() { let msg = &hello[..]; msg.to_string(); //~^ str_to_string - } diff --git a/tests/ui/string_slice.rs b/tests/ui/string_slice.rs index 9251b348af3f..0acc48c1f412 100644 --- a/tests/ui/string_slice.rs +++ b/tests/ui/string_slice.rs @@ -7,7 +7,6 @@ fn main() { &"Ölkanne"[1..]; //~^ string_slice - let m = "Mötörhead"; &m[2..5]; //~^ string_slice @@ -19,5 +18,4 @@ fn main() { let a = Cow::Borrowed("foo"); &a[0..3]; //~^ string_slice - } diff --git a/tests/ui/string_slice.stderr b/tests/ui/string_slice.stderr index 4932152af6b6..f99413c6dfc6 100644 --- a/tests/ui/string_slice.stderr +++ b/tests/ui/string_slice.stderr @@ -8,19 +8,19 @@ LL | &"Ölkanne"[1..]; = help: to override `-D warnings` add `#[allow(clippy::string_slice)]` error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:12:6 + --> tests/ui/string_slice.rs:11:6 | LL | &m[2..5]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:16:6 + --> tests/ui/string_slice.rs:15:6 | LL | &s[0..2]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> tests/ui/string_slice.rs:20:6 + --> tests/ui/string_slice.rs:19:6 | LL | &a[0..3]; | ^^^^^^^ diff --git a/tests/ui/string_to_string.rs b/tests/ui/string_to_string.rs index e3f5b6cf3bdc..94174e1253b8 100644 --- a/tests/ui/string_to_string.rs +++ b/tests/ui/string_to_string.rs @@ -5,5 +5,4 @@ fn main() { let mut message = String::from("Hello"); let mut v = message.to_string(); //~^ string_to_string - } diff --git a/tests/ui/struct_excessive_bools.rs b/tests/ui/struct_excessive_bools.rs index f509c3143a86..36cbc6278030 100644 --- a/tests/ui/struct_excessive_bools.rs +++ b/tests/ui/struct_excessive_bools.rs @@ -20,8 +20,7 @@ struct Foo { } struct BadFoo { -//~^ struct_excessive_bools - + //~^ struct_excessive_bools a: bool, b: bool, c: bool, @@ -38,8 +37,7 @@ struct Bar { fn main() { struct FooFoo { - //~^ struct_excessive_bools - + //~^ struct_excessive_bools a: bool, b: bool, c: bool, diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index 573af45355a6..bdf6f0b7a1da 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -3,9 +3,9 @@ error: more than 3 bools in a struct | LL | / struct BadFoo { LL | | -LL | | LL | | a: bool, -... | +LL | | b: bool, +LL | | c: bool, LL | | d: bool, LL | | } | |_^ @@ -15,13 +15,13 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: more than 3 bools in a struct - --> tests/ui/struct_excessive_bools.rs:40:5 + --> tests/ui/struct_excessive_bools.rs:39:5 | LL | / struct FooFoo { LL | | -LL | | LL | | a: bool, -... | +LL | | b: bool, +LL | | c: bool, LL | | d: bool, LL | | } | |_____^ diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index b9207b1b3f91..9798d2049c62 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -13,8 +13,6 @@ impl Add for Foo { fn add(self, other: Self) -> Self { Foo(self.0 - other.0) //~^ suspicious_arithmetic_impl - - } } @@ -22,8 +20,6 @@ impl AddAssign for Foo { fn add_assign(&mut self, other: Foo) { *self = *self - other; //~^ suspicious_op_assign_impl - - } } @@ -38,7 +34,6 @@ impl MulAssign for Foo { fn mul_assign(&mut self, other: Foo) { self.0 /= other.0; //~^ suspicious_op_assign_impl - } } @@ -78,7 +73,6 @@ impl Rem for Foo { fn rem(self, other: Self) -> Self { Foo(self.0 / other.0) //~^ suspicious_arithmetic_impl - } } @@ -88,7 +82,6 @@ impl BitAnd for Foo { fn bitand(self, other: Self) -> Self { Foo(self.0 | other.0) //~^ suspicious_arithmetic_impl - } } @@ -98,7 +91,6 @@ impl BitOr for Foo { fn bitor(self, other: Self) -> Self { Foo(self.0 ^ other.0) //~^ suspicious_arithmetic_impl - } } @@ -108,7 +100,6 @@ impl BitXor for Foo { fn bitxor(self, other: Self) -> Self { Foo(self.0 & other.0) //~^ suspicious_arithmetic_impl - } } @@ -118,7 +109,6 @@ impl Shl for Foo { fn shl(self, other: Self) -> Self { Foo(self.0 >> other.0) //~^ suspicious_arithmetic_impl - } } @@ -128,7 +118,6 @@ impl Shr for Foo { fn shr(self, other: Self) -> Self { Foo(self.0 << other.0) //~^ suspicious_arithmetic_impl - } } diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index a392aa16f1d4..2d8aac4db2a7 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -8,7 +8,7 @@ LL | Foo(self.0 - other.0) = help: to override `-D warnings` add `#[allow(clippy::suspicious_arithmetic_impl)]` error: suspicious use of `-` in `AddAssign` impl - --> tests/ui/suspicious_arithmetic_impl.rs:23:23 + --> tests/ui/suspicious_arithmetic_impl.rs:21:23 | LL | *self = *self - other; | ^ @@ -17,43 +17,43 @@ LL | *self = *self - other; = help: to override `-D warnings` add `#[allow(clippy::suspicious_op_assign_impl)]` error: suspicious use of `/` in `MulAssign` impl - --> tests/ui/suspicious_arithmetic_impl.rs:39:16 + --> tests/ui/suspicious_arithmetic_impl.rs:35:16 | LL | self.0 /= other.0; | ^^ error: suspicious use of `/` in `Rem` impl - --> tests/ui/suspicious_arithmetic_impl.rs:79:20 + --> tests/ui/suspicious_arithmetic_impl.rs:74:20 | LL | Foo(self.0 / other.0) | ^ error: suspicious use of `|` in `BitAnd` impl - --> tests/ui/suspicious_arithmetic_impl.rs:89:20 + --> tests/ui/suspicious_arithmetic_impl.rs:83:20 | LL | Foo(self.0 | other.0) | ^ error: suspicious use of `^` in `BitOr` impl - --> tests/ui/suspicious_arithmetic_impl.rs:99:20 + --> tests/ui/suspicious_arithmetic_impl.rs:92:20 | LL | Foo(self.0 ^ other.0) | ^ error: suspicious use of `&` in `BitXor` impl - --> tests/ui/suspicious_arithmetic_impl.rs:109:20 + --> tests/ui/suspicious_arithmetic_impl.rs:101:20 | LL | Foo(self.0 & other.0) | ^ error: suspicious use of `>>` in `Shl` impl - --> tests/ui/suspicious_arithmetic_impl.rs:119:20 + --> tests/ui/suspicious_arithmetic_impl.rs:110:20 | LL | Foo(self.0 >> other.0) | ^^ error: suspicious use of `<<` in `Shr` impl - --> tests/ui/suspicious_arithmetic_impl.rs:129:20 + --> tests/ui/suspicious_arithmetic_impl.rs:119: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 5ab070f88dcf..0a0d90f75e57 100644 --- a/tests/ui/suspicious_command_arg_space.fixed +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -4,11 +4,9 @@ fn main() { std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); //~^ suspicious_command_arg_space - std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); //~^ suspicious_command_arg_space - // 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(); diff --git a/tests/ui/suspicious_command_arg_space.rs b/tests/ui/suspicious_command_arg_space.rs index 0017bd44dbfe..78bdfbdf0cb6 100644 --- a/tests/ui/suspicious_command_arg_space.rs +++ b/tests/ui/suspicious_command_arg_space.rs @@ -4,11 +4,9 @@ fn main() { std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); //~^ suspicious_command_arg_space - std::process::Command::new("cat").arg("--number file").spawn().unwrap(); //~^ suspicious_command_arg_space - // 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(); diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index f4d7d79def14..6fd07d07d7be 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -12,7 +12,7 @@ LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap | ~~~~ ~~~~~~~~~~~~~~~ error: single argument that looks like it should be multiple arguments - --> tests/ui/suspicious_command_arg_space.rs:8:43 + --> tests/ui/suspicious_command_arg_space.rs:7:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 58f6ebdb4c7c..0c878afc66e1 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -21,8 +21,8 @@ pub mod singleline_inner_doc { pub mod multiline_outer_doc { /*! This module contains useful functions. - //~^ suspicious_doc_comments */ + //~^^ suspicious_doc_comments pub fn bar() {} } diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index 26ee028b8c57..d89fe4f1bec7 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -21,8 +21,8 @@ pub mod singleline_inner_doc { pub mod multiline_outer_doc { /**! This module contains useful functions. - //~^ suspicious_doc_comments */ + //~^^ suspicious_doc_comments pub fn bar() {} } diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index 8982e98b4daa..61363ff9bd20 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -26,14 +26,12 @@ error: this is an outer doc comment and does not apply to the parent module or c --> tests/ui/suspicious_doc_comments.rs:23:5 | LL | / /**! This module contains useful functions. -LL | | LL | | */ | |_______^ | help: use an inner doc comment to document the parent module or crate | LL ~ /*! This module contains useful functions. -LL + LL + */ | diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 255c6f7237df..e526de5ca2c3 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -4,7 +4,6 @@ ///! a //~^ suspicious_doc_comments - ///! b /// c ///! d diff --git a/tests/ui/suspicious_doc_comments_unfixable.stderr b/tests/ui/suspicious_doc_comments_unfixable.stderr index ff4cb3358a81..234a22021df3 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -2,7 +2,9 @@ error: this is an outer doc comment and does not apply to the parent module or c --> tests/ui/suspicious_doc_comments_unfixable.rs:4:1 | LL | / ///! a -... | +LL | | +LL | | +LL | | ///! b LL | | /// c LL | | ///! d | |______^ @@ -14,14 +16,13 @@ help: use an inner doc comment to document the parent module or crate LL + //! a LL | 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 - --> tests/ui/suspicious_doc_comments_unfixable.rs:13:1 + --> tests/ui/suspicious_doc_comments_unfixable.rs:12:1 | LL | / ///! a LL | | diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs index 3e3035a68f49..86e48e29bb9e 100644 --- a/tests/ui/suspicious_map.rs +++ b/tests/ui/suspicious_map.rs @@ -5,11 +5,9 @@ fn main() { let _ = (0..3).map(|x| x + 2).count(); //~^ suspicious_map - let f = |x| x + 1; let _ = (0..3).map(f).count(); //~^ suspicious_map - } fn negative() { diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index 7c08168f0c20..769adebaede7 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -9,7 +9,7 @@ LL | let _ = (0..3).map(|x| x + 2).count(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]` error: this call to `map()` won't have an effect on the call to `count()` - --> tests/ui/suspicious_map.rs:10:13 + --> tests/ui/suspicious_map.rs:9:13 | LL | let _ = (0..3).map(f).count(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index 1da292130d05..37054222bd62 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -216,7 +216,7 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` if s1.a < s2.a && s1.b < s2.b { - //~^ suspicious_operation_groupings + //~^ suspicious_operation_groupings s1.c = s2.c; } } diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index 25ccba182fa5..f4d1c3c70b56 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -216,7 +216,7 @@ fn inside_fn_with_similar_expression(s1: &S, s2: &S, strict: bool) -> bool { fn inside_an_if_statement(s1: &mut S, s2: &S) { // There's no `s1.b` if s1.a < s2.a && s1.a < s2.b { - //~^ suspicious_operation_groupings + //~^ suspicious_operation_groupings s1.c = s2.c; } } diff --git a/tests/ui/suspicious_splitn.rs b/tests/ui/suspicious_splitn.rs index d7c1dd972450..535f62c6bede 100644 --- a/tests/ui/suspicious_splitn.rs +++ b/tests/ui/suspicious_splitn.rs @@ -10,39 +10,28 @@ fn main() { let _ = "a,b".splitn(0, ','); //~^ suspicious_splitn - let _ = "a,b".rsplitn(0, ','); //~^ suspicious_splitn - let _ = "a,b".splitn(1, ','); //~^ suspicious_splitn - let _ = [0, 1, 2].splitn(0, |&x| x == 1); //~^ suspicious_splitn - let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); //~^ suspicious_splitn - let _ = [0, 1, 2].splitn(1, |&x| x == 1); //~^ suspicious_splitn - let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); //~^ suspicious_splitn - - const X: usize = 0; let _ = "a,b".splitn(X + 1, ','); //~^ suspicious_splitn - let _ = "a,b".splitn(X, ','); //~^ suspicious_splitn - - } diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 1e1a9b22ffbd..910c905bc990 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -9,7 +9,7 @@ LL | let _ = "a,b".splitn(0, ','); = help: to override `-D warnings` add `#[allow(clippy::suspicious_splitn)]` error: `rsplitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:14:13 + --> tests/ui/suspicious_splitn.rs:13:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:18:13 + --> tests/ui/suspicious_splitn.rs:16:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = "a,b".splitn(1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:22:13 + --> tests/ui/suspicious_splitn.rs:19:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn_mut` called with `0` splits - --> tests/ui/suspicious_splitn.rs:26:13 + --> tests/ui/suspicious_splitn.rs:22:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:30:13 + --> tests/ui/suspicious_splitn.rs:25:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `rsplitn_mut` called with `1` split - --> tests/ui/suspicious_splitn.rs:34:13 + --> tests/ui/suspicious_splitn.rs:28:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:40:13 + --> tests/ui/suspicious_splitn.rs:32:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = "a,b".splitn(X + 1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:44:13 + --> tests/ui/suspicious_splitn.rs:35:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index bde20f4116c3..2eec05ccaf4c 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -17,7 +17,6 @@ fn main() { let _ = cow.to_owned(); //~^ suspicious_to_owned - // we expect no lints for this let cow = Cow::Borrowed(moo); let _ = cow.into_owned(); @@ -70,8 +69,6 @@ fn main() { let _ = String::from(moo).to_owned(); //~^ implicit_clone - let _ = moos_vec.to_owned(); //~^ implicit_clone - } diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 6c00819b4863..cc6f5b7d3a5a 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -16,7 +16,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 - --> tests/ui/suspicious_to_owned.rs:30:13 + --> tests/ui/suspicious_to_owned.rs:29:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -31,7 +31,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 - --> tests/ui/suspicious_to_owned.rs:42:13 + --> tests/ui/suspicious_to_owned.rs:41:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -46,7 +46,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 - --> tests/ui/suspicious_to_owned.rs:54:13 + --> tests/ui/suspicious_to_owned.rs:53:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:70:13 + --> tests/ui/suspicious_to_owned.rs:69:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -70,7 +70,7 @@ LL | let _ = String::from(moo).to_owned(); = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:74:13 + --> tests/ui/suspicious_to_owned.rs:72: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 229ed3383329..e0290b7ce8f1 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -20,7 +20,6 @@ fn main() { let _ = 2 ^ 5; //~^ suspicious_xor_used_as_pow - let _ = 2i32 ^ 9i32; //~^ suspicious_xor_used_as_pow diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 3fb3b4a34e53..d08773a8759a 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -12,7 +12,7 @@ LL | let _ = 2.pow(5); | ~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:23:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = 2i32.pow(9i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:27:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = 2i32.pow(2i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:29:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = 50i32.pow(3i32); | ~~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:33:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:32:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = 5i32.pow(8i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:36:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:35:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ diff --git a/tests/ui/swap_ptr_to_ref_unfixable.rs b/tests/ui/swap_ptr_to_ref_unfixable.rs index 9fe5925214a4..9c7cf27096cc 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.rs +++ b/tests/ui/swap_ptr_to_ref_unfixable.rs @@ -14,12 +14,10 @@ fn main() { core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); //~^ swap_ptr_to_ref - core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); //~^ swap_ptr_to_ref core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); //~^ swap_ptr_to_ref - } } diff --git a/tests/ui/swap_ptr_to_ref_unfixable.stderr b/tests/ui/swap_ptr_to_ref_unfixable.stderr index f4c7c8db15ac..3bb9d87b70a5 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -8,13 +8,13 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> tests/ui/swap_ptr_to_ref_unfixable.rs:18:9 + --> tests/ui/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 - --> tests/ui/swap_ptr_to_ref_unfixable.rs:21:9 + --> tests/ui/swap_ptr_to_ref_unfixable.rs:20:9 | LL | core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed index 5e5821a140de..c96a53ba2cd1 100644 --- a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed +++ b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.fixed @@ -4,5 +4,6 @@ use std::marker::PhantomData; pub struct Aa(PhantomData); fn aa(a: Aa) { +//~^ ERROR: expected one of } diff --git a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs index d6e1da0e0898..a3a35eb26d10 100644 --- a/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs +++ b/tests/ui/syntax-error-recovery/non_expressive_names_error_recovery.rs @@ -4,5 +4,6 @@ use std::marker::PhantomData; pub struct Aa(PhantomData); fn aa(a: Aa tests/ui/temporary_assignment.rs:52:5 + --> tests/ui/temporary_assignment.rs:51:5 | LL | / MultiStruct { LL | | -LL | | LL | | structure: Struct { field: 0 }, -LL | | } -LL | | .structure +... | LL | | .field = 1; | |______________^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:59:5 + --> tests/ui/temporary_assignment.rs:57:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:62:5 + --> tests/ui/temporary_assignment.rs:60:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/tests/ui/test_attr_in_doctest.rs b/tests/ui/test_attr_in_doctest.rs index 8ca33c677f88..6cffd813b835 100644 --- a/tests/ui/test_attr_in_doctest.rs +++ b/tests/ui/test_attr_in_doctest.rs @@ -9,10 +9,9 @@ /// assert_eq!(1, 1); /// } /// ``` -/// +/// /// Make sure we catch multiple tests in one example, /// and show that we really parse the attr: -/// /// ``` /// #[test] //~^ test_attr_in_doctest @@ -29,24 +28,20 @@ /// "); /// } /// ``` -/// +/// /// We don't catch examples that aren't run: -/// /// ```ignore /// #[test] /// fn ignored() { todo!() } /// ``` -/// /// ```no_run /// #[test] /// fn ignored() { todo!() } /// ``` -/// /// ```compile_fail /// #[test] /// fn ignored() { Err(()) } /// ``` -/// /// ```txt /// #[test] /// fn not_even_rust() { panic!("Ouch") } diff --git a/tests/ui/test_attr_in_doctest.stderr b/tests/ui/test_attr_in_doctest.stderr index b8de466e9698..166b9b417b62 100644 --- a/tests/ui/test_attr_in_doctest.stderr +++ b/tests/ui/test_attr_in_doctest.stderr @@ -11,7 +11,7 @@ LL | | /// fn should_be_linted() { = help: to override `-D warnings` add `#[allow(clippy::test_attr_in_doctest)]` error: unit tests in doctest are not executed - --> tests/ui/test_attr_in_doctest.rs:17:5 + --> tests/ui/test_attr_in_doctest.rs:16:5 | LL | /// #[test] | _____^ @@ -20,7 +20,7 @@ LL | | /// fn should_also_be_linted() { | |____________________________^ error: unit tests in doctest are not executed - --> tests/ui/test_attr_in_doctest.rs:24:5 + --> tests/ui/test_attr_in_doctest.rs:23:5 | LL | /// #[test] | _____^ diff --git a/tests/ui/to_string_trait_impl.rs b/tests/ui/to_string_trait_impl.rs index f8195e55f9a8..646ec4db1f11 100644 --- a/tests/ui/to_string_trait_impl.rs +++ b/tests/ui/to_string_trait_impl.rs @@ -9,7 +9,7 @@ struct Point { } impl ToString for Point { -//~^ to_string_trait_impl + //~^ to_string_trait_impl fn to_string(&self) -> String { format!("({}, {})", self.x, self.y) } diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs index 729f528a8e59..87c84a7ee14a 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -7,7 +7,7 @@ extern crate proc_macros; use proc_macros::{external, inline_macros}; fn the_answer(ref mut x: u8) { -//~^ toplevel_ref_arg + //~^ toplevel_ref_arg *x = 42; } diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index 2297e645c9e6..a8c3ffdb0dab 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -4,45 +4,39 @@ // Do lint: struct RarelyUseful { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; 0], } struct OnlyField { -//~^ trailing_empty_array - + //~^ trailing_empty_array first_and_last: [usize; 0], } struct GenericArrayType { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [T; 0], } #[must_use] struct OnlyAnotherAttribute { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; 0], } #[derive(Debug)] struct OnlyADeriveAttribute { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; 0], } const ZERO: usize = 0; struct ZeroSizedWithConst { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; ZERO], } @@ -52,8 +46,7 @@ const fn compute_zero() -> usize { (4 + 6) - (2 * 5) } struct ZeroSizedWithConstFunction { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; compute_zero()], } @@ -62,8 +55,7 @@ const fn compute_zero_from_arg(x: usize) -> usize { x - 1 } struct ZeroSizedWithConstFunction2 { -//~^ trailing_empty_array - + //~^ trailing_empty_array field: i32, last: [usize; compute_zero_from_arg(1)], } @@ -71,14 +63,11 @@ struct ZeroSizedWithConstFunction2 { struct ZeroSizedArrayWrapper([usize; 0]); //~^ trailing_empty_array - struct TupleStruct(i32, [usize; 0]); //~^ trailing_empty_array - struct LotsOfFields { -//~^ trailing_empty_array - + //~^ trailing_empty_array f1: u32, f2: u32, f3: u32, diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index 424d23d07cdf..7ebff372cf75 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -3,7 +3,6 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` a | LL | / struct RarelyUseful { LL | | -LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -14,11 +13,10 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::trailing_empty_array)]` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> tests/ui/trailing_empty_array.rs:13:1 + --> tests/ui/trailing_empty_array.rs:12:1 | LL | / struct OnlyField { LL | | -LL | | LL | | first_and_last: [usize; 0], LL | | } | |_^ @@ -26,11 +24,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 - --> tests/ui/trailing_empty_array.rs:19:1 + --> tests/ui/trailing_empty_array.rs:17:1 | LL | / struct GenericArrayType { LL | | -LL | | LL | | field: i32, LL | | last: [T; 0], LL | | } @@ -39,11 +36,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 - --> tests/ui/trailing_empty_array.rs:27:1 + --> tests/ui/trailing_empty_array.rs:24:1 | LL | / struct OnlyAnotherAttribute { LL | | -LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -52,11 +48,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 - --> tests/ui/trailing_empty_array.rs:35:1 + --> tests/ui/trailing_empty_array.rs:31:1 | LL | / struct OnlyADeriveAttribute { LL | | -LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -65,11 +60,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 - --> tests/ui/trailing_empty_array.rs:43:1 + --> tests/ui/trailing_empty_array.rs:38:1 | LL | / struct ZeroSizedWithConst { LL | | -LL | | LL | | field: i32, LL | | last: [usize; ZERO], LL | | } @@ -78,11 +72,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 - --> tests/ui/trailing_empty_array.rs:54:1 + --> tests/ui/trailing_empty_array.rs:48:1 | LL | / struct ZeroSizedWithConstFunction { LL | | -LL | | LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } @@ -91,11 +84,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 - --> tests/ui/trailing_empty_array.rs:64:1 + --> tests/ui/trailing_empty_array.rs:57:1 | LL | / struct ZeroSizedWithConstFunction2 { LL | | -LL | | LL | | field: i32, LL | | last: [usize; compute_zero_from_arg(1)], LL | | } @@ -104,7 +96,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 - --> tests/ui/trailing_empty_array.rs:71:1 + --> tests/ui/trailing_empty_array.rs:63:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +104,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 - --> tests/ui/trailing_empty_array.rs:75:1 + --> tests/ui/trailing_empty_array.rs:66:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,12 +112,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 - --> tests/ui/trailing_empty_array.rs:79:1 + --> tests/ui/trailing_empty_array.rs:69:1 | LL | / struct LotsOfFields { LL | | -LL | | LL | | f1: u32, +LL | | f2: u32, ... | LL | | last: [usize; 0], LL | | } diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 273dd5d70646..8c30b062fb18 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -6,7 +6,6 @@ fn main() { let _ = x.trailing_zeros() >= 4; //~^ verbose_bit_mask - let _ = x.trailing_zeros() >= 5; //~^ verbose_bit_mask diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index f3fffa7be840..369a31557392 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -6,7 +6,6 @@ fn main() { let _ = (x & 0b1111 == 0); //~^ verbose_bit_mask - let _ = x & 0b1_1111 == 0; //~^ verbose_bit_mask diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 4b608e32a587..6f3e7aa1d762 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -8,7 +8,7 @@ LL | let _ = (x & 0b1111 == 0); = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` error: bit mask could be simplified with a call to `trailing_zeros` - --> tests/ui/trailing_zeros.rs:10:13 + --> tests/ui/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.fixed b/tests/ui/trait_duplication_in_bounds.fixed index afd0f4d77d3e..666ff78b2189 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -5,7 +5,7 @@ use std::any::Any; fn bad_foo(arg0: T, argo1: U) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -41,7 +41,7 @@ trait GoodSelfWhereClause { } trait BadSelfTraitBound: Clone { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds fn f(); } @@ -49,7 +49,7 @@ trait BadSelfWhereClause { fn f() where Self: Clone; - //~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds } trait GoodTraitBound { @@ -64,7 +64,7 @@ trait GoodWhereClause { } trait BadTraitBound { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds fn f(); } @@ -106,7 +106,7 @@ fn good_generic + GenericTrait>(arg0: T) { } fn bad_generic + GenericTrait>(arg0: T) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -115,7 +115,7 @@ mod foo { } fn qualified_path(arg0: T) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -124,7 +124,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { } fn bad_trait_object(arg0: &(dyn Any + Send)) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -174,14 +174,12 @@ const fn const_trait_bounds_good() {} const fn const_trait_bounds_bad() {} //~^ trait_duplication_in_bounds - fn projections() where U: ToOwned, V: ToOwned, T: IntoIterator, //~^ trait_duplication_in_bounds - V: IntoIterator + IntoIterator, { } @@ -204,6 +202,5 @@ fn assoc_const_args() where T: AssocConstTrait, //~^ trait_duplication_in_bounds - { } diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index 4d417e89bd82..a1a86fe058e6 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -5,7 +5,7 @@ use std::any::Any; fn bad_foo(arg0: T, argo1: U) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -41,7 +41,7 @@ trait GoodSelfWhereClause { } trait BadSelfTraitBound: Clone + Clone + Clone { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds fn f(); } @@ -49,7 +49,7 @@ trait BadSelfWhereClause { fn f() where Self: Clone + Clone + Clone; - //~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds } trait GoodTraitBound { @@ -64,7 +64,7 @@ trait GoodWhereClause { } trait BadTraitBound { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds fn f(); } @@ -106,7 +106,7 @@ fn good_generic + GenericTrait>(arg0: T) { } fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -115,7 +115,7 @@ mod foo { } fn qualified_path(arg0: T) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -124,7 +124,7 @@ fn good_trait_object(arg0: &(dyn Any + Send)) { } fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { -//~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds unimplemented!(); } @@ -174,14 +174,12 @@ const fn const_trait_bounds_good() {} const fn const_trait_bounds_bad() {} //~^ trait_duplication_in_bounds - fn projections() where U: ToOwned, V: ToOwned, T: IntoIterator + IntoIterator, //~^ trait_duplication_in_bounds - V: IntoIterator + IntoIterator, { } @@ -204,6 +202,5 @@ fn assoc_const_args() where T: AssocConstTrait + AssocConstTrait, //~^ trait_duplication_in_bounds - { } diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 974dfe538799..d76b4e458480 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -65,13 +65,13 @@ LL | const fn const_trait_bounds_bad() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `~const ConstTrait` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:182:8 + --> tests/ui/trait_duplication_in_bounds.rs:181:8 | LL | T: IntoIterator + IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:205:8 + --> tests/ui/trait_duplication_in_bounds.rs:203:8 | LL | T: AssocConstTrait + AssocConstTrait, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `AssocConstTrait` diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.rs b/tests/ui/trait_duplication_in_bounds_unfixable.rs index 38a42c3bd365..cf72ed844a78 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -7,8 +7,6 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; fn bad_foo(arg0: T, arg1: Z) //~^ trait_duplication_in_bounds //~| trait_duplication_in_bounds - - where T: Clone, T: Default, @@ -38,8 +36,7 @@ trait T: Default { fn f() where Self: Default; - //~^ trait_duplication_in_bounds - + //~^ trait_duplication_in_bounds } trait U: Default { @@ -54,22 +51,20 @@ trait ZZ: Default { fn f() where Self: Default + Clone; - //~^ trait_duplication_in_bounds - + //~^ trait_duplication_in_bounds } trait BadTrait: Default + Clone { fn f() where Self: Default + Clone; - //~^ trait_duplication_in_bounds - //~| trait_duplication_in_bounds - + //~^ trait_duplication_in_bounds + //~| trait_duplication_in_bounds fn g() where Self: Default; - //~^ trait_duplication_in_bounds + //~^ trait_duplication_in_bounds fn h() where @@ -107,7 +102,6 @@ trait FooIter: Iterator { where Self: Iterator, //~^ trait_duplication_in_bounds - { } } diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index c7b8ba01c493..546d39518e1f 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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:40:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:38: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:56:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:53: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:64:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:60: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:64:25 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:60: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:71:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:66: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 - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:108:15 + --> tests/ui/trait_duplication_in_bounds_unfixable.rs:103:15 | LL | Self: Iterator, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 0fec14ffd975..3aecde398dc3 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -31,15 +31,11 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { let _: *const T = core::mem::transmute(t); //~^ useless_transmute - - let _: *mut T = core::mem::transmute(t); //~^ useless_transmute - let _: *const U = core::mem::transmute(t); //~^ useless_transmute - } #[warn(clippy::useless_transmute)] @@ -48,33 +44,26 @@ fn useless() { let _: Vec = core::mem::transmute(my_vec()); //~^ useless_transmute - let _: Vec = core::mem::transmute(my_vec()); //~^ useless_transmute - let _: Vec = std::mem::transmute(my_vec()); //~^ useless_transmute - let _: Vec = std::mem::transmute(my_vec()); //~^ useless_transmute - let _: Vec = my_transmute(my_vec()); //~^ useless_transmute - let _: *const usize = std::mem::transmute(5_isize); //~^ useless_transmute - let _ = 5_isize as *const usize; let _: *const usize = std::mem::transmute(1 + 1usize); //~^ useless_transmute - let _ = (1 + 1_usize) as *const usize; } @@ -107,19 +96,14 @@ fn crosspointer() { let _: Usize = core::mem::transmute(int_const_ptr); //~^ crosspointer_transmute - - let _: Usize = core::mem::transmute(int_mut_ptr); //~^ crosspointer_transmute - let _: *const Usize = core::mem::transmute(my_int()); //~^ crosspointer_transmute - let _: *mut Usize = core::mem::transmute(my_int()); //~^ crosspointer_transmute - } } @@ -127,8 +111,6 @@ fn crosspointer() { fn int_to_bool() { let _: bool = unsafe { std::mem::transmute(0_u8) }; //~^ transmute_int_to_bool - - } #[warn(clippy::transmute_int_to_float)] @@ -137,7 +119,6 @@ mod int_to_float { let _: f16 = unsafe { std::mem::transmute(0_u16) }; //~^ transmute_int_to_float - let _: f16 = unsafe { std::mem::transmute(0_i16) }; //~^ transmute_int_to_float @@ -158,7 +139,6 @@ mod int_to_float { let _: f128 = unsafe { std::mem::transmute(0_i128) }; //~^ transmute_int_to_float - } mod issue_5747 { @@ -174,29 +154,24 @@ mod int_to_float { const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) }; //~^ transmute_int_to_float - const fn from_bits_16(v: i16) -> f16 { unsafe { std::mem::transmute(v) } //~^ transmute_int_to_float - } const fn from_bits_32(v: i32) -> f32 { unsafe { std::mem::transmute(v) } //~^ transmute_int_to_float - } const fn from_bits_64(v: u64) -> f64 { unsafe { std::mem::transmute(v) } //~^ transmute_int_to_float - } const fn from_bits_128(v: u128) -> f128 { unsafe { std::mem::transmute(v) } //~^ transmute_int_to_float - } } } @@ -207,7 +182,6 @@ mod num_to_bytes { let _: [u8; 1] = std::mem::transmute(0u8); //~^ transmute_num_to_bytes - let _: [u8; 4] = std::mem::transmute(0u32); //~^ transmute_num_to_bytes @@ -223,7 +197,6 @@ mod num_to_bytes { let _: [u8; 16] = std::mem::transmute(0i128); //~^ transmute_num_to_bytes - let _: [u8; 2] = std::mem::transmute(0.0f16); //~^ transmute_num_to_bytes @@ -235,7 +208,6 @@ mod num_to_bytes { let _: [u8; 16] = std::mem::transmute(0.0f128); //~^ transmute_num_to_bytes - } } const fn test_const() { @@ -258,7 +230,6 @@ mod num_to_bytes { let _: [u8; 16] = std::mem::transmute(0i128); //~^ transmute_num_to_bytes - let _: [u8; 2] = std::mem::transmute(0.0f16); //~^ transmute_num_to_bytes @@ -270,7 +241,6 @@ mod num_to_bytes { let _: [u8; 16] = std::mem::transmute(0.0f128); //~^ transmute_num_to_bytes - } } } @@ -281,13 +251,11 @@ fn bytes_to_str(mb: &mut [u8]) { let _: &str = unsafe { std::mem::transmute(B) }; //~^ transmute_bytes_to_str - let _: &mut str = unsafe { std::mem::transmute(mb) }; //~^ transmute_bytes_to_str const _: &str = unsafe { std::mem::transmute(B) }; //~^ transmute_bytes_to_str - } fn main() {} diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 7db7fad28d80..e0d28437aafc 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -8,61 +8,61 @@ LL | let _: *const T = core::mem::transmute(t); = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:36:21 + --> tests/ui/transmute.rs:34:21 | LL | let _: *mut T = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:40:23 + --> tests/ui/transmute.rs:37:23 | LL | let _: *const U = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:48:27 + --> tests/ui/transmute.rs:44:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:52:27 + --> tests/ui/transmute.rs:47:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: transmute from a type (`std::vec::Vec`) to itself + --> tests/ui/transmute.rs:50:27 + | +LL | let _: Vec = std::mem::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> tests/ui/transmute.rs:53:27 + | +LL | let _: Vec = std::mem::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: transmute from a type (`std::vec::Vec`) to itself --> tests/ui/transmute.rs:56:27 | -LL | let _: Vec = std::mem::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:60:27 - | -LL | let _: Vec = std::mem::transmute(my_vec()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:64:27 - | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> tests/ui/transmute.rs:68:31 + --> tests/ui/transmute.rs:59: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 - --> tests/ui/transmute.rs:74:31 + --> tests/ui/transmute.rs:64: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`) - --> tests/ui/transmute.rs:107:24 + --> tests/ui/transmute.rs:96:24 | LL | let _: Usize = core::mem::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,25 +71,25 @@ LL | let _: Usize = core::mem::transmute(int_const_ptr); = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:112:24 + --> tests/ui/transmute.rs:99:24 | LL | let _: Usize = core::mem::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> tests/ui/transmute.rs:116:31 + --> tests/ui/transmute.rs:102:31 | LL | let _: *const Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> tests/ui/transmute.rs:120:29 + --> tests/ui/transmute.rs:105:29 | LL | let _: *mut Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u8` to a `bool` - --> tests/ui/transmute.rs:128:28 + --> tests/ui/transmute.rs:112:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -98,7 +98,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` error: transmute from a `u16` to a `f16` - --> tests/ui/transmute.rs:137:31 + --> tests/ui/transmute.rs:119:31 | LL | let _: f16 = unsafe { std::mem::transmute(0_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)` @@ -107,97 +107,97 @@ LL | let _: f16 = unsafe { std::mem::transmute(0_u16) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]` error: transmute from a `i16` to a `f16` - --> tests/ui/transmute.rs:141:31 + --> tests/ui/transmute.rs:122:31 | LL | let _: f16 = unsafe { std::mem::transmute(0_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_i16 as u16)` error: transmute from a `u32` to a `f32` - --> tests/ui/transmute.rs:144:31 + --> tests/ui/transmute.rs:125:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` error: transmute from a `i32` to a `f32` - --> tests/ui/transmute.rs:147:31 + --> tests/ui/transmute.rs:128: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` - --> tests/ui/transmute.rs:150:31 + --> tests/ui/transmute.rs:131: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` - --> tests/ui/transmute.rs:153:31 + --> tests/ui/transmute.rs:134:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `u128` to a `f128` - --> tests/ui/transmute.rs:156:32 + --> tests/ui/transmute.rs:137:32 | LL | let _: f128 = unsafe { std::mem::transmute(0_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_u128)` error: transmute from a `i128` to a `f128` - --> tests/ui/transmute.rs:159:32 + --> tests/ui/transmute.rs:140:32 | LL | let _: f128 = unsafe { std::mem::transmute(0_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)` error: transmute from a `u16` to a `f16` - --> tests/ui/transmute.rs:165:39 + --> tests/ui/transmute.rs:145:39 | LL | const VALUE16: f16 = unsafe { std::mem::transmute(0_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(0_u16)` error: transmute from a `u32` to a `f32` - --> tests/ui/transmute.rs:168:39 + --> tests/ui/transmute.rs:148:39 | LL | const VALUE32: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` error: transmute from a `i64` to a `f64` - --> tests/ui/transmute.rs:171:39 + --> tests/ui/transmute.rs:151:39 | LL | const VALUE64: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `i128` to a `f128` - --> tests/ui/transmute.rs:174:41 + --> tests/ui/transmute.rs:154:41 | LL | const VALUE128: f128 = unsafe { std::mem::transmute(0_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(0_i128 as u128)` error: transmute from a `i16` to a `f16` - --> tests/ui/transmute.rs:179:22 + --> tests/ui/transmute.rs:158:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f16::from_bits(v as u16)` error: transmute from a `i32` to a `f32` - --> tests/ui/transmute.rs:185:22 + --> tests/ui/transmute.rs:163:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(v as u32)` error: transmute from a `u64` to a `f64` - --> tests/ui/transmute.rs:191:22 + --> tests/ui/transmute.rs:168:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(v)` error: transmute from a `u128` to a `f128` - --> tests/ui/transmute.rs:197:22 + --> tests/ui/transmute.rs:173:22 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f128::from_bits(v)` error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:207:30 + --> tests/ui/transmute.rs:182:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` @@ -206,121 +206,121 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); = help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]` error: transmute from a `u32` to a `[u8; 4]` - --> tests/ui/transmute.rs:211:30 + --> tests/ui/transmute.rs:185: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]` - --> tests/ui/transmute.rs:214:31 + --> tests/ui/transmute.rs:188: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]` - --> tests/ui/transmute.rs:217:30 + --> tests/ui/transmute.rs:191: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]` - --> tests/ui/transmute.rs:220:30 + --> tests/ui/transmute.rs:194: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]` - --> tests/ui/transmute.rs:223:31 + --> tests/ui/transmute.rs:197:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f16` to a `[u8; 2]` - --> tests/ui/transmute.rs:227:30 + --> tests/ui/transmute.rs:200:30 | LL | let _: [u8; 2] = std::mem::transmute(0.0f16); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> tests/ui/transmute.rs:230:30 + --> tests/ui/transmute.rs:203: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]` - --> tests/ui/transmute.rs:233:30 + --> tests/ui/transmute.rs:206: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 `f128` to a `[u8; 16]` - --> tests/ui/transmute.rs:236:31 + --> tests/ui/transmute.rs:209:31 | LL | let _: [u8; 16] = std::mem::transmute(0.0f128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()` error: transmute from a `u8` to a `[u8; 1]` - --> tests/ui/transmute.rs:243:30 + --> tests/ui/transmute.rs:215: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]` - --> tests/ui/transmute.rs:246:30 + --> tests/ui/transmute.rs:218: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]` - --> tests/ui/transmute.rs:249:31 + --> tests/ui/transmute.rs:221: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]` - --> tests/ui/transmute.rs:252:30 + --> tests/ui/transmute.rs:224: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]` - --> tests/ui/transmute.rs:255:30 + --> tests/ui/transmute.rs:227: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]` - --> tests/ui/transmute.rs:258:31 + --> tests/ui/transmute.rs:230:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f16` to a `[u8; 2]` - --> tests/ui/transmute.rs:262:30 + --> tests/ui/transmute.rs:233:30 | LL | let _: [u8; 2] = std::mem::transmute(0.0f16); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f16.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> tests/ui/transmute.rs:265:30 + --> tests/ui/transmute.rs:236: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]` - --> tests/ui/transmute.rs:268:30 + --> tests/ui/transmute.rs:239: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 `f128` to a `[u8; 16]` - --> tests/ui/transmute.rs:271:31 + --> tests/ui/transmute.rs:242:31 | LL | let _: [u8; 16] = std::mem::transmute(0.0f128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:281:28 + --> tests/ui/transmute.rs:251:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -329,13 +329,13 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` - --> tests/ui/transmute.rs:285:32 + --> tests/ui/transmute.rs:254:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:288:30 + --> tests/ui/transmute.rs:257: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 9570fa5ab093..1a4bfffdc322 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -6,10 +6,7 @@ fn main() { let _: *const usize = std::mem::transmute(6.0f64); //~^ wrong_transmute - - let _: *mut usize = std::mem::transmute(6.0f64); //~^ wrong_transmute - } } diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index 789eba5247fa..e75b81671e09 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -8,7 +8,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); = help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]` error: transmute from a `f64` to a pointer - --> tests/ui/transmute_64bit.rs:11:29 + --> tests/ui/transmute_64bit.rs:9: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 20952dfa2839..74d7f5e38bf8 100644 --- a/tests/ui/transmute_collection.rs +++ b/tests/ui/transmute_collection.rs @@ -10,12 +10,10 @@ fn main() { let _ = transmute::<_, Vec>(vec![0u8]); //~^ unsound_collection_transmute - // wrong layout let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, VecDeque>(VecDeque::::new()); //~^ unsound_collection_transmute @@ -24,7 +22,6 @@ fn main() { let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); //~^ unsound_collection_transmute @@ -33,7 +30,6 @@ fn main() { let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); //~^ unsound_collection_transmute @@ -42,7 +38,6 @@ fn main() { let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, HashSet>(HashSet::::new()); //~^ unsound_collection_transmute @@ -51,7 +46,6 @@ fn main() { let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); //~^ unsound_collection_transmute @@ -66,7 +60,6 @@ fn main() { let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); //~^ unsound_collection_transmute - // wrong size let _ = transmute::<_, HashMap>(HashMap::::new()); //~^ unsound_collection_transmute @@ -81,7 +74,6 @@ fn main() { let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); //~^ unsound_collection_transmute - 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 f887afc9b676..ac2de07f6bf2 100644 --- a/tests/ui/transmute_collection.stderr +++ b/tests/ui/transmute_collection.stderr @@ -8,103 +8,103 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); = help: to override `-D warnings` add `#[allow(clippy::unsound_collection_transmute)]` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:15:17 + --> tests/ui/transmute_collection.rs:14:17 | LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:20:17 + --> tests/ui/transmute_collection.rs:18:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:24:17 + --> tests/ui/transmute_collection.rs:22:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:29:17 + --> tests/ui/transmute_collection.rs:26:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:33:17 + --> tests/ui/transmute_collection.rs:30:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:38:17 + --> tests/ui/transmute_collection.rs:34:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:42:17 + --> tests/ui/transmute_collection.rs:38:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:47:17 + --> tests/ui/transmute_collection.rs:42:17 | LL | let _ = transmute::<_, HashSet>(HashSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:51:17 + --> tests/ui/transmute_collection.rs:46:17 | LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:56:17 + --> tests/ui/transmute_collection.rs:50:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:59:17 + --> tests/ui/transmute_collection.rs:53:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:63:17 + --> tests/ui/transmute_collection.rs:57: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 - --> tests/ui/transmute_collection.rs:66:17 + --> tests/ui/transmute_collection.rs:60: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 - --> tests/ui/transmute_collection.rs:71:17 + --> tests/ui/transmute_collection.rs:64:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:74:17 + --> tests/ui/transmute_collection.rs:67:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> tests/ui/transmute_collection.rs:78:17 + --> tests/ui/transmute_collection.rs:71: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 - --> tests/ui/transmute_collection.rs:81:17 + --> tests/ui/transmute_collection.rs:74: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 e1feb57ae736..1f97b997eaa0 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -7,7 +7,6 @@ fn float_to_int() { let _: u32 = unsafe { 1f32.to_bits() }; //~^ transmute_float_to_int - let _: i32 = unsafe { 1f32.to_bits() as i32 }; //~^ transmute_float_to_int @@ -22,7 +21,6 @@ fn float_to_int() { let _: u64 = unsafe { (-1.0f64).to_bits() }; //~^ transmute_float_to_int - } mod issue_5747 { @@ -38,29 +36,24 @@ mod issue_5747 { const VALUE128: u128 = unsafe { 1f128.to_bits() }; //~^ transmute_float_to_int - const fn to_bits_16(v: f16) -> u16 { unsafe { v.to_bits() } //~^ transmute_float_to_int - } const fn to_bits_32(v: f32) -> u32 { unsafe { v.to_bits() } //~^ transmute_float_to_int - } const fn to_bits_64(v: f64) -> i64 { unsafe { v.to_bits() as i64 } //~^ transmute_float_to_int - } const fn to_bits_128(v: f128) -> i128 { unsafe { v.to_bits() as i128 } //~^ transmute_float_to_int - } } diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index ac2a1a1ad05d..788a7e1026c6 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -7,7 +7,6 @@ fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; //~^ transmute_float_to_int - let _: i32 = unsafe { std::mem::transmute(1f32) }; //~^ transmute_float_to_int @@ -22,7 +21,6 @@ fn float_to_int() { let _: u64 = unsafe { std::mem::transmute(-1.0) }; //~^ transmute_float_to_int - } mod issue_5747 { @@ -38,29 +36,24 @@ mod issue_5747 { const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; //~^ transmute_float_to_int - const fn to_bits_16(v: f16) -> u16 { unsafe { std::mem::transmute(v) } //~^ transmute_float_to_int - } const fn to_bits_32(v: f32) -> u32 { unsafe { std::mem::transmute(v) } //~^ transmute_float_to_int - } const fn to_bits_64(v: f64) -> i64 { unsafe { std::mem::transmute(v) } //~^ transmute_float_to_int - } const fn to_bits_128(v: f128) -> i128 { unsafe { std::mem::transmute(v) } //~^ transmute_float_to_int - } } diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index 551fcb1f7d0d..223cbc4e90c0 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -8,79 +8,79 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]` error: transmute from a `f32` to a `i32` - --> tests/ui/transmute_float_to_int.rs:11:27 + --> tests/ui/transmute_float_to_int.rs:10: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` - --> tests/ui/transmute_float_to_int.rs:14:27 + --> tests/ui/transmute_float_to_int.rs:13:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> tests/ui/transmute_float_to_int.rs:17:27 + --> tests/ui/transmute_float_to_int.rs:16: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` - --> tests/ui/transmute_float_to_int.rs:20:27 + --> tests/ui/transmute_float_to_int.rs:19: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` - --> tests/ui/transmute_float_to_int.rs:23:27 + --> tests/ui/transmute_float_to_int.rs:22:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` error: transmute from a `f16` to a `i16` - --> tests/ui/transmute_float_to_int.rs:29:35 + --> tests/ui/transmute_float_to_int.rs:27:35 | LL | const VALUE16: i16 = unsafe { std::mem::transmute(1f16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f16.to_bits() as i16` error: transmute from a `f32` to a `i32` - --> tests/ui/transmute_float_to_int.rs:32:35 + --> tests/ui/transmute_float_to_int.rs:30:35 | LL | const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> tests/ui/transmute_float_to_int.rs:35:35 + --> tests/ui/transmute_float_to_int.rs:33:35 | LL | const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f128` to a `u128` - --> tests/ui/transmute_float_to_int.rs:38:37 + --> tests/ui/transmute_float_to_int.rs:36:37 | LL | const VALUE128: u128 = unsafe { std::mem::transmute(1f128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f128.to_bits()` error: transmute from a `f16` to a `u16` - --> tests/ui/transmute_float_to_int.rs:43:18 + --> tests/ui/transmute_float_to_int.rs:40:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()` error: transmute from a `f32` to a `u32` - --> tests/ui/transmute_float_to_int.rs:49:18 + --> tests/ui/transmute_float_to_int.rs:45:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits()` error: transmute from a `f64` to a `i64` - --> tests/ui/transmute_float_to_int.rs:55:18 + --> tests/ui/transmute_float_to_int.rs:50:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i64` error: transmute from a `f128` to a `i128` - --> tests/ui/transmute_float_to_int.rs:61:18 + --> tests/ui/transmute_float_to_int.rs:55:18 | LL | unsafe { std::mem::transmute(v) } | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `v.to_bits() as i128` diff --git a/tests/ui/transmute_int_to_char.fixed b/tests/ui/transmute_int_to_char.fixed index e28467f00434..b5425a2e9e85 100644 --- a/tests/ui/transmute_int_to_char.fixed +++ b/tests/ui/transmute_int_to_char.fixed @@ -5,11 +5,9 @@ fn int_to_char() { let _: char = unsafe { std::char::from_u32(0_u32).unwrap() }; //~^ transmute_int_to_char - let _: char = unsafe { std::char::from_u32(0_i32 as u32).unwrap() }; //~^ transmute_int_to_char - // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; const _: char = unsafe { std::mem::transmute(0_i32) }; diff --git a/tests/ui/transmute_int_to_char.rs b/tests/ui/transmute_int_to_char.rs index decdaaa463a9..b24bb177c9fc 100644 --- a/tests/ui/transmute_int_to_char.rs +++ b/tests/ui/transmute_int_to_char.rs @@ -5,11 +5,9 @@ fn int_to_char() { let _: char = unsafe { std::mem::transmute(0_u32) }; //~^ transmute_int_to_char - let _: char = unsafe { std::mem::transmute(0_i32) }; //~^ transmute_int_to_char - // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; const _: char = unsafe { std::mem::transmute(0_i32) }; diff --git a/tests/ui/transmute_int_to_char.stderr b/tests/ui/transmute_int_to_char.stderr index 5dc58abb38ea..e3a3620f28b7 100644 --- a/tests/ui/transmute_int_to_char.stderr +++ b/tests/ui/transmute_int_to_char.stderr @@ -8,7 +8,7 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` - --> tests/ui/transmute_int_to_char.rs:9:28 + --> tests/ui/transmute_int_to_char.rs:8:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` diff --git a/tests/ui/transmute_int_to_char_no_std.fixed b/tests/ui/transmute_int_to_char_no_std.fixed index 09a353dc1ae9..e525751e306e 100644 --- a/tests/ui/transmute_int_to_char_no_std.fixed +++ b/tests/ui/transmute_int_to_char_no_std.fixed @@ -17,11 +17,9 @@ fn int_to_char() { let _: char = unsafe { core::char::from_u32(0_u32).unwrap() }; //~^ transmute_int_to_char - let _: char = unsafe { core::char::from_u32(0_i32 as u32).unwrap() }; //~^ transmute_int_to_char - // These shouldn't warn const _: char = unsafe { core::mem::transmute(0_u32) }; const _: char = unsafe { core::mem::transmute(0_i32) }; diff --git a/tests/ui/transmute_int_to_char_no_std.rs b/tests/ui/transmute_int_to_char_no_std.rs index fb47b3ce3ba9..7cb508ceaf3b 100644 --- a/tests/ui/transmute_int_to_char_no_std.rs +++ b/tests/ui/transmute_int_to_char_no_std.rs @@ -17,11 +17,9 @@ fn int_to_char() { let _: char = unsafe { core::mem::transmute(0_u32) }; //~^ transmute_int_to_char - let _: char = unsafe { core::mem::transmute(0_i32) }; //~^ transmute_int_to_char - // These shouldn't warn const _: char = unsafe { core::mem::transmute(0_u32) }; const _: char = unsafe { core::mem::transmute(0_i32) }; diff --git a/tests/ui/transmute_int_to_char_no_std.stderr b/tests/ui/transmute_int_to_char_no_std.stderr index 37f996e6277f..d94580a84d7a 100644 --- a/tests/ui/transmute_int_to_char_no_std.stderr +++ b/tests/ui/transmute_int_to_char_no_std.stderr @@ -8,7 +8,7 @@ LL | let _: char = unsafe { core::mem::transmute(0_u32) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` - --> tests/ui/transmute_int_to_char_no_std.rs:21:28 + --> tests/ui/transmute_int_to_char_no_std.rs:20:28 | LL | let _: char = unsafe { core::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::char::from_u32(0_i32 as u32).unwrap()` diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index 12d8d20f4d8f..273090fef387 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -19,7 +19,6 @@ fn main() { let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; //~^ transmute_int_to_non_zero @@ -32,7 +31,6 @@ fn main() { let _: NonZero = unsafe { NonZero::new_unchecked(int_u128) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { NonZero::new_unchecked(int_i8) }; //~^ transmute_int_to_non_zero @@ -48,7 +46,6 @@ fn main() { let _: NonZero = unsafe { NonZero::new_unchecked(int_i128) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs index a01b9aaa7f2e..f27bc9b42d42 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -19,7 +19,6 @@ fn main() { let _: NonZero = unsafe { std::mem::transmute(int_u8) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { std::mem::transmute(int_u16) }; //~^ transmute_int_to_non_zero @@ -32,7 +31,6 @@ fn main() { let _: NonZero = unsafe { std::mem::transmute(int_u128) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { std::mem::transmute(int_i8) }; //~^ transmute_int_to_non_zero @@ -48,7 +46,6 @@ fn main() { let _: NonZero = unsafe { std::mem::transmute(int_i128) }; //~^ transmute_int_to_non_zero - let _: NonZero = unsafe { NonZero::new_unchecked(int_u8) }; let _: NonZero = unsafe { NonZero::new_unchecked(int_u16) }; let _: NonZero = unsafe { NonZero::new_unchecked(int_u32) }; diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index 1a1cd03248b4..995ab11a5bc9 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -8,55 +8,55 @@ LL | let _: NonZero = unsafe { std::mem::transmute(int_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` error: transmute from a `u16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:23:36 + --> tests/ui/transmute_int_to_non_zero.rs:22:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:26:36 + --> tests/ui/transmute_int_to_non_zero.rs:25:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:29:36 + --> tests/ui/transmute_int_to_non_zero.rs:28:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:32:37 + --> tests/ui/transmute_int_to_non_zero.rs:31:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:36:35 + --> tests/ui/transmute_int_to_non_zero.rs:34:35 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:39:36 + --> tests/ui/transmute_int_to_non_zero.rs:37:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:42:36 + --> tests/ui/transmute_int_to_non_zero.rs:40:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:45:36 + --> tests/ui/transmute_int_to_non_zero.rs:43:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:48:37 + --> tests/ui/transmute_int_to_non_zero.rs:46:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)` diff --git a/tests/ui/transmute_null_to_fn.rs b/tests/ui/transmute_null_to_fn.rs index a9eaf16d05aa..e88f05bb662e 100644 --- a/tests/ui/transmute_null_to_fn.rs +++ b/tests/ui/transmute_null_to_fn.rs @@ -10,7 +10,6 @@ fn one_liners() { let _: fn() = std::mem::transmute(std::ptr::null::<()>()); //~^ transmute_null_to_fn - } } @@ -38,7 +37,6 @@ fn issue_11485() { let _: fn() = std::mem::transmute(ZPTR as *const u8); //~^ transmute_null_to_fn - } } diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index 9b2253c444f4..f7d80147445d 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -17,7 +17,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:23:23 + --> tests/ui/transmute_null_to_fn.rs:22:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -25,7 +25,7 @@ LL | let _: fn() = std::mem::transmute(ZPTR); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:33:23 + --> tests/ui/transmute_null_to_fn.rs:32:23 | LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -33,7 +33,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:36:23 + --> tests/ui/transmute_null_to_fn.rs:35:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -41,7 +41,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:39:23 + --> tests/ui/transmute_null_to_fn.rs:38:23 | LL | let _: fn() = std::mem::transmute(ZPTR as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed index d595ecf32a1c..3a67be5f45d0 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -59,7 +59,6 @@ fn transmute_ptr_to_ptr() { let _: *mut u32 = ptr.cast_mut(); //~^ transmute_ptr_to_ptr - } // transmute internal lifetimes, should not lint @@ -72,7 +71,6 @@ fn transmute_ptr_to_ptr() { fn lifetime_to_static(v: *mut &()) -> *const &'static () { unsafe { v as *const &() } //~^ transmute_ptr_to_ptr - } // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 2e72f86dd3b3..01ad3a3296b1 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -59,7 +59,6 @@ fn transmute_ptr_to_ptr() { let _: *mut u32 = transmute(ptr); //~^ transmute_ptr_to_ptr - } // transmute internal lifetimes, should not lint @@ -72,7 +71,6 @@ fn transmute_ptr_to_ptr() { fn lifetime_to_static(v: *mut &()) -> *const &'static () { unsafe { transmute(v) } //~^ transmute_ptr_to_ptr - } // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 3e7e170eff7f..0ff1cd3c090b 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -75,7 +75,7 @@ LL | let _: *mut u32 = ptr.cast_mut(); | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:73:14 + --> tests/ui/transmute_ptr_to_ptr.rs:72:14 | LL | unsafe { transmute(v) } | ^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | unsafe { v as *const &() } | ~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:89:28 + --> tests/ui/transmute_ptr_to_ptr.rs:87:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: *const i8 = ptr as *const i8; | ~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:97:28 + --> tests/ui/transmute_ptr_to_ptr.rs:95:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | let _: *const i8 = ptr.cast::(); | ~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:105:26 + --> tests/ui/transmute_ptr_to_ptr.rs:103:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | let _: *mut u8 = ptr as *mut u8; | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:107:28 + --> tests/ui/transmute_ptr_to_ptr.rs:105:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -130,7 +130,7 @@ LL | let _: *const u8 = mut_ptr as *const u8; | ~~~~~~~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:115:26 + --> tests/ui/transmute_ptr_to_ptr.rs:113:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -141,7 +141,7 @@ LL | let _: *mut u8 = ptr.cast_mut(); | ~~~~~~~~~~~~~~ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:117:28 + --> tests/ui/transmute_ptr_to_ptr.rs:115:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_ref_to_ref.rs b/tests/ui/transmute_ref_to_ref.rs index c2094ab0cad6..8bdf07b4a428 100644 --- a/tests/ui/transmute_ref_to_ref.rs +++ b/tests/ui/transmute_ref_to_ref.rs @@ -16,6 +16,5 @@ fn main() { let bytes = &[1u8, 2u8, 3u8, 4u8] as &[u8]; let alt_slice: &[u32] = unsafe { std::mem::transmute(bytes) }; //~^ transmute_ptr_to_ptr - } } diff --git a/tests/ui/transmute_ref_to_ref_no_std.rs b/tests/ui/transmute_ref_to_ref_no_std.rs index 86c4189d87e4..faa776f2afce 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.rs +++ b/tests/ui/transmute_ref_to_ref_no_std.rs @@ -28,6 +28,5 @@ fn main() { let bytes = &[1u8, 2u8, 3u8, 4u8] as &[u8]; let alt_slice: &[u32] = unsafe { core::mem::transmute(bytes) }; //~^ transmute_ptr_to_ptr - } } diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index db876150f406..a449d6a4302f 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -34,12 +34,10 @@ fn main() { let _: Ty2C = transmute(value::>()); //~^ transmute_undefined_repr - // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>()); //~^ transmute_undefined_repr - // Ok, Ty2 types are the same let _: Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same @@ -49,13 +47,10 @@ fn main() { let _: Ty2 = transmute(value::>>()); //~^ transmute_undefined_repr - // Lint, different Ty2 instances let _: Ty> = transmute(value::>()); //~^ transmute_undefined_repr - - let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); @@ -63,13 +58,10 @@ fn main() { let _: &Ty2 = transmute(value::>>()); //~^ transmute_undefined_repr - // Lint, different Ty2 instances let _: Ty<&Ty2> = transmute(value::<&Ty2>()); //~^ transmute_undefined_repr - - // Ok, pointer to usize conversion let _: Ty = transmute(value::<&Ty2>()); // Ok, pointer to usize conversion @@ -99,13 +91,10 @@ fn main() { let _: &'static mut Ty2 = transmute(value::>>()); //~^ transmute_undefined_repr - // Lint, different Ty2 instances let _: Box> = transmute(value::<&'static mut Ty2>()); //~^ transmute_undefined_repr - - // Ok, type erasure let _: *const () = transmute(value::>>()); // Ok, reverse type erasure @@ -202,13 +191,10 @@ fn main() { let _: *const Ty2 = transmute(value::<*const Ty2C>>()); //~^ transmute_undefined_repr - // Err let _: *const Ty2C> = transmute(value::<*const Ty2>()); //~^ transmute_undefined_repr - - // Ok let _: NonNull = transmute(value::>()); // Ok @@ -255,13 +241,10 @@ fn _with_generics() { let _: Vec> = transmute(value::>>()); //~^ transmute_undefined_repr - // Err let _: Vec> = transmute(value::>>()); //~^ transmute_undefined_repr - - // Ok let _: *const u32 = transmute(value::>()); // Ok diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index a569309b2eb4..a259ef784c78 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -8,13 +8,13 @@ LL | let _: Ty2C = transmute(value::>()); = help: to override `-D warnings` add `#[allow(clippy::transmute_undefined_repr)]` error: transmute into `Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:39:32 + --> tests/ui/transmute_undefined_repr.rs:38:32 | LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:49:32 + --> tests/ui/transmute_undefined_repr.rs:47:32 | LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | let _: Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:54:36 + --> tests/ui/transmute_undefined_repr.rs:51:36 | LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _: Ty> = transmute(value::>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:63:33 + --> tests/ui/transmute_undefined_repr.rs:58:33 | LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | let _: &Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:68:37 + --> tests/ui/transmute_undefined_repr.rs:62:37 | LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:99:45 + --> tests/ui/transmute_undefined_repr.rs:91:45 | LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | let _: &'static mut Ty2 = transmute(value::` to `std::boxed::Box>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:104:37 + --> tests/ui/transmute_undefined_repr.rs:95:37 | LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | let _: Box> = transmute(value::<&'static mut Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:202:39 + --> tests/ui/transmute_undefined_repr.rs:191:39 | LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _: *const Ty2 = transmute(value::<*const Ty2C` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:207:50 + --> tests/ui/transmute_undefined_repr.rs:195:50 | LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: *const Ty2C> = transmute(value::<*const T = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:255:35 + --> tests/ui/transmute_undefined_repr.rs:241:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | let _: Vec> = transmute(value::>>()); = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:260:35 + --> tests/ui/transmute_undefined_repr.rs:245:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs index 91f32a725589..bcd35bbd4e72 100644 --- a/tests/ui/transmuting_null.rs +++ b/tests/ui/transmuting_null.rs @@ -10,10 +10,8 @@ fn one_liners() { let _: &u64 = std::mem::transmute(0 as *const u64); //~^ transmuting_null - let _: &u64 = std::mem::transmute(std::ptr::null::()); //~^ transmuting_null - } } diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr index 2e5fffd3ac28..84e6e374d525 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -8,13 +8,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); = help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]` error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:14:23 + --> tests/ui/transmuting_null.rs:13:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:26:23 + --> tests/ui/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 09c7bcc68408..89c4955c9f6f 100644 --- a/tests/ui/type_complexity.rs +++ b/tests/ui/type_complexity.rs @@ -7,28 +7,22 @@ type Alias = Vec>>; // no warning here const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~^ type_complexity - static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~^ type_complexity - struct S { f: Vec>>, //~^ type_complexity - } struct Ts(Vec>>); //~^ type_complexity - enum E { Tuple(Vec>>), //~^ type_complexity - Struct { f: Vec>> }, //~^ type_complexity - } impl S { @@ -37,7 +31,6 @@ impl S { fn impl_method(&self, p: Vec>>) {} //~^ type_complexity - } trait T { @@ -52,7 +45,6 @@ trait T { fn def_method(&self, p: Vec>>) {} //~^ type_complexity - } // Should not warn since there is likely no way to simplify this (#1013) @@ -65,7 +57,7 @@ impl T for () { } fn test1() -> Vec>> { -//~^ type_complexity + //~^ type_complexity vec![] } @@ -73,11 +65,9 @@ fn test1() -> Vec>> { fn test2(_x: Vec>>) {} //~^ type_complexity - fn test3() { let _y: Vec>> = vec![]; //~^ type_complexity - } #[repr(C)] diff --git a/tests/ui/type_complexity.stderr b/tests/ui/type_complexity.stderr index 4926432aab88..181e04d38e9a 100644 --- a/tests/ui/type_complexity.stderr +++ b/tests/ui/type_complexity.stderr @@ -8,85 +8,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:11:12 + --> tests/ui/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 - --> tests/ui/type_complexity.rs:16:8 + --> tests/ui/type_complexity.rs:14:8 | LL | f: Vec>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:21:11 + --> tests/ui/type_complexity.rs:18:11 | LL | struct Ts(Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:26:11 + --> tests/ui/type_complexity.rs:22:11 | LL | Tuple(Vec>>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:29:17 + --> tests/ui/type_complexity.rs:24:17 | LL | Struct { f: Vec>> }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:35:14 + --> tests/ui/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 - --> tests/ui/type_complexity.rs:38:30 + --> tests/ui/type_complexity.rs:32:30 | LL | fn impl_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:44:14 + --> tests/ui/type_complexity.rs:37:14 | LL | const A: Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:47:14 + --> tests/ui/type_complexity.rs:40:14 | LL | type B = Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:50:25 + --> tests/ui/type_complexity.rs:43:25 | LL | fn method(&self, p: Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:53:29 + --> tests/ui/type_complexity.rs:46:29 | LL | fn def_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:67:15 + --> tests/ui/type_complexity.rs:59:15 | LL | fn test1() -> Vec>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:73:14 + --> tests/ui/type_complexity.rs:65:14 | LL | fn test2(_x: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> tests/ui/type_complexity.rs:78:13 + --> tests/ui/type_complexity.rs:69:13 | LL | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_id_on_box.fixed b/tests/ui/type_id_on_box.fixed index f0d8a4acb2e3..2e241c36b34a 100644 --- a/tests/ui/type_id_on_box.fixed +++ b/tests/ui/type_id_on_box.fixed @@ -31,7 +31,6 @@ fn main() { let _ = (*any_box).type_id(); //~^ type_id_on_box - // Don't lint. We explicitly say "do this instead" if this is intentional let _ = TypeId::of::>(); let _ = (*any_box).type_id(); @@ -41,7 +40,6 @@ fn main() { let _ = (**any_box).type_id(); //~^ type_id_on_box - let b = existential(); let _ = b.type_id(); // Don't @@ -49,12 +47,10 @@ fn main() { let _ = (*b).type_id(); //~^ type_id_on_box - let b: SomeBox = Box::new(0usize); let _ = (*b).type_id(); //~^ type_id_on_box - let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! } diff --git a/tests/ui/type_id_on_box.rs b/tests/ui/type_id_on_box.rs index b446ec287b67..46fac632894c 100644 --- a/tests/ui/type_id_on_box.rs +++ b/tests/ui/type_id_on_box.rs @@ -31,7 +31,6 @@ fn main() { let _ = any_box.type_id(); //~^ type_id_on_box - // Don't lint. We explicitly say "do this instead" if this is intentional let _ = TypeId::of::>(); let _ = (*any_box).type_id(); @@ -41,7 +40,6 @@ fn main() { let _ = any_box.type_id(); //~^ type_id_on_box - let b = existential(); let _ = b.type_id(); // Don't @@ -49,12 +47,10 @@ fn main() { let _ = b.type_id(); //~^ type_id_on_box - let b: SomeBox = Box::new(0usize); let _ = b.type_id(); //~^ type_id_on_box - let b = BadBox(Box::new(0usize)); let _ = b.type_id(); // Don't lint. This is a call to `::type_id`. Not `std::boxed::Box`! } diff --git a/tests/ui/type_id_on_box.stderr b/tests/ui/type_id_on_box.stderr index 8004ef71287c..4528195607da 100644 --- a/tests/ui/type_id_on_box.stderr +++ b/tests/ui/type_id_on_box.stderr @@ -12,7 +12,7 @@ LL | let _ = any_box.type_id(); = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:41:13 + --> tests/ui/type_id_on_box.rs:40:13 | LL | let _ = any_box.type_id(); | -------^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = any_box.type_id(); = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:49:13 + --> tests/ui/type_id_on_box.rs:47:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = b.type_id(); = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box.rs:54:13 + --> tests/ui/type_id_on_box.rs:51:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ diff --git a/tests/ui/type_id_on_box_unfixable.rs b/tests/ui/type_id_on_box_unfixable.rs index 4df0ebb897a8..58d245d56aa5 100644 --- a/tests/ui/type_id_on_box_unfixable.rs +++ b/tests/ui/type_id_on_box_unfixable.rs @@ -25,9 +25,7 @@ fn main() { let _ = b.type_id(); //~^ type_id_on_box - let b: Box = Box::new(1); let _ = b.type_id(); //~^ type_id_on_box - } diff --git a/tests/ui/type_id_on_box_unfixable.stderr b/tests/ui/type_id_on_box_unfixable.stderr index c653fd7835ff..539ed481ec10 100644 --- a/tests/ui/type_id_on_box_unfixable.stderr +++ b/tests/ui/type_id_on_box_unfixable.stderr @@ -10,7 +10,7 @@ LL | let _ = b.type_id(); = help: to override `-D warnings` add `#[allow(clippy::type_id_on_box)]` error: calling `.type_id()` on `Box` - --> tests/ui/type_id_on_box_unfixable.rs:30:13 + --> tests/ui/type_id_on_box_unfixable.rs:29:13 | LL | let _ = b.type_id(); | ^^^^^^^^^^^ diff --git a/tests/ui/unbuffered_bytes.rs b/tests/ui/unbuffered_bytes.rs index 82c8839e8391..87199c7e335d 100644 --- a/tests/ui/unbuffered_bytes.rs +++ b/tests/ui/unbuffered_bytes.rs @@ -8,10 +8,12 @@ fn main() { // File is not buffered, should complain let file = File::open("./bytes.txt").unwrap(); file.bytes(); + //~^ unbuffered_bytes // TcpStream is not buffered, should complain let tcp_stream: TcpStream = TcpStream::connect("127.0.0.1:80").unwrap(); tcp_stream.bytes(); + //~^ unbuffered_bytes // BufReader is buffered, should not complain let file = BufReader::new(File::open("./bytes.txt").unwrap()); @@ -24,6 +26,7 @@ fn main() { // Stdio would acquire the lock for every byte, should complain let s: Stdin = stdin(); s.bytes(); + //~^ unbuffered_bytes // But when locking stdin, this is fine so should not complain let s: Stdin = stdin(); @@ -34,4 +37,5 @@ fn main() { fn use_read(r: R) { // Callers of `use_read` may choose a `R` that is not buffered r.bytes(); + //~^ unbuffered_bytes } diff --git a/tests/ui/unbuffered_bytes.stderr b/tests/ui/unbuffered_bytes.stderr index 3303d579fedc..7505eb9e363a 100644 --- a/tests/ui/unbuffered_bytes.stderr +++ b/tests/ui/unbuffered_bytes.stderr @@ -9,7 +9,7 @@ LL | file.bytes(); = help: to override `-D warnings` add `#[allow(clippy::unbuffered_bytes)]` error: calling .bytes() is very inefficient when data is not in memory - --> tests/ui/unbuffered_bytes.rs:14:5 + --> tests/ui/unbuffered_bytes.rs:15:5 | LL | tcp_stream.bytes(); | ^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | tcp_stream.bytes(); = help: consider using `BufReader` error: calling .bytes() is very inefficient when data is not in memory - --> tests/ui/unbuffered_bytes.rs:26:5 + --> tests/ui/unbuffered_bytes.rs:28:5 | LL | s.bytes(); | ^^^^^^^^^ @@ -25,7 +25,7 @@ LL | s.bytes(); = help: consider using `BufReader` error: calling .bytes() is very inefficient when data is not in memory - --> tests/ui/unbuffered_bytes.rs:36:5 + --> tests/ui/unbuffered_bytes.rs:39:5 | LL | r.bytes(); | ^^^^^^^^^ diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 6cbd6bffb8db..d9f4c07dc902 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -15,12 +15,12 @@ enum Foo { impl PartialEq for Foo { fn ne(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self != other } fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self == other } @@ -33,11 +33,11 @@ enum Foo2 { impl PartialEq for Foo2 { fn ne(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self != &Foo2::B // no error here } fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self == &Foo2::B // no error here } } @@ -49,13 +49,13 @@ enum Foo3 { impl PartialEq for Foo3 { fn ne(&self, other: &Self) -> bool { - //~^ unconditional_recursion - //~| ERROR: function cannot return without recursing + //~^ unconditional_recursion + //~| ERROR: function cannot return without recursing self.ne(other) } fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion - //~| ERROR: function cannot return without recursing + //~^ unconditional_recursion + //~| ERROR: function cannot return without recursing self.eq(other) } @@ -100,12 +100,12 @@ struct S; // Check the order doesn't matter. impl PartialEq for S { fn ne(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion other != self } fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion other == self } @@ -116,13 +116,13 @@ struct S2; // Check that if the same element is compared, it's also triggering the lint. impl PartialEq for S2 { fn ne(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion other != other //~^ eq_op } fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion other == other //~^ eq_op @@ -133,13 +133,13 @@ struct S3; impl PartialEq for S3 { fn ne(&self, _other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self != self //~^ eq_op } fn eq(&self, _other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self == self //~^ eq_op @@ -169,7 +169,7 @@ macro_rules! impl_partial_eq { ($ty:ident) => { impl PartialEq for $ty { fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion self == other } @@ -199,7 +199,7 @@ struct S7<'a> { impl<'a> PartialEq for S7<'a> { fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion let mine = &self.field; let theirs = &other.field; @@ -269,7 +269,7 @@ impl std::default::Default for S12 { impl S12 { fn new() -> Self { - //~^ unconditional_recursion + //~^ unconditional_recursion Self::default() } @@ -309,7 +309,7 @@ struct S15<'a> { impl PartialEq for S15<'_> { fn eq(&self, other: &Self) -> bool { - //~^ unconditional_recursion + //~^ unconditional_recursion let mine = &self.field; let theirs = &other.field; @@ -381,7 +381,7 @@ struct BadFromTy1<'a>(&'a ()); struct BadIntoTy1<'b>(&'b ()); impl<'a> From> for BadIntoTy1<'static> { fn from(f: BadFromTy1<'a>) -> Self { - //~^ unconditional_recursion + //~^ unconditional_recursion f.into() } } @@ -391,7 +391,7 @@ struct BadFromTy2<'a>(&'a ()); struct BadIntoTy2<'b>(&'b ()); impl<'a> From> for BadIntoTy2<'static> { fn from(f: BadFromTy2<'a>) -> Self { - //~^ unconditional_recursion + //~^ unconditional_recursion Into::into(f) } } diff --git a/tests/ui/uninhabited_references.rs b/tests/ui/uninhabited_references.rs index 649af4312ce4..9b3616ad5187 100644 --- a/tests/ui/uninhabited_references.rs +++ b/tests/ui/uninhabited_references.rs @@ -3,14 +3,14 @@ #![feature(never_type)] fn ret_uninh_ref() -> &'static std::convert::Infallible { -//~^ uninhabited_references + //~^ uninhabited_references unsafe { std::mem::transmute(&()) } } macro_rules! ret_something { ($name:ident, $ty:ty) => { fn $name(x: &$ty) -> &$ty { - //~^ uninhabited_references + //~^ uninhabited_references &*x //~^ uninhabited_references } diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index 965ef4a10b39..f74248c8aea8 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -12,8 +12,6 @@ fn main() { let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; //~^ uninit_assumed_init - - // This is OK, because ZSTs do not contain data. let _: () = unsafe { MaybeUninit::uninit().assume_init() }; @@ -36,7 +34,6 @@ fn main() { let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; //~^ uninit_assumed_init - polymorphic::<()>(); polymorphic_maybe_uninit_array::<10>(); polymorphic_maybe_uninit::(); @@ -45,7 +42,6 @@ fn main() { // We are conservative around polymorphic types. let _: T = unsafe { MaybeUninit::uninit().assume_init() }; //~^ uninit_assumed_init - } fn polymorphic_maybe_uninit_array() { diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr index 9179a2b28dbb..d6f54dd61ca0 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 - --> tests/ui/uninit.rs:36:29 + --> tests/ui/uninit.rs:34:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:46:29 + --> tests/ui/uninit.rs:43:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 444a5b1cfb5f..6db094babb24 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -53,7 +53,7 @@ fn tester(fn_arg: i32) { println!("val='{local_i32}'"); // tab+space //~^ uninlined_format_args println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "val='{local_i32}'" ); println!("{local_i32}"); @@ -173,7 +173,7 @@ fn tester(fn_arg: i32) { println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); //~^ uninlined_format_args println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}", ); println!( @@ -208,7 +208,7 @@ fn tester(fn_arg: i32) { println!(no_param_str!(), local_i32); println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "{val}", ); println!("{val}"); diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index 526fd98dfa4b..7ca61b800219 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -53,7 +53,7 @@ fn tester(fn_arg: i32) { println!("val='{ }'", local_i32); // tab+space //~^ uninlined_format_args println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "val='{ }'", local_i32 @@ -175,7 +175,7 @@ fn tester(fn_arg: i32) { println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); //~^ uninlined_format_args println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", local_i32, width, prec, ); @@ -211,7 +211,7 @@ fn tester(fn_arg: i32) { println!(no_param_str!(), local_i32); println!( - //~^ uninlined_format_args + //~^ uninlined_format_args "{}", // comment with a comma , in it val, diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 3a3962d09143..22a6a26dab62 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -61,30 +61,30 @@ impl Tr for B { fn bad() { foo({ - //~^ unit_arg + //~^ unit_arg 1; }); foo(foo(1)); //~^ unit_arg foo({ - //~^ unit_arg + //~^ unit_arg foo(1); foo(2); }); let b = Bar; b.bar({ - //~^ unit_arg + //~^ unit_arg 1; }); taking_multiple_units(foo(0), foo(1)); //~^ unit_arg taking_multiple_units(foo(0), { - //~^ unit_arg + //~^ unit_arg foo(1); foo(2); }); taking_multiple_units( - //~^ unit_arg + //~^ unit_arg { foo(0); foo(1); diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index 0b1cccfbadf6..93f5b87c3d2a 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -15,8 +15,7 @@ fn main() { // this warns if { - //~^ unit_cmp - + //~^ unit_cmp true; } == { @@ -24,7 +23,7 @@ fn main() { } {} if { - //~^ unit_cmp + //~^ unit_cmp true; } > { @@ -32,8 +31,7 @@ fn main() { } {} assert_eq!( - //~^ unit_cmp - + //~^ unit_cmp { true; }, @@ -42,8 +40,7 @@ fn main() { } ); debug_assert_eq!( - //~^ unit_cmp - + //~^ unit_cmp { true; }, @@ -53,8 +50,7 @@ fn main() { ); assert_ne!( - //~^ unit_cmp - + //~^ unit_cmp { true; }, @@ -63,8 +59,7 @@ fn main() { } ); debug_assert_ne!( - //~^ unit_cmp - + //~^ unit_cmp { true; }, diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 0c485edd9736..8f26749fd860 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -3,7 +3,10 @@ error: ==-comparison of unit values detected. This will always be true | LL | if { | ________^ -... | +LL | | +LL | | +LL | | true; +LL | | } == { LL | | false; LL | | } {} | |_____^ @@ -12,7 +15,7 @@ LL | | } {} = help: to override `-D warnings` add `#[allow(clippy::unit_cmp)]` error: >-comparison of unit values detected. This will always be false - --> tests/ui/unit_cmp.rs:26:8 + --> tests/ui/unit_cmp.rs:25:8 | LL | if { | ________^ @@ -25,33 +28,45 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:34:5 + --> tests/ui/unit_cmp.rs:33:5 | LL | / assert_eq!( +LL | | +LL | | { +LL | | true; ... | LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:44:5 + --> tests/ui/unit_cmp.rs:42:5 | LL | / debug_assert_eq!( +LL | | +LL | | { +LL | | true; ... | LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:55:5 + --> tests/ui/unit_cmp.rs:52:5 | LL | / assert_ne!( +LL | | +LL | | { +LL | | true; ... | LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:65:5 + --> tests/ui/unit_cmp.rs:61:5 | LL | / debug_assert_ne!( +LL | | +LL | | { +LL | | true; ... | LL | | ); | |_____^ diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed index 4df67c783d32..25c90e6ddc4c 100644 --- a/tests/ui/unit_hash.fixed +++ b/tests/ui/unit_hash.fixed @@ -18,8 +18,6 @@ fn main() { match my_enum { Foo::Empty => 0_u8.hash(&mut state), //~^ unit_hash - - Foo::WithValue(x) => x.hash(&mut state), } @@ -27,11 +25,7 @@ fn main() { 0_u8.hash(&mut state); //~^ unit_hash - - #[allow(clippy::unit_arg)] 0_u8.hash(&mut state); //~^ unit_hash - - } diff --git a/tests/ui/unit_hash.rs b/tests/ui/unit_hash.rs index 15f27aab95e1..b04cca6adf2a 100644 --- a/tests/ui/unit_hash.rs +++ b/tests/ui/unit_hash.rs @@ -18,8 +18,6 @@ fn main() { match my_enum { Foo::Empty => ().hash(&mut state), //~^ unit_hash - - Foo::WithValue(x) => x.hash(&mut state), } @@ -27,11 +25,7 @@ fn main() { res.hash(&mut state); //~^ unit_hash - - #[allow(clippy::unit_arg)] do_nothing().hash(&mut state); //~^ unit_hash - - } diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index be019d398b58..d1cabf89f8e7 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -9,7 +9,7 @@ LL | Foo::Empty => ().hash(&mut state), = help: to override `-D warnings` add `#[allow(clippy::unit_hash)]` error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:27:5 + --> tests/ui/unit_hash.rs:25:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -17,7 +17,7 @@ LL | res.hash(&mut state); = note: the implementation of `Hash` for `()` is a no-op error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:33:5 + --> tests/ui/unit_hash.rs:29: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 3585eb5395db..74cd30472684 100644 --- a/tests/ui/unit_return_expecting_ord.rs +++ b/tests/ui/unit_return_expecting_ord.rs @@ -16,18 +16,18 @@ fn unit(_i: isize) {} fn main() { let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }]; structs.sort_by_key(|s| { - //~^ unit_return_expecting_ord + //~^ unit_return_expecting_ord double(s.field); }); structs.sort_by_key(|s| double(s.field)); structs.is_sorted_by_key(|s| { - //~^ unit_return_expecting_ord + //~^ unit_return_expecting_ord double(s.field); }); structs.is_sorted_by_key(|s| { - //~^ unit_return_expecting_ord + //~^ unit_return_expecting_ord if s.field > 0 { () @@ -40,5 +40,4 @@ fn main() { }); structs.sort_by_key(|s| unit(s.field)); //~^ unit_return_expecting_ord - } diff --git a/tests/ui/unnecessary_box_returns.rs b/tests/ui/unnecessary_box_returns.rs index 5037c05a0acb..a7ab7e90be06 100644 --- a/tests/ui/unnecessary_box_returns.rs +++ b/tests/ui/unnecessary_box_returns.rs @@ -4,7 +4,6 @@ trait Bar { // lint fn baz(&self) -> Box; //~^ unnecessary_box_returns - } pub struct Foo {} @@ -18,7 +17,7 @@ impl Bar for Foo { impl Foo { fn baz(&self) -> Box { - //~^ unnecessary_box_returns + //~^ unnecessary_box_returns // lint Box::new(13) @@ -27,14 +26,14 @@ impl Foo { // lint fn bxed_usize() -> Box { -//~^ unnecessary_box_returns + //~^ unnecessary_box_returns Box::new(5) } // lint fn _bxed_foo() -> Box { -//~^ unnecessary_box_returns + //~^ unnecessary_box_returns Box::new(Foo {}) } diff --git a/tests/ui/unnecessary_box_returns.stderr b/tests/ui/unnecessary_box_returns.stderr index 9df056569a29..ab1d90f13b92 100644 --- a/tests/ui/unnecessary_box_returns.stderr +++ b/tests/ui/unnecessary_box_returns.stderr @@ -9,7 +9,7 @@ LL | fn baz(&self) -> Box; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` error: boxed return of the sized type `usize` - --> tests/ui/unnecessary_box_returns.rs:20:22 + --> tests/ui/unnecessary_box_returns.rs:19:22 | LL | fn baz(&self) -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -17,7 +17,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` - --> tests/ui/unnecessary_box_returns.rs:29:20 + --> tests/ui/unnecessary_box_returns.rs:28:20 | LL | fn bxed_usize() -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -25,7 +25,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` - --> tests/ui/unnecessary_box_returns.rs:36:19 + --> tests/ui/unnecessary_box_returns.rs:35: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 05dd20c7a114..2bb64c3e80e3 100644 --- a/tests/ui/unnecessary_cast_unfixable.rs +++ b/tests/ui/unnecessary_cast_unfixable.rs @@ -3,8 +3,6 @@ fn main() { let _ = std::ptr::null() as *const u8; //~^ unnecessary_cast - - } mod issue11113 { @@ -21,7 +19,6 @@ mod issue11113 { unsafe fn query(&self) { ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() //~^ unnecessary_cast - } } } diff --git a/tests/ui/unnecessary_cast_unfixable.stderr b/tests/ui/unnecessary_cast_unfixable.stderr index 0047b38850b7..6ba1c7873066 100644 --- a/tests/ui/unnecessary_cast_unfixable.stderr +++ b/tests/ui/unnecessary_cast_unfixable.stderr @@ -8,7 +8,7 @@ LL | let _ = std::ptr::null() as *const u8; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) - --> tests/ui/unnecessary_cast_unfixable.rs:22:16 + --> tests/ui/unnecessary_cast_unfixable.rs:20:16 | LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs index 406c0133c5d3..e7e01248dfbe 100644 --- a/tests/ui/unnecessary_clippy_cfg.rs +++ b/tests/ui/unnecessary_clippy_cfg.rs @@ -3,28 +3,21 @@ #![warn(clippy::unnecessary_clippy_cfg)] #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg - #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg - #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg //~| duplicated_attributes - #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg - #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg - #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg - #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg //~| duplicated_attributes - #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg diff --git a/tests/ui/unnecessary_clippy_cfg.stderr b/tests/ui/unnecessary_clippy_cfg.stderr index f6f36fbf2baa..f66c68949548 100644 --- a/tests/ui/unnecessary_clippy_cfg.stderr +++ b/tests/ui/unnecessary_clippy_cfg.stderr @@ -8,7 +8,7 @@ LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] = help: to override `-D warnings` add `#[allow(clippy::unnecessary_clippy_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:7:37 + --> tests/ui/unnecessary_clippy_cfg.rs:6:37 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:10:37 + --> tests/ui/unnecessary_clippy_cfg.rs:8:37 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,19 +24,19 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:14:1 + --> tests/ui/unnecessary_clippy_cfg.rs:11:1 | LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:18:1 + --> tests/ui/unnecessary_clippy_cfg.rs:14:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:21:36 + --> tests/ui/unnecessary_clippy_cfg.rs:16:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:24:36 + --> tests/ui/unnecessary_clippy_cfg.rs:18:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,24 +52,24 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:28:1 + --> tests/ui/unnecessary_clippy_cfg.rs:21:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:10:26 + --> tests/ui/unnecessary_clippy_cfg.rs:8:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ | note: first defined here - --> tests/ui/unnecessary_clippy_cfg.rs:7:26 + --> tests/ui/unnecessary_clippy_cfg.rs:6:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:10:26 + --> tests/ui/unnecessary_clippy_cfg.rs:8:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ @@ -77,18 +77,18 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:24:25 + --> tests/ui/unnecessary_clippy_cfg.rs:18:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ | note: first defined here - --> tests/ui/unnecessary_clippy_cfg.rs:21:25 + --> tests/ui/unnecessary_clippy_cfg.rs:16:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:24:25 + --> tests/ui/unnecessary_clippy_cfg.rs:18:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 3ce7c7ef0252..7335b6f9f039 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -23,7 +23,6 @@ fn clone_on_ref_ptr() { rc.clone(); //~^ clone_on_ref_ptr - Rc::clone(&rc); arc.clone(); @@ -44,18 +43,14 @@ fn clone_on_ref_ptr() { let x = Arc::new(SomeImpl); let _: Arc = x.clone(); //~^ clone_on_ref_ptr - } fn clone_on_copy_generic(t: T) { t.clone(); //~^ clone_on_copy - - Some(t).clone(); //~^ clone_on_copy - } mod many_derefs { @@ -112,6 +107,5 @@ mod issue2076 { let rc = Rc::new(42); Some(try_opt!(Some(rc)).clone()) //~^ clone_on_ref_ptr - } } diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index cf508eb4c645..a4fdf09cd5dc 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -8,31 +8,31 @@ LL | rc.clone(); = help: to override `-D warnings` add `#[allow(clippy::clone_on_ref_ptr)]` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:29:5 + --> tests/ui/unnecessary_clone.rs:28:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try: `Arc::::clone(&arc)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:34:5 + --> tests/ui/unnecessary_clone.rs:33:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try: `Weak::::clone(&rcweak)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:39:5 + --> tests/ui/unnecessary_clone.rs:38:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try: `Weak::::clone(&arc_weak)` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:45:33 + --> tests/ui/unnecessary_clone.rs:44:33 | LL | let _: Arc = x.clone(); | ^^^^^^^^^ help: try: `Arc::::clone(&x)` error: using `clone` on type `T` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:51:5 + --> tests/ui/unnecessary_clone.rs:49:5 | LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` @@ -41,19 +41,19 @@ LL | t.clone(); = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `Option` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:56:5 + --> tests/ui/unnecessary_clone.rs:52:5 | LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on type `E` which implements the `Copy` trait - --> tests/ui/unnecessary_clone.rs:92:20 + --> tests/ui/unnecessary_clone.rs:87:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` error: using `.clone()` on a ref-counted pointer - --> tests/ui/unnecessary_clone.rs:113:14 + --> tests/ui/unnecessary_clone.rs:108:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::::clone(&try_opt!(Some(rc)))` diff --git a/tests/ui/unnecessary_fallible_conversions.fixed b/tests/ui/unnecessary_fallible_conversions.fixed index 59d24e9bb7e2..bae8f066cf12 100644 --- a/tests/ui/unnecessary_fallible_conversions.fixed +++ b/tests/ui/unnecessary_fallible_conversions.fixed @@ -6,48 +6,38 @@ fn main() { let _: i64 = 0i32.into(); //~^ unnecessary_fallible_conversions - let _: i64 = 0i32.into(); //~^ unnecessary_fallible_conversions - // --- TryFromFunction `T::try_from(U)` --- let _ = i64::from(0i32); //~^ unnecessary_fallible_conversions - let _ = i64::from(0i32); //~^ unnecessary_fallible_conversions - // --- TryIntoFunction `U::try_into(t)` --- let _: i64 = i32::into(0); //~^ unnecessary_fallible_conversions - let _: i64 = i32::into(0i32); //~^ unnecessary_fallible_conversions - // --- TryFromFunction `>::try_from(U)` --- let _ = >::from(0); //~^ unnecessary_fallible_conversions - let _ = >::from(0); //~^ unnecessary_fallible_conversions - // --- TryIntoFunction `>::try_into(U)` --- let _: i64 = >::into(0); //~^ unnecessary_fallible_conversions - let _: i64 = >::into(0); //~^ unnecessary_fallible_conversions - } diff --git a/tests/ui/unnecessary_fallible_conversions.rs b/tests/ui/unnecessary_fallible_conversions.rs index 7e504acb5e21..04c9826f3765 100644 --- a/tests/ui/unnecessary_fallible_conversions.rs +++ b/tests/ui/unnecessary_fallible_conversions.rs @@ -6,48 +6,38 @@ fn main() { let _: i64 = 0i32.try_into().unwrap(); //~^ unnecessary_fallible_conversions - let _: i64 = 0i32.try_into().expect("can't happen"); //~^ unnecessary_fallible_conversions - // --- TryFromFunction `T::try_from(U)` --- let _ = i64::try_from(0i32).unwrap(); //~^ unnecessary_fallible_conversions - let _ = i64::try_from(0i32).expect("can't happen"); //~^ unnecessary_fallible_conversions - // --- TryIntoFunction `U::try_into(t)` --- let _: i64 = i32::try_into(0).unwrap(); //~^ unnecessary_fallible_conversions - let _: i64 = i32::try_into(0i32).expect("can't happen"); //~^ unnecessary_fallible_conversions - // --- TryFromFunction `>::try_from(U)` --- let _ = >::try_from(0).unwrap(); //~^ unnecessary_fallible_conversions - let _ = >::try_from(0).expect("can't happen"); //~^ unnecessary_fallible_conversions - // --- TryIntoFunction `>::try_into(U)` --- let _: i64 = >::try_into(0).unwrap(); //~^ unnecessary_fallible_conversions - let _: i64 = >::try_into(0).expect("can't happen"); //~^ unnecessary_fallible_conversions - } diff --git a/tests/ui/unnecessary_fallible_conversions.stderr b/tests/ui/unnecessary_fallible_conversions.stderr index 160917694c44..ade3aada9289 100644 --- a/tests/ui/unnecessary_fallible_conversions.stderr +++ b/tests/ui/unnecessary_fallible_conversions.stderr @@ -14,7 +14,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:10:23 + --> tests/ui/unnecessary_fallible_conversions.rs:9:23 | LL | let _: i64 = 0i32.try_into().expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL + let _: i64 = 0i32.into(); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:16:13 + --> tests/ui/unnecessary_fallible_conversions.rs:14:13 | LL | let _ = i64::try_from(0i32).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:20:13 + --> tests/ui/unnecessary_fallible_conversions.rs:17:13 | LL | let _ = i64::try_from(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL + let _ = i64::from(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:26:18 + --> tests/ui/unnecessary_fallible_conversions.rs:22:18 | LL | let _: i64 = i32::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL + let _: i64 = i32::into(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:30:18 + --> tests/ui/unnecessary_fallible_conversions.rs:25:18 | LL | let _: i64 = i32::try_into(0i32).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ LL + let _: i64 = i32::into(0i32); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:36:13 + --> tests/ui/unnecessary_fallible_conversions.rs:30:13 | LL | let _ = >::try_from(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL + let _ = >::from(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:40:13 + --> tests/ui/unnecessary_fallible_conversions.rs:33:13 | LL | let _ = >::try_from(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL + let _ = >::from(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:46:18 + --> tests/ui/unnecessary_fallible_conversions.rs:38:18 | LL | let _: i64 = >::try_into(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL + let _: i64 = >::into(0); | error: use of a fallible conversion when an infallible one could be used - --> tests/ui/unnecessary_fallible_conversions.rs:50:18 + --> tests/ui/unnecessary_fallible_conversions.rs:41:18 | LL | let _: i64 = >::try_into(0).expect("can't happen"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index e05161d207ec..c4f1b6bc7e3d 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -5,9 +5,8 @@ fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); //~^ unnecessary_filter_map - let _ = (0..4).filter_map(|x| { - //~^ unnecessary_filter_map + //~^ unnecessary_filter_map if x > 1 { return Some(x); @@ -15,8 +14,7 @@ fn main() { None }); let _ = (0..4).filter_map(|x| match x { - //~^ unnecessary_filter_map - + //~^ unnecessary_filter_map 0 | 1 => None, _ => Some(x), }); @@ -24,7 +22,6 @@ fn main() { let _ = (0..4).filter_map(|x| Some(x + 1)); //~^ unnecessary_filter_map - let _ = (0..4).filter_map(i32::checked_abs); let _ = (0..4).filter_map(Some); diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index 94435ab3effd..6683444b7273 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:9:13 + --> tests/ui/unnecessary_filter_map.rs:8:13 | LL | let _ = (0..4).filter_map(|x| { | _____________^ @@ -21,25 +21,24 @@ LL | | }); | |______^ help: try instead: `filter` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:17:13 + --> tests/ui/unnecessary_filter_map.rs:16:13 | LL | let _ = (0..4).filter_map(|x| match x { | _____________^ LL | | -LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ help: try instead: `filter` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:24:13 + --> tests/ui/unnecessary_filter_map.rs:22:13 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map` error: redundant closure - --> tests/ui/unnecessary_filter_map.rs:32:57 + --> tests/ui/unnecessary_filter_map.rs:29:57 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^^^^^^^^ help: replace the closure with the function itself: `Some` @@ -48,19 +47,19 @@ LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: filter_map is unnecessary - --> tests/ui/unnecessary_filter_map.rs:32:61 + --> tests/ui/unnecessary_filter_map.rs:29:61 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^ help: try removing the filter_map error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:32:13 + --> tests/ui/unnecessary_filter_map.rs:29:13 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map` error: this `.filter_map` can be written more simply - --> tests/ui/unnecessary_filter_map.rs:172:14 + --> tests/ui/unnecessary_filter_map.rs:169:14 | LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `filter` diff --git a/tests/ui/unnecessary_find_map.rs b/tests/ui/unnecessary_find_map.rs index f883b4eb38c5..8c8a3799f021 100644 --- a/tests/ui/unnecessary_find_map.rs +++ b/tests/ui/unnecessary_find_map.rs @@ -5,9 +5,8 @@ fn main() { let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); //~^ unnecessary_find_map - let _ = (0..4).find_map(|x| { - //~^ unnecessary_find_map + //~^ unnecessary_find_map if x > 1 { return Some(x); @@ -15,8 +14,7 @@ fn main() { None }); let _ = (0..4).find_map(|x| match x { - //~^ unnecessary_find_map - + //~^ unnecessary_find_map 0 | 1 => None, _ => Some(x), }); @@ -24,7 +22,6 @@ fn main() { let _ = (0..4).find_map(|x| Some(x + 1)); //~^ unnecessary_find_map - 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 079c1092784e..94e320773a6f 100644 --- a/tests/ui/unnecessary_find_map.stderr +++ b/tests/ui/unnecessary_find_map.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:9:13 + --> tests/ui/unnecessary_find_map.rs:8:13 | LL | let _ = (0..4).find_map(|x| { | _____________^ @@ -21,25 +21,24 @@ LL | | }); | |______^ help: try instead: `find` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:17:13 + --> tests/ui/unnecessary_find_map.rs:16:13 | LL | let _ = (0..4).find_map(|x| match x { | _____________^ LL | | -LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ help: try instead: `find` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:24:13 + --> tests/ui/unnecessary_find_map.rs:22:13 | LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map(..).next()` error: this `.find_map` can be written more simply - --> tests/ui/unnecessary_find_map.rs:37:14 + --> tests/ui/unnecessary_find_map.rs:34:14 | LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `find` diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed index 2c3f87513c40..1c331be75094 100644 --- a/tests/ui/unnecessary_fold.fixed +++ b/tests/ui/unnecessary_fold.fixed @@ -57,7 +57,7 @@ fn unnecessary_fold_over_multiple_lines() { .map(|x| x + 1) .filter(|x| x % 2 == 0) .any(|x| x > 2); - //~^ unnecessary_fold + //~^ unnecessary_fold } fn issue10000() { diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index 954020046763..e2050e37e3b1 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -57,7 +57,7 @@ fn unnecessary_fold_over_multiple_lines() { .map(|x| x + 1) .filter(|x| x % 2 == 0) .fold(false, |acc, x| acc || x > 2); - //~^ unnecessary_fold + //~^ unnecessary_fold } fn issue10000() { diff --git a/tests/ui/unnecessary_get_then_check.fixed b/tests/ui/unnecessary_get_then_check.fixed index 6aba66b87318..c6da769544e0 100644 --- a/tests/ui/unnecessary_get_then_check.fixed +++ b/tests/ui/unnecessary_get_then_check.fixed @@ -4,33 +4,33 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; fn main() { let s: HashSet = HashSet::new(); -let _ = s.contains("a"); -//~^ unnecessary_get_then_check -let _ = !s.contains("a"); -//~^ unnecessary_get_then_check + let _ = s.contains("a"); + //~^ unnecessary_get_then_check + let _ = !s.contains("a"); + //~^ unnecessary_get_then_check let s: HashMap = HashMap::new(); -let _ = s.contains_key("a"); -//~^ unnecessary_get_then_check -let _ = !s.contains_key("a"); -//~^ unnecessary_get_then_check + let _ = s.contains_key("a"); + //~^ unnecessary_get_then_check + let _ = !s.contains_key("a"); + //~^ unnecessary_get_then_check let s: BTreeSet = BTreeSet::new(); -let _ = s.contains("a"); -//~^ unnecessary_get_then_check -let _ = !s.contains("a"); -//~^ unnecessary_get_then_check + let _ = s.contains("a"); + //~^ unnecessary_get_then_check + let _ = !s.contains("a"); + //~^ unnecessary_get_then_check let s: BTreeMap = BTreeMap::new(); -let _ = s.contains_key("a"); -//~^ unnecessary_get_then_check -let _ = !s.contains_key("a"); -//~^ unnecessary_get_then_check + let _ = s.contains_key("a"); + //~^ unnecessary_get_then_check + let _ = !s.contains_key("a"); + //~^ unnecessary_get_then_check // Import to check that the generic annotations are kept! let s: HashSet = HashSet::new(); -let _ = s.contains::("a"); -//~^ unnecessary_get_then_check -let _ = !s.contains::("a"); -//~^ unnecessary_get_then_check + let _ = s.contains::("a"); + //~^ unnecessary_get_then_check + let _ = !s.contains::("a"); + //~^ unnecessary_get_then_check } diff --git a/tests/ui/unnecessary_get_then_check.rs b/tests/ui/unnecessary_get_then_check.rs index d56e7d209e4e..323ccc2136ce 100644 --- a/tests/ui/unnecessary_get_then_check.rs +++ b/tests/ui/unnecessary_get_then_check.rs @@ -4,33 +4,33 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; fn main() { let s: HashSet = HashSet::new(); -let _ = s.get("a").is_some(); -//~^ unnecessary_get_then_check -let _ = s.get("a").is_none(); -//~^ unnecessary_get_then_check + let _ = s.get("a").is_some(); + //~^ unnecessary_get_then_check + let _ = s.get("a").is_none(); + //~^ unnecessary_get_then_check let s: HashMap = HashMap::new(); -let _ = s.get("a").is_some(); -//~^ unnecessary_get_then_check -let _ = s.get("a").is_none(); -//~^ unnecessary_get_then_check + let _ = s.get("a").is_some(); + //~^ unnecessary_get_then_check + let _ = s.get("a").is_none(); + //~^ unnecessary_get_then_check let s: BTreeSet = BTreeSet::new(); -let _ = s.get("a").is_some(); -//~^ unnecessary_get_then_check -let _ = s.get("a").is_none(); -//~^ unnecessary_get_then_check + let _ = s.get("a").is_some(); + //~^ unnecessary_get_then_check + let _ = s.get("a").is_none(); + //~^ unnecessary_get_then_check let s: BTreeMap = BTreeMap::new(); -let _ = s.get("a").is_some(); -//~^ unnecessary_get_then_check -let _ = s.get("a").is_none(); -//~^ unnecessary_get_then_check + let _ = s.get("a").is_some(); + //~^ unnecessary_get_then_check + let _ = s.get("a").is_none(); + //~^ unnecessary_get_then_check // Import to check that the generic annotations are kept! let s: HashSet = HashSet::new(); -let _ = s.get::("a").is_some(); -//~^ unnecessary_get_then_check -let _ = s.get::("a").is_none(); -//~^ unnecessary_get_then_check + let _ = s.get::("a").is_some(); + //~^ unnecessary_get_then_check + let _ = s.get::("a").is_none(); + //~^ unnecessary_get_then_check } diff --git a/tests/ui/unnecessary_get_then_check.stderr b/tests/ui/unnecessary_get_then_check.stderr index a33409b30c80..5ecb3d4e29dd 100644 --- a/tests/ui/unnecessary_get_then_check.stderr +++ b/tests/ui/unnecessary_get_then_check.stderr @@ -1,75 +1,75 @@ error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:7:11 + --> tests/ui/unnecessary_get_then_check.rs:7:15 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` | = note: `-D clippy::unnecessary-get-then-check` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_get_then_check)]` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:9:11 + --> tests/ui/unnecessary_get_then_check.rs:9:15 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:13:11 + --> tests/ui/unnecessary_get_then_check.rs:13:15 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:15:11 + --> tests/ui/unnecessary_get_then_check.rs:15:15 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains_key("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains_key("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:19:11 + --> tests/ui/unnecessary_get_then_check.rs:19:15 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:21:11 + --> tests/ui/unnecessary_get_then_check.rs:21:15 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains("a")` error: unnecessary use of `get("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:25:11 + --> tests/ui/unnecessary_get_then_check.rs:25:15 | -LL | let _ = s.get("a").is_some(); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` +LL | let _ = s.get("a").is_some(); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `contains_key("a")` error: unnecessary use of `get("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:27:11 + --> tests/ui/unnecessary_get_then_check.rs:27:15 | -LL | let _ = s.get("a").is_none(); - | --^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains_key("a")` +LL | let _ = s.get("a").is_none(); + | --^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains_key("a")` error: unnecessary use of `get::("a").is_some()` - --> tests/ui/unnecessary_get_then_check.rs:32:11 + --> tests/ui/unnecessary_get_then_check.rs:32:15 | -LL | let _ = s.get::("a").is_some(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains::("a")` +LL | let _ = s.get::("a").is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `contains::("a")` error: unnecessary use of `get::("a").is_none()` - --> tests/ui/unnecessary_get_then_check.rs:34:11 + --> tests/ui/unnecessary_get_then_check.rs:34:15 | -LL | let _ = s.get::("a").is_none(); - | --^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: replace it with: `!s.contains::("a")` +LL | let _ = s.get::("a").is_none(); + | --^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | help: replace it with: `!s.contains::("a")` error: aborting due to 10 previous errors diff --git a/tests/ui/unnecessary_iter_cloned.fixed b/tests/ui/unnecessary_iter_cloned.fixed index 533059d91fce..aed2dbe1f1ce 100644 --- a/tests/ui/unnecessary_iter_cloned.fixed +++ b/tests/ui/unnecessary_iter_cloned.fixed @@ -29,7 +29,7 @@ fn main() { // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { for (t, path) in files { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let other = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -45,7 +45,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { for (t, path) in files.iter() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let other = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -177,7 +177,7 @@ mod issue_12821 { fn foo() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned println!("{c}"); // should not suggest to remove `&` } @@ -186,9 +186,9 @@ mod issue_12821 { fn bar() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned -let ref_c = c; + let ref_c = c; println!("{ref_c}"); } } @@ -196,9 +196,9 @@ let ref_c = c; fn baz() { let v: Vec<_> = "hello".chars().enumerate().collect(); for (i, c) in v.iter() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned -let ref_c = c; + let ref_c = c; let ref_i = i; println!("{i} {ref_c}"); // should not suggest to remove `&` from `i` } diff --git a/tests/ui/unnecessary_iter_cloned.rs b/tests/ui/unnecessary_iter_cloned.rs index 5e0c2e6d78ec..12fdd150e423 100644 --- a/tests/ui/unnecessary_iter_cloned.rs +++ b/tests/ui/unnecessary_iter_cloned.rs @@ -29,7 +29,7 @@ fn main() { // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { for (t, path) in files.iter().copied() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let other = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -45,7 +45,7 @@ fn check_files(files: &[(FileType, &std::path::Path)]) -> bool { fn check_files_vec(files: Vec<(FileType, &std::path::Path)>) -> bool { for (t, path) in files.iter().copied() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let other = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -177,7 +177,7 @@ mod issue_12821 { fn foo() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter().cloned() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned println!("{c}"); // should not suggest to remove `&` } @@ -186,9 +186,9 @@ mod issue_12821 { fn bar() { let v: Vec<_> = "hello".chars().collect(); for c in v.iter().cloned() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned -let ref_c = &c; + let ref_c = &c; println!("{ref_c}"); } } @@ -196,9 +196,9 @@ let ref_c = &c; fn baz() { let v: Vec<_> = "hello".chars().enumerate().collect(); for (i, c) in v.iter().cloned() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned -let ref_c = &c; + let ref_c = &c; let ref_i = &i; println!("{i} {ref_c}"); // should not suggest to remove `&` from `i` } diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index 61ae9acc35cc..632c8f371106 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -43,7 +43,7 @@ help: remove any references to the binding LL ~ for c in v.iter() { LL | LL | -LL ~ let ref_c = c; +LL ~ let ref_c = c; | error: unnecessary use of `cloned` @@ -57,7 +57,7 @@ help: remove any references to the binding LL ~ for (i, c) in v.iter() { LL | LL | -LL ~ let ref_c = c; +LL ~ let ref_c = c; LL ~ let ref_i = i; | diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index 54a2d4cee36f..6d28d544dfe0 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -13,7 +13,6 @@ fn main() { let _ = Ok(1).unwrap_or_else(|()| 2); //~^ unnecessary_lazy_evaluations - mod e { pub struct E; } @@ -23,7 +22,6 @@ fn main() { let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); //~^ unnecessary_lazy_evaluations - // Fix #6343 let arr = [(Some(1),)]; Some(&0).and_then(|&i| arr[i].0); diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 11eecdf6fa4a..0a62b312f71c 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -12,7 +12,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:20:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:19:13 | LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:23:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:22:13 | LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = Ok(1).unwrap_or(2); | ~~~~~~~~~~~~ error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval_unfixable.rs:34:13 + --> tests/ui/unnecessary_lazy_eval_unfixable.rs:32:13 | LL | let _ = true.then(|| -> &[u8] { &[] }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_literal_bound.fixed b/tests/ui/unnecessary_literal_bound.fixed index 5ac38a5b76ae..ec0d2db154ce 100644 --- a/tests/ui/unnecessary_literal_bound.fixed +++ b/tests/ui/unnecessary_literal_bound.fixed @@ -7,7 +7,7 @@ struct Struct<'a> { impl Struct<'_> { // Should warn fn returns_lit(&self) -> &'static str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound "Hello" } @@ -28,7 +28,7 @@ impl Struct<'_> { // Should warn fn contionally_returns_literals_explicit(&self, cond: bool) -> &'static str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound if cond { return "Literal"; } @@ -53,7 +53,7 @@ trait ReturnsStr { impl ReturnsStr for u8 { // Should warn, even though not useful without trait refinement fn trait_method(&self) -> &'static str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound "Literal" } } diff --git a/tests/ui/unnecessary_literal_bound.rs b/tests/ui/unnecessary_literal_bound.rs index 487ca04c6ab3..713dee4d30a6 100644 --- a/tests/ui/unnecessary_literal_bound.rs +++ b/tests/ui/unnecessary_literal_bound.rs @@ -7,7 +7,7 @@ struct Struct<'a> { impl Struct<'_> { // Should warn fn returns_lit(&self) -> &str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound "Hello" } @@ -28,7 +28,7 @@ impl Struct<'_> { // Should warn fn contionally_returns_literals_explicit(&self, cond: bool) -> &str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound if cond { return "Literal"; } @@ -53,7 +53,7 @@ trait ReturnsStr { impl ReturnsStr for u8 { // Should warn, even though not useful without trait refinement fn trait_method(&self) -> &str { - //~^ unnecessary_literal_bound + //~^ unnecessary_literal_bound "Literal" } } diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 4bb93fc391e6..b6cba4e6a568 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -9,7 +9,6 @@ fn unwrap_option_some() { let _val2 = val.expect("this never happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_option_some_context() { @@ -19,14 +18,12 @@ fn unwrap_option_some_context() { let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); //~^ unnecessary_literal_unwrap - let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); //~^ unnecessary_literal_unwrap let _val2 = val.expect("this never happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_option_none() { @@ -42,7 +39,6 @@ fn unwrap_option_none() { None::<()>.unwrap_or_default(); //~^ unnecessary_literal_unwrap - } fn unwrap_result_ok() { @@ -58,7 +54,6 @@ fn unwrap_result_ok() { let _val2 = val.expect_err("this always happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_result_ok_context() { @@ -74,7 +69,6 @@ fn unwrap_result_ok_context() { let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); //~^ unnecessary_literal_unwrap - let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); //~^ unnecessary_literal_unwrap @@ -87,7 +81,6 @@ fn unwrap_result_ok_context() { let _val2 = val.expect_err("this always happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_result_err() { @@ -103,7 +96,6 @@ fn unwrap_result_err() { let _val2 = val.expect("this always happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_result_err_context() { @@ -119,7 +111,6 @@ fn unwrap_result_err_context() { let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); //~^ unnecessary_literal_unwrap - let val = Err::<(), usize>([1, 2, 3].iter().sum()); let _val2 = val.unwrap_err(); //~^ unnecessary_literal_unwrap @@ -132,7 +123,6 @@ fn unwrap_result_err_context() { let _val2 = val.expect("this always happens"); //~^ unnecessary_literal_unwrap - } fn unwrap_methods_option() { @@ -145,7 +135,6 @@ fn unwrap_methods_option() { let _val2 = val.unwrap_or_else(|| 2); //~^ unnecessary_literal_unwrap - } fn unwrap_methods_option_context() { @@ -158,7 +147,6 @@ fn unwrap_methods_option_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); //~^ unnecessary_literal_unwrap - let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); //~^ unnecessary_literal_unwrap @@ -168,7 +156,6 @@ fn unwrap_methods_option_context() { let _val2 = val.unwrap_or_else(|| 2); //~^ unnecessary_literal_unwrap - } fn unwrap_methods_result() { @@ -181,7 +168,6 @@ fn unwrap_methods_result() { let _val2 = val.unwrap_or_else(|_| 2); //~^ unnecessary_literal_unwrap - } fn unwrap_methods_result_context() { @@ -194,7 +180,6 @@ fn unwrap_methods_result_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); //~^ unnecessary_literal_unwrap - let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); //~^ unnecessary_literal_unwrap @@ -204,7 +189,6 @@ fn unwrap_methods_result_context() { let _val2 = val.unwrap_or_else(|_| 2); //~^ unnecessary_literal_unwrap - } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index b579bb74ef74..4994eeded776 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -25,589 +25,589 @@ LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:16:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:19:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:24:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:23:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:27:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:25:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:23:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:31:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:33:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:37:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:33:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:40:21 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:37: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 - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:43:5 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:40:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:50:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:46:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:53:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:56:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:52:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:59:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:55:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:74:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:74:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:82:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:85:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:82:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:95:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:98:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:101:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:104:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:97:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:116:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:116:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:119:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:124:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:127:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:130:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:121:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:124:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:140:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:130:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:143:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:136:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:139:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:152:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:152:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:155:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:155:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:158:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:158:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:163:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:151:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:169:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:157:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:176:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:163:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:179:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:182:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:169:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:175:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:188:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:188:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:191:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:191:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:194:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:194:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:199:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:184:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:202:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:205:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:190:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:198:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_map_or.fixed b/tests/ui/unnecessary_map_or.fixed index f51da49edabb..01646faea4b6 100644 --- a/tests/ui/unnecessary_map_or.fixed +++ b/tests/ui/unnecessary_map_or.fixed @@ -16,7 +16,7 @@ fn main() { //~^ unnecessary_map_or let _ = Some(5) == Some(5); let _ = Some(5).is_some_and(|n| { - //~^ unnecessary_map_or + //~^ unnecessary_map_or let _ = n; 6 >= 5 }); diff --git a/tests/ui/unnecessary_map_or.rs b/tests/ui/unnecessary_map_or.rs index a1ae97af2b9f..10669f2a7f1a 100644 --- a/tests/ui/unnecessary_map_or.rs +++ b/tests/ui/unnecessary_map_or.rs @@ -15,12 +15,12 @@ fn main() { let _ = Some(5).map_or(true, |n| n != 5); //~^ unnecessary_map_or let _ = Some(5).map_or(false, |n| { - //~^ unnecessary_map_or + //~^ unnecessary_map_or let _ = 1; n == 5 }); let _ = Some(5).map_or(false, |n| { - //~^ unnecessary_map_or + //~^ unnecessary_map_or let _ = n; 6 >= 5 }); diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index ec3e64e15b85..05dfb72f48d2 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -142,5 +142,4 @@ const _: () = { const fn foo() { assert!([42, 55].len() > get_usize()); //~^ unnecessary_operation - } diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index 3f903cd04ef8..6ef74c3eb1c1 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -102,11 +102,11 @@ fn main() { [42; 55][get_usize()]; //~^ unnecessary_operation { - //~^ unnecessary_operation + //~^ unnecessary_operation get_number() }; FooString { - //~^ unnecessary_operation + //~^ unnecessary_operation s: String::from("blah"), }; @@ -148,5 +148,4 @@ const _: () = { const fn foo() { [42, 55][get_usize()]; //~^ unnecessary_operation - } diff --git a/tests/ui/unnecessary_result_map_or_else.fixed b/tests/ui/unnecessary_result_map_or_else.fixed index 784a42a04ba8..5d7e3fa355fd 100644 --- a/tests/ui/unnecessary_result_map_or_else.fixed +++ b/tests/ui/unnecessary_result_map_or_else.fixed @@ -3,19 +3,19 @@ fn main() { let x: Result<(), ()> = Ok(()); -x.unwrap_or_else(|err| err); -//~^ unnecessary_result_map_or_else + x.unwrap_or_else(|err| err); + //~^ unnecessary_result_map_or_else // Type ascribtion. let x: Result<(), ()> = Ok(()); -x.unwrap_or_else(|err: ()| err); -//~^ unnecessary_result_map_or_else + x.unwrap_or_else(|err: ()| err); + //~^ unnecessary_result_map_or_else // Auto-deref. let y = String::new(); let x: Result<&String, &String> = Ok(&y); -let y: &str = x.unwrap_or_else(|err| err); -//~^ unnecessary_result_map_or_else + let y: &str = x.unwrap_or_else(|err| err); + //~^ unnecessary_result_map_or_else // Temporary variable. let x: Result<(), ()> = Ok(()); diff --git a/tests/ui/unnecessary_result_map_or_else.rs b/tests/ui/unnecessary_result_map_or_else.rs index 39b15f6d26d0..d2bab0f9d9c1 100644 --- a/tests/ui/unnecessary_result_map_or_else.rs +++ b/tests/ui/unnecessary_result_map_or_else.rs @@ -3,25 +3,24 @@ fn main() { let x: Result<(), ()> = Ok(()); -x.map_or_else(|err| err, |n| n); -//~^ unnecessary_result_map_or_else + x.map_or_else(|err| err, |n| n); + //~^ unnecessary_result_map_or_else // Type ascribtion. let x: Result<(), ()> = Ok(()); -x.map_or_else(|err: ()| err, |n: ()| n); -//~^ unnecessary_result_map_or_else + x.map_or_else(|err: ()| err, |n: ()| n); + //~^ unnecessary_result_map_or_else // Auto-deref. let y = String::new(); let x: Result<&String, &String> = Ok(&y); -let y: &str = x.map_or_else(|err| err, |n| n); -//~^ unnecessary_result_map_or_else + let y: &str = x.map_or_else(|err| err, |n| n); + //~^ unnecessary_result_map_or_else // Temporary variable. let x: Result<(), ()> = Ok(()); x.map_or_else( - //~^ unnecessary_result_map_or_else - + //~^ unnecessary_result_map_or_else |err| err, |n| { let tmp = n; diff --git a/tests/ui/unnecessary_result_map_or_else.stderr b/tests/ui/unnecessary_result_map_or_else.stderr index 6334fe5eca68..e6afa50217cc 100644 --- a/tests/ui/unnecessary_result_map_or_else.stderr +++ b/tests/ui/unnecessary_result_map_or_else.stderr @@ -1,31 +1,31 @@ error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:6:1 + --> tests/ui/unnecessary_result_map_or_else.rs:6:5 | -LL | x.map_or_else(|err| err, |n| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` +LL | x.map_or_else(|err| err, |n| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` | = note: `-D clippy::unnecessary-result-map-or-else` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_result_map_or_else)]` error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:11:1 + --> tests/ui/unnecessary_result_map_or_else.rs:11:5 | -LL | x.map_or_else(|err: ()| err, |n: ()| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err: ()| err)` +LL | x.map_or_else(|err: ()| err, |n: ()| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err: ()| err)` error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:17:15 + --> tests/ui/unnecessary_result_map_or_else.rs:17:19 | -LL | let y: &str = x.map_or_else(|err| err, |n| n); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` +LL | let y: &str = x.map_or_else(|err| err, |n| n); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)` error: unused "map closure" when calling `Result::map_or_else` value --> tests/ui/unnecessary_result_map_or_else.rs:22:5 | LL | / x.map_or_else( LL | | -LL | | LL | | |err| err, +LL | | |n| { ... | LL | | }, LL | | ); diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index 3bdeda2724c6..4440089b3633 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -21,7 +21,6 @@ mod unsafe_items_invalid_comment { // SAFETY: mod module {} //~^ unnecessary_safety_comment - } mod unnecessary_from_macro { @@ -53,16 +52,13 @@ fn unnecessary_on_stmt_and_expr() -> u32 { let num = 42; //~^ unnecessary_safety_comment - // SAFETY: unnecessary if num > 24 {} //~^ unnecessary_safety_comment - // SAFETY: unnecessary 24 //~^ unnecessary_safety_comment - } mod issue_10084 { diff --git a/tests/ui/unnecessary_safety_comment.stderr b/tests/ui/unnecessary_safety_comment.stderr index 3f9e35b095b9..b56e8b354931 100644 --- a/tests/ui/unnecessary_safety_comment.stderr +++ b/tests/ui/unnecessary_safety_comment.stderr @@ -61,7 +61,7 @@ LL | // SAFETY: | ^^^^^^^^^^ error: impl has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:43:13 + --> tests/ui/unnecessary_safety_comment.rs:42:13 | LL | impl T for $t {} | ^^^^^^^^^^^^^^^^ @@ -70,44 +70,44 @@ LL | with_safety_comment!(i32); | ------------------------- in this macro invocation | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:42:13 + --> tests/ui/unnecessary_safety_comment.rs:41: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 - --> tests/ui/unnecessary_safety_comment.rs:63:5 + --> tests/ui/unnecessary_safety_comment.rs:60:5 | LL | 24 | ^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:62:5 + --> tests/ui/unnecessary_safety_comment.rs:59:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:53:5 + --> tests/ui/unnecessary_safety_comment.rs:52:5 | LL | let num = 42; | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:52:5 + --> tests/ui/unnecessary_safety_comment.rs:51:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> tests/ui/unnecessary_safety_comment.rs:58:5 + --> tests/ui/unnecessary_safety_comment.rs:56:5 | LL | if num > 24 {} | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui/unnecessary_safety_comment.rs:57:5 + --> tests/ui/unnecessary_safety_comment.rs:55:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_semicolon.edition2021.fixed b/tests/ui/unnecessary_semicolon.edition2021.fixed index 1dcc6484a195..f10d804c8ccc 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.fixed +++ b/tests/ui/unnecessary_semicolon.edition2021.fixed @@ -29,13 +29,11 @@ fn main() { } //~^ unnecessary_semicolon - a.match { 3 => println!("three"), _ => println!("not three"), } //~^ unnecessary_semicolon - } // This is a problem in edition 2021 and below diff --git a/tests/ui/unnecessary_semicolon.edition2021.stderr b/tests/ui/unnecessary_semicolon.edition2021.stderr index 3299442a5c1d..a3b139f73805 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.stderr +++ b/tests/ui/unnecessary_semicolon.edition2021.stderr @@ -8,13 +8,13 @@ LL | }; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]` error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:36:6 + --> tests/ui/unnecessary_semicolon.rs:35:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:59:6 + --> tests/ui/unnecessary_semicolon.rs:57:6 | LL | }; | ^ help: remove diff --git a/tests/ui/unnecessary_semicolon.edition2024.fixed b/tests/ui/unnecessary_semicolon.edition2024.fixed index 91eef8022ed2..32a3bb9b4081 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.fixed +++ b/tests/ui/unnecessary_semicolon.edition2024.fixed @@ -29,13 +29,11 @@ fn main() { } //~^ unnecessary_semicolon - a.match { 3 => println!("three"), _ => println!("not three"), } //~^ unnecessary_semicolon - } // This is a problem in edition 2021 and below diff --git a/tests/ui/unnecessary_semicolon.edition2024.stderr b/tests/ui/unnecessary_semicolon.edition2024.stderr index 98adc2f0a0a2..d5ccae7fdf58 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.stderr +++ b/tests/ui/unnecessary_semicolon.edition2024.stderr @@ -8,19 +8,19 @@ LL | }; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]` error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:36:6 + --> tests/ui/unnecessary_semicolon.rs:35:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:49:6 + --> tests/ui/unnecessary_semicolon.rs:47:6 | LL | }; | ^ help: remove error: unnecessary semicolon - --> tests/ui/unnecessary_semicolon.rs:59:6 + --> tests/ui/unnecessary_semicolon.rs:57:6 | LL | }; | ^ help: remove diff --git a/tests/ui/unnecessary_semicolon.rs b/tests/ui/unnecessary_semicolon.rs index 6c48bfae14ce..91b282180224 100644 --- a/tests/ui/unnecessary_semicolon.rs +++ b/tests/ui/unnecessary_semicolon.rs @@ -29,13 +29,11 @@ fn main() { }; //~^ unnecessary_semicolon - a.match { 3 => println!("three"), _ => println!("not three"), }; //~^ unnecessary_semicolon - } // This is a problem in edition 2021 and below diff --git a/tests/ui/unnecessary_struct_initialization.rs b/tests/ui/unnecessary_struct_initialization.rs index 2b26bc413b8f..12a444fc878b 100644 --- a/tests/ui/unnecessary_struct_initialization.rs +++ b/tests/ui/unnecessary_struct_initialization.rs @@ -60,7 +60,7 @@ fn main() { // Should lint: the result of an expression is mutable let h = &mut S { - //~^ unnecessary_struct_initialization + //~^ unnecessary_struct_initialization ..*Box::new(S { f: String::from("foo") }) }; @@ -80,7 +80,7 @@ fn main() { // Should lint: the result of an expression is mutable and temporary let p = &mut T { - //~^ unnecessary_struct_initialization + //~^ unnecessary_struct_initialization ..*Box::new(T { f: 5 }) }; diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index a03bfb2eafe3..136dafda27ea 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -296,7 +296,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { for t in file_types { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let path = match get_file_path(t) { Ok(p) => p, Err(_) => { @@ -639,23 +639,23 @@ fn borrow_checks() { fn inner(a: &[&str]) { let mut s = HashSet::from([vec!["a"]]); -s.remove(a); -//~^ unnecessary_to_owned + s.remove(a); + //~^ unnecessary_to_owned } let mut s = HashSet::from(["a".to_string()]); -s.remove("b"); -//~^ unnecessary_to_owned -s.remove("b"); -//~^ unnecessary_to_owned + s.remove("b"); + //~^ unnecessary_to_owned + s.remove("b"); + //~^ unnecessary_to_owned // Should not warn. s.remove("b"); let mut s = HashSet::from([vec!["a"]]); -s.remove(["b"].as_slice()); -//~^ unnecessary_to_owned -s.remove((&["b"]).as_slice()); -//~^ unnecessary_to_owned + s.remove(["b"].as_slice()); + //~^ unnecessary_to_owned + s.remove((&["b"]).as_slice()); + //~^ unnecessary_to_owned // Should not warn. s.remove(&["b"].to_vec().clone()); diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs index a03b13d47565..0948ac5de3ef 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -296,7 +296,7 @@ fn require_as_ref_slice_str, V: AsRef>(_: U, _: V) {} // https://github.com/breard-r/acmed/blob/1f0dcc32aadbc5e52de6d23b9703554c0f925113/acmed/src/storage.rs#L262 fn check_files(file_types: &[FileType]) -> bool { for t in file_types.to_vec() { - //~^ unnecessary_to_owned + //~^ unnecessary_to_owned let path = match get_file_path(&t) { Ok(p) => p, Err(_) => { @@ -639,23 +639,23 @@ fn borrow_checks() { fn inner(a: &[&str]) { let mut s = HashSet::from([vec!["a"]]); -s.remove(&a.to_vec()); -//~^ unnecessary_to_owned + s.remove(&a.to_vec()); + //~^ unnecessary_to_owned } let mut s = HashSet::from(["a".to_string()]); -s.remove(&"b".to_owned()); -//~^ unnecessary_to_owned -s.remove(&"b".to_string()); -//~^ unnecessary_to_owned + s.remove(&"b".to_owned()); + //~^ unnecessary_to_owned + s.remove(&"b".to_string()); + //~^ unnecessary_to_owned // Should not warn. s.remove("b"); let mut s = HashSet::from([vec!["a"]]); -s.remove(&["b"].to_vec()); -//~^ unnecessary_to_owned -s.remove(&(&["b"]).to_vec()); -//~^ unnecessary_to_owned + s.remove(&["b"].to_vec()); + //~^ unnecessary_to_owned + s.remove(&(&["b"]).to_vec()); + //~^ unnecessary_to_owned // Should not warn. s.remove(&["b"].to_vec().clone()); diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 23963fd6779a..f8ad85dbed02 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -557,34 +557,34 @@ LL | IntoFuture::into_future(foo([].to_vec(), &0)); | ^^^^^^^^^^^ help: use: `[]` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:642:10 + --> tests/ui/unnecessary_to_owned.rs:642:18 | -LL | s.remove(&a.to_vec()); - | ^^^^^^^^^^^ help: replace it with: `a` +LL | s.remove(&a.to_vec()); + | ^^^^^^^^^^^ help: replace it with: `a` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:647:10 + --> tests/ui/unnecessary_to_owned.rs:647:14 | -LL | s.remove(&"b".to_owned()); - | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` +LL | s.remove(&"b".to_owned()); + | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:649:10 + --> tests/ui/unnecessary_to_owned.rs:649:14 | -LL | s.remove(&"b".to_string()); - | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` +LL | s.remove(&"b".to_string()); + | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:655:10 + --> tests/ui/unnecessary_to_owned.rs:655:14 | -LL | s.remove(&["b"].to_vec()); - | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` +LL | s.remove(&["b"].to_vec()); + | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:657:10 + --> tests/ui/unnecessary_to_owned.rs:657:14 | -LL | s.remove(&(&["b"]).to_vec()); - | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` +LL | s.remove(&(&["b"]).to_vec()); + | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` error: aborting due to 88 previous errors diff --git a/tests/ui/unnecessary_to_owned_on_split.fixed b/tests/ui/unnecessary_to_owned_on_split.fixed index be453758ff3a..f43d92a2d9ba 100644 --- a/tests/ui/unnecessary_to_owned_on_split.fixed +++ b/tests/ui/unnecessary_to_owned_on_split.fixed @@ -31,7 +31,6 @@ fn main() { let _ = Issue12068.as_ref().split('a').next().unwrap(); //~^ unnecessary_to_owned - let _ = [1].split(|x| *x == 2).next().unwrap(); //~^ unnecessary_to_owned @@ -43,5 +42,4 @@ fn main() { let _ = [1].split(|x| *x == 2).next().unwrap(); //~^ unnecessary_to_owned - } diff --git a/tests/ui/unnecessary_to_owned_on_split.rs b/tests/ui/unnecessary_to_owned_on_split.rs index b6317db80d7c..bdf5f98bf61e 100644 --- a/tests/ui/unnecessary_to_owned_on_split.rs +++ b/tests/ui/unnecessary_to_owned_on_split.rs @@ -31,7 +31,6 @@ fn main() { let _ = Issue12068.to_string().split('a').next().unwrap(); //~^ unnecessary_to_owned - let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); //~^ unnecessary_to_owned @@ -43,5 +42,4 @@ fn main() { let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); //~^ unnecessary_to_owned - } diff --git a/tests/ui/unnecessary_to_owned_on_split.stderr b/tests/ui/unnecessary_to_owned_on_split.stderr index 32cf52381d83..5e4fbb1035d6 100644 --- a/tests/ui/unnecessary_to_owned_on_split.stderr +++ b/tests/ui/unnecessary_to_owned_on_split.stderr @@ -32,25 +32,25 @@ LL | let _ = Issue12068.to_string().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Issue12068.as_ref().split('a')` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:35:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:34:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:38:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:37:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:41:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:40:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:44:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:43:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 2fe6c2b23a66..7a847d2e3b50 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -17,7 +17,7 @@ pub fn destroy_the_planet() { /// /// This function shouldn't be called unless the horsemen are ready pub fn apocalypse(universe: &mut ()) { -//~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc unimplemented!(); } @@ -44,7 +44,7 @@ mod private_mod { /// /// Unnecessary safety! pub fn republished() { - //~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc unimplemented!(); } } @@ -69,7 +69,7 @@ pub trait SafeTrait { /// /// Unnecessary! pub trait DocumentedSafeTrait { -//~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc fn method2(); } @@ -98,7 +98,7 @@ impl Struct { /// /// Unnecessary! pub fn documented() -> Self { - //~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc unimplemented!(); } @@ -126,7 +126,7 @@ macro_rules! very_safe { /// /// Driving is very safe already! pub fn drive() { - //~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc whee() } }; @@ -155,6 +155,6 @@ pub mod __macro { /// # Implementation safety pub trait DocumentedSafeTraitWithImplementationHeader { -//~^ unnecessary_safety_doc + //~^ unnecessary_safety_doc fn method(); } diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index dee51ef67c3d..4770ef3b4830 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -7,8 +7,7 @@ // should be linted fn func1(a: bool, b: bool) -> Option { -//~^ unnecessary_wraps - + //~^ unnecessary_wraps if a && b { return Some(42); @@ -23,7 +22,7 @@ fn func1(a: bool, b: bool) -> Option { // should be linted fn func2(a: bool, b: bool) -> Option { -//~^ unnecessary_wraps + //~^ unnecessary_wraps if a && b { return Some(10); @@ -43,7 +42,7 @@ fn func4(a: bool) -> Option { // should be linted fn func5() -> Option { -//~^ unnecessary_wraps + //~^ unnecessary_wraps Some(1) } @@ -55,7 +54,7 @@ fn func6() -> Option { // should be linted fn func7() -> Result { -//~^ unnecessary_wraps + //~^ unnecessary_wraps Ok(1) } @@ -85,7 +84,7 @@ impl A { // should be linted fn func12() -> Option { - //~^ unnecessary_wraps + //~^ unnecessary_wraps Some(1) } @@ -114,7 +113,7 @@ fn issue_6384(s: &str) -> Option<&str> { // should be linted fn issue_6640_1(a: bool, b: bool) -> Option<()> { -//~^ unnecessary_wraps + //~^ unnecessary_wraps if a && b { return Some(()); @@ -129,7 +128,7 @@ fn issue_6640_1(a: bool, b: bool) -> Option<()> { // should be linted fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { -//~^ unnecessary_wraps + //~^ unnecessary_wraps if a && b { return Ok(()); diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index c193c4cf91ad..53fd8bd44146 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -2,6 +2,9 @@ error: this function's return value is unnecessarily wrapped by `Option` --> tests/ui/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { +LL | | +LL | | +LL | | if a && b { ... | LL | | } | |_^ @@ -24,7 +27,7 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:25:1 + --> tests/ui/unnecessary_wraps.rs:24:1 | LL | / fn func2(a: bool, b: bool) -> Option { LL | | @@ -47,7 +50,7 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:45:1 + --> tests/ui/unnecessary_wraps.rs:44:1 | LL | / fn func5() -> Option { LL | | @@ -66,7 +69,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> tests/ui/unnecessary_wraps.rs:57:1 + --> tests/ui/unnecessary_wraps.rs:56:1 | LL | / fn func7() -> Result { LL | | @@ -85,7 +88,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:87:5 + --> tests/ui/unnecessary_wraps.rs:86:5 | LL | / fn func12() -> Option { LL | | @@ -104,7 +107,7 @@ LL | 1 | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:116:1 + --> tests/ui/unnecessary_wraps.rs:115:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { LL | | @@ -130,7 +133,7 @@ LL ~ return ; | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:131:1 + --> tests/ui/unnecessary_wraps.rs:130:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { LL | | diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index e4f6a704024b..327b64e7c4aa 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -17,7 +17,6 @@ fn main() { match f { Foo { a: _, b: 0, .. } => {}, //~^ unneeded_field_pattern - Foo { a: _, b: _, c: _ } => {}, //~^ unneeded_field_pattern } diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr index 27e10f129dd6..4ea33a5db9e2 100644 --- a/tests/ui/unneeded_field_pattern.stderr +++ b/tests/ui/unneeded_field_pattern.stderr @@ -9,7 +9,7 @@ LL | Foo { a: _, b: 0, .. } => {}, = help: to override `-D warnings` add `#[allow(clippy::unneeded_field_pattern)]` error: all the struct fields are matched to a wildcard pattern, consider using `..` - --> tests/ui/unneeded_field_pattern.rs:21:9 + --> tests/ui/unneeded_field_pattern.rs:20:9 | LL | Foo { a: _, b: _, c: _ } => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unneeded_struct_pattern.fixed b/tests/ui/unneeded_struct_pattern.fixed index 3f24094ff316..1fcaa29c51f0 100644 --- a/tests/ui/unneeded_struct_pattern.fixed +++ b/tests/ui/unneeded_struct_pattern.fixed @@ -89,24 +89,24 @@ fn main() { noop(); } if let Custom::NoBrackets = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets | Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ unneeded_struct_pattern - //~| unneeded_struct_pattern + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } @@ -123,23 +123,21 @@ fn main() { }; let Custom::NoBrackets = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; enum Refutable { Variant, } - - } fn external_crate() { diff --git a/tests/ui/unneeded_struct_pattern.rs b/tests/ui/unneeded_struct_pattern.rs index 0e6ae5124822..e51311afd5f8 100644 --- a/tests/ui/unneeded_struct_pattern.rs +++ b/tests/ui/unneeded_struct_pattern.rs @@ -80,7 +80,7 @@ fn main() { //~^^^ match_single_binding match Custom::Init { - //~^ match_single_binding + //~^ match_single_binding _ => 0, }; @@ -94,24 +94,24 @@ fn main() { noop(); } if let Custom::NoBrackets {} = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets { .. } = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { - //~^ unneeded_struct_pattern - //~| unneeded_struct_pattern + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive {} = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } if let Custom::NoBracketsNonExhaustive { .. } = Custom::Init { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern noop(); } @@ -128,23 +128,21 @@ fn main() { }; let Custom::NoBrackets { .. } = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive {} = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { - //~^ unneeded_struct_pattern + //~^ unneeded_struct_pattern panic!() }; enum Refutable { Variant, } - - } fn external_crate() { @@ -157,13 +155,13 @@ fn external_crate() { }; match ExhaustiveUnit { - //~^ match_single_binding + //~^ match_single_binding // Exhaustive variant _ => 0, }; match ExhaustiveUnit { - //~^ match_single_binding + //~^ match_single_binding // Exhaustive variant _ => 0, }; diff --git a/tests/ui/unneeded_struct_pattern.stderr b/tests/ui/unneeded_struct_pattern.stderr index 9fd698ebf861..5630795823c4 100644 --- a/tests/ui/unneeded_struct_pattern.stderr +++ b/tests/ui/unneeded_struct_pattern.stderr @@ -136,7 +136,7 @@ LL | let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:159:5 + --> tests/ui/unneeded_struct_pattern.rs:157:5 | LL | / match ExhaustiveUnit { LL | | @@ -146,7 +146,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `0` error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:165:5 + --> tests/ui/unneeded_struct_pattern.rs:163:5 | LL | / match ExhaustiveUnit { LL | | diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index 124206e8e353..2e1d8b60a0e2 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -5,12 +5,9 @@ use std::cell::UnsafeCell as TotallySafeCell; //~^ unsafe_removed_from_name - - use std::cell::UnsafeCell as TotallySafeCellAgain; //~^ unsafe_removed_from_name - // Shouldn't error use std::cell::RefCell as ProbablyNotUnsafe; @@ -30,14 +27,11 @@ mod mod_with_some_unsafe_things { use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; //~^ unsafe_removed_from_name - // merged imports use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; //~^ unsafe_removed_from_name //~| unsafe_removed_from_name - - // 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 899d438ea76b..5268c16ec9ba 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -8,25 +8,25 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; = help: to override `-D warnings` add `#[allow(clippy::unsafe_removed_from_name)]` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> tests/ui/unsafe_removed_from_name.rs:10:1 + --> tests/ui/unsafe_removed_from_name.rs:8:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> tests/ui/unsafe_removed_from_name.rs:30:1 + --> tests/ui/unsafe_removed_from_name.rs:27:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> tests/ui/unsafe_removed_from_name.rs:35:1 + --> tests/ui/unsafe_removed_from_name.rs:31:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `B` - --> tests/ui/unsafe_removed_from_name.rs:35:1 + --> tests/ui/unsafe_removed_from_name.rs:31: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 225f09ed94e6..5aaf7b9f5b59 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -10,7 +10,7 @@ mod issue10800 { use std::future::ready; async fn async_block_await() { - //~^ unused_async + //~^ unused_async async { ready(()).await; @@ -46,7 +46,6 @@ mod issue9695 { async fn f3() {} //~^ unused_async - fn needs_async_fn>(_: fn() -> F) {} fn test() { @@ -74,7 +73,7 @@ mod issue13466 { } async fn foo() -> i32 { -//~^ unused_async + //~^ unused_async 4 } @@ -87,7 +86,7 @@ struct S; impl S { async fn unused(&self) -> i32 { - //~^ unused_async + //~^ unused_async 1 } diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 5b8d8f5097be..f95fdd865300 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -28,7 +28,7 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:76:1 + --> tests/ui/unused_async.rs:75:1 | LL | / async fn foo() -> i32 { LL | | @@ -40,7 +40,7 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:89:5 + --> tests/ui/unused_async.rs:88:5 | LL | / async fn unused(&self) -> i32 { LL | | diff --git a/tests/ui/unused_enumerate_index.fixed b/tests/ui/unused_enumerate_index.fixed index 8c713e273f4a..258e52971cea 100644 --- a/tests/ui/unused_enumerate_index.fixed +++ b/tests/ui/unused_enumerate_index.fixed @@ -10,7 +10,7 @@ fn get_enumerate() -> Enumerate> { fn main() { let v = [1, 2, 3]; for x in v.iter() { - //~^ unused_enumerate_index + //~^ unused_enumerate_index println!("{x}"); } @@ -58,7 +58,7 @@ fn main() { let dummy = Dummy3(vec![1, 2, 3].into_iter()); for x in dummy { - //~^ unused_enumerate_index + //~^ unused_enumerate_index println!("{x}"); } diff --git a/tests/ui/unused_enumerate_index.rs b/tests/ui/unused_enumerate_index.rs index 97018ee985e5..a17e3259a9b0 100644 --- a/tests/ui/unused_enumerate_index.rs +++ b/tests/ui/unused_enumerate_index.rs @@ -10,7 +10,7 @@ fn get_enumerate() -> Enumerate> { fn main() { let v = [1, 2, 3]; for (_, x) in v.iter().enumerate() { - //~^ unused_enumerate_index + //~^ unused_enumerate_index println!("{x}"); } @@ -58,7 +58,7 @@ fn main() { let dummy = Dummy3(vec![1, 2, 3].into_iter()); for (_, x) in dummy.enumerate() { - //~^ unused_enumerate_index + //~^ unused_enumerate_index println!("{x}"); } diff --git a/tests/ui/unused_format_specs.1.fixed b/tests/ui/unused_format_specs.1.fixed index 850240bab608..05bd1df9a523 100644 --- a/tests/ui/unused_format_specs.1.fixed +++ b/tests/ui/unused_format_specs.1.fixed @@ -12,20 +12,16 @@ fn main() { println!("{:5}.", format!("")); //~^ unused_format_specs - //prints `abcde`, not `abc` println!("{:.3}", format!("abcde")); //~^ unused_format_specs - println!("{}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); println!("{args}"); //~^ unused_format_specs - } fn should_not_lint() { @@ -56,15 +52,12 @@ fn should_lint_user() { usr_println!(true, "{:.3}", format!("abcde")); //~^ unused_format_specs - usr_println!(true, "{}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); usr_println!(true, "{args}"); //~^ unused_format_specs - } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.2.fixed b/tests/ui/unused_format_specs.2.fixed index f8d5f615e045..c1f3d4fa20c6 100644 --- a/tests/ui/unused_format_specs.2.fixed +++ b/tests/ui/unused_format_specs.2.fixed @@ -12,20 +12,16 @@ fn main() { println!("{}.", format_args!("")); //~^ unused_format_specs - //prints `abcde`, not `abc` println!("{}", format_args!("abcde")); //~^ unused_format_specs - println!("{}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); println!("{args}"); //~^ unused_format_specs - } fn should_not_lint() { @@ -56,15 +52,12 @@ fn should_lint_user() { usr_println!(true, "{}", format_args!("abcde")); //~^ unused_format_specs - usr_println!(true, "{}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); usr_println!(true, "{args}"); //~^ unused_format_specs - } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.rs b/tests/ui/unused_format_specs.rs index 777901258a77..b47047ba34e5 100644 --- a/tests/ui/unused_format_specs.rs +++ b/tests/ui/unused_format_specs.rs @@ -12,20 +12,16 @@ fn main() { println!("{:5}.", format_args!("")); //~^ unused_format_specs - //prints `abcde`, not `abc` println!("{:.3}", format_args!("abcde")); //~^ unused_format_specs - println!("{:5}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); println!("{args:5}"); //~^ unused_format_specs - } fn should_not_lint() { @@ -56,15 +52,12 @@ fn should_lint_user() { usr_println!(true, "{:.3}", format_args!("abcde")); //~^ unused_format_specs - usr_println!(true, "{:5}.", format_args_from_macro!()); //~^ unused_format_specs - let args = format_args!(""); usr_println!(true, "{args:5}"); //~^ unused_format_specs - } fn should_not_lint_user() { diff --git a/tests/ui/unused_format_specs.stderr b/tests/ui/unused_format_specs.stderr index a88a808afe82..704e4987ec4a 100644 --- a/tests/ui/unused_format_specs.stderr +++ b/tests/ui/unused_format_specs.stderr @@ -17,7 +17,7 @@ LL + println!("{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:17:15 + --> tests/ui/unused_format_specs.rs:16:15 | LL | println!("{:.3}", format_args!("abcde")); | ^^^^^ @@ -33,7 +33,7 @@ LL + println!("{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:21:15 + --> tests/ui/unused_format_specs.rs:19:15 | LL | println!("{:5}.", format_args_from_macro!()); | ^^^^ @@ -46,7 +46,7 @@ LL + println!("{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:26:15 + --> tests/ui/unused_format_specs.rs:23:15 | LL | println!("{args:5}"); | ^^^^^^^^ @@ -59,7 +59,7 @@ LL + println!("{args}"); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:52:25 + --> tests/ui/unused_format_specs.rs:48:25 | LL | usr_println!(true, "{:5}.", format_args!("")); | ^^^^ @@ -75,7 +75,7 @@ LL + usr_println!(true, "{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:56:25 + --> tests/ui/unused_format_specs.rs:52:25 | LL | usr_println!(true, "{:.3}", format_args!("abcde")); | ^^^^^ @@ -91,7 +91,7 @@ LL + usr_println!(true, "{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:60:25 + --> tests/ui/unused_format_specs.rs:55:25 | LL | usr_println!(true, "{:5}.", format_args_from_macro!()); | ^^^^ @@ -104,7 +104,7 @@ LL + usr_println!(true, "{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> tests/ui/unused_format_specs.rs:65:25 + --> tests/ui/unused_format_specs.rs:59:25 | LL | usr_println!(true, "{args:5}"); | ^^^^^^^^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index f0531836db1c..32a50375806a 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -66,7 +66,7 @@ fn combine_or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader - //~^ unused_io_amount + //~^ unused_io_amount .read(&mut result) .or(Err(Error::Kind)) .or(Err(Error::Kind)) @@ -146,14 +146,14 @@ async fn undetected_bad_async_write(w: &mut W) { fn match_okay_underscore(s: &mut T) { match s.write(b"test") { - //~^ unused_io_amount + //~^ unused_io_amount Ok(_) => todo!(), Err(_) => todo!(), }; let mut buf = [0u8; 4]; match s.read(&mut buf) { - //~^ unused_io_amount + //~^ unused_io_amount Ok(_) => todo!(), Err(_) => todo!(), } @@ -161,7 +161,7 @@ fn match_okay_underscore(s: &mut T) { fn match_okay_underscore_read_expr(s: &mut T) { match s.read(&mut [0u8; 4]) { - //~^ unused_io_amount + //~^ unused_io_amount Ok(_) => todo!(), Err(_) => todo!(), } @@ -169,7 +169,7 @@ fn match_okay_underscore_read_expr(s: &mut T) { fn match_okay_underscore_write_expr(s: &mut T) { match s.write(b"test") { - //~^ unused_io_amount + //~^ unused_io_amount Ok(_) => todo!(), Err(_) => todo!(), } @@ -181,21 +181,21 @@ fn returned_value_should_not_lint(s: &mut T) -> Result< fn if_okay_underscore_read_expr(s: &mut T) { if let Ok(_) = s.read(&mut [0u8; 4]) { - //~^ unused_io_amount + //~^ unused_io_amount todo!() } } fn if_okay_underscore_write_expr(s: &mut T) { if let Ok(_) = s.write(b"test") { - //~^ unused_io_amount + //~^ unused_io_amount todo!() } } fn if_okay_dots_write_expr(s: &mut T) { if let Ok(..) = s.write(b"test") { - //~^ unused_io_amount + //~^ unused_io_amount todo!() } } diff --git a/tests/ui/unused_peekable.rs b/tests/ui/unused_peekable.rs index 8382db3be005..e7fe297764eb 100644 --- a/tests/ui/unused_peekable.rs +++ b/tests/ui/unused_peekable.rs @@ -13,19 +13,16 @@ fn invalid() { let peekable = std::iter::empty::().peekable(); //~^ unused_peekable - // Only lint `new_local` let old_local = std::iter::empty::().peekable(); let new_local = old_local; //~^ unused_peekable - // Behind mut ref let mut by_mut_ref_test = std::iter::empty::().peekable(); let by_mut_ref = &mut by_mut_ref_test; //~^ unused_peekable - // Explicitly returns `Peekable` fn returns_peekable() -> Peekable> { std::iter::empty().peekable() @@ -34,7 +31,6 @@ fn invalid() { let peekable_from_fn = returns_peekable(); //~^ unused_peekable - // Using a method not exclusive to `Peekable` let mut peekable_using_iterator_method = std::iter::empty::().peekable(); //~^ unused_peekable @@ -53,7 +49,6 @@ fn invalid() { let _by_ref = by_ref_test.by_ref(); //~^ unused_peekable - let mut peekable_in_for_loop = std::iter::empty::().peekable(); //~^ unused_peekable diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index 9b49e32fa8ba..9330d8c58001 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -9,7 +9,7 @@ LL | let peekable = std::iter::empty::().peekable(); = help: to override `-D warnings` add `#[allow(clippy::unused_peekable)]` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:19:9 + --> tests/ui/unused_peekable.rs:18:9 | LL | let new_local = old_local; | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let new_local = old_local; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:25:9 + --> tests/ui/unused_peekable.rs:23:9 | LL | let by_mut_ref = &mut by_mut_ref_test; | ^^^^^^^^^^ @@ -25,7 +25,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 - --> tests/ui/unused_peekable.rs:34:9 + --> tests/ui/unused_peekable.rs:31:9 | LL | let peekable_from_fn = returns_peekable(); | ^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let peekable_from_fn = returns_peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:39:13 + --> tests/ui/unused_peekable.rs:35:13 | LL | let mut peekable_using_iterator_method = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,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 - --> tests/ui/unused_peekable.rs:46:9 + --> tests/ui/unused_peekable.rs:42:9 | LL | let passed_along_ref = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let passed_along_ref = std::iter::empty::().peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:53:9 + --> tests/ui/unused_peekable.rs:49:9 | LL | let _by_ref = by_ref_test.by_ref(); | ^^^^^^^ @@ -57,7 +57,7 @@ LL | let _by_ref = by_ref_test.by_ref(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> tests/ui/unused_peekable.rs:57:13 + --> tests/ui/unused_peekable.rs:52: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 fac0b36c33a4..cb80d946aced 100644 --- a/tests/ui/unused_self.rs +++ b/tests/ui/unused_self.rs @@ -30,12 +30,12 @@ mod unused_self { //~^ unused_self fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { - //~^ unused_self + //~^ unused_self x + y } fn unused_self_class_method(&self) { - //~^ unused_self + //~^ unused_self Self::static_method(); } diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs index 637d2da3750e..3191b396f99b 100644 --- a/tests/ui/unwrap.rs +++ b/tests/ui/unwrap.rs @@ -5,7 +5,6 @@ fn unwrap_option() { let opt = Some(0); let _ = opt.unwrap(); //~^ unwrap_used - } fn unwrap_result() { @@ -15,7 +14,6 @@ fn unwrap_result() { let _ = res.unwrap_err(); //~^ unwrap_used - } fn main() { diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index c568d8308200..c242541a6bd7 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -10,7 +10,7 @@ LL | let _ = opt.unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `unwrap()` on a `Result` value - --> tests/ui/unwrap.rs:13:13 + --> tests/ui/unwrap.rs:12:13 | LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let _ = res.unwrap(); = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value - --> tests/ui/unwrap.rs:16:13 + --> tests/ui/unwrap.rs:15:13 | LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index c2c9db775370..d0bb571273b5 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -30,7 +30,6 @@ fn main() { Some(3).expect("Hello world!"); //~^ expect_used - // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); Some(3).expect_err("Hello none!"); diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index 7476e372bcbb..79eac3f58ccb 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -19,7 +19,7 @@ LL | Some(3).expect("Hello world!"); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `unwrap()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:47:5 + --> tests/ui/unwrap_expect_used.rs:46:5 | LL | a.unwrap(); | ^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | a.unwrap(); = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:50:5 + --> tests/ui/unwrap_expect_used.rs:49:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL | a.expect("Hello world!"); = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:53:5 + --> tests/ui/unwrap_expect_used.rs:52:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | a.unwrap_err(); = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> tests/ui/unwrap_expect_used.rs:56:5 + --> tests/ui/unwrap_expect_used.rs:55:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_in_result.rs b/tests/ui/unwrap_in_result.rs index 58235d138658..4e872c67b423 100644 --- a/tests/ui/unwrap_in_result.rs +++ b/tests/ui/unwrap_in_result.rs @@ -20,7 +20,7 @@ impl A { // should be detected fn bad_divisible_by_3(i_str: String) -> Result { - //~^ unwrap_in_result + //~^ unwrap_in_result // checks whether a string represents a number divisible by 3 let i = i_str.parse::().unwrap(); @@ -32,7 +32,7 @@ impl A { } fn example_option_expect(i_str: String) -> Option { - //~^ unwrap_in_result + //~^ unwrap_in_result let i = i_str.parse::().expect("not a number"); if i % 3 == 0 { @@ -42,7 +42,7 @@ impl A { } fn in_closure(a: Option) -> Option { - //~^ unwrap_in_result + //~^ unwrap_in_result let c = || a.unwrap(); Some(c()) } diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index 7a00d346cac5..c794ed577032 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -4,12 +4,9 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); //~^ or_fun_call - - } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); //~^ or_fun_call - } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 30779ac1b109..11a6883b7403 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -4,12 +4,9 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); //~^ or_fun_call - - } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); //~^ or_fun_call - } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index b2c20a9e9b5e..e95633680acc 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -8,7 +8,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: function call inside of `unwrap_or` - --> tests/ui/unwrap_or.rs:12:47 + --> tests/ui/unwrap_or.rs:10: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 b8c10b370680..da44c8e3026e 100644 --- a/tests/ui/upper_case_acronyms.fixed +++ b/tests/ui/upper_case_acronyms.fixed @@ -8,29 +8,20 @@ enum Flags { NS, // not linted Cwr, //~^ upper_case_acronyms - - Ece, //~^ upper_case_acronyms - Urg, //~^ upper_case_acronyms - Ack, //~^ upper_case_acronyms - Psh, //~^ upper_case_acronyms - Rst, //~^ upper_case_acronyms - Syn, //~^ upper_case_acronyms - Fin, //~^ upper_case_acronyms - } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -52,7 +43,6 @@ pub enum ParseError { enum ParseErrorPrivate { Wasd(u8), //~^ upper_case_acronyms - Utf8(std::string::FromUtf8Error), Parse(T, String), } @@ -61,11 +51,9 @@ enum ParseErrorPrivate { struct Json; //~^ upper_case_acronyms - // do lint here enum Yaml { -//~^ upper_case_acronyms - + //~^ upper_case_acronyms Num(u32), Str(String), } @@ -74,7 +62,6 @@ enum Yaml { enum AllowOnField { Disallow, //~^ upper_case_acronyms - #[allow(clippy::upper_case_acronyms)] ALLOW, } diff --git a/tests/ui/upper_case_acronyms.rs b/tests/ui/upper_case_acronyms.rs index 4ad6c6d4c8c8..d223b02acda9 100644 --- a/tests/ui/upper_case_acronyms.rs +++ b/tests/ui/upper_case_acronyms.rs @@ -8,29 +8,20 @@ enum Flags { NS, // not linted CWR, //~^ upper_case_acronyms - - ECE, //~^ upper_case_acronyms - URG, //~^ upper_case_acronyms - ACK, //~^ upper_case_acronyms - PSH, //~^ upper_case_acronyms - RST, //~^ upper_case_acronyms - SYN, //~^ upper_case_acronyms - FIN, //~^ upper_case_acronyms - } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -52,7 +43,6 @@ pub enum ParseError { enum ParseErrorPrivate { WASD(u8), //~^ upper_case_acronyms - Utf8(std::string::FromUtf8Error), Parse(T, String), } @@ -61,11 +51,9 @@ enum ParseErrorPrivate { struct JSON; //~^ upper_case_acronyms - // do lint here enum YAML { -//~^ upper_case_acronyms - + //~^ upper_case_acronyms Num(u32), Str(String), } @@ -74,7 +62,6 @@ enum YAML { enum AllowOnField { DISALLOW, //~^ upper_case_acronyms - #[allow(clippy::upper_case_acronyms)] ALLOW, } diff --git a/tests/ui/upper_case_acronyms.stderr b/tests/ui/upper_case_acronyms.stderr index 24e1d808d8ed..dd548fc143e2 100644 --- a/tests/ui/upper_case_acronyms.stderr +++ b/tests/ui/upper_case_acronyms.stderr @@ -8,67 +8,67 @@ LL | CWR, = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `ECE` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:13:5 + --> tests/ui/upper_case_acronyms.rs:11:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:16:5 + --> tests/ui/upper_case_acronyms.rs:13:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:19:5 + --> tests/ui/upper_case_acronyms.rs:15:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:22:5 + --> tests/ui/upper_case_acronyms.rs:17:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:25:5 + --> tests/ui/upper_case_acronyms.rs:19:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:28:5 + --> tests/ui/upper_case_acronyms.rs:21:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:31:5 + --> tests/ui/upper_case_acronyms.rs:23:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `WASD` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:53:5 + --> tests/ui/upper_case_acronyms.rs:44:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `JSON` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:61:8 + --> tests/ui/upper_case_acronyms.rs:51:8 | LL | struct JSON; | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json` error: name `YAML` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:66:6 + --> tests/ui/upper_case_acronyms.rs:55:6 | LL | enum YAML { | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml` error: name `DISALLOW` contains a capitalized acronym - --> tests/ui/upper_case_acronyms.rs:75:5 + --> tests/ui/upper_case_acronyms.rs:63:5 | LL | DISALLOW, | ^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `Disallow` diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index faabf0e256db..f15e5e0a5bb4 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -21,12 +21,12 @@ mod use_self { impl Foo { fn new() -> Self { - //~^ use_self + //~^ use_self Self {} //~^ use_self } fn test() -> Self { - //~^ use_self + //~^ use_self Self::new() //~^ use_self } @@ -34,7 +34,7 @@ mod use_self { impl Default for Foo { fn default() -> Self { - //~^ use_self + //~^ use_self Self::new() //~^ use_self } @@ -78,7 +78,7 @@ mod lifetimes { } fn clone(&self) -> Self { - //~^ use_self + //~^ use_self Foo { foo_str: self.foo_str } } @@ -112,8 +112,8 @@ mod existential { impl Foo { fn bad(foos: &[Self]) -> impl Iterator { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self foos.iter() } @@ -165,7 +165,7 @@ mod nesting { impl Bar { fn bar() -> Self { - //~^ use_self + //~^ use_self Self { foo: Foo {} } //~^ use_self } @@ -179,7 +179,7 @@ mod nesting { // Should lint here fn baz() -> Self { - //~^ use_self + //~^ use_self Self {} //~^ use_self } @@ -286,7 +286,7 @@ mod paths_created_by_lowering { const B: usize = 1; async fn g() -> Self { - //~^ use_self + //~^ use_self Self {} //~^ use_self } @@ -318,7 +318,7 @@ mod generics { impl Foo { // `Self` is applicable here fn foo(value: T) -> Self { - //~^ use_self + //~^ use_self Self { value } //~^ use_self } @@ -578,7 +578,7 @@ mod use_self_in_pat { None => unimplemented!(), } if let Self::Bar = self { - //~^ use_self + //~^ use_self unimplemented!() } } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index b91856e48097..b6376938611e 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -21,12 +21,12 @@ mod use_self { impl Foo { fn new() -> Foo { - //~^ use_self + //~^ use_self Foo {} //~^ use_self } fn test() -> Foo { - //~^ use_self + //~^ use_self Foo::new() //~^ use_self } @@ -34,7 +34,7 @@ mod use_self { impl Default for Foo { fn default() -> Foo { - //~^ use_self + //~^ use_self Foo::new() //~^ use_self } @@ -78,7 +78,7 @@ mod lifetimes { } fn clone(&self) -> Foo<'a> { - //~^ use_self + //~^ use_self Foo { foo_str: self.foo_str } } @@ -112,8 +112,8 @@ mod existential { impl Foo { fn bad(foos: &[Foo]) -> impl Iterator { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self foos.iter() } @@ -165,7 +165,7 @@ mod nesting { impl Bar { fn bar() -> Bar { - //~^ use_self + //~^ use_self Bar { foo: Foo {} } //~^ use_self } @@ -179,7 +179,7 @@ mod nesting { // Should lint here fn baz() -> Foo { - //~^ use_self + //~^ use_self Foo {} //~^ use_self } @@ -286,7 +286,7 @@ mod paths_created_by_lowering { const B: usize = 1; async fn g() -> S { - //~^ use_self + //~^ use_self S {} //~^ use_self } @@ -318,7 +318,7 @@ mod generics { impl Foo { // `Self` is applicable here fn foo(value: T) -> Foo { - //~^ use_self + //~^ use_self Foo:: { value } //~^ use_self } @@ -578,7 +578,7 @@ mod use_self_in_pat { None => unimplemented!(), } if let Foo::Bar = self { - //~^ use_self + //~^ use_self unimplemented!() } } diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed index 2df7eec92f2f..820282d8da54 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -17,20 +17,20 @@ struct Bad; impl SelfTrait for Bad { fn refs(p1: &Self) -> &Self { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } fn mut_refs(p1: &mut Self) -> &mut Self { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } @@ -39,8 +39,8 @@ impl SelfTrait for Bad { //~| use_self fn vals(_: Self) -> Self { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self Self //~^ use_self } @@ -51,8 +51,8 @@ impl Mul for Bad { //~^ use_self fn mul(self, rhs: Self) -> Self { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self rhs } } diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index 48118e59fe67..aa9761e5609f 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -17,20 +17,20 @@ struct Bad; impl SelfTrait for Bad { fn refs(p1: &Bad) -> &Bad { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } fn mut_refs(p1: &mut Bad) -> &mut Bad { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self p1 } @@ -39,8 +39,8 @@ impl SelfTrait for Bad { //~| use_self fn vals(_: Bad) -> Bad { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self Bad //~^ use_self } @@ -51,8 +51,8 @@ impl Mul for Bad { //~^ use_self fn mul(self, rhs: Bad) -> Bad { - //~^ use_self - //~| use_self + //~^ use_self + //~| use_self rhs } } diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index 235b49649001..e399bd76fc1e 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -157,7 +157,6 @@ fn foo() { let z = x.clone(); //~^ useless_asref - } mod issue12135 { @@ -189,13 +188,11 @@ mod issue12135 { x.field.clone(); //~^ useless_asref - // https://github.com/rust-lang/rust-clippy/pull/12136#discussion_r1451565223 #[allow(clippy::clone_on_copy)] Some(1).clone(); //~^ useless_asref - x.field.as_ref().map(|v| v.method().clone()) } } diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index 261bbe18e357..4c76a2ecf7b0 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -157,7 +157,6 @@ fn foo() { let z = x.as_ref().map(|z| String::clone(z)); //~^ useless_asref - } mod issue12135 { @@ -189,13 +188,11 @@ mod issue12135 { x.field.as_ref().map(|v| Clone::clone(v)); //~^ useless_asref - // https://github.com/rust-lang/rust-clippy/pull/12136#discussion_r1451565223 #[allow(clippy::clone_on_copy)] Some(1).as_ref().map(|&x| x.clone()); //~^ useless_asref - x.field.as_ref().map(|v| v.method().clone()) } } diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index 97be7996f008..d0ca10936fd5 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -89,25 +89,25 @@ LL | let z = x.as_ref().map(|z| String::clone(z)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:183:9 + --> tests/ui/useless_asref.rs:182:9 | LL | x.field.as_ref().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:186:9 + --> tests/ui/useless_asref.rs:185:9 | LL | x.field.as_ref().map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:189:9 + --> tests/ui/useless_asref.rs:188:9 | LL | x.field.as_ref().map(|v| Clone::clone(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:195:9 + --> tests/ui/useless_asref.rs:193:9 | LL | Some(1).as_ref().map(|&x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(1).clone()` diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index 2b9ef0209047..489caacf2123 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -341,7 +341,6 @@ fn direct_application() { let _: Result<(), std::io::Error> = test_issue_3913(); //~^ useless_conversion - let c: ControlFlow<()> = ControlFlow::Continue(()); let _: ControlFlow<()> = c; //~^ useless_conversion @@ -350,7 +349,6 @@ fn direct_application() { let _: ControlFlow<()> = c; //~^ useless_conversion - struct Absorb; impl From<()> for Absorb { fn from(_: ()) -> Self { @@ -365,7 +363,6 @@ fn direct_application() { let _: Vec = [1u32].into_iter().collect(); //~^ useless_conversion - // No lint for those let _: Result = test_issue_3913().map(Into::into); let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into); @@ -376,7 +373,6 @@ fn direct_application() { fn gen_identity(x: [T; 3]) -> Vec { x.into_iter().collect() //~^ useless_conversion - } mod issue11819 { @@ -393,7 +389,6 @@ mod issue11819 { { takes_into_iter(&self.my_field); //~^ useless_conversion - } pub fn with_ref_mut<'a>(&'a mut self) @@ -402,7 +397,6 @@ mod issue11819 { { takes_into_iter(&mut self.my_field); //~^ useless_conversion - } pub fn with_deref(&mut self) @@ -412,7 +406,6 @@ mod issue11819 { { takes_into_iter(*self.my_field); //~^ useless_conversion - } pub fn with_reborrow<'a, Y: 'a>(&'a mut self) @@ -422,7 +415,6 @@ mod issue11819 { { takes_into_iter(&*self.my_field); //~^ useless_conversion - } pub fn with_reborrow_mut<'a, Y: 'a>(&'a mut self) @@ -432,7 +424,6 @@ mod issue11819 { { takes_into_iter(&mut *self.my_field); //~^ useless_conversion - } } } diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 84b5b12580e5..4f3a3b00ea20 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -341,7 +341,6 @@ fn direct_application() { let _: Result<(), std::io::Error> = test_issue_3913().map_err(From::from); //~^ useless_conversion - let c: ControlFlow<()> = ControlFlow::Continue(()); let _: ControlFlow<()> = c.map_break(Into::into); //~^ useless_conversion @@ -350,7 +349,6 @@ fn direct_application() { let _: ControlFlow<()> = c.map_continue(Into::into); //~^ useless_conversion - struct Absorb; impl From<()> for Absorb { fn from(_: ()) -> Self { @@ -365,7 +363,6 @@ fn direct_application() { let _: Vec = [1u32].into_iter().map(Into::into).collect(); //~^ useless_conversion - // No lint for those let _: Result = test_issue_3913().map(Into::into); let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into); @@ -376,7 +373,6 @@ fn direct_application() { fn gen_identity(x: [T; 3]) -> Vec { x.into_iter().map(Into::into).collect() //~^ useless_conversion - } mod issue11819 { @@ -393,7 +389,6 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion - } pub fn with_ref_mut<'a>(&'a mut self) @@ -402,7 +397,6 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion - } pub fn with_deref(&mut self) @@ -412,7 +406,6 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion - } pub fn with_reborrow<'a, Y: 'a>(&'a mut self) @@ -422,7 +415,6 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion - } pub fn with_reborrow_mut<'a, Y: 'a>(&'a mut self) @@ -432,7 +424,6 @@ mod issue11819 { { takes_into_iter(self.my_field.into_iter()); //~^ useless_conversion - } } } diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index 39c625429c66..3cde2a786e46 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -269,37 +269,37 @@ LL | let _: Result<(), std::io::Error> = test_issue_3913().map_err(From::fro | ^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:346:31 + --> tests/ui/useless_conversion.rs:345:31 | LL | let _: ControlFlow<()> = c.map_break(Into::into); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `()` - --> tests/ui/useless_conversion.rs:350:31 + --> tests/ui/useless_conversion.rs:349:31 | LL | let _: ControlFlow<()> = c.map_continue(Into::into); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `u32` - --> tests/ui/useless_conversion.rs:365:41 + --> tests/ui/useless_conversion.rs:363:41 | LL | let _: Vec = [1u32].into_iter().map(Into::into).collect(); | ^^^^^^^^^^^^^^^^ help: consider removing error: useless conversion to the same type: `T` - --> tests/ui/useless_conversion.rs:377:18 + --> tests/ui/useless_conversion.rs:374:18 | LL | x.into_iter().map(Into::into).collect() | ^^^^^^^^^^^^^^^^ help: consider removing error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:394:29 + --> tests/ui/useless_conversion.rs:390:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:383:32 + --> tests/ui/useless_conversion.rs:379:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -310,13 +310,13 @@ LL + takes_into_iter(&self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:403:29 + --> tests/ui/useless_conversion.rs:398:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:383:32 + --> tests/ui/useless_conversion.rs:379:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -327,13 +327,13 @@ LL + takes_into_iter(&mut self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:413:29 + --> tests/ui/useless_conversion.rs:407:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:383:32 + --> tests/ui/useless_conversion.rs:379:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -344,13 +344,13 @@ LL + takes_into_iter(*self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:423:29 + --> tests/ui/useless_conversion.rs:416:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:383:32 + --> tests/ui/useless_conversion.rs:379:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,13 +361,13 @@ LL + takes_into_iter(&*self.my_field); | error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> tests/ui/useless_conversion.rs:433:29 + --> tests/ui/useless_conversion.rs:425:29 | LL | takes_into_iter(self.my_field.into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> tests/ui/useless_conversion.rs:383:32 + --> tests/ui/useless_conversion.rs:379:32 | LL | fn takes_into_iter(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useless_conversion_try.rs b/tests/ui/useless_conversion_try.rs index 7f469a819ef2..d16506d94aa3 100644 --- a/tests/ui/useless_conversion_try.rs +++ b/tests/ui/useless_conversion_try.rs @@ -11,7 +11,6 @@ fn test_generic(val: T) -> T { val.try_into().unwrap() //~^ useless_conversion - } fn test_generic2 + Into, U: From>(val: T) { @@ -52,8 +51,7 @@ fn main() { //~^ useless_conversion let _: String = match String::from("_").try_into() { - //~^ useless_conversion - + //~^ useless_conversion Ok(a) => a, Err(_) => String::new(), }; diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr index af2199837bf7..1c62426c8952 100644 --- a/tests/ui/useless_conversion_try.stderr +++ b/tests/ui/useless_conversion_try.stderr @@ -20,7 +20,7 @@ LL | val.try_into().unwrap() = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> tests/ui/useless_conversion_try.rs:36:21 + --> tests/ui/useless_conversion_try.rs:35: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` - --> tests/ui/useless_conversion_try.rs:39:21 + --> tests/ui/useless_conversion_try.rs:38: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` - --> tests/ui/useless_conversion_try.rs:42:13 + --> tests/ui/useless_conversion_try.rs:41: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` - --> tests/ui/useless_conversion_try.rs:45:13 + --> tests/ui/useless_conversion_try.rs:44: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` - --> tests/ui/useless_conversion_try.rs:48:21 + --> tests/ui/useless_conversion_try.rs:47: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` - --> tests/ui/useless_conversion_try.rs:51:21 + --> tests/ui/useless_conversion_try.rs:50: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` - --> tests/ui/useless_conversion_try.rs:54:27 + --> tests/ui/useless_conversion_try.rs:53:27 | LL | let _: String = match String::from("_").try_into() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/useless_nonzero_new_unchecked.fixed b/tests/ui/useless_nonzero_new_unchecked.fixed index 8e5e105215a9..f7f60bbe3f8d 100644 --- a/tests/ui/useless_nonzero_new_unchecked.fixed +++ b/tests/ui/useless_nonzero_new_unchecked.fixed @@ -6,7 +6,6 @@ use std::num::{NonZero, NonZeroUsize}; const fn func() -> NonZeroUsize { const { NonZeroUsize::new(3).unwrap() } //~^ useless_nonzero_new_unchecked - } #[clippy::msrv = "1.82"] @@ -38,20 +37,16 @@ fn main() { const _A: NonZeroUsize = NonZeroUsize::new(3).unwrap(); //~^ useless_nonzero_new_unchecked - static _B: NonZero = NonZero::::new(42).unwrap(); //~^ useless_nonzero_new_unchecked - const _C: usize = unsafe { NonZeroUsize::new(3).unwrap().get() }; //~^ useless_nonzero_new_unchecked - const AUX: usize = 3; const _D: NonZeroUsize = NonZeroUsize::new(AUX).unwrap(); //~^ useless_nonzero_new_unchecked - const _X: NonZeroUsize = uns!(NonZeroUsize::new_unchecked(3)); const _Y: NonZeroUsize = unsafe { nzu!() }; } diff --git a/tests/ui/useless_nonzero_new_unchecked.rs b/tests/ui/useless_nonzero_new_unchecked.rs index 43fd1f2e5849..c90a63915efb 100644 --- a/tests/ui/useless_nonzero_new_unchecked.rs +++ b/tests/ui/useless_nonzero_new_unchecked.rs @@ -6,7 +6,6 @@ use std::num::{NonZero, NonZeroUsize}; const fn func() -> NonZeroUsize { const { unsafe { NonZeroUsize::new_unchecked(3) } } //~^ useless_nonzero_new_unchecked - } #[clippy::msrv = "1.82"] @@ -38,20 +37,16 @@ fn main() { const _A: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; //~^ useless_nonzero_new_unchecked - static _B: NonZero = unsafe { NonZero::::new_unchecked(42) }; //~^ useless_nonzero_new_unchecked - const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; //~^ useless_nonzero_new_unchecked - const AUX: usize = 3; const _D: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(AUX) }; //~^ useless_nonzero_new_unchecked - const _X: NonZeroUsize = uns!(NonZeroUsize::new_unchecked(3)); const _Y: NonZeroUsize = unsafe { nzu!() }; } diff --git a/tests/ui/useless_nonzero_new_unchecked.stderr b/tests/ui/useless_nonzero_new_unchecked.stderr index b9fc333dd4f5..adb146167633 100644 --- a/tests/ui/useless_nonzero_new_unchecked.stderr +++ b/tests/ui/useless_nonzero_new_unchecked.stderr @@ -8,19 +8,19 @@ LL | const { unsafe { NonZeroUsize::new_unchecked(3) } } = help: to override `-D warnings` add `#[allow(clippy::useless_nonzero_new_unchecked)]` error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:38:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:37:30 | LL | const _A: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(3).unwrap()` error: `NonZero::::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:42:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:40:30 | LL | static _B: NonZero = unsafe { NonZero::::new_unchecked(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZero::::new(42).unwrap()` error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:46:32 + --> tests/ui/useless_nonzero_new_unchecked.rs:43:32 | LL | const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(3).unwrap()` @@ -28,7 +28,7 @@ LL | const _C: usize = unsafe { NonZeroUsize::new_unchecked(3).get() }; = note: the fixed expression does not require an `unsafe` context error: `NonZeroUsize::new()` and `Option::unwrap()` can be safely used in a `const` context - --> tests/ui/useless_nonzero_new_unchecked.rs:51:30 + --> tests/ui/useless_nonzero_new_unchecked.rs:47:30 | LL | const _D: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(AUX) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use instead: `NonZeroUsize::new(AUX).unwrap()` diff --git a/tests/ui/useless_vec.rs b/tests/ui/useless_vec.rs index 65aafb66568f..880809f81d7a 100644 --- a/tests/ui/useless_vec.rs +++ b/tests/ui/useless_vec.rs @@ -6,8 +6,7 @@ fn foo() { // There should be no suggestion in this case. let _some_variable = vec![ - //~^ useless_vec - + //~^ useless_vec 1, 2, // i'm here to stay 3, 4, // but this one going away ;-; ]; // that is life anyways diff --git a/tests/ui/useless_vec.stderr b/tests/ui/useless_vec.stderr index 39927d0b4654..e47364fb06d3 100644 --- a/tests/ui/useless_vec.stderr +++ b/tests/ui/useless_vec.stderr @@ -4,7 +4,6 @@ error: useless use of `vec!` LL | let _some_variable = vec![ | __________________________^ LL | | -LL | | LL | | 1, 2, // i'm here to stay LL | | 3, 4, // but this one going away ;-; LL | | ]; // that is life anyways diff --git a/tests/ui/vec.fixed b/tests/ui/vec.fixed index 5b35b2b26243..f360a8afadf6 100644 --- a/tests/ui/vec.fixed +++ b/tests/ui/vec.fixed @@ -136,7 +136,7 @@ fn issue11075() { } #[allow(clippy::never_loop)] for _string in [repro!(true), repro!(null)] { - //~^ useless_vec + //~^ useless_vec unimplemented!(); } @@ -175,12 +175,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { for a in [1, 2, 3] { - //~^ useless_vec + //~^ useless_vec let _: usize = a; } for a in [String::new(), String::new()] { - //~^ useless_vec + //~^ useless_vec let _: String = a; } } @@ -212,8 +212,8 @@ fn issue11861() { // Do not lint the next line this_macro_needs_vec!(vec![1]); -this_macro_doesnt_need_vec!([1]); -//~^ useless_vec + this_macro_doesnt_need_vec!([1]); + //~^ useless_vec macro_rules! m { ($x:expr) => { diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index c82580b2fd1a..a779d33557cb 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -136,7 +136,7 @@ fn issue11075() { } #[allow(clippy::never_loop)] for _string in vec![repro!(true), repro!(null)] { - //~^ useless_vec + //~^ useless_vec unimplemented!(); } @@ -175,12 +175,12 @@ fn issue11075() { #[clippy::msrv = "1.53"] fn above() { for a in vec![1, 2, 3] { - //~^ useless_vec + //~^ useless_vec let _: usize = a; } for a in vec![String::new(), String::new()] { - //~^ useless_vec + //~^ useless_vec let _: String = a; } } @@ -212,8 +212,8 @@ fn issue11861() { // Do not lint the next line this_macro_needs_vec!(vec![1]); -this_macro_doesnt_need_vec!(vec![1]); -//~^ useless_vec + this_macro_doesnt_need_vec!(vec![1]); + //~^ useless_vec macro_rules! m { ($x:expr) => { diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index 1063e0e37d89..806d6617200f 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -116,10 +116,10 @@ LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` error: useless use of `vec!` - --> tests/ui/vec.rs:215:29 + --> tests/ui/vec.rs:215:33 | -LL | this_macro_doesnt_need_vec!(vec![1]); - | ^^^^^^^ help: you can use an array directly: `[1]` +LL | this_macro_doesnt_need_vec!(vec![1]); + | ^^^^^^^ help: you can use an array directly: `[1]` error: useless use of `vec!` --> tests/ui/vec.rs:242:14 diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs index d32081c26a03..897add423b6d 100644 --- a/tests/ui/vec_box_sized.rs +++ b/tests/ui/vec_box_sized.rs @@ -39,15 +39,15 @@ mod should_trigger { //~^ vec_box fn allocator_global_defined_vec() -> Vec, std::alloc::Global> { - //~^ vec_box + //~^ vec_box Vec::new() } fn allocator_global_defined_box() -> Vec> { - //~^ vec_box + //~^ vec_box Vec::new() } fn allocator_match() -> Vec, DummyAllocator> { - //~^ vec_box + //~^ vec_box Vec::new_in(DummyAllocator) } } @@ -85,7 +85,7 @@ mod inner_mod { use super::inner::S; pub fn f() -> Vec> { - //~^ vec_box + //~^ vec_box vec![] } } diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index 31cd84d2cf40..a32187edfea6 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -5,7 +5,6 @@ fn main() { let mut def_err: Vec = Default::default(); //~^ vec_init_then_push - def_err.push(0); let mut new_err = Vec::::new(); diff --git a/tests/ui/vec_init_then_push.stderr b/tests/ui/vec_init_then_push.stderr index 3be277bb07b9..1900ad7bd6a0 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -10,7 +10,7 @@ LL | | def_err.push(0); = help: to override `-D warnings` add `#[allow(clippy::vec_init_then_push)]` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:11:5 + --> tests/ui/vec_init_then_push.rs:10:5 | LL | / let mut new_err = Vec::::new(); ... | @@ -18,7 +18,7 @@ LL | | new_err.push(1); | |____________________^ help: consider using the `vec![]` macro: `let mut new_err = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:16:5 + --> tests/ui/vec_init_then_push.rs:15:5 | LL | / let mut cap_err = Vec::with_capacity(2); LL | | @@ -29,7 +29,7 @@ LL | | cap_err.push(2); | |____________________^ help: consider using the `vec![]` macro: `let mut cap_err = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:30:5 + --> tests/ui/vec_init_then_push.rs:29:5 | LL | / new_err = Vec::new(); ... | @@ -37,7 +37,7 @@ LL | | new_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `new_err = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:82:5 + --> tests/ui/vec_init_then_push.rs:81:5 | LL | / let mut v = Vec::new(); LL | | @@ -47,7 +47,7 @@ LL | | v.push(1); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:92:5 + --> tests/ui/vec_init_then_push.rs:91:5 | LL | / let mut v = Vec::new(); LL | | @@ -59,7 +59,7 @@ LL | | v.push(0); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:107:5 + --> tests/ui/vec_init_then_push.rs:106:5 | LL | / let mut v2 = Vec::new(); LL | | @@ -71,7 +71,7 @@ LL | | v2.push(0); | |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];` error: calls to `push` immediately after creation - --> tests/ui/vec_init_then_push.rs:124:5 + --> tests/ui/vec_init_then_push.rs:123:5 | LL | / let mut v = Vec::new(); ... | diff --git a/tests/ui/vec_resize_to_zero.fixed b/tests/ui/vec_resize_to_zero.fixed index f5c0ecd72e00..260943f655e3 100644 --- a/tests/ui/vec_resize_to_zero.fixed +++ b/tests/ui/vec_resize_to_zero.fixed @@ -7,7 +7,6 @@ fn main() { v.clear(); //~^ vec_resize_to_zero - // 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 2b75b475223c..d6054715143c 100644 --- a/tests/ui/vec_resize_to_zero.rs +++ b/tests/ui/vec_resize_to_zero.rs @@ -7,7 +7,6 @@ fn main() { v.resize(0, 5); //~^ vec_resize_to_zero - // not applicable v.resize(2, 5); diff --git a/tests/ui/while_float.rs b/tests/ui/while_float.rs index 06dc700c1980..727b954ffcca 100644 --- a/tests/ui/while_float.rs +++ b/tests/ui/while_float.rs @@ -2,11 +2,11 @@ fn main() { let mut x = 0.0_f32; while x < 42.0_f32 { - //~^ while_float + //~^ while_float x += 0.5; } while x < 42.0 { - //~^ while_float + //~^ while_float x += 1.0; } let mut x = 0; diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs index ea442b9b2b5c..d591ab984cfa 100644 --- a/tests/ui/while_let_loop.rs +++ b/tests/ui/while_let_loop.rs @@ -4,8 +4,7 @@ fn main() { let y = Some(true); loop { - //~^ while_let_loop - + //~^ while_let_loop if let Some(_x) = y { let _v = 1; @@ -24,7 +23,7 @@ fn main() { } loop { - //~^ while_let_loop + //~^ while_let_loop match y { Some(_x) => true, @@ -33,7 +32,7 @@ fn main() { } loop { - //~^ while_let_loop + //~^ while_let_loop let x = match y { Some(x) => x, @@ -44,7 +43,7 @@ fn main() { } loop { - //~^ while_let_loop + //~^ while_let_loop let x = match y { Some(x) => x, @@ -76,7 +75,7 @@ fn main() { // #675, this used to have a wrong suggestion loop { - //~^ while_let_loop + //~^ while_let_loop let (e, l) = match "".split_whitespace().next() { Some(word) => (word.is_empty(), word.len()), diff --git a/tests/ui/while_let_loop.stderr b/tests/ui/while_let_loop.stderr index 3bd8ab85a92f..bd482857e675 100644 --- a/tests/ui/while_let_loop.stderr +++ b/tests/ui/while_let_loop.stderr @@ -2,6 +2,9 @@ error: this loop could be written as a `while let` loop --> tests/ui/while_let_loop.rs:6:5 | LL | / loop { +LL | | +LL | | +LL | | if let Some(_x) = y { ... | LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` @@ -10,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:26:5 + --> tests/ui/while_let_loop.rs:25:5 | LL | / loop { LL | | @@ -22,7 +25,7 @@ LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:35:5 + --> tests/ui/while_let_loop.rs:34:5 | LL | / loop { LL | | @@ -34,7 +37,7 @@ LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:46:5 + --> tests/ui/while_let_loop.rs:45:5 | LL | / loop { LL | | @@ -45,7 +48,7 @@ LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> tests/ui/while_let_loop.rs:78:5 + --> tests/ui/while_let_loop.rs:77:5 | LL | / loop { LL | | diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index bf4950620340..f9ccefab5898 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -13,13 +13,13 @@ fn base() { let mut iter = 1..20; for x in iter { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; for x in iter { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } @@ -124,7 +124,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); for x @ [_] in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{:?}", x); } } @@ -145,7 +145,7 @@ fn nested_loops() { loop { let mut y = a.iter(); for _ in y { - //~^ while_let_on_iterator + //~^ while_let_on_iterator // use a for loop here } } @@ -203,7 +203,7 @@ fn issue6491() { let mut it = 1..40; while let Some(n) = it.next() { for m in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -215,10 +215,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; for n in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator let mut it = 1..40; for m in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -228,7 +228,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); for m in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -238,7 +238,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; for m in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -256,7 +256,7 @@ fn issue6231() { let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { for m in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n % 10 == 0 { break; } @@ -272,7 +272,7 @@ fn issue1924() { fn f(&mut self) -> Option { // Used as a field. for i in self.0.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if !(3..8).contains(&i) { return Some(i); } @@ -305,7 +305,7 @@ fn issue1924() { } // This one is fine, a different field is borrowed for i in self.0.0.0.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if i == 1 { return self.0.1.take(); } else { @@ -335,7 +335,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); for n in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n == 0 { break; } @@ -348,7 +348,7 @@ fn issue7249() { let mut x = || { // Needs &mut, the closure can be called multiple times for x in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -363,7 +363,7 @@ fn issue7510() { let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable for x in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -375,7 +375,7 @@ fn issue7510() { let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable for x in it.0.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -411,7 +411,7 @@ fn custom_deref() { let mut s = S2(S1 { x: 0..10 }); for x in s.x.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } } @@ -419,7 +419,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; for x in x[0].by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } } @@ -428,7 +428,7 @@ fn fn_once_closure() { let mut it = 0..10; (|| { for x in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -439,7 +439,7 @@ fn fn_once_closure() { let mut it = 0..10; f(|| { for x in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -450,7 +450,7 @@ fn fn_once_closure() { let mut it = 0..10; f2(|| { for x in it.by_ref() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -461,7 +461,7 @@ fn fn_once_closure() { f3(|| { let mut it = 0..10; for x in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -474,7 +474,7 @@ fn fn_once_closure() { let mut it = 0..10; f4(|| { for x in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -485,7 +485,7 @@ fn fn_once_closure() { fn issue13123() { let mut it = 0..20; 'label: for n in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n % 25 == 0 { break 'label; } @@ -495,7 +495,7 @@ fn issue13123() { fn main() { let mut it = 0..20; for _ in it { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("test"); } } diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index d34b78efc706..f957f2e5a523 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -13,13 +13,13 @@ fn base() { let mut iter = 1..20; while let Option::Some(x) = iter.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } let mut iter = 1..20; while let Some(x) = iter.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } @@ -124,7 +124,7 @@ fn refutable2() { let v = vec![[1], [2], [3]]; let mut it = v.iter(); while let Some(x @ [_]) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{:?}", x); } } @@ -145,7 +145,7 @@ fn nested_loops() { loop { let mut y = a.iter(); while let Some(_) = y.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator // use a for loop here } } @@ -203,7 +203,7 @@ fn issue6491() { let mut it = 1..40; while let Some(n) = it.next() { while let Some(m) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -215,10 +215,10 @@ fn issue6491() { // This is fine, inner loop uses a new iterator. let mut it = 1..40; while let Some(n) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator let mut it = 1..40; while let Some(m) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -228,7 +228,7 @@ fn issue6491() { // Weird binding shouldn't change anything. let (mut it, _) = (1..40, 0); while let Some(m) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -238,7 +238,7 @@ fn issue6491() { // Used after the loop, needs &mut. let mut it = 1..40; while let Some(m) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if m % 10 == 0 { break; } @@ -256,7 +256,7 @@ fn issue6231() { let mut opt = Some(0); while let Some(n) = opt.take().or_else(|| it.next()) { while let Some(m) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n % 10 == 0 { break; } @@ -272,7 +272,7 @@ fn issue1924() { fn f(&mut self) -> Option { // Used as a field. while let Some(i) = self.0.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if !(3..8).contains(&i) { return Some(i); } @@ -305,7 +305,7 @@ fn issue1924() { } // This one is fine, a different field is borrowed while let Some(i) = self.0.0.0.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if i == 1 { return self.0.1.take(); } else { @@ -335,7 +335,7 @@ fn issue1924() { // Needs &mut, field of the iterator is accessed after the loop let mut it = S2(1..40, 0); while let Some(n) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n == 0 { break; } @@ -348,7 +348,7 @@ fn issue7249() { let mut x = || { // Needs &mut, the closure can be called multiple times while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -363,7 +363,7 @@ fn issue7510() { let it = &mut it; // Needs to reborrow `it` as the binding isn't mutable while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -375,7 +375,7 @@ fn issue7510() { let it = S(&mut it); // Needs to reborrow `it.0` as the binding isn't mutable while let Some(x) = it.0.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -411,7 +411,7 @@ fn custom_deref() { let mut s = S2(S1 { x: 0..10 }); while let Some(x) = s.x.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } } @@ -419,7 +419,7 @@ fn custom_deref() { fn issue_8113() { let mut x = [0..10]; while let Some(x) = x[0].next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("{}", x); } } @@ -428,7 +428,7 @@ fn fn_once_closure() { let mut it = 0..10; (|| { while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -439,7 +439,7 @@ fn fn_once_closure() { let mut it = 0..10; f(|| { while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -450,7 +450,7 @@ fn fn_once_closure() { let mut it = 0..10; f2(|| { while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -461,7 +461,7 @@ fn fn_once_closure() { f3(|| { let mut it = 0..10; while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -474,7 +474,7 @@ fn fn_once_closure() { let mut it = 0..10; f4(|| { while let Some(x) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if x % 2 == 0 { break; } @@ -485,7 +485,7 @@ fn fn_once_closure() { fn issue13123() { let mut it = 0..20; 'label: while let Some(n) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator if n % 25 == 0 { break 'label; } @@ -495,7 +495,7 @@ fn issue13123() { fn main() { let mut it = 0..20; while let Some(..) = it.next() { - //~^ while_let_on_iterator + //~^ while_let_on_iterator println!("test"); } } diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs index 8d194a38ddf8..ced13cc50c5d 100644 --- a/tests/ui/wild_in_or_pats.rs +++ b/tests/ui/wild_in_or_pats.rs @@ -6,7 +6,7 @@ fn main() { dbg!("matched a"); }, "bar" | _ => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("matched (bar or) wild"); }, @@ -16,7 +16,7 @@ fn main() { dbg!("matched a"); }, "bar" | "bar2" | _ => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("matched (bar or bar2 or) wild"); }, @@ -26,7 +26,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" | _ => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("matched (bar or) wild"); }, @@ -36,7 +36,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("matched (bar or) wild"); }, @@ -71,7 +71,7 @@ fn main() { dbg!("Change the color"); }, ExhaustiveEnum::Quit | _ => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("Quit or other"); }, }; @@ -107,7 +107,7 @@ fn main() { dbg!("On the y axis at {y}"); }, ExhaustiveStruct { x: 1, y: 1 } | _ => { - //~^ wildcard_in_or_patterns + //~^ wildcard_in_or_patterns dbg!("On neither axis: ({x}, {y})"); }, } diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed index b82d77aaa418..e84f768e33d0 100644 --- a/tests/ui/write_literal.fixed +++ b/tests/ui/write_literal.fixed @@ -31,7 +31,6 @@ fn main() { write!(v, "Hello world"); //~^ write_literal - writeln!(v, "Hello {} world", world); //~^ write_literal @@ -41,7 +40,6 @@ fn main() { writeln!(v, "a literal {:.4}", 5); //~^ write_literal - // positional args don't change the fact // that we're using a literal -- this should // throw a warning @@ -51,7 +49,6 @@ fn main() { writeln!(v, "world hello"); //~^ write_literal - // named args shouldn't change anything either writeln!(v, "hello world"); //~^ write_literal @@ -59,7 +56,6 @@ fn main() { writeln!(v, "world hello"); //~^ write_literal - // #10128 writeln!(v, "hello {0} world", 2); //~^ write_literal @@ -72,7 +68,6 @@ fn main() { writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); //~^ write_literal - } fn issue_13959() { diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index e9f5990d7ec6..fc29fcbede7e 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -31,7 +31,6 @@ fn main() { write!(v, "Hello {}", "world"); //~^ write_literal - writeln!(v, "Hello {} {}", world, "world"); //~^ write_literal @@ -41,7 +40,6 @@ fn main() { writeln!(v, "{} {:.4}", "a literal", 5); //~^ write_literal - // positional args don't change the fact // that we're using a literal -- this should // throw a warning @@ -51,7 +49,6 @@ fn main() { writeln!(v, "{1} {0}", "hello", "world"); //~^ write_literal - // named args shouldn't change anything either writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); //~^ write_literal @@ -59,7 +56,6 @@ fn main() { writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); //~^ write_literal - // #10128 writeln!(v, "{0} {1} {2}", "hello", 2, "world"); //~^ write_literal @@ -72,7 +68,6 @@ fn main() { writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); //~^ write_literal - } fn issue_13959() { diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 834162473c58..d53c2a7de2e0 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -13,7 +13,7 @@ LL + write!(v, "Hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:35:39 + --> tests/ui/write_literal.rs:34:39 | LL | writeln!(v, "Hello {} {}", world, "world"); | ^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, "Hello {} world", world); | error: literal with an empty format string - --> tests/ui/write_literal.rs:38:29 + --> tests/ui/write_literal.rs:37:29 | LL | writeln!(v, "Hello {}", "world"); | ^^^^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "Hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:41:29 + --> tests/ui/write_literal.rs:40:29 | LL | writeln!(v, "{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + writeln!(v, "a literal {:.4}", 5); | error: literal with an empty format string - --> tests/ui/write_literal.rs:48:28 + --> tests/ui/write_literal.rs:46:28 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + writeln!(v, "hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:51:28 + --> tests/ui/write_literal.rs:49:28 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + writeln!(v, "world hello"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:56:38 + --> tests/ui/write_literal.rs:53:38 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + writeln!(v, "hello world"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:59:38 + --> tests/ui/write_literal.rs:56:38 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + writeln!(v, "world hello"); | error: literal with an empty format string - --> tests/ui/write_literal.rs:64:32 + --> tests/ui/write_literal.rs:60:32 | LL | writeln!(v, "{0} {1} {2}", "hello", 2, "world"); | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + writeln!(v, "hello {0} world", 2); | error: literal with an empty format string - --> tests/ui/write_literal.rs:67:32 + --> tests/ui/write_literal.rs:63:32 | LL | writeln!(v, "{2} {1} {0}", "hello", 2, "world"); | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + writeln!(v, "world {0} hello", 2); | error: literal with an empty format string - --> tests/ui/write_literal.rs:70:39 + --> tests/ui/write_literal.rs:66:39 | LL | writeln!(v, "{0} {1} {2}, {bar}", "hello", 2, 3, bar = 4); | ^^^^^^^ @@ -133,7 +133,7 @@ LL + writeln!(v, "hello {0} {1}, {bar}", 2, 3, bar = 4); | error: literal with an empty format string - --> tests/ui/write_literal.rs:73:41 + --> tests/ui/write_literal.rs:69:41 | LL | writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4); | error: literal with an empty format string - --> tests/ui/write_literal.rs:80:23 + --> tests/ui/write_literal.rs:75:23 | LL | writeln!(v, "{}", r#"""#); | ^^^^^^ @@ -157,7 +157,7 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> tests/ui/write_literal.rs:85:9 + --> tests/ui/write_literal.rs:80:9 | LL | / r#" LL | | diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index 2edd50c43403..f896782aaf3b 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -10,7 +10,6 @@ fn main() { writeln!(v, "{}", "{hello}"); //~^ write_literal - writeln!(v, r"{}", r"{hello}"); //~^ write_literal @@ -32,14 +31,15 @@ fn main() { "hello \ //~^ write_literal world!", - ); writeln!( v, "some {}\ {} \\ {}", - "1", "2", "3", - //~^ write_literal + "1", + "2", + "3", + //~^^^ write_literal ); writeln!(v, "{}", "\\"); //~^ write_literal diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index f3f86586ef85..29803d6a8b18 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -13,7 +13,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:14:24 + --> tests/ui/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:17:23 + --> tests/ui/write_literal_2.rs:16:23 | LL | writeln!(v, "{}", '\''); | ^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "'"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:20:23 + --> tests/ui/write_literal_2.rs:19:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -49,13 +49,13 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:23:24 + --> tests/ui/write_literal_2.rs:22:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> tests/ui/write_literal_2.rs:26:24 + --> tests/ui/write_literal_2.rs:25:24 | LL | writeln!(v, r"{}", '\''); | ^^^^ @@ -67,7 +67,7 @@ LL + writeln!(v, r"'"); | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:32:9 + --> tests/ui/write_literal_2.rs:31:9 | LL | / "hello \ LL | | @@ -82,10 +82,12 @@ LL ~ world!", | error: literal with an empty format string - --> tests/ui/write_literal_2.rs:41:9 + --> tests/ui/write_literal_2.rs:39:9 | -LL | "1", "2", "3", - | ^^^^^^^^^^^^^ +LL | / "1", +LL | | "2", +LL | | "3", + | |___________^ | help: try | diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index bd2285d16bcf..40742bbbb427 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -12,7 +12,6 @@ fn main() { writeln!(v, "Hello"); //~^ write_with_newline - writeln!(v, "Hello {}", "world"); //~^ write_with_newline @@ -25,7 +24,6 @@ fn main() { writeln!(v); //~^ write_with_newline - // These should be fine write!(v, ""); write!(v, "Hello"); @@ -57,13 +55,11 @@ fn main() { // Literal newlines should also fail writeln!( - //~^ write_with_newline - + //~^ write_with_newline v ); writeln!( - //~^ write_with_newline - + //~^ write_with_newline v ); diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index b70349ae82e6..ad6af69e7813 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -12,7 +12,6 @@ fn main() { write!(v, "Hello\n"); //~^ write_with_newline - write!(v, "Hello {}\n", "world"); //~^ write_with_newline @@ -25,7 +24,6 @@ fn main() { write!(v, "\n"); //~^ write_with_newline - // These should be fine write!(v, ""); write!(v, "Hello"); @@ -57,15 +55,13 @@ fn main() { // Literal newlines should also fail write!( - //~^ write_with_newline - + //~^ write_with_newline v, " " ); write!( - //~^ write_with_newline - + //~^ write_with_newline v, r" " diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 9ab17cfdf3af..7243b7943df0 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -13,7 +13,7 @@ LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:16:5 + --> tests/ui/write_with_newline.rs:15:5 | LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:19:5 + --> tests/ui/write_with_newline.rs:18:5 | LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:22:5 + --> tests/ui/write_with_newline.rs:21:5 | LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:25:5 + --> tests/ui/write_with_newline.rs:24:5 | LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:49:5 + --> tests/ui/write_with_newline.rs:47:5 | LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ @@ -73,11 +73,10 @@ LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:59:5 + --> tests/ui/write_with_newline.rs:57:5 | LL | / write!( LL | | -LL | | LL | | v, LL | | " LL | | " @@ -88,16 +87,14 @@ help: use `writeln!` instead | LL ~ writeln!( LL | -LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:66:5 + --> tests/ui/write_with_newline.rs:63:5 | LL | / write!( LL | | -LL | | LL | | v, LL | | r" LL | | " @@ -108,12 +105,11 @@ help: use `writeln!` instead | LL ~ writeln!( LL | -LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> tests/ui/write_with_newline.rs:77:5 + --> tests/ui/write_with_newline.rs:73:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index 42d600b67f8e..840dfe7c6524 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -16,7 +16,6 @@ impl Foo { fn from_i32(self) {} //~^ wrong_self_convention - pub fn as_i64(self) {} pub fn into_i64(self) {} pub fn is_i64(self) {} @@ -54,7 +53,6 @@ impl Bar { fn from_i32(self) {} //~^ wrong_self_convention - pub fn as_i64(self) {} //~^ wrong_self_convention @@ -70,7 +68,6 @@ impl Bar { pub fn from_i64(self) {} //~^ wrong_self_convention - // test for false positives fn as_(self) {} fn into_(&self) {} @@ -216,7 +213,7 @@ mod issue6727 { } // trigger lint fn to_u64_v2(&self) -> u64 { - //~^ wrong_self_convention + //~^ wrong_self_convention 1 } @@ -227,7 +224,7 @@ mod issue6727 { impl FooNoCopy { // trigger lint fn to_u64(self) -> u64 { - //~^ wrong_self_convention + //~^ wrong_self_convention 2 } diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index fe6d231578b1..e720ddf3fae1 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -9,7 +9,7 @@ LL | fn from_i32(self) {} = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:24:21 + --> tests/ui/wrong_self_convention.rs:23:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -17,7 +17,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 - --> tests/ui/wrong_self_convention.rs:38:15 + --> tests/ui/wrong_self_convention.rs:37:15 | LL | fn as_i32(self) {} | ^^^^ @@ -25,7 +25,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:42:17 + --> tests/ui/wrong_self_convention.rs:41:17 | LL | fn into_i32(&self) {} | ^^^^^ @@ -33,7 +33,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` - --> tests/ui/wrong_self_convention.rs:46:15 + --> tests/ui/wrong_self_convention.rs:45:15 | LL | fn is_i32(self) {} | ^^^^ @@ -41,7 +41,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 - --> tests/ui/wrong_self_convention.rs:50:15 + --> tests/ui/wrong_self_convention.rs:49:15 | LL | fn to_i32(self) {} | ^^^^ @@ -49,7 +49,7 @@ LL | fn to_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:54:17 + --> tests/ui/wrong_self_convention.rs:53:17 | LL | fn from_i32(self) {} | ^^^^ @@ -57,7 +57,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 - --> tests/ui/wrong_self_convention.rs:58:19 + --> tests/ui/wrong_self_convention.rs:56:19 | LL | pub fn as_i64(self) {} | ^^^^ @@ -65,7 +65,7 @@ LL | pub fn as_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:61:21 + --> tests/ui/wrong_self_convention.rs:59:21 | LL | pub fn into_i64(&self) {} | ^^^^^ @@ -73,7 +73,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` - --> tests/ui/wrong_self_convention.rs:64:19 + --> tests/ui/wrong_self_convention.rs:62:19 | LL | pub fn is_i64(self) {} | ^^^^ @@ -81,7 +81,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 - --> tests/ui/wrong_self_convention.rs:67:19 + --> tests/ui/wrong_self_convention.rs:65:19 | LL | pub fn to_i64(self) {} | ^^^^ @@ -89,7 +89,7 @@ LL | pub fn to_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:70:21 + --> tests/ui/wrong_self_convention.rs:68:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -97,7 +97,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 - --> tests/ui/wrong_self_convention.rs:117:19 + --> tests/ui/wrong_self_convention.rs:114:19 | LL | fn as_i32(self) {} | ^^^^ @@ -105,7 +105,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:122:25 + --> tests/ui/wrong_self_convention.rs:119:25 | LL | fn into_i32_ref(&self) {} | ^^^^^ @@ -113,7 +113,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` - --> tests/ui/wrong_self_convention.rs:126:19 + --> tests/ui/wrong_self_convention.rs:123:19 | LL | fn is_i32(self) {} | ^^^^ @@ -121,7 +121,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:132:21 + --> tests/ui/wrong_self_convention.rs:129:21 | LL | fn from_i32(self) {} | ^^^^ @@ -129,7 +129,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 - --> tests/ui/wrong_self_convention.rs:149:19 + --> tests/ui/wrong_self_convention.rs:146:19 | LL | fn as_i32(self); | ^^^^ @@ -137,7 +137,7 @@ LL | fn as_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:154:25 + --> tests/ui/wrong_self_convention.rs:151:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -145,7 +145,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` - --> tests/ui/wrong_self_convention.rs:158:19 + --> tests/ui/wrong_self_convention.rs:155:19 | LL | fn is_i32(self); | ^^^^ @@ -153,7 +153,7 @@ LL | fn is_i32(self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:164:21 + --> tests/ui/wrong_self_convention.rs:161:21 | LL | fn from_i32(self); | ^^^^ @@ -161,7 +161,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> tests/ui/wrong_self_convention.rs:184:25 + --> tests/ui/wrong_self_convention.rs:181:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -169,7 +169,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> tests/ui/wrong_self_convention.rs:192:21 + --> tests/ui/wrong_self_convention.rs:189:21 | LL | fn from_i32(self); | ^^^^ @@ -177,7 +177,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 - --> tests/ui/wrong_self_convention.rs:218:22 + --> tests/ui/wrong_self_convention.rs:215:22 | LL | fn to_u64_v2(&self) -> u64 { | ^^^^^ @@ -185,7 +185,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 - --> tests/ui/wrong_self_convention.rs:229:19 + --> tests/ui/wrong_self_convention.rs:226:19 | LL | fn to_u64(self) -> u64 { | ^^^^ diff --git a/tests/ui/wrong_self_convention2.rs b/tests/ui/wrong_self_convention2.rs index 0740af48d741..0a3e4982a49a 100644 --- a/tests/ui/wrong_self_convention2.rs +++ b/tests/ui/wrong_self_convention2.rs @@ -52,7 +52,7 @@ mod issue7179 { // lint pub fn from_be_self(self) -> Self { - //~^ wrong_self_convention + //~^ wrong_self_convention S(i32::from_be(self.0)) } @@ -64,7 +64,6 @@ mod issue7179 { // lint fn from_be_self(self) -> Self; //~^ wrong_self_convention - } trait Foo: Sized { diff --git a/tests/ui/wrong_self_conventions_mut.rs b/tests/ui/wrong_self_conventions_mut.rs index 73df332d77ce..eb6f08fff424 100644 --- a/tests/ui/wrong_self_conventions_mut.rs +++ b/tests/ui/wrong_self_conventions_mut.rs @@ -12,7 +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]> { - //~^ wrong_self_convention + //~^ wrong_self_convention match self { Self::Many(data) => Some(data), @@ -22,7 +22,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]> { - //~^ wrong_self_convention + //~^ wrong_self_convention match self { Self::Many(data) => Some(data), diff --git a/tests/ui/zero_offset.rs b/tests/ui/zero_offset.rs index dd2063ee5d9e..bedb09536c53 100644 --- a/tests/ui/zero_offset.rs +++ b/tests/ui/zero_offset.rs @@ -5,7 +5,6 @@ fn main() { m.offset(0); //~^ zst_offset - m.wrapping_add(0); //~^ zst_offset @@ -15,7 +14,6 @@ fn main() { m.wrapping_sub(0); //~^ zst_offset - let c = &() as *const (); c.offset(0); //~^ zst_offset @@ -29,7 +27,6 @@ fn main() { c.wrapping_sub(0); //~^ zst_offset - let sized = &1 as *const i32; sized.offset(0); } diff --git a/tests/ui/zero_offset.stderr b/tests/ui/zero_offset.stderr index 4dfde7d4e1b0..b69c7b92d56a 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 - --> tests/ui/zero_offset.rs:9:9 + --> tests/ui/zero_offset.rs:8:9 | LL | m.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:12:9 + --> tests/ui/zero_offset.rs:11:9 | LL | m.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:15:9 + --> tests/ui/zero_offset.rs:14:9 | LL | m.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:20:9 + --> tests/ui/zero_offset.rs:18:9 | LL | c.offset(0); | ^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:23:9 + --> tests/ui/zero_offset.rs:21:9 | LL | c.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:26:9 + --> tests/ui/zero_offset.rs:24:9 | LL | c.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> tests/ui/zero_offset.rs:29:9 + --> tests/ui/zero_offset.rs:27: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 ddcfce672bf9..cdeea15f28bc 100644 --- a/tests/ui/zero_sized_btreemap_values.rs +++ b/tests/ui/zero_sized_btreemap_values.rs @@ -5,32 +5,26 @@ const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; //~^ zero_sized_map_values - static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; //~^ zero_sized_map_values - type OkMap = BTreeMap; type NotOkMap = BTreeMap; //~^ zero_sized_map_values - enum TestEnum { Ok(BTreeMap), NotOk(BTreeMap), //~^ zero_sized_map_values - } struct Test { ok: BTreeMap, not_ok: BTreeMap, //~^ zero_sized_map_values - also_not_ok: Vec>, //~^ zero_sized_map_values - } trait TestTrait { @@ -40,7 +34,6 @@ trait TestTrait { fn weird_map(&self, map: BTreeMap); //~^ zero_sized_map_values - } impl Test { @@ -49,7 +42,7 @@ impl Test { } fn not_ok(&self) -> BTreeMap { - //~^ zero_sized_map_values + //~^ zero_sized_map_values todo!() } @@ -68,9 +61,8 @@ impl TestTrait for Test { } fn test(map: BTreeMap, key: &str) -> BTreeMap { -//~^ zero_sized_map_values -//~| zero_sized_map_values - + //~^ zero_sized_map_values + //~| zero_sized_map_values todo!(); } @@ -84,10 +76,8 @@ fn main() { //~^ zero_sized_map_values //~| zero_sized_map_values - let _: BTreeMap = BTreeMap::new(); let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); //~^ zero_sized_map_values - } diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index f9184dc9ae1f..40acb0b211f7 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -9,7 +9,7 @@ LL | const CONST_NOT_OK: Option> = None; = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:10:30 + --> tests/ui/zero_sized_btreemap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:15:17 + --> tests/ui/zero_sized_btreemap_values.rs:13:17 | LL | type NotOkMap = BTreeMap; | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | type NotOkMap = BTreeMap; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:21:11 + --> tests/ui/zero_sized_btreemap_values.rs:18:11 | LL | NotOk(BTreeMap), | ^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | NotOk(BTreeMap), = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:28:13 + --> tests/ui/zero_sized_btreemap_values.rs:24:13 | LL | not_ok: BTreeMap, | ^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | not_ok: BTreeMap, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:31:22 + --> tests/ui/zero_sized_btreemap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:41:30 + --> tests/ui/zero_sized_btreemap_values.rs:35:30 | LL | fn weird_map(&self, map: BTreeMap); | ^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | fn weird_map(&self, map: BTreeMap); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:51:25 + --> tests/ui/zero_sized_btreemap_values.rs:44:25 | LL | fn not_ok(&self) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | fn not_ok(&self) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:70:14 + --> tests/ui/zero_sized_btreemap_values.rs:63:14 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:70:50 + --> tests/ui/zero_sized_btreemap_values.rs:63:50 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:83:35 + --> tests/ui/zero_sized_btreemap_values.rs:75:35 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:83:12 + --> tests/ui/zero_sized_btreemap_values.rs:75:12 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_btreemap_values.rs:90:12 + --> tests/ui/zero_sized_btreemap_values.rs:81: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 132716da3b27..4beeef421f30 100644 --- a/tests/ui/zero_sized_hashmap_values.rs +++ b/tests/ui/zero_sized_hashmap_values.rs @@ -5,32 +5,26 @@ const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; //~^ zero_sized_map_values - static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; //~^ zero_sized_map_values - type OkMap = HashMap; type NotOkMap = HashMap; //~^ zero_sized_map_values - enum TestEnum { Ok(HashMap), NotOk(HashMap), //~^ zero_sized_map_values - } struct Test { ok: HashMap, not_ok: HashMap, //~^ zero_sized_map_values - also_not_ok: Vec>, //~^ zero_sized_map_values - } trait TestTrait { @@ -40,7 +34,6 @@ trait TestTrait { fn weird_map(&self, map: HashMap); //~^ zero_sized_map_values - } impl Test { @@ -49,7 +42,7 @@ impl Test { } fn not_ok(&self) -> HashMap { - //~^ zero_sized_map_values + //~^ zero_sized_map_values todo!() } @@ -68,9 +61,8 @@ impl TestTrait for Test { } fn test(map: HashMap, key: &str) -> HashMap { -//~^ zero_sized_map_values -//~| zero_sized_map_values - + //~^ zero_sized_map_values + //~| zero_sized_map_values todo!(); } @@ -84,10 +76,8 @@ fn main() { //~^ zero_sized_map_values //~| zero_sized_map_values - let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); //~^ zero_sized_map_values - } diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 059902047b55..ed8536acfe8f 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -9,7 +9,7 @@ LL | const CONST_NOT_OK: Option> = None; = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:10:30 + --> tests/ui/zero_sized_hashmap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:15:17 + --> tests/ui/zero_sized_hashmap_values.rs:13:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:21:11 + --> tests/ui/zero_sized_hashmap_values.rs:18:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:28:13 + --> tests/ui/zero_sized_hashmap_values.rs:24:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:31:22 + --> tests/ui/zero_sized_hashmap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:41:30 + --> tests/ui/zero_sized_hashmap_values.rs:35:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | fn weird_map(&self, map: HashMap); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:51:25 + --> tests/ui/zero_sized_hashmap_values.rs:44:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:70:14 + --> tests/ui/zero_sized_hashmap_values.rs:63:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:70:49 + --> tests/ui/zero_sized_hashmap_values.rs:63:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:83:34 + --> tests/ui/zero_sized_hashmap_values.rs:75:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^ @@ -89,7 +89,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:83:12 + --> tests/ui/zero_sized_hashmap_values.rs:75:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> tests/ui/zero_sized_hashmap_values.rs:90:12 + --> tests/ui/zero_sized_hashmap_values.rs:81:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ From a2c890fa0fd14273d98c160229184f02734a5800 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Feb 2025 00:10:26 +0100 Subject: [PATCH 090/161] Make fmt (weirdly) happy --- tests/ui/borrow_deref_ref.fixed | 3 +- tests/ui/borrow_deref_ref.rs | 3 +- tests/ui/cast.rs | 9 +- tests/ui/cast.stderr | 12 +- tests/ui/clone_on_copy.fixed | 3 +- tests/ui/clone_on_copy.rs | 3 +- tests/ui/cloned_instead_of_copied.fixed | 6 +- tests/ui/cloned_instead_of_copied.rs | 6 +- tests/ui/cloned_instead_of_copied.stderr | 4 +- tests/ui/collapsible_else_if.stderr | 154 ++++++++++ tests/ui/collapsible_if.stderr | 139 +++++++++ tests/ui/crashes/ice-5835.1.fixed | 11 + tests/ui/crashes/ice-5835.2.fixed | 13 + tests/ui/deref_by_slicing.fixed | 12 +- tests/ui/deref_by_slicing.rs | 12 +- tests/ui/deref_by_slicing.stderr | 10 +- tests/ui/eta.fixed | 9 +- tests/ui/eta.rs | 9 +- tests/ui/eta.stderr | 66 ++-- tests/ui/explicit_auto_deref.fixed | 9 +- tests/ui/explicit_auto_deref.rs | 9 +- tests/ui/explicit_auto_deref.stderr | 82 ++--- .../ui/literal_string_with_formatting_arg.rs | 3 +- tests/ui/manual_instant_elapsed.fixed | 3 +- tests/ui/manual_instant_elapsed.rs | 3 +- tests/ui/manual_slice_size_calculation.fixed | 24 +- tests/ui/manual_slice_size_calculation.rs | 24 +- tests/ui/manual_slice_size_calculation.stderr | 16 +- tests/ui/mistyped_literal_suffix.fixed | 21 +- tests/ui/mistyped_literal_suffix.rs | 21 +- tests/ui/mistyped_literal_suffix.stderr | 26 +- .../global_allow.stderr | 20 ++ tests/ui/needless_bool/simple.stderr | 45 +++ tests/ui/needless_bool_assign.stderr | 55 ++++ tests/ui/needless_borrow.fixed | 6 +- tests/ui/needless_borrow.rs | 6 +- tests/ui/needless_borrow.stderr | 54 ++-- .../needless_borrows_for_generic_args.fixed | 6 +- tests/ui/needless_borrows_for_generic_args.rs | 6 +- .../needless_borrows_for_generic_args.stderr | 2 +- tests/ui/needless_else.stderr | 13 + tests/ui/option_env_unwrap.rs | 3 +- tests/ui/option_env_unwrap.stderr | 8 +- tests/ui/or_fun_call.fixed | 9 +- tests/ui/or_fun_call.rs | 9 +- tests/ui/or_fun_call.stderr | 10 +- tests/ui/or_then_unwrap.fixed | 9 +- tests/ui/or_then_unwrap.rs | 9 +- tests/ui/or_then_unwrap.stderr | 4 +- .../redundant_pattern_matching_option.fixed | 3 +- tests/ui/redundant_pattern_matching_option.rs | 3 +- .../redundant_pattern_matching_option.stderr | 58 ++-- tests/ui/redundant_pub_crate.fixed | 39 ++- tests/ui/redundant_pub_crate.rs | 39 ++- tests/ui/redundant_pub_crate.stderr | 30 +- tests/ui/redundant_slicing.fixed | 6 +- tests/ui/redundant_slicing.rs | 6 +- tests/ui/redundant_slicing.stderr | 4 +- tests/ui/search_is_some_fixable_none.fixed | 3 +- tests/ui/search_is_some_fixable_none.rs | 3 +- tests/ui/search_is_some_fixable_none.stderr | 106 +++---- tests/ui/search_is_some_fixable_some.fixed | 3 +- tests/ui/search_is_some_fixable_some.rs | 3 +- tests/ui/search_is_some_fixable_some.stderr | 90 +++--- tests/ui/single_char_pattern.fixed | 6 +- tests/ui/single_char_pattern.rs | 6 +- tests/ui/single_char_pattern.stderr | 16 +- tests/ui/single_match.stderr | 282 ++++++++++++++++++ tests/ui/single_match_else.stderr | 211 +++++++++++++ tests/ui/suspicious_xor_used_as_pow.rs | 3 +- tests/ui/suspicious_xor_used_as_pow.stderr | 12 +- tests/ui/trim_split_whitespace.fixed | 24 +- tests/ui/trim_split_whitespace.rs | 24 +- tests/ui/trim_split_whitespace.stderr | 14 +- tests/ui/uninlined_format_args.fixed | 12 +- tests/ui/uninlined_format_args.rs | 12 +- tests/ui/uninlined_format_args.stderr | 146 ++++----- tests/ui/unnecessary_cast.fixed | 3 +- tests/ui/unnecessary_cast.rs | 3 +- tests/ui/unnecessary_cast.stderr | 4 +- tests/ui/unnecessary_literal_unwrap.fixed | 3 +- tests/ui/unnecessary_literal_unwrap.rs | 3 +- tests/ui/unnecessary_literal_unwrap.stderr | 10 +- tests/ui/use_self_trait.fixed | 3 +- tests/ui/use_self_trait.rs | 3 +- 85 files changed, 1647 insertions(+), 548 deletions(-) create mode 100644 tests/ui/collapsible_else_if.stderr create mode 100644 tests/ui/collapsible_if.stderr create mode 100644 tests/ui/crashes/ice-5835.1.fixed create mode 100644 tests/ui/crashes/ice-5835.2.fixed create mode 100644 tests/ui/mixed_attributes_style/global_allow.stderr create mode 100644 tests/ui/needless_bool/simple.stderr create mode 100644 tests/ui/needless_bool_assign.stderr create mode 100644 tests/ui/needless_else.stderr create mode 100644 tests/ui/single_match.stderr create mode 100644 tests/ui/single_match_else.stderr diff --git a/tests/ui/borrow_deref_ref.fixed b/tests/ui/borrow_deref_ref.fixed index 93cd3e3b5e59..17c224f10bfe 100644 --- a/tests/ui/borrow_deref_ref.fixed +++ b/tests/ui/borrow_deref_ref.fixed @@ -69,7 +69,8 @@ mod false_negative { let x = &12; let addr_x = &x as *const _ as usize; let addr_y = &x as *const _ as usize; // assert ok - //~^ borrow_deref_ref + // + //~^^ borrow_deref_ref // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); } diff --git a/tests/ui/borrow_deref_ref.rs b/tests/ui/borrow_deref_ref.rs index 1e41d24998f9..130ed2903dc6 100644 --- a/tests/ui/borrow_deref_ref.rs +++ b/tests/ui/borrow_deref_ref.rs @@ -69,7 +69,8 @@ mod false_negative { let x = &12; let addr_x = &x as *const _ as usize; let addr_y = &&*x as *const _ as usize; // assert ok - //~^ borrow_deref_ref + // + //~^^ borrow_deref_ref // let addr_y = &x as *const _ as usize; // assert fail assert_ne!(addr_x, addr_y); } diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 56e4326cdc1d..88c2549f4dc5 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -532,11 +532,14 @@ fn issue11738() { macro_rules! m { () => { let _ = i32::MIN as u32; // cast_sign_loss - //~^ cast_sign_loss + // + //~^^ cast_sign_loss let _ = u32::MAX as u8; // cast_possible_truncation - //~^ cast_possible_truncation + // + //~^^ cast_possible_truncation let _ = std::f64::consts::PI as f32; // cast_possible_truncation - //~^ cast_possible_truncation + // + //~^^ cast_possible_truncation let _ = 0i8 as i32; // cast_lossless }; } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index 484be7905d42..1c5ff52ae722 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -662,7 +662,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `u32` to `u8` may truncate the value - --> tests/ui/cast.rs:536:21 + --> tests/ui/cast.rs:537:21 | LL | let _ = u32::MAX as u8; // cast_possible_truncation | ^^^^^^^^^^^^^^ @@ -678,7 +678,7 @@ LL | let _ = u8::try_from(u32::MAX); // cast_possible_truncation | ~~~~~~~~~~~~~~~~~~~~~~ error: casting `f64` to `f32` may truncate the value - --> tests/ui/cast.rs:538:21 + --> tests/ui/cast.rs:540:21 | LL | let _ = std::f64::consts::PI as f32; // cast_possible_truncation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -690,7 +690,7 @@ LL | m!(); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast.rs:548:5 + --> tests/ui/cast.rs:551:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -702,13 +702,13 @@ LL | usize::try_from(bar.unwrap().unwrap()) | error: casting `i64` to `usize` may lose the sign of the value - --> tests/ui/cast.rs:548:5 + --> tests/ui/cast.rs:551:5 | LL | bar.unwrap().unwrap() as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:565:5 + --> tests/ui/cast.rs:568:5 | LL | (256 & 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL | u8::try_from(256 & 999999u64); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> tests/ui/cast.rs:568:5 + --> tests/ui/cast.rs:571:5 | LL | (255 % 999999u64) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/clone_on_copy.fixed b/tests/ui/clone_on_copy.fixed index f965aa5c182d..2dd8af152515 100644 --- a/tests/ui/clone_on_copy.fixed +++ b/tests/ui/clone_on_copy.fixed @@ -81,6 +81,7 @@ fn clone_on_copy() -> Option<(i32)> { // Issue #9277 let opt: &Option = &None; let value = (*opt)?; // operator precedence needed (*opt)? - //~^ clone_on_copy + // + //~^^ clone_on_copy None } diff --git a/tests/ui/clone_on_copy.rs b/tests/ui/clone_on_copy.rs index f6a542296de1..a371afb04a78 100644 --- a/tests/ui/clone_on_copy.rs +++ b/tests/ui/clone_on_copy.rs @@ -81,6 +81,7 @@ fn clone_on_copy() -> Option<(i32)> { // Issue #9277 let opt: &Option = &None; let value = opt.clone()?; // operator precedence needed (*opt)? - //~^ clone_on_copy + // + //~^^ clone_on_copy None } diff --git a/tests/ui/cloned_instead_of_copied.fixed b/tests/ui/cloned_instead_of_copied.fixed index 94784b4747e8..0a1a59ddf9b8 100644 --- a/tests/ui/cloned_instead_of_copied.fixed +++ b/tests/ui/cloned_instead_of_copied.fixed @@ -30,13 +30,15 @@ fn msrv_1_34() { fn msrv_1_35() { let _ = [1].iter().cloned(); let _ = Some(&1).copied(); // Option::copied needs 1.35 - //~^ cloned_instead_of_copied + // + //~^^ cloned_instead_of_copied } #[clippy::msrv = "1.36"] fn msrv_1_36() { let _ = [1].iter().copied(); // Iterator::copied needs 1.36 - //~^ cloned_instead_of_copied + // + //~^^ cloned_instead_of_copied let _ = Some(&1).copied(); //~^ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.rs b/tests/ui/cloned_instead_of_copied.rs index 54e01e369f9d..c452dd007a1e 100644 --- a/tests/ui/cloned_instead_of_copied.rs +++ b/tests/ui/cloned_instead_of_copied.rs @@ -30,13 +30,15 @@ fn msrv_1_34() { fn msrv_1_35() { let _ = [1].iter().cloned(); let _ = Some(&1).cloned(); // Option::copied needs 1.35 - //~^ cloned_instead_of_copied + // + //~^^ cloned_instead_of_copied } #[clippy::msrv = "1.36"] fn msrv_1_36() { let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 - //~^ cloned_instead_of_copied + // + //~^^ cloned_instead_of_copied let _ = Some(&1).cloned(); //~^ cloned_instead_of_copied } diff --git a/tests/ui/cloned_instead_of_copied.stderr b/tests/ui/cloned_instead_of_copied.stderr index 70ac0a767daf..bd741e41321b 100644 --- a/tests/ui/cloned_instead_of_copied.stderr +++ b/tests/ui/cloned_instead_of_copied.stderr @@ -38,13 +38,13 @@ LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:38:24 + --> tests/ui/cloned_instead_of_copied.rs:39:24 | LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> tests/ui/cloned_instead_of_copied.rs:40:22 + --> tests/ui/cloned_instead_of_copied.rs:42:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr new file mode 100644 index 000000000000..7d80894cadbb --- /dev/null +++ b/tests/ui/collapsible_else_if.stderr @@ -0,0 +1,154 @@ +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:11:12 + | +LL | } else { + | ____________^ +LL | | if y == "world" { +LL | | println!("world!") +LL | | } +LL | | } + | |_____^ + | + = note: `-D clippy::collapsible-else-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_else_if)]` +help: collapse nested if block + | +LL ~ } else if y == "world" { +LL + println!("world!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:20:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world!") +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:29:12 + | +LL | } else { + | ____________^ +LL | | if y == "world" { +LL | | println!("world") +... | +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if y == "world" { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:41:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +... | +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:53:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +... | +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:65:12 + | +LL | } else { + | ____________^ +LL | | if x == "hello" { +LL | | println!("world") +... | +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if x == "hello" { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:77:12 + | +LL | } else { + | ____________^ +LL | | if let Some(42) = Some(42) { +LL | | println!("world") +... | +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ } else if let Some(42) = Some(42) { +LL + println!("world") +LL + } +LL + else { +LL + println!("!") +LL + } + | + +error: this `else { if .. }` block can be collapsed + --> tests/ui/collapsible_else_if.rs:100:10 + | +LL | }else{ + | __________^ +LL | | if false {} +LL | | } + | |_____^ help: collapse nested if block: `if false {}` + +error: aborting due to 8 previous errors + diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr new file mode 100644 index 000000000000..3cc3fe5534f2 --- /dev/null +++ b/tests/ui/collapsible_if.stderr @@ -0,0 +1,139 @@ +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:15:5 + | +LL | / if x == "hello" { +LL | | if y == "world" { +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | + = note: `-D clippy::collapsible-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` +help: collapse nested if block + | +LL ~ if x == "hello" && y == "world" { +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:22:5 + | +LL | / if x == "hello" || x == "world" { +LL | | if y == "world" || y == "hello" { +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if (x == "hello" || x == "world") && (y == "world" || y == "hello") { +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:29:5 + | +LL | / if x == "hello" && x == "world" { +LL | | if y == "world" || y == "hello" { +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if x == "hello" && x == "world" && (y == "world" || y == "hello") { +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:36:5 + | +LL | / if x == "hello" || x == "world" { +LL | | if y == "world" && y == "hello" { +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if (x == "hello" || x == "world") && y == "world" && y == "hello" { +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:43:5 + | +LL | / if x == "hello" && x == "world" { +LL | | if y == "world" && y == "hello" { +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if x == "hello" && x == "world" && y == "world" && y == "hello" { +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:50:5 + | +LL | / if 42 == 1337 { +LL | | if 'a' != 'A' { +LL | | println!("world!") +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if 42 == 1337 && 'a' != 'A' { +LL + println!("world!") +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:107:5 + | +LL | / if x == "hello" { +LL | | if y == "world" { // Collapsible +LL | | println!("Hello world!"); +LL | | } +LL | | } + | |_____^ + | +help: collapse nested if block + | +LL ~ if x == "hello" && y == "world" { // Collapsible +LL + println!("Hello world!"); +LL + } + | + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:167:5 + | +LL | / if matches!(true, true) { +LL | | if matches!(true, true) {} +LL | | } + | |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}` + +error: this `if` statement can be collapsed + --> tests/ui/collapsible_if.rs:173:5 + | +LL | / if matches!(true, true) && truth() { +LL | | if matches!(true, true) {} +LL | | } + | |_____^ help: collapse nested if block: `if matches!(true, true) && truth() && matches!(true, true) {}` + +error: aborting due to 9 previous errors + diff --git a/tests/ui/crashes/ice-5835.1.fixed b/tests/ui/crashes/ice-5835.1.fixed new file mode 100644 index 000000000000..acd61a9bd6c3 --- /dev/null +++ b/tests/ui/crashes/ice-5835.1.fixed @@ -0,0 +1,11 @@ +#[rustfmt::skip] +pub struct Foo { + /// 位 + //~^ tabs_in_doc_comments + //~| empty_line_after_doc_comments + /// ^ 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-5835.2.fixed b/tests/ui/crashes/ice-5835.2.fixed new file mode 100644 index 000000000000..71d2ec0c0018 --- /dev/null +++ b/tests/ui/crashes/ice-5835.2.fixed @@ -0,0 +1,13 @@ +#[rustfmt::skip] +pub struct Foo { + // /// 位 + //~^ tabs_in_doc_comments + //~| empty_line_after_doc_comments + + + /// ^ Do not remove this tab character. + /// It was required to trigger the ICE. + pub bar: u8, +} + +fn main() {} diff --git a/tests/ui/deref_by_slicing.fixed b/tests/ui/deref_by_slicing.fixed index 78a8f292bc9a..ba03904040b4 100644 --- a/tests/ui/deref_by_slicing.fixed +++ b/tests/ui/deref_by_slicing.fixed @@ -16,7 +16,8 @@ fn main() { let mut_slice = &mut **ref_vec; //~^ deref_by_slicing let _ = &mut *mut_slice; // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let s = String::new(); let _ = &*s; @@ -24,16 +25,19 @@ fn main() { static S: &[u8] = &[0, 1, 2]; let _ = &mut &*S; // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; let _ = *slice_ref; // Err, derefs slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let bytes: &[u8] = &[]; let _ = (&*bytes).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing // issue 12751 let a = &mut [1, 2, 3][..]; diff --git a/tests/ui/deref_by_slicing.rs b/tests/ui/deref_by_slicing.rs index 205cad63ddac..fdaac9467f86 100644 --- a/tests/ui/deref_by_slicing.rs +++ b/tests/ui/deref_by_slicing.rs @@ -16,7 +16,8 @@ fn main() { let mut_slice = &mut ref_vec[..]; //~^ deref_by_slicing let _ = &mut mut_slice[..]; // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let s = String::new(); let _ = &s[..]; @@ -24,16 +25,19 @@ fn main() { static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let slice: &[u32] = &[0u32, 1u32]; let slice_ref = &slice; let _ = &slice_ref[..]; // Err, derefs slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing let bytes: &[u8] = &[]; let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice - //~^ deref_by_slicing + // + //~^^ deref_by_slicing // issue 12751 let a = &mut [1, 2, 3][..]; diff --git a/tests/ui/deref_by_slicing.stderr b/tests/ui/deref_by_slicing.stderr index a1fda3b3ec50..4a379a83dfa7 100644 --- a/tests/ui/deref_by_slicing.stderr +++ b/tests/ui/deref_by_slicing.stderr @@ -32,31 +32,31 @@ LL | let _ = &mut mut_slice[..]; // Err, re-borrows slice | ^^^^^^^^^^^^^^^^^^ help: reborrow the original value instead: `&mut *mut_slice` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:22:13 + --> tests/ui/deref_by_slicing.rs:23:13 | LL | let _ = &s[..]; | ^^^^^^ help: dereference the original value instead: `&*s` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:26:18 + --> tests/ui/deref_by_slicing.rs:27:18 | LL | let _ = &mut &S[..]; // Err, re-borrows slice | ^^^^^^ help: reborrow the original value instead: `&*S` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:31:13 + --> tests/ui/deref_by_slicing.rs:33:13 | LL | let _ = &slice_ref[..]; // Err, derefs slice | ^^^^^^^^^^^^^^ help: dereference the original value instead: `*slice_ref` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:35:13 + --> tests/ui/deref_by_slicing.rs:38:13 | LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` error: slicing when dereferencing would work - --> tests/ui/deref_by_slicing.rs:40:13 + --> tests/ui/deref_by_slicing.rs:44:13 | LL | let _ = &a[..]; | ^^^^^^ help: reborrow the original value instead: `&*a` diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index 2be5c7d2b4b0..0ba631fda051 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -34,11 +34,14 @@ fn main() { true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion let _: Option> = true.then(std::vec::Vec::new); // special case vec! - //~^ redundant_closure + // + //~^^ redundant_closure let d = Some(1u8).map(|a| foo(foo2(a))); //is adjusted? - //~^ redundant_closure + // + //~^^ redundant_closure all(&[1, 2, 3], &&2, below); //is adjusted - //~^ redundant_closure + // + //~^^ redundant_closure unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 7c9a92306b95..4d8b29d450c5 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -34,11 +34,14 @@ fn main() { true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion let _: Option> = true.then(|| vec![]); // special case vec! - //~^ redundant_closure + // + //~^^ redundant_closure let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? - //~^ redundant_closure + // + //~^^ redundant_closure all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted - //~^ redundant_closure + // + //~^^ redundant_closure unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 434a034a4f8e..8bc08add2fab 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -14,25 +14,25 @@ LL | let _: Option> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> tests/ui/eta.rs:38:35 + --> tests/ui/eta.rs:39: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 - --> tests/ui/eta.rs:40:26 + --> tests/ui/eta.rs:42: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 - --> tests/ui/eta.rs:48:27 + --> tests/ui/eta.rs:51:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> tests/ui/eta.rs:101:51 + --> tests/ui/eta.rs:104:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -41,175 +41,175 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure - --> tests/ui/eta.rs:103:51 + --> tests/ui/eta.rs:106: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 - --> tests/ui/eta.rs:106:42 + --> tests/ui/eta.rs:109: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 - --> tests/ui/eta.rs:111:29 + --> tests/ui/eta.rs:114: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 - --> tests/ui/eta.rs:113:27 + --> tests/ui/eta.rs:116: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 - --> tests/ui/eta.rs:116:65 + --> tests/ui/eta.rs:119: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 - --> tests/ui/eta.rs:133:23 + --> tests/ui/eta.rs:136:23 | LL | let _ = x.map(|x| x.parse::()); | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `str::parse::` error: redundant closure - --> tests/ui/eta.rs:186:22 + --> tests/ui/eta.rs:189:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> tests/ui/eta.rs:194:27 + --> tests/ui/eta.rs:197:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> tests/ui/eta.rs:200:27 + --> tests/ui/eta.rs:203:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> tests/ui/eta.rs:233:28 + --> tests/ui/eta.rs:236: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 - --> tests/ui/eta.rs:235:28 + --> tests/ui/eta.rs:238: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 - --> tests/ui/eta.rs:237:28 + --> tests/ui/eta.rs:240: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 - --> tests/ui/eta.rs:245:21 + --> tests/ui/eta.rs:248:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> tests/ui/eta.rs:250:21 + --> tests/ui/eta.rs:253:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> tests/ui/eta.rs:344:18 + --> tests/ui/eta.rs:347:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:348:19 + --> tests/ui/eta.rs:351:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:353:26 + --> tests/ui/eta.rs:356:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> tests/ui/eta.rs:366:19 + --> tests/ui/eta.rs:369:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> tests/ui/eta.rs:370:19 + --> tests/ui/eta.rs:373:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> tests/ui/eta.rs:374:17 + --> tests/ui/eta.rs:377:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> tests/ui/eta.rs:379:17 + --> tests/ui/eta.rs:382:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `::method_on_dyn` error: redundant closure - --> tests/ui/eta.rs:440:19 + --> tests/ui/eta.rs:443:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> tests/ui/eta.rs:469:22 + --> tests/ui/eta.rs:472:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> tests/ui/eta.rs:474:22 + --> tests/ui/eta.rs:477:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> tests/ui/eta.rs:488:18 + --> tests/ui/eta.rs:491:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> tests/ui/eta.rs:496:30 + --> tests/ui/eta.rs:499:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` error: redundant closure - --> tests/ui/eta.rs:516:38 + --> tests/ui/eta.rs:519:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `&f` error: redundant closure - --> tests/ui/eta.rs:521:38 + --> tests/ui/eta.rs:524:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` error: redundant closure - --> tests/ui/eta.rs:539:35 + --> tests/ui/eta.rs:542:35 | LL | let _field = bind.or_else(|| get_default()).unwrap(); | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default` diff --git a/tests/ui/explicit_auto_deref.fixed b/tests/ui/explicit_auto_deref.fixed index c7edf33012e0..7235f7d5b82a 100644 --- a/tests/ui/explicit_auto_deref.fixed +++ b/tests/ui/explicit_auto_deref.fixed @@ -81,7 +81,8 @@ fn main() { f_ref_t(&*s); // Don't lint. Inferred type would change. f_str_t(&s, &*s); // Don't lint second param. - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref let b = Box::new(Box::new(Box::new(5))); let _: &Box = &b; @@ -239,9 +240,11 @@ fn main() { } f_str(&ref_str); // `needless_borrow` will suggest removing both references - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref f_str(&ref_str); // `needless_borrow` will suggest removing only one reference - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref let x = &&40; unsafe { diff --git a/tests/ui/explicit_auto_deref.rs b/tests/ui/explicit_auto_deref.rs index 4d2b2fc3fc39..c4d2b28ff4b5 100644 --- a/tests/ui/explicit_auto_deref.rs +++ b/tests/ui/explicit_auto_deref.rs @@ -81,7 +81,8 @@ fn main() { f_ref_t(&*s); // Don't lint. Inferred type would change. f_str_t(&*s, &*s); // Don't lint second param. - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref let b = Box::new(Box::new(Box::new(5))); let _: &Box = &**b; @@ -239,9 +240,11 @@ fn main() { } f_str(&&*ref_str); // `needless_borrow` will suggest removing both references - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference - //~^ explicit_auto_deref + // + //~^^ explicit_auto_deref let x = &&40; unsafe { diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index e1cfb214864f..ba4cd86e0b5a 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -32,247 +32,247 @@ LL | f_str_t(&*s, &*s); // Don't lint second param. | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:87:24 + --> tests/ui/explicit_auto_deref.rs:88:24 | LL | let _: &Box = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:94:7 + --> tests/ui/explicit_auto_deref.rs:95:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:101:9 + --> tests/ui/explicit_auto_deref.rs:102:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:106:11 + --> tests/ui/explicit_auto_deref.rs:107:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:111:9 + --> tests/ui/explicit_auto_deref.rs:112:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:116:9 + --> tests/ui/explicit_auto_deref.rs:117:9 | LL | &***x | ^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:134:12 + --> tests/ui/explicit_auto_deref.rs:135:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:136:12 + --> tests/ui/explicit_auto_deref.rs:137:12 | LL | f2(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:138:12 + --> tests/ui/explicit_auto_deref.rs:139:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:140:27 + --> tests/ui/explicit_auto_deref.rs:141:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:142:12 + --> tests/ui/explicit_auto_deref.rs:143:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:144:12 + --> tests/ui/explicit_auto_deref.rs:145:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:146:27 + --> tests/ui/explicit_auto_deref.rs:147:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:148:25 + --> tests/ui/explicit_auto_deref.rs:149:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:150:12 + --> tests/ui/explicit_auto_deref.rs:151:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:152:13 + --> tests/ui/explicit_auto_deref.rs:153:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:154:26 + --> tests/ui/explicit_auto_deref.rs:155:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:159:16 + --> tests/ui/explicit_auto_deref.rs:160:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:165:21 + --> tests/ui/explicit_auto_deref.rs:166:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:182:30 + --> tests/ui/explicit_auto_deref.rs:183:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:184:35 + --> tests/ui/explicit_auto_deref.rs:185:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:188:20 + --> tests/ui/explicit_auto_deref.rs:189:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:190:25 + --> tests/ui/explicit_auto_deref.rs:191:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:209:13 + --> tests/ui/explicit_auto_deref.rs:210:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:211:13 + --> tests/ui/explicit_auto_deref.rs:212:13 | LL | let _ = (**b).foo; | ^^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:227:19 + --> tests/ui/explicit_auto_deref.rs:228:19 | LL | let _ = f_str(*ref_str); | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:230:19 + --> tests/ui/explicit_auto_deref.rs:231:19 | LL | let _ = f_str(**ref_ref_str); | ^^^^^^^^^^^^^ help: try: `ref_ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:241:12 + --> tests/ui/explicit_auto_deref.rs:242:12 | 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 - --> tests/ui/explicit_auto_deref.rs:243:12 + --> tests/ui/explicit_auto_deref.rs:245: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 - --> tests/ui/explicit_auto_deref.rs:253:41 + --> tests/ui/explicit_auto_deref.rs:256:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:273:9 + --> tests/ui/explicit_auto_deref.rs:276:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:297:8 + --> tests/ui/explicit_auto_deref.rs:300:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:301:20 + --> tests/ui/explicit_auto_deref.rs:304:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:304:9 + --> tests/ui/explicit_auto_deref.rs:307:9 | LL | *x | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:339:20 + --> tests/ui/explicit_auto_deref.rs:342:20 | LL | Some(x) => &mut *x, | ^^^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:373:22 + --> tests/ui/explicit_auto_deref.rs:376:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:380:22 + --> tests/ui/explicit_auto_deref.rs:383:22 | LL | let _ = &mut (**x.u).x; | ^^^^^^^ help: try: `(*x.u)` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:382:22 + --> tests/ui/explicit_auto_deref.rs:385:22 | LL | let _ = &mut (**{ x.u }).x; | ^^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:387:22 + --> tests/ui/explicit_auto_deref.rs:390:22 | LL | let _ = &mut (*x.u).x; | ^^^^^^ help: try: `x.u` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:389:22 + --> tests/ui/explicit_auto_deref.rs:392:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:413:13 + --> tests/ui/explicit_auto_deref.rs:416:13 | LL | foo(&*wrapped_bar); | ^^^^^^^^^^^^^ help: try: `&wrapped_bar` diff --git a/tests/ui/literal_string_with_formatting_arg.rs b/tests/ui/literal_string_with_formatting_arg.rs index b6f865b1ef28..d54cceae53eb 100644 --- a/tests/ui/literal_string_with_formatting_arg.rs +++ b/tests/ui/literal_string_with_formatting_arg.rs @@ -52,7 +52,8 @@ fn main() { x.expect("{{y:?}"); x.expect(" {0}"); // If it only contains an integer, we ignore it. x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint - //~^ literal_string_with_formatting_args + // + //~^^ literal_string_with_formatting_args x.expect("{y:...}"); let _ = "fn main {\n\ }"; diff --git a/tests/ui/manual_instant_elapsed.fixed b/tests/ui/manual_instant_elapsed.fixed index 4ef22002226e..187802bb76c9 100644 --- a/tests/ui/manual_instant_elapsed.fixed +++ b/tests/ui/manual_instant_elapsed.fixed @@ -25,5 +25,6 @@ fn main() { let ref_to_instant = &Instant::now(); (*ref_to_instant).elapsed(); // to ensure parens are added correctly - //~^ manual_instant_elapsed + // + //~^^ manual_instant_elapsed } diff --git a/tests/ui/manual_instant_elapsed.rs b/tests/ui/manual_instant_elapsed.rs index 4586b33cf880..61e14e5a3d9d 100644 --- a/tests/ui/manual_instant_elapsed.rs +++ b/tests/ui/manual_instant_elapsed.rs @@ -25,5 +25,6 @@ fn main() { let ref_to_instant = &Instant::now(); Instant::now() - *ref_to_instant; // to ensure parens are added correctly - //~^ manual_instant_elapsed + // + //~^^ manual_instant_elapsed } diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 91ada0b75d5c..294d1e1506de 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -15,24 +15,32 @@ fn main() { // True positives: let _ = std::mem::size_of_val(s_i32); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32) * 5; // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(*s_i32_ref); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(**s_i32_ref_ref); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let len = s_i32.len(); let size = size_of::(); let _ = std::mem::size_of_val(s_i32); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(s_i32); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = std::mem::size_of_val(external!(&[1u64][..])); //~^ manual_slice_size_calculation diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index 0ef3793619c4..ae5225663139 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -15,24 +15,32 @@ fn main() { // True positives: let _ = s_i32.len() * size_of::(); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = size_of::() * s_i32.len(); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = size_of::() * s_i32.len() * 5; // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = size_of::() * s_i32_ref.len(); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = size_of::() * s_i32_ref_ref.len(); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let len = s_i32.len(); let size = size_of::(); let _ = len * size_of::(); // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = s_i32.len() * size; // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = len * size; // WARNING - //~^ manual_slice_size_calculation + // + //~^^ manual_slice_size_calculation let _ = external!(&[1u64][..]).len() * size_of::(); //~^ manual_slice_size_calculation diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index d752e8356aa8..f07e97a1c863 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -8,49 +8,49 @@ LL | let _ = s_i32.len() * size_of::(); // WARNING = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:19:13 + --> tests/ui/manual_slice_size_calculation.rs:20:13 | LL | let _ = size_of::() * s_i32.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:21:13 + --> tests/ui/manual_slice_size_calculation.rs:23:13 | LL | let _ = size_of::() * s_i32.len() * 5; // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:23:13 + --> tests/ui/manual_slice_size_calculation.rs:26:13 | LL | let _ = size_of::() * s_i32_ref.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(*s_i32_ref)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:25:13 + --> tests/ui/manual_slice_size_calculation.rs:29:13 | LL | let _ = size_of::() * s_i32_ref_ref.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(**s_i32_ref_ref)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:30:13 + --> tests/ui/manual_slice_size_calculation.rs:35:13 | LL | let _ = len * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:32:13 + --> tests/ui/manual_slice_size_calculation.rs:38:13 | LL | let _ = s_i32.len() * size; // WARNING | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:34:13 + --> tests/ui/manual_slice_size_calculation.rs:41:13 | LL | let _ = len * size; // WARNING | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:37:13 + --> tests/ui/manual_slice_size_calculation.rs:45:13 | LL | let _ = external!(&[1u64][..]).len() * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index 50ef32e47c03..a0190acc5d4b 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -18,15 +18,19 @@ fn main() { let fail15 = 4_i64; //~^ mistyped_literal_suffixes let fail16 = 7_i8; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail17 = 23_i16; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok18 = 23_128; let fail20 = 2_i8; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail21 = 4_i16; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok24 = 12.34_64; let fail25 = 1E2_f32; @@ -41,9 +45,11 @@ fn main() { // testing that the suggestion actually fits in its type let fail30 = 127_i8; // should be i8 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail31 = 240_u8; // should be u8 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok32 = 360_8; // doesn't fit in either, should be ignored let fail33 = 0x1234_i16; //~^ mistyped_literal_suffixes @@ -51,7 +57,8 @@ fn main() { //~^ mistyped_literal_suffixes let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_u64; // u64 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes // issue #6129 let ok37 = 123_32.123; diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index 92f827608b10..12a26204e755 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -18,15 +18,19 @@ fn main() { let fail15 = 4_64; //~^ mistyped_literal_suffixes let fail16 = 7_8; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail17 = 23_16; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok18 = 23_128; let fail20 = 2__8; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail21 = 4___16; // - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok24 = 12.34_64; let fail25 = 1E2_32; @@ -41,9 +45,11 @@ fn main() { // testing that the suggestion actually fits in its type let fail30 = 127_8; // should be i8 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let fail31 = 240_8; // should be u8 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes let ok32 = 360_8; // doesn't fit in either, should be ignored let fail33 = 0x1234_16; //~^ mistyped_literal_suffixes @@ -51,7 +57,8 @@ fn main() { //~^ mistyped_literal_suffixes let ok35 = 0x12345_16; let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 - //~^ mistyped_literal_suffixes + // + //~^^ mistyped_literal_suffixes // issue #6129 let ok37 = 123_32.123; diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index 2fb3012b84f6..9c6b2fab21c3 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -19,79 +19,79 @@ LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:22:18 + --> tests/ui/mistyped_literal_suffix.rs:23:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:26:18 + --> tests/ui/mistyped_literal_suffix.rs:28:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:28:18 + --> tests/ui/mistyped_literal_suffix.rs:31:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:32:18 + --> tests/ui/mistyped_literal_suffix.rs:36:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:34:18 + --> tests/ui/mistyped_literal_suffix.rs:38:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:36:18 + --> tests/ui/mistyped_literal_suffix.rs:40:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:38:18 + --> tests/ui/mistyped_literal_suffix.rs:42:18 | LL | let fail28 = 241251235E723_64; | ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:43:18 + --> tests/ui/mistyped_literal_suffix.rs:47:18 | LL | let fail30 = 127_8; // should be i8 | ^^^^^ help: did you mean to write: `127_i8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:45:18 + --> tests/ui/mistyped_literal_suffix.rs:50:18 | LL | let fail31 = 240_8; // should be u8 | ^^^^^ help: did you mean to write: `240_u8` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:48:18 + --> tests/ui/mistyped_literal_suffix.rs:54:18 | LL | let fail33 = 0x1234_16; | ^^^^^^^^^ help: did you mean to write: `0x1234_i16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:50:18 + --> tests/ui/mistyped_literal_suffix.rs:56:18 | LL | let fail34 = 0xABCD_16; | ^^^^^^^^^ help: did you mean to write: `0xABCD_u16` error: mistyped literal suffix - --> tests/ui/mistyped_literal_suffix.rs:53:18 + --> tests/ui/mistyped_literal_suffix.rs:59: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 - --> tests/ui/mistyped_literal_suffix.rs:60:13 + --> tests/ui/mistyped_literal_suffix.rs:67:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` diff --git a/tests/ui/mixed_attributes_style/global_allow.stderr b/tests/ui/mixed_attributes_style/global_allow.stderr new file mode 100644 index 000000000000..5fc1d2ac0c3e --- /dev/null +++ b/tests/ui/mixed_attributes_style/global_allow.stderr @@ -0,0 +1,20 @@ +error: empty line after outer attribute + --> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1 + | +LL | / #[allow(unused)] +LL | | +LL | | + | |_^ +LL | mod foo { + | ------- the attribute applies to this module + | + = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` + = help: if the empty line is unintentional remove it +help: if the attribute should apply to the parent module use an inner attribute + | +LL | #![allow(unused)] + | + + +error: aborting due to 1 previous error + diff --git a/tests/ui/needless_bool/simple.stderr b/tests/ui/needless_bool/simple.stderr new file mode 100644 index 000000000000..077e9b5df47c --- /dev/null +++ b/tests/ui/needless_bool/simple.stderr @@ -0,0 +1,45 @@ +error: this if-then-else expression will always return true + --> tests/ui/needless_bool/simple.rs:14:5 + | +LL | / if x { +LL | | true +LL | | } else { +LL | | true +LL | | }; + | |_____^ + | + = note: `-D clippy::needless-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` + +error: this if-then-else expression will always return false + --> tests/ui/needless_bool/simple.rs:20:5 + | +LL | / if x { +LL | | false +LL | | } else { +LL | | false +LL | | }; + | |_____^ + +error: this if-then-else expression will always return true + --> tests/ui/needless_bool/simple.rs:36:5 + | +LL | / if x { +LL | | return true; +LL | | } else { +LL | | return true; +LL | | }; + | |_____^ + +error: this if-then-else expression will always return false + --> tests/ui/needless_bool/simple.rs:45:5 + | +LL | / if x { +LL | | return false; +LL | | } else { +LL | | return false; +LL | | }; + | |_____^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/needless_bool_assign.stderr b/tests/ui/needless_bool_assign.stderr new file mode 100644 index 000000000000..f33a4bc0c592 --- /dev/null +++ b/tests/ui/needless_bool_assign.stderr @@ -0,0 +1,55 @@ +error: this if-then-else expression assigns a bool literal + --> tests/ui/needless_bool_assign.rs:13:5 + | +LL | / if random() && random() { +LL | | a.field = true; +LL | | } else { +LL | | a.field = false +LL | | } + | |_____^ help: you can reduce it to: `a.field = random() && random();` + | + = note: `-D clippy::needless-bool-assign` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool_assign)]` + +error: this if-then-else expression assigns a bool literal + --> tests/ui/needless_bool_assign.rs:19:5 + | +LL | / if random() && random() { +LL | | a.field = false; +LL | | } else { +LL | | a.field = true +LL | | } + | |_____^ help: you can reduce it to: `a.field = !(random() && random());` + +error: this if-then-else expression assigns a bool literal + --> tests/ui/needless_bool_assign.rs:34:5 + | +LL | / if random() { +LL | | a.field = true; +LL | | } else { +LL | | a.field = true; +LL | | } + | |_____^ help: you can reduce it to: `random(); a.field = true;` + +error: this `if` has identical blocks + --> tests/ui/needless_bool_assign.rs:34:17 + | +LL | if random() { + | _________________^ +LL | | a.field = true; +LL | | } else { + | |_____^ + | +note: same as this + --> tests/ui/needless_bool_assign.rs:36:12 + | +LL | } else { + | ____________^ +LL | | a.field = true; +LL | | } + | |_____^ + = note: `-D clippy::if-same-then-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 7bd42d17f3a4..d7d344452c5d 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -14,12 +14,14 @@ fn main() { let ref_a = &a; let _ = x(&a); // no warning let _ = x(&a); // warn - //~^ needless_borrow + // + //~^^ needless_borrow let mut b = 5; mut_ref(&mut b); // no warning mut_ref(&mut b); // warn - //~^ needless_borrow + // + //~^^ needless_borrow let s = &String::from("hi"); let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index a5b337140b5b..1f05b90b4728 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -14,12 +14,14 @@ fn main() { let ref_a = &a; let _ = x(&a); // no warning let _ = x(&&a); // warn - //~^ needless_borrow + // + //~^^ needless_borrow let mut b = 5; mut_ref(&mut b); // no warning mut_ref(&mut &mut b); // warn - //~^ needless_borrow + // + //~^^ needless_borrow let s = &String::from("hi"); let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index b574948962de..b036b1e47d18 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:21:13 + --> tests/ui/needless_borrow.rs:22:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:34:13 + --> tests/ui/needless_borrow.rs:36:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:37:15 + --> tests/ui/needless_borrow.rs:39:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:44:27 + --> tests/ui/needless_borrow.rs:46:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:52:15 + --> tests/ui/needless_borrow.rs:54:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:54:15 + --> tests/ui/needless_borrow.rs:56:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:56:15 + --> tests/ui/needless_borrow.rs:58:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:58:15 + --> tests/ui/needless_borrow.rs:60:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:62:11 + --> tests/ui/needless_borrow.rs:64:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:70:13 + --> tests/ui/needless_borrow.rs:72:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:72:13 + --> tests/ui/needless_borrow.rs:74:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:74:23 + --> tests/ui/needless_borrow.rs:76:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:76:23 + --> tests/ui/needless_borrow.rs:78:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:86:14 + --> tests/ui/needless_borrow.rs:88:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:93:14 + --> tests/ui/needless_borrow.rs:95:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:106:13 + --> tests/ui/needless_borrow.rs:108:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:109:22 + --> tests/ui/needless_borrow.rs:111:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:120:5 + --> tests/ui/needless_borrow.rs:122:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:130:5 + --> tests/ui/needless_borrow.rs:132:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:157:23 + --> tests/ui/needless_borrow.rs:159:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:200:13 + --> tests/ui/needless_borrow.rs:202:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:210:13 + --> tests/ui/needless_borrow.rs:212:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:248:22 + --> tests/ui/needless_borrow.rs:250:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:256:22 + --> tests/ui/needless_borrow.rs:258:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:261:22 + --> tests/ui/needless_borrow.rs:263:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:263:22 + --> tests/ui/needless_borrow.rs:265:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:285:23 + --> tests/ui/needless_borrow.rs:287:23 | LL | option.unwrap_or((&x.0,)); | ^^^^ help: change this to: `x.0` diff --git a/tests/ui/needless_borrows_for_generic_args.fixed b/tests/ui/needless_borrows_for_generic_args.fixed index 374caeacfd28..8dea0d259772 100644 --- a/tests/ui/needless_borrows_for_generic_args.fixed +++ b/tests/ui/needless_borrows_for_generic_args.fixed @@ -338,11 +338,13 @@ fn main() { let x = String::new(); f(&x); // Don't lint, not a copy, makes it unavailable later f(String::new()); // Lint, makes no difference - //~^ needless_borrows_for_generic_args + // + //~^^ needless_borrows_for_generic_args let y = "".to_owned(); f(&y); // Don't lint f("".to_owned()); // Lint - //~^ needless_borrows_for_generic_args + // + //~^^ needless_borrows_for_generic_args } { fn takes_writer(_: T) {} diff --git a/tests/ui/needless_borrows_for_generic_args.rs b/tests/ui/needless_borrows_for_generic_args.rs index 06e2a4505211..bc2db6774e96 100644 --- a/tests/ui/needless_borrows_for_generic_args.rs +++ b/tests/ui/needless_borrows_for_generic_args.rs @@ -338,11 +338,13 @@ fn main() { let x = String::new(); f(&x); // Don't lint, not a copy, makes it unavailable later f(&String::new()); // Lint, makes no difference - //~^ needless_borrows_for_generic_args + // + //~^^ needless_borrows_for_generic_args let y = "".to_owned(); f(&y); // Don't lint f(&"".to_owned()); // Lint - //~^ needless_borrows_for_generic_args + // + //~^^ needless_borrows_for_generic_args } { fn takes_writer(_: T) {} diff --git a/tests/ui/needless_borrows_for_generic_args.stderr b/tests/ui/needless_borrows_for_generic_args.stderr index 6b5a0b4b1b67..8829854e3073 100644 --- a/tests/ui/needless_borrows_for_generic_args.stderr +++ b/tests/ui/needless_borrows_for_generic_args.stderr @@ -62,7 +62,7 @@ LL | f(&String::new()); // Lint, makes no difference | ^^^^^^^^^^^^^^ help: change this to: `String::new()` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:344:11 + --> tests/ui/needless_borrows_for_generic_args.rs:345:11 | LL | f(&"".to_owned()); // Lint | ^^^^^^^^^^^^^^ help: change this to: `"".to_owned()` diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr new file mode 100644 index 000000000000..77ead31b31cc --- /dev/null +++ b/tests/ui/needless_else.stderr @@ -0,0 +1,13 @@ +error: this `else` branch is empty + --> tests/ui/needless_else.rs:23:7 + | +LL | } else { + | _______^ +LL | | } + | |_____^ help: you can remove it + | + = note: `-D clippy::needless-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_else)]` + +error: aborting due to 1 previous error + diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index f5e57284df49..b8476830efe5 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -12,7 +12,8 @@ fn main() { let _ = option_env!("PATH").expect("environment variable PATH isn't set"); //~^ option_env_unwrap let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment. - //~^ option_env_unwrap + // + //~^^ option_env_unwrap let _ = inline!(option_env!($"PATH").unwrap()); //~^ option_env_unwrap let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index cee0fe6bf9ae..bbcbfedb7882 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -25,7 +25,7 @@ LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only work = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:16:21 + --> tests/ui/option_env_unwrap.rs:17:21 | LL | let _ = inline!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = inline!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:18:21 + --> tests/ui/option_env_unwrap.rs:19:21 | LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:20:13 + --> tests/ui/option_env_unwrap.rs:21:13 | LL | let _ = external!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = external!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:22:13 + --> tests/ui/option_env_unwrap.rs:23:13 | LL | let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 7014e20c1f85..1794ac57fe5b 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -374,11 +374,13 @@ fn fn_call_in_nested_expr() { let opt: Option = Some(1); let _ = opt.unwrap_or_else(f); // suggest `.unwrap_or_else(f)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or_else(|| f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or_else(|| { @@ -388,7 +390,8 @@ fn fn_call_in_nested_expr() { }); let _ = opt.map_or_else(|| f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or_default(); diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index d8a0ab033c4d..256db343c057 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -374,11 +374,13 @@ fn fn_call_in_nested_expr() { let opt: Option = Some(1); let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or({ @@ -388,7 +390,8 @@ fn fn_call_in_nested_expr() { }); let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` - //~^ or_fun_call + // + //~^^ or_fun_call // let _ = opt.unwrap_or({ i32::default() }); diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 0cc8ad39421c..93c87b2f12cd 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -203,13 +203,13 @@ LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:380:17 + --> tests/ui/or_fun_call.rs:381:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:384:17 + --> tests/ui/or_fun_call.rs:386:17 | LL | let _ = opt.unwrap_or({ | _________________^ @@ -229,19 +229,19 @@ LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:390:17 + --> tests/ui/or_fun_call.rs:392:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| f() + 1, |v| v)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:394:17 + --> tests/ui/or_fun_call.rs:397:17 | LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:401:21 + --> tests/ui/or_fun_call.rs:404:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index 19db0e47279c..ba9beef57afa 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -20,16 +20,19 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; let _ = option.unwrap_or("fallback"); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap let result: Result<&str, &str> = Err("Error"); let _ = result.unwrap_or("fallback"); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap // as part of a method chain let option: Option<&str> = None; let _ = option.map(|v| v).unwrap_or("fallback").to_string().chars(); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap // Not Option/Result let instance = SomeStruct {}; diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index 7af03b523f73..fac90249a243 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -20,16 +20,19 @@ impl SomeOtherStruct { fn main() { let option: Option<&str> = None; let _ = option.or(Some("fallback")).unwrap(); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap let result: Result<&str, &str> = Err("Error"); let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap // as part of a method chain let option: Option<&str> = None; let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint - //~^ or_then_unwrap + // + //~^^ or_then_unwrap // Not Option/Result let instance = SomeStruct {}; diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index d64cc58a790b..1160498c6053 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -8,13 +8,13 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:26:20 + --> tests/ui/or_then_unwrap.rs:27:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` error: found `.or(Some(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:31:31 + --> tests/ui/or_then_unwrap.rs:33: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/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index 711196f8e19b..5585006dc362 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -17,7 +17,8 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs parentheses - //~^ redundant_pattern_matching + // + //~^^ redundant_pattern_matching let _ = match maybe_some { // can't use `matches!` here // because `expr` metavars in macros don't allow let exprs diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index 41106840cb8d..581a432f38e1 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -17,7 +17,8 @@ fn issue_11174(boolean: bool, maybe_some: Option) -> bool { fn issue_11174_edge_cases(boolean: bool, boolean2: bool, maybe_some: Option) { let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses - //~^ redundant_pattern_matching + // + //~^^ redundant_pattern_matching let _ = match maybe_some { // can't use `matches!` here // because `expr` metavars in macros don't allow let exprs diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index 0dfa05970ce3..681602567d2f 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -14,49 +14,49 @@ LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard nee | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (boolean || boolean2)` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:34:12 + --> tests/ui/redundant_pattern_matching_option.rs:35:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:37:12 + --> tests/ui/redundant_pattern_matching_option.rs:38:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:40:12 + --> tests/ui/redundant_pattern_matching_option.rs:41:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:47:15 + --> tests/ui/redundant_pattern_matching_option.rs:48:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:50:15 + --> tests/ui/redundant_pattern_matching_option.rs:51:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:53:15 + --> tests/ui/redundant_pattern_matching_option.rs:54:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:57:15 + --> tests/ui/redundant_pattern_matching_option.rs:58:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:66:5 + --> tests/ui/redundant_pattern_matching_option.rs:67:5 | LL | / match Some(42) { LL | | @@ -66,7 +66,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:72:5 + --> tests/ui/redundant_pattern_matching_option.rs:73:5 | LL | / match None::<()> { LL | | @@ -76,7 +76,7 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:78:13 + --> tests/ui/redundant_pattern_matching_option.rs:79:13 | LL | let _ = match None::<()> { | _____________^ @@ -87,55 +87,55 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:85:20 + --> tests/ui/redundant_pattern_matching_option.rs:86:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:92:20 + --> tests/ui/redundant_pattern_matching_option.rs:93:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:95:19 + --> tests/ui/redundant_pattern_matching_option.rs:96:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:102:12 + --> tests/ui/redundant_pattern_matching_option.rs:103:12 | LL | if let Some(..) = gen_opt() {} | -------^^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:118:12 + --> tests/ui/redundant_pattern_matching_option.rs:119:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:121:12 + --> tests/ui/redundant_pattern_matching_option.rs:122:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:124:15 + --> tests/ui/redundant_pattern_matching_option.rs:125:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:127:15 + --> tests/ui/redundant_pattern_matching_option.rs:128:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:130:5 + --> tests/ui/redundant_pattern_matching_option.rs:131:5 | LL | / match Some(42) { LL | | @@ -145,7 +145,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:136:5 + --> tests/ui/redundant_pattern_matching_option.rs:137:5 | LL | / match None::<()> { LL | | @@ -155,19 +155,19 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:145:12 + --> tests/ui/redundant_pattern_matching_option.rs:146:12 | LL | if let None = *(&None::<()>) {} | -------^^^^----------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:147:12 + --> tests/ui/redundant_pattern_matching_option.rs:148:12 | LL | if let None = *&None::<()> {} | -------^^^^--------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:154:5 + --> tests/ui/redundant_pattern_matching_option.rs:155:5 | LL | / match x { LL | | @@ -177,7 +177,7 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:160:5 + --> tests/ui/redundant_pattern_matching_option.rs:161:5 | LL | / match x { LL | | @@ -187,7 +187,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:166:5 + --> tests/ui/redundant_pattern_matching_option.rs:167:5 | LL | / match x { LL | | @@ -197,7 +197,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:172:5 + --> tests/ui/redundant_pattern_matching_option.rs:173:5 | LL | / match x { LL | | @@ -207,19 +207,19 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_some()` - --> tests/ui/redundant_pattern_matching_option.rs:188:13 + --> tests/ui/redundant_pattern_matching_option.rs:189:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:191:13 + --> tests/ui/redundant_pattern_matching_option.rs:192:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> tests/ui/redundant_pattern_matching_option.rs:202:17 + --> tests/ui/redundant_pattern_matching_option.rs:203:17 | LL | let _ = matches!(*p, None); | ^^^^^^^^^^^^^^^^^^ help: try: `(*p).is_none()` diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index 7424af19a999..a6450123f4c9 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -5,13 +5,15 @@ mod m1 { fn f() {} pub fn g() {} // private due to m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m1_1 { fn f() {} pub fn g() {} // private due to m1_1 and m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -20,14 +22,16 @@ mod m1 { //:^ private due to m1 fn f() {} pub fn g() {} // private due to m1_2 and m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } pub mod m1_3 { fn f() {} pub fn g() {} // private due to m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } } @@ -35,13 +39,15 @@ mod m1 { pub(crate) mod m2 { fn f() {} pub fn g() {} // already crate visible due to m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m2_1 { fn f() {} pub fn g() {} // private due to m2_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -50,14 +56,16 @@ pub(crate) mod m2 { //:^ already crate visible due to m2 fn f() {} pub fn g() {} // already crate visible due to m2_2 and m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } pub mod m2_3 { fn f() {} pub fn g() {} // already crate visible due to m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } } @@ -70,7 +78,8 @@ pub mod m3 { mod m3_1 { fn f() {} pub fn g() {} // private due to m3_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -78,7 +87,8 @@ pub mod m3 { //:^ ok fn f() {} pub fn g() {} // already crate visible due to m3_2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -92,13 +102,15 @@ pub mod m3 { mod m4 { fn f() {} pub fn g() {} // private: not re-exported by `pub use m4::*` - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m4_1 { fn f() {} pub fn g() {} // private due to m4_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -107,7 +119,8 @@ mod m4 { //:^ private: not re-exported by `pub use m4::*` fn f() {} pub fn g() {} // private due to m4_2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index a995ed592289..7415d34d50cc 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -5,13 +5,15 @@ mod m1 { fn f() {} pub(crate) fn g() {} // private due to m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m1_1 { fn f() {} pub(crate) fn g() {} // private due to m1_1 and m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -20,14 +22,16 @@ mod m1 { //:^ private due to m1 fn f() {} pub(crate) fn g() {} // private due to m1_2 and m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } pub mod m1_3 { fn f() {} pub(crate) fn g() {} // private due to m1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } } @@ -35,13 +39,15 @@ mod m1 { pub(crate) mod m2 { fn f() {} pub(crate) fn g() {} // already crate visible due to m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m2_1 { fn f() {} pub(crate) fn g() {} // private due to m2_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -50,14 +56,16 @@ pub(crate) mod m2 { //:^ already crate visible due to m2 fn f() {} pub(crate) fn g() {} // already crate visible due to m2_2 and m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } pub mod m2_3 { fn f() {} pub(crate) fn g() {} // already crate visible due to m2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } } @@ -70,7 +78,8 @@ pub mod m3 { mod m3_1 { fn f() {} pub(crate) fn g() {} // private due to m3_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -78,7 +87,8 @@ pub mod m3 { //:^ ok fn f() {} pub(crate) fn g() {} // already crate visible due to m3_2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -92,13 +102,15 @@ pub mod m3 { mod m4 { fn f() {} pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} mod m4_1 { fn f() {} pub(crate) fn g() {} // private due to m4_1 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } @@ -107,7 +119,8 @@ mod m4 { //:^ private: not re-exported by `pub use m4::*` fn f() {} pub(crate) fn g() {} // private due to m4_2 - //~^ redundant_pub_crate + // + //~^^ redundant_pub_crate pub fn h() {} } diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index 90be83d948bd..95909ea8b066 100644 --- a/tests/ui/redundant_pub_crate.stderr +++ b/tests/ui/redundant_pub_crate.stderr @@ -10,7 +10,7 @@ LL | pub(crate) fn g() {} // private due to m1 = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:13:9 + --> tests/ui/redundant_pub_crate.rs:14:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -18,7 +18,7 @@ LL | pub(crate) fn g() {} // private due to m1_1 and m1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:18:5 + --> tests/ui/redundant_pub_crate.rs:20:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -26,7 +26,7 @@ LL | pub(crate) mod m1_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:22:9 + --> tests/ui/redundant_pub_crate.rs:24:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -34,7 +34,7 @@ LL | pub(crate) fn g() {} // private due to m1_2 and m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:29:9 + --> tests/ui/redundant_pub_crate.rs:32:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -42,7 +42,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:37:5 + --> tests/ui/redundant_pub_crate.rs:41:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -50,7 +50,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:43:9 + --> tests/ui/redundant_pub_crate.rs:48:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -58,7 +58,7 @@ LL | pub(crate) fn g() {} // private due to m2_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:48:5 + --> tests/ui/redundant_pub_crate.rs:54:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -66,7 +66,7 @@ LL | pub(crate) mod m2_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:52:9 + --> tests/ui/redundant_pub_crate.rs:58:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -74,7 +74,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:59:9 + --> tests/ui/redundant_pub_crate.rs:66:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -82,7 +82,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:72:9 + --> tests/ui/redundant_pub_crate.rs:80:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -90,7 +90,7 @@ LL | pub(crate) fn g() {} // private due to m3_1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:80:9 + --> tests/ui/redundant_pub_crate.rs:89:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -98,7 +98,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m3_2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:94:5 + --> tests/ui/redundant_pub_crate.rs:104:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -106,7 +106,7 @@ LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:100:9 + --> tests/ui/redundant_pub_crate.rs:111:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -114,7 +114,7 @@ LL | pub(crate) fn g() {} // private due to m4_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:105:5 + --> tests/ui/redundant_pub_crate.rs:117:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -122,7 +122,7 @@ LL | pub(crate) mod m4_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:109:9 + --> tests/ui/redundant_pub_crate.rs:121: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 d640de71e446..385a5d97cf1a 100644 --- a/tests/ui/redundant_slicing.fixed +++ b/tests/ui/redundant_slicing.fixed @@ -6,12 +6,14 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; let _ = slice; // Redundant slice - //~^ redundant_slicing + // + //~^^ redundant_slicing let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` let _ = (&*v); // Outer borrow is redundant - //~^ redundant_slicing + // + //~^^ redundant_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Ok, re-borrows slice diff --git a/tests/ui/redundant_slicing.rs b/tests/ui/redundant_slicing.rs index 34596cf84799..04f181da250d 100644 --- a/tests/ui/redundant_slicing.rs +++ b/tests/ui/redundant_slicing.rs @@ -6,12 +6,14 @@ use std::io::Read; fn main() { let slice: &[u32] = &[0]; let _ = &slice[..]; // Redundant slice - //~^ redundant_slicing + // + //~^^ redundant_slicing let v = vec![0]; let _ = &v[..]; // Ok, results in `&[_]` let _ = &(&*v)[..]; // Outer borrow is redundant - //~^ redundant_slicing + // + //~^^ redundant_slicing static S: &[u8] = &[0, 1, 2]; let _ = &mut &S[..]; // Ok, re-borrows slice diff --git a/tests/ui/redundant_slicing.stderr b/tests/ui/redundant_slicing.stderr index 47a61b41e978..964111bccf88 100644 --- a/tests/ui/redundant_slicing.stderr +++ b/tests/ui/redundant_slicing.stderr @@ -8,13 +8,13 @@ LL | let _ = &slice[..]; // Redundant slice = help: to override `-D warnings` add `#[allow(clippy::redundant_slicing)]` error: redundant slicing of the whole range - --> tests/ui/redundant_slicing.rs:13:13 + --> tests/ui/redundant_slicing.rs:14:13 | LL | let _ = &(&*v)[..]; // Outer borrow is redundant | ^^^^^^^^^^ help: use the original value instead: `(&*v)` error: redundant slicing of the whole range - --> tests/ui/redundant_slicing.rs:31:13 + --> tests/ui/redundant_slicing.rs:33:13 | LL | let _ = &m!(slice)[..]; | ^^^^^^^^^^^^^^ help: use the original value instead: `slice` diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 8169550b0d55..e6355bdf792f 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -9,7 +9,8 @@ fn main() { let _ = !v.iter().any(|x| *x < 0); //~^ search_is_some let _ = !(0..1).any(|x| **y == x); // one dereference less - //~^ search_is_some + // + //~^^ search_is_some let _ = !(0..1).any(|x| x == 0); //~^ search_is_some let _ = !v.iter().any(|x| *x == 0); diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index 5935f0dd7e29..8cc80f122f08 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -9,7 +9,8 @@ fn main() { let _ = v.iter().find(|&x| *x < 0).is_none(); //~^ search_is_some let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less - //~^ search_is_some + // + //~^^ search_is_some let _ = (0..1).find(|x| *x == 0).is_none(); //~^ search_is_some let _ = v.iter().find(|x| **x == 0).is_none(); diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index e134df9f63c9..ccc17025222d 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -14,43 +14,43 @@ LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| **y == x)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:13:13 + --> tests/ui/search_is_some_fixable_none.rs:14:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:15:13 + --> tests/ui/search_is_some_fixable_none.rs:16:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:17:13 + --> tests/ui/search_is_some_fixable_none.rs:18:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:19:13 + --> tests/ui/search_is_some_fixable_none.rs:20:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:21:13 + --> tests/ui/search_is_some_fixable_none.rs:22:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:23:13 + --> tests/ui/search_is_some_fixable_none.rs:24:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:25:13 + --> tests/ui/search_is_some_fixable_none.rs:26:13 | LL | let _ = (1..3) | _____________^ @@ -60,91 +60,91 @@ LL | | .is_none(); | |__________________^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_none()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_none.rs:31:13 + --> tests/ui/search_is_some_fixable_none.rs:32:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_none.rs:35:13 + --> tests/ui/search_is_some_fixable_none.rs:36:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:42:13 + --> tests/ui/search_is_some_fixable_none.rs:43:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:44:13 + --> tests/ui/search_is_some_fixable_none.rs:45:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:46:13 + --> tests/ui/search_is_some_fixable_none.rs:47:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:49:13 + --> tests/ui/search_is_some_fixable_none.rs:50:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:51:13 + --> tests/ui/search_is_some_fixable_none.rs:52:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:53:13 + --> tests/ui/search_is_some_fixable_none.rs:54:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:56:13 + --> tests/ui/search_is_some_fixable_none.rs:57:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:58:13 + --> tests/ui/search_is_some_fixable_none.rs:59:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:60:13 + --> tests/ui/search_is_some_fixable_none.rs:61:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:77:25 + --> tests/ui/search_is_some_fixable_none.rs:78:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:94:30 + --> tests/ui/search_is_some_fixable_none.rs:95:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:106:17 + --> tests/ui/search_is_some_fixable_none.rs:107:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.foo == 1 && v.bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:110:17 + --> tests/ui/search_is_some_fixable_none.rs:111:17 | LL | let _ = vfoo | _________________^ @@ -162,55 +162,55 @@ LL ~ .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:119:17 + --> tests/ui/search_is_some_fixable_none.rs:120:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:126:17 + --> tests/ui/search_is_some_fixable_none.rs:127:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:145:17 + --> tests/ui/search_is_some_fixable_none.rs:146:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:147:17 + --> tests/ui/search_is_some_fixable_none.rs:148:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:151:17 + --> tests/ui/search_is_some_fixable_none.rs:152:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:153:17 + --> tests/ui/search_is_some_fixable_none.rs:154:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:157:17 + --> tests/ui/search_is_some_fixable_none.rs:158:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:160:17 + --> tests/ui/search_is_some_fixable_none.rs:161:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:181:17 + --> tests/ui/search_is_some_fixable_none.rs:182:17 | LL | let _ = vfoo | _________________^ @@ -228,133 +228,133 @@ LL ~ .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:198:17 + --> tests/ui/search_is_some_fixable_none.rs:199:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.inner[0].bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:204:17 + --> tests/ui/search_is_some_fixable_none.rs:205:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:218:17 + --> tests/ui/search_is_some_fixable_none.rs:219:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.by_ref(&v.bar))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:223:17 + --> tests/ui/search_is_some_fixable_none.rs:224:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:225:17 + --> tests/ui/search_is_some_fixable_none.rs:226:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:245:17 + --> tests/ui/search_is_some_fixable_none.rs:246:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| s[0].is_empty())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:247:17 + --> tests/ui/search_is_some_fixable_none.rs:248:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| test_string_1(&s[0]))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:257:17 + --> tests/ui/search_is_some_fixable_none.rs:258:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| fp.field.is_power_of_two())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:259:17 + --> tests/ui/search_is_some_fixable_none.rs:260:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_1(fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:261:17 + --> tests/ui/search_is_some_fixable_none.rs:262:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_2(*fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:278:17 + --> tests/ui/search_is_some_fixable_none.rs:279:17 | LL | let _ = v.iter().find(|x| **x == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:280:17 + --> tests/ui/search_is_some_fixable_none.rs:281:17 | LL | Foo.bar(v.iter().find(|x| **x == 42).is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:286:9 + --> tests/ui/search_is_some_fixable_none.rs:287:9 | LL | v.iter().find(|x| **x == 42).is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:292:9 + --> tests/ui/search_is_some_fixable_none.rs:293:9 | LL | v.iter().find(|x| **x == 42).is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:298:17 + --> tests/ui/search_is_some_fixable_none.rs:299:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:300:17 + --> tests/ui/search_is_some_fixable_none.rs:301:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:303:17 + --> tests/ui/search_is_some_fixable_none.rs:304:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:305:17 + --> tests/ui/search_is_some_fixable_none.rs:306:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:311:17 + --> tests/ui/search_is_some_fixable_none.rs:312:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:314:17 + --> tests/ui/search_is_some_fixable_none.rs:315:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:320:17 + --> tests/ui/search_is_some_fixable_none.rs:321:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:323:17 + --> tests/ui/search_is_some_fixable_none.rs:324:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index 69467796e0c9..6ab0593eecde 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -9,7 +9,8 @@ fn main() { let _ = v.iter().any(|x| *x < 0); //~^ search_is_some let _ = (0..1).any(|x| **y == x); // one dereference less - //~^ search_is_some + // + //~^^ search_is_some let _ = (0..1).any(|x| x == 0); //~^ search_is_some let _ = v.iter().any(|x| *x == 0); diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index 0ca80a563e28..35094cdf2c07 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -9,7 +9,8 @@ fn main() { let _ = v.iter().find(|&x| *x < 0).is_some(); //~^ search_is_some let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less - //~^ search_is_some + // + //~^^ search_is_some let _ = (0..1).find(|x| *x == 0).is_some(); //~^ search_is_some let _ = v.iter().find(|x| **x == 0).is_some(); diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index 3f18b0fdd3c3..af719b78831a 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -14,43 +14,43 @@ LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:13:20 + --> tests/ui/search_is_some_fixable_some.rs:14:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:15:22 + --> tests/ui/search_is_some_fixable_some.rs:16:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| *x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:17:20 + --> tests/ui/search_is_some_fixable_some.rs:18:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 1 || x == 3 || x == 5)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:19:20 + --> tests/ui/search_is_some_fixable_some.rs:20:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:21:20 + --> tests/ui/search_is_some_fixable_some.rs:22:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:23:20 + --> tests/ui/search_is_some_fixable_some.rs:24:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:26:10 + --> tests/ui/search_is_some_fixable_some.rs:27:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ @@ -59,91 +59,91 @@ LL | | .is_some(); | |__________________^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_some()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_some.rs:31:22 + --> tests/ui/search_is_some_fixable_some.rs:32:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_some.rs:35:22 + --> tests/ui/search_is_some_fixable_some.rs:36:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:41:27 + --> tests/ui/search_is_some_fixable_some.rs:42:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:43:27 + --> tests/ui/search_is_some_fixable_some.rs:44:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:45:27 + --> tests/ui/search_is_some_fixable_some.rs:46:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:48:16 + --> tests/ui/search_is_some_fixable_some.rs:49:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:50:16 + --> tests/ui/search_is_some_fixable_some.rs:51:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:52:16 + --> tests/ui/search_is_some_fixable_some.rs:53:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:55:21 + --> tests/ui/search_is_some_fixable_some.rs:56:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:57:21 + --> tests/ui/search_is_some_fixable_some.rs:58:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:59:21 + --> tests/ui/search_is_some_fixable_some.rs:60:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:76:44 + --> tests/ui/search_is_some_fixable_some.rs:77:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:93:49 + --> tests/ui/search_is_some_fixable_some.rs:94:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:105:29 + --> tests/ui/search_is_some_fixable_some.rs:106:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:111:14 + --> tests/ui/search_is_some_fixable_some.rs:112:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ @@ -152,55 +152,55 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:118:29 + --> tests/ui/search_is_some_fixable_some.rs:119:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:125:29 + --> tests/ui/search_is_some_fixable_some.rs:126:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:144:30 + --> tests/ui/search_is_some_fixable_some.rs:145:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:146:50 + --> tests/ui/search_is_some_fixable_some.rs:147:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s.len() == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:150:26 + --> tests/ui/search_is_some_fixable_some.rs:151:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:152:26 + --> tests/ui/search_is_some_fixable_some.rs:153:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:156:26 + --> tests/ui/search_is_some_fixable_some.rs:157:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:159:26 + --> tests/ui/search_is_some_fixable_some.rs:160:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:182:14 + --> tests/ui/search_is_some_fixable_some.rs:183:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ @@ -209,85 +209,85 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:197:29 + --> tests/ui/search_is_some_fixable_some.rs:198:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:203:29 + --> tests/ui/search_is_some_fixable_some.rs:204:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:217:29 + --> tests/ui/search_is_some_fixable_some.rs:218:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.by_ref(&v.bar))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:222:55 + --> tests/ui/search_is_some_fixable_some.rs:223:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:224:55 + --> tests/ui/search_is_some_fixable_some.rs:225:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:244:26 + --> tests/ui/search_is_some_fixable_some.rs:245:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:246:26 + --> tests/ui/search_is_some_fixable_some.rs:247:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| test_string_1(&s[0]))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:256:26 + --> tests/ui/search_is_some_fixable_some.rs:257:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| fp.field.is_power_of_two())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:258:26 + --> tests/ui/search_is_some_fixable_some.rs:259:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:260:26 + --> tests/ui/search_is_some_fixable_some.rs:261:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:276:18 + --> tests/ui/search_is_some_fixable_some.rs:277:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:286:26 + --> tests/ui/search_is_some_fixable_some.rs:287:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_impl(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:290:26 + --> tests/ui/search_is_some_fixable_some.rs:291:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_dyn(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:294:26 + --> tests/ui/search_is_some_fixable_some.rs:295:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed index 717779f03ab2..9bf9d6630441 100644 --- a/tests/ui/single_char_pattern.fixed +++ b/tests/ui/single_char_pattern.fixed @@ -73,9 +73,11 @@ fn main() { h.contains("X"); // should not warn x.replace(';', ",").split(','); // issue #2978 - //~^ single_char_pattern + // + //~^^ single_char_pattern x.starts_with('\x03'); // issue #2996 - //~^ single_char_pattern + // + //~^^ single_char_pattern // Issue #3204 const S: &str = "#"; diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index 88f6b85f946f..0560a848fe9d 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -73,9 +73,11 @@ fn main() { h.contains("X"); // should not warn x.replace(';', ",").split(","); // issue #2978 - //~^ single_char_pattern + // + //~^^ single_char_pattern x.starts_with("\x03"); // issue #2996 - //~^ single_char_pattern + // + //~^^ single_char_pattern // Issue #3204 const S: &str = "#"; diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index 80d9c7b04637..aa4ba28884a8 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -164,49 +164,49 @@ LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: consider using a `char`: `','` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:77:19 + --> tests/ui/single_char_pattern.rs:78:19 | LL | x.starts_with("\x03"); // issue #2996 | ^^^^^^ help: consider using a `char`: `'\x03'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:85:13 + --> tests/ui/single_char_pattern.rs:87:13 | LL | x.split(r"a"); | ^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:87:13 + --> tests/ui/single_char_pattern.rs:89:13 | LL | x.split(r#"a"#); | ^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:89:13 + --> tests/ui/single_char_pattern.rs:91:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:91:13 + --> tests/ui/single_char_pattern.rs:93:13 | LL | x.split(r###"'"###); | ^^^^^^^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:93:13 + --> tests/ui/single_char_pattern.rs:95:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: consider using a `char`: `'#'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:96:13 + --> tests/ui/single_char_pattern.rs:98:13 | LL | x.split(r#"\"#); | ^^^^^^ help: consider using a `char`: `'\\'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:98:13 + --> tests/ui/single_char_pattern.rs:100:13 | LL | x.split(r"\"); | ^^^^ help: consider using a `char`: `'\\'` diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr new file mode 100644 index 000000000000..c88296959489 --- /dev/null +++ b/tests/ui/single_match.stderr @@ -0,0 +1,282 @@ +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:15:5 + | +LL | / match x { +LL | | Some(y) => { +LL | | println!("{:?}", y); +LL | | }, +LL | | _ => (), +LL | | }; + | |_____^ + | + = note: `-D clippy::single-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match)]` +help: try + | +LL ~ if let Some(y) = x { +LL + println!("{:?}", y); +LL ~ }; + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:33:5 + | +LL | / match z { +LL | | (2..=3, 7..=9) => dummy(), +LL | | _ => {}, +LL | | }; + | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:63:5 + | +LL | / match x { +LL | | Some(y) => dummy(), +LL | | None => (), +LL | | }; + | |_____^ help: try: `if let Some(y) = x { dummy() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:69:5 + | +LL | / match y { +LL | | Ok(y) => dummy(), +LL | | Err(..) => (), +LL | | }; + | |_____^ help: try: `if let Ok(y) = y { dummy() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:77:5 + | +LL | / match c { +LL | | Cow::Borrowed(..) => dummy(), +LL | | Cow::Owned(..) => (), +LL | | }; + | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:99:5 + | +LL | / match x { +LL | | "test" => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if x == "test" { println!() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:113:5 + | +LL | / match x { +LL | | Foo::A => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if x == Foo::A { println!() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:120:5 + | +LL | / match x { +LL | | FOO_C => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if x == FOO_C { println!() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:126:5 + | +LL | / match &&x { +LL | | Foo::A => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if x == Foo::A { println!() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:133:5 + | +LL | / match &x { +LL | | Foo::A => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if x == &Foo::A { println!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:151:5 + | +LL | / match x { +LL | | Bar::A => println!(), +LL | | _ => (), +LL | | } + | |_____^ help: try: `if let Bar::A = x { println!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:160:5 + | +LL | / match x { +LL | | None => println!(), +LL | | _ => (), +LL | | }; + | |_____^ help: try: `if let None = x { println!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:183:5 + | +LL | / match x { +LL | | (Some(_), _) => {}, +LL | | (None, _) => {}, +LL | | } + | |_____^ help: try: `if let (Some(_), _) = x {}` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:190:5 + | +LL | / match x { +LL | | (Some(E::V), _) => todo!(), +LL | | (_, _) => {}, +LL | | } + | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:197:5 + | +LL | / match (Some(42), Some(E::V), Some(42)) { +LL | | (.., Some(E::V), _) => {}, +LL | | (..) => {}, +LL | | } + | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:270:5 + | +LL | / match bar { +LL | | Some(v) => unsafe { +LL | | let r = &v as *const i32; +LL | | println!("{}", *r); +LL | | }, +LL | | _ => {}, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { unsafe { +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:279:5 + | +LL | / match bar { +LL | | #[rustfmt::skip] +LL | | Some(v) => { +LL | | unsafe { +... | +LL | | _ => {}, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { +LL + unsafe { +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:360:5 + | +LL | / match Ok::<_, u32>(Some(A)) { +LL | | Ok(Some(A)) => println!(), +LL | | Err(_) | Ok(None | Some(_)) => {}, +LL | | } + | |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }` + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match.rs:376:5 + | +LL | / match &Some(A) { +LL | | Some(A | B) => println!(), +LL | | None | Some(_) => {}, +LL | | } + | |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }` + +error: you seem to be trying to use `match` for an equality check. Consider using `if` + --> tests/ui/single_match.rs:384:5 + | +LL | / match &s[0..3] { +LL | | b"foo" => println!(), +LL | | _ => {}, +LL | | } + | |_____^ help: try: `if &s[0..3] == b"foo" { println!() }` + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:398:5 + | +LL | / match DATA { +LL | | DATA => println!(), +LL | | _ => {}, +LL | | } + | |_____^ help: try: `println!();` + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:404:5 + | +LL | / match CONST_I32 { +LL | | CONST_I32 => println!(), +LL | | _ => {}, +LL | | } + | |_____^ help: try: `println!();` + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:411:5 + | +LL | / match i { +LL | | i => { +LL | | let a = 1; +LL | | let b = 2; +LL | | }, +LL | | _ => {}, +LL | | } + | |_____^ + | +help: try + | +LL ~ { +LL + let a = 1; +LL + let b = 2; +LL + } + | + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:420:5 + | +LL | / match i { +LL | | i => {}, +LL | | _ => {}, +LL | | } + | |_____^ help: `match` expression can be removed + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:426:5 + | +LL | / match i { +LL | | i => (), +LL | | _ => (), +LL | | } + | |_____^ help: `match` expression can be removed + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match.rs:432:5 + | +LL | / match CONST_I32 { +LL | | CONST_I32 => println!(), +LL | | _ => {}, +LL | | } + | |_____^ help: try: `println!();` + +error: aborting due to 26 previous errors + diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr new file mode 100644 index 000000000000..7d4ba5fb75ef --- /dev/null +++ b/tests/ui/single_match_else.stderr @@ -0,0 +1,211 @@ +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:17:13 + | +LL | let _ = match ExprNode::Butterflies { + | _____________^ +LL | | ExprNode::ExprAddrOf => Some(&NODE), +LL | | _ => { +LL | | let x = 5; +LL | | None +LL | | }, +LL | | }; + | |_____^ + | + = note: `-D clippy::single-match-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match_else)]` +help: try + | +LL ~ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { +LL + let x = 5; +LL + None +LL ~ }; + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:83:5 + | +LL | / match Some(1) { +LL | | Some(a) => println!("${:?}", a), +LL | | None => { +LL | | println!("else block"); +LL | | return +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:93:5 + | +LL | / match Some(1) { +LL | | Some(a) => println!("${:?}", a), +LL | | None => { +LL | | println!("else block"); +LL | | return; +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return; +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:104:5 + | +LL | / match Result::::Ok(1) { +LL | | Ok(a) => println!("${:?}", a), +LL | | Err(_) => { +LL | | println!("else block"); +... | +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Ok(a) = Result::::Ok(1) { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return; +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:114:5 + | +LL | / match Cow::from("moo") { +LL | | Cow::Owned(a) => println!("${:?}", a), +LL | | Cow::Borrowed(_) => { +LL | | println!("else block"); +... | +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else { +LL + println!("else block"); +LL + return; +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:125:5 + | +LL | / match bar { +LL | | Some(v) => unsafe { +LL | | let r = &v as *const i32; +LL | | println!("{}", *r); +... | +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { unsafe { +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } } else { +LL + println!("None1"); +LL + println!("None2"); +LL + } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:137:5 + | +LL | / match bar { +LL | | Some(v) => { +LL | | println!("Some"); +LL | | println!("{v}"); +... | +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { +LL + println!("Some"); +LL + println!("{v}"); +LL + } else { unsafe { +LL + let v = 0; +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:150:5 + | +LL | / match bar { +LL | | Some(v) => unsafe { +LL | | let r = &v as *const i32; +LL | | println!("{}", *r); +... | +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { unsafe { +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } } else { unsafe { +LL + let v = 0; +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } } + | + +error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` + --> tests/ui/single_match_else.rs:163:5 + | +LL | / match bar { +LL | | #[rustfmt::skip] +LL | | Some(v) => { +LL | | unsafe { +... | +LL | | }, +LL | | } + | |_____^ + | +help: try + | +LL ~ if let Some(v) = bar { +LL + unsafe { +LL + let r = &v as *const i32; +LL + println!("{}", *r); +LL + } +LL + } else { +LL + println!("None"); +LL + println!("None"); +LL + } + | + +error: this pattern is irrefutable, `match` is useless + --> tests/ui/single_match_else.rs:213:5 + | +LL | / match ExprNode::Butterflies { +LL | | ExprNode::Butterflies => Some(&NODE), +LL | | _ => { +LL | | let x = 5; +LL | | None +LL | | }, +LL | | } + | |_____^ help: try: `Some(&NODE)` + +error: aborting due to 10 previous errors + diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index e0290b7ce8f1..40a8d8c366ba 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -11,7 +11,8 @@ macro_rules! macro_test { macro_rules! macro_test_inside { () => { 1 ^ 2 // should warn even if inside macro - //~^ suspicious_xor_used_as_pow + // + //~^^ suspicious_xor_used_as_pow }; } diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index d08773a8759a..0913154a26e2 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -1,5 +1,5 @@ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:20:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:21:13 | LL | let _ = 2 ^ 5; | ^^^^^ @@ -12,7 +12,7 @@ LL | let _ = 2.pow(5); | ~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:23:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let _ = 2i32.pow(9i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:27:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = 2i32.pow(2i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:29:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = 50i32.pow(3i32); | ~~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:32:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:33:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = 5i32.pow(8i32); | ~~~~~~~~~~~~~~ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:35:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:36:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ diff --git a/tests/ui/trim_split_whitespace.fixed b/tests/ui/trim_split_whitespace.fixed index c7c241e3075f..434e91b7d953 100644 --- a/tests/ui/trim_split_whitespace.fixed +++ b/tests/ui/trim_split_whitespace.fixed @@ -59,19 +59,25 @@ impl DerefStrAndCustomTrim { fn main() { // &str let _ = " A B C ".split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = " A B C ".split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // String let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = (" A B C ").to_string().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Custom let _ = Custom.trim().split_whitespace(); // should not trigger lint @@ -79,7 +85,8 @@ fn main() { // Deref let s = DerefStr(" A B C "); let _ = s.split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Deref + custom impl let s = DerefStrAndCustom(" A B C "); @@ -88,7 +95,8 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); let _ = s.split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.rs b/tests/ui/trim_split_whitespace.rs index aa2cd92430ed..b939ecdfba85 100644 --- a/tests/ui/trim_split_whitespace.rs +++ b/tests/ui/trim_split_whitespace.rs @@ -59,19 +59,25 @@ impl DerefStrAndCustomTrim { fn main() { // &str let _ = " A B C ".trim().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // String let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Custom let _ = Custom.trim().split_whitespace(); // should not trigger lint @@ -79,7 +85,8 @@ fn main() { // Deref let s = DerefStr(" A B C "); let _ = s.trim().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Deref + custom impl let s = DerefStrAndCustom(" A B C "); @@ -88,7 +95,8 @@ fn main() { // Deref + only custom split_ws() impl let s = DerefStrAndCustomSplit(" A B C "); let _ = s.trim().split_whitespace(); // should trigger lint - //~^ trim_split_whitespace + // + //~^^ trim_split_whitespace // Expl: trim() is called on str (deref) and returns &str. // Thus split_ws() is called on str as well and the custom impl on S is unused diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index deaec54d9363..f242dd802115 100644 --- a/tests/ui/trim_split_whitespace.stderr +++ b/tests/ui/trim_split_whitespace.stderr @@ -8,43 +8,43 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::trim_split_whitespace)]` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:63:23 + --> tests/ui/trim_split_whitespace.rs:64:23 | LL | let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:65:23 + --> tests/ui/trim_split_whitespace.rs:67:23 | LL | let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:69:37 + --> tests/ui/trim_split_whitespace.rs:72:37 | LL | let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:71:37 + --> tests/ui/trim_split_whitespace.rs:75:37 | LL | let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:73:37 + --> tests/ui/trim_split_whitespace.rs:78:37 | LL | let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:81:15 + --> tests/ui/trim_split_whitespace.rs:87:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:90:15 + --> tests/ui/trim_split_whitespace.rs:97:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 6db094babb24..7b609d9163a9 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -45,13 +45,17 @@ fn tester(fn_arg: i32) { println!("val='{local_i32}'"); //~^ uninlined_format_args println!("val='{local_i32}'"); // 3 spaces - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{local_i32}'"); // tab - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{local_i32}'"); // space+tab - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{local_i32}'"); // tab+space - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!( //~^ uninlined_format_args "val='{local_i32}'" diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index 7ca61b800219..14e0b6caabc0 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -45,13 +45,17 @@ fn tester(fn_arg: i32) { println!("val='{}'", local_i32); //~^ uninlined_format_args println!("val='{ }'", local_i32); // 3 spaces - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{ }'", local_i32); // tab - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{ }'", local_i32); // space+tab - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!("val='{ }'", local_i32); // tab+space - //~^ uninlined_format_args + // + //~^^ uninlined_format_args println!( //~^ uninlined_format_args "val='{ diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index df688bc757c7..7e62a095eadf 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -25,7 +25,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:49:5 + --> tests/ui/uninlined_format_args.rs:50:5 | LL | println!("val='{ }'", local_i32); // tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("val='{local_i32}'"); // tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:51:5 + --> tests/ui/uninlined_format_args.rs:53:5 | LL | println!("val='{ }'", local_i32); // space+tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("val='{local_i32}'"); // space+tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:53:5 + --> tests/ui/uninlined_format_args.rs:56:5 | LL | println!("val='{ }'", local_i32); // tab+space | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("val='{local_i32}'"); // tab+space | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:55:5 + --> tests/ui/uninlined_format_args.rs:59:5 | LL | / println!( LL | | @@ -72,7 +72,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:61:5 + --> tests/ui/uninlined_format_args.rs:65:5 | LL | println!("{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:63:5 + --> tests/ui/uninlined_format_args.rs:67:5 | LL | println!("{}", fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + println!("{fn_arg}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:65:5 + --> tests/ui/uninlined_format_args.rs:69:5 | LL | println!("{:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:67:5 + --> tests/ui/uninlined_format_args.rs:71:5 | LL | println!("{:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:69:5 + --> tests/ui/uninlined_format_args.rs:73:5 | LL | println!("{:4}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + println!("{local_i32:4}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:71:5 + --> tests/ui/uninlined_format_args.rs:75:5 | LL | println!("{:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:73:5 + --> tests/ui/uninlined_format_args.rs:77:5 | LL | println!("{:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:75:5 + --> tests/ui/uninlined_format_args.rs:79:5 | LL | println!("{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,7 +168,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:77:5 + --> tests/ui/uninlined_format_args.rs:81:5 | LL | println!("{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:82:5 + --> tests/ui/uninlined_format_args.rs:86:5 | LL | println!("{} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +192,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:85:5 + --> tests/ui/uninlined_format_args.rs:89:5 | LL | println!("{}", val); | ^^^^^^^^^^^^^^^^^^^ @@ -204,7 +204,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:87:5 + --> tests/ui/uninlined_format_args.rs:91:5 | LL | println!("{}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -216,7 +216,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:90:5 + --> tests/ui/uninlined_format_args.rs:94:5 | LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:92:5 + --> tests/ui/uninlined_format_args.rs:96:5 | LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:94:5 + --> tests/ui/uninlined_format_args.rs:98:5 | LL | println!("val='{local_i32}'", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -252,7 +252,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:96:5 + --> tests/ui/uninlined_format_args.rs:100:5 | LL | println!("val='{local_i32}'", local_i32 = fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -264,7 +264,7 @@ LL + println!("val='{fn_arg}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:98:5 + --> tests/ui/uninlined_format_args.rs:102:5 | LL | println!("{0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:100:5 + --> tests/ui/uninlined_format_args.rs:104:5 | LL | println!("{0:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:102:5 + --> tests/ui/uninlined_format_args.rs:106:5 | LL | println!("{0:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:104:5 + --> tests/ui/uninlined_format_args.rs:108:5 | LL | println!("{0:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -312,7 +312,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:106:5 + --> tests/ui/uninlined_format_args.rs:110:5 | LL | println!("{0:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -324,7 +324,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:108:5 + --> tests/ui/uninlined_format_args.rs:112:5 | LL | println!("{0:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +336,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:110:5 + --> tests/ui/uninlined_format_args.rs:114:5 | LL | println!("{0:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -348,7 +348,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:112:5 + --> tests/ui/uninlined_format_args.rs:116:5 | LL | println!("{0} {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -360,7 +360,7 @@ LL + println!("{local_i32} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:114:5 + --> tests/ui/uninlined_format_args.rs:118:5 | LL | println!("{1} {} {0} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -372,7 +372,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:116:5 + --> tests/ui/uninlined_format_args.rs:120:5 | LL | println!("{0} {1}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +384,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:118:5 + --> tests/ui/uninlined_format_args.rs:122:5 | LL | println!("{1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -396,7 +396,7 @@ LL + println!("{local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:120:5 + --> tests/ui/uninlined_format_args.rs:124:5 | LL | println!("{1} {0} {1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -408,7 +408,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:123:5 + --> tests/ui/uninlined_format_args.rs:127:5 | LL | println!("{v}", v = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -420,7 +420,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:125:5 + --> tests/ui/uninlined_format_args.rs:129:5 | LL | println!("{local_i32:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -432,7 +432,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:127:5 + --> tests/ui/uninlined_format_args.rs:131:5 | LL | println!("{local_i32:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -444,7 +444,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:129:5 + --> tests/ui/uninlined_format_args.rs:133:5 | LL | println!("{local_i32:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -456,7 +456,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:131:5 + --> tests/ui/uninlined_format_args.rs:135:5 | LL | println!("{local_i32:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -468,7 +468,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:133:5 + --> tests/ui/uninlined_format_args.rs:137:5 | LL | println!("{:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -480,7 +480,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:135:5 + --> tests/ui/uninlined_format_args.rs:139:5 | LL | println!("{0:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -492,7 +492,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:137:5 + --> tests/ui/uninlined_format_args.rs:141:5 | LL | println!("{:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -504,7 +504,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:139:5 + --> tests/ui/uninlined_format_args.rs:143:5 | LL | println!("{0:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -516,7 +516,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:141:5 + --> tests/ui/uninlined_format_args.rs:145:5 | LL | println!("{0:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -528,7 +528,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:143:5 + --> tests/ui/uninlined_format_args.rs:147:5 | LL | println!("{0:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -540,7 +540,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:145:5 + --> tests/ui/uninlined_format_args.rs:149:5 | LL | println!("{v:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -552,7 +552,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:147:5 + --> tests/ui/uninlined_format_args.rs:151:5 | LL | println!("{v:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -564,7 +564,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:149:5 + --> tests/ui/uninlined_format_args.rs:153:5 | LL | println!("{v:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -576,7 +576,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:151:5 + --> tests/ui/uninlined_format_args.rs:155:5 | LL | println!("{v:v$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -588,7 +588,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:153:5 + --> tests/ui/uninlined_format_args.rs:157:5 | LL | println!("{:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -600,7 +600,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:155:5 + --> tests/ui/uninlined_format_args.rs:159:5 | LL | println!("{:1$}", local_i32, width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -612,7 +612,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:157:5 + --> tests/ui/uninlined_format_args.rs:161:5 | LL | println!("{:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -624,7 +624,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:159:5 + --> tests/ui/uninlined_format_args.rs:163:5 | LL | println!("{:w$}", local_i32, w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -636,7 +636,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:161:5 + --> tests/ui/uninlined_format_args.rs:165:5 | LL | println!("{:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -648,7 +648,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:163:5 + --> tests/ui/uninlined_format_args.rs:167:5 | LL | println!("{:.1$}", local_i32, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -660,7 +660,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:165:5 + --> tests/ui/uninlined_format_args.rs:169:5 | LL | println!("{:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -672,7 +672,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:167:5 + --> tests/ui/uninlined_format_args.rs:171:5 | LL | println!("{:.p$}", local_i32, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -684,7 +684,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:169:5 + --> tests/ui/uninlined_format_args.rs:173:5 | LL | println!("{:0$.1$}", width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -696,7 +696,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:171:5 + --> tests/ui/uninlined_format_args.rs:175:5 | LL | println!("{:0$.w$}", width, w = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -708,7 +708,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:173:5 + --> tests/ui/uninlined_format_args.rs:177:5 | LL | println!("{:1$.2$}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL + println!("{local_f64:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:175:5 + --> tests/ui/uninlined_format_args.rs:179:5 | LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -732,7 +732,7 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:177:5 + --> tests/ui/uninlined_format_args.rs:181:5 | LL | / println!( LL | | @@ -742,7 +742,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:189:5 + --> tests/ui/uninlined_format_args.rs:193:5 | LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -754,7 +754,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$ | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:191:5 + --> tests/ui/uninlined_format_args.rs:195:5 | LL | println!("{:w$.p$}", local_i32, w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -766,7 +766,7 @@ LL + println!("{local_i32:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:193:5 + --> tests/ui/uninlined_format_args.rs:197:5 | LL | println!("{:w$.p$}", w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -778,7 +778,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:213:5 + --> tests/ui/uninlined_format_args.rs:217:5 | LL | / println!( LL | | @@ -788,7 +788,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:219:5 + --> tests/ui/uninlined_format_args.rs:223:5 | LL | println!("{}", /* comment with a comma , in it */ val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -800,7 +800,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:226:9 + --> tests/ui/uninlined_format_args.rs:230:9 | LL | panic!("p1 {}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -812,7 +812,7 @@ LL + panic!("p1 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:230:9 + --> tests/ui/uninlined_format_args.rs:234:9 | LL | panic!("p2 {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -824,7 +824,7 @@ LL + panic!("p2 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:234:9 + --> tests/ui/uninlined_format_args.rs:238:9 | LL | panic!("p3 {local_i32}", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -836,7 +836,7 @@ LL + panic!("p3 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:255:5 + --> tests/ui/uninlined_format_args.rs:259:5 | LL | println!("expand='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -848,7 +848,7 @@ LL + println!("expand='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:358:5 + --> tests/ui/uninlined_format_args.rs:362:5 | LL | usr_println!(true, "val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -860,7 +860,7 @@ LL + usr_println!(true, "val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:360:5 + --> tests/ui/uninlined_format_args.rs:364:5 | LL | usr_println!(true, "{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -872,7 +872,7 @@ LL + usr_println!(true, "{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:362:5 + --> tests/ui/uninlined_format_args.rs:366:5 | LL | usr_println!(true, "{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -884,7 +884,7 @@ LL + usr_println!(true, "{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:364:5 + --> tests/ui/uninlined_format_args.rs:368:5 | LL | usr_println!(true, "{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index abaab6aa9a05..ba167e79a308 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -246,7 +246,8 @@ mod fixable { //~^ unnecessary_cast #[allow(ambiguous_negative_literals)] let _: f64 = -8.0_f64.exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior - //~^ unnecessary_cast + // + //~^^ unnecessary_cast } fn issue_9562_non_literal() { diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index 8f2493def09a..0f90a8b05965 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -246,7 +246,8 @@ mod fixable { //~^ unnecessary_cast #[allow(ambiguous_negative_literals)] let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior - //~^ unnecessary_cast + // + //~^^ unnecessary_cast } fn issue_9562_non_literal() { diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 3b8f5d0c5fd1..c83770c1a299 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -236,13 +236,13 @@ LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp() | ^^^^^^^^^^^^ help: try: `8.0_f64` error: casting to the same type is unnecessary (`f32` -> `f32`) - --> tests/ui/unnecessary_cast.rs:257:20 + --> tests/ui/unnecessary_cast.rs:258:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:268:9 + --> tests/ui/unnecessary_cast.rs:269:9 | LL | (*x as usize).pow(2) | ^^^^^^^^^^^^^ help: try: `{ *x }` diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index e999dc3ade7f..877f4ad41c7e 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -138,7 +138,8 @@ fn unwrap_unchecked() { let _ = 1; //~^ unnecessary_literal_unwrap let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block - //~^ unnecessary_literal_unwrap + // + //~^^ unnecessary_literal_unwrap let _ = 1 + 1; //~^ unnecessary_literal_unwrap let _ = 1; diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index 1f47d3898bbb..c0a35ae78a71 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -138,7 +138,8 @@ fn unwrap_unchecked() { let _ = unsafe { Some(1).unwrap_unchecked() }; //~^ unnecessary_literal_unwrap let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block - //~^ unnecessary_literal_unwrap + // + //~^^ unnecessary_literal_unwrap let _ = unsafe { Some(1).unwrap_unchecked() } + 1; //~^ unnecessary_literal_unwrap let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index f4880637375a..7d6e096a1c93 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -543,7 +543,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:142:22 + --> tests/ui/unnecessary_literal_unwrap.rs:143:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:144:22 + --> tests/ui/unnecessary_literal_unwrap.rs:145:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:146:22 + --> tests/ui/unnecessary_literal_unwrap.rs:147:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:148:22 + --> tests/ui/unnecessary_literal_unwrap.rs:149:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -591,7 +591,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:150:22 + --> tests/ui/unnecessary_literal_unwrap.rs:151:22 | LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed index 820282d8da54..c5d800dc94e1 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -158,7 +158,8 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { Self // Should lint - //~^ use_self + // + //~^^ use_self } } } diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index aa9761e5609f..dcf5820afc26 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -158,7 +158,8 @@ mod full_path_replacement { impl Error for std::fmt::Error { fn custom(_msg: T) -> Self { std::fmt::Error // Should lint - //~^ use_self + // + //~^^ use_self } } } From 3053bad40af1022b1f16d2778612dfeeef73e362 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Feb 2025 12:58:03 +0100 Subject: [PATCH 091/161] Update ui-toml tests --- .../absolute_paths_2015.default.stderr | 14 --- .../absolute_paths/absolute_paths_2015.rs | 5 +- .../uninlined_format_args.fixed | 6 ++ .../uninlined_format_args.rs | 6 ++ .../uninlined_format_args.stderr | 10 +- .../ordering_good.rs | 5 + .../ordering_good_var_1.rs | 1 + .../ordering_mixed.default.stderr | 67 +++++++------ .../ordering_mixed.rs | 17 ++++ .../ordering_mixed_var_1.rs | 8 ++ .../ordering_mixed_var_1.var_1.stderr | 28 +++--- .../ordering_only_enum.rs | 1 + .../ordering_only_impl.only_impl.stderr | 6 +- .../ordering_only_impl.rs | 3 + .../ordering_only_trait.only_trait.stderr | 8 +- .../ordering_only_trait.rs | 3 + .../arithmetic_side_effects_allowed.rs | 9 ++ .../arithmetic_side_effects_allowed.stderr | 16 ++-- .../array_size_threshold.rs | 2 + .../array_size_threshold.stderr | 2 +- .../await_holding_invalid_type.rs | 3 + .../await_holding_invalid_type.stderr | 4 +- .../await_holding_invalid_type.rs | 1 + .../borrow_interior_mutable_const/ignore.rs | 1 + .../conf_deprecated_key.rs | 1 + tests/ui-toml/dbg_macro/dbg_macro.fixed | 7 ++ tests/ui-toml/dbg_macro/dbg_macro.rs | 7 ++ tests/ui-toml/dbg_macro/dbg_macro.stderr | 12 +-- .../declare_interior_mutable_const/ignore.rs | 1 + .../disallowed_macros/disallowed_macros.rs | 16 ++++ .../disallowed_macros.stderr | 31 +++--- .../disallowed_names.rs | 2 + .../disallowed_names.stderr | 2 +- .../disallowed_names.rs | 1 + .../doc_markdown.fixed | 1 + .../doc_valid_idents_append/doc_markdown.rs | 1 + .../doc_markdown.fixed | 3 + .../doc_valid_idents_replace/doc_markdown.rs | 3 + .../doc_markdown.stderr | 2 +- .../duplicated_keys.rs | 1 + .../duplicated_keys.rs | 1 + .../excessive_nesting/excessive_nesting.rs | 37 ++++++++ .../excessive_nesting.stderr | 77 ++++++++------- tests/ui-toml/expect_used/expect_used.rs | 6 +- tests/ui-toml/expect_used/expect_used.stderr | 6 +- .../extra_unused_type_parameters.rs | 1 + .../ui-toml/fn_params_excessive_bools/test.rs | 1 + tests/ui-toml/functions_maxlines/test.rs | 4 + tests/ui-toml/functions_maxlines/test.stderr | 10 +- .../conf_no_false_negatives.rs | 1 + tests/ui-toml/ifs_same_cond/ifs_same_cond.rs | 1 + .../indexing_slicing/indexing_slicing.rs | 1 + .../allowed_prefixes/item_name_repetitions.rs | 1 + .../item_name_repetitions.rs | 1 + .../threshold0/item_name_repetitions.rs | 2 + .../ui-toml/large_futures/large_futures.fixed | 1 + tests/ui-toml/large_futures/large_futures.rs | 1 + .../large_include_file/large_include_file.rs | 2 +- .../lint_decimal_readability/test.fixed | 2 + .../ui-toml/lint_decimal_readability/test.rs | 2 + .../lint_decimal_readability/test.stderr | 2 +- .../macro_metavars_in_unsafe/default/test.rs | 29 +++--- .../min_ident_chars/min_ident_chars.rs | 8 ++ .../min_ident_chars/min_ident_chars.stderr | 14 +-- .../min_rust_version/min_rust_version.fixed | 1 + .../min_rust_version/min_rust_version.rs | 1 + .../conf_missing_enforced_import_rename.fixed | 6 ++ .../conf_missing_enforced_import_rename.rs | 6 ++ ...conf_missing_enforced_import_rename.stderr | 10 +- .../module_inception/module_inception.rs | 2 + .../module_inception/module_inception.stderr | 4 +- .../modulo_arithmetic/modulo_arithmetic.rs | 4 + .../modulo_arithmetic.stderr | 6 +- tests/ui-toml/mut_key/mut_key.rs | 1 + .../needless_raw_string_hashes.fixed | 3 + .../needless_raw_string_hashes.rs | 3 + .../needless_raw_string_hashes.stderr | 4 +- .../conf_nonstandard_macro_braces.fixed | 8 ++ .../conf_nonstandard_macro_braces.rs | 8 ++ .../conf_nonstandard_macro_braces.stderr | 14 +-- tests/ui-toml/panic/panic.rs | 2 + tests/ui-toml/panic/panic.stderr | 2 +- .../path_ends_with_ext/path_ends_with_ext.rs | 2 + tests/ui-toml/print_macro/print_macro.rs | 2 + tests/ui-toml/print_macro/print_macro.stderr | 2 +- .../pub_crate_missing_doc.rs | 7 ++ .../pub_crate_missing_doc.stderr | 14 +-- ...ub_underscore_fields.all_pub_fields.stderr | 12 +-- .../pub_underscore_fields.rs | 7 ++ .../renamed_function_params.default.stderr | 6 +- .../renamed_function_params.extend.stderr | 4 +- .../renamed_function_params.rs | 11 ++- .../replaceable_disallowed_types.fixed | 1 + .../replaceable_disallowed_types.rs | 1 + tests/ui-toml/semicolon_block/both.fixed | 4 + tests/ui-toml/semicolon_block/both.rs | 4 + tests/ui-toml/semicolon_block/both.stderr | 7 +- .../semicolon_inside_block.fixed | 1 + .../semicolon_block/semicolon_inside_block.rs | 1 + .../semicolon_inside_block.stderr | 1 + .../semicolon_outside_block.fixed | 3 + .../semicolon_outside_block.rs | 3 + .../semicolon_outside_block.stderr | 4 +- .../strict_non_send_fields_in_send_ty/test.rs | 4 + .../test.stderr | 24 ++--- tests/ui-toml/struct_excessive_bools/test.rs | 1 + .../struct_excessive_bools/test.stderr | 1 + tests/ui-toml/suppress_lint_in_const/test.rs | 6 ++ .../suppress_lint_in_const/test.stderr | 10 +- .../conf_french_disallowed_name.rs | 7 ++ .../conf_french_disallowed_name.stderr | 12 +-- .../conf_disallowed_methods.rs | 14 +++ .../conf_disallowed_methods.stderr | 26 ++--- .../conf_disallowed_types.rs | 21 ++++ .../conf_disallowed_types.stderr | 40 ++++---- ...conf_inconsistent_struct_constructor.fixed | 5 + .../conf_inconsistent_struct_constructor.rs | 5 + ...onf_inconsistent_struct_constructor.stderr | 16 +++- .../replaceable_disallowed_methods.fixed | 2 + .../replaceable_disallowed_methods.rs | 2 + .../replaceable_disallowed_methods.stderr | 2 +- tests/ui-toml/toml_trivially_copy/test.rs | 2 + .../toml_unknown_key/conf_unknown_key.rs | 4 +- .../undocumented_unsafe_blocks.default.stderr | 75 ++++++++------- ...undocumented_unsafe_blocks.disabled.stderr | 95 +++++++++---------- .../undocumented_unsafe_blocks.rs | 46 +++++++++ tests/ui-toml/unwrap_used/unwrap_used.fixed | 28 ++++++ tests/ui-toml/unwrap_used/unwrap_used.rs | 28 ++++++ tests/ui-toml/unwrap_used/unwrap_used.stderr | 52 +++++----- .../upper_case_acronyms.fixed | 13 +++ .../upper_case_acronyms.rs | 13 +++ .../upper_case_acronyms.stderr | 24 ++--- tests/ui-toml/useless_vec/useless_vec.fixed | 1 + tests/ui-toml/useless_vec/useless_vec.rs | 1 + tests/ui-toml/vec_box_sized/test.fixed | 3 + tests/ui-toml/vec_box_sized/test.rs | 3 + tests/ui-toml/vec_box_sized/test.stderr | 4 +- .../zero_single_char_names.rs | 1 + 138 files changed, 888 insertions(+), 413 deletions(-) delete mode 100644 tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr diff --git a/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr b/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr deleted file mode 100644 index 6fc495f01808..000000000000 --- a/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths_2015.rs:15:13 - | -LL | let _ = ::m1::m2::X; - | ^^^^^^^^^^^ - | -note: the lint level is defined here - --> tests/ui-toml/absolute_paths/absolute_paths_2015.rs:6:9 - | -LL | #![deny(clippy::absolute_paths)] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui-toml/absolute_paths/absolute_paths_2015.rs b/tests/ui-toml/absolute_paths/absolute_paths_2015.rs index 033c47809191..ea556b7e437d 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths_2015.rs +++ b/tests/ui-toml/absolute_paths/absolute_paths_2015.rs @@ -2,6 +2,7 @@ //@[default]rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/default //@[allow_crates]rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates //@edition:2015 +//@check-pass #![deny(clippy::absolute_paths)] @@ -11,6 +12,4 @@ mod m1 { } } -fn main() { - let _ = ::m1::m2::X; //~[default] absolute_paths -} +fn main() {} 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 c04543da94b9..e12a94a4b205 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 @@ -7,8 +7,14 @@ fn main() { let local_opt: Option = Some(3); println!("val='{local_i32}'"); + //~^ uninlined_format_args println!("Hello x is {local_f64:.local_i32$}"); + //~^ uninlined_format_args + //~| print_literal println!("Hello {local_i32} is {local_f64:.*}", 5); + //~^ uninlined_format_args println!("Hello {local_i32} is {local_f64:.*}", 5); + //~^ uninlined_format_args println!("{local_i32}, {}", local_opt.unwrap()); + //~^ uninlined_format_args } 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 813830d80b83..ad5aec133e91 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 @@ -7,8 +7,14 @@ fn main() { let local_opt: Option = Some(3); println!("val='{}'", local_i32); + //~^ uninlined_format_args println!("Hello {} is {:.*}", "x", local_i32, local_f64); + //~^ uninlined_format_args + //~| print_literal println!("Hello {} is {:.*}", local_i32, 5, local_f64); + //~^ uninlined_format_args println!("Hello {} is {2:.*}", local_i32, 5, local_f64); + //~^ uninlined_format_args println!("{}, {}", local_i32, local_opt.unwrap()); + //~^ uninlined_format_args } 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 73ef620bd12e..3ffe61b8ed72 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 @@ -13,7 +13,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:10:5 + --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:11:5 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {} is {local_f64:.local_i32$}", "x"); | error: literal with an empty format string - --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:10:35 + --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:11:35 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^ @@ -39,7 +39,7 @@ LL + println!("Hello x is {:.*}", local_i32, local_f64); | error: variables can be used directly in the `format!` string - --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:11:5 + --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:14:5 | LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,7 +51,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:12:5 + --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:16:5 | LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:13:5 + --> tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs:18:5 | LL | println!("{}, {}", local_i32, local_opt.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs index e9bcc30c15e0..05eb40506db4 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_good.rs @@ -5,6 +5,11 @@ //@[bad_conf_1] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_1 //@[bad_conf_2] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_2 //@[bad_conf_3] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/bad_conf_3 +//@[default] check-pass +//@[default_exp] check-pass +//@[bad_conf_1] error-in-other-file: +//@[bad_conf_2] error-in-other-file: +//@[bad_conf_3] error-in-other-file: #![allow(dead_code)] #![warn(clippy::arbitrary_source_item_ordering)] diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs index 0fccbd4790bc..fb2d2e64bcea 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_good_var_1.rs @@ -1,6 +1,7 @@ //@aux-build:../../ui/auxiliary/proc_macros.rs //@revisions: var_1 //@[var_1] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/var_1 +//@check-pass #![allow(dead_code)] #![warn(clippy::arbitrary_source_item_ordering)] diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.default.stderr b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.default.stderr index ee2868869deb..3605952bddc9 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.default.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.default.stderr @@ -1,11 +1,11 @@ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:21:14 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:22:14 | LL | use std::rc::Weak; | ^^^^ | note: should be placed before `SNAKE_CASE` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:19:7 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:20:7 | LL | const SNAKE_CASE: &str = "zzzzzzzz"; | ^^^^^^^^^^ @@ -13,18 +13,18 @@ LL | const SNAKE_CASE: &str = "zzzzzzzz"; = help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]` error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:64:1 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:67:1 | LL | / impl CloneSelf for StructOrdered { +LL | | LL | | fn clone_self(&self) -> Self { LL | | Self { -LL | | a: true, ... | LL | | } | |_^ | note: should be placed before the following item - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:54:1 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:57:1 | LL | / impl Default for StructOrdered { LL | | fn default() -> Self { @@ -35,55 +35,54 @@ LL | | } | |_^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:136:7 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:145:7 | LL | const ZIS_SHOULD_BE_REALLY_EARLY: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before `TraitUnorderedItemKinds` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:124:7 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:132:7 | LL | trait TraitUnorderedItemKinds { | ^^^^^^^^^^^^^^^^^^^^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:151:1 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:163:1 | LL | impl BasicEmptyTrait for StructOrdered {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before the following item - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:138:1 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:148:1 | LL | / impl TraitUnordered for StructUnordered { LL | | const A: bool = false; LL | | const C: bool = false; LL | | const B: bool = false; ... | -LL | | fn b() {} LL | | } | |_^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:170:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:184:5 | LL | mod this_is_in_the_wrong_position { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before `main` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:165:4 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:179:4 | LL | fn main() { | ^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:178:7 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:194:7 | LL | const ZIS_SHOULD_BE_EVEN_EARLIER: () = (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before `ZisShouldBeBeforeZeMainFn` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:176:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:192:8 | LL | struct ZisShouldBeBeforeZeMainFn; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -101,121 +100,121 @@ LL | const BEFORE: i8 = 0; | ^^^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:38:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:40:5 | LL | B, | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:37:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:39:5 | LL | C, | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:88:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:92:5 | LL | b: bool, | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:87:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:91:5 | LL | c: bool, | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:96:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:101:5 | LL | b: bool, | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:95:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:100:5 | LL | c: bool, | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:115:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:121:11 | LL | const B: bool; | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:114:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:120:11 | LL | const C: bool; | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:121:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:128:8 | LL | fn b(); | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:120:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:127:8 | LL | fn c(); | ^ error: incorrect ordering of trait items (defined order: [Const, Type, Fn]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:127:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:135:5 | LL | const A: bool; | ^^^^^^^^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:125:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:133:5 | LL | type SomeType; | ^^^^^^^^^^^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:141:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:151:11 | LL | const B: bool = false; | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:140:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:150:11 | LL | const C: bool = false; | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:147:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:158:8 | LL | fn b() {} | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:146:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:157:8 | LL | fn c() {} | ^ error: incorrect ordering of impl items (defined order: [Const, Type, Fn]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:156:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:169:5 | LL | const A: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:154:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:167:5 | LL | type SomeType = (); | ^^^^^^^^^^^^^^^^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:172:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:187:11 | LL | const A: i8 = 1; | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:171:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs:186:11 | LL | const C: i8 = 0; | ^ diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs index 2765bf935b7c..9e65a9cca0da 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs @@ -10,6 +10,7 @@ mod i_am_just_right { const BEFORE: i8 = 0; const AFTER: i8 = 0; + //~^ arbitrary_source_item_ordering } // Use statements should not be linted internally - this is normally auto-sorted using rustfmt. @@ -19,6 +20,7 @@ use std::sync::{Arc, Barrier, RwLock}; const SNAKE_CASE: &str = "zzzzzzzz"; use std::rc::Weak; +//~^ arbitrary_source_item_ordering trait BasicEmptyTrait {} @@ -36,6 +38,7 @@ enum EnumUnordered { A, C, B, + //~^ arbitrary_source_item_ordering } #[allow(clippy::arbitrary_source_item_ordering)] @@ -62,6 +65,7 @@ impl Default for StructOrdered { } impl CloneSelf for StructOrdered { + //~^ arbitrary_source_item_ordering fn clone_self(&self) -> Self { Self { a: true, @@ -86,6 +90,7 @@ struct StructUnordered { a: bool, c: bool, b: bool, + //~^ arbitrary_source_item_ordering d: bool, } @@ -94,6 +99,7 @@ struct StructUnorderedGeneric { a: bool, c: bool, b: bool, + //~^ arbitrary_source_item_ordering d: bool, } @@ -113,18 +119,21 @@ trait TraitUnordered { const A: bool; const C: bool; const B: bool; + //~^ arbitrary_source_item_ordering type SomeType; fn a(); fn c(); fn b(); + //~^ arbitrary_source_item_ordering } trait TraitUnorderedItemKinds { type SomeType; const A: bool; + //~^ arbitrary_source_item_ordering const B: bool; const C: bool; @@ -134,26 +143,31 @@ trait TraitUnorderedItemKinds { } const ZIS_SHOULD_BE_REALLY_EARLY: () = (); +//~^ arbitrary_source_item_ordering impl TraitUnordered for StructUnordered { const A: bool = false; const C: bool = false; const B: bool = false; + //~^ arbitrary_source_item_ordering type SomeType = (); fn a() {} fn c() {} fn b() {} + //~^ arbitrary_source_item_ordering } // Trait impls should be located just after the type they implement it for. impl BasicEmptyTrait for StructOrdered {} +//~^ arbitrary_source_item_ordering impl TraitUnorderedItemKinds for StructUnordered { type SomeType = (); const A: bool = false; + //~^ arbitrary_source_item_ordering const B: bool = false; const C: bool = false; @@ -168,14 +182,17 @@ fn main() { /// Note that the linting pass is stopped before recursing into this module. mod this_is_in_the_wrong_position { + //~^ arbitrary_source_item_ordering const C: i8 = 0; const A: i8 = 1; + //~^ arbitrary_source_item_ordering } #[derive(Default, std::clone::Clone)] struct ZisShouldBeBeforeZeMainFn; const ZIS_SHOULD_BE_EVEN_EARLIER: () = (); +//~^ arbitrary_source_item_ordering #[cfg(test)] mod test { diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs index 44902336573c..96b2fb16f8f5 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs @@ -103,20 +103,24 @@ impl TraitUnordered for StructUnordered { fn a() {} fn c() {} fn b() {} + //~^ arbitrary_source_item_ordering type SomeType = (); const A: bool = false; const C: bool = false; const B: bool = false; + //~^ arbitrary_source_item_ordering } impl TraitUnorderedItemKinds for StructUnordered { const A: bool = false; type SomeType = (); + //~^ arbitrary_source_item_ordering fn a() {} + //~^ arbitrary_source_item_ordering } struct StructUnorderedGeneric { @@ -143,20 +147,24 @@ trait TraitUnordered { fn a(); fn c(); fn b(); + //~^ arbitrary_source_item_ordering type SomeType; const A: bool; const C: bool; const B: bool; + //~^ arbitrary_source_item_ordering } trait TraitUnorderedItemKinds { const A: bool; type SomeType; + //~^ arbitrary_source_item_ordering fn a(); + //~^ arbitrary_source_item_ordering } #[derive(std::clone::Clone, Default)] diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.var_1.stderr b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.var_1.stderr index f31f7f68c17e..730f12c38a0d 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.var_1.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.var_1.stderr @@ -13,85 +13,85 @@ LL | fn c() {} = help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]` error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:111:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:112:11 | LL | const B: bool = false; | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:110:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:111:11 | LL | const C: bool = false; | ^ error: incorrect ordering of impl items (defined order: [Fn, Type, Const]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:117:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:119:5 | LL | type SomeType = (); | ^^^^^^^^^^^^^^^^^^^ | note: should be placed before `A` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:115:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:117:5 | LL | const A: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^ error: incorrect ordering of impl items (defined order: [Fn, Type, Const]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:119:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:122:5 | LL | fn a() {} | ^^^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:117:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:119:5 | LL | type SomeType = (); | ^^^^^^^^^^^^^^^^^^^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:145:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:149:8 | LL | fn b(); | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:144:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:148:8 | LL | fn c(); | ^ error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:151:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:156:11 | LL | const B: bool; | ^ | note: should be placed before `C` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:150:11 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:155:11 | LL | const C: bool; | ^ error: incorrect ordering of trait items (defined order: [Fn, Type, Const]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:157:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:163:5 | LL | type SomeType; | ^^^^^^^^^^^^^^ | note: should be placed before `A` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:155:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:161:5 | LL | const A: bool; | ^^^^^^^^^^^^^^ error: incorrect ordering of trait items (defined order: [Fn, Type, Const]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:159:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:166:5 | LL | fn a(); | ^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:157:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed_var_1.rs:163:5 | LL | type SomeType; | ^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs index e8002c4a1633..4e8ed5e550a3 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_enum.rs @@ -20,6 +20,7 @@ enum EnumOrdered { enum EnumUnordered { B, A, + //~^ arbitrary_source_item_ordering } trait TraitUnordered { diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.only_impl.stderr b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.only_impl.stderr index 40348ecbdae1..77596ba23946 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.only_impl.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.only_impl.stderr @@ -13,7 +13,7 @@ LL | fn b() {} = help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]` error: incorrect ordering of impl items (defined order: [Const, Type, Fn]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:46:5 | LL | type SomeType = i8; | ^^^^^^^^^^^^^^^^^^^ @@ -25,13 +25,13 @@ LL | fn a() {} | ^^^^^^^^^ error: incorrect ordering of impl items (defined order: [Const, Type, Fn]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:47:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:49:5 | LL | const A: bool = true; | ^^^^^^^^^^^^^^^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:45:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs:46:5 | LL | type SomeType = i8; | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs index bd969c865b5a..56e2e188be6a 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_impl.rs @@ -41,10 +41,13 @@ trait TraitUnordered { impl BasicTrait for StructUnordered { fn b() {} fn a() {} + //~^ arbitrary_source_item_ordering type SomeType = i8; + //~^ arbitrary_source_item_ordering const A: bool = true; + //~^ arbitrary_source_item_ordering } trait TraitUnorderedItemKinds { diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.only_trait.stderr b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.only_trait.stderr index 9b86ebd48e3d..3d903330be8f 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.only_trait.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.only_trait.stderr @@ -13,25 +13,25 @@ LL | const B: bool; = help: to override `-D warnings` add `#[allow(clippy::arbitrary_source_item_ordering)]` error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:37:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:38:8 | LL | fn a(); | ^ | note: should be placed before `b` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:36:8 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:37:8 | LL | fn b(); | ^ error: incorrect ordering of trait items (defined order: [Const, Type, Fn]) - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:43:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:45:5 | LL | const A: bool; | ^^^^^^^^^^^^^^ | note: should be placed before `SomeType` - --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:41:5 + --> tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs:43:5 | LL | type SomeType; | ^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs index 979a52ecb100..d885a20ca50a 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_only_trait.rs @@ -30,17 +30,20 @@ enum EnumUnordered { trait TraitUnordered { const B: bool; const A: bool; + //~^ arbitrary_source_item_ordering type SomeType; fn b(); fn a(); + //~^ arbitrary_source_item_ordering } trait TraitUnorderedItemKinds { type SomeType; const A: bool; + //~^ arbitrary_source_item_ordering fn a(); } diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs index 33f7c8ba8042..01a84a526c09 100644 --- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs +++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs @@ -67,6 +67,7 @@ fn lhs_and_rhs_are_equal() { let _ = Bar + Bar; // not on the list let _ = Baz + Baz; + //~^ arithmetic_side_effects } fn lhs_is_different() { @@ -78,13 +79,16 @@ fn lhs_is_different() { let _ = 1i32 + Bar; // not on the list let _ = 1i32 + Baz; + //~^ arithmetic_side_effects // not on the list let _ = 1i64 + Foo; + //~^ arithmetic_side_effects // is implicitly on the list let _ = 1i64 + Bar; // not on the list let _ = 1i64 + Baz; + //~^ arithmetic_side_effects } fn rhs_is_different() { @@ -96,13 +100,16 @@ fn rhs_is_different() { let _ = Bar + 1i32; // not on the list let _ = Baz + 1i32; + //~^ arithmetic_side_effects // not on the list let _ = Foo + 1i64; + //~^ arithmetic_side_effects // is implicitly on the list let _ = Bar + 1i64; // not on the list let _ = Baz + 1i64; + //~^ arithmetic_side_effects } fn unary() { @@ -112,8 +119,10 @@ fn unary() { let _ = -Foo; // not on the list let _ = -Bar; + //~^ arithmetic_side_effects // not on the list let _ = -Baz; + //~^ arithmetic_side_effects } fn main() {} diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr index 3c5216023b54..93efcc01c88f 100644 --- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr +++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr @@ -8,49 +8,49 @@ LL | let _ = Baz + Baz; = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:80:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:81:13 | LL | let _ = 1i32 + Baz; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:83:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:85:13 | LL | let _ = 1i64 + Foo; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:87:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:90:13 | LL | let _ = 1i64 + Baz; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:98:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:102:13 | LL | let _ = Baz + 1i32; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:101:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:106:13 | LL | let _ = Foo + 1i64; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:105:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:111:13 | LL | let _ = Baz + 1i64; | ^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:114:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:121:13 | LL | let _ = -Bar; | ^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:116:13 + --> tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs:124:13 | LL | let _ = -Baz; | ^^^^ 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 d36159e12639..b8652137378e 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.rs +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.rs @@ -2,9 +2,11 @@ #![warn(clippy::large_const_arrays, clippy::large_stack_arrays)] //@no-rustfix const ABOVE: [u8; 11] = [0; 11]; +//~^ large_const_arrays const BELOW: [u8; 10] = [0; 10]; fn main() { let above = [0u8; 11]; + //~^ large_stack_arrays let below = [0u8; 10]; } diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr index 41cb85b67df8..c962e8094076 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -10,7 +10,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: allocating a local array larger than 10 bytes - --> tests/ui-toml/array_size_threshold/array_size_threshold.rs:8:17 + --> tests/ui-toml/array_size_threshold/array_size_threshold.rs:9:17 | LL | let above = [0u8; 11]; | ^^^^^^^^^ diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs index 868cf00a8d46..6a9a49324db9 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs @@ -3,11 +3,13 @@ use std::net::Ipv4Addr; async fn bad() -> u32 { let _x = String::from("hello"); + //~^ await_holding_invalid_type baz().await } async fn bad_reason() -> u32 { let x = Ipv4Addr::new(127, 0, 0, 1); + //~^ await_holding_invalid_type let y = baz().await; let _x = x; y @@ -31,6 +33,7 @@ async fn baz() -> u32 { fn block_bad() -> impl std::future::Future { async move { let _x = String::from("hi!"); + //~^ await_holding_invalid_type baz().await } } diff --git a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index 39b8634be109..deb7f49db9e1 100644 --- a/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -9,13 +9,13 @@ LL | let _x = String::from("hello"); = help: to override `-D warnings` add `#[allow(clippy::await_holding_invalid_type)]` error: holding a disallowed type across an await point `std::net::Ipv4Addr` - --> tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs:10:9 + --> tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs:11:9 | LL | let x = Ipv4Addr::new(127, 0, 0, 1); | ^ error: holding a disallowed type across an await point `std::string::String` - --> tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs:33:13 + --> tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs:35:13 | LL | let _x = String::from("hi!"); | ^^ diff --git a/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs index f328e4d9d04c..b5a1f3def61e 100644 --- a/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs +++ b/tests/ui-toml/await_holding_invalid_type_with_replacement/await_holding_invalid_type.rs @@ -1 +1,2 @@ +//@error-in-other-file: fn main() {} diff --git a/tests/ui-toml/borrow_interior_mutable_const/ignore.rs b/tests/ui-toml/borrow_interior_mutable_const/ignore.rs index 79c7cef6ce1b..0514419fd189 100644 --- a/tests/ui-toml/borrow_interior_mutable_const/ignore.rs +++ b/tests/ui-toml/borrow_interior_mutable_const/ignore.rs @@ -1,4 +1,5 @@ //@compile-flags: --crate-name borrow_interior_mutable_const_ignore +//@check-pass #![warn(clippy::borrow_interior_mutable_const)] #![allow(clippy::declare_interior_mutable_const)] diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs index 7f1c512d7c97..ecb43dc34a8a 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs @@ -4,6 +4,7 @@ fn main() {} #[warn(clippy::cognitive_complexity)] fn cognitive_complexity() { + //~^ cognitive_complexity let x = vec![1, 2, 3]; for i in x { if i == 1 { diff --git a/tests/ui-toml/dbg_macro/dbg_macro.fixed b/tests/ui-toml/dbg_macro/dbg_macro.fixed index d42b29ba21a6..a91414559324 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.fixed +++ b/tests/ui-toml/dbg_macro/dbg_macro.fixed @@ -4,20 +4,27 @@ fn foo(n: u32) -> u32 { if let Some(n) = n.checked_sub(4) { n } else { n } + //~^ dbg_macro } fn factorial(n: u32) -> u32 { if n <= 1 { + //~^ dbg_macro 1 + //~^ dbg_macro } else { n * factorial(n - 1) + //~^ dbg_macro } } fn main() { 42; + //~^ dbg_macro foo(3) + factorial(4); + //~^ dbg_macro (1, 2, 3, 4, 5); + //~^ dbg_macro } #[test] diff --git a/tests/ui-toml/dbg_macro/dbg_macro.rs b/tests/ui-toml/dbg_macro/dbg_macro.rs index bd189b1576f9..6565f2e3cf7c 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.rs +++ b/tests/ui-toml/dbg_macro/dbg_macro.rs @@ -4,20 +4,27 @@ fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } + //~^ dbg_macro } fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { + //~^ dbg_macro dbg!(1) + //~^ dbg_macro } else { dbg!(n * factorial(n - 1)) + //~^ dbg_macro } } fn main() { dbg!(42); + //~^ dbg_macro foo(3) + dbg!(factorial(4)); + //~^ dbg_macro dbg!(1, 2, 3, 4, 5); + //~^ dbg_macro } #[test] diff --git a/tests/ui-toml/dbg_macro/dbg_macro.stderr b/tests/ui-toml/dbg_macro/dbg_macro.stderr index 129fab5ff97a..3d869f97c0af 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -12,7 +12,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:10:8 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:11:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:11:9 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:13:9 | LL | dbg!(1) | ^^^^^^^ @@ -34,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:13:9 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:16:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:18:5 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:22:5 | LL | dbg!(42); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:19:14 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:24:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:20:5 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:26:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/declare_interior_mutable_const/ignore.rs b/tests/ui-toml/declare_interior_mutable_const/ignore.rs index 6385cf4f852f..49ffc7a939de 100644 --- a/tests/ui-toml/declare_interior_mutable_const/ignore.rs +++ b/tests/ui-toml/declare_interior_mutable_const/ignore.rs @@ -1,4 +1,5 @@ //@compile-flags: --crate-name declare_interior_mutable_const_ignore +//@check-pass #![warn(clippy::declare_interior_mutable_const)] #![allow(clippy::borrow_interior_mutable_const)] diff --git a/tests/ui-toml/disallowed_macros/disallowed_macros.rs b/tests/ui-toml/disallowed_macros/disallowed_macros.rs index e63a99e74cbb..cfe19606ef4a 100644 --- a/tests/ui-toml/disallowed_macros/disallowed_macros.rs +++ b/tests/ui-toml/disallowed_macros/disallowed_macros.rs @@ -11,38 +11,54 @@ use serde::Serialize; fn main() { println!("one"); + //~^ disallowed_macros println!("two"); + //~^ disallowed_macros cfg!(unix); + //~^ disallowed_macros vec![1, 2, 3]; + //~^ disallowed_macros #[derive(Serialize)] + //~^ disallowed_macros struct Derive; let _ = macros::expr!(); + //~^ disallowed_macros macros::stmt!(); + //~^ disallowed_macros let macros::pat!() = 1; + //~^ disallowed_macros let _: macros::ty!() = ""; + //~^ disallowed_macros macros::item!(); + //~^ disallowed_macros let _ = macros::binop!(1); + //~^ disallowed_macros eprintln!("allowed"); } macros::attr! { +//~^ disallowed_macros struct S; } impl S { macros::item!(); + //~^ disallowed_macros } trait Y { macros::item!(); + //~^ disallowed_macros } impl Y for S { macros::item!(); + //~^ disallowed_macros } #[derive(Derive)] +//~^ disallowed_macros struct Foo; diff --git a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr index 6a6c6168a1f5..589995fa87d9 100644 --- a/tests/ui-toml/disallowed_macros/disallowed_macros.stderr +++ b/tests/ui-toml/disallowed_macros/disallowed_macros.stderr @@ -1,5 +1,5 @@ error: use of a disallowed macro `serde::Serialize` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:18:14 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:22:14 | LL | #[derive(Serialize)] | ^^^^^^^^^ @@ -9,15 +9,16 @@ LL | #[derive(Serialize)] = help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]` error: use of a disallowed macro `macros::attr` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:31:1 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:42:1 | LL | / macros::attr! { +LL | | LL | | struct S; LL | | } | |_^ error: use of a disallowed macro `proc_macros::Derive` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:47:10 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:62:10 | LL | #[derive(Derive)] | ^^^^^^ @@ -29,73 +30,73 @@ LL | println!("one"); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `std::println` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:14:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:15:5 | LL | println!("two"); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `std::cfg` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:15:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:17:5 | LL | cfg!(unix); | ^^^^^^^^^^ error: use of a disallowed macro `std::vec` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:16:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:19:5 | LL | vec![1, 2, 3]; | ^^^^^^^^^^^^^ error: use of a disallowed macro `macros::expr` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:21:13 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:26:13 | LL | let _ = macros::expr!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::stmt` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:22:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:28:5 | LL | macros::stmt!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::pat` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:23:9 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:30:9 | LL | let macros::pat!() = 1; | ^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::ty` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:24:12 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:32:12 | LL | let _: macros::ty!() = ""; | ^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:25:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:34:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::binop` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:26:13 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:36:13 | LL | let _ = macros::binop!(1); | ^^^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:36:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:48:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:40:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:53:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:44:5 + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:58:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/disallowed_names_append/disallowed_names.rs b/tests/ui-toml/disallowed_names_append/disallowed_names.rs index 61ae8de8e335..ea7e31a119dc 100644 --- a/tests/ui-toml/disallowed_names_append/disallowed_names.rs +++ b/tests/ui-toml/disallowed_names_append/disallowed_names.rs @@ -3,8 +3,10 @@ fn main() { // `foo` is part of the default configuration let foo = "bar"; + //~^ disallowed_names // `ducks` was unrightfully disallowed let ducks = ["quack", "quack"]; + //~^ disallowed_names // `fox` is okay let fox = ["what", "does", "the", "fox", "say", "?"]; } diff --git a/tests/ui-toml/disallowed_names_append/disallowed_names.stderr b/tests/ui-toml/disallowed_names_append/disallowed_names.stderr index e6481c9cc63b..6b7a3fbd8c8d 100644 --- a/tests/ui-toml/disallowed_names_append/disallowed_names.stderr +++ b/tests/ui-toml/disallowed_names_append/disallowed_names.stderr @@ -8,7 +8,7 @@ LL | let foo = "bar"; = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `ducks` - --> tests/ui-toml/disallowed_names_append/disallowed_names.rs:7:9 + --> tests/ui-toml/disallowed_names_append/disallowed_names.rs:8:9 | LL | let ducks = ["quack", "quack"]; | ^^^^^ diff --git a/tests/ui-toml/disallowed_names_replace/disallowed_names.rs b/tests/ui-toml/disallowed_names_replace/disallowed_names.rs index 61ae8de8e335..dd79795d76a2 100644 --- a/tests/ui-toml/disallowed_names_replace/disallowed_names.rs +++ b/tests/ui-toml/disallowed_names_replace/disallowed_names.rs @@ -5,6 +5,7 @@ fn main() { let foo = "bar"; // `ducks` was unrightfully disallowed let ducks = ["quack", "quack"]; + //~^ disallowed_names // `fox` is okay let fox = ["what", "does", "the", "fox", "say", "?"]; } diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed index f16e138da2be..e295712e85f4 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed @@ -7,6 +7,7 @@ fn allowed_name() {} fn default_name() {} /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +//~^ doc_markdown fn unknown_name() {} fn main() {} diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs b/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs index 327a592e9cad..192652a7f65b 100644 --- a/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.rs @@ -7,6 +7,7 @@ fn allowed_name() {} fn default_name() {} /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +//~^ doc_markdown 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 index af6ec675e81b..48a6f5fe61e6 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed @@ -4,9 +4,12 @@ fn allowed_name() {} /// `OAuth` and `LaTeX` are inside Clippy's default list. +//~^ doc_markdown +//~| doc_markdown fn default_name() {} /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +//~^ doc_markdown fn unknown_name() {} fn main() {} diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs index 327a592e9cad..f700c1ab0336 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs @@ -4,9 +4,12 @@ fn allowed_name() {} /// OAuth and LaTeX are inside Clippy's default list. +//~^ doc_markdown +//~| doc_markdown fn default_name() {} /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. +//~^ doc_markdown fn unknown_name() {} fn main() {} diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index d4d8a579798c..cb5f5abda6c6 100644 --- a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -23,7 +23,7 @@ LL | /// OAuth and `LaTeX` are inside Clippy's default list. | ~~~~~~~ error: item in documentation is missing backticks - --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:9:5 + --> tests/ui-toml/doc_valid_idents_replace/doc_markdown.rs:11:5 | LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and should be linted. | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.rs b/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.rs index f328e4d9d04c..b5a1f3def61e 100644 --- a/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.rs +++ b/tests/ui-toml/duplicated_keys_deprecated/duplicated_keys.rs @@ -1 +1,2 @@ +//@error-in-other-file: fn main() {} diff --git a/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.rs b/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.rs index f328e4d9d04c..b5a1f3def61e 100644 --- a/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.rs +++ b/tests/ui-toml/duplicated_keys_deprecated_2/duplicated_keys.rs @@ -1 +1,2 @@ +//@error-in-other-file: fn main() {} diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/tests/ui-toml/excessive_nesting/excessive_nesting.rs index 858aab528a91..205cd8ba4ee8 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -23,6 +23,7 @@ static X: u32 = { let y = { let z = { let w = { 3 }; + //~^ excessive_nesting w }; z @@ -69,6 +70,7 @@ impl A { struct C; impl C { + //~^ excessive_nesting pub fn c() {} } } @@ -83,6 +85,7 @@ trait Lol { fn bb() { fn cc() { let x = { 1 }; // not a warning, but cc is + //~^ excessive_nesting } let x = { 1 }; // warning @@ -100,6 +103,7 @@ pub mod a { pub mod c { pub mod d { pub mod e { + //~^ excessive_nesting pub mod f {} } // not here } // only warning should be here @@ -113,13 +117,17 @@ fn main() { let a = A; a_but_not({{{{{{{{0}}}}}}}}); + //~^ excessive_nesting a.a({{{{{{{{{0}}}}}}}}}); + //~^ excessive_nesting (0, {{{{{{{1}}}}}}}); + //~^ excessive_nesting if true { if true { if true { if true { + //~^ excessive_nesting if true { } @@ -132,6 +140,7 @@ fn main() { let x = (|| { let y = (|| { let z = (|| { + //~^ excessive_nesting let w = { 3 }; w })(); @@ -151,38 +160,64 @@ fn main() { // this is a mess, but that's intentional let mut y = 1; y += {{{{{5}}}}}; + //~^ excessive_nesting let z = y + {{{{{{{{{5}}}}}}}}}; + //~^ excessive_nesting [0, {{{{{{{{{{0}}}}}}}}}}]; + //~^ excessive_nesting let mut xx = [0; {{{{{{{{100}}}}}}}}]; + //~^ excessive_nesting xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; + //~^ excessive_nesting &mut {{{{{{{{{{y}}}}}}}}}}; + //~^ excessive_nesting for i in {{{{xx}}}} {{{{{{{{}}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} + //~^ excessive_nesting + //~| excessive_nesting let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; + //~^ excessive_nesting {{{{1;}}}}..{{{{{{3}}}}}}; + //~^ excessive_nesting + //~| excessive_nesting {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; + //~^ excessive_nesting + //~| excessive_nesting ..{{{{{{{5}}}}}}}; + //~^ excessive_nesting ..={{{{{3}}}}}; + //~^ excessive_nesting {{{{{1;}}}}}..; + //~^ excessive_nesting loop { break {{{{1}}}} }; + //~^ excessive_nesting loop {{{{{{}}}}}} + //~^ excessive_nesting match {{{{{{true}}}}}} { + //~^ excessive_nesting true => {{{{}}}}, + //~^ excessive_nesting false => {{{{}}}}, + //~^ excessive_nesting } { { { { + //~^ excessive_nesting println!("warning! :)"); } } @@ -192,10 +227,12 @@ fn main() { async fn b() -> u32 { async fn c() -> u32 {{{{{{{0}}}}}}} + //~^ excessive_nesting c().await } async fn a() { {{{{b().await}}}}; + //~^ excessive_nesting } diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index 9cf6fc66757d..bc2c4b8612ec 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -9,9 +9,10 @@ LL | let w = { 3 }; = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:71:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:72:17 | LL | / impl C { +LL | | LL | | pub fn c() {} LL | | } | |_________________^ @@ -19,7 +20,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:85:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:87:25 | LL | let x = { 1 }; // not a warning, but cc is | ^^^^^ @@ -27,9 +28,10 @@ LL | let x = { 1 }; // not a warning, but cc is = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:102:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:105:17 | LL | / pub mod e { +LL | | LL | | pub mod f {} LL | | } // not here | |_________________^ @@ -37,7 +39,7 @@ LL | | } // not here = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:115:18 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:119:18 | LL | a_but_not({{{{{{{{0}}}}}}}}); | ^^^^^^^^^^^ @@ -45,7 +47,7 @@ LL | a_but_not({{{{{{{{0}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:116:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:121:12 | LL | a.a({{{{{{{{{0}}}}}}}}}); | ^^^^^^^^^^^^^ @@ -53,7 +55,7 @@ LL | a.a({{{{{{{{{0}}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:117:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:123:12 | LL | (0, {{{{{{{1}}}}}}}); | ^^^^^^^^^ @@ -61,10 +63,11 @@ LL | (0, {{{{{{{1}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:122:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:129:25 | LL | if true { | _________________________^ +LL | | LL | | if true { ... | LL | | } @@ -73,10 +76,11 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:134:29 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:142:29 | LL | let z = (|| { | _____________________________^ +LL | | LL | | let w = { 3 }; LL | | w LL | | })(); @@ -85,7 +89,7 @@ LL | | })(); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:153:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:13 | LL | y += {{{{{5}}}}}; | ^^^^^ @@ -93,7 +97,7 @@ LL | y += {{{{{5}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:154:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:20 | LL | let z = y + {{{{{{{{{5}}}}}}}}}; | ^^^^^^^^^^^^^ @@ -101,7 +105,7 @@ LL | let z = y + {{{{{{{{{5}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:155:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:12 | LL | [0, {{{{{{{{{{0}}}}}}}}}}]; | ^^^^^^^^^^^^^^^ @@ -109,7 +113,7 @@ LL | [0, {{{{{{{{{{0}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:156:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:25 | LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; | ^^^^^^^^^^^^^ @@ -117,7 +121,7 @@ LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:157:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:11 | LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -125,7 +129,7 @@ LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:158:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:172:13 | LL | &mut {{{{{{{{{{y}}}}}}}}}}; | ^^^^^^^^^^^^^^^ @@ -133,7 +137,7 @@ LL | &mut {{{{{{{{{{y}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:17 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^ @@ -141,7 +145,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:160:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:28 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^^^^^^^ @@ -149,7 +153,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:28 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^^^^^^ @@ -157,7 +161,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:48 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:48 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^ @@ -165,7 +169,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:183:14 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^^^ @@ -173,7 +177,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:35 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:183:35 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^ @@ -181,7 +185,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:23 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:187:23 | LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +193,7 @@ LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:8 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^ @@ -197,7 +201,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:20 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^^^^ @@ -205,7 +209,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:193:8 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^ @@ -213,7 +217,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:193:21 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -221,7 +225,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:10 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:196:10 | LL | ..{{{{{{{5}}}}}}}; | ^^^^^^^^^ @@ -229,7 +233,7 @@ LL | ..{{{{{{{5}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:198:11 | LL | ..={{{{{3}}}}}; | ^^^^^ @@ -237,7 +241,7 @@ LL | ..={{{{{3}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:172:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:200:8 | LL | {{{{{1;}}}}}..; | ^^^^^^ @@ -245,7 +249,7 @@ LL | {{{{{1;}}}}}..; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:174:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:203:20 | LL | loop { break {{{{1}}}} }; | ^^^^^ @@ -253,7 +257,7 @@ LL | loop { break {{{{1}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:205:13 | LL | loop {{{{{{}}}}}} | ^^^^^^ @@ -261,7 +265,7 @@ LL | loop {{{{{{}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:177:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:208:14 | LL | match {{{{{{true}}}}}} { | ^^^^^^^^^^ @@ -269,7 +273,7 @@ LL | match {{{{{{true}}}}}} { = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:178:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:210:20 | LL | true => {{{{}}}}, | ^^ @@ -277,7 +281,7 @@ LL | true => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:212:21 | LL | false => {{{{}}}}, | ^^ @@ -285,9 +289,10 @@ LL | false => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:185:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:219:17 | LL | / { +LL | | LL | | println!("warning! :)"); LL | | } | |_________________^ @@ -295,7 +300,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:194:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:229:28 | LL | async fn c() -> u32 {{{{{{{0}}}}}}} | ^^^^^^^^^ @@ -303,7 +308,7 @@ LL | async fn c() -> u32 {{{{{{{0}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:200:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:236:8 | LL | {{{{b().await}}}}; | ^^^^^^^^^^^ diff --git a/tests/ui-toml/expect_used/expect_used.rs b/tests/ui-toml/expect_used/expect_used.rs index f0b92329f97a..9955c9b6baa1 100644 --- a/tests/ui-toml/expect_used/expect_used.rs +++ b/tests/ui-toml/expect_used/expect_used.rs @@ -6,11 +6,13 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); + //~^ expect_used } fn expect_result() { let res: Result = Ok(0); let _ = res.expect(""); + //~^ expect_used } fn main() { @@ -19,10 +21,10 @@ fn main() { const SOME: Option = Some(3); const UNWRAPPED: i32 = SOME.expect("Not three?"); - //~^ ERROR: used `expect()` on an `Option` value + //~^ expect_used const { SOME.expect("Still not three?"); - //~^ ERROR: used `expect()` on an `Option` value + //~^ expect_used } } diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr index b28bb7b7e0d1..3bb471e6dfcc 100644 --- a/tests/ui-toml/expect_used/expect_used.stderr +++ b/tests/ui-toml/expect_used/expect_used.stderr @@ -9,7 +9,7 @@ LL | let _ = opt.expect(""); = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value - --> tests/ui-toml/expect_used/expect_used.rs:13:13 + --> tests/ui-toml/expect_used/expect_used.rs:14:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect()` on an `Option` value - --> tests/ui-toml/expect_used/expect_used.rs:21:28 + --> tests/ui-toml/expect_used/expect_used.rs:23:28 | LL | const UNWRAPPED: i32 = SOME.expect("Not three?"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | const UNWRAPPED: i32 = SOME.expect("Not three?"); = note: if this value is `None`, it will panic error: used `expect()` on an `Option` value - --> tests/ui-toml/expect_used/expect_used.rs:24:9 + --> tests/ui-toml/expect_used/expect_used.rs:26:9 | LL | SOME.expect("Still not three?"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/extra_unused_type_parameters/extra_unused_type_parameters.rs b/tests/ui-toml/extra_unused_type_parameters/extra_unused_type_parameters.rs index 5655232455cb..1256c93c0fa1 100644 --- a/tests/ui-toml/extra_unused_type_parameters/extra_unused_type_parameters.rs +++ b/tests/ui-toml/extra_unused_type_parameters/extra_unused_type_parameters.rs @@ -1,3 +1,4 @@ +//@check-pass pub struct S; impl S { diff --git a/tests/ui-toml/fn_params_excessive_bools/test.rs b/tests/ui-toml/fn_params_excessive_bools/test.rs index 42897b389edf..af8b8a7991ab 100644 --- a/tests/ui-toml/fn_params_excessive_bools/test.rs +++ b/tests/ui-toml/fn_params_excessive_bools/test.rs @@ -2,5 +2,6 @@ fn f(_: bool) {} fn g(_: bool, _: bool) {} +//~^ fn_params_excessive_bools fn main() {} diff --git a/tests/ui-toml/functions_maxlines/test.rs b/tests/ui-toml/functions_maxlines/test.rs index 4ac0378544c7..09d76a9b2657 100644 --- a/tests/ui-toml/functions_maxlines/test.rs +++ b/tests/ui-toml/functions_maxlines/test.rs @@ -17,18 +17,21 @@ fn many_comments_but_one_line_of_code() { // This should be considered two and a fail. fn too_many_lines() { + //~^ too_many_lines println!("This is bad."); println!("This is bad."); } // This should only fail once (#7517). async fn async_too_many_lines() { + //~^ too_many_lines println!("This is bad."); println!("This is bad."); } // This should fail only once, without failing on the closure. fn closure_too_many_lines() { + //~^ too_many_lines let _ = { println!("This is bad."); println!("This is bad."); @@ -51,6 +54,7 @@ fn comment_after_code() { // This should fail since it is technically two lines. #[rustfmt::skip] fn comment_before_code() { +//~^ too_many_lines let _ = "test"; /* This comment extends to the front of the code but this line should still count. */ let _ = 5; diff --git a/tests/ui-toml/functions_maxlines/test.stderr b/tests/ui-toml/functions_maxlines/test.stderr index cb188a868c44..14a49cb76c1c 100644 --- a/tests/ui-toml/functions_maxlines/test.stderr +++ b/tests/ui-toml/functions_maxlines/test.stderr @@ -2,6 +2,7 @@ error: this function has too many lines (2/1) --> tests/ui-toml/functions_maxlines/test.rs:19:1 | LL | / fn too_many_lines() { +LL | | LL | | println!("This is bad."); LL | | println!("This is bad."); LL | | } @@ -11,18 +12,20 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: this function has too many lines (4/1) - --> tests/ui-toml/functions_maxlines/test.rs:25:1 + --> tests/ui-toml/functions_maxlines/test.rs:26:1 | LL | / async fn async_too_many_lines() { +LL | | LL | | println!("This is bad."); LL | | println!("This is bad."); LL | | } | |_^ error: this function has too many lines (4/1) - --> tests/ui-toml/functions_maxlines/test.rs:31:1 + --> tests/ui-toml/functions_maxlines/test.rs:33:1 | LL | / fn closure_too_many_lines() { +LL | | LL | | let _ = { LL | | println!("This is bad."); LL | | println!("This is bad."); @@ -31,9 +34,10 @@ LL | | } | |_^ error: this function has too many lines (2/1) - --> tests/ui-toml/functions_maxlines/test.rs:53:1 + --> tests/ui-toml/functions_maxlines/test.rs:56:1 | LL | / fn comment_before_code() { +LL | | LL | | let _ = "test"; LL | | /* This comment extends to the front of LL | | the code but this line should still count. */ let _ = 5; diff --git a/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs b/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs index f328e4d9d04c..9763a0977801 100644 --- a/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs +++ b/tests/ui-toml/good_toml_no_false_negatives/conf_no_false_negatives.rs @@ -1 +1,2 @@ +//@check-pass fn main() {} diff --git a/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs b/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs index 4882416c414a..e953a2a4e90b 100644 --- a/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs +++ b/tests/ui-toml/ifs_same_cond/ifs_same_cond.rs @@ -13,6 +13,7 @@ fn issue10272() { if x.get() { } else if !x.take() { } else if x.get() { + //~^ ifs_same_cond } else { } } diff --git a/tests/ui-toml/indexing_slicing/indexing_slicing.rs b/tests/ui-toml/indexing_slicing/indexing_slicing.rs index 0a0da88ea1fa..dd741be91d29 100644 --- a/tests/ui-toml/indexing_slicing/indexing_slicing.rs +++ b/tests/ui-toml/indexing_slicing/indexing_slicing.rs @@ -6,6 +6,7 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; &x[index..]; + //~^ indexing_slicing } #[cfg(test)] diff --git a/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs b/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs index 2ae673a6def0..d6b0a3017920 100644 --- a/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs +++ b/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs @@ -7,6 +7,7 @@ pub mod foo { // this line should produce a warning: pub fn to_foo() {} + //~^ module_name_repetitions // but this line shouldn't pub fn bar_foo() {} diff --git a/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs b/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs index dbd61992c0d6..347430f3d2f9 100644 --- a/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs +++ b/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs @@ -7,6 +7,7 @@ pub mod foo { // this line should produce a warning: pub fn something_foo() {} + //~^ module_name_repetitions // but none of the following should: pub fn bar_foo() {} diff --git a/tests/ui-toml/item_name_repetitions/threshold0/item_name_repetitions.rs b/tests/ui-toml/item_name_repetitions/threshold0/item_name_repetitions.rs index b633dcbd19e4..f05e2410f7e2 100644 --- a/tests/ui-toml/item_name_repetitions/threshold0/item_name_repetitions.rs +++ b/tests/ui-toml/item_name_repetitions/threshold0/item_name_repetitions.rs @@ -1,3 +1,5 @@ +//@check-pass + struct Data {} enum Actions {} diff --git a/tests/ui-toml/large_futures/large_futures.fixed b/tests/ui-toml/large_futures/large_futures.fixed index 7dea9fb95b4b..17d6553a283b 100644 --- a/tests/ui-toml/large_futures/large_futures.fixed +++ b/tests/ui-toml/large_futures/large_futures.fixed @@ -16,6 +16,7 @@ pub async fn should_not_warn() { pub async fn bar() { Box::pin(should_warn()).await; + //~^ large_futures async { let x = [0u8; 1024]; diff --git a/tests/ui-toml/large_futures/large_futures.rs b/tests/ui-toml/large_futures/large_futures.rs index 4158df8b5ff5..bc601227e562 100644 --- a/tests/ui-toml/large_futures/large_futures.rs +++ b/tests/ui-toml/large_futures/large_futures.rs @@ -16,6 +16,7 @@ pub async fn should_not_warn() { pub async fn bar() { should_warn().await; + //~^ large_futures async { let x = [0u8; 1024]; diff --git a/tests/ui-toml/large_include_file/large_include_file.rs b/tests/ui-toml/large_include_file/large_include_file.rs index 184c6d17ba41..685ef1689e72 100644 --- a/tests/ui-toml/large_include_file/large_include_file.rs +++ b/tests/ui-toml/large_include_file/large_include_file.rs @@ -2,7 +2,7 @@ #![allow(clippy::literal_string_with_formatting_args)] // Good -const GOOD_INCLUDE_BYTES: &[u8; 68] = include_bytes!("../../ui/author.rs"); +const GOOD_INCLUDE_BYTES: &[u8; 84] = include_bytes!("../../ui/author.rs"); const GOOD_INCLUDE_STR: &str = include_str!("../../ui/author.rs"); #[allow(clippy::large_include_file)] diff --git a/tests/ui-toml/lint_decimal_readability/test.fixed b/tests/ui-toml/lint_decimal_readability/test.fixed index f013153f5166..2d76824128bf 100644 --- a/tests/ui-toml/lint_decimal_readability/test.fixed +++ b/tests/ui-toml/lint_decimal_readability/test.fixed @@ -17,7 +17,9 @@ fn main() { // due to clippy::inconsistent-digit-grouping let _fail1 = 100_200_300.123_456_789; + //~^ inconsistent_digit_grouping // fail due to the integer part let _fail2 = 100_200_300.300_200_100; + //~^ unreadable_literal } diff --git a/tests/ui-toml/lint_decimal_readability/test.rs b/tests/ui-toml/lint_decimal_readability/test.rs index bd5110138c8c..b42e31085217 100644 --- a/tests/ui-toml/lint_decimal_readability/test.rs +++ b/tests/ui-toml/lint_decimal_readability/test.rs @@ -17,7 +17,9 @@ fn main() { // due to clippy::inconsistent-digit-grouping let _fail1 = 100_200_300.123456789; + //~^ inconsistent_digit_grouping // fail due to the integer part let _fail2 = 100200300.300200100; + //~^ unreadable_literal } diff --git a/tests/ui-toml/lint_decimal_readability/test.stderr b/tests/ui-toml/lint_decimal_readability/test.stderr index 766722d35ab7..c4e164c67ed8 100644 --- a/tests/ui-toml/lint_decimal_readability/test.stderr +++ b/tests/ui-toml/lint_decimal_readability/test.stderr @@ -8,7 +8,7 @@ LL | let _fail1 = 100_200_300.123456789; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: long literal lacking separators - --> tests/ui-toml/lint_decimal_readability/test.rs:22:18 + --> tests/ui-toml/lint_decimal_readability/test.rs:23:18 | LL | let _fail2 = 100200300.300200100; | ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100` diff --git a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs index 3dafea56514d..2465fe45645f 100644 --- a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs +++ b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs @@ -17,7 +17,7 @@ macro_rules! allow_works { macro_rules! simple { ($v:expr) => { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe dbg!($v); } }; @@ -28,7 +28,7 @@ macro_rules! simple { macro_rules! raw_symbol { ($r#mod:expr, $r#unsafe:expr) => { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $r#mod; } $r#unsafe; @@ -40,7 +40,7 @@ macro_rules! multilevel_unsafe { ($v:expr) => { unsafe { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $v; } } @@ -65,7 +65,7 @@ macro_rules! in_function_with_unsafe { unsafe { fn f() { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $v; } } @@ -93,7 +93,7 @@ macro_rules! const_generic_in_struct { const M: i32 = { 1; unsafe { $inside_unsafe } - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe }, const N: i32 = { $outside_unsafe }, >; @@ -108,7 +108,7 @@ macro_rules! fn_with_const_generic { fn f() { $outside_unsafe; unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $inside_unsafe; } } @@ -120,7 +120,7 @@ macro_rules! fn_with_const_generic { macro_rules! variables { ($inside_unsafe:expr, $outside_unsafe:expr) => { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $inside_unsafe; let inside_unsafe = 1; inside_unsafe; @@ -135,7 +135,7 @@ macro_rules! variables { macro_rules! multiple_matchers { ($inside_unsafe:expr, $outside_unsafe:expr) => { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $inside_unsafe; } $outside_unsafe; @@ -144,7 +144,7 @@ macro_rules! multiple_matchers { $( $v; unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $x; } );+ @@ -156,11 +156,11 @@ macro_rules! multiple_unsafe_blocks { ($w:expr, $x:expr, $y:expr) => { $w; unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $x; } unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $x; $y; } @@ -169,7 +169,7 @@ macro_rules! multiple_unsafe_blocks { pub macro macro2_0($v:expr) { unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $v; } } @@ -220,7 +220,7 @@ macro_rules! unsafe_from_root_ctxt { macro_rules! nested_macro_helper { ($v:expr) => {{ unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe $v; } }}; @@ -230,7 +230,7 @@ macro_rules! nested_macro_helper { macro_rules! nested_macros { ($v:expr, $v2:expr) => {{ unsafe { - //~^ ERROR: this macro expands metavariables in an unsafe block + //~^ macro_metavars_in_unsafe nested_macro_helper!($v); $v; } @@ -243,6 +243,7 @@ pub mod issue13219 { ($e:expr) => { // Metavariable in a block tail expression unsafe { $e } + //~^ macro_metavars_in_unsafe }; } pub fn f(p: *const i32) -> i32 { diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.rs b/tests/ui-toml/min_ident_chars/min_ident_chars.rs index ded3c72c3e04..385e23d69bcd 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.rs +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.rs @@ -4,19 +4,27 @@ extern crate extern_types; use extern_types::{Aaa, LONGER, M, N as W}; +//~^ min_ident_chars pub const N: u32 = 0; +//~^ min_ident_chars pub const LONG: u32 = 32; struct Owo { Uwu: u128, aaa: Aaa, + //~^ min_ident_chars } fn main() { let wha = 1; let vvv = 1; + //~^ min_ident_chars let uuu = 1; + //~^ min_ident_chars let (mut a, mut b) = (1, 2); + //~^ min_ident_chars + //~| min_ident_chars for i in 0..1000 {} + //~^ min_ident_chars } diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr index 63a057aca279..be795f4daff2 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr @@ -8,43 +8,43 @@ LL | use extern_types::{Aaa, LONGER, M, N as W}; = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident is too short (1 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:8:11 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:9:11 | LL | pub const N: u32 = 0; | ^ error: this ident is too short (3 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:13:5 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:15:5 | LL | aaa: Aaa, | ^^^ error: this ident is too short (3 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:18:9 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:21:9 | LL | let vvv = 1; | ^^^ error: this ident is too short (3 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:19:9 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:23:9 | LL | let uuu = 1; | ^^^ error: this ident is too short (1 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:20:14 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:25:14 | LL | let (mut a, mut b) = (1, 2); | ^ error: this ident is too short (1 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:20:21 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:25:21 | LL | let (mut a, mut b) = (1, 2); | ^ error: this ident is too short (1 <= 3) - --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:21:9 + --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:28:9 | LL | for i in 0..1000 {} | ^ diff --git a/tests/ui-toml/min_rust_version/min_rust_version.fixed b/tests/ui-toml/min_rust_version/min_rust_version.fixed index 497f783087a1..685f77b7efe8 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.fixed +++ b/tests/ui-toml/min_rust_version/min_rust_version.fixed @@ -72,6 +72,7 @@ fn check_index_refutable_slice() { fn map_clone_suggest_copied() { // This should still trigger the lint but suggest `cloned()` instead of `copied()` let _: Option = Some(&16).cloned(); + //~^ map_clone } fn borrow_as_ptr() { diff --git a/tests/ui-toml/min_rust_version/min_rust_version.rs b/tests/ui-toml/min_rust_version/min_rust_version.rs index 6e7874108a34..0bf073af8903 100644 --- a/tests/ui-toml/min_rust_version/min_rust_version.rs +++ b/tests/ui-toml/min_rust_version/min_rust_version.rs @@ -72,6 +72,7 @@ fn check_index_refutable_slice() { fn map_clone_suggest_copied() { // This should still trigger the lint but suggest `cloned()` instead of `copied()` let _: Option = Some(&16).map(|b| *b); + //~^ map_clone } fn 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 index a6072111dc06..3e882f496985 100644 --- 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 @@ -3,14 +3,20 @@ use std::alloc as colla; use std::option::Option as Maybe; use std::process::{Child as Kid, exit as goodbye}; +//~^ missing_enforced_import_renames use std::thread::sleep as thread_sleep; +//~^ missing_enforced_import_renames #[rustfmt::skip] use std::{ any::{type_name as ident, Any}, + //~^ missing_enforced_import_renames clone as foo, + //~^ missing_enforced_import_renames sync :: Mutex as StdMutie, + //~^ missing_enforced_import_renames }; fn main() { use std::collections::BTreeMap as Map; + //~^ missing_enforced_import_renames } diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs index c2b61aab5b3c..32255af5117f 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs @@ -3,14 +3,20 @@ use std::alloc as colla; use std::option::Option as Maybe; use std::process::{Child as Kid, exit as wrong_exit}; +//~^ missing_enforced_import_renames use std::thread::sleep; +//~^ missing_enforced_import_renames #[rustfmt::skip] use std::{ any::{type_name, Any}, + //~^ missing_enforced_import_renames clone, + //~^ missing_enforced_import_renames sync :: Mutex, + //~^ missing_enforced_import_renames }; fn main() { use std::collections::BTreeMap as OopsWrongRename; + //~^ missing_enforced_import_renames } diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr index d3bb07ec47fd..982b144eb872 100644 --- a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr @@ -8,31 +8,31 @@ LL | use std::process::{Child as Kid, exit as wrong_exit}; = help: to override `-D warnings` add `#[allow(clippy::missing_enforced_import_renames)]` error: this import should be renamed - --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:6:1 + --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:7:1 | LL | use std::thread::sleep; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `use std::thread::sleep as thread_sleep` error: this import should be renamed - --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:9:11 + --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:11:11 | LL | any::{type_name, Any}, | ^^^^^^^^^ help: try: `type_name as ident` error: this import should be renamed - --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:10:5 + --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:13:5 | LL | clone, | ^^^^^ help: try: `clone as foo` error: this import should be renamed - --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:11:5 + --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:15:5 | LL | sync :: Mutex, | ^^^^^^^^^^^^^ help: try: `sync :: Mutex as StdMutie` error: this import should be renamed - --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:15:5 + --> tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.rs:20:5 | LL | use std::collections::BTreeMap as OopsWrongRename; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `use std::collections::BTreeMap as Map` diff --git a/tests/ui-toml/module_inception/module_inception.rs b/tests/ui-toml/module_inception/module_inception.rs index cd495c884a43..94866a7e81bf 100644 --- a/tests/ui-toml/module_inception/module_inception.rs +++ b/tests/ui-toml/module_inception/module_inception.rs @@ -4,11 +4,13 @@ pub mod foo2 { pub mod bar2 { pub mod bar2 { + //~^ module_inception pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { + //~^ module_inception pub mod bar2 {} } } diff --git a/tests/ui-toml/module_inception/module_inception.stderr b/tests/ui-toml/module_inception/module_inception.stderr index 75e78c829226..efef1d010233 100644 --- a/tests/ui-toml/module_inception/module_inception.stderr +++ b/tests/ui-toml/module_inception/module_inception.stderr @@ -2,6 +2,7 @@ error: module has the same name as its containing module --> tests/ui-toml/module_inception/module_inception.rs:6:9 | LL | / pub mod bar2 { +LL | | LL | | pub mod foo2 {} LL | | } | |_________^ @@ -10,9 +11,10 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module - --> tests/ui-toml/module_inception/module_inception.rs:11:5 + --> tests/ui-toml/module_inception/module_inception.rs:12:5 | LL | / pub mod foo2 { +LL | | LL | | pub mod bar2 {} LL | | } | |_____^ diff --git a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs index 27d27564baf3..7e42f095cbba 100644 --- a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs +++ b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs @@ -4,7 +4,11 @@ fn main() { let a = -1; let b = 2; let c = a % b == 0; + //~^ modulo_arithmetic let c = a % b != 0; + //~^ modulo_arithmetic let c = 0 == a % b; + //~^ modulo_arithmetic let c = 0 != a % b; + //~^ modulo_arithmetic } diff --git a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.stderr b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.stderr index 8d01b66522c6..02286f66f4d1 100644 --- a/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.stderr +++ b/tests/ui-toml/modulo_arithmetic/modulo_arithmetic.stderr @@ -10,7 +10,7 @@ LL | let c = a % b == 0; = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on types that might have different signs - --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:7:13 + --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:8:13 | LL | let c = a % b != 0; | ^^^^^ @@ -19,7 +19,7 @@ LL | let c = a % b != 0; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:8:18 + --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:10:18 | LL | let c = 0 == a % b; | ^^^^^ @@ -28,7 +28,7 @@ LL | let c = 0 == a % b; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:9:18 + --> tests/ui-toml/modulo_arithmetic/modulo_arithmetic.rs:12:18 | LL | let c = 0 != a % b; | ^^^^^ diff --git a/tests/ui-toml/mut_key/mut_key.rs b/tests/ui-toml/mut_key/mut_key.rs index 3a8e3741e20c..b23c2340b7d6 100644 --- a/tests/ui-toml/mut_key/mut_key.rs +++ b/tests/ui-toml/mut_key/mut_key.rs @@ -1,4 +1,5 @@ //@compile-flags: --crate-name mut_key +//@check-pass #![warn(clippy::mutable_key_type)] diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed index fd20bdff6e25..6b386046efa7 100644 --- a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed @@ -4,6 +4,9 @@ fn main() { r#"\aaa"#; r#"\aaa"#; + //~^ needless_raw_string_hashes r#"Hello "world"!"#; + //~^ needless_raw_string_hashes r####" "### "## "# "####; + //~^ needless_raw_string_hashes } diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs index 3c6c24637006..f928e590d45c 100644 --- a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs @@ -4,6 +4,9 @@ fn main() { r#"\aaa"#; r##"\aaa"##; + //~^ needless_raw_string_hashes r##"Hello "world"!"##; + //~^ needless_raw_string_hashes r######" "### "## "# "######; + //~^ needless_raw_string_hashes } diff --git a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr index 421ad66e4c96..43d02837c6cc 100644 --- a/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr +++ b/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr @@ -13,7 +13,7 @@ LL + r#"\aaa"#; | error: unnecessary hashes around raw string literal - --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:7:5 + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:8:5 | LL | r##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + r#"Hello "world"!"#; | error: unnecessary hashes around raw string literal - --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:8:5 + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:10:5 | LL | r######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 673106f0b12d..8da607ec6584 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 @@ -16,6 +16,7 @@ proc_macro_derive::foo_bar!(); macro_rules! test { () => { vec![0, 0, 0] + //~^ nonstandard_macro_braces }; } @@ -41,10 +42,15 @@ macro_rules! printlnfoo { #[rustfmt::skip] fn main() { let _ = vec![1, 2, 3]; + //~^ nonstandard_macro_braces let _ = format!("ugh {} stop being such a good compiler", "hello"); + //~^ nonstandard_macro_braces let _ = matches!({}, ()); + //~^ nonstandard_macro_braces let _ = quote!{let x = 1;}; + //~^ nonstandard_macro_braces let _ = quote::quote!{match match match}; + //~^ nonstandard_macro_braces let _ = test!(); // trigger when macro def is inside our own crate let _ = vec![1,2,3]; @@ -54,8 +60,10 @@ fn main() { let _ = test2!["{}{}{}", 1, 2, 3]; let _: type_pos![usize] = vec![]; + //~^ nonstandard_macro_braces eprint!["test if user config overrides defaults"]; + //~^ nonstandard_macro_braces printlnfoo!["test if printlnfoo is triggered by println"]; } 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 b9c69037be07..e35844a209fa 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 @@ -16,6 +16,7 @@ proc_macro_derive::foo_bar!(); macro_rules! test { () => { vec!{0, 0, 0} + //~^ nonstandard_macro_braces }; } @@ -41,10 +42,15 @@ macro_rules! printlnfoo { #[rustfmt::skip] fn main() { let _ = vec! {1, 2, 3}; + //~^ nonstandard_macro_braces let _ = format!["ugh {} stop being such a good compiler", "hello"]; + //~^ nonstandard_macro_braces let _ = matches!{{}, ()}; + //~^ nonstandard_macro_braces let _ = quote!(let x = 1;); + //~^ nonstandard_macro_braces let _ = quote::quote!(match match match); + //~^ nonstandard_macro_braces let _ = test!(); // trigger when macro def is inside our own crate let _ = vec![1,2,3]; @@ -54,8 +60,10 @@ fn main() { let _ = test2!["{}{}{}", 1, 2, 3]; let _: type_pos!(usize) = vec![]; + //~^ nonstandard_macro_braces eprint!("test if user config overrides defaults"); + //~^ nonstandard_macro_braces printlnfoo!["test if printlnfoo is triggered by println"]; } 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 c2c76e444cfe..fda6addc7aa3 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 - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:43:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:44:13 | LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` @@ -8,25 +8,25 @@ LL | let _ = vec! {1, 2, 3}; = help: to override `-D warnings` add `#[allow(clippy::nonstandard_macro_braces)]` error: use of irregular braces for `format!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:44:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:46:13 | LL | let _ = format!["ugh {} stop being such a good compiler", "hello"]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `format!("ugh {} stop being such a good compiler", "hello")` error: use of irregular braces for `matches!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:45:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:48:13 | LL | let _ = matches!{{}, ()}; | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())` error: use of irregular braces for `quote!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:46:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:50:13 | LL | let _ = quote!(let x = 1;); | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}` error: use of irregular braces for `quote::quote!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:47:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:52:13 | LL | let _ = quote::quote!(match match match); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}` @@ -43,13 +43,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 - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:56:12 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:62:12 | LL | let _: type_pos!(usize) = vec![]; | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]` error: use of irregular braces for `eprint!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:58:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:65: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/panic/panic.rs b/tests/ui-toml/panic/panic.rs index b6264c950e45..7bdc896453d8 100644 --- a/tests/ui-toml/panic/panic.rs +++ b/tests/ui-toml/panic/panic.rs @@ -10,11 +10,13 @@ fn main() { match a { Enam::A => {}, _ => panic!(""), + //~^ panic } } fn issue_13292() { panic_any("should lint") + //~^ panic } #[test] diff --git a/tests/ui-toml/panic/panic.stderr b/tests/ui-toml/panic/panic.stderr index a034207d919f..5dfecfe51ddb 100644 --- a/tests/ui-toml/panic/panic.stderr +++ b/tests/ui-toml/panic/panic.stderr @@ -8,7 +8,7 @@ LL | _ => panic!(""), = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic_any` should not be present in production code - --> tests/ui-toml/panic/panic.rs:17:5 + --> tests/ui-toml/panic/panic.rs:18:5 | LL | panic_any("should lint") | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs b/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs index a34b15f4ac9a..455623cec43e 100644 --- a/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs +++ b/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs @@ -1,3 +1,5 @@ +//@check-pass + #![warn(clippy::path_ends_with_ext)] use std::path::Path; diff --git a/tests/ui-toml/print_macro/print_macro.rs b/tests/ui-toml/print_macro/print_macro.rs index 3a8b30cca36a..74f3ba7e7fa9 100644 --- a/tests/ui-toml/print_macro/print_macro.rs +++ b/tests/ui-toml/print_macro/print_macro.rs @@ -4,7 +4,9 @@ fn foo(n: u32) { print!("{n}"); + //~^ print_stdout eprint!("{n}"); + //~^ print_stderr } #[test] diff --git a/tests/ui-toml/print_macro/print_macro.stderr b/tests/ui-toml/print_macro/print_macro.stderr index fea11107c7ca..835af7ef8c72 100644 --- a/tests/ui-toml/print_macro/print_macro.stderr +++ b/tests/ui-toml/print_macro/print_macro.stderr @@ -8,7 +8,7 @@ LL | print!("{n}"); = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `eprint!` - --> tests/ui-toml/print_macro/print_macro.rs:7:5 + --> tests/ui-toml/print_macro/print_macro.rs:8:5 | LL | eprint!("{n}"); | ^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs index cd53f5044599..6a1d2b51abc8 100644 --- a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs +++ b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs @@ -11,9 +11,11 @@ mod my_mod { /// some docs pub(crate) fn crate_with_docs() {} pub(crate) fn crate_no_docs() {} + //~^ missing_docs_in_private_items /// some docs pub(super) fn super_with_docs() {} pub(super) fn super_no_docs() {} + //~^ missing_docs_in_private_items mod my_sub { /// some docs @@ -22,6 +24,7 @@ mod my_mod { /// some docs pub(crate) fn sub_crate_with_docs() {} pub(crate) fn sub_crate_no_docs() {} + //~^ missing_docs_in_private_items /// some docs pub(super) fn sub_super_with_docs() {} pub(super) fn sub_super_no_docs() {} @@ -32,15 +35,18 @@ mod my_mod { /// some docs pub(crate) crate_field_with_docs: (), pub(crate) crate_field_no_docs: (), + //~^ missing_docs_in_private_items /// some docs priv_field_with_docs: (), priv_field_no_docs: (), } pub(crate) struct CrateStructNoDocs { + //~^ missing_docs_in_private_items /// some docs pub(crate) crate_field_with_docs: (), pub(crate) crate_field_no_docs: (), + //~^ missing_docs_in_private_items /// some docs priv_field_with_docs: (), priv_field_no_docs: (), @@ -50,6 +56,7 @@ mod my_mod { /// some docs type CrateTypedefWithDocs = String; type CrateTypedefNoDocs = String; +//~^ missing_docs_in_private_items /// some docs pub type PubTypedefWithDocs = String; pub type PubTypedefNoDocs = String; diff --git a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr index 9cf79fccb60b..0d70276de42d 100644 --- a/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr +++ b/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr @@ -8,43 +8,43 @@ LL | pub(crate) fn crate_no_docs() {} = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a function - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:16:5 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:17:5 | LL | pub(super) fn super_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:24:9 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:26:9 | LL | pub(crate) fn sub_crate_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:34:9 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:37:9 | LL | pub(crate) crate_field_no_docs: (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:40:5 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:44:5 | LL | / pub(crate) struct CrateStructNoDocs { +LL | | LL | | /// some docs LL | | pub(crate) crate_field_with_docs: (), -LL | | pub(crate) crate_field_no_docs: (), ... | LL | | priv_field_no_docs: (), LL | | } | |_____^ error: missing documentation for a struct field - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:43:9 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:48:9 | LL | pub(crate) crate_field_no_docs: (), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a type alias - --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:52:1 + --> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:58:1 | LL | type CrateTypedefNoDocs = String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr index dd1035e53fa9..335ff403d062 100644 --- a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr +++ b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.all_pub_fields.stderr @@ -9,7 +9,7 @@ LL | pub _b: u8, = help: to override `-D warnings` add `#[allow(clippy::pub_underscore_fields)]` error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:23:13 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:24:13 | LL | pub(in crate::inner) _f: Option<()>, | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub(in crate::inner) _f: Option<()>, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:27:13 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:29:13 | LL | pub _g: String, | ^^^^^^ @@ -25,7 +25,7 @@ LL | pub _g: String, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:34:9 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:37:9 | LL | pub _a: usize, | ^^^^^^ @@ -33,7 +33,7 @@ LL | pub _a: usize, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:41:9 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:45:9 | LL | pub _c: i64, | ^^^^^^ @@ -41,7 +41,7 @@ LL | pub _c: i64, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:44:9 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:49:9 | LL | pub _e: Option, | ^^^^^^ @@ -49,7 +49,7 @@ LL | pub _e: Option, = help: consider removing the underscore, or making the field private error: field marked as public but also inferred as unused because it's prefixed with `_` - --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:57:9 + --> tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs:63:9 | LL | pub(crate) _b: Option, | ^^^^^^^^^^^^^ diff --git a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs index 4ee8dbb88347..2c1d3cf23647 100644 --- a/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs +++ b/tests/ui-toml/pub_underscore_fields/pub_underscore_fields.rs @@ -13,6 +13,7 @@ pub mod inner { pub struct PubSuper { pub(super) a: usize, pub _b: u8, + //~^ pub_underscore_fields _c: i32, pub _mark: marker::PhantomData, } @@ -21,10 +22,12 @@ pub mod inner { pub struct PubModVisibility { pub(in crate::inner) e: bool, pub(in crate::inner) _f: Option<()>, + //~[all_pub_fields]^ pub_underscore_fields } struct PrivateStructPubField { pub _g: String, + //~[all_pub_fields]^ pub_underscore_fields } } } @@ -32,6 +35,7 @@ pub mod inner { fn main() { pub struct StructWithOneViolation { pub _a: usize, + //~[all_pub_fields]^ pub_underscore_fields } // should handle structs with multiple violations @@ -39,9 +43,11 @@ fn main() { a: u8, _b: usize, pub _c: i64, + //~[all_pub_fields]^ pub_underscore_fields #[doc(hidden)] pub d: String, pub _e: Option, + //~[all_pub_fields]^ pub_underscore_fields } // shouldn't warn on anonymous fields @@ -55,6 +61,7 @@ fn main() { pub struct PubCrate { pub(crate) a: String, pub(crate) _b: Option, + //~[all_pub_fields]^ pub_underscore_fields } // shouldn't warn on fields named pub diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr index 2d700f607592..e7e526628ce7 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.default.stderr @@ -20,13 +20,13 @@ LL | fn foo(&self, i_dont_wanna_use_your_name: u8) {} // only lint in `exten | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the default name: `val` error: renamed function parameter of trait impl - --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:55:31 + --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:57:31 | LL | fn hash(&self, states: &mut H) { | ^^^^^^ help: consider using the default name: `state` error: renamed function parameters of trait impl - --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:59:30 + --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:61:30 | LL | fn hash_slice(date: &[Self], states: &mut H) { | ^^^^ ^^^^^^ @@ -37,7 +37,7 @@ LL | fn hash_slice(data: &[Self], state: &mut H) { | ~~~~ ~~~~~ error: renamed function parameter of trait impl - --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:80:18 + --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:82:18 | LL | fn add(self, b: B) -> C { | ^ help: consider using the default name: `rhs` diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr index e57554fa613a..46e5f34b1761 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.extend.stderr @@ -14,13 +14,13 @@ LL | fn ne(&self, rhs: &Self) -> bool { | ^^^ help: consider using the default name: `other` error: renamed function parameter of trait impl - --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:55:31 + --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:57:31 | LL | fn hash(&self, states: &mut H) { | ^^^^^^ help: consider using the default name: `state` error: renamed function parameters of trait impl - --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:59:30 + --> tests/ui-toml/renamed_function_params/renamed_function_params.rs:61:30 | LL | fn hash_slice(date: &[Self], states: &mut H) { | ^^^^ ^^^^^^ diff --git a/tests/ui-toml/renamed_function_params/renamed_function_params.rs b/tests/ui-toml/renamed_function_params/renamed_function_params.rs index f3eb910abbd6..26ca1d860947 100644 --- a/tests/ui-toml/renamed_function_params/renamed_function_params.rs +++ b/tests/ui-toml/renamed_function_params/renamed_function_params.rs @@ -28,11 +28,11 @@ impl std::convert::From for String { } impl PartialEq for B { fn eq(&self, rhs: &Self) -> bool { - //~^ ERROR: renamed function parameter of trait impl + //~^ renamed_function_params self.0 == rhs.0 } fn ne(&self, rhs: &Self) -> bool { - //~^ ERROR: renamed function parameter of trait impl + //~^ renamed_function_params self.0 != rhs.0 } } @@ -46,6 +46,8 @@ trait MyTrait { impl MyTrait for B { fn foo(&self, i_dont_wanna_use_your_name: u8) {} // only lint in `extend` + // + //~[default]^^ renamed_function_params fn bar(_a: u8, _: u8) {} fn baz(self, val: u8) {} fn quz(&self, val: u8) {} @@ -53,11 +55,11 @@ impl MyTrait for B { impl Hash for B { fn hash(&self, states: &mut H) { - //~^ ERROR: renamed function parameter of trait impl + //~^ renamed_function_params self.0.hash(states); } fn hash_slice(date: &[Self], states: &mut H) { - //~^ ERROR: renamed function parameters of trait impl + //~^ renamed_function_params for d in date { d.hash(states); } @@ -78,6 +80,7 @@ enum C { impl std::ops::Add for C { type Output = C; fn add(self, b: B) -> C { + //~[default]^ renamed_function_params // only lint in `extend` C::B(b.0) } diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed index 6546981bd81c..f0dab64d78c6 100644 --- a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed +++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed @@ -13,4 +13,5 @@ mod wrapper { fn main() { let _ = wrapper::String::from("x"); + //~^ disallowed_types } diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs index d76f1af481de..2585e6f90fc4 100644 --- a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs +++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs @@ -13,4 +13,5 @@ mod wrapper { fn main() { let _ = String::from("x"); + //~^ disallowed_types } diff --git a/tests/ui-toml/semicolon_block/both.fixed b/tests/ui-toml/semicolon_block/both.fixed index 306cd23c8239..33f490fad6e8 100644 --- a/tests/ui-toml/semicolon_block/both.fixed +++ b/tests/ui-toml/semicolon_block/both.fixed @@ -40,12 +40,15 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block() }; + //~^ semicolon_outside_block unsafe { unit_fn_block() }; + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block(); } @@ -60,6 +63,7 @@ fn main() { { m!(()) }; { m!(()) }; + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/both.rs b/tests/ui-toml/semicolon_block/both.rs index b9f012cfbb0d..8e650979e6c9 100644 --- a/tests/ui-toml/semicolon_block/both.rs +++ b/tests/ui-toml/semicolon_block/both.rs @@ -40,12 +40,15 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block(); } + //~^ semicolon_outside_block unsafe { unit_fn_block(); } + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block() }; @@ -60,6 +63,7 @@ fn main() { { m!(()) }; { m!(()); } + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/both.stderr b/tests/ui-toml/semicolon_block/both.stderr index 7d7749b282f0..c2aad39b6832 100644 --- a/tests/ui-toml/semicolon_block/both.stderr +++ b/tests/ui-toml/semicolon_block/both.stderr @@ -13,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui-toml/semicolon_block/both.rs:43:5 + --> tests/ui-toml/semicolon_block/both.rs:44:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,9 +25,10 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui-toml/semicolon_block/both.rs:48:5 + --> tests/ui-toml/semicolon_block/both.rs:50:5 | LL | / { +LL | | LL | | unit_fn_block(); LL | | unit_fn_block() LL | | }; @@ -42,7 +43,7 @@ LL ~ } | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui-toml/semicolon_block/both.rs:62:5 + --> tests/ui-toml/semicolon_block/both.rs:65: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 5b7f8e00c7a0..7b1af090e933 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed @@ -45,6 +45,7 @@ fn main() { unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block(); } diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs index 3a81661cd16f..e243d4514da2 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs @@ -45,6 +45,7 @@ fn main() { unsafe { unit_fn_block(); }; { + //~^ semicolon_inside_block unit_fn_block(); unit_fn_block() }; diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index b1638e40206d..4d4e43f6b9c1 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr @@ -2,6 +2,7 @@ error: consider moving the `;` inside the block for consistent formatting --> tests/ui-toml/semicolon_block/semicolon_inside_block.rs:47:5 | LL | / { +LL | | LL | | unit_fn_block(); LL | | unit_fn_block() LL | | }; diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed index 14604eaea7e4..f6aa49fc8868 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed @@ -39,7 +39,9 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block() }; + //~^ semicolon_outside_block unsafe { unit_fn_block() }; + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -59,6 +61,7 @@ fn main() { { m!(()) }; { m!(()) }; + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs index c767201469ab..0d25a29627fb 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs @@ -39,7 +39,9 @@ fn main() { unsafe { unit_fn_block() }; { unit_fn_block(); } + //~^ semicolon_outside_block unsafe { unit_fn_block(); } + //~^ semicolon_outside_block { unit_fn_block(); }; unsafe { unit_fn_block(); }; @@ -59,6 +61,7 @@ fn main() { { m!(()) }; { m!(()); } + //~^ semicolon_outside_block { m!(()); }; m!(0); m!(1); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr index 7bcb63a6abbb..18400da07a89 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr @@ -13,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui-toml/semicolon_block/semicolon_outside_block.rs:42:5 + --> tests/ui-toml/semicolon_block/semicolon_outside_block.rs:43:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui-toml/semicolon_block/semicolon_outside_block.rs:61:5 + --> tests/ui-toml/semicolon_block/semicolon_outside_block.rs:63:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs index 90c2439dc34f..08a8e1186d5c 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs @@ -9,6 +9,7 @@ pub struct NoGeneric { } unsafe impl Send for NoGeneric {} +//~^ non_send_fields_in_send_ty pub struct MultiField { field1: T, @@ -17,6 +18,7 @@ pub struct MultiField { } unsafe impl Send for MultiField {} +//~^ non_send_fields_in_send_ty pub enum MyOption { MySome(T), @@ -24,6 +26,7 @@ pub enum MyOption { } unsafe impl Send for MyOption {} +//~^ non_send_fields_in_send_ty // All fields are disallowed when raw pointer heuristic is off extern "C" { @@ -39,5 +42,6 @@ pub struct HeuristicTest { } unsafe impl Send for HeuristicTest {} +//~^ non_send_fields_in_send_ty fn main() {} diff --git a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr index bd1b75458fd1..cdb4a2f44513 100644 --- a/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr +++ b/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr @@ -14,75 +14,75 @@ LL | rc_is_not_send: Rc, = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MultiField` are not safe to be sent to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:19:1 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:20:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:14:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:15:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:15:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:16:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:16:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:17: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 - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:26:1 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:28:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:22:12 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:24:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:41:1 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:44:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:34:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:37:5 | LL | field1: Vec<*const NonSend>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field2` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:35:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:38:5 | LL | field2: [*const NonSend; 3], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field3` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:36:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:39:5 | LL | field3: (*const NonSend, *const NonSend, *const NonSend), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field4` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:37:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:40:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` note: it is not safe to send field `field5` to another thread - --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:38:5 + --> tests/ui-toml/strict_non_send_fields_in_send_ty/test.rs:41:5 | LL | field5: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/struct_excessive_bools/test.rs b/tests/ui-toml/struct_excessive_bools/test.rs index 32dd80246fab..590cd6eeaa47 100644 --- a/tests/ui-toml/struct_excessive_bools/test.rs +++ b/tests/ui-toml/struct_excessive_bools/test.rs @@ -1,6 +1,7 @@ #![warn(clippy::struct_excessive_bools)] struct S { + //~^ struct_excessive_bools a: bool, } diff --git a/tests/ui-toml/struct_excessive_bools/test.stderr b/tests/ui-toml/struct_excessive_bools/test.stderr index ddf8ec0e5217..d70c76055df8 100644 --- a/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/tests/ui-toml/struct_excessive_bools/test.stderr @@ -2,6 +2,7 @@ error: more than 0 bools in a struct --> tests/ui-toml/struct_excessive_bools/test.rs:3:1 | LL | / struct S { +LL | | LL | | a: bool, LL | | } | |_^ diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs index 4613a74b85d8..b077b848837a 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/tests/ui-toml/suppress_lint_in_const/test.rs @@ -25,6 +25,7 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; + //~^ indexing_slicing 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. @@ -40,15 +41,20 @@ fn main() { let v = vec![0; 5]; v[0]; + //~^ indexing_slicing v[10]; + //~^ indexing_slicing v[1 << 3]; + //~^ indexing_slicing 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. v[N]; + //~^ indexing_slicing v[M]; + //~^ indexing_slicing } /// An opaque integer representation diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index 120f5c35cb03..4c78a6b924cf 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -9,7 +9,7 @@ LL | x[index]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:42:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 | LL | v[0]; | ^^^^ @@ -17,7 +17,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:45:5 | LL | v[10]; | ^^^^^ @@ -25,7 +25,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:44:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:47:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -33,7 +33,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:50:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:54:5 | LL | v[N]; | ^^^^ @@ -41,7 +41,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:51:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:56:5 | LL | v[M]; | ^^^^ diff --git a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs index 2f86b3eda4c5..6555e4291959 100644 --- a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs +++ b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs @@ -4,17 +4,24 @@ #![warn(clippy::disallowed_names)] fn test(toto: ()) {} +//~^ disallowed_names fn main() { let toto = 42; + //~^ disallowed_names let tata = 42; + //~^ disallowed_names let titi = 42; + //~^ disallowed_names let tatab = 42; let tatatataic = 42; match (42, Some(1337), Some(0)) { (toto, Some(tata), titi @ Some(_)) => (), + //~^ disallowed_names + //~| disallowed_names + //~| disallowed_names _ => (), } } diff --git a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr index 6cd0f9b0d7cb..9096ffca2796 100644 --- a/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr +++ b/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr @@ -8,37 +8,37 @@ LL | fn test(toto: ()) {} = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `toto` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:9:9 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:10:9 | LL | let toto = 42; | ^^^^ error: use of a disallowed/placeholder name `tata` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:10:9 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:12:9 | LL | let tata = 42; | ^^^^ error: use of a disallowed/placeholder name `titi` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:11:9 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:14:9 | LL | let titi = 42; | ^^^^ error: use of a disallowed/placeholder name `toto` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:17:10 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:21:10 | LL | (toto, Some(tata), titi @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `tata` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:17:21 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:21:21 | LL | (toto, Some(tata), titi @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `titi` - --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:17:28 + --> tests/ui-toml/toml_disallow/conf_french_disallowed_name.rs:21:28 | LL | (toto, Some(tata), titi @ Some(_)) => (), | ^^^^ diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs index 0986290bb0e6..dd170d6baf85 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -31,30 +31,44 @@ mod local_mod { fn main() { let re = Regex::new(r"ab.*c").unwrap(); + //~^ disallowed_methods re.is_match("abc"); + //~^ disallowed_methods let mut a = vec![1, 2, 3, 4]; a.iter().sum::(); + //~^ disallowed_methods a.sort_unstable(); + //~^ disallowed_methods // FIXME(f16_f128): add a clamp test once the function is available let _ = 2.0f32.clamp(3.0f32, 4.0f32); + //~^ disallowed_methods let _ = 2.0f64.clamp(3.0f64, 4.0f64); let indirect: fn(&str) -> Result = Regex::new; + //~^ disallowed_methods let re = indirect(".").unwrap(); let in_call = Box::new(f32::clamp); + //~^ disallowed_methods let in_method_call = ["^", "$"].into_iter().map(Regex::new); + //~^ disallowed_methods // resolve ambiguity between `futures::stream::select_all` the module and the function let same_name_as_module = select_all(vec![empty::<()>()]); + //~^ disallowed_methods local_fn(); + //~^ disallowed_methods local_mod::f(); + //~^ disallowed_methods let s = Struct; s.method(); + //~^ disallowed_methods s.provided_method(); + //~^ disallowed_methods s.implemented_method(); + //~^ disallowed_methods } diff --git a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index edda35d647ab..f7dda81eb936 100644 --- a/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -8,7 +8,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` error: use of a disallowed method `regex::Regex::is_match` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:34:8 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:35:8 | LL | re.is_match("abc"); | ^^^^^^^^ @@ -16,73 +16,73 @@ LL | re.is_match("abc"); = note: no matching allowed error: use of a disallowed method `std::iter::Iterator::sum` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:37:14 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:14 | LL | a.iter().sum::(); | ^^^ error: use of a disallowed method `slice::sort_unstable` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:42:7 | LL | a.sort_unstable(); | ^^^^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:42:20 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:46:20 | LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); | ^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:45:61 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:61 | LL | let indirect: fn(&str) -> Result = Regex::new; | ^^^^^^^^^^ error: use of a disallowed method `f32::clamp` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:48:28 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:28 | LL | let in_call = Box::new(f32::clamp); | ^^^^^^^^^^ error: use of a disallowed method `regex::Regex::new` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:49:53 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:53 | LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new); | ^^^^^^^^^^ error: use of a disallowed method `futures::stream::select_all` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:52:31 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:31 | LL | let same_name_as_module = select_all(vec![empty::<()>()]); | ^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_fn` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:63:5 | LL | local_fn(); | ^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::local_mod::f` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:55:5 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:65:5 | LL | local_mod::f(); | ^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Struct::method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:68:7 | LL | s.method(); | ^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:58:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:70:7 | LL | s.provided_method(); | ^^^^^^^^^^^^^^^ error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method` - --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:7 + --> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:72:7 | LL | s.implemented_method(); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs index f02bd07cfe7b..82c9abe8beb4 100644 --- a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs +++ b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs @@ -5,40 +5,61 @@ extern crate syn; use std::sync as foo; use std::sync::atomic::AtomicU32; +//~^ disallowed_types use std::time::Instant as Sneaky; +//~^ disallowed_types struct HashMap; fn bad_return_type() -> fn() -> Sneaky { + //~^ disallowed_types todo!() } fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} +//~^ disallowed_types +//~| disallowed_types fn trait_obj(_: &dyn std::io::Read) {} +//~^ disallowed_types fn full_and_single_path_prim(_: usize, _: bool) {} +//~^ disallowed_types +//~| disallowed_types fn const_generics() {} +//~^ disallowed_types struct GenArg([u8; U]); +//~^ disallowed_types static BAD: foo::atomic::AtomicPtr<()> = foo::atomic::AtomicPtr::new(std::ptr::null_mut()); fn ip(_: std::net::Ipv4Addr) {} +//~^ disallowed_types fn listener(_: std::net::TcpListener) {} +//~^ disallowed_types #[allow(clippy::diverging_sub_expression)] fn main() { let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); + //~^ disallowed_types + //~| disallowed_types let _ = Sneaky::now(); + //~^ disallowed_types let _ = foo::atomic::AtomicU32::new(0); + //~^ disallowed_types static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); + //~^ disallowed_types + //~| disallowed_types let _: std::collections::BTreeMap<(), syn::TypePath> = Default::default(); + //~^ disallowed_types let _ = syn::Ident::new("", todo!()); + //~^ disallowed_types let _ = HashMap; let _: usize = 64_usize; + //~^ disallowed_types } mod useless_attribute { diff --git a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr index 322cde15526a..18bc36ca1e33 100644 --- a/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr +++ b/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr @@ -8,61 +8,61 @@ LL | use std::sync::atomic::AtomicU32; = help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]` error: use of a disallowed type `std::time::Instant` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:8:1 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:9:1 | LL | use std::time::Instant as Sneaky; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::time::Instant` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:12:33 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:14:33 | LL | fn bad_return_type() -> fn() -> Sneaky { | ^^^^^^ error: use of a disallowed type `std::time::Instant` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:16:28 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:19:28 | LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} | ^^^^^^ error: use of a disallowed type `std::sync::atomic::AtomicU32` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:16:39 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:19:39 | LL | fn bad_arg_type(_: impl Fn(Sneaky) -> foo::atomic::AtomicU32) {} | ^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::io::Read` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:18:22 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:23:22 | LL | fn trait_obj(_: &dyn std::io::Read) {} | ^^^^^^^^^^^^^ error: use of a disallowed type `std::primitive::usize` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:20:33 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:26:33 | LL | fn full_and_single_path_prim(_: usize, _: bool) {} | ^^^^^ error: use of a disallowed type `bool` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:20:43 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:26:43 | LL | fn full_and_single_path_prim(_: usize, _: bool) {} | ^^^^ error: use of a disallowed type `std::primitive::usize` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:22:28 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:30:28 | LL | fn const_generics() {} | ^^^^^ error: use of a disallowed type `std::primitive::usize` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:24:24 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:33:24 | LL | struct GenArg([u8; U]); | ^^^^^ error: use of a disallowed type `std::net::Ipv4Addr` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:28:10 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:38:10 | LL | fn ip(_: std::net::Ipv4Addr) {} | ^^^^^^^^^^^^^^^^^^ @@ -70,61 +70,61 @@ LL | fn ip(_: std::net::Ipv4Addr) {} = note: no IPv4 allowed error: use of a disallowed type `std::net::TcpListener` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:30:16 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:41:16 | LL | fn listener(_: std::net::TcpListener) {} | ^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::collections::HashMap` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:34:48 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:46:48 | LL | let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::collections::HashMap` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:34:12 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:46:12 | LL | let _: std::collections::HashMap<(), ()> = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::time::Instant` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:35:13 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:49:13 | LL | let _ = Sneaky::now(); | ^^^^^^ error: use of a disallowed type `std::sync::atomic::AtomicU32` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:36:13 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:51:13 | LL | let _ = foo::atomic::AtomicU32::new(0); | ^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::sync::atomic::AtomicU32` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:37:17 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:53:17 | LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `std::sync::atomic::AtomicU32` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:37:48 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:53:48 | LL | static FOO: std::sync::atomic::AtomicU32 = foo::atomic::AtomicU32::new(1); | ^^^^^^^^^^^^^^^^^^^^^^ error: use of a disallowed type `syn::TypePath` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:38:43 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:56:43 | LL | let _: std::collections::BTreeMap<(), syn::TypePath> = Default::default(); | ^^^^^^^^^^^^^ error: use of a disallowed type `proc_macro2::Ident` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:39:13 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:58:13 | LL | let _ = syn::Ident::new("", todo!()); | ^^^^^^^^^^ error: use of a disallowed type `std::primitive::usize` - --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:41:12 + --> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:61:12 | LL | let _: usize = 64_usize; | ^^^^^ diff --git a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.fixed b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.fixed index 8092e40ff9f1..d44f5fb84bd5 100644 --- a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.fixed +++ b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.fixed @@ -16,9 +16,11 @@ fn main() { let z = 1; Foo { x, y, z: z }; + //~^ inconsistent_struct_constructor Foo { x, + //~^ inconsistent_struct_constructor z: z, ..Default::default() }; @@ -35,6 +37,7 @@ mod field_attributes { BodyVisitor { macro_unsafe_blocks: Vec::new(), #[expect(clippy::bool_to_int_with_if)] // obfuscates the meaning + //~^ inconsistent_struct_constructor expn_depth: if condition { 1 } else { 0 }, }; } @@ -53,6 +56,7 @@ mod cfgs_between_fields { } let s = S { a: 3, + //~^ inconsistent_struct_constructor b: 2, #[cfg(all())] c: 1, @@ -70,6 +74,7 @@ mod cfgs_between_fields { } let s = S { a: 3, + //~^ inconsistent_struct_constructor #[cfg(any())] c: 1, b: 2, diff --git a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs index cd1aff966528..77ac2b4e7c11 100644 --- a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs +++ b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs @@ -16,9 +16,11 @@ fn main() { let z = 1; Foo { y, x, z: z }; + //~^ inconsistent_struct_constructor Foo { z: z, + //~^ inconsistent_struct_constructor x, ..Default::default() }; @@ -34,6 +36,7 @@ mod field_attributes { fn check_body(condition: bool) { BodyVisitor { #[expect(clippy::bool_to_int_with_if)] // obfuscates the meaning + //~^ inconsistent_struct_constructor expn_depth: if condition { 1 } else { 0 }, macro_unsafe_blocks: Vec::new(), }; @@ -53,6 +56,7 @@ mod cfgs_between_fields { } let s = S { d: 0, + //~^ inconsistent_struct_constructor #[cfg(all())] c: 1, b: 2, @@ -70,6 +74,7 @@ mod cfgs_between_fields { } let s = S { d: 0, + //~^ inconsistent_struct_constructor #[cfg(any())] c: 1, b: 2, diff --git a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.stderr b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.stderr index d2533960b84c..be85fa574480 100644 --- a/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.stderr +++ b/tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.stderr @@ -8,22 +8,25 @@ LL | Foo { y, x, z: z }; = help: to override `-D warnings` add `#[allow(clippy::inconsistent_struct_constructor)]` error: struct constructor field order is inconsistent with struct definition field order - --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:21:9 + --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:22:9 | LL | / z: z, +LL | | LL | | x, | |_________^ | help: if the field evaluation order doesn't matter, try | LL ~ x, +LL + LL ~ z: z, | error: struct constructor field order is inconsistent with struct definition field order - --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:36:13 + --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:38:13 | LL | / #[expect(clippy::bool_to_int_with_if)] // obfuscates the meaning +LL | | LL | | expn_depth: if condition { 1 } else { 0 }, LL | | macro_unsafe_blocks: Vec::new(), | |___________________________________________^ @@ -32,13 +35,15 @@ help: if the field evaluation order doesn't matter, try | LL ~ macro_unsafe_blocks: Vec::new(), LL + #[expect(clippy::bool_to_int_with_if)] // obfuscates the meaning +LL + LL ~ expn_depth: if condition { 1 } else { 0 }, | error: struct constructor field order is inconsistent with struct definition field order - --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:55:13 + --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:58:13 | LL | / d: 0, +LL | | LL | | #[cfg(all())] LL | | c: 1, LL | | b: 2, @@ -48,6 +53,7 @@ LL | | a: 3, help: if the field evaluation order doesn't matter, try | LL ~ a: 3, +LL + LL + b: 2, LL + #[cfg(all())] LL + c: 1, @@ -55,9 +61,10 @@ LL ~ d: 0, | error: struct constructor field order is inconsistent with struct definition field order - --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:72:13 + --> tests/ui-toml/toml_inconsistent_struct_constructor/conf_inconsistent_struct_constructor.rs:76:13 | LL | / d: 0, +LL | | LL | | #[cfg(any())] LL | | c: 1, LL | | b: 2, @@ -67,6 +74,7 @@ LL | | a: 3, help: if the field evaluation order doesn't matter, try | LL ~ a: 3, +LL + LL + #[cfg(any())] LL + c: 1, LL + b: 2, diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed index dae7ce76ba28..df28e0bc94be 100644 --- a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.fixed @@ -4,5 +4,7 @@ fn good() {} fn main() { good(); + //~^ disallowed_methods good(); + //~^ disallowed_methods } diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs index 53678ffdf1c9..9257f0e3e1a7 100644 --- a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs @@ -4,5 +4,7 @@ fn good() {} fn main() { bad(); + //~^ disallowed_methods questionable(); + //~^ disallowed_methods } diff --git a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr index b85592029420..6f70b4ae6a9e 100644 --- a/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr +++ b/tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.stderr @@ -8,7 +8,7 @@ LL | bad(); = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` error: use of a disallowed method `replaceable_disallowed_methods::questionable` - --> tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs:7:5 + --> tests/ui-toml/toml_replaceable_disallowed_methods/replaceable_disallowed_methods.rs:8:5 | LL | questionable(); | ^^^^^^^^^^^^ help: a better function exists: `good` diff --git a/tests/ui-toml/toml_trivially_copy/test.rs b/tests/ui-toml/toml_trivially_copy/test.rs index 145a2ce441d3..46f21eef9740 100644 --- a/tests/ui-toml/toml_trivially_copy/test.rs +++ b/tests/ui-toml/toml_trivially_copy/test.rs @@ -13,6 +13,8 @@ struct Bar(u32); fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) {} fn bad(x: &u16, y: &Foo) {} +//~^ trivially_copy_pass_by_ref +//~| trivially_copy_pass_by_ref fn main() { let (mut a, b, c, d, x, y) = (0, 0, Bar(0), 0, 0, Foo(0)); diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs b/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs index 49139b60a9f4..8d02924c9d93 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs @@ -1,4 +1,6 @@ //@no-rustfix -//@error-in-other-file: unknown field `foobar`, expected one of +//@error-in-other-file: unknown field +//@error-in-other-file: error reading Clippy +//@error-in-other-file: error reading Clippy fn main() {} diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr index 9677beeb2c24..32ed78151d23 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr @@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {} = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:274:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:275:5 | LL | unsafe {} | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:14 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:29 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:29 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:48 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:48 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:18 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:37 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:286:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:291:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:299:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:306:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:311:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:305:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:316:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:315:8 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:327:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:321:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:334:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:333:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:349:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:360:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:20 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:365:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:354:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:373:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:361:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:381:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:382:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:429:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:415:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:439:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:429:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:421:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:446:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:493:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:498:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:503:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:478:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:507:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:487:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:518:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:496:1 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:528:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,24 +279,23 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:543:5 | LL | / let _ = { +LL | | LL | | if unsafe { true } { -LL | | todo!(); -LL | | } else { ... | LL | | }; | |______^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:542:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:12 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -304,7 +303,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:513:23 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:549:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr index 0eccdd428008..83a6986addf2 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr @@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {} = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:274:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:275:5 | LL | unsafe {} | ^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:14 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:29 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:29 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:278:48 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:280:48 | LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; | ^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:18 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:18 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:282:37 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:287:37 | LL | let _ = (42, unsafe {}, "test", unsafe {}); | ^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:286:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:293:14 | LL | let _ = *unsafe { &42 }; | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:291:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:299:19 | LL | let _ = match unsafe {} { | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | let _ = match unsafe {} { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:297:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:306:14 | LL | let _ = &unsafe {}; | ^^^^^^^^^ @@ -81,7 +81,7 @@ LL | let _ = &unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:301:14 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:311:14 | LL | let _ = [unsafe {}; 5]; | ^^^^^^^^^ @@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5]; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:305:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:316:13 | LL | let _ = unsafe {}; | ^^^^^^^^^ @@ -97,7 +97,7 @@ LL | let _ = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:315:8 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:327:8 | LL | t!(unsafe {}); | ^^^^^^^^^ @@ -105,7 +105,7 @@ LL | t!(unsafe {}); = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:321:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:334:13 | LL | unsafe {} | ^^^^^^^^^ @@ -117,7 +117,7 @@ LL | t!(); = note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:329:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 | LL | unsafe {} // SAFETY: | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY: = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:333:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:349:5 | LL | unsafe { | ^^^^^^^^ @@ -133,7 +133,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:343:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:360:5 | LL | unsafe {}; | ^^^^^^^^^ @@ -141,7 +141,7 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:347:20 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:365:20 | LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:354:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:373:5 | LL | unsafe impl A for () {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL | unsafe impl A for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:361:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:381:9 | LL | unsafe impl B for (u32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:382:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:403:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:429:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -189,7 +189,7 @@ LL | no_safety_comment!(()); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:415:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:439:5 | LL | unsafe impl T for (i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:407:13 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:429:13 | LL | unsafe impl T for $t {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | no_safety_comment!(u32); = note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:421:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:446:5 | LL | unsafe impl T for (bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:467:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:493:5 | LL | unsafe impl NoComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:471:19 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:498:19 | LL | /* SAFETY: */ unsafe impl InlineComment for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:475:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:503:5 | LL | unsafe impl TrailingComment for () {} // SAFETY: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY: = help: consider adding a safety comment on the preceding line error: constant item has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:479:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 | LL | const BIG_NUMBER: i32 = 1000000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:478:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:507:5 | LL | // SAFETY: | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | // SAFETY: = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:480:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:5 | LL | unsafe impl Interference for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:487:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:518:5 | LL | unsafe impl ImplInFn for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {} = help: consider adding a safety comment on the preceding line error: unsafe impl missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:496:1 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:528:1 | LL | unsafe impl CrateRoot for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:506:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:539:9 | LL | unsafe {}; | ^^^^^^^^^ @@ -287,24 +287,23 @@ LL | unsafe {}; = help: consider adding a safety comment on the preceding line error: statement has unnecessary safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:509:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:543:5 | LL | / let _ = { +LL | | LL | | if unsafe { true } { -LL | | todo!(); -LL | | } else { ... | LL | | }; | |______^ | help: consider removing the safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:542:5 | LL | // SAFETY: this is more than one level away, so it should warn | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:510:12 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:12 | LL | if unsafe { true } { | ^^^^^^^^^^^^^^^ @@ -312,7 +311,7 @@ LL | if unsafe { true } { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:513:23 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:549:23 | LL | let bar = unsafe {}; | ^^^^^^^^^ @@ -320,7 +319,7 @@ LL | let bar = unsafe {}; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:531:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:568:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -328,7 +327,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:535:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:573:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +335,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:539:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:578:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -344,7 +343,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:545:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:585:5 | LL | unsafe {} | ^^^^^^^^^ @@ -352,7 +351,7 @@ LL | unsafe {} = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:549:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:590:5 | LL | unsafe { | ^^^^^^^^ @@ -360,7 +359,7 @@ LL | unsafe { = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:556:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:598:9 | LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -368,7 +367,7 @@ LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() }; = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:561:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:604:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -376,7 +375,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:567:9 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:611:9 | LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +383,7 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() = help: consider adding a safety comment on the preceding line error: unsafe block missing a safety comment - --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:572:5 + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:617:5 | LL | unsafe {} | ^^^^^^^^^ 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 02170e1f7402..6a3fda3df5c3 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -268,41 +268,53 @@ fn in_closure(x: *const u32) { #[rustfmt::skip] fn inline_block_comment() { /* Safety: */ unsafe {} + //~^ undocumented_unsafe_blocks } fn no_comment() { unsafe {} + //~^ undocumented_unsafe_blocks } fn no_comment_array() { let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; + //~^ undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks } fn no_comment_tuple() { let _ = (42, unsafe {}, "test", unsafe {}); + //~^ undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks } fn no_comment_unary() { let _ = *unsafe { &42 }; + //~^ undocumented_unsafe_blocks } #[allow(clippy::match_single_binding)] fn no_comment_match() { let _ = match unsafe {} { + //~^ undocumented_unsafe_blocks _ => {}, }; } fn no_comment_addr_of() { let _ = &unsafe {}; + //~^ undocumented_unsafe_blocks } fn no_comment_repeat() { let _ = [unsafe {}; 5]; + //~^ undocumented_unsafe_blocks } fn local_no_comment() { let _ = unsafe {}; + //~^ undocumented_unsafe_blocks } fn no_comment_macro_call() { @@ -313,12 +325,14 @@ fn no_comment_macro_call() { } t!(unsafe {}); + //~^ undocumented_unsafe_blocks } fn no_comment_macro_def() { macro_rules! t { () => { unsafe {} + //~^ undocumented_unsafe_blocks }; } @@ -327,10 +341,13 @@ fn no_comment_macro_def() { fn trailing_comment() { unsafe {} // SAFETY: + // + //~^^ undocumented_unsafe_blocks } fn internal_comment() { unsafe { + //~^ undocumented_unsafe_blocks // SAFETY: } } @@ -341,10 +358,12 @@ fn interference() { let _ = 42; unsafe {}; + //~^ undocumented_unsafe_blocks } pub fn print_binary_tree() { println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); + //~^ undocumented_unsafe_blocks } mod unsafe_impl_smoke_test { @@ -352,6 +371,7 @@ mod unsafe_impl_smoke_test { // error: no safety comment unsafe impl A for () {} + //~^ undocumented_unsafe_blocks // Safety: ok unsafe impl A for (i32) {} @@ -359,6 +379,7 @@ mod unsafe_impl_smoke_test { mod sub_mod { // error: unsafe impl B for (u32) {} + //~^ undocumented_unsafe_blocks unsafe trait B {} } @@ -380,6 +401,7 @@ mod unsafe_impl_from_macro { macro_rules! no_safety_comment { ($t:ty) => { unsafe impl T for $t {} + //~^ undocumented_unsafe_blocks }; } @@ -405,6 +427,8 @@ mod unsafe_impl_macro_and_not_macro { macro_rules! no_safety_comment { ($t:ty) => { unsafe impl T for $t {} + //~^ undocumented_unsafe_blocks + //~| undocumented_unsafe_blocks }; } @@ -413,12 +437,14 @@ mod unsafe_impl_macro_and_not_macro { // error unsafe impl T for (i32) {} + //~^ undocumented_unsafe_blocks // ok no_safety_comment!(u32); // error unsafe impl T for (bool) {} + //~^ undocumented_unsafe_blocks } #[rustfmt::skip] @@ -465,19 +491,24 @@ mod unsafe_impl_invalid_comment { unsafe trait NoComment {} unsafe impl NoComment for () {} + //~^ undocumented_unsafe_blocks unsafe trait InlineComment {} /* SAFETY: */ unsafe impl InlineComment for () {} + //~^ undocumented_unsafe_blocks unsafe trait TrailingComment {} unsafe impl TrailingComment for () {} // SAFETY: + //~^ undocumented_unsafe_blocks unsafe trait Interference {} // SAFETY: const BIG_NUMBER: i32 = 1000000; + //~^ unnecessary_safety_comment unsafe impl Interference for () {} + //~^ undocumented_unsafe_blocks } unsafe trait ImplInFn {} @@ -485,6 +516,7 @@ unsafe trait ImplInFn {} fn impl_in_fn() { // error unsafe impl ImplInFn for () {} + //~^ undocumented_unsafe_blocks // SAFETY: ok unsafe impl ImplInFn for (i32) {} @@ -494,6 +526,7 @@ unsafe trait CrateRoot {} // error unsafe impl CrateRoot for () {} +//~^ undocumented_unsafe_blocks // SAFETY: ok unsafe impl CrateRoot for (i32) {} @@ -504,13 +537,17 @@ fn nested_block_separation_issue_9142() { // we need this comment to avoid rustfmt putting // it all on one line unsafe {}; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: this is more than one level away, so it should warn let _ = { + //~^ unnecessary_safety_comment if unsafe { true } { + //~^ undocumented_unsafe_blocks todo!(); } else { let bar = unsafe {}; + //~^ undocumented_unsafe_blocks todo!(); bar } @@ -529,24 +566,29 @@ fn separate_line_from_let_issue_10832() { // SAFETY: fail ONLY if `accept-comment-above-statement = false` let _some_variable_with_a_very_long_name_to_break_the_line = unsafe { a_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-statement = false` const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-statement = false` static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks } fn above_expr_attribute_issue_8679() { // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] unsafe {} + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[expect(unsafe_code, reason = "totally safe")] unsafe { + //~[disabled]^ undocumented_unsafe_blocks *std::ptr::null::() }; @@ -554,22 +596,26 @@ fn above_expr_attribute_issue_8679() { #[allow(unsafe_code)] let _some_variable_with_a_very_long_name_to_break_the_line = unsafe { a_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] #[allow(non_upper_case_globals)] static _some_static_with_a_very_long_name_to_break_the_line: u32 = unsafe { a_const_function_with_a_very_long_name_to_break_the_line() }; + //~[disabled]^ undocumented_unsafe_blocks // SAFETY: #[allow(unsafe_code)] // This shouldn't work either unsafe {} + //~[disabled]^ undocumented_unsafe_blocks } mod issue_11246 { diff --git a/tests/ui-toml/unwrap_used/unwrap_used.fixed b/tests/ui-toml/unwrap_used/unwrap_used.fixed index cdb8fa0454cd..9b4eaa208eb2 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.fixed +++ b/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -36,23 +36,45 @@ fn main() { { // Test `get().unwrap()` let _ = &boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_slice[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vec[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_vecdeque[0]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_hashmap[&1]; + //~^ get_unwrap + //~| unwrap_used let _ = &some_btreemap[&1]; + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = boxed_slice[1]; + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` boxed_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_slice[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vec[0] = 1; + //~^ get_unwrap + //~| unwrap_used some_vecdeque[0] = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -65,7 +87,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec[0..1].to_vec(); + //~^ get_unwrap + //~| unwrap_used } } @@ -73,6 +99,7 @@ fn main() { fn test() { let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); let _ = &boxed_slice[1]; + //~^ get_unwrap } #[cfg(test)] @@ -92,5 +119,6 @@ mod issue9612 { let _a: u8 = 5.try_into().expect(""); // should still warn let _ = &Box::new([0])[1]; + //~^ get_unwrap } } diff --git a/tests/ui-toml/unwrap_used/unwrap_used.rs b/tests/ui-toml/unwrap_used/unwrap_used.rs index e53d53db5f7a..4845efa68733 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.rs +++ b/tests/ui-toml/unwrap_used/unwrap_used.rs @@ -36,23 +36,45 @@ fn main() { { // Test `get().unwrap()` let _ = boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_slice.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vecdeque.get(0).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_hashmap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used let _ = some_btreemap.get(&1).unwrap(); + //~^ get_unwrap + //~| unwrap_used #[allow(clippy::unwrap_used)] let _ = false_positive.get(0).unwrap(); // Test with deref let _: u8 = *boxed_slice.get(1).unwrap(); + //~^ get_unwrap + //~| unwrap_used } { // Test `get_mut().unwrap()` *boxed_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_slice.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vec.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used *some_vecdeque.get_mut(0).unwrap() = 1; + //~^ get_unwrap + //~| unwrap_used // Check false positives #[allow(clippy::unwrap_used)] { @@ -65,7 +87,11 @@ fn main() { { // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` let _ = some_vec.get(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used let _ = some_vec.get_mut(0..1).unwrap().to_vec(); + //~^ get_unwrap + //~| unwrap_used } } @@ -73,6 +99,7 @@ fn main() { fn test() { let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); let _ = boxed_slice.get(1).unwrap(); + //~^ get_unwrap } #[cfg(test)] @@ -92,5 +119,6 @@ mod issue9612 { let _a: u8 = 5.try_into().expect(""); // should still warn let _ = Box::new([0]).get(1).unwrap(); + //~^ get_unwrap } } diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index b58ce9b8af3e..cb9a3f6887dc 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -23,7 +23,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice - --> tests/ui-toml/unwrap_used/unwrap_used.rs:39:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = &some_slice[0]; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:39:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | let _ = some_slice.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec - --> tests/ui-toml/unwrap_used/unwrap_used.rs:40:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:44:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | let _ = &some_vec[0]; | ~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:40:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:44:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | let _ = some_vec.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque - --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL | let _ = &some_vecdeque[0]; | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:41:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap - --> tests/ui-toml/unwrap_used/unwrap_used.rs:42:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:50:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | let _ = &some_hashmap[&1]; | ~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:42:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:50:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap - --> tests/ui-toml/unwrap_used/unwrap_used.rs:43:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +114,7 @@ LL | let _ = &some_btreemap[&1]; | ~~~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:43:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice - --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:21 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:59:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | let _: u8 = boxed_slice[1]; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:47:22 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:59:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -143,7 +143,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:52:9 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:66:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | boxed_slice[0] = 1; | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:52:10 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:66:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:9 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:69:9 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -174,7 +174,7 @@ LL | some_slice[0] = 1; | ~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:53:10 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:69:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -183,7 +183,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:54:9 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:72:9 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -194,7 +194,7 @@ LL | some_vec[0] = 1; | ~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:54:10 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:72:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:55:9 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:75:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -214,7 +214,7 @@ LL | some_vecdeque[0] = 1; | ~~~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:55:10 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:75:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -223,7 +223,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:67:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:89:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -234,7 +234,7 @@ LL | let _ = some_vec[0..1].to_vec(); | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:67:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:89:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -243,7 +243,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:68:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:92:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -254,7 +254,7 @@ LL | let _ = some_vec[0..1].to_vec(); | ~~~~~~~~~~~~~~ error: used `unwrap()` on an `Option` value - --> tests/ui-toml/unwrap_used/unwrap_used.rs:68:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:92:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -263,7 +263,7 @@ 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 - --> tests/ui-toml/unwrap_used/unwrap_used.rs:75:13 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:101:13 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -274,7 +274,7 @@ LL | let _ = &boxed_slice[1]; | ~~~~~~~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:121:17 | LL | let _ = Box::new([0]).get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 index afb889f157f0..4f1f9ca07273 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed @@ -1,24 +1,35 @@ #![warn(clippy::upper_case_acronyms)] struct HttpResponse; // not linted by default, but with cfg option +//~^ upper_case_acronyms struct CString; // not linted enum Flags { Ns, // not linted + //~^ upper_case_acronyms Cwr, + //~^ upper_case_acronyms Ece, + //~^ upper_case_acronyms Urg, + //~^ upper_case_acronyms Ack, + //~^ upper_case_acronyms Psh, + //~^ upper_case_acronyms Rst, + //~^ upper_case_acronyms Syn, + //~^ upper_case_acronyms Fin, + //~^ upper_case_acronyms } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of // `GccLlvmSomething` struct GccllvmSomething; +//~^ upper_case_acronyms // don't warn on public items pub struct MIXEDCapital; @@ -36,7 +47,9 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { Wasd(u8), + //~^ upper_case_acronyms WasdMixed(String), + //~^ upper_case_acronyms Utf8(std::string::FromUtf8Error), Parse(T, String), } diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs index 1a5cf1b1947c..da522aadfdd7 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs @@ -1,24 +1,35 @@ #![warn(clippy::upper_case_acronyms)] struct HTTPResponse; // not linted by default, but with cfg option +//~^ upper_case_acronyms struct CString; // not linted enum Flags { NS, // not linted + //~^ upper_case_acronyms CWR, + //~^ upper_case_acronyms ECE, + //~^ upper_case_acronyms URG, + //~^ upper_case_acronyms ACK, + //~^ upper_case_acronyms PSH, + //~^ upper_case_acronyms RST, + //~^ upper_case_acronyms SYN, + //~^ upper_case_acronyms FIN, + //~^ upper_case_acronyms } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of // `GccLlvmSomething` struct GCCLLVMSomething; +//~^ upper_case_acronyms // don't warn on public items pub struct MIXEDCapital; @@ -36,7 +47,9 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { WASD(u8), + //~^ upper_case_acronyms WASDMixed(String), + //~^ upper_case_acronyms Utf8(std::string::FromUtf8Error), Parse(T, String), } diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr index 88917603ff8c..e1706b7472c0 100644 --- a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr @@ -8,73 +8,73 @@ LL | struct HTTPResponse; // not linted by default, but with cfg option = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `NS` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:8:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:9:5 | LL | NS, // not linted | ^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ns` error: name `CWR` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:9:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:11:5 | LL | CWR, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Cwr` error: name `ECE` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:10:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:13:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:11:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:15:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:12:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:17:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:13:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:19:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:14:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:21:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:15:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:23:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:16:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:25:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `GCCLLVMSomething` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:21:8 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:31:8 | LL | struct GCCLLVMSomething; | ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething` error: name `WASD` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:38:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:49:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `WASDMixed` contains a capitalized acronym - --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:39:5 + --> tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.rs:51:5 | LL | WASDMixed(String), | ^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `WasdMixed` diff --git a/tests/ui-toml/useless_vec/useless_vec.fixed b/tests/ui-toml/useless_vec/useless_vec.fixed index 08323a0dcc90..6181abc6ea57 100644 --- a/tests/ui-toml/useless_vec/useless_vec.fixed +++ b/tests/ui-toml/useless_vec/useless_vec.fixed @@ -6,6 +6,7 @@ fn foo(_: &[u32]) {} fn main() { foo(&[1_u32]); + //~^ useless_vec } #[test] diff --git a/tests/ui-toml/useless_vec/useless_vec.rs b/tests/ui-toml/useless_vec/useless_vec.rs index 1f4b27c53429..bffdcc59752b 100644 --- a/tests/ui-toml/useless_vec/useless_vec.rs +++ b/tests/ui-toml/useless_vec/useless_vec.rs @@ -6,6 +6,7 @@ fn foo(_: &[u32]) {} fn main() { foo(&vec![1_u32]); + //~^ useless_vec } #[test] diff --git a/tests/ui-toml/vec_box_sized/test.fixed b/tests/ui-toml/vec_box_sized/test.fixed index bb4936401ceb..423c761f1b17 100644 --- a/tests/ui-toml/vec_box_sized/test.fixed +++ b/tests/ui-toml/vec_box_sized/test.fixed @@ -7,10 +7,13 @@ struct C { } struct Foo(Vec); +//~^ vec_box struct Bar(Vec); +//~^ vec_box struct Quux(Vec>); struct Baz(Vec>); struct BarBaz(Vec>); struct FooBarBaz(Vec); +//~^ vec_box fn main() {} diff --git a/tests/ui-toml/vec_box_sized/test.rs b/tests/ui-toml/vec_box_sized/test.rs index 4c46deb585b6..fd9a13430021 100644 --- a/tests/ui-toml/vec_box_sized/test.rs +++ b/tests/ui-toml/vec_box_sized/test.rs @@ -7,10 +7,13 @@ struct C { } struct Foo(Vec>); +//~^ vec_box struct Bar(Vec>); +//~^ vec_box struct Quux(Vec>); struct Baz(Vec>); struct BarBaz(Vec>); struct FooBarBaz(Vec>); +//~^ vec_box fn main() {} diff --git a/tests/ui-toml/vec_box_sized/test.stderr b/tests/ui-toml/vec_box_sized/test.stderr index 8c0750d86663..b80b9492c3ca 100644 --- a/tests/ui-toml/vec_box_sized/test.stderr +++ b/tests/ui-toml/vec_box_sized/test.stderr @@ -8,13 +8,13 @@ LL | struct Foo(Vec>); = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui-toml/vec_box_sized/test.rs:10:12 + --> tests/ui-toml/vec_box_sized/test.rs:11:12 | LL | struct Bar(Vec>); | ^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> tests/ui-toml/vec_box_sized/test.rs:14:18 + --> tests/ui-toml/vec_box_sized/test.rs:16:18 | LL | struct FooBarBaz(Vec>); | ^^^^^^^^^^^ help: try: `Vec` diff --git a/tests/ui-toml/zero_single_char_names/zero_single_char_names.rs b/tests/ui-toml/zero_single_char_names/zero_single_char_names.rs index 22aaa242b9b9..d335b12d41ec 100644 --- a/tests/ui-toml/zero_single_char_names/zero_single_char_names.rs +++ b/tests/ui-toml/zero_single_char_names/zero_single_char_names.rs @@ -1,3 +1,4 @@ +//@check-pass #![warn(clippy::many_single_char_names)] fn main() {} From 0841f6e9dc3fa7f6be2b2c59f52a68988e4dda5a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Feb 2025 14:15:08 +0100 Subject: [PATCH 092/161] Don't make ui test annotations madatory for `ui-cargo` --- tests/compile-test.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 838ca2919a26..8d725d743dba 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -139,7 +139,7 @@ impl TestContext { } } - fn base_config(&self, test_dir: &str) -> Config { + fn base_config(&self, test_dir: &str, mandatory_annotations: bool) -> Config { let target_dir = PathBuf::from(var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())); let mut config = Config { output_conflict_handling: OutputConflictHandling::Error, @@ -153,7 +153,11 @@ impl TestContext { }; let defaults = config.comment_defaults.base(); defaults.exit_status = None.into(); - defaults.require_annotations = Some(Spanned::dummy(true)).into(); + if mandatory_annotations { + defaults.require_annotations = Some(Spanned::dummy(true)).into(); + } else { + defaults.require_annotations = None.into(); + } defaults.diagnostic_code_prefix = Some(Spanned::dummy("clippy::".into())).into(); defaults.set_custom("rustfix", RustfixMode::Everything); if let Some(collector) = self.diagnostic_collector.clone() { @@ -197,7 +201,7 @@ impl TestContext { } fn run_ui(cx: &TestContext) { - let mut config = cx.base_config("ui"); + let mut config = cx.base_config("ui", true); config .program .envs @@ -216,7 +220,7 @@ fn run_internal_tests(cx: &TestContext) { if !RUN_INTERNAL_TESTS { return; } - let mut config = cx.base_config("ui-internal"); + let mut config = cx.base_config("ui-internal", true); config.bless_command = Some("cargo uitest --features internal -- -- --bless".into()); ui_test::run_tests_generic( @@ -229,7 +233,7 @@ fn run_internal_tests(cx: &TestContext) { } fn run_ui_toml(cx: &TestContext) { - let mut config = cx.base_config("ui-toml"); + let mut config = cx.base_config("ui-toml", true); config .comment_defaults @@ -259,7 +263,7 @@ fn run_ui_cargo(cx: &TestContext) { return; } - let mut config = cx.base_config("ui-cargo"); + let mut config = cx.base_config("ui-cargo", false); 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()]; From a50953c1b96bf2c7b2c5bd7411f11fbcf67e8aeb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Feb 2025 14:42:33 +0100 Subject: [PATCH 093/161] Disable mandatory annotations for `ui-internals` tests for now until we find a solution for `tests/ui-internal/custom_ice_message.rs` --- tests/compile-test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 8d725d743dba..837096d00620 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -220,7 +220,7 @@ fn run_internal_tests(cx: &TestContext) { if !RUN_INTERNAL_TESTS { return; } - let mut config = cx.base_config("ui-internal", true); + let mut config = cx.base_config("ui-internal", false); config.bless_command = Some("cargo uitest --features internal -- -- --bless".into()); ui_test::run_tests_generic( From cc915cced82359b9816b3016958dadf6a503fb6f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Feb 2025 13:44:26 +0100 Subject: [PATCH 094/161] Add missing ui annotations to new ui tests --- tests/ui/unnecessary_map_or.fixed | 2 ++ tests/ui/unnecessary_map_or.rs | 2 ++ tests/ui/unnecessary_map_or.stderr | 4 ++-- tests/ui/{literal_string_with_formatting_args}.rs | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/ui/unnecessary_map_or.fixed b/tests/ui/unnecessary_map_or.fixed index 01646faea4b6..3c7243972845 100644 --- a/tests/ui/unnecessary_map_or.fixed +++ b/tests/ui/unnecessary_map_or.fixed @@ -125,6 +125,8 @@ fn with_deref(o: &S) -> bool { fn issue14201(a: Option, b: Option, s: &String) -> bool { let x = a.is_some_and(|a| a == *s); + //~^ unnecessary_map_or let y = b.is_none_or(|b| b == *s); + //~^ unnecessary_map_or x && y } diff --git a/tests/ui/unnecessary_map_or.rs b/tests/ui/unnecessary_map_or.rs index 10669f2a7f1a..e734a27badab 100644 --- a/tests/ui/unnecessary_map_or.rs +++ b/tests/ui/unnecessary_map_or.rs @@ -129,6 +129,8 @@ fn with_deref(o: &S) -> bool { fn issue14201(a: Option, b: Option, s: &String) -> bool { let x = a.map_or(false, |a| a == *s); + //~^ unnecessary_map_or let y = b.map_or(true, |b| b == *s); + //~^ unnecessary_map_or x && y } diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index 57a76c21c70d..fb469e1f472e 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -290,7 +290,7 @@ LL + o.is_none_or(|n| n > 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:107:13 + --> tests/ui/unnecessary_map_or.rs:131:13 | LL | let x = a.map_or(false, |a| a == *s); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -302,7 +302,7 @@ LL + let x = a.is_some_and(|a| a == *s); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:108:13 + --> tests/ui/unnecessary_map_or.rs:133:13 | LL | let y = b.map_or(true, |b| b == *s); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/{literal_string_with_formatting_args}.rs b/tests/ui/{literal_string_with_formatting_args}.rs index 0f5b36e67503..3096558a516a 100644 --- a/tests/ui/{literal_string_with_formatting_args}.rs +++ b/tests/ui/{literal_string_with_formatting_args}.rs @@ -1,3 +1,5 @@ +//@check-pass + // Regression test for . // The `dbg` macro generates a literal with the name of the current file, so // we need to ensure the lint is not emitted in this case. From 211f79d84e3e6a9c2be01dc3025b01f3e23474d9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Feb 2025 14:05:59 +0100 Subject: [PATCH 095/161] Fix `tests/ui-toml/absolute_paths/absolute_paths_2015.rs` test --- .../absolute_paths_2015.default.stderr | 14 ++++++++++++++ .../ui-toml/absolute_paths/absolute_paths_2015.rs | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr diff --git a/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr b/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr new file mode 100644 index 000000000000..b946514454aa --- /dev/null +++ b/tests/ui-toml/absolute_paths/absolute_paths_2015.default.stderr @@ -0,0 +1,14 @@ +error: consider bringing this path into scope with the `use` keyword + --> tests/ui-toml/absolute_paths/absolute_paths_2015.rs:16:13 + | +LL | let _ = ::m1::m2::X; + | ^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui-toml/absolute_paths/absolute_paths_2015.rs:7:9 + | +LL | #![deny(clippy::absolute_paths)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui-toml/absolute_paths/absolute_paths_2015.rs b/tests/ui-toml/absolute_paths/absolute_paths_2015.rs index ea556b7e437d..86981f979556 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths_2015.rs +++ b/tests/ui-toml/absolute_paths/absolute_paths_2015.rs @@ -1,8 +1,8 @@ //@revisions: default allow_crates //@[default]rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/default //@[allow_crates]rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates +//@[allow_crates]check-pass //@edition:2015 -//@check-pass #![deny(clippy::absolute_paths)] @@ -12,4 +12,6 @@ mod m1 { } } -fn main() {} +fn main() { + let _ = ::m1::m2::X; //~[default] absolute_paths +} From 0fcc2dba925cd60f6a518e60f9be9017c26cd174 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 15 Feb 2025 14:51:03 +0100 Subject: [PATCH 096/161] Fix 32 bits tests --- tests/ui/cast_size.32bit.stderr | 36 ++++++------- tests/ui/fn_to_numeric_cast.32bit.stderr | 44 ++++++++-------- tests/ui/large_enum_variant.32bit.stderr | 64 +++++++++++++++--------- 3 files changed, 81 insertions(+), 63 deletions(-) diff --git a/tests/ui/cast_size.32bit.stderr b/tests/ui/cast_size.32bit.stderr index 8ff3464676c3..d2c845dc8217 100644 --- a/tests/ui/cast_size.32bit.stderr +++ b/tests/ui/cast_size.32bit.stderr @@ -13,7 +13,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ 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) - --> tests/ui/cast_size.rs:21:5 + --> tests/ui/cast_size.rs:22:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -22,25 +22,25 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` 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) - --> tests/ui/cast_size.rs:22:5 + --> tests/ui/cast_size.rs:24:5 | LL | x1 as f32; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:23:5 + --> tests/ui/cast_size.rs:26:5 | LL | x0 as f64; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:24:5 + --> tests/ui/cast_size.rs:28:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:33:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:29:5 + --> tests/ui/cast_size.rs:35:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:30:5 + --> tests/ui/cast_size.rs:37:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:31:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:31:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:32:5 + --> tests/ui/cast_size.rs:42:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:33:5 + --> tests/ui/cast_size.rs:44:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:34:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:34:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:35:5 + --> tests/ui/cast_size.rs:49:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,25 +151,25 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:36:5 + --> tests/ui/cast_size.rs:51: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) - --> tests/ui/cast_size.rs:43:5 + --> tests/ui/cast_size.rs:59: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) - --> tests/ui/cast_size.rs:44:5 + --> tests/ui/cast_size.rs:61:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal out of range for `usize` - --> tests/ui/cast_size.rs:44:5 + --> tests/ui/cast_size.rs:61:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fn_to_numeric_cast.32bit.stderr b/tests/ui/fn_to_numeric_cast.32bit.stderr index 65991a3989ac..7093f8caf101 100644 --- a/tests/ui/fn_to_numeric_cast.32bit.stderr +++ b/tests/ui/fn_to_numeric_cast.32bit.stderr @@ -8,13 +8,13 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:11:13 + --> tests/ui/fn_to_numeric_cast.rs:12:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:12:13 + --> tests/ui/fn_to_numeric_cast.rs:14:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` @@ -23,121 +23,121 @@ LL | let _ = foo as i32; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:13:13 + --> tests/ui/fn_to_numeric_cast.rs:16:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:14:13 + --> tests/ui/fn_to_numeric_cast.rs:18:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:15:13 + --> tests/ui/fn_to_numeric_cast.rs:20:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:17:13 + --> tests/ui/fn_to_numeric_cast.rs:23:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:18:13 + --> tests/ui/fn_to_numeric_cast.rs:25:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32` - --> tests/ui/fn_to_numeric_cast.rs:19:13 + --> tests/ui/fn_to_numeric_cast.rs:27:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:20:13 + --> tests/ui/fn_to_numeric_cast.rs:29:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:21:13 + --> tests/ui/fn_to_numeric_cast.rs:31:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:34:13 + --> tests/ui/fn_to_numeric_cast.rs:45:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:35:13 + --> tests/ui/fn_to_numeric_cast.rs:47:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:36:13 + --> tests/ui/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:37:13 + --> tests/ui/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:38:13 + --> tests/ui/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:39:13 + --> tests/ui/fn_to_numeric_cast.rs:55:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:41:13 + --> tests/ui/fn_to_numeric_cast.rs:58:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:42:13 + --> tests/ui/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32` - --> tests/ui/fn_to_numeric_cast.rs:43:13 + --> tests/ui/fn_to_numeric_cast.rs:62:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:44:13 + --> tests/ui/fn_to_numeric_cast.rs:64:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:45:13 + --> tests/ui/fn_to_numeric_cast.rs:66:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:52:5 + --> tests/ui/fn_to_numeric_cast.rs:74:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index 36f3d930b535..af09a56854aa 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -2,6 +2,7 @@ error: large size difference between variants --> tests/ui/large_enum_variant.rs:11:1 | LL | / enum LargeEnum { +LL | | LL | | A(i32), | | ------ the second-largest variant contains at least 4 bytes LL | | B([i32; 8000]), @@ -17,9 +18,10 @@ LL | B(Box<[i32; 8000]>), | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:35:1 + --> tests/ui/large_enum_variant.rs:36:1 | LL | / enum LargeEnum2 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | ContainingLargeEnum(LargeEnum), @@ -33,9 +35,10 @@ LL | ContainingLargeEnum(Box), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:40:1 + --> tests/ui/large_enum_variant.rs:42:1 | LL | / enum LargeEnum3 { +LL | | LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), | | --------------------------------------------------------- the largest variant contains at least 70004 bytes LL | | VoidVariant, @@ -50,9 +53,10 @@ LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:46:1 + --> tests/ui/large_enum_variant.rs:49:1 | LL | / enum LargeEnum4 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | StructLikeLarge { x: [i32; 8000], y: i32 }, @@ -66,9 +70,10 @@ LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:51:1 + --> tests/ui/large_enum_variant.rs:55:1 | LL | / enum LargeEnum5 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | StructLikeLarge2 { x: [i32; 8000] }, @@ -82,9 +87,10 @@ LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:67:1 + --> tests/ui/large_enum_variant.rs:72:1 | LL | / enum LargeEnum7 { +LL | | LL | | A, LL | | B([u8; 1255]), | | ------------- the largest variant contains at least 1255 bytes @@ -99,9 +105,10 @@ LL | B(Box<[u8; 1255]>), | ~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:73:1 + --> tests/ui/large_enum_variant.rs:79:1 | LL | / enum LargeEnum8 { +LL | | LL | | VariantOk(i32, u32), | | ------------------- the second-largest variant contains at least 8 bytes LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), @@ -115,9 +122,10 @@ LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]> | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:78:1 + --> tests/ui/large_enum_variant.rs:85:1 | LL | / enum LargeEnum9 { +LL | | LL | | A(Struct<()>), | | ------------- the second-largest variant contains at least 4 bytes LL | | B(Struct2), @@ -131,9 +139,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:83:1 + --> tests/ui/large_enum_variant.rs:91:1 | LL | / enum LargeEnumOk2 { +LL | | LL | | A(T), | | ---- the second-largest variant contains at least 0 bytes LL | | B(Struct2), @@ -147,9 +156,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:88:1 + --> tests/ui/large_enum_variant.rs:97:1 | LL | / enum LargeEnumOk3 { +LL | | LL | | A(Struct), | | ------------ the second-largest variant contains at least 4 bytes LL | | B(Struct2), @@ -163,9 +173,10 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:103:1 + --> tests/ui/large_enum_variant.rs:113:1 | LL | / enum CopyableLargeEnum { +LL | | LL | | A(bool), | | ------- the second-largest variant contains at least 1 bytes LL | | B([u64; 8000]), @@ -174,20 +185,21 @@ LL | | } | |_^ the entire enum is at least 64004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:103:6 + --> tests/ui/large_enum_variant.rs:113:6 | LL | enum CopyableLargeEnum { | ^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:105:5 + --> tests/ui/large_enum_variant.rs:116:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:108:1 + --> tests/ui/large_enum_variant.rs:119:1 | LL | / enum ManuallyCopyLargeEnum { +LL | | LL | | A(bool), | | ------- the second-largest variant contains at least 1 bytes LL | | B([u64; 8000]), @@ -196,20 +208,21 @@ LL | | } | |_^ the entire enum is at least 64004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:108:6 + --> tests/ui/large_enum_variant.rs:119:6 | LL | enum ManuallyCopyLargeEnum { | ^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:110:5 + --> tests/ui/large_enum_variant.rs:122:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:121:1 + --> tests/ui/large_enum_variant.rs:133:1 | LL | / enum SomeGenericPossiblyCopyEnum { +LL | | LL | | A(bool, std::marker::PhantomData), | | ------------------------------------ the second-largest variant contains at least 1 bytes LL | | B([u64; 4000]), @@ -218,20 +231,21 @@ LL | | } | |_^ the entire enum is at least 32004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:121:6 + --> tests/ui/large_enum_variant.rs:133:6 | LL | enum SomeGenericPossiblyCopyEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:123:5 + --> tests/ui/large_enum_variant.rs:136:5 | LL | B([u64; 4000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:134:1 + --> tests/ui/large_enum_variant.rs:147:1 | LL | / enum LargeEnumWithGenerics { +LL | | LL | | Small, | | ----- the second-largest variant carries no data at all LL | | Large((T, [u8; 512])), @@ -245,9 +259,10 @@ LL | Large(Box<(T, [u8; 512])>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:143:1 + --> tests/ui/large_enum_variant.rs:157:1 | LL | / enum WithGenerics { +LL | | LL | | Large([Foo; 64]), | | --------------------- the largest variant contains at least 512 bytes LL | | Small(u8), @@ -261,9 +276,10 @@ LL | Large(Box<[Foo; 64]>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:153:1 + --> tests/ui/large_enum_variant.rs:168:1 | LL | / enum LargeEnumOfConst { +LL | | LL | | Ok, | | -- the second-largest variant carries no data at all LL | | Error(PossiblyLargeEnumWithConst<256>), @@ -277,9 +293,10 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:158:1 + --> tests/ui/large_enum_variant.rs:174:1 | LL | / enum WithRecursion { +LL | | LL | | Large([u64; 64]), | | ---------------- the largest variant contains at least 512 bytes LL | | Recursive(Box), @@ -293,9 +310,10 @@ LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:168:1 + --> tests/ui/large_enum_variant.rs:185:1 | LL | / enum LargeEnumWithGenericsAndRecursive { +LL | | LL | | Ok(), | | ---- the second-largest variant carries no data at all LL | | Error(WithRecursionAndGenerics), From 8ae4e7f76dcf5e30ed40ecda537792a3f93f15fb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Feb 2025 14:59:48 +0100 Subject: [PATCH 097/161] Fix `tests/ui/transmute_32bit.rs` annotations --- tests/ui/transmute_32bit.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ui/transmute_32bit.rs b/tests/ui/transmute_32bit.rs index e162bbb2d929..997f43ab12b5 100644 --- a/tests/ui/transmute_32bit.rs +++ b/tests/ui/transmute_32bit.rs @@ -3,12 +3,12 @@ #[warn(clippy::wrong_transmute)] fn main() { unsafe { - let _: *const usize = std::mem::transmute(6.0f32); + let _: *const usize = std::mem::transmute(6.0f32); //~ wrong_transmute - let _: *mut usize = std::mem::transmute(6.0f32); + let _: *mut usize = std::mem::transmute(6.0f32); //~ wrong_transmute - let _: *const usize = std::mem::transmute('x'); + let _: *const usize = std::mem::transmute('x'); //~ wrong_transmute - let _: *mut usize = std::mem::transmute('x'); + let _: *mut usize = std::mem::transmute('x'); //~ wrong_transmute } } From 2c0c661e56185cd50170d1f1251add4a584a88f2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Feb 2025 15:21:22 +0100 Subject: [PATCH 098/161] Better handle 32bit/64bit-specific ui tests --- tests/ui/cast_size.32bit.stderr | 38 ++++++++--------- tests/ui/cast_size.64bit.stderr | 36 ++++++++-------- tests/ui/cast_size.rs | 5 ++- tests/ui/fn_to_numeric_cast.32bit.stderr | 46 ++++++++++----------- tests/ui/fn_to_numeric_cast.64bit.stderr | 46 ++++++++++----------- tests/ui/fn_to_numeric_cast.rs | 19 ++++++--- tests/ui/large_enum_variant.32bit.stderr | 48 +++++++++++----------- tests/ui/large_enum_variant.64bit.stderr | 52 ++++++++++++------------ tests/ui/large_enum_variant.rs | 8 ++-- 9 files changed, 155 insertions(+), 143 deletions(-) diff --git a/tests/ui/cast_size.32bit.stderr b/tests/ui/cast_size.32bit.stderr index d2c845dc8217..637dd6fddea1 100644 --- a/tests/ui/cast_size.32bit.stderr +++ b/tests/ui/cast_size.32bit.stderr @@ -1,5 +1,5 @@ error: casting `isize` to `i8` may truncate the value - --> tests/ui/cast_size.rs:15:5 + --> tests/ui/cast_size.rs:17:5 | LL | 1isize as i8; | ^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ 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) - --> tests/ui/cast_size.rs:22:5 + --> tests/ui/cast_size.rs:24:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -22,25 +22,25 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` 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) - --> tests/ui/cast_size.rs:24:5 + --> tests/ui/cast_size.rs:26:5 | LL | x1 as f32; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:26:5 + --> tests/ui/cast_size.rs:28:5 | LL | x0 as f64; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:30:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:33:5 + --> tests/ui/cast_size.rs:35:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:35:5 + --> tests/ui/cast_size.rs:37:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:37:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:39:5 + --> tests/ui/cast_size.rs:41:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:39:5 + --> tests/ui/cast_size.rs:41:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:42:5 + --> tests/ui/cast_size.rs:44:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:44:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:46:5 + --> tests/ui/cast_size.rs:48:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:46:5 + --> tests/ui/cast_size.rs:48:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:49:5 + --> tests/ui/cast_size.rs:51:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,25 +151,25 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:51:5 + --> tests/ui/cast_size.rs:53: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) - --> tests/ui/cast_size.rs:59:5 + --> tests/ui/cast_size.rs:61: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) - --> tests/ui/cast_size.rs:61:5 + --> tests/ui/cast_size.rs:63:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal out of range for `usize` - --> tests/ui/cast_size.rs:61:5 + --> tests/ui/cast_size.rs:63:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.64bit.stderr b/tests/ui/cast_size.64bit.stderr index d67040bcc1cb..0e12ecb6f2da 100644 --- a/tests/ui/cast_size.64bit.stderr +++ b/tests/ui/cast_size.64bit.stderr @@ -1,5 +1,5 @@ error: casting `isize` to `i8` may truncate the value - --> tests/ui/cast_size.rs:15:5 + --> tests/ui/cast_size.rs:17:5 | LL | 1isize as i8; | ^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ 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) - --> tests/ui/cast_size.rs:22:5 + --> tests/ui/cast_size.rs:24:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -22,25 +22,25 @@ LL | x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` 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) - --> tests/ui/cast_size.rs:24:5 + --> tests/ui/cast_size.rs:26:5 | LL | x1 as f32; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:26:5 + --> tests/ui/cast_size.rs:28:5 | LL | x0 as f64; | ^^^^^^^^^ 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) - --> tests/ui/cast_size.rs:28:5 + --> tests/ui/cast_size.rs:30:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:33:5 + --> tests/ui/cast_size.rs:35:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:35:5 + --> tests/ui/cast_size.rs:37:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:37:5 + --> tests/ui/cast_size.rs:39:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -76,7 +76,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:39:5 + --> tests/ui/cast_size.rs:41:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:39:5 + --> tests/ui/cast_size.rs:41:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | 1usize as i32; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:42:5 + --> tests/ui/cast_size.rs:44:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:44:5 + --> tests/ui/cast_size.rs:46:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:46:5 + --> tests/ui/cast_size.rs:48:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -133,13 +133,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> tests/ui/cast_size.rs:46:5 + --> tests/ui/cast_size.rs:48:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:49:5 + --> tests/ui/cast_size.rs:51:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -151,19 +151,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> tests/ui/cast_size.rs:51:5 + --> tests/ui/cast_size.rs:53: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) - --> tests/ui/cast_size.rs:59:5 + --> tests/ui/cast_size.rs:61: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) - --> tests/ui/cast_size.rs:61:5 + --> tests/ui/cast_size.rs:63:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index 9fc07b2ae4fd..f7c294357702 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -1,4 +1,6 @@ -//@stderr-per-bitwidth +//@revisions: 32bit 64bit +//@[32bit]ignore-bitwidth: 64 +//@[64bit]ignore-bitwidth: 32 //@no-rustfix #![warn( @@ -60,5 +62,6 @@ fn main() { //~^ cast_precision_loss 9_999_999_999_999_999usize as f64; //~^ cast_precision_loss + //~[32bit]^^ overflowing_literals // 999_999_999_999_999_999_999_999_999_999u128 as f128; } diff --git a/tests/ui/fn_to_numeric_cast.32bit.stderr b/tests/ui/fn_to_numeric_cast.32bit.stderr index 7093f8caf101..2affd0b7d6e9 100644 --- a/tests/ui/fn_to_numeric_cast.32bit.stderr +++ b/tests/ui/fn_to_numeric_cast.32bit.stderr @@ -1,5 +1,5 @@ error: casting function pointer `foo` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:10:13 + --> tests/ui/fn_to_numeric_cast.rs:12:13 | LL | let _ = foo as i8; | ^^^^^^^^^ help: try: `foo as usize` @@ -8,13 +8,13 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:12:13 + --> tests/ui/fn_to_numeric_cast.rs:14:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:14:13 + --> tests/ui/fn_to_numeric_cast.rs:16:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` @@ -23,121 +23,121 @@ LL | let _ = foo as i32; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:16:13 + --> tests/ui/fn_to_numeric_cast.rs:19:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:18:13 + --> tests/ui/fn_to_numeric_cast.rs:21:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:20:13 + --> tests/ui/fn_to_numeric_cast.rs:23:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:23:13 + --> tests/ui/fn_to_numeric_cast.rs:26:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:25:13 + --> tests/ui/fn_to_numeric_cast.rs:28:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32` - --> tests/ui/fn_to_numeric_cast.rs:27:13 + --> tests/ui/fn_to_numeric_cast.rs:30:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:29:13 + --> tests/ui/fn_to_numeric_cast.rs:33:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:31:13 + --> tests/ui/fn_to_numeric_cast.rs:35:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:45:13 + --> tests/ui/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:47:13 + --> tests/ui/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:49:13 + --> tests/ui/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:51:13 + --> tests/ui/fn_to_numeric_cast.rs:56:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:53:13 + --> tests/ui/fn_to_numeric_cast.rs:58:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:55:13 + --> tests/ui/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:58:13 + --> tests/ui/fn_to_numeric_cast.rs:63:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:60:13 + --> tests/ui/fn_to_numeric_cast.rs:65:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32` - --> tests/ui/fn_to_numeric_cast.rs:62:13 + --> tests/ui/fn_to_numeric_cast.rs:67:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:64:13 + --> tests/ui/fn_to_numeric_cast.rs:70:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:66:13 + --> tests/ui/fn_to_numeric_cast.rs:72:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32` - --> tests/ui/fn_to_numeric_cast.rs:74:5 + --> tests/ui/fn_to_numeric_cast.rs:80:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/fn_to_numeric_cast.64bit.stderr b/tests/ui/fn_to_numeric_cast.64bit.stderr index 1c2a0dab10b5..48961d14f2bb 100644 --- a/tests/ui/fn_to_numeric_cast.64bit.stderr +++ b/tests/ui/fn_to_numeric_cast.64bit.stderr @@ -1,5 +1,5 @@ error: casting function pointer `foo` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:10:13 + --> tests/ui/fn_to_numeric_cast.rs:12:13 | LL | let _ = foo as i8; | ^^^^^^^^^ help: try: `foo as usize` @@ -8,19 +8,19 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` error: casting function pointer `foo` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:12:13 + --> tests/ui/fn_to_numeric_cast.rs:14:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:14:13 + --> tests/ui/fn_to_numeric_cast.rs:16:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:16:13 + --> tests/ui/fn_to_numeric_cast.rs:19:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` @@ -29,115 +29,115 @@ LL | let _ = foo as i64; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` error: casting function pointer `foo` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:18:13 + --> tests/ui/fn_to_numeric_cast.rs:21:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:20:13 + --> tests/ui/fn_to_numeric_cast.rs:23:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:23:13 + --> tests/ui/fn_to_numeric_cast.rs:26:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:25:13 + --> tests/ui/fn_to_numeric_cast.rs:28:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:27:13 + --> tests/ui/fn_to_numeric_cast.rs:30:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:29:13 + --> tests/ui/fn_to_numeric_cast.rs:33:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:31:13 + --> tests/ui/fn_to_numeric_cast.rs:35:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:45:13 + --> tests/ui/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:47:13 + --> tests/ui/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:49:13 + --> tests/ui/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> tests/ui/fn_to_numeric_cast.rs:51:13 + --> tests/ui/fn_to_numeric_cast.rs:56:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> tests/ui/fn_to_numeric_cast.rs:53:13 + --> tests/ui/fn_to_numeric_cast.rs:58:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> tests/ui/fn_to_numeric_cast.rs:55:13 + --> tests/ui/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:58:13 + --> tests/ui/fn_to_numeric_cast.rs:63:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:60:13 + --> tests/ui/fn_to_numeric_cast.rs:65:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:62:13 + --> tests/ui/fn_to_numeric_cast.rs:67:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> tests/ui/fn_to_numeric_cast.rs:64:13 + --> tests/ui/fn_to_numeric_cast.rs:70:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> tests/ui/fn_to_numeric_cast.rs:66:13 + --> tests/ui/fn_to_numeric_cast.rs:72:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32`, which truncates the value - --> tests/ui/fn_to_numeric_cast.rs:74:5 + --> tests/ui/fn_to_numeric_cast.rs:80:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 70be37c0f959..b09938dfc562 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -1,4 +1,6 @@ -//@stderr-per-bitwidth +//@revisions: 32bit 64bit +//@[32bit]ignore-bitwidth: 64 +//@[64bit]ignore-bitwidth: 32 //@no-rustfix #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] @@ -12,7 +14,8 @@ fn test_function_to_numeric_cast() { let _ = foo as i16; //~^ fn_to_numeric_cast_with_truncation let _ = foo as i32; - //~^ fn_to_numeric_cast_with_truncation + //~[64bit]^ fn_to_numeric_cast_with_truncation + //~[32bit]^^ fn_to_numeric_cast let _ = foo as i64; //~^ fn_to_numeric_cast let _ = foo as i128; @@ -25,7 +28,8 @@ fn test_function_to_numeric_cast() { let _ = foo as u16; //~^ fn_to_numeric_cast_with_truncation let _ = foo as u32; - //~^ fn_to_numeric_cast_with_truncation + //~[64bit]^ fn_to_numeric_cast_with_truncation + //~[32bit]^^ fn_to_numeric_cast let _ = foo as u64; //~^ fn_to_numeric_cast let _ = foo as u128; @@ -47,7 +51,8 @@ fn test_function_var_to_numeric_cast() { let _ = abc as i16; //~^ fn_to_numeric_cast_with_truncation let _ = abc as i32; - //~^ fn_to_numeric_cast_with_truncation + //~[64bit]^ fn_to_numeric_cast_with_truncation + //~[32bit]^^ fn_to_numeric_cast let _ = abc as i64; //~^ fn_to_numeric_cast let _ = abc as i128; @@ -60,7 +65,8 @@ fn test_function_var_to_numeric_cast() { let _ = abc as u16; //~^ fn_to_numeric_cast_with_truncation let _ = abc as u32; - //~^ fn_to_numeric_cast_with_truncation + //~[64bit]^ fn_to_numeric_cast_with_truncation + //~[32bit]^^ fn_to_numeric_cast let _ = abc as u64; //~^ fn_to_numeric_cast let _ = abc as u128; @@ -72,7 +78,8 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 - //~^ fn_to_numeric_cast_with_truncation + //~[64bit]^ fn_to_numeric_cast_with_truncation + //~[32bit]^^ ERROR: literal out of range for `usize` } fn main() {} diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index af09a56854aa..7f66207ce797 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -1,5 +1,5 @@ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:11:1 + --> tests/ui/large_enum_variant.rs:13:1 | LL | / enum LargeEnum { LL | | @@ -18,7 +18,7 @@ LL | B(Box<[i32; 8000]>), | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:36:1 + --> tests/ui/large_enum_variant.rs:38:1 | LL | / enum LargeEnum2 { LL | | @@ -35,7 +35,7 @@ LL | ContainingLargeEnum(Box), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:42:1 + --> tests/ui/large_enum_variant.rs:44:1 | LL | / enum LargeEnum3 { LL | | @@ -53,7 +53,7 @@ LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:49:1 + --> tests/ui/large_enum_variant.rs:51:1 | LL | / enum LargeEnum4 { LL | | @@ -70,7 +70,7 @@ LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:55:1 + --> tests/ui/large_enum_variant.rs:57:1 | LL | / enum LargeEnum5 { LL | | @@ -87,7 +87,7 @@ LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:72:1 + --> tests/ui/large_enum_variant.rs:74:1 | LL | / enum LargeEnum7 { LL | | @@ -105,7 +105,7 @@ LL | B(Box<[u8; 1255]>), | ~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:79:1 + --> tests/ui/large_enum_variant.rs:81:1 | LL | / enum LargeEnum8 { LL | | @@ -122,7 +122,7 @@ LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]> | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:85:1 + --> tests/ui/large_enum_variant.rs:87:1 | LL | / enum LargeEnum9 { LL | | @@ -139,7 +139,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:91:1 + --> tests/ui/large_enum_variant.rs:93:1 | LL | / enum LargeEnumOk2 { LL | | @@ -156,7 +156,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:97:1 + --> tests/ui/large_enum_variant.rs:99:1 | LL | / enum LargeEnumOk3 { LL | | @@ -173,7 +173,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:113:1 + --> tests/ui/large_enum_variant.rs:115:1 | LL | / enum CopyableLargeEnum { LL | | @@ -185,18 +185,18 @@ LL | | } | |_^ the entire enum is at least 64004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:113:6 + --> tests/ui/large_enum_variant.rs:115:6 | LL | enum CopyableLargeEnum { | ^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:116:5 + --> tests/ui/large_enum_variant.rs:118:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:119:1 + --> tests/ui/large_enum_variant.rs:121:1 | LL | / enum ManuallyCopyLargeEnum { LL | | @@ -208,18 +208,18 @@ LL | | } | |_^ the entire enum is at least 64004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:119:6 + --> tests/ui/large_enum_variant.rs:121:6 | LL | enum ManuallyCopyLargeEnum { | ^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:122:5 + --> tests/ui/large_enum_variant.rs:124:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:133:1 + --> tests/ui/large_enum_variant.rs:135:1 | LL | / enum SomeGenericPossiblyCopyEnum { LL | | @@ -231,18 +231,18 @@ LL | | } | |_^ the entire enum is at least 32004 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:133:6 + --> tests/ui/large_enum_variant.rs:135:6 | LL | enum SomeGenericPossiblyCopyEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:136:5 + --> tests/ui/large_enum_variant.rs:138:5 | LL | B([u64; 4000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:147:1 + --> tests/ui/large_enum_variant.rs:149:1 | LL | / enum LargeEnumWithGenerics { LL | | @@ -259,7 +259,7 @@ LL | Large(Box<(T, [u8; 512])>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:157:1 + --> tests/ui/large_enum_variant.rs:159:1 | LL | / enum WithGenerics { LL | | @@ -276,7 +276,7 @@ LL | Large(Box<[Foo; 64]>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:168:1 + --> tests/ui/large_enum_variant.rs:170:1 | LL | / enum LargeEnumOfConst { LL | | @@ -293,7 +293,7 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:174:1 + --> tests/ui/large_enum_variant.rs:176:1 | LL | / enum WithRecursion { LL | | @@ -310,7 +310,7 @@ LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:185:1 + --> tests/ui/large_enum_variant.rs:187:1 | LL | / enum LargeEnumWithGenericsAndRecursive { LL | | diff --git a/tests/ui/large_enum_variant.64bit.stderr b/tests/ui/large_enum_variant.64bit.stderr index 8f70ad2b5b72..dbc4c125e610 100644 --- a/tests/ui/large_enum_variant.64bit.stderr +++ b/tests/ui/large_enum_variant.64bit.stderr @@ -1,5 +1,5 @@ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:11:1 + --> tests/ui/large_enum_variant.rs:13:1 | LL | / enum LargeEnum { LL | | @@ -18,7 +18,7 @@ LL | B(Box<[i32; 8000]>), | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:36:1 + --> tests/ui/large_enum_variant.rs:38:1 | LL | / enum LargeEnum2 { LL | | @@ -35,7 +35,7 @@ LL | ContainingLargeEnum(Box), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:42:1 + --> tests/ui/large_enum_variant.rs:44:1 | LL | / enum LargeEnum3 { LL | | @@ -53,7 +53,7 @@ LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:49:1 + --> tests/ui/large_enum_variant.rs:51:1 | LL | / enum LargeEnum4 { LL | | @@ -70,7 +70,7 @@ LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:55:1 + --> tests/ui/large_enum_variant.rs:57:1 | LL | / enum LargeEnum5 { LL | | @@ -87,7 +87,7 @@ LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, | ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:72:1 + --> tests/ui/large_enum_variant.rs:74:1 | LL | / enum LargeEnum7 { LL | | @@ -105,7 +105,7 @@ LL | B(Box<[u8; 1255]>), | ~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:79:1 + --> tests/ui/large_enum_variant.rs:81:1 | LL | / enum LargeEnum8 { LL | | @@ -122,7 +122,7 @@ LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]> | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:85:1 + --> tests/ui/large_enum_variant.rs:87:1 | LL | / enum LargeEnum9 { LL | | @@ -139,7 +139,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:91:1 + --> tests/ui/large_enum_variant.rs:93:1 | LL | / enum LargeEnumOk2 { LL | | @@ -156,7 +156,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:97:1 + --> tests/ui/large_enum_variant.rs:99:1 | LL | / enum LargeEnumOk3 { LL | | @@ -173,7 +173,7 @@ LL | B(Box), | ~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:113:1 + --> tests/ui/large_enum_variant.rs:115:1 | LL | / enum CopyableLargeEnum { LL | | @@ -185,18 +185,18 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:113:6 + --> tests/ui/large_enum_variant.rs:115:6 | LL | enum CopyableLargeEnum { | ^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:116:5 + --> tests/ui/large_enum_variant.rs:118:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:119:1 + --> tests/ui/large_enum_variant.rs:121:1 | LL | / enum ManuallyCopyLargeEnum { LL | | @@ -208,18 +208,18 @@ LL | | } | |_^ the entire enum is at least 64008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:119:6 + --> tests/ui/large_enum_variant.rs:121:6 | LL | enum ManuallyCopyLargeEnum { | ^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:122:5 + --> tests/ui/large_enum_variant.rs:124:5 | LL | B([u64; 8000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:133:1 + --> tests/ui/large_enum_variant.rs:135:1 | LL | / enum SomeGenericPossiblyCopyEnum { LL | | @@ -231,18 +231,18 @@ LL | | } | |_^ the entire enum is at least 32008 bytes | note: boxing a variant would require the type no longer be `Copy` - --> tests/ui/large_enum_variant.rs:133:6 + --> tests/ui/large_enum_variant.rs:135:6 | LL | enum SomeGenericPossiblyCopyEnum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum - --> tests/ui/large_enum_variant.rs:136:5 + --> tests/ui/large_enum_variant.rs:138:5 | LL | B([u64; 4000]), | ^^^^^^^^^^^^^^ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:147:1 + --> tests/ui/large_enum_variant.rs:149:1 | LL | / enum LargeEnumWithGenerics { LL | | @@ -259,7 +259,7 @@ LL | Large(Box<(T, [u8; 512])>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:157:1 + --> tests/ui/large_enum_variant.rs:159:1 | LL | / enum WithGenerics { LL | | @@ -276,7 +276,7 @@ LL | Large(Box<[Foo; 64]>), | ~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:168:1 + --> tests/ui/large_enum_variant.rs:170:1 | LL | / enum LargeEnumOfConst { LL | | @@ -293,7 +293,7 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:174:1 + --> tests/ui/large_enum_variant.rs:176:1 | LL | / enum WithRecursion { LL | | @@ -310,7 +310,7 @@ LL | Large(Box<[u64; 64]>), | ~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:185:1 + --> tests/ui/large_enum_variant.rs:187:1 | LL | / enum LargeEnumWithGenericsAndRecursive { LL | | @@ -327,7 +327,7 @@ LL | Error(Box>), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:221:5 + --> tests/ui/large_enum_variant.rs:223:5 | LL | / enum NoWarnings { LL | | @@ -344,7 +344,7 @@ LL | BigBoi(Box), | ~~~~~~~~~~~~~~~~~~~~~ error: large size difference between variants - --> tests/ui/large_enum_variant.rs:227:5 + --> tests/ui/large_enum_variant.rs:229:5 | LL | / enum MakesClippyAngry { LL | | diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 9e0fc03cb4e1..9cf6318ca342 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -1,6 +1,8 @@ -//@stderr-per-bitwidth +//@revisions: 32bit 64bit //@aux-build:proc_macros.rs //@no-rustfix +//@[32bit]ignore-bitwidth: 64 +//@[64bit]ignore-bitwidth: 32 #![allow(dead_code)] #![allow(unused_variables)] #![warn(clippy::large_enum_variant)] @@ -219,13 +221,13 @@ mod issue11915 { } enum NoWarnings { - //~^ large_enum_variant + //~[64bit]^ large_enum_variant BigBoi(PublishWithBytes), _SmallBoi(u8), } enum MakesClippyAngry { - //~^ large_enum_variant + //~[64bit]^ large_enum_variant BigBoi(PublishWithVec), _SmallBoi(u8), } From 847bd6707d6a6d2a91dca93ad91119adee611a43 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Feb 2025 15:41:30 +0100 Subject: [PATCH 099/161] f --- tests/ui/cast_size.rs | 2 +- tests/ui/fn_to_numeric_cast.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index f7c294357702..e92401808867 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -62,6 +62,6 @@ fn main() { //~^ cast_precision_loss 9_999_999_999_999_999usize as f64; //~^ cast_precision_loss - //~[32bit]^^ overflowing_literals + //~[32bit]^^ ERROR: literal out of range for `usize` // 999_999_999_999_999_999_999_999_999_999u128 as f128; } diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index b09938dfc562..f53cbacdb377 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -79,7 +79,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 //~[64bit]^ fn_to_numeric_cast_with_truncation - //~[32bit]^^ ERROR: literal out of range for `usize` + //~[32bit]^^ fn_to_numeric_cast } fn main() {} From e0a62acc8826875dcf2ff17750f6c28fcc69c2f4 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 2 Feb 2025 17:23:00 +0100 Subject: [PATCH 100/161] Add `clippy_utils::is_mutable()` --- clippy_utils/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0d9502c50db6..8130f2951c06 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -3675,3 +3675,24 @@ pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) - _ => false, } } + +/// Returns `true` if `expr` designates a mutable static, a mutable local binding, or an expression +/// that can be owned. +pub fn is_mutable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + if let Some(hir_id) = path_to_local(expr) + && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) + { + matches!(pat.kind, PatKind::Binding(BindingMode::MUT, ..)) + } else if let ExprKind::Path(p) = &expr.kind + && let Some(mutability) = cx + .qpath_res(p, expr.hir_id) + .opt_def_id() + .and_then(|id| cx.tcx.static_mutability(id)) + { + mutability == Mutability::Mut + } else if let ExprKind::Field(parent, _) = expr.kind { + is_mutable(cx, parent) + } else { + true + } +} From 35ad69c124d67faa72e3a61f77118d1fb0585002 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 10 Feb 2025 17:56:53 +0100 Subject: [PATCH 101/161] Cleanup: remove useless `span_is_local()` calls in `manual_slice_fill` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In both instances, `!assign_val.span.from_expansion()` – which is more restrictive than `span_is_local(assign_val.span)` – has been required already. --- clippy_lints/src/loops/manual_slice_fill.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs index bece83eaf3d8..70766b0b4e4b 100644 --- a/clippy_lints/src/loops/manual_slice_fill.rs +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -1,6 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::eager_or_lazy::switch_to_eager_eval; -use clippy_utils::macros::span_is_local; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::{HasSession, snippet_with_applicability}; use clippy_utils::ty::implements_trait; @@ -55,7 +54,6 @@ pub(super) fn check<'tcx>( && !assignval.span.from_expansion() // It is generally not equivalent to use the `fill` method if `assignval` can have side effects && switch_to_eager_eval(cx, assignval) - && span_is_local(assignval.span) // The `fill` method requires that the slice's element type implements the `Clone` trait. && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() && implements_trait(cx, cx.typeck_results().expr_ty(slice), clone_trait, &[]) @@ -78,7 +76,6 @@ pub(super) fn check<'tcx>( && local == pat.hir_id && !assignval.span.from_expansion() && switch_to_eager_eval(cx, assignval) - && span_is_local(assignval.span) // The `fill` method cannot be used if the slice's element type does not implement the `Clone` trait. && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() && implements_trait(cx, cx.typeck_results().expr_ty(recv), clone_trait, &[]) From 510d3b69fc2e13f7cc2cb485716aba6908f147dc Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 2 Feb 2025 19:11:14 +0100 Subject: [PATCH 102/161] Use `clippy_utils::is_mutable()` in `unnecessary_struct_initialization` --- .../src/unnecessary_struct_initialization.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/unnecessary_struct_initialization.rs b/clippy_lints/src/unnecessary_struct_initialization.rs index 1df229c330eb..5792b6b3178d 100644 --- a/clippy_lints/src/unnecessary_struct_initialization.rs +++ b/clippy_lints/src/unnecessary_struct_initialization.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::is_copy; -use clippy_utils::{get_parent_expr, path_to_local}; -use rustc_hir::{BindingMode, Expr, ExprField, ExprKind, Node, PatKind, Path, QPath, StructTailExpr, UnOp}; +use clippy_utils::{get_parent_expr, is_mutable, path_to_local}; +use rustc_hir::{Expr, ExprField, ExprKind, Path, QPath, StructTailExpr, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -157,16 +157,6 @@ fn same_path_in_all_fields<'tcx>( } } -fn is_mutable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let Some(hir_id) = path_to_local(expr) - && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) - { - matches!(pat.kind, PatKind::Binding(BindingMode::MUT, ..)) - } else { - true - } -} - fn check_references(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool { if let Some(parent) = get_parent_expr(cx, expr_a) && let parent_ty = cx.typeck_results().expr_ty_adjusted(parent) From 44aa75fd2aa94850103215c8e67b0d0baa24b6b7 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 10 Feb 2025 18:05:11 +0100 Subject: [PATCH 103/161] `manual_slice_fill`: initializer must not reference the iterator ```rust let mut tmp = vec![1, 2, 3]; for b in &mut tmp { *b = !*b; } ``` must not suggest the invalid `tmp.fill(!*b)`. --- clippy_lints/src/loops/manual_slice_fill.rs | 2 ++ tests/ui/manual_slice_fill.fixed | 8 ++++++++ tests/ui/manual_slice_fill.rs | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs index 70766b0b4e4b..a97641788621 100644 --- a/clippy_lints/src/loops/manual_slice_fill.rs +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -76,6 +76,8 @@ pub(super) fn check<'tcx>( && local == pat.hir_id && !assignval.span.from_expansion() && switch_to_eager_eval(cx, assignval) + // `assignval` must not reference the iterator + && !is_local_used(cx, assignval, local) // The `fill` method cannot be used if the slice's element type does not implement the `Clone` trait. && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() && implements_trait(cx, cx.typeck_results().expr_ty(recv), clone_trait, &[]) diff --git a/tests/ui/manual_slice_fill.fixed b/tests/ui/manual_slice_fill.fixed index 80e271117fc1..bba863247f5d 100644 --- a/tests/ui/manual_slice_fill.fixed +++ b/tests/ui/manual_slice_fill.fixed @@ -115,3 +115,11 @@ fn issue_14192() { tmp[0] = i; } } + +fn issue14189() { + // Should not lint because `!*b` is not constant + let mut tmp = vec![1, 2, 3]; + for b in &mut tmp { + *b = !*b; + } +} diff --git a/tests/ui/manual_slice_fill.rs b/tests/ui/manual_slice_fill.rs index f758f47bbcb0..44c60dc40f07 100644 --- a/tests/ui/manual_slice_fill.rs +++ b/tests/ui/manual_slice_fill.rs @@ -128,3 +128,11 @@ fn issue_14192() { tmp[0] = i; } } + +fn issue14189() { + // Should not lint because `!*b` is not constant + let mut tmp = vec![1, 2, 3]; + for b in &mut tmp { + *b = !*b; + } +} From 01d7a324dc66dfca20e1644419688c9d12b8f486 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 10 Feb 2025 13:09:31 +0100 Subject: [PATCH 104/161] `manual_strip`: use existing identifier instead of placeholder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the manually stripped entity receives a name as the first use through a simple `let` statement, this name can be used in the generated `if let Some(…)` expression instead of a placeholder. --- clippy_lints/src/manual_strip.rs | 73 +++++++++++++++++++++------- tests/ui/manual_strip.rs | 17 +++++++ tests/ui/manual_strip.stderr | 47 ++++++++++++++++-- tests/ui/manual_strip_fixable.fixed | 15 ++++++ tests/ui/manual_strip_fixable.rs | 17 +++++++ tests/ui/manual_strip_fixable.stderr | 40 +++++++++++++++ 6 files changed, 188 insertions(+), 21 deletions(-) create mode 100644 tests/ui/manual_strip_fixable.fixed create mode 100644 tests/ui/manual_strip_fixable.rs create mode 100644 tests/ui/manual_strip_fixable.stderr diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index d69384a2cb70..daed88b492e6 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -2,19 +2,21 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::snippet; +use clippy_utils::source::snippet_with_applicability; use clippy_utils::usage::mutated_variables; use clippy_utils::{eq_expr_value, higher}; +use rustc_ast::BindingMode; use rustc_ast::ast::LitKind; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::intravisit::{Visitor, walk_expr}; -use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_hir::intravisit::{Visitor, walk_expr, walk_pat}; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, Node, PatKind}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::impl_lint_pass; use rustc_span::source_map::Spanned; -use rustc_span::{Span, sym}; +use rustc_span::{Symbol, sym}; use std::iter; declare_clippy_lint! { @@ -95,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { return; } - let strippings = find_stripping(cx, strip_kind, target_res, pattern, then); + let (strippings, bindings) = find_stripping(cx, strip_kind, target_res, pattern, then); if !strippings.is_empty() { let kind_word = match strip_kind { StripKind::Prefix => "prefix", @@ -103,10 +105,29 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { }; let test_span = expr.span.until(then.span); + + // If the first use is a simple `let` statement, reuse its identifier in the `if let Some(…)` and + // remove the `let` statement as long as the identifier is never bound again within the lexical + // scope of interest. + let (ident_name, let_stmt_span, skip, mut app) = if let Node::LetStmt(let_stmt) = + cx.tcx.parent_hir_node(strippings[0].hir_id) + && let PatKind::Binding(BindingMode::NONE, _, ident, None) = &let_stmt.pat.kind + && bindings.get(&ident.name) == Some(&1) + { + ( + ident.name.as_str(), + Some(cx.sess().source_map().span_extend_while_whitespace(let_stmt.span)), + 1, + Applicability::MachineApplicable, + ) + } else { + ("", None, 0, Applicability::HasPlaceholders) + }; + span_lint_and_then( cx, MANUAL_STRIP, - strippings[0], + strippings[0].span, format!("stripping a {kind_word} manually"), |diag| { diag.span_note(test_span, format!("the {kind_word} was tested here")); @@ -115,14 +136,20 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { iter::once(( test_span, format!( - "if let Some() = {}.strip_{kind_word}({}) ", - snippet(cx, target_arg.span, ".."), - snippet(cx, pattern.span, "..") + "if let Some({ident_name}) = {}.strip_{kind_word}({}) ", + snippet_with_applicability(cx, target_arg.span, "_", &mut app), + snippet_with_applicability(cx, pattern.span, "_", &mut app) ), )) - .chain(strippings.into_iter().map(|span| (span, "".into()))) + .chain(let_stmt_span.map(|span| (span, String::new()))) + .chain( + strippings + .into_iter() + .skip(skip) + .map(|expr| (expr.span, ident_name.into())), + ) .collect(), - Applicability::HasPlaceholders, + app, ); }, ); @@ -188,19 +215,21 @@ fn peel_ref<'a>(expr: &'a Expr<'_>) -> &'a Expr<'a> { /// Find expressions where `target` is stripped using the length of `pattern`. /// We'll suggest replacing these expressions with the result of the `strip_{prefix,suffix}` /// method. +/// Also, all bindings found during the visit are counted and returned. fn find_stripping<'tcx>( cx: &LateContext<'tcx>, strip_kind: StripKind, target: Res, pattern: &'tcx Expr<'_>, - expr: &'tcx Expr<'_>, -) -> Vec { + expr: &'tcx Expr<'tcx>, +) -> (Vec<&'tcx Expr<'tcx>>, FxHashMap) { struct StrippingFinder<'a, 'tcx> { cx: &'a LateContext<'tcx>, strip_kind: StripKind, target: Res, pattern: &'tcx Expr<'tcx>, - results: Vec, + results: Vec<&'tcx Expr<'tcx>>, + bindings: FxHashMap, } impl<'tcx> Visitor<'tcx> for StrippingFinder<'_, 'tcx> { @@ -215,7 +244,7 @@ fn find_stripping<'tcx>( match (self.strip_kind, start, end) { (StripKind::Prefix, Some(start), None) => { if eq_pattern_length(self.cx, self.pattern, start) { - self.results.push(ex.span); + self.results.push(ex); return; } }, @@ -232,7 +261,7 @@ fn find_stripping<'tcx>( && self.cx.qpath_res(left_path, left_arg.hir_id) == self.target && eq_pattern_length(self.cx, self.pattern, right) { - self.results.push(ex.span); + self.results.push(ex); return; } }, @@ -242,6 +271,13 @@ fn find_stripping<'tcx>( walk_expr(self, ex); } + + fn visit_pat(&mut self, pat: &'tcx rustc_hir::Pat<'tcx>) -> Self::Result { + if let PatKind::Binding(_, _, ident, _) = pat.kind { + *self.bindings.entry(ident.name).or_default() += 1; + } + walk_pat(self, pat); + } } let mut finder = StrippingFinder { @@ -250,7 +286,8 @@ fn find_stripping<'tcx>( target, pattern, results: vec![], + bindings: FxHashMap::default(), }; walk_expr(&mut finder, expr); - finder.results + (finder.results, finder.bindings) } diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs index ce53c99e6b50..086b75a39875 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -74,6 +74,23 @@ fn main() { if s3.starts_with("ab") { s4[2..].to_string(); } + + // Don't propose to reuse the `stripped` identifier as it is overriden + if s.starts_with("ab") { + let stripped = &s["ab".len()..]; + //~^ ERROR: stripping a prefix manually + let stripped = format!("{stripped}-"); + println!("{stripped}{}", &s["ab".len()..]); + } + + // Don't propose to reuse the `stripped` identifier as it is mutable + if s.starts_with("ab") { + let mut stripped = &s["ab".len()..]; + //~^ ERROR: stripping a prefix manually + stripped = ""; + let stripped = format!("{stripped}-"); + println!("{stripped}{}", &s["ab".len()..]); + } } #[clippy::msrv = "1.44"] diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index 41d15da610c4..a323ef700e76 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -138,13 +138,54 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> tests/ui/manual_strip.rs:91:9 + --> tests/ui/manual_strip.rs:80:24 + | +LL | let stripped = &s["ab".len()..]; + | ^^^^^^^^^^^^^^^^ + | +note: the prefix was tested here + --> tests/ui/manual_strip.rs:79:5 + | +LL | if s.starts_with("ab") { + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: try using the `strip_prefix` method + | +LL ~ if let Some() = s.strip_prefix("ab") { +LL ~ let stripped = ; +LL | +LL | let stripped = format!("{stripped}-"); +LL ~ println!("{stripped}{}", ); + | + +error: stripping a prefix manually + --> tests/ui/manual_strip.rs:88:28 + | +LL | let mut stripped = &s["ab".len()..]; + | ^^^^^^^^^^^^^^^^ + | +note: the prefix was tested here + --> tests/ui/manual_strip.rs:87:5 + | +LL | if s.starts_with("ab") { + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: try using the `strip_prefix` method + | +LL ~ if let Some() = s.strip_prefix("ab") { +LL ~ let mut stripped = ; +LL | +LL | stripped = ""; +LL | let stripped = format!("{stripped}-"); +LL ~ println!("{stripped}{}", ); + | + +error: stripping a prefix manually + --> tests/ui/manual_strip.rs:108:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> tests/ui/manual_strip.rs:90:5 + --> tests/ui/manual_strip.rs:107:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -154,5 +195,5 @@ LL ~ if let Some() = s.strip_prefix('a') { LL ~ .to_string(); | -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors diff --git a/tests/ui/manual_strip_fixable.fixed b/tests/ui/manual_strip_fixable.fixed new file mode 100644 index 000000000000..75a3f1645de3 --- /dev/null +++ b/tests/ui/manual_strip_fixable.fixed @@ -0,0 +1,15 @@ +#![warn(clippy::manual_strip)] + +fn main() { + let s = "abc"; + + if let Some(stripped) = s.strip_prefix("ab") { + //~^ ERROR: stripping a prefix manually + println!("{stripped}{}", stripped); + } + + if let Some(stripped) = s.strip_suffix("bc") { + //~^ ERROR: stripping a suffix manually + println!("{stripped}{}", stripped); + } +} diff --git a/tests/ui/manual_strip_fixable.rs b/tests/ui/manual_strip_fixable.rs new file mode 100644 index 000000000000..5080068449e2 --- /dev/null +++ b/tests/ui/manual_strip_fixable.rs @@ -0,0 +1,17 @@ +#![warn(clippy::manual_strip)] + +fn main() { + let s = "abc"; + + if s.starts_with("ab") { + let stripped = &s["ab".len()..]; + //~^ ERROR: stripping a prefix manually + println!("{stripped}{}", &s["ab".len()..]); + } + + if s.ends_with("bc") { + let stripped = &s[..s.len() - "bc".len()]; + //~^ ERROR: stripping a suffix manually + println!("{stripped}{}", &s[..s.len() - "bc".len()]); + } +} diff --git a/tests/ui/manual_strip_fixable.stderr b/tests/ui/manual_strip_fixable.stderr new file mode 100644 index 000000000000..1c276e5d8fdf --- /dev/null +++ b/tests/ui/manual_strip_fixable.stderr @@ -0,0 +1,40 @@ +error: stripping a prefix manually + --> tests/ui/manual_strip_fixable.rs:7:24 + | +LL | let stripped = &s["ab".len()..]; + | ^^^^^^^^^^^^^^^^ + | +note: the prefix was tested here + --> tests/ui/manual_strip_fixable.rs:6:5 + | +LL | if s.starts_with("ab") { + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::manual-strip` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_strip)]` +help: try using the `strip_prefix` method + | +LL ~ if let Some(stripped) = s.strip_prefix("ab") { +LL ~ +LL ~ println!("{stripped}{}", stripped); + | + +error: stripping a suffix manually + --> tests/ui/manual_strip_fixable.rs:13:24 + | +LL | let stripped = &s[..s.len() - "bc".len()]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the suffix was tested here + --> tests/ui/manual_strip_fixable.rs:12:5 + | +LL | if s.ends_with("bc") { + | ^^^^^^^^^^^^^^^^^^^^^ +help: try using the `strip_suffix` method + | +LL ~ if let Some(stripped) = s.strip_suffix("bc") { +LL ~ +LL ~ println!("{stripped}{}", stripped); + | + +error: aborting due to 2 previous errors + From 91548d0fe33eeab33db48e81d7a07d7edee0965a Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sat, 8 Feb 2025 22:10:12 +0900 Subject: [PATCH 105/161] prevent `useless_asref` from suggesting `.clone()` on types without the `Clone` trait --- clippy_lints/src/methods/useless_asref.rs | 5 +++- tests/ui/useless_asref.fixed | 30 +++++++++++++++++++ tests/ui/useless_asref.rs | 30 +++++++++++++++++++ tests/ui/useless_asref.stderr | 36 +++++++++++------------ 4 files changed, 82 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 6d3da42775f4..58bce32c1ac6 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::ty::{should_call_clone_as_function, walk_ptrs_ty_depth}; +use clippy_utils::ty::{implements_trait, should_call_clone_as_function, walk_ptrs_ty_depth}; use clippy_utils::{ get_parent_expr, is_diag_trait_item, match_def_path, path_to_local_id, peel_blocks, strip_pat_refs, }; @@ -101,6 +101,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, && is_calling_clone(cx, arg) // And that we are not recommending recv.clone() over Arc::clone() or similar && !should_call_clone_as_function(cx, rcv_ty) + // https://github.com/rust-lang/rust-clippy/issues/12357 + && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() + && implements_trait(cx, cx.typeck_results().expr_ty(recvr), clone_trait, &[]) { lint_as_ref_clone(cx, expr.span.with_hi(parent.span.hi()), recvr, call_name); } diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index e399bd76fc1e..8c1f948fb580 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -8,6 +8,7 @@ )] use std::fmt::Debug; +use std::ops::Deref; use std::rc::{Rc, Weak as RcWeak}; use std::sync::{Arc, Weak as ArcWeak}; @@ -218,6 +219,35 @@ fn issue_14088() { let _: Option<&str> = s.as_ref().map(|x| x.as_ref()); } +pub struct Wrap { + inner: T, +} + +impl Deref for Wrap { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +struct NonCloneableError; + +pub struct Issue12357 { + current: Option>>, +} + +impl Issue12357 { + fn f(&self) -> Option> { + self.current.as_ref().map(|p| Arc::clone(p)) + } + + fn g(&self) { + let result: Result = Ok("Hello".to_string()); + let cloned = result.as_ref().map(|s| s.clone()); + } +} + fn main() { not_ok(); ok(); diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index 4c76a2ecf7b0..d9db2d4f5596 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -8,6 +8,7 @@ )] use std::fmt::Debug; +use std::ops::Deref; use std::rc::{Rc, Weak as RcWeak}; use std::sync::{Arc, Weak as ArcWeak}; @@ -218,6 +219,35 @@ fn issue_14088() { let _: Option<&str> = s.as_ref().map(|x| x.as_ref()); } +pub struct Wrap { + inner: T, +} + +impl Deref for Wrap { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +struct NonCloneableError; + +pub struct Issue12357 { + current: Option>>, +} + +impl Issue12357 { + fn f(&self) -> Option> { + self.current.as_ref().map(|p| Arc::clone(p)) + } + + fn g(&self) { + let result: Result = Ok("Hello".to_string()); + let cloned = result.as_ref().map(|s| s.clone()); + } +} + fn main() { not_ok(); ok(); diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index d0ca10936fd5..8255f5d9d2ab 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -1,5 +1,5 @@ error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:50:18 + --> tests/ui/useless_asref.rs:51:18 | LL | foo_rstr(rstr.as_ref()); | ^^^^^^^^^^^^^ help: try: `rstr` @@ -11,103 +11,103 @@ LL | #![deny(clippy::useless_asref)] | ^^^^^^^^^^^^^^^^^^^^^ error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:53:20 + --> tests/ui/useless_asref.rs:54:20 | LL | foo_rslice(rslice.as_ref()); | ^^^^^^^^^^^^^^^ help: try: `rslice` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:58:21 + --> tests/ui/useless_asref.rs:59:21 | LL | foo_mrslice(mrslice.as_mut()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:61:20 + --> tests/ui/useless_asref.rs:62:20 | LL | foo_rslice(mrslice.as_ref()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:69:20 + --> tests/ui/useless_asref.rs:70:20 | LL | foo_rslice(rrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:72:18 + --> tests/ui/useless_asref.rs:73:18 | LL | foo_rstr(rrrrrstr.as_ref()); | ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:78:21 + --> tests/ui/useless_asref.rs:79:21 | LL | foo_mrslice(mrrrrrslice.as_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:81:20 + --> tests/ui/useless_asref.rs:82:20 | LL | foo_rslice(mrrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:86:16 + --> tests/ui/useless_asref.rs:87:16 | LL | foo_rrrrmr((&&&&MoreRef).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)` error: this call to `as_mut` does nothing - --> tests/ui/useless_asref.rs:137:13 + --> tests/ui/useless_asref.rs:138:13 | LL | foo_mrt(mrt.as_mut()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref` does nothing - --> tests/ui/useless_asref.rs:140:12 + --> tests/ui/useless_asref.rs:141:12 | LL | foo_rt(mrt.as_ref()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:152:13 + --> tests/ui/useless_asref.rs:153:13 | LL | let z = x.as_ref().map(String::clone); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:155:13 + --> tests/ui/useless_asref.rs:156:13 | LL | let z = x.as_ref().map(|z| z.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:158:13 + --> tests/ui/useless_asref.rs:159:13 | LL | let z = x.as_ref().map(|z| String::clone(z)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:182:9 + --> tests/ui/useless_asref.rs:183:9 | LL | x.field.as_ref().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:185:9 + --> tests/ui/useless_asref.rs:186:9 | LL | x.field.as_ref().map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:188:9 + --> tests/ui/useless_asref.rs:189:9 | LL | x.field.as_ref().map(|v| Clone::clone(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.field.clone()` error: this call to `as_ref.map(...)` does nothing - --> tests/ui/useless_asref.rs:193:9 + --> tests/ui/useless_asref.rs:194:9 | LL | Some(1).as_ref().map(|&x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(1).clone()` From fd17bfe57d615673f94e1c4a5686222ad03a1056 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Tue, 11 Feb 2025 15:16:32 +0900 Subject: [PATCH 106/161] add `manual_contains` lint --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/methods/manual_contains.rs | 113 ++++++++++++++++++++ clippy_lints/src/methods/mod.rs | 30 ++++++ tests/ui/manual_contains.fixed | 98 +++++++++++++++++ tests/ui/manual_contains.rs | 98 +++++++++++++++++ tests/ui/manual_contains.stderr | 77 +++++++++++++ tests/ui/needless_collect.fixed | 8 +- tests/ui/needless_collect.rs | 8 +- tests/ui/needless_collect.stderr | 38 +++---- tests/ui/search_is_some_fixable_none.fixed | 2 +- tests/ui/search_is_some_fixable_none.rs | 2 +- tests/ui/search_is_some_fixable_some.fixed | 2 +- tests/ui/search_is_some_fixable_some.rs | 2 +- 14 files changed, 455 insertions(+), 25 deletions(-) create mode 100644 clippy_lints/src/methods/manual_contains.rs create mode 100644 tests/ui/manual_contains.fixed create mode 100644 tests/ui/manual_contains.rs create mode 100644 tests/ui/manual_contains.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ea3ce8f79d..2b8695f66279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5743,6 +5743,7 @@ Released 2018-09-13 [`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits [`manual_c_str_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals [`manual_clamp`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp +[`manual_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_contains [`manual_div_ceil`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_div_ceil [`manual_filter`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter [`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1f00fb82c6db..4b439d3a7a2d 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -418,6 +418,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::ITER_SKIP_ZERO_INFO, crate::methods::ITER_WITH_DRAIN_INFO, crate::methods::JOIN_ABSOLUTE_PATHS_INFO, + crate::methods::MANUAL_CONTAINS_INFO, crate::methods::MANUAL_C_STR_LITERALS_INFO, crate::methods::MANUAL_FILTER_MAP_INFO, crate::methods::MANUAL_FIND_MAP_INFO, diff --git a/clippy_lints/src/methods/manual_contains.rs b/clippy_lints/src/methods/manual_contains.rs new file mode 100644 index 000000000000..61bf32cc19bb --- /dev/null +++ b/clippy_lints/src/methods/manual_contains.rs @@ -0,0 +1,113 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::eager_or_lazy::switch_to_eager_eval; +use clippy_utils::peel_hir_pat_refs; +use clippy_utils::source::snippet_with_applicability; +use clippy_utils::sugg::Sugg; +use rustc_ast::UnOp; +use rustc_errors::Applicability; +use rustc_hir::def::Res; +use rustc_hir::{BinOpKind, Body, Expr, ExprKind, HirId, QPath}; +use rustc_lint::LateContext; +use rustc_middle::ty::{self}; +use rustc_span::source_map::Spanned; + +use super::MANUAL_CONTAINS; + +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>) { + let mut app = Applicability::MachineApplicable; + + if !expr.span.from_expansion() + // check if `iter().any()` can be replaced with `contains()` + && let ExprKind::Closure(closure) = closure_arg.kind + && let Body{params: [param],value} = cx.tcx.hir().body(closure.body) + && let ExprKind::Binary(op, lhs, rhs) = value.kind + && let (peeled_ref_pat, _) = peel_hir_pat_refs(param.pat) + && let Some((snip,snip_expr)) = can_replace_with_contains(cx, op, lhs, rhs, peeled_ref_pat.hir_id, &mut app) + && let ref_type = cx.typeck_results().expr_ty_adjusted(recv) + && let ty::Ref(_, inner_type, _) = ref_type.kind() + && let ty::Slice(slice_type) = inner_type.kind() + && *slice_type == cx.typeck_results().expr_ty(snip_expr) + { + span_lint_and_sugg( + cx, + MANUAL_CONTAINS, + expr.span, + "using `contains()` instead of `iter().any()` is more efficient", + "try", + format!( + "{}.contains({})", + snippet_with_applicability(cx, recv.span, "_", &mut app), + snip + ), + app, + ); + } +} + +enum EligibleArg { + IsClosureArg, + ContainsArg(String), +} + +fn try_get_eligible_arg<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'tcx>, + closure_arg_id: HirId, + applicability: &mut Applicability, +) -> Option<(EligibleArg, &'tcx Expr<'tcx>)> { + let mut get_snippet = |expr: &Expr<'_>, needs_borrow: bool| { + let sugg = Sugg::hir_with_applicability(cx, expr, "_", applicability); + EligibleArg::ContainsArg((if needs_borrow { sugg.addr() } else { sugg }).to_string()) + }; + + match expr.kind { + ExprKind::Path(QPath::Resolved(_, path)) => { + if path.res == Res::Local(closure_arg_id) { + Some((EligibleArg::IsClosureArg, expr)) + } else { + Some((get_snippet(expr, true), expr)) + } + }, + ExprKind::Unary(UnOp::Deref, inner) => { + if let ExprKind::Path(QPath::Resolved(_, path)) = inner.kind { + if path.res == Res::Local(closure_arg_id) { + Some((EligibleArg::IsClosureArg, expr)) + } else { + Some((get_snippet(inner, false), expr)) + } + } else { + None + } + }, + _ => { + if switch_to_eager_eval(cx, expr) { + Some((get_snippet(expr, true), expr)) + } else { + None + } + }, + } +} + +fn can_replace_with_contains<'tcx>( + cx: &LateContext<'tcx>, + bin_op: Spanned, + left_expr: &'tcx Expr<'tcx>, + right_expr: &'tcx Expr<'tcx>, + closure_arg_id: HirId, + applicability: &mut Applicability, +) -> Option<(String, &'tcx Expr<'tcx>)> { + if bin_op.node != BinOpKind::Eq { + return None; + } + + let left_candidate = try_get_eligible_arg(cx, left_expr, closure_arg_id, applicability)?; + let right_candidate = try_get_eligible_arg(cx, right_expr, closure_arg_id, applicability)?; + match (left_candidate, right_candidate) { + ((EligibleArg::IsClosureArg, _), (EligibleArg::ContainsArg(snip), candidate_expr)) + | ((EligibleArg::ContainsArg(snip), candidate_expr), (EligibleArg::IsClosureArg, _)) => { + Some((snip, candidate_expr)) + }, + _ => None, + } +} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7e9db66ff864..7e66016b89d9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -54,6 +54,7 @@ mod iter_with_drain; mod iterator_step_by_zero; mod join_absolute_paths; mod manual_c_str_literals; +mod manual_contains; mod manual_inspect; mod manual_is_variant_and; mod manual_next_back; @@ -4434,6 +4435,31 @@ declare_clippy_lint! { "calling .bytes() is very inefficient when data is not in memory" } +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `iter().any()` on slices when it can be replaced with `contains()` and suggests doing so. + /// + /// ### Why is this bad? + /// `contains()` is more concise and idiomatic, sometimes more fast. + /// + /// ### Example + /// ```no_run + /// fn foo(values: &[u8]) -> bool { + /// values.iter().any(|&v| v == 10) + /// } + /// ``` + /// Use instead: + /// ```no_run + /// fn foo(values: &[u8]) -> bool { + /// values.contains(&10) + /// } + /// ``` + #[clippy::version = "1.86.0"] + pub MANUAL_CONTAINS, + perf, + "unnecessary `iter().any()` on slices that can be replaced with `contains()`" +} + #[expect(clippy::struct_excessive_bools)] pub struct Methods { avoid_breaking_exported_api: bool, @@ -4609,6 +4635,7 @@ impl_lint_pass!(Methods => [ SLICED_STRING_AS_BYTES, RETURN_AND_THEN, UNBUFFERED_BYTES, + MANUAL_CONTAINS, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4866,6 +4893,9 @@ impl Methods { Some(("map", _, [map_arg], _, map_call_span)) => { map_all_any_identity::check(cx, expr, recv, map_call_span, map_arg, call_span, arg, "any"); }, + Some(("iter", iter_recv, ..)) => { + manual_contains::check(cx, expr, iter_recv, arg); + }, _ => {}, } }, diff --git a/tests/ui/manual_contains.fixed b/tests/ui/manual_contains.fixed new file mode 100644 index 000000000000..d26c948a7817 --- /dev/null +++ b/tests/ui/manual_contains.fixed @@ -0,0 +1,98 @@ +#![warn(clippy::manual_contains)] +#![allow(clippy::eq_op, clippy::useless_vec)] + +fn should_lint() { + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.contains(&4); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.contains(&4); + //~^ manual_contains + + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.contains(&10); + //~^ manual_contains + + let num = 14; + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.contains(&num); + //~^ manual_contains + + let num = 14; + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.contains(&num); + //~^ manual_contains + + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.contains(&4); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.contains(&4); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let a = &4; + let _ = values.contains(a); + //~^ manual_contains + + let vec = vec!["1", "2", "3", "4", "5", "6"]; + let values = &vec[..]; + let _ = values.contains(&"4"); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.contains(&(4 + 1)); + //~^ manual_contains +} + +fn should_not_lint() { + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|&v| v > 10); + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v % 2 == 0); + let _ = values.iter().any(|&v| v * 2 == 6); + let _ = values.iter().any(|&v| v == v); + let _ = values.iter().any(|&v| 4 == 4); + let _ = values.contains(&4); + + let a = 1; + let b = 2; + let _ = values.iter().any(|&v| a == b); + let _ = values.iter().any(|&v| a == 4); + + let vec: Vec = vec!["1", "2", "3", "4", "5", "6"] + .iter() + .map(|&x| x.to_string()) + .collect(); + let values = &vec[..]; + let _ = values.iter().any(|v| v == "4"); + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let mut counter = 0; + let mut count = || { + counter += 1; + counter + }; + let _ = values.iter().any(|&v| v == count()); + let _ = values.iter().any(|&v| v == v * 2); +} + +fn foo(values: &[u8]) -> bool { + values.contains(&10) + //~^ manual_contains +} + +fn bar(values: [u8; 3]) -> bool { + values.contains(&10) + //~^ manual_contains +} diff --git a/tests/ui/manual_contains.rs b/tests/ui/manual_contains.rs new file mode 100644 index 000000000000..fe67d2ee5d5c --- /dev/null +++ b/tests/ui/manual_contains.rs @@ -0,0 +1,98 @@ +#![warn(clippy::manual_contains)] +#![allow(clippy::eq_op, clippy::useless_vec)] + +fn should_lint() { + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v == 4); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v == 4); + //~^ manual_contains + + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|&v| v == 10); + //~^ manual_contains + + let num = 14; + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|&v| v == num); + //~^ manual_contains + + let num = 14; + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|&v| num == v); + //~^ manual_contains + + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|v| *v == 4); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| 4 == v); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let a = &4; + let _ = values.iter().any(|v| *v == *a); + //~^ manual_contains + + let vec = vec!["1", "2", "3", "4", "5", "6"]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v == "4"); + //~^ manual_contains + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v == 4 + 1); + //~^ manual_contains +} + +fn should_not_lint() { + let values: [u8; 6] = [3, 14, 15, 92, 6, 5]; + let _ = values.iter().any(|&v| v > 10); + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let _ = values.iter().any(|&v| v % 2 == 0); + let _ = values.iter().any(|&v| v * 2 == 6); + let _ = values.iter().any(|&v| v == v); + let _ = values.iter().any(|&v| 4 == 4); + let _ = values.contains(&4); + + let a = 1; + let b = 2; + let _ = values.iter().any(|&v| a == b); + let _ = values.iter().any(|&v| a == 4); + + let vec: Vec = vec!["1", "2", "3", "4", "5", "6"] + .iter() + .map(|&x| x.to_string()) + .collect(); + let values = &vec[..]; + let _ = values.iter().any(|v| v == "4"); + + let vec: Vec = vec![1, 2, 3, 4, 5, 6]; + let values = &vec[..]; + let mut counter = 0; + let mut count = || { + counter += 1; + counter + }; + let _ = values.iter().any(|&v| v == count()); + let _ = values.iter().any(|&v| v == v * 2); +} + +fn foo(values: &[u8]) -> bool { + values.iter().any(|&v| v == 10) + //~^ manual_contains +} + +fn bar(values: [u8; 3]) -> bool { + values.iter().any(|&v| v == 10) + //~^ manual_contains +} diff --git a/tests/ui/manual_contains.stderr b/tests/ui/manual_contains.stderr new file mode 100644 index 000000000000..e6e2dea560c6 --- /dev/null +++ b/tests/ui/manual_contains.stderr @@ -0,0 +1,77 @@ +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:7:13 + | +LL | let _ = values.iter().any(|&v| v == 4); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&4)` + | + = note: `-D clippy::manual-contains` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_contains)]` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:12:13 + | +LL | let _ = values.iter().any(|&v| v == 4); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&4)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:16:13 + | +LL | let _ = values.iter().any(|&v| v == 10); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&10)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:21:13 + | +LL | let _ = values.iter().any(|&v| v == num); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&num)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:26:13 + | +LL | let _ = values.iter().any(|&v| num == v); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&num)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:30:13 + | +LL | let _ = values.iter().any(|v| *v == 4); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&4)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:35:13 + | +LL | let _ = values.iter().any(|&v| 4 == v); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&4)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:41:13 + | +LL | let _ = values.iter().any(|v| *v == *a); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(a)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:46:13 + | +LL | let _ = values.iter().any(|&v| v == "4"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&"4")` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:51:13 + | +LL | let _ = values.iter().any(|&v| v == 4 + 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&(4 + 1))` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:91:5 + | +LL | values.iter().any(|&v| v == 10) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&10)` + +error: using `contains()` instead of `iter().any()` is more efficient + --> tests/ui/manual_contains.rs:96:5 + | +LL | values.iter().any(|&v| v == 10) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `values.contains(&10)` + +error: aborting due to 12 previous errors + diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index 104941dc9937..bad8c307586c 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -1,4 +1,10 @@ -#![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] +#![allow( + unused, + clippy::needless_if, + clippy::suspicious_map, + clippy::iter_count, + clippy::manual_contains +)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 7f05f51b82e9..3dfb5194f404 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -1,4 +1,10 @@ -#![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] +#![allow( + unused, + clippy::needless_if, + clippy::suspicious_map, + clippy::iter_count, + clippy::manual_contains +)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index cba54f0af6bf..00745eb2923c 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -1,5 +1,5 @@ error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:9:29 + --> tests/ui/needless_collect.rs:15:29 | LL | let len = sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` @@ -8,109 +8,109 @@ LL | let len = sample.iter().collect::>().len(); = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:11:22 + --> tests/ui/needless_collect.rs:17:22 | LL | if sample.iter().collect::>().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:15:28 + --> tests/ui/needless_collect.rs:21:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:21:35 + --> tests/ui/needless_collect.rs:27:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:23:35 + --> tests/ui/needless_collect.rs:29:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:31:19 + --> tests/ui/needless_collect.rs:37:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:33:19 + --> tests/ui/needless_collect.rs:39:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:35:28 + --> tests/ui/needless_collect.rs:41:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:37:19 + --> tests/ui/needless_collect.rs:43:19 | LL | sample.iter().collect::>().contains(&&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:41:19 + --> tests/ui/needless_collect.rs:47:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:43:19 + --> tests/ui/needless_collect.rs:49:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:49:27 + --> tests/ui/needless_collect.rs:55:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:51:27 + --> tests/ui/needless_collect.rs:57:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:74:27 + --> tests/ui/needless_collect.rs:80:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:76:27 + --> tests/ui/needless_collect.rs:82:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:81:40 + --> tests/ui/needless_collect.rs:87:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:83:20 + --> tests/ui/needless_collect.rs:89:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:85:49 + --> tests/ui/needless_collect.rs:91:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:87:37 + --> tests/ui/needless_collect.rs:93:37 | LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index e6355bdf792f..847e5140d3e6 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] +#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] fn main() { diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index 8cc80f122f08..e976d12600cc 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] +#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] fn main() { diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index 6ab0593eecde..05e88b8528f1 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] +#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] fn main() { diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index 35094cdf2c07..caab816f2436 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] +#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] fn main() { From 1c0e120d8b6e78c8e18cce2f0068b85542567d9b Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Tue, 11 Feb 2025 17:53:37 +0900 Subject: [PATCH 107/161] apply `manual_contains` to Clippy sources --- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/casts/cast_sign_loss.rs | 4 ++-- clippy_lints/src/size_of_in_element_count.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index ee21f9379a52..58a011713a7b 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -555,7 +555,7 @@ impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> { _ => simplified.push(Bool::Not(Box::new(simple.clone()))), } let simple_negated = simple_negate(simple); - if simplified.iter().any(|s| *s == simple_negated) { + if simplified.contains(&simple_negated) { continue; } simplified.push(simple_negated); diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index 45045e58ac75..c8abf9dac9af 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -142,11 +142,11 @@ fn expr_sign<'cx, 'tcx>(cx: &LateContext<'cx>, mut expr: &'tcx Expr<'tcx>, ty: i expr = recv; } - if METHODS_POW.iter().any(|&name| method_name == name) + if METHODS_POW.contains(&method_name) && let [arg] = args { return pow_call_result_sign(cx, caller, arg); - } else if METHODS_RET_POSITIVE.iter().any(|&name| method_name == name) { + } else if METHODS_RET_POSITIVE.contains(&method_name) { return Sign::ZeroOrPositive; } } diff --git a/clippy_lints/src/size_of_in_element_count.rs b/clippy_lints/src/size_of_in_element_count.rs index b22c638fc363..dc19236011bd 100644 --- a/clippy_lints/src/size_of_in_element_count.rs +++ b/clippy_lints/src/size_of_in_element_count.rs @@ -99,7 +99,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( if let ExprKind::MethodCall(method_path, ptr_self, [.., count], _) = expr.kind // Find calls to copy_{from,to}{,_nonoverlapping} && let method_ident = method_path.ident.as_str() - && METHODS.iter().any(|m| *m == method_ident) + && METHODS.contains(&method_ident) // Get the pointee type && let ty::RawPtr(pointee_ty, _) = From a12d5a02851f05f1899e59b4ad2be41607f43132 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Sun, 16 Feb 2025 14:22:18 +0900 Subject: [PATCH 108/161] add suggestion example for `cast_possible_wrap` --- clippy_lints/src/casts/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 521bd394901a..78c0acf72b9a 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -134,8 +134,14 @@ declare_clippy_lint! { /// /// ### Example /// ```no_run - /// u32::MAX as i32; // will yield a value of `-1` + /// let _ = u32::MAX as i32; // will yield a value of `-1` /// ``` + /// + /// Use instead: + /// ```no_run + /// let _ = i32::try_from(u32::MAX).ok(); + /// ``` + /// #[clippy::version = "pre 1.29.0"] pub CAST_POSSIBLE_WRAP, pedantic, From 6dd477ad5ad0e83f60892425170f828c718f6332 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 16 Feb 2025 12:43:08 +0100 Subject: [PATCH 109/161] Add `--allow-no-vcs` to `cargo dev dogfood --fix` Some developers might prefer to use alternate VCS, such as Jujutsu, which are not detected by `cargo fix`. This forwards the `--allow-no-vcs` command line argument to `cargo fix`. --- clippy_dev/src/dogfood.rs | 7 ++++++- clippy_dev/src/main.rs | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clippy_dev/src/dogfood.rs b/clippy_dev/src/dogfood.rs index 75a4cbd2f92e..05fa24d8d4ee 100644 --- a/clippy_dev/src/dogfood.rs +++ b/clippy_dev/src/dogfood.rs @@ -4,7 +4,8 @@ use std::process::Command; /// # Panics /// /// Panics if unable to run the dogfood test -pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) { +#[allow(clippy::fn_params_excessive_bools)] +pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool, allow_no_vcs: bool) { let mut cmd = Command::new("cargo"); cmd.current_dir(clippy_project_root()) @@ -25,6 +26,10 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) { dogfood_args.push("--allow-staged"); } + if allow_no_vcs { + dogfood_args.push("--allow-no-vcs"); + } + cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" ")); exit_if_err(cmd.status()); diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 93a74ba83871..81a2ebd025be 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -17,7 +17,8 @@ fn main() { fix, allow_dirty, allow_staged, - } => dogfood::dogfood(fix, allow_dirty, allow_staged), + allow_no_vcs, + } => dogfood::dogfood(fix, allow_dirty, allow_staged, allow_no_vcs), DevCommand::Fmt { check, verbose } => fmt::run(check, verbose), DevCommand::UpdateLints { print_only, check } => { if print_only { @@ -106,6 +107,9 @@ enum DevCommand { #[arg(long, requires = "fix")] /// Fix code even if the working directory has staged changes allow_staged: bool, + #[arg(long, requires = "fix")] + /// Fix code even if a VCS was not detected + allow_no_vcs: bool, }, /// Run rustfmt on all projects and tests Fmt { From ef7e9fe70481dddf5a5b1dc8a915ee34596c0263 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Sun, 16 Feb 2025 13:38:59 +0100 Subject: [PATCH 110/161] Update version attribute for 1.85 clippy lints --- clippy_lints/src/attrs/mod.rs | 2 +- clippy_lints/src/casts/mod.rs | 2 +- clippy_lints/src/doc/mod.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 92efd1a4ddcd..e0aab8c95a8e 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -305,7 +305,7 @@ declare_clippy_lint! { /// header_version: u16 /// } /// ``` - #[clippy::version = "1.84.0"] + #[clippy::version = "1.85.0"] pub REPR_PACKED_WITHOUT_ABI, suspicious, "ensures that `repr(packed)` always comes with a qualified ABI" diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 521bd394901a..aab69ac59eaa 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -747,7 +747,7 @@ declare_clippy_lint! { /// t as *const T as usize /// } /// ``` - #[clippy::version = "1.81.0"] + #[clippy::version = "1.85.0"] pub AS_POINTER_UNDERSCORE, restriction, "detects `as *mut _` and `as *const _` conversion" diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 7b07d302d4f8..b5fb492b96c8 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -612,7 +612,7 @@ declare_clippy_lint! { /// ```no_run /// #![cfg_attr(doc, doc = include_str!("some_file.md"))] /// ``` - #[clippy::version = "1.84.0"] + #[clippy::version = "1.85.0"] pub DOC_INCLUDE_WITHOUT_CFG, restriction, "check if files included in documentation are behind `cfg(doc)`" @@ -638,7 +638,7 @@ declare_clippy_lint! { /// //! /// //! [link]: destination (for link reference definition) /// ``` - #[clippy::version = "1.84.0"] + #[clippy::version = "1.85.0"] pub DOC_NESTED_REFDEFS, suspicious, "link reference defined in list item or quote" From 3e637202321834f41f5f1dcda6816dceb535da78 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Sun, 16 Feb 2025 13:40:11 +0100 Subject: [PATCH 111/161] Changelog for Clippy 1.85 :parrot: --- CHANGELOG.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8695f66279..6f7e5ae92ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,53 @@ document. ## Unreleased / Beta / In Rust Nightly -[786fbd6d...master](https://github.com/rust-lang/rust-clippy/compare/786fbd6d...master) +[609cd310...master](https://github.com/rust-lang/rust-clippy/compare/609cd310...master) + +## Rust 1.85 + +Current stable, released 2025-02-20 + +[View all 72 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-11-15T19%3A31%3A08Z..2024-12-26T13%3A59%3A48Z+base%3Amaster) + +### New Lints + +* Added [`repr_packed_without_abi`] to `suspicious` + [#13398](https://github.com/rust-lang/rust-clippy/pull/13398) +* Added [`as_pointer_underscore`] to `restriction` + [#13251](https://github.com/rust-lang/rust-clippy/pull/13251) +* Added [`doc_nested_refdefs`] to `suspicious` + [#13707](https://github.com/rust-lang/rust-clippy/pull/13707) +* Added [`literal_string_with_formatting_args`] to `nursery` + [#13410](https://github.com/rust-lang/rust-clippy/pull/13410) +* Added [`doc_include_without_cfg`] to `restriction` + [#13625](https://github.com/rust-lang/rust-clippy/pull/13625) + +### Enhancements + +* [`indexing_slicing`]: Can now be allowed in tests using the [`allow-indexing-slicing-in-tests`] + configuration + [#13854](https://github.com/rust-lang/rust-clippy/pull/13854) +* [`if_let_mutex`]: disable lint from Edition 2024 since + [if_let_rescope](https://github.com/rust-lang/rust/issues/131154) was stabilized + [#13695](https://github.com/rust-lang/rust-clippy/pull/13695) +* [`format_in_format_args`], [`recursive_format_impl`], [`to_string_in_format_args`], + [`uninlined_format_args`], [`unused_format_specs`]: Can now support 3er party format macros + if they're marked with the `#[clippy::format_args]` attribute + [#9948](https://github.com/rust-lang/rust-clippy/pull/9948) + +### ICE Fixes + +* [`trait_duplication_in_bounds`]: fix ICE on duplicate type or constant bound + [#13722](https://github.com/rust-lang/rust-clippy/pull/13722) + +### Others + +* `clippy_utils` is now published to crates.io. Note that this crate is and will remain unstable. + [#13700](https://github.com/rust-lang/rust-clippy/pull/13700) ## Rust 1.84 -Current stable, released 2025-01-09 +Released 2025-01-09 [View all 84 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-10-03T21%3A23%3A58Z..2024-11-14T17%3A41%3A37Z+base%3Amaster) From f68f0b3e118de3a0ce15524413ef1a04b164242c Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sun, 16 Feb 2025 01:18:29 +0300 Subject: [PATCH 112/161] clippy: string_from_utf8_as_bytes: also detect inherent `from_utf8` --- clippy_lints/src/strings.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 6164a6191db0..4a5f143a2d34 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -2,8 +2,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_lang_item; use clippy_utils::{ - SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, is_path_diagnostic_item, - method_calls, peel_blocks, + SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, path_def_id, + peel_blocks, }; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; @@ -253,8 +253,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes { use rustc_ast::LitKind; if let ExprKind::Call(fun, [bytes_arg]) = e.kind - // Find std::str::converts::from_utf8 - && is_path_diagnostic_item(cx, fun, sym::str_from_utf8) + // Find `std::str::converts::from_utf8` or `std::primitive::str::from_utf8` + && let Some(sym::str_from_utf8 | sym::str_inherent_from_utf8) = + path_def_id(cx, fun).and_then(|id| cx.tcx.get_diagnostic_name(id)) // Find string::as_bytes && let ExprKind::AddrOf(BorrowKind::Ref, _, args) = bytes_arg.kind From 058ae80a55a97e6a077f5b464cebcae3c6b4ea56 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 16 Feb 2025 14:43:18 +0000 Subject: [PATCH 113/161] Add `cargo dev setup toolchain --standalone` --- clippy_dev/src/main.rs | 20 ++++++++++++++++++-- clippy_dev/src/setup/toolchain.rs | 27 +++++++++++++++++++++------ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 93a74ba83871..1c36de0ac61b 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -53,7 +53,12 @@ fn main() { setup::git_hook::install_hook(force_override); } }, - SetupSubcommand::Toolchain { force, release, name } => setup::toolchain::create(force, release, &name), + SetupSubcommand::Toolchain { + standalone, + force, + release, + name, + } => setup::toolchain::create(standalone, force, release, &name), SetupSubcommand::VscodeTasks { remove, force_override } => { if remove { setup::vscode::remove_tasks(); @@ -267,14 +272,25 @@ enum SetupSubcommand { force_override: bool, }, /// Install a rustup toolchain pointing to the local clippy build + /// + /// This creates a toolchain with symlinks pointing at + /// `target/.../{clippy-driver,cargo-clippy}`, rebuilds of the project will be reflected in the + /// created toolchain unless `--standalone` is passed Toolchain { + #[arg(long, short)] + /// Create a standalone toolchain by copying the clippy binaries instead + /// of symlinking them + /// + /// Use this for example to create a toolchain, make a small change and then make another + /// toolchain with a different name in order to easily compare the two + standalone: bool, #[arg(long, short)] /// Override an existing toolchain force: bool, #[arg(long, short)] /// Point to --release clippy binary release: bool, - #[arg(long, default_value = "clippy")] + #[arg(long, short, default_value = "clippy")] /// Name of the toolchain name: String, }, diff --git a/clippy_dev/src/setup/toolchain.rs b/clippy_dev/src/setup/toolchain.rs index 8d98c6c92d9d..2966629cf70a 100644 --- a/clippy_dev/src/setup/toolchain.rs +++ b/clippy_dev/src/setup/toolchain.rs @@ -3,11 +3,14 @@ use std::env::current_dir; use std::ffi::OsStr; use std::fs; use std::path::{Path, PathBuf}; +use std::process::Command; use walkdir::WalkDir; +use crate::utils::exit_if_err; + use super::verify_inside_clippy_dir; -pub fn create(force: bool, release: bool, name: &str) { +pub fn create(standalone: bool, force: bool, release: bool, name: &str) { if !verify_inside_clippy_dir() { return; } @@ -48,14 +51,22 @@ pub fn create(force: bool, release: bool, name: &str) { } } - symlink_bin("cargo-clippy", &dest, release); - symlink_bin("clippy-driver", &dest, release); + let status = Command::new("cargo") + .arg("build") + .args(release.then_some("--release")) + .status(); + exit_if_err(status); + + install_bin("cargo-clippy", &dest, standalone, release); + install_bin("clippy-driver", &dest, standalone, release); println!("Created toolchain {name}, use it in other projects with e.g. `cargo +{name} clippy`"); - println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes"); + if !standalone { + println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes"); + } } -fn symlink_bin(bin: &str, dest: &Path, release: bool) { +fn install_bin(bin: &str, dest: &Path, standalone: bool, release: bool) { #[cfg(windows)] use std::os::windows::fs::symlink_file as symlink; @@ -71,5 +82,9 @@ fn symlink_bin(bin: &str, dest: &Path, release: bool) { let mut dest = dest.to_path_buf(); dest.extend(["bin", &file_name]); - symlink(src, dest).unwrap(); + if standalone { + fs::copy(src, dest).unwrap(); + } else { + symlink(src, dest).unwrap(); + } } From d03ae8ba6ba0ec4f9c67f1982db8467d231fb646 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 16 Feb 2025 15:38:07 +0000 Subject: [PATCH 114/161] `ui_test` annotation cleanup --- tests/ui/asm_syntax_not_x86.rs | 6 +- tests/ui/attrs.rs | 5 +- tests/ui/attrs.stderr | 4 +- tests/ui/crashes/ice-5835.fixed | 10 + tests/ui/crashes/ice-5835.rs | 5 +- tests/ui/crashes/ice-5835.stderr | 20 +- tests/ui/doc/unbalanced_ticks.rs | 25 +-- tests/ui/doc/unbalanced_ticks.stderr | 172 ++++++++---------- tests/ui/doc_link_with_quotes.rs | 1 - tests/ui/doc_link_with_quotes.stderr | 4 +- .../ui/empty_line_after/doc_comments.1.fixed | 23 +-- .../ui/empty_line_after/doc_comments.2.fixed | 50 +++-- tests/ui/empty_line_after/doc_comments.rs | 23 +-- tests/ui/empty_line_after/doc_comments.stderr | 67 +++---- .../auxiliary/submodule.rs | 2 - .../ui/mixed_attributes_style/global_allow.rs | 5 +- .../global_allow.stderr | 20 -- .../mixed_attributes_style/mod_declaration.rs | 1 - .../mod_declaration.stderr | 22 +-- tests/ui/suspicious_else_formatting.rs | 3 +- tests/ui/suspicious_else_formatting.stderr | 16 +- tests/ui/unneeded_struct_pattern.fixed | 39 +++- tests/ui/unneeded_struct_pattern.rs | 24 ++- tests/ui/unneeded_struct_pattern.stderr | 152 ++++++++++------ 24 files changed, 342 insertions(+), 357 deletions(-) create mode 100644 tests/ui/crashes/ice-5835.fixed delete mode 100644 tests/ui/mixed_attributes_style/global_allow.stderr diff --git a/tests/ui/asm_syntax_not_x86.rs b/tests/ui/asm_syntax_not_x86.rs index 91fde12680cc..edcd5247f18c 100644 --- a/tests/ui/asm_syntax_not_x86.rs +++ b/tests/ui/asm_syntax_not_x86.rs @@ -1,5 +1,6 @@ //@ignore-target: i686 x86 //@needs-asm-support +//@check-pass #[warn(clippy::inline_asm_x86_intel_syntax)] #[warn(clippy::inline_asm_x86_att_syntax)] @@ -8,17 +9,12 @@ mod dont_warn { pub(super) unsafe fn use_asm() { asm!(""); - //~^ inline_asm_x86_intel_syntax asm!("", options()); - //~^ inline_asm_x86_intel_syntax asm!("", options(nostack)); - //~^ inline_asm_x86_intel_syntax } global_asm!(""); - //~^ inline_asm_x86_intel_syntax global_asm!("", options()); - //~^ inline_asm_x86_intel_syntax } fn main() { diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 583a0ada437d..f60c71837d5e 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -1,10 +1,9 @@ #![warn(clippy::inline_always, clippy::deprecated_semver)] -#![allow(clippy::assertions_on_constants, clippy::empty_line_after_outer_attr)] +#![allow(clippy::assertions_on_constants)] #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] //~^ inline_always - fn test_attr_lint() { assert!(true) } @@ -26,12 +25,10 @@ fn empty_and_false_positive_stmt() { #[deprecated(since = "forever")] //~^ deprecated_semver - pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] //~^ deprecated_semver - pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index a7fdceaba6f3..85b318cc0fdb 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -1,5 +1,5 @@ error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:27:14 + --> tests/ui/attrs.rs:26:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | #[deprecated(since = "forever")] = help: to override `-D warnings` add `#[allow(clippy::deprecated_semver)]` error: the since field must contain a semver-compliant version - --> tests/ui/attrs.rs:32:14 + --> tests/ui/attrs.rs:30:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ diff --git a/tests/ui/crashes/ice-5835.fixed b/tests/ui/crashes/ice-5835.fixed new file mode 100644 index 000000000000..e9c24b8e9f09 --- /dev/null +++ b/tests/ui/crashes/ice-5835.fixed @@ -0,0 +1,10 @@ +#[rustfmt::skip] +pub struct Foo { + //~v tabs_in_doc_comments + /// 位 + /// ^ 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-5835.rs b/tests/ui/crashes/ice-5835.rs index 149ba4786181..99858f45933e 100644 --- a/tests/ui/crashes/ice-5835.rs +++ b/tests/ui/crashes/ice-5835.rs @@ -1,10 +1,7 @@ #[rustfmt::skip] pub struct Foo { + //~v tabs_in_doc_comments /// 位 - //~^ tabs_in_doc_comments - //~| empty_line_after_doc_comments - - /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5835.stderr b/tests/ui/crashes/ice-5835.stderr index b342b43d0416..4ef91e4116b2 100644 --- a/tests/ui/crashes/ice-5835.stderr +++ b/tests/ui/crashes/ice-5835.stderr @@ -1,5 +1,5 @@ error: using tabs in doc comments is not recommended - --> tests/ui/crashes/ice-5835.rs:3:10 + --> tests/ui/crashes/ice-5835.rs:4:10 | LL | /// 位 | ^^^^ help: consider using four spaces per tab @@ -7,21 +7,5 @@ LL | /// 位 = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` -error: empty lines after doc comment - --> tests/ui/crashes/ice-5835.rs:3:5 - | -LL | / /// 位 -... | -LL | | - | |_^ - | - = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` - = help: if the empty lines are unintentional remove them -help: if the doc comment should not document `bar` comment it out - | -LL | // /// 位 - | ++ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 8adbb1f7f714..e8cfe44a6789 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -5,22 +5,20 @@ #![warn(clippy::doc_markdown)] /// This is a doc comment with `unbalanced_tick marks and several words that -//~^ empty_line_after_doc_comments - +//~^ doc_markdown /// 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. -//~^ empty_line_after_doc_comments - +//~^ doc_markdown /// /// This paragraph is fine and should_be linted normally. - +//~^ doc_markdown /// /// Double unbalanced backtick from ``here to here` should lint. - +//~^ doc_markdown /// /// Double balanced back ticks ``start end`` is fine. fn multiple_paragraphs() {} @@ -34,16 +32,15 @@ fn in_code_block() {} /// # `Fine` /// /// ## not_fine -//~^ empty_line_after_doc_comments - +//~^ doc_markdown /// /// ### `unbalanced - +//~^ doc_markdown /// /// - This `item has unbalanced tick marks - +//~^ doc_markdown /// - This item needs backticks_here - +//~^ doc_markdown fn other_markdown() {} #[rustfmt::skip] @@ -54,8 +51,7 @@ fn other_markdown() {} fn issue_7421() {} /// ` -//~^ empty_line_after_doc_comments - +//~^ doc_markdown fn escape_0() {} /// Escaped \` backticks don't count. @@ -65,8 +61,7 @@ fn escape_1() {} fn escape_2() {} /// Escaped \` ` backticks don't count, but unescaped backticks do. -//~^ empty_line_after_doc_comments - +//~^ doc_markdown fn escape_3() {} /// Backslashes ` \` within code blocks don't count. diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index 563d86376481..50324010e97f 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -1,112 +1,98 @@ -error: empty line after doc comment - --> tests/ui/doc/unbalanced_ticks.rs:7:1 +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:7:5 | -LL | / /// This is a doc comment with `unbalanced_tick marks and several words that +LL | /// This is a doc comment with `unbalanced_tick marks and several words that + | _____^ LL | | -LL | | - | |_^ -... -LL | fn main() {} - | --------- the comment documents this function +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`. + | |____________________________________^ | - = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` - = help: if the empty line is unintentional remove it -help: if the doc comment should not document `main` comment it out - | -LL | // /// This is a doc comment with `unbalanced_tick marks and several words that - | ++ + = help: a backtick may be missing a pair + = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` -error: empty lines after doc comment - --> tests/ui/doc/unbalanced_ticks.rs:15:1 +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:14:5 | -LL | / /// This paragraph has `unbalanced_tick marks and should stop_linting. -LL | | -LL | | -LL | | /// -... | -LL | | /// Double unbalanced backtick from ``here to here` should lint. -LL | | - | |_^ -... -LL | fn multiple_paragraphs() {} - | ------------------------ the comment documents this function - | - = help: if the empty lines are unintentional remove them -help: if the doc comment should not document `multiple_paragraphs` comment it out - | -LL ~ // /// This paragraph has `unbalanced_tick marks and should stop_linting. -LL | -LL | -LL ~ // /// -LL ~ // /// This paragraph is fine and should_be linted normally. -LL | -LL ~ // /// -LL ~ // /// Double unbalanced backtick from ``here to here` should lint. +LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = help: a backtick may be missing a pair -error: empty lines after doc comment - --> tests/ui/doc/unbalanced_ticks.rs:36:1 +error: item in documentation is missing backticks + --> tests/ui/doc/unbalanced_ticks.rs:17:32 | -LL | / /// ## not_fine -LL | | -LL | | -LL | | /// -... | -LL | | /// - This item needs backticks_here -LL | | - | |_^ -LL | fn other_markdown() {} - | ------------------- the comment documents this function +LL | /// This paragraph is fine and should_be linted normally. + | ^^^^^^^^^ | - = help: if the empty lines are unintentional remove them -help: if the doc comment should not document `other_markdown` comment it out - | -LL ~ // /// # `Fine` -LL ~ // /// -LL ~ // /// ## not_fine -LL | -LL | -LL ~ // /// -LL ~ // /// ### `unbalanced -LL | -LL ~ // /// -LL ~ // /// - This `item has unbalanced tick marks -LL | -LL ~ // /// - This item needs backticks_here +help: try | +LL | /// This paragraph is fine and `should_be` linted normally. + | ~~~~~~~~~~~ -error: empty line after doc comment - --> tests/ui/doc/unbalanced_ticks.rs:56:1 +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:20:5 | -LL | / /// ` -LL | | -LL | | - | |_^ -LL | fn escape_0() {} - | ------------- the comment documents this function +LL | /// Double unbalanced backtick from ``here to here` should lint. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if the empty line is unintentional remove it -help: if the doc comment should not document `escape_0` comment it out - | -LL | // /// ` - | ++ + = help: a backtick may be missing a pair -error: empty line after doc comment - --> tests/ui/doc/unbalanced_ticks.rs:67:1 +error: item in documentation is missing backticks + --> tests/ui/doc/unbalanced_ticks.rs:34:8 | -LL | / /// Escaped \` ` backticks don't count, but unescaped backticks do. -LL | | -LL | | - | |_^ -LL | fn escape_3() {} - | ------------- the comment documents this function +LL | /// ## not_fine + | ^^^^^^^^ | - = help: if the empty line is unintentional remove it -help: if the doc comment should not document `escape_3` comment it out +help: try | -LL | // /// Escaped \` ` backticks don't count, but unescaped backticks do. - | ++ +LL | /// ## `not_fine` + | ~~~~~~~~~~ -error: aborting due to 5 previous errors +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:37:5 + | +LL | /// ### `unbalanced + | ^^^^^^^^^^^^^^^ + | + = help: a backtick may be missing a pair + +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:40:5 + | +LL | /// - This `item has unbalanced tick marks + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: a backtick may be missing a pair + +error: item in documentation is missing backticks + --> tests/ui/doc/unbalanced_ticks.rs:42:23 + | +LL | /// - This item needs backticks_here + | ^^^^^^^^^^^^^^ + | +help: try + | +LL | /// - This item needs `backticks_here` + | ~~~~~~~~~~~~~~~~ + +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:53:5 + | +LL | /// ` + | ^ + | + = help: a backtick may be missing a pair + +error: backticks are unbalanced + --> tests/ui/doc/unbalanced_ticks.rs:63:5 + | +LL | /// Escaped \` ` backticks don't count, but unescaped backticks do. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: a backtick may be missing a pair + +error: aborting due to 10 previous errors diff --git a/tests/ui/doc_link_with_quotes.rs b/tests/ui/doc_link_with_quotes.rs index e2614e6b4318..0c0e273da6db 100644 --- a/tests/ui/doc_link_with_quotes.rs +++ b/tests/ui/doc_link_with_quotes.rs @@ -1,5 +1,4 @@ #![warn(clippy::doc_link_with_quotes)] -#![allow(clippy::empty_line_after_doc_comments)] fn main() { foo() diff --git a/tests/ui/doc_link_with_quotes.stderr b/tests/ui/doc_link_with_quotes.stderr index 1c1d8e0ffd52..47c60390310c 100644 --- a/tests/ui/doc_link_with_quotes.stderr +++ b/tests/ui/doc_link_with_quotes.stderr @@ -1,5 +1,5 @@ error: possible intra-doc link using quotes instead of backticks - --> tests/ui/doc_link_with_quotes.rs:8:12 + --> tests/ui/doc_link_with_quotes.rs:7:12 | LL | /// Calls ['bar'] uselessly | ^^^^^ @@ -8,7 +8,7 @@ LL | /// Calls ['bar'] uselessly = help: to override `-D warnings` add `#[allow(clippy::doc_link_with_quotes)]` error: possible intra-doc link using quotes instead of backticks - --> tests/ui/doc_link_with_quotes.rs:14:12 + --> tests/ui/doc_link_with_quotes.rs:13:12 | LL | /// Calls ["bar"] uselessly | ^^^^^ diff --git a/tests/ui/empty_line_after/doc_comments.1.fixed b/tests/ui/empty_line_after/doc_comments.1.fixed index c1a15f47ba10..fd6a94b6a80c 100644 --- a/tests/ui/empty_line_after/doc_comments.1.fixed +++ b/tests/ui/empty_line_after/doc_comments.1.fixed @@ -1,17 +1,16 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] +//~vvv empty_line_after_doc_comments /// Meant to be an /// inner doc comment /// for the crate -//~^ empty_line_after_doc_comments fn first_in_crate() {} mod m { - + //~vvv empty_line_after_doc_comments /// Meant to be an /// inner doc comment /// for the module - //~^ empty_line_after_doc_comments fn first_in_module() {} } @@ -22,14 +21,14 @@ mod some_mod { fn some_noop() {} } + //~v empty_line_after_doc_comments /// # Indented - //~^ empty_line_after_doc_comments /// Blank line fn indented() {} } +//~v empty_line_after_doc_comments /// This should produce a warning -//~^ empty_line_after_doc_comments fn with_doc_and_newline() {} // This should *NOT* produce a warning @@ -37,8 +36,8 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} +//~v empty_line_after_doc_comments /// This doc comment should produce a warning -//~^ empty_line_after_doc_comments /** This is also a doc comment and is part of the warning */ #[allow(non_camel_case_types)] @@ -47,15 +46,14 @@ fn with_no_newline_and_comment() {} fn three_attributes() {} mod misattributed { - + //~v empty_line_after_doc_comments /// docs for `old_code` - //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} + //~vv empty_line_after_doc_comments /// Docs /// for OldA - //~^ empty_line_after_doc_comments // struct OldA; /// Docs /// for OldB @@ -67,25 +65,24 @@ mod misattributed { } mod block_comments { - + //~v empty_line_after_doc_comments /** * Meant to be inner doc comment */ - //~^^^ empty_line_after_doc_comments fn first_in_module() {} + //~v empty_line_after_doc_comments /** * Docs for `old_code` */ - //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** * Docs for `new_code` */ fn new_code() {} + //~v empty_line_after_doc_comments /// Docs for `old_code2` - //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` fn new_code2() {} diff --git a/tests/ui/empty_line_after/doc_comments.2.fixed b/tests/ui/empty_line_after/doc_comments.2.fixed index abec7b54c632..7a57dcd92332 100644 --- a/tests/ui/empty_line_after/doc_comments.2.fixed +++ b/tests/ui/empty_line_after/doc_comments.2.fixed @@ -1,18 +1,17 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] -// /// Meant to be an -// /// inner doc comment -// /// for the crate -//~^ empty_line_after_doc_comments +//~vvv empty_line_after_doc_comments +//! Meant to be an +//! inner doc comment +//! for the crate fn first_in_crate() {} mod m { - - // /// Meant to be an - // /// inner doc comment - // /// for the module - //~^ empty_line_after_doc_comments + //~vvv empty_line_after_doc_comments + //! Meant to be an + //! inner doc comment + //! for the module fn first_in_module() {} } @@ -24,16 +23,15 @@ mod some_mod { fn some_noop() {} } - // /// # Indented - //~^ empty_line_after_doc_comments - + //~v empty_line_after_doc_comments + /// # Indented + /// /// Blank line fn indented() {} } -// /// This should produce a warning -//~^ empty_line_after_doc_comments - +//~v empty_line_after_doc_comments +/// This should produce a warning fn with_doc_and_newline() {} // This should *NOT* produce a warning @@ -41,28 +39,25 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} -// /// This doc comment should produce a warning -//~^ empty_line_after_doc_comments - -/* This is also a doc comment and is part of the warning +//~v empty_line_after_doc_comments +/// This doc comment should produce a warning +/** This is also a doc comment and is part of the warning */ - #[allow(non_camel_case_types)] #[allow(missing_docs)] #[allow(dead_code)] fn three_attributes() {} mod misattributed { - + //~v empty_line_after_doc_comments // /// docs for `old_code` - //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} + //~vv empty_line_after_doc_comments // /// Docs // /// for OldA - //~^ empty_line_after_doc_comments // struct OldA; // /// Docs @@ -76,18 +71,17 @@ mod misattributed { } mod block_comments { - - /* + //~v empty_line_after_doc_comments + /*! * Meant to be inner doc comment */ - //~^^^ empty_line_after_doc_comments fn first_in_module() {} + //~v empty_line_after_doc_comments /* * Docs for `old_code` */ - //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** @@ -95,8 +89,8 @@ mod block_comments { */ fn new_code() {} + //~v empty_line_after_doc_comments // /// Docs for `old_code2` - //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` diff --git a/tests/ui/empty_line_after/doc_comments.rs b/tests/ui/empty_line_after/doc_comments.rs index d225768f6125..1da761a5c3d5 100644 --- a/tests/ui/empty_line_after/doc_comments.rs +++ b/tests/ui/empty_line_after/doc_comments.rs @@ -1,18 +1,17 @@ #![warn(clippy::empty_line_after_outer_attr, clippy::empty_line_after_doc_comments)] +//~vvv empty_line_after_doc_comments /// Meant to be an /// inner doc comment /// for the crate -//~^ empty_line_after_doc_comments fn first_in_crate() {} mod m { - + //~vvv empty_line_after_doc_comments /// Meant to be an /// inner doc comment /// for the module - //~^ empty_line_after_doc_comments fn first_in_module() {} } @@ -24,15 +23,15 @@ mod some_mod { fn some_noop() {} } + //~v empty_line_after_doc_comments /// # Indented - //~^ empty_line_after_doc_comments /// Blank line fn indented() {} } +//~v empty_line_after_doc_comments /// This should produce a warning -//~^ empty_line_after_doc_comments fn with_doc_and_newline() {} @@ -41,8 +40,8 @@ fn with_doc_and_newline() {} /// some comment fn with_no_newline_and_comment() {} +//~v empty_line_after_doc_comments /// This doc comment should produce a warning -//~^ empty_line_after_doc_comments /** This is also a doc comment and is part of the warning */ @@ -53,16 +52,15 @@ fn with_no_newline_and_comment() {} fn three_attributes() {} mod misattributed { - + //~v empty_line_after_doc_comments /// docs for `old_code` - //~^ empty_line_after_doc_comments // fn old_code() {} fn new_code() {} + //~vv empty_line_after_doc_comments /// Docs /// for OldA - //~^ empty_line_after_doc_comments // struct OldA; /// Docs @@ -76,18 +74,17 @@ mod misattributed { } mod block_comments { - + //~v empty_line_after_doc_comments /** * Meant to be inner doc comment */ - //~^^^ empty_line_after_doc_comments fn first_in_module() {} + //~v empty_line_after_doc_comments /** * Docs for `old_code` */ - //~^^^ empty_line_after_doc_comments /* fn old_code() {} */ /** @@ -95,8 +92,8 @@ mod block_comments { */ fn new_code() {} + //~v empty_line_after_doc_comments /// Docs for `old_code2` - //~^ empty_line_after_doc_comments /* fn old_code2() {} */ /// Docs for `new_code2` diff --git a/tests/ui/empty_line_after/doc_comments.stderr b/tests/ui/empty_line_after/doc_comments.stderr index 9b627e8df1ff..c5d5f3d37594 100644 --- a/tests/ui/empty_line_after/doc_comments.stderr +++ b/tests/ui/empty_line_after/doc_comments.stderr @@ -1,8 +1,7 @@ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:5:1 + --> tests/ui/empty_line_after/doc_comments.rs:6:1 | LL | / /// for the crate -LL | | LL | | | |_^ LL | fn first_in_crate() {} @@ -11,36 +10,34 @@ LL | fn first_in_crate() {} = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` = help: if the empty line is unintentional remove it -help: if the doc comment should not document `first_in_crate` comment it out +help: if the comment should document the crate use an inner doc comment | -LL ~ // /// Meant to be an -LL ~ // /// inner doc comment -LL ~ // /// for the crate +LL ~ //! Meant to be an +LL ~ //! inner doc comment +LL ~ //! for the crate | error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:14:5 | LL | / /// for the module -LL | | LL | | | |_^ LL | fn first_in_module() {} | -------------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the doc comment should not document `first_in_module` comment it out +help: if the comment should document the parent module use an inner doc comment | -LL ~ // /// Meant to be an -LL ~ // /// inner doc comment -LL ~ // /// for the module +LL ~ //! Meant to be an +LL ~ //! inner doc comment +LL ~ //! for the module | error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:27:5 | LL | / /// # Indented -LL | | LL | | | |_^ LL | /// Blank line @@ -48,33 +45,27 @@ LL | fn indented() {} | ------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the doc comment should not document `indented` comment it out +help: if the documentation should include the empty line include it in the comment + | +LL | /// | -LL | // /// # Indented - | ++ error: empty line after doc comment --> tests/ui/empty_line_after/doc_comments.rs:34:1 | LL | / /// This should produce a warning -LL | | LL | | | |_^ LL | fn with_doc_and_newline() {} | ------------------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the doc comment should not document `with_doc_and_newline` comment it out - | -LL | // /// This should produce a warning - | ++ error: empty lines after doc comment --> tests/ui/empty_line_after/doc_comments.rs:44:1 | LL | / /// This doc comment should produce a warning LL | | -LL | | LL | | /** This is also a doc comment and is part of the warning LL | | */ LL | | @@ -84,19 +75,12 @@ LL | fn three_attributes() {} | --------------------- the comment documents this function | = help: if the empty lines are unintentional remove them -help: if the doc comment should not document `three_attributes` comment it out - | -LL ~ // /// This doc comment should produce a warning -LL | -LL | -LL ~ /* This is also a doc comment and is part of the warning - | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:57:5 + --> tests/ui/empty_line_after/doc_comments.rs:56:5 | LL | / /// docs for `old_code` -... | +LL | | // fn old_code() {} LL | | | |_^ LL | fn new_code() {} @@ -109,9 +93,12 @@ LL | // /// docs for `old_code` | ++ error: empty lines after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:64:5 + --> tests/ui/empty_line_after/doc_comments.rs:63:5 | LL | / /// for OldA +LL | | // struct OldA; +LL | | +LL | | /// Docs ... | LL | | | |_^ @@ -124,7 +111,6 @@ help: if the doc comment should not document `Multiple` comment it out | LL ~ // /// Docs LL ~ // /// for OldA -LL | LL | // struct OldA; LL | LL ~ // /// Docs @@ -132,31 +118,29 @@ LL ~ // /// for OldB | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:80:5 + --> tests/ui/empty_line_after/doc_comments.rs:78:5 | LL | / /** LL | | * Meant to be inner doc comment LL | | */ -LL | | LL | | | |_^ LL | fn first_in_module() {} | -------------------- the comment documents this function | = help: if the empty line is unintentional remove it -help: if the doc comment should not document `first_in_module` comment it out - | -LL - /** -LL + /* +help: if the comment should document the parent module use an inner doc comment | +LL | /*! + | ~ error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:87:5 + --> tests/ui/empty_line_after/doc_comments.rs:85:5 | LL | / /** LL | | * Docs for `old_code` LL | | */ -... | +LL | | /* fn old_code() {} */ LL | | | |_^ ... @@ -171,10 +155,9 @@ LL + /* | error: empty line after doc comment - --> tests/ui/empty_line_after/doc_comments.rs:98:5 + --> tests/ui/empty_line_after/doc_comments.rs:96:5 | LL | / /// Docs for `old_code2` -LL | | LL | | /* fn old_code2() {} */ LL | | | |_^ diff --git a/tests/ui/mixed_attributes_style/auxiliary/submodule.rs b/tests/ui/mixed_attributes_style/auxiliary/submodule.rs index 61615c5d3a64..43d22940415f 100644 --- a/tests/ui/mixed_attributes_style/auxiliary/submodule.rs +++ b/tests/ui/mixed_attributes_style/auxiliary/submodule.rs @@ -3,8 +3,6 @@ #![allow(dead_code)] #[allow(unused)] -//~^ mixed_attributes_style - mod foo { #![allow(dead_code)] } diff --git a/tests/ui/mixed_attributes_style/global_allow.rs b/tests/ui/mixed_attributes_style/global_allow.rs index c68a5462afea..19a45e720a60 100644 --- a/tests/ui/mixed_attributes_style/global_allow.rs +++ b/tests/ui/mixed_attributes_style/global_allow.rs @@ -1,6 +1,5 @@ -//@error-in-other-file: -//@no-rustfix -// issue 12436 +// https://github.com/rust-lang/rust-clippy/issues/12436 +//@check-pass #![allow(clippy::mixed_attributes_style)] #[path = "auxiliary/submodule.rs"] diff --git a/tests/ui/mixed_attributes_style/global_allow.stderr b/tests/ui/mixed_attributes_style/global_allow.stderr deleted file mode 100644 index 5fc1d2ac0c3e..000000000000 --- a/tests/ui/mixed_attributes_style/global_allow.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: empty line after outer attribute - --> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1 - | -LL | / #[allow(unused)] -LL | | -LL | | - | |_^ -LL | mod foo { - | ------- the attribute applies to this module - | - = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` - = help: if the empty line is unintentional remove it -help: if the attribute should apply to the parent module use an inner attribute - | -LL | #![allow(unused)] - | + - -error: aborting due to 1 previous error - diff --git a/tests/ui/mixed_attributes_style/mod_declaration.rs b/tests/ui/mixed_attributes_style/mod_declaration.rs index f2aad9a21e99..8cef6a80048a 100644 --- a/tests/ui/mixed_attributes_style/mod_declaration.rs +++ b/tests/ui/mixed_attributes_style/mod_declaration.rs @@ -1,4 +1,3 @@ -//@error-in-other-file: empty line after outer attribute //@error-in-other-file: item has both inner and outer attributes //@no-rustfix #[path = "auxiliary/submodule.rs"] // don't lint. diff --git a/tests/ui/mixed_attributes_style/mod_declaration.stderr b/tests/ui/mixed_attributes_style/mod_declaration.stderr index 13ec97fbc1af..1239742a05b7 100644 --- a/tests/ui/mixed_attributes_style/mod_declaration.stderr +++ b/tests/ui/mixed_attributes_style/mod_declaration.stderr @@ -2,8 +2,6 @@ error: item has both inner and outer attributes --> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1 | LL | / #[allow(unused)] -LL | | -LL | | LL | | mod foo { LL | | #![allow(dead_code)] | |________________________^ @@ -11,23 +9,5 @@ LL | | #![allow(dead_code)] = note: `-D clippy::mixed-attributes-style` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]` -error: empty line after outer attribute - --> tests/ui/mixed_attributes_style/auxiliary/submodule.rs:5:1 - | -LL | / #[allow(unused)] -LL | | -LL | | - | |_^ -LL | mod foo { - | ------- the attribute applies to this module - | - = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` - = help: if the empty line is unintentional remove it -help: if the attribute should apply to the parent module use an inner attribute - | -LL | #![allow(unused)] - | + - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index 7e57684bd437..28a3b551116d 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -99,10 +99,11 @@ fn main() { // Almost Allman style braces. Lint these. if foo() { } + else { - } + //~^^^^^ suspicious_else_formatting if foo() { } diff --git a/tests/ui/suspicious_else_formatting.stderr b/tests/ui/suspicious_else_formatting.stderr index cf2788b67d07..affd20b22d9c 100644 --- a/tests/ui/suspicious_else_formatting.stderr +++ b/tests/ui/suspicious_else_formatting.stderr @@ -64,7 +64,19 @@ LL | | if foo() { // the span of the above error should continue here = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` error: this is an `else {..}` but the formatting might hide it - --> tests/ui/suspicious_else_formatting.rs:108:6 + --> tests/ui/suspicious_else_formatting.rs:101:6 + | +LL | } + | ______^ +LL | | +LL | | else +LL | | { + | |____^ + | + = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` + +error: this is an `else {..}` but the formatting might hide it + --> tests/ui/suspicious_else_formatting.rs:109:6 | LL | } | ______^ @@ -75,5 +87,5 @@ LL | | { | = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/unneeded_struct_pattern.fixed b/tests/ui/unneeded_struct_pattern.fixed index 1fcaa29c51f0..665ab98913be 100644 --- a/tests/ui/unneeded_struct_pattern.fixed +++ b/tests/ui/unneeded_struct_pattern.fixed @@ -2,8 +2,7 @@ #![allow( clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::redundant_pattern_matching, - clippy::no_effect + clippy::redundant_pattern_matching )] #![warn(clippy::unneeded_struct_pattern)] @@ -65,19 +64,30 @@ fn main() { match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields {} => 0, + Custom::NoBrackets => 0, //~ unneeded_struct_pattern + Custom::NoBracketsNonExhaustive => 0, //~ unneeded_struct_pattern _ => 0, }; match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields { .. } => 0, + Custom::NoBrackets => 0, //~ unneeded_struct_pattern + Custom::NoBracketsNonExhaustive => 0, //~ unneeded_struct_pattern _ => 0, }; - 0; - //~^^^ match_single_binding + match Custom::Init { + Custom::NoBrackets if true => 0, //~ unneeded_struct_pattern + _ => 0, + }; - 0; + match Custom::Init { + Custom::NoBrackets | Custom::NoBracketsNonExhaustive => 0, + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern + _ => 0, + }; if let Custom::HasFields { field: value } = Custom::Init { noop(); @@ -121,6 +131,7 @@ fn main() { let Custom::HasBracketsNoFields { .. } = Custom::Init else { panic!() }; + let Custom::NoBrackets = Custom::Init else { panic!() }; //~ unneeded_struct_pattern let Custom::NoBrackets = Custom::Init else { //~^ unneeded_struct_pattern @@ -138,6 +149,12 @@ fn main() { enum Refutable { Variant, } + + fn pat_in_fn_param_1(Refutable::Variant: Refutable) {} //~ unneeded_struct_pattern + fn pat_in_fn_param_2(Refutable::Variant: Refutable) {} //~ unneeded_struct_pattern + + for Refutable::Variant in [] {} //~ unneeded_struct_pattern + for Refutable::Variant in [] {} //~ unneeded_struct_pattern } fn external_crate() { @@ -149,9 +166,17 @@ fn external_crate() { _ => 0, }; - 0; + match ExhaustiveUnit { + // Exhaustive variant + ExhaustiveUnit => 0, //~ unneeded_struct_pattern + _ => 0, + }; - 0; + match ExhaustiveUnit { + // Exhaustive variant + ExhaustiveUnit => 0, //~ unneeded_struct_pattern + _ => 0, + }; match ExhaustiveUnit { ExhaustiveUnit => 0, diff --git a/tests/ui/unneeded_struct_pattern.rs b/tests/ui/unneeded_struct_pattern.rs index e51311afd5f8..7cadb6c7fbb5 100644 --- a/tests/ui/unneeded_struct_pattern.rs +++ b/tests/ui/unneeded_struct_pattern.rs @@ -2,8 +2,7 @@ #![allow( clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::redundant_pattern_matching, - clippy::no_effect + clippy::redundant_pattern_matching )] #![warn(clippy::unneeded_struct_pattern)] @@ -65,22 +64,28 @@ fn main() { match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields {} => 0, + Custom::NoBrackets {} => 0, //~ unneeded_struct_pattern + Custom::NoBracketsNonExhaustive {} => 0, //~ unneeded_struct_pattern _ => 0, }; match Custom::Init { Custom::HasFields { field: value } => value, Custom::HasBracketsNoFields { .. } => 0, + Custom::NoBrackets { .. } => 0, //~ unneeded_struct_pattern + Custom::NoBracketsNonExhaustive { .. } => 0, //~ unneeded_struct_pattern _ => 0, }; match Custom::Init { + Custom::NoBrackets {} if true => 0, //~ unneeded_struct_pattern _ => 0, }; - //~^^^ match_single_binding match Custom::Init { - //~^ match_single_binding + Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, + //~^ unneeded_struct_pattern + //~| unneeded_struct_pattern _ => 0, }; @@ -126,6 +131,7 @@ fn main() { let Custom::HasBracketsNoFields { .. } = Custom::Init else { panic!() }; + let Custom::NoBrackets {} = Custom::Init else { panic!() }; //~ unneeded_struct_pattern let Custom::NoBrackets { .. } = Custom::Init else { //~^ unneeded_struct_pattern @@ -143,6 +149,12 @@ fn main() { enum Refutable { Variant, } + + fn pat_in_fn_param_1(Refutable::Variant {}: Refutable) {} //~ unneeded_struct_pattern + fn pat_in_fn_param_2(Refutable::Variant { .. }: Refutable) {} //~ unneeded_struct_pattern + + for Refutable::Variant {} in [] {} //~ unneeded_struct_pattern + for Refutable::Variant { .. } in [] {} //~ unneeded_struct_pattern } fn external_crate() { @@ -155,14 +167,14 @@ fn external_crate() { }; match ExhaustiveUnit { - //~^ match_single_binding // Exhaustive variant + ExhaustiveUnit { .. } => 0, //~ unneeded_struct_pattern _ => 0, }; match ExhaustiveUnit { - //~^ match_single_binding // Exhaustive variant + ExhaustiveUnit {} => 0, //~ unneeded_struct_pattern _ => 0, }; diff --git a/tests/ui/unneeded_struct_pattern.stderr b/tests/ui/unneeded_struct_pattern.stderr index 5630795823c4..7c0c3c9e4462 100644 --- a/tests/ui/unneeded_struct_pattern.stderr +++ b/tests/ui/unneeded_struct_pattern.stderr @@ -1,5 +1,5 @@ error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:18:13 + --> tests/ui/unneeded_struct_pattern.rs:17:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern @@ -8,152 +8,196 @@ LL | None {} => 0, = help: to override `-D warnings` add `#[allow(clippy::unneeded_struct_pattern)]` error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:24:13 + --> tests/ui/unneeded_struct_pattern.rs:23:13 | LL | None { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:35:18 + --> tests/ui/unneeded_struct_pattern.rs:34:18 | LL | Some(None {}) => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:37:13 + --> tests/ui/unneeded_struct_pattern.rs:36:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:41:16 + --> tests/ui/unneeded_struct_pattern.rs:40:16 | LL | if let None {} = Some(0) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:43:16 + --> tests/ui/unneeded_struct_pattern.rs:42:16 | LL | if let None { .. } = Some(0) {} | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:45:21 + --> tests/ui/unneeded_struct_pattern.rs:44:21 | LL | if let Some(None {}) = Some(Some(0)) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:47:13 + --> tests/ui/unneeded_struct_pattern.rs:46:13 | LL | let None {} = Some(0) else { panic!() }; | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:49:13 + --> tests/ui/unneeded_struct_pattern.rs:48:13 | LL | let None { .. } = Some(0) else { panic!() }; | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:51:18 + --> tests/ui/unneeded_struct_pattern.rs:50:18 | LL | let Some(None {}) = Some(Some(0)) else { panic!() }; | ^^^ help: remove the struct pattern -error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:77:5 +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:67:27 | -LL | / match Custom::Init { -LL | | _ => 0, -LL | | }; - | |_____^ help: consider using the match body instead: `0` - | - = note: `-D clippy::match-single-binding` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` - -error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:82:5 - | -LL | / match Custom::Init { -LL | | -LL | | _ => 0, -LL | | }; - | |_____^ help: consider using the match body instead: `0` +LL | Custom::NoBrackets {} => 0, + | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:96:30 + --> tests/ui/unneeded_struct_pattern.rs:68:40 + | +LL | Custom::NoBracketsNonExhaustive {} => 0, + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:75:27 + | +LL | Custom::NoBrackets { .. } => 0, + | ^^^^^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:76:40 + | +LL | Custom::NoBracketsNonExhaustive { .. } => 0, + | ^^^^^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:81:27 + | +LL | Custom::NoBrackets {} if true => 0, + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:86:27 + | +LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:86:64 + | +LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:101:30 | LL | if let Custom::NoBrackets {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:100:30 + --> tests/ui/unneeded_struct_pattern.rs:105:30 | LL | if let Custom::NoBrackets { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:104:30 + --> tests/ui/unneeded_struct_pattern.rs:109:30 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:104:67 + --> tests/ui/unneeded_struct_pattern.rs:109:67 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:109:43 + --> tests/ui/unneeded_struct_pattern.rs:114:43 | LL | if let Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:113:43 + --> tests/ui/unneeded_struct_pattern.rs:118:43 | LL | if let Custom::NoBracketsNonExhaustive { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:130:27 + --> tests/ui/unneeded_struct_pattern.rs:134:27 + | +LL | let Custom::NoBrackets {} = Custom::Init else { panic!() }; + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:136:27 | LL | let Custom::NoBrackets { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:134:40 + --> tests/ui/unneeded_struct_pattern.rs:140:40 | LL | let Custom::NoBracketsNonExhaustive {} = Custom::Init else { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:138:40 + --> tests/ui/unneeded_struct_pattern.rs:144:40 | LL | let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern -error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:157:5 +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:153:44 | -LL | / match ExhaustiveUnit { -LL | | -LL | | // Exhaustive variant -LL | | _ => 0, -LL | | }; - | |_____^ help: consider using the match body instead: `0` +LL | fn pat_in_fn_param_1(Refutable::Variant {}: Refutable) {} + | ^^^ help: remove the struct pattern -error: this match could be replaced by its body itself - --> tests/ui/unneeded_struct_pattern.rs:163:5 +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:154:44 | -LL | / match ExhaustiveUnit { -LL | | -LL | | // Exhaustive variant -LL | | _ => 0, -LL | | }; - | |_____^ help: consider using the match body instead: `0` +LL | fn pat_in_fn_param_2(Refutable::Variant { .. }: Refutable) {} + | ^^^^^^^ help: remove the struct pattern -error: aborting due to 23 previous errors +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:156:27 + | +LL | for Refutable::Variant {} in [] {} + | ^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:157:27 + | +LL | for Refutable::Variant { .. } in [] {} + | ^^^^^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:171:23 + | +LL | ExhaustiveUnit { .. } => 0, + | ^^^^^^^ help: remove the struct pattern + +error: struct pattern is not needed for a unit variant + --> tests/ui/unneeded_struct_pattern.rs:177:23 + | +LL | ExhaustiveUnit {} => 0, + | ^^^ help: remove the struct pattern + +error: aborting due to 33 previous errors From 8cf9eea5b3640fc119db11a70107ef09b44a5082 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Feb 2025 10:45:49 +1100 Subject: [PATCH 115/161] Move some `Map` methods onto `TyCtxt`. The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`. --- .../src/arbitrary_source_item_ordering.rs | 2 +- clippy_lints/src/async_yields_async.rs | 4 ++-- clippy_lints/src/attrs/utils.rs | 6 ++--- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/collection_is_never_read.rs | 2 +- clippy_lints/src/derivable_impls.rs | 2 +- clippy_lints/src/doc/missing_headers.rs | 2 +- clippy_lints/src/doc/mod.rs | 4 ++-- clippy_lints/src/empty_drop.rs | 2 +- clippy_lints/src/eta_reduction.rs | 2 +- .../src/extra_unused_type_parameters.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 4 ++-- clippy_lints/src/format_impl.rs | 2 +- clippy_lints/src/from_over_into.rs | 4 ++-- .../src/functions/impl_trait_in_params.rs | 2 +- clippy_lints/src/functions/must_use.rs | 6 ++--- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/items_after_statements.rs | 2 +- clippy_lints/src/items_after_test_module.rs | 4 ++-- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/lines_filter_map_ok.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 2 +- .../src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/manual_option_as_slice.rs | 2 +- clippy_lints/src/manual_retain.rs | 6 ++--- clippy_lints/src/map_unit_fn.rs | 2 +- .../src/methods/bind_instead_of_map.rs | 2 +- clippy_lints/src/methods/bytecount.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 6 ++--- .../src/methods/filter_map_bool_then.rs | 4 ++-- clippy_lints/src/methods/format_collect.rs | 2 +- clippy_lints/src/methods/iter_filter.rs | 2 +- clippy_lints/src/methods/iter_kv_map.rs | 2 +- .../src/methods/iter_overeager_cloned.rs | 2 +- clippy_lints/src/methods/manual_inspect.rs | 4 ++-- clippy_lints/src/methods/manual_ok_or.rs | 2 +- clippy_lints/src/methods/map_clone.rs | 2 +- clippy_lints/src/methods/map_err_ignore.rs | 2 +- .../map_with_unused_argument_over_ranges.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- .../methods/needless_character_iteration.rs | 2 +- clippy_lints/src/methods/needless_collect.rs | 2 +- .../src/methods/obfuscated_if_else.rs | 2 +- .../src/methods/option_as_ref_deref.rs | 2 +- .../src/methods/option_map_or_none.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 2 +- .../src/methods/result_map_or_else_none.rs | 2 +- clippy_lints/src/methods/return_and_then.rs | 2 +- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/suspicious_map.rs | 2 +- .../src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- .../src/methods/unnecessary_lazy_eval.rs | 2 +- .../src/methods/unnecessary_literal_unwrap.rs | 2 +- .../src/methods/unnecessary_map_or.rs | 2 +- .../methods/unnecessary_result_map_or_else.rs | 2 +- .../src/methods/unnecessary_sort_by.rs | 2 +- .../src/methods/unnecessary_to_owned.rs | 2 +- .../src/methods/unused_enumerate_index.rs | 2 +- clippy_lints/src/methods/useless_asref.rs | 2 +- clippy_lints/src/missing_fields_in_debug.rs | 4 ++-- clippy_lints/src/missing_inline.rs | 4 ++-- clippy_lints/src/needless_for_each.rs | 2 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 3 +-- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/non_canonical_impls.rs | 4 ++-- clippy_lints/src/non_std_lazy_statics.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/redundant_async_block.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/same_name_method.rs | 4 ++-- clippy_lints/src/string_patterns.rs | 2 +- clippy_lints/src/suspicious_trait_impl.rs | 2 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/types/borrowed_box.rs | 4 ++-- clippy_lints/src/unconditional_recursion.rs | 4 ++-- .../src/undocumented_unsafe_blocks.rs | 6 ++--- clippy_lints/src/unit_return_expecting_ord.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/unused_self.rs | 2 +- clippy_lints/src/unwrap_in_result.rs | 2 +- clippy_lints/src/utils/author.rs | 4 ++-- .../utils/internal_lints/collapsible_calls.rs | 2 +- .../src/utils/internal_lints/invalid_paths.rs | 2 +- .../internal_lints/lint_without_lint_pass.rs | 2 +- clippy_lints/src/zero_repeat_side_effects.rs | 3 +-- clippy_utils/src/check_proc_macro.rs | 2 +- clippy_utils/src/consts.rs | 8 +++---- clippy_utils/src/hir_utils.rs | 8 +++---- clippy_utils/src/lib.rs | 22 +++++++++---------- clippy_utils/src/ptr.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/visitors.rs | 4 ++-- tests/ui/author/blocks.stdout | 4 ++-- tests/ui/author/macro_in_closure.stdout | 2 +- tests/ui/author/repeat.stdout | 2 +- 102 files changed, 146 insertions(+), 150 deletions(-) diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index f519a65fc272..aff40fa846be 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -338,7 +338,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { return; } - let items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id)); + let items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id)); // Iterates over the items within a module. // diff --git a/clippy_lints/src/async_yields_async.rs b/clippy_lints/src/async_yields_async.rs index eeaa3de3725f..013819b0da8a 100644 --- a/clippy_lints/src/async_yields_async.rs +++ b/clippy_lints/src/async_yields_async.rs @@ -60,12 +60,12 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { // XXXkhuey maybe we should? return; }, - CoroutineSource::Block => cx.tcx.hir().body(*body_id).value, + CoroutineSource::Block => cx.tcx.hir_body(*body_id).value, CoroutineSource::Closure => { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - let async_closure_body = cx.tcx.hir().body(*body_id).value; + let async_closure_body = cx.tcx.hir_body(*body_id).value; let ExprKind::Block(block, _) = async_closure_body.kind else { return; }; diff --git a/clippy_lints/src/attrs/utils.rs b/clippy_lints/src/attrs/utils.rs index 152e6ec70a18..a667649f7343 100644 --- a/clippy_lints/src/attrs/utils.rs +++ b/clippy_lints/src/attrs/utils.rs @@ -22,7 +22,7 @@ pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if let ItemKind::Fn { body: eid, .. } = item.kind { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value) } else { true } @@ -30,7 +30,7 @@ pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { pub(super) fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool { match item.kind { - ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value), + ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value), _ => false, } } @@ -39,7 +39,7 @@ pub(super) fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> b match item.kind { TraitItemKind::Fn(_, TraitFn::Required(_)) => true, TraitItemKind::Fn(_, TraitFn::Provided(eid)) => { - is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) + is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value) }, _ => false, } diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index f8c30d1c881d..f30f16997d76 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -452,7 +452,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti }) }, ExprKind::Closure(closure) => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); let params = body .params .iter() diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs index 8276e53648c0..1279be34ed8f 100644 --- a/clippy_lints/src/collection_is_never_read.rs +++ b/clippy_lints/src/collection_is_never_read.rs @@ -118,7 +118,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI let is_read_in_closure_arg = args.iter().any(|arg| { if let ExprKind::Closure(closure) = arg.kind // To keep things simple, we only check the first param to see if its read. - && let Body { params: [param, ..], value } = cx.tcx.hir().body(closure.body) + && let Body { params: [param, ..], value } = cx.tcx.hir_body(closure.body) { !has_no_read_access(cx, param.hir_id, *value) } else { diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 9569081ad088..bb445e0155f6 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -197,7 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let impl_item_hir = child.id.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind - && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) + && let Body { value: func_expr, .. } = cx.tcx.hir_body(*b) && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let attrs = cx.tcx.hir().attrs(item.hir_id()) && !attrs.iter().any(|attr| attr.doc_str().is_some()) diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index 8e2af6bf14a6..d1ffbb6ffe25 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -68,7 +68,7 @@ pub fn check( } else if let Some(body_id) = body_id && let Some(future) = cx.tcx.lang_items().future_trait() && let typeck = cx.tcx.typeck_body(body_id) - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) && let ret_ty = typeck.expr_ty(body.value) && implements_trait_with_env( cx.tcx, diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 42e1f7fd950d..36baf492a540 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -597,7 +597,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || item.span.in_external_macro(cx.tcx.sess.source_map())) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let panic_info = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(item.owner_id), body.value); missing_headers::check( @@ -649,7 +649,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { && !impl_item.span.in_external_macro(cx.tcx.sess.source_map()) && !is_trait_impl_item(cx, impl_item.hir_id()) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let panic_span = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(impl_item.owner_id), body.value); missing_headers::check( diff --git a/clippy_lints/src/empty_drop.rs b/clippy_lints/src/empty_drop.rs index 10a84b1b2ff2..d557a36c7ac2 100644 --- a/clippy_lints/src/empty_drop.rs +++ b/clippy_lints/src/empty_drop.rs @@ -44,7 +44,7 @@ impl LateLintPass<'_> for EmptyDrop { && let impl_item_hir = child.id.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind - && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) + && let Body { value: func_expr, .. } = cx.tcx.hir_body(*b) && let func_expr = peel_blocks(func_expr) && let ExprKind::Block(block, _) = func_expr.kind && block.stmts.is_empty() diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index ae3acc1c4b19..d1782d582f4d 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -97,7 +97,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx && matches!(c.fn_decl.output, FnRetTy::DefaultReturn(_)) && !expr.span.from_expansion() { - cx.tcx.hir().body(c.body) + cx.tcx.hir_body(c.body) } else { return; }; diff --git a/clippy_lints/src/extra_unused_type_parameters.rs b/clippy_lints/src/extra_unused_type_parameters.rs index 5d93aceb33ff..6ccea22e191c 100644 --- a/clippy_lints/src/extra_unused_type_parameters.rs +++ b/clippy_lints/src/extra_unused_type_parameters.rs @@ -247,7 +247,7 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> { } fn is_empty_body(cx: &LateContext<'_>, body: BodyId) -> bool { - matches!(cx.tcx.hir().body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none()) + matches!(cx.tcx.hir_body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none()) } impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters { diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index f822432cce63..f67d38d932b9 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -98,10 +98,10 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl for impl_item in impl_items { if impl_item.ident.name == sym::from - && let ImplItemKind::Fn(_, body_id) = cx.tcx.hir().impl_item(impl_item.id).kind + && let ImplItemKind::Fn(_, body_id) = cx.tcx.hir_impl_item(impl_item.id).kind { // check the body for `begin_panic` or `unwrap` - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let mut fpu = FindPanicUnwrap { lcx: cx, typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id), diff --git a/clippy_lints/src/format_impl.rs b/clippy_lints/src/format_impl.rs index 5619cb0ab1b0..ff75fcf2b417 100644 --- a/clippy_lints/src/format_impl.rs +++ b/clippy_lints/src/format_impl.rs @@ -262,7 +262,7 @@ fn is_format_trait_impl(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) -> Optio && let Some(name) = cx.tcx.get_diagnostic_name(did) && matches!(name, sym::Debug | sym::Display) { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let formatter_name = body .params .get(1) diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 9a73d0c0993f..167377972db9 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -175,11 +175,11 @@ fn convert_to_from( // bad suggestion/fix. return None; } - let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); + let impl_item = cx.tcx.hir_impl_item(impl_item_ref.id); let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else { return None; }; - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let [input] = body.params else { return None }; let PatKind::Binding(.., self_ident, None) = input.pat.kind else { return None; diff --git a/clippy_lints/src/functions/impl_trait_in_params.rs b/clippy_lints/src/functions/impl_trait_in_params.rs index 752dbc0db4db..6d1c55d06938 100644 --- a/clippy_lints/src/functions/impl_trait_in_params.rs +++ b/clippy_lints/src/functions/impl_trait_in_params.rs @@ -56,7 +56,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { && let hir::ItemKind::Impl(impl_) = item.kind && let hir::Impl { of_trait, .. } = *impl_ && of_trait.is_none() - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) && cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, impl_item.hir_id()) { diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index e480805cac2f..e6e3ea59a9f6 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -37,7 +37,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> check_must_use_candidate( cx, sig.decl, - cx.tcx.hir().body(*body_id), + cx.tcx.hir_body(*body_id), item.span, item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), @@ -59,7 +59,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp check_must_use_candidate( cx, sig.decl, - cx.tcx.hir().body(*body_id), + cx.tcx.hir_body(*body_id), item.span, item.owner_id, item.span.with_hi(sig.decl.output.span().hi()), @@ -79,7 +79,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr if let Some(attr) = attr { check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig); } else if let hir::TraitFn::Provided(eid) = *eid { - let body = cx.tcx.hir().body(eid); + let body = cx.tcx.hir_body(eid); if attr.is_none() && is_public && !is_proc_macro(attrs) { check_must_use_candidate( cx, diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 8a74951ef63e..906bbd006d46 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -30,7 +30,7 @@ pub(super) fn check_fn<'tcx>( pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) { if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind { - let body = cx.tcx.hir().body(eid); + let body = cx.tcx.hir_body(eid); check_raw_ptr(cx, sig.header.safety(), sig.decl, body, item.owner_id.def_id); } } diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 47a5c19215b8..1b39663f4f81 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { }); let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - for item in impl_.items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { + for item in impl_.items.iter().map(|item| cx.tcx.hir_impl_item(item.id)) { ctr_vis.visit_impl_item(item); } @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { body: body_id, .. } => { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); for ty in sig.decl.inputs { let mut vis = ImplicitHasherTypeVisitor::new(cx); diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index d3aade31f14f..3cb47d8ef919 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { } if method.ident.name.as_str() == "flat_map" && args.len() == 1 { if let ExprKind::Closure(&Closure { body, .. }) = args[0].kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); return is_infinite(cx, body.value); } } diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index f5ad79a00279..021d43cefdda 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -59,7 +59,7 @@ impl LateLintPass<'_> for ItemsAfterStatements { .iter() .skip_while(|stmt| matches!(stmt.kind, StmtKind::Item(..))) .filter_map(|stmt| match stmt.kind { - StmtKind::Item(id) => Some(cx.tcx.hir().item(id)), + StmtKind::Item(id) => Some(cx.tcx.hir_item(id)), _ => None, }) // Ignore macros since they can only see previously defined locals. diff --git a/clippy_lints/src/items_after_test_module.rs b/clippy_lints/src/items_after_test_module.rs index 1ac549b74ac6..9df044f25eb7 100644 --- a/clippy_lints/src/items_after_test_module.rs +++ b/clippy_lints/src/items_after_test_module.rs @@ -58,7 +58,7 @@ fn cfg_test_module<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool { impl LateLintPass<'_> for ItemsAfterTestModule { fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) { - let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id)); + let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id)); let Some((mod_pos, test_mod)) = items.by_ref().enumerate().find(|(_, item)| cfg_test_module(cx, item)) else { return; @@ -91,7 +91,7 @@ impl LateLintPass<'_> for ItemsAfterTestModule { "items after a test module", |diag| { if let Some(prev) = mod_pos.checked_sub(1) - && let prev = cx.tcx.hir().item(module.item_ids[prev]) + && let prev = cx.tcx.hir_item(module.item_ids[prev]) && let items_span = last.span.with_lo(test_mod.span.hi()) && let Some(items) = items_span.get_source_text(cx) { diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index 238f66d66755..173232c511a5 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -142,7 +142,7 @@ impl LateLintPass<'_> for IterWithoutIntoIter { }) && let Some(iter_assoc_span) = imp.items.iter().find_map(|item| { if item.ident.name.as_str() == "IntoIter" { - Some(cx.tcx.hir().impl_item(item.id).expect_type().span) + Some(cx.tcx.hir_impl_item(item.id).expect_type().span) } else { None } diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 26bea8d633a3..98ba52f12707 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -316,7 +316,7 @@ enum LenOutput { fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { if let ty::Alias(_, alias_ty) = ty.kind() - && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id) + && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.def_id) && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin && let [GenericBound::Trait(trait_ref)] = &opaque.bounds && let Some(segment) = trait_ref.trait_ref.path.segments.last() diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 860c0584accf..8eb45109d68c 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -275,7 +275,7 @@ fn could_use_elision<'tcx>( } if let Some(body_id) = body { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let first_ident = body.params.first().and_then(|param| param.pat.simple_ident()); if non_elidable_self_type(cx, func, first_ident, msrv) { diff --git a/clippy_lints/src/lines_filter_map_ok.rs b/clippy_lints/src/lines_filter_map_ok.rs index 8206c75927b7..f022598651b7 100644 --- a/clippy_lints/src/lines_filter_map_ok.rs +++ b/clippy_lints/src/lines_filter_map_ok.rs @@ -101,7 +101,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> boo ExprKind::Closure(Closure { body, .. }) => { if let Body { params: [param], value, .. - } = cx.tcx.hir().body(*body) + } = cx.tcx.hir_body(*body) && let ExprKind::MethodCall(method, receiver, [], _) = value.kind && path_to_local_id(receiver, param.pat.hir_id) && let Some(method_did) = cx.typeck_results().type_dependent_def_id(value.hir_id) diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 2e6442156ef6..e98c3c9698ba 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -370,7 +370,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> { } }, ExprKind::Closure(&Closure { body, .. }) => { - let body = self.cx.tcx.hir().body(body); + let body = self.cx.tcx.hir_body(body); self.visit_expr(body.value); }, _ => walk_expr(self, expr), diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index b7e37c1a876f..e31b474c83f6 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -351,7 +351,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & loop_id: loop_expr.hir_id, after_loop: false, }; - v.visit_expr(cx.tcx.hir().body(cx.enclosing_body.unwrap()).value) + v.visit_expr(cx.tcx.hir_body(cx.enclosing_body.unwrap()).value) .is_break() } } diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 9f3b0957eab1..6f3a7d8cccc8 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -168,7 +168,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) && let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) = kind { - return Some(cx.tcx.hir().body(body)); + return Some(cx.tcx.hir_body(body)); } None diff --git a/clippy_lints/src/manual_option_as_slice.rs b/clippy_lints/src/manual_option_as_slice.rs index 5c40c945c690..e4360518b66e 100644 --- a/clippy_lints/src/manual_option_as_slice.rs +++ b/clippy_lints/src/manual_option_as_slice.rs @@ -191,7 +191,7 @@ fn check_arms(cx: &LateContext<'_>, none_arm: &Arm<'_>, some_arm: &Arm<'_>) -> b fn returns_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Path(_) => clippy_utils::is_path_diagnostic_item(cx, expr, sym::default_fn), - ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir().body(cl.body).value), + ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir_body(cl.body).value), _ => false, } } diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 708980ac503d..0a4e756096e9 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -92,7 +92,7 @@ fn check_into_iter( && SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = target_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { if match_map_type(cx, left_expr) { @@ -139,7 +139,7 @@ fn check_iter( && SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { match filter_params.pat.kind { @@ -198,7 +198,7 @@ fn check_to_owned( && SpanlessEq::new(cx).eq_expr(left_expr, str_expr) && let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind && let hir::ExprKind::Closure(closure) = closure_expr.kind - && let filter_body = cx.tcx.hir().body(closure.body) + && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params { if let hir::PatKind::Ref(pat, _) = filter_params.pat.kind { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 3221a04d2d03..56aead85e7c4 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -163,7 +163,7 @@ fn unit_closure<'tcx>( expr: &hir::Expr<'_>, ) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> { if let hir::ExprKind::Closure(&hir::Closure { fn_decl, body, .. }) = expr.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let body_expr = &body.value && fn_decl.inputs.len() == 1 && is_unit_expression(cx, body_expr) diff --git a/clippy_lints/src/methods/bind_instead_of_map.rs b/clippy_lints/src/methods/bind_instead_of_map.rs index 91a5de16e967..1e9b29f567f4 100644 --- a/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/clippy_lints/src/methods/bind_instead_of_map.rs @@ -163,7 +163,7 @@ impl BindInsteadOfMap { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); if self.lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) { diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index 687272e550bb..0498f317442a 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -18,7 +18,7 @@ pub(super) fn check<'tcx>( filter_arg: &'tcx Expr<'_>, ) { if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let [param] = body.params && let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind && let ExprKind::Binary(ref op, l, r) = body.value.kind diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index c1653b65e982..5b9df6c2bfdd 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -22,7 +22,7 @@ fn is_method(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol) -> bool ExprKind::Path(QPath::Resolved(_, segments)) => segments.segments.last().unwrap().ident.name == method_name, ExprKind::MethodCall(segment, _, _, _) => segment.ident.name == method_name, ExprKind::Closure(Closure { body, .. }) => { - let body = cx.tcx.hir().body(*body); + let body = cx.tcx.hir_body(*body); let closure_expr = peel_blocks(body.value); match closure_expr.kind { ExprKind::MethodCall(PathSegment { ident, .. }, receiver, ..) => { @@ -404,7 +404,7 @@ fn is_find_or_filter<'a>( if is_trait_method(cx, map_recv, sym::Iterator) // filter(|x| ...is_some())... && let ExprKind::Closure(&Closure { body: filter_body_id, .. }) = filter_arg.kind - && let filter_body = cx.tcx.hir().body(filter_body_id) + && let filter_body = cx.tcx.hir_body(filter_body_id) && let [filter_param] = filter_body.params // optional ref pattern: `filter(|&x| ..)` && let (filter_pat, is_filter_param_ref) = if let PatKind::Ref(ref_pat, _) = filter_param.pat.kind { @@ -417,7 +417,7 @@ fn is_find_or_filter<'a>( && let Some(mut offending_expr) = OffendingFilterExpr::hir(cx, filter_body.value, filter_param_id) && let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind - && let map_body = cx.tcx.hir().body(map_body_id) + && let map_body = cx.tcx.hir_body(map_body_id) && let [map_param] = map_body.params && let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs index d550c1454668..f7e116c5310e 100644 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ b/clippy_lints/src/methods/filter_map_bool_then.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & if !expr.span.in_external_macro(cx.sess().source_map()) && is_trait_method(cx, expr, sym::Iterator) && let ExprKind::Closure(closure) = arg.kind - && let body = cx.tcx.hir().body(closure.body) + && 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 @@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & && 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 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) && cx.tcx.is_diagnostic_item(sym::bool_then, def_id) && !is_from_proc_macro(cx, expr) diff --git a/clippy_lints/src/methods/format_collect.rs b/clippy_lints/src/methods/format_collect.rs index 3e5162ef4580..1b28596d50da 100644 --- a/clippy_lints/src/methods/format_collect.rs +++ b/clippy_lints/src/methods/format_collect.rs @@ -19,7 +19,7 @@ fn peel_non_expn_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx> pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, map_arg: &Expr<'_>, map_span: Span) { if is_type_lang_item(cx, cx.typeck_results().expr_ty(expr), LangItem::String) && let ExprKind::Closure(closure) = map_arg.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && let Some(value) = peel_non_expn_blocks(body.value) && let Some(mac) = root_macro_call_first_node(cx, value) && is_format_macro(cx, mac.def_id) diff --git a/clippy_lints/src/methods/iter_filter.rs b/clippy_lints/src/methods/iter_filter.rs index 30387ba62a73..76a0c0061e52 100644 --- a/clippy_lints/src/methods/iter_filter.rs +++ b/clippy_lints/src/methods/iter_filter.rs @@ -95,7 +95,7 @@ fn is_method( false }, ExprKind::Closure(&hir::Closure { body, .. }) => { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(body.value); let params = body.params.iter().map(|param| param.pat).collect::>(); is_method(cx, closure_expr, type_symbol, method_name, params.as_slice()) diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 299f6d101123..518041177e92 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -30,7 +30,7 @@ pub(super) fn check<'tcx>( && let Body { params: [p], value: body_expr, - } = cx.tcx.hir().body(c.body) + } = cx.tcx.hir_body(c.body) && let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind && let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) { (key, PatKind::Binding(ann, _, value, _)) if pat_is_wild(cx, key, m_arg) => ("value", ann, value), diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 5ccb5243e903..a80977459f21 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -62,7 +62,7 @@ pub(super) fn check<'tcx>( let ExprKind::Closure(closure) = expr.kind else { return; }; - let body @ Body { params: [p], .. } = cx.tcx.hir().body(closure.body) else { + let body @ Body { params: [p], .. } = cx.tcx.hir_body(closure.body) else { return; }; let mut delegate = MoveDelegate { diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index 20e4d233525a..de37df2394d3 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -22,7 +22,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: && (is_diag_trait_item(cx, fn_id, sym::Iterator) || (msrv.meets(msrvs::OPTION_RESULT_INSPECT) && (is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result)))) - && let body = cx.tcx.hir().body(c.body) + && let body = cx.tcx.hir_body(c.body) && let [param] = body.params && let PatKind::Binding(BindingMode(ByRef::No, Mutability::Not), arg_id, _, None) = param.pat.kind && let arg_ty = typeck.node_type(arg_id) @@ -45,7 +45,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: let can_lint = for_each_expr_without_closures(block.stmts, |e| { if let ExprKind::Closure(c) = e.kind { // Nested closures don't need to treat returns specially. - let _: Option = for_each_expr(cx, cx.tcx.hir().body(c.body).value, |e| { + let _: Option = for_each_expr(cx, cx.tcx.hir_body(c.body).value, |e| { if path_to_local_id(e, arg_id) { let (kind, same_ctxt) = check_use(cx, e); match (kind, same_ctxt && e.span.ctxt() == ctxt) { diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index 4321dd6b0e09..8265c93bfe9f 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -44,7 +44,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool { match map_expr.kind { ExprKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, map_expr.hir_id), ResultOk) => true, ExprKind::Closure(closure) => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind && let ExprKind::Call(callee, [ok_arg]) = body.value.kind && is_res_lang_ctor(cx, path_res(cx, callee), ResultOk) diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index 1252f7ccd357..b2705e1ffc2d 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -47,7 +47,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, Mutability::Not) => { diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index 162f0ac564d7..5d0d4dae35fa 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) { fn_decl_span, .. }) = arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let [param] = closure_body.params && let PatKind::Wild = param.pat.kind { diff --git a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs index 78656ace831d..35dd7c082c90 100644 --- a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs +++ b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs @@ -68,7 +68,7 @@ pub(super) fn check( let mut applicability = Applicability::MaybeIncorrect; if let Some(range) = higher::Range::hir(receiver) && let ExprKind::Closure(Closure { body, .. }) = arg.kind - && let body_hir = cx.tcx.hir().body(*body) + && let body_hir = cx.tcx.hir_body(*body) && let Body { params: [param], value: body_expr, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 0a8eafad0e84..ccc5cd4fa417 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4716,7 +4716,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if sig.decl.implicit_self.has_implicit_self() && !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id)) - && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next() + && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir_body(id)).next() && let Some(first_arg_ty) = first_arg_ty_opt { wrong_self_convention::check( @@ -4852,7 +4852,7 @@ impl Methods { ), Some(("chars", recv, _, _, _)) if let ExprKind::Closure(arg) = arg.kind - && let body = cx.tcx.hir().body(arg.body) + && let body = cx.tcx.hir_body(arg.body) && let [param] = body.params => { string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); diff --git a/clippy_lints/src/methods/needless_character_iteration.rs b/clippy_lints/src/methods/needless_character_iteration.rs index 6993150fb57a..743aacf05885 100644 --- a/clippy_lints/src/methods/needless_character_iteration.rs +++ b/clippy_lints/src/methods/needless_character_iteration.rs @@ -99,7 +99,7 @@ fn handle_expr( pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>, is_all: bool) { if let ExprKind::Closure(&Closure { body, .. }) = closure_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some(first_param) = body.params.first() && let ExprKind::MethodCall(method, mut recv, [], _) = recv.kind && method.ident.name.as_str() == "chars" diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 2780c3f8af5c..5664ffba1a0e 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -498,7 +498,7 @@ fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet { } }, ty::Closure(def_id, _) => { - let closure_hir_node = cx.tcx.hir().get_if_local(*def_id).unwrap(); + let closure_hir_node = cx.tcx.hir_get_if_local(*def_id).unwrap(); if let Node::Expr(closure_expr) = closure_hir_node { can_move_expr_to_closure(cx, closure_expr) .unwrap() diff --git a/clippy_lints/src/methods/obfuscated_if_else.rs b/clippy_lints/src/methods/obfuscated_if_else.rs index b71f79f84824..e0905374ddaa 100644 --- a/clippy_lints/src/methods/obfuscated_if_else.rs +++ b/clippy_lints/src/methods/obfuscated_if_else.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( let if_then = match then_method_name { "then" if let ExprKind::Closure(closure) = then_arg.kind => { - let body = cx.tcx.hir().body(closure.body); + let body = cx.tcx.hir_body(closure.body); snippet_with_applicability(cx, body.value.span, "..", &mut applicability) }, "then_some" => snippet_with_applicability(cx, then_arg.span, "..", &mut applicability), diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 8d97d1c72a6b..469fcccbe4f6 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -54,7 +54,7 @@ pub(super) fn check( }) }, hir::ExprKind::Closure(&hir::Closure { body, .. }) => { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); let closure_expr = peel_blocks(closure_body.value); match &closure_expr.kind { diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 193deafccf65..1a273f77fb7d 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -60,7 +60,7 @@ pub(super) fn check<'tcx>( let self_snippet = snippet(cx, recv.span, ".."); if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind && let arg_snippet = snippet(cx, fn_decl_span, "..") - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some((func, [arg_char])) = reduce_unit_expression(body.value) && let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id)) && Some(id) == cx.tcx.lang_items().option_some_variant() diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 6b39b753885e..f5f404070cab 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -253,7 +253,7 @@ pub(super) fn check<'tcx>( fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool { if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = e.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if body.params.is_empty() && let hir::Expr { kind, .. } = &body.value diff --git a/clippy_lints/src/methods/result_map_or_else_none.rs b/clippy_lints/src/methods/result_map_or_else_none.rs index 3b0dc506305b..af619c9e3bb1 100644 --- a/clippy_lints/src/methods/result_map_or_else_none.rs +++ b/clippy_lints/src/methods/result_map_or_else_none.rs @@ -23,7 +23,7 @@ pub(super) fn check<'tcx>( // We check that it is mapped as `Some`. && is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome) && let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) // And finally we check that we return a `None` in the "else case". && is_res_lang_ctor(cx, path_res(cx, peel_blocks(body.value)), OptionNone) { diff --git a/clippy_lints/src/methods/return_and_then.rs b/clippy_lints/src/methods/return_and_then.rs index 7b1199ad1e2d..68ffa81a2781 100644 --- a/clippy_lints/src/methods/return_and_then.rs +++ b/clippy_lints/src/methods/return_and_then.rs @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( }; let closure_arg = fn_decl.inputs[0]; - let closure_expr = peel_blocks(cx.tcx.hir().body(body).value); + let closure_expr = peel_blocks(cx.tcx.hir_body(body).value); let mut applicability = Applicability::MachineApplicable; let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability); diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 4ab165a5528b..97c8ce2bcdd2 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( let mut applicability = Applicability::MachineApplicable; let any_search_snippet = if search_method == "find" && let ExprKind::Closure(&hir::Closure { body, .. }) = search_arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let Some(closure_arg) = closure_body.params.first() { if let PatKind::Ref(..) = closure_arg.pat.kind { diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index ed49233acb7f..1bd48525f12d 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -10,7 +10,7 @@ use super::SUSPICIOUS_MAP; pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) { if is_trait_method(cx, count_recv, sym::Iterator) && let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind - && let closure_body = cx.tcx.hir().body(closure.body) + && let closure_body = cx.tcx.hir_body(closure.body) && !cx.typeck_results().expr_ty(closure_body.value).is_unit() { if let Some(map_mutated_vars) = mutated_variables(closure_body.value, cx) { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 5b9e9e70e477..ca42a9ac04e0 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a } if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let arg_id = body.params[0].pat.hir_id; let mutates_arg = mutated_variables(body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id)); let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, body.value); diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index e7adf3b43ba5..8e3cc9abe832 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -62,7 +62,7 @@ fn check_fold_with_op( ) { if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind // Extract the body of the closure passed to fold - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let closure_expr = peel_blocks(closure_body.value) // Check if the closure body is of the form `acc some_expr(x)` diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 7af550fa7c68..9f4080100da2 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( if is_option || is_result || is_bool { if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); let body_expr = &body.value; if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) { diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs index 10112b62878a..00690aca6d13 100644 --- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs +++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs @@ -99,7 +99,7 @@ pub(super) fn check( ("None", "unwrap_or_else", _) => match args[0].kind { hir::ExprKind::Closure(hir::Closure { body, .. }) => Some(vec![ ( - expr.span.with_hi(cx.tcx.hir().body(*body).value.span.lo()), + expr.span.with_hi(cx.tcx.hir_body(*body).value.span.lo()), String::new(), ), (expr.span.with_lo(args[0].span.hi()), String::new()), diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index 6dea1506d0e3..5f88a7fd31f2 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -63,7 +63,7 @@ pub(super) fn check<'a>( let ext_def_span = def.span.until(map.span); let (sugg, method, applicability) = if let ExprKind::Closure(map_closure) = map.kind - && let closure_body = cx.tcx.hir().body(map_closure.body) + && let closure_body = cx.tcx.hir_body(map_closure.body) && let closure_body_value = closure_body.value.peel_blocks() && let ExprKind::Binary(op, l, r) = closure_body_value.kind && let Some(param) = closure_body.params.first() diff --git a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs index dc50717112d8..f84d0d6dff0a 100644 --- a/clippy_lints/src/methods/unnecessary_result_map_or_else.rs +++ b/clippy_lints/src/methods/unnecessary_result_map_or_else.rs @@ -53,7 +53,7 @@ pub(super) fn check<'tcx>( // lint if the caller of `map_or_else()` is a `Result` if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) && let ExprKind::Closure(&Closure { body, .. }) = map_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let Some(first_param) = body.params.first() { let body_expr = peel_blocks(body.value); diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index f0b29213e1e5..fb4984914eb0 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -117,7 +117,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp && let Some(impl_id) = cx.tcx.impl_of_method(method_id) && cx.tcx.type_of(impl_id).instantiate_identity().is_slice() && let ExprKind::Closure(&Closure { body, .. }) = arg.kind - && let closure_body = cx.tcx.hir().body(body) + && let closure_body = cx.tcx.hir_body(body) && let &[ Param { pat: diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 7d72310c1c44..e80d99dca56d 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -506,7 +506,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< if has_lifetime(output_ty) && has_lifetime(ty) { return false; } - let body = cx.tcx.hir().body(*body_id); + let body = cx.tcx.hir_body(*body_id); let body_expr = &body.value; let mut count = 0; return find_all_ret_expressions(cx, body_expr, |_| { diff --git a/clippy_lints/src/methods/unused_enumerate_index.rs b/clippy_lints/src/methods/unused_enumerate_index.rs index 0aec26f10111..af466fe091c2 100644 --- a/clippy_lints/src/methods/unused_enumerate_index.rs +++ b/clippy_lints/src/methods/unused_enumerate_index.rs @@ -46,7 +46,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, && is_trait_method(cx, call_expr, sym::Iterator) // And the map argument is a closure && let ExprKind::Closure(closure) = closure_arg.kind - && let closure_body = cx.tcx.hir().body(closure.body) + && let closure_body = cx.tcx.hir_body(closure.body) // And that closure has one argument ... && let [closure_param] = closure_body.params // .. which is a tuple of 2 elements diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 82313257e5c4..19152362fb5f 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -113,7 +113,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, .. }) // If it's a closure, we need to check what is called. - if let closure_body = cx.tcx.hir().body(body) + if let closure_body = cx.tcx.hir_body(body) && let [param] = closure_body.params && let hir::PatKind::Binding(_, local_id, ..) = strip_pat_refs(param.pat).kind => { diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index e9ec23b1efa6..675989156cad 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -213,8 +213,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug { && !item.span.from_expansion() // find `Debug::fmt` function && let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt) - && let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir().impl_item(fmt_item.id) - && let body = cx.tcx.hir().body(*body_id) + && let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir_impl_item(fmt_item.id) + && let body = cx.tcx.hir_body(*body_id) && let ExprKind::Block(block, _) = body.value.kind // inspect `self` && let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs() diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 18385ac92692..fdc0930e957a 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // note: we need to check if the trait is exported so we can't use // `LateLintPass::check_trait_item` here. for tit in trait_items { - let tit_ = cx.tcx.hir().trait_item(tit.id); + let tit_ = cx.tcx.hir_trait_item(tit.id); match tit_.kind { hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Fn(..) => { @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; - let item = cx.tcx.hir().trait_item(tit.id); + let item = cx.tcx.hir_trait_item(tit.id); let attrs = cx.tcx.hir().attrs(item.hir_id()); check_missing_inline_attrs(cx, attrs, item.span, desc); } diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 93e20f37ef8a..90b27f5dbac8 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { // Skip the lint if the body is not block because this is simpler than `for` loop. // e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop. && let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) // Skip the lint if the body is not safe, so as not to suggest `for … in … unsafe {}` // and suggesting `for … in … { unsafe { } }` is a little ugly. && let ExprKind::Block(Block { rules: BlockCheckMode::DefaultBlock, .. }, ..) = body.value.kind diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 996251fdf162..6a1dc5e41a07 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -103,7 +103,6 @@ fn check_closures<'tcx>( checked_closures: &mut FxHashSet, closures: FxIndexSet, ) { - let hir = cx.tcx.hir(); for closure in closures { if !checked_closures.insert(closure) { continue; @@ -114,7 +113,7 @@ fn check_closures<'tcx>( .tcx .hir_node_by_def_id(closure) .associated_body() - .map(|(_, body_id)| hir.body(body_id)) + .map(|(_, body_id)| cx.tcx.hir_body(body_id)) { euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx) .consume_body(body) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index cc56df3a23d7..cf407e51f7af 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { { for assoc_item in *items { if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) { - let impl_item = cx.tcx.hir().impl_item(assoc_item.id); + let impl_item = cx.tcx.hir_impl_item(assoc_item.id); if impl_item.span.in_external_macro(cx.sess().source_map()) { return; } diff --git a/clippy_lints/src/non_canonical_impls.rs b/clippy_lints/src/non_canonical_impls.rs index dad1e8a3d6a1..448bb603cf2c 100644 --- a/clippy_lints/src/non_canonical_impls.rs +++ b/clippy_lints/src/non_canonical_impls.rs @@ -121,10 +121,10 @@ impl LateLintPass<'_> for NonCanonicalImpls { if cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) { return; } - let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir().impl_item(impl_item.impl_item_id()).kind else { + let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir_impl_item(impl_item.impl_item_id()).kind else { return; }; - let body = cx.tcx.hir().body(impl_item_id); + let body = cx.tcx.hir_body(impl_item_id); let ExprKind::Block(block, ..) = body.value.kind else { return; }; diff --git a/clippy_lints/src/non_std_lazy_statics.rs b/clippy_lints/src/non_std_lazy_statics.rs index 22116505a1c1..774a182d089f 100644 --- a/clippy_lints/src/non_std_lazy_statics.rs +++ b/clippy_lints/src/non_std_lazy_statics.rs @@ -214,7 +214,7 @@ impl LazyInfo { && state.once_cell_sync_lazy.contains(&path_def_id) { let ty_span_no_args = path_span_without_args(path); - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); // visit body to collect `Lazy::new` calls let mut new_fn_calls = FxIndexMap::default(); diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 95403403217a..73c31b83b51f 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -136,7 +136,7 @@ impl PassByRefOrValue { } let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity(); - let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id)); + let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir_body(id)); // Gather all the lifetimes found in the output type which may affect whether // `TRIVIALLY_COPY_PASS_BY_REF` should be linted. diff --git a/clippy_lints/src/redundant_async_block.rs b/clippy_lints/src/redundant_async_block.rs index 65fd312b3a09..bc5e8fd2c258 100644 --- a/clippy_lints/src/redundant_async_block.rs +++ b/clippy_lints/src/redundant_async_block.rs @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock { /// any variable by ref. fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { if let ExprKind::Closure(Closure { body, def_id, kind, .. }) = expr.kind - && let body = cx.tcx.hir().body(*body) + && let body = cx.tcx.hir_body(*body) && matches!( kind, ClosureKind::Coroutine(CoroutineKind::Desugared( diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 91d023500ca6..54e507655e9c 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -90,7 +90,7 @@ fn find_innermost_closure<'tcx>( let mut data = None; while let ExprKind::Closure(closure) = expr.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && { let mut visitor = ReturnVisitor; !visitor.visit_expr(body.value).is_break() @@ -179,7 +179,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - let async_closure_body = cx.tcx.hir().body(closure.body).value; + let async_closure_body = cx.tcx.hir_body(closure.body).value; let ExprKind::Block(block, _) = async_closure_body.kind else { return; }; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index a1cf16e6ce9f..9f0ea84246dd 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { // Ensure this is not the final stmt, otherwise removing it would cause a compile error && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) && let ItemKind::Fn { body, .. } = item.kind - && let block = cx.tcx.hir().body(body).value + && let block = cx.tcx.hir_body(body).value && let ExprKind::Block(block, _) = block.kind && !is_inside_let_else(cx.tcx, expr) && let [.., final_stmt] = block.stmts diff --git a/clippy_lints/src/same_name_method.rs b/clippy_lints/src/same_name_method.rs index 29914d4379fe..552135b15fd8 100644 --- a/clippy_lints/src/same_name_method.rs +++ b/clippy_lints/src/same_name_method.rs @@ -50,9 +50,9 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { fn check_crate_post(&mut self, cx: &LateContext<'tcx>) { let mut map = FxHashMap::::default(); - for id in cx.tcx.hir().items() { + for id in cx.tcx.hir_free_items() { if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl { .. }) - && let item = cx.tcx.hir().item(id) + && let item = cx.tcx.hir_item(id) && let ItemKind::Impl(Impl { items, of_trait, diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 3834087f7977..694ad4f6347b 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -138,7 +138,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) { if let ExprKind::Closure(closure) = method_arg.kind - && let body = cx.tcx.hir().body(closure.body) + && let body = cx.tcx.hir_body(closure.body) && let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind) { let mut set_char_spans: Vec = Vec::new(); diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index e9779d437d43..9326b2adaffb 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id && let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn) && let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id && let Some(trait_ref) = trait_ref_of_method(cx, parent_fn) && let trait_id = trait_ref.path.res.def_id() diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 790e0965198d..cbf7b126632e 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { && let Some(Node::Item(Item { kind: ItemKind::Trait(_, _, _, self_bounds, _), .. - })) = cx.tcx.hir().get_if_local(*def_id) + })) = cx.tcx.hir_get_if_local(*def_id) { if self_bounds_map.is_empty() { for bound in *self_bounds { diff --git a/clippy_lints/src/types/borrowed_box.rs b/clippy_lints/src/types/borrowed_box.rs index 2e97772407fd..004ad03e7085 100644 --- a/clippy_lints/src/types/borrowed_box.rs +++ b/clippy_lints/src/types/borrowed_box.rs @@ -96,10 +96,10 @@ fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool { fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option> { if let Some(did) = cx.qpath_res(qpath, id).opt_def_id() - && let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did) + && let Some(Node::GenericParam(generic_param)) = cx.tcx.hir_get_if_local(did) && let GenericParamKind::Type { synthetic, .. } = generic_param.kind && synthetic - && let Some(generics) = cx.tcx.hir().get_generics(id.owner.def_id) + && let Some(generics) = cx.tcx.hir_get_generics(id.owner.def_id) && let Some(pred) = generics.bounds_for_param(did.expect_local()).next() { Some(pred.bounds) diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 207f2ef4563a..16fe035802fa 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -326,9 +326,9 @@ impl UnconditionalRecursion { .find(|item| { item.kind == AssocKind::Fn && item.def_id.is_local() && item.name == kw::Default }) - && let Some(body_node) = cx.tcx.hir().get_if_local(assoc_item.def_id) + && let Some(body_node) = cx.tcx.hir_get_if_local(assoc_item.def_id) && let Some(body_id) = body_node.body_id() - && let body = cx.tcx.hir().body(body_id) + && let body = cx.tcx.hir_body(body_id) // We don't want to keep it if it has conditional return. && let [return_expr] = get_return_calls_in_body(body).as_slice() && let ExprKind::Call(call_expr, _) = return_expr.kind diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index b3d269080930..c8e3c46f2f6f 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -245,7 +245,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { // const and static items only need a safety comment if their body is an unsafe block, lint otherwise (&ItemKind::Const(.., body) | &ItemKind::Static(.., body), HasSafetyComment::Yes(pos)) => { if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, body.hir_id) { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if !matches!( body.value.kind, hir::ExprKind::Block(block, _) if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) @@ -558,7 +558,7 @@ fn comment_start_before_item_in_mod( // some_item /* comment */ unsafe impl T {} // ^-------^ returns the end of this span // ^---------------^ finally checks comments in this range - let prev_item = cx.tcx.hir().item(parent_mod.item_ids[idx - 1]); + let prev_item = cx.tcx.hir_item(parent_mod.item_ids[idx - 1]); if let Some(sp) = walk_span_to_context(prev_item.span, SyntaxContext::root()) { return Some(sp.hi()); } @@ -605,7 +605,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span fn get_body_search_span(cx: &LateContext<'_>) -> Option { let body = cx.enclosing_body?; let map = cx.tcx.hir(); - let mut span = map.body(body).value.span; + let mut span = cx.tcx.hir_body(body).value.span; let mut maybe_global_var = false; for (_, node) in map.parent_iter(body.hir_id) { match node { diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 87478a120dd0..67ceac92dbc0 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -123,7 +123,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa && let ty = cx.tcx.instantiate_bound_regions_with_erased(ret_ty) && ty.is_unit() { - let body = cx.tcx.hir().body(body); + let body = cx.tcx.hir_body(body); if let ExprKind::Block(block, _) = body.value.kind && block.expr.is_none() && let Some(stmt) = block.stmts.last() diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 00b80e827d8a..87f184e13ce1 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) { if let PatKind::Binding(_, binding_hir_id, ..) = local.pat.kind && let Some(body_id) = cx.enclosing_body.as_ref() { - let body = cx.tcx.hir().body(*body_id); + let body = cx.tcx.hir_body(*body_id); // Collect variable usages let mut visitor = UnitVariableCollector::new(binding_hir_id); diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 781f51aa9b07..d8305a628290 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { && assoc_item.fn_has_self_parameter && let ImplItemKind::Fn(.., body_id) = &impl_item.kind && (!cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) || !self.avoid_breaking_exported_api) - && let body = cx.tcx.hir().body(*body_id) + && let body = cx.tcx.hir_body(*body_id) && let [self_param, ..] = body.params && !is_local_used(cx, body, self_param.pat.hir_id) && !contains_todo(cx, body) diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index 9b9a2ffbbc80..f870eb71e19b 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) { if let ImplItemKind::Fn(_, body_id) = impl_item.kind { - let body = cx.tcx.hir().body(body_id); + let body = cx.tcx.hir_body(body_id); let typeck = cx.tcx.typeck(impl_item.owner_id.def_id); let mut result = Vec::new(); let _: Option = for_each_expr(cx, body.value, |e| { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 6bad78cf8718..ce489054e16e 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -637,9 +637,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } fn body(&self, body_id: &Binding) { - let expr = self.cx.tcx.hir().body(body_id.value).value; + let expr = self.cx.tcx.hir_body(body_id.value).value; bind!(self, expr); - chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value"); + chain!(self, "{expr} = &cx.tcx.hir_body({body_id}).value"); self.expr(expr); } diff --git a/clippy_lints/src/utils/internal_lints/collapsible_calls.rs b/clippy_lints/src/utils/internal_lints/collapsible_calls.rs index eaeb754a23f1..2e6fb7c4ce4d 100644 --- a/clippy_lints/src/utils/internal_lints/collapsible_calls.rs +++ b/clippy_lints/src/utils/internal_lints/collapsible_calls.rs @@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { if let ExprKind::Call(func, [call_cx, call_lint, call_sp, call_msg, call_f]) = expr.kind && is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"]) && let ExprKind::Closure(&Closure { body, .. }) = call_f.kind - && let body = cx.tcx.hir().body(body) + && let body = cx.tcx.hir_body(body) && let only_expr = peel_blocks_with_stmt(body.value) && let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind && let ExprKind::Path(..) = recv.kind diff --git a/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/clippy_lints/src/utils/internal_lints/invalid_paths.rs index 08c178ed229f..252ac5e67682 100644 --- a/clippy_lints/src/utils/internal_lints/invalid_paths.rs +++ b/clippy_lints/src/utils/internal_lints/invalid_paths.rs @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths { ty::TypingEnv::post_analysis(cx.tcx, item.owner_id), cx.tcx.typeck(item.owner_id), ) - .eval_simple(cx.tcx.hir().body(body_id).value) + .eval_simple(cx.tcx.hir_body(body_id).value) && let Some(path) = path .iter() .map(|x| { diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index dac1951489ca..315c83507d07 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { if is_lint_ref_type(cx, ty) { check_invalid_clippy_version_attribute(cx, item); - let expr = &cx.tcx.hir().body(body_id).value; + let expr = &cx.tcx.hir_body(body_id).value; let fields = if let ExprKind::AddrOf(_, _, inner_exp) = expr.kind && let ExprKind::Struct(_, struct_fields, _) = inner_exp.kind { diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index 05f856507697..30fdf22fdbb0 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -47,7 +47,6 @@ declare_lint_pass!(ZeroRepeatSideEffects => [ZERO_REPEAT_SIDE_EFFECTS]); impl LateLintPass<'_> for ZeroRepeatSideEffects { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &rustc_hir::Expr<'_>) { - let hir_map = cx.tcx.hir(); if let Some(args) = VecArgs::hir(cx, expr) && let VecArgs::Repeat(inner_expr, len) = args && let ExprKind::Lit(l) = len.kind @@ -62,7 +61,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects { // sessions). else if let ExprKind::Repeat(inner_expr, const_arg) = expr.kind && let ConstArgKind::Anon(anon_const) = const_arg.kind - && let length_expr = hir_map.body(anon_const.body).value + && let length_expr = cx.tcx.hir_body(anon_const.body).value && !length_expr.span.from_expansion() && let ExprKind::Lit(literal) = length_expr.kind && let LitKind::Int(Pu128(0), _) = literal.node diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 59aaaa3d9fb7..4f48fb3b8a96 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -192,7 +192,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { }, ExprKind::Closure(&Closure { body, .. }) => ( Pat::Str(""), - expr_search_pat_inner(tcx, tcx.hir().body(body).value, outer_span).1, + expr_search_pat_inner(tcx, tcx.hir_body(body).value, outer_span).1, ), ExprKind::Block( Block { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index db82c458f703..4f707e34abf9 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -455,7 +455,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { Some(val) } }, - PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(*body).value), + PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(*body).value), PatExprKind::Path(qpath) => self.qpath(qpath, pat_expr.hir_id), } } @@ -483,7 +483,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { /// Simple constant folding: Insert an expression, get a constant or none. fn expr(&self, e: &Expr<'_>) -> Option> { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.expr(e), ExprKind::Path(ref qpath) => self.qpath(qpath, e.hir_id), ExprKind::Block(block, _) => self.block(block), @@ -550,7 +550,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { /// leaves the local crate. pub fn eval_is_empty(&self, e: &Expr<'_>) -> Option { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir().body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.eval_is_empty(e), ExprKind::Path(ref qpath) => { if !self @@ -645,7 +645,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { // Check if this constant is based on `cfg!(..)`, // which is NOT constant for our purposes. - if let Some(node) = self.tcx.hir().get_if_local(def_id) + if let Some(node) = self.tcx.hir_get_if_local(def_id) && let Node::Item(Item { kind: ItemKind::Const(.., body_id), .. diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 4bbf28115a68..9ee30094d608 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -273,8 +273,8 @@ impl HirEqInterExpr<'_, '_, '_> { self.inner.cx.tcx.typeck_body(right), )); let res = self.eq_expr( - self.inner.cx.tcx.hir().body(left).value, - self.inner.cx.tcx.hir().body(right).value, + self.inner.cx.tcx.hir_body(left).value, + self.inner.cx.tcx.hir_body(right).value, ); self.inner.maybe_typeck_results = old_maybe_typeck_results; res @@ -906,7 +906,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }) => { std::mem::discriminant(&capture_clause).hash(&mut self.s); // closures inherit TypeckResults - self.hash_expr(self.cx.tcx.hir().body(body).value); + self.hash_expr(self.cx.tcx.hir_body(body).value); }, ExprKind::ConstBlock(ref l_id) => { self.hash_body(l_id.body); @@ -1316,7 +1316,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_body(&mut self, body_id: BodyId) { // swap out TypeckResults when hashing a body let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id)); - self.hash_expr(self.cx.tcx.hir().body(body_id).value); + self.hash_expr(self.cx.tcx.hir_body(body_id).value); self.maybe_typeck_results = old_maybe_typeck_results; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 79cc50665800..c4ba4c94c946 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -652,8 +652,6 @@ fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) } fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symbol) -> Vec { - let hir = tcx.hir(); - let root_mod; let item_kind = match tcx.hir_node_by_def_id(local_id) { Node::Crate(r#mod) => { @@ -677,7 +675,7 @@ fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symb ItemKind::Mod(r#mod) => r#mod .item_ids .iter() - .filter_map(|&item_id| res(hir.item(item_id).ident, item_id.owner_id)) + .filter_map(|&item_id| res(tcx.hir_item(item_id).ident, item_id.owner_id)) .collect(), ItemKind::Impl(r#impl) => r#impl .items @@ -944,7 +942,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)), ExprKind::Repeat(x, len) => { if let ConstArgKind::Anon(anon_const) = len.kind - && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind + && let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind && let LitKind::Int(v, _) = const_lit.node && v <= 32 && is_default_equivalent(cx, x) @@ -974,7 +972,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: & ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec), ExprKind::Repeat(_, len) => { if let ConstArgKind::Anon(anon_const) = len.kind - && let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind + && let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind && let LitKind::Int(v, _) = const_lit.node { return v == 0 && is_path_diagnostic_item(cx, ty, sym::Vec); @@ -1424,7 +1422,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio | Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(_, eid), .. - }) => match cx.tcx.hir().body(eid).value.kind { + }) => match cx.tcx.hir_body(eid).value.kind { ExprKind::Block(block, _) => Some(block), _ => None, }, @@ -2067,7 +2065,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t .. }, _, - ) = tcx.hir().body(body).value.kind + ) = tcx.hir_body(body).value.kind { return Some(expr); } @@ -2175,7 +2173,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) ExprKind::Closure(&Closure { body, fn_decl, .. }) if fn_decl.inputs.iter().all(|ty| matches!(ty.kind, TyKind::Infer(()))) => { - is_body_identity_function(cx, cx.tcx.hir().body(body)) + is_body_identity_function(cx, cx.tcx.hir_body(body)) }, ExprKind::Path(QPath::Resolved(_, path)) if path.segments.iter().all(|seg| seg.infer_args) @@ -2197,7 +2195,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) /// errors. pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match expr.kind { - ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)), + ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir_body(body)), _ => path_def_id(cx, expr).is_some_and(|id| cx.tcx.is_diagnostic_item(sym::convert_identity, id)), } } @@ -2552,9 +2550,9 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Sym Entry::Occupied(entry) => f(entry.get()), Entry::Vacant(entry) => { let mut names = Vec::new(); - for id in tcx.hir().module_items(module) { + for id in tcx.hir_module_free_items(module) { if matches!(tcx.def_kind(id.owner_id), DefKind::Const) - && let item = tcx.hir().item(id) + && let item = tcx.hir_item(id) && let ItemKind::Const(ty, _generics, _body) = item.kind { if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { @@ -2932,7 +2930,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU #[allow(unreachable_patterns)] Some(ControlFlow::Break(_)) => unreachable!("type of node is ControlFlow"), None => ExprUseCtxt { - node: Node::Crate(cx.tcx.hir().root_module()), + node: Node::Crate(cx.tcx.hir_root_module()), child_id: HirId::INVALID, adjustments: &[], is_ty_unified: true, diff --git a/clippy_utils/src/ptr.rs b/clippy_utils/src/ptr.rs index 273c1b0defab..360c6251a57c 100644 --- a/clippy_utils/src/ptr.rs +++ b/clippy_utils/src/ptr.rs @@ -13,7 +13,7 @@ pub fn get_spans( idx: usize, replacements: &[(&'static str, &'static str)], ) -> Option)>> { - if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) { + if let Some(body) = opt_body_id.map(|id| cx.tcx.hir_body(id)) { if let PatKind::Binding(_, binding_id, _, _) = strip_pat_refs(body.params[idx].pat).kind { extract_clone_suggestions(cx, binding_id, replacements, body) } else { diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 088abd7c4791..d5e0e2e3436e 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -809,7 +809,7 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti fn_decl, def_id, body, .. }) = closure.kind { - let closure_body = cx.tcx.hir().body(body); + let closure_body = cx.tcx.hir_body(body); // is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`) // a type annotation is present if param `kind` is different from `TyKind::Infer` let closure_arg_is_type_annotated_double_ref = if let TyKind::Ref(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 70910f5bf52d..9b35ecee1dd1 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -296,7 +296,7 @@ where /// Checks if the given resolved path is used in the given body. pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool { - for_each_expr(cx, cx.tcx.hir().body(body).value, |e| { + for_each_expr(cx, cx.tcx.hir_body(body).value, |e| { if let ExprKind::Path(p) = &e.kind { if cx.qpath_res(p, e.hir_id) == res { return ControlFlow::Break(()); @@ -456,7 +456,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { } } fn visit_nested_item(&mut self, id: ItemId) -> Self::Result { - if let ItemKind::Impl(i) = &self.cx.tcx.hir().item(id).kind + if let ItemKind::Impl(i) = &self.cx.tcx.hir_item(id).kind && i.safety.is_unsafe() { ControlFlow::Break(()) diff --git a/tests/ui/author/blocks.stdout b/tests/ui/author/blocks.stdout index 6bf48d5ba4ef..54325f9776c5 100644 --- a/tests/ui/author/blocks.stdout +++ b/tests/ui/author/blocks.stdout @@ -42,10 +42,10 @@ if let ExprKind::Block(block, None) = expr.kind } if let ExprKind::Closure { capture_clause: CaptureBy::Value { .. }, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::CoroutineClosure(CoroutineDesugaring::Async), .. } = expr.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output - && expr1 = &cx.tcx.hir().body(body_id).value + && expr1 = &cx.tcx.hir_body(body_id).value && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl1, body: body_id1, closure_kind: ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Closure)), .. } = expr1.kind && let FnRetTy::DefaultReturn(_) = fn_decl1.output - && expr2 = &cx.tcx.hir().body(body_id1).value + && expr2 = &cx.tcx.hir_body(body_id1).value && let ExprKind::Block(block, None) = expr2.kind && block.stmts.is_empty() && let Some(trailing_expr) = block.expr diff --git a/tests/ui/author/macro_in_closure.stdout b/tests/ui/author/macro_in_closure.stdout index 66caf382d897..3186d0cbc276 100644 --- a/tests/ui/author/macro_in_closure.stdout +++ b/tests/ui/author/macro_in_closure.stdout @@ -2,7 +2,7 @@ if let StmtKind::Let(local) = stmt.kind && let Some(init) = local.init && let ExprKind::Closure { capture_clause: CaptureBy::Ref, fn_decl: fn_decl, body: body_id, closure_kind: ClosureKind::Closure, .. } = init.kind && let FnRetTy::DefaultReturn(_) = fn_decl.output - && expr = &cx.tcx.hir().body(body_id).value + && expr = &cx.tcx.hir_body(body_id).value && let ExprKind::Block(block, None) = expr.kind && block.stmts.len() == 1 && let StmtKind::Semi(e) = block.stmts[0].kind diff --git a/tests/ui/author/repeat.stdout b/tests/ui/author/repeat.stdout index 1a608734ada9..f2c6b3f807f1 100644 --- a/tests/ui/author/repeat.stdout +++ b/tests/ui/author/repeat.stdout @@ -2,7 +2,7 @@ if let ExprKind::Repeat(value, length) = expr.kind && let ExprKind::Lit(ref lit) = value.kind && let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node && let ConstArgKind::Anon(anon_const) = length.kind - && expr1 = &cx.tcx.hir().body(anon_const.body).value + && expr1 = &cx.tcx.hir_body(anon_const.body).value && let ExprKind::Lit(ref lit1) = expr1.kind && let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node { From 91481e3bcf4df9bee2a61c99894096864b9d7e83 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Feb 2025 14:42:01 +1100 Subject: [PATCH 116/161] Overhaul the `intravisit::Map` trait. First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`. --- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/doc/mod.rs | 4 ++-- .../src/extra_unused_type_parameters.rs | 4 ++-- clippy_lints/src/from_over_into.rs | 4 ++-- clippy_lints/src/implicit_hasher.rs | 4 ++-- clippy_lints/src/index_refutable_slice.rs | 4 ++-- clippy_lints/src/lifetimes.rs | 8 ++++---- clippy_lints/src/loops/utils.rs | 4 ++-- .../src/loops/while_let_on_iterator.rs | 8 ++++---- clippy_lints/src/methods/needless_collect.rs | 4 ++-- .../src/methods/option_map_unwrap_or.rs | 8 ++++---- clippy_lints/src/methods/utils.rs | 4 ++-- clippy_lints/src/mutable_debug_assertion.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/unconditional_recursion.rs | 7 ++----- clippy_lints/src/unused_async.rs | 4 ++-- clippy_lints/src/unused_peekable.rs | 4 ++-- clippy_lints/src/unwrap.rs | 4 ++-- .../internal_lints/lint_without_lint_pass.rs | 2 +- clippy_lints/src/zombie_processes.rs | 4 ++-- clippy_utils/src/lib.rs | 4 ++-- clippy_utils/src/usage.rs | 4 ++-- clippy_utils/src/visitors.rs | 20 +++++++++---------- 24 files changed, 61 insertions(+), 64 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 91ddbb44ff89..db3e6034c5ba 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -437,8 +437,8 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { walk_expr(self, expr) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 36baf492a540..93c2b7a2d182 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1079,8 +1079,8 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> { // Panics in const blocks will cause compilation to fail. fn visit_anon_const(&mut self, _: &'tcx AnonConst) {} - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/extra_unused_type_parameters.rs b/clippy_lints/src/extra_unused_type_parameters.rs index 6ccea22e191c..6a217b6182ce 100644 --- a/clippy_lints/src/extra_unused_type_parameters.rs +++ b/clippy_lints/src/extra_unused_type_parameters.rs @@ -241,8 +241,8 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 167377972db9..41bf6e81916a 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -134,8 +134,8 @@ impl<'tcx> Visitor<'tcx> for SelfFinder<'_, 'tcx> { type Result = ControlFlow<()>; type NestedFilter = OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) -> Self::Result { diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index 1b39663f4f81..d2545e57652a 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -363,7 +363,7 @@ impl<'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'_, '_, 'tcx> { walk_expr(self, e); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 15650c4f7329..deac51ab4c49 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -223,8 +223,8 @@ struct SliceIndexLintingVisitor<'a, 'tcx> { impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 8eb45109d68c..f08812017b9c 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -19,8 +19,8 @@ use rustc_hir::{ WherePredicateKind, lang_items, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter as middle_nested_filter; +use rustc_middle::ty::TyCtxt; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; @@ -582,7 +582,7 @@ impl<'tcx, F> Visitor<'tcx> for LifetimeChecker<'_, 'tcx, F> where F: NestedFilter<'tcx>, { - type Map = Map<'tcx>; + type MaybeTyCtxt = TyCtxt<'tcx>; type NestedFilter = F; // for lifetimes as parameters of generics @@ -628,8 +628,8 @@ where self.lifetime_elision_impossible = false; } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 51fde5288ab9..a5185d38e7c3 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -240,8 +240,8 @@ impl<'tcx> Visitor<'tcx> for InitializeVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index e31b474c83f6..6000ff7a3609 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -245,8 +245,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & impl<'tcx> Visitor<'tcx> for AfterLoopVisitor<'_, '_, 'tcx> { type NestedFilter = OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result { @@ -288,8 +288,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & } impl<'tcx> Visitor<'tcx> for NestedLoopVisitor<'_, '_, 'tcx> { type NestedFilter = OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_local(&mut self, l: &'tcx LetStmt<'_>) { diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 5664ffba1a0e..45f79dd44f2a 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -456,8 +456,8 @@ impl<'tcx> Visitor<'tcx> for UsedCountVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 7c4dc4ffb202..4a8a221e8c36 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -143,8 +143,8 @@ impl<'tcx> Visitor<'tcx> for UnwrapVisitor<'_, 'tcx> { walk_path(self, path); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } @@ -174,7 +174,7 @@ impl<'tcx> Visitor<'tcx> for ReferenceVisitor<'_, 'tcx> { rustc_hir::intravisit::walk_expr(self, expr) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 6e39e7be2c43..3611b341897a 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -89,8 +89,8 @@ struct CloneOrCopyVisitor<'cx, 'tcx> { impl<'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index 152635a5c35c..13a23a13b9c2 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -119,7 +119,7 @@ impl<'tcx> Visitor<'tcx> for MutArgVisitor<'_, 'tcx> { walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 7fba4b6a6c8b..9b241edf4ccf 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -583,8 +583,8 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ } impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_anon_const(&mut self, _: &'tcx AnonConst) {} diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 54e507655e9c..1498a49a7a4a 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -241,8 +241,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { hir_visit::walk_expr(self, expr); } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 }; diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 16fe035802fa..529f85be3720 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -9,7 +9,6 @@ use rustc_hir::intravisit::{FnKind, Visitor, walk_body, walk_expr}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind}; use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, AssocKind, Ty, TyCtxt}; use rustc_session::impl_lint_pass; @@ -275,7 +274,6 @@ fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>, struct CheckCalls<'a, 'tcx> { cx: &'a LateContext<'tcx>, - map: Map<'tcx>, implemented_ty_id: DefId, method_span: Span, } @@ -287,8 +285,8 @@ where type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.map + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) -> ControlFlow<()> { @@ -380,7 +378,6 @@ impl UnconditionalRecursion { { let mut c = CheckCalls { cx, - map: cx.tcx.hir(), implemented_ty_id, method_span, }; diff --git a/clippy_lints/src/unused_async.rs b/clippy_lints/src/unused_async.rs index d00bd7f2b3db..1c1c841e9641 100644 --- a/clippy_lints/src/unused_async.rs +++ b/clippy_lints/src/unused_async.rs @@ -101,8 +101,8 @@ impl<'tcx> Visitor<'tcx> for AsyncFnVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 71aa57e0a14c..0f9b05c84d4b 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -112,8 +112,8 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { type NestedFilter = OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> { diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 6a952c0d97aa..76b9bbbd32fd 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -374,8 +374,8 @@ impl<'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index 315c83507d07..e31da9e9f611 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -277,7 +277,7 @@ impl<'tcx> Visitor<'tcx> for LintCollector<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { self.cx.tcx.hir() } } diff --git a/clippy_lints/src/zombie_processes.rs b/clippy_lints/src/zombie_processes.rs index 4df34891a2b1..9bd00b1e5c8c 100644 --- a/clippy_lints/src/zombie_processes.rs +++ b/clippy_lints/src/zombie_processes.rs @@ -249,8 +249,8 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> { walk_expr(self, ex) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index c4ba4c94c946..ccf32f42a47b 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1370,8 +1370,8 @@ impl<'tcx> Visitor<'tcx> for ContainsName<'_, 'tcx> { } } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index 37f729668925..3bf518f7fe70 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -133,8 +133,8 @@ impl<'tcx> Visitor<'tcx> for BindingUsageFinder<'_, 'tcx> { ControlFlow::Continue(()) } - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 9b35ecee1dd1..2ac0efd7e392 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -154,8 +154,8 @@ pub fn for_each_expr<'tcx, B, C: Continue>( type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow; - fn nested_visit_map(&mut self) -> Self::Map { - self.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) -> Self::Result { @@ -412,8 +412,8 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow<()>; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result { match e.kind { @@ -477,8 +477,8 @@ pub fn contains_unsafe_block<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) impl<'tcx> Visitor<'tcx> for V<'_, 'tcx> { type Result = ControlFlow<()>; type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_block(&mut self, b: &'tcx Block<'_>) -> Self::Result { @@ -544,8 +544,8 @@ pub fn for_each_local_use_after_expr<'tcx, B>( } impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow, B> Visitor<'tcx> for V<'_, 'tcx, F, B> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) { @@ -729,8 +729,8 @@ pub fn for_each_local_assignment<'tcx, B>( } impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow, B> Visitor<'tcx> for V<'_, 'tcx, F, B> { type NestedFilter = nested_filter::OnlyBodies; - fn nested_visit_map(&mut self) -> Self::Map { - self.cx.tcx.hir() + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.cx.tcx } fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) { From 822e45b1862956eb51fd3624604cbc6abf89f49a Mon Sep 17 00:00:00 2001 From: Fridtjof Stoldt Date: Mon, 17 Feb 2025 11:55:44 +0100 Subject: [PATCH 117/161] "Typo Catch Check" passed by @flip1995 This was *totally* intentional to check if this would get caught :P Co-authored-by: Philipp Krones --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7e5ae92ca8..f25c5b061f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ Current stable, released 2025-02-20 [if_let_rescope](https://github.com/rust-lang/rust/issues/131154) was stabilized [#13695](https://github.com/rust-lang/rust-clippy/pull/13695) * [`format_in_format_args`], [`recursive_format_impl`], [`to_string_in_format_args`], - [`uninlined_format_args`], [`unused_format_specs`]: Can now support 3er party format macros + [`uninlined_format_args`], [`unused_format_specs`]: Can now support 3rd party format macros if they're marked with the `#[clippy::format_args]` attribute [#9948](https://github.com/rust-lang/rust-clippy/pull/9948) From 66d19d84ae1a83bba0317e2c991cadb2ab28a064 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 17 Feb 2025 15:22:46 +0100 Subject: [PATCH 118/161] =?UTF-8?q?`manual=5Fok=5Ferr`:=20blockify=20the?= =?UTF-8?q?=20replacement=20of=20an=20`else=20if=20=E2=80=A6`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the part being replaced is an `if` expression following an `else`, the replacement expression must be blockified. --- clippy_lints/src/matches/manual_ok_err.rs | 15 +++++++++++++-- tests/ui/manual_ok_err.fixed | 9 +++++++++ tests/ui/manual_ok_err.rs | 11 +++++++++++ tests/ui/manual_ok_err.stderr | 20 +++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/matches/manual_ok_err.rs b/clippy_lints/src/matches/manual_ok_err.rs index 3deaaf96c1e8..576e42a564c2 100644 --- a/clippy_lints/src/matches/manual_ok_err.rs +++ b/clippy_lints/src/matches/manual_ok_err.rs @@ -1,7 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::{indent_of, reindent_multiline}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::option_arg_ty; -use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks, span_contains_comment}; +use clippy_utils::{get_parent_expr, is_res_lang_ctor, path_res, peel_blocks, span_contains_comment}; use rustc_ast::BindingMode; use rustc_errors::Applicability; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr}; @@ -132,13 +133,23 @@ fn apply_lint(cx: &LateContext<'_>, expr: &Expr<'_>, scrutinee: &Expr<'_>, is_ok Applicability::MachineApplicable }; let scrut = Sugg::hir_with_applicability(cx, scrutinee, "..", &mut app).maybe_par(); + let sugg = format!("{scrut}.{method}()"); + // If the expression being expanded is the `if …` part of an `else if …`, it must be blockified. + let sugg = if let Some(parent_expr) = get_parent_expr(cx, expr) + && let ExprKind::If(_, _, Some(else_part)) = parent_expr.kind + && else_part.hir_id == expr.hir_id + { + reindent_multiline(&format!("{{\n {sugg}\n}}"), true, indent_of(cx, parent_expr.span)) + } else { + sugg + }; span_lint_and_sugg( cx, MANUAL_OK_ERR, expr.span, format!("manual implementation of `{method}`"), "replace with", - format!("{scrut}.{method}()"), + sugg, app, ); } diff --git a/tests/ui/manual_ok_err.fixed b/tests/ui/manual_ok_err.fixed index e7e0464c4787..bc169b64be9f 100644 --- a/tests/ui/manual_ok_err.fixed +++ b/tests/ui/manual_ok_err.fixed @@ -89,3 +89,12 @@ const fn cf(x: Result) -> Option { Err(_) => None, } } + +fn issue14239() { + let _ = if false { + None + } else { + "1".parse::().ok() + }; + //~^^^^^ manual_ok_err +} diff --git a/tests/ui/manual_ok_err.rs b/tests/ui/manual_ok_err.rs index 77300b7af539..03c730d4b4e4 100644 --- a/tests/ui/manual_ok_err.rs +++ b/tests/ui/manual_ok_err.rs @@ -125,3 +125,14 @@ const fn cf(x: Result) -> Option { Err(_) => None, } } + +fn issue14239() { + let _ = if false { + None + } else if let Ok(n) = "1".parse::() { + Some(n) + } else { + None + }; + //~^^^^^ manual_ok_err +} diff --git a/tests/ui/manual_ok_err.stderr b/tests/ui/manual_ok_err.stderr index f10f52cc4c97..13fceacda107 100644 --- a/tests/ui/manual_ok_err.stderr +++ b/tests/ui/manual_ok_err.stderr @@ -93,5 +93,23 @@ LL | | _ => None, LL | | }; | |_____^ help: replace with: `(-S).ok()` -error: aborting due to 8 previous errors +error: manual implementation of `ok` + --> tests/ui/manual_ok_err.rs:132:12 + | +LL | } else if let Ok(n) = "1".parse::() { + | ____________^ +LL | | Some(n) +LL | | } else { +LL | | None +LL | | }; + | |_____^ + | +help: replace with + | +LL ~ } else { +LL + "1".parse::().ok() +LL ~ }; + | + +error: aborting due to 9 previous errors From 01085cb16a78fb18bfdb0330180128e294f50eba Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 17 Feb 2025 10:36:08 -0500 Subject: [PATCH 119/161] Update mention of `ref_to_mut` to `invalid_reference_casting` This lint was renamed in 50da77521e922f17735b9d97461925ca0f3dec1c. While I'm here convert the list of separate lints into a proper list for ease of use and clarify which lints are in clippy and which are in rustc. --- clippy_lints/src/as_conversions.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 847653ed6e98..78102772927c 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -9,12 +9,24 @@ declare_clippy_lint! { /// Checks for usage of `as` conversions. /// /// Note that this lint is specialized in linting *every single* use of `as` - /// regardless of whether good alternatives exist or not. - /// If you want more precise lints for `as`, please consider using these separate lints: - /// `unnecessary_cast`, `cast_lossless/cast_possible_truncation/cast_possible_wrap/cast_precision_loss/cast_sign_loss`, - /// `fn_to_numeric_cast(_with_truncation)`, `char_lit_as_u8`, `ref_to_mut` and `ptr_as_ptr`. - /// There is a good explanation the reason why this lint should work in this way and how it is useful - /// [in this issue](https://github.com/rust-lang/rust-clippy/issues/5122). + /// regardless of whether good alternatives exist or not. If you want more + /// precise lints for `as`, please consider using these separate lints: + /// + /// - clippy::cast_lossless + /// - clippy::cast_possible_truncation + /// - clippy::cast_possible_wrap + /// - clippy::cast_precision_loss + /// - clippy::cast_sign_loss + /// - clippy::char_lit_as_u8 + /// - clippy::fn_to_numeric_cast + /// - clippy::fn_to_numeric_cast_with_truncation + /// - clippy::ptr_as_ptr + /// - clippy::unnecessary_cast + /// - invalid_reference_casting + /// + /// There is a good explanation the reason why this lint should work in this + /// way and how it is useful [in this + /// issue](https://github.com/rust-lang/rust-clippy/issues/5122). /// /// ### Why restrict this? /// `as` conversions will perform many kinds of From 835e6a694b543af769c84a99659505b2418d640e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 17 Feb 2025 14:17:57 +1100 Subject: [PATCH 120/161] Move methods from `Map` to `TyCtxt`, part 2. Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that. --- clippy_lints/src/default_numeric_fallback.rs | 3 +-- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/functions/impl_trait_in_params.rs | 4 ++-- clippy_lints/src/functions/renamed_function_params.rs | 2 +- clippy_lints/src/manual_float_methods.rs | 2 +- clippy_lints/src/methods/option_map_unwrap_or.rs | 3 +-- clippy_lints/src/needless_borrows_for_generic_args.rs | 4 ++-- clippy_lints/src/needless_pass_by_ref_mut.rs | 2 +- clippy_lints/src/operators/arithmetic_side_effects.rs | 8 ++++---- clippy_lints/src/operators/numeric_arithmetic.rs | 8 ++++---- clippy_lints/src/redundant_locals.rs | 2 +- clippy_lints/src/shadow.rs | 8 +++----- clippy_lints/src/single_call_fn.rs | 3 +-- .../src/transmute/missing_transmute_annotations.rs | 4 ++-- clippy_lints/src/unconditional_recursion.rs | 4 ++-- clippy_lints/src/utils/author.rs | 3 +-- .../src/utils/internal_lints/lint_without_lint_pass.rs | 2 +- clippy_utils/src/lib.rs | 10 ++++------ clippy_utils/src/mir/mod.rs | 4 ++-- clippy_utils/src/ty/mod.rs | 4 ++-- 20 files changed, 37 insertions(+), 45 deletions(-) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 772268e7899e..784214c29af9 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -52,11 +52,10 @@ declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]); impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { - let hir = cx.tcx.hir(); // NOTE: this is different from `clippy_utils::is_inside_always_const_context`. // Inline const supports type inference. let is_parent_const = matches!( - hir.body_const_context(hir.body_owner_def_id(body.id())), + cx.tcx.hir_body_const_context(cx.tcx.hir_body_owner_def_id(body.id())), Some(ConstContext::Const { inline: false } | ConstContext::Static(_)) ); let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const); diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index a090a987d4fc..2e1f8ac615a2 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant { if let ItemKind::Enum(def, _) = &item.kind { for var in def.variants { if let Some(anon_const) = &var.disr_expr { - let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); + let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body); let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity(); let constant = cx .tcx diff --git a/clippy_lints/src/functions/impl_trait_in_params.rs b/clippy_lints/src/functions/impl_trait_in_params.rs index 6d1c55d06938..cb83b1395d26 100644 --- a/clippy_lints/src/functions/impl_trait_in_params.rs +++ b/clippy_lints/src/functions/impl_trait_in_params.rs @@ -39,7 +39,7 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: &'tcx Body<'_>, hir_id: HirId) { if let FnKind::ItemFn(_, generics, _) = kind - && cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public() + && cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, hir_id) { for param in generics.params { @@ -57,7 +57,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { && let hir::Impl { of_trait, .. } = *impl_ && of_trait.is_none() && let body = cx.tcx.hir_body(body_id) - && cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public() + && cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, impl_item.hir_id()) { for param in impl_item.generics.params { diff --git a/clippy_lints/src/functions/renamed_function_params.rs b/clippy_lints/src/functions/renamed_function_params.rs index ac2e866e4ff7..5ad83f886e2e 100644 --- a/clippy_lints/src/functions/renamed_function_params.rs +++ b/clippy_lints/src/functions/renamed_function_params.rs @@ -22,7 +22,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored && let Some(did) = trait_item_def_id_of_impl(items, item.owner_id) && !is_from_ignored_trait(trait_ref, ignored_traits) { - let mut param_idents_iter = cx.tcx.hir().body_param_names(body_id); + let mut param_idents_iter = cx.tcx.hir_body_param_names(body_id); let mut default_param_idents_iter = cx.tcx.fn_arg_names(did).iter().copied(); let renames = RenamedFnArgs::new(&mut default_param_idents_iter, &mut param_idents_iter); diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 052e6502da92..2a5aa12d126c 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { && exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2 && !expr.span.in_external_macro(cx.sess().source_map()) && ( - is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into()) + is_not_const(cx.tcx, cx.tcx.hir_enclosing_body_owner(expr.hir_id).into()) || self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY) ) && let [first, second, const_1, const_2] = exprs diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 4a8a221e8c36..b1107d8cc72f 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -58,8 +58,7 @@ pub(super) fn check<'tcx>( unwrap_or_span: unwrap_arg.span, }; - let map = cx.tcx.hir(); - let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id)); + let body = cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id)); // Visit the body, and return if we've found a reference if reference_visitor.visit_body(body).is_break() { diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 7f91e555054d..ea1d7e5d4382 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { if self .possible_borrowers .last() - .is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir().body_owner_def_id(body.id())) + .is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir_body_owner_def_id(body.id())) { self.possible_borrowers.pop(); } @@ -359,7 +359,7 @@ fn referent_used_exactly_once<'tcx>( && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind && !place.is_indirect_first_projection() { - let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id); + let body_owner_local_def_id = cx.tcx.hir_enclosing_body_owner(reference.hir_id); if possible_borrowers .last() .is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 6a1dc5e41a07..5e85d23718a9 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -352,7 +352,7 @@ impl MutablyUsedVariablesCtxt<'_> { fn is_in_unsafe_block(&self, item: HirId) -> bool { let hir = self.tcx.hir(); for (parent, node) in hir.parent_iter(item) { - if let Some(fn_sig) = hir.fn_sig_by_hir_id(parent) { + if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) { return fn_sig.header.is_unsafe(); } else if let Node::Block(block) = node { if matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) { diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 9d07a14718da..594101427f5a 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -349,10 +349,10 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { } fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); + let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id()); - let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id); + let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id); if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind { let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span @@ -365,7 +365,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects { } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); let body_span = cx.tcx.hir().span(body_owner); if let Some(span) = self.const_span && span.contains(body_span) diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index 2083f2bf628d..cda99a362dca 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -68,10 +68,10 @@ impl Context { } pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); - let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); + let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id()); - match cx.tcx.hir().body_owner_kind(body_owner_def_id) { + match cx.tcx.hir_body_owner_kind(body_owner_def_id) { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => { let body_span = cx.tcx.hir().span_with_body(body_owner); @@ -87,7 +87,7 @@ impl Context { } pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { - let body_owner = cx.tcx.hir().body_owner(body.id()); + let body_owner = cx.tcx.hir_body_owner(body.id()); let body_span = cx.tcx.hir().span_with_body(body_owner); if let Some(span) = self.const_span { diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index ebe3e7c20196..e15e12629209 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { /// assert_static(closure); /// ``` fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_variable: HirId) -> bool { - let closure_def_id = cx.tcx.hir().enclosing_body_owner(redefinition); + let closure_def_id = cx.tcx.hir_enclosing_body_owner(redefinition); cx.tcx.is_closure_like(closure_def_id.to_def_id()) && cx.tcx.closure_captures(closure_def_id).iter().any(|c| { diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 83199ba0f707..a931e39bac9c 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -149,17 +149,15 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { } fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { - let hir = cx.tcx.hir(); - let owner_id = hir.body_owner_def_id(body.id()); - if !matches!(hir.body_owner_kind(owner_id), BodyOwnerKind::Closure) { + let owner_id = cx.tcx.hir_body_owner_def_id(body.id()); + if !matches!(cx.tcx.hir_body_owner_kind(owner_id), BodyOwnerKind::Closure) { self.bindings.push((FxHashMap::default(), owner_id)); } } fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { - let hir = cx.tcx.hir(); if !matches!( - hir.body_owner_kind(hir.body_owner_def_id(body.id())), + cx.tcx.hir_body_owner_kind(cx.tcx.hir_body_owner_def_id(body.id())), BodyOwnerKind::Closure ) { self.bindings.pop(); diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index fdbccbaa8a59..1a2fb77acc15 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -90,8 +90,7 @@ impl SingleCallFn { || fn_span.in_external_macro(cx.sess().source_map()) || cx .tcx - .hir() - .maybe_body_owned_by(fn_def_id) + .hir_maybe_body_owned_by(fn_def_id) .is_none_or(|body| is_in_test_function(cx.tcx, body.value.hir_id)) || match cx.tcx.hir_node(fn_hir_id) { Node::Item(item) => is_from_proc_macro(cx, item), diff --git a/clippy_lints/src/transmute/missing_transmute_annotations.rs b/clippy_lints/src/transmute/missing_transmute_annotations.rs index 4961dd6b280a..0b5d83ef58ca 100644 --- a/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -28,8 +28,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) } fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool { - let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id); - if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) { + let def_id = cx.tcx.hir_enclosing_body_owner(expr_hir_id); + if let Some(body) = cx.tcx.hir_maybe_body_owned_by(def_id) { return body.value.peel_blocks().hir_id == expr_hir_id; } false diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 529f85be3720..76a0b927df42 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -331,8 +331,8 @@ impl UnconditionalRecursion { && let [return_expr] = get_return_calls_in_body(body).as_slice() && let ExprKind::Call(call_expr, _) = return_expr.kind // We need to use typeck here to infer the actual function being called. - && let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id) - && let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id) + && let body_def_id = cx.tcx.hir_enclosing_body_owner(call_expr.hir_id) + && let Some(body_owner) = cx.tcx.hir_maybe_body_owned_by(body_def_id) && let typeck = cx.tcx.typeck_body(body_owner.id()) && let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id) { diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index ce489054e16e..5fc166438e84 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -132,8 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { } fn check_item(cx: &LateContext<'_>, hir_id: HirId) { - let hir = cx.tcx.hir(); - if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) { + if let Some(body) = cx.tcx.hir_maybe_body_owned_by(hir_id.expect_owner().def_id) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", body.value)); }); diff --git a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs index e31da9e9f611..d6f10f1e4b80 100644 --- a/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs +++ b/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs @@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { output: &mut self.registered_lints, cx, }; - let body = cx.tcx.hir().body_owned_by( + let body = cx.tcx.hir_body_owned_by( impl_item_refs .iter() .find(|iiref| iiref.ident.as_str() == "lint_vec") diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index ccf32f42a47b..15e395731ade 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -237,8 +237,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool { debug_assert!(cx.enclosing_body.is_some(), "`LateContext` has no enclosing body"); cx.enclosing_body.is_some_and(|id| { cx.tcx - .hir() - .body_const_context(cx.tcx.hir().body_owner_def_id(id)) + .hir_body_const_context(cx.tcx.hir_body_owner_def_id(id)) .is_some() }) } @@ -251,8 +250,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool { /// * associated constants pub fn is_inside_always_const_context(tcx: TyCtxt<'_>, hir_id: HirId) -> bool { use ConstContext::{Const, ConstFn, Static}; - let hir = tcx.hir(); - let Some(ctx) = hir.body_const_context(hir.enclosing_body_owner(hir_id)) else { + let Some(ctx) = tcx.hir_body_const_context(tcx.hir_enclosing_body_owner(hir_id)) else { return false; }; match ctx { @@ -1648,7 +1646,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool if is_integer_literal(e, value) { return true; } - let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id); + let enclosing_body = cx.tcx.hir_enclosing_body_owner(e.hir_id); if let Some(Constant::Int(v)) = ConstEvalCtxt::with_env(cx.tcx, cx.typing_env(), cx.tcx.typeck(enclosing_body)).eval(e) { @@ -2762,7 +2760,7 @@ impl<'tcx> ExprUseCtxt<'tcx> { Node::Expr(use_expr) => match use_expr.kind { ExprKind::Ret(_) => ExprUseNode::Return(OwnerId { - def_id: cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()), + def_id: cx.tcx.hir_body_owner_def_id(cx.enclosing_body.unwrap()), }), ExprKind::Closure(closure) => ExprUseNode::Return(OwnerId { def_id: closure.def_id }), diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index 85250f81dc47..637c0bafd964 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -136,8 +136,8 @@ pub fn used_exactly_once(mir: &Body<'_>, local: Local) -> Option { /// Returns the `mir::Body` containing the node associated with `hir_id`. #[allow(clippy::module_name_repetitions)] pub fn enclosing_mir(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<&Body<'_>> { - let body_owner_local_def_id = tcx.hir().enclosing_body_owner(hir_id); - if tcx.hir().body_owner_kind(body_owner_local_def_id).is_fn_or_closure() { + let body_owner_local_def_id = tcx.hir_enclosing_body_owner(hir_id); + if tcx.hir_body_owner_kind(body_owner_local_def_id).is_fn_or_closure() { Some(tcx.optimized_mir(body_owner_local_def_id.to_def_id())) } else { None diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index a5374f6904e3..8eef6a7f57ed 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -267,7 +267,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // through calling `body_owner_kind`, which would panic if the callee // does not have a body. if let Some(callee_id) = callee_id { - let _ = tcx.hir().body_owner_kind(callee_id); + let _ = tcx.hir_body_owner_kind(callee_id); } let ty = tcx.erase_regions(ty); @@ -705,7 +705,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { let decl = id .as_local() - .and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id))); + .and_then(|id| cx.tcx.hir_fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id))); Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) }, ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), From 758ec1d33239ac0d7c8b427a7945e75900cdb689 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 18 Feb 2025 11:04:53 +0100 Subject: [PATCH 121/161] remove an unneeded `#![feature]` --- clippy_lints/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 6708be5b332c..5349b27de4a3 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,5 +1,4 @@ #![feature(array_windows)] -#![feature(binary_heap_into_iter_sorted)] #![feature(box_patterns)] #![feature(macro_metavar_expr_concat)] #![feature(f128)] From 45f7a60d313f75709690bfcb1cc4232d0f44ed3f Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 2 Feb 2025 17:16:36 +0100 Subject: [PATCH 122/161] `.last()` to `.next_back()` requires a mutable receiver In the case where `iter` is a `DoubleEndedIterator`, replacing a call to `iter.last()` (which consumes `iter`) by `iter.next_back()` (which requires a mutable reference to `iter`) cannot be done when `iter` Is not a mutable binding or a mutable reference. When `iter` is a local binding, it can be made mutable by fixing its definition site. --- .../src/methods/double_ended_iterator_last.rs | 42 ++++++++++--- tests/ui/double_ended_iterator_last.fixed | 30 +++++++-- tests/ui/double_ended_iterator_last.rs | 30 +++++++-- tests/ui/double_ended_iterator_last.stderr | 62 +++++++++++++++++-- .../double_ended_iterator_last_unfixable.rs | 8 +++ ...ouble_ended_iterator_last_unfixable.stderr | 18 ++++++ 6 files changed, 169 insertions(+), 21 deletions(-) create mode 100644 tests/ui/double_ended_iterator_last_unfixable.rs create mode 100644 tests/ui/double_ended_iterator_last_unfixable.stderr diff --git a/clippy_lints/src/methods/double_ended_iterator_last.rs b/clippy_lints/src/methods/double_ended_iterator_last.rs index 208172980c9f..19797cc32f59 100644 --- a/clippy_lints/src/methods/double_ended_iterator_last.rs +++ b/clippy_lints/src/methods/double_ended_iterator_last.rs @@ -1,8 +1,8 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_trait_method; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::implements_trait; +use clippy_utils::{is_mutable, is_trait_method, path_to_local}; use rustc_errors::Applicability; -use rustc_hir::Expr; +use rustc_hir::{Expr, Node, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty::Instance; use rustc_span::{Span, sym}; @@ -28,14 +28,40 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, self_expr: &'_ Exp // if the resolved method is the same as the provided definition && fn_def.def_id() == last_def.def_id { - span_lint_and_sugg( + let mut sugg = vec![(call_span, String::from("next_back()"))]; + let mut dont_apply = false; + // if `self_expr` is a reference, it is mutable because it is used for `.last()` + if !(is_mutable(cx, self_expr) || self_type.is_ref()) { + if let Some(hir_id) = path_to_local(self_expr) + && let Node::Pat(pat) = cx.tcx.hir_node(hir_id) + && let PatKind::Binding(_, _, ident, _) = pat.kind + { + sugg.push((ident.span.shrink_to_lo(), String::from("mut "))); + } else { + // If we can't make the binding mutable, make the suggestion `Unspecified` to prevent it from being + // automatically applied, and add a complementary help message. + dont_apply = true; + } + } + span_lint_and_then( cx, DOUBLE_ENDED_ITERATOR_LAST, - call_span, + expr.span, "called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator", - "try", - "next_back()".to_string(), - Applicability::MachineApplicable, + |diag| { + diag.multipart_suggestion( + "try", + sugg, + if dont_apply { + Applicability::Unspecified + } else { + Applicability::MachineApplicable + }, + ); + if dont_apply { + diag.span_note(self_expr.span, "this must be made mutable to use `.next_back()`"); + } + }, ); } } diff --git a/tests/ui/double_ended_iterator_last.fixed b/tests/ui/double_ended_iterator_last.fixed index 08f3d4907153..09eba48ea89a 100644 --- a/tests/ui/double_ended_iterator_last.fixed +++ b/tests/ui/double_ended_iterator_last.fixed @@ -2,8 +2,7 @@ // Typical case pub fn last_arg(s: &str) -> Option<&str> { - s.split(' ').next_back() - //~^ double_ended_iterator_last + s.split(' ').next_back() //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` } fn main() { @@ -20,8 +19,7 @@ fn main() { Some(()) } } - let _ = DeIterator.next_back(); - //~^ double_ended_iterator_last + let _ = DeIterator.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` // Should not apply to other methods of Iterator let _ = DeIterator.count(); @@ -53,3 +51,27 @@ fn main() { } let _ = CustomLast.last(); } + +fn issue_14139() { + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let subindex = &mut subindex; + let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let subindex = &mut subindex; + let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let (mut subindex, _) = (index.by_ref().take(3), 42); + let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` +} diff --git a/tests/ui/double_ended_iterator_last.rs b/tests/ui/double_ended_iterator_last.rs index 2c2f311805ef..2bde5e3ecb31 100644 --- a/tests/ui/double_ended_iterator_last.rs +++ b/tests/ui/double_ended_iterator_last.rs @@ -2,8 +2,7 @@ // Typical case pub fn last_arg(s: &str) -> Option<&str> { - s.split(' ').last() - //~^ double_ended_iterator_last + s.split(' ').last() //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` } fn main() { @@ -20,8 +19,7 @@ fn main() { Some(()) } } - let _ = DeIterator.last(); - //~^ double_ended_iterator_last + let _ = DeIterator.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` // Should not apply to other methods of Iterator let _ = DeIterator.count(); @@ -53,3 +51,27 @@ fn main() { } let _ = CustomLast.last(); } + +fn issue_14139() { + let mut index = [true, true, false, false, false, true].iter(); + let subindex = index.by_ref().take(3); + let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let subindex = &mut subindex; + let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let mut subindex = index.by_ref().take(3); + let subindex = &mut subindex; + let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + + let mut index = [true, true, false, false, false, true].iter(); + let (subindex, _) = (index.by_ref().take(3), 42); + let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` +} diff --git a/tests/ui/double_ended_iterator_last.stderr b/tests/ui/double_ended_iterator_last.stderr index ea1962176a61..6c900b078262 100644 --- a/tests/ui/double_ended_iterator_last.stderr +++ b/tests/ui/double_ended_iterator_last.stderr @@ -1,17 +1,69 @@ error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator - --> tests/ui/double_ended_iterator_last.rs:5:18 + --> tests/ui/double_ended_iterator_last.rs:5:5 | LL | s.split(' ').last() - | ^^^^^^ help: try: `next_back()` + | ^^^^^^^^^^^^^------ + | | + | help: try: `next_back()` | = note: `-D clippy::double-ended-iterator-last` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::double_ended_iterator_last)]` error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator - --> tests/ui/double_ended_iterator_last.rs:23:24 + --> tests/ui/double_ended_iterator_last.rs:22:13 | LL | let _ = DeIterator.last(); - | ^^^^^^ help: try: `next_back()` + | ^^^^^^^^^^^------ + | | + | help: try: `next_back()` -error: aborting due to 2 previous errors +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:58:13 + | +LL | let _ = subindex.last(); + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let mut subindex = index.by_ref().take(3); +LL ~ let _ = subindex.next_back(); + | + +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:62:13 + | +LL | let _ = subindex.last(); + | ^^^^^^^^^------ + | | + | help: try: `next_back()` + +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:67:13 + | +LL | let _ = subindex.last(); + | ^^^^^^^^^------ + | | + | help: try: `next_back()` + +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:72:13 + | +LL | let _ = subindex.last(); + | ^^^^^^^^^------ + | | + | help: try: `next_back()` + +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:76:13 + | +LL | let _ = subindex.last(); + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL ~ let (mut subindex, _) = (index.by_ref().take(3), 42); +LL ~ let _ = subindex.next_back(); + | + +error: aborting due to 7 previous errors diff --git a/tests/ui/double_ended_iterator_last_unfixable.rs b/tests/ui/double_ended_iterator_last_unfixable.rs new file mode 100644 index 000000000000..edc2a05649dd --- /dev/null +++ b/tests/ui/double_ended_iterator_last_unfixable.rs @@ -0,0 +1,8 @@ +//@no-rustfix +#![warn(clippy::double_ended_iterator_last)] + +fn main() { + let mut index = [true, true, false, false, false, true].iter(); + let subindex = (index.by_ref().take(3), 42); + let _ = subindex.0.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` +} diff --git a/tests/ui/double_ended_iterator_last_unfixable.stderr b/tests/ui/double_ended_iterator_last_unfixable.stderr new file mode 100644 index 000000000000..9dd3f9386481 --- /dev/null +++ b/tests/ui/double_ended_iterator_last_unfixable.stderr @@ -0,0 +1,18 @@ +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last_unfixable.rs:7:13 + | +LL | let _ = subindex.0.last(); + | ^^^^^^^^^^^------ + | | + | help: try: `next_back()` + | +note: this must be made mutable to use `.next_back()` + --> tests/ui/double_ended_iterator_last_unfixable.rs:7:13 + | +LL | let _ = subindex.0.last(); + | ^^^^^^^^^^ + = note: `-D clippy::double-ended-iterator-last` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_ended_iterator_last)]` + +error: aborting due to 1 previous error + From 939429a8b98b98d7a8f942f8e55b6b3639865497 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Wed, 19 Feb 2025 05:50:45 +0900 Subject: [PATCH 123/161] update `rustfix` link --- book/src/development/adding_lints.md | 2 +- book/src/development/writing_tests.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index 48506127dee4..60135e96c5a5 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -169,7 +169,7 @@ from the lint to the code of the test file and compare that to the contents of a Use `cargo bless` to automatically generate the `.fixed` file while running the tests. -[rustfix]: https://github.com/rust-lang/rustfix +[rustfix]: https://github.com/rust-lang/cargo/tree/master/crates/rustfix ## Testing manually diff --git a/book/src/development/writing_tests.md b/book/src/development/writing_tests.md index 39a5ad966885..d4cca2a72f0b 100644 --- a/book/src/development/writing_tests.md +++ b/book/src/development/writing_tests.md @@ -203,7 +203,7 @@ We'll talk about suggestions more in depth in a [later chapter](emitting_lints.m Use `cargo bless` to automatically generate the `.fixed` file after running the tests. -[`rustfix`]: https://github.com/rust-lang/rustfix +[`rustfix`]: https://github.com/rust-lang/cargo/tree/master/crates/rustfix [`span_lint_and_sugg`]: https://doc.rust-lang.org/beta/nightly-rustc/clippy_utils/diagnostics/fn.span_lint_and_sugg.html ## Testing Manually From e2cdfed0ea09e430f1b24351856b224eda3683d9 Mon Sep 17 00:00:00 2001 From: yanglsh Date: Wed, 5 Feb 2025 02:32:18 -0700 Subject: [PATCH 124/161] fix: `map_entry` FP on struct member --- clippy_lints/src/entry.rs | 17 ++++++++++++++++- tests/ui/entry.fixed | 23 +++++++++++++++++++++++ tests/ui/entry.rs | 23 +++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 99d635aa5cc0..f8a5cf53cda0 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -1,5 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{reindent_multiline, snippet_indent, snippet_with_applicability, snippet_with_context}; +use clippy_utils::visitors::for_each_expr; use clippy_utils::{ SpanlessEq, can_move_expr_to_closure_no_visit, higher, is_expr_final_block_expr, is_expr_used_or_unified, peel_hir_expr_while, @@ -12,6 +13,7 @@ use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::{DUMMY_SP, Span, SyntaxContext, sym}; +use std::ops::ControlFlow; declare_clippy_lint! { /// ### What it does @@ -500,7 +502,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { self.visit_non_tail_expr(insert_expr.value); self.is_single_insert = is_single_insert; }, - _ if SpanlessEq::new(self.cx).eq_expr(self.map, expr) => { + _ if is_any_expr_in_map_used(self.cx, self.map, expr) => { self.is_map_used = true; }, _ => match expr.kind { @@ -562,6 +564,19 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { } } +/// Check if the given expression is used for each sub-expression in the given map. +/// For example, in map `a.b.c.my_map`, The expression `a.b.c.my_map`, `a.b.c`, `a.b`, and `a` are +/// all checked. +fn is_any_expr_in_map_used<'tcx>(cx: &LateContext<'tcx>, map: &'tcx Expr<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { + for_each_expr(cx, map, |e| { + if SpanlessEq::new(cx).eq_expr(e, expr) { + return ControlFlow::Break(()); + } + ControlFlow::Continue(()) + }) + .is_some() +} + struct InsertSearchResults<'tcx> { edits: Vec>, allow_insert_closure: bool, diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index 9856fa9b39fd..d52299306fd0 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -195,4 +195,27 @@ fn issue12489(map: &mut HashMap) -> Option<()> { Some(()) } +mod issue13934 { + use std::collections::HashMap; + + struct Member {} + + pub struct Foo { + members: HashMap, + } + + impl Foo { + pub fn should_also_not_cause_lint(&mut self, input: u8) { + if self.members.contains_key(&input) { + todo!(); + } else { + self.other(); + self.members.insert(input, Member {}); + } + } + + fn other(&self) {} + } +} + fn main() {} diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index bb8ebb4eac08..25cd6eaa4132 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -201,4 +201,27 @@ fn issue12489(map: &mut HashMap) -> Option<()> { Some(()) } +mod issue13934 { + use std::collections::HashMap; + + struct Member {} + + pub struct Foo { + members: HashMap, + } + + impl Foo { + pub fn should_also_not_cause_lint(&mut self, input: u8) { + if self.members.contains_key(&input) { + todo!(); + } else { + self.other(); + self.members.insert(input, Member {}); + } + } + + fn other(&self) {} + } +} + fn main() {} From dcd643a6524f0f18a17df9fecb6e9821c1f5b33b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 14 Feb 2025 18:00:13 +0100 Subject: [PATCH 125/161] `double_ended_iterator_last`: note when drop order is changed `iter.last()` will drop all elements of `iter` in order, while `iter.next_back()` will drop the non-last elements of `iter` when `iter` goes out of scope since `.next_back()` does not consume its argument. When the transformation proposed by `double_ended_iterator_last` would concern an iterator whose element type has a significant drop, a note is added to warn about the possible drop order change, and the suggestion is switched from `MachineApplicable` to `MaybeIncorrect`. --- .../src/methods/double_ended_iterator_last.rs | 7 +++++++ tests/ui/double_ended_iterator_last.fixed | 15 +++++++++++++++ tests/ui/double_ended_iterator_last.rs | 15 +++++++++++++++ tests/ui/double_ended_iterator_last.stderr | 15 ++++++++++++++- .../ui/double_ended_iterator_last_unfixable.rs | 15 +++++++++++++++ .../double_ended_iterator_last_unfixable.stderr | 17 ++++++++++++++++- 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/double_ended_iterator_last.rs b/clippy_lints/src/methods/double_ended_iterator_last.rs index 19797cc32f59..e82211bbf3ef 100644 --- a/clippy_lints/src/methods/double_ended_iterator_last.rs +++ b/clippy_lints/src/methods/double_ended_iterator_last.rs @@ -49,15 +49,22 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, self_expr: &'_ Exp expr.span, "called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator", |diag| { + let expr_ty = cx.typeck_results().expr_ty(expr); + let droppable_elements = expr_ty.has_significant_drop(cx.tcx, cx.typing_env()); diag.multipart_suggestion( "try", sugg, if dont_apply { Applicability::Unspecified + } else if droppable_elements { + Applicability::MaybeIncorrect } else { Applicability::MachineApplicable }, ); + if droppable_elements { + diag.note("this change will alter drop order which may be undesirable"); + } if dont_apply { diag.span_note(self_expr.span, "this must be made mutable to use `.next_back()`"); } diff --git a/tests/ui/double_ended_iterator_last.fixed b/tests/ui/double_ended_iterator_last.fixed index 09eba48ea89a..17d0d71a8854 100644 --- a/tests/ui/double_ended_iterator_last.fixed +++ b/tests/ui/double_ended_iterator_last.fixed @@ -75,3 +75,18 @@ fn issue_14139() { let (mut subindex, _) = (index.by_ref().take(3), 42); let _ = subindex.next_back(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` } + +fn drop_order() { + struct S(&'static str); + impl std::ops::Drop for S { + fn drop(&mut self) { + println!("Dropping {}", self.0); + } + } + + let v = vec![S("one"), S("two"), S("three")]; + let mut v = v.into_iter(); + println!("Last element is {}", v.next_back().unwrap().0); + //~^ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + println!("Done"); +} diff --git a/tests/ui/double_ended_iterator_last.rs b/tests/ui/double_ended_iterator_last.rs index 2bde5e3ecb31..41bc669b1719 100644 --- a/tests/ui/double_ended_iterator_last.rs +++ b/tests/ui/double_ended_iterator_last.rs @@ -75,3 +75,18 @@ fn issue_14139() { let (subindex, _) = (index.by_ref().take(3), 42); let _ = subindex.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` } + +fn drop_order() { + struct S(&'static str); + impl std::ops::Drop for S { + fn drop(&mut self) { + println!("Dropping {}", self.0); + } + } + + let v = vec![S("one"), S("two"), S("three")]; + let v = v.into_iter(); + println!("Last element is {}", v.last().unwrap().0); + //~^ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + println!("Done"); +} diff --git a/tests/ui/double_ended_iterator_last.stderr b/tests/ui/double_ended_iterator_last.stderr index 6c900b078262..1702a24d7a05 100644 --- a/tests/ui/double_ended_iterator_last.stderr +++ b/tests/ui/double_ended_iterator_last.stderr @@ -65,5 +65,18 @@ LL ~ let (mut subindex, _) = (index.by_ref().take(3), 42); LL ~ let _ = subindex.next_back(); | -error: aborting due to 7 previous errors +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last.rs:89:36 + | +LL | println!("Last element is {}", v.last().unwrap().0); + | ^^^^^^^^ + | + = note: this change will alter drop order which may be undesirable +help: try + | +LL ~ let mut v = v.into_iter(); +LL ~ println!("Last element is {}", v.next_back().unwrap().0); + | + +error: aborting due to 8 previous errors diff --git a/tests/ui/double_ended_iterator_last_unfixable.rs b/tests/ui/double_ended_iterator_last_unfixable.rs index edc2a05649dd..3f125c7f20c1 100644 --- a/tests/ui/double_ended_iterator_last_unfixable.rs +++ b/tests/ui/double_ended_iterator_last_unfixable.rs @@ -6,3 +6,18 @@ fn main() { let subindex = (index.by_ref().take(3), 42); let _ = subindex.0.last(); //~ ERROR: called `Iterator::last` on a `DoubleEndedIterator` } + +fn drop_order() { + struct S(&'static str); + impl std::ops::Drop for S { + fn drop(&mut self) { + println!("Dropping {}", self.0); + } + } + + let v = vec![S("one"), S("two"), S("three")]; + let v = (v.into_iter(), 42); + println!("Last element is {}", v.0.last().unwrap().0); + //~^ ERROR: called `Iterator::last` on a `DoubleEndedIterator` + println!("Done"); +} diff --git a/tests/ui/double_ended_iterator_last_unfixable.stderr b/tests/ui/double_ended_iterator_last_unfixable.stderr index 9dd3f9386481..f4be757d00d2 100644 --- a/tests/ui/double_ended_iterator_last_unfixable.stderr +++ b/tests/ui/double_ended_iterator_last_unfixable.stderr @@ -14,5 +14,20 @@ LL | let _ = subindex.0.last(); = note: `-D clippy::double-ended-iterator-last` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::double_ended_iterator_last)]` -error: aborting due to 1 previous error +error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator + --> tests/ui/double_ended_iterator_last_unfixable.rs:20:36 + | +LL | println!("Last element is {}", v.0.last().unwrap().0); + | ^^^^------ + | | + | help: try: `next_back()` + | + = note: this change will alter drop order which may be undesirable +note: this must be made mutable to use `.next_back()` + --> tests/ui/double_ended_iterator_last_unfixable.rs:20:36 + | +LL | println!("Last element is {}", v.0.last().unwrap().0); + | ^^^ + +error: aborting due to 2 previous errors From 83f5cbad188a905ec5793002b36e5d27a7a20890 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Sun, 5 Jan 2025 13:34:27 +0100 Subject: [PATCH 126/161] add `owned_cow` lint --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/types/mod.rs | 62 ++++++++- clippy_lints/src/types/owned_cow.rs | 66 ++++++++++ tests/ui/owned_cow.fixed | 23 ++++ tests/ui/owned_cow.rs | 23 ++++ tests/ui/owned_cow.stderr | 41 ++++++ tests/ui/unnecessary_to_owned.fixed | 3 +- tests/ui/unnecessary_to_owned.rs | 3 +- tests/ui/unnecessary_to_owned.stderr | 186 +++++++++++++-------------- 12 files changed, 315 insertions(+), 96 deletions(-) create mode 100644 clippy_lints/src/types/owned_cow.rs create mode 100644 tests/ui/owned_cow.fixed create mode 100644 tests/ui/owned_cow.rs create mode 100644 tests/ui/owned_cow.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8695f66279..a4d20b2586ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5942,6 +5942,7 @@ Released 2018-09-13 [`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing [`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional [`overly_complex_bool_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#overly_complex_bool_expr +[`owned_cow`]: https://rust-lang.github.io/rust-clippy/master/index.html#owned_cow [`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic [`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn [`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 0e264cdcd4a3..1fb59ca85fe8 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -380,6 +380,7 @@ Suppress lints whenever the suggested change would cause breakage for other crat * [`linkedlist`](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist) * [`needless_pass_by_ref_mut`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut) * [`option_option`](https://rust-lang.github.io/rust-clippy/master/index.html#option_option) +* [`owned_cow`](https://rust-lang.github.io/rust-clippy/master/index.html#owned_cow) * [`rc_buffer`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer) * [`rc_mutex`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex) * [`redundant_allocation`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index cac4408fff0e..9436ba7f1809 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -438,6 +438,7 @@ define_Conf! { linkedlist, needless_pass_by_ref_mut, option_option, + owned_cow, rc_buffer, rc_mutex, redundant_allocation, diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 4b439d3a7a2d..011eed25552c 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -745,6 +745,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::types::BOX_COLLECTION_INFO, crate::types::LINKEDLIST_INFO, crate::types::OPTION_OPTION_INFO, + crate::types::OWNED_COW_INFO, crate::types::RC_BUFFER_INFO, crate::types::RC_MUTEX_INFO, crate::types::REDUNDANT_ALLOCATION_INFO, diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 579cbf447a2b..7385b13578da 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -2,6 +2,7 @@ mod borrowed_box; mod box_collection; mod linked_list; mod option_option; +mod owned_cow; mod rc_buffer; mod rc_mutex; mod redundant_allocation; @@ -355,13 +356,63 @@ declare_clippy_lint! { "usage of `Rc>`" } +declare_clippy_lint! { + /// ### What it does + /// Detects needlessly owned `Cow` types. + /// + /// ### Why is this bad? + /// The borrowed types are usually more flexible, in that e.g. a + /// `Cow<'_, str>` can accept both `&str` and `String` while + /// `Cow<'_, String>` can only accept `&String` and `String`. In + /// particular, `&str` is more general, because it allows for string + /// literals while `&String` can only be borrowed from a heap-owned + /// `String`). + /// + /// ### Known Problems + /// The lint does not check for usage of the type. There may be external + /// interfaces that require the use of an owned type. + /// + /// At least the `CString` type also has a different API than `CStr`: The + /// former has an `as_bytes` method which the latter calls `to_bytes`. + /// There is no guarantee that other types won't gain additional methods + /// leading to a similar mismatch. + /// + /// In addition, the lint only checks for the known problematic types + /// `String`, `Vec<_>`, `CString`, `OsString` and `PathBuf`. Custom types + /// that implement `ToOwned` will not be detected. + /// + /// ### Example + /// ```no_run + /// let wrogn: std::borrow::Cow<'_, Vec>; + /// ``` + /// Use instead: + /// ```no_run + /// let right: std::borrow::Cow<'_, [u8]>; + /// ``` + #[clippy::version = "1.85.0"] + pub OWNED_COW, + style, + "needlessly owned Cow type" +} + pub struct Types { vec_box_size_threshold: u64, type_complexity_threshold: u64, avoid_breaking_exported_api: bool, } -impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX, REDUNDANT_ALLOCATION, RC_BUFFER, RC_MUTEX, TYPE_COMPLEXITY]); +impl_lint_pass!(Types => [ + BOX_COLLECTION, + VEC_BOX, + OPTION_OPTION, + LINKEDLIST, + BORROWED_BOX, + REDUNDANT_ALLOCATION, + RC_BUFFER, + RC_MUTEX, + TYPE_COMPLEXITY, + OWNED_COW +]); impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn( @@ -561,6 +612,7 @@ impl Types { triggered |= option_option::check(cx, hir_ty, qpath, def_id); triggered |= linked_list::check(cx, hir_ty, def_id); triggered |= rc_mutex::check(cx, hir_ty, qpath, def_id); + triggered |= owned_cow::check(cx, qpath, def_id); if triggered { return; @@ -612,6 +664,14 @@ impl Types { QPath::LangItem(..) => {}, } }, + TyKind::Path(ref qpath) => { + let res = cx.qpath_res(qpath, hir_ty.hir_id); + if let Some(def_id) = res.opt_def_id() + && self.is_type_change_allowed(context) + { + owned_cow::check(cx, qpath, def_id); + } + }, TyKind::Ref(lt, ref mut_ty) => { context.is_nested_call = true; if !borrowed_box::check(cx, hir_ty, lt, mut_ty) { diff --git a/clippy_lints/src/types/owned_cow.rs b/clippy_lints/src/types/owned_cow.rs new file mode 100644 index 000000000000..8933994d1855 --- /dev/null +++ b/clippy_lints/src/types/owned_cow.rs @@ -0,0 +1,66 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::snippet_opt; +use rustc_errors::Applicability; +use rustc_hir::def_id::DefId; +use rustc_hir::{self as hir}; +use rustc_lint::LateContext; +use rustc_span::{Span, sym}; + +pub(super) fn check(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, def_id: DefId) -> bool { + if cx.tcx.is_diagnostic_item(sym::Cow, def_id) + && let hir::QPath::Resolved(_, path) = qpath + && let [.., last_seg] = path.segments + && let Some(args) = last_seg.args + && let [_lt, carg] = args.args + && let hir::GenericArg::Type(cty) = carg + && let Some((span, repl)) = replacement(cx, cty.as_unambig_ty()) + { + span_lint_and_sugg( + cx, + super::OWNED_COW, + span, + "needlessly owned Cow type", + "use", + repl, + Applicability::Unspecified, + ); + return true; + } + false +} + +fn replacement(cx: &LateContext<'_>, cty: &hir::Ty<'_>) -> Option<(Span, String)> { + if clippy_utils::is_path_lang_item(cx, cty, hir::LangItem::String) { + return Some((cty.span, "str".into())); + } + if clippy_utils::is_path_diagnostic_item(cx, cty, sym::Vec) { + return if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = cty.kind + && let [.., last_seg] = path.segments + && let Some(args) = last_seg.args + && let [t, ..] = args.args + && let Some(snip) = snippet_opt(cx, t.span()) + { + Some((cty.span, format!("[{snip}]"))) + } else { + None + }; + } + if clippy_utils::is_path_diagnostic_item(cx, cty, sym::cstring_type) { + return Some(( + cty.span, + (if clippy_utils::is_no_std_crate(cx) { + "core::ffi::CStr" + } else { + "std::ffi::CStr" + }) + .into(), + )); + } + // Neither OsString nor PathBuf are available outside std + for (diag, repl) in [(sym::OsString, "std::ffi::OsStr"), (sym::PathBuf, "std::path::Path")] { + if clippy_utils::is_path_diagnostic_item(cx, cty, diag) { + return Some((cty.span, repl.into())); + } + } + None +} diff --git a/tests/ui/owned_cow.fixed b/tests/ui/owned_cow.fixed new file mode 100644 index 000000000000..b62e9107a561 --- /dev/null +++ b/tests/ui/owned_cow.fixed @@ -0,0 +1,23 @@ +#![warn(clippy::owned_cow)] + +use std::borrow::Cow; +use std::ffi::{CString, OsString}; +use std::path::PathBuf; + +fn main() { + let x: Cow<'static, str> = Cow::Owned(String::from("Hi!")); + //~^ ERROR: needlessly owned Cow type + let y: Cow<'_, [u8]> = Cow::Owned(vec![]); + //~^ ERROR: needlessly owned Cow type + let z: Cow<'_, [_]> = Cow::Owned(vec![2_i32]); + //~^ ERROR: needlessly owned Cow type + let o: Cow<'_, std::ffi::OsStr> = Cow::Owned(OsString::new()); + //~^ ERROR: needlessly owned Cow type + let c: Cow<'_, std::ffi::CStr> = Cow::Owned(CString::new("").unwrap()); + //~^ ERROR: needlessly owned Cow type + let p: Cow<'_, std::path::Path> = Cow::Owned(PathBuf::new()); + //~^ ERROR: needlessly owned Cow type + + // false positive: borrowed type + let b: Cow<'_, str> = Cow::Borrowed("Hi!"); +} diff --git a/tests/ui/owned_cow.rs b/tests/ui/owned_cow.rs new file mode 100644 index 000000000000..0e0f14711b7f --- /dev/null +++ b/tests/ui/owned_cow.rs @@ -0,0 +1,23 @@ +#![warn(clippy::owned_cow)] + +use std::borrow::Cow; +use std::ffi::{CString, OsString}; +use std::path::PathBuf; + +fn main() { + let x: Cow<'static, String> = Cow::Owned(String::from("Hi!")); + //~^ ERROR: needlessly owned Cow type + let y: Cow<'_, Vec> = Cow::Owned(vec![]); + //~^ ERROR: needlessly owned Cow type + let z: Cow<'_, Vec<_>> = Cow::Owned(vec![2_i32]); + //~^ ERROR: needlessly owned Cow type + let o: Cow<'_, OsString> = Cow::Owned(OsString::new()); + //~^ ERROR: needlessly owned Cow type + let c: Cow<'_, CString> = Cow::Owned(CString::new("").unwrap()); + //~^ ERROR: needlessly owned Cow type + let p: Cow<'_, PathBuf> = Cow::Owned(PathBuf::new()); + //~^ ERROR: needlessly owned Cow type + + // false positive: borrowed type + let b: Cow<'_, str> = Cow::Borrowed("Hi!"); +} diff --git a/tests/ui/owned_cow.stderr b/tests/ui/owned_cow.stderr new file mode 100644 index 000000000000..8985d6db623d --- /dev/null +++ b/tests/ui/owned_cow.stderr @@ -0,0 +1,41 @@ +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:8:25 + | +LL | let x: Cow<'static, String> = Cow::Owned(String::from("Hi!")); + | ^^^^^^ help: use: `str` + | + = note: `-D clippy::owned-cow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::owned_cow)]` + +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:10:20 + | +LL | let y: Cow<'_, Vec> = Cow::Owned(vec![]); + | ^^^^^^^ help: use: `[u8]` + +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:12:20 + | +LL | let z: Cow<'_, Vec<_>> = Cow::Owned(vec![2_i32]); + | ^^^^^^ help: use: `[_]` + +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:14:20 + | +LL | let o: Cow<'_, OsString> = Cow::Owned(OsString::new()); + | ^^^^^^^^ help: use: `std::ffi::OsStr` + +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:16:20 + | +LL | let c: Cow<'_, CString> = Cow::Owned(CString::new("").unwrap()); + | ^^^^^^^ help: use: `std::ffi::CStr` + +error: needlessly owned Cow type + --> tests/ui/owned_cow.rs:18:20 + | +LL | let p: Cow<'_, PathBuf> = Cow::Owned(PathBuf::new()); + | ^^^^^^^ help: use: `std::path::Path` + +error: aborting due to 6 previous errors + diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index 136dafda27ea..bf271aef763b 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -3,7 +3,8 @@ clippy::needless_borrows_for_generic_args, clippy::ptr_arg, clippy::manual_async_fn, - clippy::needless_lifetimes + clippy::needless_lifetimes, + clippy::owned_cow )] #![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 0948ac5de3ef..95b95ab6bd22 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -3,7 +3,8 @@ clippy::needless_borrows_for_generic_args, clippy::ptr_arg, clippy::manual_async_fn, - clippy::needless_lifetimes + clippy::needless_lifetimes, + clippy::owned_cow )] #![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 f8ad85dbed02..4daa3876e60e 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:224:64 + --> tests/ui/unnecessary_to_owned.rs:225:64 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:224:20 + --> tests/ui/unnecessary_to_owned.rs:225:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,55 +13,55 @@ LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()) = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:226:40 + --> tests/ui/unnecessary_to_owned.rs:227:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:226:21 + --> tests/ui/unnecessary_to_owned.rs:227:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:228:48 + --> tests/ui/unnecessary_to_owned.rs:229:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:228:19 + --> tests/ui/unnecessary_to_owned.rs:229:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:230:35 + --> tests/ui/unnecessary_to_owned.rs:231:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:230:18 + --> tests/ui/unnecessary_to_owned.rs:231:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:232:39 + --> tests/ui/unnecessary_to_owned.rs:233:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:232:20 + --> tests/ui/unnecessary_to_owned.rs:233:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:64:36 + --> tests/ui/unnecessary_to_owned.rs:65:36 | LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this @@ -70,415 +70,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:66:19 + --> tests/ui/unnecessary_to_owned.rs:67:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> tests/ui/unnecessary_to_owned.rs:69:20 + --> tests/ui/unnecessary_to_owned.rs:70:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:71:38 + --> tests/ui/unnecessary_to_owned.rs:72:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:73:20 + --> tests/ui/unnecessary_to_owned.rs:74:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> tests/ui/unnecessary_to_owned.rs:76:18 + --> tests/ui/unnecessary_to_owned.rs:77:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:78:34 + --> tests/ui/unnecessary_to_owned.rs:79:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:80:18 + --> tests/ui/unnecessary_to_owned.rs:81:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:83:17 + --> tests/ui/unnecessary_to_owned.rs:84:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:85:30 + --> tests/ui/unnecessary_to_owned.rs:86:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:87:17 + --> tests/ui/unnecessary_to_owned.rs:88:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:89:17 + --> tests/ui/unnecessary_to_owned.rs:90:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:92:19 + --> tests/ui/unnecessary_to_owned.rs:93:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:94:36 + --> tests/ui/unnecessary_to_owned.rs:95:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:96:19 + --> tests/ui/unnecessary_to_owned.rs:97:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:98:19 + --> tests/ui/unnecessary_to_owned.rs:99:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:100:19 + --> tests/ui/unnecessary_to_owned.rs:101:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:104:42 + --> tests/ui/unnecessary_to_owned.rs:105:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:108:25 + --> tests/ui/unnecessary_to_owned.rs:109:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:110:26 + --> tests/ui/unnecessary_to_owned.rs:111:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:112:24 + --> tests/ui/unnecessary_to_owned.rs:113:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:114:23 + --> tests/ui/unnecessary_to_owned.rs:115:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:116:25 + --> tests/ui/unnecessary_to_owned.rs:117:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:119:30 + --> tests/ui/unnecessary_to_owned.rs:120:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:121:31 + --> tests/ui/unnecessary_to_owned.rs:122:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:123:29 + --> tests/ui/unnecessary_to_owned.rs:124:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:125:28 + --> tests/ui/unnecessary_to_owned.rs:126:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:127:30 + --> tests/ui/unnecessary_to_owned.rs:128:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:130:29 + --> tests/ui/unnecessary_to_owned.rs:131:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:130:43 + --> tests/ui/unnecessary_to_owned.rs:131:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:133:29 + --> tests/ui/unnecessary_to_owned.rs:134:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:133:47 + --> tests/ui/unnecessary_to_owned.rs:134:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:137:26 + --> tests/ui/unnecessary_to_owned.rs:138:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:139:27 + --> tests/ui/unnecessary_to_owned.rs:140:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:141:25 + --> tests/ui/unnecessary_to_owned.rs:142:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:143:24 + --> tests/ui/unnecessary_to_owned.rs:144:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:145:24 + --> tests/ui/unnecessary_to_owned.rs:146:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:147:26 + --> tests/ui/unnecessary_to_owned.rs:148:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:149:26 + --> tests/ui/unnecessary_to_owned.rs:150:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:151:26 + --> tests/ui/unnecessary_to_owned.rs:152:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:154:31 + --> tests/ui/unnecessary_to_owned.rs:155:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:156:32 + --> tests/ui/unnecessary_to_owned.rs:157:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:158:30 + --> tests/ui/unnecessary_to_owned.rs:159:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:160:29 + --> tests/ui/unnecessary_to_owned.rs:161:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:162:29 + --> tests/ui/unnecessary_to_owned.rs:163:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:164:31 + --> tests/ui/unnecessary_to_owned.rs:165:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:166:31 + --> tests/ui/unnecessary_to_owned.rs:167:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:168:31 + --> tests/ui/unnecessary_to_owned.rs:169:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:171:30 + --> tests/ui/unnecessary_to_owned.rs:172:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:171:44 + --> tests/ui/unnecessary_to_owned.rs:172:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:174:30 + --> tests/ui/unnecessary_to_owned.rs:175:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:174:44 + --> tests/ui/unnecessary_to_owned.rs:175:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:177:30 + --> tests/ui/unnecessary_to_owned.rs:178:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:177:44 + --> tests/ui/unnecessary_to_owned.rs:178:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:180:30 + --> tests/ui/unnecessary_to_owned.rs:181:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:180:48 + --> tests/ui/unnecessary_to_owned.rs:181:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:183:30 + --> tests/ui/unnecessary_to_owned.rs:184:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:183:52 + --> tests/ui/unnecessary_to_owned.rs:184:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:186:30 + --> tests/ui/unnecessary_to_owned.rs:187:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:186:48 + --> tests/ui/unnecessary_to_owned.rs:187:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:190:20 + --> tests/ui/unnecessary_to_owned.rs:191:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:193:13 + --> tests/ui/unnecessary_to_owned.rs:194:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:195:13 + --> tests/ui/unnecessary_to_owned.rs:196:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:197:13 + --> tests/ui/unnecessary_to_owned.rs:198: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` - --> tests/ui/unnecessary_to_owned.rs:199:13 + --> tests/ui/unnecessary_to_owned.rs:200: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` - --> tests/ui/unnecessary_to_owned.rs:202:13 + --> tests/ui/unnecessary_to_owned.rs:203:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:204:13 + --> tests/ui/unnecessary_to_owned.rs:205:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:206:13 + --> tests/ui/unnecessary_to_owned.rs:207: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` - --> tests/ui/unnecessary_to_owned.rs:208:13 + --> tests/ui/unnecessary_to_owned.rs:209:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:236:26 + --> tests/ui/unnecessary_to_owned.rs:237:26 | LL | let _ref_str: &str = &String::from_utf8(slice.to_vec()).expect("not UTF-8"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -490,7 +490,7 @@ LL + let _ref_str: &str = core::str::from_utf8(&slice).expect("not UTF-8"); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:238:26 + --> tests/ui/unnecessary_to_owned.rs:239:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".to_vec()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -502,7 +502,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo").unwrap(); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:240:26 + --> tests/ui/unnecessary_to_owned.rs:241:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".as_slice().to_owned()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -514,7 +514,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo".as_slice()).unwrap(); | error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:298:14 + --> tests/ui/unnecessary_to_owned.rs:299:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -527,61 +527,61 @@ LL ~ let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:322:14 + --> tests/ui/unnecessary_to_owned.rs:323:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:328:14 + --> tests/ui/unnecessary_to_owned.rs:329:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:377:24 + --> tests/ui/unnecessary_to_owned.rs:378:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:487:12 + --> tests/ui/unnecessary_to_owned.rs:488:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:631:37 + --> tests/ui/unnecessary_to_owned.rs:632:37 | LL | IntoFuture::into_future(foo([].to_vec(), &0)); | ^^^^^^^^^^^ help: use: `[]` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:642:18 + --> tests/ui/unnecessary_to_owned.rs:643:18 | LL | s.remove(&a.to_vec()); | ^^^^^^^^^^^ help: replace it with: `a` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:647:14 + --> tests/ui/unnecessary_to_owned.rs:648:14 | LL | s.remove(&"b".to_owned()); | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:649:14 + --> tests/ui/unnecessary_to_owned.rs:650:14 | LL | s.remove(&"b".to_string()); | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:655:14 + --> tests/ui/unnecessary_to_owned.rs:656:14 | LL | s.remove(&["b"].to_vec()); | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:657:14 + --> tests/ui/unnecessary_to_owned.rs:658:14 | LL | s.remove(&(&["b"]).to_vec()); | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` From 90bd46bfc3e3a7c1ff67e7693f1b354264bb253b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 19 Feb 2025 14:08:52 +1100 Subject: [PATCH 127/161] Simplify `Postorder` customization. `Postorder` has a `C: Customization<'tcx>` parameter, that gives it flexibility about how it computes successors. But in practice, there are only two `impls` of `Customization`, and one is for the unit type. This commit simplifies things by removing the generic parameter and replacing it with an `Option`. --- clippy_utils/src/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index 637c0bafd964..ffcfcd240ea5 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -30,7 +30,7 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) - locals.len() ]; - traversal::Postorder::new(&mir.basic_blocks, location.block, ()) + traversal::Postorder::new(&mir.basic_blocks, location.block, None) .collect::>() .into_iter() .rev() From 3c9a0ab38c498fc67a5e120094b9d610e6be6a9f Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 20 Feb 2025 23:26:51 +0900 Subject: [PATCH 128/161] rename the MSRV alias `MANUAL_DIV_CEIL` to `DIV_CEIL` --- clippy_lints/src/manual_div_ceil.rs | 2 +- clippy_utils/src/msrvs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/manual_div_ceil.rs b/clippy_lints/src/manual_div_ceil.rs index 04357cdd8f66..dd242c4168c6 100644 --- a/clippy_lints/src/manual_div_ceil.rs +++ b/clippy_lints/src/manual_div_ceil.rs @@ -59,7 +59,7 @@ impl_lint_pass!(ManualDivCeil => [MANUAL_DIV_CEIL]); impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if !self.msrv.meets(msrvs::MANUAL_DIV_CEIL) { + if !self.msrv.meets(msrvs::DIV_CEIL) { return; } diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 2e8bcfaa7af0..bf8106042f31 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -28,7 +28,7 @@ msrv_aliases! { 1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT } 1,75,0 { OPTION_AS_SLICE } 1,74,0 { REPR_RUST } - 1,73,0 { MANUAL_DIV_CEIL } + 1,73,0 { DIV_CEIL } 1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE } 1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN } 1,68,0 { PATH_MAIN_SEPARATOR_STR } From 8844a969caaaa32ae20826fae2f41640a023aa81 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 20 Feb 2025 15:26:51 +0100 Subject: [PATCH 129/161] Bump Clippy version -> 0.1.87 --- Cargo.toml | 2 +- clippy_config/Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- clippy_utils/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c19e7af5f8b..23b2b4ff0b47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" diff --git a/clippy_config/Cargo.toml b/clippy_config/Cargo.toml index e473a5839402..934725fccb8e 100644 --- a/clippy_config/Cargo.toml +++ b/clippy_config/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_config" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version edition = "2024" publish = false diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index c62a7ec783b6..54347043a13d 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 68b7e1592e2e..ba4bb1d177c5 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_utils" # begin autogenerated version -version = "0.1.86" +version = "0.1.87" # end autogenerated version edition = "2024" description = "Helpful tools for writing lints, provided as they are used in Clippy" From 55f32d9259c37a9306838b5792153604d8b4461e Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 20 Feb 2025 23:27:15 +0900 Subject: [PATCH 130/161] add missing MSRV configuration information for `manual_div_ceil` --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 0e264cdcd4a3..78e29640714f 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -764,6 +764,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_bits`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits) * [`manual_c_str_literals`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals) * [`manual_clamp`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp) +* [`manual_div_ceil`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_div_ceil) * [`manual_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten) * [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one) * [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index cac4408fff0e..05e7d26faedd 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -619,6 +619,7 @@ define_Conf! { manual_bits, manual_c_str_literals, manual_clamp, + manual_div_ceil, manual_flatten, manual_hash_one, manual_is_ascii_check, From 934471ce30a1630397518b56a29a5ea04b059353 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 20 Feb 2025 15:27:19 +0100 Subject: [PATCH 131/161] Bump nightly version -> 2025-02-20 --- clippy_utils/README.md | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/README.md b/clippy_utils/README.md index 41f3b1cbd507..e513d9354507 100644 --- a/clippy_utils/README.md +++ b/clippy_utils/README.md @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain: ``` -nightly-2025-02-06 +nightly-2025-02-20 ``` diff --git a/rust-toolchain b/rust-toolchain index ab760287e83a..4956ab5d3775 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,6 +1,6 @@ [toolchain] # begin autogenerated nightly -channel = "nightly-2025-02-06" +channel = "nightly-2025-02-20" # end autogenerated nightly components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal" From e6be02eaf5372d82690d8724ff8cf3718076bb48 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 20 Feb 2025 15:54:12 +0100 Subject: [PATCH 132/161] Rustup: fix 32bit tests --- tests/ui/cast_size.32bit.stderr | 45 ++++++++------ tests/ui/large_enum_variant.32bit.stderr | 75 ++++++++++++++---------- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/tests/ui/cast_size.32bit.stderr b/tests/ui/cast_size.32bit.stderr index 637dd6fddea1..cb1620e36a26 100644 --- a/tests/ui/cast_size.32bit.stderr +++ b/tests/ui/cast_size.32bit.stderr @@ -9,8 +9,9 @@ LL | 1isize as i8; = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i8; +LL + i8::try_from(1isize); + | 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) --> tests/ui/cast_size.rs:24:5 @@ -48,8 +49,9 @@ LL | 1isize 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(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as i32; +LL + i32::try_from(1isize); + | error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:37:5 @@ -60,8 +62,9 @@ LL | 1isize as u32; = 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 | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1isize as u32; +LL + u32::try_from(1isize); + | error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:39:5 @@ -72,8 +75,9 @@ LL | 1usize as u32; = 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 | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as u32; +LL + u32::try_from(1usize); + | error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -84,8 +88,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1usize as i32; +LL + i32::try_from(1usize); + | error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:41:5 @@ -105,8 +110,9 @@ LL | 1i64 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(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as isize; +LL + isize::try_from(1i64); + | error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:46:5 @@ -117,8 +123,9 @@ LL | 1i64 as usize; = 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 | usize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1i64 as usize; +LL + usize::try_from(1i64); + | error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -129,8 +136,9 @@ 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); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as isize; +LL + isize::try_from(1u64); + | error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers --> tests/ui/cast_size.rs:48:5 @@ -147,8 +155,9 @@ LL | 1u64 as usize; = 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 | usize::try_from(1u64); - | ~~~~~~~~~~~~~~~~~~~~~ +LL - 1u64 as usize; +LL + usize::try_from(1u64); + | error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers --> tests/ui/cast_size.rs:53:5 diff --git a/tests/ui/large_enum_variant.32bit.stderr b/tests/ui/large_enum_variant.32bit.stderr index 7f66207ce797..80ca5daa1d57 100644 --- a/tests/ui/large_enum_variant.32bit.stderr +++ b/tests/ui/large_enum_variant.32bit.stderr @@ -14,8 +14,9 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[i32; 8000]>), - | ~~~~~~~~~~~~~~~~ +LL - B([i32; 8000]), +LL + B(Box<[i32; 8000]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:38:1 @@ -31,8 +32,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingLargeEnum(Box), - | ~~~~~~~~~~~~~~ +LL - ContainingLargeEnum(LargeEnum), +LL + ContainingLargeEnum(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:44:1 @@ -49,8 +51,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), +LL + ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:51:1 @@ -66,8 +69,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge { x: [i32; 8000], y: i32 }, +LL + StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:57:1 @@ -83,8 +87,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ~~~~~~~~~~~~~~~~ +LL - StructLikeLarge2 { x: [i32; 8000] }, +LL + StructLikeLarge2 { x: Box<[i32; 8000]> }, + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:74:1 @@ -101,8 +106,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box<[u8; 1255]>), - | ~~~~~~~~~~~~~~~ +LL - B([u8; 1255]), +LL + B(Box<[u8; 1255]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:81:1 @@ -118,8 +124,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ +LL - ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), +LL + ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:87:1 @@ -135,8 +142,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:93:1 @@ -152,8 +160,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:99:1 @@ -169,8 +178,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | B(Box), - | ~~~~~~~~~~~~ +LL - B(Struct2), +LL + B(Box), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:115:1 @@ -255,8 +265,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<(T, [u8; 512])>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large((T, [u8; 512])), +LL + Large(Box<(T, [u8; 512])>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:159:1 @@ -272,8 +283,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[Foo; 64]>), - | ~~~~~~~~~~~~~~~~~~~ +LL - Large([Foo; 64]), +LL + Large(Box<[Foo; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:170:1 @@ -289,8 +301,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(PossiblyLargeEnumWithConst<256>), +LL + Error(Box>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:176:1 @@ -306,8 +319,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Large(Box<[u64; 64]>), - | ~~~~~~~~~~~~~~ +LL - Large([u64; 64]), +LL + Large(Box<[u64; 64]>), + | error: large size difference between variants --> tests/ui/large_enum_variant.rs:187:1 @@ -323,8 +337,9 @@ LL | | } | help: consider boxing the large fields to reduce the total size of the enum | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - Error(WithRecursionAndGenerics), +LL + Error(Box>), + | error: aborting due to 18 previous errors From acfbbc65b54600a4e3b16d6c63258e51907336fe Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 20 Feb 2025 17:54:49 +0100 Subject: [PATCH 133/161] Remove obsolete comment and simplify code The `IoBufRead` diagnostic has been added during the latest rustup. --- clippy_lints/src/methods/unbuffered_bytes.rs | 34 ++++++++------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/methods/unbuffered_bytes.rs b/clippy_lints/src/methods/unbuffered_bytes.rs index c4d2515a7bcb..dd5566f8c8ba 100644 --- a/clippy_lints/src/methods/unbuffered_bytes.rs +++ b/clippy_lints/src/methods/unbuffered_bytes.rs @@ -7,25 +7,19 @@ use rustc_lint::LateContext; use rustc_span::sym; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { - let ty = cx.typeck_results().expr_ty_adjusted(recv); - - // If the .bytes() call is a call from the Read trait - if is_trait_method(cx, expr, sym::IoRead) { - // Retrieve the DefId of the BufRead trait - // FIXME: add a diagnostic item for `BufRead` - let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead) else { - return; - }; - // And the implementor of the trait is not buffered - if !implements_trait(cx, ty, buf_read, &[]) { - span_lint_and_help( - cx, - UNBUFFERED_BYTES, - expr.span, - "calling .bytes() is very inefficient when data is not in memory", - None, - "consider using `BufReader`", - ); - } + // Lint if the `.bytes()` call is from the `Read` trait and the implementor is not buffered. + if is_trait_method(cx, expr, sym::IoRead) + && let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead) + && let ty = cx.typeck_results().expr_ty_adjusted(recv) + && !implements_trait(cx, ty, buf_read, &[]) + { + span_lint_and_help( + cx, + UNBUFFERED_BYTES, + expr.span, + "calling .bytes() is very inefficient when data is not in memory", + None, + "consider using `BufReader`", + ); } } From 41a34552c75d647f6b6f72cbe0c682515711a48d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 13 Feb 2025 14:00:39 +1100 Subject: [PATCH 134/161] Rename `ClearCrossCrate::assert_crate_local`. As `unwrap_crate_local`, because it follows exactly the standard form of an `unwrap` function. --- clippy_lints/src/redundant_clone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index fb1bc494bd94..cfa622aea582 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { let node = mir.source_scopes[scope] .local_data .as_ref() - .assert_crate_local() + .unwrap_crate_local() .lint_root; if let Some(snip) = span.get_source_text(cx) From fef0ea905acb3f66c6957d4e12d22d35424fd40f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 20 Feb 2025 23:05:38 +0000 Subject: [PATCH 135/161] More sophisticated span trimming --- tests/ui/borrow_deref_ref_unfixable.stderr | 5 +- tests/ui/fn_to_numeric_cast_any.stderr | 81 +++++++++------------- tests/ui/implicit_hasher.stderr | 15 ++-- tests/ui/literals.stderr | 5 +- tests/ui/octal_escapes.stderr | 75 ++++++++------------ tests/ui/suspicious_to_owned.stderr | 20 +++--- 6 files changed, 80 insertions(+), 121 deletions(-) diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 71f43af46c24..b8a0eedeb9ee 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -13,9 +13,8 @@ LL + let x: &str = s; | help: if you would like to deref, try using `&**` | -LL - let x: &str = &*s; -LL + let x: &str = &**s; - | +LL | let x: &str = &**s; + | + error: aborting due to 1 previous error diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index c069c9d1672d..895297a04006 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -8,9 +8,8 @@ LL | let _ = foo as i8; = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` help: did you mean to invoke the function? | -LL - let _ = foo as i8; -LL + let _ = foo() as i8; - | +LL | let _ = foo() as i8; + | ++ error: casting function pointer `foo` to `i16` --> tests/ui/fn_to_numeric_cast_any.rs:26:13 @@ -20,9 +19,8 @@ LL | let _ = foo as i16; | help: did you mean to invoke the function? | -LL - let _ = foo as i16; -LL + let _ = foo() as i16; - | +LL | let _ = foo() as i16; + | ++ error: casting function pointer `foo` to `i32` --> tests/ui/fn_to_numeric_cast_any.rs:28:13 @@ -32,9 +30,8 @@ LL | let _ = foo as i32; | help: did you mean to invoke the function? | -LL - let _ = foo as i32; -LL + let _ = foo() as i32; - | +LL | let _ = foo() as i32; + | ++ error: casting function pointer `foo` to `i64` --> tests/ui/fn_to_numeric_cast_any.rs:30:13 @@ -44,9 +41,8 @@ LL | let _ = foo as i64; | help: did you mean to invoke the function? | -LL - let _ = foo as i64; -LL + let _ = foo() as i64; - | +LL | let _ = foo() as i64; + | ++ error: casting function pointer `foo` to `i128` --> tests/ui/fn_to_numeric_cast_any.rs:32:13 @@ -56,9 +52,8 @@ LL | let _ = foo as i128; | help: did you mean to invoke the function? | -LL - let _ = foo as i128; -LL + let _ = foo() as i128; - | +LL | let _ = foo() as i128; + | ++ error: casting function pointer `foo` to `isize` --> tests/ui/fn_to_numeric_cast_any.rs:34:13 @@ -68,9 +63,8 @@ LL | let _ = foo as isize; | help: did you mean to invoke the function? | -LL - let _ = foo as isize; -LL + let _ = foo() as isize; - | +LL | let _ = foo() as isize; + | ++ error: casting function pointer `foo` to `u8` --> tests/ui/fn_to_numeric_cast_any.rs:37:13 @@ -80,9 +74,8 @@ LL | let _ = foo as u8; | help: did you mean to invoke the function? | -LL - let _ = foo as u8; -LL + let _ = foo() as u8; - | +LL | let _ = foo() as u8; + | ++ error: casting function pointer `foo` to `u16` --> tests/ui/fn_to_numeric_cast_any.rs:39:13 @@ -92,9 +85,8 @@ LL | let _ = foo as u16; | help: did you mean to invoke the function? | -LL - let _ = foo as u16; -LL + let _ = foo() as u16; - | +LL | let _ = foo() as u16; + | ++ error: casting function pointer `foo` to `u32` --> tests/ui/fn_to_numeric_cast_any.rs:41:13 @@ -104,9 +96,8 @@ LL | let _ = foo as u32; | help: did you mean to invoke the function? | -LL - let _ = foo as u32; -LL + let _ = foo() as u32; - | +LL | let _ = foo() as u32; + | ++ error: casting function pointer `foo` to `u64` --> tests/ui/fn_to_numeric_cast_any.rs:43:13 @@ -116,9 +107,8 @@ LL | let _ = foo as u64; | help: did you mean to invoke the function? | -LL - let _ = foo as u64; -LL + let _ = foo() as u64; - | +LL | let _ = foo() as u64; + | ++ error: casting function pointer `foo` to `u128` --> tests/ui/fn_to_numeric_cast_any.rs:45:13 @@ -128,9 +118,8 @@ LL | let _ = foo as u128; | help: did you mean to invoke the function? | -LL - let _ = foo as u128; -LL + let _ = foo() as u128; - | +LL | let _ = foo() as u128; + | ++ error: casting function pointer `foo` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:47:13 @@ -140,9 +129,8 @@ LL | let _ = foo as usize; | help: did you mean to invoke the function? | -LL - let _ = foo as usize; -LL + let _ = foo() as usize; - | +LL | let _ = foo() as usize; + | ++ error: casting function pointer `Struct::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:52:13 @@ -152,9 +140,8 @@ LL | let _ = Struct::static_method as usize; | help: did you mean to invoke the function? | -LL - let _ = Struct::static_method as usize; -LL + let _ = Struct::static_method() as usize; - | +LL | let _ = Struct::static_method() as usize; + | ++ error: casting function pointer `f` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:57:5 @@ -164,8 +151,7 @@ LL | f as usize | help: did you mean to invoke the function? | -LL - f as usize -LL + f() as usize +LL | f() as usize | error: casting function pointer `T::static_method` to `usize` @@ -176,8 +162,7 @@ LL | T::static_method as usize | help: did you mean to invoke the function? | -LL - T::static_method as usize -LL + T::static_method() as usize +LL | T::static_method() as usize | error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` @@ -188,9 +173,8 @@ LL | let _ = (clos as fn(u32) -> u32) as usize; | help: did you mean to invoke the function? | -LL - let _ = (clos as fn(u32) -> u32) as usize; -LL + let _ = (clos as fn(u32) -> u32)() as usize; - | +LL | let _ = (clos as fn(u32) -> u32)() as usize; + | ++ error: casting function pointer `foo` to `*const ()` --> tests/ui/fn_to_numeric_cast_any.rs:74:13 @@ -200,9 +184,8 @@ LL | let _ = foo as *const (); | help: did you mean to invoke the function? | -LL - let _ = foo as *const (); -LL + let _ = foo() as *const (); - | +LL | let _ = foo() as *const (); + | ++ error: aborting due to 17 previous errors diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 6e964c65a2e4..01d08a1bd9b2 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -78,9 +78,8 @@ LL | pub fn map(map: &mut HashMap) {} | help: add a type parameter for `BuildHasher` | -LL - pub fn map(map: &mut HashMap) {} -LL + pub fn map(map: &mut HashMap) {} - | +LL | pub fn map(map: &mut HashMap) {} + | +++++++++++++++++++++++++++++ +++ error: parameter of type `HashSet` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:70:22 @@ -90,9 +89,8 @@ LL | pub fn set(set: &mut HashSet) {} | help: add a type parameter for `BuildHasher` | -LL - pub fn set(set: &mut HashSet) {} -LL + pub fn set(set: &mut HashSet) {} - | +LL | pub fn set(set: &mut HashSet) {} + | +++++++++++++++++++++++++++++ +++ error: impl for `HashMap` should be generalized over different hashers --> tests/ui/implicit_hasher.rs:76:43 @@ -116,9 +114,8 @@ LL | pub async fn election_vote(_data: HashMap) {} | help: add a type parameter for `BuildHasher` | -LL - pub async fn election_vote(_data: HashMap) {} -LL + pub async fn election_vote(_data: HashMap) {} - | +LL | pub async fn election_vote(_data: HashMap) {} + | +++++++++++++++++++++++++++++ +++ error: aborting due to 9 previous errors diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index a9192825b354..576b38a47d2d 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -99,9 +99,8 @@ LL + let fail8 = 123; | help: if you mean to use an octal constant, use `0o` | -LL - let fail8 = 0123; -LL + let fail8 = 0o123; - | +LL | let fail8 = 0o123; + | + error: integer type suffix should not be separated by an underscore --> tests/ui/literals.rs:48:16 diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index c8a89ac8bea4..61c781e316ef 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -14,9 +14,8 @@ LL + let _bad1 = "\x1b[0m"; | help: if a null escape is intended, disambiguate using | -LL - let _bad1 = "\033[0m"; -LL + let _bad1 = "\x0033[0m"; - | +LL | let _bad1 = "\x0033[0m"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:6:19 @@ -31,9 +30,8 @@ LL + let _bad2 = b"\x1b[0m"; | help: if a null escape is intended, disambiguate using | -LL - let _bad2 = b"\033[0m"; -LL + let _bad2 = b"\x0033[0m"; - | +LL | let _bad2 = b"\x0033[0m"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:7:20 @@ -48,9 +46,8 @@ LL + let _bad3 = "\\\x1b[0m"; | help: if a null escape is intended, disambiguate using | -LL - let _bad3 = "\\\033[0m"; -LL + let _bad3 = "\\\x0033[0m"; - | +LL | let _bad3 = "\\\x0033[0m"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:9:18 @@ -65,9 +62,8 @@ LL + let _bad4 = "\x0a34567"; | help: if a null escape is intended, disambiguate using | -LL - let _bad4 = "\01234567"; -LL + let _bad4 = "\x001234567"; - | +LL | let _bad4 = "\x001234567"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:10:20 @@ -77,14 +73,12 @@ LL | let _bad5 = "\0\03"; | help: if an octal escape is intended, use a hex escape instead | -LL - let _bad5 = "\0\03"; -LL + let _bad5 = "\0\x03"; - | +LL | let _bad5 = "\0\x03"; + | + help: if a null escape is intended, disambiguate using | -LL - let _bad5 = "\0\03"; -LL + let _bad5 = "\0\x0003"; - | +LL | let _bad5 = "\0\x0003"; + | +++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:11:23 @@ -99,9 +93,8 @@ LL + let _bad6 = "Text-\x2d\077-MoreText"; | help: if a null escape is intended, disambiguate using | -LL - let _bad6 = "Text-\055\077-MoreText"; -LL + let _bad6 = "Text-\x0055\077-MoreText"; - | +LL | let _bad6 = "Text-\x0055\077-MoreText"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:11:27 @@ -116,9 +109,8 @@ LL + let _bad6 = "Text-\055\x3f-MoreText"; | help: if a null escape is intended, disambiguate using | -LL - let _bad6 = "Text-\055\077-MoreText"; -LL + let _bad6 = "Text-\055\x0077-MoreText"; - | +LL | let _bad6 = "Text-\055\x0077-MoreText"; + | ++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:14:31 @@ -128,14 +120,12 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; -LL + let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; - | +LL | let _bad7 = "EvenMoreText-\x01\02-ShortEscapes"; + | + help: if a null escape is intended, disambiguate using | -LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; -LL + let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; - | +LL | let _bad7 = "EvenMoreText-\x0001\02-ShortEscapes"; + | +++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:14:34 @@ -145,14 +135,12 @@ LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | help: if an octal escape is intended, use a hex escape instead | -LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; -LL + let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; - | +LL | let _bad7 = "EvenMoreText-\01\x02-ShortEscapes"; + | + help: if a null escape is intended, disambiguate using | -LL - let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; -LL + let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; - | +LL | let _bad7 = "EvenMoreText-\01\x0002-ShortEscapes"; + | +++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:17:19 @@ -162,14 +150,12 @@ LL | let _bad8 = "锈\01锈"; | help: if an octal escape is intended, use a hex escape instead | -LL - let _bad8 = "锈\01锈"; -LL + let _bad8 = "锈\x01锈"; - | +LL | let _bad8 = "锈\x01锈"; + | + help: if a null escape is intended, disambiguate using | -LL - let _bad8 = "锈\01锈"; -LL + let _bad8 = "锈\x0001锈"; - | +LL | let _bad8 = "锈\x0001锈"; + | +++ error: octal-looking escape in a literal --> tests/ui/octal_escapes.rs:18:19 @@ -184,9 +170,8 @@ LL + let _bad9 = "锈\x09锈"; | help: if a null escape is intended, disambiguate using | -LL - let _bad9 = "锈\011锈"; -LL + let _bad9 = "锈\x0011锈"; - | +LL | let _bad9 = "锈\x0011锈"; + | ++ error: aborting due to 11 previous errors diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 74bbcfcca51e..2c26565d5ef1 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -8,9 +8,8 @@ LL | let _ = cow.to_owned(); = help: to override `-D warnings` add `#[allow(clippy::suspicious_to_owned)]` help: depending on intent, either make the Cow an Owned variant | -LL - let _ = cow.to_owned(); -LL + let _ = cow.into_owned(); - | +LL | let _ = cow.into_owned(); + | ++ help: or clone the Cow itself | LL - let _ = cow.to_owned(); @@ -25,9 +24,8 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL - let _ = cow.to_owned(); -LL + let _ = cow.into_owned(); - | +LL | let _ = cow.into_owned(); + | ++ help: or clone the Cow itself | LL - let _ = cow.to_owned(); @@ -42,9 +40,8 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL - let _ = cow.to_owned(); -LL + let _ = cow.into_owned(); - | +LL | let _ = cow.into_owned(); + | ++ help: or clone the Cow itself | LL - let _ = cow.to_owned(); @@ -59,9 +56,8 @@ LL | let _ = cow.to_owned(); | help: depending on intent, either make the Cow an Owned variant | -LL - let _ = cow.to_owned(); -LL + let _ = cow.into_owned(); - | +LL | let _ = cow.into_owned(); + | ++ help: or clone the Cow itself | LL - let _ = cow.to_owned(); From a04e819b937471a89dff103a83139fea7ed9125f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 21 Feb 2025 00:29:56 +0000 Subject: [PATCH 136/161] Trim suggestion part before generating highlights --- tests/ui/async_yields_async.stderr | 12 ++++++------ tests/ui/fn_to_numeric_cast_any.stderr | 4 ++-- tests/ui/implicit_return.stderr | 14 ++++++-------- tests/ui/manual_flatten.stderr | 8 +++----- tests/ui/too_long_first_doc_paragraph-fix.stderr | 2 +- tests/ui/too_long_first_doc_paragraph.stderr | 4 ++-- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 474914299d06..8c023d0d61f4 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -14,9 +14,9 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]` help: consider awaiting this value | -LL ~ async { -LL + 3 -LL + }.await +LL | async { +LL | 3 +LL ~ }.await | error: an async construct yields a type which is itself awaitable @@ -46,9 +46,9 @@ LL | | }; | help: consider awaiting this value | -LL ~ async { -LL + 3 -LL + }.await +LL | async { +LL | 3 +LL ~ }.await | error: an async construct yields a type which is itself awaitable diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index 895297a04006..0238e3a91369 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -152,7 +152,7 @@ LL | f as usize help: did you mean to invoke the function? | LL | f() as usize - | + | ++ error: casting function pointer `T::static_method` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:62:5 @@ -163,7 +163,7 @@ LL | T::static_method as usize help: did you mean to invoke the function? | LL | T::static_method() as usize - | + | ++ error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` --> tests/ui/fn_to_numeric_cast_any.rs:69:13 diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 7ea72307450c..936a779fa747 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -9,7 +9,7 @@ LL | true help: add `return` as shown | LL | return true - | + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:19:15 @@ -122,7 +122,7 @@ LL | format!("test {}", "test") help: add `return` as shown | LL | return format!("test {}", "test") - | + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:90:5 @@ -133,7 +133,7 @@ LL | m!(true, false) help: add `return` as shown | LL | return m!(true, false) - | + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:96:13 @@ -169,10 +169,8 @@ LL | | } | help: add `return` as shown | -LL ~ return loop { -LL + m!(true); -LL + } - | +LL | return loop { + | ++++++ error: missing `return` statement --> tests/ui/implicit_return.rs:130:5 @@ -183,7 +181,7 @@ LL | true help: add `return` as shown | LL | return true - | + | ++++++ error: aborting due to 16 previous errors diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index cf1b0a1c8bbf..93f7f11b5e64 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -196,11 +196,9 @@ LL | | } | |_________^ help: try | -LL ~ for n in vec![ -LL + -LL + Some(1), -LL + Some(2), -LL + Some(3) +LL | for n in vec![ +... +LL | Some(3) LL ~ ].iter().flatten() { | diff --git a/tests/ui/too_long_first_doc_paragraph-fix.stderr b/tests/ui/too_long_first_doc_paragraph-fix.stderr index 6ef333f0cfd2..84a574017a9b 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.stderr +++ b/tests/ui/too_long_first_doc_paragraph-fix.stderr @@ -12,7 +12,7 @@ LL | | /// 200 characters so I needed to write something longeeeeeeer. = help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]` help: add an empty line | -LL ~ /// A very short summary. +LL | /// A very short summary. LL + /// | diff --git a/tests/ui/too_long_first_doc_paragraph.stderr b/tests/ui/too_long_first_doc_paragraph.stderr index 95f42349b9b3..8bc853132ec0 100644 --- a/tests/ui/too_long_first_doc_paragraph.stderr +++ b/tests/ui/too_long_first_doc_paragraph.stderr @@ -12,8 +12,8 @@ LL | | //! 200 characters so I needed to write something longeeeeeeer. = help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]` help: add an empty line | -LL ~ //! A very short summary. -LL + //! +LL | //! A very short summary. +LL ~ //! LL ~ //! A much longer explanation that goes into a lot more detail about | From c2d75cff47e208280ce9c8d81331639dbb1ae086 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 21 Feb 2025 07:54:35 +1100 Subject: [PATCH 137/161] Move methods from Map to TyCtxt, part 3. Continuing the work from #137162. Every method gains a `hir_` prefix. --- clippy_lints/src/assigning_clones.rs | 2 +- clippy_lints/src/doc/missing_headers.rs | 3 +- clippy_lints/src/doc/mod.rs | 2 +- clippy_lints/src/escape.rs | 3 +- clippy_lints/src/exit.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 6 +-- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/loops/infinite_loop.rs | 2 +- clippy_lints/src/loops/manual_find.rs | 2 +- clippy_lints/src/loops/needless_range_loop.rs | 4 +- .../src/matches/redundant_pattern_match.rs | 2 +- clippy_lints/src/methods/is_empty.rs | 3 +- clippy_lints/src/methods/iter_nth_zero.rs | 2 +- .../src/methods/manual_c_str_literals.rs | 2 +- clippy_lints/src/methods/manual_inspect.rs | 2 +- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 6 +-- .../src/methods/unnecessary_to_owned.rs | 2 +- clippy_lints/src/min_ident_chars.rs | 6 +-- clippy_lints/src/missing_const_for_fn.rs | 2 +- .../src/missing_const_for_thread_local.rs | 2 +- clippy_lints/src/needless_borrowed_ref.rs | 3 +- clippy_lints/src/needless_late_init.rs | 2 +- clippy_lints/src/needless_pass_by_ref_mut.rs | 3 +- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/no_effect.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/non_zero_suggestions.rs | 2 +- .../src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/operators/identity_op.rs | 4 +- clippy_lints/src/panic_unimplemented.rs | 4 +- clippy_lints/src/ptr.rs | 3 +- clippy_lints/src/redundant_locals.rs | 5 +- clippy_lints/src/returns.rs | 5 +- clippy_lints/src/self_named_constructors.rs | 2 +- clippy_lints/src/shadow.rs | 10 ++-- .../src/significant_drop_tightening.rs | 3 +- clippy_lints/src/suspicious_trait_impl.rs | 4 +- clippy_lints/src/transmute/eager_transmute.rs | 2 +- .../missing_transmute_annotations.rs | 2 +- clippy_lints/src/types/mod.rs | 5 +- clippy_lints/src/unconditional_recursion.rs | 6 +-- .../src/undocumented_unsafe_blocks.rs | 5 +- clippy_lints/src/unused_io_amount.rs | 2 +- clippy_lints/src/unused_peekable.rs | 2 +- clippy_lints/src/unused_self.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 4 +- clippy_utils/src/higher.rs | 2 +- clippy_utils/src/lib.rs | 51 +++++++++---------- clippy_utils/src/macros.rs | 2 +- 51 files changed, 96 insertions(+), 108 deletions(-) diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs index c01155ca86e0..348495f97a27 100644 --- a/clippy_lints/src/assigning_clones.rs +++ b/clippy_lints/src/assigning_clones.rs @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { && !cx.tcx.is_builtin_derived(resolved_impl) // Don't suggest calling a function we're implementing. && resolved_impl.as_local().is_none_or(|block_id| { - cx.tcx.hir().parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id) + cx.tcx.hir_parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id) }) && let resolved_assoc_items = cx.tcx.associated_items(resolved_impl) // Only suggest if `clone_from`/`clone_into` is explicitly implemented diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index d1ffbb6ffe25..e8638595c4b2 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -24,8 +24,7 @@ pub fn check( if !check_private_items && cx .tcx - .hir() - .parent_iter(owner_id.into()) + .hir_parent_iter(owner_id.into()) .any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id))) { return; diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 93c2b7a2d182..713d62a8801d 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1057,7 +1057,7 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> { "assert" | "assert_eq" | "assert_ne" ) { - self.is_const = self.cx.tcx.hir().is_inside_const_context(expr.hir_id); + self.is_const = self.cx.tcx.hir_is_inside_const_context(expr.hir_id); self.panic_span = Some(macro_call.span); } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index c55d4387d696..0c06c9117d73 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -80,8 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let parent_id = cx .tcx - .hir() - .get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) + .hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) .def_id; let mut trait_self_ty = None; diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index e6ddcd107d9d..cc8e4d7d9e28 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { && let ExprKind::Path(ref path) = path_expr.kind && let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::process_exit, def_id) - && let parent = cx.tcx.hir().get_parent_item(e.hir_id) + && let parent = cx.tcx.hir_get_parent_item(e.hir_id) && let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent) // If the next item up is a function we check if it is an entry point // and only then emit a linter warning diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index f666ed0a440b..33431385c7de 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -112,7 +112,7 @@ impl IndexingSlicing { impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(array, index, _) = &expr.kind - && (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id)) + && (!self.suppress_restriction_lint_in_const || !cx.tcx.hir_is_inside_const_context(expr.hir_id)) && let expr_ty = cx.typeck_results().expr_ty(array) && let mut deref = deref_chain(cx, expr_ty) && deref.any(|l| { @@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { span_lint_and_then(cx, INDEXING_SLICING, expr.span, "slicing may panic", |diag| { diag.help(help_msg); - if cx.tcx.hir().is_inside_const_context(expr.hir_id) { + if cx.tcx.hir_is_inside_const_context(expr.hir_id) { diag.note(note); } }); @@ -223,7 +223,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { span_lint_and_then(cx, INDEXING_SLICING, expr.span, "indexing may panic", |diag| { diag.help("consider using `.get(n)` or `.get_mut(n)` instead"); - if cx.tcx.hir().is_inside_const_context(expr.hir_id) { + if cx.tcx.hir_is_inside_const_context(expr.hir_id) { diag.note(note); } }); diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index c68499ce9f78..620e27fa67c6 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() && let Some(element_count) = cst.try_to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) - && !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { + && !cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| { matches!( node, Node::Item(Item { diff --git a/clippy_lints/src/loops/infinite_loop.rs b/clippy_lints/src/loops/infinite_loop.rs index 4d206850c998..797ff1f39866 100644 --- a/clippy_lints/src/loops/infinite_loop.rs +++ b/clippy_lints/src/loops/infinite_loop.rs @@ -61,7 +61,7 @@ pub(super) fn check<'tcx>( } fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { - for (_, parent_node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, parent_node) in cx.tcx.hir_parent_iter(expr.hir_id) { match parent_node { // Skip `Coroutine` closures, these are the body of `async fn`, not async closures. // This is because we still need to backtrack one parent node to get the `OpaqueDef` ty. diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs index 1721f569541b..aa8a2934f89b 100644 --- a/clippy_lints/src/loops/manual_find.rs +++ b/clippy_lints/src/loops/manual_find.rs @@ -134,7 +134,7 @@ fn last_stmt_and_ret<'tcx>( } None } - let mut parent_iter = cx.tcx.hir().parent_iter(expr.hir_id); + let mut parent_iter = cx.tcx.hir_parent_iter(expr.hir_id); if let Some((node_hir, Node::Stmt(..))) = parent_iter.next() // This should be the loop // This should be the function body diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index e98c3c9698ba..0f62183eb33d 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>( // ensure that the indexed variable was declared before the loop, see #601 if let Some(indexed_extent) = indexed_extent { - let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_def_id = cx.tcx.hir_get_parent_item(expr.hir_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap(); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { @@ -256,7 +256,7 @@ impl<'tcx> VarVisitor<'_, 'tcx> { let res = self.cx.qpath_res(seqpath, seqexpr.hir_id); match res { Res::Local(hir_id) => { - let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_def_id = self.cx.tcx.hir_get_parent_item(expr.hir_id); let extent = self .cx .tcx diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 393399660131..722ea7042dd7 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -199,7 +199,7 @@ fn find_method_sugg_for_if_let<'tcx>( // type needs to be considered, not just the inner type of the branch being matched on. // Note the last expression in a block is dropped after all local bindings. let check_ty = if has_else - || (keyword == "if" && matches!(cx.tcx.hir().parent_iter(expr.hir_id).next(), Some((_, Node::Block(..))))) + || (keyword == "if" && matches!(cx.tcx.hir_parent_iter(expr.hir_id).next(), Some((_, Node::Block(..))))) { op_ty } else { diff --git a/clippy_lints/src/methods/is_empty.rs b/clippy_lints/src/methods/is_empty.rs index 92c81b3c49d8..1c64f78678ae 100644 --- a/clippy_lints/src/methods/is_empty.rs +++ b/clippy_lints/src/methods/is_empty.rs @@ -40,8 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_ fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool { cx.tcx - .hir() - .parent_id_iter(id) + .hir_parent_id_iter(id) .any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg))) } diff --git a/clippy_lints/src/methods/iter_nth_zero.rs b/clippy_lints/src/methods/iter_nth_zero.rs index 9ff6eaa34871..4bdf589f4876 100644 --- a/clippy_lints/src/methods/iter_nth_zero.rs +++ b/clippy_lints/src/methods/iter_nth_zero.rs @@ -11,7 +11,7 @@ use rustc_span::sym; use super::ITER_NTH_ZERO; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) + if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id)) && let def_id = item.owner_id.to_def_id() && is_trait_method(cx, expr, sym::Iterator) && let Some(Constant::Int(0)) = ConstEvalCtxt::new(cx).eval(arg) diff --git a/clippy_lints/src/methods/manual_c_str_literals.rs b/clippy_lints/src/methods/manual_c_str_literals.rs index 7d5ebdedd0c3..e1ebca0b09df 100644 --- a/clippy_lints/src/methods/manual_c_str_literals.rs +++ b/clippy_lints/src/methods/manual_c_str_literals.rs @@ -187,7 +187,7 @@ fn peel_ptr_cast<'tcx>(e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { /// ^ given this `x` expression, returns the `foo(...)` expression fn peel_ptr_cast_ancestors<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { let mut prev = e; - for (_, node) in cx.tcx.hir().parent_iter(e.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(e.hir_id) { if let Node::Expr(e) = node && get_cast_target(e).is_some() { diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index de37df2394d3..09ccb386a20b 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -123,7 +123,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: }; let mut prev_expr = e; - for (_, parent) in cx.tcx.hir().parent_iter(e.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(e.hir_id) { if let Node::Expr(e) = parent { match e.kind { ExprKind::Field(_, name) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ccc5cd4fa417..b58e8ba32e78 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4671,7 +4671,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index f5f404070cab..69f933fee68f 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -92,7 +92,7 @@ pub(super) fn check<'tcx>( let in_sugg_method_implementation = { matches!( suggested_method_def_id.as_local(), - Some(local_def_id) if local_def_id == cx.tcx.hir().get_parent_item(receiver.hir_id).def_id + Some(local_def_id) if local_def_id == cx.tcx.hir_get_parent_item(receiver.hir_id).def_id ) }; if in_sugg_method_implementation { diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 8a99974394c3..8389c2e3f982 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -35,7 +35,7 @@ pub(super) fn check( }; let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE); - match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) { + match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir_parent_iter(expr.hir_id)) { Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg), Some(usage) if manual => check_manual_split_once(cx, method_name, expr, self_arg, pat_arg, &usage), None if manual => { @@ -127,7 +127,7 @@ fn check_manual_split_once_indirect( pat_arg: &Expr<'_>, ) -> Option<()> { let ctxt = expr.span.ctxt(); - let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); + let mut parents = cx.tcx.hir_parent_iter(expr.hir_id); if let (_, Node::LetStmt(local)) = parents.next()? && let PatKind::Binding(BindingMode::MUT, iter_binding_id, _, None) = local.pat.kind && let (iter_stmt_id, Node::Stmt(_)) = parents.next()? @@ -220,7 +220,7 @@ fn indirect_usage<'tcx>( ControlFlow::Continue(Descend::from(path_to_binding.is_none())) }); - let mut parents = cx.tcx.hir().parent_iter(path_to_binding?.hir_id); + let mut parents = cx.tcx.hir_parent_iter(path_to_binding?.hir_id); let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?; let (parent_id, _) = parents.find(|(_, node)| { diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index e80d99dca56d..ea134c057053 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -494,7 +494,7 @@ fn get_input_traits_and_projections<'tcx>( #[expect(clippy::too_many_lines)] fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool { - for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) { match node { Node::Stmt(_) => return true, Node::Block(..) => {}, diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 4119b1d1051c..e5801124db48 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -121,9 +121,9 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { // Check whether the node is part of a `use` statement. We don't want to emit a warning if the user // has no control over the type. let usenode = opt_as_use_node(node).or_else(|| { - cx.tcx - .hir() - .parent_iter(hir_id) + cx + .tcx + .hir_parent_iter(hir_id) .find_map(|(_, node)| opt_as_use_node(node)) }); diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index ba4af134ccd0..8d751c2c0acb 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { // Const fns are not allowed as methods in a trait. { - let parent = cx.tcx.hir().get_parent_item(hir_id).def_id; + let parent = cx.tcx.hir_get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID { if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) { if let hir::ItemKind::Trait(..) = &item.kind { diff --git a/clippy_lints/src/missing_const_for_thread_local.rs b/clippy_lints/src/missing_const_for_thread_local.rs index e2ca4458edaa..d4181c677afd 100644 --- a/clippy_lints/src/missing_const_for_thread_local.rs +++ b/clippy_lints/src/missing_const_for_thread_local.rs @@ -81,7 +81,7 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { | sym::core_panic_2015_macro | sym::std_panic_2015_macro | sym::core_panic_2021_macro - ) && !cx.tcx.hir().is_inside_const_context(expr.hir_id)) + ) && !cx.tcx.hir_is_inside_const_context(expr.hir_id)) || matches!( diag_name, sym::unimplemented_macro | sym::todo_macro | sym::unreachable_macro | sym::unreachable_2015_macro diff --git a/clippy_lints/src/needless_borrowed_ref.rs b/clippy_lints/src/needless_borrowed_ref.rs index 098098718af3..1b6896827fed 100644 --- a/clippy_lints/src/needless_borrowed_ref.rs +++ b/clippy_lints/src/needless_borrowed_ref.rs @@ -41,8 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { && !ref_pat.span.from_expansion() && cx .tcx - .hir() - .parent_iter(ref_pat.hir_id) + .hir_parent_iter(ref_pat.hir_id) .map_while(|(_, parent)| if let Node::Pat(pat) = parent { Some(pat) } else { None }) // Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms .all(|pat| !matches!(pat.kind, PatKind::Or(_))) diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 4e19a2f409dd..863a1f895c93 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -347,7 +347,7 @@ fn check<'tcx>( impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { - let mut parents = cx.tcx.hir().parent_iter(local.hir_id); + let mut parents = cx.tcx.hir_parent_iter(local.hir_id); if let LetStmt { init: None, pat: diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 5e85d23718a9..36a0738cbc95 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -350,8 +350,7 @@ impl MutablyUsedVariablesCtxt<'_> { // The goal here is to find if the current scope is unsafe or not. It stops when it finds // a function or an unsafe block. fn is_in_unsafe_block(&self, item: HirId) -> bool { - let hir = self.tcx.hir(); - for (parent, node) in hir.parent_iter(item) { + for (parent, node) in self.tcx.hir_parent_iter(item) { if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) { return fn_sig.header.is_unsafe(); } else if let Node::Block(block) = node { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index cf407e51f7af..f0ee613791fb 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if sig.decl.inputs.is_empty() && name == sym::new && cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id) - && let self_def_id = cx.tcx.hir().get_parent_item(id.into()) + && let self_def_id = cx.tcx.hir_get_parent_item(id.into()) && let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity() && self_ty == return_ty(cx, id) && let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default) diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 4d3e6aa79d0a..7187a8f2c11a 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -141,7 +141,7 @@ impl NoEffect { stmt.span, "statement with no effect", |diag| { - for parent in cx.tcx.hir().parent_iter(stmt.hir_id) { + for parent in cx.tcx.hir_parent_iter(stmt.hir_id) { if let Node::Item(item) = parent.1 && let ItemKind::Fn { .. } = item.kind && let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id) diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index f965ab90da23..4007ca88a00e 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(_, body_id) = &impl_item.kind { - let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let item_def_id = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { diff --git a/clippy_lints/src/non_zero_suggestions.rs b/clippy_lints/src/non_zero_suggestions.rs index f6ce1d1d5867..16c4391c0fbe 100644 --- a/clippy_lints/src/non_zero_suggestions.rs +++ b/clippy_lints/src/non_zero_suggestions.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for NonZeroSuggestions { check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable); } else { // Check if the parent expression is a binary operation - let parent_is_binary = cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { + let parent_is_binary = cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| { matches!(node, rustc_hir::Node::Expr(parent_expr) if matches!(parent_expr.kind, ExprKind::Binary(..))) }); diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 1315c3dfc127..5737a91031db 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( let rty = cx.typeck_results().expr_ty(rhs); if let Some((_, lang_item)) = binop_traits(op.node) && let Some(trait_id) = cx.tcx.lang_items().get(lang_item) - && let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id).def_id && trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id) && implements_trait(cx, ty, trait_id, &[rty.into()]) { diff --git a/clippy_lints/src/operators/identity_op.rs b/clippy_lints/src/operators/identity_op.rs index 1c2d6e90fc95..035823228278 100644 --- a/clippy_lints/src/operators/identity_op.rs +++ b/clippy_lints/src/operators/identity_op.rs @@ -120,7 +120,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>) // the parent HIR node is an expression, or if the parent HIR node // is a Block or Stmt, and the new left hand side would need // parenthesis be treated as a statement rather than an expression. - if let Some((_, parent)) = cx.tcx.hir().parent_iter(binary.hir_id).next() { + if let Some((_, parent)) = cx.tcx.hir_parent_iter(binary.hir_id).next() { match parent { Node::Expr(_) => return Parens::Needed, Node::Block(_) | Node::Stmt(_) => { @@ -142,7 +142,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>) // This would mean that the rustfix suggestion will appear at the start of a line, which causes // these expressions to be interpreted as statements if they do not have parenthesis. let mut prev_id = binary.hir_id; - for (_, parent) in cx.tcx.hir().parent_iter(binary.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(binary.hir_id) { if let Node::Expr(expr) = parent && let ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) | ExprKind::Unary(_, lhs) = expr.kind && lhs.hir_id == prev_id diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index fa5b02a5a41b..c9bdeed660e2 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some(macro_call) = root_macro_call_first_node(cx, expr) { if is_panic(cx, macro_call.def_id) { - if cx.tcx.hir().is_inside_const_context(expr.hir_id) + if cx.tcx.hir_is_inside_const_context(expr.hir_id) || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) { return; @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { && let Res::Def(DefKind::Fn, def_id) = expr_path.res && match_def_path(cx, def_id, &paths::PANIC_ANY) { - if cx.tcx.hir().is_inside_const_context(expr.hir_id) + if cx.tcx.hir_is_inside_const_context(expr.hir_id) || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) { return; diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 9b241edf4ccf..ef4948a05b7f 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -186,8 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { - let hir = cx.tcx.hir(); - let mut parents = hir.parent_iter(body.value.hir_id); + let mut parents = cx.tcx.hir_parent_iter(body.value.hir_id); let (item_id, sig, is_trait_item) = match parents.next() { Some((_, Node::Item(i))) => { if let ItemKind::Fn { sig, .. } = &i.kind { diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index e15e12629209..f3ccc9e38f4d 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -122,8 +122,7 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { /// 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) + mutability == Mutability::Mut + && cx.tcx.hir_get_enclosing_scope(bind) != cx.tcx.hir_get_enclosing_scope(rebind) } diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 9f0ea84246dd..152739c2973b 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -177,8 +177,7 @@ declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN, NEEDLESS_RETURN_W /// because of the never-ness of `return` expressions fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool { cx.tcx - .hir() - .parent_iter(stmt_hir_id) + .hir_parent_iter(stmt_hir_id) .find_map(|(_, node)| if let Node::Expr(expr) = node { Some(expr) } else { None }) .is_some_and(|e| { cx.typeck_results() @@ -203,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { && is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr) // Ensure this is not the final stmt, otherwise removing it would cause a compile error - && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) + && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id)) && let ItemKind::Fn { body, .. } = item.kind && let block = cx.tcx.hir_body(body).value && let ExprKind::Block(block, _) = block.kind diff --git a/clippy_lints/src/self_named_constructors.rs b/clippy_lints/src/self_named_constructors.rs index 23b47606f8aa..fc02c3a51716 100644 --- a/clippy_lints/src/self_named_constructors.rs +++ b/clippy_lints/src/self_named_constructors.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let ret_ty = return_ty(cx, impl_item.owner_id); diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index a931e39bac9c..ee282ee1dfb7 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -224,9 +224,9 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) /// Returns true if the expression is a simple transformation of a local binding such as `&x` fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_id: HirId) -> bool { - let hir = cx.tcx.hir(); - let is_direct_binding = hir - .parent_iter(pat.hir_id) + let is_direct_binding = cx + .tcx + .hir_parent_iter(pat.hir_id) .map_while(|(_id, node)| match node { Node::Pat(pat) => Some(pat), _ => None, @@ -259,14 +259,14 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_ /// For closure arguments passed to a method call, returns the method call, and the `HirId` of the /// closure (which will later be skipped). This is for fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option)> { - for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) { + for (hir_id, node) in cx.tcx.hir_parent_iter(hir_id) { let init = match node { Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue, Node::Expr(expr) => match expr.kind { ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)), // If we're a closure argument, then a parent call is also an associated item. ExprKind::Closure(_) => { - if let Some((_, node)) = cx.tcx.hir().parent_iter(hir_id).next() { + if let Some((_, node)) = cx.tcx.hir_parent_iter(hir_id).next() { match node { Node::Expr(expr) => match expr.kind { ExprKind::MethodCall(_, _, _, _) | ExprKind::Call(_, _) => Some((expr, Some(hir_id))), diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index 597bfddecbc5..e9db7c9d031a 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -232,8 +232,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx let block_is_ancestor = self .cx .tcx - .hir() - .parent_iter(self.ap.curr_block_hir_id) + .hir_parent_iter(self.ap.curr_block_hir_id) .any(|(id, _)| id == apa.first_block_hir_id); if last_stmt_is_not_dummy && last_stmt_is_not_curr && (block_equals_curr || block_is_ancestor) { apa.has_expensive_expr_after_last_attr = true; diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 9326b2adaffb..fb426e91bf01 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -63,11 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives - && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id && let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn) && let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind && let body = cx.tcx.hir_body(body_id) - && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id && let Some(trait_ref) = trait_ref_of_method(cx, parent_fn) && let trait_id = trait_ref.path.res.def_id() && ![binop_trait_id, op_assign_trait_id].contains(&trait_id) diff --git a/clippy_lints/src/transmute/eager_transmute.rs b/clippy_lints/src/transmute/eager_transmute.rs index 1209bd5b34f2..81c0a57083e8 100644 --- a/clippy_lints/src/transmute/eager_transmute.rs +++ b/clippy_lints/src/transmute/eager_transmute.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::Ty; use super::EAGER_TRANSMUTE; fn peel_parent_unsafe_blocks<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { - for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(expr.hir_id) { match parent { Node::Block(_) => {}, Node::Expr(e) if let ExprKind::Block(..) = e.kind => {}, diff --git a/clippy_lints/src/transmute/missing_transmute_annotations.rs b/clippy_lints/src/transmute/missing_transmute_annotations.rs index 0b5d83ef58ca..96286fcf73d6 100644 --- a/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::Ty; use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS; fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option> { - let mut parent_iter = cx.tcx.hir().parent_iter(expr_hir_id); + let mut parent_iter = cx.tcx.hir_parent_iter(expr_hir_id); if let Some((_, node)) = parent_iter.next() { match node { Node::LetStmt(local) => Some(*local), diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 579cbf447a2b..71e6e75c1bd3 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -375,8 +375,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ) { let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id( cx.tcx - .hir() - .get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) + .hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) .def_id, ) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) @@ -420,7 +419,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let hir::Node::Item(item) = cx .tcx - .hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) + .hir_node_by_def_id(cx.tcx.hir_get_parent_item(item.hir_id()).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index 76a0b927df42..a443043bef90 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -111,7 +111,7 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt owner_id, .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.has_attr(*owner_id, sym::automatically_derived) // It is a implementation of a trait. @@ -216,7 +216,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local owner_id, .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.has_attr(*owner_id, sym::automatically_derived) // It is a implementation of a trait. @@ -367,7 +367,7 @@ impl UnconditionalRecursion { kind: ItemKind::Impl(impl_), .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() && let Some(implemented_ty_id) = get_hir_ty_def_id(cx.tcx, *impl_.self_ty) && { self.init_default_impl_for_type_if_needed(cx); diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index c8e3c46f2f6f..93abf95e3577 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -291,7 +291,7 @@ fn expr_has_unnecessary_safety_comment<'tcx>( expr: &'tcx hir::Expr<'tcx>, comment_pos: BytePos, ) -> Option { - if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| { + if cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, ref node)| { matches!( node, Node::Block(Block { @@ -604,10 +604,9 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span fn get_body_search_span(cx: &LateContext<'_>) -> Option { let body = cx.enclosing_body?; - let map = cx.tcx.hir(); let mut span = cx.tcx.hir_body(body).value.span; let mut maybe_global_var = false; - for (_, node) in map.parent_iter(body.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(body.hir_id) { match node { Node::Expr(e) => span = e.span, Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (), diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index e65123b8a949..0687fc319af6 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -224,7 +224,7 @@ fn is_unreachable_or_panic(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { return false; }; if is_panic(cx, macro_call.def_id) { - return !cx.tcx.hir().is_inside_const_context(expr.hir_id); + return !cx.tcx.hir_is_inside_const_context(expr.hir_id); } matches!(cx.tcx.item_name(macro_call.def_id).as_str(), "unreachable") } diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 0f9b05c84d4b..7487e273caa7 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> { if path_to_local_id(ex, self.expected_hir_id) { - for (_, node) in self.cx.tcx.hir().parent_iter(ex.hir_id) { + for (_, node) in self.cx.tcx.hir_parent_iter(ex.hir_id) { match node { Node::Expr(expr) => { match expr.kind { diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index d8305a628290..2c6c75693166 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.owner_id); let contains_todo = |cx, body: &'_ Body<'_>| -> bool { diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 1221abec1abf..4c9a7f0e16de 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -73,8 +73,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues { } fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { - let parent_id = cx.tcx.hir().get_parent_item(hir_id); - let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id; + let parent_id = cx.tcx.hir_get_parent_item(hir_id); + let second_parent_id = cx.tcx.hir_get_parent_item(parent_id.into()).def_id; if let Node::Item(item) = cx.tcx.hir_node_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 6bb876322f24..c4d00002292c 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -117,7 +117,7 @@ impl<'hir> IfLet<'hir> { if_else, ) = expr.kind { - let mut iter = cx.tcx.hir().parent_iter(expr.hir_id); + let mut iter = cx.tcx.hir_parent_iter(expr.hir_id); if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() { if let Some(( _, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 15e395731ade..40ddd75b7fad 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -212,7 +212,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< /// /// e.g. returns true for `x` in `fn f(x: usize) { .. }` and `let x = 1;` but false for `let x;` pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool { - for (_, node) in cx.tcx.hir().parent_iter(local) { + for (_, node) in cx.tcx.hir_parent_iter(local) { match node { Node::Pat(..) | Node::PatField(..) => {}, Node::LetStmt(let_stmt) => return let_stmt.init.is_some(), @@ -227,7 +227,7 @@ pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool { /// /// The current context is determined based on the current body which is set before calling a lint's /// entry point (any function on `LateLintPass`). If you need to check in a different context use -/// `tcx.hir().is_inside_const_context(_)`. +/// `tcx.hir_is_inside_const_context(_)`. /// /// Do not call this unless the `LateContext` has an enclosing body. For release build this case /// will safely return `false`, but debug builds will ICE. Note that `check_expr`, `check_block`, @@ -806,7 +806,7 @@ pub fn get_trait_def_id(tcx: TyCtxt<'_>, path: &[&str]) -> Option { pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> Option<&'tcx TraitRef<'tcx>> { // Get the implemented trait for the current function let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); - let parent_impl = cx.tcx.hir().get_parent_item(hir_id); + let parent_impl = cx.tcx.hir_get_parent_item(hir_id); if parent_impl != hir::CRATE_OWNER_ID && let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_impl.def_id) && let ItemKind::Impl(impl_) = &item.kind @@ -1117,7 +1117,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { let mut capture = CaptureKind::Value; let mut capture_expr_ty = e; - for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) { + for (parent_id, parent) in cx.tcx.hir_parent_iter(e.hir_id) { if let [ Adjustment { kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)), @@ -1336,13 +1336,13 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool { /// Returns `true` if the expression is in the program's `#[panic_handler]`. pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - let parent = cx.tcx.hir().get_parent_item(e.hir_id); + let parent = cx.tcx.hir_get_parent_item(e.hir_id); Some(parent.to_def_id()) == cx.tcx.lang_items().panic_impl() } /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; + let parent_id = cx.tcx.hir_get_parent_item(expr.hir_id).def_id; match cx.tcx.hir_node_by_def_id(parent_id) { Node::Item(Item { ident, .. }) | Node::TraitItem(TraitItem { ident, .. }) @@ -1407,9 +1407,9 @@ pub fn get_parent_expr_for_hir<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> O /// Gets the enclosing block, if any. pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> { - let map = &cx.tcx.hir(); - let enclosing_node = map - .get_enclosing_scope(hir_id) + let enclosing_node = cx + .tcx + .hir_get_enclosing_scope(hir_id) .map(|enclosing_id| cx.tcx.hir_node(enclosing_id)); enclosing_node.and_then(|node| match node { Node::Block(block) => Some(block), @@ -1433,7 +1433,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( cx: &LateContext<'tcx>, expr: &Expr<'_>, ) -> Option<&'tcx Expr<'tcx>> { - for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) { match node { Node::Expr(e) => match e.kind { ExprKind::Closure { .. } @@ -1453,7 +1453,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( /// Gets the parent node if it's an impl block. pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> { - match tcx.hir().parent_iter(id).next() { + match tcx.hir_parent_iter(id).next() { Some(( _, Node::Item(Item { @@ -1531,7 +1531,7 @@ pub fn peel_blocks_with_stmt<'a>(mut expr: &'a Expr<'a>) -> &'a Expr<'a> { /// Checks if the given expression is the else clause of either an `if` or `if let` expression. pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { - let mut iter = tcx.hir().parent_iter(expr.hir_id); + let mut iter = tcx.hir_parent_iter(expr.hir_id); match iter.next() { Some(( _, @@ -1548,7 +1548,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { /// returns `true` for both the `init` and the `else` part pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; - for (parent_id, node) in tcx.hir().parent_iter(child_id) { + for (parent_id, node) in tcx.hir_parent_iter(child_id) { if let Node::LetStmt(LetStmt { init: Some(init), els: Some(els), @@ -1568,7 +1568,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { /// Checks if the given expression is the else clause of a `let else` expression pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; - for (parent_id, node) in tcx.hir().parent_iter(child_id) { + for (parent_id, node) in tcx.hir_parent_iter(child_id) { if let Node::LetStmt(LetStmt { els: Some(els), .. }) = node && els.hir_id == child_id { @@ -1961,7 +1961,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool return true; } prev_enclosing_node = Some(enclosing_node); - enclosing_node = map.get_parent_item(enclosing_node).into(); + enclosing_node = tcx.hir_get_parent_item(enclosing_node).into(); } false @@ -1970,8 +1970,8 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool /// Checks if the given HIR node is inside an `impl` block with the `automatically_derived` /// attribute. pub fn in_automatically_derived(tcx: TyCtxt<'_>, id: HirId) -> bool { - tcx.hir() - .parent_owner_iter(id) + tcx + .hir_parent_owner_iter(id) .filter(|(_, node)| matches!(node, OwnerNode::Item(item) if matches!(item.kind, ItemKind::Impl(_)))) .any(|(id, _)| { has_attr( @@ -2202,7 +2202,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool /// Returns both the node and the `HirId` of the closest child node. pub fn get_expr_use_or_unification_node<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<(Node<'tcx>, HirId)> { let mut child_id = expr.hir_id; - let mut iter = tcx.hir().parent_iter(child_id); + let mut iter = tcx.hir_parent_iter(child_id); loop { match iter.next() { None => break None, @@ -2581,7 +2581,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool { with_test_item_names(tcx, tcx.parent_module(id), |names| { let node = tcx.hir_node(id); once((id, node)) - .chain(tcx.hir().parent_iter(id)) + .chain(tcx.hir_parent_iter(id)) // Since you can nest functions we need to collect all until we leave // function scope .any(|(_id, node)| { @@ -2617,8 +2617,8 @@ pub fn is_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool { /// Checks if any parent node of `HirId` has `#[cfg(test)]` attribute applied pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool { - tcx.hir() - .parent_id_iter(id) + tcx + .hir_parent_id_iter(id) .any(|parent_id| is_cfg_test(tcx, parent_id)) } @@ -2632,8 +2632,8 @@ pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let hir = tcx.hir(); tcx.has_attr(def_id, sym::cfg) - || hir - .parent_iter(tcx.local_def_id_to_hir_id(def_id)) + || tcx + .hir_parent_iter(tcx.local_def_id_to_hir_id(def_id)) .flat_map(|(parent_id, _)| hir.attrs(parent_id)) .any(|attr| attr.has_name(sym::cfg)) } @@ -2653,8 +2653,7 @@ pub fn walk_to_expr_usage<'tcx, T>( e: &Expr<'tcx>, mut f: impl FnMut(HirId, Node<'tcx>, HirId) -> ControlFlow, ) -> Option, HirId)>> { - let map = cx.tcx.hir(); - let mut iter = map.parent_iter(e.hir_id); + let mut iter = cx.tcx.hir_parent_iter(e.hir_id); let mut child_id = e.hir_id; while let Some((parent_id, parent)) = iter.next() { @@ -2677,7 +2676,7 @@ pub fn walk_to_expr_usage<'tcx, T>( ExprKind::If(child, ..) | ExprKind::Match(child, ..) if child.hir_id != child_id => child_id = parent_id, ExprKind::Break(Destination { target_id: Ok(id), .. }, _) => { child_id = id; - iter = map.parent_iter(id); + iter = cx.tcx.hir_parent_iter(id); }, ExprKind::Block(..) | ExprKind::DropTemps(_) => child_id = parent_id, _ => return Some(ControlFlow::Continue((parent, child_id))), diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 30fd48fc0605..9ce0fd8318f1 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -178,7 +178,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option< // get the parent node, possibly skipping over a statement // if the parent is not found, it is sensible to return `Some(root)` let hir = cx.tcx.hir(); - let mut parent_iter = hir.parent_iter(node.hir_id()); + let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id()); let (parent_id, _) = match parent_iter.next() { None => return Some(ExpnId::root()), Some((_, Node::Stmt(_))) => match parent_iter.next() { From 373f809c1ddf0046300cad3e9161c17f13155675 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 20 Feb 2025 22:59:05 -0500 Subject: [PATCH 138/161] Add `todo!` & `unimplemented!` to format macros list For some reason, the `todo!` and `unimplemented!` macros were not included in the list of format-supporting macros list. Since they seem to behave exactly the same as all others like `write!` and `assert!`, adding them now. --- clippy_utils/src/macros.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 30fd48fc0605..5a94dd06c454 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -30,6 +30,8 @@ const FORMAT_MACRO_DIAG_ITEMS: &[Symbol] = &[ sym::print_macro, sym::println_macro, sym::std_panic_macro, + sym::todo_macro, + sym::unimplemented_macro, sym::write_macro, sym::writeln_macro, ]; From 4ac7a5361be9739b729a0554a40013435b030dce Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 21 Feb 2025 09:42:12 +0100 Subject: [PATCH 139/161] Represent the capability instead of the lint name in msrv aliases `INTEGER_BITS` better represents the addition of the `BITS` value on the primitive integer types. --- clippy_lints/src/manual_bits.rs | 2 +- clippy_utils/src/msrvs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 17e25635ce10..4a34a334cf2b 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { if let ExprKind::Binary(bin_op, left_expr, right_expr) = expr.kind && let BinOpKind::Mul = &bin_op.node && !expr.span.from_expansion() - && self.msrv.meets(msrvs::MANUAL_BITS) + && self.msrv.meets(msrvs::INTEGER_BITS) && let ctxt = expr.span.ctxt() && left_expr.span.ctxt() == ctxt && right_expr.span.ctxt() == ctxt diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 2e8bcfaa7af0..21e8076985e8 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -41,7 +41,7 @@ msrv_aliases! { 1,56,0 { CONST_FN_UNION } 1,55,0 { SEEK_REWIND } 1,54,0 { INTO_KEYS } - 1,53,0 { OR_PATTERNS, MANUAL_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN, ARRAY_INTO_ITERATOR } + 1,53,0 { OR_PATTERNS, INTEGER_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN, ARRAY_INTO_ITERATOR } 1,52,0 { STR_SPLIT_ONCE, REM_EUCLID_CONST } 1,51,0 { BORROW_AS_PTR, SEEK_FROM_CURRENT, UNSIGNED_ABS } 1,50,0 { BOOL_THEN, CLAMP, SLICE_FILL } From 6c6ffd27a2ddd928e144149fb66937f033bdd177 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Thu, 6 Feb 2025 23:42:03 +0900 Subject: [PATCH 140/161] extend `obfuscated_if_else` to support `then().unwrap_or_else()` and `then_some().unwrap_or_else()` --- clippy_lints/src/methods/mod.rs | 5 +- .../src/methods/obfuscated_if_else.rs | 18 +++++- tests/ui/obfuscated_if_else.fixed | 24 +++++++- tests/ui/obfuscated_if_else.rs | 24 +++++++- tests/ui/obfuscated_if_else.stderr | 60 ++++++++++++++----- 5 files changed, 111 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7f421d098270..f3c826e5c061 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -5398,7 +5398,7 @@ impl Methods { option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, &self.msrv); }, Some((then_method @ ("then" | "then_some"), t_recv, [t_arg], _, _)) => { - obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg, then_method); + obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg, then_method, "unwrap_or"); }, _ => {}, } @@ -5417,6 +5417,9 @@ impl Methods { match method_call(recv) { Some(("map", recv, [map_arg], _, _)) if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {}, + Some((then_method @ ("then" | "then_some"), t_recv, [t_arg], _, _)) => { + obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg, then_method, "unwrap_or_else"); + }, _ => { unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or"); }, diff --git a/clippy_lints/src/methods/obfuscated_if_else.rs b/clippy_lints/src/methods/obfuscated_if_else.rs index 3ef4906b3c9d..9a5ffdeaf4e8 100644 --- a/clippy_lints/src/methods/obfuscated_if_else.rs +++ b/clippy_lints/src/methods/obfuscated_if_else.rs @@ -16,6 +16,7 @@ pub(super) fn check<'tcx>( then_arg: &'tcx hir::Expr<'_>, unwrap_arg: &'tcx hir::Expr<'_>, then_method_name: &str, + unwrap_method_name: &str, ) { let recv_ty = cx.typeck_results().expr_ty(then_recv); @@ -32,14 +33,27 @@ pub(super) fn check<'tcx>( snippet_with_applicability(cx, body.value.span, "..", &mut applicability) }, "then_some" => snippet_with_applicability(cx, then_arg.span, "..", &mut applicability), - _ => String::new().into(), + _ => return, + }; + + // FIXME: Add `unwrap_or_else` symbol + let els = match unwrap_method_name { + "unwrap_or" => snippet_with_applicability(cx, unwrap_arg.span, "..", &mut applicability), + "unwrap_or_else" if let ExprKind::Closure(closure) = unwrap_arg.kind => { + let body = cx.tcx.hir_body(closure.body); + snippet_with_applicability(cx, body.value.span, "..", &mut applicability) + }, + "unwrap_or_else" if let ExprKind::Path(_) = unwrap_arg.kind => { + snippet_with_applicability(cx, unwrap_arg.span, "_", &mut applicability) + "()" + }, + _ => return, }; let sugg = format!( "if {} {{ {} }} else {{ {} }}", Sugg::hir_with_applicability(cx, then_recv, "..", &mut applicability), if_then, - snippet_with_applicability(cx, unwrap_arg.span, "..", &mut applicability) + els ); // To be parsed as an expression, the `if { … } else { … }` as the left operand of a binary operator diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index b7a9cc836475..66f5070787b0 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -1,5 +1,10 @@ #![warn(clippy::obfuscated_if_else)] -#![allow(clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit)] +#![allow( + clippy::unnecessary_lazy_evaluations, + clippy::unit_arg, + clippy::unused_unit, + clippy::unwrap_or_default +)] fn main() { if true { "a" } else { "b" }; @@ -24,6 +29,23 @@ fn main() { if true { () } else { a += 2 }; //~^ obfuscated_if_else + + let mut n = 1; + if true { n = 1 } else { n = 2 }; + //~^ obfuscated_if_else + if true { 1 } else { n * 2 }; + //~^ obfuscated_if_else + if true { n += 1 } else { () }; + //~^ obfuscated_if_else + + let _ = if true { 1 } else { n * 2 }; + //~^ obfuscated_if_else + + if true { 1 } else { Default::default() }; + //~^ obfuscated_if_else + + let partial = true.then_some(1); + partial.unwrap_or_else(|| n * 2); // not lint } fn issue11141() { diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index a6470fedd5c6..4efd740eb60b 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -1,5 +1,10 @@ #![warn(clippy::obfuscated_if_else)] -#![allow(clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit)] +#![allow( + clippy::unnecessary_lazy_evaluations, + clippy::unit_arg, + clippy::unused_unit, + clippy::unwrap_or_default +)] fn main() { true.then_some("a").unwrap_or("b"); @@ -24,6 +29,23 @@ fn main() { true.then_some(()).unwrap_or(a += 2); //~^ obfuscated_if_else + + let mut n = 1; + true.then(|| n = 1).unwrap_or_else(|| n = 2); + //~^ obfuscated_if_else + true.then_some(1).unwrap_or_else(|| n * 2); + //~^ obfuscated_if_else + true.then_some(n += 1).unwrap_or_else(|| ()); + //~^ obfuscated_if_else + + let _ = true.then_some(1).unwrap_or_else(|| n * 2); + //~^ obfuscated_if_else + + true.then_some(1).unwrap_or_else(Default::default); + //~^ obfuscated_if_else + + let partial = true.then_some(1); + partial.unwrap_or_else(|| n * 2); // not lint } fn issue11141() { diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index 84caa848ece6..d676c2566957 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -1,5 +1,5 @@ error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:5:5 + --> tests/ui/obfuscated_if_else.rs:10:5 | LL | true.then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` @@ -8,82 +8,112 @@ LL | true.then_some("a").unwrap_or("b"); = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:8:5 + --> tests/ui/obfuscated_if_else.rs:13:5 | LL | true.then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:12:5 + --> tests/ui/obfuscated_if_else.rs:17:5 | LL | (a == 1).then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:15:5 + --> tests/ui/obfuscated_if_else.rs:20:5 | LL | (a == 1).then(|| "a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:22:5 + --> tests/ui/obfuscated_if_else.rs:27:5 | LL | true.then_some(a += 1).unwrap_or(()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:25:5 + --> tests/ui/obfuscated_if_else.rs:30:5 | LL | true.then_some(()).unwrap_or(a += 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:31:13 + --> tests/ui/obfuscated_if_else.rs:34:5 + | +LL | true.then(|| n = 1).unwrap_or_else(|| n = 2); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { n = 1 } else { n = 2 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:36:5 + | +LL | true.then_some(1).unwrap_or_else(|| n * 2); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 1 } else { n * 2 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:38:5 + | +LL | true.then_some(n += 1).unwrap_or_else(|| ()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { n += 1 } else { () }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:41:13 + | +LL | let _ = true.then_some(1).unwrap_or_else(|| n * 2); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 1 } else { n * 2 }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:44:5 + | +LL | true.then_some(1).unwrap_or_else(Default::default); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 1 } else { Default::default() }` + +error: this method chain can be written more clearly with `if .. else ..` + --> tests/ui/obfuscated_if_else.rs:53:13 | LL | let _ = true.then_some(40).unwrap_or(17) | 2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 40 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:35:13 + --> tests/ui/obfuscated_if_else.rs:57:13 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(if true { 30 } else { 17 })` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:35:48 + --> tests/ui/obfuscated_if_else.rs:57:48 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 2 } else { 3 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:35:81 + --> tests/ui/obfuscated_if_else.rs:57:81 | LL | let _ = true.then_some(30).unwrap_or(17) | true.then_some(2).unwrap_or(3) | true.then_some(10).unwrap_or(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 10 } else { 1 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:41:17 + --> tests/ui/obfuscated_if_else.rs:63:17 | LL | let _ = 2 | true.then_some(40).unwrap_or(17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 40 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:45:13 + --> tests/ui/obfuscated_if_else.rs:67:13 | LL | let _ = true.then_some(42).unwrap_or(17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { 42 } else { 17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:49:14 + --> tests/ui/obfuscated_if_else.rs:71:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` error: this method chain can be written more clearly with `if .. else ..` - --> tests/ui/obfuscated_if_else.rs:53:14 + --> tests/ui/obfuscated_if_else.rs:75:14 | LL | let _ = *true.then_some(&42).unwrap_or(&17) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { &42 } else { &17 }` -error: aborting due to 14 previous errors +error: aborting due to 19 previous errors From 6366cca43958bedcfcc1b980061793e1f6664c43 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Sat, 18 Jan 2025 11:40:39 +0100 Subject: [PATCH 141/161] add `io_other_error` lint --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_dev/src/new_lint.rs | 5 +- clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/manual_div_ceil.rs | 2 +- clippy_lints/src/methods/io_other_error.rs | 37 +++++++++++++++ clippy_lints/src/methods/mod.rs | 25 ++++++++++ clippy_utils/src/msrvs.rs | 4 +- clippy_utils/src/paths.rs | 2 + tests/ui/format_args_unfixable.rs | 8 ++-- tests/ui/io_other_error.fixed | 55 ++++++++++++++++++++++ tests/ui/io_other_error.rs | 55 ++++++++++++++++++++++ tests/ui/io_other_error.stderr | 52 ++++++++++++++++++++ 14 files changed, 239 insertions(+), 10 deletions(-) create mode 100644 clippy_lints/src/methods/io_other_error.rs create mode 100644 tests/ui/io_other_error.fixed create mode 100644 tests/ui/io_other_error.rs create mode 100644 tests/ui/io_other_error.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a7eebb3592..be5e95e9744e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5726,6 +5726,7 @@ Released 2018-09-13 [`invalid_utf8_in_unchecked`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_utf8_in_unchecked [`inverted_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#inverted_saturating_sub [`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters +[`io_other_error`]: https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error [`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix [`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements [`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index fc3d005c0c94..74c2be3479ec 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -759,6 +759,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`from_over_into`](https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into) * [`if_then_some_else_none`](https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none) * [`index_refutable_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) +* [`io_other_error`](https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error) * [`iter_kv_map`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map) * [`legacy_numeric_constants`](https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants) * [`lines_filter_map_ok`](https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 62f2f798a9cd..ff2a86182402 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -614,6 +614,7 @@ define_Conf! { from_over_into, if_then_some_else_none, index_refutable_slice, + io_other_error, iter_kv_map, legacy_numeric_constants, lines_filter_map_ok, diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index cc4b26867a20..cf6e44245660 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -1,11 +1,10 @@ use crate::utils::{clippy_project_root, clippy_version}; use indoc::{formatdoc, writedoc}; -use std::fmt; use std::fmt::Write as _; use std::fs::{self, OpenOptions}; use std::io::prelude::*; -use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; +use std::{fmt, io}; struct LintData<'a> { pass: &'a str, @@ -25,7 +24,7 @@ impl Context for io::Result { Ok(t) => Ok(t), Err(e) => { let message = format!("{}: {e}", text.as_ref()); - Err(io::Error::new(ErrorKind::Other, message)) + Err(io::Error::other(message)) }, } } diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1cc1a81f8cee..9df9a62438ce 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -400,6 +400,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::INEFFICIENT_TO_STRING_INFO, crate::methods::INSPECT_FOR_EACH_INFO, crate::methods::INTO_ITER_ON_REF_INFO, + crate::methods::IO_OTHER_ERROR_INFO, crate::methods::IS_DIGIT_ASCII_RADIX_INFO, crate::methods::ITERATOR_STEP_BY_ZERO_INFO, crate::methods::ITER_CLONED_COLLECT_INFO, diff --git a/clippy_lints/src/manual_div_ceil.rs b/clippy_lints/src/manual_div_ceil.rs index dd242c4168c6..04357cdd8f66 100644 --- a/clippy_lints/src/manual_div_ceil.rs +++ b/clippy_lints/src/manual_div_ceil.rs @@ -59,7 +59,7 @@ impl_lint_pass!(ManualDivCeil => [MANUAL_DIV_CEIL]); impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if !self.msrv.meets(msrvs::DIV_CEIL) { + if !self.msrv.meets(msrvs::MANUAL_DIV_CEIL) { return; } diff --git a/clippy_lints/src/methods/io_other_error.rs b/clippy_lints/src/methods/io_other_error.rs new file mode 100644 index 000000000000..e0ce013ca7b7 --- /dev/null +++ b/clippy_lints/src/methods/io_other_error.rs @@ -0,0 +1,37 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::msrvs::{IO_ERROR_OTHER, Msrv}; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind, QPath}; +use rustc_lint::LateContext; + +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args: &[Expr<'_>], msrv: &Msrv) { + if let [error_kind, error] = args + && !expr.span.from_expansion() + && !error_kind.span.from_expansion() + && clippy_utils::is_expr_path_def_path(cx, path, &clippy_utils::paths::IO_ERROR_NEW) + && clippy_utils::is_expr_path_def_path( + cx, + clippy_utils::expr_or_init(cx, error_kind), + &clippy_utils::paths::IO_ERRORKIND_OTHER, + ) + && let ExprKind::Path(QPath::TypeRelative(_, new_segment)) = path.kind + && msrv.meets(IO_ERROR_OTHER) + { + span_lint_and_then( + cx, + super::IO_OTHER_ERROR, + expr.span, + "this can be `std::io::Error::other(_)`", + |diag| { + diag.multipart_suggestion_verbose( + "use `std::io::Error::other`", + vec![ + (new_segment.ident.span, "other".to_owned()), + (error_kind.span.until(error.span), String::new()), + ], + Applicability::MachineApplicable, + ); + }, + ); + } +} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7f421d098270..291ddc1ce171 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -36,6 +36,7 @@ mod implicit_clone; mod inefficient_to_string; mod inspect_for_each; mod into_iter_on_ref; +mod io_other_error; mod is_digit_ascii_radix; mod is_empty; mod iter_cloned_collect; @@ -4461,6 +4462,28 @@ declare_clippy_lint! { "unnecessary `iter().any()` on slices that can be replaced with `contains()`" } +declare_clippy_lint! { + /// This lint warns on calling `io::Error::new(..)` with a kind of + /// `io::ErrorKind::Other`. + /// + /// ### Why is this bad? + /// Since Rust 1.74, there's the `io::Error::other(_)` shortcut. + /// + /// ### Example + /// ```no_run + /// use std::io; + /// let _ = io::Error::new(io::ErrorKind::Other, "bad".to_string()); + /// ``` + /// Use instead: + /// ```no_run + /// let _ = std::io::Error::other("bad".to_string()); + /// ``` + #[clippy::version = "1.86.0"] + pub IO_OTHER_ERROR, + style, + "calling `std::io::Error::new(std::io::ErrorKind::Other, _)`" +} + #[expect(clippy::struct_excessive_bools)] pub struct Methods { avoid_breaking_exported_api: bool, @@ -4637,6 +4660,7 @@ impl_lint_pass!(Methods => [ RETURN_AND_THEN, UNBUFFERED_BYTES, MANUAL_CONTAINS, + IO_OTHER_ERROR, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4666,6 +4690,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { unnecessary_fallible_conversions::check_function(cx, expr, func); manual_c_str_literals::check(cx, expr, func, args, &self.msrv); useless_nonzero_new_unchecked::check(cx, expr, func, args, &self.msrv); + io_other_error::check(cx, expr, func, args, &self.msrv); }, ExprKind::MethodCall(method_call, receiver, args, _) => { let method_span = method_call.ident.span; diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 7b3aedb80f90..8c9832af0a19 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -27,8 +27,8 @@ msrv_aliases! { 1,77,0 { C_STR_LITERALS } 1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT } 1,75,0 { OPTION_AS_SLICE } - 1,74,0 { REPR_RUST } - 1,73,0 { DIV_CEIL } + 1,74,0 { REPR_RUST, IO_ERROR_OTHER } + 1,73,0 { MANUAL_DIV_CEIL } 1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE } 1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN } 1,68,0 { PATH_MAIN_SEPARATOR_STR } diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 2250d991bd8e..452bb4ce4c77 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -29,6 +29,8 @@ pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"] // Paths in `core`/`alloc`/`std`. This should be avoided and cleaned up by adding diagnostic items. pub const CHAR_IS_ASCII: [&str; 5] = ["core", "char", "methods", "", "is_ascii"]; +pub const IO_ERROR_NEW: [&str; 5] = ["std", "io", "error", "Error", "new"]; +pub const IO_ERRORKIND_OTHER: [&str; 5] = ["std", "io", "error", "ErrorKind", "Other"]; // Paths in clippy itself pub const MSRV: [&str; 3] = ["clippy_utils", "msrvs", "Msrv"]; diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs index 08cd7dbe54f7..9e1d6a649c35 100644 --- a/tests/ui/format_args_unfixable.rs +++ b/tests/ui/format_args_unfixable.rs @@ -2,7 +2,7 @@ #![allow(unused)] #![allow(clippy::assertions_on_constants, clippy::eq_op, clippy::uninlined_format_args)] -use std::io::{Error, ErrorKind, Write, stdout}; +use std::io::{Error, Write, stdout}; use std::ops::Deref; use std::panic::Location; @@ -20,7 +20,7 @@ macro_rules! my_other_macro { } fn main() { - let error = Error::new(ErrorKind::Other, "bad thing"); + let error = Error::other("bad thing"); let x = 'x'; println!("error: {}", format!("something failed at {}", Location::caller())); @@ -115,7 +115,7 @@ macro_rules! my_println2_args { } fn test2() { - let error = Error::new(ErrorKind::Other, "bad thing"); + let error = Error::other("bad thing"); // None of these should be linted without the config change my_println2!(true, "error: {}", format!("something failed at {}", Location::caller())); @@ -145,7 +145,7 @@ macro_rules! usr_println { } fn user_format() { - let error = Error::new(ErrorKind::Other, "bad thing"); + let error = Error::other("bad thing"); let x = 'x'; usr_println!(true, "error: {}", format!("boom at {}", Location::caller())); diff --git a/tests/ui/io_other_error.fixed b/tests/ui/io_other_error.fixed new file mode 100644 index 000000000000..0054c56fb628 --- /dev/null +++ b/tests/ui/io_other_error.fixed @@ -0,0 +1,55 @@ +#![warn(clippy::io_other_error)] +use std::fmt; + +#[derive(Debug)] +struct E; + +impl std::error::Error for E {} +impl fmt::Display for E { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("E") + } +} + +macro_rules! o { + {} => { std::io::ErrorKind::Other }; +} + +macro_rules! e { + { $kind:expr } => { std::io::Error::new($kind, E) }; +} + +fn main() { + let _err = std::io::Error::other(E); + //~^ ERROR: this can be `std::io::Error::other(_)` + let other = std::io::ErrorKind::Other; + let _err = std::io::Error::other(E); + //~^ ERROR: this can be `std::io::Error::other(_)` + + // not other + let _err = std::io::Error::new(std::io::ErrorKind::TimedOut, E); + + // from expansion + let _err = e!(other); + let _err = std::io::Error::new(o!(), E); + let _err = e!(o!()); + + paths::short(); + under_msrv(); +} + +mod paths { + use std::io::{self, Error, ErrorKind}; + + pub fn short() { + let _err = Error::other(super::E); + //~^ ERROR: this can be `std::io::Error::other(_)` + let _err = io::Error::other(super::E); + //~^ ERROR: this can be `std::io::Error::other(_)` + } +} + +#[clippy::msrv = "1.73"] +fn under_msrv() { + let _err = std::io::Error::new(std::io::ErrorKind::Other, E); +} diff --git a/tests/ui/io_other_error.rs b/tests/ui/io_other_error.rs new file mode 100644 index 000000000000..8529fb9a77f9 --- /dev/null +++ b/tests/ui/io_other_error.rs @@ -0,0 +1,55 @@ +#![warn(clippy::io_other_error)] +use std::fmt; + +#[derive(Debug)] +struct E; + +impl std::error::Error for E {} +impl fmt::Display for E { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("E") + } +} + +macro_rules! o { + {} => { std::io::ErrorKind::Other }; +} + +macro_rules! e { + { $kind:expr } => { std::io::Error::new($kind, E) }; +} + +fn main() { + let _err = std::io::Error::new(std::io::ErrorKind::Other, E); + //~^ ERROR: this can be `std::io::Error::other(_)` + let other = std::io::ErrorKind::Other; + let _err = std::io::Error::new(other, E); + //~^ ERROR: this can be `std::io::Error::other(_)` + + // not other + let _err = std::io::Error::new(std::io::ErrorKind::TimedOut, E); + + // from expansion + let _err = e!(other); + let _err = std::io::Error::new(o!(), E); + let _err = e!(o!()); + + paths::short(); + under_msrv(); +} + +mod paths { + use std::io::{self, Error, ErrorKind}; + + pub fn short() { + let _err = Error::new(ErrorKind::Other, super::E); + //~^ ERROR: this can be `std::io::Error::other(_)` + let _err = io::Error::new(io::ErrorKind::Other, super::E); + //~^ ERROR: this can be `std::io::Error::other(_)` + } +} + +#[clippy::msrv = "1.73"] +fn under_msrv() { + let _err = std::io::Error::new(std::io::ErrorKind::Other, E); +} diff --git a/tests/ui/io_other_error.stderr b/tests/ui/io_other_error.stderr new file mode 100644 index 000000000000..e79e05ecd406 --- /dev/null +++ b/tests/ui/io_other_error.stderr @@ -0,0 +1,52 @@ +error: this can be `std::io::Error::other(_)` + --> tests/ui/io_other_error.rs:23:16 + | +LL | let _err = std::io::Error::new(std::io::ErrorKind::Other, E); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::io-other-error` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::io_other_error)]` +help: use `std::io::Error::other` + | +LL - let _err = std::io::Error::new(std::io::ErrorKind::Other, E); +LL + let _err = std::io::Error::other(E); + | + +error: this can be `std::io::Error::other(_)` + --> tests/ui/io_other_error.rs:26:16 + | +LL | let _err = std::io::Error::new(other, E); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use `std::io::Error::other` + | +LL - let _err = std::io::Error::new(other, E); +LL + let _err = std::io::Error::other(E); + | + +error: this can be `std::io::Error::other(_)` + --> tests/ui/io_other_error.rs:45:20 + | +LL | let _err = Error::new(ErrorKind::Other, super::E); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use `std::io::Error::other` + | +LL - let _err = Error::new(ErrorKind::Other, super::E); +LL + let _err = Error::other(super::E); + | + +error: this can be `std::io::Error::other(_)` + --> tests/ui/io_other_error.rs:47:20 + | +LL | let _err = io::Error::new(io::ErrorKind::Other, super::E); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use `std::io::Error::other` + | +LL - let _err = io::Error::new(io::ErrorKind::Other, super::E); +LL + let _err = io::Error::other(super::E); + | + +error: aborting due to 4 previous errors + From e5dbcc2c16bd73f2b6bb81c452af66289c2a3902 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 17 Feb 2025 05:33:06 +0000 Subject: [PATCH 142/161] Make asm a named field --- clippy_lints/src/arbitrary_source_item_ordering.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index aff40fa846be..c0ae4960e10d 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -362,7 +362,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { } } else if let ItemKind::ForeignMod { .. } = item.kind { continue; - } else if let ItemKind::GlobalAsm(_) = item.kind { + } else if let ItemKind::GlobalAsm { .. } = item.kind { continue; } else if let ItemKind::Use(path, use_kind) = item.kind { if path.segments.is_empty() { @@ -467,7 +467,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte ItemKind::Macro(..) => Macro, ItemKind::Mod(..) => Mod, ItemKind::ForeignMod { .. } => ForeignMod, - ItemKind::GlobalAsm(..) => GlobalAsm, + ItemKind::GlobalAsm { .. } => GlobalAsm, ItemKind::TyAlias(..) => TyAlias, ItemKind::Enum(..) => Enum, ItemKind::Struct(..) => Struct, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 06e92985e664..47a9e17b3cfe 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -217,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::Union(..) => {}, hir::ItemKind::ExternCrate(..) | hir::ItemKind::ForeignMod { .. } - | hir::ItemKind::GlobalAsm(..) + | hir::ItemKind::GlobalAsm { .. } | hir::ItemKind::Impl { .. } | hir::ItemKind::Use(..) => note_prev_span_then_ret!(self.prev_span, it.span), } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index fdc0930e957a..3cf1a80607e8 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::TraitAlias(..) - | hir::ItemKind::GlobalAsm(..) + | hir::ItemKind::GlobalAsm { .. } | hir::ItemKind::TyAlias(..) | hir::ItemKind::Union(..) | hir::ItemKind::ExternCrate(..) From ba8079d0dbb1c5237e04c207ac06640ae189a960 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 17 Feb 2025 16:09:46 +0000 Subject: [PATCH 143/161] Make a fake body to store typeck results for global_asm --- clippy_lints/src/operators/numeric_arithmetic.rs | 2 +- clippy_utils/src/hir_utils.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/operators/numeric_arithmetic.rs b/clippy_lints/src/operators/numeric_arithmetic.rs index cda99a362dca..c261fd9bd9cb 100644 --- a/clippy_lints/src/operators/numeric_arithmetic.rs +++ b/clippy_lints/src/operators/numeric_arithmetic.rs @@ -82,7 +82,7 @@ impl Context { } self.const_span = Some(body_span); }, - hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => (), + hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::GlobalAsm => (), } } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 9ee30094d608..0ac675345ae0 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -968,7 +968,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_expr(out_expr); } }, - InlineAsmOperand::Const { anon_const } | InlineAsmOperand::SymFn { anon_const } => { + InlineAsmOperand::SymFn { expr } => { + self.hash_expr(expr); + } + InlineAsmOperand::Const { anon_const } => { self.hash_body(anon_const.body); }, InlineAsmOperand::SymStatic { path, def_id: _ } => self.hash_qpath(path), From 2ad3520d514d41eeb892652ea8da95323e1242ed Mon Sep 17 00:00:00 2001 From: yanglsh Date: Sat, 22 Feb 2025 19:04:25 +0800 Subject: [PATCH 144/161] fix: `too_long_first_doc_paragraph` suggests wrongly when first line too long --- clippy_lints/src/doc/too_long_first_doc_paragraph.rs | 4 ++++ tests/ui/too_long_first_doc_paragraph.rs | 7 +++++++ tests/ui/too_long_first_doc_paragraph.stderr | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 1f89cab91480..8f9a54d50f88 100644 --- a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -51,7 +51,11 @@ pub(super) fn check( // We make this suggestion only if the first doc line ends with a punctuation // because it might just need to add an empty line with `///`. should_suggest_empty_doc = doc.ends_with('.') || doc.ends_with('!') || doc.ends_with('?'); + } else if spans.len() == 2 { + // We make this suggestion only if the second doc line is not empty. + should_suggest_empty_doc &= !doc.is_empty(); } + let len = doc.chars().count(); if len >= first_paragraph_len { break; diff --git a/tests/ui/too_long_first_doc_paragraph.rs b/tests/ui/too_long_first_doc_paragraph.rs index 2321e228866c..49420841c88c 100644 --- a/tests/ui/too_long_first_doc_paragraph.rs +++ b/tests/ui/too_long_first_doc_paragraph.rs @@ -61,6 +61,13 @@ pub union Union2 { /// gravida non lacinia at, rhoncus eu lacus. fn f() {} +#[rustfmt::skip] +/// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. +//~^ too_long_first_doc_paragraph +/// +/// Here's a second paragraph. It would be preferable to put the details here. +pub fn issue_14274() {} + fn main() { // test code goes here } diff --git a/tests/ui/too_long_first_doc_paragraph.stderr b/tests/ui/too_long_first_doc_paragraph.stderr index 2d4abaa9d63c..287a2c1c3e44 100644 --- a/tests/ui/too_long_first_doc_paragraph.stderr +++ b/tests/ui/too_long_first_doc_paragraph.stderr @@ -39,5 +39,14 @@ LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris a LL | | /// gravida non lacinia at, rhoncus eu lacus. | |_^ -error: aborting due to 3 previous errors +error: first doc comment paragraph is too long + --> tests/ui/too_long_first_doc_paragraph.rs:65:1 + | +LL | / /// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lore... +LL | | +LL | | /// +LL | | /// Here's a second paragraph. It would be preferable to put the details here. + | |_^ + +error: aborting due to 4 previous errors From 443b0f5ccf3181f18afa6102008ab4536ef0e5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Sun, 9 Feb 2025 22:49:57 +0100 Subject: [PATCH 145/161] Fix rustdoc and clippy --- clippy_lints/src/attrs/inline_always.rs | 2 +- clippy_lints/src/attrs/repr_attributes.rs | 42 ++++++------- .../src/attrs/unnecessary_clippy_cfg.rs | 2 +- clippy_lints/src/attrs/utils.rs | 2 +- .../src/default_union_representation.rs | 17 ++---- clippy_lints/src/disallowed_macros.rs | 1 + .../src/doc/include_in_doc_without_cfg.rs | 9 ++- clippy_lints/src/doc/mod.rs | 12 +++- .../src/doc/suspicious_doc_comments.rs | 10 ++-- .../src/doc/too_long_first_doc_paragraph.rs | 9 +-- clippy_lints/src/four_forward_slashes.rs | 3 +- clippy_lints/src/functions/must_use.rs | 7 ++- .../src/inconsistent_struct_constructor.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 4 +- clippy_lints/src/large_include_file.rs | 59 +++++++++++-------- clippy_lints/src/lib.rs | 4 +- clippy_lints/src/macro_use.rs | 6 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/no_mangle_with_rust_abi.rs | 2 +- .../src/undocumented_unsafe_blocks.rs | 2 +- clippy_utils/src/lib.rs | 3 +- .../large_include_file.stderr | 20 +++---- tests/ui/must_use_unit.fixed | 4 +- tests/ui/must_use_unit.stderr | 6 +- 24 files changed, 118 insertions(+), 112 deletions(-) diff --git a/clippy_lints/src/attrs/inline_always.rs b/clippy_lints/src/attrs/inline_always.rs index 2325f914b0b0..cb63fadb4e21 100644 --- a/clippy_lints/src/attrs/inline_always.rs +++ b/clippy_lints/src/attrs/inline_always.rs @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Att span_lint( cx, INLINE_ALWAYS, - attr.span, + attr.span(), format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"), ); } diff --git a/clippy_lints/src/attrs/repr_attributes.rs b/clippy_lints/src/attrs/repr_attributes.rs index 6d1ab46aa0c1..6cc47596bbb6 100644 --- a/clippy_lints/src/attrs/repr_attributes.rs +++ b/clippy_lints/src/attrs/repr_attributes.rs @@ -1,6 +1,7 @@ +use rustc_attr_parsing::{find_attr, AttributeKind, ReprAttr}; use rustc_hir::Attribute; use rustc_lint::LateContext; -use rustc_span::{Span, sym}; +use rustc_span::Span; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs; @@ -14,30 +15,21 @@ pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute], } fn check_packed(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) { - if let Some(items) = attrs.iter().find_map(|attr| { - if attr.ident().is_some_and(|ident| matches!(ident.name, sym::repr)) { - attr.meta_item_list() - } else { - None + if let Some(reprs) = find_attr!(attrs, AttributeKind::Repr(r) => r) { + let packed_span = reprs.iter().find(|(r, _)| matches!(r, ReprAttr::ReprPacked(..))).map(|(_, s)| *s); + + if let Some(packed_span) = packed_span && !reprs.iter().any(|(x, _)| *x == ReprAttr::ReprC || *x == ReprAttr::ReprRust) { + span_lint_and_then( + cx, + REPR_PACKED_WITHOUT_ABI, + item_span, + "item uses `packed` representation without ABI-qualification", + |diag| { + diag.warn("unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI") + .help("qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`") + .span_label(packed_span, "`packed` representation set here"); + }, + ); } - }) && let Some(packed) = items - .iter() - .find(|item| item.ident().is_some_and(|ident| matches!(ident.name, sym::packed))) - && !items.iter().any(|item| { - item.ident() - .is_some_and(|ident| matches!(ident.name, sym::C | sym::Rust)) - }) - { - span_lint_and_then( - cx, - REPR_PACKED_WITHOUT_ABI, - item_span, - "item uses `packed` representation without ABI-qualification", - |diag| { - diag.warn("unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI") - .help("qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`") - .span_label(packed.span(), "`packed` representation set here"); - }, - ); } } diff --git a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs b/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs index 478ba7a187be..6ee3290fa761 100644 --- a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs +++ b/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs @@ -15,7 +15,7 @@ pub(super) fn check( ) { if cfg_attr.has_name(sym::clippy) && let Some(ident) = behind_cfg_attr.ident() - && Level::from_symbol(ident.name, Some(attr.id)).is_some() + && Level::from_symbol(ident.name, || Some(attr.id)).is_some() && let Some(items) = behind_cfg_attr.meta_item_list() { let nb_items = items.len(); diff --git a/clippy_lints/src/attrs/utils.rs b/clippy_lints/src/attrs/utils.rs index a667649f7343..0e650e493925 100644 --- a/clippy_lints/src/attrs/utils.rs +++ b/clippy_lints/src/attrs/utils.rs @@ -17,7 +17,7 @@ pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool { } pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { - Level::from_symbol(symbol, Some(attr_id)).is_some() + Level::from_symbol(symbol, || Some(attr_id)).is_some() } pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index 9f020d3081c4..6e6d81db11c0 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; +use rustc_attr_parsing::{find_attr, AttributeKind, ReprAttr}; use rustc_hir::{HirId, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, FieldDef}; use rustc_session::declare_lint_pass; -use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -97,16 +97,7 @@ fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsR } fn has_c_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool { - cx.tcx.hir().attrs(hir_id).iter().any(|attr| { - if attr.has_name(sym::repr) { - if let Some(items) = attr.meta_item_list() { - for item in items { - if item.is_word() && matches!(item.name_or_empty(), sym::C) { - return true; - } - } - } - } - false - }) + let attrs = cx.tcx.hir().attrs(hir_id); + + find_attr!(attrs, AttributeKind::Repr(r) if r.iter().any(|(x, _)| *x == ReprAttr::ReprC)) } diff --git a/clippy_lints/src/disallowed_macros.rs b/clippy_lints/src/disallowed_macros.rs index 4e8853821c3e..6de16e306c9a 100644 --- a/clippy_lints/src/disallowed_macros.rs +++ b/clippy_lints/src/disallowed_macros.rs @@ -1,3 +1,4 @@ + use clippy_config::Conf; use clippy_config::types::create_disallowed_map; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; diff --git a/clippy_lints/src/doc/include_in_doc_without_cfg.rs b/clippy_lints/src/doc/include_in_doc_without_cfg.rs index 4b40fc0b1ee2..aa29705cf938 100644 --- a/clippy_lints/src/doc/include_in_doc_without_cfg.rs +++ b/clippy_lints/src/doc/include_in_doc_without_cfg.rs @@ -1,18 +1,17 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; -use rustc_ast::AttrStyle; use rustc_errors::Applicability; -use rustc_hir::{AttrArgs, AttrKind, Attribute}; -use rustc_lint::LateContext; +use rustc_lint::EarlyContext; +use rustc_ast::{Attribute, AttrKind, AttrArgs, AttrStyle}; use super::DOC_INCLUDE_WITHOUT_CFG; -pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) { +pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) { for attr in attrs { if !attr.span.from_expansion() && let AttrKind::Normal(ref item) = attr.kind && attr.doc_str().is_some() - && let AttrArgs::Eq { expr: meta, .. } = &item.args + && let AttrArgs::Eq { expr: meta, .. } = &item.item.args && !attr.span.contains(meta.span) // Since the `include_str` is already expanded at this point, we can only take the // whole attribute snippet and then modify for our suggestion. diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 713d62a8801d..42192801af7c 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -20,7 +20,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Attribute, Expr, ImplItemKind, ItemKind, Node, Safety, TraitItemKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::ty; use rustc_resolve::rustdoc::{ @@ -577,6 +577,13 @@ impl_lint_pass!(Documentation => [ DOC_INCLUDE_WITHOUT_CFG, ]); + +impl EarlyLintPass for Documentation { + fn check_attributes(&mut self, cx: &EarlyContext<'_>, attrs: &[rustc_ast::Attribute]) { + include_in_doc_without_cfg::check(cx, attrs); + } +} + impl<'tcx> LateLintPass<'tcx> for Documentation { fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { @@ -704,14 +711,13 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ Some(("fake".into(), "fake".into())) } - include_in_doc_without_cfg::check(cx, attrs); if suspicious_doc_comments::check(cx, attrs) || is_doc_hidden(attrs) { return None; } let (fragments, _) = attrs_to_doc_fragments( attrs.iter().filter_map(|attr| { - if attr.span.in_external_macro(cx.sess().source_map()) { + if !attr.doc_str_and_comment_kind().is_some() || attr.span().in_external_macro(cx.sess().source_map()) { None } else { Some((attr, None)) diff --git a/clippy_lints/src/doc/suspicious_doc_comments.rs b/clippy_lints/src/doc/suspicious_doc_comments.rs index 84393213e6f0..bfc36deea7b2 100644 --- a/clippy_lints/src/doc/suspicious_doc_comments.rs +++ b/clippy_lints/src/doc/suspicious_doc_comments.rs @@ -3,6 +3,7 @@ use rustc_ast::AttrStyle; use rustc_ast::token::CommentKind; use rustc_errors::Applicability; use rustc_hir::Attribute; +use rustc_attr_parsing::AttributeKind; use rustc_lint::LateContext; use rustc_span::Span; @@ -36,15 +37,14 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> { attrs .iter() .filter_map(|attr| { - if let Some((sym, com_kind)) = attr.doc_str_and_comment_kind() - && let AttrStyle::Outer = attr.style - && let Some(com) = sym.as_str().strip_prefix('!') + if let Attribute::Parsed(AttributeKind::DocComment{ style: AttrStyle::Outer, kind, comment, ..}) = attr + && let Some(com) = comment.as_str().strip_prefix('!') { - let sugg = match com_kind { + let sugg = match kind { CommentKind::Line => format!("//!{com}"), CommentKind::Block => format!("/*!{com}*/"), }; - Some((attr.span, sugg)) + Some((attr.span(), sugg)) } else { None } diff --git a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 1f89cab91480..1eda73a96727 100644 --- a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -1,5 +1,6 @@ use rustc_errors::Applicability; use rustc_hir::{Attribute, Item, ItemKind}; +use rustc_attr_parsing::AttributeKind; use rustc_lint::LateContext; use clippy_utils::diagnostics::span_lint_and_then; @@ -43,9 +44,9 @@ pub(super) fn check( let mut should_suggest_empty_doc = false; for attr in attrs { - if let Some(doc) = attr.doc_str() { - spans.push(attr.span); - let doc = doc.as_str(); + if let Attribute::Parsed(AttributeKind::DocComment {span, comment, ..}) = attr { + spans.push(span); + let doc = comment.as_str(); let doc = doc.trim(); if spans.len() == 1 { // We make this suggestion only if the first doc line ends with a punctuation @@ -78,7 +79,7 @@ pub(super) fn check( && let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi()) && let Some(snippet) = snippet_opt(cx, new_span) { - let Some(first) = snippet_opt(cx, first_span) else { + let Some(first) = snippet_opt(cx, *first_span) else { return; }; let Some(comment_form) = first.get(..3) else { diff --git a/clippy_lints/src/four_forward_slashes.rs b/clippy_lints/src/four_forward_slashes.rs index 0599e08e6c0a..0bdb99d7b9a4 100644 --- a/clippy_lints/src/four_forward_slashes.rs +++ b/clippy_lints/src/four_forward_slashes.rs @@ -46,7 +46,8 @@ impl<'tcx> LateLintPass<'tcx> for FourForwardSlashes { .hir() .attrs(item.hir_id()) .iter() - .fold(item.span.shrink_to_lo(), |span, attr| span.to(attr.span)); + .filter(|i| i.is_doc_comment()) + .fold(item.span.shrink_to_lo(), |span, attr| span.to(attr.span())); let (Some(file), _, _, end_line, _) = sm.span_to_location_info(span) else { return; }; diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index e6e3ea59a9f6..dbc08fca3624 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -95,6 +95,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr } } +// FIXME: needs to be an EARLY LINT. all attribute lints should be #[allow(clippy::too_many_arguments)] fn check_needless_must_use( cx: &LateContext<'_>, @@ -117,7 +118,7 @@ fn check_needless_must_use( fn_header_span, "this unit-returning function has a `#[must_use]` attribute", |diag| { - diag.span_suggestion(attr.span, "remove the attribute", "", Applicability::MachineApplicable); + diag.span_suggestion(attr.span(), "remove the attribute", "", Applicability::MachineApplicable); }, ); } else { @@ -130,7 +131,7 @@ fn check_needless_must_use( "this unit-returning function has a `#[must_use]` attribute", |diag| { let mut attrs_without_must_use = attrs.to_vec(); - attrs_without_must_use.retain(|a| a.id != attr.id); + attrs_without_must_use.retain(|a| a.id() != attr.id()); let sugg_str = attrs_without_must_use .iter() .map(|a| { @@ -143,7 +144,7 @@ fn check_needless_must_use( .join(", "); diag.span_suggestion( - attrs[0].span.with_hi(attrs[attrs.len() - 1].span.hi()), + attrs[0].span().with_hi(attrs[attrs.len() - 1].span().hi()), "change these attributes to", sugg_str, Applicability::MachineApplicable, diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs index 39ff3c13bcce..5b58113169b1 100644 --- a/clippy_lints/src/inconsistent_struct_constructor.rs +++ b/clippy_lints/src/inconsistent_struct_constructor.rs @@ -183,7 +183,7 @@ fn suggestion<'tcx>( fn field_with_attrs_span(tcx: TyCtxt<'_>, field: &hir::ExprField<'_>) -> Span { if let Some(attr) = tcx.hir().attrs(field.hir_id).first() { - field.span.with_lo(attr.span.lo()) + field.span.with_lo(attr.span().lo()) } else { field.span } diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 1b900f6be8e8..9b4a3b3f9c84 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -42,10 +42,10 @@ impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody { span_lint_and_then( cx, INLINE_FN_WITHOUT_BODY, - attr.span, + attr.span(), format!("use of `#[inline]` on trait method `{}` which has no body", item.ident), |diag| { - diag.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable); + diag.suggest_remove_item(cx, attr.span(), "remove", Applicability::MachineApplicable); }, ); } diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs index f3d62b513e84..53dc070833b5 100644 --- a/clippy_lints/src/large_include_file.rs +++ b/clippy_lints/src/large_include_file.rs @@ -3,10 +3,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::source::snippet_opt; use rustc_ast::LitKind; -use rustc_hir::{AttrArgs, AttrKind, Attribute, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_hir::{Expr, ExprKind}; +use rustc_ast::{Attribute, AttrArgs, AttrKind}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_span::{Span, sym}; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -52,24 +53,6 @@ impl LargeIncludeFile { impl_lint_pass!(LargeIncludeFile => [LARGE_INCLUDE_FILE]); -impl LargeIncludeFile { - fn emit_lint(&self, cx: &LateContext<'_>, span: Span) { - #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] - span_lint_and_then( - cx, - LARGE_INCLUDE_FILE, - span, - "attempted to include a large file", - |diag| { - diag.note(format!( - "the configuration allows a maximum size of {} bytes", - self.max_file_size - )); - }, - ); - } -} - impl LateLintPass<'_> for LargeIncludeFile { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { if let ExprKind::Lit(lit) = &expr.kind @@ -85,18 +68,32 @@ impl LateLintPass<'_> for LargeIncludeFile { && (cx.tcx.is_diagnostic_item(sym::include_bytes_macro, macro_call.def_id) || cx.tcx.is_diagnostic_item(sym::include_str_macro, macro_call.def_id)) { - self.emit_lint(cx, expr.span.source_callsite()); + #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] + span_lint_and_then( + cx, + LARGE_INCLUDE_FILE, + expr.span.source_callsite(), + "attempted to include a large file", + |diag| { + diag.note(format!( + "the configuration allows a maximum size of {} bytes", + self.max_file_size + )); + }, + ); } } +} - fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &Attribute) { +impl EarlyLintPass for LargeIncludeFile { + fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { if !attr.span.from_expansion() // Currently, rustc limits the usage of macro at the top-level of attributes, // so we don't need to recurse into each level. && let AttrKind::Normal(ref item) = attr.kind && let Some(doc) = attr.doc_str() && doc.as_str().len() as u64 > self.max_file_size - && let AttrArgs::Eq { expr: meta, .. } = &item.args + && let AttrArgs::Eq { expr: meta, .. } = &item.item.args && !attr.span.contains(meta.span) // Since the `include_str` is already expanded at this point, we can only take the // whole attribute snippet and then modify for our suggestion. @@ -113,7 +110,19 @@ impl LateLintPass<'_> for LargeIncludeFile { && let sub_snippet = sub_snippet.trim() && (sub_snippet.starts_with("include_str!") || sub_snippet.starts_with("include_bytes!")) { - self.emit_lint(cx, attr.span); + #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] + span_lint_and_then( + cx, + LARGE_INCLUDE_FILE, + attr.span, + "attempted to include a large file", + |diag| { + diag.note(format!( + "the configuration allows a maximum size of {} bytes", + self.max_file_size + )); + }, + ); } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 13218331a67b..177f83921cd5 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -407,9 +407,9 @@ mod zombie_processes; use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation}; use clippy_utils::macros::FormatArgsStorage; +use utils::attr_collector::{AttrCollector, AttrStorage}; use rustc_data_structures::fx::FxHashSet; use rustc_lint::{Lint, LintId}; -use utils::attr_collector::{AttrCollector, AttrStorage}; /// Register all pre expansion lints /// @@ -717,6 +717,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(disallowed_names::DisallowedNames::new(conf))); store.register_late_pass(move |tcx| Box::new(functions::Functions::new(tcx, conf))); store.register_late_pass(move |_| Box::new(doc::Documentation::new(conf))); + store.register_early_pass(move || Box::new(doc::Documentation::new(conf))); store.register_late_pass(|_| Box::new(neg_multiply::NegMultiply)); store.register_late_pass(|_| Box::new(let_if_seq::LetIfSeq)); store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence)); @@ -860,6 +861,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_early_pass(|| Box::new(pub_use::PubUse)); store.register_late_pass(|_| Box::new(format_push_string::FormatPushString)); store.register_late_pass(move |_| Box::new(large_include_file::LargeIncludeFile::new(conf))); + store.register_early_pass(move || Box::new(large_include_file::LargeIncludeFile::new(conf))); store.register_late_pass(|_| Box::new(strings::TrimSplitWhitespace)); store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit)); store.register_early_pass(|| Box::::default()); diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 374128665392..165e8c2ea05a 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -94,7 +94,7 @@ impl LateLintPass<'_> for MacroUseImports { { for kid in cx.tcx.module_children(id) { if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res { - let span = mac_attr.span; + let span = mac_attr.span(); let def_path = cx.tcx.def_path_str(mac_id); self.imports.push((def_path, span, hir_id)); } @@ -104,8 +104,8 @@ impl LateLintPass<'_> for MacroUseImports { } } fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &hir::Attribute) { - if attr.span.from_expansion() { - self.push_unique_macro(cx, attr.span); + if attr.span().from_expansion() { + self.push_unique_macro(cx, attr.span()); } } fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 00800231fe46..83d8a5093906 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive { if let Some(non_exhaustive) = attr::find_by_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive) { - diag.span_note(non_exhaustive.span, "the struct is already non-exhaustive"); + diag.span_note(non_exhaustive.span(), "the struct is already non-exhaustive"); } else { let indent = snippet_indent(cx, item.span).unwrap_or_default(); diag.span_suggestion_verbose( diff --git a/clippy_lints/src/no_mangle_with_rust_abi.rs b/clippy_lints/src/no_mangle_with_rust_abi.rs index b73b9083a991..6eca3f12cf25 100644 --- a/clippy_lints/src/no_mangle_with_rust_abi.rs +++ b/clippy_lints/src/no_mangle_with_rust_abi.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi { .span .with_lo(fn_sig.span.lo() + BytePos::from_usize(fn_attrs.len())) .shrink_to_lo(); - let attr_snippet = snippet(cx, attr.span, ".."); + let attr_snippet = snippet(cx, attr.span(), ".."); span_lint_and_then( cx, diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 93abf95e3577..16916e3aaad5 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -432,7 +432,7 @@ fn include_attrs_in_span(cx: &LateContext<'_>, hir_id: HirId, span: Span) -> Spa .hir() .attrs(hir_id) .iter() - .fold(span, |acc, attr| acc.to(attr.span))) + .fold(span, |acc, attr| acc.to(attr.span()))) } enum HasSafetyComment { diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 40ddd75b7fad..7fc25e3617d0 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -93,6 +93,7 @@ use std::sync::{Mutex, MutexGuard, OnceLock}; use itertools::Itertools; use rustc_ast::ast::{self, LitKind, RangeLimits}; +use rustc_attr_parsing::{find_attr, AttributeKind}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnhashMap; @@ -1949,7 +1950,7 @@ pub fn has_attr(attrs: &[hir::Attribute], symbol: Symbol) -> bool { } pub fn has_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool { - has_attr(cx.tcx.hir().attrs(hir_id), sym::repr) + find_attr!(cx.tcx.hir().attrs(hir_id), AttributeKind::Repr(..)) } pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool { diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index 82b926cc53ba..c9f0e661dbd1 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -1,3 +1,13 @@ +error: attempted to include a large file + --> tests/ui-toml/large_include_file/large_include_file.rs:19:1 + | +LL | #[doc = include_str!("too_big.txt")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the configuration allows a maximum size of 600 bytes + = note: `-D clippy::large-include-file` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` + error: attempted to include a large file --> tests/ui-toml/large_include_file/large_include_file.rs:14:43 | @@ -5,8 +15,6 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the configuration allows a maximum size of 600 bytes - = note: `-D clippy::large-include-file` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` error: attempted to include a large file --> tests/ui-toml/large_include_file/large_include_file.rs:16:35 @@ -16,13 +24,5 @@ LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); | = note: the configuration allows a maximum size of 600 bytes -error: attempted to include a large file - --> tests/ui-toml/large_include_file/large_include_file.rs:19:1 - | -LL | #[doc = include_str!("too_big.txt")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the configuration allows a maximum size of 600 bytes - error: aborting due to 3 previous errors diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index b92d9379c904..f2b990beddc4 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -24,8 +24,8 @@ fn main() { ); } -#[cfg_attr(all(), deprecated)] +#[cfg_attr(all(), )] fn issue_12320() {} -#[cfg_attr(all(), deprecated, doc = "foo")] +#[cfg_attr(all(), deprecateddoc = "foo", doc = "foo", must_use)] fn issue_12320_2() {} diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index b435568deeab..40a0dc3ca9b0 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -25,19 +25,21 @@ LL | #[must_use = "With note"] LL | pub fn must_use_with_note() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +[Unparsed(AttrItem { path: AttrPath { segments: [must_use#0], span: tests/ui/must_use_unit.rs:30:19: 30:27 (#0) }, args: Empty, id: HashIgnoredAttrId { attr_id: AttrId(9) }, style: Outer, span: tests/ui/must_use_unit.rs:30:19: 30:27 (#0) }), Parsed(Deprecation { deprecation: Deprecation { since: Unspecified, note: None, suggestion: None }, span: tests/ui/must_use_unit.rs:30:29: 30:39 (#0) })] error: this unit-returning function has a `#[must_use]` attribute --> tests/ui/must_use_unit.rs:31:1 | LL | #[cfg_attr(all(), must_use, deprecated)] - | -------------------- help: change these attributes to: `deprecated` + | -------------------- help: change these attributes to LL | fn issue_12320() {} | ^^^^^^^^^^^^^^^^ +[Unparsed(AttrItem { path: AttrPath { segments: [doc#0], span: tests/ui/must_use_unit.rs:33:31: 33:34 (#0) }, args: Eq { eq_span: tests/ui/must_use_unit.rs:33:35: 33:36 (#0), expr: MetaItemLit { symbol: "foo", suffix: None, kind: Str("foo", Cooked), span: tests/ui/must_use_unit.rs:33:37: 33:42 (#0) } }, id: HashIgnoredAttrId { attr_id: AttrId(12) }, style: Outer, span: tests/ui/must_use_unit.rs:33:31: 33:42 (#0) }), Unparsed(AttrItem { path: AttrPath { segments: [must_use#0], span: tests/ui/must_use_unit.rs:33:44: 33:52 (#0) }, args: Empty, id: HashIgnoredAttrId { attr_id: AttrId(13) }, style: Outer, span: tests/ui/must_use_unit.rs:33:44: 33:52 (#0) }), Parsed(Deprecation { deprecation: Deprecation { since: Unspecified, note: None, suggestion: None }, span: tests/ui/must_use_unit.rs:33:19: 33:29 (#0) })] error: this unit-returning function has a `#[must_use]` attribute --> tests/ui/must_use_unit.rs:34:1 | LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] - | --------------------------------- help: change these attributes to: `deprecated, doc = "foo"` + | -- help: change these attributes to: `doc = "foo",` LL | fn issue_12320_2() {} | ^^^^^^^^^^^^^^^^^^ From 17bda0c0febb8c51fb14a6856d365eab86fc6162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Sun, 9 Feb 2025 22:49:59 +0100 Subject: [PATCH 146/161] simplify must-use lint slightly --- clippy_lints/src/functions/must_use.rs | 30 ++++++-------------------- tests/ui/must_use_unit.fixed | 5 ----- tests/ui/must_use_unit.rs | 5 ----- tests/ui/must_use_unit.stderr | 20 +---------------- tests/ui/must_use_unit_12320.rs | 11 ++++++++++ tests/ui/must_use_unit_12320.stderr | 28 ++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 52 deletions(-) create mode 100644 tests/ui/must_use_unit_12320.rs create mode 100644 tests/ui/must_use_unit_12320.stderr diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index dbc08fca3624..0ed4426d6e92 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -124,32 +124,16 @@ fn check_needless_must_use( } else { // When there are multiple attributes, it is not sufficient to simply make `must_use` empty, see // issue #12320. - span_lint_and_then( + // FIXME(jdonszelmann): this used to give a machine-applicable fix. However, it was super fragile, + // honestly looked incorrect, and is a little hard to support for a little bit now. Some day this could be + // re-added. + span_lint_and_help( cx, - MUST_USE_UNIT, + DOUBLE_MUST_USE, fn_header_span, "this unit-returning function has a `#[must_use]` attribute", - |diag| { - let mut attrs_without_must_use = attrs.to_vec(); - attrs_without_must_use.retain(|a| a.id() != attr.id()); - let sugg_str = attrs_without_must_use - .iter() - .map(|a| { - if a.value_str().is_none() { - return a.name_or_empty().to_string(); - } - format!("{} = \"{}\"", a.name_or_empty(), a.value_str().unwrap()) - }) - .collect::>() - .join(", "); - - diag.span_suggestion( - attrs[0].span().with_hi(attrs[attrs.len() - 1].span().hi()), - "change these attributes to", - sugg_str, - Applicability::MachineApplicable, - ); - }, + Some(attr.span()), + "remove `must_use`", ); } } else if attr.value_str().is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) { diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index f2b990beddc4..7e2a72960492 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -24,8 +24,3 @@ fn main() { ); } -#[cfg_attr(all(), )] -fn issue_12320() {} - -#[cfg_attr(all(), deprecateddoc = "foo", doc = "foo", must_use)] -fn issue_12320_2() {} diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index c77e72827504..f41b1a7c8005 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -27,8 +27,3 @@ fn main() { ); } -#[cfg_attr(all(), must_use, deprecated)] -fn issue_12320() {} - -#[cfg_attr(all(), deprecated, doc = "foo", must_use)] -fn issue_12320_2() {} diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index 40a0dc3ca9b0..c2ee2edda7dc 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -25,23 +25,5 @@ LL | #[must_use = "With note"] LL | pub fn must_use_with_note() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -[Unparsed(AttrItem { path: AttrPath { segments: [must_use#0], span: tests/ui/must_use_unit.rs:30:19: 30:27 (#0) }, args: Empty, id: HashIgnoredAttrId { attr_id: AttrId(9) }, style: Outer, span: tests/ui/must_use_unit.rs:30:19: 30:27 (#0) }), Parsed(Deprecation { deprecation: Deprecation { since: Unspecified, note: None, suggestion: None }, span: tests/ui/must_use_unit.rs:30:29: 30:39 (#0) })] -error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:31:1 - | -LL | #[cfg_attr(all(), must_use, deprecated)] - | -------------------- help: change these attributes to -LL | fn issue_12320() {} - | ^^^^^^^^^^^^^^^^ - -[Unparsed(AttrItem { path: AttrPath { segments: [doc#0], span: tests/ui/must_use_unit.rs:33:31: 33:34 (#0) }, args: Eq { eq_span: tests/ui/must_use_unit.rs:33:35: 33:36 (#0), expr: MetaItemLit { symbol: "foo", suffix: None, kind: Str("foo", Cooked), span: tests/ui/must_use_unit.rs:33:37: 33:42 (#0) } }, id: HashIgnoredAttrId { attr_id: AttrId(12) }, style: Outer, span: tests/ui/must_use_unit.rs:33:31: 33:42 (#0) }), Unparsed(AttrItem { path: AttrPath { segments: [must_use#0], span: tests/ui/must_use_unit.rs:33:44: 33:52 (#0) }, args: Empty, id: HashIgnoredAttrId { attr_id: AttrId(13) }, style: Outer, span: tests/ui/must_use_unit.rs:33:44: 33:52 (#0) }), Parsed(Deprecation { deprecation: Deprecation { since: Unspecified, note: None, suggestion: None }, span: tests/ui/must_use_unit.rs:33:19: 33:29 (#0) })] -error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:34:1 - | -LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] - | -- help: change these attributes to: `doc = "foo",` -LL | fn issue_12320_2() {} - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/must_use_unit_12320.rs b/tests/ui/must_use_unit_12320.rs new file mode 100644 index 000000000000..39dcafdb38b5 --- /dev/null +++ b/tests/ui/must_use_unit_12320.rs @@ -0,0 +1,11 @@ +//@aux-build:proc_macros.rs +//@no-rustfix + +#![warn(clippy::must_use_unit)] +#![allow(clippy::unused_unit)] + +#[cfg_attr(all(), must_use, deprecated)] +fn issue_12320() {} + +#[cfg_attr(all(), deprecated, doc = "foo", must_use)] +fn issue_12320_2() {} diff --git a/tests/ui/must_use_unit_12320.stderr b/tests/ui/must_use_unit_12320.stderr new file mode 100644 index 000000000000..b3e1cbc04576 --- /dev/null +++ b/tests/ui/must_use_unit_12320.stderr @@ -0,0 +1,28 @@ +error: this unit-returning function has a `#[must_use]` attribute + --> tests/ui/must_use_unit_12320.rs:8:1 + | +LL | fn issue_12320() {} + | ^^^^^^^^^^^^^^^^ + | +help: remove `must_use` + --> tests/ui/must_use_unit_12320.rs:7:19 + | +LL | #[cfg_attr(all(), must_use, deprecated)] + | ^^^^^^^^ + = note: `-D clippy::double-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` + +error: this unit-returning function has a `#[must_use]` attribute + --> tests/ui/must_use_unit_12320.rs:11:1 + | +LL | fn issue_12320_2() {} + | ^^^^^^^^^^^^^^^^^^ + | +help: remove `must_use` + --> tests/ui/must_use_unit_12320.rs:10:44 + | +LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] + | ^^^^^^^^ + +error: aborting due to 2 previous errors + From efcf1f57302b9d865caea8e069aef826e060e0b2 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Tue, 7 Jan 2025 16:01:23 +0000 Subject: [PATCH 147/161] Split needless_lifetime '_ suggestions into elidable_lifetime_names --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/lifetimes.rs | 110 ++++++-- ... elidable_lifetime_names_impl_trait.fixed} | 6 +- ... => elidable_lifetime_names_impl_trait.rs} | 6 +- ...elidable_lifetime_names_impl_trait.stderr} | 10 +- tests/ui/elidable_lifetime_names.fixed | 194 ++++++++++++++ tests/ui/elidable_lifetime_names.rs | 194 ++++++++++++++ tests/ui/elidable_lifetime_names.stderr | 162 ++++++++++++ tests/ui/methods.rs | 1 + tests/ui/methods.stderr | 4 +- tests/ui/needless_lifetimes.fixed | 199 +-------------- tests/ui/needless_lifetimes.rs | 199 +-------------- tests/ui/needless_lifetimes.stderr | 237 +++--------------- 14 files changed, 687 insertions(+), 637 deletions(-) rename tests/ui/crashes/{needless_lifetimes_impl_trait.fixed => elidable_lifetime_names_impl_trait.fixed} (65%) rename tests/ui/crashes/{needless_lifetimes_impl_trait.rs => elidable_lifetime_names_impl_trait.rs} (67%) rename tests/ui/crashes/{needless_lifetimes_impl_trait.stderr => elidable_lifetime_names_impl_trait.stderr} (67%) create mode 100644 tests/ui/elidable_lifetime_names.fixed create mode 100644 tests/ui/elidable_lifetime_names.rs create mode 100644 tests/ui/elidable_lifetime_names.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index be5e95e9744e..fa2143a3493e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5592,6 +5592,7 @@ Released 2018-09-13 [`duplicated_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes [`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec [`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute +[`elidable_lifetime_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names [`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else [`empty_docs`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs [`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9df9a62438ce..0bfc6b14588b 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -273,6 +273,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::let_underscore::LET_UNDERSCORE_MUST_USE_INFO, crate::let_underscore::LET_UNDERSCORE_UNTYPED_INFO, crate::let_with_type_underscore::LET_WITH_TYPE_UNDERSCORE_INFO, + crate::lifetimes::ELIDABLE_LIFETIME_NAMES_INFO, crate::lifetimes::EXTRA_UNUSED_LIFETIMES_INFO, crate::lifetimes::NEEDLESS_LIFETIMES_INFO, crate::lines_filter_map_ok::LINES_FILTER_MAP_OK_INFO, diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index f08812017b9c..7589ab1229af 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -38,8 +38,8 @@ declare_clippy_lint! { /// them leads to more readable code. /// /// ### Known problems - /// - We bail out if the function has a `where` clause where lifetimes - /// are mentioned due to potential false positives. + /// This lint ignores functions with `where` clauses that reference + /// lifetimes to prevent false positives. /// /// ### Example /// ```no_run @@ -62,6 +62,38 @@ declare_clippy_lint! { would allow omitting them" } +declare_clippy_lint! { + /// ### What it does + /// Checks for lifetime annotations which can be replaced with anonymous lifetimes (`'_`). + /// + /// ### Why is this bad? + /// The additional lifetimes can make the code look more complicated. + /// + /// ### Known problems + /// This lint ignores functions with `where` clauses that reference + /// lifetimes to prevent false positives. + /// + /// ### Example + /// ```no_run + /// # use std::str::Chars; + /// fn f<'a>(x: &'a str) -> Chars<'a> { + /// x.chars() + /// } + /// ``` + /// + /// Use instead: + /// ```no_run + /// # use std::str::Chars; + /// fn f(x: &str) -> Chars<'_> { + /// x.chars() + /// } + /// ``` + #[clippy::version = "1.84.0"] + pub ELIDABLE_LIFETIME_NAMES, + pedantic, + "lifetime name that can be replaced with the anonymous lifetime" +} + declare_clippy_lint! { /// ### What it does /// Checks for lifetimes in generics that are never used @@ -104,7 +136,11 @@ impl Lifetimes { } } -impl_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]); +impl_lint_pass!(Lifetimes => [ + NEEDLESS_LIFETIMES, + ELIDABLE_LIFETIME_NAMES, + EXTRA_UNUSED_LIFETIMES, +]); impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { @@ -746,6 +782,15 @@ fn report_elidable_impl_lifetimes<'tcx>( report_elidable_lifetimes(cx, impl_.generics, &elidable_lts, &usages, true); } +#[derive(Copy, Clone)] +enum ElidableUsage { + /// Used in a ref (`&'a T`), can be removed + Ref(Span), + /// Used as a generic param (`T<'a>`) or an impl lifetime (`impl T + 'a`), can be replaced + /// with `'_` + Other(Span), +} + /// Generate diagnostic messages for elidable lifetimes. fn report_elidable_lifetimes( cx: &LateContext<'_>, @@ -763,9 +808,29 @@ fn report_elidable_lifetimes( .collect::>() .join(", "); + let elidable_usages: Vec = usages + .iter() + .filter(|usage| named_lifetime(usage).is_some_and(|id| elidable_lts.contains(&id))) + .map(|usage| match cx.tcx.parent_hir_node(usage.hir_id) { + Node::Ty(Ty { + kind: TyKind::Ref(..), .. + }) => ElidableUsage::Ref(usage.ident.span), + _ => ElidableUsage::Other(usage.ident.span), + }) + .collect(); + + let lint = if elidable_usages + .iter() + .any(|usage| matches!(usage, ElidableUsage::Other(_))) + { + ELIDABLE_LIFETIME_NAMES + } else { + NEEDLESS_LIFETIMES + }; + span_lint_and_then( cx, - NEEDLESS_LIFETIMES, + lint, elidable_lts .iter() .map(|<| cx.tcx.def_span(lt)) @@ -785,7 +850,7 @@ fn report_elidable_lifetimes( return; } - if let Some(suggestions) = elision_suggestions(cx, generics, elidable_lts, usages) { + if let Some(suggestions) = elision_suggestions(cx, generics, elidable_lts, &elidable_usages) { diag.multipart_suggestion("elide the lifetimes", suggestions, Applicability::MachineApplicable); } }, @@ -796,7 +861,7 @@ fn elision_suggestions( cx: &LateContext<'_>, generics: &Generics<'_>, elidable_lts: &[LocalDefId], - usages: &[Lifetime], + usages: &[ElidableUsage], ) -> Option> { let explicit_params = generics .params @@ -836,26 +901,21 @@ fn elision_suggestions( .collect::>>()? }; - suggestions.extend( - usages - .iter() - .filter(|usage| named_lifetime(usage).is_some_and(|id| elidable_lts.contains(&id))) - .map(|usage| { - match cx.tcx.parent_hir_node(usage.hir_id) { - Node::Ty(Ty { - kind: TyKind::Ref(..), .. - }) => { - // expand `&'a T` to `&'a T` - // ^^ ^^^ - let span = cx.sess().source_map().span_extend_while_whitespace(usage.ident.span); + suggestions.extend(usages.iter().map(|&usage| { + match usage { + ElidableUsage::Ref(span) => { + // expand `&'a T` to `&'a T` + // ^^ ^^^ + let span = cx.sess().source_map().span_extend_while_whitespace(span); - (span, String::new()) - }, - // `T<'a>` and `impl Foo + 'a` should be replaced by `'_` - _ => (usage.ident.span, String::from("'_")), - } - }), - ); + (span, String::new()) + }, + ElidableUsage::Other(span) => { + // `T<'a>` and `impl Foo + 'a` should be replaced by `'_` + (span, String::from("'_")) + }, + } + })); Some(suggestions) } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/elidable_lifetime_names_impl_trait.fixed similarity index 65% rename from tests/ui/crashes/needless_lifetimes_impl_trait.fixed rename to tests/ui/crashes/elidable_lifetime_names_impl_trait.fixed index da3b82a60c5f..681887314ed5 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/elidable_lifetime_names_impl_trait.fixed @@ -1,4 +1,4 @@ -#![deny(clippy::needless_lifetimes)] +#![deny(clippy::elidable_lifetime_names)] #![allow(dead_code)] trait Foo {} @@ -10,11 +10,11 @@ struct Baz<'a> { } impl Foo for Baz<'_> {} -//~^ needless_lifetimes +//~^ elidable_lifetime_names impl Bar { fn baz(&self) -> impl Foo + '_ { - //~^ needless_lifetimes + //~^ elidable_lifetime_names Baz { bar: self } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/elidable_lifetime_names_impl_trait.rs similarity index 67% rename from tests/ui/crashes/needless_lifetimes_impl_trait.rs rename to tests/ui/crashes/elidable_lifetime_names_impl_trait.rs index 456d315926db..ed5f95bdca82 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/elidable_lifetime_names_impl_trait.rs @@ -1,4 +1,4 @@ -#![deny(clippy::needless_lifetimes)] +#![deny(clippy::elidable_lifetime_names)] #![allow(dead_code)] trait Foo {} @@ -10,11 +10,11 @@ struct Baz<'a> { } impl<'a> Foo for Baz<'a> {} -//~^ needless_lifetimes +//~^ elidable_lifetime_names impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { - //~^ needless_lifetimes + //~^ elidable_lifetime_names Baz { bar: self } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/elidable_lifetime_names_impl_trait.stderr similarity index 67% rename from tests/ui/crashes/needless_lifetimes_impl_trait.stderr rename to tests/ui/crashes/elidable_lifetime_names_impl_trait.stderr index 97fb6d29cfbe..ef4b7e0a476e 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ b/tests/ui/crashes/elidable_lifetime_names_impl_trait.stderr @@ -1,14 +1,14 @@ error: the following explicit lifetimes could be elided: 'a - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:12:6 + --> tests/ui/crashes/elidable_lifetime_names_impl_trait.rs:12:6 | LL | impl<'a> Foo for Baz<'a> {} | ^^ ^^ | note: the lint level is defined here - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:1:9 + --> tests/ui/crashes/elidable_lifetime_names_impl_trait.rs:1:9 | -LL | #![deny(clippy::needless_lifetimes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(clippy::elidable_lifetime_names)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: elide the lifetimes | LL - impl<'a> Foo for Baz<'a> {} @@ -16,7 +16,7 @@ LL + impl Foo for Baz<'_> {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:16:12 + --> tests/ui/crashes/elidable_lifetime_names_impl_trait.rs:16:12 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ diff --git a/tests/ui/elidable_lifetime_names.fixed b/tests/ui/elidable_lifetime_names.fixed new file mode 100644 index 000000000000..abeee5c4cef3 --- /dev/null +++ b/tests/ui/elidable_lifetime_names.fixed @@ -0,0 +1,194 @@ +#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] + +type Ref<'r> = &'r u8; + +// No error; same lifetime on two params. +fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} + +//~v ERROR: could be elided: 'a, 'b +fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} + +// No error; bounded lifetime. +fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} + +// No error; bounded lifetime. +fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) +where + 'b: 'a, +{ +} + +struct Lt<'a, I: 'static> { + x: &'a I, +} + +// No error; fn bound references `'a`. +fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +where + F: Fn(Lt<'a, I>) -> Lt<'a, I>, +{ + unreachable!() +} + +//~v ERROR: could be elided: 'a +fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> +where + for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, +{ + unreachable!() +} + +struct Foo<'a>(&'a u8); + +//~v ERROR: could be elided: 'a +fn struct_with_lt(_foo: Foo<'_>) -> &str { + unimplemented!() +} + +// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). +fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). +fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { + unimplemented!() +} + +//~v ERROR: could be elided: 'b +fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { + unimplemented!() +} + +type FooAlias<'a> = Foo<'a>; + +//~v ERROR: could be elided: 'a +fn alias_with_lt(_foo: FooAlias<'_>) -> &str { + unimplemented!() +} + +// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). +fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). +fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { + unimplemented!() +} + +//~v ERROR: could be elided: 'b +fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { + unimplemented!() +} + +// Issue #3284: give hint regarding lifetime in return type. +struct Cow<'a> { + x: &'a str, +} + +//~v ERROR: could be elided: 'a +fn out_return_type_lts(e: &str) -> Cow<'_> { + unimplemented!() +} + +mod issue2944 { + trait Foo {} + struct Bar; + struct Baz<'a> { + bar: &'a Bar, + } + + //~v ERROR: could be elided: 'a + impl Foo for Baz<'_> {} + impl Bar { + //~v ERROR: could be elided: 'a + fn baz(&self) -> impl Foo + '_ { + Baz { bar: self } + } + } +} + +mod issue13923 { + struct Py<'py> { + data: &'py str, + } + + enum Content<'t, 'py> { + Py(Py<'py>), + T1(&'t str), + T2(&'t str), + } + + enum ContentString<'t> { + T1(&'t str), + T2(&'t str), + } + + impl<'t, 'py> ContentString<'t> { + // `'py` cannot be elided + fn map_content1(self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t> ContentString<'t> { + // `'py` can be elided because of `&self` + fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t> ContentString<'t> { + // `'py` can be elided because of `&'_ self` + fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + impl<'t, 'py> ContentString<'t> { + // `'py` should not be elided as the default lifetime, even if working, could be named as `'t` + fn map_content4(self, f: impl FnOnce(&'t str) -> &'t str, o: &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(_) => Content::T2(o), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t> ContentString<'t> { + // `'py` can be elided because of `&Self` + fn map_content5( + self: std::pin::Pin<&Self>, + f: impl FnOnce(&'t str) -> &'t str, + o: &'t str, + ) -> Content<'t, '_> { + match *self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(_) => Content::T2(o), + } + } + } + + struct Cx<'a, 'b> { + a: &'a u32, + b: &'b u32, + } + + // `'c` cannot be elided because we have several input lifetimes + fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { + x.b + } +} diff --git a/tests/ui/elidable_lifetime_names.rs b/tests/ui/elidable_lifetime_names.rs new file mode 100644 index 000000000000..fae3577a8e96 --- /dev/null +++ b/tests/ui/elidable_lifetime_names.rs @@ -0,0 +1,194 @@ +#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] + +type Ref<'r> = &'r u8; + +// No error; same lifetime on two params. +fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} + +//~v ERROR: could be elided: 'a, 'b +fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} + +// No error; bounded lifetime. +fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} + +// No error; bounded lifetime. +fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) +where + 'b: 'a, +{ +} + +struct Lt<'a, I: 'static> { + x: &'a I, +} + +// No error; fn bound references `'a`. +fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +where + F: Fn(Lt<'a, I>) -> Lt<'a, I>, +{ + unreachable!() +} + +//~v ERROR: could be elided: 'a +fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +where + for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, +{ + unreachable!() +} + +struct Foo<'a>(&'a u8); + +//~v ERROR: could be elided: 'a +fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). +fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). +fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { + unimplemented!() +} + +//~v ERROR: could be elided: 'b +fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { + unimplemented!() +} + +type FooAlias<'a> = Foo<'a>; + +//~v ERROR: could be elided: 'a +fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). +fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { + unimplemented!() +} + +// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). +fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { + unimplemented!() +} + +//~v ERROR: could be elided: 'b +fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { + unimplemented!() +} + +// Issue #3284: give hint regarding lifetime in return type. +struct Cow<'a> { + x: &'a str, +} + +//~v ERROR: could be elided: 'a +fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { + unimplemented!() +} + +mod issue2944 { + trait Foo {} + struct Bar; + struct Baz<'a> { + bar: &'a Bar, + } + + //~v ERROR: could be elided: 'a + impl<'a> Foo for Baz<'a> {} + impl Bar { + //~v ERROR: could be elided: 'a + fn baz<'a>(&'a self) -> impl Foo + 'a { + Baz { bar: self } + } + } +} + +mod issue13923 { + struct Py<'py> { + data: &'py str, + } + + enum Content<'t, 'py> { + Py(Py<'py>), + T1(&'t str), + T2(&'t str), + } + + enum ContentString<'t> { + T1(&'t str), + T2(&'t str), + } + + impl<'t, 'py> ContentString<'t> { + // `'py` cannot be elided + fn map_content1(self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t, 'py> ContentString<'t> { + // `'py` can be elided because of `&self` + fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t, 'py> ContentString<'t> { + // `'py` can be elided because of `&'_ self` + fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(content) => Content::T2(f(content)), + } + } + } + + impl<'t, 'py> ContentString<'t> { + // `'py` should not be elided as the default lifetime, even if working, could be named as `'t` + fn map_content4(self, f: impl FnOnce(&'t str) -> &'t str, o: &'t str) -> Content<'t, 'py> { + match self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(_) => Content::T2(o), + } + } + } + + //~v ERROR: could be elided: 'py + impl<'t, 'py> ContentString<'t> { + // `'py` can be elided because of `&Self` + fn map_content5( + self: std::pin::Pin<&Self>, + f: impl FnOnce(&'t str) -> &'t str, + o: &'t str, + ) -> Content<'t, 'py> { + match *self { + Self::T1(content) => Content::T1(f(content)), + Self::T2(_) => Content::T2(o), + } + } + } + + struct Cx<'a, 'b> { + a: &'a u32, + b: &'b u32, + } + + // `'c` cannot be elided because we have several input lifetimes + fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { + x.b + } +} diff --git a/tests/ui/elidable_lifetime_names.stderr b/tests/ui/elidable_lifetime_names.stderr new file mode 100644 index 000000000000..a60dfc697564 --- /dev/null +++ b/tests/ui/elidable_lifetime_names.stderr @@ -0,0 +1,162 @@ +error: the following explicit lifetimes could be elided: 'a, 'b + --> tests/ui/elidable_lifetime_names.rs:9:21 + | +LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} + | ^^ ^^ ^^ ^^ + | + = note: `-D clippy::elidable-lifetime-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::elidable_lifetime_names)]` +help: elide the lifetimes + | +LL - fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} +LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:34:15 + | +LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> + | ^^ ^^ ^^ + | +help: elide the lifetimes + | +LL - fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> +LL + fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:44:19 + | +LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | +LL - fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { +LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { + | + +error: the following explicit lifetimes could be elided: 'b + --> tests/ui/elidable_lifetime_names.rs:59:25 + | +LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { + | ^^ ^^ + | +help: elide the lifetimes + | +LL - fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { +LL + fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:66:18 + | +LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | +LL - fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { +LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { + | + +error: the following explicit lifetimes could be elided: 'b + --> tests/ui/elidable_lifetime_names.rs:81:24 + | +LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { + | ^^ ^^ + | +help: elide the lifetimes + | +LL - fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { +LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:91:24 + | +LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | +LL - fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { +LL + fn out_return_type_lts(e: &str) -> Cow<'_> { + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:103:10 + | +LL | impl<'a> Foo for Baz<'a> {} + | ^^ ^^ + | +help: elide the lifetimes + | +LL - impl<'a> Foo for Baz<'a> {} +LL + impl Foo for Baz<'_> {} + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/elidable_lifetime_names.rs:106:16 + | +LL | fn baz<'a>(&'a self) -> impl Foo + 'a { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | +LL - fn baz<'a>(&'a self) -> impl Foo + 'a { +LL + fn baz(&self) -> impl Foo + '_ { + | + +error: the following explicit lifetimes could be elided: 'py + --> tests/ui/elidable_lifetime_names.rs:139:14 + | +LL | impl<'t, 'py> ContentString<'t> { + | ^^^ +LL | // `'py` can be elided because of `&self` +LL | fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + | ^^^ + | +help: elide the lifetimes + | +LL ~ impl<'t> ContentString<'t> { +LL | // `'py` can be elided because of `&self` +LL ~ fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { + | + +error: the following explicit lifetimes could be elided: 'py + --> tests/ui/elidable_lifetime_names.rs:150:14 + | +LL | impl<'t, 'py> ContentString<'t> { + | ^^^ +LL | // `'py` can be elided because of `&'_ self` +LL | fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { + | ^^^ + | +help: elide the lifetimes + | +LL ~ impl<'t> ContentString<'t> { +LL | // `'py` can be elided because of `&'_ self` +LL ~ fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { + | + +error: the following explicit lifetimes could be elided: 'py + --> tests/ui/elidable_lifetime_names.rs:171:14 + | +LL | impl<'t, 'py> ContentString<'t> { + | ^^^ +... +LL | ) -> Content<'t, 'py> { + | ^^^ + | +help: elide the lifetimes + | +LL ~ impl<'t> ContentString<'t> { +LL | // `'py` can be elided because of `&Self` +... +LL | o: &'t str, +LL ~ ) -> Content<'t, '_> { + | + +error: aborting due to 12 previous errors + diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index 85a4d59e5ca0..76b0d131dd41 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -11,6 +11,7 @@ clippy::new_without_default, clippy::needless_pass_by_value, clippy::needless_lifetimes, + clippy::elidable_lifetime_names, clippy::print_stdout, clippy::must_use_candidate, clippy::use_self, diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 30e8d0794f71..353b999d7da0 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -1,5 +1,5 @@ error: methods called `new` usually return `Self` - --> tests/ui/methods.rs:103:5 + --> tests/ui/methods.rs:104:5 | LL | / fn new() -> i32 { LL | | @@ -11,7 +11,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead - --> tests/ui/methods.rs:125:13 + --> tests/ui/methods.rs:126:13 | LL | let _ = v.iter().filter(|&x| { | _____________^ diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index 283635d42def..d59393fb3f3c 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![warn(clippy::needless_lifetimes)] +#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] #![allow( unused, clippy::boxed_local, @@ -101,44 +101,6 @@ where Ok(x) } -type Ref<'r> = &'r u8; - -// No error; same lifetime on two params. -fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} - -fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} -//~^ needless_lifetimes - -// No error; bounded lifetime. -fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} - -// No error; bounded lifetime. -fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) -where - 'b: 'a, -{ -} - -struct Lt<'a, I: 'static> { - x: &'a I, -} - -// No error; fn bound references `'a`. -fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -where - F: Fn(Lt<'a, I>) -> Lt<'a, I>, -{ - unreachable!() -} - -fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> -//~^ needless_lifetimes -where - for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, -{ - unreachable!() -} - // No error; see below. fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { f(x); @@ -203,30 +165,6 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { unimplemented!() } -fn struct_with_lt(_foo: Foo<'_>) -> &str { - //~^ needless_lifetimes - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). -fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). -fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { - unimplemented!() -} - -// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is -// valid: -// fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str -// ^^ -fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - // Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is // valid: // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str @@ -254,30 +192,6 @@ fn trait_obj_elided2(_arg: &dyn Drop) -> &str { type FooAlias<'a> = Foo<'a>; -fn alias_with_lt(_foo: FooAlias<'_>) -> &str { - //~^ needless_lifetimes - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). -fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). -fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { - unimplemented!() -} - -// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is -// valid: -// fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str -// ^^ -fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - // Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is // valid: // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str @@ -329,15 +243,6 @@ fn test<'a>(x: &'a [u8]) -> u8 { *y } -// Issue #3284: give hint regarding lifetime in return type. -struct Cow<'a> { - x: &'a str, -} -fn out_return_type_lts(e: &str) -> Cow<'_> { - //~^ needless_lifetimes - unimplemented!() -} - // Make sure we still warn on implementations mod issue4291 { trait BadTrait { @@ -351,23 +256,6 @@ mod issue4291 { } } -mod issue2944 { - trait Foo {} - struct Bar; - struct Baz<'a> { - bar: &'a Bar, - } - - impl Foo for Baz<'_> {} - //~^ needless_lifetimes - impl Bar { - fn baz(&self) -> impl Foo + '_ { - //~^ needless_lifetimes - Baz { bar: self } - } - } -} - mod nested_elision_sites { // issue #issue2944 @@ -646,89 +534,4 @@ mod issue13749bis { impl<'a, T: 'a> Generic {} } -mod issue13923 { - struct Py<'py> { - data: &'py str, - } - - enum Content<'t, 'py> { - Py(Py<'py>), - T1(&'t str), - T2(&'t str), - } - - enum ContentString<'t> { - T1(&'t str), - T2(&'t str), - } - - impl<'t, 'py> ContentString<'t> { - // `'py` cannot be elided - fn map_content1(self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&self` - fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&'_ self` - fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t, 'py> ContentString<'t> { - // `'py` should not be elided as the default lifetime, even if working, could be named as `'t` - fn map_content4(self, f: impl FnOnce(&'t str) -> &'t str, o: &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(_) => Content::T2(o), - } - } - } - - impl<'t> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&Self` - fn map_content5( - self: std::pin::Pin<&Self>, - f: impl FnOnce(&'t str) -> &'t str, - o: &'t str, - ) -> Content<'t, '_> { - match *self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(_) => Content::T2(o), - } - } - } - - struct Cx<'a, 'b> { - a: &'a u32, - b: &'b u32, - } - - // `'c` cannot be elided because we have several input lifetimes - fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { - x.b - //~^ needless_borrow - } -} - fn main() {} diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 2853870473db..e24907ab5fcd 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![warn(clippy::needless_lifetimes)] +#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] #![allow( unused, clippy::boxed_local, @@ -101,44 +101,6 @@ where Ok(x) } -type Ref<'r> = &'r u8; - -// No error; same lifetime on two params. -fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} - -fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} -//~^ needless_lifetimes - -// No error; bounded lifetime. -fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} - -// No error; bounded lifetime. -fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) -where - 'b: 'a, -{ -} - -struct Lt<'a, I: 'static> { - x: &'a I, -} - -// No error; fn bound references `'a`. -fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -where - F: Fn(Lt<'a, I>) -> Lt<'a, I>, -{ - unreachable!() -} - -fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -//~^ needless_lifetimes -where - for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, -{ - unreachable!() -} - // No error; see below. fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { f(x); @@ -203,30 +165,6 @@ fn already_elided<'a>(_: &u8, _: &'a u8) -> &'a u8 { unimplemented!() } -fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). -fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). -fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { - unimplemented!() -} - -// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is -// valid: -// fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str -// ^^ -fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - // Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is // valid: // fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str @@ -254,30 +192,6 @@ fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { type FooAlias<'a> = Foo<'a>; -fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - -// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). -fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { - unimplemented!() -} - -// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). -fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { - unimplemented!() -} - -// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is -// valid: -// fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str -// ^^ -fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { - //~^ needless_lifetimes - unimplemented!() -} - // Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is // valid: // fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str @@ -329,15 +243,6 @@ fn test<'a>(x: &'a [u8]) -> u8 { *y } -// Issue #3284: give hint regarding lifetime in return type. -struct Cow<'a> { - x: &'a str, -} -fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { - //~^ needless_lifetimes - unimplemented!() -} - // Make sure we still warn on implementations mod issue4291 { trait BadTrait { @@ -351,23 +256,6 @@ mod issue4291 { } } -mod issue2944 { - trait Foo {} - struct Bar; - struct Baz<'a> { - bar: &'a Bar, - } - - impl<'a> Foo for Baz<'a> {} - //~^ needless_lifetimes - impl Bar { - fn baz<'a>(&'a self) -> impl Foo + 'a { - //~^ needless_lifetimes - Baz { bar: self } - } - } -} - mod nested_elision_sites { // issue #issue2944 @@ -646,89 +534,4 @@ mod issue13749bis { impl<'a, T: 'a> Generic {} } -mod issue13923 { - struct Py<'py> { - data: &'py str, - } - - enum Content<'t, 'py> { - Py(Py<'py>), - T1(&'t str), - T2(&'t str), - } - - enum ContentString<'t> { - T1(&'t str), - T2(&'t str), - } - - impl<'t, 'py> ContentString<'t> { - // `'py` cannot be elided - fn map_content1(self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&self` - fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&'_ self` - fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(content) => Content::T2(f(content)), - } - } - } - - impl<'t, 'py> ContentString<'t> { - // `'py` should not be elided as the default lifetime, even if working, could be named as `'t` - fn map_content4(self, f: impl FnOnce(&'t str) -> &'t str, o: &'t str) -> Content<'t, 'py> { - match self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(_) => Content::T2(o), - } - } - } - - impl<'t, 'py> ContentString<'t> { - //~^ needless_lifetimes - // `'py` can be elided because of `&Self` - fn map_content5( - self: std::pin::Pin<&Self>, - f: impl FnOnce(&'t str) -> &'t str, - o: &'t str, - ) -> Content<'t, 'py> { - match *self { - Self::T1(content) => Content::T1(f(content)), - Self::T2(_) => Content::T2(o), - } - } - } - - struct Cx<'a, 'b> { - a: &'a u32, - b: &'b u32, - } - - // `'c` cannot be elided because we have several input lifetimes - fn one_explicit<'b>(x: Cx<'_, 'b>) -> &'b u32 { - &x.b - //~^ needless_borrow - } -} - fn main() {} diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index b1d1c88a2968..138d0498c43e 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -108,32 +108,8 @@ LL - fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> LL + fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> | -error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:109:21 - | -LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} - | ^^ ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} -LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:134:15 - | -LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> - | ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> -LL + fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> - | - error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:165:21 + --> tests/ui/needless_lifetimes.rs:127:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -145,7 +121,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> tests/ui/needless_lifetimes.rs:173:30 + --> tests/ui/needless_lifetimes.rs:135:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -157,7 +133,7 @@ LL + fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { | error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:181:26 + --> tests/ui/needless_lifetimes.rs:143:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -169,7 +145,7 @@ LL + fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { | error: the following explicit lifetimes could be elided: 's, 't - --> tests/ui/needless_lifetimes.rs:186:29 + --> tests/ui/needless_lifetimes.rs:148:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -181,31 +157,7 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:206:19 - | -LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { - | ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { -LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { - | - -error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:225:25 - | -LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { - | ^^ ^^ - | -help: elide the lifetimes - | -LL - fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { -LL + fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:234:21 + --> tests/ui/needless_lifetimes.rs:172:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -217,7 +169,7 @@ LL + fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:250:22 + --> tests/ui/needless_lifetimes.rs:188:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -229,31 +181,7 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:257:18 - | -LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { - | ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { -LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { - | - -error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:276:24 - | -LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { - | ^^ ^^ - | -help: elide the lifetimes - | -LL - fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { -LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:285:20 + --> tests/ui/needless_lifetimes.rs:199:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -265,7 +193,7 @@ LL + fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:290:30 + --> tests/ui/needless_lifetimes.rs:204:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -277,7 +205,7 @@ LL + fn named_input_elided_output(_arg: &str) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:299:19 + --> tests/ui/needless_lifetimes.rs:213:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -289,19 +217,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:336:24 - | -LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { - | ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { -LL + fn out_return_type_lts(e: &str) -> Cow<'_> { - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:344:24 + --> tests/ui/needless_lifetimes.rs:249:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -313,7 +229,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:349:24 + --> tests/ui/needless_lifetimes.rs:254:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -325,31 +241,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:361:10 - | -LL | impl<'a> Foo for Baz<'a> {} - | ^^ ^^ - | -help: elide the lifetimes - | -LL - impl<'a> Foo for Baz<'a> {} -LL + impl Foo for Baz<'_> {} - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:364:16 - | -LL | fn baz<'a>(&'a self) -> impl Foo + 'a { - | ^^ ^^ ^^ - | -help: elide the lifetimes - | -LL - fn baz<'a>(&'a self) -> impl Foo + 'a { -LL + fn baz(&self) -> impl Foo + '_ { - | - -error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:397:55 + --> tests/ui/needless_lifetimes.rs:285:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -361,7 +253,7 @@ LL + fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(& | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:407:26 + --> tests/ui/needless_lifetimes.rs:295:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -373,7 +265,7 @@ LL + fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:420:30 + --> tests/ui/needless_lifetimes.rs:308:30 | LL | fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -385,7 +277,7 @@ LL + fn where_clause_elidable(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:436:28 + --> tests/ui/needless_lifetimes.rs:324:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -397,7 +289,7 @@ LL + fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:450:28 + --> tests/ui/needless_lifetimes.rs:338:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -409,7 +301,7 @@ LL + fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:454:28 + --> tests/ui/needless_lifetimes.rs:342:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -421,7 +313,7 @@ LL + fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:477:21 + --> tests/ui/needless_lifetimes.rs:365:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -433,7 +325,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:481:25 + --> tests/ui/needless_lifetimes.rs:369:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -445,7 +337,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:486:21 + --> tests/ui/needless_lifetimes.rs:374:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -457,7 +349,7 @@ LL + fn explicit(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:491:25 + --> tests/ui/needless_lifetimes.rs:379:25 | LL | fn explicit_mut<'a>(self: &'a mut Rc) -> &'a () { | ^^ ^^ ^^ @@ -469,7 +361,7 @@ LL + fn explicit_mut(self: &mut Rc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:504:31 + --> tests/ui/needless_lifetimes.rs:392:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -481,7 +373,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:511:21 + --> tests/ui/needless_lifetimes.rs:399:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -493,7 +385,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:513:30 + --> tests/ui/needless_lifetimes.rs:401:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -505,7 +397,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:519:21 + --> tests/ui/needless_lifetimes.rs:407:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a (); | ^^ ^^ ^^ @@ -517,7 +409,7 @@ LL + fn explicit(self: &Arc) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:522:30 + --> tests/ui/needless_lifetimes.rs:410:30 | LL | fn explicit_provided<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -529,7 +421,7 @@ LL + fn explicit_provided(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:533:31 + --> tests/ui/needless_lifetimes.rs:421:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -541,7 +433,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:535:40 + --> tests/ui/needless_lifetimes.rs:423:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -553,7 +445,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:545:12 + --> tests/ui/needless_lifetimes.rs:433:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -565,7 +457,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:548:12 + --> tests/ui/needless_lifetimes.rs:436:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -577,7 +469,7 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:556:18 + --> tests/ui/needless_lifetimes.rs:444:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -589,7 +481,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:562:42 + --> tests/ui/needless_lifetimes.rs:450:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -601,7 +493,7 @@ LL + fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:579:22 + --> tests/ui/needless_lifetimes.rs:467:22 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -613,66 +505,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 { LL + fn one_input(x: &u8) -> &u8 { | -error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:675:14 - | -LL | impl<'t, 'py> ContentString<'t> { - | ^^^ -... -LL | fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - | ^^^ - | -help: elide the lifetimes - | -LL ~ impl<'t> ContentString<'t> { -LL | -LL | // `'py` can be elided because of `&self` -LL ~ fn map_content2(&self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { - | - -error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:686:14 - | -LL | impl<'t, 'py> ContentString<'t> { - | ^^^ -... -LL | fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, 'py> { - | ^^^ - | -help: elide the lifetimes - | -LL ~ impl<'t> ContentString<'t> { -LL | -LL | // `'py` can be elided because of `&'_ self` -LL ~ fn map_content3(&'_ self, f: impl FnOnce(&'t str) -> &'t str) -> Content<'t, '_> { - | - -error: the following explicit lifetimes could be elided: 'py - --> tests/ui/needless_lifetimes.rs:707:14 - | -LL | impl<'t, 'py> ContentString<'t> { - | ^^^ -... -LL | ) -> Content<'t, 'py> { - | ^^^ - | -help: elide the lifetimes - | -LL ~ impl<'t> ContentString<'t> { -LL | -... -LL | o: &'t str, -LL ~ ) -> Content<'t, '_> { - | - -error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_lifetimes.rs:729:9 - | -LL | &x.b - | ^^^^ help: change this to: `x.b` - | - = note: `-D clippy::needless-borrow` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` - -error: aborting due to 55 previous errors +error: aborting due to 42 previous errors From 325bfef88d03cb79c6369d22adb14d997d090573 Mon Sep 17 00:00:00 2001 From: Bryce Berger Date: Sat, 22 Feb 2025 18:53:25 -0500 Subject: [PATCH 148/161] configuration option to lint `incompatible_msrv` in test code --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 10 ++++++ clippy_config/src/conf.rs | 3 ++ clippy_lints/src/incompatible_msrv.rs | 4 ++- ..._incompatible_msrv_in_tests.default.stderr | 11 +++++++ ..._incompatible_msrv_in_tests.enabled.stderr | 23 ++++++++++++++ .../check_incompatible_msrv_in_tests.rs | 31 +++++++++++++++++++ .../default/clippy.toml | 1 + .../enabled/clippy.toml | 1 + .../toml_unknown_key/conf_unknown_key.stderr | 3 ++ 10 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.default.stderr create mode 100644 tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.enabled.stderr create mode 100644 tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs create mode 100644 tests/ui-toml/check_incompatible_msrv_in_tests/default/clippy.toml create mode 100644 tests/ui-toml/check_incompatible_msrv_in_tests/enabled/clippy.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index be5e95e9744e..58172b7a15dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6341,6 +6341,7 @@ Released 2018-09-13 [`avoid-breaking-exported-api`]: https://doc.rust-lang.org/clippy/lint_configuration.html#avoid-breaking-exported-api [`await-holding-invalid-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#await-holding-invalid-types [`cargo-ignore-publish`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cargo-ignore-publish +[`check-incompatible-msrv-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-incompatible-msrv-in-tests [`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items [`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold [`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 74c2be3479ec..5f4d31e2bad0 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -415,6 +415,16 @@ For internal testing only, ignores the current `publish` settings in the Cargo m * [`cargo_common_metadata`](https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata) +## `check-incompatible-msrv-in-tests` +Whether to check MSRV compatibility in `#[test]` and `#[cfg(test)]` code. + +**Default Value:** `false` + +--- +**Affected lints:** +* [`incompatible_msrv`](https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv) + + ## `check-private-items` Whether to also run the listed lints on private items. diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index ff2a86182402..1dd7a6ac4219 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -464,6 +464,9 @@ define_Conf! { /// For internal testing only, ignores the current `publish` settings in the Cargo manifest. #[lints(cargo_common_metadata)] cargo_ignore_publish: bool = false, + /// Whether to check MSRV compatibility in `#[test]` and `#[cfg(test)]` code. + #[lints(incompatible_msrv)] + check_incompatible_msrv_in_tests: bool = false, /// Whether to also run the listed lints on private items. #[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)] check_private_items: bool = false, diff --git a/clippy_lints/src/incompatible_msrv.rs b/clippy_lints/src/incompatible_msrv.rs index b10206dcd05e..26df41e42a60 100644 --- a/clippy_lints/src/incompatible_msrv.rs +++ b/clippy_lints/src/incompatible_msrv.rs @@ -42,6 +42,7 @@ declare_clippy_lint! { pub struct IncompatibleMsrv { msrv: Msrv, is_above_msrv: FxHashMap, + check_in_tests: bool, } impl_lint_pass!(IncompatibleMsrv => [INCOMPATIBLE_MSRV]); @@ -51,6 +52,7 @@ impl IncompatibleMsrv { Self { msrv: conf.msrv.clone(), is_above_msrv: FxHashMap::default(), + check_in_tests: conf.check_incompatible_msrv_in_tests, } } @@ -87,7 +89,7 @@ impl IncompatibleMsrv { return; } let version = self.get_def_id_version(cx.tcx, def_id); - if self.msrv.meets(version) || is_in_test(cx.tcx, node) { + if self.msrv.meets(version) || (!self.check_in_tests && is_in_test(cx.tcx, node)) { return; } if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind { diff --git a/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.default.stderr b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.default.stderr new file mode 100644 index 000000000000..2a6170b0bcdc --- /dev/null +++ b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.default.stderr @@ -0,0 +1,11 @@ +error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` + --> tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs:14:5 + | +LL | sleep(Duration::new(1, 0)) + | ^^^^^ + | + = note: `-D clippy::incompatible-msrv` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]` + +error: aborting due to 1 previous error + diff --git a/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.enabled.stderr b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.enabled.stderr new file mode 100644 index 000000000000..8a85d38fba3c --- /dev/null +++ b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.enabled.stderr @@ -0,0 +1,23 @@ +error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` + --> tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs:14:5 + | +LL | sleep(Duration::new(1, 0)) + | ^^^^^ + | + = note: `-D clippy::incompatible-msrv` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]` + +error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` + --> tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs:20:5 + | +LL | sleep(Duration::new(1, 0)); + | ^^^^^ + +error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0` + --> tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs:28:9 + | +LL | sleep(Duration::new(1, 0)); + | ^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs new file mode 100644 index 000000000000..fed5f350b722 --- /dev/null +++ b/tests/ui-toml/check_incompatible_msrv_in_tests/check_incompatible_msrv_in_tests.rs @@ -0,0 +1,31 @@ +//@compile-flags: --test +//@revisions: default enabled +//@[enabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/check_incompatible_msrv_in_tests/enabled +//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/check_incompatible_msrv_in_tests/default + +#![warn(clippy::incompatible_msrv)] +#![feature(custom_inner_attributes)] +#![clippy::msrv = "1.3.0"] + +use std::thread::sleep; +use std::time::Duration; + +fn main() { + sleep(Duration::new(1, 0)) + //~^ incompatible_msrv +} + +#[test] +fn test() { + sleep(Duration::new(1, 0)); + //~[enabled]^ incompatible_msrv +} + +#[cfg(test)] +mod tests { + use super::*; + fn helper() { + sleep(Duration::new(1, 0)); + //~[enabled]^ incompatible_msrv + } +} diff --git a/tests/ui-toml/check_incompatible_msrv_in_tests/default/clippy.toml b/tests/ui-toml/check_incompatible_msrv_in_tests/default/clippy.toml new file mode 100644 index 000000000000..1d13759aceb7 --- /dev/null +++ b/tests/ui-toml/check_incompatible_msrv_in_tests/default/clippy.toml @@ -0,0 +1 @@ +# default config has check-incompatible-msrv-in-tests as false diff --git a/tests/ui-toml/check_incompatible_msrv_in_tests/enabled/clippy.toml b/tests/ui-toml/check_incompatible_msrv_in_tests/enabled/clippy.toml new file mode 100644 index 000000000000..c56af6c82186 --- /dev/null +++ b/tests/ui-toml/check_incompatible_msrv_in_tests/enabled/clippy.toml @@ -0,0 +1 @@ +check-incompatible-msrv-in-tests = true diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 842059df1e92..acfe739277cc 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -31,6 +31,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect await-holding-invalid-types blacklisted-names cargo-ignore-publish + check-incompatible-msrv-in-tests check-private-items cognitive-complexity-threshold cyclomatic-complexity-threshold @@ -122,6 +123,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect await-holding-invalid-types blacklisted-names cargo-ignore-publish + check-incompatible-msrv-in-tests check-private-items cognitive-complexity-threshold cyclomatic-complexity-threshold @@ -213,6 +215,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni await-holding-invalid-types blacklisted-names cargo-ignore-publish + check-incompatible-msrv-in-tests check-private-items cognitive-complexity-threshold cyclomatic-complexity-threshold From 6af901c51edbe2019e6aa18f7b33eb8581dc49af Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Sat, 28 Dec 2024 20:23:14 -0500 Subject: [PATCH 149/161] Add `unnecessary_debug_formatting` lint Address review comments Fix adjacent code Required now that the lint is pedantic Add inline formatting tests Add note re formatting changes Address `unnecessary_map_or` warnings Address additional review comments Typo Update Clippy version --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/format_args.rs | 122 ++++++++++++++++-- clippy_lints/src/lib.rs | 2 +- lintcheck/src/input.rs | 4 +- tests/compile-test.rs | 6 +- .../ui/unnecessary_os_str_debug_formatting.rs | 23 ++++ ...unnecessary_os_str_debug_formatting.stderr | 58 +++++++++ tests/ui/unnecessary_path_debug_formatting.rs | 44 +++++++ .../unnecessary_path_debug_formatting.stderr | 67 ++++++++++ 10 files changed, 314 insertions(+), 14 deletions(-) create mode 100644 tests/ui/unnecessary_os_str_debug_formatting.rs create mode 100644 tests/ui/unnecessary_os_str_debug_formatting.stderr create mode 100644 tests/ui/unnecessary_path_debug_formatting.rs create mode 100644 tests/ui/unnecessary_path_debug_formatting.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 664a7e766304..f72632371291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6110,6 +6110,7 @@ Released 2018-09-13 [`unnecessary_box_returns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns [`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [`unnecessary_clippy_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_clippy_cfg +[`unnecessary_debug_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_debug_formatting [`unnecessary_fallible_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions [`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map [`unnecessary_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_find_map diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 7451fb909ef8..985278e47802 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -191,6 +191,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::format_args::FORMAT_IN_FORMAT_ARGS_INFO, crate::format_args::TO_STRING_IN_FORMAT_ARGS_INFO, crate::format_args::UNINLINED_FORMAT_ARGS_INFO, + crate::format_args::UNNECESSARY_DEBUG_FORMATTING_INFO, crate::format_args::UNUSED_FORMAT_SPECS_INFO, crate::format_impl::PRINT_IN_FORMAT_IMPL_INFO, crate::format_impl::RECURSIVE_FORMAT_IMPL_INFO, diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index da5825b7ab21..ea617dd1bab8 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -1,26 +1,27 @@ use arrayvec::ArrayVec; use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::is_diag_trait_item; use clippy_utils::macros::{ FormatArgsStorage, FormatParamUsage, MacroCall, find_format_arg_expr, format_arg_removal_span, format_placeholder_format_span, is_assert_macro, is_format_macro, is_panic, matching_root_macro_call, root_macro_call_first_node, }; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanRangeExt; +use clippy_utils::source::{SpanRangeExt, snippet}; use clippy_utils::ty::{implements_trait, is_type_lang_item}; +use clippy_utils::{is_diag_trait_item, is_from_proc_macro}; use itertools::Itertools; use rustc_ast::{ FormatArgPosition, FormatArgPositionKind, FormatArgsPiece, FormatArgumentKind, FormatCount, FormatOptions, FormatPlaceholder, FormatTrait, }; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_errors::SuggestionStyle::{CompletelyHidden, ShowCode}; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::Ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment}; +use rustc_middle::ty::{List, Ty, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition::Edition2021; use rustc_span::{Span, Symbol, sym}; @@ -50,6 +51,36 @@ declare_clippy_lint! { "`format!` used in a macro that does formatting" } +declare_clippy_lint! { + /// ### What it does + /// Checks for `Debug` formatting (`{:?}`) applied to an `OsStr` or `Path`. + /// + /// ### Why is this bad? + /// Rust doesn't guarantee what `Debug` formatting looks like, and it could + /// change in the future. `OsStr`s and `Path`s can be `Display` formatted + /// using their `display` methods. + /// + /// Furthermore, with `Debug` formatting, certain characters are escaped. + /// Thus, a `Debug` formatted `Path` is less likely to be clickable. + /// + /// ### Example + /// ```no_run + /// # use std::path::Path; + /// let path = Path::new("..."); + /// println!("The path is {:?}", path); + /// ``` + /// Use instead: + /// ```no_run + /// # use std::path::Path; + /// let path = Path::new("…"); + /// println!("The path is {}", path.display()); + /// ``` + #[clippy::version = "1.87.0"] + pub UNNECESSARY_DEBUG_FORMATTING, + pedantic, + "`Debug` formatting applied to an `OsStr` or `Path` when `.display()` is available" +} + declare_clippy_lint! { /// ### What it does /// Checks for [`ToString::to_string`](https://doc.rust-lang.org/std/string/trait.ToString.html#tymethod.to_string) @@ -162,31 +193,35 @@ declare_clippy_lint! { "use of a format specifier that has no effect" } -impl_lint_pass!(FormatArgs => [ +impl_lint_pass!(FormatArgs<'_> => [ FORMAT_IN_FORMAT_ARGS, TO_STRING_IN_FORMAT_ARGS, UNINLINED_FORMAT_ARGS, + UNNECESSARY_DEBUG_FORMATTING, UNUSED_FORMAT_SPECS, ]); #[allow(clippy::struct_field_names)] -pub struct FormatArgs { +pub struct FormatArgs<'tcx> { format_args: FormatArgsStorage, msrv: Msrv, ignore_mixed: bool, + ty_feature_map: FxHashMap, Option>, } -impl FormatArgs { - pub fn new(conf: &'static Conf, format_args: FormatArgsStorage) -> Self { +impl<'tcx> FormatArgs<'tcx> { + pub fn new(tcx: TyCtxt<'tcx>, conf: &'static Conf, format_args: FormatArgsStorage) -> Self { + let ty_feature_map = make_ty_feature_map(tcx); Self { format_args, msrv: conf.msrv.clone(), ignore_mixed: conf.allow_mixed_uninlined_format_args, + ty_feature_map, } } } -impl<'tcx> LateLintPass<'tcx> for FormatArgs { +impl<'tcx> LateLintPass<'tcx> for FormatArgs<'tcx> { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let Some(macro_call) = root_macro_call_first_node(cx, expr) && is_format_macro(cx, macro_call.def_id) @@ -198,6 +233,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { macro_call: ¯o_call, format_args, ignore_mixed: self.ignore_mixed, + ty_feature_map: &self.ty_feature_map, }; linter.check_templates(); @@ -217,9 +253,10 @@ struct FormatArgsExpr<'a, 'tcx> { macro_call: &'a MacroCall, format_args: &'a rustc_ast::FormatArgs, ignore_mixed: bool, + ty_feature_map: &'a FxHashMap, Option>, } -impl FormatArgsExpr<'_, '_> { +impl<'tcx> FormatArgsExpr<'_, 'tcx> { fn check_templates(&self) { for piece in &self.format_args.template { if let FormatArgsPiece::Placeholder(placeholder) = piece @@ -237,6 +274,11 @@ impl FormatArgsExpr<'_, '_> { self.check_format_in_format_args(name, arg_expr); self.check_to_string_in_format_args(name, arg_expr); } + + if placeholder.format_trait == FormatTrait::Debug { + let name = self.cx.tcx.item_name(self.macro_call.def_id); + self.check_unnecessary_debug_formatting(name, arg_expr); + } } } } @@ -439,6 +481,33 @@ impl FormatArgsExpr<'_, '_> { } } + fn check_unnecessary_debug_formatting(&self, name: Symbol, value: &Expr<'tcx>) { + let cx = self.cx; + if !value.span.from_expansion() + && !is_from_proc_macro(cx, value) + && let ty = cx.typeck_results().expr_ty(value) + && self.can_display_format(ty) + { + let snippet = snippet(cx.sess(), value.span, ".."); + span_lint_and_then( + cx, + UNNECESSARY_DEBUG_FORMATTING, + value.span, + format!("unnecessary `Debug` formatting in `{name}!` args"), + |diag| { + diag.help(format!( + "use `Display` formatting and change this to `{snippet}.display()`" + )); + diag.note( + "switching to `Display` formatting will change how the value is shown; \ + escaped characters will no longer be escaped and surrounding quotes will \ + be removed", + ); + }, + ); + } + } + fn format_arg_positions(&self) -> impl Iterator { self.format_args.template.iter().flat_map(|piece| match piece { FormatArgsPiece::Placeholder(placeholder) => { @@ -465,6 +534,41 @@ impl FormatArgsExpr<'_, '_> { .at_most_one() .is_err() } + + fn can_display_format(&self, ty: Ty<'tcx>) -> bool { + let ty = ty.peel_refs(); + + if let Some(feature) = self.ty_feature_map.get(&ty) + && feature.is_none_or(|feature| self.cx.tcx.features().enabled(feature)) + { + return true; + } + + // Even if `ty` is not in `self.ty_feature_map`, check whether `ty` implements `Deref` with + // a `Target` that is in `self.ty_feature_map`. + if let Some(deref_trait_id) = self.cx.tcx.lang_items().deref_trait() + && implements_trait(self.cx, ty, deref_trait_id, &[]) + && let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, "Target") + && let Some(feature) = self.ty_feature_map.get(&target_ty) + && feature.is_none_or(|feature| self.cx.tcx.features().enabled(feature)) + { + return true; + } + + false + } +} + +fn make_ty_feature_map(tcx: TyCtxt<'_>) -> FxHashMap, Option> { + [(sym::OsStr, Some(Symbol::intern("os_str_display"))), (sym::Path, None)] + .into_iter() + .filter_map(|(name, feature)| { + tcx.get_diagnostic_item(name).map(|def_id| { + let ty = Ty::new_adt(tcx, tcx.adt_def(def_id), List::empty()); + (ty, feature) + }) + }) + .collect() } fn count_needed_derefs<'tcx, I>(mut ty: Ty<'tcx>, mut iter: I) -> (usize, Ty<'tcx>) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index fad6f9d08803..ea7566a8e858 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -835,7 +835,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(conf))); store.register_late_pass(move |_| Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks::new(conf))); let format_args = format_args_storage.clone(); - store.register_late_pass(move |_| Box::new(format_args::FormatArgs::new(conf, format_args.clone()))); + store.register_late_pass(move |tcx| Box::new(format_args::FormatArgs::new(tcx, conf, format_args.clone()))); store.register_late_pass(|_| Box::new(trailing_empty_array::TrailingEmptyArray)); store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes)); store.register_late_pass(|_| Box::new(needless_late_init::NeedlessLateInit)); diff --git a/lintcheck/src/input.rs b/lintcheck/src/input.rs index 3383d50fa02c..83eb0a577d6b 100644 --- a/lintcheck/src/input.rs +++ b/lintcheck/src/input.rs @@ -288,11 +288,11 @@ impl CrateWithSource { // as a result of this filter. let dest_crate_root = PathBuf::from(LINTCHECK_SOURCES).join(name); if dest_crate_root.exists() { - println!("Deleting existing directory at {dest_crate_root:?}"); + println!("Deleting existing directory at `{}`", dest_crate_root.display()); fs::remove_dir_all(&dest_crate_root).unwrap(); } - println!("Copying {path:?} to {dest_crate_root:?}"); + println!("Copying `{}` to `{}`", path.display(), dest_crate_root.display()); for entry in WalkDir::new(path).into_iter().filter_entry(|e| !is_cache_dir(e)) { let entry = entry.unwrap(); diff --git a/tests/compile-test.rs b/tests/compile-test.rs index e2e4d92df79f..10a3e85ed1df 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -377,13 +377,15 @@ fn ui_cargo_toml_metadata() { .map(|component| component.as_os_str().to_string_lossy().replace('-', "_")) .any(|s| *s == name) || path.starts_with(&cargo_common_metadata_path), - "{path:?} has incorrect package name" + "`{}` has incorrect package name", + path.display(), ); let publish = package.get("publish").and_then(toml::Value::as_bool).unwrap_or(true); assert!( !publish || publish_exceptions.contains(&path.parent().unwrap().to_path_buf()), - "{path:?} lacks `publish = false`" + "`{}` lacks `publish = false`", + path.display(), ); } } diff --git a/tests/ui/unnecessary_os_str_debug_formatting.rs b/tests/ui/unnecessary_os_str_debug_formatting.rs new file mode 100644 index 000000000000..3c264e5fc598 --- /dev/null +++ b/tests/ui/unnecessary_os_str_debug_formatting.rs @@ -0,0 +1,23 @@ +#![feature(os_str_display)] +#![warn(clippy::unnecessary_debug_formatting)] + +use std::ffi::{OsStr, OsString}; + +fn main() { + let os_str = OsStr::new("abc"); + let os_string = os_str.to_os_string(); + + // negative tests + println!("{}", os_str.display()); + println!("{}", os_string.display()); + + // positive tests + println!("{:?}", os_str); //~ unnecessary_debug_formatting + println!("{:?}", os_string); //~ unnecessary_debug_formatting + + println!("{os_str:?}"); //~ unnecessary_debug_formatting + println!("{os_string:?}"); //~ unnecessary_debug_formatting + + let _: String = format!("{:?}", os_str); //~ unnecessary_debug_formatting + let _: String = format!("{:?}", os_string); //~ unnecessary_debug_formatting +} diff --git a/tests/ui/unnecessary_os_str_debug_formatting.stderr b/tests/ui/unnecessary_os_str_debug_formatting.stderr new file mode 100644 index 000000000000..382e59b04619 --- /dev/null +++ b/tests/ui/unnecessary_os_str_debug_formatting.stderr @@ -0,0 +1,58 @@ +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:15:22 + | +LL | println!("{:?}", os_str); + | ^^^^^^ + | + = help: use `Display` formatting and change this to `os_str.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + = note: `-D clippy::unnecessary-debug-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:16:22 + | +LL | println!("{:?}", os_string); + | ^^^^^^^^^ + | + = help: use `Display` formatting and change this to `os_string.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:18:16 + | +LL | println!("{os_str:?}"); + | ^^^^^^ + | + = help: use `Display` formatting and change this to `os_str.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:19:16 + | +LL | println!("{os_string:?}"); + | ^^^^^^^^^ + | + = help: use `Display` formatting and change this to `os_string.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `format!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:21:37 + | +LL | let _: String = format!("{:?}", os_str); + | ^^^^^^ + | + = help: use `Display` formatting and change this to `os_str.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `format!` args + --> tests/ui/unnecessary_os_str_debug_formatting.rs:22:37 + | +LL | let _: String = format!("{:?}", os_string); + | ^^^^^^^^^ + | + = help: use `Display` formatting and change this to `os_string.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: aborting due to 6 previous errors + diff --git a/tests/ui/unnecessary_path_debug_formatting.rs b/tests/ui/unnecessary_path_debug_formatting.rs new file mode 100644 index 000000000000..96ad2ee2bf23 --- /dev/null +++ b/tests/ui/unnecessary_path_debug_formatting.rs @@ -0,0 +1,44 @@ +#![warn(clippy::unnecessary_debug_formatting)] + +use std::ffi::{OsStr, OsString}; +use std::ops::Deref; +use std::path::{Path, PathBuf}; + +struct DerefPath<'a> { + path: &'a Path, +} + +impl Deref for DerefPath<'_> { + type Target = Path; + fn deref(&self) -> &Self::Target { + self.path + } +} + +fn main() { + let path = Path::new("/a/b/c"); + let path_buf = path.to_path_buf(); + let os_str = OsStr::new("abc"); + let os_string = os_str.to_os_string(); + + // negative tests + println!("{}", path.display()); + println!("{}", path_buf.display()); + + // should not fire because feature `os_str_display` is not enabled + println!("{:?}", os_str); + println!("{:?}", os_string); + + // positive tests + println!("{:?}", path); //~ unnecessary_debug_formatting + println!("{:?}", path_buf); //~ unnecessary_debug_formatting + + println!("{path:?}"); //~ unnecessary_debug_formatting + println!("{path_buf:?}"); //~ unnecessary_debug_formatting + + let _: String = format!("{:?}", path); //~ unnecessary_debug_formatting + let _: String = format!("{:?}", path_buf); //~ unnecessary_debug_formatting + + let deref_path = DerefPath { path }; + println!("{:?}", &*deref_path); //~ unnecessary_debug_formatting +} diff --git a/tests/ui/unnecessary_path_debug_formatting.stderr b/tests/ui/unnecessary_path_debug_formatting.stderr new file mode 100644 index 000000000000..c9f649dbc0a1 --- /dev/null +++ b/tests/ui/unnecessary_path_debug_formatting.stderr @@ -0,0 +1,67 @@ +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:33:22 + | +LL | println!("{:?}", path); + | ^^^^ + | + = help: use `Display` formatting and change this to `path.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + = note: `-D clippy::unnecessary-debug-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:34:22 + | +LL | println!("{:?}", path_buf); + | ^^^^^^^^ + | + = help: use `Display` formatting and change this to `path_buf.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:36:16 + | +LL | println!("{path:?}"); + | ^^^^ + | + = help: use `Display` formatting and change this to `path.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:37:16 + | +LL | println!("{path_buf:?}"); + | ^^^^^^^^ + | + = help: use `Display` formatting and change this to `path_buf.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `format!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:39:37 + | +LL | let _: String = format!("{:?}", path); + | ^^^^ + | + = help: use `Display` formatting and change this to `path.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `format!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:40:37 + | +LL | let _: String = format!("{:?}", path_buf); + | ^^^^^^^^ + | + = help: use `Display` formatting and change this to `path_buf.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:43:22 + | +LL | println!("{:?}", &*deref_path); + | ^^^^^^^^^^^^ + | + = help: use `Display` formatting and change this to `&*deref_path.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: aborting due to 7 previous errors + From e9561289d6835bcb32f2c59aea81b77914e7e669 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 26 Feb 2025 23:36:10 +0100 Subject: [PATCH 150/161] Remove obsolete TODO --- clippy_lints/src/doc/lazy_continuation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/doc/lazy_continuation.rs b/clippy_lints/src/doc/lazy_continuation.rs index 2577324f23df..8aeb835fe393 100644 --- a/clippy_lints/src/doc/lazy_continuation.rs +++ b/clippy_lints/src/doc/lazy_continuation.rs @@ -16,7 +16,6 @@ fn map_container_to_text(c: &super::Container) -> &'static str { } } -// TODO: Adjust the parameters as necessary pub(super) fn check( cx: &LateContext<'_>, doc: &str, From e399e152e8e5c0060c4f37d39de202d5c9b546d1 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Thu, 27 Feb 2025 10:18:44 +0100 Subject: [PATCH 151/161] Fix ICE --- clippy_lints/src/doc/mod.rs | 11 +++++++- .../ui/doc/doc_nested_refdef_list_item.fixed | 8 ++++++ tests/ui/doc/doc_nested_refdef_list_item.rs | 8 ++++++ .../ui/doc/doc_nested_refdef_list_item.stderr | 26 ++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index bc3e78c7a2c6..984a5e74ce4f 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1004,7 +1004,12 @@ fn check_doc<'a, Events: Iterator, Range range.start { + start - range.start + } else { + 0 + } } } else { 0 @@ -1184,6 +1189,10 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> { #[expect(clippy::range_plus_one)] // inclusive ranges aren't the same type fn looks_like_refdef(doc: &str, range: Range) -> Option> { + if range.end < range.start { + return None; + } + let offset = range.start; let mut iterator = doc.as_bytes()[range].iter().copied().enumerate(); let mut start = None; diff --git a/tests/ui/doc/doc_nested_refdef_list_item.fixed b/tests/ui/doc/doc_nested_refdef_list_item.fixed index fcfcfcc40736..065f4486e390 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.fixed +++ b/tests/ui/doc/doc_nested_refdef_list_item.fixed @@ -69,3 +69,11 @@ pub struct NotEmpty; /// - [link]\: notdef /// inner text pub struct NotEmptyTight; + +/// ## Heading +/// +/// - [x][] - Done +//~^ ERROR: link reference defined in list item +/// - [ ][] - Not Done +//~^ ERROR: link reference defined in list item +pub struct GithubCheckboxes; diff --git a/tests/ui/doc/doc_nested_refdef_list_item.rs b/tests/ui/doc/doc_nested_refdef_list_item.rs index 53368de4616d..c7eab50c8b38 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.rs +++ b/tests/ui/doc/doc_nested_refdef_list_item.rs @@ -69,3 +69,11 @@ pub struct NotEmpty; /// - [link]\: notdef /// inner text pub struct NotEmptyTight; + +/// ## Heading +/// +/// - [x] - Done +//~^ ERROR: link reference defined in list item +/// - [ ] - Not Done +//~^ ERROR: link reference defined in list item +pub struct GithubCheckboxes; diff --git a/tests/ui/doc/doc_nested_refdef_list_item.stderr b/tests/ui/doc/doc_nested_refdef_list_item.stderr index 27314c7e968d..5a815dabf4d8 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.stderr +++ b/tests/ui/doc/doc_nested_refdef_list_item.stderr @@ -144,5 +144,29 @@ help: for an intra-doc link, add `[]` between the label and the colon LL | /// - [link][]: def "title" | ++ -error: aborting due to 12 previous errors +error: link reference defined in list item + --> tests/ui/doc/doc_nested_refdef_list_item.rs:75:7 + | +LL | /// - [x] - Done + | ^^^ + | + = help: link definitions are not shown in rendered documentation +help: for an intra-doc link, add `[]` between the label and the colon + | +LL | /// - [x][] - Done + | ++ + +error: link reference defined in list item + --> tests/ui/doc/doc_nested_refdef_list_item.rs:77:7 + | +LL | /// - [ ] - Not Done + | ^^^ + | + = help: link definitions are not shown in rendered documentation +help: for an intra-doc link, add `[]` between the label and the colon + | +LL | /// - [ ][] - Not Done + | ++ + +error: aborting due to 14 previous errors From 329acde93e357e9797dc14aec9503b1f9234dfc9 Mon Sep 17 00:00:00 2001 From: yanglsh Date: Thu, 27 Feb 2025 16:20:29 +0800 Subject: [PATCH 152/161] fix: `map_entry` FP inside closure --- clippy_lints/src/entry.rs | 5 +++-- tests/ui/entry.fixed | 8 ++++++++ tests/ui/entry.rs | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index f8a5cf53cda0..f404bc59b3b8 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -8,7 +8,7 @@ use clippy_utils::{ use core::fmt::{self, Write}; use rustc_errors::Applicability; use rustc_hir::hir_id::HirIdSet; -use rustc_hir::intravisit::{Visitor, walk_expr}; +use rustc_hir::intravisit::{Visitor, walk_body, walk_expr}; use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -331,7 +331,7 @@ impl<'tcx> Edit<'tcx> { if let Self::Insertion(i) = self { Some(i) } else { None } } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] struct Insertion<'tcx> { call: &'tcx Expr<'tcx>, value: &'tcx Expr<'tcx>, @@ -544,6 +544,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { ExprKind::InlineAsm(_) => { self.can_use_entry = false; }, + ExprKind::Closure(closure) => walk_body(self, self.cx.tcx.hir_body(closure.body)), _ => { self.allow_insert_closure &= !self.in_tail_pos; self.allow_insert_closure &= diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index d52299306fd0..69452a8d9a67 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -218,4 +218,12 @@ mod issue13934 { } } +fn issue11976() { + let mut hashmap = std::collections::HashMap::new(); + if !hashmap.contains_key(&0) { + let _ = || hashmap.get(&0); + hashmap.insert(0, 0); + } +} + fn main() {} diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 25cd6eaa4132..3578324f01c5 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -224,4 +224,12 @@ mod issue13934 { } } +fn issue11976() { + let mut hashmap = std::collections::HashMap::new(); + if !hashmap.contains_key(&0) { + let _ = || hashmap.get(&0); + hashmap.insert(0, 0); + } +} + fn main() {} From 063d6aef0eb8fe81d83a896400c15c6fe9cf0c34 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 27 Feb 2025 20:36:19 +0100 Subject: [PATCH 153/161] macro_use_import: Don't check is attribute comes from expansion It is not possible to write a declarative macro, that produces an attribute w/o an item attached to it. This means that the `check_item` will already insert the span in the map, if it came from an expansion. So additionally checking if the macro came from an expansion doesn't add anything here. So the `check_attribute` function, and with that the problematic `attr.span()` call can be completely removed. Fixes #14303 --- clippy_lints/src/macro_use.rs | 5 ----- tests/ui/crashes/ice-14303.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 tests/ui/crashes/ice-14303.rs diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index bb6e22d9e5c7..68dc1903a248 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -117,11 +117,6 @@ impl LateLintPass<'_> for MacroUseImports { self.push_unique_macro_pat_ty(cx, item.span); } } - fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &hir::Attribute) { - if attr.span.from_expansion() { - self.push_unique_macro(cx, attr.span); - } - } fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { if expr.span.from_expansion() { self.push_unique_macro(cx, expr.span); diff --git a/tests/ui/crashes/ice-14303.rs b/tests/ui/crashes/ice-14303.rs new file mode 100644 index 000000000000..e81f29cd7af9 --- /dev/null +++ b/tests/ui/crashes/ice-14303.rs @@ -0,0 +1,12 @@ +//@check-pass +#![warn(clippy::macro_use_imports)] + +#[repr(transparent)] +pub struct X(()); + +#[repr(u8)] +pub enum Action { + Off = 0, +} + +fn main() {} From 53a1ff70e87ba92caddfbcc9feee8bc89e4a02fc Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 26 Feb 2025 19:46:01 +0100 Subject: [PATCH 154/161] Check os_str_display MSRV instead of feature This feature was stabilized, so the FormatArgs lints should check if the MSRV of the stabilization is met, rather than checking if the feature is enabled. --- clippy_lints/src/format_args.rs | 29 +++++++------- clippy_utils/src/msrvs.rs | 1 + .../ui/unnecessary_os_str_debug_formatting.rs | 1 - ...unnecessary_os_str_debug_formatting.stderr | 12 +++--- tests/ui/unnecessary_path_debug_formatting.rs | 7 ++-- .../unnecessary_path_debug_formatting.stderr | 38 ++++++++++++++----- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index ea617dd1bab8..1ba355938b68 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -15,6 +15,7 @@ use rustc_ast::{ FormatArgPosition, FormatArgPositionKind, FormatArgsPiece, FormatArgumentKind, FormatCount, FormatOptions, FormatPlaceholder, FormatTrait, }; +use rustc_attr_parsing::RustcVersion; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_errors::SuggestionStyle::{CompletelyHidden, ShowCode}; @@ -206,17 +207,17 @@ pub struct FormatArgs<'tcx> { format_args: FormatArgsStorage, msrv: Msrv, ignore_mixed: bool, - ty_feature_map: FxHashMap, Option>, + ty_msrv_map: FxHashMap, Option>, } impl<'tcx> FormatArgs<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, conf: &'static Conf, format_args: FormatArgsStorage) -> Self { - let ty_feature_map = make_ty_feature_map(tcx); + let ty_msrv_map = make_ty_msrv_map(tcx); Self { format_args, msrv: conf.msrv.clone(), ignore_mixed: conf.allow_mixed_uninlined_format_args, - ty_feature_map, + ty_msrv_map, } } } @@ -233,7 +234,8 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs<'tcx> { macro_call: ¯o_call, format_args, ignore_mixed: self.ignore_mixed, - ty_feature_map: &self.ty_feature_map, + msrv: &self.msrv, + ty_msrv_map: &self.ty_msrv_map, }; linter.check_templates(); @@ -253,7 +255,8 @@ struct FormatArgsExpr<'a, 'tcx> { macro_call: &'a MacroCall, format_args: &'a rustc_ast::FormatArgs, ignore_mixed: bool, - ty_feature_map: &'a FxHashMap, Option>, + msrv: &'a Msrv, + ty_msrv_map: &'a FxHashMap, Option>, } impl<'tcx> FormatArgsExpr<'_, 'tcx> { @@ -538,19 +541,19 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> { fn can_display_format(&self, ty: Ty<'tcx>) -> bool { let ty = ty.peel_refs(); - if let Some(feature) = self.ty_feature_map.get(&ty) - && feature.is_none_or(|feature| self.cx.tcx.features().enabled(feature)) + if let Some(msrv) = self.ty_msrv_map.get(&ty) + && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) { return true; } - // Even if `ty` is not in `self.ty_feature_map`, check whether `ty` implements `Deref` with - // a `Target` that is in `self.ty_feature_map`. + // Even if `ty` is not in `self.ty_msrv_map`, check whether `ty` implements `Deref` with + // a `Target` that is in `self.ty_msrv_map`. if let Some(deref_trait_id) = self.cx.tcx.lang_items().deref_trait() && implements_trait(self.cx, ty, deref_trait_id, &[]) && let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, "Target") - && let Some(feature) = self.ty_feature_map.get(&target_ty) - && feature.is_none_or(|feature| self.cx.tcx.features().enabled(feature)) + && let Some(msrv) = self.ty_msrv_map.get(&target_ty) + && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) { return true; } @@ -559,8 +562,8 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> { } } -fn make_ty_feature_map(tcx: TyCtxt<'_>) -> FxHashMap, Option> { - [(sym::OsStr, Some(Symbol::intern("os_str_display"))), (sym::Path, None)] +fn make_ty_msrv_map(tcx: TyCtxt<'_>) -> FxHashMap, Option> { + [(sym::OsStr, Some(msrvs::OS_STR_DISPLAY)), (sym::Path, None)] .into_iter() .filter_map(|(name, feature)| { tcx.get_diagnostic_item(name).map(|def_id| { diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 8c9832af0a19..8a7a7d006352 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -19,6 +19,7 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { + 1,87,0 { OS_STR_DISPLAY } 1,84,0 { CONST_OPTION_AS_SLICE } 1,83,0 { CONST_EXTERN_FN, CONST_FLOAT_BITS_CONV, CONST_FLOAT_CLASSIFY, CONST_MUT_REFS, CONST_UNWRAP } 1,82,0 { IS_NONE_OR, REPEAT_N, RAW_REF_OP } diff --git a/tests/ui/unnecessary_os_str_debug_formatting.rs b/tests/ui/unnecessary_os_str_debug_formatting.rs index 3c264e5fc598..12663ec9a528 100644 --- a/tests/ui/unnecessary_os_str_debug_formatting.rs +++ b/tests/ui/unnecessary_os_str_debug_formatting.rs @@ -1,4 +1,3 @@ -#![feature(os_str_display)] #![warn(clippy::unnecessary_debug_formatting)] use std::ffi::{OsStr, OsString}; diff --git a/tests/ui/unnecessary_os_str_debug_formatting.stderr b/tests/ui/unnecessary_os_str_debug_formatting.stderr index 382e59b04619..001309ab817a 100644 --- a/tests/ui/unnecessary_os_str_debug_formatting.stderr +++ b/tests/ui/unnecessary_os_str_debug_formatting.stderr @@ -1,5 +1,5 @@ error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:15:22 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:14:22 | LL | println!("{:?}", os_str); | ^^^^^^ @@ -10,7 +10,7 @@ LL | println!("{:?}", os_str); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:16:22 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:15:22 | LL | println!("{:?}", os_string); | ^^^^^^^^^ @@ -19,7 +19,7 @@ LL | println!("{:?}", os_string); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:18:16 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:17:16 | LL | println!("{os_str:?}"); | ^^^^^^ @@ -28,7 +28,7 @@ LL | println!("{os_str:?}"); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:19:16 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:18:16 | LL | println!("{os_string:?}"); | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL | println!("{os_string:?}"); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `format!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:21:37 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:20:37 | LL | let _: String = format!("{:?}", os_str); | ^^^^^^ @@ -46,7 +46,7 @@ LL | let _: String = format!("{:?}", os_str); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `format!` args - --> tests/ui/unnecessary_os_str_debug_formatting.rs:22:37 + --> tests/ui/unnecessary_os_str_debug_formatting.rs:21:37 | LL | let _: String = format!("{:?}", os_string); | ^^^^^^^^^ diff --git a/tests/ui/unnecessary_path_debug_formatting.rs b/tests/ui/unnecessary_path_debug_formatting.rs index 96ad2ee2bf23..02adeece2809 100644 --- a/tests/ui/unnecessary_path_debug_formatting.rs +++ b/tests/ui/unnecessary_path_debug_formatting.rs @@ -25,11 +25,10 @@ fn main() { println!("{}", path.display()); println!("{}", path_buf.display()); - // should not fire because feature `os_str_display` is not enabled - println!("{:?}", os_str); - println!("{:?}", os_string); - // positive tests + println!("{:?}", os_str); //~ unnecessary_debug_formatting + println!("{:?}", os_string); //~ unnecessary_debug_formatting + println!("{:?}", path); //~ unnecessary_debug_formatting println!("{:?}", path_buf); //~ unnecessary_debug_formatting diff --git a/tests/ui/unnecessary_path_debug_formatting.stderr b/tests/ui/unnecessary_path_debug_formatting.stderr index c9f649dbc0a1..f12fa72c84b3 100644 --- a/tests/ui/unnecessary_path_debug_formatting.stderr +++ b/tests/ui/unnecessary_path_debug_formatting.stderr @@ -1,16 +1,34 @@ error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:33:22 + --> tests/ui/unnecessary_path_debug_formatting.rs:29:22 + | +LL | println!("{:?}", os_str); + | ^^^^^^ + | + = help: use `Display` formatting and change this to `os_str.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + = note: `-D clippy::unnecessary-debug-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:30:22 + | +LL | println!("{:?}", os_string); + | ^^^^^^^^^ + | + = help: use `Display` formatting and change this to `os_string.display()` + = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed + +error: unnecessary `Debug` formatting in `println!` args + --> tests/ui/unnecessary_path_debug_formatting.rs:32:22 | LL | println!("{:?}", path); | ^^^^ | = help: use `Display` formatting and change this to `path.display()` = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed - = note: `-D clippy::unnecessary-debug-formatting` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:34:22 + --> tests/ui/unnecessary_path_debug_formatting.rs:33:22 | LL | println!("{:?}", path_buf); | ^^^^^^^^ @@ -19,7 +37,7 @@ LL | println!("{:?}", path_buf); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:36:16 + --> tests/ui/unnecessary_path_debug_formatting.rs:35:16 | LL | println!("{path:?}"); | ^^^^ @@ -28,7 +46,7 @@ LL | println!("{path:?}"); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:37:16 + --> tests/ui/unnecessary_path_debug_formatting.rs:36:16 | LL | println!("{path_buf:?}"); | ^^^^^^^^ @@ -37,7 +55,7 @@ LL | println!("{path_buf:?}"); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `format!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:39:37 + --> tests/ui/unnecessary_path_debug_formatting.rs:38:37 | LL | let _: String = format!("{:?}", path); | ^^^^ @@ -46,7 +64,7 @@ LL | let _: String = format!("{:?}", path); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `format!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:40:37 + --> tests/ui/unnecessary_path_debug_formatting.rs:39:37 | LL | let _: String = format!("{:?}", path_buf); | ^^^^^^^^ @@ -55,7 +73,7 @@ LL | let _: String = format!("{:?}", path_buf); = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed error: unnecessary `Debug` formatting in `println!` args - --> tests/ui/unnecessary_path_debug_formatting.rs:43:22 + --> tests/ui/unnecessary_path_debug_formatting.rs:42:22 | LL | println!("{:?}", &*deref_path); | ^^^^^^^^^^^^ @@ -63,5 +81,5 @@ LL | println!("{:?}", &*deref_path); = help: use `Display` formatting and change this to `&*deref_path.display()` = note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed -error: aborting due to 7 previous errors +error: aborting due to 9 previous errors From 28555d1231beb1546b6ac5e1f81780db00aa46aa Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 26 Feb 2025 19:47:30 +0100 Subject: [PATCH 155/161] Split must_use_unit test into an unfixable part With the attribute refactor in rustc, making this case machine applicable is not easily possible anymore. This splits up the tests properly. --- tests/ui/must_use_unit.fixed | 8 -------- tests/ui/must_use_unit.rs | 8 -------- tests/ui/must_use_unit.stderr | 18 +----------------- ...nit_12320.rs => must_use_unit_unfixable.rs} | 8 ++++---- ...0.stderr => must_use_unit_unfixable.stderr} | 12 ++++++------ 5 files changed, 11 insertions(+), 43 deletions(-) rename tests/ui/{must_use_unit_12320.rs => must_use_unit_unfixable.rs} (62%) rename tests/ui/{must_use_unit_12320.stderr => must_use_unit_unfixable.stderr} (62%) diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index 5a8603ceb562..683754a98c82 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -26,11 +26,3 @@ fn main() { fn foo() {} ); } - -#[cfg_attr(all(), deprecated)] -fn issue_12320() {} -//~^ must_use_unit - -#[cfg_attr(all(), deprecated, doc = "foo")] -fn issue_12320_2() {} -//~^ must_use_unit diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index ab2764841cb4..519b8fa36821 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -29,11 +29,3 @@ fn main() { fn foo() {} ); } - -#[cfg_attr(all(), must_use, deprecated)] -fn issue_12320() {} -//~^ must_use_unit - -#[cfg_attr(all(), deprecated, doc = "foo", must_use)] -fn issue_12320_2() {} -//~^ must_use_unit diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index 3df9738a9693..8f2af0cbd291 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -25,21 +25,5 @@ LL | #[must_use = "With note"] LL | pub fn must_use_with_note() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:34:1 - | -LL | #[cfg_attr(all(), must_use, deprecated)] - | -------------------- help: change these attributes to: `deprecated` -LL | fn issue_12320() {} - | ^^^^^^^^^^^^^^^^ - -error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit.rs:38:1 - | -LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] - | --------------------------------- help: change these attributes to: `deprecated, doc = "foo"` -LL | fn issue_12320_2() {} - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/must_use_unit_12320.rs b/tests/ui/must_use_unit_unfixable.rs similarity index 62% rename from tests/ui/must_use_unit_12320.rs rename to tests/ui/must_use_unit_unfixable.rs index 39dcafdb38b5..0dba7996bac3 100644 --- a/tests/ui/must_use_unit_12320.rs +++ b/tests/ui/must_use_unit_unfixable.rs @@ -1,11 +1,11 @@ -//@aux-build:proc_macros.rs //@no-rustfix -#![warn(clippy::must_use_unit)] -#![allow(clippy::unused_unit)] - #[cfg_attr(all(), must_use, deprecated)] fn issue_12320() {} +//~^ must_use_unit #[cfg_attr(all(), deprecated, doc = "foo", must_use)] fn issue_12320_2() {} +//~^ must_use_unit + +fn main() {} diff --git a/tests/ui/must_use_unit_12320.stderr b/tests/ui/must_use_unit_unfixable.stderr similarity index 62% rename from tests/ui/must_use_unit_12320.stderr rename to tests/ui/must_use_unit_unfixable.stderr index b3e1cbc04576..087682199afb 100644 --- a/tests/ui/must_use_unit_12320.stderr +++ b/tests/ui/must_use_unit_unfixable.stderr @@ -1,25 +1,25 @@ error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit_12320.rs:8:1 + --> tests/ui/must_use_unit_unfixable.rs:4:1 | LL | fn issue_12320() {} | ^^^^^^^^^^^^^^^^ | help: remove `must_use` - --> tests/ui/must_use_unit_12320.rs:7:19 + --> tests/ui/must_use_unit_unfixable.rs:3:19 | LL | #[cfg_attr(all(), must_use, deprecated)] | ^^^^^^^^ - = note: `-D clippy::double-must-use` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` + = note: `-D clippy::must-use-unit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::must_use_unit)]` error: this unit-returning function has a `#[must_use]` attribute - --> tests/ui/must_use_unit_12320.rs:11:1 + --> tests/ui/must_use_unit_unfixable.rs:8:1 | LL | fn issue_12320_2() {} | ^^^^^^^^^^^^^^^^^^ | help: remove `must_use` - --> tests/ui/must_use_unit_12320.rs:10:44 + --> tests/ui/must_use_unit_unfixable.rs:7:44 | LL | #[cfg_attr(all(), deprecated, doc = "foo", must_use)] | ^^^^^^^^ From b3d35b1af6d997b138d679aa4c1143dbac11c11e Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 27 Feb 2025 21:49:59 +0100 Subject: [PATCH 156/161] Bump nightly version -> 2025-02-27 --- clippy_utils/README.md | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/README.md b/clippy_utils/README.md index 41f3b1cbd507..5dd31b52f880 100644 --- a/clippy_utils/README.md +++ b/clippy_utils/README.md @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain: ``` -nightly-2025-02-06 +nightly-2025-02-27 ``` diff --git a/rust-toolchain b/rust-toolchain index ab760287e83a..a4931499c802 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,6 +1,6 @@ [toolchain] # begin autogenerated nightly -channel = "nightly-2025-02-06" +channel = "nightly-2025-02-27" # end autogenerated nightly components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal" From 06175f43b3119b537b48291fa771c7396b8e92cd Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 17 Dec 2024 22:43:19 +0100 Subject: [PATCH 157/161] Add `is_float_literal` utility --- clippy_utils/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index dc3bbb417c0a..3e9429399b31 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1752,6 +1752,17 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { false } +/// Checks whether the given expression is a constant literal of the given value. +pub fn is_float_literal(expr: &Expr<'_>, value: f64) -> bool { + if let ExprKind::Lit(spanned) = expr.kind + && let LitKind::Float(v, _) = spanned.node + { + v.as_str().parse() == Ok(value) + } else { + false + } +} + /// Returns `true` if the given `Expr` has been coerced before. /// /// Examples of coercions can be found in the Nomicon at From baadee8fd36e951c258d3d8505aa292bc3165b31 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 17 Dec 2024 22:43:19 +0100 Subject: [PATCH 158/161] New lint: `manual_midpoint` --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/operators/manual_midpoint.rs | 64 ++++++++++++++++ clippy_lints/src/operators/mod.rs | 32 ++++++++ clippy_utils/src/msrvs.rs | 3 +- tests/ui/manual_midpoint.fixed | 74 +++++++++++++++++++ tests/ui/manual_midpoint.rs | 74 +++++++++++++++++++ tests/ui/manual_midpoint.stderr | 65 ++++++++++++++++ tests/ui/option_if_let_else.fixed | 1 + tests/ui/option_if_let_else.rs | 1 + tests/ui/option_if_let_else.stderr | 50 ++++++------- tests/ui/suspicious_operation_groupings.fixed | 2 +- tests/ui/suspicious_operation_groupings.rs | 2 +- 15 files changed, 344 insertions(+), 28 deletions(-) create mode 100644 clippy_lints/src/operators/manual_midpoint.rs create mode 100644 tests/ui/manual_midpoint.fixed create mode 100644 tests/ui/manual_midpoint.rs create mode 100644 tests/ui/manual_midpoint.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8ca7cb1496..ce3960186e39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5807,6 +5807,7 @@ Released 2018-09-13 [`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str [`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map [`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy +[`manual_midpoint`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_midpoint [`manual_next_back`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_next_back [`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive [`manual_ok_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 7a70c6c40ac8..4b416c2b595d 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -771,6 +771,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one) * [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) * [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) +* [`manual_midpoint`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_midpoint) * [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive) * [`manual_option_as_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_as_slice) * [`manual_pattern_char_comparison`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 23d585a6c159..c97f5b0f8067 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -626,6 +626,7 @@ define_Conf! { manual_hash_one, manual_is_ascii_check, manual_let_else, + manual_midpoint, manual_non_exhaustive, manual_option_as_slice, manual_pattern_char_comparison, diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9dde6a7933c6..0834618499c7 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -608,6 +608,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::operators::IMPOSSIBLE_COMPARISONS_INFO, crate::operators::INEFFECTIVE_BIT_MASK_INFO, crate::operators::INTEGER_DIVISION_INFO, + crate::operators::MANUAL_MIDPOINT_INFO, crate::operators::MISREFACTORED_ASSIGN_OP_INFO, crate::operators::MODULO_ARITHMETIC_INFO, crate::operators::MODULO_ONE_INFO, diff --git a/clippy_lints/src/operators/manual_midpoint.rs b/clippy_lints/src/operators/manual_midpoint.rs new file mode 100644 index 000000000000..61ef5670a5ad --- /dev/null +++ b/clippy_lints/src/operators/manual_midpoint.rs @@ -0,0 +1,64 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::sugg::Sugg; +use clippy_utils::{is_float_literal, is_integer_literal}; +use rustc_ast::BinOpKind; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind}; +use rustc_lint::LateContext; +use rustc_middle::ty::{self, Ty}; + +use super::MANUAL_MIDPOINT; + +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'_>, + op: BinOpKind, + left: &'tcx Expr<'_>, + right: &'tcx Expr<'_>, + msrv: &Msrv, +) { + if !left.span.from_expansion() + && !right.span.from_expansion() + && op == BinOpKind::Div + && (is_integer_literal(right, 2) || is_float_literal(right, 2.0)) + && let Some((ll_expr, lr_expr)) = add_operands(left) + && add_operands(ll_expr).is_none() && add_operands(lr_expr).is_none() + && let left_ty = cx.typeck_results().expr_ty_adjusted(ll_expr) + && let right_ty = cx.typeck_results().expr_ty_adjusted(lr_expr) + && left_ty == right_ty + // Do not lint on `(_+1)/2` and `(1+_)/2`, it is likely a `div_ceil()` operation + && !is_integer_literal(ll_expr, 1) && !is_integer_literal(lr_expr, 1) + && is_midpoint_implemented(left_ty, msrv) + { + let mut app = Applicability::MachineApplicable; + let left_sugg = Sugg::hir_with_context(cx, ll_expr, expr.span.ctxt(), "..", &mut app); + let right_sugg = Sugg::hir_with_context(cx, lr_expr, expr.span.ctxt(), "..", &mut app); + let sugg = format!("{left_ty}::midpoint({left_sugg}, {right_sugg})"); + span_lint_and_sugg( + cx, + MANUAL_MIDPOINT, + expr.span, + "manual implementation of `midpoint` which can overflow", + format!("use `{left_ty}::midpoint` instead"), + sugg, + app, + ); + } +} + +/// Return the left and right operands if `expr` represents an addition +fn add_operands<'e, 'tcx>(expr: &'e Expr<'tcx>) -> Option<(&'e Expr<'tcx>, &'e Expr<'tcx>)> { + match expr.kind { + ExprKind::Binary(op, left, right) if op.node == BinOpKind::Add => Some((left, right)), + _ => None, + } +} + +fn is_midpoint_implemented(ty: Ty<'_>, msrv: &Msrv) -> bool { + match ty.kind() { + ty::Uint(_) | ty::Float(_) => msrv.meets(msrvs::UINT_FLOAT_MIDPOINT), + ty::Int(_) => msrv.meets(msrvs::INT_MIDPOINT), + _ => false, + } +} diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index 9ad32c2bd396..43b657ea7ff0 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -11,6 +11,7 @@ mod float_cmp; mod float_equality_without_abs; mod identity_op; mod integer_division; +mod manual_midpoint; mod misrefactored_assign_op; mod modulo_arithmetic; mod modulo_one; @@ -24,6 +25,7 @@ mod verbose_bit_mask; pub(crate) mod arithmetic_side_effects; use clippy_config::Conf; +use clippy_utils::msrvs::Msrv; use rustc_hir::{Body, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; @@ -834,10 +836,35 @@ declare_clippy_lint! { "explicit self-assignment" } +declare_clippy_lint! { + /// ### What it does + /// Checks for manual implementation of `midpoint`. + /// + /// ### Why is this bad? + /// Using `(x + y) / 2` might cause an overflow on the intermediate + /// addition result. + /// + /// ### Example + /// ```no_run + /// # let a: u32 = 0; + /// let c = (a + 10) / 2; + /// ``` + /// Use instead: + /// ```no_run + /// # let a: u32 = 0; + /// let c = u32::midpoint(a, 10); + /// ``` + #[clippy::version = "1.87.0"] + pub MANUAL_MIDPOINT, + pedantic, + "manual implementation of `midpoint` which can overflow" +} + pub struct Operators { arithmetic_context: numeric_arithmetic::Context, verbose_bit_mask_threshold: u64, modulo_arithmetic_allow_comparison_to_zero: bool, + msrv: Msrv, } impl Operators { pub fn new(conf: &'static Conf) -> Self { @@ -845,6 +872,7 @@ impl Operators { arithmetic_context: numeric_arithmetic::Context::default(), verbose_bit_mask_threshold: conf.verbose_bit_mask_threshold, modulo_arithmetic_allow_comparison_to_zero: conf.allow_comparison_to_zero, + msrv: conf.msrv.clone(), } } } @@ -876,6 +904,7 @@ impl_lint_pass!(Operators => [ NEEDLESS_BITWISE_BOOL, PTR_EQ, SELF_ASSIGNMENT, + MANUAL_MIDPOINT, ]); impl<'tcx> LateLintPass<'tcx> for Operators { @@ -893,6 +922,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators { identity_op::check(cx, e, op.node, lhs, rhs); needless_bitwise_bool::check(cx, e, op.node, lhs, rhs); ptr_eq::check(cx, e, op.node, lhs, rhs); + manual_midpoint::check(cx, e, op.node, lhs, rhs, &self.msrv); } self.arithmetic_context.check_binary(cx, e, op.node, lhs, rhs); bit_mask::check(cx, e, op.node, lhs, rhs); @@ -943,6 +973,8 @@ impl<'tcx> LateLintPass<'tcx> for Operators { fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) { self.arithmetic_context.body_post(cx, b); } + + extract_msrv_attr!(LateContext); } fn macro_with_not_op(e: &Expr<'_>) -> bool { diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 8a7a7d006352..f9cf29cbdf46 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -19,7 +19,8 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { - 1,87,0 { OS_STR_DISPLAY } + 1,87,0 { OS_STR_DISPLAY, INT_MIDPOINT } + 1,85,0 { UINT_FLOAT_MIDPOINT } 1,84,0 { CONST_OPTION_AS_SLICE } 1,83,0 { CONST_EXTERN_FN, CONST_FLOAT_BITS_CONV, CONST_FLOAT_CLASSIFY, CONST_MUT_REFS, CONST_UNWRAP } 1,82,0 { IS_NONE_OR, REPEAT_N, RAW_REF_OP } diff --git a/tests/ui/manual_midpoint.fixed b/tests/ui/manual_midpoint.fixed new file mode 100644 index 000000000000..63116ced8438 --- /dev/null +++ b/tests/ui/manual_midpoint.fixed @@ -0,0 +1,74 @@ +#![warn(clippy::manual_midpoint)] + +macro_rules! mac { + ($a: expr, $b: expr) => { + ($a + $b) / 2 + }; +} + +macro_rules! add { + ($a: expr, $b: expr) => { + ($a + $b) + }; +} + +macro_rules! two { + () => { + 2 + }; +} + +#[clippy::msrv = "1.84"] +fn older_msrv() { + let a: u32 = 10; + let _ = (a + 5) / 2; +} + +#[clippy::msrv = "1.85"] +fn main() { + let a: u32 = 10; + let _ = u32::midpoint(a, 5); //~ ERROR: manual implementation of `midpoint` + + let f: f32 = 10.0; + let _ = f32::midpoint(f, 5.0); //~ ERROR: manual implementation of `midpoint` + + let _: u32 = 5 + u32::midpoint(8, 8) + 2; //~ ERROR: manual implementation of `midpoint` + let _: u32 = const { u32::midpoint(8, 8) }; //~ ERROR: manual implementation of `midpoint` + let _: f64 = const { f64::midpoint(8.0f64, 8.) }; //~ ERROR: manual implementation of `midpoint` + let _: u32 = u32::midpoint(u32::default(), u32::default()); //~ ERROR: manual implementation of `midpoint` + let _: u32 = u32::midpoint(two!(), two!()); //~ ERROR: manual implementation of `midpoint` + + // Do not lint in presence of an addition with more than 2 operands + let _: u32 = (10 + 20 + 30) / 2; + + // Do not lint if whole or part is coming from a macro + let _ = mac!(10, 20); + let _: u32 = add!(10u32, 20u32) / 2; + let _: u32 = (10 + 20) / two!(); + + // Do not lint if a literal is not present + let _ = (f + 5.0) / (1.0 + 1.0); + + // Do not lint on signed integer types + let i: i32 = 10; + let _ = (i + 5) / 2; + + // Do not lint on (x+1)/2 or (1+x)/2 as this looks more like a `div_ceil()` operation + let _ = (i + 1) / 2; + let _ = (1 + i) / 2; + + // But if we see (x+1.0)/2.0 or (x+1.0)/2.0, it is probably a midpoint operation + let _ = f32::midpoint(f, 1.0); //~ ERROR: manual implementation of `midpoint` + let _ = f32::midpoint(1.0, f); //~ ERROR: manual implementation of `midpoint` +} + +#[clippy::msrv = "1.86"] +fn older_signed_midpoint(i: i32) { + // Do not lint + let _ = (i + 10) / 2; +} + +#[clippy::msrv = "1.87"] +fn signed_midpoint(i: i32) { + let _ = i32::midpoint(i, 10); //~ ERROR: manual implementation of `midpoint` +} diff --git a/tests/ui/manual_midpoint.rs b/tests/ui/manual_midpoint.rs new file mode 100644 index 000000000000..47f1b88c78cd --- /dev/null +++ b/tests/ui/manual_midpoint.rs @@ -0,0 +1,74 @@ +#![warn(clippy::manual_midpoint)] + +macro_rules! mac { + ($a: expr, $b: expr) => { + ($a + $b) / 2 + }; +} + +macro_rules! add { + ($a: expr, $b: expr) => { + ($a + $b) + }; +} + +macro_rules! two { + () => { + 2 + }; +} + +#[clippy::msrv = "1.84"] +fn older_msrv() { + let a: u32 = 10; + let _ = (a + 5) / 2; +} + +#[clippy::msrv = "1.85"] +fn main() { + let a: u32 = 10; + let _ = (a + 5) / 2; //~ ERROR: manual implementation of `midpoint` + + let f: f32 = 10.0; + let _ = (f + 5.0) / 2.0; //~ ERROR: manual implementation of `midpoint` + + let _: u32 = 5 + (8 + 8) / 2 + 2; //~ ERROR: manual implementation of `midpoint` + let _: u32 = const { (8 + 8) / 2 }; //~ ERROR: manual implementation of `midpoint` + let _: f64 = const { (8.0f64 + 8.) / 2. }; //~ ERROR: manual implementation of `midpoint` + let _: u32 = (u32::default() + u32::default()) / 2; //~ ERROR: manual implementation of `midpoint` + let _: u32 = (two!() + two!()) / 2; //~ ERROR: manual implementation of `midpoint` + + // Do not lint in presence of an addition with more than 2 operands + let _: u32 = (10 + 20 + 30) / 2; + + // Do not lint if whole or part is coming from a macro + let _ = mac!(10, 20); + let _: u32 = add!(10u32, 20u32) / 2; + let _: u32 = (10 + 20) / two!(); + + // Do not lint if a literal is not present + let _ = (f + 5.0) / (1.0 + 1.0); + + // Do not lint on signed integer types + let i: i32 = 10; + let _ = (i + 5) / 2; + + // Do not lint on (x+1)/2 or (1+x)/2 as this looks more like a `div_ceil()` operation + let _ = (i + 1) / 2; + let _ = (1 + i) / 2; + + // But if we see (x+1.0)/2.0 or (x+1.0)/2.0, it is probably a midpoint operation + let _ = (f + 1.0) / 2.0; //~ ERROR: manual implementation of `midpoint` + let _ = (1.0 + f) / 2.0; //~ ERROR: manual implementation of `midpoint` +} + +#[clippy::msrv = "1.86"] +fn older_signed_midpoint(i: i32) { + // Do not lint + let _ = (i + 10) / 2; +} + +#[clippy::msrv = "1.87"] +fn signed_midpoint(i: i32) { + let _ = (i + 10) / 2; //~ ERROR: manual implementation of `midpoint` +} diff --git a/tests/ui/manual_midpoint.stderr b/tests/ui/manual_midpoint.stderr new file mode 100644 index 000000000000..3d588e2114df --- /dev/null +++ b/tests/ui/manual_midpoint.stderr @@ -0,0 +1,65 @@ +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:30:13 + | +LL | let _ = (a + 5) / 2; + | ^^^^^^^^^^^ help: use `u32::midpoint` instead: `u32::midpoint(a, 5)` + | + = note: `-D clippy::manual-midpoint` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_midpoint)]` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:33:13 + | +LL | let _ = (f + 5.0) / 2.0; + | ^^^^^^^^^^^^^^^ help: use `f32::midpoint` instead: `f32::midpoint(f, 5.0)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:35:22 + | +LL | let _: u32 = 5 + (8 + 8) / 2 + 2; + | ^^^^^^^^^^^ help: use `u32::midpoint` instead: `u32::midpoint(8, 8)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:36:26 + | +LL | let _: u32 = const { (8 + 8) / 2 }; + | ^^^^^^^^^^^ help: use `u32::midpoint` instead: `u32::midpoint(8, 8)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:37:26 + | +LL | let _: f64 = const { (8.0f64 + 8.) / 2. }; + | ^^^^^^^^^^^^^^^^^^ help: use `f64::midpoint` instead: `f64::midpoint(8.0f64, 8.)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:38:18 + | +LL | let _: u32 = (u32::default() + u32::default()) / 2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `u32::midpoint` instead: `u32::midpoint(u32::default(), u32::default())` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:39:18 + | +LL | let _: u32 = (two!() + two!()) / 2; + | ^^^^^^^^^^^^^^^^^^^^^ help: use `u32::midpoint` instead: `u32::midpoint(two!(), two!())` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:61:13 + | +LL | let _ = (f + 1.0) / 2.0; + | ^^^^^^^^^^^^^^^ help: use `f32::midpoint` instead: `f32::midpoint(f, 1.0)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:62:13 + | +LL | let _ = (1.0 + f) / 2.0; + | ^^^^^^^^^^^^^^^ help: use `f32::midpoint` instead: `f32::midpoint(1.0, f)` + +error: manual implementation of `midpoint` which can overflow + --> tests/ui/manual_midpoint.rs:73:13 + | +LL | let _ = (i + 10) / 2; + | ^^^^^^^^^^^^ help: use `i32::midpoint` instead: `i32::midpoint(i, 10)` + +error: aborting due to 10 previous errors + diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 56b313244e36..f5a869cf2831 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -4,6 +4,7 @@ clippy::equatable_if_let, clippy::let_unit_value, clippy::redundant_locals, + clippy::manual_midpoint, clippy::manual_unwrap_or_default, clippy::manual_unwrap_or )] diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index 4a4bb141ed54..d48272e618ac 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -4,6 +4,7 @@ clippy::equatable_if_let, clippy::let_unit_value, clippy::redundant_locals, + clippy::manual_midpoint, clippy::manual_unwrap_or_default, clippy::manual_unwrap_or )] diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index f872ac991840..9eb41f81a539 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:12:5 + --> tests/ui/option_if_let_else.rs:13:5 | LL | / if let Some(x) = string { LL | | @@ -13,19 +13,19 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:31:13 + --> tests/ui/option_if_let_else.rs:32:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:33:13 + --> tests/ui/option_if_let_else.rs:34:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:35:13 + --> tests/ui/option_if_let_else.rs:36:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -47,13 +47,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:42:13 + --> tests/ui/option_if_let_else.rs:43:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:44:13 + --> tests/ui/option_if_let_else.rs:45:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -75,7 +75,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:51:13 + --> tests/ui/option_if_let_else.rs:52:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -97,7 +97,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:61:5 + --> tests/ui/option_if_let_else.rs:62:5 | LL | / if let Some(x) = arg { LL | | @@ -118,7 +118,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:75:13 + --> tests/ui/option_if_let_else.rs:76:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:85:13 + --> tests/ui/option_if_let_else.rs:86:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -154,7 +154,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:119:13 + --> tests/ui/option_if_let_else.rs:120:13 | LL | / if let Some(idx) = s.find('.') { LL | | @@ -165,7 +165,7 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:131:5 + --> tests/ui/option_if_let_else.rs:132:5 | LL | / if let Ok(binding) = variable { LL | | @@ -189,13 +189,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:156:13 + --> tests/ui/option_if_let_else.rs:157:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:167:13 + --> tests/ui/option_if_let_else.rs:168:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -217,13 +217,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:196:13 + --> tests/ui/option_if_let_else.rs:197:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:201:13 + --> tests/ui/option_if_let_else.rs:202:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -245,7 +245,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:241:13 + --> tests/ui/option_if_let_else.rs:242:13 | LL | let _ = match s { | _____________^ @@ -256,7 +256,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:246:13 + --> tests/ui/option_if_let_else.rs:247:13 | LL | let _ = match Some(10) { | _____________^ @@ -267,7 +267,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:253:13 + --> tests/ui/option_if_let_else.rs:254:13 | LL | let _ = match res { | _____________^ @@ -278,7 +278,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:258:13 + --> tests/ui/option_if_let_else.rs:259:13 | LL | let _ = match res { | _____________^ @@ -289,13 +289,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:263:13 + --> tests/ui/option_if_let_else.rs:264:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:281:17 + --> tests/ui/option_if_let_else.rs:282:17 | LL | let _ = match initial { | _________________^ @@ -306,7 +306,7 @@ LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:289:17 + --> tests/ui/option_if_let_else.rs:290:17 | LL | let _ = match initial { | _________________^ @@ -317,7 +317,7 @@ LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:313:24 + --> tests/ui/option_if_let_else.rs:314:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ @@ -329,7 +329,7 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:320:19 + --> tests/ui/option_if_let_else.rs:321:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index 37054222bd62..fa680e537d30 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -1,7 +1,7 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::suspicious_operation_groupings)] -#![allow(dead_code, unused_parens, clippy::eq_op)] +#![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] struct Vec3 { x: f64, diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index f4d1c3c70b56..4ffee640e8bd 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -1,7 +1,7 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::suspicious_operation_groupings)] -#![allow(dead_code, unused_parens, clippy::eq_op)] +#![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] struct Vec3 { x: f64, From 0972c3b56596b51f9cfdf99a5ad74c754e94d3aa Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Fri, 13 Dec 2024 17:40:07 +0000 Subject: [PATCH 159/161] Check for MSRV attributes in late passes using the HIR --- book/src/development/adding_lints.md | 31 ++-- clippy_config/src/conf.rs | 2 +- clippy_dev/src/main.rs | 6 +- clippy_dev/src/new_lint.rs | 82 ++++++----- clippy_utils/src/lib.rs | 17 +-- clippy_utils/src/msrvs.rs | 139 +++++++++++------- clippy_utils/src/paths.rs | 3 +- clippy_utils/src/qualify_min_const_fn.rs | 123 +++++++++------- .../ui-internal/invalid_msrv_attr_impl.fixed | 11 +- tests/ui-internal/invalid_msrv_attr_impl.rs | 8 +- .../ui-internal/invalid_msrv_attr_impl.stderr | 26 +--- .../ui/msrv_attributes_without_early_lints.rs | 12 ++ 12 files changed, 246 insertions(+), 214 deletions(-) create mode 100644 tests/ui/msrv_attributes_without_early_lints.rs diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index 60135e96c5a5..0b9010f01071 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -460,7 +460,7 @@ pub struct ManualStrip { impl ManualStrip { pub fn new(conf: &'static Conf) -> Self { - Self { msrv: conf.msrv.clone() } + Self { msrv: conf.msrv } } } ``` @@ -469,24 +469,13 @@ The project's MSRV can then be matched against the feature MSRV in the LintPass using the `Msrv::meets` method. ``` rust -if !self.msrv.meets(msrvs::STR_STRIP_PREFIX) { +if !self.msrv.meets(cx, msrvs::STR_STRIP_PREFIX) { return; } ``` -The project's MSRV can also be specified as an attribute, which overrides -the value from `clippy.toml`. This can be accounted for using the -`extract_msrv_attr!(LintContext)` macro and passing -`LateContext`/`EarlyContext`. - -```rust,ignore -impl<'tcx> LateLintPass<'tcx> for ManualStrip { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - ... - } - extract_msrv_attr!(LateContext); -} -``` +Early lint passes should instead use `MsrvStack` coupled with +`extract_msrv_attr!()` Once the `msrv` is added to the lint, a relevant test case should be added to the lint's test file, `tests/ui/manual_strip.rs` in this example. It should @@ -512,8 +501,16 @@ in `clippy_config/src/conf.rs`: ```rust define_Conf! { - /// Lint: LIST, OF, LINTS, . The minimum rust version that the project supports - (msrv: Option = None), + #[lints( + allow_attributes, + allow_attributes_without_reason, + .. + , + .. + unused_trait_names, + use_self, + )] + msrv: Msrv = Msrv::default(), ... } ``` diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index e4571204f46a..a61acbaa96bc 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -670,7 +670,7 @@ define_Conf! { unused_trait_names, use_self, )] - msrv: Msrv = Msrv::empty(), + msrv: Msrv = Msrv::default(), /// The minimum size (in bytes) to consider a type for passing by reference instead of by value. #[lints(large_types_passed_by_value)] pass_by_value_size_limit: u64 = 256, diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index fcdee073f88d..074dea4ab77b 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -35,7 +35,7 @@ fn main() { category, r#type, msrv, - } => match new_lint::create(&pass, &name, &category, r#type.as_deref(), msrv) { + } => match new_lint::create(pass, &name, &category, r#type.as_deref(), msrv) { Ok(()) => update_lints::update(utils::UpdateMode::Change), Err(e) => eprintln!("Unable to create lint: {e}"), }, @@ -147,9 +147,9 @@ enum DevCommand { #[command(name = "new_lint")] /// Create a new lint and run `cargo dev update_lints` NewLint { - #[arg(short, long, value_parser = ["early", "late"], conflicts_with = "type", default_value = "late")] + #[arg(short, long, conflicts_with = "type", default_value = "late")] /// Specify whether the lint runs during the early or late pass - pass: String, + pass: new_lint::Pass, #[arg( short, long, diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index cf6e44245660..96e12706c9e2 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -1,13 +1,28 @@ use crate::utils::{clippy_project_root, clippy_version}; +use clap::ValueEnum; use indoc::{formatdoc, writedoc}; -use std::fmt::Write as _; +use std::fmt::{self, Write as _}; use std::fs::{self, OpenOptions}; -use std::io::prelude::*; +use std::io::{self, Write as _}; use std::path::{Path, PathBuf}; -use std::{fmt, io}; + +#[derive(Clone, Copy, PartialEq, ValueEnum)] +pub enum Pass { + Early, + Late, +} + +impl fmt::Display for Pass { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Pass::Early => "early", + Pass::Late => "late", + }) + } +} struct LintData<'a> { - pass: &'a str, + pass: Pass, name: &'a str, category: &'a str, ty: Option<&'a str>, @@ -35,7 +50,7 @@ impl Context for io::Result { /// # Errors /// /// This function errors out if the files couldn't be created or written to. -pub fn create(pass: &str, name: &str, category: &str, mut ty: Option<&str>, msrv: bool) -> io::Result<()> { +pub fn create(pass: Pass, name: &str, category: &str, mut ty: Option<&str>, msrv: bool) -> io::Result<()> { if category == "cargo" && ty.is_none() { // `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo` ty = Some("cargo"); @@ -56,7 +71,7 @@ pub fn create(pass: &str, name: &str, category: &str, mut ty: Option<&str>, msrv add_lint(&lint, msrv).context("Unable to add lint to clippy_lints/src/lib.rs")?; } - if pass == "early" { + if pass == Pass::Early { println!( "\n\ NOTE: Use a late pass unless you need something specific from\n\ @@ -136,23 +151,17 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> { let mut lib_rs = fs::read_to_string(path).context("reading")?; let comment_start = lib_rs.find("// add lints here,").expect("Couldn't find comment"); + let ctor_arg = if lint.pass == Pass::Late { "_" } else { "" }; + let lint_pass = lint.pass; + let module_name = lint.name; + let camel_name = to_camel_case(lint.name); let new_lint = if enable_msrv { format!( "store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf)));\n ", - lint_pass = lint.pass, - ctor_arg = if lint.pass == "late" { "_" } else { "" }, - module_name = lint.name, - camel_name = to_camel_case(lint.name), ) } else { - format!( - "store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ", - lint_pass = lint.pass, - ctor_arg = if lint.pass == "late" { "_" } else { "" }, - module_name = lint.name, - camel_name = to_camel_case(lint.name), - ) + format!("store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ",) }; lib_rs.insert_str(comment_start, &new_lint); @@ -242,11 +251,16 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { let mut result = String::new(); let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass { - "early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"), - "late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"), - _ => { - unreachable!("`pass_type` should only ever be `early` or `late`!"); - }, + Pass::Early => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"), + Pass::Late => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"), + }; + let (msrv_ty, msrv_ctor, extract_msrv) = match lint.pass { + Pass::Early => ( + "MsrvStack", + "MsrvStack::new(conf.msrv)", + "\n extract_msrv_attr!();\n", + ), + Pass::Late => ("Msrv", "conf.msrv", ""), }; let lint_name = lint.name; @@ -258,10 +272,10 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { let _: fmt::Result = writedoc!( result, r" - use clippy_utils::msrvs::{{self, Msrv}}; + use clippy_utils::msrvs::{{self, {msrv_ty}}}; use clippy_config::Conf; {pass_import} - use rustc_lint::{{{context_import}, {pass_type}, LintContext}}; + use rustc_lint::{{{context_import}, {pass_type}}}; use rustc_session::impl_lint_pass; " @@ -285,20 +299,18 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String { result, r" pub struct {name_camel} {{ - msrv: Msrv, + msrv: {msrv_ty}, }} impl {name_camel} {{ pub fn new(conf: &'static Conf) -> Self {{ - Self {{ msrv: conf.msrv.clone() }} + Self {{ msrv: {msrv_ctor} }} }} }} impl_lint_pass!({name_camel} => [{name_upper}]); - impl {pass_type}{pass_lifetimes} for {name_camel} {{ - extract_msrv_attr!({context_import}); - }} + impl {pass_type}{pass_lifetimes} for {name_camel} {{{extract_msrv}}} // TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed. // TODO: Update msrv config comment in `clippy_config/src/conf.rs` @@ -375,9 +387,9 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R let mod_file_path = ty_dir.join("mod.rs"); let context_import = setup_mod_file(&mod_file_path, lint)?; - let pass_lifetimes = match context_import { - "LateContext" => "<'_>", - _ => "", + let (pass_lifetimes, msrv_ty, msrv_ref, msrv_cx) = match context_import { + "LateContext" => ("<'_>", "Msrv", "", "cx, "), + _ => ("", "MsrvStack", "&", ""), }; let name_upper = lint.name.to_uppercase(); @@ -387,14 +399,14 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R let _: fmt::Result = writedoc!( lint_file_contents, r#" - use clippy_utils::msrvs::{{self, Msrv}}; + use clippy_utils::msrvs::{{self, {msrv_ty}}}; use rustc_lint::{{{context_import}, LintContext}}; use super::{name_upper}; // TODO: Adjust the parameters as necessary - pub(super) fn check(cx: &{context_import}{pass_lifetimes}, msrv: &Msrv) {{ - if !msrv.meets(todo!("Add a new entry in `clippy_utils/src/msrvs`")) {{ + pub(super) fn check(cx: &{context_import}{pass_lifetimes}, msrv: {msrv_ref}{msrv_ty}) {{ + if !msrv.meets({msrv_cx}todo!("Add a new entry in `clippy_utils/src/msrvs`")) {{ return; }} todo!(); diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3e9429399b31..ba7346979460 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -137,24 +137,13 @@ use rustc_middle::hir::nested_filter; #[macro_export] macro_rules! extract_msrv_attr { - (LateContext) => { - fn check_attributes(&mut self, cx: &rustc_lint::LateContext<'_>, attrs: &[rustc_hir::Attribute]) { + () => { + fn check_attributes(&mut self, cx: &rustc_lint::EarlyContext<'_>, attrs: &[rustc_ast::ast::Attribute]) { let sess = rustc_lint::LintContext::sess(cx); self.msrv.check_attributes(sess, attrs); } - fn check_attributes_post(&mut self, cx: &rustc_lint::LateContext<'_>, attrs: &[rustc_hir::Attribute]) { - let sess = rustc_lint::LintContext::sess(cx); - self.msrv.check_attributes_post(sess, attrs); - } - }; - (EarlyContext) => { - fn check_attributes(&mut self, cx: &rustc_lint::EarlyContext<'_>, attrs: &[rustc_ast::Attribute]) { - let sess = rustc_lint::LintContext::sess(cx); - self.msrv.check_attributes(sess, attrs); - } - - fn check_attributes_post(&mut self, cx: &rustc_lint::EarlyContext<'_>, attrs: &[rustc_ast::Attribute]) { + fn check_attributes_post(&mut self, cx: &rustc_lint::EarlyContext<'_>, attrs: &[rustc_ast::ast::Attribute]) { let sess = rustc_lint::LintContext::sess(cx); self.msrv.check_attributes_post(sess, attrs); } diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index f9cf29cbdf46..5bb2b12988a6 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -1,11 +1,14 @@ +use rustc_ast::Attribute; use rustc_ast::attr::AttributeExt; use rustc_attr_parsing::{RustcVersion, parse_version}; +use rustc_lint::LateContext; use rustc_session::Session; use rustc_span::{Symbol, sym}; use serde::Deserialize; -use smallvec::{SmallVec, smallvec}; -use std::fmt; +use smallvec::SmallVec; +use std::iter::once; +use std::sync::atomic::{AtomicBool, Ordering}; macro_rules! msrv_aliases { ($($major:literal,$minor:literal,$patch:literal { @@ -73,21 +76,15 @@ msrv_aliases! { 1,15,0 { MAYBE_BOUND_IN_WHERE } } -/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]` -#[derive(Debug, Clone)] -pub struct Msrv { - stack: SmallVec<[RustcVersion; 2]>, -} +/// `#[clippy::msrv]` attributes are rarely used outside of Clippy's test suite, as a basic +/// optimization we can skip traversing the HIR in [`Msrv::meets`] if we never saw an MSRV attribute +/// during the early lint passes +static SEEN_MSRV_ATTR: AtomicBool = AtomicBool::new(false); -impl fmt::Display for Msrv { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let Some(msrv) = self.current() { - write!(f, "{msrv}") - } else { - f.write_str("1.0.0") - } - } -} +/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]` in late +/// lint passes, use [`MsrvStack`] for early passes +#[derive(Copy, Clone, Debug, Default)] +pub struct Msrv(Option); impl<'de> Deserialize<'de> for Msrv { fn deserialize(deserializer: D) -> Result @@ -96,14 +93,36 @@ impl<'de> Deserialize<'de> for Msrv { { let v = String::deserialize(deserializer)?; parse_version(Symbol::intern(&v)) - .map(|v| Msrv { stack: smallvec![v] }) + .map(|v| Self(Some(v))) .ok_or_else(|| serde::de::Error::custom("not a valid Rust version")) } } impl Msrv { - pub fn empty() -> Msrv { - Msrv { stack: SmallVec::new() } + /// Returns the MSRV at the current node + /// + /// If the crate being linted uses an `#[clippy::msrv]` attribute this will search the parent + /// nodes for that attribute, prefer to run this check after cheaper pattern matching operations + pub fn current(self, cx: &LateContext<'_>) -> Option { + if SEEN_MSRV_ATTR.load(Ordering::Relaxed) { + let start = cx.last_node_with_lint_attrs; + if let Some(msrv_attr) = once(start) + .chain(cx.tcx.hir_parent_id_iter(start)) + .find_map(|id| parse_attrs(cx.tcx.sess, cx.tcx.hir().attrs(id))) + { + return Some(msrv_attr); + } + } + + self.0 + } + + /// Checks if a required version from [this module](self) is met at the current node + /// + /// If the crate being linted uses an `#[clippy::msrv]` attribute this will search the parent + /// nodes for that attribute, prefer to run this check after cheaper pattern matching operations + pub fn meets(self, cx: &LateContext<'_>, required: RustcVersion) -> bool { + self.current(cx).is_none_or(|msrv| msrv >= required) } pub fn read_cargo(&mut self, sess: &Session) { @@ -111,8 +130,8 @@ impl Msrv { .ok() .and_then(|v| parse_version(Symbol::intern(&v))); - match (self.current(), cargo_msrv) { - (None, Some(cargo_msrv)) => self.stack = smallvec![cargo_msrv], + match (self.0, cargo_msrv) { + (None, Some(cargo_msrv)) => self.0 = Some(cargo_msrv), (Some(clippy_msrv), Some(cargo_msrv)) => { if clippy_msrv != cargo_msrv { sess.dcx().warn(format!( @@ -123,6 +142,21 @@ impl Msrv { _ => {}, } } +} + +/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]` in early +/// lint passes, use [`Msrv`] for late passes +#[derive(Debug, Clone)] +pub struct MsrvStack { + stack: SmallVec<[RustcVersion; 2]>, +} + +impl MsrvStack { + pub fn new(initial: Msrv) -> Self { + Self { + stack: SmallVec::from_iter(initial.0), + } + } pub fn current(&self) -> Option { self.stack.last().copied() @@ -132,42 +166,43 @@ impl Msrv { self.current().is_none_or(|msrv| msrv >= required) } - fn parse_attr(sess: &Session, attrs: &[impl AttributeExt]) -> Option { - let sym_msrv = Symbol::intern("msrv"); - let mut msrv_attrs = attrs.iter().filter(|attr| attr.path_matches(&[sym::clippy, sym_msrv])); - - if let Some(msrv_attr) = msrv_attrs.next() { - if let Some(duplicate) = msrv_attrs.next_back() { - sess.dcx() - .struct_span_err(duplicate.span(), "`clippy::msrv` is defined multiple times") - .with_span_note(msrv_attr.span(), "first definition found here") - .emit(); - } - - if let Some(msrv) = msrv_attr.value_str() { - if let Some(version) = parse_version(msrv) { - return Some(version); - } - - sess.dcx() - .span_err(msrv_attr.span(), format!("`{msrv}` is not a valid Rust version")); - } else { - sess.dcx().span_err(msrv_attr.span(), "bad clippy attribute"); - } - } - - None - } - - pub fn check_attributes(&mut self, sess: &Session, attrs: &[impl AttributeExt]) { - if let Some(version) = Self::parse_attr(sess, attrs) { + pub fn check_attributes(&mut self, sess: &Session, attrs: &[Attribute]) { + if let Some(version) = parse_attrs(sess, attrs) { + SEEN_MSRV_ATTR.store(true, Ordering::Relaxed); self.stack.push(version); } } - pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[impl AttributeExt]) { - if Self::parse_attr(sess, attrs).is_some() { + pub fn check_attributes_post(&mut self, sess: &Session, attrs: &[Attribute]) { + if parse_attrs(sess, attrs).is_some() { self.stack.pop(); } } } + +fn parse_attrs(sess: &Session, attrs: &[impl AttributeExt]) -> Option { + let sym_msrv = Symbol::intern("msrv"); + let mut msrv_attrs = attrs.iter().filter(|attr| attr.path_matches(&[sym::clippy, sym_msrv])); + + if let Some(msrv_attr) = msrv_attrs.next() { + if let Some(duplicate) = msrv_attrs.next_back() { + sess.dcx() + .struct_span_err(duplicate.span(), "`clippy::msrv` is defined multiple times") + .with_span_note(msrv_attr.span(), "first definition found here") + .emit(); + } + + if let Some(msrv) = msrv_attr.value_str() { + if let Some(version) = parse_version(msrv) { + return Some(version); + } + + sess.dcx() + .span_err(msrv_attr.span(), format!("`{msrv}` is not a valid Rust version")); + } else { + sess.dcx().span_err(msrv_attr.span(), "bad clippy attribute"); + } + } + + None +} diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 452bb4ce4c77..51d06ad9b1aa 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -19,7 +19,6 @@ pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"]; pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"]; pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"]; pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"]; -pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"]; pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"]; pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"]; pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"]; @@ -33,7 +32,7 @@ pub const IO_ERROR_NEW: [&str; 5] = ["std", "io", "error", "Error", "new"]; pub const IO_ERRORKIND_OTHER: [&str; 5] = ["std", "io", "error", "ErrorKind", "Other"]; // Paths in clippy itself -pub const MSRV: [&str; 3] = ["clippy_utils", "msrvs", "Msrv"]; +pub const MSRV_STACK: [&str; 3] = ["clippy_utils", "msrvs", "MsrvStack"]; // Paths in external crates #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index c7890f33f27e..8e6f4d4a317e 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -11,6 +11,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::Obligation; +use rustc_lint::LateContext; use rustc_middle::mir::{ Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, @@ -25,16 +26,16 @@ use std::borrow::Cow; type McfResult = Result<(), (Span, Cow<'static, str>)>; -pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) -> McfResult { +pub fn is_min_const_fn<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, msrv: Msrv) -> McfResult { let def_id = body.source.def_id(); for local in &body.local_decls { - check_ty(tcx, local.ty, local.source_info.span, msrv)?; + check_ty(cx, local.ty, local.source_info.span, msrv)?; } // impl trait is gone in MIR, so check the return type manually check_ty( - tcx, - tcx.fn_sig(def_id).instantiate_identity().output().skip_binder(), + cx, + cx.tcx.fn_sig(def_id).instantiate_identity().output().skip_binder(), body.local_decls.iter().next().unwrap().source_info.span, msrv, )?; @@ -43,16 +44,16 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv) // Cleanup blocks are ignored entirely by const eval, so we can too: // https://github.com/rust-lang/rust/blob/1dea922ea6e74f99a0e97de5cdb8174e4dea0444/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382 if !bb.is_cleanup { - check_terminator(tcx, body, bb.terminator(), msrv)?; + check_terminator(cx, body, bb.terminator(), msrv)?; for stmt in &bb.statements { - check_statement(tcx, body, def_id, stmt, msrv)?; + check_statement(cx, body, def_id, stmt, msrv)?; } } } Ok(()) } -fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, msrv: &Msrv) -> McfResult { +fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) -> McfResult { for arg in ty.walk() { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, @@ -63,7 +64,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, msrv: &Msrv) -> M }; match ty.kind() { - ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(msrvs::CONST_MUT_REFS) => { + ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => { return Err((span, "mutable references in const fn are unstable".into())); }, ty::Alias(ty::Opaque, ..) => return Err((span, "`impl Trait` in const fn is unstable".into())), @@ -82,7 +83,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, msrv: &Msrv) -> M )); }, ty::ExistentialPredicate::Trait(trait_ref) => { - if Some(trait_ref.def_id) != tcx.lang_items().sized_trait() { + if Some(trait_ref.def_id) != cx.tcx.lang_items().sized_trait() { return Err(( span, "trait bounds other than `Sized` \ @@ -101,19 +102,19 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, msrv: &Msrv) -> M } fn check_rvalue<'tcx>( - tcx: TyCtxt<'tcx>, + cx: &LateContext<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rvalue<'tcx>, span: Span, - msrv: &Msrv, + msrv: Msrv, ) -> McfResult { match rvalue { Rvalue::ThreadLocalRef(_) => Err((span, "cannot access thread local storage in const fn".into())), Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => { - check_place(tcx, *place, span, body, msrv) + check_place(cx, *place, span, body, msrv) }, - Rvalue::CopyForDeref(place) => check_place(tcx, *place, span, body, msrv), + Rvalue::CopyForDeref(place) => check_place(cx, *place, span, body, msrv), Rvalue::Repeat(operand, _) | Rvalue::Use(operand) | Rvalue::WrapUnsafeBinder(operand, _) @@ -128,7 +129,7 @@ fn check_rvalue<'tcx>( | CastKind::PointerCoercion(PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer, _), operand, _, - ) => check_operand(tcx, operand, span, body, msrv), + ) => check_operand(cx, operand, span, body, msrv), Rvalue::Cast( CastKind::PointerCoercion( PointerCoercion::UnsafeFnPointer @@ -144,9 +145,11 @@ fn check_rvalue<'tcx>( // We cannot allow this for now. return Err((span, "unsizing casts are only allowed for references right now".into())); }; - let unsized_ty = tcx.struct_tail_for_codegen(pointee_ty, ty::TypingEnv::post_analysis(tcx, def_id)); + let unsized_ty = cx + .tcx + .struct_tail_for_codegen(pointee_ty, ty::TypingEnv::post_analysis(cx.tcx, def_id)); if let ty::Slice(_) | ty::Str = unsized_ty.kind() { - check_operand(tcx, op, span, body, msrv)?; + check_operand(cx, op, span, body, msrv)?; // Casting/coercing things to slices is fine. Ok(()) } else { @@ -167,9 +170,9 @@ fn check_rvalue<'tcx>( )), // binops are fine on integers Rvalue::BinaryOp(_, box (lhs, rhs)) => { - check_operand(tcx, lhs, span, body, msrv)?; - check_operand(tcx, rhs, span, body, msrv)?; - let ty = lhs.ty(body, tcx); + check_operand(cx, lhs, span, body, msrv)?; + check_operand(cx, rhs, span, body, msrv)?; + let ty = lhs.ty(body, cx.tcx); if ty.is_integral() || ty.is_bool() || ty.is_char() { Ok(()) } else { @@ -185,16 +188,16 @@ fn check_rvalue<'tcx>( ) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { - let ty = operand.ty(body, tcx); + let ty = operand.ty(body, cx.tcx); if ty.is_integral() || ty.is_bool() { - check_operand(tcx, operand, span, body, msrv) + check_operand(cx, operand, span, body, msrv) } else { Err((span, "only int and `bool` operations are stable in const fn".into())) } }, Rvalue::Aggregate(_, operands) => { for operand in operands { - check_operand(tcx, operand, span, body, msrv)?; + check_operand(cx, operand, span, body, msrv)?; } Ok(()) }, @@ -202,33 +205,33 @@ fn check_rvalue<'tcx>( } fn check_statement<'tcx>( - tcx: TyCtxt<'tcx>, + cx: &LateContext<'tcx>, body: &Body<'tcx>, def_id: DefId, statement: &Statement<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) -> McfResult { let span = statement.source_info.span; match &statement.kind { StatementKind::Assign(box (place, rval)) => { - check_place(tcx, *place, span, body, msrv)?; - check_rvalue(tcx, body, def_id, rval, span, msrv) + check_place(cx, *place, span, body, msrv)?; + check_rvalue(cx, body, def_id, rval, span, msrv) }, - StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body, msrv), + StatementKind::FakeRead(box (_, place)) => check_place(cx, *place, span, body, msrv), // just an assignment StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => { - check_place(tcx, **place, span, body, msrv) + check_place(cx, **place, span, body, msrv) }, - StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => check_operand(tcx, op, span, body, msrv), + StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => check_operand(cx, op, span, body, msrv), StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( rustc_middle::mir::CopyNonOverlapping { dst, src, count }, )) => { - check_operand(tcx, dst, span, body, msrv)?; - check_operand(tcx, src, span, body, msrv)?; - check_operand(tcx, count, span, body, msrv) + check_operand(cx, dst, span, body, msrv)?; + check_operand(cx, src, span, body, msrv)?; + check_operand(cx, count, span, body, msrv) }, // These are all NOPs StatementKind::StorageLive(_) @@ -244,16 +247,16 @@ fn check_statement<'tcx>( } fn check_operand<'tcx>( - tcx: TyCtxt<'tcx>, + cx: &LateContext<'tcx>, operand: &Operand<'tcx>, span: Span, body: &Body<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) -> McfResult { match operand { Operand::Move(place) => { if !place.projection.as_ref().is_empty() - && !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) + && !is_ty_const_destruct(cx.tcx, place.ty(&body.local_decls, cx.tcx).ty, body) { return Err(( span, @@ -261,29 +264,35 @@ fn check_operand<'tcx>( )); } - check_place(tcx, *place, span, body, msrv) + check_place(cx, *place, span, body, msrv) }, - Operand::Copy(place) => check_place(tcx, *place, span, body, msrv), - Operand::Constant(c) => match c.check_static_ptr(tcx) { + Operand::Copy(place) => check_place(cx, *place, span, body, msrv), + Operand::Constant(c) => match c.check_static_ptr(cx.tcx) { Some(_) => Err((span, "cannot access `static` items in const fn".into())), None => Ok(()), }, } } -fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &Body<'tcx>, msrv: &Msrv) -> McfResult { +fn check_place<'tcx>( + cx: &LateContext<'tcx>, + place: Place<'tcx>, + span: Span, + body: &Body<'tcx>, + msrv: Msrv, +) -> McfResult { for (base, elem) in place.as_ref().iter_projections() { match elem { ProjectionElem::Field(..) => { - if base.ty(body, tcx).ty.is_union() && !msrv.meets(msrvs::CONST_FN_UNION) { + if base.ty(body, cx.tcx).ty.is_union() && !msrv.meets(cx, msrvs::CONST_FN_UNION) { return Err((span, "accessing union fields is unstable".into())); } }, - ProjectionElem::Deref => match base.ty(body, tcx).ty.kind() { + ProjectionElem::Deref => match base.ty(body, cx.tcx).ty.kind() { ty::RawPtr(_, hir::Mutability::Mut) => { return Err((span, "dereferencing raw mut pointer in const fn is unstable".into())); }, - ty::RawPtr(_, hir::Mutability::Not) if !msrv.meets(msrvs::CONST_RAW_PTR_DEREF) => { + ty::RawPtr(_, hir::Mutability::Not) if !msrv.meets(cx, msrvs::CONST_RAW_PTR_DEREF) => { return Err((span, "dereferencing raw const pointer in const fn is unstable".into())); }, _ => (), @@ -302,10 +311,10 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B } fn check_terminator<'tcx>( - tcx: TyCtxt<'tcx>, + cx: &LateContext<'tcx>, body: &Body<'tcx>, terminator: &Terminator<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) -> McfResult { let span = terminator.source_info.span; match &terminator.kind { @@ -317,7 +326,7 @@ fn check_terminator<'tcx>( | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => { - if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) { + if !is_ty_const_destruct(cx.tcx, place.ty(&body.local_decls, cx.tcx).ty, body) { return Err(( span, "cannot drop locals with a non constant destructor in const fn".into(), @@ -325,7 +334,7 @@ fn check_terminator<'tcx>( } Ok(()) }, - TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body, msrv), + TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(cx, discr, span, body, msrv), TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { Err((span, "const fn coroutines are unstable".into())) }, @@ -339,9 +348,9 @@ fn check_terminator<'tcx>( fn_span: _, } | TerminatorKind::TailCall { func, args, fn_span: _ } => { - let fn_ty = func.ty(body, tcx); + let fn_ty = func.ty(body, cx.tcx); if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { - if !is_stable_const_fn(tcx, fn_def_id, msrv) { + if !is_stable_const_fn(cx, fn_def_id, msrv) { return Err(( span, format!( @@ -356,17 +365,17 @@ fn check_terminator<'tcx>( // within const fns. `transmute` is allowed in all other const contexts. // This won't really scale to more intrinsics or functions. Let's allow const // transmutes in const fn before we add more hacks to this. - if tcx.is_intrinsic(fn_def_id, sym::transmute) { + if cx.tcx.is_intrinsic(fn_def_id, sym::transmute) { return Err(( span, "can only call `transmute` from const items, not `const fn`".into(), )); } - check_operand(tcx, func, span, body, msrv)?; + check_operand(cx, func, span, body, msrv)?; for arg in args { - check_operand(tcx, &arg.node, span, body, msrv)?; + check_operand(cx, &arg.node, span, body, msrv)?; } Ok(()) } else { @@ -379,14 +388,14 @@ fn check_terminator<'tcx>( msg: _, target: _, unwind: _, - } => check_operand(tcx, cond, span, body, msrv), + } => check_operand(cx, cond, span, body, msrv), TerminatorKind::InlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())), } } -fn is_stable_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { - tcx.is_const_fn(def_id) - && tcx.lookup_const_stability(def_id).is_none_or(|const_stab| { +fn is_stable_const_fn(cx: &LateContext<'_>, def_id: DefId, msrv: Msrv) -> bool { + cx.tcx.is_const_fn(def_id) + && cx.tcx.lookup_const_stability(def_id).is_none_or(|const_stab| { if let rustc_attr_parsing::StabilityLevel::Stable { since, .. } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire // function could be removed if `rustc` provided a MSRV-aware version of `is_stable_const_fn`. @@ -398,10 +407,10 @@ fn is_stable_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool { StableSince::Err => return false, }; - msrv.meets(const_stab_rust_version) + msrv.meets(cx, const_stab_rust_version) } else { // Unstable const fn, check if the feature is enabled. - tcx.features().enabled(const_stab.feature) && msrv.current().is_none() + cx.tcx.features().enabled(const_stab.feature) && msrv.current(cx).is_none() } }) } diff --git a/tests/ui-internal/invalid_msrv_attr_impl.fixed b/tests/ui-internal/invalid_msrv_attr_impl.fixed index 928596d08091..7011ef518f20 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.fixed +++ b/tests/ui-internal/invalid_msrv_attr_impl.fixed @@ -9,7 +9,7 @@ extern crate rustc_middle; #[macro_use] extern crate rustc_session; use clippy_utils::extract_msrv_attr; -use clippy_utils::msrvs::Msrv; +use clippy_utils::msrvs::MsrvStack; use rustc_hir::Expr; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; @@ -20,18 +20,13 @@ declare_lint! { } struct Pass { - msrv: Msrv, + msrv: MsrvStack, } impl_lint_pass!(Pass => [TEST_LINT]); -impl LateLintPass<'_> for Pass { - extract_msrv_attr!(LateContext); - fn check_expr(&mut self, _: &LateContext<'_>, _: &Expr<'_>) {} -} - impl EarlyLintPass for Pass { - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {} } diff --git a/tests/ui-internal/invalid_msrv_attr_impl.rs b/tests/ui-internal/invalid_msrv_attr_impl.rs index 50b28648ccc9..323061decd23 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.rs +++ b/tests/ui-internal/invalid_msrv_attr_impl.rs @@ -9,7 +9,7 @@ extern crate rustc_middle; #[macro_use] extern crate rustc_session; use clippy_utils::extract_msrv_attr; -use clippy_utils::msrvs::Msrv; +use clippy_utils::msrvs::MsrvStack; use rustc_hir::Expr; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; @@ -20,15 +20,11 @@ declare_lint! { } struct Pass { - msrv: Msrv, + msrv: MsrvStack, } impl_lint_pass!(Pass => [TEST_LINT]); -impl LateLintPass<'_> for Pass { - fn check_expr(&mut self, _: &LateContext<'_>, _: &Expr<'_>) {} -} - impl EarlyLintPass for Pass { fn check_expr(&mut self, _: &EarlyContext<'_>, _: &rustc_ast::Expr) {} } diff --git a/tests/ui-internal/invalid_msrv_attr_impl.stderr b/tests/ui-internal/invalid_msrv_attr_impl.stderr index 8b69af122e45..8ba42e4bb2b2 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.stderr +++ b/tests/ui-internal/invalid_msrv_attr_impl.stderr @@ -1,8 +1,8 @@ -error: `extract_msrv_attr!` macro missing from `LateLintPass` implementation +error: `extract_msrv_attr!` macro missing from `EarlyLintPass` implementation --> tests/ui-internal/invalid_msrv_attr_impl.rs:28:1 | -LL | impl LateLintPass<'_> for Pass { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | impl EarlyLintPass for Pass { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> tests/ui-internal/invalid_msrv_attr_impl.rs:1:9 @@ -10,23 +10,11 @@ note: the lint level is defined here LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::missing_msrv_attr_impl)]` implied by `#[deny(clippy::internal)]` -help: add `extract_msrv_attr!(LateContext)` to the `LateLintPass` implementation +help: add `extract_msrv_attr!()` to the `EarlyLintPass` implementation | -LL ~ impl LateLintPass<'_> for Pass { -LL + extract_msrv_attr!(LateContext); +LL + impl EarlyLintPass for Pass { +LL + extract_msrv_attr!(); | -error: `extract_msrv_attr!` macro missing from `EarlyLintPass` implementation - --> tests/ui-internal/invalid_msrv_attr_impl.rs:32:1 - | -LL | impl EarlyLintPass for Pass { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: add `extract_msrv_attr!(EarlyContext)` to the `EarlyLintPass` implementation - | -LL ~ impl EarlyLintPass for Pass { -LL + extract_msrv_attr!(EarlyContext); - | - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/msrv_attributes_without_early_lints.rs b/tests/ui/msrv_attributes_without_early_lints.rs new file mode 100644 index 000000000000..dec62c15079d --- /dev/null +++ b/tests/ui/msrv_attributes_without_early_lints.rs @@ -0,0 +1,12 @@ +#![allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] +#![forbid(clippy::ptr_as_ptr)] + +/// MSRV checking in late passes skips checking the parent nodes if no early pass sees a +/// `#[clippy::msrv]` attribute +/// +/// Here we ensure that even if all early passes are allowed (above) the attribute is still detected +/// in late lints such as `clippy::ptr_as_ptr` +#[clippy::msrv = "1.37"] +fn f(p: *const i32) { + let _ = p as *const i64; +} From 5b0004c45fae362f50e9e587f7a16249501d07f8 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sat, 18 Jan 2025 17:41:57 +0000 Subject: [PATCH 160/161] Migrate `clippy_lints` to new MSRV API --- clippy_lints/src/almost_complete_range.rs | 8 +-- clippy_lints/src/approx_const.rs | 8 +-- clippy_lints/src/assigning_clones.rs | 8 +-- clippy_lints/src/attrs/deprecated_cfg_attr.rs | 4 +- clippy_lints/src/attrs/mod.rs | 22 +++---- clippy_lints/src/attrs/repr_attributes.rs | 11 +--- clippy_lints/src/booleans.rs | 22 +++---- clippy_lints/src/casts/borrow_as_ptr.rs | 4 +- .../src/casts/cast_abs_to_unsigned.rs | 6 +- clippy_lints/src/casts/cast_lossless.rs | 6 +- .../src/casts/cast_slice_different_sizes.rs | 9 +-- .../src/casts/cast_slice_from_raw_parts.rs | 6 +- clippy_lints/src/casts/mod.rs | 24 +++---- clippy_lints/src/casts/ptr_as_ptr.rs | 7 +- clippy_lints/src/casts/ptr_cast_constness.rs | 4 +- clippy_lints/src/checked_conversions.rs | 8 +-- clippy_lints/src/derivable_impls.rs | 8 +-- clippy_lints/src/format_args.rs | 10 ++- clippy_lints/src/from_over_into.rs | 10 +-- clippy_lints/src/functions/mod.rs | 10 ++- clippy_lints/src/functions/result.rs | 10 +-- clippy_lints/src/if_then_some_else_none.rs | 10 +-- clippy_lints/src/implicit_saturating_sub.rs | 16 ++--- clippy_lints/src/incompatible_msrv.rs | 39 +++++------ clippy_lints/src/index_refutable_slice.rs | 6 +- clippy_lints/src/instant_subtraction.rs | 8 +-- clippy_lints/src/legacy_numeric_constants.rs | 12 ++-- clippy_lints/src/lifetimes.rs | 27 +++----- clippy_lints/src/lines_filter_map_ok.rs | 10 +-- clippy_lints/src/loops/explicit_iter_loop.rs | 13 ++-- clippy_lints/src/loops/manual_flatten.rs | 4 +- clippy_lints/src/loops/manual_slice_fill.rs | 8 +-- clippy_lints/src/loops/mod.rs | 12 ++-- clippy_lints/src/loops/same_item_push.rs | 6 +- clippy_lints/src/manual_bits.rs | 8 +-- clippy_lints/src/manual_clamp.rs | 14 ++-- clippy_lints/src/manual_div_ceil.rs | 11 +--- clippy_lints/src/manual_float_methods.rs | 8 +-- clippy_lints/src/manual_hash_one.rs | 8 +-- clippy_lints/src/manual_is_ascii_check.rs | 10 +-- clippy_lints/src/manual_let_else.rs | 2 +- clippy_lints/src/manual_main_separator_str.rs | 8 +-- clippy_lints/src/manual_non_exhaustive.rs | 6 +- clippy_lints/src/manual_option_as_slice.rs | 45 +++++++------ clippy_lints/src/manual_rem_euclid.rs | 10 +-- clippy_lints/src/manual_retain.rs | 26 ++++---- clippy_lints/src/manual_strip.rs | 9 +-- clippy_lints/src/matches/collapsible_match.rs | 8 +-- clippy_lints/src/matches/mod.rs | 28 ++++---- clippy_lints/src/matches/redundant_guards.rs | 6 +- clippy_lints/src/mem_replace.rs | 20 +++--- .../src/methods/cloned_instead_of_copied.rs | 6 +- clippy_lints/src/methods/err_expect.rs | 7 +- clippy_lints/src/methods/filter_map_next.rs | 4 +- clippy_lints/src/methods/io_other_error.rs | 6 +- .../src/methods/is_digit_ascii_radix.rs | 10 +-- clippy_lints/src/methods/iter_kv_map.rs | 4 +- .../src/methods/manual_c_str_literals.rs | 8 +-- clippy_lints/src/methods/manual_inspect.rs | 6 +- .../src/methods/manual_is_variant_and.rs | 4 +- clippy_lints/src/methods/manual_repeat_n.rs | 6 +- clippy_lints/src/methods/manual_try_fold.rs | 4 +- clippy_lints/src/methods/map_clone.rs | 6 +- clippy_lints/src/methods/map_unwrap_or.rs | 4 +- .../map_with_unused_argument_over_ranges.rs | 6 +- clippy_lints/src/methods/mod.rs | 64 +++++++++---------- .../src/methods/option_as_ref_deref.rs | 8 +-- .../src/methods/option_map_unwrap_or.rs | 8 +-- .../src/methods/path_ends_with_ext.rs | 4 +- clippy_lints/src/methods/str_splitn.rs | 4 +- .../src/methods/string_lit_chars_any.rs | 6 +- .../src/methods/unnecessary_map_or.rs | 6 +- .../src/methods/unnecessary_to_owned.rs | 6 +- .../methods/useless_nonzero_new_unchecked.rs | 6 +- clippy_lints/src/missing_const_for_fn.rs | 26 ++++---- .../src/missing_const_for_thread_local.rs | 16 ++--- .../src/needless_borrows_for_generic_args.rs | 10 ++- clippy_lints/src/non_std_lazy_statics.rs | 34 +++------- clippy_lints/src/operators/manual_midpoint.rs | 10 +-- clippy_lints/src/operators/mod.rs | 6 +- clippy_lints/src/question_mark.rs | 3 +- clippy_lints/src/ranges.rs | 7 +- clippy_lints/src/redundant_field_names.rs | 9 +-- .../src/redundant_static_lifetimes.rs | 8 +-- clippy_lints/src/repeat_vec_with_capacity.rs | 13 ++-- clippy_lints/src/std_instead_of_core.rs | 12 ++-- clippy_lints/src/string_patterns.rs | 12 ++-- clippy_lints/src/trait_bounds.rs | 8 +-- clippy_lints/src/transmute/mod.rs | 16 ++--- .../src/transmute/transmute_float_to_int.rs | 4 +- .../src/transmute/transmute_int_to_float.rs | 4 +- .../src/transmute/transmute_num_to_bytes.rs | 5 +- .../src/transmute/transmute_ptr_to_ptr.rs | 6 +- .../src/transmute/transmute_ptr_to_ref.rs | 6 +- clippy_lints/src/tuple_array_conversions.rs | 8 +-- clippy_lints/src/unnested_or_patterns.rs | 8 +-- clippy_lints/src/unused_trait_names.rs | 10 +-- clippy_lints/src/use_self.rs | 10 ++- .../utils/internal_lints/msrv_attr_impl.rs | 13 ++-- clippy_lints/src/vec.rs | 6 +- .../ui-internal/invalid_msrv_attr_impl.stderr | 2 +- .../ui/msrv_attributes_without_early_lints.rs | 2 + 102 files changed, 430 insertions(+), 640 deletions(-) diff --git a/clippy_lints/src/almost_complete_range.rs b/clippy_lints/src/almost_complete_range.rs index 0f7f779e8ea7..4f55968d5625 100644 --- a/clippy_lints/src/almost_complete_range.rs +++ b/clippy_lints/src/almost_complete_range.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::source::{trim_span, walk_span_to_context}; use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits}; use rustc_errors::Applicability; @@ -31,12 +31,12 @@ declare_clippy_lint! { impl_lint_pass!(AlmostCompleteRange => [ALMOST_COMPLETE_RANGE]); pub struct AlmostCompleteRange { - msrv: Msrv, + msrv: MsrvStack, } impl AlmostCompleteRange { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -96,7 +96,7 @@ impl EarlyLintPass for AlmostCompleteRange { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } fn is_incomplete_range(start: &Expr, end: &Expr) -> bool { diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index fbcd49f00184..9ae746c13b26 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -69,9 +69,7 @@ pub struct ApproxConstant { impl ApproxConstant { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -89,8 +87,6 @@ impl LateLintPass<'_> for ApproxConstant { _ => (), } } - - extract_msrv_attr!(LateContext); } impl ApproxConstant { @@ -98,7 +94,7 @@ impl ApproxConstant { let s = s.as_str(); if s.parse::().is_ok() { for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS { - if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) { + if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv)) { span_lint_and_help( cx, APPROX_CONSTANT, diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs index 348495f97a27..ab34af7c3174 100644 --- a/clippy_lints/src/assigning_clones.rs +++ b/clippy_lints/src/assigning_clones.rs @@ -59,9 +59,7 @@ pub struct AssigningClones { impl AssigningClones { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -90,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { sym::clone if is_diag_trait_item(cx, fn_id, sym::Clone) => CloneTrait::Clone, _ if fn_name.as_str() == "to_owned" && is_diag_trait_item(cx, fn_id, sym::ToOwned) - && self.msrv.meets(msrvs::CLONE_INTO) => + && self.msrv.meets(cx, msrvs::CLONE_INTO) => { CloneTrait::ToOwned }, @@ -143,8 +141,6 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { ); } } - - extract_msrv_attr!(LateContext); } /// Checks if the data being cloned borrows from the place that is being assigned to: diff --git a/clippy_lints/src/attrs/deprecated_cfg_attr.rs b/clippy_lints/src/attrs/deprecated_cfg_attr.rs index 3a462018e3e0..cd38aed26a3e 100644 --- a/clippy_lints/src/attrs/deprecated_cfg_attr.rs +++ b/clippy_lints/src/attrs/deprecated_cfg_attr.rs @@ -1,12 +1,12 @@ use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::AttrStyle; use rustc_errors::Applicability; use rustc_lint::EarlyContext; use rustc_span::sym; -pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msrv) { +pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) { // check cfg_attr if attr.has_name(sym::cfg_attr) && let Some(items) = attr.meta_item_list() diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index e0aab8c95a8e..2b59c218d57a 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -14,7 +14,7 @@ mod useless_attribute; mod utils; use clippy_config::Conf; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, Msrv, MsrvStack}; use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind}; use rustc_hir::{ImplItem, Item, TraitItem}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; @@ -459,9 +459,7 @@ impl_lint_pass!(Attributes => [ impl Attributes { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -471,7 +469,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { if is_relevant_item(cx, item) { inline_always::check(cx, item.span, item.ident.name, attrs); } - repr_attributes::check(cx, item.span, attrs, &self.msrv); + repr_attributes::check(cx, item.span, attrs, self.msrv); } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { @@ -485,18 +483,16 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())); } } - - extract_msrv_attr!(LateContext); } pub struct EarlyAttributes { - msrv: Msrv, + msrv: MsrvStack, } impl EarlyAttributes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -515,17 +511,17 @@ impl EarlyLintPass for EarlyAttributes { non_minimal_cfg::check(cx, attr); } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } pub struct PostExpansionEarlyAttributes { - msrv: Msrv, + msrv: MsrvStack, } impl PostExpansionEarlyAttributes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -589,5 +585,5 @@ impl EarlyLintPass for PostExpansionEarlyAttributes { duplicated_attributes::check(cx, &item.attrs); } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } diff --git a/clippy_lints/src/attrs/repr_attributes.rs b/clippy_lints/src/attrs/repr_attributes.rs index 3efb8bd3ff00..e5cfbaf952a7 100644 --- a/clippy_lints/src/attrs/repr_attributes.rs +++ b/clippy_lints/src/attrs/repr_attributes.rs @@ -4,17 +4,11 @@ use rustc_lint::LateContext; use rustc_span::Span; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs; +use clippy_utils::msrvs::{self, Msrv}; use super::REPR_PACKED_WITHOUT_ABI; -pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute], msrv: &msrvs::Msrv) { - if msrv.meets(msrvs::REPR_RUST) { - check_packed(cx, item_span, attrs); - } -} - -fn check_packed(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) { +pub(super) fn check(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute], msrv: Msrv) { if let Some(reprs) = find_attr!(attrs, AttributeKind::Repr(r) => r) { let packed_span = reprs .iter() @@ -25,6 +19,7 @@ fn check_packed(cx: &LateContext<'_>, item_span: Span, attrs: &[Attribute]) { && !reprs .iter() .any(|(x, _)| *x == ReprAttr::ReprC || *x == ReprAttr::ReprRust) + && msrv.meets(cx, msrvs::REPR_RUST) { span_lint_and_then( cx, diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index f57f56f3efdc..48b5d4da8886 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -85,9 +85,7 @@ pub struct NonminimalBool { impl NonminimalBool { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -103,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _: Span, _: LocalDefId, ) { - NonminimalBoolVisitor { cx, msrv: &self.msrv }.visit_body(body); + NonminimalBoolVisitor { cx, msrv: self.msrv }.visit_body(body); } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { @@ -120,8 +118,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool { _ => {}, } } - - extract_msrv_attr!(LateContext); } fn inverted_bin_op_eq_str(op: BinOpKind) -> Option<&'static str> { @@ -198,7 +194,7 @@ fn check_inverted_bool_in_condition( ); } -fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) { +fn check_simplify_not(cx: &LateContext<'_>, msrv: Msrv, expr: &Expr<'_>) { if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind && !expr.span.from_expansion() && !inner.span.from_expansion() @@ -234,7 +230,7 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) { struct NonminimalBoolVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, - msrv: &'a Msrv, + msrv: Msrv, } use quine_mc_cluskey::Bool; @@ -327,7 +323,7 @@ impl<'v> Hir2Qmm<'_, '_, 'v> { struct SuggestContext<'a, 'tcx, 'v> { terminals: &'v [&'v Expr<'v>], cx: &'a LateContext<'tcx>, - msrv: &'a Msrv, + msrv: Msrv, output: String, } @@ -398,7 +394,7 @@ impl SuggestContext<'_, '_, '_> { } } -fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Option { +fn simplify_not(cx: &LateContext<'_>, curr_msrv: Msrv, expr: &Expr<'_>) -> Option { match &expr.kind { ExprKind::Binary(binop, lhs, rhs) => { if !implements_ord(cx, lhs) { @@ -440,7 +436,9 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti .iter() .copied() .flat_map(|(msrv, a, b)| vec![(msrv, a, b), (msrv, b, a)]) - .find(|&(msrv, a, _)| msrv.is_none_or(|msrv| curr_msrv.meets(msrv)) && a == path.ident.name.as_str()) + .find(|&(msrv, a, _)| { + a == path.ident.name.as_str() && msrv.is_none_or(|msrv| curr_msrv.meets(cx, msrv)) + }) .and_then(|(_, _, neg_method)| { let negated_args = args .iter() @@ -469,7 +467,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti } } -fn suggest(cx: &LateContext<'_>, msrv: &Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { +fn suggest(cx: &LateContext<'_>, msrv: Msrv, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String { let mut suggest_context = SuggestContext { terminals, cx, diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs index 6057144bc6a4..d143629da3a0 100644 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ b/clippy_lints/src/casts/borrow_as_ptr.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'_>, cast_expr: &'tcx Expr<'_>, cast_to: &'tcx Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { if matches!(cast_to.kind, TyKind::Ptr(_)) && let ExprKind::AddrOf(BorrowKind::Ref, mutability, e) = cast_expr.kind @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>( return false; } - let (suggestion, span) = if msrv.meets(msrvs::RAW_REF_OP) { + let (suggestion, span) = if msrv.meets(cx, msrvs::RAW_REF_OP) { let operator_kind = match mutability { Mutability::Not => "const", Mutability::Mut => "mut", diff --git a/clippy_lints/src/casts/cast_abs_to_unsigned.rs b/clippy_lints/src/casts/cast_abs_to_unsigned.rs index ae433773193a..8b3529e84fc6 100644 --- a/clippy_lints/src/casts/cast_abs_to_unsigned.rs +++ b/clippy_lints/src/casts/cast_abs_to_unsigned.rs @@ -14,13 +14,13 @@ pub(super) fn check( cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::UNSIGNED_ABS) - && let ty::Int(from) = cast_from.kind() + if let ty::Int(from) = cast_from.kind() && let ty::Uint(to) = cast_to.kind() && let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind && method_path.ident.name.as_str() == "abs" + && msrv.meets(cx, msrvs::UNSIGNED_ABS) { let span = if from.bit_width() == to.bit_width() { expr.span diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index c326a0d935c7..3ae43732dc03 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -19,7 +19,7 @@ pub(super) fn check( cast_from: Ty<'_>, cast_to: Ty<'_>, cast_to_hir: &rustc_hir::Ty<'_>, - msrv: &Msrv, + msrv: Msrv, ) { if !should_lint(cx, cast_from, cast_to, msrv) { return; @@ -70,7 +70,7 @@ pub(super) fn check( ); } -fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool { +fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: Msrv) -> bool { // Do not suggest using From in consts/statics until it is valid to do so (see #2267). if is_in_const_context(cx) { return false; @@ -96,7 +96,7 @@ fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: & }; !is_isize_or_usize(cast_from) && from_nbits < to_nbits }, - (false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(msrvs::FROM_BOOL) => true, + (false, true) if matches!(cast_from.kind(), ty::Bool) && msrv.meets(cx, msrvs::FROM_BOOL) => true, (_, _) => { matches!(cast_from.kind(), ty::Float(FloatTy::F32)) && matches!(cast_to.kind(), ty::Float(FloatTy::F64)) }, diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index 030c2d322db6..c48f253606dc 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -9,12 +9,7 @@ use rustc_middle::ty::{self, Ty, TypeAndMut}; use super::CAST_SLICE_DIFFERENT_SIZES; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv) { - // suggestion is invalid if `ptr::slice_from_raw_parts` does not exist - if !msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) { - return; - } - +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Msrv) { // if this cast is the child of another cast expression then don't emit something for it, the full // chain will be analyzed if is_child_of_cast(cx, expr) { @@ -30,7 +25,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv if let (Ok(from_layout), Ok(to_layout)) = (cx.layout_of(start_ty.ty), cx.layout_of(end_ty.ty)) { let from_size = from_layout.size.bytes(); let to_size = to_layout.size.bytes(); - if from_size != to_size && from_size != 0 && to_size != 0 { + if from_size != to_size && from_size != 0 && to_size != 0 && msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) { span_lint_and_then( cx, CAST_SLICE_DIFFERENT_SIZES, diff --git a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs index c3bc5c0c9f2a..46b0c88d3fed 100644 --- a/clippy_lints/src/casts/cast_slice_from_raw_parts.rs +++ b/clippy_lints/src/casts/cast_slice_from_raw_parts.rs @@ -23,9 +23,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option { } } -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) { - if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS) - && let ty::RawPtr(ptrty, _) = cast_to.kind() +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: Msrv) { + if let ty::RawPtr(ptrty, _) = cast_to.kind() && let ty::Slice(_) = ptrty.kind() && let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind && let ExprKind::Path(ref qpath) = fun.kind @@ -33,6 +32,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, && let Some(rpk) = raw_parts_kind(cx, fun_def_id) && let ctxt = expr.span.ctxt() && cast_expr.span.ctxt() == ctxt + && msrv.meets(cx, msrvs::PTR_SLICE_RAW_PARTS) { let func = match rpk { RawPartsKind::Immutable => "from_raw_parts", diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index 3701f9eb5e86..dc2a1fa85bf5 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -765,9 +765,7 @@ pub struct Casts { impl Casts { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -817,8 +815,8 @@ impl<'tcx> LateLintPass<'tcx> for Casts { if !expr.span.from_expansion() && unnecessary_cast::check(cx, expr, cast_from_expr, cast_from, cast_to) { return; } - cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, &self.msrv); - ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, &self.msrv); + cast_slice_from_raw_parts::check(cx, expr, cast_from_expr, cast_to, self.msrv); + ptr_cast_constness::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv); as_ptr_cast_mut::check(cx, expr, cast_from_expr, cast_to); fn_to_numeric_cast_any::check(cx, expr, cast_from_expr, cast_from, cast_to); fn_to_numeric_cast::check(cx, expr, cast_from_expr, cast_from, cast_to); @@ -831,29 +829,27 @@ impl<'tcx> LateLintPass<'tcx> for Casts { cast_possible_wrap::check(cx, expr, cast_from, cast_to); cast_precision_loss::check(cx, expr, cast_from, cast_to); cast_sign_loss::check(cx, expr, cast_from_expr, cast_from, cast_to); - cast_abs_to_unsigned::check(cx, expr, cast_from_expr, cast_from, cast_to, &self.msrv); + cast_abs_to_unsigned::check(cx, expr, cast_from_expr, cast_from, cast_to, self.msrv); cast_nan_to_int::check(cx, expr, cast_from_expr, cast_from, cast_to); } - cast_lossless::check(cx, expr, cast_from_expr, cast_from, cast_to, cast_to_hir, &self.msrv); + cast_lossless::check(cx, expr, cast_from_expr, cast_from, cast_to, cast_to_hir, self.msrv); cast_enum_constructor::check(cx, expr, cast_from_expr, cast_from); } as_underscore::check(cx, expr, cast_to_hir); as_pointer_underscore::check(cx, cast_to, cast_to_hir); - let was_borrow_as_ptr_emitted = self.msrv.meets(msrvs::BORROW_AS_PTR) - && borrow_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir, &self.msrv); - if self.msrv.meets(msrvs::PTR_FROM_REF) && !was_borrow_as_ptr_emitted { + let was_borrow_as_ptr_emitted = self.msrv.meets(cx, msrvs::BORROW_AS_PTR) + && borrow_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir, self.msrv); + if !was_borrow_as_ptr_emitted && self.msrv.meets(cx, msrvs::PTR_FROM_REF) { ref_as_ptr::check(cx, expr, cast_from_expr, cast_to_hir); } } cast_ptr_alignment::check(cx, expr); char_lit_as_u8::check(cx, expr); - ptr_as_ptr::check(cx, expr, &self.msrv); - cast_slice_different_sizes::check(cx, expr, &self.msrv); + ptr_as_ptr::check(cx, expr, self.msrv); + cast_slice_different_sizes::check(cx, expr, self.msrv); ptr_cast_constness::check_null_ptr_cast_method(cx, expr); } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index bdc389d39dd3..d57e391b55d5 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -26,11 +26,7 @@ impl OmitFollowedCastReason<'_> { } } -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { - if !msrv.meets(msrvs::POINTER_CAST) { - return; - } - +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) { 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(_, from_mutbl) = cast_from.kind() @@ -40,6 +36,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { // The `U` in `pointer::cast` have to be `Sized` // as explained here: https://github.com/rust-lang/rust/issues/60602. && to_pointee_ty.is_sized(cx.tcx, cx.typing_env()) + && msrv.meets(cx, msrvs::POINTER_CAST) { let mut app = Applicability::MachineApplicable; let turbofish = match &cast_to_hir_ty.kind { diff --git a/clippy_lints/src/casts/ptr_cast_constness.rs b/clippy_lints/src/casts/ptr_cast_constness.rs index 945c05ee9436..cad9c1df273f 100644 --- a/clippy_lints/src/casts/ptr_cast_constness.rs +++ b/clippy_lints/src/casts/ptr_cast_constness.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( cast_expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { if let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind() && let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind() @@ -52,7 +52,7 @@ pub(super) fn check<'tcx>( return; } - if msrv.meets(msrvs::POINTER_CAST_CONSTNESS) { + if msrv.meets(cx, msrvs::POINTER_CAST_CONSTNESS) { let sugg = Sugg::hir(cx, cast_expr, "_"); let constness = match *to_mutbl { Mutability::Not => "const", diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 9516af7334d7..b36c8662289c 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -39,9 +39,7 @@ pub struct CheckedConversions { impl CheckedConversions { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -65,7 +63,6 @@ impl LateLintPass<'_> for CheckedConversions { } && !item.span.in_external_macro(cx.sess().source_map()) && !is_in_const_context(cx) - && self.msrv.meets(msrvs::TRY_FROM) && let Some(cv) = match op2 { // todo: check for case signed -> larger unsigned == only x >= 0 None => check_upper_bound(lt1, gt1).filter(|cv| cv.cvt == ConversionType::FromUnsigned), @@ -79,6 +76,7 @@ impl LateLintPass<'_> for CheckedConversions { }, } && let Some(to_type) = cv.to_type + && self.msrv.meets(cx, msrvs::TRY_FROM) { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, cv.expr_to_cast.span, "_", &mut applicability); @@ -93,8 +91,6 @@ impl LateLintPass<'_> for CheckedConversions { ); } } - - extract_msrv_attr!(LateContext); } /// Contains the result of a tried conversion check diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index bb445e0155f6..66a3e5e3d3c7 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -62,9 +62,7 @@ pub struct DerivableImpls { impl DerivableImpls { pub fn new(conf: &'static Conf) -> Self { - DerivableImpls { - msrv: conf.msrv.clone(), - } + DerivableImpls { msrv: conf.msrv } } } @@ -205,11 +203,9 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { { if adt_def.is_struct() { check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b)); - } else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) { + } else if adt_def.is_enum() && self.msrv.meets(cx, msrvs::DEFAULT_ENUM_ATTRIBUTE) { check_enum(cx, item, func_expr, adt_def); } } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 1ba355938b68..fc5f76179f90 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -215,7 +215,7 @@ impl<'tcx> FormatArgs<'tcx> { let ty_msrv_map = make_ty_msrv_map(tcx); Self { format_args, - msrv: conf.msrv.clone(), + msrv: conf.msrv, ignore_mixed: conf.allow_mixed_uninlined_format_args, ty_msrv_map, } @@ -240,13 +240,11 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs<'tcx> { linter.check_templates(); - if self.msrv.meets(msrvs::FORMAT_ARGS_CAPTURE) { + if self.msrv.meets(cx, msrvs::FORMAT_ARGS_CAPTURE) { linter.check_uninlined_args(); } } } - - extract_msrv_attr!(LateContext); } struct FormatArgsExpr<'a, 'tcx> { @@ -542,7 +540,7 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> { let ty = ty.peel_refs(); if let Some(msrv) = self.ty_msrv_map.get(&ty) - && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) + && msrv.is_none_or(|msrv| self.msrv.meets(self.cx, msrv)) { return true; } @@ -553,7 +551,7 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> { && implements_trait(self.cx, ty, deref_trait_id, &[]) && let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, "Target") && let Some(msrv) = self.ty_msrv_map.get(&target_ty) - && msrv.is_none_or(|msrv| self.msrv.meets(msrv)) + && msrv.is_none_or(|msrv| self.msrv.meets(self.cx, msrv)) { return true; } diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 41bf6e81916a..6da5567d9c70 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -58,9 +58,7 @@ pub struct FromOverInto { impl FromOverInto { pub fn new(conf: &'static Conf) -> Self { - FromOverInto { - msrv: conf.msrv.clone(), - } + FromOverInto { msrv: conf.msrv } } } @@ -77,12 +75,12 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && self.msrv.meets(msrvs::RE_REBALANCING_COHERENCE) && span_is_local(item.span) && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) - .map(ty::EarlyBinder::instantiate_identity) + .map(ty::EarlyBinder::instantiate_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::Opaque, _)) + && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) { span_lint_and_then( cx, @@ -114,8 +112,6 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { ); } } - - extract_msrv_attr!(LateContext); } /// Finds the occurrences of `Self` and `self` diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 243eb5cbfd40..5f3fc5100e75 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -471,7 +471,7 @@ impl Functions { .iter() .flat_map(|p| def_path_def_ids(tcx, &p.split("::").collect::>())) .collect(), - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -521,12 +521,12 @@ impl<'tcx> LateLintPass<'tcx> for Functions { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { must_use::check_item(cx, item); - result::check_item(cx, item, self.large_error_threshold, &self.msrv); + result::check_item(cx, item, self.large_error_threshold, self.msrv); } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { must_use::check_impl_item(cx, item); - result::check_impl_item(cx, item, self.large_error_threshold, &self.msrv); + result::check_impl_item(cx, item, self.large_error_threshold, self.msrv); impl_trait_in_params::check_impl_item(cx, item); renamed_function_params::check_impl_item(cx, item, &self.trait_ids); } @@ -535,10 +535,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions { too_many_arguments::check_trait_item(cx, item, self.too_many_arguments_threshold); not_unsafe_ptr_arg_deref::check_trait_item(cx, item); must_use::check_trait_item(cx, item); - result::check_trait_item(cx, item, self.large_error_threshold, &self.msrv); + result::check_trait_item(cx, item, self.large_error_threshold, self.msrv); impl_trait_in_params::check_trait_item(cx, item, self.avoid_breaking_exported_api); ref_option::check_trait_item(cx, item, self.avoid_breaking_exported_api); } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 74d365a72556..cade56f58226 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -34,7 +34,7 @@ fn result_err_ty<'tcx>( } } -pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64, msrv: &Msrv) { +pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64, msrv: Msrv) { if let hir::ItemKind::Fn { ref sig, .. } = item.kind && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) { @@ -50,7 +50,7 @@ pub(super) fn check_impl_item<'tcx>( cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64, - msrv: &Msrv, + msrv: Msrv, ) { // Don't lint if method is a trait's implementation, we can't do anything about those if let hir::ImplItemKind::Fn(ref sig, _) = item.kind @@ -69,7 +69,7 @@ pub(super) fn check_trait_item<'tcx>( cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64, - msrv: &Msrv, + msrv: Msrv, ) { if let hir::TraitItemKind::Fn(ref sig, _) = item.kind { let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); @@ -82,8 +82,8 @@ pub(super) fn check_trait_item<'tcx>( } } -fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: Span, msrv: &Msrv) { - if err_ty.is_unit() && (!is_no_std_crate(cx) || msrv.meets(msrvs::ERROR_IN_CORE)) { +fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: Span, msrv: Msrv) { + if err_ty.is_unit() && (!is_no_std_crate(cx) || msrv.meets(cx, msrvs::ERROR_IN_CORE)) { span_lint_and_help( cx, RESULT_UNIT_ERR, diff --git a/clippy_lints/src/if_then_some_else_none.rs b/clippy_lints/src/if_then_some_else_none.rs index 28e6344186fa..fbbd33efd02d 100644 --- a/clippy_lints/src/if_then_some_else_none.rs +++ b/clippy_lints/src/if_then_some_else_none.rs @@ -54,9 +54,7 @@ pub struct IfThenSomeElseNone { impl IfThenSomeElseNone { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -79,10 +77,10 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { && !is_else_clause(cx.tcx, expr) && !is_in_const_context(cx) && !expr.span.in_external_macro(cx.sess().source_map()) - && self.msrv.meets(msrvs::BOOL_THEN) + && self.msrv.meets(cx, msrvs::BOOL_THEN) && !contains_return(then_block.stmts) { - let method_name = if switch_to_eager_eval(cx, expr) && self.msrv.meets(msrvs::BOOL_THEN_SOME) { + let method_name = if switch_to_eager_eval(cx, expr) && self.msrv.meets(cx, msrvs::BOOL_THEN_SOME) { "then_some" } else { "then" @@ -120,6 +118,4 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 152d506a7c00..f2d16ff2e564 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -83,9 +83,7 @@ impl_lint_pass!(ImplicitSaturatingSub => [IMPLICIT_SATURATING_SUB, INVERTED_SATU impl ImplicitSaturatingSub { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -108,12 +106,10 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { && let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind { check_manual_check( - cx, expr, cond_op, cond_left, cond_right, if_block, else_block, &self.msrv, + cx, expr, cond_op, cond_left, cond_right, if_block, else_block, self.msrv, ); } } - - extract_msrv_attr!(LateContext); } #[allow(clippy::too_many_arguments)] @@ -125,7 +121,7 @@ fn check_manual_check<'tcx>( right_hand: &Expr<'tcx>, if_block: &Expr<'tcx>, else_block: &Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { let ty = cx.typeck_results().expr_ty(left_hand); if ty.is_numeric() && !ty.is_signed() { @@ -178,7 +174,7 @@ fn check_gt( little_var: &Expr<'_>, if_block: &Expr<'_>, else_block: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, is_composited: bool, ) { if let Some(big_var) = Var::new(big_var) @@ -221,7 +217,7 @@ fn check_subtraction( little_var: Var, if_block: &Expr<'_>, else_block: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, is_composited: bool, ) { let if_block = peel_blocks(if_block); @@ -258,7 +254,7 @@ fn check_subtraction( // if `snippet_opt` fails, it won't try the next conditions. if let Some(big_var_snippet) = snippet_opt(cx, big_var.span) && let Some(little_var_snippet) = snippet_opt(cx, little_var.span) - && (!is_in_const_context(cx) || msrv.meets(msrvs::SATURATING_SUB_CONST)) + && (!is_in_const_context(cx) || msrv.meets(cx, msrvs::SATURATING_SUB_CONST)) { let sugg = format!( "{}{big_var_snippet}.saturating_sub({little_var_snippet}){}", diff --git a/clippy_lints/src/incompatible_msrv.rs b/clippy_lints/src/incompatible_msrv.rs index 26df41e42a60..12dfb14c454d 100644 --- a/clippy_lints/src/incompatible_msrv.rs +++ b/clippy_lints/src/incompatible_msrv.rs @@ -50,7 +50,7 @@ impl_lint_pass!(IncompatibleMsrv => [INCOMPATIBLE_MSRV]); impl IncompatibleMsrv { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, is_above_msrv: FxHashMap::default(), check_in_tests: conf.check_incompatible_msrv_in_tests, } @@ -88,39 +88,30 @@ impl IncompatibleMsrv { // We don't check local items since their MSRV is supposed to always be valid. return; } - let version = self.get_def_id_version(cx.tcx, def_id); - if self.msrv.meets(version) || (!self.check_in_tests && is_in_test(cx.tcx, node)) { - return; - } if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind { // Desugared expressions get to cheat and stability is ignored. // Intentionally not using `.from_expansion()`, since we do still care about macro expansions return; } - self.emit_lint_for(cx, span, version); - } - - fn emit_lint_for(&self, cx: &LateContext<'_>, span: Span, version: RustcVersion) { - span_lint( - cx, - INCOMPATIBLE_MSRV, - span, - format!( - "current MSRV (Minimum Supported Rust Version) is `{}` but this item is stable since `{version}`", - self.msrv - ), - ); + if (self.check_in_tests || !is_in_test(cx.tcx, node)) + && let Some(current) = self.msrv.current(cx) + && let version = self.get_def_id_version(cx.tcx, def_id) + && version > current + { + span_lint( + cx, + INCOMPATIBLE_MSRV, + span, + format!( + "current MSRV (Minimum Supported Rust Version) is `{current}` but this item is stable since `{version}`" + ), + ); + } } } impl<'tcx> LateLintPass<'tcx> for IncompatibleMsrv { - extract_msrv_attr!(LateContext); - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if self.msrv.current().is_none() { - // If there is no MSRV, then no need to check anything... - return; - } match expr.kind { ExprKind::MethodCall(_, _, _, span) => { if let Some(method_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index deac51ab4c49..d53e139de014 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -62,7 +62,7 @@ impl IndexRefutableSlice { pub fn new(conf: &'static Conf) -> Self { Self { max_suggested_slice: conf.max_suggested_slice_pattern_length, - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -74,19 +74,17 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { if let Some(IfLet { let_pat, if_then, .. }) = IfLet::hir(cx, expr) && (!expr.span.from_expansion() || is_expn_of(expr.span, "if_chain").is_some()) && !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id) - && self.msrv.meets(msrvs::SLICE_PATTERNS) && let found_slices = find_slice_values(cx, let_pat) && !found_slices.is_empty() && let filtered_slices = filter_lintable_slices(cx, found_slices, self.max_suggested_slice, if_then) && !filtered_slices.is_empty() + && self.msrv.meets(cx, msrvs::SLICE_PATTERNS) { for slice in filtered_slices.values() { lint_slice(cx, slice); } } } - - extract_msrv_attr!(LateContext); } fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { diff --git a/clippy_lints/src/instant_subtraction.rs b/clippy_lints/src/instant_subtraction.rs index f4e41dc826b0..4ae1119ab3a2 100644 --- a/clippy_lints/src/instant_subtraction.rs +++ b/clippy_lints/src/instant_subtraction.rs @@ -70,9 +70,7 @@ pub struct InstantSubtraction { impl InstantSubtraction { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -99,14 +97,12 @@ impl LateLintPass<'_> for InstantSubtraction { print_manual_instant_elapsed_sugg(cx, expr, sugg); } else if ty::is_type_diagnostic_item(cx, rhs_ty, sym::Duration) && !expr.span.from_expansion() - && self.msrv.meets(msrvs::TRY_FROM) + && self.msrv.meets(cx, msrvs::TRY_FROM) { print_unchecked_duration_subtraction_sugg(cx, lhs, rhs, expr); } } } - - extract_msrv_attr!(LateContext); } fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool { diff --git a/clippy_lints/src/legacy_numeric_constants.rs b/clippy_lints/src/legacy_numeric_constants.rs index 6f2ce04e8f8e..3939318bee6e 100644 --- a/clippy_lints/src/legacy_numeric_constants.rs +++ b/clippy_lints/src/legacy_numeric_constants.rs @@ -39,9 +39,7 @@ pub struct LegacyNumericConstants { impl LegacyNumericConstants { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -52,9 +50,9 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { // Integer modules are "TBD" deprecated, and the contents are too, // so lint on the `use` statement directly. if let ItemKind::Use(path, kind @ (UseKind::Single | UseKind::Glob)) = item.kind - && self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) && !item.span.in_external_macro(cx.sess().source_map()) && let Some(def_id) = path.res[0].opt_def_id() + && self.msrv.meets(cx, msrvs::NUMERIC_ASSOCIATED_CONSTANTS) { let module = if is_integer_module(cx, def_id) { true @@ -137,8 +135,8 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { return; }; - if self.msrv.meets(msrvs::NUMERIC_ASSOCIATED_CONSTANTS) - && !expr.span.in_external_macro(cx.sess().source_map()) + if !expr.span.in_external_macro(cx.sess().source_map()) + && self.msrv.meets(cx, msrvs::NUMERIC_ASSOCIATED_CONSTANTS) && !is_from_proc_macro(cx, expr) { span_lint_hir_and_then(cx, LEGACY_NUMERIC_CONSTANTS, expr.hir_id, span, msg, |diag| { @@ -151,8 +149,6 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants { }); } } - - extract_msrv_attr!(LateContext); } fn is_integer_module(cx: &LateContext<'_>, did: DefId) -> bool { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 7589ab1229af..3dd2de1fafc7 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -130,9 +130,7 @@ pub struct Lifetimes { impl Lifetimes { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -151,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { .. } = item.kind { - check_fn_inner(cx, sig, Some(id), None, generics, item.span, true, &self.msrv); + check_fn_inner(cx, sig, Some(id), None, generics, item.span, true, self.msrv); } else if let ItemKind::Impl(impl_) = item.kind { if !item.span.from_expansion() { report_extra_impl_lifetimes(cx, impl_); @@ -170,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { item.generics, item.span, report_extra_lifetimes, - &self.msrv, + self.msrv, ); } } @@ -181,11 +179,9 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { TraitFn::Required(sig) => (None, Some(sig)), TraitFn::Provided(id) => (Some(id), None), }; - check_fn_inner(cx, sig, body, trait_sig, item.generics, item.span, true, &self.msrv); + check_fn_inner(cx, sig, body, trait_sig, item.generics, item.span, true, self.msrv); } } - - extract_msrv_attr!(LateContext); } #[allow(clippy::too_many_arguments)] @@ -197,7 +193,7 @@ fn check_fn_inner<'tcx>( generics: &'tcx Generics<'_>, span: Span, report_extra_lifetimes: bool, - msrv: &Msrv, + msrv: Msrv, ) { if span.in_external_macro(cx.sess().source_map()) || has_where_lifetimes(cx, generics) { return; @@ -270,7 +266,7 @@ fn could_use_elision<'tcx>( body: Option, trait_sig: Option<&[Ident]>, named_generics: &'tcx [GenericParam<'_>], - msrv: &Msrv, + msrv: Msrv, ) -> Option<(Vec, Vec)> { // There are two scenarios where elision works: // * no output references, all input references have different LT @@ -388,17 +384,12 @@ fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxIndexSet( - cx: &LateContext<'tcx>, - func: &FnDecl<'tcx>, - ident: Option, - msrv: &Msrv, -) -> bool { - if !msrv.meets(msrvs::EXPLICIT_SELF_TYPE_ELISION) - && let Some(ident) = ident +fn non_elidable_self_type<'tcx>(cx: &LateContext<'tcx>, func: &FnDecl<'tcx>, ident: Option, msrv: Msrv) -> bool { + if let Some(ident) = ident && ident.name == kw::SelfLower && !func.implicit_self.has_implicit_self() && let Some(self_ty) = func.inputs.first() + && !msrv.meets(cx, msrvs::EXPLICIT_SELF_TYPE_ELISION) { let mut visitor = RefVisitor::new(cx); visitor.visit_ty_unambig(self_ty); diff --git a/clippy_lints/src/lines_filter_map_ok.rs b/clippy_lints/src/lines_filter_map_ok.rs index 08548f564009..d8af44233d3e 100644 --- a/clippy_lints/src/lines_filter_map_ok.rs +++ b/clippy_lints/src/lines_filter_map_ok.rs @@ -15,9 +15,7 @@ pub struct LinesFilterMapOk { impl LinesFilterMapOk { pub fn new(conf: &Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -74,13 +72,13 @@ impl_lint_pass!(LinesFilterMapOk => [LINES_FILTER_MAP_OK]); impl LateLintPass<'_> for LinesFilterMapOk { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if self.msrv.meets(msrvs::MAP_WHILE) - && let ExprKind::MethodCall(fm_method, fm_receiver, fm_args, fm_span) = expr.kind + if let ExprKind::MethodCall(fm_method, fm_receiver, fm_args, fm_span) = expr.kind && is_trait_method(cx, expr, sym::Iterator) && let fm_method_str = fm_method.ident.as_str() && matches!(fm_method_str, "filter_map" | "flat_map" | "flatten") && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty_adjusted(fm_receiver), sym::IoLines) && should_lint(cx, fm_args, fm_method_str) + && self.msrv.meets(cx, msrvs::MAP_WHILE) { span_lint_and_then( cx, @@ -101,8 +99,6 @@ impl LateLintPass<'_> for LinesFilterMapOk { ); } } - - extract_msrv_attr!(LateContext); } fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> bool { diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index 06cf901bfb23..412c78cc8041 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -17,7 +17,7 @@ pub(super) fn check( cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, enforce_iter_loop_reborrow: bool, ) { let Some((adjust, ty)) = is_ref_iterable(cx, self_arg, call_expr, enforce_iter_loop_reborrow, msrv) else { @@ -26,10 +26,11 @@ pub(super) fn check( if let ty::Array(_, count) = *ty.peel_refs().kind() { if !ty.is_ref() { - if !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) { + if !msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) { return; } - } else if count.try_to_target_usize(cx.tcx).is_none_or(|x| x > 32) && !msrv.meets(msrvs::ARRAY_IMPL_ANY_LEN) { + } else if count.try_to_target_usize(cx.tcx).is_none_or(|x| x > 32) && !msrv.meets(cx, msrvs::ARRAY_IMPL_ANY_LEN) + { return; } } @@ -106,7 +107,7 @@ fn is_ref_iterable<'tcx>( self_arg: &Expr<'_>, call_expr: &Expr<'_>, enforce_iter_loop_reborrow: bool, - msrv: &Msrv, + msrv: Msrv, ) -> Option<(AdjustKind, Ty<'tcx>)> { let typeck = cx.typeck_results(); if let Some(trait_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator) @@ -126,8 +127,8 @@ fn is_ref_iterable<'tcx>( let self_ty = typeck.expr_ty(self_arg); let self_is_copy = is_copy(cx, self_ty); - if !msrv.meets(msrvs::BOX_INTO_ITER) - && is_type_lang_item(cx, self_ty.peel_refs(), rustc_hir::LangItem::OwnedBox) + if is_type_lang_item(cx, self_ty.peel_refs(), rustc_hir::LangItem::OwnedBox) + && !msrv.meets(cx, msrvs::BOX_INTO_ITER) { return None; } diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index ffeb7e889c2e..9b6f97b9a2eb 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -19,7 +19,7 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, span: Span, - msrv: &Msrv, + msrv: Msrv, ) { let inner_expr = peel_blocks_with_stmt(body); if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else: None, .. }) @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>( && (some_ctor || ok_ctor) // Ensure expr in `if let` is not used afterwards && !is_local_used(cx, if_then, pat_hir_id) - && msrv.meets(msrvs::ITER_FLATTEN) + && msrv.meets(cx, msrvs::ITER_FLATTEN) { let if_let_type = if some_ctor { "Some" } else { "Ok" }; // Prepare the error message diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs index a97641788621..343f7c5d2d12 100644 --- a/clippy_lints/src/loops/manual_slice_fill.rs +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -24,12 +24,8 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, expr: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if !msrv.meets(msrvs::SLICE_FILL) { - return; - } - // `for _ in 0..slice.len() { slice[_] = value; }` if let Some(higher::Range { start: Some(start), @@ -61,6 +57,7 @@ pub(super) fn check<'tcx>( && let ExprKind::Path(Resolved(_, idx_path)) = idx.kind && let Res::Local(idx_hir) = idx_path.res && !is_local_used(cx, assignval, idx_hir) + && msrv.meets(cx, msrvs::SLICE_FILL) { sugg(cx, body, expr, slice.span, assignval.span); } @@ -81,6 +78,7 @@ pub(super) fn check<'tcx>( // The `fill` method cannot be used if the slice's element type does not implement the `Clone` trait. && let Some(clone_trait) = cx.tcx.lang_items().clone_trait() && implements_trait(cx, cx.typeck_results().expr_ty(recv), clone_trait, &[]) + && msrv.meets(cx, msrvs::SLICE_FILL) { sugg(cx, body, expr, recv_path.span, assignval.span); } diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index ffe7566f5fb6..ed725a039891 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -747,7 +747,7 @@ pub struct Loops { impl Loops { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, enforce_iter_loop_reborrow: conf.enforce_iter_loop_reborrow, } } @@ -832,8 +832,6 @@ impl<'tcx> LateLintPass<'tcx> for Loops { manual_while_let_some::check(cx, condition, body, span); } } - - extract_msrv_attr!(LateContext); } impl Loops { @@ -850,7 +848,7 @@ impl Loops { ) { let is_manual_memcpy_triggered = manual_memcpy::check(cx, pat, arg, body, expr); if !is_manual_memcpy_triggered { - manual_slice_fill::check(cx, pat, arg, body, expr, &self.msrv); + manual_slice_fill::check(cx, pat, arg, body, expr, self.msrv); needless_range_loop::check(cx, pat, arg, body, expr); explicit_counter_loop::check(cx, pat, arg, body, expr, label); } @@ -858,8 +856,8 @@ impl Loops { for_kv_map::check(cx, pat, arg, body); mut_range_bound::check(cx, arg, body); single_element_loop::check(cx, pat, arg, body, expr); - same_item_push::check(cx, pat, arg, body, expr, &self.msrv); - manual_flatten::check(cx, pat, arg, body, span, &self.msrv); + same_item_push::check(cx, pat, arg, body, expr, self.msrv); + manual_flatten::check(cx, pat, arg, body, span, self.msrv); manual_find::check(cx, pat, arg, body, span, expr); unused_enumerate_index::check(cx, pat, arg, body); } @@ -868,7 +866,7 @@ impl Loops { if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind { match method.ident.as_str() { "iter" | "iter_mut" => { - explicit_iter_loop::check(cx, self_arg, arg, &self.msrv, self.enforce_iter_loop_reborrow); + explicit_iter_loop::check(cx, self_arg, arg, self.msrv, self.enforce_iter_loop_reborrow); }, "into_iter" => { explicit_into_iter_loop::check(cx, self_arg, arg); diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index c27e930c99a5..661b4b590d8f 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -20,14 +20,14 @@ pub(super) fn check<'tcx>( _: &'tcx Expr<'_>, body: &'tcx Expr<'_>, _: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>, ctxt: SyntaxContext, msrv: &Msrv) { + fn emit_lint(cx: &LateContext<'_>, vec: &Expr<'_>, pushed_item: &Expr<'_>, ctxt: SyntaxContext, msrv: Msrv) { let mut app = Applicability::Unspecified; let vec_str = snippet_with_context(cx, vec.span, ctxt, "", &mut app).0; let item_str = snippet_with_context(cx, pushed_item.span, ctxt, "", &mut app).0; - let secondary_help = if msrv.meets(msrvs::REPEAT_N) + let secondary_help = if msrv.meets(cx, msrvs::REPEAT_N) && let Some(std_or_core) = std_or_core(cx) { format!("or `{vec_str}.extend({std_or_core}::iter::repeat_n({item_str}, SIZE))`") diff --git a/clippy_lints/src/manual_bits.rs b/clippy_lints/src/manual_bits.rs index 4a34a334cf2b..39c4857b3e87 100644 --- a/clippy_lints/src/manual_bits.rs +++ b/clippy_lints/src/manual_bits.rs @@ -40,9 +40,7 @@ pub struct ManualBits { impl ManualBits { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -53,7 +51,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { if let ExprKind::Binary(bin_op, left_expr, right_expr) = expr.kind && let BinOpKind::Mul = &bin_op.node && !expr.span.from_expansion() - && self.msrv.meets(msrvs::INTEGER_BITS) && let ctxt = expr.span.ctxt() && left_expr.span.ctxt() == ctxt && right_expr.span.ctxt() == ctxt @@ -61,6 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { && matches!(resolved_ty.kind(), ty::Int(_) | ty::Uint(_)) && let ExprKind::Lit(lit) = &other_expr.kind && let LitKind::Int(Pu128(8), _) = lit.node + && self.msrv.meets(cx, msrvs::INTEGER_BITS) { let mut app = Applicability::MachineApplicable; let ty_snip = snippet_with_context(cx, real_ty_span, ctxt, "..", &mut app).0; @@ -77,8 +75,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits { ); } } - - extract_msrv_attr!(LateContext); } fn get_one_size_of_ty<'tcx>( diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 484a7ba256bd..50c8331eebab 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -99,9 +99,7 @@ pub struct ManualClamp { impl ManualClamp { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -144,30 +142,28 @@ struct InputMinMax<'tcx> { impl<'tcx> LateLintPass<'tcx> for ManualClamp { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if !self.msrv.meets(msrvs::CLAMP) { - return; - } if !expr.span.from_expansion() && !is_in_const_context(cx) { let suggestion = is_if_elseif_else_pattern(cx, expr) .or_else(|| is_max_min_pattern(cx, expr)) .or_else(|| is_call_max_min_pattern(cx, expr)) .or_else(|| is_match_pattern(cx, expr)) .or_else(|| is_if_elseif_pattern(cx, expr)); - if let Some(suggestion) = suggestion { + if let Some(suggestion) = suggestion + && self.msrv.meets(cx, msrvs::CLAMP) + { maybe_emit_suggestion(cx, &suggestion); } } } fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) { - if !self.msrv.meets(msrvs::CLAMP) || is_in_const_context(cx) { + if is_in_const_context(cx) || !self.msrv.meets(cx, msrvs::CLAMP) { return; } for suggestion in is_two_if_pattern(cx, block) { maybe_emit_suggestion(cx, &suggestion); } } - extract_msrv_attr!(LateContext); } fn maybe_emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'tcx>) { diff --git a/clippy_lints/src/manual_div_ceil.rs b/clippy_lints/src/manual_div_ceil.rs index 04357cdd8f66..9c1419175d55 100644 --- a/clippy_lints/src/manual_div_ceil.rs +++ b/clippy_lints/src/manual_div_ceil.rs @@ -49,9 +49,7 @@ pub struct ManualDivCeil { impl ManualDivCeil { #[must_use] pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -59,10 +57,6 @@ impl_lint_pass!(ManualDivCeil => [MANUAL_DIV_CEIL]); impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) { - if !self.msrv.meets(msrvs::MANUAL_DIV_CEIL) { - return; - } - let mut applicability = Applicability::MachineApplicable; if let ExprKind::Binary(div_op, div_lhs, div_rhs) = expr.kind @@ -70,6 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { && check_int_ty_and_feature(cx, div_lhs) && check_int_ty_and_feature(cx, div_rhs) && let ExprKind::Binary(inner_op, inner_lhs, inner_rhs) = div_lhs.kind + && self.msrv.meets(cx, msrvs::MANUAL_DIV_CEIL) { // (x + (y - 1)) / y if let ExprKind::Binary(sub_op, sub_lhs, sub_rhs) = inner_rhs.kind @@ -122,8 +117,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualDivCeil { } } } - - extract_msrv_attr!(LateContext); } /// Checks if two expressions represent non-zero integer literals such that `small_expr + 1 == diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index 2a5aa12d126c..bd2785fea270 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -90,9 +90,7 @@ pub struct ManualFloatMethods { impl ManualFloatMethods { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -144,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { && !expr.span.in_external_macro(cx.sess().source_map()) && ( is_not_const(cx.tcx, cx.tcx.hir_enclosing_body_owner(expr.hir_id).into()) - || self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY) + || self.msrv.meets(cx, msrvs::CONST_FLOAT_CLASSIFY) ) && let [first, second, const_1, const_2] = exprs && let ecx = ConstEvalCtxt::new(cx) @@ -202,8 +200,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { }); } } - - extract_msrv_attr!(LateContext); } fn is_infinity(constant: &Constant<'_>) -> bool { diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index 7e092d11f1b4..f71264a93ca8 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -53,9 +53,7 @@ pub struct ManualHashOne { impl ManualHashOne { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -98,7 +96,7 @@ impl LateLintPass<'_> for ManualHashOne { && let ExprKind::MethodCall(seg, _, [], _) = finish_expr.kind && seg.ident.name.as_str() == "finish" - && self.msrv.meets(msrvs::BUILD_HASHER_HASH_ONE) + && self.msrv.meets(cx, msrvs::BUILD_HASHER_HASH_ONE) { span_lint_hir_and_then( cx, @@ -129,6 +127,4 @@ impl LateLintPass<'_> for ManualHashOne { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_is_ascii_check.rs b/clippy_lints/src/manual_is_ascii_check.rs index 38106277a88f..faf01a276a13 100644 --- a/clippy_lints/src/manual_is_ascii_check.rs +++ b/clippy_lints/src/manual_is_ascii_check.rs @@ -64,9 +64,7 @@ pub struct ManualIsAsciiCheck { impl ManualIsAsciiCheck { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -91,11 +89,11 @@ enum CharRange { impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !self.msrv.meets(msrvs::IS_ASCII_DIGIT) { + if !self.msrv.meets(cx, msrvs::IS_ASCII_DIGIT) { return; } - if is_in_const_context(cx) && !self.msrv.meets(msrvs::IS_ASCII_DIGIT_CONST) { + if is_in_const_context(cx) && !self.msrv.meets(cx, msrvs::IS_ASCII_DIGIT_CONST) { return; } @@ -119,8 +117,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck { check_is_ascii(cx, expr.span, arg, &range, ty_sugg); } } - - extract_msrv_attr!(LateContext); } fn get_ty_sugg<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'_>) -> Option<(Span, Ty<'tcx>)> { diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index 3643b8c4425e..47939767212e 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -53,8 +53,8 @@ impl<'tcx> QuestionMark { && local.ty.is_none() && init.span.eq_ctxt(stmt.span) && let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) - && self.msrv.meets(msrvs::LET_ELSE) && !stmt.span.in_external_macro(cx.sess().source_map()) + && self.msrv.meets(cx, msrvs::LET_ELSE) { match if_let_or_match { IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else, ..) => { diff --git a/clippy_lints/src/manual_main_separator_str.rs b/clippy_lints/src/manual_main_separator_str.rs index b7563a2508d0..f54ccf2c87b0 100644 --- a/clippy_lints/src/manual_main_separator_str.rs +++ b/clippy_lints/src/manual_main_separator_str.rs @@ -39,9 +39,7 @@ pub struct ManualMainSeparatorStr { impl ManualMainSeparatorStr { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -55,10 +53,10 @@ impl LateLintPass<'_> for ManualMainSeparatorStr { && let ExprKind::Path(QPath::Resolved(None, path)) = receiver.kind && let Res::Def(DefKind::Const, receiver_def_id) = path.res && is_trait_method(cx, target, sym::ToString) - && self.msrv.meets(msrvs::PATH_MAIN_SEPARATOR_STR) && cx.tcx.is_diagnostic_item(sym::path_main_separator, receiver_def_id) && let ty::Ref(_, ty, Mutability::Not) = cx.typeck_results().expr_ty_adjusted(expr).kind() && ty.is_str() + && self.msrv.meets(cx, msrvs::PATH_MAIN_SEPARATOR_STR) { span_lint_and_sugg( cx, @@ -71,6 +69,4 @@ impl LateLintPass<'_> for ManualMainSeparatorStr { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 83d8a5093906..496e0660d4f9 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -71,7 +71,7 @@ pub struct ManualNonExhaustive { impl ManualNonExhaustive { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, constructed_enum_variants: FxHashSet::default(), potential_enums: Vec::new(), } @@ -82,7 +82,7 @@ impl_lint_pass!(ManualNonExhaustive => [MANUAL_NON_EXHAUSTIVE]); impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if !self.msrv.meets(msrvs::NON_EXHAUSTIVE) || !cx.effective_visibilities.is_exported(item.owner_id.def_id) { + if !cx.effective_visibilities.is_exported(item.owner_id.def_id) || !self.msrv.meets(cx, msrvs::NON_EXHAUSTIVE) { return; } @@ -171,6 +171,4 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/manual_option_as_slice.rs b/clippy_lints/src/manual_option_as_slice.rs index e4360518b66e..8dee29b2a0b5 100644 --- a/clippy_lints/src/manual_option_as_slice.rs +++ b/clippy_lints/src/manual_option_as_slice.rs @@ -1,5 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::msrvs::Msrv; use clippy_utils::{is_none_arm, msrvs, peel_hir_expr_refs}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; @@ -40,31 +41,21 @@ declare_clippy_lint! { } pub struct ManualOptionAsSlice { - msrv: msrvs::Msrv, + msrv: Msrv, } impl ManualOptionAsSlice { pub fn new(conf: &Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } impl_lint_pass!(ManualOptionAsSlice => [MANUAL_OPTION_AS_SLICE]); impl LateLintPass<'_> for ManualOptionAsSlice { - extract_msrv_attr!(LateContext); - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { let span = expr.span; - if span.from_expansion() - || !self.msrv.meets(if clippy_utils::is_in_const_context(cx) { - msrvs::CONST_OPTION_AS_SLICE - } else { - msrvs::OPTION_AS_SLICE - }) - { + if span.from_expansion() { return; } match expr.kind { @@ -72,7 +63,7 @@ impl LateLintPass<'_> for ManualOptionAsSlice { if is_none_arm(cx, arm2) && check_arms(cx, arm2, arm1) || is_none_arm(cx, arm1) && check_arms(cx, arm1, arm2) { - check_as_ref(cx, scrutinee, span); + check_as_ref(cx, scrutinee, span, self.msrv); } }, ExprKind::If(cond, then, Some(other)) => { @@ -81,23 +72,23 @@ impl LateLintPass<'_> for ManualOptionAsSlice { && check_some_body(cx, binding, then) && is_empty_slice(cx, other.peel_blocks()) { - check_as_ref(cx, let_expr.init, span); + check_as_ref(cx, let_expr.init, span, self.msrv); } }, ExprKind::MethodCall(seg, callee, [], _) => { if seg.ident.name.as_str() == "unwrap_or_default" { - check_map(cx, callee, span); + check_map(cx, callee, span, self.msrv); } }, ExprKind::MethodCall(seg, callee, [or], _) => match seg.ident.name.as_str() { "unwrap_or" => { if is_empty_slice(cx, or) { - check_map(cx, callee, span); + check_map(cx, callee, span, self.msrv); } }, "unwrap_or_else" => { if returns_empty_slice(cx, or) { - check_map(cx, callee, span); + check_map(cx, callee, span, self.msrv); } }, _ => {}, @@ -105,12 +96,12 @@ impl LateLintPass<'_> for ManualOptionAsSlice { ExprKind::MethodCall(seg, callee, [or_else, map], _) => match seg.ident.name.as_str() { "map_or" => { if is_empty_slice(cx, or_else) && is_slice_from_ref(cx, map) { - check_as_ref(cx, callee, span); + check_as_ref(cx, callee, span, self.msrv); } }, "map_or_else" => { if returns_empty_slice(cx, or_else) && is_slice_from_ref(cx, map) { - check_as_ref(cx, callee, span); + check_as_ref(cx, callee, span, self.msrv); } }, _ => {}, @@ -120,20 +111,28 @@ impl LateLintPass<'_> for ManualOptionAsSlice { } } -fn check_map(cx: &LateContext<'_>, map: &Expr<'_>, span: Span) { +fn check_map(cx: &LateContext<'_>, map: &Expr<'_>, span: Span, msrv: Msrv) { if let ExprKind::MethodCall(seg, callee, [mapping], _) = map.kind && seg.ident.name == sym::map && is_slice_from_ref(cx, mapping) { - check_as_ref(cx, callee, span); + check_as_ref(cx, callee, span, msrv); } } -fn check_as_ref(cx: &LateContext<'_>, expr: &Expr<'_>, span: Span) { +fn check_as_ref(cx: &LateContext<'_>, expr: &Expr<'_>, span: Span, msrv: Msrv) { if let ExprKind::MethodCall(seg, callee, [], _) = expr.kind && seg.ident.name == sym::as_ref && let ty::Adt(adtdef, ..) = cx.typeck_results().expr_ty(callee).kind() && cx.tcx.is_diagnostic_item(sym::Option, adtdef.did()) + && msrv.meets( + cx, + if clippy_utils::is_in_const_context(cx) { + msrvs::CONST_OPTION_AS_SLICE + } else { + msrvs::OPTION_AS_SLICE + }, + ) { if let Some(snippet) = clippy_utils::source::snippet_opt(cx, callee.span) { span_lint_and_sugg( diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 469b4b7cf89f..41e07e26bff0 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -39,9 +39,7 @@ pub struct ManualRemEuclid { impl ManualRemEuclid { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -60,8 +58,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && add_lhs.span.ctxt() == ctxt && add_rhs.span.ctxt() == ctxt && !expr.span.in_external_macro(cx.sess().source_map()) - && self.msrv.meets(msrvs::REM_EUCLID) - && (self.msrv.meets(msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx)) && let Some(const1) = check_for_unsigned_int_constant(cx, rem_rhs) && let Some((const2, add_other)) = check_for_either_unsigned_int_constant(cx, add_lhs, add_rhs) && let ExprKind::Binary(rem2_op, rem2_lhs, rem2_rhs) = add_other.kind @@ -73,6 +69,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && const2 == const3 && rem2_lhs.span.ctxt() == ctxt && rem2_rhs.span.ctxt() == ctxt + && self.msrv.meets(cx, msrvs::REM_EUCLID) + && (self.msrv.meets(cx, msrvs::REM_EUCLID_CONST) || !is_in_const_context(cx)) { // Apply only to params or locals with annotated types match cx.tcx.parent_hir_node(hir_id) { @@ -99,8 +97,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { ); } } - - extract_msrv_attr!(LateContext); } // Checks if either the left or right expressions can be an unsigned int constant and returns that diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 0a4e756096e9..16dd1ad4e478 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -50,9 +50,7 @@ pub struct ManualRetain { impl ManualRetain { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -66,13 +64,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualRetain { && let Some(collect_def_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id) && cx.tcx.is_diagnostic_item(sym::iterator_collect_fn, collect_def_id) { - check_into_iter(cx, left_expr, target_expr, expr.span, &self.msrv); - check_iter(cx, left_expr, target_expr, expr.span, &self.msrv); - check_to_owned(cx, left_expr, target_expr, expr.span, &self.msrv); + check_into_iter(cx, left_expr, target_expr, expr.span, self.msrv); + check_iter(cx, left_expr, target_expr, expr.span, self.msrv); + check_to_owned(cx, left_expr, target_expr, expr.span, self.msrv); } } - - extract_msrv_attr!(LateContext); } fn check_into_iter( @@ -80,7 +76,7 @@ fn check_into_iter( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if let hir::ExprKind::MethodCall(_, into_iter_expr, [_], _) = &target_expr.kind && let Some(filter_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) @@ -123,7 +119,7 @@ fn check_iter( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(copied_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) @@ -181,10 +177,9 @@ fn check_to_owned( left_expr: &hir::Expr<'_>, target_expr: &hir::Expr<'_>, parent_expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::STRING_RETAIN) - && let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind + if let hir::ExprKind::MethodCall(_, filter_expr, [], _) = &target_expr.kind && let Some(to_owned_def_id) = cx.typeck_results().type_dependent_def_id(target_expr.hir_id) && cx.tcx.is_diagnostic_item(sym::to_owned_method, to_owned_def_id) && let hir::ExprKind::MethodCall(_, chars_expr, [_], _) = &filter_expr.kind @@ -200,6 +195,7 @@ fn check_to_owned( && let hir::ExprKind::Closure(closure) = closure_expr.kind && let filter_body = cx.tcx.hir_body(closure.body) && let [filter_params] = filter_body.params + && msrv.meets(cx, msrvs::STRING_RETAIN) { if let hir::PatKind::Ref(pat, _) = filter_params.pat.kind { make_span_lint_and_sugg( @@ -253,7 +249,7 @@ fn match_acceptable_sym(cx: &LateContext<'_>, collect_def_id: DefId) -> bool { .any(|&method| cx.tcx.is_diagnostic_item(method, collect_def_id)) } -fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: &Msrv) -> bool { +fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: Msrv) -> bool { let ty = cx.typeck_results().expr_ty(expr).peel_refs(); let required = match get_type_diagnostic_name(cx, ty) { Some(sym::BinaryHeap) => msrvs::BINARY_HEAP_RETAIN, @@ -264,7 +260,7 @@ fn match_acceptable_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>, msrv: &Msrv Some(sym::Vec | sym::VecDeque) => return true, _ => return false, }; - msrv.meets(required) + msrv.meets(cx, required) } fn match_map_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { diff --git a/clippy_lints/src/manual_strip.rs b/clippy_lints/src/manual_strip.rs index daed88b492e6..9e911e61f196 100644 --- a/clippy_lints/src/manual_strip.rs +++ b/clippy_lints/src/manual_strip.rs @@ -56,9 +56,7 @@ pub struct ManualStrip { impl ManualStrip { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -75,7 +73,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr) && let ExprKind::MethodCall(_, target_arg, [pattern], _) = cond.kind && let ExprKind::Path(target_path) = &target_arg.kind - && self.msrv.meets(msrvs::STR_STRIP_PREFIX) && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id) { let strip_kind = if cx.tcx.is_diagnostic_item(sym::str_starts_with, method_def_id) { @@ -98,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } let (strippings, bindings) = find_stripping(cx, strip_kind, target_res, pattern, then); - if !strippings.is_empty() { + if !strippings.is_empty() && self.msrv.meets(cx, msrvs::STR_STRIP_PREFIX) { let kind_word = match strip_kind { StripKind::Prefix => "prefix", StripKind::Suffix => "suffix", @@ -156,8 +153,6 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip { } } } - - extract_msrv_attr!(LateContext); } // Returns `Some(arg)` if `expr` matches `arg.len()` and `None` otherwise. diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs index 97e8423695d9..6f446bf95658 100644 --- a/clippy_lints/src/matches/collapsible_match.rs +++ b/clippy_lints/src/matches/collapsible_match.rs @@ -14,7 +14,7 @@ use rustc_span::Span; use super::{COLLAPSIBLE_MATCH, pat_contains_disallowed_or}; -pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], msrv: &Msrv) { +pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], msrv: Msrv) { if let Some(els_arm) = arms.iter().rfind(|arm| arm_is_wild_like(cx, arm)) { for arm in arms { check_arm(cx, true, arm.pat, arm.body, arm.guard, Some(els_arm.body), msrv); @@ -27,7 +27,7 @@ pub(super) fn check_if_let<'tcx>( pat: &'tcx Pat<'_>, body: &'tcx Expr<'_>, else_expr: Option<&'tcx Expr<'_>>, - msrv: &Msrv, + msrv: Msrv, ) { check_arm(cx, false, pat, body, None, else_expr, msrv); } @@ -39,7 +39,7 @@ fn check_arm<'tcx>( outer_then_body: &'tcx Expr<'tcx>, outer_guard: Option<&'tcx Expr<'tcx>>, outer_else_body: Option<&'tcx Expr<'tcx>>, - msrv: &Msrv, + msrv: Msrv, ) { let inner_expr = peel_blocks_with_stmt(outer_then_body); if let Some(inner) = IfLetOrMatch::parse(cx, inner_expr) @@ -60,7 +60,7 @@ fn check_arm<'tcx>( // match expression must be a local binding // match { .. } && let Some(binding_id) = path_to_local(peel_ref_operators(cx, inner_scrutinee)) - && !pat_contains_disallowed_or(inner_then_pat, msrv) + && !pat_contains_disallowed_or(cx, inner_then_pat, msrv) // the binding must come from the pattern of the containing match arm // .... => match { .. } && let (Some(binding_span), is_innermost_parent_pat_struct) diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 9ca914af281b..35caa7d1f3a6 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1014,7 +1014,7 @@ pub struct Matches { impl Matches { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, infallible_destructuring_match_linted: false, } } @@ -1073,7 +1073,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { significant_drop_in_scrutinee::check_match(cx, expr, ex, arms, source); } - collapsible_match::check_match(cx, arms, &self.msrv); + collapsible_match::check_match(cx, arms, self.msrv); if !from_expansion { // These don't depend on a relationship between multiple arms match_wild_err_arm::check(cx, ex, arms); @@ -1086,7 +1086,9 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if !from_expansion && !contains_cfg_arm(cx, expr, ex, arms) { if source == MatchSource::Normal { - if !(self.msrv.meets(msrvs::MATCHES_MACRO) && match_like_matches::check_match(cx, expr, ex, arms)) { + if !(self.msrv.meets(cx, msrvs::MATCHES_MACRO) + && match_like_matches::check_match(cx, expr, ex, arms)) + { match_same_arms::check(cx, arms); } @@ -1120,7 +1122,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { needless_match::check_match(cx, ex, arms, expr); match_on_vec_items::check(cx, ex); match_str_case_mismatch::check(cx, ex, arms); - redundant_guards::check(cx, arms, &self.msrv); + redundant_guards::check(cx, arms, self.msrv); if !is_in_const_context(cx) { manual_unwrap_or::check_match(cx, expr, ex, arms); @@ -1138,11 +1140,11 @@ impl<'tcx> LateLintPass<'tcx> for Matches { match_ref_pats::check(cx, ex, arms.iter().map(|el| el.pat), expr); } } else if let Some(if_let) = higher::IfLet::hir(cx, expr) { - collapsible_match::check_if_let(cx, if_let.let_pat, if_let.if_then, if_let.if_else, &self.msrv); + collapsible_match::check_if_let(cx, if_let.let_pat, if_let.if_then, if_let.if_else, self.msrv); significant_drop_in_scrutinee::check_if_let(cx, expr, if_let.let_expr, if_let.if_then, if_let.if_else); if !from_expansion { if let Some(else_expr) = if_let.if_else { - if self.msrv.meets(msrvs::MATCHES_MACRO) { + if self.msrv.meets(cx, msrvs::MATCHES_MACRO) { match_like_matches::check_if_let( cx, expr, @@ -1208,8 +1210,6 @@ impl<'tcx> LateLintPass<'tcx> for Matches { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { rest_pat_in_fully_bound_struct::check(cx, pat); } - - extract_msrv_attr!(LateContext); } /// Checks if there are any arms with a `#[cfg(..)]` attribute. @@ -1274,16 +1274,12 @@ fn contains_cfg_arm(cx: &LateContext<'_>, e: &Expr<'_>, scrutinee: &Expr<'_>, ar } /// Checks if `pat` contains OR patterns that cannot be nested due to a too low MSRV. -fn pat_contains_disallowed_or(pat: &Pat<'_>, msrv: &Msrv) -> bool { - if msrv.meets(msrvs::OR_PATTERNS) { - return false; - } - - let mut result = false; +fn pat_contains_disallowed_or(cx: &LateContext<'_>, pat: &Pat<'_>, msrv: Msrv) -> bool { + let mut contains_or = false; pat.walk(|p| { let is_or = matches!(p.kind, PatKind::Or(_)); - result |= is_or; + contains_or |= is_or; !is_or }); - result + contains_or && !msrv.meets(cx, msrvs::OR_PATTERNS) } diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index dfc0513add93..ab53ad98572e 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -16,7 +16,7 @@ use std::ops::ControlFlow; use super::{REDUNDANT_GUARDS, pat_contains_disallowed_or}; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: &Msrv) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: Msrv) { for outer_arm in arms { let Some(guard) = outer_arm.guard else { continue; @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: if let ExprKind::Match(scrutinee, [arm, _], MatchSource::Normal) = guard.kind && matching_root_macro_call(cx, guard.span, sym::matches_macro).is_some() && let Some(binding) = get_pat_binding(cx, scrutinee, outer_arm) - && !pat_contains_disallowed_or(arm.pat, msrv) + && !pat_contains_disallowed_or(cx, arm.pat, msrv) { let pat_span = match (arm.pat.kind, binding.byref_ident) { (PatKind::Ref(pat, _), Some(_)) => pat.span, @@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'tcx>], msrv: // `Some(x) if let Some(2) = x` else if let ExprKind::Let(let_expr) = guard.kind && let Some(binding) = get_pat_binding(cx, let_expr.init, outer_arm) - && !pat_contains_disallowed_or(let_expr.pat, msrv) + && !pat_contains_disallowed_or(cx, let_expr.pat, msrv) { let pat_span = match (let_expr.pat.kind, binding.byref_ident) { (PatKind::Ref(pat, _), Some(_)) => pat.span, diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 2fe5f6a3a37a..a0919947b3fc 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -160,11 +160,11 @@ fn check_replace_option_with_some( src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span, - msrv: &Msrv, + msrv: Msrv, ) -> bool { - if msrv.meets(msrvs::OPTION_REPLACE) - && let ExprKind::Call(src_func, [src_arg]) = src.kind + if let ExprKind::Call(src_func, [src_arg]) = src.kind && is_res_lang_ctor(cx, path_res(cx, src_func), OptionSome) + && msrv.meets(cx, msrvs::OPTION_REPLACE) { // We do not have to check for a `const` context here, because `core::mem::replace()` and // `Option::replace()` have been const-stabilized simultaneously in version 1.83.0. @@ -250,15 +250,16 @@ fn check_replace_with_default( src: &Expr<'_>, dest: &Expr<'_>, expr: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { - if msrv.meets(msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) + if is_expr_used_or_unified(cx.tcx, expr) // disable lint for primitives && let expr_type = cx.typeck_results().expr_ty_adjusted(src) && !is_non_aggregate_primitive_type(expr_type) && is_default_equivalent(cx, src) && !expr.span.in_external_macro(cx.tcx.sess.source_map()) && let Some(top_crate) = std_or_core(cx) + && msrv.meets(cx, msrvs::MEM_TAKE) { span_lint_and_then( cx, @@ -292,9 +293,7 @@ pub struct MemReplace { impl MemReplace { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -308,12 +307,11 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace { { // Check that second argument is `Option::None` if !check_replace_option_with_none(cx, src, dest, expr.span) - && !check_replace_option_with_some(cx, src, dest, expr.span, &self.msrv) - && !check_replace_with_default(cx, src, dest, expr, &self.msrv) + && !check_replace_option_with_some(cx, src, dest, expr.span, self.msrv) + && !check_replace_with_default(cx, src, dest, expr, self.msrv) { check_replace_with_uninit(cx, src, dest, expr.span); } } } - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index 223a960b800e..f50fb627b89a 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -10,16 +10,16 @@ use rustc_span::{Span, sym}; use super::CLONED_INSTEAD_OF_COPIED; -pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: &Msrv) { +pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Msrv) { let recv_ty = cx.typeck_results().expr_ty_adjusted(recv); let inner_ty = match recv_ty.kind() { // `Option` -> `T` ty::Adt(adt, subst) - if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && msrv.meets(msrvs::OPTION_COPIED) => + if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) && msrv.meets(cx, msrvs::OPTION_COPIED) => { subst.type_at(0) }, - _ if is_trait_method(cx, expr, sym::Iterator) && msrv.meets(msrvs::ITERATOR_COPIED) => { + _ if is_trait_method(cx, expr, sym::Iterator) && msrv.meets(cx, msrvs::ITERATOR_COPIED) => { match get_iterator_item_ty(cx, recv_ty) { // ::Item Some(ty) => ty, diff --git a/clippy_lints/src/methods/err_expect.rs b/clippy_lints/src/methods/err_expect.rs index f2786efa44cb..91ddaca07d8b 100644 --- a/clippy_lints/src/methods/err_expect.rs +++ b/clippy_lints/src/methods/err_expect.rs @@ -14,19 +14,16 @@ pub(super) fn check( recv: &rustc_hir::Expr<'_>, expect_span: Span, err_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) - // Test the version to make sure the lint can be showed (expect_err has been - // introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982) - && msrv.meets(msrvs::EXPECT_ERR) - // Grabs the `Result` type && let result_type = cx.typeck_results().expr_ty(recv) // Tests if the T type in a `Result` is not None && let Some(data_type) = get_data_type(cx, result_type) // Tests if the T type in a `Result` implements debug && has_debug_impl(cx, data_type) + && msrv.meets(cx, msrvs::EXPECT_ERR) { span_lint_and_sugg( cx, diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 3f89e5931487..9f3c346042ff 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -14,10 +14,10 @@ pub(super) fn check<'tcx>( expr: &'tcx hir::Expr<'_>, recv: &'tcx hir::Expr<'_>, arg: &'tcx hir::Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { if is_trait_method(cx, expr, sym::Iterator) { - if !msrv.meets(msrvs::ITERATOR_FIND_MAP) { + if !msrv.meets(cx, msrvs::ITERATOR_FIND_MAP) { return; } diff --git a/clippy_lints/src/methods/io_other_error.rs b/clippy_lints/src/methods/io_other_error.rs index e0ce013ca7b7..4659e9e163fe 100644 --- a/clippy_lints/src/methods/io_other_error.rs +++ b/clippy_lints/src/methods/io_other_error.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{IO_ERROR_OTHER, Msrv}; +use clippy_utils::msrvs::{self, Msrv}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args: &[Expr<'_>], msrv: &Msrv) { +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args: &[Expr<'_>], msrv: Msrv) { if let [error_kind, error] = args && !expr.span.from_expansion() && !error_kind.span.from_expansion() @@ -15,7 +15,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args &clippy_utils::paths::IO_ERRORKIND_OTHER, ) && let ExprKind::Path(QPath::TypeRelative(_, new_segment)) = path.kind - && msrv.meets(IO_ERROR_OTHER) + && msrv.meets(cx, msrvs::IO_ERROR_OTHER) { span_lint_and_then( cx, diff --git a/clippy_lints/src/methods/is_digit_ascii_radix.rs b/clippy_lints/src/methods/is_digit_ascii_radix.rs index d8bb9e377a0c..9c32e9ac539d 100644 --- a/clippy_lints/src/methods/is_digit_ascii_radix.rs +++ b/clippy_lints/src/methods/is_digit_ascii_radix.rs @@ -12,12 +12,8 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'_>, self_arg: &'tcx Expr<'_>, radix: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if !msrv.meets(msrvs::IS_ASCII_DIGIT) { - return; - } - if !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_char() { return; } @@ -30,6 +26,10 @@ pub(super) fn check<'tcx>( }; let mut applicability = Applicability::MachineApplicable; + if !msrv.meets(cx, msrvs::IS_ASCII_DIGIT) { + return; + } + span_lint_and_sugg( cx, IS_DIGIT_ASCII_RADIX, diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 518041177e92..94415fc91061 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -20,9 +20,9 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'tcx>, // .iter().map(|(_, v_| v)) recv: &'tcx Expr<'tcx>, // hashmap m_arg: &'tcx Expr<'tcx>, // |(_, v)| v - msrv: &Msrv, + msrv: Msrv, ) { - if map_type == "into_iter" && !msrv.meets(msrvs::INTO_KEYS) { + if map_type == "into_iter" && !msrv.meets(cx, msrvs::INTO_KEYS) { return; } if !expr.span.from_expansion() diff --git a/clippy_lints/src/methods/manual_c_str_literals.rs b/clippy_lints/src/methods/manual_c_str_literals.rs index e1ebca0b09df..0274e31b4c33 100644 --- a/clippy_lints/src/methods/manual_c_str_literals.rs +++ b/clippy_lints/src/methods/manual_c_str_literals.rs @@ -22,7 +22,7 @@ pub(super) fn check_as_ptr<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, receiver: &'tcx Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) { if let ExprKind::Lit(lit) = receiver.kind && let LitKind::ByteStr(_, StrStyle::Cooked) | LitKind::Str(_, StrStyle::Cooked) = lit.node @@ -32,7 +32,7 @@ pub(super) fn check_as_ptr<'tcx>( |parent| matches!(parent.kind, ExprKind::Call(func, _) if is_c_str_function(cx, func).is_some()), ) && let Some(sugg) = rewrite_as_cstr(cx, lit.span) - && msrv.meets(msrvs::C_STR_LITERALS) + && msrv.meets(cx, msrvs::C_STR_LITERALS) { span_lint_and_sugg( cx, @@ -65,11 +65,11 @@ fn is_c_str_function(cx: &LateContext<'_>, func: &Expr<'_>) -> Option { /// - `CStr::from_bytes_with_nul(..)` /// - `CStr::from_bytes_with_nul_unchecked(..)` /// - `CStr::from_ptr(..)` -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args: &[Expr<'_>], msrv: &Msrv) { +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args: &[Expr<'_>], msrv: Msrv) { if let Some(fn_name) = is_c_str_function(cx, func) && let [arg] = args && cx.tcx.sess.edition() >= Edition2021 - && msrv.meets(msrvs::C_STR_LITERALS) + && msrv.meets(cx, msrvs::C_STR_LITERALS) { match fn_name.as_str() { name @ ("from_bytes_with_nul" | "from_bytes_with_nul_unchecked") diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index 09ccb386a20b..173ebcb7020b 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -14,14 +14,14 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym}; use super::MANUAL_INSPECT; #[expect(clippy::too_many_lines)] -pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: &str, name_span: Span, msrv: &Msrv) { +pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: &str, name_span: Span, msrv: Msrv) { if let ExprKind::Closure(c) = arg.kind && matches!(c.kind, ClosureKind::Closure) && let typeck = cx.typeck_results() && let Some(fn_id) = typeck.type_dependent_def_id(expr.hir_id) && (is_diag_trait_item(cx, fn_id, sym::Iterator) - || (msrv.meets(msrvs::OPTION_RESULT_INSPECT) - && (is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result)))) + || ((is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result)) + && msrv.meets(cx, msrvs::OPTION_RESULT_INSPECT))) && let body = cx.tcx.hir_body(c.body) && let [param] = body.params && let PatKind::Binding(BindingMode(ByRef::No, Mutability::Not), arg_id, _, None) = param.pat.kind diff --git a/clippy_lints/src/methods/manual_is_variant_and.rs b/clippy_lints/src/methods/manual_is_variant_and.rs index 90e502f244fa..40aad03960c4 100644 --- a/clippy_lints/src/methods/manual_is_variant_and.rs +++ b/clippy_lints/src/methods/manual_is_variant_and.rs @@ -14,7 +14,7 @@ pub(super) fn check<'tcx>( map_recv: &'tcx rustc_hir::Expr<'_>, map_arg: &'tcx rustc_hir::Expr<'_>, map_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { // Don't lint if: @@ -36,7 +36,7 @@ pub(super) fn check<'tcx>( } // 4. msrv doesn't meet `OPTION_RESULT_IS_VARIANT_AND` - if !msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) { + if !msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) { return; } diff --git a/clippy_lints/src/methods/manual_repeat_n.rs b/clippy_lints/src/methods/manual_repeat_n.rs index 6e09bf132aa1..83b57cca17bf 100644 --- a/clippy_lints/src/methods/manual_repeat_n.rs +++ b/clippy_lints/src/methods/manual_repeat_n.rs @@ -14,16 +14,16 @@ pub(super) fn check<'tcx>( expr: &'tcx Expr<'tcx>, repeat_expr: &Expr<'_>, take_arg: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::REPEAT_N) - && !expr.span.from_expansion() + if !expr.span.from_expansion() && is_trait_method(cx, expr, sym::Iterator) && let ExprKind::Call(_, [repeat_arg]) = repeat_expr.kind && let Some(def_id) = fn_def_id(cx, repeat_expr) && cx.tcx.is_diagnostic_item(sym::iter_repeat, def_id) && !expr_use_ctxt(cx, expr).is_ty_unified && let Some(std_or_core) = std_or_core(cx) + && msrv.meets(cx, msrvs::REPEAT_N) { let mut app = Applicability::MachineApplicable; span_lint_and_sugg( diff --git a/clippy_lints/src/methods/manual_try_fold.rs b/clippy_lints/src/methods/manual_try_fold.rs index a56378b5b73a..23dba47f60f4 100644 --- a/clippy_lints/src/methods/manual_try_fold.rs +++ b/clippy_lints/src/methods/manual_try_fold.rs @@ -17,10 +17,9 @@ pub(super) fn check<'tcx>( init: &Expr<'_>, acc: &Expr<'_>, fold_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { if !fold_span.in_external_macro(cx.sess().source_map()) - && msrv.meets(msrvs::ITERATOR_TRY_FOLD) && is_trait_method(cx, expr, sym::Iterator) && let init_ty = cx.typeck_results().expr_ty(init) && let Some(try_trait) = cx.tcx.lang_items().try_trait() @@ -29,6 +28,7 @@ pub(super) fn check<'tcx>( && let ExprKind::Path(qpath) = path.kind && let Res::Def(DefKind::Ctor(_, _), _) = cx.qpath_res(&qpath, path.hir_id) && let ExprKind::Closure(closure) = acc.kind + && msrv.meets(cx, msrvs::ITERATOR_TRY_FOLD) && !is_from_proc_macro(cx, expr) && let Some(args_snip) = closure .fn_arg_span diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index b2705e1ffc2d..128b3695f48b 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -41,7 +41,7 @@ fn should_run_lint(cx: &LateContext<'_>, e: &hir::Expr<'_>, method_id: DefId) -> true } -pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, msrv: &Msrv) { +pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, msrv: Msrv) { if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && should_run_lint(cx, e, method_id) { @@ -169,10 +169,10 @@ fn lint_path(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool) { ); } -fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool, msrv: &Msrv) { +fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool, msrv: Msrv) { let mut applicability = Applicability::MachineApplicable; - let (message, sugg_method) = if is_copy && msrv.meets(msrvs::ITERATOR_COPIED) { + let (message, sugg_method) = if is_copy && msrv.meets(cx, msrvs::ITERATOR_COPIED) { ("you are using an explicit closure for copying elements", "copied") } else { ("you are using an explicit closure for cloning elements", "cloned") diff --git a/clippy_lints/src/methods/map_unwrap_or.rs b/clippy_lints/src/methods/map_unwrap_or.rs index 428da0cf107e..df5a0de3392b 100644 --- a/clippy_lints/src/methods/map_unwrap_or.rs +++ b/clippy_lints/src/methods/map_unwrap_or.rs @@ -19,13 +19,13 @@ pub(super) fn check<'tcx>( recv: &'tcx hir::Expr<'_>, map_arg: &'tcx hir::Expr<'_>, unwrap_arg: &'tcx hir::Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { // lint if the caller of `map()` is an `Option` or a `Result`. let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option); let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); - if is_result && !msrv.meets(msrvs::RESULT_MAP_OR_ELSE) { + if is_result && !msrv.meets(cx, msrvs::RESULT_MAP_OR_ELSE) { return false; } diff --git a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs index 35dd7c082c90..6cf0936c598f 100644 --- a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs +++ b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs @@ -62,7 +62,7 @@ pub(super) fn check( ex: &Expr<'_>, receiver: &Expr<'_>, arg: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, method_call_span: Span, ) { let mut applicability = Applicability::MaybeIncorrect; @@ -82,7 +82,7 @@ pub(super) fn check( let use_take; if eager_or_lazy::switch_to_eager_eval(cx, body_expr) { - if msrv.meets(msrvs::REPEAT_N) { + if msrv.meets(cx, msrvs::REPEAT_N) { method_to_use_name = "repeat_n"; let body_snippet = snippet_with_applicability(cx, body_expr.span, "..", &mut applicability); new_span = (arg.span, format!("{body_snippet}, {count}")); @@ -93,7 +93,7 @@ pub(super) fn check( new_span = (arg.span, body_snippet.to_string()); use_take = true; } - } else if msrv.meets(msrvs::REPEAT_WITH) { + } else if msrv.meets(cx, msrvs::REPEAT_WITH) { method_to_use_name = "repeat_with"; new_span = (param.span, String::new()); use_take = true; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 0c154b296bc1..94d3657d9f12 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4503,7 +4503,7 @@ impl Methods { Self { avoid_breaking_exported_api: conf.avoid_breaking_exported_api, - msrv: conf.msrv.clone(), + msrv: conf.msrv, allow_expect_in_tests: conf.allow_expect_in_tests, allow_unwrap_in_tests: conf.allow_unwrap_in_tests, allow_expect_in_consts: conf.allow_expect_in_consts, @@ -4688,9 +4688,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods { ExprKind::Call(func, args) => { from_iter_instead_of_collect::check(cx, expr, args, func); unnecessary_fallible_conversions::check_function(cx, expr, func); - manual_c_str_literals::check(cx, expr, func, args, &self.msrv); - useless_nonzero_new_unchecked::check(cx, expr, func, args, &self.msrv); - io_other_error::check(cx, expr, func, args, &self.msrv); + manual_c_str_literals::check(cx, expr, func, args, self.msrv); + useless_nonzero_new_unchecked::check(cx, expr, func, args, self.msrv); + io_other_error::check(cx, expr, func, args, self.msrv); }, ExprKind::MethodCall(method_call, receiver, args, _) => { let method_span = method_call.ident.span; @@ -4709,7 +4709,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { inefficient_to_string::check(cx, expr, method_call.ident.name, receiver, args); single_char_add_str::check(cx, expr, receiver, args); into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, receiver); - unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, &self.msrv); + unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, self.msrv); }, ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => { let mut info = BinaryExprInfo { @@ -4855,8 +4855,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods { ); } } - - extract_msrv_attr!(LateContext); } impl Methods { @@ -4914,7 +4912,7 @@ impl Methods { && let body = cx.tcx.hir_body(arg.body) && let [param] = body.params => { - string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); + string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), self.msrv); }, Some(("map", _, [map_arg], _, map_call_span)) => { map_all_any_identity::check(cx, expr, recv, map_call_span, map_arg, call_span, arg, "any"); @@ -4938,12 +4936,12 @@ impl Methods { sliced_string_as_bytes::check(cx, expr, recv); }, ("as_mut", []) => useless_asref::check(cx, expr, "as_mut", recv), - ("as_ptr", []) => manual_c_str_literals::check_as_ptr(cx, expr, recv, &self.msrv), + ("as_ptr", []) => manual_c_str_literals::check_as_ptr(cx, expr, recv, self.msrv), ("as_ref", []) => useless_asref::check(cx, expr, "as_ref", recv), ("assume_init", []) => uninit_assumed_init::check(cx, expr, recv), ("bytes", []) => unbuffered_bytes::check(cx, expr, recv), ("cloned", []) => { - cloned_instead_of_copied::check(cx, expr, recv, span, &self.msrv); + cloned_instead_of_copied::check(cx, expr, recv, span, self.msrv); option_as_ref_cloned::check(cx, recv, span); }, ("collect", []) if is_trait_method(cx, expr, sym::Iterator) => { @@ -4957,7 +4955,7 @@ impl Methods { format_collect::check(cx, expr, m_arg, m_ident_span); }, Some(("take", take_self_arg, [take_arg], _, _)) => { - if self.msrv.meets(msrvs::STR_REPEAT) { + if self.msrv.meets(cx, msrvs::STR_REPEAT) { manual_str_repeat::check(cx, expr, recv, take_self_arg, take_arg); } }, @@ -4996,13 +4994,13 @@ impl Methods { if let ExprKind::MethodCall(.., span) = expr.kind { case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg); } - path_ends_with_ext::check(cx, recv, arg, expr, &self.msrv, &self.allowed_dotfiles); + path_ends_with_ext::check(cx, recv, arg, expr, self.msrv, &self.allowed_dotfiles); }, ("expect", [_]) => { 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); + err_expect::check(cx, expr, recv, span, err_span, self.msrv); }, _ => unwrap_expect_used::check( cx, @@ -5044,7 +5042,7 @@ impl Methods { false, ); } - if self.msrv.meets(msrvs::ITER_FLATTEN) { + if self.msrv.meets(cx, msrvs::ITER_FLATTEN) { // use the sourcemap to get the span of the closure iter_filter::check(cx, expr, arg, span); } @@ -5092,7 +5090,7 @@ impl Methods { _ => {}, }, ("fold", [init, acc]) => { - manual_try_fold::check(cx, expr, init, acc, call_span, &self.msrv); + manual_try_fold::check(cx, expr, init, acc, call_span, self.msrv); unnecessary_fold::check(cx, expr, init, acc, span); }, ("for_each", [arg]) => { @@ -5133,7 +5131,7 @@ impl Methods { is_empty::check(cx, expr, recv); }, ("is_file", []) => filetype_is_file::check(cx, expr, recv), - ("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, &self.msrv), + ("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv), ("is_none", []) => check_is_some_is_none(cx, expr, recv, call_span, false), ("is_some", []) => check_is_some_is_none(cx, expr, recv, call_span, true), ("iter" | "iter_mut" | "into_iter", []) => { @@ -5170,11 +5168,11 @@ impl Methods { (name @ ("map" | "map_err"), [m_arg]) => { if name == "map" { unused_enumerate_index::check(cx, expr, recv, m_arg); - map_clone::check(cx, expr, recv, m_arg, &self.msrv); - map_with_unused_argument_over_ranges::check(cx, expr, recv, m_arg, &self.msrv, span); + map_clone::check(cx, expr, recv, m_arg, self.msrv); + map_with_unused_argument_over_ranges::check(cx, expr, recv, m_arg, self.msrv, span); match method_call(recv) { Some((map_name @ ("iter" | "into_iter"), recv2, _, _, _)) => { - iter_kv_map::check(cx, map_name, expr, recv2, m_arg, &self.msrv); + iter_kv_map::check(cx, map_name, expr, recv2, m_arg, self.msrv); }, Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( cx, @@ -5191,8 +5189,8 @@ impl Methods { } if let Some((name, recv2, args, span2, _)) = method_call(recv) { match (name, args) { - ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, &self.msrv), - ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, &self.msrv), + ("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, self.msrv), + ("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, self.msrv), ("filter", [f_arg]) => { filter_map::check(cx, expr, recv2, f_arg, span2, recv, m_arg, span, false); }, @@ -5203,7 +5201,7 @@ impl Methods { } } map_identity::check(cx, expr, recv, m_arg, name, span); - manual_inspect::check(cx, expr, m_arg, name, span, &self.msrv); + manual_inspect::check(cx, expr, m_arg, name, span, self.msrv); crate::useless_conversion::check_function_application(cx, expr, recv, m_arg); }, ("map_break" | "map_continue", [m_arg]) => { @@ -5212,7 +5210,7 @@ impl Methods { ("map_or", [def, map]) => { option_map_or_none::check(cx, expr, recv, def, map); manual_ok_or::check(cx, expr, recv, def, map); - unnecessary_map_or::check(cx, expr, recv, def, map, span, &self.msrv); + unnecessary_map_or::check(cx, expr, recv, def, map, span, self.msrv); }, ("map_or_else", [def, map]) => { result_map_or_else_none::check(cx, expr, recv, def, map); @@ -5230,7 +5228,7 @@ impl Methods { false, ), ("filter", [arg]) => filter_next::check(cx, expr, recv2, arg), - ("filter_map", [arg]) => filter_map_next::check(cx, expr, recv2, arg, &self.msrv), + ("filter_map", [arg]) => filter_map_next::check(cx, expr, recv2, arg, self.msrv), ("iter", []) => iter_next_slice::check(cx, expr, recv2), ("skip", [arg]) => iter_skip_next::check(cx, expr, recv2, arg), ("skip_while", [_]) => skip_while_next::check(cx, expr), @@ -5286,7 +5284,7 @@ impl Methods { no_effect_replace::check(cx, expr, arg1, arg2); // Check for repeated `str::replace` calls to perform `collapsible_str_replace` lint - if self.msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) + if self.msrv.meets(cx, msrvs::PATTERN_TRAIT_CHAR_ARRAY) && name == "replace" && let Some(("replace", ..)) = method_call(recv) { @@ -5297,10 +5295,10 @@ impl Methods { vec_resize_to_zero::check(cx, expr, count_arg, default_arg, span); }, ("seek", [arg]) => { - if self.msrv.meets(msrvs::SEEK_FROM_CURRENT) { + if self.msrv.meets(cx, msrvs::SEEK_FROM_CURRENT) { seek_from_current::check(cx, expr, recv, arg); } - if self.msrv.meets(msrvs::SEEK_REWIND) { + if self.msrv.meets(cx, msrvs::SEEK_REWIND) { seek_to_start_instead_of_rewind::check(cx, expr, recv, arg, span); } }, @@ -5334,7 +5332,7 @@ impl Methods { ("splitn" | "rsplitn", [count_arg, pat_arg]) => { if let Some(Constant::Int(count)) = ConstEvalCtxt::new(cx).eval(count_arg) { suspicious_splitn::check(cx, name, expr, recv, count); - str_splitn::check(cx, name, expr, recv, pat_arg, count, &self.msrv); + str_splitn::check(cx, name, expr, recv, pat_arg, count, self.msrv); } }, ("splitn_mut" | "rsplitn_mut", [count_arg, _]) => { @@ -5345,7 +5343,7 @@ impl Methods { ("step_by", [arg]) => iterator_step_by_zero::check(cx, expr, arg), ("take", [arg]) => { iter_out_of_bounds::check_take(cx, expr, recv, arg); - manual_repeat_n::check(cx, expr, recv, arg, &self.msrv); + manual_repeat_n::check(cx, expr, recv, arg, self.msrv); if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { iter_overeager_cloned::check( cx, @@ -5359,7 +5357,7 @@ impl Methods { }, ("take", []) => needless_option_take::check(cx, expr, recv), ("then", [arg]) => { - if !self.msrv.meets(msrvs::BOOL_THEN_SOME) { + if !self.msrv.meets(cx, msrvs::BOOL_THEN_SOME) { return; } unnecessary_lazy_eval::check(cx, expr, recv, arg, "then_some"); @@ -5420,7 +5418,7 @@ impl Methods { manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]); }, Some(("map", m_recv, [m_arg], span, _)) => { - option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, &self.msrv); + option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span, self.msrv); }, Some((then_method @ ("then" | "then_some"), t_recv, [t_arg], _, _)) => { obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg, then_method, "unwrap_or"); @@ -5431,7 +5429,7 @@ impl Methods { }, ("unwrap_or_default", []) => { if let Some(("map", m_recv, [arg], span, _)) = method_call(recv) { - manual_is_variant_and::check(cx, expr, m_recv, arg, span, &self.msrv); + manual_is_variant_and::check(cx, expr, m_recv, arg, span, self.msrv); } unnecessary_literal_unwrap::check(cx, expr, recv, name, args); }, @@ -5441,7 +5439,7 @@ impl Methods { ("unwrap_or_else", [u_arg]) => { match method_call(recv) { Some(("map", recv, [map_arg], _, _)) - if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {}, + if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, self.msrv) => {}, Some((then_method @ ("then" | "then_some"), t_recv, [t_arg], _, _)) => { obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg, then_method, "unwrap_or_else"); }, diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index 469fcccbe4f6..63ee922acfa0 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -18,12 +18,8 @@ pub(super) fn check( as_ref_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>, is_mut: bool, - msrv: &Msrv, + msrv: Msrv, ) { - if !msrv.meets(msrvs::OPTION_AS_DEREF) { - return; - } - let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); let option_ty = cx.typeck_results().expr_ty(as_ref_recv); @@ -93,7 +89,7 @@ pub(super) fn check( _ => false, }; - if is_deref { + if is_deref && msrv.meets(cx, msrvs::OPTION_AS_DEREF) { let current_method = if is_mut { format!(".as_mut().map({})", snippet(cx, map_arg.span, "..")) } else { diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index b1107d8cc72f..4ba8e0109042 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>( unwrap_recv: &rustc_hir::Expr<'_>, unwrap_arg: &'tcx rustc_hir::Expr<'_>, map_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { // lint if the caller of `map()` is an `Option` if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) { @@ -71,9 +71,9 @@ pub(super) fn check<'tcx>( } // is_some_and is stabilised && `unwrap_or` argument is false; suggest `is_some_and` instead - let suggest_is_some_and = msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) - && matches!(&unwrap_arg.kind, ExprKind::Lit(lit) - if matches!(lit.node, rustc_ast::LitKind::Bool(false))); + let suggest_is_some_and = matches!(&unwrap_arg.kind, ExprKind::Lit(lit) + if matches!(lit.node, rustc_ast::LitKind::Bool(false))) + && msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND); let mut applicability = Applicability::MachineApplicable; // get snippet for unwrap_or() diff --git a/clippy_lints/src/methods/path_ends_with_ext.rs b/clippy_lints/src/methods/path_ends_with_ext.rs index b3811a335e1a..d3f513e7abd2 100644 --- a/clippy_lints/src/methods/path_ends_with_ext.rs +++ b/clippy_lints/src/methods/path_ends_with_ext.rs @@ -20,7 +20,7 @@ pub(super) fn check( recv: &Expr<'_>, path: &Expr<'_>, expr: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, allowed_dotfiles: &FxHashSet<&'static str>, ) { if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv).peel_refs(), sym::Path) @@ -33,7 +33,7 @@ pub(super) fn check( && path.chars().all(char::is_alphanumeric) { let mut sugg = snippet(cx, recv.span, "..").into_owned(); - if msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) { + if msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) { let _ = write!(sugg, r#".extension().is_some_and(|ext| ext == "{path}")"#); } else { let _ = write!(sugg, r#".extension().map_or(false, |ext| ext == "{path}")"#); diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 8389c2e3f982..4ccefb7ec9d7 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -23,7 +23,7 @@ pub(super) fn check( self_arg: &Expr<'_>, pat_arg: &Expr<'_>, count: u128, - msrv: &Msrv, + msrv: Msrv, ) { if count < 2 || !cx.typeck_results().expr_ty_adjusted(self_arg).peel_refs().is_str() { return; @@ -33,7 +33,7 @@ pub(super) fn check( IterUsageKind::Nth(n) => count > n + 1, IterUsageKind::NextTuple => count > 2, }; - let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE); + let manual = count == 2 && msrv.meets(cx, msrvs::STR_SPLIT_ONCE); match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir_parent_iter(expr.hir_id)) { Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg), diff --git a/clippy_lints/src/methods/string_lit_chars_any.rs b/clippy_lints/src/methods/string_lit_chars_any.rs index cb719b34b1f0..f0f9d30d3000 100644 --- a/clippy_lints/src/methods/string_lit_chars_any.rs +++ b/clippy_lints/src/methods/string_lit_chars_any.rs @@ -17,10 +17,9 @@ pub(super) fn check<'tcx>( recv: &Expr<'_>, param: &'tcx Param<'tcx>, body: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { - if msrv.meets(msrvs::MATCHES_MACRO) - && is_trait_method(cx, expr, sym::Iterator) + if is_trait_method(cx, expr, sym::Iterator) && let PatKind::Binding(_, arg, _, _) = param.pat.kind && let ExprKind::Lit(lit_kind) = recv.kind && let LitKind::Str(val, _) = lit_kind.node @@ -33,6 +32,7 @@ pub(super) fn check<'tcx>( (false, true) => lhs, _ => return, } + && msrv.meets(cx, msrvs::MATCHES_MACRO) && !is_from_proc_macro(cx, expr) && let Some(scrutinee_snip) = scrutinee.span.get_source_text(cx) { diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index 3a669fca177f..d7bd522ddab9 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -42,7 +42,7 @@ pub(super) fn check<'a>( def: &Expr<'_>, map: &Expr<'_>, method_span: Span, - msrv: &Msrv, + msrv: Msrv, ) { let ExprKind::Lit(def_kind) = def.kind else { return; @@ -119,14 +119,14 @@ pub(super) fn check<'a>( .into_string(); (vec![(expr.span, sugg)], "a standard comparison", app) - } else if !def_bool && msrv.meets(msrvs::OPTION_RESULT_IS_VARIANT_AND) { + } else if !def_bool && msrv.meets(cx, msrvs::OPTION_RESULT_IS_VARIANT_AND) { let suggested_name = variant.method_name(); ( vec![(method_span, suggested_name.into()), (ext_def_span, String::default())], suggested_name, Applicability::MachineApplicable, ) - } else if def_bool && matches!(variant, Variant::Some) && msrv.meets(msrvs::IS_NONE_OR) { + } else if def_bool && matches!(variant, Variant::Some) && msrv.meets(cx, msrvs::IS_NONE_OR) { ( vec![(method_span, "is_none_or".into()), (ext_def_span, String::default())], "is_none_or", diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index ea134c057053..a71b3659fd24 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -31,7 +31,7 @@ pub fn check<'tcx>( method_name: Symbol, receiver: &'tcx Expr<'_>, args: &'tcx [Expr<'_>], - msrv: &Msrv, + msrv: Msrv, ) { if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && args.is_empty() @@ -207,7 +207,7 @@ fn check_into_iter_call_arg( expr: &Expr<'_>, method_name: Symbol, receiver: &Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { if let Some(parent) = get_parent_expr(cx, expr) && let Some(callee_def_id) = fn_def_id(cx, parent) @@ -224,7 +224,7 @@ fn check_into_iter_call_arg( return true; } - let cloned_or_copied = if is_copy(cx, item_ty) && msrv.meets(msrvs::ITERATOR_COPIED) { + let cloned_or_copied = if is_copy(cx, item_ty) && msrv.meets(cx, msrvs::ITERATOR_COPIED) { "copied" } else { "cloned" diff --git a/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs b/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs index 0bd50429c09d..22df1f3f485e 100644 --- a/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs +++ b/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs @@ -10,13 +10,13 @@ use rustc_span::sym; use super::USELESS_NONZERO_NEW_UNCHECKED; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, func: &Expr<'tcx>, args: &[Expr<'_>], msrv: &Msrv) { - if msrv.meets(msrvs::CONST_UNWRAP) - && let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, func: &Expr<'tcx>, args: &[Expr<'_>], msrv: Msrv) { + if let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind && segment.ident.name == sym::new_unchecked && let [init_arg] = args && is_inside_always_const_context(cx.tcx, expr.hir_id) && is_type_diagnostic_item(cx, cx.typeck_results().node_type(ty.hir_id), sym::NonZero) + && msrv.meets(cx, msrvs::CONST_UNWRAP) { let mut app = Applicability::MachineApplicable; let ty_str = snippet_with_applicability(cx, ty.span, "_", &mut app); diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index bc60fa507b12..38a19dd2999b 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -80,9 +80,7 @@ pub struct MissingConstForFn { impl MissingConstForFn { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -101,10 +99,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { return; } - if !self.msrv.meets(msrvs::CONST_IF_MATCH) { - return; - } - if span.in_external_macro(cx.tcx.sess.source_map()) || is_entrypoint_fn(cx, def_id.to_def_id()) { return; } @@ -123,7 +117,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { .iter() .any(|param| matches!(param.kind, GenericParamKind::Const { .. })); - if already_const(header) || has_const_generic_params || !could_be_const_with_abi(&self.msrv, header.abi) + if already_const(header) + || has_const_generic_params + || !could_be_const_with_abi(cx, self.msrv, header.abi) { return; } @@ -152,13 +148,17 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { } } + if !self.msrv.meets(cx, msrvs::CONST_IF_MATCH) { + return; + } + if is_from_proc_macro(cx, &(&kind, body, hir_id, span)) { return; } let mir = cx.tcx.optimized_mir(def_id); - if let Ok(()) = is_min_const_fn(cx.tcx, mir, &self.msrv) + if let Ok(()) = is_min_const_fn(cx, mir, self.msrv) && let hir::Node::Item(hir::Item { vis_span, .. }) | hir::Node::ImplItem(hir::ImplItem { vis_span, .. }) = cx.tcx.hir_node_by_def_id(def_id) { @@ -173,8 +173,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { }); } } - - extract_msrv_attr!(LateContext); } // We don't have to lint on something that's already `const` @@ -183,13 +181,13 @@ fn already_const(header: hir::FnHeader) -> bool { header.constness == Constness::Const } -fn could_be_const_with_abi(msrv: &Msrv, abi: ExternAbi) -> bool { +fn could_be_const_with_abi(cx: &LateContext<'_>, msrv: Msrv, abi: ExternAbi) -> bool { match abi { ExternAbi::Rust => true, // `const extern "C"` was stabilized after 1.62.0 - ExternAbi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN), + ExternAbi::C { unwind: false } => msrv.meets(cx, msrvs::CONST_EXTERN_C_FN), // Rest ABIs are still unstable and need the `const_extern_fn` feature enabled. - _ => msrv.meets(msrvs::CONST_EXTERN_FN), + _ => msrv.meets(cx, msrvs::CONST_EXTERN_FN), } } diff --git a/clippy_lints/src/missing_const_for_thread_local.rs b/clippy_lints/src/missing_const_for_thread_local.rs index d4181c677afd..ea74940828a1 100644 --- a/clippy_lints/src/missing_const_for_thread_local.rs +++ b/clippy_lints/src/missing_const_for_thread_local.rs @@ -49,9 +49,7 @@ pub struct MissingConstForThreadLocal { impl MissingConstForThreadLocal { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -91,11 +89,11 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { } #[inline] -fn initializer_can_be_made_const(cx: &LateContext<'_>, defid: rustc_span::def_id::DefId, msrv: &Msrv) -> bool { +fn initializer_can_be_made_const(cx: &LateContext<'_>, defid: rustc_span::def_id::DefId, msrv: Msrv) -> bool { // Building MIR for `fn`s with unsatisfiable preds results in ICE. if !fn_has_unsatisfiable_preds(cx, defid) && let mir = cx.tcx.optimized_mir(defid) - && let Ok(()) = is_min_const_fn(cx.tcx, mir, msrv) + && let Ok(()) = is_min_const_fn(cx, mir, msrv) { return true; } @@ -113,8 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { local_defid: rustc_span::def_id::LocalDefId, ) { let defid = local_defid.to_def_id(); - if self.msrv.meets(msrvs::THREAD_LOCAL_CONST_INIT) - && is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false) + if is_thread_local_initializer(cx, fn_kind, span).unwrap_or(false) // Some implementations of `thread_local!` include an initializer fn. // In the case of a const initializer, the init fn is also const, // so we can skip the lint in that case. This occurs only on some @@ -131,11 +128,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { // https://github.com/rust-lang/rust-clippy/issues/12637 // we ensure that this is reachable before we check in mir && !is_unreachable(cx, ret_expr) - && initializer_can_be_made_const(cx, defid, &self.msrv) + && initializer_can_be_made_const(cx, defid, self.msrv) // we know that the function is const-qualifiable, so now // we need only to get the initializer expression to span-lint it. && let initializer_snippet = snippet(cx, ret_expr.span, "thread_local! { ... }") && initializer_snippet != "thread_local! { ... }" + && self.msrv.meets(cx, msrvs::THREAD_LOCAL_CONST_INIT) { span_lint_and_sugg( cx, @@ -148,6 +146,4 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForThreadLocal { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index ea1d7e5d4382..f686cc912ddb 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -72,7 +72,7 @@ impl NeedlessBorrowsForGenericArgs<'_> { pub fn new(conf: &'static Conf) -> Self { Self { possible_borrowers: Vec::new(), - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { i, param_ty, expr, - &self.msrv, + self.msrv, ) && count != 0 { @@ -142,8 +142,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { self.possible_borrowers.pop(); } } - - extract_msrv_attr!(LateContext); } fn path_has_args(p: &QPath<'_>) -> bool { @@ -172,7 +170,7 @@ fn needless_borrow_count<'tcx>( arg_index: usize, param_ty: ParamTy, mut expr: &Expr<'tcx>, - msrv: &Msrv, + msrv: Msrv, ) -> usize { let destruct_trait_def_id = cx.tcx.lang_items().destruct_trait(); let sized_trait_def_id = cx.tcx.lang_items().sized_trait(); @@ -273,7 +271,7 @@ fn needless_borrow_count<'tcx>( && let ty::Param(param_ty) = trait_predicate.self_ty().kind() && let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack() && ty.is_array() - && !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) + && !msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) { return false; } diff --git a/clippy_lints/src/non_std_lazy_statics.rs b/clippy_lints/src/non_std_lazy_statics.rs index 774a182d089f..a82365f94318 100644 --- a/clippy_lints/src/non_std_lazy_statics.rs +++ b/clippy_lints/src/non_std_lazy_statics.rs @@ -1,8 +1,8 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; -use clippy_utils::msrvs::Msrv; +use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::visitors::for_each_expr; -use clippy_utils::{def_path_def_ids, fn_def_id, path_def_id}; +use clippy_utils::{def_path_def_ids, fn_def_id, is_no_std_crate, path_def_id}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; @@ -75,7 +75,7 @@ impl NonStdLazyStatic { #[must_use] pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, lazy_static_lazy_static: Vec::new(), once_cell_crate: Vec::new(), once_cell_sync_lazy: Vec::new(), @@ -89,23 +89,12 @@ impl NonStdLazyStatic { impl_lint_pass!(NonStdLazyStatic => [NON_STD_LAZY_STATICS]); -/// Return if current MSRV does not meet the requirement for `lazy_cell` feature, -/// or current context has `no_std` attribute. -macro_rules! ensure_prerequisite { - ($msrv:expr, $cx:ident) => { - if !$msrv.meets(clippy_utils::msrvs::LAZY_CELL) || clippy_utils::is_no_std_crate($cx) { - return; - } - }; +fn can_use_lazy_cell(cx: &LateContext<'_>, msrv: Msrv) -> bool { + msrv.meets(cx, msrvs::LAZY_CELL) && !is_no_std_crate(cx) } impl<'hir> LateLintPass<'hir> for NonStdLazyStatic { - extract_msrv_attr!(LateContext); - fn check_crate(&mut self, cx: &LateContext<'hir>) { - // Do not lint if current crate does not support `LazyLock`. - ensure_prerequisite!(self.msrv, cx); - // Fetch def_ids for external paths self.lazy_static_lazy_static = def_path_def_ids(cx.tcx, &["lazy_static", "lazy_static"]).collect(); self.once_cell_sync_lazy = def_path_def_ids(cx.tcx, &["once_cell", "sync", "Lazy"]).collect(); @@ -123,11 +112,10 @@ impl<'hir> LateLintPass<'hir> for NonStdLazyStatic { } fn check_item(&mut self, cx: &LateContext<'hir>, item: &Item<'hir>) { - ensure_prerequisite!(self.msrv, cx); - if let ItemKind::Static(..) = item.kind && let Some(macro_call) = clippy_utils::macros::root_macro_call(item.span) && self.lazy_static_lazy_static.contains(¯o_call.def_id) + && can_use_lazy_cell(cx, self.msrv) { span_lint( cx, @@ -142,14 +130,14 @@ impl<'hir> LateLintPass<'hir> for NonStdLazyStatic { return; } - if let Some(lazy_info) = LazyInfo::from_item(self, cx, item) { + if let Some(lazy_info) = LazyInfo::from_item(self, cx, item) + && can_use_lazy_cell(cx, self.msrv) + { self.lazy_type_defs.insert(item.owner_id.to_def_id(), lazy_info); } } fn check_expr(&mut self, cx: &LateContext<'hir>, expr: &Expr<'hir>) { - ensure_prerequisite!(self.msrv, cx); - // All functions in the `FUNCTION_REPLACEMENTS` have only one args if let ExprKind::Call(callee, [arg]) = expr.kind && let Some(call_def_id) = fn_def_id(cx, expr) @@ -163,8 +151,6 @@ impl<'hir> LateLintPass<'hir> for NonStdLazyStatic { } fn check_ty(&mut self, cx: &LateContext<'hir>, ty: &'hir rustc_hir::Ty<'hir, rustc_hir::AmbigArg>) { - ensure_prerequisite!(self.msrv, cx); - // Record if types from `once_cell` besides `sync::Lazy` are used. if let rustc_hir::TyKind::Path(qpath) = ty.peel_refs().kind && let Some(ty_def_id) = cx.qpath_res(&qpath, ty.hir_id).opt_def_id() @@ -178,8 +164,6 @@ impl<'hir> LateLintPass<'hir> for NonStdLazyStatic { } fn check_crate_post(&mut self, cx: &LateContext<'hir>) { - ensure_prerequisite!(self.msrv, cx); - if !self.uses_other_once_cell_types { for (_, lazy_info) in &self.lazy_type_defs { lazy_info.lint(cx, &self.sugg_map); diff --git a/clippy_lints/src/operators/manual_midpoint.rs b/clippy_lints/src/operators/manual_midpoint.rs index 61ef5670a5ad..81721a9f2af5 100644 --- a/clippy_lints/src/operators/manual_midpoint.rs +++ b/clippy_lints/src/operators/manual_midpoint.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>( op: BinOpKind, left: &'tcx Expr<'_>, right: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) { if !left.span.from_expansion() && !right.span.from_expansion() @@ -29,7 +29,7 @@ pub(super) fn check<'tcx>( && left_ty == right_ty // Do not lint on `(_+1)/2` and `(1+_)/2`, it is likely a `div_ceil()` operation && !is_integer_literal(ll_expr, 1) && !is_integer_literal(lr_expr, 1) - && is_midpoint_implemented(left_ty, msrv) + && is_midpoint_implemented(cx, left_ty, msrv) { let mut app = Applicability::MachineApplicable; let left_sugg = Sugg::hir_with_context(cx, ll_expr, expr.span.ctxt(), "..", &mut app); @@ -55,10 +55,10 @@ fn add_operands<'e, 'tcx>(expr: &'e Expr<'tcx>) -> Option<(&'e Expr<'tcx>, &'e E } } -fn is_midpoint_implemented(ty: Ty<'_>, msrv: &Msrv) -> bool { +fn is_midpoint_implemented(cx: &LateContext<'_>, ty: Ty<'_>, msrv: Msrv) -> bool { match ty.kind() { - ty::Uint(_) | ty::Float(_) => msrv.meets(msrvs::UINT_FLOAT_MIDPOINT), - ty::Int(_) => msrv.meets(msrvs::INT_MIDPOINT), + ty::Uint(_) | ty::Float(_) => msrv.meets(cx, msrvs::UINT_FLOAT_MIDPOINT), + ty::Int(_) => msrv.meets(cx, msrvs::INT_MIDPOINT), _ => false, } } diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index 43b657ea7ff0..80459945094e 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -872,7 +872,7 @@ impl Operators { arithmetic_context: numeric_arithmetic::Context::default(), verbose_bit_mask_threshold: conf.verbose_bit_mask_threshold, modulo_arithmetic_allow_comparison_to_zero: conf.allow_comparison_to_zero, - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -922,7 +922,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators { identity_op::check(cx, e, op.node, lhs, rhs); needless_bitwise_bool::check(cx, e, op.node, lhs, rhs); ptr_eq::check(cx, e, op.node, lhs, rhs); - manual_midpoint::check(cx, e, op.node, lhs, rhs, &self.msrv); + manual_midpoint::check(cx, e, op.node, lhs, rhs, self.msrv); } self.arithmetic_context.check_binary(cx, e, op.node, lhs, rhs); bit_mask::check(cx, e, op.node, lhs, rhs); @@ -973,8 +973,6 @@ impl<'tcx> LateLintPass<'tcx> for Operators { fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) { self.arithmetic_context.body_post(cx, b); } - - extract_msrv_attr!(LateContext); } fn macro_with_not_op(e: &Expr<'_>) -> bool { diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index ffc3b86c502e..4f5f3eb6c15a 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -68,7 +68,7 @@ impl_lint_pass!(QuestionMark => [QUESTION_MARK, MANUAL_LET_ELSE]); impl QuestionMark { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, matches_behaviour: conf.matches_for_let_else, try_block_depth_stack: Vec::new(), inferred_ret_closure_stack: 0, @@ -543,5 +543,4 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark { .expect("blocks are always part of bodies and must have a depth") -= 1; } } - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 1b0c0a4956f7..cc423eca74fb 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -166,9 +166,7 @@ pub struct Ranges { impl Ranges { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -182,7 +180,7 @@ impl_lint_pass!(Ranges => [ impl<'tcx> LateLintPass<'tcx> for Ranges { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Binary(ref op, l, r) = expr.kind { - if self.msrv.meets(msrvs::RANGE_CONTAINS) { + if self.msrv.meets(cx, msrvs::RANGE_CONTAINS) { check_possible_range_contains(cx, op.node, l, r, expr, expr.span); } } @@ -191,7 +189,6 @@ impl<'tcx> LateLintPass<'tcx> for Ranges { check_inclusive_range_minus_one(cx, expr); check_reversed_empty_range(cx, expr); } - extract_msrv_attr!(LateContext); } fn check_possible_range_contains( diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 707abc008a86..feefe10f57d7 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; @@ -36,13 +36,13 @@ declare_clippy_lint! { } pub struct RedundantFieldNames { - msrv: Msrv, + msrv: MsrvStack, } impl RedundantFieldNames { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -80,5 +80,6 @@ impl EarlyLintPass for RedundantFieldNames { } } } - extract_msrv_attr!(EarlyContext); + + extract_msrv_attr!(); } diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 06c854338066..b4e1f70d1535 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::source::snippet; use rustc_ast::ast::{ConstItem, Item, ItemKind, StaticItem, Ty, TyKind}; use rustc_errors::Applicability; @@ -35,13 +35,13 @@ declare_clippy_lint! { } pub struct RedundantStaticLifetimes { - msrv: Msrv, + msrv: MsrvStack, } impl RedundantStaticLifetimes { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -115,5 +115,5 @@ impl EarlyLintPass for RedundantStaticLifetimes { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } diff --git a/clippy_lints/src/repeat_vec_with_capacity.rs b/clippy_lints/src/repeat_vec_with_capacity.rs index 40263afd28f1..8805687efccf 100644 --- a/clippy_lints/src/repeat_vec_with_capacity.rs +++ b/clippy_lints/src/repeat_vec_with_capacity.rs @@ -18,9 +18,7 @@ pub struct RepeatVecWithCapacity { impl RepeatVecWithCapacity { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -101,13 +99,14 @@ fn check_vec_macro(cx: &LateContext<'_>, expr: &Expr<'_>) { } /// Checks `iter::repeat(Vec::with_capacity(x))` -fn check_repeat_fn(cx: &LateContext<'_>, expr: &Expr<'_>) { +fn check_repeat_fn(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) { if !expr.span.from_expansion() && fn_def_id(cx, expr).is_some_and(|did| cx.tcx.is_diagnostic_item(sym::iter_repeat, did)) && let ExprKind::Call(_, [repeat_expr]) = expr.kind && fn_def_id(cx, repeat_expr).is_some_and(|did| cx.tcx.is_diagnostic_item(sym::vec_with_capacity, did)) && !repeat_expr.span.from_expansion() && let Some(exec_context) = std_or_core(cx) + && msrv.meets(cx, msrvs::REPEAT_WITH) { emit_lint( cx, @@ -126,10 +125,6 @@ fn check_repeat_fn(cx: &LateContext<'_>, expr: &Expr<'_>) { impl LateLintPass<'_> for RepeatVecWithCapacity { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { check_vec_macro(cx, expr); - if self.msrv.meets(msrvs::REPEAT_WITH) { - check_repeat_fn(cx, expr); - } + check_repeat_fn(cx, expr, self.msrv); } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs index 59c13a1e2c53..d68ac8bab128 100644 --- a/clippy_lints/src/std_instead_of_core.rs +++ b/clippy_lints/src/std_instead_of_core.rs @@ -99,7 +99,7 @@ impl StdReexports { pub fn new(conf: &'static Conf) -> Self { Self { prev_span: Span::default(), - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -110,7 +110,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { fn check_path(&mut self, cx: &LateContext<'tcx>, path: &Path<'tcx>, _: HirId) { if let Res::Def(_, def_id) = path.res && let Some(first_segment) = get_first_segment(path) - && is_stable(cx, def_id, &self.msrv) + && is_stable(cx, def_id, self.msrv) && !path.span.in_external_macro(cx.sess().source_map()) && !is_from_proc_macro(cx, &first_segment.ident) { @@ -153,8 +153,6 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { } } } - - extract_msrv_attr!(LateContext); } /// Returns the first named segment of a [`Path`]. @@ -174,7 +172,7 @@ fn get_first_segment<'tcx>(path: &Path<'tcx>) -> Option<&'tcx PathSegment<'tcx>> /// or now stable moves that were once unstable. /// /// Does not catch individually moved items -fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool { +fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: Msrv) -> bool { loop { if let Some(stability) = cx.tcx.lookup_stability(def_id) && let StabilityLevel::Stable { @@ -183,8 +181,8 @@ fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: &Msrv) -> bool { } = stability.level { let stable = match since { - StableSince::Version(v) => msrv.meets(v), - StableSince::Current => msrv.current().is_none(), + StableSince::Version(v) => msrv.meets(cx, v), + StableSince::Current => msrv.current(cx).is_none(), StableSince::Err => false, }; diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 694ad4f6347b..5c95dfe83473 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -77,9 +77,7 @@ pub struct StringPatterns { impl StringPatterns { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -136,7 +134,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio } } -fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) { +fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: Msrv) { if let ExprKind::Closure(closure) = method_arg.kind && let body = cx.tcx.hir_body(closure.body) && let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind) @@ -192,7 +190,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr< { return; } - if set_char_spans.len() > 1 && !msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) { + if set_char_spans.len() > 1 && !msrv.meets(cx, msrvs::PATTERN_TRAIT_CHAR_ARRAY) { return; } span_lint_and_then( @@ -238,9 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for StringPatterns { { check_single_char_pattern_lint(cx, arg); - check_manual_pattern_char_comparison(cx, arg, &self.msrv); + check_manual_pattern_char_comparison(cx, arg, self.msrv); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index cbf7b126632e..f961e1c4d1a3 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -95,7 +95,7 @@ impl TraitBounds { pub fn new(conf: &'static Conf) -> Self { Self { max_trait_bounds: conf.max_trait_bounds, - msrv: conf.msrv.clone(), + msrv: conf.msrv, } } } @@ -223,17 +223,15 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { } } } - - extract_msrv_attr!(LateContext); } impl TraitBounds { /// Is the given bound a `?Sized` bound, and is combining it (i.e. `T: X + ?Sized`) an error on /// this MSRV? See for details. fn cannot_combine_maybe_bound(&self, cx: &LateContext<'_>, bound: &GenericBound<'_>) -> bool { - if !self.msrv.meets(msrvs::MAYBE_BOUND_IN_WHERE) - && let GenericBound::Trait(tr) = bound + if let GenericBound::Trait(tr) = bound && let BoundPolarity::Maybe(_) = tr.modifiers.polarity + && !self.msrv.meets(cx, msrvs::MAYBE_BOUND_IN_WHERE) { cx.tcx.lang_items().get(LangItem::Sized) == tr.trait_ref.path.res.opt_def_id() } else { diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 7c83a2187990..f2da8d35cb4f 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -598,9 +598,7 @@ impl_lint_pass!(Transmute => [ ]); impl Transmute { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } impl<'tcx> LateLintPass<'tcx> for Transmute { @@ -632,16 +630,16 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { | crosspointer_transmute::check(cx, e, from_ty, to_ty) | transmuting_null::check(cx, e, arg, to_ty) | transmute_null_to_fn::check(cx, e, arg, to_ty) - | transmute_ptr_to_ref::check(cx, e, from_ty, to_ty, arg, path, &self.msrv) + | transmute_ptr_to_ref::check(cx, e, from_ty, to_ty, arg, path, self.msrv) | missing_transmute_annotations::check(cx, path, from_ty, to_ty, e.hir_id) | transmute_int_to_char::check(cx, e, from_ty, to_ty, arg, const_context) | transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context) - | transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, &self.msrv) + | transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, self.msrv) | transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg) - | transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) + | transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) | transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg) - | transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) - | transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv) + | transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) + | transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv) | (unsound_collection_transmute::check(cx, e, from_ty, to_ty) || transmute_undefined_repr::check(cx, e, from_ty, to_ty)) | (eager_transmute::check(cx, e, arg, from_ty, to_ty)); @@ -651,6 +649,4 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { } } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/transmute/transmute_float_to_int.rs b/clippy_lints/src/transmute/transmute_float_to_int.rs index f0b8abf9af66..f2c757952af3 100644 --- a/clippy_lints/src/transmute/transmute_float_to_int.rs +++ b/clippy_lints/src/transmute/transmute_float_to_int.rs @@ -17,11 +17,11 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, mut arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) - if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => + if !const_context || msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) => { span_lint_and_then( cx, diff --git a/clippy_lints/src/transmute/transmute_int_to_float.rs b/clippy_lints/src/transmute/transmute_int_to_float.rs index e5b9aea6423a..aaa95396b4b4 100644 --- a/clippy_lints/src/transmute/transmute_int_to_float.rs +++ b/clippy_lints/src/transmute/transmute_int_to_float.rs @@ -16,10 +16,10 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { - (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => { + (ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_FLOAT, diff --git a/clippy_lints/src/transmute/transmute_num_to_bytes.rs b/clippy_lints/src/transmute/transmute_num_to_bytes.rs index 6d828bad9b32..d72be270b731 100644 --- a/clippy_lints/src/transmute/transmute_num_to_bytes.rs +++ b/clippy_lints/src/transmute/transmute_num_to_bytes.rs @@ -16,14 +16,15 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, const_context: bool, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => { if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) { return false; } - if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) { + if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(cx, msrvs::CONST_FLOAT_BITS_CONV) + { return false; } diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index c4a2e20fa9d3..fcc763763bd2 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>( from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (from_ty.kind(), to_ty.kind()) { (ty::RawPtr(from_pointee_ty, from_mutbl), ty::RawPtr(to_pointee_ty, to_mutbl)) => { @@ -28,7 +28,7 @@ pub(super) fn check<'tcx>( if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) { if from_mutbl == to_mutbl && to_pointee_ty.is_sized(cx.tcx, cx.typing_env()) - && msrv.meets(msrvs::POINTER_CAST) + && msrv.meets(cx, msrvs::POINTER_CAST) { diag.span_suggestion_verbose( e.span, @@ -43,7 +43,7 @@ pub(super) fn check<'tcx>( _ => None, } && !from_pointee_ty.has_erased_regions() - && msrv.meets(msrvs::POINTER_CAST_CONSTNESS) + && msrv.meets(cx, msrvs::POINTER_CAST_CONSTNESS) { diag.span_suggestion_verbose( e.span, diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index ef18633d945f..45ee83c78ab6 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, path: &'tcx Path<'_>, - msrv: &Msrv, + msrv: Msrv, ) -> bool { match (&from_ty.kind(), &to_ty.kind()) { (ty::RawPtr(from_ptr_ty, _), ty::Ref(_, to_ref_ty, mutbl)) => { @@ -37,7 +37,7 @@ pub(super) fn check<'tcx>( let sugg = if let Some(ty) = get_explicit_type(path) { let ty_snip = snippet_with_applicability(cx, ty.span, "..", &mut app); - if msrv.meets(msrvs::POINTER_CAST) { + if msrv.meets(cx, msrvs::POINTER_CAST) { format!("{deref}{}.cast::<{ty_snip}>()", arg.maybe_par()) } else if from_ptr_ty.has_erased_regions() { sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {ty_snip}"))).to_string() @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>( } } else if *from_ptr_ty == *to_ref_ty { if from_ptr_ty.has_erased_regions() { - if msrv.meets(msrvs::POINTER_CAST) { + if msrv.meets(cx, msrvs::POINTER_CAST) { format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par()) } else { sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {to_ref_ty}"))) diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index c7aefc65f707..95ce19975c7e 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -47,15 +47,13 @@ pub struct TupleArrayConversions { } impl TupleArrayConversions { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } impl LateLintPass<'_> for TupleArrayConversions { fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if expr.span.in_external_macro(cx.sess().source_map()) || !self.msrv.meets(msrvs::TUPLE_ARRAY_CONVERSIONS) { + if expr.span.in_external_macro(cx.sess().source_map()) || !self.msrv.meets(cx, msrvs::TUPLE_ARRAY_CONVERSIONS) { return; } @@ -65,8 +63,6 @@ impl LateLintPass<'_> for TupleArrayConversions { _ => {}, } } - - extract_msrv_attr!(LateContext); } fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: &'tcx [Expr<'tcx>]) { diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 8923484bb58f..f43715d6752e 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -3,7 +3,7 @@ use clippy_config::Conf; use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_maybe_qself, eq_pat, eq_path}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::over; use rustc_ast::PatKind::*; use rustc_ast::mut_visit::*; @@ -48,13 +48,13 @@ declare_clippy_lint! { } pub struct UnnestedOrPatterns { - msrv: Msrv, + msrv: MsrvStack, } impl UnnestedOrPatterns { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: MsrvStack::new(conf.msrv), } } } @@ -88,7 +88,7 @@ impl EarlyLintPass for UnnestedOrPatterns { } } - extract_msrv_attr!(EarlyContext); + extract_msrv_attr!(); } fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { diff --git a/clippy_lints/src/unused_trait_names.rs b/clippy_lints/src/unused_trait_names.rs index f83415834351..2577f1ceaa2c 100644 --- a/clippy_lints/src/unused_trait_names.rs +++ b/clippy_lints/src/unused_trait_names.rs @@ -51,9 +51,7 @@ pub struct UnusedTraitNames { impl UnusedTraitNames { pub fn new(conf: &'static Conf) -> Self { - Self { - msrv: conf.msrv.clone(), - } + Self { msrv: conf.msrv } } } @@ -61,8 +59,7 @@ impl_lint_pass!(UnusedTraitNames => [UNUSED_TRAIT_NAMES]); impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if self.msrv.meets(msrvs::UNDERSCORE_IMPORTS) - && !item.span.in_external_macro(cx.sess().source_map()) + if !item.span.in_external_macro(cx.sess().source_map()) && let ItemKind::Use(path, UseKind::Single) = item.kind // Ignore imports that already use Underscore && item.ident.name != kw::Underscore @@ -74,6 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { && cx.tcx.visibility(item.owner_id.def_id) == Visibility::Restricted(module.to_def_id()) && let Some(last_segment) = path.segments.last() && let Some(snip) = snippet_opt(cx, last_segment.ident.span) + && self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS) && !is_from_proc_macro(cx, &last_segment.ident) { let complete_span = last_segment.ident.span.to(item.ident.span); @@ -88,6 +86,4 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { ); } } - - extract_msrv_attr!(LateContext); } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 569260eda34c..743f54ca993a 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -62,7 +62,7 @@ pub struct UseSelf { impl UseSelf { pub fn new(conf: &'static Conf) -> Self { Self { - msrv: conf.msrv.clone(), + msrv: conf.msrv, stack: Vec::new(), } } @@ -198,7 +198,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &Ty<'tcx, AmbigArg>) { if !hir_ty.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, ref types_to_skip, @@ -216,6 +215,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // the lifetime parameters of `ty` are elided (`impl<'a> Foo<'a> { fn new() -> Self { Foo{..} } }`, in // which case we must still trigger the lint. && (has_no_lifetime(ty) || same_lifetimes(ty, impl_ty)) + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) { span_lint(cx, hir_ty.span); } @@ -223,9 +223,9 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if !expr.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, .. }) = self.stack.last() && cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).instantiate_identity() + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) { } else { return; @@ -244,19 +244,17 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { if !pat.span.from_expansion() - && self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS) && let Some(&StackItem::Check { impl_id, .. }) = self.stack.last() // get the path from the pattern && let PatKind::Expr(&PatExpr { kind: PatExprKind::Path(QPath::Resolved(_, path)), .. }) | PatKind::TupleStruct(QPath::Resolved(_, path), _, _) | PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind && cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).instantiate_identity() + && self.msrv.meets(cx, msrvs::TYPE_ALIAS_ENUM_VARIANTS) { check_path(cx, path); } } - - extract_msrv_attr!(LateContext); } #[derive(Default)] diff --git a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs index 686922461530..558acacb9724 100644 --- a/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs +++ b/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs @@ -30,8 +30,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { .tcx .impl_trait_ref(item.owner_id) .map(EarlyBinder::instantiate_identity) - && let is_late_pass = match_def_path(cx, trait_ref.def_id, &paths::LATE_LINT_PASS) - && (is_late_pass || match_def_path(cx, trait_ref.def_id, &paths::EARLY_LINT_PASS)) + && match_def_path(cx, trait_ref.def_id, &paths::EARLY_LINT_PASS) && let ty::Adt(self_ty_def, _) = trait_ref.self_ty().kind() && self_ty_def.is_struct() && self_ty_def.all_fields().any(|f| { @@ -40,20 +39,18 @@ impl LateLintPass<'_> for MsrvAttrImpl { .instantiate_identity() .walk() .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) - .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV)) + .any(|t| match_type(cx, t.expect_ty(), &paths::MSRV_STACK)) }) && !items.iter().any(|item| item.ident.name.as_str() == "check_attributes") { - let context = if is_late_pass { "LateContext" } else { "EarlyContext" }; - let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" }; let span = cx.sess().source_map().span_through_char(item.span, '{'); span_lint_and_sugg( cx, MISSING_MSRV_ATTR_IMPL, span, - format!("`extract_msrv_attr!` macro missing from `{lint_pass}` implementation"), - format!("add `extract_msrv_attr!({context})` to the `{lint_pass}` implementation"), - format!("{}\n extract_msrv_attr!({context});", snippet(cx, span, "..")), + "`extract_msrv_attr!` macro missing from `EarlyLintPass` implementation", + "add `extract_msrv_attr!()` to the `EarlyLintPass` implementation", + format!("{}\n extract_msrv_attr!();", snippet(cx, span, "..")), Applicability::MachineApplicable, ); } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index 03c667846b61..3346b15dae9c 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -27,7 +27,7 @@ impl UselessVec { pub fn new(conf: &'static Conf) -> Self { Self { too_large_for_stack: conf.too_large_for_stack, - msrv: conf.msrv.clone(), + msrv: conf.msrv, span_to_lint_map: BTreeMap::new(), allow_in_test: conf.allow_useless_vec_in_tests, } @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { }, // search for `for _ in vec![...]` Node::Expr(Expr { span, .. }) - if span.is_desugaring(DesugaringKind::ForLoop) && self.msrv.meets(msrvs::ARRAY_INTO_ITERATOR) => + if span.is_desugaring(DesugaringKind::ForLoop) && self.msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) => { let suggest_slice = suggest_type(expr); self.check_vec_macro(cx, &vec_args, callsite, expr.hir_id, suggest_slice); @@ -149,8 +149,6 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec { } } } - - extract_msrv_attr!(LateContext); } impl UselessVec { diff --git a/tests/ui-internal/invalid_msrv_attr_impl.stderr b/tests/ui-internal/invalid_msrv_attr_impl.stderr index 8ba42e4bb2b2..0a7636313eff 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.stderr +++ b/tests/ui-internal/invalid_msrv_attr_impl.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::internal)] = note: `#[deny(clippy::missing_msrv_attr_impl)]` implied by `#[deny(clippy::internal)]` help: add `extract_msrv_attr!()` to the `EarlyLintPass` implementation | -LL + impl EarlyLintPass for Pass { +LL ~ impl EarlyLintPass for Pass { LL + extract_msrv_attr!(); | diff --git a/tests/ui/msrv_attributes_without_early_lints.rs b/tests/ui/msrv_attributes_without_early_lints.rs index dec62c15079d..dcef1a485fce 100644 --- a/tests/ui/msrv_attributes_without_early_lints.rs +++ b/tests/ui/msrv_attributes_without_early_lints.rs @@ -1,3 +1,5 @@ +//@check-pass + #![allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] #![forbid(clippy::ptr_as_ptr)] From 900aab72cd801926ee52ba02d982ae6d92c0df4d Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Fri, 28 Feb 2025 21:09:27 +0100 Subject: [PATCH 161/161] Fix ICE in manual_map lint node_args doesn't work with struct literals and expr_ty must be used instead --- clippy_utils/src/lib.rs | 5 ++++- tests/ui/crashes/ice-14325.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/ui/crashes/ice-14325.rs diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3e9429399b31..64955003bd2c 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -3651,7 +3651,10 @@ pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) - ExprKind::Struct(qpath, _, _) => { let res = cx.typeck_results().qpath_res(qpath, expr.hir_id); if let Some((_, v_def)) = adt_and_variant_of_res(cx, res) { - let generic_args = cx.typeck_results().node_args(expr.hir_id); + let rustc_ty::Adt(_, generic_args) = cx.typeck_results().expr_ty_adjusted(expr).kind() else { + // This should never happen, but when it does, not linting is the better option. + return true; + }; v_def .fields .iter() diff --git a/tests/ui/crashes/ice-14325.rs b/tests/ui/crashes/ice-14325.rs new file mode 100644 index 000000000000..d762bd6c9e00 --- /dev/null +++ b/tests/ui/crashes/ice-14325.rs @@ -0,0 +1,17 @@ +//@check-pass + +#![allow(clippy::redundant_pattern_matching)] + +struct S<'a> { + s: &'a str, +} + +fn foo() -> Option> { + if let Some(_) = Some(0) { + Some(S { s: "xyz" }) + } else { + None + } +} + +fn main() {}